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

  ViewVC Help
Powered by ViewVC 1.1.5