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 /* While it is generally hard to recover from out-of-memory
55 * situations, we require callers to decide on the right course
56 * of action here. Consider thread creation: Failure to mmap
57 * here is common if users have started too many threads, and
58 * often we can recover from that and treat it as an ordinary
66 void os_invalidate(os_vm_address_t addr, os_vm_size_t len)
68 if(munmap((void*) addr, len) == -1)
75 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
78 addr = mmap(addr, len,
80 MAP_PRIVATE | MAP_FIXED,
83 if (addr == MAP_FAILED) {
85 lose("Unexpedted mmap(..) failure\n");
92 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
94 if(mprotect((void*)address, length, prot) == -1) {
99 static boolean in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
101 char* beg = (char*) sbeg;
102 char* end = (char*) sbeg + slen;
103 char* adr = (char*) a;
104 return (adr >= beg && adr < end);
107 boolean is_valid_lisp_addr(os_vm_address_t addr)
109 /* Old CMUCL comment:
111 Just assume address is valid if it lies within one of the known
112 spaces. (Unlike sunos-os which keeps track of every valid page.) */
114 /* FIXME: this looks like a valid definition for all targets with
115 cheney-gc; it may not be impressively smart (witness the
116 comment above) but maybe associating these functions with the
117 GC rather than the OS would be a maintainability win. -- CSR,
120 if(in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) ||
121 in_range_p(addr, STATIC_SPACE_START , STATIC_SPACE_SIZE) ||
122 #ifdef LISP_FEATURE_GENCGC
123 in_range_p(addr, DYNAMIC_SPACE_START , dynamic_space_size)
125 in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size) ||
126 in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
130 for_each_thread(th) {
131 if((th->control_stack_start <= addr) && (addr < th->control_stack_end))
133 if(in_range_p(addr, th->binding_stack_start, BINDING_STACK_SIZE))
140 #if defined LISP_FEATURE_GENCGC
143 sigsegv_handler(int signal, siginfo_t *info, os_context_t *context)
145 void* fault_addr = (void*)info->si_addr;
147 #ifdef LISP_FEATURE_SB_SAFEPOINT
148 if (handle_safepoint_violation(context, fault_addr))
152 if (!gencgc_handle_wp_violation(fault_addr))
153 if(!handle_guard_page_triggered(context, fault_addr))
154 lisp_memory_fault_error(context, fault_addr);
160 sigsegv_handler(int signal, siginfo_t *info, os_context_t *context)
162 os_vm_address_t addr = arch_get_bad_addr(signal, info, context);
164 if (!cheneygc_handle_wp_violation(context, addr)) {
165 if (!handle_guard_page_triggered(context,addr))
166 lisp_memory_fault_error(context, addr);
173 os_install_interrupt_handlers()
175 undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT,
178 /* OAOOM c.f. linux-os.c.
179 * Should we have a reusable function gc_install_interrupt_handlers? */
180 #ifdef LISP_FEATURE_SB_THREAD
181 # ifdef LISP_FEATURE_SB_SAFEPOINT
182 # ifdef LISP_FEATURE_SB_THRUPTION
183 undoably_install_low_level_interrupt_handler(SIGPIPE, thruption_handler);
186 undoably_install_low_level_interrupt_handler(SIG_STOP_FOR_GC,
187 sig_stop_for_gc_handler);
193 os_get_runtime_executable_path(int external)
195 char path[] = "/proc/self/object/a.out";
197 if (external || access(path, R_OK) == -1)
200 return copied_string(path);