summaryrefslogtreecommitdiffstats
path: root/tests/vm/mmap-inherit.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vm/mmap-inherit.c')
-rw-r--r--tests/vm/mmap-inherit.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/vm/mmap-inherit.c b/tests/vm/mmap-inherit.c
new file mode 100644
index 0000000..7fa9607
--- /dev/null
+++ b/tests/vm/mmap-inherit.c
@@ -0,0 +1,32 @@
1/* Maps a file into memory and runs child-inherit to verify that
2 mappings are not inherited. */
3
4#include <string.h>
5#include <syscall.h>
6#include "tests/vm/sample.inc"
7#include "tests/lib.h"
8#include "tests/main.h"
9
10void
11test_main (void)
12{
13 char *actual = (char *) 0x54321000;
14 int handle;
15 pid_t child;
16
17 /* Open file, map, verify data. */
18 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
19 CHECK (mmap (handle, actual) != MAP_FAILED, "mmap \"sample.txt\"");
20 if (memcmp (actual, sample, strlen (sample)))
21 fail ("read of mmap'd file reported bad data");
22
23 /* Spawn child and wait. */
24 CHECK ((child = exec ("child-inherit")) != -1, "exec \"child-inherit\"");
25 quiet = true;
26 CHECK (wait (child) == -1, "wait for child (should return -1)");
27 quiet = false;
28
29 /* Verify data again. */
30 CHECK (!memcmp (actual, sample, strlen (sample)),
31 "checking that mmap'd file still has same data");
32}