summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/sys/t_mmap.c')
-rw-r--r--contrib/netbsd-tests/lib/libc/sys/t_mmap.c89
1 files changed, 85 insertions, 4 deletions
diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
index 5d821ec..738758c 100644
--- a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
+++ b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $ */
+/* $NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -55,10 +55,11 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $");
+__RCSID("$NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $");
#include <sys/param.h>
#include <sys/mman.h>
+#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
@@ -78,7 +79,6 @@ __RCSID("$NetBSD: t_mmap.c,v 1.7 2012/06/14 17:47:58 bouyer Exp $");
#ifdef __FreeBSD__
#include <sys/disklabel.h>
-#include <sys/stat.h>
#include <stdint.h>
#endif
@@ -381,9 +381,13 @@ ATF_TC_BODY(mmap_prot_3, tc)
* the access should generate SIGSEGV.
*/
fd = open(path, O_RDWR | O_CREAT, 0700);
-
if (fd < 0)
+#ifdef __FreeBSD__
+ atf_tc_skip("opening %s failed; skipping testcase: %s",
+ path, strerror(errno));
+#else
return;
+#endif
ATF_REQUIRE(write(fd, "XXX", 3) == 3);
ATF_REQUIRE(close(fd) == 0);
@@ -409,6 +413,9 @@ ATF_TC_BODY(mmap_prot_3, tc)
ATF_REQUIRE(WIFEXITED(sta) != 0);
ATF_REQUIRE(WEXITSTATUS(sta) == SIGSEGV);
ATF_REQUIRE(munmap(map, 3) == 0);
+#ifdef __FreeBSD__
+ (void)close(fd);
+#endif
}
ATF_TC_CLEANUP(mmap_prot_3, tc)
@@ -453,6 +460,9 @@ ATF_TC_BODY(mmap_truncate, tc)
ATF_REQUIRE(ftruncate(fd, page / 12) == 0);
ATF_REQUIRE(ftruncate(fd, page / 64) == 0);
+#ifdef __FreeBSD__
+ (void)munmap(map, page);
+#endif
ATF_REQUIRE(close(fd) == 0);
}
@@ -461,6 +471,76 @@ ATF_TC_CLEANUP(mmap_truncate, tc)
(void)unlink(path);
}
+ATF_TC_WITH_CLEANUP(mmap_truncate_signal);
+ATF_TC_HEAD(mmap_truncate_signal, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test mmap(2) ftruncate(2) causing signal");
+}
+
+ATF_TC_BODY(mmap_truncate_signal, tc)
+{
+ char *map;
+ long i;
+ int fd, sta;
+ pid_t pid;
+
+#ifdef __FreeBSD__
+ atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 211924");
+#endif
+
+ fd = open(path, O_RDWR | O_CREAT, 0700);
+
+ if (fd < 0)
+ return;
+
+ ATF_REQUIRE(write(fd, "foo\n", 5) == 5);
+
+ map = mmap(NULL, page, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
+ ATF_REQUIRE(map != MAP_FAILED);
+
+ sta = 0;
+ for (i = 0; i < 5; i++)
+ sta += map[i];
+ ATF_REQUIRE(sta == 334);
+
+ ATF_REQUIRE(ftruncate(fd, 0) == 0);
+ pid = fork();
+ ATF_REQUIRE(pid >= 0);
+
+ if (pid == 0) {
+ ATF_REQUIRE(signal(SIGBUS, map_sighandler) != SIG_ERR);
+ ATF_REQUIRE(signal(SIGSEGV, map_sighandler) != SIG_ERR);
+ sta = 0;
+ for (i = 0; i < page; i++)
+ sta += map[i];
+ /* child never will get this far, but the compiler will
+ not know, so better use the values calculated to
+ prevent the access to be optimized out */
+ ATF_REQUIRE(i == 0);
+ ATF_REQUIRE(sta == 0);
+#ifdef __FreeBSD__
+ (void)munmap(map, page);
+ (void)close(fd);
+#endif
+ return;
+ }
+
+ (void)wait(&sta);
+
+ ATF_REQUIRE(WIFEXITED(sta) != 0);
+ if (WEXITSTATUS(sta) == SIGSEGV)
+ atf_tc_fail("child process got SIGSEGV instead of SIGBUS");
+ ATF_REQUIRE(WEXITSTATUS(sta) == SIGBUS);
+ ATF_REQUIRE(munmap(map, page) == 0);
+ ATF_REQUIRE(close(fd) == 0);
+}
+
+ATF_TC_CLEANUP(mmap_truncate_signal, tc)
+{
+ (void)unlink(path);
+}
+
ATF_TC(mmap_va0);
ATF_TC_HEAD(mmap_va0, tc)
{
@@ -518,6 +598,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, mmap_prot_2);
ATF_TP_ADD_TC(tp, mmap_prot_3);
ATF_TP_ADD_TC(tp, mmap_truncate);
+ ATF_TP_ADD_TC(tp, mmap_truncate_signal);
ATF_TP_ADD_TC(tp, mmap_va0);
return atf_no_error();
OpenPOWER on IntegriCloud