Date: Tue, 15 Sep 1998 07:16:00 -0500 (EST) From: Alfred Perlstein <bright@hotjobs.com> To: Konrad Heuer <kheuer@gwdu60.gwdg.de> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Catching SIGSEGV Message-ID: <Pine.BSF.3.96.980915071330.21829D-100000@bright.fx.genx.net> In-Reply-To: <Pine.BSF.3.96.980915114921.5972A-100000@gwdu60.gwdg.de>
next in thread | previous in thread | raw e-mail | index | archive | help
i had to write a short test program, but simply when SIGSEGV is caught it seems that the return address is set to as to try to "retry" the operation that failed. take a look at the output of this program: #include <signal.h> int nsegv = 0; int ptr; int zero = 0; int *inv = 0; void sighdl ( int sig ) { ptr = &zero; printf("%x\n",inv);fflush(0); inv++; /* remove this to see 0 vs behaviour */ nsegv++; } int main( ) { int buf; signal(SIGSEGV, sighdl); ptr = *(++inv); /* note this only happens once, put the ++ after and it starts at 0 rather than 4 */ buf = ptr; return 1; } it compiles with a warning... sue me i'm up 24hrs :P Alfred Perlstein - Programmer, HotJobs Inc. - www.hotjobs.com -- There are operating systems, and then there's FreeBSD. -- http://www.freebsd.org/ 3.0-current On Tue, 15 Sep 1998, Konrad Heuer wrote: > > May I ask my question here although it's not correlated to FreeBSD > development? > > I write a program which shall run under FreeBSD and want to catch SIGSEGV > to count these events. So the program is like this: > > int nsegv = 0; > int *ptr; > int zero = 0; > > void sighdl ( int sig ) > { > ptr = &zero; > nsegv++; > } > > int dowork ( ) > { > int buf; > > signal(SIGSEGV, sighdl); > > ptr = InvalidAddress; > buf = *ptr; > } > > Ok, the signal handler gets called, ptr will be reset to a legal address, > but nevertheless after returning from the signal handler it will be called > again immediately resulting in an infinite loop. > > Where's my mistake? What can I do to prevent that loop? > Thanks for any reply. > > Regards > Konrad Heuer > > // Gesellschaft fuer wissenschaftliche Datenverarbeitung mbH > // Goettingen (GWDG), Am Fassberg, D-37077 Goettingen, Germany > // > // kheuer@gwdu60.gwdg.de > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.96.980915071330.21829D-100000>