From owner-freebsd-hackers Tue Sep 15 04:15:02 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA14981 for freebsd-hackers-outgoing; Tue, 15 Sep 1998 04:15:02 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from bright.fx.genx.net (bright.fx.genx.net [206.64.4.154]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id EAA14976 for ; Tue, 15 Sep 1998 04:15:00 -0700 (PDT) (envelope-from bright@hotjobs.com) Received: from localhost (bright@localhost) by bright.fx.genx.net (8.9.1/8.8.8) with SMTP id HAA01989; Tue, 15 Sep 1998 07:16:00 -0500 (EST) (envelope-from bright@hotjobs.com) X-Authentication-Warning: bright.fx.genx.net: bright owned process doing -bs Date: Tue, 15 Sep 1998 07:16:00 -0500 (EST) From: Alfred Perlstein X-Sender: bright@bright.fx.genx.net To: Konrad Heuer cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Catching SIGSEGV In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 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