From: Matthew Dillon Date: Wed, 26 Oct 2011 22:48:10 +0000 (-0700) Subject: test - Add code to test recent bus error issue X-Git-Tag: v3.0.0~811 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/1c60bab9b3f5ce8531f1c2117542d42c2262569d test - Add code to test recent bus error issue Submitted-by: "Samuel J. Greear" --- diff --git a/test/debug/buserr.c b/test/debug/buserr.c new file mode 100644 index 0000000000..c7dfb4205a --- /dev/null +++ b/test/debug/buserr.c @@ -0,0 +1,59 @@ +/* + * Test a fork/munmap vm_object shadow chain race + * + * Written by "Samuel J. Greear" + */ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define MAPPING_PAGES 4096 + +int +main(int argc, char *argv[]) +{ + unsigned int i, size; + int status; + pid_t pid; + void *mapping; + char tmp[100]; + + for (i = 1; i < MAPPING_PAGES; ++i) { + size = PAGE_SIZE * i; + mapping = mmap(0, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, + -1, 0); + if (mapping == MAP_FAILED) + errx(EX_OSERR, "mmap() failed"); + + memset(mapping, 'x', 10); + printf(" %d", i); + fflush(stdout); + + pid = fork(); + if (pid == 0) { + memcpy(&tmp, mapping, 12); + return (0); + } else if (pid != -1) { + if (munmap(mapping, PAGE_SIZE * i) != 0) { + printf("munmap failed\n"); + return (0); + } + waitpid(pid, &status, 0); + if (status == 10) { + printf("child sig10 at %d pages\n", i); + return (0); + } + } else { + printf("fork failed\n"); + } + } + + return (0); +}