From: Frank Mori Hess Date: Sat, 24 Jul 2004 15:47:30 +0000 (+0000) Subject: fix test_segfault() so it works with 2.6 kernel signal handling behaviour X-Git-Tag: r0_7_22~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e66997b981d748941821eb224f048760386d5075;p=comedilib.git fix test_segfault() so it works with 2.6 kernel signal handling behaviour --- diff --git a/testing/mmap.c b/testing/mmap.c index 6268efb..d59843c 100644 --- a/testing/mmap.c +++ b/testing/mmap.c @@ -26,30 +26,32 @@ #define MAPLEN 20480 -jmp_buf jump_env; +sigjmp_buf jump_env; void segv_handler(int num) { - longjmp(jump_env,1); + siglongjmp(jump_env,1); } int test_segfault(void *memptr) { volatile char tmp; int ret; - - ret=setjmp(jump_env); - if(!ret) tmp = *((char *)(memptr)); - return ret; -} - -void setup_segfaulter(void) -{ struct sigaction act; + struct sigaction oldact; memset(&act,0,sizeof(act)); act.sa_handler=&segv_handler; - sigaction(SIGSEGV,&act,NULL); + ret = sigaction(SIGSEGV,&act,&oldact); + if(ret) + { + fprintf(stderr, "sigaction failed\n"); + return 0; + } + ret=sigsetjmp(jump_env, 1); + if(!ret) tmp = *((char *)(memptr)); + sigaction(SIGSEGV,&oldact,NULL); + return ret; } int test_mmap(void) @@ -79,8 +81,6 @@ int test_mmap(void) return 0; } - setup_segfaulter(); - buf=malloc(BUFSZ); map=mmap(NULL,MAPLEN,PROT_READ,MAP_SHARED,comedi_fileno(device),0); @@ -153,7 +153,7 @@ int test_mmap(void) printf("E: %p still mapped\n",adr); } } - + free(buf); return 0;