-
-
Save ytlvy/c3e90ef8ee4b1e60622e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <signal.h> | |
void | |
segv() // <--- never gets called | |
{ | |
fprintf(stderr, "segv\n"); | |
exit(0); | |
} | |
void | |
recur() | |
{ | |
recur(); | |
} | |
int | |
main() | |
{ | |
stack_t ss; | |
ss.ss_sp = malloc(65536); | |
ss.ss_size = 65536; | |
ss.ss_flags = 0; | |
if(sigaltstack(&ss, NULL) < 0) { | |
perror("sigaltstack"); | |
exit(1); | |
} | |
struct sigaction sa; | |
sa.sa_flags = SA_SIGINFO; | |
sigemptyset(&sa.sa_mask); | |
sa.sa_sigaction = segv; | |
if(sigaction(SIGSEGV, &sa, NULL) < 0) { | |
perror("sigaction"); | |
exit(0); | |
} | |
if(sigaction(SIGBUS, &sa, NULL) < 0) { | |
perror("sigaction"); | |
exit(0); | |
} | |
recur(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment