Date: Sat, 11 Oct 2008 17:51:44 -0700 (PDT) From: Nate Eldredge <neldredge@math.ucsd.edu> To: Yuri <yuri@rawbw.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Is it possible to recover from SEGV? Message-ID: <Pine.GSO.4.64.0810111745510.16737@zeno.ucsd.edu> In-Reply-To: <48F147A5.1040107@rawbw.com> References: <48F147A5.1040107@rawbw.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 neldredge@math.ucsd.edu
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.0810111745510.16737>