X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fbsd-os.c;h=64aba2cd0a569f71d59b3fb0113af6780f9162f6;hb=a5b84ffa6a4599b958f4c856c39e55712ccb8cc2;hp=eaf6e10c7f06cff1c506e4a7e9c2c309c5c08b3f;hpb=68b13d8fac5207d339de227871818203f4cab0ab;p=sbcl.git diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c index eaf6e10..64aba2c 100644 --- a/src/runtime/bsd-os.c +++ b/src/runtime/bsd-os.c @@ -29,17 +29,14 @@ #include "interr.h" #include "lispregs.h" #include "sbcl.h" +#include "thread.h" #include #include /* #include */ -#include #include "validate.h" vm_size_t os_vm_page_size; -#if defined GENCGC -#include "gencgc.h" -#endif /* The different BSD variants have diverged in exactly where they * store signal context information, but at least they tend to use the @@ -193,26 +190,25 @@ in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen) boolean is_valid_lisp_addr(os_vm_address_t addr) { - return in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) - || in_range_p(addr, STATIC_SPACE_START , STATIC_SPACE_SIZE ) - || in_range_p(addr, DYNAMIC_SPACE_START , DYNAMIC_SPACE_SIZE ) - || in_range_p(addr, CONTROL_STACK_START , CONTROL_STACK_SIZE ) - || in_range_p(addr, BINDING_STACK_START , BINDING_STACK_SIZE ); + struct thread *th; + if(in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) || + in_range_p(addr, STATIC_SPACE_START , STATIC_SPACE_SIZE) || + in_range_p(addr, DYNAMIC_SPACE_START , DYNAMIC_SPACE_SIZE)) + return 1; + for_each_thread(th) { + if((th->control_stack_start <= addr) && (addr < th->control_stack_end)) + return 1; + if(in_range_p(addr, th->binding_stack_start, BINDING_STACK_SIZE)) + return 1; + } + return 0; } /* * any OS-dependent special low-level handling for signals */ -#if !defined GENCGC - -void -os_install_interrupt_handlers(void) -{ - SHOW("os_install_interrupt_handlers()/bsd-os/!defined(GENCGC)"); -} - -#else +#if defined LISP_FEATURE_GENCGC /* * The GENCGC needs to be hooked into whatever signal is raised for @@ -230,24 +226,55 @@ memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context) #else #error unsupported BSD variant #endif - if (!gencgc_handle_wp_violation(fault_addr)) { - interrupt_handle_now(signal, siginfo, void_context); - } + os_context_t *context = arch_os_get_context(&void_context); + if (!gencgc_handle_wp_violation(fault_addr)) + if(!handle_control_stack_guard_triggered(context,fault_addr)) + /* FIXME is this context or void_context? not that it */ + /* makes a difference currently except on linux/sparc */ + interrupt_handle_now(signal, siginfo, void_context); } void os_install_interrupt_handlers(void) { SHOW("os_install_interrupt_handlers()/bsd-os/defined(GENCGC)"); -#if defined __FreeBSD__ - undoably_install_low_level_interrupt_handler(SIGBUS, + undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT, memory_fault_handler); -#elif defined __OpenBSD__ - undoably_install_low_level_interrupt_handler(SIGSEGV, - memory_fault_handler); -#else -#error unsupported BSD variant -#endif SHOW("leaving os_install_interrupt_handlers()"); } -#endif /* !defined GENCGC */ +#else +/* As of 2002.07.31, this configuration has never been tested */ +void +os_install_interrupt_handlers(void) +{ + SHOW("os_install_interrupt_handlers()/bsd-os/!defined(GENCGC)"); +} + +#endif /* defined GENCGC */ + +/* threads */ + +/* no threading in any *BSD variant on any CPU (yet? in sbcl-0.8.0 anyway) */ +#ifdef LISP_FEATURE_SB_THREAD +#error "Define threading support functions" +#else +struct thread *arch_os_get_current_thread() { + return all_threads; +} +int arch_os_thread_init(struct thread *thread) { + stack_t sigstack; +#ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK + /* Signal handlers are run on the control stack, so if it is exhausted + * we had better use an alternate stack for whatever signal tells us + * we've exhausted it */ + sigstack.ss_sp=((void *) thread)+dynamic_values_bytes; + sigstack.ss_flags=0; + sigstack.ss_size = 32*SIGSTKSZ; + sigaltstack(&sigstack,0); +#endif + return 1; /* success */ +} +int arch_os_thread_cleanup(struct thread *thread) { + return 1; /* success */ +} +#endif