1.0.20: release, will be tagged sbcl_1_0_20
[sbcl/eslaughter.git] / src / runtime / osf1-os.c
blobbaba3bfd9095862bad120a5137ff0714c446d620
1 /*
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
15 * more information.
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.
24 #include <stdio.h>
25 #include <sys/param.h>
26 #include <sys/file.h>
27 #include "sbcl.h"
28 #include "./signal.h"
29 #include "os.h"
30 #include "arch.h"
31 #include "globals.h"
32 #include "interrupt.h"
33 #include "interr.h"
34 #include "lispregs.h"
35 #include <sys/socket.h>
36 #include <sys/utsname.h>
37 #include <errno.h>
38 #include <sys/sysinfo.h>
39 #include <sys/proc.h>
40 #include <sys/mman.h>
41 #include <machine/hal_sysinfo.h>
43 #include <sys/types.h>
44 #include <signal.h>
45 #include <sys/time.h>
46 #include <sys/stat.h>
47 #include <unistd.h>
49 #include "validate.h"
50 size_t os_vm_page_size;
54 void
55 os_init(char *argv[], char *envp[])
57 os_vm_page_size = getpagesize();
61 os_vm_address_t
62 os_validate(os_vm_address_t addr, os_vm_size_t len)
64 int flags = MAP_PRIVATE|MAP_ANONYMOUS;
65 if (addr) flags |= MAP_FIXED;
66 else flags |= MAP_VARIABLE;
68 if((addr=mmap(addr,len,OS_VM_PROT_ALL,flags,-1,0)) == (os_vm_address_t) -1)
69 perror("mmap");
71 return addr;
74 void
75 os_invalidate(os_vm_address_t addr, os_vm_size_t len)
77 if (munmap(addr,len) == -1) {
78 perror("munmap");
82 os_vm_address_t
83 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
85 addr = mmap(addr, len,
86 OS_VM_PROT_ALL,
87 MAP_PRIVATE | MAP_FILE | MAP_FIXED,
88 fd, (off_t) offset);
90 if (addr == MAP_FAILED) {
91 perror("mmap");
92 lose("unexpected mmap(..) failure\n");
95 return addr;
98 void
99 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
101 if (mprotect(address, length, prot) == -1) {
102 perror("mprotect");
106 boolean
107 is_valid_lisp_addr(os_vm_address_t addr)
109 int ret;
110 os_vm_address_t newaddr;
111 newaddr=os_trunc_to_page(addr);
112 if((ret=mvalid(newaddr,newaddr-addr+4,OS_VM_PROT_ALL)) == 0)
113 return TRUE;
114 else if(errno==EINVAL)
115 perror("mvalid");
116 return FALSE;
120 * any OS-dependent special low-level handling for signals
124 static void
125 sigsegv_handler(int signal, siginfo_t *info, void* void_context)
127 os_context_t *context = arch_os_get_context(&void_context);
129 os_vm_address_t addr = arch_get_bad_addr(signal,info,context);
131 if (addr != NULL &&
132 *os_context_register_addr(context,reg_ALLOC) & (1L<<63)){
133 /* this is lifted from linux-os.c, so violates OOAO */
134 *os_context_register_addr(context,reg_ALLOC) -= (1L<<63);
135 interrupt_handle_pending(context);
136 } else if (!cheneygc_handle_wp_violation(context, addr)) {
137 if(!handle_guard_page_triggered(context,addr))
138 interrupt_handle_now(signal, info, context);
143 void
144 os_install_interrupt_handlers(void)
146 undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT,
147 sigsegv_handler);
150 char *
151 os_get_runtime_executable_path()
153 return NULL;