On Tue, Jul 25, 2000 at 09:51:26AM +0100, Chris Quinn wrote:
> Does anyone know if the faulting address related to a SIGSEGV is available? I want to mprotect(PROT_READ) mmap()'ed pages and intercept this signal, record the address and change the protection to allow continuation. The reason I ask here is I don't believe such info is available through a system call and am wondering whether it can be made so via a kernel mod; maybe even the kernel cannot know?
>
no kernel patch needed, for 2.4 try using siginfo and for 2.0-2.2 something
like this:
#if defined(linux)
#ifdef __i486__
void segv_handler(int signr, struct sigcontext_struct sigc)
{
struct sigcontext_struct *sc=&sigc;
long i;
#if 0
printf("faulting address: %d, %x, -theROM = %d, %x\n",sc->cr2,sc->cr2,
(unsigned long)sc->cr2-(unsigned long)theROM,
(unsigned long)sc->cr2-(unsigned long)theROM );
#endif
/*i=(long)sc->cr2-(long)theROM;*/
segv_generic(sc->cr2,signr);
}
#endif /* i486 */
#ifdef m68k
#include <asm/ptrace.h>
#include <asm/traps.h>
void segv_handler(int signr, int vecnum, struct sigcontext *scp)
{
unsigned long ea;
int format = (scp->sc_formatvec >> 12) & 0xf;
Frame *framedata = (struct frame *)(scp + 1);
vecnum = (vecnum & 0xfff) >> 2;
/*printf("exception vec %d, fmt %d\n",vecnum,format);*/
switch (format)
{
case 7: ea=framedata->fmt7.faddr;
#if 0
printf("segv: ssw=%x, faddr= %x, \n\twb2s=%x, wb2a=%x, wb3s=%x, wb3a=%d\n"
"MA=%x, RW=%x\n ",
framedata->fmt7.ssw, framedata->fmt7.faddr,
framedata->fmt7.wb2s, framedata->fmt7.wb2a,
framedata->fmt7.wb3s, framedata->fmt7.wb3a,
framedata->fmt7.ssw&MA_040, framedata->fmt7.ssw&RW_040
);
#endif
if (framedata->fmt7.ssw&MA_040) {
ea=PAGEX(PAGEI(ea+4));
/*printf("MA set\n");*/
}
break;
case 0xa: ea=framedata->fmta.daddr; break;
case 0xb: ea=framedata->fmtb.daddr; break;
default:
printf("illegal exception format\n");
on_fat_int(signr);
}
segv_generic(ea,signr);
}
#endif /* m68k */
#endif /* linux*/
For a larger collection of OS/archtiectures see Boehm's 'gc'.. beware it includes
a few bugs also.
Bye
Richard
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon Jul 31 2000 - 21:00:23 EST