Re: [?] Find the address of a segfault in userland

David Wragg (dpw@doc.ic.ac.uk)
Wed, 4 Mar 1998 23:10:17 GMT


Jason Duerstock <jasond@cdc.net> writes:
> I believe so. I think the alpha ends up pointing to the buggy
> instruction, but on the x86 it points to the instruction after.

If that was the case then how could the kernel do paging? Segfaults
are just a user-space reflection of the mechanism the kernel uses for
paging. The kernel at least must have the address of the faulting
instruction, so that after it has read a page in and fixed up the page
tables it can restart the instruction, if it so wishes. In this case,
of course, the kernel instead sets up the process to invoke the signal
handler.

So even on the crufty old x86, info.eip is indeed the address of the
faulting instruction.

> On Sat, 28 Feb 1998, David Woodhouse wrote:
>
> > jasond@cdc.net said:
> > > void sigsegv_handler(int num, struct sigcontext info) /* ignore the
> > > compiler whinings :D */ {
> > > printf("EIP: %x\n", info.eip); }
> >
> >
> > That doesn't give the address that caused the fault, though - does the sigsegv
> > handler have to disassemble the offending instruction and work out the
> > faulting address itself?

No, it's much simpler than that - the faulting address is passed to
the handler in the cr2 member of the sigcontext struct (named after
the register the x86 puts the address in when it invokes the kernel's
exception handler).

Look in <asm/sigcontext.h>. Most of the fields are self-explanatory.

--
Dave Wragg

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu