#include #include #include #include #include static void sighandler(int sig, siginfo_t *si, void *uc) { printf("faulting address: 0x%lx\n", (unsigned long)si->si_addr); exit(1); } int main() { char *page = mmap(0, 8192, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); mprotect(page, 4096, PROT_READ | PROT_WRITE); struct sigaction sa; sa.sa_sigaction = (void *)sighandler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO| SA_NODEFER; sigaction(SIGSEGV, &sa, NULL); void *access_addr = page + 4095; printf("Mapped page = %p; will access %p\n", page, access_addr); gettimeofday(access_addr, NULL); return 0; }