From: Matt Watson <address@hidden>
Date: September 5, 2003 11:29:37 CEST
To: Aurelien Chanudet <address@hidden>
Cc: address@hidden
Subject: Re: page fault address
I'm trying to write to an array whose memory protection disallows
writing. This gives a SIGBUS. How do I retrieve the page fault
address from within the signal handler ? (siginto_t.si_address just
gives the address of the offending instruction.)
si_addr not containing the faulting address for SIGBUS and SIGSEGV is
a bug in Darwin. You can work around it by looking at the dar field of
the exception state:
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/ucontext.h>
void handler (int sig, siginfo_t *info, void *scp)
{
ucontext_t *uc = (ucontext_t *)scp;
fprintf(stderr, "addr = 0x%08lx\n", uc->uc_mcontext->es.dar);
_exit(99);
}
int main(void)
{
struct sigaction sact;
int ret;
sigfillset(&(sact.sa_mask));
sact.sa_flags = SA_SIGINFO;
sact.sa_sigaction = (void (*)())handler;
ret = sigaction (SIGBUS, &sact, 0);
return *(int *)0x43;
}