lkml.org 
[lkml]   [2000]   [Jan]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectDetermining address which caused SEGV
Date
I am trying to write a signal handler for SEGV that can figure out
what address was being accessed to cause the fault. Yes, I have a
good reason for wanting this.

The man page for sigaction() implies that the attached program below
should print "si_addr = 0x20". But when I run it on Linux/x86 2.2.14,
it says the si_addr field is always NULL. As near as I can tell by
grepping the sources, only the m68k port even tries to set si_addr
appropriately when a memory fault occurs.

Two questions:

1) Is there an easy way to do what I want on Linux/x86?
(Disassembling the instruction which caused the fault does not
qualify as "easy".)

2) Can the kernel not set si_addr in the siginfo_t correctly?

- Pat

#include <stdio.h>
#include <signal.h>

static void
signal_handler (int signo, struct siginfo *pinfo, void *puc)
{
fprintf (stderr, "si_addr == %p\n", pinfo->si_addr);

exit (0);
}

int
main ()
{
struct sigaction sa;

memset(&sa, 0, sizeof sa);
sa.sa_sigaction = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;

sigaction (SIGSEGV, &sa, NULL);

*(int *)32 = 0;

return 0;
}
\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.038 / U:2.516 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site