mirror of
https://github.com/ptitSeb/box64.git
synced 2024-11-27 00:30:32 +00:00
31 lines
489 B
C
31 lines
489 B
C
|
#include <signal.h>
|
||
|
#include <setjmp.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
static jmp_buf context_buf;
|
||
|
|
||
|
static void segv_handler(int sig)
|
||
|
{
|
||
|
printf("sig = %d\n", sig);
|
||
|
longjmp(context_buf, 1);
|
||
|
}
|
||
|
|
||
|
void test()
|
||
|
{
|
||
|
if(!setjmp(context_buf)) {
|
||
|
int *bad_ptr = (int*)0xdeadbeef;
|
||
|
printf("*bad_ptr = %d\n", *bad_ptr);
|
||
|
} else {
|
||
|
printf("got bad_ptr\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
if(signal(SIGSEGV, segv_handler) == SIG_ERR)
|
||
|
printf("Err = %m\n");
|
||
|
//printf("handler = %p\n", segv_handler);
|
||
|
test();
|
||
|
return 0;
|
||
|
}
|