Karlis Peisenieks wrote:
> When process tries to access invalid virtual memory address, it gets
> SIGSEGV.
> Is there a way to determine what address process tried to access and
> what is virtual address of instruction that attempted access in SIGSEGV
> handler?
I don't know if there's an official way, but the address appears to be
available in the eax register, and also at ebp+56. I think that its
presence at ebp+56 may be deliberate (from setup_frame(), in
arch/i386/kernel/signal.c), while its presence in eax may be
accidental.
--
Glynn Clements <[EMAIL PROTECTED]>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void handler(int signum)
{
void *eax;
void **ebp;
__asm__("movl %%eax,%0":"=r" (eax));
__asm__("movl %%ebp,%0":"=r" (ebp));
printf("fault: eax = %p, ebp[14] = %p\n", eax, ebp[14]);
_exit(0);
}
int main(void)
{
char *p = (char *) 0xdeadbeef;
signal(SIGSEGV, handler);
return *p;
}