Re: Catching SIGSEGV with signal() in 2.6

From: Richard B. Johnson
Date: Mon Apr 05 2004 - 16:02:22 EST


On Mon, 5 Apr 2004, Jamie Lokier wrote:

> Chris Friesen wrote:
> > SA_SIGINFO implies sigaction(). The original poster was talking about
> > signal().
> >
> > That said, it seems to work with 2.6.4 on ppc32.
>
> Just tried it with 2.6.3, x86 and signal(). Works fine.
>
> -- Jamie

Are you using a longjump to get out of the signal handler?
You may find that you can trap SIGSEGV, but you can't exit
from it because it will return to the instruction that
caused the trap!!!

#include <stdio.h>
#include <signal.h>
void handler(int sig) {
fprintf(stderr, "Caught %d\n", sig);
}
int main() {
char *foo = NULL;
signal(SIGSEGV, handler);
fprintf(stderr, "Send a signal....\n");
kill(0, SIGSEGV);
fprintf(stderr, "Okay! That worked!\n");
// *foo = 0;
return 0;
}

Just un-comment the null-pointer de-reference and watch!

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/