EXC_BAD_ACCESS instead of SIGSEGV?
EXC_BAD_ACCESS instead of SIGSEGV?
- Subject: EXC_BAD_ACCESS instead of SIGSEGV?
- From: Simon Gray <email@hidden>
- Date: Thu, 6 Nov 2003 13:08:36 +0000
Good morning all,
I wonder whether someone could point me in the right direction for this
problem.
I'm working with the GNU libsigsegv library
(
http://sourceforge.net/projects/libsigsegv/) as I'm doing some
investigative work on page-mapping in Mac OSX 10.3 and I've run into a
problem:
The basic configure script tests signal handling via the code below but
no longer works in 10.3 as
a GDB trace shows that an EXC_BAD_ACCESS is generated instead of
SIGSEGV in the
function "crasher()",
and it doesn't seem possible to install a signal handler for
EXC_BAD_ACCESS (unsurprisingly, as its not a BSD signal).
Inexperienced as I am with Mach, I'm really not sure the best approach
to resolving this issue - any pointers?
best regards
Simon Gray
PS I would have attached the code below but it goes over the 8K limit :(
PPS i can just fit the primary code in below...
file: conftest.c
------------------------------------------------------------------------
------------------------------------------------------------------------
-----
#define PACKAGE_NAME ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PACKAGE_STRING ""
#define PACKAGE_BUGREPORT ""
#define PACKAGE "libsigsegv"
#define VERSION "2.1"
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_DLFCN_H 1
#define HAVE_SYS_SIGNAL_H 1
#define CFG_SIGNALS "signals-macos.h"
#define HAVE_UNISTD_H 1
#define HAVE_GETPAGESIZE 1
#define HAVE_SYSCONF_PAGESIZE 1
#define HAVE_MMAP_ANON 1
/* end confdefs.h. */
#include <stdlib.h>
#include <signal.h>
#if HAVE_SYS_SIGNAL_H
# include <sys/signal.h>
#endif
#include "./src/fault-macos-powerpc.c"
#include <sys/types.h>
#include <sys/mman.h>
#if HAVE_MMAP_DEVZERO
# include <fcntl.h>
# ifndef MAP_FILE
# define MAP_FILE 0
# endif
#endif
#ifndef PROT_NONE
# define PROT_NONE 0
#endif
#if HAVE_MMAP_ANON
# define zero_fd -1
# define map_flags MAP_ANON | MAP_PRIVATE
#elif HAVE_MMAP_ANONYMOUS
# define zero_fd -1
# define map_flags MAP_ANONYMOUS | MAP_PRIVATE
#elif HAVE_MMAP_DEVZERO
static int zero_fd;
# define map_flags MAP_FILE | MAP_PRIVATE
#endif
unsigned long page;
int handler_called = 0;
void sigsegv_handler (int sig, int code, struct sigcontext *scp)
{
void *fault_address = (void *) (get_fault_addr (scp));
handler_called++;
if (handler_called == 10)
exit (4);
if (fault_address != (void*)(page + 0x678))
exit (3);
if (mprotect ((void *) page, 0x10000, PROT_READ | PROT_WRITE) < 0)
exit (2);
}
void crasher (unsigned long p)
{
*(int *) (p + 0x678) = 42;
}
int main ()
{
void *p;
struct sigaction action;
/* Preparations. */
#if !HAVE_MMAP_ANON && !HAVE_MMAP_ANONYMOUS && HAVE_MMAP_DEVZERO
zero_fd = open ("/dev/zero", O_RDONLY, 0644);
#endif
/* Setup some mmaped memory. */
#ifdef __hpux
/* HP-UX 10 mmap() often fails when given a hint. So give the OS
complete
freedom about the address range. */
p = mmap ((void *) 0, 0x10000, PROT_READ | PROT_WRITE,
map_flags, zero_fd, 0);
#else
p = mmap ((void *) 0x12340000, 0x10000, PROT_READ | PROT_WRITE,
map_flags, zero_fd, 0);
#endif
if (p == (void *)(-1))
exit (2);
page = (unsigned long) p;
/* Make it read-only. */
if (mprotect ((void *) page, 0x10000, PROT_READ) < 0)
exit (2);
/* Install the SIGSEGV handler. */
sigemptyset(&action.sa_mask);
action.sa_handler = (void (*) (int)) &sigsegv_handler;
action.sa_flags = 0;
sigaction (EXC_BAD_ACCESS, &action, (struct sigaction *) NULL); /*
SRG - a quick check but too much to hope for ;-) */
sigaction (SIGSEGV, &action, (struct sigaction *) NULL);
sigaction (SIGBUS, &action, (struct sigaction *) NULL);
/* The first write access should invoke the handler and then
complete. */
crasher (page);
/* The second write access should not invoke the handler. */
crasher (page);
/* Check that the handler was called only once. */
if (handler_called != 1)
exit (1);
/* Test passed! */
return 0;
}
end
file--------------------------------------------------------------------
------------------------------------------------------------------------
--------
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.