Skip to content

Instantly share code, notes, and snippets.

@scottt
Last active February 15, 2018 10:41
Show Gist options
  • Save scottt/71a83179ab4cfd4837dba169b4f573a7 to your computer and use it in GitHub Desktop.
Save scottt/71a83179ab4cfd4837dba169b4f573a7 to your computer and use it in GitHub Desktop.
#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