9 #include <sys/utsname.h>
15 #include "interrupt.h"
18 #include "target-arch-os.h"
20 #ifdef LISP_FEATURE_X86
21 #include "genesis/static-symbols.h"
22 #include "genesis/fdefn.h"
25 #ifdef LISP_FEATURE_GENCGC
26 #include "gencgc-internal.h"
29 os_vm_size_t os_vm_page_size=0;
32 os_init(char *argv[], char *envp[])
35 * historically, this used sysconf to select the runtime page size
36 * per recent changes on other arches and discussion on sbcl-devel,
37 * however, this is not necessary -- the VM page size need not match
38 * the OS page size (and the default backend page size has been
39 * ramped up accordingly for efficiency reasons).
41 os_vm_page_size = BACKEND_PAGE_BYTES;
44 os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)
46 int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANON;
50 addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
52 if (addr == MAP_FAILED) {
54 lose ("Error in mmap(..)\n");
60 void os_invalidate(os_vm_address_t addr, os_vm_size_t len)
62 if(munmap((void*) addr, len) == -1)
69 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
72 addr = mmap(addr, len,
74 MAP_PRIVATE | MAP_FIXED,
77 if (addr == MAP_FAILED) {
79 lose("Unexpedted mmap(..) failure\n");
86 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
88 if(mprotect((void*)address, length, prot) == -1) {
93 static boolean in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
95 char* beg = (char*) sbeg;
96 char* end = (char*) sbeg + slen;
97 char* adr = (char*) a;
98 return (adr >= beg && adr < end);
101 boolean is_valid_lisp_addr(os_vm_address_t addr)
103 /* Old CMUCL comment:
105 Just assume address is valid if it lies within one of the known
106 spaces. (Unlike sunos-os which keeps track of every valid page.) */
108 /* FIXME: this looks like a valid definition for all targets with
109 cheney-gc; it may not be impressively smart (witness the
110 comment above) but maybe associating these functions with the
111 GC rather than the OS would be a maintainability win. -- CSR,
114 if(in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) ||
115 in_range_p(addr, STATIC_SPACE_START , STATIC_SPACE_SIZE) ||
116 #ifdef LISP_FEATURE_GENCGC
117 in_range_p(addr, DYNAMIC_SPACE_START , dynamic_space_size)
119 in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size) ||
120 in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
124 for_each_thread(th) {
125 if((th->control_stack_start <= addr) && (addr < th->control_stack_end))
127 if(in_range_p(addr, th->binding_stack_start, BINDING_STACK_SIZE))
134 #if defined LISP_FEATURE_GENCGC
137 sigsegv_handler(int signal, siginfo_t *info, os_context_t *context)
139 void* fault_addr = (void*)info->si_addr;
141 #ifdef LISP_FEATURE_SB_SAFEPOINT
142 if (handle_safepoint_violation(context, fault_addr))
146 if (!gencgc_handle_wp_violation(fault_addr))
147 if(!handle_guard_page_triggered(context, fault_addr))
148 lisp_memory_fault_error(context, fault_addr);
154 sigsegv_handler(int signal, siginfo_t *info, os_context_t *context)
156 os_vm_address_t addr = arch_get_bad_addr(signal, info, context);
158 if (!cheneygc_handle_wp_violation(context, addr)) {
159 if (!handle_guard_page_triggered(context,addr))
160 lisp_memory_fault_error(context, addr);
167 os_install_interrupt_handlers()
169 undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT,
172 /* OAOOM c.f. linux-os.c.
173 * Should we have a reusable function gc_install_interrupt_handlers? */
174 #ifdef LISP_FEATURE_SB_THREAD
175 # ifdef LISP_FEATURE_SB_SAFEPOINT
176 # ifdef LISP_FEATURE_SB_THRUPTION
177 undoably_install_low_level_interrupt_handler(SIGPIPE, thruption_handler);
180 undoably_install_low_level_interrupt_handler(SIG_STOP_FOR_GC,
181 sig_stop_for_gc_handler);
187 os_get_runtime_executable_path(int external)
189 char path[] = "/proc/self/object/a.out";
191 if (external || access(path, R_OK) == -1)
194 return copied_string(path);