X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fbsd-os.c;h=1b013969f35b1baeb3d11697ff5bd6f97f33f584;hb=0e6e1b2a81134f1b45330fd6abe49e32020e409d;hp=10c2fd439c283fbc9907f39205c481870a9406ec;hpb=402958f92506b9d3de852601b8c1ccb99b5ee558;p=sbcl.git diff --git a/src/runtime/bsd-os.c b/src/runtime/bsd-os.c index 10c2fd4..1b01396 100644 --- a/src/runtime/bsd-os.c +++ b/src/runtime/bsd-os.c @@ -41,6 +41,9 @@ #include /* #include */ #include "validate.h" +#if defined LISP_FEATURE_GENCGC +#include "gencgc-internal.h" +#endif os_vm_size_t os_vm_page_size; @@ -48,13 +51,14 @@ os_vm_size_t os_vm_page_size; #include #include #include - +#include /* For the stat-family wrappers. */ +#include /* For the opendir()/readdir() wrappers */ +#include /* For the socket() wrapper */ static void netbsd_init(); #endif /* __NetBSD__ */ #ifdef __FreeBSD__ #include -#include static void freebsd_init(); #endif /* __FreeBSD__ */ @@ -66,26 +70,8 @@ os_init(char *argv[], char *envp[]) #ifdef __NetBSD__ netbsd_init(); -#endif /* __NetBSD__ */ -#ifdef __FreeBSD__ +#elif defined(__FreeBSD__) freebsd_init(); -#endif /* __FreeBSD__ */ -} - -int *os_context_pc_addr(os_context_t *context) -{ -#if defined __FreeBSD__ - return CONTEXT_ADDR_FROM_STEM(eip); -#elif defined __OpenBSD__ - return CONTEXT_ADDR_FROM_STEM(pc); -#elif defined __NetBSD__ - return CONTEXT_ADDR_FROM_STEM(EIP); -#elif defined(LISP_FEATURE_DARWIN) && defined(LISP_FEATURE_X86) - return CONTEXT_ADDR_FROM_STEM(eip); -#elif defined LISP_FEATURE_DARWIN - return &context->uc_mcontext->ss.srr0; -#else -#error unsupported BSD variant #endif } @@ -168,12 +154,14 @@ is_valid_lisp_addr(os_vm_address_t addr) 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)) + 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)) + if(((os_vm_address_t)th->control_stack_start <= addr) && + (addr < (os_vm_address_t)th->control_stack_end)) return 1; - if(in_range_p(addr, th->binding_stack_start, BINDING_STACK_SIZE)) + if(in_range_p(addr, (lispobj)th->binding_stack_start, + BINDING_STACK_SIZE)) return 1; } return 0; @@ -189,11 +177,22 @@ is_valid_lisp_addr(os_vm_address_t addr) * The GENCGC needs to be hooked into whatever signal is raised for * page fault on this OS. */ -static void -memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context) + +void +memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context +#if defined(LISP_FEATURE_FREEBSD) && defined(LISP_FEATURE_X86_64) +/* FreeBSD/amd64 stores fault address only in undocumented 4th arg. */ + ,void *fault_addr +#endif + ) { os_context_t *context = arch_os_get_context(&void_context); +#if defined(LISP_FEATURE_FREEBSD) && defined(LISP_FEATURE_X86_64) + /* KLUDGE: Store fault address into si_addr for compatibilities. */ + siginfo->si_addr = fault_addr; +#else void *fault_addr = arch_get_bad_addr(signal, siginfo, context); +#endif #if defined(LISP_FEATURE_RESTORE_TLS_SEGMENT_REGISTER_FROM_CONTEXT) FSHOW_SIGNAL((stderr, "/ TLS: restoring fs: %p in memory_fault_handler\n", @@ -201,12 +200,12 @@ memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context) os_restore_tls_segment_register(context); #endif - FSHOW((stderr, "Memory fault at: %p, PC: %x\n", fault_addr, *os_context_pc_addr(context))); + FSHOW((stderr, "Memory fault at: %p, PC: %p\n", fault_addr, *os_context_pc_addr(context))); if (!gencgc_handle_wp_violation(fault_addr)) 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)); + lisp_memory_fault_error(context, fault_addr); #else if (!interrupt_maybe_gc_int(signal, siginfo, context)) { interrupt_handle_now(signal, siginfo, context); @@ -219,16 +218,34 @@ memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context) } } +#if defined(LISP_FEATURE_MACH_EXCEPTION_HANDLER) +void +mach_error_memory_fault_handler(int signal, siginfo_t *siginfo, void *void_context) { + lose("Unhandled memory fault. Exiting."); +} +#endif + void os_install_interrupt_handlers(void) { SHOW("os_install_interrupt_handlers()/bsd-os/defined(GENCGC)"); +#if defined(LISP_FEATURE_MACH_EXCEPTION_HANDLER) + undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT, + mach_error_memory_fault_handler); +#else undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT, +#ifdef LISP_FEATURE_FREEBSD + (__siginfohandler_t *) +#endif memory_fault_handler); #ifdef SIG_MEMORY_FAULT2 undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT2, +#ifdef LISP_FEATURE_FREEBSD + (__siginfohandler_t *) +#endif memory_fault_handler); #endif +#endif #ifdef LISP_FEATURE_SB_THREAD undoably_install_low_level_interrupt_handler(SIG_INTERRUPT_THREAD, @@ -240,7 +257,6 @@ os_install_interrupt_handlers(void) sig_stop_for_gc_handler); #endif #endif - SHOW("leaving os_install_interrupt_handlers()"); } @@ -311,6 +327,45 @@ The system may fail to start.\n", strerror(errno)); } } + +/* Various routines in NetBSD's C library are compatibility wrappers + for old versions. Programs must be processed by the C toolchain in + order to get up-to-date definitions of such routines. */ +/* The stat-family, opendir, and readdir are used only in sb-posix, as + of 2007-01-16. -- RMK */ +int +_stat(const char *path, struct stat *sb) +{ + return stat(path, sb); +} +int +_lstat(const char *path, struct stat *sb) +{ + return lstat(path, sb); +} +int +_fstat(int fd, struct stat *sb) +{ + return fstat(fd, sb); +} + +DIR * +_opendir(const char *filename) +{ + return opendir(filename); +} +struct dirent * +_readdir(DIR *dirp) +{ + return readdir(dirp); +} + +/* Used in sb-bsd-sockets. */ +int +_socket(int domain, int type, int protocol) +{ + return socket(domain, type, protocol); +} #endif /* __NetBSD__ */ #ifdef __FreeBSD__ @@ -343,6 +398,8 @@ static void freebsd_init() #define KERN_PROC_PATHNAME 12 #endif +extern int getosreldate(void); + char * os_get_runtime_executable_path() { @@ -370,7 +427,20 @@ os_get_runtime_executable_path() return NULL; return copied_string(path); } -#else /* Not DARWIN or FREEBSD */ +#elif defined(LISP_FEATURE_NETBSD) +char * +os_get_runtime_executable_path() +{ + struct stat sb; + char *path = strdup("/proc/curproc/file"); + if (path && ((stat(path, &sb)) == 0)) + return path; + else { + fprintf(stderr, "Couldn't stat /proc/curproc/file; is /proc mounted?\n"); + return NULL; + } +} +#else /* Not DARWIN or FREEBSD or NETBSD */ char * os_get_runtime_executable_path() {