Commit | Line | Data |
---|---|---|
155415a5 MV |
1 | /* |
2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers | |
3 | * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved. | |
4 | * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved. | |
5 | * Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved. | |
8cbb63c7 | 6 | * Copyright (c) 2000, 2001, 2002 Free Software Foundation |
155415a5 MV |
7 | * |
8 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | |
9 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | |
10 | * | |
11 | * Permission is hereby granted to use or copy this program | |
12 | * for any purpose, provided the above notices are retained on all copies. | |
13 | * Permission to modify the code and to distribute modified code is granted, | |
14 | * provided the above notices are retained, and a notice that the code was | |
15 | * modified is included with the above copyright notice. | |
16 | * | |
17 | */ | |
9500b5b9 | 18 | |
155415a5 | 19 | /* |
a3487916 | 20 | * Copied from gc5.2, files "os_dep.c", "gc_priv.h", "mark.c" and "gcconfig.h", |
9ec1e770 | 21 | * and modified for Guile by Marius Vollmer. |
155415a5 | 22 | */ |
9500b5b9 | 23 | |
2485c279 RB |
24 | #if HAVE_CONFIG_H |
25 | # include <config.h> | |
26 | #endif | |
27 | ||
155415a5 MV |
28 | #include <ctype.h> |
29 | #include "libguile/gc.h" | |
8cbb63c7 MV |
30 | #include "libguile/scmconfig.h" |
31 | ||
32 | #ifdef HAVE_LIBC_STACK_END | |
33 | ||
34 | extern void *__libc_stack_end; | |
35 | ||
36 | void * | |
37 | scm_get_stack_base () | |
38 | { | |
39 | return __libc_stack_end; | |
40 | } | |
41 | ||
42 | #else | |
155415a5 MV |
43 | |
44 | #define ABORT(msg) abort () | |
45 | ||
46 | typedef char * ptr_t; /* A generic pointer to which we can add */ | |
47 | /* byte displacements. */ | |
48 | /* Preferably identical to caddr_t, if it */ | |
49 | /* exists. */ | |
50 | ||
51 | /* Define word and signed_word to be unsigned and signed types of the */ | |
52 | /* size as char * or void *. There seems to be no way to do this */ | |
53 | /* even semi-portably. The following is probably no better/worse */ | |
54 | /* than almost anything else. */ | |
55 | /* The ANSI standard suggests that size_t and ptr_diff_t might be */ | |
56 | /* better choices. But those appear to have incorrect definitions */ | |
57 | /* on may systems. Notably "typedef int size_t" seems to be both */ | |
58 | /* frequent and WRONG. */ | |
59 | typedef unsigned long GC_word; | |
60 | typedef long GC_signed_word; | |
61 | ||
62 | typedef GC_word word; | |
63 | typedef GC_signed_word signed_word; | |
64 | ||
a3487916 MV |
65 | typedef int GC_bool; |
66 | # define TRUE 1 | |
67 | # define FALSE 0 | |
68 | ||
69 | #if defined(__STDC__) | |
70 | # include <stdlib.h> | |
71 | # if !(defined( sony_news ) ) | |
72 | # include <stddef.h> | |
73 | # endif | |
74 | # define VOLATILE volatile | |
75 | #else | |
76 | # ifdef MSWIN32 | |
77 | # include <stdlib.h> | |
78 | # endif | |
79 | # define VOLATILE | |
80 | #endif | |
81 | ||
155415a5 MV |
82 | /* Machine dependent parameters. Some tuning parameters can be found */ |
83 | /* near the top of gc_private.h. */ | |
84 | ||
85 | /* Machine specific parts contributed by various people. See README file. */ | |
86 | ||
87 | /* First a unified test for Linux: */ | |
88 | # if defined(linux) || defined(__linux__) | |
89 | # define LINUX | |
90 | # endif | |
91 | ||
92 | /* Determine the machine type: */ | |
93 | # if defined(sun) && defined(mc68000) | |
94 | # define M68K | |
95 | # define SUNOS4 | |
96 | # define mach_type_known | |
97 | # endif | |
98 | # if defined(hp9000s300) | |
99 | # define M68K | |
100 | # define HP | |
101 | # define mach_type_known | |
102 | # endif | |
103 | # if defined(__OpenBSD__) && defined(m68k) | |
104 | # define M68K | |
105 | # define OPENBSD | |
106 | # define mach_type_known | |
107 | # endif | |
108 | # if defined(__OpenBSD__) && defined(__sparc__) | |
109 | # define SPARC | |
110 | # define OPENBSD | |
111 | # define mach_type_known | |
112 | # endif | |
9534300a RB |
113 | # if defined(__NetBSD__) && defined(__powerpc__) |
114 | # define POWERPC | |
115 | # define NETBSD | |
116 | # define mach_type_known | |
117 | # endif | |
155415a5 MV |
118 | # if defined(__NetBSD__) && defined(m68k) |
119 | # define M68K | |
120 | # define NETBSD | |
121 | # define mach_type_known | |
122 | # endif | |
123 | # if defined(__NetBSD__) && defined(arm32) | |
124 | # define ARM32 | |
125 | # define NETBSD | |
126 | # define mach_type_known | |
127 | # endif | |
598b6787 MV |
128 | # if defined(__NetBSD__) && defined(__sparc__) |
129 | # define SPARC | |
130 | # define NETBSD | |
131 | # define mach_type_known | |
132 | # endif | |
155415a5 MV |
133 | # if defined(vax) |
134 | # define VAX | |
135 | # ifdef ultrix | |
136 | # define ULTRIX | |
137 | # else | |
138 | # define BSD | |
139 | # endif | |
140 | # define mach_type_known | |
141 | # endif | |
142 | # if defined(mips) || defined(__mips) | |
143 | # define MIPS | |
144 | # if !defined(LINUX) | |
145 | # if defined(ultrix) || defined(__ultrix) || defined(__NetBSD__) | |
146 | # define ULTRIX | |
147 | # else | |
148 | # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \ | |
149 | || defined(__SYSTYPE_SVR4__) | |
150 | # define IRIX5 /* or IRIX 6.X */ | |
151 | # else | |
152 | # define RISCOS /* or IRIX 4.X */ | |
153 | # endif | |
154 | # endif | |
155 | # endif /* !LINUX */ | |
156 | # define mach_type_known | |
157 | # endif | |
158 | # if defined(sequent) && defined(i386) | |
159 | # define I386 | |
160 | # define SEQUENT | |
161 | # define mach_type_known | |
162 | # endif | |
163 | # if defined(sun) && defined(i386) | |
164 | # define I386 | |
165 | # define SUNOS5 | |
166 | # define mach_type_known | |
167 | # endif | |
168 | # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__) | |
169 | # define I386 | |
170 | # define OS2 | |
171 | # define mach_type_known | |
172 | # endif | |
173 | # if defined(ibm032) | |
174 | # define RT | |
175 | # define mach_type_known | |
176 | # endif | |
177 | # if defined(sun) && (defined(sparc) || defined(__sparc)) | |
178 | # define SPARC | |
179 | /* Test for SunOS 5.x */ | |
180 | # include <errno.h> | |
181 | # ifdef ECHRNG | |
182 | # define SUNOS5 | |
183 | # else | |
184 | # define SUNOS4 | |
185 | # endif | |
186 | # define mach_type_known | |
187 | # endif | |
188 | # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \ | |
189 | && !defined(__OpenBSD__) | |
190 | # define SPARC | |
191 | # define DRSNX | |
192 | # define mach_type_known | |
193 | # endif | |
194 | # if defined(_IBMR2) | |
195 | # define RS6000 | |
196 | # define mach_type_known | |
197 | # endif | |
198 | # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386) | |
199 | /* The above test may need refinement */ | |
200 | # define I386 | |
201 | # if defined(_SCO_ELF) | |
202 | # define SCO_ELF | |
203 | # else | |
204 | # define SCO | |
205 | # endif | |
206 | # define mach_type_known | |
207 | # endif | |
208 | # if defined(_AUX_SOURCE) | |
209 | # define M68K | |
210 | # define SYSV | |
211 | # define mach_type_known | |
212 | # endif | |
213 | # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \ | |
214 | || defined(hppa) || defined(__hppa__) | |
215 | # define HP_PA | |
216 | # ifndef LINUX | |
217 | # define HPUX | |
218 | # endif | |
219 | # define mach_type_known | |
220 | # endif | |
221 | # if defined(LINUX) && (defined(i386) || defined(__i386__)) | |
222 | # define I386 | |
223 | # define mach_type_known | |
224 | # endif | |
225 | # if defined(LINUX) && (defined(__ia64__) || defined(__ia64)) | |
226 | # define IA64 | |
227 | # define mach_type_known | |
228 | # endif | |
229 | # if defined(LINUX) && defined(powerpc) | |
230 | # define POWERPC | |
231 | # define mach_type_known | |
232 | # endif | |
233 | # if defined(LINUX) && defined(__mc68000__) | |
234 | # define M68K | |
235 | # define mach_type_known | |
236 | # endif | |
237 | # if defined(LINUX) && (defined(sparc) || defined(__sparc__)) | |
238 | # define SPARC | |
239 | # define mach_type_known | |
240 | # endif | |
311daf8b | 241 | # if defined(LINUX) && (defined(arm) || defined (__arm__)) |
155415a5 MV |
242 | # define ARM32 |
243 | # define mach_type_known | |
244 | # endif | |
245 | # if defined(__alpha) || defined(__alpha__) | |
246 | # define ALPHA | |
247 | # if !defined(LINUX) | |
248 | # define OSF1 /* a.k.a Digital Unix */ | |
249 | # endif | |
250 | # define mach_type_known | |
251 | # endif | |
252 | # if defined(_AMIGA) && !defined(AMIGA) | |
253 | # define AMIGA | |
254 | # endif | |
9ec1e770 | 255 | # ifdef AMIGA |
155415a5 MV |
256 | # define M68K |
257 | # define mach_type_known | |
258 | # endif | |
259 | # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc) | |
260 | # define M68K | |
261 | # define MACOS | |
262 | # define mach_type_known | |
263 | # endif | |
264 | # if defined(__MWERKS__) && defined(__powerc) | |
265 | # define POWERPC | |
266 | # define MACOS | |
267 | # define mach_type_known | |
268 | # endif | |
269 | # if defined(macosx) | |
270 | # define MACOSX | |
271 | # define POWERPC | |
272 | # define mach_type_known | |
273 | # endif | |
274 | # if defined(NeXT) && defined(mc68000) | |
275 | # define M68K | |
276 | # define NEXT | |
277 | # define mach_type_known | |
278 | # endif | |
279 | # if defined(NeXT) && defined(i386) | |
280 | # define I386 | |
281 | # define NEXT | |
282 | # define mach_type_known | |
283 | # endif | |
37354cb7 | 284 | # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__)) |
155415a5 MV |
285 | # define I386 |
286 | # define OPENBSD | |
287 | # define mach_type_known | |
288 | # endif | |
289 | # if defined(__FreeBSD__) && defined(i386) | |
290 | # define I386 | |
291 | # define FREEBSD | |
292 | # define mach_type_known | |
293 | # endif | |
294 | # if defined(__NetBSD__) && defined(i386) | |
295 | # define I386 | |
296 | # define NETBSD | |
297 | # define mach_type_known | |
298 | # endif | |
299 | # if defined(bsdi) && defined(i386) | |
300 | # define I386 | |
301 | # define BSDI | |
302 | # define mach_type_known | |
303 | # endif | |
304 | # if !defined(mach_type_known) && defined(__386BSD__) | |
305 | # define I386 | |
306 | # define THREE86BSD | |
307 | # define mach_type_known | |
308 | # endif | |
309 | # if defined(_CX_UX) && defined(_M88K) | |
310 | # define M88K | |
311 | # define CX_UX | |
312 | # define mach_type_known | |
313 | # endif | |
314 | # if defined(DGUX) | |
315 | # define M88K | |
316 | /* DGUX defined */ | |
317 | # define mach_type_known | |
318 | # endif | |
319 | # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \ | |
320 | || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__) | |
321 | # define I386 | |
322 | # define MSWIN32 /* or Win32s */ | |
323 | # define mach_type_known | |
324 | # endif | |
325 | # if defined(__DJGPP__) | |
326 | # define I386 | |
327 | # ifndef DJGPP | |
328 | # define DJGPP /* MSDOS running the DJGPP port of GCC */ | |
329 | # endif | |
330 | # define mach_type_known | |
331 | # endif | |
332 | # if defined(__CYGWIN32__) || defined(__CYGWIN__) | |
333 | # define I386 | |
334 | # define CYGWIN32 | |
335 | # define mach_type_known | |
336 | # endif | |
337 | # if defined(__MINGW32__) | |
338 | # define I386 | |
339 | # define MSWIN32 | |
340 | # define mach_type_known | |
341 | # endif | |
342 | # if defined(__BORLANDC__) | |
343 | # define I386 | |
344 | # define MSWIN32 | |
345 | # define mach_type_known | |
346 | # endif | |
347 | # if defined(_UTS) && !defined(mach_type_known) | |
348 | # define S370 | |
349 | # define UTS4 | |
350 | # define mach_type_known | |
351 | # endif | |
352 | # if defined(__pj__) | |
353 | # define PJ | |
354 | # define mach_type_known | |
355 | # endif | |
356 | /* Ivan Demakov */ | |
357 | # if defined(__WATCOMC__) && defined(__386__) | |
358 | # define I386 | |
359 | # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW) | |
360 | # if defined(__OS2__) | |
361 | # define OS2 | |
362 | # else | |
363 | # if defined(__WINDOWS_386__) || defined(__NT__) | |
364 | # define MSWIN32 | |
365 | # else | |
366 | # define DOS4GW | |
367 | # endif | |
368 | # endif | |
369 | # endif | |
370 | # define mach_type_known | |
371 | # endif | |
9c52b218 RB |
372 | # if defined(__GNU__) |
373 | # define I386 | |
374 | # define GNU | |
375 | # define mach_type_known | |
376 | # endif | |
f55a171d RB |
377 | # if defined(__SCO_VERSION__) |
378 | # define I386 | |
379 | # define SYSV | |
380 | # define mach_type_known | |
381 | # endif | |
155415a5 MV |
382 | |
383 | /* Feel free to add more clauses here */ | |
384 | ||
385 | /* Or manually define the machine type here. A machine type is */ | |
386 | /* characterized by the architecture. Some */ | |
387 | /* machine types are further subdivided by OS. */ | |
388 | /* the macros ULTRIX, RISCOS, and BSD to distinguish. */ | |
389 | /* Note that SGI IRIX is treated identically to RISCOS. */ | |
390 | /* SYSV on an M68K actually means A/UX. */ | |
391 | /* The distinction in these cases is usually the stack starting address */ | |
392 | # ifndef mach_type_known | |
393 | --> unknown machine type | |
394 | # endif | |
395 | /* Mapping is: M68K ==> Motorola 680X0 */ | |
396 | /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */ | |
397 | /* MACOS and AMIGA variants) */ | |
398 | /* I386 ==> Intel 386 */ | |
399 | /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */ | |
400 | /* FREEBSD, THREE86BSD, MSWIN32, */ | |
401 | /* BSDI,SUNOS5, NEXT, other variants) */ | |
402 | /* NS32K ==> Encore Multimax */ | |
403 | /* MIPS ==> R2000 or R3000 */ | |
404 | /* (RISCOS, ULTRIX variants) */ | |
405 | /* VAX ==> DEC VAX */ | |
406 | /* (BSD, ULTRIX variants) */ | |
407 | /* RS6000 ==> IBM RS/6000 AIX3.X */ | |
408 | /* RT ==> IBM PC/RT */ | |
409 | /* HP_PA ==> HP9000/700 & /800 */ | |
410 | /* HP/UX */ | |
411 | /* SPARC ==> SPARC under SunOS */ | |
412 | /* (SUNOS4, SUNOS5, */ | |
413 | /* DRSNX variants) */ | |
414 | /* ALPHA ==> DEC Alpha */ | |
415 | /* (OSF1 and LINUX variants) */ | |
416 | /* M88K ==> Motorola 88XX0 */ | |
417 | /* (CX_UX and DGUX) */ | |
418 | /* S370 ==> 370-like machine */ | |
419 | /* running Amdahl UTS4 */ | |
420 | /* ARM32 ==> Intel StrongARM */ | |
421 | /* IA64 ==> Intel IA64 */ | |
422 | /* (e.g. Itanium) */ | |
423 | ||
424 | ||
425 | /* | |
426 | * For each architecture and OS, the following need to be defined: | |
427 | * | |
428 | * CPP_WORD_SZ is a simple integer constant representing the word size. | |
429 | * in bits. We assume byte addressibility, where a byte has 8 bits. | |
430 | * We also assume CPP_WORD_SZ is either 32 or 64. | |
431 | * (We care about the length of pointers, not hardware | |
432 | * bus widths. Thus a 64 bit processor with a C compiler that uses | |
433 | * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.) | |
434 | * | |
435 | * MACH_TYPE is a string representation of the machine type. | |
436 | * OS_TYPE is analogous for the OS. | |
437 | * | |
438 | * ALIGNMENT is the largest N, such that | |
439 | * all pointer are guaranteed to be aligned on N byte boundaries. | |
440 | * defining it to be 1 will always work, but perform poorly. | |
441 | * | |
442 | * DATASTART is the beginning of the data segment. | |
443 | * On UNIX systems, the collector will scan the area between DATASTART | |
444 | * and DATAEND for root pointers. | |
445 | * | |
446 | * DATAEND, if not &end. | |
447 | * | |
448 | * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice | |
449 | * the pointer size. | |
450 | * | |
451 | * STACKBOTTOM is the cool end of the stack, which is usually the | |
452 | * highest address in the stack. | |
453 | * Under PCR or OS/2, we have other ways of finding thread stacks. | |
454 | * For each machine, the following should: | |
2485c279 | 455 | * 1) define SCM_STACK_GROWS_UP if the stack grows toward higher addresses, and |
155415a5 MV |
456 | * 2) define exactly one of |
457 | * STACKBOTTOM (should be defined to be an expression) | |
458 | * HEURISTIC1 | |
459 | * HEURISTIC2 | |
460 | * If either of the last two macros are defined, then STACKBOTTOM is computed | |
461 | * during collector startup using one of the following two heuristics: | |
462 | * HEURISTIC1: Take an address inside GC_init's frame, and round it up to | |
463 | * the next multiple of STACK_GRAN. | |
464 | * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly | |
2485c279 | 465 | * in small steps (decrement if SCM_STACK_GROWS_UP), and read the value |
155415a5 MV |
466 | * at each location. Remember the value when the first |
467 | * Segmentation violation or Bus error is signalled. Round that | |
468 | * to the nearest plausible page boundary, and use that instead | |
469 | * of STACKBOTTOM. | |
470 | * | |
471 | * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines, | |
472 | * the value of environ is a pointer that can serve as STACKBOTTOM. | |
473 | * I expect that HEURISTIC2 can be replaced by this approach, which | |
9ec1e770 | 474 | * interferes far less with debugging. |
155415a5 MV |
475 | * |
476 | * If no expression for STACKBOTTOM can be found, and neither of the above | |
477 | * heuristics are usable, the collector can still be used with all of the above | |
478 | * undefined, provided one of the following is done: | |
479 | * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s) | |
480 | * without reference to STACKBOTTOM. This is appropriate for use in | |
481 | * conjunction with thread packages, since there will be multiple stacks. | |
482 | * (Allocating thread stacks in the heap, and treating them as ordinary | |
483 | * heap data objects is also possible as a last resort. However, this is | |
484 | * likely to introduce significant amounts of excess storage retention | |
485 | * unless the dead parts of the thread stacks are periodically cleared.) | |
486 | * 2) Client code may set GC_stackbottom before calling any GC_ routines. | |
487 | * If the author of the client code controls the main program, this is | |
488 | * easily accomplished by introducing a new main program, setting | |
489 | * GC_stackbottom to the address of a local variable, and then calling | |
490 | * the original main program. The new main program would read something | |
491 | * like: | |
492 | * | |
493 | * # include "gc_private.h" | |
494 | * | |
495 | * main(argc, argv, envp) | |
496 | * int argc; | |
497 | * char **argv, **envp; | |
498 | * { | |
499 | * int dummy; | |
500 | * | |
501 | * GC_stackbottom = (ptr_t)(&dummy); | |
502 | * return(real_main(argc, argv, envp)); | |
503 | * } | |
504 | * | |
505 | * | |
506 | * Each architecture may also define the style of virtual dirty bit | |
507 | * implementation to be used: | |
508 | * MPROTECT_VDB: Write protect the heap and catch faults. | |
509 | * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits. | |
510 | * | |
511 | * An architecture may define DYNAMIC_LOADING if dynamic_load.c | |
512 | * defined GC_register_dynamic_libraries() for the architecture. | |
513 | * | |
514 | * An architecture may define PREFETCH(x) to preload the cache with *x. | |
515 | * This defaults to a no-op. | |
516 | * | |
517 | * PREFETCH_FOR_WRITE(x) is used if *x is about to be written. | |
518 | * | |
519 | * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to | |
520 | * clear the two words at GC_malloc-aligned address x. By default, | |
521 | * word stores of 0 are used instead. | |
522 | */ | |
523 | ||
524 | ||
525 | # define STACK_GRAN 0x1000000 | |
526 | # ifdef M68K | |
527 | # define MACH_TYPE "M68K" | |
528 | # define ALIGNMENT 2 | |
529 | # ifdef OPENBSD | |
530 | # define OS_TYPE "OPENBSD" | |
531 | # define HEURISTIC2 | |
532 | extern char etext; | |
533 | # define DATASTART ((ptr_t)(&etext)) | |
534 | # endif | |
535 | # ifdef NETBSD | |
536 | # define OS_TYPE "NETBSD" | |
537 | # define HEURISTIC2 | |
538 | extern char etext; | |
539 | # define DATASTART ((ptr_t)(&etext)) | |
540 | # endif | |
541 | # ifdef LINUX | |
542 | # define OS_TYPE "LINUX" | |
543 | # define STACKBOTTOM ((ptr_t)0xf0000000) | |
544 | # define MPROTECT_VDB | |
545 | # ifdef __ELF__ | |
546 | # define DYNAMIC_LOADING | |
547 | extern char **__environ; | |
548 | # define DATASTART ((ptr_t)(&__environ)) | |
549 | /* hideous kludge: __environ is the first */ | |
550 | /* word in crt0.o, and delimits the start */ | |
551 | /* of the data segment, no matter which */ | |
552 | /* ld options were passed through. */ | |
553 | /* We could use _etext instead, but that */ | |
554 | /* would include .rodata, which may */ | |
555 | /* contain large read-only data tables */ | |
556 | /* that we'd rather not scan. */ | |
557 | extern int _end; | |
558 | # define DATAEND (&_end) | |
559 | # else | |
560 | extern int etext; | |
561 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff)) | |
562 | # endif | |
563 | # endif | |
564 | # ifdef SUNOS4 | |
565 | # define OS_TYPE "SUNOS4" | |
566 | extern char etext; | |
567 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ffff) & ~0x1ffff)) | |
568 | # define HEURISTIC1 /* differs */ | |
569 | # define DYNAMIC_LOADING | |
570 | # endif | |
571 | # ifdef HP | |
572 | # define OS_TYPE "HP" | |
573 | extern char etext; | |
574 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff)) | |
575 | # define STACKBOTTOM ((ptr_t) 0xffeffffc) | |
576 | /* empirically determined. seems to work. */ | |
577 | # include <unistd.h> | |
578 | # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE) | |
579 | # endif | |
580 | # ifdef SYSV | |
581 | # define OS_TYPE "SYSV" | |
582 | extern etext; | |
583 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \ | |
584 | & ~0x3fffff) \ | |
585 | +((word)&etext & 0x1fff)) | |
586 | /* This only works for shared-text binaries with magic number 0413. | |
587 | The other sorts of SysV binaries put the data at the end of the text, | |
588 | in which case the default of &etext would work. Unfortunately, | |
589 | handling both would require having the magic-number available. | |
590 | -- Parag | |
591 | */ | |
592 | # define STACKBOTTOM ((ptr_t)0xFFFFFFFE) | |
593 | /* The stack starts at the top of memory, but */ | |
594 | /* 0x0 cannot be used as setjump_test complains */ | |
595 | /* that the stack direction is incorrect. Two */ | |
596 | /* bytes down from 0x0 should be safe enough. */ | |
597 | /* --Parag */ | |
598 | # include <sys/mmu.h> | |
599 | # define GETPAGESIZE() PAGESIZE /* Is this still right? */ | |
600 | # endif | |
601 | # ifdef AMIGA | |
602 | # define OS_TYPE "AMIGA" | |
603 | /* STACKBOTTOM and DATASTART handled specially */ | |
604 | /* in os_dep.c */ | |
605 | # define DATAEND /* not needed */ | |
606 | # define GETPAGESIZE() 4096 | |
607 | # endif | |
608 | # ifdef MACOS | |
609 | # ifndef __LOWMEM__ | |
610 | # include <LowMem.h> | |
611 | # endif | |
612 | # define OS_TYPE "MACOS" | |
613 | /* see os_dep.c for details of global data segments. */ | |
614 | # define STACKBOTTOM ((ptr_t) LMGetCurStackBase()) | |
615 | # define DATAEND /* not needed */ | |
616 | # define GETPAGESIZE() 4096 | |
617 | # endif | |
618 | # ifdef NEXT | |
619 | # define OS_TYPE "NEXT" | |
620 | # define DATASTART ((ptr_t) get_etext()) | |
621 | # define STACKBOTTOM ((ptr_t) 0x4000000) | |
622 | # define DATAEND /* not needed */ | |
623 | # endif | |
624 | # endif | |
625 | ||
626 | # ifdef POWERPC | |
627 | # define MACH_TYPE "POWERPC" | |
628 | # ifdef MACOS | |
629 | # define ALIGNMENT 2 /* Still necessary? Could it be 4? */ | |
630 | # ifndef __LOWMEM__ | |
631 | # include <LowMem.h> | |
632 | # endif | |
633 | # define OS_TYPE "MACOS" | |
634 | /* see os_dep.c for details of global data segments. */ | |
635 | # define STACKBOTTOM ((ptr_t) LMGetCurStackBase()) | |
636 | # define DATAEND /* not needed */ | |
637 | # endif | |
638 | # ifdef LINUX | |
639 | # define ALIGNMENT 4 /* Guess. Can someone verify? */ | |
640 | /* This was 2, but that didn't sound right. */ | |
641 | # define OS_TYPE "LINUX" | |
642 | # define HEURISTIC1 | |
643 | # define DYNAMIC_LOADING | |
644 | # undef STACK_GRAN | |
645 | # define STACK_GRAN 0x10000000 | |
646 | /* Stack usually starts at 0x80000000 */ | |
647 | # define LINUX_DATA_START | |
648 | extern int _end; | |
649 | # define DATAEND (&_end) | |
650 | # endif | |
651 | # ifdef MACOSX | |
652 | # define ALIGNMENT 4 | |
653 | # define OS_TYPE "MACOSX" | |
654 | # define DATASTART ((ptr_t) get_etext()) | |
655 | # define STACKBOTTOM ((ptr_t) 0xc0000000) | |
656 | # define DATAEND /* not needed */ | |
657 | # endif | |
658 | # endif | |
659 | ||
660 | # ifdef VAX | |
661 | # define MACH_TYPE "VAX" | |
662 | # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */ | |
663 | extern char etext; | |
664 | # define DATASTART ((ptr_t)(&etext)) | |
665 | # ifdef BSD | |
666 | # define OS_TYPE "BSD" | |
667 | # define HEURISTIC1 | |
668 | /* HEURISTIC2 may be OK, but it's hard to test. */ | |
669 | # endif | |
670 | # ifdef ULTRIX | |
671 | # define OS_TYPE "ULTRIX" | |
672 | # define STACKBOTTOM ((ptr_t) 0x7fffc800) | |
673 | # endif | |
674 | # endif | |
675 | ||
676 | # ifdef RT | |
677 | # define MACH_TYPE "RT" | |
678 | # define ALIGNMENT 4 | |
679 | # define DATASTART ((ptr_t) 0x10000000) | |
680 | # define STACKBOTTOM ((ptr_t) 0x1fffd800) | |
681 | # endif | |
682 | ||
683 | # ifdef SPARC | |
684 | # define MACH_TYPE "SPARC" | |
685 | # define ALIGNMENT 4 /* Required by hardware */ | |
686 | # define ALIGN_DOUBLE | |
687 | extern int etext; | |
688 | # ifdef SUNOS5 | |
689 | # define OS_TYPE "SUNOS5" | |
690 | extern int _etext; | |
691 | extern int _end; | |
692 | extern char * GC_SysVGetDataStart(); | |
693 | # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext) | |
694 | # define DATAEND (&_end) | |
695 | # ifndef USE_MMAP | |
696 | # define USE_MMAP | |
697 | # endif | |
698 | # ifdef USE_MMAP | |
699 | # define HEAP_START (ptr_t)0x40000000 | |
700 | # else | |
701 | # define HEAP_START DATAEND | |
702 | # endif | |
703 | # define PROC_VDB | |
704 | /* HEURISTIC1 reportedly no longer works under 2.7. Thus we */ | |
705 | /* switched to HEURISTIC2, eventhough it creates some debugging */ | |
706 | /* issues. */ | |
707 | # define HEURISTIC2 | |
708 | # include <unistd.h> | |
709 | # define GETPAGESIZE() sysconf(_SC_PAGESIZE) | |
710 | /* getpagesize() appeared to be missing from at least one */ | |
711 | /* Solaris 5.4 installation. Weird. */ | |
712 | # define DYNAMIC_LOADING | |
713 | # endif | |
714 | # ifdef SUNOS4 | |
715 | # define OS_TYPE "SUNOS4" | |
716 | /* [If you have a weak stomach, don't read this.] */ | |
717 | /* We would like to use: */ | |
718 | /* # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1fff) & ~0x1fff)) */ | |
719 | /* This fails occasionally, due to an ancient, but very */ | |
720 | /* persistent ld bug. &etext is set 32 bytes too high. */ | |
721 | /* We instead read the text segment size from the a.out */ | |
722 | /* header, which happens to be mapped into our address space */ | |
723 | /* at the start of the text segment. The detective work here */ | |
724 | /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */ | |
725 | /* Serpette of INRIA. */ | |
726 | /* This assumes ZMAGIC, i.e. demand-loadable executables. */ | |
727 | # define TEXTSTART 0x2000 | |
728 | # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART)) | |
729 | # define MPROTECT_VDB | |
730 | # define HEURISTIC1 | |
731 | # define DYNAMIC_LOADING | |
732 | # endif | |
733 | # ifdef DRSNX | |
734 | # define CPP_WORDSZ 32 | |
735 | # define OS_TYPE "DRSNX" | |
736 | extern char * GC_SysVGetDataStart(); | |
737 | extern int etext; | |
738 | # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext) | |
739 | # define MPROTECT_VDB | |
740 | # define STACKBOTTOM ((ptr_t) 0xdfff0000) | |
741 | # define DYNAMIC_LOADING | |
742 | # endif | |
743 | # ifdef LINUX | |
744 | # define OS_TYPE "LINUX" | |
745 | # ifdef __ELF__ | |
746 | # define LINUX_DATA_START | |
747 | # define DYNAMIC_LOADING | |
748 | # else | |
749 | Linux Sparc non elf ? | |
750 | # endif | |
751 | extern int _end; | |
752 | # define DATAEND (&_end) | |
753 | # define SVR4 | |
754 | # define STACKBOTTOM ((ptr_t) 0xf0000000) | |
755 | # endif | |
756 | # ifdef OPENBSD | |
757 | # define OS_TYPE "OPENBSD" | |
758 | # define STACKBOTTOM ((ptr_t) 0xf8000000) | |
759 | # define DATASTART ((ptr_t)(&etext)) | |
760 | # endif | |
761 | # endif | |
762 | ||
763 | # ifdef I386 | |
764 | # define MACH_TYPE "I386" | |
765 | # define ALIGNMENT 4 /* Appears to hold for all "32 bit" compilers */ | |
766 | /* except Borland. The -a4 option fixes */ | |
767 | /* Borland. */ | |
768 | /* Ivan Demakov: For Watcom the option is -zp4. */ | |
769 | # ifndef SMALL_CONFIG | |
770 | # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */ | |
771 | /* improvement on Pentiums. */ | |
772 | # endif | |
773 | # ifdef SEQUENT | |
774 | # define OS_TYPE "SEQUENT" | |
775 | extern int etext; | |
776 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff)) | |
9ec1e770 | 777 | # define STACKBOTTOM ((ptr_t) 0x3ffff000) |
155415a5 MV |
778 | # endif |
779 | # ifdef SUNOS5 | |
780 | # define OS_TYPE "SUNOS5" | |
781 | extern int etext, _start; | |
782 | extern char * GC_SysVGetDataStart(); | |
783 | # define DATASTART GC_SysVGetDataStart(0x1000, &etext) | |
784 | # define STACKBOTTOM ((ptr_t)(&_start)) | |
785 | /** At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */ | |
786 | /*# define PROC_VDB*/ | |
787 | # define DYNAMIC_LOADING | |
788 | # ifndef USE_MMAP | |
789 | # define USE_MMAP | |
790 | # endif | |
791 | # ifdef USE_MMAP | |
792 | # define HEAP_START (ptr_t)0x40000000 | |
793 | # else | |
794 | # define HEAP_START DATAEND | |
795 | # endif | |
796 | # endif | |
797 | # ifdef SCO | |
798 | # define OS_TYPE "SCO" | |
799 | extern int etext; | |
800 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \ | |
801 | & ~0x3fffff) \ | |
802 | +((word)&etext & 0xfff)) | |
803 | # define STACKBOTTOM ((ptr_t) 0x7ffffffc) | |
804 | # endif | |
805 | # ifdef SCO_ELF | |
806 | # define OS_TYPE "SCO_ELF" | |
807 | extern int etext; | |
808 | # define DATASTART ((ptr_t)(&etext)) | |
809 | # define STACKBOTTOM ((ptr_t) 0x08048000) | |
810 | # define DYNAMIC_LOADING | |
811 | # define ELF_CLASS ELFCLASS32 | |
812 | # endif | |
813 | # ifdef LINUX | |
814 | # define OS_TYPE "LINUX" | |
815 | # define LINUX_STACKBOTTOM | |
816 | # if 0 | |
817 | # define HEURISTIC1 | |
818 | # undef STACK_GRAN | |
819 | # define STACK_GRAN 0x10000000 | |
820 | /* STACKBOTTOM is usually 0xc0000000, but this changes with */ | |
821 | /* different kernel configurations. In particular, systems */ | |
822 | /* with 2GB physical memory will usually move the user */ | |
823 | /* address space limit, and hence initial SP to 0x80000000. */ | |
824 | # endif | |
825 | # if !defined(LINUX_THREADS) || !defined(REDIRECT_MALLOC) | |
826 | # define MPROTECT_VDB | |
827 | # else | |
828 | /* We seem to get random errors in incremental mode, */ | |
829 | /* possibly because Linux threads is itself a malloc client */ | |
830 | /* and can't deal with the signals. */ | |
831 | # endif | |
832 | # ifdef __ELF__ | |
833 | # define DYNAMIC_LOADING | |
834 | # ifdef UNDEFINED /* includes ro data */ | |
835 | extern int _etext; | |
836 | # define DATASTART ((ptr_t)((((word) (&_etext)) + 0xfff) & ~0xfff)) | |
837 | # endif | |
838 | # include <features.h> | |
839 | # if defined(__GLIBC__) && __GLIBC__ >= 2 | |
840 | # define LINUX_DATA_START | |
841 | # else | |
842 | extern char **__environ; | |
843 | # define DATASTART ((ptr_t)(&__environ)) | |
844 | /* hideous kludge: __environ is the first */ | |
845 | /* word in crt0.o, and delimits the start */ | |
846 | /* of the data segment, no matter which */ | |
847 | /* ld options were passed through. */ | |
848 | /* We could use _etext instead, but that */ | |
849 | /* would include .rodata, which may */ | |
850 | /* contain large read-only data tables */ | |
851 | /* that we'd rather not scan. */ | |
852 | # endif | |
853 | extern int _end; | |
854 | # define DATAEND (&_end) | |
855 | # else | |
856 | extern int etext; | |
857 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff)) | |
858 | # endif | |
859 | # ifdef USE_I686_PREFETCH | |
860 | # define PREFETCH(x) \ | |
861 | __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x))) | |
862 | /* Empirically prefetcht0 is much more effective at reducing */ | |
863 | /* cache miss stalls for the targetted load instructions. But it */ | |
864 | /* seems to interfere enough with other cache traffic that the net */ | |
865 | /* result is worse than prefetchnta. */ | |
9ec1e770 | 866 | # if 0 |
155415a5 MV |
867 | /* Using prefetches for write seems to have a slight negative */ |
868 | /* impact on performance, at least for a PIII/500. */ | |
869 | # define PREFETCH_FOR_WRITE(x) \ | |
870 | __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x))) | |
871 | # endif | |
872 | # endif | |
873 | # ifdef USE_3DNOW_PREFETCH | |
874 | # define PREFETCH(x) \ | |
875 | __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x))) | |
9ec1e770 | 876 | # define PREFETCH_FOR_WRITE(x) |
155415a5 MV |
877 | __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x))) |
878 | # endif | |
879 | # endif | |
880 | # ifdef CYGWIN32 | |
881 | # define OS_TYPE "CYGWIN32" | |
882 | extern int _data_start__; | |
883 | extern int _data_end__; | |
884 | extern int _bss_start__; | |
885 | extern int _bss_end__; | |
886 | /* For binutils 2.9.1, we have */ | |
887 | /* DATASTART = _data_start__ */ | |
888 | /* DATAEND = _bss_end__ */ | |
889 | /* whereas for some earlier versions it was */ | |
890 | /* DATASTART = _bss_start__ */ | |
891 | /* DATAEND = _data_end__ */ | |
892 | /* To get it right for both, we take the */ | |
893 | /* minumum/maximum of the two. */ | |
894 | # define MAX(x,y) ((x) > (y) ? (x) : (y)) | |
895 | # define MIN(x,y) ((x) < (y) ? (x) : (y)) | |
896 | # define DATASTART ((ptr_t) MIN(&_data_start__, &_bss_start__)) | |
897 | # define DATAEND ((ptr_t) MAX(&_data_end__, &_bss_end__)) | |
898 | # undef STACK_GRAN | |
899 | # define STACK_GRAN 0x10000 | |
900 | # define HEURISTIC1 | |
901 | # endif | |
902 | # ifdef OS2 | |
903 | # define OS_TYPE "OS2" | |
904 | /* STACKBOTTOM and DATASTART are handled specially in */ | |
905 | /* os_dep.c. OS2 actually has the right */ | |
906 | /* system call! */ | |
907 | # define DATAEND /* not needed */ | |
908 | # endif | |
909 | # ifdef MSWIN32 | |
910 | # define OS_TYPE "MSWIN32" | |
911 | /* STACKBOTTOM and DATASTART are handled specially in */ | |
912 | /* os_dep.c. */ | |
913 | # ifndef __WATCOMC__ | |
914 | # define MPROTECT_VDB | |
915 | # endif | |
916 | # define DATAEND /* not needed */ | |
917 | # endif | |
918 | # ifdef DJGPP | |
919 | # define OS_TYPE "DJGPP" | |
920 | # include "stubinfo.h" | |
921 | extern int etext; | |
922 | extern int _stklen; | |
923 | extern int __djgpp_stack_limit; | |
924 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ff) & ~0x1ff)) | |
925 | /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \ | |
926 | + _stklen)) */ | |
927 | # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen)) | |
928 | /* This may not be right. */ | |
929 | # endif | |
930 | # ifdef OPENBSD | |
931 | # define OS_TYPE "OPENBSD" | |
932 | # endif | |
933 | # ifdef FREEBSD | |
934 | # define OS_TYPE "FREEBSD" | |
935 | # define MPROTECT_VDB | |
936 | # endif | |
937 | # ifdef NETBSD | |
938 | # define OS_TYPE "NETBSD" | |
939 | # endif | |
940 | # ifdef THREE86BSD | |
941 | # define OS_TYPE "THREE86BSD" | |
942 | # endif | |
943 | # ifdef BSDI | |
944 | # define OS_TYPE "BSDI" | |
945 | # endif | |
946 | # if defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD) \ | |
947 | || defined(THREE86BSD) || defined(BSDI) | |
948 | # define HEURISTIC2 | |
949 | extern char etext; | |
950 | # define DATASTART ((ptr_t)(&etext)) | |
951 | # endif | |
952 | # ifdef NEXT | |
953 | # define OS_TYPE "NEXT" | |
954 | # define DATASTART ((ptr_t) get_etext()) | |
955 | # define STACKBOTTOM ((ptr_t)0xc0000000) | |
956 | # define DATAEND /* not needed */ | |
957 | # endif | |
958 | # ifdef DOS4GW | |
959 | # define OS_TYPE "DOS4GW" | |
960 | extern long __nullarea; | |
961 | extern char _end; | |
962 | extern char *_STACKTOP; | |
963 | /* Depending on calling conventions Watcom C either precedes | |
964 | or does not precedes with undescore names of C-variables. | |
965 | Make sure startup code variables always have the same names. */ | |
966 | #pragma aux __nullarea "*"; | |
967 | #pragma aux _end "*"; | |
968 | # define STACKBOTTOM ((ptr_t) _STACKTOP) | |
969 | /* confused? me too. */ | |
970 | # define DATASTART ((ptr_t) &__nullarea) | |
971 | # define DATAEND ((ptr_t) &_end) | |
972 | # endif | |
9c52b218 RB |
973 | # ifdef GNU |
974 | # define OS_TYPE "GNU" | |
975 | # endif | |
155415a5 MV |
976 | # endif |
977 | ||
978 | # ifdef NS32K | |
979 | # define MACH_TYPE "NS32K" | |
980 | # define ALIGNMENT 4 | |
981 | extern char **environ; | |
982 | # define DATASTART ((ptr_t)(&environ)) | |
983 | /* hideous kludge: environ is the first */ | |
984 | /* word in crt0.o, and delimits the start */ | |
985 | /* of the data segment, no matter which */ | |
986 | /* ld options were passed through. */ | |
987 | # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */ | |
988 | # endif | |
989 | ||
990 | # ifdef MIPS | |
991 | # define MACH_TYPE "MIPS" | |
992 | /* # define STACKBOTTOM ((ptr_t)0x7fff8000) sometimes also works. */ | |
993 | # ifdef LINUX | |
994 | /* This was developed for a linuxce style platform. Probably */ | |
995 | /* needs to be tweaked for workstation class machines. */ | |
996 | # define OS_TYPE "LINUX" | |
997 | extern int __data_start; | |
998 | # define DATASTART ((ptr_t)(&__data_start)) | |
999 | # define ALIGNMENT 4 | |
1000 | # define USE_GENERIC_PUSH_REGS 1 | |
1001 | # define STACKBOTTOM 0x80000000 | |
1002 | /* In many cases, this should probably use LINUX_STACKBOTTOM */ | |
1003 | /* instead. But some kernel versions seem to give the wrong */ | |
1004 | /* value from /proc. */ | |
1005 | # endif /* Linux */ | |
1006 | # ifdef ULTRIX | |
1007 | # define HEURISTIC2 | |
1008 | # define DATASTART (ptr_t)0x10000000 | |
1009 | /* Could probably be slightly higher since */ | |
1010 | /* startup code allocates lots of stuff. */ | |
1011 | # define OS_TYPE "ULTRIX" | |
1012 | # define ALIGNMENT 4 | |
1013 | # endif | |
1014 | # ifdef RISCOS | |
1015 | # define HEURISTIC2 | |
1016 | # define DATASTART (ptr_t)0x10000000 | |
1017 | # define OS_TYPE "RISCOS" | |
1018 | # define ALIGNMENT 4 /* Required by hardware */ | |
1019 | # endif | |
1020 | # ifdef IRIX5 | |
1021 | # define HEURISTIC2 | |
1022 | extern int _fdata; | |
1023 | # define DATASTART ((ptr_t)(&_fdata)) | |
1024 | # ifdef USE_MMAP | |
1025 | # define HEAP_START (ptr_t)0x30000000 | |
1026 | # else | |
1027 | # define HEAP_START DATASTART | |
1028 | # endif | |
1029 | /* Lowest plausible heap address. */ | |
1030 | /* In the MMAP case, we map there. */ | |
1031 | /* In either case it is used to identify */ | |
1032 | /* heap sections so they're not */ | |
1033 | /* considered as roots. */ | |
1034 | # define OS_TYPE "IRIX5" | |
1035 | # define MPROTECT_VDB | |
1036 | # ifdef _MIPS_SZPTR | |
1037 | # define CPP_WORDSZ _MIPS_SZPTR | |
1038 | # define ALIGNMENT (_MIPS_SZPTR/8) | |
1039 | # if CPP_WORDSZ != 64 | |
1040 | # define ALIGN_DOUBLE | |
1041 | # endif | |
1042 | # else | |
1043 | # define ALIGNMENT 4 | |
1044 | # define ALIGN_DOUBLE | |
1045 | # endif | |
1046 | # define DYNAMIC_LOADING | |
1047 | # endif | |
1048 | # endif | |
1049 | ||
1050 | # ifdef RS6000 | |
1051 | # define MACH_TYPE "RS6000" | |
1052 | # define ALIGNMENT 4 | |
1053 | # define DATASTART ((ptr_t)0x20000000) | |
1054 | extern int errno; | |
1055 | # define STACKBOTTOM ((ptr_t)((ulong)&errno)) | |
1056 | # define DYNAMIC_LOADING | |
1057 | /* For really old versions of AIX, this may have to be removed. */ | |
1058 | # endif | |
1059 | ||
1060 | # ifdef HP_PA | |
1061 | /* OS is assumed to be HP/UX */ | |
1062 | # define MACH_TYPE "HP_PA" | |
1063 | # define OS_TYPE "HPUX" | |
1064 | # ifdef __LP64__ | |
1065 | # define CPP_WORDSZ 64 | |
1066 | # define ALIGNMENT 8 | |
1067 | # else | |
1068 | # define CPP_WORDSZ 32 | |
1069 | # define ALIGNMENT 4 | |
1070 | # define ALIGN_DOUBLE | |
1071 | # endif | |
1072 | extern int __data_start; | |
1073 | # define DATASTART ((ptr_t)(&__data_start)) | |
1074 | # if 0 | |
1075 | /* The following appears to work for 7xx systems running HP/UX */ | |
1076 | /* 9.xx Furthermore, it might result in much faster */ | |
1077 | /* collections than HEURISTIC2, which may involve scanning */ | |
1078 | /* segments that directly precede the stack. It is not the */ | |
1079 | /* default, since it may not work on older machine/OS */ | |
1080 | /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */ | |
1081 | /* this.) */ | |
1082 | # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */ | |
1083 | # else | |
1084 | /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */ | |
1085 | /* to this. We'll probably do this on other platforms, too. */ | |
1086 | /* For now I'll use it where I can test it. */ | |
1087 | extern char ** environ; | |
1088 | # define STACKBOTTOM ((ptr_t)environ) | |
1089 | # endif | |
2485c279 | 1090 | # ifndef SCM_STACK_GROWS_UP /* don't fight with scmconfig.h */ |
91b17416 | 1091 | # define SCM_STACK_GROWS_UP 1 |
2485c279 | 1092 | # endif |
155415a5 MV |
1093 | # define DYNAMIC_LOADING |
1094 | # ifndef HPUX_THREADS | |
1095 | # define MPROTECT_VDB | |
1096 | # endif | |
1097 | # include <unistd.h> | |
1098 | # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE) | |
1099 | # endif | |
1100 | ||
1101 | # ifdef ALPHA | |
1102 | # define MACH_TYPE "ALPHA" | |
1103 | # define ALIGNMENT 8 | |
1104 | # define USE_GENERIC_PUSH_REGS | |
1105 | /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */ | |
1106 | /* fp registers in some cases when the target is a 21264. The assembly */ | |
1107 | /* code doesn't handle that yet, and version dependencies make that a */ | |
1108 | /* bit tricky. Do the easy thing for now. */ | |
1109 | # ifdef OSF1 | |
1110 | # define OS_TYPE "OSF1" | |
1111 | # define DATASTART ((ptr_t) 0x140000000) | |
1112 | extern _end; | |
1113 | # define DATAEND ((ptr_t) &_end) | |
1114 | # define HEURISTIC2 | |
1115 | /* Normally HEURISTIC2 is too conervative, since */ | |
1116 | /* the text segment immediately follows the stack. */ | |
1117 | /* Hence we give an upper pound. */ | |
1118 | extern int __start; | |
1119 | # define HEURISTIC2_LIMIT ((ptr_t)((word)(&__start) & ~(getpagesize()-1))) | |
1120 | # define CPP_WORDSZ 64 | |
1121 | # define MPROTECT_VDB | |
1122 | # define DYNAMIC_LOADING | |
1123 | # endif | |
1124 | # ifdef LINUX | |
1125 | # define OS_TYPE "LINUX" | |
1126 | # define CPP_WORDSZ 64 | |
1127 | # define STACKBOTTOM ((ptr_t) 0x120000000) | |
1128 | # ifdef __ELF__ | |
1129 | # define LINUX_DATA_START | |
1130 | # define DYNAMIC_LOADING | |
1131 | /* This doesn't work if the collector is in a dynamic library. */ | |
1132 | # else | |
1133 | # define DATASTART ((ptr_t) 0x140000000) | |
1134 | # endif | |
1135 | extern int _end; | |
1136 | # define DATAEND (&_end) | |
1137 | # define MPROTECT_VDB | |
1138 | /* Has only been superficially tested. May not */ | |
1139 | /* work on all versions. */ | |
1140 | # endif | |
1141 | # endif | |
1142 | ||
1143 | # ifdef IA64 | |
1144 | # define MACH_TYPE "IA64" | |
1145 | # define ALIGN_DOUBLE | |
1146 | /* Requires 16 byte alignment for malloc */ | |
1147 | # define ALIGNMENT 8 | |
1148 | # define USE_GENERIC_PUSH_REGS | |
1149 | /* We need to get preserved registers in addition to register windows. */ | |
1150 | /* That's easiest to do with setjmp. */ | |
1151 | # ifdef HPUX | |
1152 | --> needs work | |
1153 | # endif | |
1154 | # ifdef LINUX | |
1155 | # define OS_TYPE "LINUX" | |
1156 | # define CPP_WORDSZ 64 | |
1157 | /* This should really be done through /proc, but that */ | |
1158 | /* requires we run on an IA64 kernel. */ | |
1159 | # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) | |
1160 | /* We also need the base address of the register stack */ | |
1161 | /* backing store. There is probably a better way to */ | |
1162 | /* get that, too ... */ | |
1163 | # define BACKING_STORE_BASE ((ptr_t) 0x9fffffff80000000l) | |
1164 | # if 1 | |
1165 | # define SEARCH_FOR_DATA_START | |
1166 | # define DATASTART GC_data_start | |
1167 | # else | |
1168 | extern int data_start; | |
1169 | # define DATASTART ((ptr_t)(&data_start)) | |
1170 | # endif | |
1171 | # define DYNAMIC_LOADING | |
1172 | # define MPROTECT_VDB | |
1173 | /* Requires Linux 2.3.47 or later. */ | |
1174 | extern int _end; | |
1175 | # define DATAEND (&_end) | |
1176 | # define PREFETCH(x) \ | |
1177 | __asm__ (" lfetch [%0]": : "r"((void *)(x))) | |
1178 | # define PREFETCH_FOR_WRITE(x) \ | |
1179 | __asm__ (" lfetch.excl [%0]": : "r"((void *)(x))) | |
1180 | # define CLEAR_DOUBLE(x) \ | |
1181 | __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x))) | |
1182 | # endif | |
1183 | # endif | |
1184 | ||
1185 | # ifdef M88K | |
1186 | # define MACH_TYPE "M88K" | |
1187 | # define ALIGNMENT 4 | |
1188 | # define ALIGN_DOUBLE | |
1189 | extern int etext; | |
1190 | # ifdef CX_UX | |
1191 | # define OS_TYPE "CX_UX" | |
1192 | # define DATASTART ((((word)&etext + 0x3fffff) & ~0x3fffff) + 0x10000) | |
1193 | # endif | |
1194 | # ifdef DGUX | |
1195 | # define OS_TYPE "DGUX" | |
1196 | extern char * GC_SysVGetDataStart(); | |
1197 | # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext) | |
1198 | # endif | |
1199 | # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */ | |
1200 | # endif | |
1201 | ||
1202 | # ifdef S370 | |
1203 | # define MACH_TYPE "S370" | |
1204 | # define OS_TYPE "UTS4" | |
1205 | # define ALIGNMENT 4 /* Required by hardware */ | |
1206 | extern int etext; | |
1207 | extern int _etext; | |
1208 | extern int _end; | |
1209 | extern char * GC_SysVGetDataStart(); | |
1210 | # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext) | |
1211 | # define DATAEND (&_end) | |
1212 | # define HEURISTIC2 | |
1213 | # endif | |
1214 | ||
1215 | # if defined(PJ) | |
1216 | # define ALIGNMENT 4 | |
1217 | extern int _etext; | |
1218 | # define DATASTART ((ptr_t)(&_etext)) | |
1219 | # define HEURISTIC1 | |
1220 | # endif | |
1221 | ||
1222 | # ifdef ARM32 | |
1223 | # define CPP_WORDSZ 32 | |
1224 | # define MACH_TYPE "ARM32" | |
1225 | # define ALIGNMENT 4 | |
1226 | # ifdef NETBSD | |
1227 | # define OS_TYPE "NETBSD" | |
1228 | # define HEURISTIC2 | |
1229 | extern char etext; | |
1230 | # define DATASTART ((ptr_t)(&etext)) | |
1231 | # define USE_GENERIC_PUSH_REGS | |
1232 | # endif | |
1233 | # ifdef LINUX | |
1234 | # define OS_TYPE "LINUX" | |
1235 | # define HEURISTIC1 | |
1236 | # undef STACK_GRAN | |
1237 | # define STACK_GRAN 0x10000000 | |
1238 | # define USE_GENERIC_PUSH_REGS | |
1239 | # ifdef __ELF__ | |
1240 | # define DYNAMIC_LOADING | |
1241 | # include <features.h> | |
1242 | # if defined(__GLIBC__) && __GLIBC__ >= 2 | |
1243 | # define LINUX_DATA_START | |
1244 | # else | |
1245 | extern char **__environ; | |
1246 | # define DATASTART ((ptr_t)(&__environ)) | |
1247 | /* hideous kludge: __environ is the first */ | |
1248 | /* word in crt0.o, and delimits the start */ | |
1249 | /* of the data segment, no matter which */ | |
1250 | /* ld options were passed through. */ | |
1251 | /* We could use _etext instead, but that */ | |
1252 | /* would include .rodata, which may */ | |
1253 | /* contain large read-only data tables */ | |
1254 | /* that we'd rather not scan. */ | |
1255 | # endif | |
1256 | extern int _end; | |
1257 | # define DATAEND (&_end) | |
1258 | # else | |
1259 | extern int etext; | |
1260 | # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff)) | |
1261 | # endif | |
1262 | # endif | |
1263 | #endif | |
1264 | ||
1265 | #ifdef LINUX_DATA_START | |
1266 | /* Some Linux distributions arrange to define __data_start. Some */ | |
1267 | /* define data_start as a weak symbol. The latter is technically */ | |
1268 | /* broken, since the user program may define data_start, in which */ | |
1269 | /* case we lose. Nonetheless, we try both, prefering __data_start. */ | |
1270 | /* We assume gcc. */ | |
1271 | # pragma weak __data_start | |
1272 | extern int __data_start; | |
1273 | # pragma weak data_start | |
1274 | extern int data_start; | |
1275 | # define DATASTART ((ptr_t)(&__data_start != 0? &__data_start : &data_start)) | |
1276 | #endif | |
1277 | ||
91b17416 RB |
1278 | # if SCM_STACK_GROWS_UP |
1279 | # define STACK_GROWS_DOWN 0 | |
1280 | # else | |
1281 | # define STACK_GROWS_DOWN 1 | |
1282 | #endif | |
155415a5 MV |
1283 | |
1284 | # ifndef CPP_WORDSZ | |
1285 | # define CPP_WORDSZ 32 | |
1286 | # endif | |
1287 | ||
1288 | # ifndef OS_TYPE | |
1289 | # define OS_TYPE "" | |
1290 | # endif | |
1291 | ||
1292 | # ifndef DATAEND | |
1293 | extern int end; | |
1294 | # define DATAEND (&end) | |
1295 | # endif | |
1296 | ||
1297 | # if defined(SVR4) && !defined(GETPAGESIZE) | |
1298 | # include <unistd.h> | |
1299 | # define GETPAGESIZE() sysconf(_SC_PAGESIZE) | |
1300 | # endif | |
1301 | ||
1302 | # ifndef GETPAGESIZE | |
1303 | # if defined(SUNOS5) || defined(IRIX5) | |
1304 | # include <unistd.h> | |
1305 | # endif | |
1306 | # define GETPAGESIZE() getpagesize() | |
1307 | # endif | |
1308 | ||
1309 | # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4) | |
1310 | /* OS has SVR4 generic features. Probably others also qualify. */ | |
1311 | # define SVR4 | |
1312 | # endif | |
1313 | ||
1314 | # if defined(SUNOS5) || defined(DRSNX) | |
1315 | /* OS has SUNOS5 style semi-undocumented interface to dynamic */ | |
1316 | /* loader. */ | |
1317 | # define SUNOS5DL | |
1318 | /* OS has SUNOS5 style signal handlers. */ | |
1319 | # define SUNOS5SIGS | |
1320 | # endif | |
1321 | ||
1322 | # if defined(HPUX) | |
1323 | # define SUNOS5SIGS | |
1324 | # endif | |
1325 | ||
1326 | # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64 | |
1327 | -> bad word size | |
1328 | # endif | |
1329 | ||
1330 | # ifdef PCR | |
1331 | # undef DYNAMIC_LOADING | |
1332 | # undef STACKBOTTOM | |
1333 | # undef HEURISTIC1 | |
1334 | # undef HEURISTIC2 | |
1335 | # undef PROC_VDB | |
1336 | # undef MPROTECT_VDB | |
1337 | # define PCR_VDB | |
1338 | # endif | |
1339 | ||
1340 | # ifdef SRC_M3 | |
1341 | /* Postponed for now. */ | |
1342 | # undef PROC_VDB | |
1343 | # undef MPROTECT_VDB | |
1344 | # endif | |
1345 | ||
1346 | # ifdef SMALL_CONFIG | |
1347 | /* Presumably not worth the space it takes. */ | |
1348 | # undef PROC_VDB | |
1349 | # undef MPROTECT_VDB | |
1350 | # endif | |
1351 | ||
1352 | # ifdef USE_MUNMAP | |
1353 | # undef MPROTECT_VDB /* Can't deal with address space holes. */ | |
1354 | # endif | |
1355 | ||
1356 | # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB) | |
1357 | # define DEFAULT_VDB | |
1358 | # endif | |
1359 | ||
1360 | # ifndef PREFETCH | |
1361 | # define PREFETCH(x) | |
1362 | # define NO_PREFETCH | |
1363 | # endif | |
1364 | ||
1365 | # ifndef PREFETCH_FOR_WRITE | |
1366 | # define PREFETCH_FOR_WRITE(x) | |
1367 | # define NO_PREFETCH_FOR_WRITE | |
1368 | # endif | |
1369 | ||
1370 | # ifndef CACHE_LINE_SIZE | |
1371 | # define CACHE_LINE_SIZE 32 /* Wild guess */ | |
1372 | # endif | |
1373 | ||
1374 | # ifndef CLEAR_DOUBLE | |
1375 | # define CLEAR_DOUBLE(x) \ | |
1376 | ((word*)x)[0] = 0; \ | |
1377 | ((word*)x)[1] = 0; | |
1378 | # endif /* CLEAR_DOUBLE */ | |
1379 | ||
1380 | # if defined(_SOLARIS_PTHREADS) && !defined(SOLARIS_THREADS) | |
1381 | # define SOLARIS_THREADS | |
1382 | # endif | |
1383 | # if defined(IRIX_THREADS) && !defined(IRIX5) | |
1384 | --> inconsistent configuration | |
1385 | # endif | |
1386 | # if defined(IRIX_JDK_THREADS) && !defined(IRIX5) | |
1387 | --> inconsistent configuration | |
1388 | # endif | |
1389 | # if defined(LINUX_THREADS) && !defined(LINUX) | |
1390 | --> inconsistent configuration | |
1391 | # endif | |
1392 | # if defined(SOLARIS_THREADS) && !defined(SUNOS5) | |
1393 | --> inconsistent configuration | |
1394 | # endif | |
1395 | # if defined(HPUX_THREADS) && !defined(HPUX) | |
1396 | --> inconsistent configuration | |
1397 | # endif | |
1398 | # if defined(PCR) || defined(SRC_M3) || \ | |
1399 | defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || \ | |
1400 | defined(IRIX_THREADS) || defined(LINUX_THREADS) || \ | |
1401 | defined(IRIX_JDK_THREADS) || defined(HPUX_THREADS) | |
1402 | # define THREADS | |
1403 | # endif | |
1404 | ||
1405 | # if defined(HP_PA) || defined(M88K) || defined(POWERPC) \ | |
1406 | || (defined(I386) && defined(OS2)) || defined(UTS4) || defined(LINT) | |
1407 | /* Use setjmp based hack to mark from callee-save registers. */ | |
1408 | # define USE_GENERIC_PUSH_REGS | |
1409 | # endif | |
1410 | # if defined(SPARC) && !defined(LINUX) | |
1411 | # define SAVE_CALL_CHAIN | |
1412 | # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */ | |
1413 | /* include assembly code to do it well. */ | |
1414 | # endif | |
1415 | ||
1416 | # if defined(LINUX) && !defined(POWERPC) | |
bc286d9f | 1417 | |
9ec1e770 | 1418 | # if 0 |
155415a5 MV |
1419 | # include <linux/version.h> |
1420 | # if (LINUX_VERSION_CODE <= 0x10400) | |
bc286d9f | 1421 | /* Ugly hack to get struct sigcontext_struct definition. Required */ |
155415a5 MV |
1422 | /* for some early 1.3.X releases. Will hopefully go away soon. */ |
1423 | /* in some later Linux releases, asm/sigcontext.h may have to */ | |
1424 | /* be included instead. */ | |
1425 | # define __KERNEL__ | |
1426 | # include <asm/signal.h> | |
1427 | # undef __KERNEL__ | |
5159b336 MV |
1428 | # endif |
1429 | ||
1430 | # else | |
bc286d9f | 1431 | |
155415a5 MV |
1432 | /* Kernels prior to 2.1.1 defined struct sigcontext_struct instead of */ |
1433 | /* struct sigcontext. libc6 (glibc2) uses "struct sigcontext" in */ | |
1434 | /* prototypes, so we have to include the top-level sigcontext.h to */ | |
1435 | /* make sure the former gets defined to be the latter if appropriate. */ | |
1436 | # include <features.h> | |
1437 | # if 2 <= __GLIBC__ | |
1438 | # if 2 == __GLIBC__ && 0 == __GLIBC_MINOR__ | |
1439 | /* glibc 2.1 no longer has sigcontext.h. But signal.h */ | |
1440 | /* has the right declaration for glibc 2.1. */ | |
1441 | # include <sigcontext.h> | |
1442 | # endif /* 0 == __GLIBC_MINOR__ */ | |
1443 | # else /* not 2 <= __GLIBC__ */ | |
1444 | /* libc5 doesn't have <sigcontext.h>: go directly with the kernel */ | |
1445 | /* one. Check LINUX_VERSION_CODE to see which we should reference. */ | |
1446 | # include <asm/sigcontext.h> | |
1447 | # endif /* 2 <= __GLIBC__ */ | |
1448 | # endif | |
1449 | # endif | |
1450 | # if !defined(OS2) && !defined(PCR) && !defined(AMIGA) && !defined(MACOS) | |
1451 | # include <sys/types.h> | |
1452 | # if !defined(MSWIN32) && !defined(SUNOS4) | |
1453 | # include <unistd.h> | |
1454 | # endif | |
1455 | # endif | |
1456 | ||
155415a5 MV |
1457 | # include <signal.h> |
1458 | ||
1459 | /* Blatantly OS dependent routines, except for those that are related */ | |
1460 | /* to dynamic loading. */ | |
1461 | ||
1462 | # if !defined(THREADS) && !defined(STACKBOTTOM) && defined(HEURISTIC2) | |
1463 | # define NEED_FIND_LIMIT | |
1464 | # endif | |
1465 | ||
1466 | # if defined(IRIX_THREADS) || defined(HPUX_THREADS) | |
1467 | # define NEED_FIND_LIMIT | |
1468 | # endif | |
1469 | ||
1470 | # if (defined(SUNOS4) && defined(DYNAMIC_LOADING)) && !defined(PCR) | |
1471 | # define NEED_FIND_LIMIT | |
1472 | # endif | |
1473 | ||
1474 | # if (defined(SVR4) || defined(AUX) || defined(DGUX)) && !defined(PCR) | |
1475 | # define NEED_FIND_LIMIT | |
1476 | # endif | |
1477 | ||
1478 | # if defined(LINUX) && \ | |
1479 | (defined(POWERPC) || defined(SPARC) || defined(ALPHA) || defined(IA64) \ | |
1480 | || defined(MIPS)) | |
1481 | # define NEED_FIND_LIMIT | |
1482 | # endif | |
1483 | ||
1484 | #ifdef NEED_FIND_LIMIT | |
1485 | # include <setjmp.h> | |
1486 | #endif | |
1487 | ||
1488 | #ifdef FREEBSD | |
1489 | # include <machine/trap.h> | |
1490 | #endif | |
1491 | ||
1492 | #ifdef AMIGA | |
1493 | # include <proto/exec.h> | |
1494 | # include <proto/dos.h> | |
1495 | # include <dos/dosextens.h> | |
1496 | # include <workbench/startup.h> | |
1497 | #endif | |
1498 | ||
1499 | #ifdef MSWIN32 | |
1500 | # define WIN32_LEAN_AND_MEAN | |
1501 | # define NOSERVICE | |
1502 | # include <windows.h> | |
1503 | #endif | |
1504 | ||
1505 | #ifdef MACOS | |
1506 | # include <Processes.h> | |
1507 | #endif | |
1508 | ||
1509 | #ifdef IRIX5 | |
1510 | # include <sys/uio.h> | |
1511 | # include <malloc.h> /* for locking */ | |
1512 | #endif | |
1513 | #ifdef USE_MMAP | |
1514 | # include <sys/types.h> | |
1515 | # include <sys/mman.h> | |
1516 | # include <sys/stat.h> | |
1517 | # include <fcntl.h> | |
1518 | #endif | |
1519 | ||
1520 | #ifdef SUNOS5SIGS | |
1521 | # include <sys/siginfo.h> | |
1522 | # undef setjmp | |
1523 | # undef longjmp | |
1524 | # define setjmp(env) sigsetjmp(env, 1) | |
1525 | # define longjmp(env, val) siglongjmp(env, val) | |
1526 | # define jmp_buf sigjmp_buf | |
1527 | #endif | |
1528 | ||
1529 | #ifdef DJGPP | |
1530 | /* Apparently necessary for djgpp 2.01. May casuse problems with */ | |
1531 | /* other versions. */ | |
1532 | typedef long unsigned int caddr_t; | |
1533 | #endif | |
1534 | ||
1535 | #ifdef PCR | |
1536 | # include "il/PCR_IL.h" | |
1537 | # include "th/PCR_ThCtl.h" | |
1538 | # include "mm/PCR_MM.h" | |
1539 | #endif | |
1540 | ||
1541 | #if !defined(NO_EXECUTE_PERMISSION) | |
1542 | # define OPT_PROT_EXEC PROT_EXEC | |
1543 | #else | |
1544 | # define OPT_PROT_EXEC 0 | |
1545 | #endif | |
1546 | ||
1547 | # ifdef OS2 | |
1548 | ||
1549 | # include <stddef.h> | |
1550 | ||
1551 | # if !defined(__IBMC__) && !defined(__WATCOMC__) /* e.g. EMX */ | |
1552 | ||
1553 | # else /* IBM's compiler */ | |
1554 | ||
1555 | /* A kludge to get around what appears to be a header file bug */ | |
1556 | # ifndef WORD | |
1557 | # define WORD unsigned short | |
1558 | # endif | |
1559 | # ifndef DWORD | |
1560 | # define DWORD unsigned long | |
1561 | # endif | |
1562 | ||
1563 | # define EXE386 1 | |
1564 | # include <newexe.h> | |
1565 | # include <exe386.h> | |
1566 | ||
1567 | # endif /* __IBMC__ */ | |
1568 | ||
1569 | # define INCL_DOSEXCEPTIONS | |
1570 | # define INCL_DOSPROCESS | |
1571 | # define INCL_DOSERRORS | |
1572 | # define INCL_DOSMODULEMGR | |
1573 | # define INCL_DOSMEMMGR | |
1574 | # include <os2.h> | |
1575 | ||
1576 | # endif /*!OS/2 */ | |
1577 | ||
9ec1e770 TTN |
1578 | /* |
1579 | * Find the base of the stack. | |
155415a5 MV |
1580 | * Used only in single-threaded environment. |
1581 | * With threads, GC_mark_roots needs to know how to do this. | |
1582 | * Called with allocator lock held. | |
1583 | */ | |
9ec1e770 | 1584 | # ifdef MSWIN32 |
155415a5 MV |
1585 | # define is_writable(prot) ((prot) == PAGE_READWRITE \ |
1586 | || (prot) == PAGE_WRITECOPY \ | |
1587 | || (prot) == PAGE_EXECUTE_READWRITE \ | |
1588 | || (prot) == PAGE_EXECUTE_WRITECOPY) | |
1589 | /* Return the number of bytes that are writable starting at p. */ | |
1590 | /* The pointer p is assumed to be page aligned. */ | |
1591 | /* If base is not 0, *base becomes the beginning of the */ | |
1592 | /* allocation region containing p. */ | |
1593 | static word GC_get_writable_length(ptr_t p, ptr_t *base) | |
1594 | { | |
1595 | MEMORY_BASIC_INFORMATION buf; | |
1596 | word result; | |
1597 | word protect; | |
9ec1e770 | 1598 | |
155415a5 MV |
1599 | result = VirtualQuery(p, &buf, sizeof(buf)); |
1600 | if (result != sizeof(buf)) ABORT("Weird VirtualQuery result"); | |
1601 | if (base != 0) *base = (ptr_t)(buf.AllocationBase); | |
1602 | protect = (buf.Protect & ~(PAGE_GUARD | PAGE_NOCACHE)); | |
1603 | if (!is_writable(protect)) { | |
1604 | return(0); | |
1605 | } | |
1606 | if (buf.State != MEM_COMMIT) return(0); | |
1607 | return(buf.RegionSize); | |
1608 | } | |
1609 | ||
1610 | void *scm_get_stack_base() | |
1611 | { | |
1612 | int dummy; | |
1613 | ptr_t sp = (ptr_t)(&dummy); | |
70f95333 MV |
1614 | ptr_t trunc_sp; |
1615 | word size; | |
1616 | static word GC_page_size = 0; | |
1617 | if (!GC_page_size) { | |
1618 | SYSTEM_INFO sysinfo; | |
1619 | GetSystemInfo(&sysinfo); | |
1620 | GC_page_size = sysinfo.dwPageSize; | |
1621 | } | |
1622 | trunc_sp = (ptr_t)((word)sp & ~(GC_page_size - 1)); | |
1623 | size = GC_get_writable_length(trunc_sp, 0); | |
155415a5 MV |
1624 | return(trunc_sp + size); |
1625 | } | |
1626 | ||
1627 | ||
1628 | # else | |
1629 | ||
1630 | # ifdef OS2 | |
1631 | ||
1632 | void *scm_get_stack_base() | |
1633 | { | |
1634 | PTIB ptib; | |
1635 | PPIB ppib; | |
9ec1e770 | 1636 | |
155415a5 MV |
1637 | if (DosGetInfoBlocks(&ptib, &ppib) != NO_ERROR) { |
1638 | GC_err_printf0("DosGetInfoBlocks failed\n"); | |
1639 | ABORT("DosGetInfoBlocks failed\n"); | |
1640 | } | |
1641 | return((ptr_t)(ptib -> tib_pstacklimit)); | |
1642 | } | |
1643 | ||
1644 | # else | |
1645 | ||
1646 | # ifdef AMIGA | |
1647 | ||
1648 | void *scm_get_stack_base() | |
1649 | { | |
1650 | struct Process *proc = (struct Process*)SysBase->ThisTask; | |
9ec1e770 | 1651 | |
155415a5 MV |
1652 | /* Reference: Amiga Guru Book Pages: 42,567,574 */ |
1653 | if (proc->pr_Task.tc_Node.ln_Type==NT_PROCESS | |
1654 | && proc->pr_CLI != NULL) { | |
1655 | /* first ULONG is StackSize */ | |
1656 | /*longPtr = proc->pr_ReturnAddr; | |
1657 | size = longPtr[0];*/ | |
1658 | ||
1659 | return (char *)proc->pr_ReturnAddr + sizeof(ULONG); | |
1660 | } else { | |
1661 | return (char *)proc->pr_Task.tc_SPUpper; | |
1662 | } | |
1663 | } | |
1664 | ||
1665 | #if 0 /* old version */ | |
1666 | void *scm_get_stack_base() | |
1667 | { | |
1668 | extern struct WBStartup *_WBenchMsg; | |
1669 | extern long __base; | |
1670 | extern long __stack; | |
1671 | struct Task *task; | |
1672 | struct Process *proc; | |
1673 | struct CommandLineInterface *cli; | |
1674 | long size; | |
1675 | ||
1676 | if ((task = FindTask(0)) == 0) { | |
1677 | GC_err_puts("Cannot find own task structure\n"); | |
1678 | ABORT("task missing"); | |
1679 | } | |
1680 | proc = (struct Process *)task; | |
1681 | cli = BADDR(proc->pr_CLI); | |
1682 | ||
1683 | if (_WBenchMsg != 0 || cli == 0) { | |
1684 | size = (char *)task->tc_SPUpper - (char *)task->tc_SPLower; | |
1685 | } else { | |
1686 | size = cli->cli_DefaultStack * 4; | |
1687 | } | |
1688 | return (ptr_t)(__base + GC_max(size, __stack)); | |
1689 | } | |
1690 | #endif /* 0 */ | |
1691 | ||
1692 | # else /* !AMIGA, !OS2, ... */ | |
1693 | ||
1694 | # ifdef NEED_FIND_LIMIT | |
1695 | /* Some tools to implement HEURISTIC2 */ | |
1696 | # define MIN_PAGE_SIZE 256 /* Smallest conceivable page size, bytes */ | |
1697 | /* static */ jmp_buf GC_jmp_buf; | |
9ec1e770 | 1698 | |
155415a5 MV |
1699 | /*ARGSUSED*/ |
1700 | static void GC_fault_handler(sig) | |
1701 | int sig; | |
1702 | { | |
1703 | longjmp(GC_jmp_buf, 1); | |
1704 | } | |
1705 | ||
1706 | # ifdef __STDC__ | |
1707 | typedef void (*handler)(int); | |
1708 | # else | |
1709 | typedef void (*handler)(); | |
1710 | # endif | |
1711 | ||
1712 | # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) | |
1713 | static struct sigaction old_segv_act; | |
1714 | # if defined(_sigargs) || defined(HPUX) /* !Irix6.x */ | |
1715 | static struct sigaction old_bus_act; | |
1716 | # endif | |
1717 | # else | |
1718 | static handler old_segv_handler, old_bus_handler; | |
1719 | # endif | |
9ec1e770 | 1720 | |
155415a5 MV |
1721 | static void GC_setup_temporary_fault_handler() |
1722 | { | |
1723 | # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) | |
1724 | struct sigaction act; | |
1725 | ||
1726 | act.sa_handler = GC_fault_handler; | |
1727 | act.sa_flags = SA_RESTART | SA_NODEFER; | |
1728 | /* The presence of SA_NODEFER represents yet another gross */ | |
1729 | /* hack. Under Solaris 2.3, siglongjmp doesn't appear to */ | |
1730 | /* interact correctly with -lthread. We hide the confusion */ | |
1731 | /* by making sure that signal handling doesn't affect the */ | |
1732 | /* signal mask. */ | |
1733 | ||
1734 | (void) sigemptyset(&act.sa_mask); | |
1735 | # ifdef IRIX_THREADS | |
1736 | /* Older versions have a bug related to retrieving and */ | |
1737 | /* and setting a handler at the same time. */ | |
1738 | (void) sigaction(SIGSEGV, 0, &old_segv_act); | |
1739 | (void) sigaction(SIGSEGV, &act, 0); | |
1740 | # else | |
1741 | (void) sigaction(SIGSEGV, &act, &old_segv_act); | |
1742 | # if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \ | |
1743 | || defined(HPUX) | |
1744 | /* Under Irix 5.x or HP/UX, we may get SIGBUS. */ | |
1745 | /* Pthreads doesn't exist under Irix 5.x, so we */ | |
1746 | /* don't have to worry in the threads case. */ | |
1747 | (void) sigaction(SIGBUS, &act, &old_bus_act); | |
1748 | # endif | |
1749 | # endif /* IRIX_THREADS */ | |
1750 | # else | |
1751 | old_segv_handler = signal(SIGSEGV, GC_fault_handler); | |
1752 | # ifdef SIGBUS | |
1753 | old_bus_handler = signal(SIGBUS, GC_fault_handler); | |
1754 | # endif | |
1755 | # endif | |
1756 | } | |
9ec1e770 | 1757 | |
155415a5 MV |
1758 | static void GC_reset_fault_handler() |
1759 | { | |
1760 | # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1) | |
1761 | (void) sigaction(SIGSEGV, &old_segv_act, 0); | |
1762 | # if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \ | |
1763 | || defined(HPUX) | |
1764 | (void) sigaction(SIGBUS, &old_bus_act, 0); | |
1765 | # endif | |
1766 | # else | |
1767 | (void) signal(SIGSEGV, old_segv_handler); | |
1768 | # ifdef SIGBUS | |
1769 | (void) signal(SIGBUS, old_bus_handler); | |
1770 | # endif | |
1771 | # endif | |
1772 | } | |
1773 | ||
9ec1e770 TTN |
1774 | /* Single argument version, robust against whole program analysis. */ |
1775 | static void | |
1776 | GC_noop1(x) | |
1777 | word x; | |
1778 | { | |
1779 | static VOLATILE word sink; | |
1780 | sink = x; | |
1781 | } | |
1782 | ||
155415a5 MV |
1783 | /* Return the first nonaddressible location > p (up) or */ |
1784 | /* the smallest location q s.t. [q,p] is addressible (!up). */ | |
1785 | static ptr_t GC_find_limit(p, up) | |
1786 | ptr_t p; | |
1787 | GC_bool up; | |
1788 | { | |
1789 | static VOLATILE ptr_t result; | |
1790 | /* Needs to be static, since otherwise it may not be */ | |
1791 | /* preserved across the longjmp. Can safely be */ | |
1792 | /* static since it's only called once, with the */ | |
1793 | /* allocation lock held. */ | |
1794 | ||
1795 | ||
1796 | GC_setup_temporary_fault_handler(); | |
1797 | if (setjmp(GC_jmp_buf) == 0) { | |
1798 | result = (ptr_t)(((word)(p)) | |
1799 | & ~(MIN_PAGE_SIZE-1)); | |
1800 | for (;;) { | |
1801 | if (up) { | |
1802 | result += MIN_PAGE_SIZE; | |
1803 | } else { | |
1804 | result -= MIN_PAGE_SIZE; | |
1805 | } | |
1806 | GC_noop1((word)(*result)); | |
1807 | } | |
1808 | } | |
1809 | GC_reset_fault_handler(); | |
1810 | if (!up) { | |
1811 | result += MIN_PAGE_SIZE; | |
1812 | } | |
1813 | return(result); | |
1814 | } | |
d315ea8c | 1815 | |
155415a5 MV |
1816 | # endif |
1817 | ||
1818 | #ifdef LINUX_STACKBOTTOM | |
1819 | ||
1820 | #include <sys/types.h> | |
1821 | #include <sys/stat.h> | |
1822 | #include <fcntl.h> | |
1823 | ||
1824 | # define STAT_SKIP 27 /* Number of fields preceding startstack */ | |
1825 | /* field in /proc/self/stat */ | |
1826 | ||
1827 | static ptr_t GC_linux_stack_base(void) | |
1828 | { | |
1829 | /* We read the stack base value from /proc/self/stat. We do this */ | |
1830 | /* using direct I/O system calls in order to avoid calling malloc */ | |
9ec1e770 | 1831 | /* in case REDIRECT_MALLOC is defined. */ |
155415a5 MV |
1832 | # define STAT_BUF_SIZE 4096 |
1833 | # ifdef USE_LD_WRAP | |
1834 | # define STAT_READ __real_read | |
1835 | # else | |
1836 | # define STAT_READ read | |
9ec1e770 | 1837 | # endif |
155415a5 MV |
1838 | char stat_buf[STAT_BUF_SIZE]; |
1839 | int f; | |
1840 | char c; | |
1841 | word result = 0; | |
1842 | size_t i, buf_offset = 0; | |
1843 | ||
1844 | f = open("/proc/self/stat", O_RDONLY); | |
1845 | if (f < 0 || STAT_READ(f, stat_buf, STAT_BUF_SIZE) < 2 * STAT_SKIP) { | |
1846 | ABORT("Couldn't read /proc/self/stat"); | |
1847 | } | |
1848 | c = stat_buf[buf_offset++]; | |
1849 | /* Skip the required number of fields. This number is hopefully */ | |
1850 | /* constant across all Linux implementations. */ | |
1851 | for (i = 0; i < STAT_SKIP; ++i) { | |
1852 | while (isspace(c)) c = stat_buf[buf_offset++]; | |
1853 | while (!isspace(c)) c = stat_buf[buf_offset++]; | |
1854 | } | |
1855 | while (isspace(c)) c = stat_buf[buf_offset++]; | |
1856 | while (isdigit(c)) { | |
1857 | result *= 10; | |
1858 | result += c - '0'; | |
1859 | c = stat_buf[buf_offset++]; | |
1860 | } | |
1861 | close(f); | |
1862 | if (result < 0x10000000) ABORT("Absurd stack bottom value"); | |
1863 | return (ptr_t)result; | |
1864 | } | |
1865 | ||
1866 | #endif /* LINUX_STACKBOTTOM */ | |
1867 | ||
1868 | void *scm_get_stack_base() | |
9500b5b9 | 1869 | { |
155415a5 MV |
1870 | word dummy; |
1871 | void *result = &dummy; /* initialize to silence compiler */ | |
1872 | ||
1873 | # define STACKBOTTOM_ALIGNMENT_M1 ((word)STACK_GRAN - 1) | |
1874 | ||
1875 | # ifdef STACKBOTTOM | |
1876 | return(STACKBOTTOM); | |
1877 | # else | |
1878 | # ifdef HEURISTIC1 | |
91b17416 | 1879 | # if STACK_GROWS_DOWN |
155415a5 MV |
1880 | result = (ptr_t)((((word)(&dummy)) |
1881 | + STACKBOTTOM_ALIGNMENT_M1) | |
1882 | & ~STACKBOTTOM_ALIGNMENT_M1); | |
1883 | # else | |
1884 | result = (ptr_t)(((word)(&dummy)) | |
1885 | & ~STACKBOTTOM_ALIGNMENT_M1); | |
1886 | # endif | |
1887 | # endif /* HEURISTIC1 */ | |
1888 | # ifdef LINUX_STACKBOTTOM | |
1889 | result = GC_linux_stack_base(); | |
1890 | # endif | |
1891 | # ifdef HEURISTIC2 | |
91b17416 | 1892 | # if STACK_GROWS_DOWN |
155415a5 MV |
1893 | result = GC_find_limit((ptr_t)(&dummy), TRUE); |
1894 | # ifdef HEURISTIC2_LIMIT | |
1895 | if (result > HEURISTIC2_LIMIT | |
1896 | && (ptr_t)(&dummy) < HEURISTIC2_LIMIT) { | |
1897 | result = HEURISTIC2_LIMIT; | |
1898 | } | |
1899 | # endif | |
1900 | # else | |
1901 | result = GC_find_limit((ptr_t)(&dummy), FALSE); | |
1902 | # ifdef HEURISTIC2_LIMIT | |
1903 | if (result < HEURISTIC2_LIMIT | |
1904 | && (ptr_t)(&dummy) > HEURISTIC2_LIMIT) { | |
1905 | result = HEURISTIC2_LIMIT; | |
1906 | } | |
1907 | # endif | |
1908 | # endif | |
1909 | ||
1910 | # endif /* HEURISTIC2 */ | |
91b17416 | 1911 | # if STACK_GROWS_DOWN |
155415a5 MV |
1912 | if (result == 0) result = (ptr_t)(signed_word)(-sizeof(ptr_t)); |
1913 | # endif | |
1914 | return(result); | |
1915 | # endif /* STACKBOTTOM */ | |
9500b5b9 | 1916 | } |
155415a5 MV |
1917 | |
1918 | # endif /* ! AMIGA */ | |
1919 | # endif /* ! OS2 */ | |
1920 | # endif /* ! MSWIN32 */ | |
8cbb63c7 MV |
1921 | |
1922 | #endif /* ! HAVE_LIBC_STACK_END */ |