/[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.7 - (show annotations)
Tue Sep 16 08:52:31 2008 UTC (5 years, 7 months ago) by cshapiro
Branch: MAIN
CVS Tags: sse2-packed-2008-11-12, sse2-base, sse2-packed-base, snapshot-2008-11, merge-sse2-packed, snapshot-2008-10, sse2-checkpoint-2008-10-01, sse2-merge-with-2008-11, sse2-merge-with-2008-10
Branch point for: sse2-packed-branch, sse2-branch
Changes since 1.6: +2 -16 lines
File MIME type: text/plain
Move the gencgc write barrier code into its own function.
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.7 2008/09/16 08:52:31 cshapiro 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 #define DPRINTF(t,a) {if (t) fprintf a;}
39
40 #if defined GENCGC
41 #include "gencgc.h"
42 #endif
43
44
45 void
46 os_init(void)
47 {
48 os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
49 }
50
51 int *
52 sc_reg(struct sigcontext *c, int offset)
53 {
54 switch (offset) {
55 case 0:
56 return &c->sc_eax;
57 case 2:
58 return &c->sc_ecx;
59 case 4:
60 return &c->sc_edx;
61 case 6:
62 return &c->sc_ebx;
63 case 8:
64 return &c->sc_esp;
65 case 10:
66 return &c->sc_ebp;
67 case 12:
68 return &c->sc_esi;
69 case 14:
70 return &c->sc_edi;
71 }
72 return (int *) 0;
73 }
74
75 os_vm_address_t
76 os_validate(os_vm_address_t addr, os_vm_size_t len)
77 {
78 int flags = MAP_PRIVATE | MAP_ANON;
79
80 if (addr)
81 flags |= MAP_FIXED;
82
83 DPRINTF(0, (stderr, "os_validate %x %d => ", addr, len));
84
85 addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
86
87 if (addr == (os_vm_address_t) - 1) {
88 perror("mmap");
89 return NULL;
90 }
91
92 DPRINTF(0, (stderr, "%x\n", addr));
93
94 return addr;
95 }
96
97 void
98 os_invalidate(os_vm_address_t addr, os_vm_size_t len)
99 {
100 DPRINTF(0, (stderr, "os_invalidate %x %d\n", addr, len));
101
102 if (munmap(addr, len) == -1)
103 perror("munmap");
104 }
105
106 os_vm_address_t
107 os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
108 {
109 addr = mmap(addr, len,
110 OS_VM_PROT_ALL,
111 MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, (off_t) offset);
112
113 if (addr == (os_vm_address_t) - 1)
114 perror("mmap");
115
116 return addr;
117 }
118
119 void
120 os_flush_icache(os_vm_address_t address, os_vm_size_t length)
121 {
122 }
123
124 void
125 os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
126 {
127 if (mprotect(address, length, prot) == -1)
128 perror("mprotect");
129 }
130
131
132
133 static boolean
134 in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
135 {
136 char *beg = (char *) sbeg;
137 char *end = (char *) sbeg + slen;
138 char *adr = (char *) a;
139
140 return (adr >= beg && adr < end);
141 }
142
143 boolean
144 valid_addr(os_vm_address_t addr)
145 {
146 int ret;
147 os_vm_address_t newaddr;
148
149 newaddr = os_trunc_to_page(addr);
150
151 if (in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)
152 || in_range_p(addr, STATIC_SPACE_START, STATIC_SPACE_SIZE)
153 || in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size)
154 || in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size)
155 || in_range_p(addr, CONTROL_STACK_START, CONTROL_STACK_SIZE)
156 || in_range_p(addr, BINDING_STACK_START, BINDING_STACK_SIZE))
157 return TRUE;
158 return FALSE;
159 }
160
161
162 static void
163 sigsegv_handler(HANDLER_ARGS)
164 {
165 #if defined GENCGC
166 caddr_t fault_addr = code->si_addr;
167
168 #if SIGSEGV_VERBOSE
169 fprintf(stderr, "Signal %d, fault_addr=%x, page_index=%d:\n",
170 signal, fault_addr, page_index);
171 #endif
172
173 if (gc_write_barrier(code->si_addr))
174 return;
175 #endif
176
177 SAVE_CONTEXT();
178
179 DPRINTF(0, (stderr, "sigsegv:\n"));
180 interrupt_handle_now(signal, code, context);
181 }
182
183 static void
184 sigbus_handler(HANDLER_ARGS)
185 {
186 SAVE_CONTEXT();
187
188 DPRINTF(0, (stderr, "sigbus:\n"));
189 interrupt_handle_now(signal, code, context);
190 }
191
192 void
193 os_install_interrupt_handlers(void)
194 {
195 interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
196 interrupt_install_low_level_handler(SIGBUS, sigbus_handler);
197 }

  ViewVC Help
Powered by ViewVC 1.1.5