2 * $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/osf1-os.c,v 1.7 2011/09/01 05:18:26 rtoy Exp $
4 * OS-dependent routines. This file (along with os.h) exports an
5 * OS-independent interface to the operating system VM facilities.
6 * Suprisingly, this interface looks a lot like the Mach interface
7 * (but simpler in some places). For some operating systems, a subset
8 * of these functions will have to be emulated.
10 * This is the OSF1 version. By Sean Hallgren.
20 #include "interrupt.h"
22 #include <sys/types.h>
23 #include <sys/sysinfo.h>
26 vm_size_t os_vm_page_size;
29 os_init0(const char *argv[], const char *envp[])
33 os_init(const char *argv[], const char *envp[])
35 int buf[2] = { SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT };
38 os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
39 if (setsysinfo(SSI_NVPAIRS, buf, 1, NULL, NULL) == -1)
43 os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)
45 int flags = MAP_PRIVATE | MAP_ANONYMOUS;
50 flags |= MAP_VARIABLE;
52 if ((addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0)) ==
53 (os_vm_address_t) - 1)
60 os_invalidate(os_vm_address_t addr, os_vm_size_t len)
62 if (munmap(addr, len) == -1)
67 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
71 mmap(addr, len, OS_VM_PROT_ALL, MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd,
72 (off_t) offset)) == (os_vm_address_t) - 1)
79 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
84 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
86 if (mprotect(address, length, prot) == -1)
90 boolean valid_addr(os_vm_address_t addr)
93 os_vm_address_t newaddr;
95 newaddr = os_trunc_to_page(addr);
96 if ((ret = mvalid(newaddr, newaddr - addr + 4, OS_VM_PROT_ALL)) == 0)
98 else if (errno == EINVAL)
104 sigbus_handler(int signal, int code, struct sigcontext *context)
106 context->sc_pc -= 4; /* pc is +4 on bus error!?!!? */
107 if (arch_get_bad_addr(signal, code, context) &&
108 context->sc_regs[reg_ALLOC] & 2) {
109 context->sc_regs[reg_ALLOC] -= 2;
110 interrupt_handle_pending(context);
112 interrupt_handle_now(signal, code, context);
116 sigsegv_handler(int signal, int code, struct sigcontext *context)
118 if (!interrupt_maybe_gc(signal, code, context))
119 interrupt_handle_now(signal, code, context);
123 os_install_interrupt_handlers(void)
125 interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
126 interrupt_install_low_level_handler(SIGBUS, sigbus_handler);