/[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.6.6.1 - (hide annotations)
Sun Nov 2 13:30:03 2008 UTC (5 years, 5 months ago) by rtoy
Branch: unicode-utf16-extfmt-branch
Changes since 1.6: +2 -16 lines
File MIME type: text/plain
Sync to snapshot 2008-11.  But we didn't sync code/extfmts.lisp or
iso8859-1.lisp and utf-8.lisp.  (I don't think we want those changes,
yet.)
1 pmai 1.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 rtoy 1.6.6.1 * $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/OpenBSD-os.c,v 1.6.6.1 2008/11/02 13:30:03 rtoy Exp $
17 pmai 1.1 *
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 rtoy 1.2
44 pmai 1.1
45 rtoy 1.2 void
46     os_init(void)
47 pmai 1.1 {
48 rtoy 1.2 os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
49 pmai 1.1 }
50    
51 cshapiro 1.3 int *
52 rtoy 1.2 sc_reg(struct sigcontext *c, int offset)
53 pmai 1.1 {
54 rtoy 1.2 switch (offset) {
55     case 0:
56 cshapiro 1.3 return &c->sc_eax;
57 rtoy 1.2 case 2:
58 cshapiro 1.3 return &c->sc_ecx;
59 rtoy 1.2 case 4:
60 cshapiro 1.3 return &c->sc_edx;
61 rtoy 1.2 case 6:
62 cshapiro 1.3 return &c->sc_ebx;
63 rtoy 1.2 case 8:
64 cshapiro 1.3 return &c->sc_esp;
65 rtoy 1.2 case 10:
66 cshapiro 1.3 return &c->sc_ebp;
67 rtoy 1.2 case 12:
68 cshapiro 1.3 return &c->sc_esi;
69 rtoy 1.2 case 14:
70 cshapiro 1.3 return &c->sc_edi;
71 pmai 1.1 }
72 cshapiro 1.3 return (int *) 0;
73 pmai 1.1 }
74    
75 rtoy 1.2 os_vm_address_t
76     os_validate(os_vm_address_t addr, os_vm_size_t len)
77 pmai 1.1 {
78 cshapiro 1.4 int flags = MAP_PRIVATE | MAP_ANON;
79 pmai 1.1
80 rtoy 1.2 if (addr)
81     flags |= MAP_FIXED;
82 pmai 1.1
83 rtoy 1.2 DPRINTF(0, (stderr, "os_validate %x %d => ", addr, len));
84 pmai 1.1
85 rtoy 1.2 addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
86 pmai 1.1
87 rtoy 1.2 if (addr == (os_vm_address_t) - 1) {
88     perror("mmap");
89     return NULL;
90 pmai 1.1 }
91    
92 rtoy 1.2 DPRINTF(0, (stderr, "%x\n", addr));
93 pmai 1.1
94 rtoy 1.2 return addr;
95 pmai 1.1 }
96    
97 rtoy 1.2 void
98     os_invalidate(os_vm_address_t addr, os_vm_size_t len)
99 pmai 1.1 {
100 rtoy 1.2 DPRINTF(0, (stderr, "os_invalidate %x %d\n", addr, len));
101 pmai 1.1
102 rtoy 1.2 if (munmap(addr, len) == -1)
103     perror("munmap");
104 pmai 1.1 }
105    
106 rtoy 1.2 os_vm_address_t
107     os_map(int fd, int offset, os_vm_address_t addr, os_vm_size_t len)
108 pmai 1.1 {
109 rtoy 1.2 addr = mmap(addr, len,
110     OS_VM_PROT_ALL,
111     MAP_PRIVATE | MAP_FILE | MAP_FIXED, fd, (off_t) offset);
112 pmai 1.1
113 rtoy 1.2 if (addr == (os_vm_address_t) - 1)
114     perror("mmap");
115 pmai 1.1
116 rtoy 1.2 return addr;
117 pmai 1.1 }
118    
119 rtoy 1.2 void
120     os_flush_icache(os_vm_address_t address, os_vm_size_t length)
121 pmai 1.1 {
122     }
123    
124 rtoy 1.2 void
125     os_protect(os_vm_address_t address, os_vm_size_t length, os_vm_prot_t prot)
126 pmai 1.1 {
127 rtoy 1.2 if (mprotect(address, length, prot) == -1)
128     perror("mprotect");
129 pmai 1.1 }
130 rtoy 1.2
131 pmai 1.1
132    
133 rtoy 1.2 static boolean
134     in_range_p(os_vm_address_t a, lispobj sbeg, size_t slen)
135 pmai 1.1 {
136 rtoy 1.2 char *beg = (char *) sbeg;
137     char *end = (char *) sbeg + slen;
138     char *adr = (char *) a;
139    
140     return (adr >= beg && adr < end);
141 pmai 1.1 }
142    
143 rtoy 1.2 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 pmai 1.1
161 rtoy 1.2
162     static void
163     sigsegv_handler(HANDLER_ARGS)
164 pmai 1.1 {
165     #if defined GENCGC
166 rtoy 1.2 caddr_t fault_addr = code->si_addr;
167 pmai 1.1
168     #if SIGSEGV_VERBOSE
169 rtoy 1.2 fprintf(stderr, "Signal %d, fault_addr=%x, page_index=%d:\n",
170     signal, fault_addr, page_index);
171 pmai 1.1 #endif
172    
173 rtoy 1.6.6.1 if (gc_write_barrier(code->si_addr))
174 rtoy 1.2 return;
175 pmai 1.1 #endif
176    
177 rtoy 1.2 SAVE_CONTEXT();
178 pmai 1.1
179 rtoy 1.2 DPRINTF(0, (stderr, "sigsegv:\n"));
180     interrupt_handle_now(signal, code, context);
181 pmai 1.1 }
182    
183 rtoy 1.2 static void
184     sigbus_handler(HANDLER_ARGS)
185 pmai 1.1 {
186 rtoy 1.2 SAVE_CONTEXT();
187 pmai 1.1
188 rtoy 1.2 DPRINTF(0, (stderr, "sigbus:\n"));
189     interrupt_handle_now(signal, code, context);
190 pmai 1.1 }
191    
192 rtoy 1.2 void
193     os_install_interrupt_handlers(void)
194 pmai 1.1 {
195 rtoy 1.2 interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
196     interrupt_install_low_level_handler(SIGBUS, sigbus_handler);
197 pmai 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.5