Re: Is it possible to recover from SEGV?

2008-10-12 Thread Romain Tartière
Hi Yuri,

On Sat, Oct 11, 2008 at 05:41:09PM -0700, Yuri wrote:
 Is there a way to access from signal handler CPU registers as they
 were before signal, modify some of them, clear the signal and
 continue from the instruction that caused SEGV initially?

Maybe you can have a look to the development version of the
Enlightenment window manager [1]. It catches segfaults and displayed a
window to ask the user what to do (continue, abort).  I experienced a
few crashes where this helpful window was triggered a dozen times, I
asked the window manager to continue and could save my work before
everything crashed.

First moves in the svn repository [2] (basically grep SEGV):
| ./src/bin/e_exec.c:456:   else if (cfdata-event.exit_signal == SIGSEGV)
| ./src/bin/e_desklock.c:689:   sigaction(SIGSEGV, action, NULL);
| ./src/bin/e_object.c:153: sigaction(SIGSEGV, act, oact);
| ./src/bin/e_object.c:158:  sigaction(SIGSEGV, oact, NULL);
| ./src/bin/e_object.c:168:  sigaction(SIGSEGV, oact, NULL);
| ./src/bin/e_signals.c:28:   e_alert_show(This is very bad. Enlightenment 
SEGV'd.\n
| ./src/bin/e_signals.c:48:   e_alert_show(This is very bad. Enlightenment 
SEGV'd.\n
| ./src/bin/e_main.c:99:   sigaction(SIGSEGV, action, NULL);
| ./src/bin/e_main.c:322:// FIXME: SEGV's on shutdown if fm2 windows up - 
disable for now.

Hope that helps!
Romain

References:
  1. http://enlightenment.org/
  2. http://svn.enlightenment.org/svn/e/trunk/e/

-- 
Romain Tartière [EMAIL PROTECTED]http://romain.blogreen.org/
pgp: 8DAB A124 0DA4 7024 F82A  E748 D8E9 A33F FF56 FF43 (ID: 0xFF56FF43)
(plain text =non-HTML= PGP/GPG encrypted/signed e-mail much appreciated)


pgpVxJ2QWDAt9.pgp
Description: PGP signature


Re: Is it possible to recover from SEGV?

2008-10-11 Thread Nate Eldredge

On Sat, 11 Oct 2008, Yuri wrote:


Let's say I have signal(3) handler set.
And I know exactly what instruction caused SEGV and why.

Is there a way to access from signal handler CPU registers as they
were before signal, modify some of them, clear the signal and
continue from the instruction that caused SEGV initially?


Absolutely.  Declare your signal handler as

void handler(int sig, int code, struct sigcontext *scp);

You will need to cast the pointer passed to signal(3).  struct sigcontext 
is defined in machine/sysarch.h I believe.   struct sigcontext contains 
the CPU registers as they were when the faulting instruction began to 
execute.  You can modify them and then return from the signal handler. 
The program will resume the faulting instruction with the new registers. 
You can also alter the copy of the instruction pointer in the struct 
sigcontext if you want it to resume somewhere else.


There is also a libsigsegv which looks like it wraps some of this process 
in a less machine-specific way.


Out of curiosity, what are you looking to achieve with this?  And what 
architecture are you on?


--

Nate Eldredge
[EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]