2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2015, Joyent, Inc.
17 * Verify that using MC_INHERIT_ZERO doesn't work on mappings that aren't
18 * anonymous private mappings.
21 #include <sys/types.h>
37 char *template = "/tmp/inz_inval.XXXXXX";
39 size_t mapsz
= sysconf(_SC_PAGESIZE
) * 2;
40 caddr_t bad
= (caddr_t
)(uintptr_t)23;
42 buf
= mmap(NULL
, mapsz
, PROT_READ
| PROT_WRITE
,
43 MAP_PRIVATE
| MAP_ANON
, -1, 0);
44 assert(buf
!= MAP_FAILED
);
46 /* Bad arguments to memcntl */
47 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, bad
, 0, 0);
49 assert(errno
== EINVAL
);
51 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, 0, PROT_READ
, 0);
53 assert(errno
== EINVAL
);
55 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, bad
, PROT_READ
| PRIVATE
, 0);
57 assert(errno
== EINVAL
);
59 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, 0, 0, 1);
61 assert(errno
== EINVAL
);
63 ret
= munmap(buf
, mapsz
);
66 /* Mapping non-existant region */
67 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, 0, 0, 0);
69 assert(errno
== ENOMEM
);
71 /* Map anon MAP_SHARED */
72 buf
= mmap(NULL
, mapsz
, PROT_READ
| PROT_WRITE
,
73 MAP_SHARED
| MAP_ANON
, -1, 0);
74 assert(buf
!= MAP_FAILED
);
75 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, 0, 0, 0);
77 assert(errno
== EINVAL
);
78 ret
= munmap(buf
, mapsz
);
81 /* Grab a temp file and get it to be the right size */
82 tmpfile
= strdup(template);
83 assert(tmpfile
!= NULL
);
84 fd
= mkstemp(tmpfile
);
86 ret
= ftruncate(fd
, mapsz
);
89 /* MAP_PRIVATE file */
90 buf
= mmap(NULL
, mapsz
, PROT_READ
| PROT_WRITE
, MAP_PRIVATE
, fd
, 0);
91 assert(buf
!= MAP_FAILED
);
92 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, 0, 0, 0);
94 assert(errno
== EINVAL
);
95 ret
= munmap(buf
, mapsz
);
99 buf
= mmap(NULL
, mapsz
, PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, 0);
100 assert(buf
!= MAP_FAILED
);
101 ret
= memcntl(buf
, mapsz
, MC_INHERIT_ZERO
, 0, 0, 0);
103 assert(errno
== EINVAL
);
104 ret
= munmap(buf
, mapsz
);
109 (void) unlink(tmpfile
);