From 94725152ceb445d6af0823ffc8514a281393042e Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Sat, 23 May 2009 15:53:30 +0200 Subject: [PATCH] Fix Boehm-Weiser gc so that we can use our mprotect() mechanism for deferring signals together with B-W's memory protection and generational garbage collector. --- src/CHANGELOG | 7 +++++++ src/aclocal.m4 | 3 +++ src/c/alloc_2.d | 2 +- src/c/unixint.d | 20 ++++---------------- src/clos/conditions.lsp | 6 +++++- src/configure | 3 +++ src/gc/os_dep.c | 15 ++++++--------- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/CHANGELOG b/src/CHANGELOG index 98f034faa..3855bfc88 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -28,6 +28,13 @@ ECL 9.5: By default a correctable error is signaled and the user is given the chance to increase the heap size. + - Under Mac OS/X, ECL now uses its own modified version of the Boehm-Weiser + garbage collector that allows both --enable-gengc and our optimized + code for signal handling. + + - New condition EXT:SEGMENTATION-VIOLATION signaled by SIGSEGV and SIGBUS + events. + * Bugs fixed: - Remove an obsolete #if statement for Solaris that broke current builds diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 7dd05b951..9812e733f 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -324,6 +324,9 @@ case "${host_os}" in else export ABI=mode32 fi + # The Boehm-Weiser GC library shipped with Fink does not work + # well with our signal handler. + enable_boehm=included # ECL, due to some of the libraries, does not build on # 64 bit mode on OSX. We prevent GMP using that mode. SONAME="${SHAREDPREFIX}ecl.SOVERSION.${SHAREDEXT}" diff --git a/src/c/alloc_2.d b/src/c/alloc_2.d index 29f2017bf..7d116ac9f 100644 --- a/src/c/alloc_2.d +++ b/src/c/alloc_2.d @@ -417,7 +417,7 @@ init_alloc(void) GC_start_call_back = (void (*)())finalize_queued; GC_java_finalization = 1; GC_oom_fn = out_of_memory; - GC_set_warn_proc(no_warnings); + /*GC_set_warn_proc(no_warnings);*/ GC_enable(); } diff --git a/src/c/unixint.d b/src/c/unixint.d index 26863ad7c..c1f0c1646 100644 --- a/src/c/unixint.d +++ b/src/c/unixint.d @@ -256,23 +256,11 @@ handler_fn_protype(lisp_signal_handler, int sig, siginfo_t *info, void *aux) cl_error(1, condition); break; } - case SIGSEGV: { - ecl_frame_ptr destination = frs_sch(OBJNULL); - if (destination) { - the_env->nvalues = 0; - ecl_unwind(the_env, destination); - } - ecl_internal_error("SIGSEGV without handler to jump to."); - } + case SIGSEGV: + cl_error(1, @'ext::segmentation-violation'); #ifdef SIGBUS - case SIGBUS: { - ecl_frame_ptr destination = frs_sch(OBJNULL); - if (destination) { - the_env->nvalues = 0; - ecl_unwind(the_env, destination); - } - ecl_internal_error("SIGBUS without handler to jump to."); - } + case SIGBUS: + cl_error(1, @'ext::segmentation-violation'); #endif default: FEerror("Serious signal ~D caught.", 1, MAKE_FIXNUM(sig)); diff --git a/src/clos/conditions.lsp b/src/clos/conditions.lsp index 462ba571d..b05acadf3 100644 --- a/src/clos/conditions.lsp +++ b/src/clos/conditions.lsp @@ -538,7 +538,11 @@ returns with NIL." (define-condition storage-condition (serious-condition) ()) -(define-condition ext:segmentation-violation (storage-condition) ()) +(define-condition ext:segmentation-violation (storage-condition) + () + (:REPORT + (lambda (condition stream) + (format stream "Detected access to an invalid or protected memory address.")))) (define-condition ext:stack-overflow (storage-condition) ((size :initarg :size :initform 0 :reader ext:stack-overflow-size) diff --git a/src/configure b/src/configure index 6e0dda50a..2590d76fb 100755 --- a/src/configure +++ b/src/configure @@ -4459,6 +4459,9 @@ case "${host_os}" in else export ABI=mode32 fi + # The Boehm-Weiser GC library shipped with Fink does not work + # well with our signal handler. + enable_boehm=included # ECL, due to some of the libraries, does not build on # 64 bit mode on OSX. We prevent GMP using that mode. SONAME="${SHAREDPREFIX}ecl.SOVERSION.${SHAREDEXT}" diff --git a/src/gc/os_dep.c b/src/gc/os_dep.c index f40337565..b5c5d0c46 100644 --- a/src/gc/os_dep.c +++ b/src/gc/os_dep.c @@ -3808,16 +3808,13 @@ static kern_return_t GC_forward_exception(mach_port_t thread, mach_port_t task, behavior = GC_old_exc_ports.behaviors[i]; flavor = GC_old_exc_ports.flavors[i]; - if(behavior != EXCEPTION_DEFAULT) { + if (behavior == EXCEPTION_STATE || behavior == EXCEPTION_STATE_IDENTITY) { r = thread_get_state(thread, flavor, thread_state, &thread_state_count); if(r != KERN_SUCCESS) ABORT("thread_get_state failed in forward_exception"); - } + } switch(behavior) { - case EXCEPTION_DEFAULT: - r = exception_raise(port, thread, task, exception, data, data_count); - break; case EXCEPTION_STATE: r = exception_raise_state(port, thread, task, exception, data, data_count, &flavor, thread_state, thread_state_count, @@ -3829,13 +3826,13 @@ static kern_return_t GC_forward_exception(mach_port_t thread, mach_port_t task, thread_state_count, thread_state, &thread_state_count); break; - default: - r = KERN_FAILURE; /* make gcc happy */ - ABORT("forward_exception: unknown behavior"); + case EXCEPTION_DEFAULT: /* default signal handlers */ + default: /* user supplied signal handlers */ + r = exception_raise(port, thread, task, exception, data, data_count); break; } - if(behavior != EXCEPTION_DEFAULT) { + if (behavior == EXCEPTION_STATE || behavior == EXCEPTION_STATE_IDENTITY) { r = thread_set_state(thread, flavor, thread_state, thread_state_count); if(r != KERN_SUCCESS) ABORT("thread_set_state failed in forward_exception");