blob: 909a2ef1a423476820fae87953abb5bbe90c5464 [file] [log] [blame]
Dmitry V. Levine96cb622015-02-15 15:52:02 +00001#include <unistd.h>
2#include <sys/mman.h>
3#include <sys/wait.h>
4
5int main(void)
6{
7 const unsigned long size = sysconf(_SC_PAGESIZE);
8 const unsigned long mask = ~(size - 1);
9
10 /* write instruction pointer length to the log */
11 if (write(-1, NULL, 2 * sizeof(void *)) >= 0)
12 return 77;
13 /* just a noticeable line in the log */
14 if (munmap(&munmap, 0) >= 0)
15 return 77;
16
17 int pid = fork();
18 if (pid < 0)
19 return 77;
20
21 if (!pid) {
22 munmap((void *) ((unsigned long) &munmap & mask), size);
23 /* SIGSEGV is expected */
24 munmap((void *) (((unsigned long) &munmap & mask) + size), size);
25 return 77;
26 }
27
28 int status;
29 if (wait(&status) != pid ||
30 !WIFSIGNALED(status) ||
31 WTERMSIG(status) != SIGSEGV)
32 return 77;
33
34 return 0;
35}