X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Flinux-os.c;h=669ae7cbf589df60d20f0cc0ac2534e598e0e418;hb=10adbe19b88bf9d4fe65ad67f6de0fd065af87ff;hp=ea2f1b07939960387b745abd944c3fba9790c2b1;hpb=2378b4fe567a8fea78b1e4915b9497d8c18ca92f;p=sbcl.git diff --git a/src/runtime/linux-os.c b/src/runtime/linux-os.c index ea2f1b0..669ae7c 100644 --- a/src/runtime/linux-os.c +++ b/src/runtime/linux-os.c @@ -28,10 +28,12 @@ #include "os.h" #include "arch.h" #include "globals.h" -#include "sbcl.h" #include "interrupt.h" #include "interr.h" #include "lispregs.h" +#include "runtime.h" +#include "genesis/static-symbols.h" +#include "genesis/fdefn.h" #include #include @@ -47,51 +49,63 @@ #include "thread.h" size_t os_vm_page_size; +#ifdef LISP_FEATURE_SB_THREAD +#include +#include + +/* values taken from the kernel's linux/futex.h. This header file + doesn't exist in userspace, which is our excuse for not grovelling + them automatically */ +#define FUTEX_WAIT (0) +#define FUTEX_WAKE (1) +#define FUTEX_FD (2) +#define FUTEX_REQUEUE (3) + +#define __NR_sys_futex __NR_futex + +_syscall4(int,sys_futex, + int *, futex, + int, op, + int, val, + struct timespec *, rel); +#endif + #include "gc.h" int linux_sparc_siginfo_bug = 0; +int linux_no_threads_p = 0; void os_init(void) { /* Conduct various version checks: do we have enough mmap(), is * this a sparc running 2.2, can we do threads? */ - { - struct utsname name; - int major_version; - int minor_version; - char *p; - uname(&name); - p=name.release; - major_version = atoi(p); - p=strchr(p,'.')+1; - minor_version = atoi(p); - if (major_version<2) { - lose("linux kernel version too old: major version=%d (can't run in version < 2.0.0)", - major_version); - } -#ifdef LISP_FEATURE_SB_THREAD - if ((major_version <2) || (major_version==2 && minor_version < 4)) { - lose("linux kernel 2.4 required for thread-enabled SBCL"); - } -#endif + int *futex=0; + struct utsname name; + int major_version; + int minor_version; + char *p; + uname(&name); + p=name.release; + major_version = atoi(p); + p=strchr(p,'.')+1; + minor_version = atoi(p); + if (major_version<2) { + lose("linux kernel version too old: major version=%d (can't run in version < 2.0.0)", + major_version); + } + if (!(major_version>2 || minor_version >= 4)) { #ifdef LISP_FEATURE_SPARC - if ((major_version <2) || (major_version==2 && minor_version < 4)) { - FSHOW((stderr,"linux kernel %d.%d predates 2.4;\n enabling workarounds for SPARC kernel bugs in signal handling.\n", major_version,minor_version)); - linux_sparc_siginfo_bug = 1; - } + FSHOW((stderr,"linux kernel %d.%d predates 2.4;\n enabling workarounds for SPARC kernel bugs in signal handling.\n", major_version,minor_version)); + linux_sparc_siginfo_bug = 1; #endif } - - os_vm_page_size = getpagesize(); - /* This could just as well be in arch_init(), but it's not. */ -#ifdef __i386__ - /* FIXME: This used to be here. However, I have just removed it - with no apparent ill effects (it may be that earlier kernels - started up a process with a different set of traps, or - something?) Find out what this was meant to do, and reenable it - or delete it if possible. -- CSR, 2002-07-15 */ - /* SET_FPU_CONTROL_WORD(0x1372|4|8|16|32); no interrupts */ +#ifdef LISP_FEATURE_SB_THREAD + futex_wait(futex,-1); + if(errno==ENOSYS) linux_no_threads_p = 1; + if(linux_no_threads_p) + fprintf(stderr,"Linux with NPTL support (e.g. kernel 2.6 or newer) required for \nthread-enabled SBCL. Disabling thread support.\n\n"); #endif + os_vm_page_size = getpagesize(); } @@ -209,10 +223,14 @@ void sigsegv_handler(int signal, siginfo_t *info, void* void_context) { os_context_t *context = arch_os_get_context(&void_context); - void* fault_addr = (void*)context->uc_mcontext.cr2; + void* fault_addr = (void*)info->si_addr; if (!gencgc_handle_wp_violation(fault_addr)) - if(!handle_control_stack_guard_triggered(context,fault_addr)) - interrupt_handle_now(signal, info, void_context); + if(!handle_guard_page_triggered(context,fault_addr)) +#ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK + arrange_return_to_lisp_function(context, SymbolFunction(MEMORY_FAULT_ERROR)); +#else + interrupt_handle_now(signal, info, context); +#endif } #else @@ -241,7 +259,7 @@ sigsegv_handler(int signal, siginfo_t *info, void* void_context) interrupt_handle_pending(context); } else { if(!interrupt_maybe_gc(signal, info, context)) - if(!handle_control_stack_guard_triggered(context,addr)) + if(!handle_guard_page_triggered(context,addr)) interrupt_handle_now(signal, info, context); } } @@ -264,11 +282,20 @@ os_install_interrupt_handlers(void) sigsegv_handler); #ifdef LISP_FEATURE_SB_THREAD undoably_install_low_level_interrupt_handler(SIG_INTERRUPT_THREAD, - handle_rt_signal); + interrupt_thread_handler); undoably_install_low_level_interrupt_handler(SIG_STOP_FOR_GC, sig_stop_for_gc_handler); + undoably_install_low_level_interrupt_handler(SIG_THREAD_EXIT, + thread_exit_handler); #endif - undoably_install_low_level_interrupt_handler(SIGCONT, - sigcont_handler); } +#ifdef LISP_FEATURE_SB_THREAD +int futex_wait(int *lock_word, int oldval) { + int t= sys_futex(lock_word,FUTEX_WAIT,oldval, 0); + return t; +} +int futex_wake(int *lock_word, int n){ + return sys_futex(lock_word,FUTEX_WAKE,n,0); +} +#endif