X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Flinux-os.c;h=c5d5485da316233b469d813095204f339d537f8c;hb=81cfdf526490d642c73602ebac9bcacb8af644e1;hp=8bcb7a841f873bc21a48c45c174ff3b3e65090d3;hpb=a530bbe337109d898d5b4a001fc8f1afa3b5dc39;p=sbcl.git diff --git a/src/runtime/linux-os.c b/src/runtime/linux-os.c index 8bcb7a8..c5d5485 100644 --- a/src/runtime/linux-os.c +++ b/src/runtime/linux-os.c @@ -1,5 +1,6 @@ /* - * the Linux incarnation of OS-dependent routines + * the Linux incarnation of OS-dependent routines. See also + * $(sbcl_arch)-linux-os.c * * This file (along with os.h) exports an OS-independent interface to * the operating system VM facilities. Surprise surprise, this @@ -19,10 +20,6 @@ * files for more information. */ -/* - * $Header$ - */ - #include #include #include @@ -31,6 +28,7 @@ #include "arch.h" #include "globals.h" #include "interrupt.h" +#include "interr.h" #include "lispregs.h" #include "sbcl.h" #include @@ -43,7 +41,7 @@ #include #include -#include "x86-validate.h" +#include "validate.h" size_t os_vm_page_size; #if defined GENCGC @@ -66,46 +64,15 @@ void os_init(void) } os_vm_page_size = getpagesize(); - + /* This could just as well be in arch_init(), but it's not. */ +#ifdef __i386__ SET_FPU_CONTROL_WORD(0x1372|4|8|16|32); /* no interrupts */ +#endif } -/* KLUDGE: As of kernel 2.2.14 on Red Hat 6.2, there's code in the - * file to define symbolic names for offsets into - * gregs[], but it's conditional on __USE_GNU and not defined, so - * we need to do this nasty absolute index magic number thing - * instead. */ -int * -os_context_register_addr(os_context_t *context, int offset) -{ - switch(offset) { - case 0: return &context->uc_mcontext.gregs[11]; /* EAX */ - case 2: return &context->uc_mcontext.gregs[10]; /* ECX */ - case 4: return &context->uc_mcontext.gregs[9]; /* EDX */ - case 6: return &context->uc_mcontext.gregs[8]; /* EBX */ - case 8: return &context->uc_mcontext.gregs[7]; /* ESP */ - case 10: return &context->uc_mcontext.gregs[6]; /* EBP */ - case 12: return &context->uc_mcontext.gregs[5]; /* ESI */ - case 14: return &context->uc_mcontext.gregs[4]; /* EDI */ - default: return 0; - } -} -int * -os_context_pc_addr(os_context_t *context) -{ - return &context->uc_mcontext.gregs[14]; -} -int * -os_context_sp_addr(os_context_t *context) -{ - return &context->uc_mcontext.gregs[17]; -} - -sigset_t * -os_context_sigmask_addr(os_context_t *context) -{ - return &context->uc_sigmask; -} +/* various os_context_*_addr accessors moved to {x86,alpha}-linux-os.c + * -dan 20010125 + */ /* In Debian CMU CL ca. 2.4.9, it was possible to get an infinite * cascade of errors from do_mmap(..). This variable is a counter to @@ -117,15 +84,15 @@ int n_do_mmap_ignorable_errors = 3; static int do_mmap(os_vm_address_t *addr, os_vm_size_t len, int flags) { - /* We *must* have the memory where we want it. */ - os_vm_address_t old_addr=*addr; + /* We *must* have the memory where we expect it. */ + os_vm_address_t old_addr = *addr; *addr = mmap(*addr, len, OS_VM_PROT_ALL, flags, -1, 0); if (*addr == MAP_FAILED || ((old_addr != NULL) && (*addr != old_addr))) { FSHOW((stderr, - "error in allocating memory from the OS\n" - "(addr=%lx, len=%lx, flags=%lx)\n", + "/retryable error in allocating memory from the OS\n" + "(addr=0x%lx, len=0x%lx, flags=0x%lx)\n", (long) addr, (long) len, (long) flags)); @@ -224,11 +191,6 @@ os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len) } void -os_flush_icache(os_vm_address_t address, os_vm_size_t length) -{ -} - -void os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot) { if (mprotect(address, length, prot) == -1) { @@ -236,11 +198,14 @@ os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot) } } +/* FIXME: Now that FOO_END, rather than FOO_SIZE, is the fundamental + * description of a space, we could probably punt this and just do + * (FOO_START <= x && x < FOO_END) everywhere it's called. */ static boolean in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen) { - char* beg = (char*)sbeg; - char* end = (char*)sbeg + slen; + char* beg = (char*)((long)sbeg); + char* end = (char*)((long)sbeg) + slen; char* adr = (char*)a; return (adr >= beg && adr < end); } @@ -251,8 +216,7 @@ 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_0_SPACE_START, DYNAMIC_SPACE_SIZE) || - in_range_p(addr, DYNAMIC_1_SPACE_START, DYNAMIC_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); } @@ -261,13 +225,7 @@ is_valid_lisp_addr(os_vm_address_t addr) * any OS-dependent special low-level handling for signals */ -#if !defined GENCGC - -void -os_install_interrupt_handlers(void) -{} - -#else +#if defined GENCGC /* * The GENCGC needs to be hooked into whatever signal is raised for @@ -282,10 +240,58 @@ sigsegv_handler(int signal, siginfo_t *info, void* void_context) interrupt_handle_now(signal, info, void_context); } } + +#else + +static void +sigsegv_handler(int signal, siginfo_t *info, void* void_context) +{ + os_context_t *context = (os_context_t*)void_context; + os_vm_address_t addr; + +#ifdef __i386__ + interrupt_handle_now(signal,contextstruct); +#else + char *control_stack_top = (char*)CONTROL_STACK_START + CONTROL_STACK_SIZE; + + addr = arch_get_bad_addr(signal,info,context); + + if(addr != NULL && + *os_context_register_addr(context,reg_ALLOC) & (1L<<63)){ + /* This is the end of a pseudo-atomic section during which + * a signal was received. We must deal with the pending interrupt + * (see also interrupt.c, ../code/interrupt.lisp) + */ + + /* (how we got here: when interrupting, we set bit 63 in + * reg_Alloc. At the end of the atomic section we tried to + * write to reg_Alloc, got a SIGSEGV (there's nothing mapped + * there) so ended up here + */ + *os_context_register_addr(context,reg_ALLOC) -= (1L<<63); + interrupt_handle_pending(context); + } else if (addr > control_stack_top && addr < BINDING_STACK_START) { + fprintf(stderr, + "Possible stack overflow at 0x%016lX:\n" + "control_stack_top=%lx, BINDING_STACK_START=%lx\n", + addr, + control_stack_top, + BINDING_STACK_START); + /* Try to fix control frame pointer. */ + while ( ! (CONTROL_STACK_START <= *current_control_frame_pointer && + *current_control_frame_pointer <= control_stack_top)) + ((char*)current_control_frame_pointer) -= sizeof(lispobj); + monitor_or_something(); + } else if (!interrupt_maybe_gc(signal, info, context)) { + interrupt_handle_now(signal, info, context); + } +#endif +} +#endif + void os_install_interrupt_handlers(void) { - interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler); + undoably_install_low_level_interrupt_handler(SIGSEGV, sigsegv_handler); } -#endif