// *** Synnergy Networks // * Description: // // Test for catching the SIGSEGV and SIGBUS without crashing // and with setjmp()/longjmp() // * Author: // // guidob (guidob@synnergy.net) // Synnergy Networks (c) 1999, http://www.synnergy.net // * Greets: // // Synnergy Networks, Hit2000 crew, Cindy // * Comments: // // For more details, read the source. // *** Synnergy Networks #include #include #include #include #include #include jmp_buf env; void notwithme(int); int beyond(int); int main(){ int i; int mysig; sigset(SIGSEGV,notwithme); sigset(SIGBUS,notwithme); if( ( mysig = setjmp(env) ) == 0 ){ // Now it's the first time here for(i=10000;;i++){ cout << "Testing with i = " << i << endl; beyond(i); } }else{ // Now we come from signal handler cout << "I survived the fatal error, but still withdraw\n"; cout << "The signal I got was: " << mysig << endl; sleep(1); return(0); } return(0); } int beyond(int x){ int a[20]; // Just one critical operation, which cannot workout a[x]=1; return(1); } void notwithme(int sig){ longjmp(env, sig); // just for savety exit(0); } // EOF