2 * This file (along with os.h) exports an OS-independent interface to
3 * the operating system VM facilities. Surprise surprise, this
4 * interface looks a lot like the Mach interface (but simpler in some
5 * places). For some operating systems, a subset of these functions
6 * will have to be emulated.
8 * This is the OSF/1 version, based on the Linux version, itself based
9 * on the OSF1 version from CMUCL by Sean Hallgren. Now _there's_
10 * a metacircularity for you ...
14 * This software is part of the SBCL system. See the README file for
17 * This software is derived from the CMU CL system, which was
18 * written at Carnegie Mellon University and released into the
19 * public domain. The software is in the public domain and is
20 * provided with absolutely no warranty. See the COPYING and CREDITS
21 * files for more information.
25 #include <sys/param.h>
31 #include "interrupt.h"
35 #include <sys/socket.h>
36 #include <sys/utsname.h>
38 #include <sys/sysinfo.h>
41 #include <machine/hal_sysinfo.h>
43 #include <sys/types.h>
50 size_t os_vm_page_size;
60 os_vm_page_size = getpagesize();
66 os_validate(os_vm_address_t addr, os_vm_size_t len)
68 int flags = MAP_PRIVATE|MAP_ANONYMOUS;
69 if (addr) flags |= MAP_FIXED;
70 else flags |= MAP_VARIABLE;
72 if((addr=mmap(addr,len,OS_VM_PROT_ALL,flags,-1,0)) == (os_vm_address_t) -1)
79 os_invalidate(os_vm_address_t addr, os_vm_size_t len)
81 if (munmap(addr,len) == -1) {
87 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
89 addr = mmap(addr, len,
91 MAP_PRIVATE | MAP_FILE | MAP_FIXED,
94 if (addr == MAP_FAILED) {
96 lose("unexpected mmap(..) failure");
103 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
105 if (mprotect(address, length, prot) == -1) {
111 is_valid_lisp_addr(os_vm_address_t addr)
114 os_vm_address_t newaddr;
115 newaddr=os_trunc_to_page(addr);
116 if((ret=mvalid(newaddr,newaddr-addr+4,OS_VM_PROT_ALL)) == 0)
118 else if(errno==EINVAL)
124 * any OS-dependent special low-level handling for signals
129 sigsegv_handler(int signal, siginfo_t *info, void* void_context)
131 os_context_t *context = arch_os_get_context(&void_context);
133 os_vm_address_t addr = arch_get_bad_addr(signal,info,context);
136 *os_context_register_addr(context,reg_ALLOC) & (1L<<63)){
137 /* this is lifted from linux-os.c, so violates OOAO */
138 *os_context_register_addr(context,reg_ALLOC) -= (1L<<63);
139 interrupt_handle_pending(context);
140 } else if(((addr>=DYNAMIC_0_SPACE_END) && (addr<DYNAMIC_1_SPACE_START)) ||
141 ((addr>=DYNAMIC_1_SPACE_END) && (addr<CONTROL_STACK_START))){
142 /* there's empty gap between these spaces. This clause needs
143 review if the spaces are ever juggled to make this untrue */
144 fprintf(stderr, "bad address 0x%p\n",addr);
145 lose("ran off end of dynamic space");
146 } else if (!interrupt_maybe_gc(signal, info, context)) {
147 interrupt_handle_now(signal, info, context);
153 os_install_interrupt_handlers(void)
155 undoably_install_low_level_interrupt_handler(SIGSEGV, sigsegv_handler);