X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fsunos-os.c;h=9278a72628ac7f8fb58e807dad2c602f4af5559f;hb=1de12891f900d156ed035a097561ecd7755a256a;hp=5aadf8c2a6c4e3d2bd60777eb8b3d2cca3a69143;hpb=686043635c45a16b418d2cc96a7f704fdab182c2;p=sbcl.git diff --git a/src/runtime/sunos-os.c b/src/runtime/sunos-os.c index 5aadf8c..9278a72 100644 --- a/src/runtime/sunos-os.c +++ b/src/runtime/sunos-os.c @@ -6,72 +6,124 @@ #include #include #include +#include +#include "sbcl.h" #include "os.h" #include "arch.h" #include "interr.h" #include "interrupt.h" #include "globals.h" #include "validate.h" -#include "sbcl.h" #include "target-arch-os.h" +#ifdef LISP_FEATURE_X86 +#include "genesis/static-symbols.h" +#include "genesis/fdefn.h" +#endif + +#ifdef LISP_FEATURE_GENCGC +#include "gencgc-internal.h" +#endif + +#if defined LISP_FEATURE_SPARC #define OS_VM_DEFAULT_PAGESIZE 8192 +#elif defined LISP_FEATURE_X86 +#define OS_VM_DEFAULT_PAGESIZE 4096 +#else +#error "Don't know OS_VM_DEFAULT_PAGESIZE" +#endif long os_vm_page_size=(-1); static long os_real_page_size=(-1); static os_vm_size_t real_page_size_difference=0; +/* So, this sucks. Versions of Solaris prior to 8 (SunOS releases + earlier than 5.8) do not support MAP_ANON passed as a flag to + mmap(). However, we would like SBCL compiled on SunOS 5.7 but + running on 5.8 to use MAP_ANON, but because of C's lack of + introspection at runtime, we can't grab the right value because + it's stuffed in a header file somewhere. We can, however, hardcode + it, and test at runtime for whether to use it... -- CSR, 2002-05-06 + + And, in fact, it sucks slightly more, as if you don't use MAP_ANON + you need to have /dev/zero open and pass the file descriptor to + mmap(). So overall, this counts as a KLUDGE. -- CSR, 2002-05-20 */ +int KLUDGE_MAYBE_MAP_ANON = 0x0; +int kludge_mmap_fd = -1; /* default for MAP_ANON */ + void -os_init(void) +os_init(char *argv[], char *envp[]) { + struct utsname name; + int major_version; + int minor_version; + + uname(&name); + major_version = atoi(name.release); + if (major_version != 5) { + lose("sunos major version=%d (which isn't 5!)\n", major_version); + } + minor_version = atoi(name.release+2); + if ((minor_version < 8)) { + kludge_mmap_fd = open("/dev/zero",O_RDONLY); + if (kludge_mmap_fd < 0) { + perror("open"); + lose("Error in open(..)\n"); + } + } else if (minor_version > 11) { + FSHOW((stderr, "os_init: Solaris version greater than 11?\nUnknown MAP_ANON behaviour.\n")); + lose("Unknown mmap() interaction with MAP_ANON\n"); + } else { + /* Versions 8-11*/ + KLUDGE_MAYBE_MAP_ANON = 0x100; + } + /* I do not understand this at all. FIXME. */ os_vm_page_size = os_real_page_size = sysconf(_SC_PAGESIZE); if(os_vm_page_size>OS_VM_DEFAULT_PAGESIZE){ - fprintf(stderr,"os_init: Pagesize too large (%d > %d)\n", - os_vm_page_size,OS_VM_DEFAULT_PAGESIZE); - exit(1); - }else{ - /* - * we do this because there are apparently dependencies on - * the pagesize being OS_VM_DEFAULT_PAGESIZE somewhere... - * but since the OS doesn't know we're using this restriction, - * we have to grovel around a bit to enforce it, thus anything - * that uses real_page_size_difference. - */ - /* FIXME: Is this still true? */ - real_page_size_difference=OS_VM_DEFAULT_PAGESIZE-os_vm_page_size; - os_vm_page_size=OS_VM_DEFAULT_PAGESIZE; + fprintf(stderr,"os_init: Pagesize too large (%d > %d)\n", + os_vm_page_size,OS_VM_DEFAULT_PAGESIZE); + exit(1); + } else { + /* + * we do this because there are apparently dependencies on + * the pagesize being OS_VM_DEFAULT_PAGESIZE somewhere... + * but since the OS doesn't know we're using this restriction, + * we have to grovel around a bit to enforce it, thus anything + * that uses real_page_size_difference. + */ + /* FIXME: Is this still true? */ + real_page_size_difference=OS_VM_DEFAULT_PAGESIZE-os_vm_page_size; + os_vm_page_size=OS_VM_DEFAULT_PAGESIZE; } } -os_vm_address_t -os_validate(os_vm_address_t addr, os_vm_size_t len) +os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len) { - int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANON; - - if (addr) - flags |= MAP_FIXED; - - addr = mmap(addr, len, - OS_VM_PROT_ALL, - flags, - -1, 0); + int flags = MAP_PRIVATE | MAP_NORESERVE | KLUDGE_MAYBE_MAP_ANON; + if (addr) + flags |= MAP_FIXED; + + addr = mmap(addr, len, + OS_VM_PROT_ALL, + flags, + kludge_mmap_fd, 0); + if (addr == MAP_FAILED) { - perror("mmap"); - lose ("Error in mmap(..)"); + perror("mmap"); + lose ("Error in mmap(..)\n"); } - + return addr; } -void -os_invalidate(os_vm_address_t addr, os_vm_size_t len) +void os_invalidate(os_vm_address_t addr, os_vm_size_t len) { if(munmap((void*) addr, len) == -1) - perror("munmap"); + perror("munmap"); } @@ -81,15 +133,15 @@ os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len) { addr = mmap(addr, len, - OS_VM_PROT_ALL, - MAP_PRIVATE | MAP_FIXED, - fd, (off_t) offset); + OS_VM_PROT_ALL, + MAP_PRIVATE | MAP_FIXED, + fd, (off_t) offset); if (addr == MAP_FAILED) { - perror("mmap"); - lose("Unexpedted mmap(..) failure"); + perror("mmap"); + lose("Unexpedted mmap(..) failure\n"); } - + return addr; } @@ -97,12 +149,11 @@ void os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot) { if(mprotect((void*)address, length, prot) == -1) { - perror("mprotect"); + perror("mprotect"); } } -static boolean -in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen) +static boolean in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen) { char* beg = (char*) sbeg; char* end = (char*) sbeg + slen; @@ -110,24 +161,56 @@ in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen) return (adr >= beg && adr < end); } -boolean -is_valid_lisp_addr(os_vm_address_t addr) +boolean is_valid_lisp_addr(os_vm_address_t addr) { - /* Just assume address is valid if it lies within one of the known + /* Old CMUCL comment: + + Just assume address is valid if it lies within one of the known spaces. (Unlike sunos-os which keeps track of every valid page.) */ - 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, CONTROL_STACK_START , CONTROL_STACK_SIZE ) - || in_range_p(addr, BINDING_STACK_START , BINDING_STACK_SIZE )); -} + /* FIXME: this looks like a valid definition for all targets with + cheney-gc; it may not be impressively smart (witness the + comment above) but maybe associating these functions with the + GC rather than the OS would be a maintainability win. -- CSR, + 2003-04-04 */ + 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) || +#ifdef LISP_FEATURE_GENCGC + in_range_p(addr, DYNAMIC_SPACE_START , dynamic_space_size) +#else + in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size) || + in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size) +#endif + ) + 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; +} -#if defined GENCGC +#if defined LISP_FEATURE_GENCGC -#error "GENCGC is not yet supported (presumably on x86 solaris?)" +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*)info->si_addr; + + 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)); +#else + interrupt_handle_now(signal, info, context); +#endif +} #else @@ -138,10 +221,9 @@ sigsegv_handler(int signal, siginfo_t *info, void* void_context) os_vm_address_t addr; addr = arch_get_bad_addr(signal, info, context); - /* There's some complicated recovery code in linux-os.c here - that I'm currently too confused to understand. Fixme. */ if(!interrupt_maybe_gc(signal, info, context)) { - interrupt_handle_now(signal, info, context); + if(!handle_guard_page_triggered(context,addr)) + interrupt_handle_now(signal, info, context); } } @@ -150,5 +232,27 @@ sigsegv_handler(int signal, siginfo_t *info, void* void_context) void os_install_interrupt_handlers() { - undoably_install_low_level_interrupt_handler(SIGSEGV,sigsegv_handler); + undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT, + sigsegv_handler); + +#ifdef LISP_FEATURE_SB_THREAD + undoably_install_low_level_interrupt_handler(SIG_INTERRUPT_THREAD, + interrupt_thread_handler); + undoably_install_low_level_interrupt_handler(SIG_STOP_FOR_GC, + sig_stop_for_gc_handler); +#endif +} + +char * +os_get_runtime_executable_path() +{ + int ret; + char path[] = "/proc/self/object/a.out"; + + ret = access(path, R_OK); + if (ret == -1) + return NULL; + + return copied_string(path); } +