1 /* $NetBSD: t_minherit.c,v 1.1 2014/07/18 12:34:52 christos Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_minherit.c,v 1.1 2014/07/18 12:34:52 christos Exp $");
34 #include <sys/param.h>
36 #include <sys/sysctl.h>
50 makemap(int v
, int f
) {
51 void *map
= mmap(NULL
, page
, PROT_READ
|PROT_WRITE
,
52 MAP_SHARED
|MAP_ANON
, -1, 0);
53 ATF_REQUIRE(map
!= MAP_FAILED
);
56 ATF_REQUIRE(minherit(map
, page
, f
) == 0);
58 ATF_REQUIRE(minherit(map
, page
, f
) == -1);
62 ATF_TC(minherit_copy
);
63 ATF_TC_HEAD(minherit_copy
, tc
)
65 atf_tc_set_md_var(tc
, "descr",
66 "Test for MAP_INHERIT_COPY from minherit(2)");
69 ATF_TC_BODY(minherit_copy
, tc
)
71 void *map1
= makemap(1, MAP_INHERIT_COPY
);
72 void *map2
= makemap(1, MAP_INHERIT_COPY
);
75 ATF_REQUIRE(wait(NULL
) != -1);
76 ATF_REQUIRE(memcmp(map1
, map2
, page
) == 0);
82 ATF_REQUIRE(memcmp(map1
, map2
, page
) == 0);
83 memset(map1
, 0, page
);
88 ATF_TC(minherit_share
);
89 ATF_TC_HEAD(minherit_share
, tc
)
91 atf_tc_set_md_var(tc
, "descr",
92 "Test for MAP_INHERIT_SHARE from minherit(2)");
95 ATF_TC_BODY(minherit_share
, tc
)
97 void *map1
= makemap(1, MAP_INHERIT_SHARE
);
98 void *map2
= makemap(1, MAP_INHERIT_SHARE
);
102 ATF_REQUIRE(wait(NULL
) != -1);
103 memset(map2
, 0, page
);
104 ATF_REQUIRE(memcmp(map1
, map2
, page
) == 0);
110 ATF_REQUIRE(memcmp(map1
, map2
, page
) == 0);
111 memset(map1
, 0, page
);
121 ATF_TC(minherit_none
);
122 ATF_TC_HEAD(minherit_none
, tc
)
124 atf_tc_set_md_var(tc
, "descr",
125 "Test for MAP_INHERIT_NONE from minherit(2)");
128 ATF_TC_BODY(minherit_none
, tc
)
130 void *map1
= makemap(0, MAP_INHERIT_NONE
);
135 ATF_REQUIRE(wait(&status
) != -1);
136 ATF_REQUIRE(WEXITSTATUS(status
) == SIGSEGV
);
142 ATF_REQUIRE(signal(SIGSEGV
, segv
) != SIG_ERR
);
143 memset(map1
, 0, page
);
148 ATF_TC(minherit_zero
);
149 ATF_TC_HEAD(minherit_zero
, tc
)
151 atf_tc_set_md_var(tc
, "descr",
152 "Test for MAP_INHERIT_ZERO from minherit(2)");
155 ATF_TC_BODY(minherit_zero
, tc
)
157 void *map1
= makemap(1, MAP_INHERIT_ZERO
);
158 void *map2
= makemap(0, MAP_INHERIT_SHARE
);
162 ATF_REQUIRE(wait(NULL
) != -1);
163 memset(map2
, 1, page
);
164 ATF_REQUIRE(memcmp(map1
, map2
, page
) == 0);
170 ATF_REQUIRE(memcmp(map1
, map2
, page
) == 0);
171 memset(map1
, 2, page
);
176 ATF_TC(minherit_bad
);
177 ATF_TC_HEAD(minherit_bad
, tc
)
179 atf_tc_set_md_var(tc
, "descr",
180 "Test for bad minherit(2)");
183 ATF_TC_BODY(minherit_bad
, tc
)
185 (void)makemap(0, 666);
190 page
= sysconf(_SC_PAGESIZE
);
191 ATF_REQUIRE(page
>= 0);
193 ATF_TP_ADD_TC(tp
, minherit_copy
);
194 ATF_TP_ADD_TC(tp
, minherit_share
);
195 ATF_TP_ADD_TC(tp
, minherit_none
);
196 ATF_TP_ADD_TC(tp
, minherit_zero
);
197 ATF_TP_ADD_TC(tp
, minherit_bad
);
199 return atf_no_error();