summaryrefslogtreecommitdiff
path: root/regress/sys/kern
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-01-31 15:53:13 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-01-31 15:53:13 +0000
commit1318653226f5ea80c155df568a23d2be6df2cb3d (patch)
tree61e85280f441e294d5e147278fd1fbd259531023 /regress/sys/kern
parent2afcaf7ec9ae9192e8774dd69bcd5aed32aec69e (diff)
simple test for minherit.
Diffstat (limited to 'regress/sys/kern')
-rw-r--r--regress/sys/kern/minherit/Makefile4
-rw-r--r--regress/sys/kern/minherit/minherit.c63
2 files changed, 67 insertions, 0 deletions
diff --git a/regress/sys/kern/minherit/Makefile b/regress/sys/kern/minherit/Makefile
new file mode 100644
index 00000000000..e63cca1fbf7
--- /dev/null
+++ b/regress/sys/kern/minherit/Makefile
@@ -0,0 +1,4 @@
+# $OpenBSD: Makefile,v 1.1 2002/01/31 15:53:12 art Exp $
+PROG=minherit
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/minherit/minherit.c b/regress/sys/kern/minherit/minherit.c
new file mode 100644
index 00000000000..2b5ed236db2
--- /dev/null
+++ b/regress/sys/kern/minherit/minherit.c
@@ -0,0 +1,63 @@
+/* $OpenBSD: minherit.c,v 1.1 2002/01/31 15:53:12 art Exp $ */
+/*
+ * Written by Artur Grabowski <art@openbsd.org> Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/mman.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+
+#define MAGIC "inherited"
+
+int
+main()
+{
+ void *map1, *map2;
+ int page_size;
+ int status;
+
+ page_size = getpagesize();
+
+ if ((map1 = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_ANON,
+ -1, 0)) == MAP_FAILED)
+ err(1, "mmap");
+
+ if ((map2 = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_ANON,
+ -1, 0)) == MAP_FAILED)
+ err(1, "mmap");
+
+ memset(map1, 0, sizeof(MAGIC));
+ memcpy(map2, MAGIC, sizeof(MAGIC));
+
+ if (minherit(map1, page_size, MAP_INHERIT_SHARE) != 0)
+ err(1, "minherit");
+
+ if (minherit(map2, page_size, MAP_INHERIT_NONE) != 0)
+ err(1, "minherit");
+
+ switch(fork()) {
+ case -1:
+ err(1, "fork");
+ case 0:
+ memcpy(map1, MAGIC, sizeof(MAGIC));
+ /* map2 is not mapped and should give us error on munmap */
+ if (munmap(map2, page_size) == 0)
+ _exit(1);
+ _exit(0);
+ }
+
+ if (wait(&status) < 0)
+ err(1, "wait");
+
+ if (!WIFEXITED(status))
+ err(1, "child error");
+
+ if (memcmp(map1, MAGIC, sizeof(MAGIC)) != 0)
+ return 1;
+
+ return WEXITSTATUS(status) != 0;
+} \ No newline at end of file