9 #include <sys/utsname.h>
14 #include "interrupt.h"
18 #include "target-arch-os.h"
20 #define OS_VM_DEFAULT_PAGESIZE 8192
22 long os_vm_page_size=(-1);
23 static long os_real_page_size=(-1);
25 static os_vm_size_t real_page_size_difference=0;
27 /* So, this sucks. Versions of Solaris prior to 8 (SunOS releases
28 earlier than 5.8) do not support MAP_ANON passed as a flag to
29 mmap(). However, we would like SBCL compiled on SunOS 5.7 but
30 running on 5.8 to use MAP_ANON, but because of C's lack of
31 introspection at runtime, we can't grab the right value because
32 it's stuffed in a header file somewhere. We can, however, hardcode
33 it, and test at runtime for whether to use it... -- CSR, 2002-05-06
35 And, in fact, it sucks slightly more, as if you don't use MAP_ANON
36 you need to have /dev/zero open and pass the file descriptor to
37 mmap(). So overall, this counts as a KLUDGE. -- CSR, 2002-05-20 */
38 int KLUDGE_MAYBE_MAP_ANON = 0x0;
39 int kludge_mmap_fd = -1; /* default for MAP_ANON */
48 major_version = atoi(name.release);
49 if (major_version != 5) {
50 lose("sunos major version=%d (which isn't 5!)", major_version);
52 minor_version = atoi(name.release+2);
53 if ((minor_version == 8) || (minor_version == 9)) {
54 KLUDGE_MAYBE_MAP_ANON = 0x100;
55 } else if (minor_version > 9) {
56 FSHOW((stderr, "os_init: Solaris version greater than 9?\nUnknown MAP_ANON behaviour.\n"));
57 lose("Unknown mmap() interaction with MAP_ANON");
58 } else { /* minor_version < 8 */
59 kludge_mmap_fd = open("/dev/zero",O_RDONLY);
60 if (kludge_mmap_fd < 0) {
62 lose("Error in open(..)");
66 /* I do not understand this at all. FIXME. */
67 os_vm_page_size = os_real_page_size = sysconf(_SC_PAGESIZE);
69 if(os_vm_page_size>OS_VM_DEFAULT_PAGESIZE){
70 fprintf(stderr,"os_init: Pagesize too large (%d > %d)\n",
71 os_vm_page_size,OS_VM_DEFAULT_PAGESIZE);
75 * we do this because there are apparently dependencies on
76 * the pagesize being OS_VM_DEFAULT_PAGESIZE somewhere...
77 * but since the OS doesn't know we're using this restriction,
78 * we have to grovel around a bit to enforce it, thus anything
79 * that uses real_page_size_difference.
81 /* FIXME: Is this still true? */
82 real_page_size_difference=OS_VM_DEFAULT_PAGESIZE-os_vm_page_size;
83 os_vm_page_size=OS_VM_DEFAULT_PAGESIZE;
87 os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)
89 int flags = MAP_PRIVATE | MAP_NORESERVE | KLUDGE_MAYBE_MAP_ANON;
93 addr = mmap(addr, len,
98 if (addr == MAP_FAILED) {
100 lose ("Error in mmap(..)");
106 void os_invalidate(os_vm_address_t addr, os_vm_size_t len)
108 if(munmap((void*) addr, len) == -1)
115 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
118 addr = mmap(addr, len,
120 MAP_PRIVATE | MAP_FIXED,
123 if (addr == MAP_FAILED) {
125 lose("Unexpedted mmap(..) failure");
132 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
134 if(mprotect((void*)address, length, prot) == -1) {
139 static boolean in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
141 char* beg = (char*) sbeg;
142 char* end = (char*) sbeg + slen;
143 char* adr = (char*) a;
144 return (adr >= beg && adr < end);
147 boolean is_valid_lisp_addr(os_vm_address_t addr)
149 /* Old CMUCL comment:
151 Just assume address is valid if it lies within one of the known
152 spaces. (Unlike sunos-os which keeps track of every valid page.) */
154 /* FIXME: this looks like a valid definition for all targets with
155 cheney-gc; it may not be impressively smart (witness the
156 comment above) but maybe associating these functions with the
157 GC rather than the OS would be a maintainability win. -- CSR,
160 if(in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE) ||
161 in_range_p(addr, STATIC_SPACE_START , STATIC_SPACE_SIZE) ||
162 in_range_p(addr, DYNAMIC_0_SPACE_START, DYNAMIC_SPACE_SIZE) ||
163 in_range_p(addr, DYNAMIC_1_SPACE_START, DYNAMIC_SPACE_SIZE))
165 for_each_thread(th) {
166 if((th->control_stack_start <= addr) && (addr < th->control_stack_end))
168 if(in_range_p(addr, th->binding_stack_start, BINDING_STACK_SIZE))
177 sigsegv_handler(int signal, siginfo_t *info, void* void_context)
179 os_context_t *context = arch_os_get_context(&void_context);
180 os_vm_address_t addr;
182 addr = arch_get_bad_addr(signal, info, context);
183 if(!interrupt_maybe_gc(signal, info, context)) {
184 if(!handle_control_stack_guard_triggered(context,addr))
185 interrupt_handle_now(signal, info, context);
190 os_install_interrupt_handlers()
192 undoably_install_low_level_interrupt_handler(SIG_MEMORY_FAULT,