Last active
February 15, 2018 10:41
-
-
Save scottt/71a83179ab4cfd4837dba169b4f573a7 to your computer and use it in GitHub Desktop.
This file contains 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 <unistd.h> | |
#include <assert.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <setjmp.h> | |
char *c; | |
sigjmp_buf jbuf; | |
void sighandler(int signumber) { | |
printf("got signal %d (%s)\n", signumber, | |
sys_siglist[signumber]); | |
c = (char*)malloc(sizeof(char)); | |
siglongjmp(jbuf, 2); | |
} | |
int main(int argc, char **argv) { | |
void (*h)(int); | |
h = signal(SIGSEGV, sighandler); | |
assert(h != SIG_ERR); | |
sigsetjmp(jbuf, 0); | |
/* force reload of 'c' with volatile cast */ | |
*((volatile char *)c) = '0'; /*segmentation fault*/ | |
printf("my pid is %d\n", getpid()); | |
printf("press any key to resume\n"); | |
getchar(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment