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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.2.3 - (show annotations)
Tue Oct 24 13:33:55 2000 UTC (13 years, 5 months ago) by dtc
Branch: RELENG_18
CVS Tags: RELEASE_18c
Changes since 1.1.2.2: +3 -3 lines
File MIME type: text/plain
o Add the command line switch -dynamic-space-size for setting the size
  of the dynamic space. DYNAMIC_SPACE_SIZE now defines the maximum
  size, and when defined DEFAULT_DYNAMIC_SPACE_SIZE gives the default.

o Increase the maximum dynamic space size for Linux x86 to 1.625GB,
  with the default remaining at 512MB.

o Define the default dynamic space size for FreeBSD x86 to also be 512MB,
  with a maximum of 2GB.
1 /*
2 * FreeBSD-os.c. Maybe could be just BSD-os.c
3 * From osf1-os.c,v 1.1 94/03/27 15:30:51 hallgren 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 *
15 * $Header: /tiger/var/lib/cvsroots/cmucl/src/lisp/FreeBSD-os.c,v 1.1.2.3 2000/10/24 13:33:55 dtc Exp $
16 *
17 */
18
19 #include <stdio.h>
20 #include <sys/param.h>
21 #include <sys/file.h>
22 #include <errno.h>
23 #include "./signal.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 os_init(void)
46 {
47 os_vm_page_size = OS_VM_DEFAULT_PAGESIZE;
48 }
49
50 int sc_reg(struct sigcontext *c, int offset)
51 {
52 switch(offset)
53 {
54 case 0: return c->sc_eax;
55 case 2: return c->sc_ecx;
56 case 4: return c->sc_edx;
57 case 6: return c->sc_ebx;
58 case 8: return c->sc_esp;
59 case 10: return c->sc_ebp;
60 case 12: return c->sc_esi;
61 case 14: return c->sc_edi;
62 }
63 return 0;
64 }
65
66 void os_save_context(void)
67 {
68 /*
69 * Called from interrupt handlers so C stuff knows things set in Lisp.
70 */
71 }
72
73 void os_set_context(void)
74 {
75 }
76
77 os_vm_address_t os_validate(os_vm_address_t addr, os_vm_size_t len)
78 {
79 int flags = MAP_PRIVATE | MAP_ANONYMOUS;
80
81 if (addr)
82 flags |= MAP_FIXED;
83 else
84 flags |= MAP_VARIABLE;
85
86 DPRINTF(0, (stderr, "os_validate %x %d => ", addr, len));
87
88 addr = mmap(addr, len, OS_VM_PROT_ALL, flags, -1, 0);
89
90 if (addr == (os_vm_address_t) -1)
91 {
92 perror("mmap");
93 return NULL;
94 }
95
96 DPRINTF(0, (stderr, "%x\n", addr));
97
98 return addr;
99 }
100
101 void os_invalidate(os_vm_address_t addr, os_vm_size_t len)
102 {
103 DPRINTF(0, (stderr, "os_invalidate %x %d\n", addr, len));
104
105 if (munmap(addr, len) == -1)
106 perror("munmap");
107 }
108
109 os_vm_address_t os_map(int fd, int offset, os_vm_address_t addr,
110 os_vm_size_t len)
111 {
112 addr = mmap(addr, len,
113 OS_VM_PROT_ALL,
114 MAP_PRIVATE | MAP_FILE | MAP_FIXED,
115 fd, (off_t) offset);
116
117 if (addr == (os_vm_address_t) -1)
118 perror("mmap");
119
120 return addr;
121 }
122
123 void os_flush_icache(os_vm_address_t address, os_vm_size_t length)
124 {
125 }
126
127 void os_protect(os_vm_address_t address, os_vm_size_t length,
128 os_vm_prot_t prot)
129 {
130 if (mprotect(address, length, prot) == -1)
131 perror("mprotect");
132 }
133
134
135
136 static boolean 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 return (adr >= beg && adr < end);
142 }
143
144 boolean valid_addr(os_vm_address_t addr)
145 {
146 int ret;
147 os_vm_address_t newaddr;
148 newaddr = os_trunc_to_page(addr);
149
150 if ( in_range_p(addr, READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE)
151 || in_range_p(addr, STATIC_SPACE_START , STATIC_SPACE_SIZE )
152 || in_range_p(addr, DYNAMIC_0_SPACE_START, dynamic_space_size )
153 || in_range_p(addr, DYNAMIC_1_SPACE_START, dynamic_space_size )
154 || in_range_p(addr, CONTROL_STACK_START , CONTROL_STACK_SIZE )
155 || in_range_p(addr, BINDING_STACK_START , BINDING_STACK_SIZE ))
156 return TRUE;
157 return FALSE;
158 }
159
160
161 static void sigbus_handler(int signal, int code, struct sigcontext *context,
162 void *fault_addr)
163 {
164 #if defined GENCGC
165 int page_index = find_page_index(fault_addr);
166
167 #if SIGBUS_VERBOSE
168 fprintf(stderr,"Signal %d, fault_addr=%x, page_index=%d:\n",
169 signal, fault_addr, page_index);
170 #endif
171
172 /* Check if the fault is within the dynamic space. */
173 if (page_index != -1) {
174 /* Un-protect the page */
175
176 /* The page should have been marked write protected */
177 if (!PAGE_WRITE_PROTECTED(page_index))
178 fprintf(stderr, "*** Sigbus in page not marked as write protected\n");
179
180 os_protect(page_address(page_index), 4096, OS_VM_PROT_ALL);
181 page_table[page_index].flags &= ~PAGE_WRITE_PROTECTED_MASK;
182 page_table[page_index].flags |= PAGE_WRITE_PROTECT_CLEARED_MASK;
183
184 return;
185 }
186 #endif
187
188 DPRINTF(0, (stderr, "sigbus:\n"));
189 interrupt_handle_now(signal, code, context);
190 }
191
192 static void sigsegv_handler(int signal, int code, struct sigcontext *context)
193 {
194 DPRINTF(0, (stderr, "os_sigsegv\n"));
195 interrupt_handle_now(signal, code, context);
196 }
197
198 void os_install_interrupt_handlers(void)
199 {
200 interrupt_install_low_level_handler(SIGSEGV, sigsegv_handler);
201 interrupt_install_low_level_handler(SIGBUS, sigbus_handler);
202 }

  ViewVC Help
Powered by ViewVC 1.1.5