gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] Fwd: page fault address


From: Aurelien Chanudet
Subject: [Gcl-devel] Fwd: page fault address
Date: Sun, 23 May 2004 08:11:06 +0200

Below is a copy of a mail I sent to the darwin-development mailing list some time ago in order to understand how to set up the SGC mechanism on OS X.

Aurelien

Begin forwarded message:

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;
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]