3 * OS-dependent routines. This file (along with os.h) exports an
4 * OS-independent interface to the operating system VM facilities.
5 * Suprisingly, this interface looks a lot like the Mach interface
6 * (but simpler in some places). For some operating systems, a subset
7 * of these functions will have to be emulated.
9 * This is the OSF1 version. By Sean Hallgren.
19 #include "interrupt.h"
21 #include <sys/types.h>
22 #include <sys/sysinfo.h>
25 vm_size_t os_vm_page_size;
28 os_init0(const char *argv[], const char *envp[])
32 os_init(const char *argv[], const char *envp[])
34 int buf[2] = { SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT };
37 os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
38 if (setsysinfo(SSI_NVPAIRS, buf, 1, NULL, NULL) == -1)
42 os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)
44 int flags = MAP_PRIVATE | MAP_ANONYMOUS;
49 flags |= MAP_VARIABLE;
51 if ((addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0)) ==
52 (os_vm_address_t) - 1)
59 os_invalidate(os_vm_address_t addr, os_vm_size_t len)
61 if (munmap(addr, len) == -1)
66 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
70 mmap(addr, len, OS_VM_PROT_ALL, MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd,
71 (off_t) offset)) == (os_vm_address_t) - 1)
78 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
83 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
85 if (mprotect(address, length, prot) == -1)
89 boolean valid_addr(os_vm_address_t addr)
92 os_vm_address_t newaddr;
94 newaddr = os_trunc_to_page(addr);
95 if ((ret = mvalid(newaddr, newaddr - addr + 4, OS_VM_PROT_ALL)) == 0)
97 else if (errno == EINVAL)
103 sigbus_handler(int signal, int code, struct sigcontext *context)
105 context->sc_pc -= 4; /* pc is +4 on bus error!?!!? */
106 if (arch_get_bad_addr(signal, code, context) &&
107 context->sc_regs[reg_ALLOC] & 2) {
108 context->sc_regs[reg_ALLOC] -= 2;
109 interrupt_handle_pending(context);
111 interrupt_handle_now(signal, code, context);
115 sigsegv_handler(int signal, int code, struct sigcontext *context)
117 if (!interrupt_maybe_gc(signal, code, context))
118 interrupt_handle_now(signal, code, context);
122 os_install_interrupt_handlers(void)
124 interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
125 interrupt_install_low_level_handler(SIGBUS, sigbus_handler);