X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fsunos-os.c;h=4ed611d4c4c44a6429d168a73dfdaaa9dc515015;hb=94ac5b7c3ff37850210b6fc9a7593cf1c5752993;hp=dc58ee4e626c70c168ae2bbd7150c1497d9ed3e4;hpb=0d669e68a1ffbea42af6216f2ae8c7d7ca12ffb6;p=sbcl.git diff --git a/src/runtime/sunos-os.c b/src/runtime/sunos-os.c index dc58ee4..4ed611d 100644 --- a/src/runtime/sunos-os.c +++ b/src/runtime/sunos-os.c @@ -1,11 +1,12 @@ #include - +#include #include #include #include #include #include +#include #include "os.h" #include "arch.h" @@ -23,9 +24,45 @@ static long os_real_page_size=(-1); static os_vm_size_t real_page_size_difference=0; -void -os_init(void) +/* 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) { + 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!)", major_version); + } + minor_version = atoi(name.release+2); + if (minor_version == 8) { + KLUDGE_MAYBE_MAP_ANON = 0x100; + } else if (minor_version > 8) { + FSHOW((stderr, "os_init: Solaris version greater than 8?\nUnknown MAP_ANON behaviour.\n")); + lose("Unknown mmap() interaction with MAP_ANON"); + } else { /* minor_version < 8 */ + kludge_mmap_fd = open("/dev/zero",O_RDONLY); + if (kludge_mmap_fd < 0) { + perror("open"); + lose("Error in open(..)"); + } + } + /* I do not understand this at all. FIXME. */ os_vm_page_size = os_real_page_size = sysconf(_SC_PAGESIZE); @@ -33,7 +70,7 @@ os_init(void) fprintf(stderr,"os_init: Pagesize too large (%d > %d)\n", os_vm_page_size,OS_VM_DEFAULT_PAGESIZE); exit(1); - }else{ + } else { /* * we do this because there are apparently dependencies on * the pagesize being OS_VM_DEFAULT_PAGESIZE somewhere... @@ -47,18 +84,17 @@ os_init(void) } } -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; - + int flags = MAP_PRIVATE | MAP_NORESERVE | KLUDGE_MAYBE_MAP_ANON; if (addr) flags |= MAP_FIXED; - + addr = mmap(addr, len, OS_VM_PROT_ALL, flags, - -1, 0); + kludge_mmap_fd, 0); + if (addr == MAP_FAILED) { perror("mmap"); lose ("Error in mmap(..)"); @@ -67,8 +103,7 @@ os_validate(os_vm_address_t addr, os_vm_size_t len) 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"); @@ -76,7 +111,7 @@ os_invalidate(os_vm_address_t addr, os_vm_size_t len) -os_vm_address_t +os_vm_address_t os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len) { @@ -101,8 +136,7 @@ os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot) } } -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,10 +144,11 @@ 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 ) @@ -138,8 +173,8 @@ 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. */ + /* 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); }