/[cmucl]/src/lisp/OpenBSD-os.c
ViewVC logotype

Contents of /src/lisp/OpenBSD-os.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations)
Thu Sep 1 05:18:26 2011 UTC (2 years, 7 months ago) by rtoy
Branch: MAIN
CVS Tags: GIT-CONVERSION, snapshot-2011-09, HEAD
Changes since 1.10: +5 -1 lines
File MIME type: text/plain
Add os_init0 to allow for some really early OS inits.

On Linux, os_init can re-exec lisp to set up the correct personality.
Not normally a problem, but if any output happens before os_init is
called, the output appears to happen twice.  So add os_init0 to do
this early on, before any output.  This is a bit of a kludge.

lisp/lisp.c:
o Call os_init0 early in main.

lisp/Linux-os.c:
o Move the personality stuff from os_init to os_init0.

lisp/Darwin-os.c:
lisp/FreeBSD-os.c:
lisp/NetBSD-os.c:
lisp/OpenBSD-os.c:
lisp/hpux-os.c:
lisp/irix-os.c:
lisp/mach-os.c:
lisp/osf1-os.c:
lisp/solaris-os.c:
lisp/sunos-os.c:
o Add dummy implementation of os_init0.  These OSes don't (currently)
  need anything special.

lisp/os.h:
o Declare os_init0.
1 /*
2 * OpenBSD-os.c.
3 * From FreeBSD-os.c 1.6 2000/10/24 13:32:30 dtc Exp
4 *
5 * OS-dependent routines. This file (along with os.h) exports an
6 * OS-independent interface to the operating system VM facilities.
7 * Suprisingly, this interface looks a lot like the Mach interface
8 * (but simpler in some places). For some operating systems, a subset
9 * of these functions will have to be emulated.
10 *
11 * This is the OSF1 version. By Sean Hallgren.
12 * Much hacked by Paul Werkowski
13 * GENCGC support by Douglas Crosher, 1996, 1997.
14 * Frobbed for OpenBSD by Pierre R. Mai, 2001.
15 *
16 * $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/OpenBSD-os.c,v 1.11 2011/09/01 05:18:26 rtoy Exp $
17 *
18 */
19
20 #include <stdio.h>
21 #include <sys/param.h>
22 #include <sys/file.h>
23 #include <errno.h>
24 #include "os.h"
25 #include "arch.h"
26 #include "globals.h"
27 #include "interrupt.h"
28 #include "lispregs.h"
29 #include "internals.h"
30
31 #include <sys/types.h>
32 #include <signal.h>
33 /* #include <sys/sysinfo.h> */
34 #include <sys/proc.h>
35 #include "validate.h"
36 vm_size_t os_vm_page_size;
37
38 #if defined GENCGC
39 #include "gencgc.h"
40 #endif
41
42
43 void
44 os_init0(const char *argv[], const char *envp[])
45 {}
46
47 void
48 os_init(const char *argv[], const char *envp[])
49 {
50 os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
51 }
52
53 int *
54 sc_reg(struct sigcontext *c, int offset)
55 {
56 switch (offset) {
57 case 0:
58 return &c->sc_eax;
59 case 2:
60 return &c->sc_ecx;
61 case 4:
62 return &c->sc_edx;
63 case 6:
64 return &c->sc_ebx;
65 case 8:
66 return &c->sc_esp;
67 case 10:
68 return &c->sc_ebp;
69 case 12:
70 return &c->sc_esi;
71 case 14:
72 return &c->sc_edi;
73 }
74 return (int *) 0;
75 }
76
77 os_vm_address_t
78 os_validate(os_vm_address_t addr, os_vm_size_t len)
79 {
80 int flags = MAP_PRIVATE | MAP_ANON;
81
82 if (addr)
83 flags |= MAP_FIXED;
84
85 DPRINTF(0, (stderr, "os_validate %x %d => ", addr, len));
86
87 addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
88
89 if (addr == (os_vm_address_t) - 1) {
90 perror("mmap");
91 return NULL;
92 }
93
94 DPRINTF(0, (stderr, "%x\n", addr));
95
96 return addr;
97 }
98
99 void
100 os_invalidate(os_vm_address_t addr, os_vm_size_t len)
101 {
102 DPRINTF(0, (stderr, "os_invalidate %x %d\n", addr, len));
103
104 if (munmap(addr, len) == -1)
105 perror("munmap");
106 }
107
108 os_vm_address_t
109 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
110 {
111 addr = mmap(addr, len,
112 OS_VM_PROT_ALL,
113 MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, (off_t) offset);
114
115 if (addr == (os_vm_address_t) - 1)
116 perror("mmap");
117
118 return addr;
119 }
120
121 void
122 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
123 {
124 }
125
126 void
127 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
128 {
129 if (mprotect(address, length, prot) == -1)
130 perror("mprotect");
131 }
132
133
134
135 static boolean
136 in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
137 {
138 char *beg = (char *) sbeg;
139 char *end = (char *) sbeg + slen;
140 char *adr = (char *) a;
141
142 return (adr >= beg && adr < end);
143 }
144
145 boolean
146 valid_addr(os_vm_address_t addr)
147 {
148 int ret;
149 os_vm_address_t newaddr;
150
151 newaddr = os_trunc_to_page(addr);
152
153 if (in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)
154 || in_range_p(addr, STATIC_SPACE_START, STATIC_SPACE_SIZE)
155 || in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size)
156 || in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
157 || in_range_p(addr, CONTROL_STACK_START, CONTROL_STACK_SIZE)
158 || in_range_p(addr, BINDING_STACK_START, BINDING_STACK_SIZE))
159 return TRUE;
160 return FALSE;
161 }
162
163
164 static void
165 sigsegv_handler(HANDLER_ARGS)
166 {
167 #if defined GENCGC
168 caddr_t fault_addr = code->si_addr;
169
170 #if SIGSEGV_VERBOSE
171 fprintf(stderr, "Signal %d, fault_addr=%x, page_index=%d:\n",
172 signal, fault_addr, page_index);
173 #endif
174
175 if (gc_write_barrier(code->si_addr))
176 return;
177 #endif
178
179 SAVE_CONTEXT();
180
181 DPRINTF(0, (stderr, "sigsegv:\n"));
182 interrupt_handle_now(signal, code, context);
183 }
184
185 static void
186 sigbus_handler(HANDLER_ARGS)
187 {
188 SAVE_CONTEXT();
189
190 DPRINTF(0, (stderr, "sigbus:\n"));
191 interrupt_handle_now(signal, code, context);
192 }
193
194 void
195 os_install_interrupt_handlers(void)
196 {
197 interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
198 interrupt_install_low_level_handler(SIGBUS, sigbus_handler);
199 }

  ViewVC Help
Powered by ViewVC 1.1.5