/* Test that gatching SIGSEGV gives the correct fault address. */ #include #include #include #include void * volatile p = NULL; void * volatile block; void foo(int n, siginfo_t *info, void *data) { p = info->si_addr; printf ("%p\n", block); mprotect(block, sizeof(int), PROT_READ | PROT_WRITE); } int main() { struct sigaction sa; p = &sa; memset (&sa, 0, sizeof(sa)); sa.sa_sigaction = foo; sa.sa_flags = SA_SIGINFO; sigaction (SIGSEGV, &sa, NULL); block = mmap(NULL, sizeof(int), PROT_READ, MAP_SHARED|MAP_ANONYMOUS, 0, 0); if (block == MAP_FAILED) { printf ("mmap failed\n"); return 1; } *(volatile int *) block = 42; sleep(1); if (p != block) printf ("FAIL: expected %p, got %p\n", block, p); else printf ("OK\n"); return 0; }