Import boehm-gc snapshot, taken from
[official-gcc.git] / boehm-gc / include / private / gcconfig.h
blobc21c38ca32f258692e10e54e0b1c96b9f155e765
1 /*
2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
5 * Copyright (c) 2000-2004 Hewlett-Packard Development Company, L.P.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
18 * This header is private to the gc. It is almost always included from
19 * gc_priv.h. However it is possible to include it by itself if just the
20 * configuration macros are needed. In that
21 * case, a few declarations relying on types declared in gc_priv.h will be
22 * omitted.
25 #ifndef GCCONFIG_H
26 #define GCCONFIG_H
28 # ifndef GC_PRIVATE_H
29 /* Fake ptr_t declaration, just to avoid compilation errors. */
30 /* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
31 typedef struct GC_undefined_struct * ptr_t;
32 # include <stddef.h> /* For size_t etc. */
33 # endif
35 /* Machine dependent parameters. Some tuning parameters can be found */
36 /* near the top of gc_private.h. */
38 /* Machine specific parts contributed by various people. See README file. */
40 #if defined(__ANDROID__) && !defined(PLATFORM_ANDROID)
41 /* __ANDROID__ macro is defined by Android NDK gcc. */
42 # define PLATFORM_ANDROID 1
43 #endif
45 #if defined(__SYMBIAN32__) && !defined(SYMBIAN)
46 # define SYMBIAN
47 # ifdef __WINS__
48 # pragma data_seg(".data2")
49 # endif
50 #endif
52 /* First a unified test for Linux: */
53 # if (defined(linux) || defined(__linux__) || defined(PLATFORM_ANDROID)) \
54 && !defined(LINUX) && !defined(__native_client__)
55 # define LINUX
56 # endif
58 /* And one for NetBSD: */
59 # if defined(__NetBSD__)
60 # define NETBSD
61 # endif
63 /* And one for OpenBSD: */
64 # if defined(__OpenBSD__)
65 # define OPENBSD
66 # endif
68 /* And one for FreeBSD: */
69 # if (defined(__FreeBSD__) || defined(__DragonFly__) \
70 || defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
71 # define FREEBSD
72 # endif
74 /* And one for Darwin: */
75 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
76 # define DARWIN
77 # endif
79 /* Determine the machine type: */
80 # if defined(__native_client__)
81 # define NACL
82 # define I386
83 # define mach_type_known
84 # endif
85 # if defined(__arm) || defined(__arm__) || defined(__thumb__)
86 # define ARM32
87 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
88 && !defined(DARWIN) && !defined(_WIN32) && !defined(__CEGCC__) \
89 && !defined(SYMBIAN)
90 # define NOSYS
91 # define mach_type_known
92 # endif
93 # endif
94 # if defined(sun) && defined(mc68000)
95 # error SUNOS4 no longer supported
96 # endif
97 # if defined(hp9000s300)
98 # error M68K based HP machines no longer supported.
99 # endif
100 # if defined(OPENBSD) && defined(m68k)
101 /* FIXME: Should we remove this case? */
102 # define M68K
103 # define mach_type_known
104 # endif
105 # if defined(OPENBSD) && defined(__sparc__)
106 # define SPARC
107 # define mach_type_known
108 # endif
109 # if defined(OPENBSD) && defined(__arm__)
110 # define ARM32
111 # define mach_type_known
112 # endif
113 # if defined(OPENBSD) && defined(__sh__)
114 # define SH
115 # define mach_type_known
116 # endif
117 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
118 # define M68K
119 # define mach_type_known
120 # endif
121 # if defined(NETBSD) && defined(__powerpc__)
122 # define POWERPC
123 # define mach_type_known
124 # endif
125 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
126 # define ARM32
127 # define mach_type_known
128 # endif
129 # if defined(NETBSD) && defined(__sh__)
130 # define SH
131 # define mach_type_known
132 # endif
133 # if defined(vax) || 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(__NetBSD__) && defined(__vax__)
143 # define VAX
144 # define mach_type_known
145 # endif
146 # if defined(mips) || defined(__mips) || defined(_mips)
147 # define MIPS
148 # if defined(nec_ews) || defined(_nec_ews)
149 # define EWS4800
150 # endif
151 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD) \
152 && !defined(OPENBSD)
153 # if defined(ultrix) || defined(__ultrix)
154 # define ULTRIX
155 # else
156 # define IRIX5 /* or IRIX 6.X */
157 # endif
158 # endif /* !LINUX */
159 # if defined(__NetBSD__) && defined(__MIPSEL__)
160 # undef ULTRIX
161 # endif
162 # define mach_type_known
163 # endif
164 # if defined(DGUX) && (defined(i386) || defined(__i386__))
165 # define I386
166 # ifndef _USING_DGUX
167 # define _USING_DGUX
168 # endif
169 # define mach_type_known
170 # endif
171 # if defined(sequent) && (defined(i386) || defined(__i386__))
172 # define I386
173 # define SEQUENT
174 # define mach_type_known
175 # endif
176 # if defined(sun) && (defined(i386) || defined(__i386__))
177 # define I386
178 # define SOLARIS
179 # define mach_type_known
180 # endif
181 # if defined(sun) && defined(__amd64)
182 # define X86_64
183 # define SOLARIS
184 # define mach_type_known
185 # endif
186 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
187 # define I386
188 # define OS2
189 # define mach_type_known
190 # endif
191 # if defined(ibm032)
192 # error IBM PC/RT no longer supported.
193 # endif
194 # if defined(sun) && (defined(sparc) || defined(__sparc))
195 # define SPARC
196 /* Test for SunOS 5.x */
197 # include <errno.h>
198 # define SOLARIS
199 # define mach_type_known
200 # endif
201 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
202 && !defined(__OpenBSD__) && !defined(__NetBSD__) \
203 && !defined(__FreeBSD__) && !defined(__DragonFly__)
204 # define SPARC
205 # define DRSNX
206 # define mach_type_known
207 # endif
208 # if defined(_IBMR2)
209 # define POWERPC
210 # define AIX
211 # define mach_type_known
212 # endif
213 # if defined(__NetBSD__) && defined(__sparc__)
214 # define SPARC
215 # define mach_type_known
216 # endif
217 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
218 /* The above test may need refinement */
219 # define I386
220 # if defined(_SCO_ELF)
221 # define SCO_ELF
222 # else
223 # define SCO
224 # endif
225 # define mach_type_known
226 # endif
227 # if defined(_AUX_SOURCE)
228 # error A/UX no longer supported
229 # endif
230 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
231 || defined(hppa) || defined(__hppa__)
232 # define HP_PA
233 # if !defined(LINUX) && !defined(HPUX) && !defined(OPENBSD)
234 # define HPUX
235 # endif
236 # define mach_type_known
237 # endif
238 # if defined(__ia64) && (defined(_HPUX_SOURCE) || defined(__HP_aCC))
239 # define IA64
240 # ifndef HPUX
241 # define HPUX
242 # endif
243 # define mach_type_known
244 # endif
245 # if defined(__BEOS__) && defined(_X86_)
246 # define I386
247 # define BEOS
248 # define mach_type_known
249 # endif
250 # if defined(OPENBSD) && defined(__amd64__)
251 # define X86_64
252 # define mach_type_known
253 # endif
254 # if defined(LINUX) && (defined(i386) || defined(__i386__))
255 # define I386
256 # define mach_type_known
257 # endif
258 # if defined(LINUX) && defined(__x86_64__)
259 # define X86_64
260 # define mach_type_known
261 # endif
262 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
263 # define IA64
264 # define mach_type_known
265 # endif
266 # if defined(LINUX) && (defined(__arm) || defined(__arm__))
267 # define ARM32
268 # define mach_type_known
269 # endif
270 # if defined(LINUX) && defined(__cris__)
271 # ifndef CRIS
272 # define CRIS
273 # endif
274 # define mach_type_known
275 # endif
276 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) \
277 || defined(powerpc64) || defined(__powerpc64__))
278 # define POWERPC
279 # define mach_type_known
280 # endif
281 # if defined(LINUX) && defined(__mc68000__)
282 # define M68K
283 # define mach_type_known
284 # endif
285 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
286 # define SPARC
287 # define mach_type_known
288 # endif
289 # if defined(LINUX) && defined(__sh__)
290 # define SH
291 # define mach_type_known
292 # endif
293 # if defined(LINUX) && defined(__avr32__)
294 # define AVR32
295 # define mach_type_known
296 # endif
297 # if defined(LINUX) && defined(__m32r__)
298 # define M32R
299 # define mach_type_known
300 # endif
301 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
302 # define POWERPC
303 # define mach_type_known
304 # endif
305 # if defined(__alpha) || defined(__alpha__)
306 # define ALPHA
307 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
308 && !defined(FREEBSD)
309 # define OSF1 /* a.k.a Digital Unix */
310 # endif
311 # define mach_type_known
312 # endif
313 # if defined(_AMIGA) && !defined(AMIGA)
314 # define AMIGA
315 # endif
316 # ifdef AMIGA
317 # define M68K
318 # define mach_type_known
319 # endif
320 # if defined(THINK_C) \
321 || (defined(__MWERKS__) && !defined(__powerc) && !defined(SYMBIAN))
322 # define M68K
323 # define MACOS
324 # define mach_type_known
325 # endif
326 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__) \
327 && !defined(SYMBIAN)
328 # define POWERPC
329 # define MACOS
330 # define mach_type_known
331 # endif
332 # if defined(__OpenBSD__) && defined(__powerpc__)
333 # define POWERPC
334 # define OPENBSD
335 # define mach_type_known
336 # endif
337 # if defined(DARWIN)
338 # if defined(__ppc__) || defined(__ppc64__)
339 # define POWERPC
340 # define mach_type_known
341 # elif defined(__x86_64__) || defined(__x86_64)
342 # define X86_64
343 # define mach_type_known
344 # elif defined(__i386__)
345 # define I386
346 # define mach_type_known
347 # elif defined(__arm__)
348 # define ARM32
349 # define mach_type_known
350 # define DARWIN_DONT_PARSE_STACK
351 # endif
352 # endif
353 # if defined(__rtems__) && (defined(i386) || defined(__i386__))
354 # define I386
355 # define RTEMS
356 # define mach_type_known
357 # endif
358 # if defined(NeXT) && defined(mc68000)
359 # define M68K
360 # define NEXT
361 # define mach_type_known
362 # endif
363 # if defined(NeXT) && (defined(i386) || defined(__i386__))
364 # define I386
365 # define NEXT
366 # define mach_type_known
367 # endif
368 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
369 # define I386
370 # define OPENBSD
371 # define mach_type_known
372 # endif
373 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
374 # define I386
375 # define mach_type_known
376 # endif
377 # if defined(FREEBSD) && defined(__x86_64__)
378 # define X86_64
379 # define mach_type_known
380 # endif
381 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
382 # define I386
383 # define mach_type_known
384 # endif
385 # if defined(__NetBSD__) && defined(__x86_64__)
386 # define X86_64
387 # define mach_type_known
388 # endif
389 # if defined(FREEBSD) && defined(__sparc__)
390 # define SPARC
391 # define mach_type_known
392 # endif
393 # if defined(bsdi) && (defined(i386) || defined(__i386__))
394 # define I386
395 # define BSDI
396 # define mach_type_known
397 # endif
398 # if !defined(mach_type_known) && defined(__386BSD__)
399 # define I386
400 # define THREE86BSD
401 # define mach_type_known
402 # endif
403 # if defined(_CX_UX) && defined(_M88K)
404 # define M88K
405 # define CX_UX
406 # define mach_type_known
407 # endif
408 # if defined(DGUX) && defined(m88k)
409 # define M88K
410 /* DGUX defined */
411 # define mach_type_known
412 # endif
413 # if defined(_WIN32_WCE) || defined(__CEGCC__) || defined(__MINGW32CE__)
414 /* SH3, SH4, MIPS already defined for corresponding architectures */
415 # if defined(SH3) || defined(SH4)
416 # define SH
417 # endif
418 # if defined(x86) || defined(__i386__)
419 # define I386
420 # endif
421 # if defined(_M_ARM) || defined(ARM) || defined(_ARM_)
422 # define ARM32
423 # endif
424 # define MSWINCE
425 # define mach_type_known
426 # else
427 # if ((defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300)) \
428 || (defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__) \
429 && !defined(SYMBIAN))
430 # if defined(__LP64__) || defined(_WIN64)
431 # define X86_64
432 # else
433 # define I386
434 # endif
435 # define MSWIN32 /* or Win64 */
436 # define mach_type_known
437 # endif
438 # if defined(_MSC_VER) && defined(_M_IA64)
439 # define IA64
440 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
441 /* variants as a different platform. */
442 # endif
443 # endif
444 # if defined(__DJGPP__)
445 # define I386
446 # ifndef DJGPP
447 # define DJGPP /* MSDOS running the DJGPP port of GCC */
448 # endif
449 # define mach_type_known
450 # endif
451 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
452 # define I386
453 # define CYGWIN32
454 # define mach_type_known
455 # endif
456 # if defined(__MINGW32__) && !defined(mach_type_known)
457 # define I386
458 # define MSWIN32
459 # define mach_type_known
460 # endif
461 # if defined(__BORLANDC__)
462 # define I386
463 # define MSWIN32
464 # define mach_type_known
465 # endif
466 # if defined(_UTS) && !defined(mach_type_known)
467 # define S370
468 # define UTS4
469 # define mach_type_known
470 # endif
471 # if defined(__pj__)
472 # error PicoJava no longer supported
473 /* The implementation had problems, and I haven't heard of users */
474 /* in ages. If you want it resurrected, let me know. */
475 # endif
476 # if defined(__embedded__) && defined(PPC)
477 # define POWERPC
478 # define NOSYS
479 # define mach_type_known
480 # endif
482 # if defined(__WATCOMC__) && defined(__386__)
483 # define I386
484 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
485 # if defined(__OS2__)
486 # define OS2
487 # else
488 # if defined(__WINDOWS_386__) || defined(__NT__)
489 # define MSWIN32
490 # else
491 # define DOS4GW
492 # endif
493 # endif
494 # endif
495 # define mach_type_known
496 # endif
497 # if defined(__s390__) && defined(LINUX)
498 # define S390
499 # define mach_type_known
500 # endif
501 # if defined(__GNU__)
502 # if defined(__i386__)
503 /* The Debian Hurd running on generic PC */
504 # define HURD
505 # define I386
506 # define mach_type_known
507 # endif
508 # endif
509 # if defined(__TANDEM)
510 /* Nonstop S-series */
511 /* FIXME: Should recognize Integrity series? */
512 # define MIPS
513 # define NONSTOP
514 # define mach_type_known
515 # endif
516 # if defined(__hexagon__) && defined(LINUX)
517 # define HEXAGON
518 # define mach_type_known
519 # endif
521 # if defined(SYMBIAN)
522 # define mach_type_known
523 # endif
525 /* Feel free to add more clauses here */
527 /* Or manually define the machine type here. A machine type is */
528 /* characterized by the architecture. Some */
529 /* machine types are further subdivided by OS. */
530 /* Macros such as LINUX, FREEBSD, etc. distinguish them. */
531 /* SYSV on an M68K actually means A/UX. */
532 /* The distinction in these cases is usually the stack starting address */
533 # ifndef mach_type_known
534 # error "The collector has not been ported to this machine/OS combination."
535 # endif
536 /* Mapping is: M68K ==> Motorola 680X0 */
537 /* (NEXT, and SYSV (A/UX), */
538 /* MACOS and AMIGA variants) */
539 /* I386 ==> Intel 386 */
540 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
541 /* FREEBSD, THREE86BSD, MSWIN32, */
542 /* BSDI,SOLARIS, NEXT, other variants) */
543 /* NS32K ==> Encore Multimax */
544 /* MIPS ==> R2000 through R14K */
545 /* (many variants) */
546 /* VAX ==> DEC VAX */
547 /* (BSD, ULTRIX variants) */
548 /* HP_PA ==> HP9000/700 & /800 */
549 /* HP/UX, LINUX */
550 /* SPARC ==> SPARC v7/v8/v9 */
551 /* (SOLARIS, LINUX, DRSNX variants) */
552 /* ALPHA ==> DEC Alpha */
553 /* (OSF1 and LINUX variants) */
554 /* M88K ==> Motorola 88XX0 */
555 /* (CX_UX and DGUX) */
556 /* S370 ==> 370-like machine */
557 /* running Amdahl UTS4 */
558 /* S390 ==> 390-like machine */
559 /* running LINUX */
560 /* ARM32 ==> Intel StrongARM */
561 /* IA64 ==> Intel IPF */
562 /* (e.g. Itanium) */
563 /* (LINUX and HPUX) */
564 /* SH ==> Hitachi SuperH */
565 /* (LINUX & MSWINCE) */
566 /* X86_64 ==> AMD x86-64 */
567 /* POWERPC ==> IBM/Apple PowerPC */
568 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
569 /* LINUX, NETBSD, AIX, NOSYS */
570 /* variants) */
571 /* Handles 32 and 64-bit variants. */
572 /* CRIS ==> Axis Etrax */
573 /* M32R ==> Renesas M32R */
574 /* HEXAGON ==> Qualcomm Hexagon */
578 * For each architecture and OS, the following need to be defined:
580 * CPP_WORDSZ is a simple integer constant representing the word size.
581 * in bits. We assume byte addressability, where a byte has 8 bits.
582 * We also assume CPP_WORDSZ is either 32 or 64.
583 * (We care about the length of pointers, not hardware
584 * bus widths. Thus a 64 bit processor with a C compiler that uses
585 * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
587 * MACH_TYPE is a string representation of the machine type.
588 * OS_TYPE is analogous for the OS.
590 * ALIGNMENT is the largest N, such that
591 * all pointer are guaranteed to be aligned on N byte boundaries.
592 * defining it to be 1 will always work, but perform poorly.
594 * DATASTART is the beginning of the data segment.
595 * On some platforms SEARCH_FOR_DATA_START is defined.
596 * SEARCH_FOR_DATASTART will cause GC_data_start to
597 * be set to an address determined by accessing data backwards from _end
598 * until an unmapped page is found. DATASTART will be defined to be
599 * GC_data_start.
600 * On UNIX-like systems, the collector will scan the area between DATASTART
601 * and DATAEND for root pointers.
603 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
604 * RTH suggests gaining access to linker script synth'd values with
605 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
606 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
607 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
608 * without any special options.
610 * STACKBOTTOM is the cool end of the stack, which is usually the
611 * highest address in the stack.
612 * Under PCR or OS/2, we have other ways of finding thread stacks.
613 * For each machine, the following should:
614 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
615 * 2) define exactly one of
616 * STACKBOTTOM (should be defined to be an expression)
617 * LINUX_STACKBOTTOM
618 * HEURISTIC1
619 * HEURISTIC2
620 * If STACKBOTTOM is defined, then it's value will be used directly as the
621 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
622 * with a method appropriate for most Linux systems. Currently we look
623 * first for __libc_stack_end (currently only if USE_LIBC_PRIVATES is
624 * defined), and if that fails read it from /proc. (If USE_LIBC_PRIVATES
625 * is not defined and NO_PROC_STAT is defined, we revert to HEURISTIC2.)
626 * If either of the last two macros are defined, then STACKBOTTOM is computed
627 * during collector startup using one of the following two heuristics:
628 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
629 * the next multiple of STACK_GRAN.
630 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
631 * in small steps (decrement if STACK_GROWS_UP), and read the value
632 * at each location. Remember the value when the first
633 * Segmentation violation or Bus error is signaled. Round that
634 * to the nearest plausible page boundary, and use that instead
635 * of STACKBOTTOM.
637 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
638 * the value of environ is a pointer that can serve as STACKBOTTOM.
639 * I expect that HEURISTIC2 can be replaced by this approach, which
640 * interferes far less with debugging. However it has the disadvantage
641 * that it's confused by a putenv call before the collector is initialized.
642 * This could be dealt with by intercepting putenv ...
644 * If no expression for STACKBOTTOM can be found, and neither of the above
645 * heuristics are usable, the collector can still be used with all of the above
646 * undefined, provided one of the following is done:
647 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
648 * without reference to STACKBOTTOM. This is appropriate for use in
649 * conjunction with thread packages, since there will be multiple stacks.
650 * (Allocating thread stacks in the heap, and treating them as ordinary
651 * heap data objects is also possible as a last resort. However, this is
652 * likely to introduce significant amounts of excess storage retention
653 * unless the dead parts of the thread stacks are periodically cleared.)
654 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
655 * If the author of the client code controls the main program, this is
656 * easily accomplished by introducing a new main program, setting
657 * GC_stackbottom to the address of a local variable, and then calling
658 * the original main program. The new main program would read something
659 * like (provided real_main() is not inlined by the compiler):
661 * # include "gc_private.h"
663 * main(argc, argv, envp)
664 * int argc;
665 * char **argv, **envp;
667 * volatile int dummy;
669 * GC_stackbottom = (ptr_t)(&dummy);
670 * return(real_main(argc, argv, envp));
674 * Each architecture may also define the style of virtual dirty bit
675 * implementation to be used:
676 * MPROTECT_VDB: Write protect the heap and catch faults.
677 * GWW_VDB: Use win32 GetWriteWatch primitive.
678 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
680 * The first and second one may be combined, in which case a runtime
681 * selection will be made, based on GetWriteWatch availability.
683 * An architecture may define DYNAMIC_LOADING if dyn_load.c
684 * defined GC_register_dynamic_libraries() for the architecture.
686 * An architecture may define PREFETCH(x) to preload the cache with *x.
687 * This defaults to a no-op.
689 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
691 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
692 * clear the two words at GC_malloc-aligned address x. By default,
693 * word stores of 0 are used instead.
695 * HEAP_START may be defined as the initial address hint for mmap-based
696 * allocation.
699 /* If we are using a recent version of gcc, we can use */
700 /* __builtin_unwind_init() to push the relevant registers onto the stack. */
701 # if defined(__GNUC__) && ((__GNUC__ >= 3) \
702 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
703 && !defined(__INTEL_COMPILER) && !defined(__PATHCC__) \
704 && !(defined(POWERPC) && defined(DARWIN)) /* for MacOS X 10.3.9 */ \
705 && !defined(RTEMS) \
706 && !defined(__clang__) /* since no-op in clang (3.0) */
707 # define HAVE_BUILTIN_UNWIND_INIT
708 # endif
710 # ifdef SYMBIAN
711 # define MACH_TYPE "SYMBIAN"
712 # define OS_TYPE "SYMBIAN"
713 # define CPP_WORDSZ 32
714 # define ALIGNMENT 4
715 # define DATASTART NULL
716 # define DATAEND NULL
717 # endif
719 # define STACK_GRAN 0x1000000
720 # ifdef M68K
721 # define MACH_TYPE "M68K"
722 # define ALIGNMENT 2
723 # ifdef OPENBSD
724 /* FIXME: Should we remove this case? */
725 # define OS_TYPE "OPENBSD"
726 # define HEURISTIC2
727 # ifdef __ELF__
728 extern ptr_t GC_data_start;
729 # define DATASTART GC_data_start
730 # define DYNAMIC_LOADING
731 # else
732 extern char etext[];
733 # define DATASTART ((ptr_t)(etext))
734 # endif
735 # endif
736 # ifdef NETBSD
737 # define OS_TYPE "NETBSD"
738 # define HEURISTIC2
739 # ifdef __ELF__
740 extern ptr_t GC_data_start;
741 # define DATASTART GC_data_start
742 # define DYNAMIC_LOADING
743 # else
744 extern char etext[];
745 # define DATASTART ((ptr_t)(etext))
746 # endif
747 # endif
748 # ifdef LINUX
749 # define OS_TYPE "LINUX"
750 # define LINUX_STACKBOTTOM
751 # define MPROTECT_VDB
752 # ifdef __ELF__
753 # define DYNAMIC_LOADING
754 # include <features.h>
755 # if defined(__GLIBC__) && __GLIBC__ >= 2
756 # define SEARCH_FOR_DATA_START
757 # else /* !GLIBC2 */
758 # ifdef PLATFORM_ANDROID
759 # define __environ environ
760 # endif
761 extern char **__environ;
762 # define DATASTART ((ptr_t)(&__environ))
763 /* hideous kludge: __environ is the first */
764 /* word in crt0.o, and delimits the start */
765 /* of the data segment, no matter which */
766 /* ld options were passed through. */
767 /* We could use _etext instead, but that */
768 /* would include .rodata, which may */
769 /* contain large read-only data tables */
770 /* that we'd rather not scan. */
771 # endif /* !GLIBC2 */
772 extern int _end[];
773 # define DATAEND (ptr_t)(_end)
774 # else
775 extern int etext[];
776 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
777 # endif
778 # endif
779 # ifdef AMIGA
780 # define OS_TYPE "AMIGA"
781 /* STACKBOTTOM and DATASTART handled specially */
782 /* in os_dep.c */
783 # define DATAEND /* not needed */
784 # define GETPAGESIZE() 4096
785 # endif
786 # ifdef MACOS
787 # ifndef __LOWMEM__
788 # include <LowMem.h>
789 # endif
790 # define OS_TYPE "MACOS"
791 /* see os_dep.c for details of global data segments. */
792 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
793 # define DATAEND /* not needed */
794 # define GETPAGESIZE() 4096
795 # endif
796 # ifdef NEXT
797 # define OS_TYPE "NEXT"
798 # define DATASTART ((ptr_t) get_etext())
799 # define DATASTART_IS_FUNC
800 # define STACKBOTTOM ((ptr_t) 0x4000000)
801 # define DATAEND /* not needed */
802 # endif
803 # endif
805 # if defined(POWERPC)
806 # define MACH_TYPE "POWERPC"
807 # ifdef MACOS
808 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
809 # ifndef __LOWMEM__
810 # include <LowMem.h>
811 # endif
812 # define OS_TYPE "MACOS"
813 /* see os_dep.c for details of global data segments. */
814 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
815 # define DATAEND /* not needed */
816 # endif
817 # ifdef LINUX
818 # if defined(__powerpc64__)
819 # define ALIGNMENT 8
820 # define CPP_WORDSZ 64
821 # ifndef HBLKSIZE
822 # define HBLKSIZE 4096
823 # endif
824 # else
825 # define ALIGNMENT 4
826 # endif
827 # define OS_TYPE "LINUX"
828 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
829 /* executable on a 64 bit kernel. */
830 # define LINUX_STACKBOTTOM
831 # define DYNAMIC_LOADING
832 # define SEARCH_FOR_DATA_START
833 extern int _end[];
834 # define DATAEND (ptr_t)(_end)
835 # endif
836 # ifdef DARWIN
837 # define OS_TYPE "DARWIN"
838 # define DYNAMIC_LOADING
839 # if defined(__ppc64__)
840 # define ALIGNMENT 8
841 # define CPP_WORDSZ 64
842 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
843 # define CACHE_LINE_SIZE 64
844 # ifndef HBLKSIZE
845 # define HBLKSIZE 4096
846 # endif
847 # else
848 # define ALIGNMENT 4
849 # define STACKBOTTOM ((ptr_t) 0xc0000000)
850 # endif
851 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
852 /* These aren't used when dyld support is enabled (it is by default). */
853 # define DATASTART ((ptr_t) get_etext())
854 # define DATAEND ((ptr_t) get_end())
855 # ifndef USE_MMAP
856 # define USE_MMAP
857 # endif
858 # define USE_MMAP_ANON
859 # define MPROTECT_VDB
860 # include <unistd.h>
861 # define GETPAGESIZE() getpagesize()
862 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
863 /* The performance impact of prefetches is untested */
864 # define PREFETCH(x) \
865 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
866 # define PREFETCH_FOR_WRITE(x) \
867 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
868 # endif
869 /* There seems to be some issues with trylock hanging on darwin. */
870 /* This should be looked into some more. */
871 # define NO_PTHREAD_TRYLOCK
872 # endif
873 # ifdef OPENBSD
874 # define OS_TYPE "OPENBSD"
875 # define ALIGNMENT 4
876 # ifdef GC_OPENBSD_THREADS
877 # define UTHREAD_SP_OFFSET 268
878 # else
879 # include <sys/param.h>
880 # include <uvm/uvm_extern.h>
881 # define STACKBOTTOM ((ptr_t) USRSTACK)
882 # endif
883 extern int __data_start[];
884 # define DATASTART ((ptr_t)__data_start)
885 extern char _end[];
886 # define DATAEND ((ptr_t)(&_end))
887 # define DYNAMIC_LOADING
888 # endif
889 # ifdef FREEBSD
890 # if defined(__powerpc64__)
891 # define ALIGNMENT 8
892 # define CPP_WORDSZ 64
893 # ifndef HBLKSIZE
894 # define HBLKSIZE 4096
895 # endif
896 # else
897 # define ALIGNMENT 4
898 # endif
899 # define OS_TYPE "FREEBSD"
900 # ifndef GC_FREEBSD_THREADS
901 # define MPROTECT_VDB
902 # endif
903 # define SIG_SUSPEND SIGUSR1
904 # define SIG_THR_RESTART SIGUSR2
905 # define FREEBSD_STACKBOTTOM
906 # ifdef __ELF__
907 # define DYNAMIC_LOADING
908 # endif
909 extern char etext[];
910 ptr_t GC_FreeBSDGetDataStart(size_t, ptr_t);
911 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
912 # define DATASTART_IS_FUNC
913 # endif
914 # ifdef NETBSD
915 # define ALIGNMENT 4
916 # define OS_TYPE "NETBSD"
917 # define HEURISTIC2
918 extern ptr_t GC_data_start;
919 # define DATASTART GC_data_start
920 # define DYNAMIC_LOADING
921 # endif
922 # ifdef SN_TARGET_PS3
923 # define NO_GETENV
924 # define CPP_WORDSZ 32
925 # define ALIGNMENT 4
926 extern int _end [];
927 extern int __bss_start;
928 # define DATAEND (ptr_t)(_end)
929 # define DATASTART (ptr_t)(__bss_start)
930 # define STACKBOTTOM ((ptr_t)ps3_get_stack_bottom())
931 # define NO_PTHREAD_TRYLOCK
932 /* Current GC LOCK() implementation for PS3 explicitly */
933 /* use pthread_mutex_lock for some reason. */
934 # endif
935 # ifdef AIX
936 # define OS_TYPE "AIX"
937 # undef ALIGNMENT /* in case it's defined */
938 # undef IA64
939 /* DOB: some AIX installs stupidly define IA64 in */
940 /* /usr/include/sys/systemcfg.h */
941 # ifdef __64BIT__
942 # define ALIGNMENT 8
943 # define CPP_WORDSZ 64
944 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
945 # else
946 # define ALIGNMENT 4
947 # define CPP_WORDSZ 32
948 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
949 # endif
950 # ifndef USE_MMAP
951 # define USE_MMAP
952 # endif
953 # define USE_MMAP_ANON
954 /* From AIX linker man page:
955 _text Specifies the first location of the program.
956 _etext Specifies the first location after the program.
957 _data Specifies the first location of the data.
958 _edata Specifies the first location after the initialized data
959 _end or end Specifies the first location after all data.
961 extern int _data[], _end[];
962 # define DATASTART ((ptr_t)((ulong)_data))
963 # define DATAEND ((ptr_t)((ulong)_end))
964 extern int errno;
965 # define DYNAMIC_LOADING
966 /* For really old versions of AIX, this may have to be removed. */
967 # endif
969 # ifdef NOSYS
970 # define ALIGNMENT 4
971 # define OS_TYPE "NOSYS"
972 extern void __end[], __dso_handle[];
973 # define DATASTART (__dso_handle) /* OK, that's ugly. */
974 # define DATAEND (ptr_t)(__end)
975 /* Stack starts at 0xE0000000 for the simulator. */
976 # undef STACK_GRAN
977 # define STACK_GRAN 0x10000000
978 # define HEURISTIC1
979 # endif
980 # endif
982 # ifdef VAX
983 # define MACH_TYPE "VAX"
984 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
985 extern char etext[];
986 # define DATASTART ((ptr_t)(etext))
987 # ifdef BSD
988 # define OS_TYPE "BSD"
989 # define HEURISTIC1
990 /* HEURISTIC2 may be OK, but it's hard to test. */
991 # endif
992 # ifdef ULTRIX
993 # define OS_TYPE "ULTRIX"
994 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
995 # endif
996 # endif
998 # ifdef SPARC
999 # define MACH_TYPE "SPARC"
1000 # if defined(__arch64__) || defined(__sparcv9)
1001 # define ALIGNMENT 8
1002 # define CPP_WORDSZ 64
1003 # define ELF_CLASS ELFCLASS64
1004 # else
1005 # define ALIGNMENT 4 /* Required by hardware */
1006 # define CPP_WORDSZ 32
1007 # endif
1008 /* Don't define USE_ASM_PUSH_REGS. We do use an asm helper, but */
1009 /* not to push the registers on the mark stack. */
1010 # ifdef SOLARIS
1011 # define OS_TYPE "SOLARIS"
1012 extern int _etext[];
1013 extern int _end[];
1014 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1015 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1016 # define DATASTART_IS_FUNC
1017 # define DATAEND (ptr_t)(_end)
1018 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1019 # define USE_MMAP
1020 /* Otherwise we now use calloc. Mmap may result in the */
1021 /* heap interleaved with thread stacks, which can result in */
1022 /* excessive blacklisting. Sbrk is unusable since it */
1023 /* doesn't interact correctly with the system malloc. */
1024 # endif
1025 # ifdef USE_MMAP
1026 # define HEAP_START (ptr_t)0x40000000
1027 # else
1028 # define HEAP_START DATAEND
1029 # endif
1030 # define PROC_VDB
1031 /* HEURISTIC1 reportedly no longer works under 2.7. */
1032 /* HEURISTIC2 probably works, but this appears to be preferable. */
1033 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
1034 /* installations that's undefined. We work around this with a */
1035 /* gross hack: */
1036 # include <sys/vmparam.h>
1037 # ifdef USERLIMIT
1038 /* This should work everywhere, but doesn't. */
1039 # define STACKBOTTOM ((ptr_t) USRSTACK)
1040 # else
1041 # define HEURISTIC2
1042 # endif
1043 # include <unistd.h>
1044 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1045 /* getpagesize() appeared to be missing from at least one */
1046 /* Solaris 5.4 installation. Weird. */
1047 # define DYNAMIC_LOADING
1048 # endif
1049 # ifdef DRSNX
1050 # define OS_TYPE "DRSNX"
1051 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1052 extern int etext[];
1053 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
1054 # define DATASTART_IS_FUNC
1055 # define MPROTECT_VDB
1056 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
1057 # define DYNAMIC_LOADING
1058 # endif
1059 # ifdef LINUX
1060 # define OS_TYPE "LINUX"
1061 # ifdef __ELF__
1062 # define DYNAMIC_LOADING
1063 # else
1064 Linux Sparc/a.out not supported
1065 # endif
1066 extern int _end[];
1067 extern int _etext[];
1068 # define DATAEND (ptr_t)(_end)
1069 # define SVR4
1070 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1071 # ifdef __arch64__
1072 # define DATASTART GC_SysVGetDataStart(0x100000, (ptr_t)_etext)
1073 # else
1074 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1075 # endif
1076 # define DATASTART_IS_FUNC
1077 # define LINUX_STACKBOTTOM
1078 # endif
1079 # ifdef OPENBSD
1080 # define OS_TYPE "OPENBSD"
1081 # ifdef GC_OPENBSD_THREADS
1082 # define UTHREAD_SP_OFFSET 232
1083 # else
1084 # include <sys/param.h>
1085 # include <uvm/uvm_extern.h>
1086 # define STACKBOTTOM ((ptr_t) USRSTACK)
1087 # endif
1088 extern int __data_start[];
1089 # define DATASTART ((ptr_t)__data_start)
1090 extern char _end[];
1091 # define DATAEND ((ptr_t)(&_end))
1092 # define DYNAMIC_LOADING
1093 # endif
1094 # ifdef NETBSD
1095 # define OS_TYPE "NETBSD"
1096 # define HEURISTIC2
1097 # ifdef __ELF__
1098 extern ptr_t GC_data_start;
1099 # define DATASTART GC_data_start
1100 # define DYNAMIC_LOADING
1101 # else
1102 extern char etext[];
1103 # define DATASTART ((ptr_t)(etext))
1104 # endif
1105 # endif
1106 # ifdef FREEBSD
1107 # define OS_TYPE "FREEBSD"
1108 # define SIG_SUSPEND SIGUSR1
1109 # define SIG_THR_RESTART SIGUSR2
1110 # define FREEBSD_STACKBOTTOM
1111 # ifdef __ELF__
1112 # define DYNAMIC_LOADING
1113 # endif
1114 extern char etext[];
1115 extern char edata[];
1116 extern char end[];
1117 # define NEED_FIND_LIMIT
1118 # define DATASTART ((ptr_t)(&etext))
1119 ptr_t GC_find_limit(ptr_t, GC_bool);
1120 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1121 # define DATAEND_IS_FUNC
1122 # define DATASTART2 ((ptr_t)(&edata))
1123 # define DATAEND2 ((ptr_t)(&end))
1124 # endif
1125 # endif
1127 # ifdef I386
1128 # define MACH_TYPE "I386"
1129 # if defined(__LP64__) || defined(_WIN64)
1130 # error This should be handled as X86_64
1131 # else
1132 # define CPP_WORDSZ 32
1133 # define ALIGNMENT 4
1134 /* Appears to hold for all "32 bit" compilers */
1135 /* except Borland. The -a4 option fixes */
1136 /* Borland. For Watcom the option is -zp4. */
1137 # endif
1138 # ifdef SEQUENT
1139 # define OS_TYPE "SEQUENT"
1140 extern int etext[];
1141 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1142 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1143 # endif
1144 # ifdef BEOS
1145 # define OS_TYPE "BEOS"
1146 # include <OS.h>
1147 # define GETPAGESIZE() B_PAGE_SIZE
1148 extern int etext[];
1149 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1150 # endif
1151 # ifdef SOLARIS
1152 # define OS_TYPE "SOLARIS"
1153 extern int _etext[], _end[];
1154 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1155 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
1156 # define DATASTART_IS_FUNC
1157 # define DATAEND (ptr_t)(_end)
1158 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1159 /* but reportedly breaks under 2.8. It appears that the stack */
1160 /* base is a property of the executable, so this should not break */
1161 /* old executables. */
1162 /* HEURISTIC2 probably works, but this appears to be preferable. */
1163 # include <sys/vm.h>
1164 # define STACKBOTTOM ((ptr_t) USRSTACK)
1165 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1166 /* It appears to be fixed in 2.8 and 2.9. */
1167 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1168 # define PROC_VDB
1169 # endif
1170 # ifndef GC_THREADS
1171 # define MPROTECT_VDB
1172 # endif
1173 # define DYNAMIC_LOADING
1174 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1175 # define USE_MMAP
1176 /* Otherwise we now use calloc. Mmap may result in the */
1177 /* heap interleaved with thread stacks, which can result in */
1178 /* excessive blacklisting. Sbrk is unusable since it */
1179 /* doesn't interact correctly with the system malloc. */
1180 # endif
1181 # ifdef USE_MMAP
1182 # define HEAP_START (ptr_t)0x40000000
1183 # else
1184 # define HEAP_START DATAEND
1185 # endif
1186 # endif
1187 # ifdef SCO
1188 # define OS_TYPE "SCO"
1189 extern int etext[];
1190 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1191 & ~0x3fffff) \
1192 +((word)etext & 0xfff))
1193 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1194 # endif
1195 # ifdef SCO_ELF
1196 # define OS_TYPE "SCO_ELF"
1197 extern int etext[];
1198 # define DATASTART ((ptr_t)(etext))
1199 # define STACKBOTTOM ((ptr_t) 0x08048000)
1200 # define DYNAMIC_LOADING
1201 # define ELF_CLASS ELFCLASS32
1202 # endif
1203 # ifdef DGUX
1204 # define OS_TYPE "DGUX"
1205 extern int _etext, _end;
1206 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1207 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)(&_etext))
1208 # define DATASTART_IS_FUNC
1209 # define DATAEND (ptr_t)(&_end)
1210 # define STACK_GROWS_DOWN
1211 # define HEURISTIC2
1212 # include <unistd.h>
1213 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1214 # define DYNAMIC_LOADING
1215 # ifndef USE_MMAP
1216 # define USE_MMAP
1217 # endif
1218 # define MAP_FAILED (void *) ((word)-1)
1219 # ifdef USE_MMAP
1220 # define HEAP_START (ptr_t)0x40000000
1221 # else
1222 # define HEAP_START DATAEND
1223 # endif
1224 # endif /* DGUX */
1226 # ifdef NACL
1227 # define OS_TYPE "NACL"
1228 extern int etext[];
1229 /* #define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff)) */
1230 # define DATASTART ((ptr_t)0x10000000)
1231 extern int _end[];
1232 # define DATAEND (_end)
1233 # undef STACK_GRAN
1234 # define STACK_GRAN 0x10000
1235 # define HEURISTIC1
1236 # define GETPAGESIZE() 65536
1237 # ifndef MAX_NACL_GC_THREADS
1238 # define MAX_NACL_GC_THREADS 1024
1239 # endif
1240 # endif /* NACL */
1242 # ifdef LINUX
1243 # define OS_TYPE "LINUX"
1244 # define LINUX_STACKBOTTOM
1245 # if 0
1246 # define HEURISTIC1
1247 # undef STACK_GRAN
1248 # define STACK_GRAN 0x10000000
1249 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1250 /* different kernel configurations. In particular, systems */
1251 /* with 2GB physical memory will usually move the user */
1252 /* address space limit, and hence initial SP to 0x80000000. */
1253 # endif
1254 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1255 # define MPROTECT_VDB
1256 # else
1257 /* We seem to get random errors in incremental mode, */
1258 /* possibly because Linux threads is itself a malloc client */
1259 /* and can't deal with the signals. */
1260 # endif
1261 # define HEAP_START (ptr_t)0x1000
1262 /* This encourages mmap to give us low addresses, */
1263 /* thus allowing the heap to grow to ~3GB */
1264 # ifdef __ELF__
1265 # define DYNAMIC_LOADING
1266 # ifdef UNDEFINED /* includes ro data */
1267 extern int _etext[];
1268 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1269 # endif
1270 # include <features.h>
1271 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1272 || defined(PLATFORM_ANDROID)
1273 # define SEARCH_FOR_DATA_START
1274 # else
1275 extern char **__environ;
1276 # define DATASTART ((ptr_t)(&__environ))
1277 /* hideous kludge: __environ is the first */
1278 /* word in crt0.o, and delimits the start */
1279 /* of the data segment, no matter which */
1280 /* ld options were passed through. */
1281 /* We could use _etext instead, but that */
1282 /* would include .rodata, which may */
1283 /* contain large read-only data tables */
1284 /* that we'd rather not scan. */
1285 # endif
1286 extern int _end[];
1287 # define DATAEND (ptr_t)(_end)
1288 # if defined(PLATFORM_ANDROID) && !defined(GC_NO_SIGSETJMP)
1289 /* As of Android NDK r8b, _sigsetjmp is still missing */
1290 /* for x86 (setjmp is used instead to find data_start). */
1291 # define GC_NO_SIGSETJMP
1292 # endif
1293 # else
1294 extern int etext[];
1295 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1296 # endif
1297 # ifdef USE_I686_PREFETCH
1298 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1299 /* for the next rtelease. */
1300 # define PREFETCH(x) \
1301 __asm__ __volatile__ ("prefetchnta %0" : : "m"(*(char *)(x)))
1302 /* Empirically prefetcht0 is much more effective at reducing */
1303 /* cache miss stalls for the targeted load instructions. But it */
1304 /* seems to interfere enough with other cache traffic that the */
1305 /* net result is worse than prefetchnta. */
1306 # ifdef FORCE_WRITE_PREFETCH
1307 /* Using prefetches for write seems to have a slight negative */
1308 /* impact on performance, at least for a PIII/500. */
1309 # define PREFETCH_FOR_WRITE(x) \
1310 __asm__ __volatile__ ("prefetcht0 %0" : : "m"(*(char *)(x)))
1311 # endif
1312 # endif
1313 # ifdef USE_3DNOW_PREFETCH
1314 # define PREFETCH(x) \
1315 __asm__ __volatile__ ("prefetch %0" : : "m"(*(char *)(x)))
1316 # define PREFETCH_FOR_WRITE(x) \
1317 __asm__ __volatile__ ("prefetchw %0" : : "m"(*(char *)(x)))
1318 # endif
1319 # endif
1320 # ifdef CYGWIN32
1321 # define OS_TYPE "CYGWIN32"
1322 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1323 # define DATAEND ((ptr_t)GC_DATAEND)
1324 # undef STACK_GRAN
1325 # define STACK_GRAN 0x10000
1326 # ifdef USE_MMAP
1327 # define NEED_FIND_LIMIT
1328 # define USE_MMAP_ANON
1329 # endif
1330 # endif
1331 # ifdef OS2
1332 # define OS_TYPE "OS2"
1333 /* STACKBOTTOM and DATASTART are handled specially in */
1334 /* os_dep.c. OS2 actually has the right */
1335 /* system call! */
1336 # define DATAEND /* not needed */
1337 # endif
1338 # ifdef MSWIN32
1339 # define OS_TYPE "MSWIN32"
1340 /* STACKBOTTOM and DATASTART are handled specially in */
1341 /* os_dep.c. */
1342 # define MPROTECT_VDB
1343 # define GWW_VDB
1344 # define DATAEND /* not needed */
1345 # endif
1346 # ifdef MSWINCE
1347 # define OS_TYPE "MSWINCE"
1348 # define DATAEND /* not needed */
1349 # endif
1350 # ifdef DJGPP
1351 # define OS_TYPE "DJGPP"
1352 # include "stubinfo.h"
1353 extern int etext[];
1354 extern int _stklen;
1355 extern int __djgpp_stack_limit;
1356 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1357 /* #define STACKBOTTOM ((ptr_t)((word)_stubinfo+_stubinfo->size+_stklen)) */
1358 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1359 /* This may not be right. */
1360 # endif
1361 # ifdef OPENBSD
1362 # define OS_TYPE "OPENBSD"
1363 # ifdef GC_OPENBSD_THREADS
1364 # define UTHREAD_SP_OFFSET 176
1365 # else
1366 # include <sys/param.h>
1367 # include <uvm/uvm_extern.h>
1368 # define STACKBOTTOM ((ptr_t) USRSTACK)
1369 # endif
1370 extern int __data_start[];
1371 # define DATASTART ((ptr_t)__data_start)
1372 extern char _end[];
1373 # define DATAEND ((ptr_t)(&_end))
1374 # define DYNAMIC_LOADING
1375 # endif
1376 # ifdef FREEBSD
1377 # define OS_TYPE "FREEBSD"
1378 # ifndef GC_FREEBSD_THREADS
1379 # define MPROTECT_VDB
1380 # endif
1381 # ifdef __GLIBC__
1382 # define SIG_SUSPEND (32+6)
1383 # define SIG_THR_RESTART (32+5)
1384 extern int _end[];
1385 # define DATAEND (ptr_t)(_end)
1386 # else
1387 # define SIG_SUSPEND SIGUSR1
1388 # define SIG_THR_RESTART SIGUSR2
1389 /* SIGTSTP and SIGCONT could be used alternatively. */
1390 # endif
1391 # define FREEBSD_STACKBOTTOM
1392 # ifdef __ELF__
1393 # define DYNAMIC_LOADING
1394 # endif
1395 extern char etext[];
1396 char * GC_FreeBSDGetDataStart(size_t, ptr_t);
1397 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
1398 # define DATASTART_IS_FUNC
1399 # endif
1400 # ifdef NETBSD
1401 # define OS_TYPE "NETBSD"
1402 # ifdef __ELF__
1403 # define DYNAMIC_LOADING
1404 # endif
1405 # endif
1406 # ifdef THREE86BSD
1407 # define OS_TYPE "THREE86BSD"
1408 # endif
1409 # ifdef BSDI
1410 # define OS_TYPE "BSDI"
1411 # endif
1412 # if defined(NETBSD) || defined(THREE86BSD) || defined(BSDI)
1413 # define HEURISTIC2
1414 extern char etext[];
1415 # define DATASTART ((ptr_t)(etext))
1416 # endif
1417 # ifdef NEXT
1418 # define OS_TYPE "NEXT"
1419 # define DATASTART ((ptr_t) get_etext())
1420 # define DATASTART_IS_FUNC
1421 # define STACKBOTTOM ((ptr_t)0xc0000000)
1422 # define DATAEND /* not needed */
1423 # endif
1424 # ifdef RTEMS
1425 # define OS_TYPE "RTEMS"
1426 # include <sys/unistd.h>
1427 extern int etext[];
1428 extern int end[];
1429 void *rtems_get_stack_bottom(void);
1430 # define InitStackBottom rtems_get_stack_bottom()
1431 # define DATASTART ((ptr_t)etext)
1432 # define DATAEND ((ptr_t)end)
1433 # define STACKBOTTOM ((ptr_t)InitStackBottom)
1434 # define SIG_SUSPEND SIGUSR1
1435 # define SIG_THR_RESTART SIGUSR2
1436 # endif
1437 # ifdef DOS4GW
1438 # define OS_TYPE "DOS4GW"
1439 extern long __nullarea;
1440 extern char _end;
1441 extern char *_STACKTOP;
1442 /* Depending on calling conventions Watcom C either precedes */
1443 /* or does not precedes with underscore names of C-variables. */
1444 /* Make sure startup code variables always have the same names. */
1445 #pragma aux __nullarea "*";
1446 #pragma aux _end "*";
1447 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1448 /* confused? me too. */
1449 # define DATASTART ((ptr_t) &__nullarea)
1450 # define DATAEND ((ptr_t) &_end)
1451 # endif
1452 # ifdef HURD
1453 # define OS_TYPE "HURD"
1454 # define STACK_GROWS_DOWN
1455 # define HEURISTIC2
1456 # define SIG_SUSPEND SIGUSR1
1457 # define SIG_THR_RESTART SIGUSR2
1458 # define SEARCH_FOR_DATA_START
1459 extern int _end[];
1460 # define DATAEND ((ptr_t) (_end))
1461 /* # define MPROTECT_VDB Not quite working yet? */
1462 # define DYNAMIC_LOADING
1463 # endif
1464 # ifdef DARWIN
1465 # define OS_TYPE "DARWIN"
1466 # define DARWIN_DONT_PARSE_STACK
1467 # define DYNAMIC_LOADING
1468 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
1469 /* These aren't used when dyld support is enabled (it is by default). */
1470 # define DATASTART ((ptr_t) get_etext())
1471 # define DATAEND ((ptr_t) get_end())
1472 # define STACKBOTTOM ((ptr_t) 0xc0000000)
1473 # ifndef USE_MMAP
1474 # define USE_MMAP
1475 # endif
1476 # define USE_MMAP_ANON
1477 # define MPROTECT_VDB
1478 # include <unistd.h>
1479 # define GETPAGESIZE() getpagesize()
1480 /* There seems to be some issues with trylock hanging on darwin. */
1481 /* This should be looked into some more. */
1482 # define NO_PTHREAD_TRYLOCK
1483 # endif /* DARWIN */
1484 # endif
1486 # ifdef NS32K
1487 # define MACH_TYPE "NS32K"
1488 # define ALIGNMENT 4
1489 extern char **environ;
1490 # define DATASTART ((ptr_t)(&environ))
1491 /* hideous kludge: environ is the first */
1492 /* word in crt0.o, and delimits the start */
1493 /* of the data segment, no matter which */
1494 /* ld options were passed through. */
1495 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1496 # endif
1498 # ifdef MIPS
1499 # define MACH_TYPE "MIPS"
1500 # ifdef LINUX
1501 # define OS_TYPE "LINUX"
1502 # define DYNAMIC_LOADING
1503 extern int _end[];
1504 # define DATAEND (ptr_t)(_end)
1505 # pragma weak __data_start
1506 extern int __data_start[];
1507 # define DATASTART ((ptr_t)(__data_start))
1508 # ifdef _MIPS_SZPTR
1509 # define CPP_WORDSZ _MIPS_SZPTR
1510 # define ALIGNMENT (_MIPS_SZPTR/8)
1511 # else
1512 # define ALIGNMENT 4
1513 # endif
1514 # ifndef HBLKSIZE
1515 # define HBLKSIZE 4096
1516 # endif
1517 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1518 # define LINUX_STACKBOTTOM
1519 # else
1520 # define STACKBOTTOM ((ptr_t)0x7fff8000)
1521 # endif
1522 # endif /* Linux */
1523 # ifdef EWS4800
1524 # define HEURISTIC2
1525 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1526 extern int _fdata[], _end[];
1527 # define DATASTART ((ptr_t)_fdata)
1528 # define DATAEND ((ptr_t)_end)
1529 # define CPP_WORDSZ _MIPS_SZPTR
1530 # define ALIGNMENT (_MIPS_SZPTR/8)
1531 # else
1532 extern int etext[], edata[], end[];
1533 extern int _DYNAMIC_LINKING[], _gp[];
1534 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1535 + ((word)etext & 0xffff)))
1536 # define DATAEND (ptr_t)(edata)
1537 # define DATASTART2 (_DYNAMIC_LINKING \
1538 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1539 : (ptr_t)edata)
1540 # define DATAEND2 (ptr_t)(end)
1541 # define ALIGNMENT 4
1542 # endif
1543 # define OS_TYPE "EWS4800"
1544 # endif
1545 # ifdef ULTRIX
1546 # define HEURISTIC2
1547 # define DATASTART (ptr_t)0x10000000
1548 /* Could probably be slightly higher since */
1549 /* startup code allocates lots of stuff. */
1550 # define OS_TYPE "ULTRIX"
1551 # define ALIGNMENT 4
1552 # endif
1553 # ifdef IRIX5
1554 # define HEURISTIC2
1555 extern int _fdata[];
1556 # define DATASTART ((ptr_t)(_fdata))
1557 # ifdef USE_MMAP
1558 # define HEAP_START (ptr_t)0x30000000
1559 # else
1560 # define HEAP_START DATASTART
1561 # endif
1562 /* Lowest plausible heap address. */
1563 /* In the MMAP case, we map there. */
1564 /* In either case it is used to identify */
1565 /* heap sections so they're not */
1566 /* considered as roots. */
1567 # define OS_TYPE "IRIX5"
1568 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1569 /* of recent breakage. */
1570 # ifdef _MIPS_SZPTR
1571 # define CPP_WORDSZ _MIPS_SZPTR
1572 # define ALIGNMENT (_MIPS_SZPTR/8)
1573 # else
1574 # define ALIGNMENT 4
1575 # endif
1576 # define DYNAMIC_LOADING
1577 # endif
1578 # ifdef MSWINCE
1579 # define OS_TYPE "MSWINCE"
1580 # define ALIGNMENT 4
1581 # define DATAEND /* not needed */
1582 # endif
1583 # if defined(NETBSD)
1584 # define OS_TYPE "NETBSD"
1585 # define ALIGNMENT 4
1586 # define HEURISTIC2
1587 # ifdef __ELF__
1588 extern ptr_t GC_data_start;
1589 # define DATASTART GC_data_start
1590 # define NEED_FIND_LIMIT
1591 # define DYNAMIC_LOADING
1592 # else
1593 # define DATASTART ((ptr_t) 0x10000000)
1594 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1595 # endif /* _ELF_ */
1596 # endif
1597 # ifdef OPENBSD
1598 # define OS_TYPE "OPENBSD"
1599 # define ALIGNMENT 4
1600 # ifdef GC_OPENBSD_THREADS
1601 # define UTHREAD_SP_OFFSET 808
1602 # else
1603 # include <sys/param.h>
1604 # include <uvm/uvm_extern.h>
1605 # define STACKBOTTOM ((ptr_t) USRSTACK)
1606 # endif
1607 extern int _fdata[];
1608 # define DATASTART ((ptr_t)_fdata)
1609 extern char _end[];
1610 # define DATAEND ((ptr_t)(&_end))
1611 # define DYNAMIC_LOADING
1612 # endif
1613 # if defined(NONSTOP)
1614 # define CPP_WORDSZ 32
1615 # define OS_TYPE "NONSTOP"
1616 # define ALIGNMENT 4
1617 # define DATASTART ((ptr_t) 0x08000000)
1618 extern char **environ;
1619 # define DATAEND ((ptr_t)(environ - 0x10))
1620 # define STACKBOTTOM ((ptr_t) 0x4fffffff)
1621 # endif
1622 # endif
1624 # ifdef HP_PA
1625 # define MACH_TYPE "HP_PA"
1626 # ifdef __LP64__
1627 # define CPP_WORDSZ 64
1628 # define ALIGNMENT 8
1629 # else
1630 # define CPP_WORDSZ 32
1631 # define ALIGNMENT 4
1632 # endif
1633 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS) \
1634 && !defined(OPENBSD) && !defined(LINUX) /* For now. */
1635 # define MPROTECT_VDB
1636 # endif
1637 # define STACK_GROWS_UP
1638 # ifdef HPUX
1639 # define OS_TYPE "HPUX"
1640 extern int __data_start[];
1641 # define DATASTART ((ptr_t)(__data_start))
1642 # ifdef USE_HPUX_FIXED_STACKBOTTOM
1643 /* The following appears to work for 7xx systems running HP/UX */
1644 /* 9.xx. Furthermore, it might result in much faster */
1645 /* collections than HEURISTIC2, which may involve scanning */
1646 /* segments that directly precede the stack. It is not the */
1647 /* default, since it may not work on older machine/OS */
1648 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1649 /* this.) */
1650 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1651 # else
1652 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1653 /* to this. Note that the GC must be initialized before the */
1654 /* first putenv call. */
1655 extern char ** environ;
1656 # define STACKBOTTOM ((ptr_t)environ)
1657 # endif
1658 # define DYNAMIC_LOADING
1659 # include <unistd.h>
1660 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1661 # ifndef __GNUC__
1662 # define PREFETCH(x) { \
1663 register long addr = (long)(x); \
1664 (void) _asm ("LDW", 0, 0, addr, 0); \
1666 # endif
1667 # endif /* HPUX */
1668 # ifdef LINUX
1669 # define OS_TYPE "LINUX"
1670 # define LINUX_STACKBOTTOM
1671 # define DYNAMIC_LOADING
1672 # define SEARCH_FOR_DATA_START
1673 extern int _end[];
1674 # define DATAEND (ptr_t)(&_end)
1675 # endif /* LINUX */
1676 # ifdef OPENBSD
1677 # define OS_TYPE "OPENBSD"
1678 # ifdef GC_OPENBSD_THREADS
1679 # define UTHREAD_SP_OFFSET 520
1680 # else
1681 # include <sys/param.h>
1682 # include <uvm/uvm_extern.h>
1683 # define STACKBOTTOM ((ptr_t) USRSTACK)
1684 # endif
1685 extern int __data_start[];
1686 # define DATASTART ((ptr_t)__data_start)
1687 extern char _end[];
1688 # define DATAEND ((ptr_t)(&_end))
1689 # define DYNAMIC_LOADING
1690 # endif
1691 # endif /* HP_PA */
1693 # ifdef ALPHA
1694 # define MACH_TYPE "ALPHA"
1695 # define ALIGNMENT 8
1696 # define CPP_WORDSZ 64
1697 # ifdef NETBSD
1698 # define OS_TYPE "NETBSD"
1699 # define HEURISTIC2
1700 extern ptr_t GC_data_start;
1701 # define DATASTART GC_data_start
1702 # define ELFCLASS32 32
1703 # define ELFCLASS64 64
1704 # define ELF_CLASS ELFCLASS64
1705 # define DYNAMIC_LOADING
1706 # endif
1707 # ifdef OPENBSD
1708 # define OS_TYPE "OPENBSD"
1709 # define ELF_CLASS ELFCLASS64
1710 # ifdef GC_OPENBSD_THREADS
1711 # define UTHREAD_SP_OFFSET 816
1712 # else
1713 # include <sys/param.h>
1714 # include <uvm/uvm_extern.h>
1715 # define STACKBOTTOM ((ptr_t) USRSTACK)
1716 # endif
1717 extern int __data_start[];
1718 # define DATASTART ((ptr_t)__data_start)
1719 extern char _end[];
1720 # define DATAEND ((ptr_t)(&_end))
1721 # define DYNAMIC_LOADING
1722 # endif
1723 # ifdef FREEBSD
1724 # define OS_TYPE "FREEBSD"
1725 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1726 # define SIG_SUSPEND SIGUSR1
1727 # define SIG_THR_RESTART SIGUSR2
1728 /* SIGTSTP and SIGCONT could be used alternatively. */
1729 # define FREEBSD_STACKBOTTOM
1730 # ifdef __ELF__
1731 # define DYNAMIC_LOADING
1732 # endif
1733 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1734 extern char etext[];
1735 extern char edata[];
1736 extern char end[];
1737 # define NEED_FIND_LIMIT
1738 # define DATASTART ((ptr_t)(&etext))
1739 ptr_t GC_find_limit(ptr_t, GC_bool);
1740 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1741 # define DATAEND_IS_FUNC
1742 # define DATASTART2 ((ptr_t)(&edata))
1743 # define DATAEND2 ((ptr_t)(&end))
1744 # endif
1745 # ifdef OSF1
1746 # define OS_TYPE "OSF1"
1747 # define DATASTART ((ptr_t) 0x140000000)
1748 extern int _end[];
1749 # define DATAEND ((ptr_t) &_end)
1750 extern char ** environ;
1751 /* round up from the value of environ to the nearest page boundary */
1752 /* Probably breaks if putenv is called before collector */
1753 /* initialization. */
1754 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1755 /* # define HEURISTIC2 */
1756 /* Normally HEURISTIC2 is too conservative, since */
1757 /* the text segment immediately follows the stack. */
1758 /* Hence we give an upper pound. */
1759 /* This is currently unused, since we disabled HEURISTIC2 */
1760 extern int __start[];
1761 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1762 # ifndef GC_OSF1_THREADS
1763 /* Unresolved signal issues with threads. */
1764 # define MPROTECT_VDB
1765 # endif
1766 # define DYNAMIC_LOADING
1767 # endif
1768 # ifdef LINUX
1769 # define OS_TYPE "LINUX"
1770 # define LINUX_STACKBOTTOM
1771 # ifdef __ELF__
1772 # define SEARCH_FOR_DATA_START
1773 # define DYNAMIC_LOADING
1774 # else
1775 # define DATASTART ((ptr_t) 0x140000000)
1776 # endif
1777 extern int _end[];
1778 # define DATAEND (ptr_t)(_end)
1779 # define MPROTECT_VDB
1780 /* Has only been superficially tested. May not */
1781 /* work on all versions. */
1782 # endif
1783 # endif
1785 # ifdef IA64
1786 # define MACH_TYPE "IA64"
1787 # ifdef HPUX
1788 # ifdef _ILP32
1789 # define CPP_WORDSZ 32
1790 /* Requires 8 byte alignment for malloc */
1791 # define ALIGNMENT 4
1792 # else
1793 # ifndef _LP64
1794 # error --> unknown ABI
1795 # endif
1796 # define CPP_WORDSZ 64
1797 /* Requires 16 byte alignment for malloc */
1798 # define ALIGNMENT 8
1799 # endif
1800 # define OS_TYPE "HPUX"
1801 extern int __data_start[];
1802 # define DATASTART ((ptr_t)(__data_start))
1803 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1804 /* to this. Note that the GC must be initialized before the */
1805 /* first putenv call. */
1806 extern char ** environ;
1807 # define STACKBOTTOM ((ptr_t)environ)
1808 # define HPUX_STACKBOTTOM
1809 # define DYNAMIC_LOADING
1810 # include <unistd.h>
1811 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1812 /* The following was empirically determined, and is probably */
1813 /* not very robust. */
1814 /* Note that the backing store base seems to be at a nice */
1815 /* address minus one page. */
1816 # define BACKING_STORE_DISPLACEMENT 0x1000000
1817 # define BACKING_STORE_ALIGNMENT 0x1000
1818 extern ptr_t GC_register_stackbottom;
1819 # define BACKING_STORE_BASE GC_register_stackbottom
1820 /* Known to be wrong for recent HP/UX versions!!! */
1821 # endif
1822 # ifdef LINUX
1823 # define CPP_WORDSZ 64
1824 # define ALIGNMENT 8
1825 # define OS_TYPE "LINUX"
1826 /* The following works on NUE and older kernels: */
1827 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1828 /* This does not work on NUE: */
1829 # define LINUX_STACKBOTTOM
1830 /* We also need the base address of the register stack */
1831 /* backing store. This is computed in */
1832 /* GC_linux_register_stack_base based on the following */
1833 /* constants: */
1834 # define BACKING_STORE_ALIGNMENT 0x100000
1835 # define BACKING_STORE_DISPLACEMENT 0x80000000
1836 extern ptr_t GC_register_stackbottom;
1837 # define BACKING_STORE_BASE GC_register_stackbottom
1838 # define SEARCH_FOR_DATA_START
1839 # ifdef __GNUC__
1840 # define DYNAMIC_LOADING
1841 # else
1842 /* In the Intel compiler environment, we seem to end up with */
1843 /* statically linked executables and an undefined reference */
1844 /* to _DYNAMIC */
1845 # endif
1846 # define MPROTECT_VDB
1847 /* Requires Linux 2.3.47 or later. */
1848 extern int _end[];
1849 # define DATAEND (ptr_t)(_end)
1850 # ifdef __GNUC__
1851 # ifndef __INTEL_COMPILER
1852 # define PREFETCH(x) \
1853 __asm__ (" lfetch [%0]": : "r"(x))
1854 # define PREFETCH_FOR_WRITE(x) \
1855 __asm__ (" lfetch.excl [%0]": : "r"(x))
1856 # define CLEAR_DOUBLE(x) \
1857 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1858 # else
1859 # include <ia64intrin.h>
1860 # define PREFETCH(x) \
1861 __lfetch(__lfhint_none, (x))
1862 # define PREFETCH_FOR_WRITE(x) \
1863 __lfetch(__lfhint_nta, (x))
1864 # define CLEAR_DOUBLE(x) \
1865 __stf_spill((void *)(x), 0)
1866 # endif /* __INTEL_COMPILER */
1867 # endif
1868 # endif
1869 # ifdef MSWIN32
1870 /* FIXME: This is a very partial guess. There is no port, yet. */
1871 # define OS_TYPE "MSWIN32"
1872 /* STACKBOTTOM and DATASTART are handled specially in */
1873 /* os_dep.c. */
1874 # define DATAEND /* not needed */
1875 # if defined(_WIN64)
1876 # define CPP_WORDSZ 64
1877 # else
1878 # define CPP_WORDSZ 32 /* Is this possible? */
1879 # endif
1880 # define ALIGNMENT 8
1881 # endif
1882 # endif
1884 # ifdef M88K
1885 # define MACH_TYPE "M88K"
1886 # define ALIGNMENT 4
1887 extern int etext[];
1888 # ifdef CX_UX
1889 # define OS_TYPE "CX_UX"
1890 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1891 # endif
1892 # ifdef DGUX
1893 # define OS_TYPE "DGUX"
1894 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1895 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
1896 # define DATASTART_IS_FUNC
1897 # endif
1898 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1899 # endif
1901 # ifdef S370
1902 /* If this still works, and if anyone cares, this should probably */
1903 /* be moved to the S390 category. */
1904 # define MACH_TYPE "S370"
1905 # define ALIGNMENT 4 /* Required by hardware */
1906 # ifdef UTS4
1907 # define OS_TYPE "UTS4"
1908 extern int etext[];
1909 extern int _etext[];
1910 extern int _end[];
1911 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1912 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1913 # define DATASTART_IS_FUNC
1914 # define DATAEND (ptr_t)(_end)
1915 # define HEURISTIC2
1916 # endif
1917 # endif
1919 # ifdef S390
1920 # define MACH_TYPE "S390"
1921 # ifndef __s390x__
1922 # define ALIGNMENT 4
1923 # define CPP_WORDSZ 32
1924 # else
1925 # define ALIGNMENT 8
1926 # define CPP_WORDSZ 64
1927 # ifndef HBLKSIZE
1928 # define HBLKSIZE 4096
1929 # endif
1930 # endif
1931 # ifdef LINUX
1932 # define OS_TYPE "LINUX"
1933 # define LINUX_STACKBOTTOM
1934 # define DYNAMIC_LOADING
1935 extern int __data_start[];
1936 # define DATASTART ((ptr_t)(__data_start))
1937 extern int _end[];
1938 # define DATAEND (ptr_t)(_end)
1939 # define CACHE_LINE_SIZE 256
1940 # define GETPAGESIZE() 4096
1941 # endif
1942 # endif
1944 # ifdef ARM32
1945 # define CPP_WORDSZ 32
1946 # define MACH_TYPE "ARM32"
1947 # define ALIGNMENT 4
1948 # ifdef NETBSD
1949 # define OS_TYPE "NETBSD"
1950 # define HEURISTIC2
1951 # ifdef __ELF__
1952 extern ptr_t GC_data_start;
1953 # define DATASTART GC_data_start
1954 # define DYNAMIC_LOADING
1955 # else
1956 extern char etext[];
1957 # define DATASTART ((ptr_t)(etext))
1958 # endif
1959 # endif
1960 # ifdef LINUX
1961 # define OS_TYPE "LINUX"
1962 # define LINUX_STACKBOTTOM
1963 # undef STACK_GRAN
1964 # define STACK_GRAN 0x10000000
1965 # ifdef __ELF__
1966 # define DYNAMIC_LOADING
1967 # include <features.h>
1968 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1969 || defined(PLATFORM_ANDROID)
1970 # define SEARCH_FOR_DATA_START
1971 # else
1972 extern char **__environ;
1973 # define DATASTART ((ptr_t)(&__environ))
1974 /* hideous kludge: __environ is the first */
1975 /* word in crt0.o, and delimits the start */
1976 /* of the data segment, no matter which */
1977 /* ld options were passed through. */
1978 /* We could use _etext instead, but that */
1979 /* would include .rodata, which may */
1980 /* contain large read-only data tables */
1981 /* that we'd rather not scan. */
1982 # endif
1983 extern int _end[];
1984 # define DATAEND (ptr_t)(_end)
1985 # else
1986 extern int etext[];
1987 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1988 # endif
1989 # endif
1990 # ifdef MSWINCE
1991 # define OS_TYPE "MSWINCE"
1992 # define DATAEND /* not needed */
1993 # endif
1994 # ifdef DARWIN
1995 /* iPhone */
1996 # define OS_TYPE "DARWIN"
1997 # ifndef GC_DONT_REGISTER_MAIN_STATIC_DATA
1998 # define DYNAMIC_LOADING
1999 # endif
2000 # define DATASTART ((ptr_t) get_etext())
2001 # define DATAEND ((ptr_t) get_end())
2002 # define STACKBOTTOM ((ptr_t) 0x30000000)
2003 # ifndef USE_MMAP
2004 # define USE_MMAP
2005 # endif
2006 # define USE_MMAP_ANON
2007 # define MPROTECT_VDB
2008 # include <unistd.h>
2009 # define GETPAGESIZE() getpagesize()
2010 /* FIXME: There seems to be some issues with trylock hanging on */
2011 /* darwin. This should be looked into some more. */
2012 # define NO_PTHREAD_TRYLOCK
2013 # ifndef NO_DYLD_BIND_FULLY_IMAGE
2014 # define NO_DYLD_BIND_FULLY_IMAGE
2015 # endif
2016 # endif
2017 # ifdef OPENBSD
2018 # define ALIGNMENT 4
2019 # define OS_TYPE "OPENBSD"
2020 # ifdef GC_OPENBSD_THREADS
2021 # define UTHREAD_SP_OFFSET 176
2022 # else
2023 # include <sys/param.h>
2024 # include <uvm/uvm_extern.h>
2025 # define STACKBOTTOM ((ptr_t) USRSTACK)
2026 # endif
2027 extern int __data_start[];
2028 # define DATASTART ((ptr_t)__data_start)
2029 extern char _end[];
2030 # define DATAEND ((ptr_t)(&_end))
2031 # define DYNAMIC_LOADING
2032 # endif
2033 # ifdef NOSYS
2034 /* __data_start is usually defined in the target linker script. */
2035 extern int __data_start[];
2036 # define DATASTART (ptr_t)(__data_start)
2037 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
2038 extern void *__stack_base__;
2039 # define STACKBOTTOM ((ptr_t) (__stack_base__))
2040 # endif
2041 #endif
2043 # ifdef CRIS
2044 # define MACH_TYPE "CRIS"
2045 # define CPP_WORDSZ 32
2046 # define ALIGNMENT 1
2047 # define OS_TYPE "LINUX"
2048 # define DYNAMIC_LOADING
2049 # define LINUX_STACKBOTTOM
2050 # define SEARCH_FOR_DATA_START
2051 extern int _end[];
2052 # define DATAEND (ptr_t)(_end)
2053 # endif
2055 # if defined(SH) && !defined(SH4)
2056 # define MACH_TYPE "SH"
2057 # define ALIGNMENT 4
2058 # ifdef MSWINCE
2059 # define OS_TYPE "MSWINCE"
2060 # define DATAEND /* not needed */
2061 # endif
2062 # ifdef LINUX
2063 # define OS_TYPE "LINUX"
2064 # define LINUX_STACKBOTTOM
2065 # define DYNAMIC_LOADING
2066 # define SEARCH_FOR_DATA_START
2067 extern int _end[];
2068 # define DATAEND (ptr_t)(_end)
2069 # endif
2070 # ifdef NETBSD
2071 # define OS_TYPE "NETBSD"
2072 # define HEURISTIC2
2073 extern ptr_t GC_data_start;
2074 # define DATASTART GC_data_start
2075 # define DYNAMIC_LOADING
2076 # endif
2077 # ifdef OPENBSD
2078 # define OS_TYPE "OPENBSD"
2079 # ifdef GC_OPENBSD_THREADS
2080 # define UTHREAD_SP_OFFSET 332
2081 # else
2082 # include <sys/param.h>
2083 # include <uvm/uvm_extern.h>
2084 # define STACKBOTTOM ((ptr_t) USRSTACK)
2085 # endif
2086 extern int __data_start[];
2087 # define DATASTART ((ptr_t)__data_start)
2088 extern char _end[];
2089 # define DATAEND ((ptr_t)(&_end))
2090 # define DYNAMIC_LOADING
2091 # endif
2092 # endif
2094 # ifdef SH4
2095 # define MACH_TYPE "SH4"
2096 # define OS_TYPE "MSWINCE"
2097 # define ALIGNMENT 4
2098 # define DATAEND /* not needed */
2099 # endif
2101 # ifdef AVR32
2102 # define MACH_TYPE "AVR32"
2103 # define CPP_WORDSZ 32
2104 # define ALIGNMENT 4
2105 # define OS_TYPE "LINUX"
2106 # define DYNAMIC_LOADING
2107 # define LINUX_STACKBOTTOM
2108 # define SEARCH_FOR_DATA_START
2109 extern int _end[];
2110 # define DATAEND (_end)
2111 # endif
2113 # ifdef M32R
2114 # define CPP_WORDSZ 32
2115 # define MACH_TYPE "M32R"
2116 # define ALIGNMENT 4
2117 # ifdef LINUX
2118 # define OS_TYPE "LINUX"
2119 # define LINUX_STACKBOTTOM
2120 # undef STACK_GRAN
2121 # define STACK_GRAN 0x10000000
2122 # define DYNAMIC_LOADING
2123 # define SEARCH_FOR_DATA_START
2124 extern int _end[];
2125 # define DATAEND (ptr_t)(_end)
2126 # endif
2127 # endif
2129 # ifdef X86_64
2130 # define MACH_TYPE "X86_64"
2131 # ifdef __ILP32__
2132 # define ALIGNMENT 4
2133 # define CPP_WORDSZ 32
2134 # else
2135 # define ALIGNMENT 8
2136 # define CPP_WORDSZ 64
2137 # endif
2138 # ifndef HBLKSIZE
2139 # define HBLKSIZE 4096
2140 # endif
2141 # define CACHE_LINE_SIZE 64
2142 # ifdef OPENBSD
2143 # define OS_TYPE "OPENBSD"
2144 # define ELF_CLASS ELFCLASS64
2145 # ifdef GC_OPENBSD_THREADS
2146 # define UTHREAD_SP_OFFSET 400
2147 # else
2148 # include <sys/param.h>
2149 # include <uvm/uvm_extern.h>
2150 # define STACKBOTTOM ((ptr_t) USRSTACK)
2151 # endif
2152 extern int __data_start[];
2153 # define DATASTART ((ptr_t)__data_start)
2154 extern char _end[];
2155 # define DATAEND ((ptr_t)(&_end))
2156 # define DYNAMIC_LOADING
2157 # endif
2158 # ifdef LINUX
2159 # define OS_TYPE "LINUX"
2160 # define LINUX_STACKBOTTOM
2161 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2162 # define MPROTECT_VDB
2163 # else
2164 /* We seem to get random errors in incremental mode, */
2165 /* possibly because Linux threads is itself a malloc client */
2166 /* and can't deal with the signals. */
2167 # endif
2168 # ifdef __ELF__
2169 # define DYNAMIC_LOADING
2170 # ifdef UNDEFINED /* includes ro data */
2171 extern int _etext[];
2172 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
2173 # endif
2174 # include <features.h>
2175 # define SEARCH_FOR_DATA_START
2176 extern int _end[];
2177 # define DATAEND (ptr_t)(_end)
2178 # else
2179 extern int etext[];
2180 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
2181 # endif
2182 # if defined(__GNUC__) && __GNUC__ >= 3
2183 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
2184 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
2185 # endif
2186 # if defined(__GLIBC__)
2187 /* At present, there's a bug in GLibc getcontext() on */
2188 /* Linux/x64 (it clears FPU exception mask). We define this */
2189 /* macro to workaround it. */
2190 /* FIXME: This seems to be fixed in GLibc v2.14. */
2191 # define GETCONTEXT_FPU_EXCMASK_BUG
2192 # endif
2193 # endif
2194 # ifdef DARWIN
2195 # define OS_TYPE "DARWIN"
2196 # define DARWIN_DONT_PARSE_STACK
2197 # define DYNAMIC_LOADING
2198 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
2199 /* These aren't used when dyld support is enabled (it is by default) */
2200 # define DATASTART ((ptr_t) get_etext())
2201 # define DATAEND ((ptr_t) get_end())
2202 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
2203 # ifndef USE_MMAP
2204 # define USE_MMAP
2205 # endif
2206 # define USE_MMAP_ANON
2207 # define MPROTECT_VDB
2208 # include <unistd.h>
2209 # define GETPAGESIZE() getpagesize()
2210 /* There seems to be some issues with trylock hanging on darwin. */
2211 /* This should be looked into some more. */
2212 # define NO_PTHREAD_TRYLOCK
2213 # endif
2214 # ifdef FREEBSD
2215 # define OS_TYPE "FREEBSD"
2216 # ifndef GC_FREEBSD_THREADS
2217 # define MPROTECT_VDB
2218 # endif
2219 # ifdef __GLIBC__
2220 # define SIG_SUSPEND (32+6)
2221 # define SIG_THR_RESTART (32+5)
2222 extern int _end[];
2223 # define DATAEND (ptr_t)(_end)
2224 # else
2225 # define SIG_SUSPEND SIGUSR1
2226 # define SIG_THR_RESTART SIGUSR2
2227 /* SIGTSTP and SIGCONT could be used alternatively. */
2228 # endif
2229 # define FREEBSD_STACKBOTTOM
2230 # ifdef __ELF__
2231 # define DYNAMIC_LOADING
2232 # endif
2233 extern char etext[];
2234 ptr_t GC_FreeBSDGetDataStart(size_t, ptr_t);
2235 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
2236 # define DATASTART_IS_FUNC
2237 # endif
2238 # ifdef NETBSD
2239 # define OS_TYPE "NETBSD"
2240 # define HEURISTIC2
2241 # ifdef __ELF__
2242 extern ptr_t GC_data_start;
2243 # define DATASTART GC_data_start
2244 # define DYNAMIC_LOADING
2245 # else
2246 # define SEARCH_FOR_DATA_START
2247 # endif
2248 # endif
2249 # ifdef SOLARIS
2250 # define OS_TYPE "SOLARIS"
2251 # define ELF_CLASS ELFCLASS64
2252 extern int _etext[], _end[];
2253 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
2254 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
2255 # define DATASTART_IS_FUNC
2256 # define DATAEND (ptr_t)(_end)
2257 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
2258 /* but reportedly breaks under 2.8. It appears that the stack */
2259 /* base is a property of the executable, so this should not break */
2260 /* old executables. */
2261 /* HEURISTIC2 probably works, but this appears to be preferable. */
2262 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
2263 /* installations that's undefined. We work around this with a */
2264 /* gross hack: */
2265 # include <sys/vmparam.h>
2266 # ifdef USERLIMIT
2267 /* This should work everywhere, but doesn't. */
2268 # define STACKBOTTOM ((ptr_t) USRSTACK)
2269 # else
2270 # define HEURISTIC2
2271 # endif
2272 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
2273 /* It appears to be fixed in 2.8 and 2.9. */
2274 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
2275 # define PROC_VDB
2276 # endif
2277 # ifndef GC_THREADS
2278 # define MPROTECT_VDB
2279 # endif
2280 # define DYNAMIC_LOADING
2281 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
2282 # define USE_MMAP
2283 /* Otherwise we now use calloc. Mmap may result in the */
2284 /* heap interleaved with thread stacks, which can result in */
2285 /* excessive blacklisting. Sbrk is unusable since it */
2286 /* doesn't interact correctly with the system malloc. */
2287 # endif
2288 # ifdef USE_MMAP
2289 # define HEAP_START (ptr_t)0x40000000
2290 # else
2291 # define HEAP_START DATAEND
2292 # endif
2293 # endif
2294 # ifdef MSWIN32
2295 # define OS_TYPE "MSWIN32"
2296 /* STACKBOTTOM and DATASTART are handled specially in */
2297 /* os_dep.c. */
2298 # if !defined(__GNUC__) || defined(__INTEL_COMPILER)
2299 /* GCC does not currently support SetUnhandledExceptionFilter */
2300 /* (does not generate SEH unwinding information) on x64. */
2301 # define MPROTECT_VDB
2302 # endif
2303 # define GWW_VDB
2304 # define DATAEND /* not needed */
2305 # endif
2306 # endif /* X86_64 */
2308 # ifdef HEXAGON
2309 # define CPP_WORDSZ 32
2310 # define MACH_TYPE "HEXAGON"
2311 # define ALIGNMENT 4
2312 # ifdef LINUX
2313 # define OS_TYPE "LINUX"
2314 # define LINUX_STACKBOTTOM
2315 # define MPROTECT_VDB
2316 # ifdef __ELF__
2317 # define DYNAMIC_LOADING
2318 # include <features.h>
2319 # if defined(__GLIBC__) && __GLIBC__ >= 2
2320 # define SEARCH_FOR_DATA_START
2321 # else
2322 # error --> unknown Hexagon libc configuration
2323 # endif
2324 extern int _end[];
2325 # define DATAEND (ptr_t)(_end)
2326 # else
2327 # error --> bad Hexagon Linux configuration
2328 # endif
2329 # else
2330 # error --> unknown Hexagon OS configuration
2331 # endif
2332 # endif
2334 #if defined(LINUX_STACKBOTTOM) && defined(NO_PROC_STAT) \
2335 && !defined(USE_LIBC_PRIVATES)
2336 /* This combination will fail, since we have no way to get */
2337 /* the stack base. Use HEURISTIC2 instead. */
2338 # undef LINUX_STACKBOTTOM
2339 # define HEURISTIC2
2340 /* This may still fail on some architectures like IA64. */
2341 /* We tried ... */
2342 #endif
2344 #if defined(LINUX) && defined(USE_MMAP)
2345 /* The kernel may do a somewhat better job merging mappings etc. */
2346 /* with anonymous mappings. */
2347 # define USE_MMAP_ANON
2348 #endif
2350 #if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
2351 && !defined(USE_PROC_FOR_LIBRARIES)
2352 /* Nptl allocates thread stacks with mmap, which is fine. But it */
2353 /* keeps a cache of thread stacks. Thread stacks contain the */
2354 /* thread control blocks. These in turn contain a pointer to */
2355 /* (sizeof (void *) from the beginning of) the dtv for thread-local */
2356 /* storage, which is calloc allocated. If we don't scan the cached */
2357 /* thread stacks, we appear to lose the dtv. This tends to */
2358 /* result in something that looks like a bogus dtv count, which */
2359 /* tends to result in a memset call on a block that is way too */
2360 /* large. Sometimes we're lucky and the process just dies ... */
2361 /* There seems to be a similar issue with some other memory */
2362 /* allocated by the dynamic loader. */
2363 /* This should be avoidable by either: */
2364 /* - Defining USE_PROC_FOR_LIBRARIES here. */
2365 /* That performs very poorly, precisely because we end up */
2366 /* scanning cached stacks. */
2367 /* - Have calloc look at its callers. */
2368 /* In spite of the fact that it is gross and disgusting. */
2369 /* In fact neither seems to suffice, probably in part because */
2370 /* even with USE_PROC_FOR_LIBRARIES, we don't scan parts of stack */
2371 /* segments that appear to be out of bounds. Thus we actually */
2372 /* do both, which seems to yield the best results. */
2374 # define USE_PROC_FOR_LIBRARIES
2375 #endif
2377 #ifndef STACK_GROWS_UP
2378 # define STACK_GROWS_DOWN
2379 #endif
2381 #ifndef CPP_WORDSZ
2382 # define CPP_WORDSZ 32
2383 #endif
2385 #ifndef OS_TYPE
2386 # define OS_TYPE ""
2387 #endif
2389 #ifndef DATAEND
2390 extern int end[];
2391 # define DATAEND (ptr_t)(end)
2392 #endif
2394 #if defined(PLATFORM_ANDROID) && !defined(THREADS) \
2395 && !defined(USE_GET_STACKBASE_FOR_MAIN)
2396 /* Always use pthread_attr_getstack on Android ("-lpthread" option is */
2397 /* not needed to be specified manually) since GC_linux_main_stack_base */
2398 /* causes app crash if invoked inside Dalvik VM. */
2399 # define USE_GET_STACKBASE_FOR_MAIN
2400 #endif
2402 #if (defined(SVR4) || defined(PLATFORM_ANDROID)) && !defined(GETPAGESIZE)
2403 # include <unistd.h>
2404 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
2405 #endif
2407 #ifndef GETPAGESIZE
2408 # if defined(SOLARIS) || defined(IRIX5) || defined(LINUX) \
2409 || defined(NETBSD) || defined(FREEBSD) || defined(HPUX)
2410 # include <unistd.h>
2411 # endif
2412 # define GETPAGESIZE() getpagesize()
2413 #endif
2415 #if defined(SOLARIS) || defined(DRSNX) || defined(UTS4)
2416 /* OS has SVR4 generic features. */
2417 /* Probably others also qualify. */
2418 # define SVR4
2419 #endif
2421 #if defined(SOLARIS) || defined(DRSNX)
2422 /* OS has SOLARIS style semi-undocumented interface */
2423 /* to dynamic loader. */
2424 # define SOLARISDL
2425 /* OS has SOLARIS style signal handlers. */
2426 # define SUNOS5SIGS
2427 #endif
2429 #if defined(HPUX)
2430 # define SUNOS5SIGS
2431 #endif
2433 #if defined(FREEBSD) && (defined(__DragonFly__) || __FreeBSD__ >= 4 \
2434 || (__FreeBSD_kernel__ >= 4))
2435 # define SUNOS5SIGS
2436 #endif
2438 #if !defined(GC_EXPLICIT_SIGNALS_UNBLOCK) && defined(SUNOS5SIGS) \
2439 && !defined(GC_NO_PTHREAD_SIGMASK)
2440 # define GC_EXPLICIT_SIGNALS_UNBLOCK
2441 #endif
2443 #ifdef GC_NETBSD_THREADS
2444 # define SIGRTMIN 33
2445 # define SIGRTMAX 63
2446 #endif
2448 #if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2449 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2450 || defined(DGUX) || defined(BSD) || defined(HURD) \
2451 || defined(AIX) || defined(DARWIN) || defined(OSF1)
2452 # define UNIX_LIKE /* Basic Unix-like system calls work. */
2453 #endif
2455 #if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2456 # error --> bad word size
2457 #endif
2459 #ifndef ALIGNMENT
2460 # error --> undefined ALIGNMENT
2461 #endif
2463 #ifdef PCR
2464 # undef DYNAMIC_LOADING
2465 # undef STACKBOTTOM
2466 # undef HEURISTIC1
2467 # undef HEURISTIC2
2468 # undef PROC_VDB
2469 # undef MPROTECT_VDB
2470 # define PCR_VDB
2471 #endif
2473 #if !defined(STACKBOTTOM) && (defined(ECOS) || defined(NOSYS))
2474 # error --> undefined STACKBOTTOM
2475 #endif
2477 #ifdef IGNORE_DYNAMIC_LOADING
2478 # undef DYNAMIC_LOADING
2479 #endif
2481 #if defined(SMALL_CONFIG) && !defined(GC_DISABLE_INCREMENTAL)
2482 /* Presumably not worth the space it takes. */
2483 # define GC_DISABLE_INCREMENTAL
2484 #endif
2486 #if (defined(MSWIN32) || defined(MSWINCE)) && !defined(USE_WINALLOC)
2487 /* USE_WINALLOC is only an option for Cygwin. */
2488 # define USE_WINALLOC
2489 #endif
2491 #ifdef USE_WINALLOC
2492 # undef USE_MMAP
2493 #endif
2495 #if defined(GC_DISABLE_INCREMENTAL) || defined(MANUAL_VDB)
2496 # undef GWW_VDB
2497 # undef MPROTECT_VDB
2498 # undef PCR_VDB
2499 # undef PROC_VDB
2500 #endif
2502 #ifdef GC_DISABLE_INCREMENTAL
2503 # undef CHECKSUMS
2504 #endif
2506 #ifdef USE_GLOBAL_ALLOC
2507 /* Cannot pass MEM_WRITE_WATCH to GlobalAlloc(). */
2508 # undef GWW_VDB
2509 #endif
2511 #ifdef USE_MUNMAP
2512 /* FIXME: Remove this undef if possible. */
2513 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2514 #endif
2516 /* PARALLEL_MARK does not cause undef MPROTECT_VDB any longer. */
2518 #if defined(MPROTECT_VDB) && defined(GC_PREFER_MPROTECT_VDB)
2519 /* Choose MPROTECT_VDB manually (if multiple strategies available). */
2520 # undef PCR_VDB
2521 # undef PROC_VDB
2522 /* #undef GWW_VDB - handled in os_dep.c */
2523 #endif
2525 #ifdef PROC_VDB
2526 /* Multi-VDB mode is not implemented. */
2527 # undef MPROTECT_VDB
2528 #endif
2530 #if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB) \
2531 && !defined(GWW_VDB) && !defined(MANUAL_VDB) \
2532 && !defined(GC_DISABLE_INCREMENTAL)
2533 # define DEFAULT_VDB
2534 #endif
2536 #if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HURD) \
2537 || defined(OPENBSD) || defined(ARM32) \
2538 || defined(MIPS) || defined(AVR32))) \
2539 || (defined(LINUX) && (defined(SPARC) || defined(M68K))) \
2540 || ((defined(RTEMS) || defined(PLATFORM_ANDROID)) && defined(I386))) \
2541 && !defined(NO_GETCONTEXT)
2542 # define NO_GETCONTEXT
2543 #endif
2545 #ifndef PREFETCH
2546 # define PREFETCH(x)
2547 # define NO_PREFETCH
2548 #endif
2550 #ifndef PREFETCH_FOR_WRITE
2551 # define PREFETCH_FOR_WRITE(x)
2552 # define NO_PREFETCH_FOR_WRITE
2553 #endif
2555 #ifndef CACHE_LINE_SIZE
2556 # define CACHE_LINE_SIZE 32 /* Wild guess */
2557 #endif
2559 #ifndef STATIC
2560 # ifndef NO_DEBUGGING
2561 # define STATIC /* ignore to aid profiling and possibly debugging */
2562 # else
2563 # define STATIC static
2564 # endif
2565 #endif
2567 #if defined(LINUX) && (defined(USE_PROC_FOR_LIBRARIES) || defined(IA64) \
2568 || !defined(SMALL_CONFIG))
2569 # define NEED_PROC_MAPS
2570 #endif
2572 #if defined(LINUX) || defined(HURD) || defined(__GLIBC__)
2573 # define REGISTER_LIBRARIES_EARLY
2574 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2575 /* lock. This isn't safe after the world has stopped. So we must */
2576 /* call GC_register_dynamic_libraries before stopping the world. */
2577 /* For performance reasons, this may be beneficial on other */
2578 /* platforms as well, though it should be avoided in win32. */
2579 #endif /* LINUX */
2581 #if defined(SEARCH_FOR_DATA_START)
2582 extern ptr_t GC_data_start;
2583 # define DATASTART GC_data_start
2584 #endif
2586 #ifndef CLEAR_DOUBLE
2587 # define CLEAR_DOUBLE(x) (((word*)(x))[0] = 0, ((word*)(x))[1] = 0)
2588 #endif
2590 #if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
2591 && !defined(INCLUDE_LINUX_THREAD_DESCR)
2592 /* Will not work, since libc and the dynamic loader use thread */
2593 /* locals, sometimes as the only reference. */
2594 # define INCLUDE_LINUX_THREAD_DESCR
2595 #endif
2597 #if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2598 # error --> inconsistent configuration
2599 #endif
2600 #if defined(GC_LINUX_THREADS) && !defined(LINUX) && !defined(NACL)
2601 # error --> inconsistent configuration
2602 #endif
2603 #if defined(GC_NETBSD_THREADS) && !defined(NETBSD)
2604 # error --> inconsistent configuration
2605 #endif
2606 #if defined(GC_FREEBSD_THREADS) && !defined(FREEBSD)
2607 # error --> inconsistent configuration
2608 #endif
2609 #if defined(GC_SOLARIS_THREADS) && !defined(SOLARIS)
2610 # error --> inconsistent configuration
2611 #endif
2612 #if defined(GC_HPUX_THREADS) && !defined(HPUX)
2613 # error --> inconsistent configuration
2614 #endif
2615 #if defined(GC_AIX_THREADS) && !defined(_AIX)
2616 # error --> inconsistent configuration
2617 #endif
2618 #if defined(GC_GNU_THREADS) && !defined(HURD)
2619 # error --> inconsistent configuration
2620 #endif
2621 #if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32) \
2622 && !defined(MSWINCE)
2623 # error --> inconsistent configuration
2624 #endif
2626 #if defined(PCR) || defined(GC_WIN32_THREADS) || defined(GC_PTHREADS) \
2627 || defined(SN_TARGET_PS3)
2628 # define THREADS
2629 #endif
2631 #if defined(PARALLEL_MARK) && !defined(THREADS)
2632 # error "invalid config - PARALLEL_MARK requires GC_THREADS"
2633 #endif
2635 #if defined(UNIX_LIKE) && defined(THREADS) && !defined(NO_CANCEL_SAFE) \
2636 && !defined(PLATFORM_ANDROID)
2637 /* Make the code cancellation-safe. This basically means that we */
2638 /* ensure that cancellation requests are ignored while we are in */
2639 /* the collector. This applies only to Posix deferred cancellation; */
2640 /* we don't handle Posix asynchronous cancellation. */
2641 /* Note that this only works if pthread_setcancelstate is */
2642 /* async-signal-safe, at least in the absence of asynchronous */
2643 /* cancellation. This appears to be true for the glibc version, */
2644 /* though it is not documented. Without that assumption, there */
2645 /* seems to be no way to safely wait in a signal handler, which */
2646 /* we need to do for thread suspension. */
2647 /* Also note that little other code appears to be cancellation-safe. */
2648 /* Hence it may make sense to turn this off for performance. */
2649 # define CANCEL_SAFE
2650 #endif
2652 #ifdef CANCEL_SAFE
2653 # define IF_CANCEL(x) x
2654 #else
2655 # define IF_CANCEL(x) /* empty */
2656 #endif
2658 #if !defined(CAN_HANDLE_FORK) && !defined(NO_HANDLE_FORK) \
2659 && !defined(HAVE_NO_FORK) \
2660 && ((defined(GC_PTHREADS) && !defined(NACL) \
2661 && !defined(GC_WIN32_PTHREADS) && !defined(USE_WINALLOC)) \
2662 || (defined(DARWIN) && defined(MPROTECT_VDB)) || defined(HANDLE_FORK))
2663 /* Attempts (where supported and requested) to make GC_malloc work in */
2664 /* a child process fork'ed from a multi-threaded parent. */
2665 # define CAN_HANDLE_FORK
2666 #endif
2668 #if defined(CAN_HANDLE_FORK) && !defined(CAN_CALL_ATFORK) \
2669 && !defined(HURD) && !defined(PLATFORM_ANDROID)
2670 /* Have working pthread_atfork(). */
2671 # define CAN_CALL_ATFORK
2672 #endif
2674 #if !defined(CAN_HANDLE_FORK) && !defined(HAVE_NO_FORK) \
2675 && (defined(MSWIN32) || defined(MSWINCE) || defined(DOS4GW) \
2676 || defined(OS2) || defined(SYMBIAN) /* and probably others ... */)
2677 # define HAVE_NO_FORK
2678 #endif
2680 #if !defined(USE_MARK_BITS) && !defined(USE_MARK_BYTES) \
2681 && defined(PARALLEL_MARK)
2682 /* Minimize compare-and-swap usage. */
2683 # define USE_MARK_BYTES
2684 #endif
2686 #if defined(MSWINCE) && !defined(__CEGCC__) && !defined(NO_GETENV)
2687 # define NO_GETENV
2688 #endif
2690 #if (defined(NO_GETENV) || defined(MSWINCE)) && !defined(NO_GETENV_WIN32)
2691 # define NO_GETENV_WIN32
2692 #endif
2694 #ifndef STRTOULL
2695 # if defined(_WIN64) && !defined(__GNUC__)
2696 # define STRTOULL _strtoui64
2697 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
2698 # define STRTOULL strtoull
2699 # else
2700 /* strtoul() fits since sizeof(long) >= sizeof(word). */
2701 # define STRTOULL strtoul
2702 # endif
2703 #endif /* !STRTOULL */
2705 #ifndef GC_WORD_C
2706 # if defined(_WIN64) && !defined(__GNUC__)
2707 # define GC_WORD_C(val) val##ui64
2708 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
2709 # define GC_WORD_C(val) val##ULL
2710 # else
2711 # define GC_WORD_C(val) ((word)val##UL)
2712 # endif
2713 #endif /* !GC_WORD_C */
2715 #if defined(SPARC)
2716 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2717 /* include assembly code to do it well. */
2718 #endif
2720 /* Can we save call chain in objects for debugging? */
2721 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2722 /* frame) to reasonable values for the platform. */
2723 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2724 /* at build time, though we feel free to adjust it slightly. */
2725 /* Define NEED_CALLINFO if we either save the call stack or */
2726 /* GC_ADD_CALLER is defined. */
2727 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2728 #if defined(SPARC)
2729 # define CAN_SAVE_CALL_ARGS
2730 #endif
2731 #if (defined(I386) || defined(X86_64)) \
2732 && (defined(LINUX) || defined(__GLIBC__))
2733 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2734 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2735 # define CAN_SAVE_CALL_ARGS
2736 #endif
2738 #if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2739 && defined(GC_CAN_SAVE_CALL_STACKS)
2740 # define SAVE_CALL_CHAIN
2741 #endif
2742 #ifdef SAVE_CALL_CHAIN
2743 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2744 # define NARGS SAVE_CALL_NARGS
2745 # else
2746 # define NARGS 0 /* Number of arguments to save for each call. */
2747 # endif
2748 #endif
2749 #ifdef SAVE_CALL_CHAIN
2750 # ifndef SAVE_CALL_COUNT
2751 # define NFRAMES 6 /* Number of frames to save. Even for */
2752 /* alignment reasons. */
2753 # else
2754 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2755 # endif
2756 # define NEED_CALLINFO
2757 #endif /* SAVE_CALL_CHAIN */
2758 #ifdef GC_ADD_CALLER
2759 # define NFRAMES 1
2760 # define NARGS 0
2761 # define NEED_CALLINFO
2762 #endif
2764 #if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2765 # define DBG_HDRS_ALL
2766 #endif
2768 #if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2769 # define POINTER_SHIFT 0
2770 #endif
2772 #if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2773 # define POINTER_MASK ((GC_word)(-1))
2774 #endif
2776 #if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2777 # define FIXUP_POINTER(p) (p = ((p) & POINTER_MASK) << POINTER_SHIFT)
2778 #endif
2780 #if defined(FIXUP_POINTER)
2781 # define NEED_FIXUP_POINTER 1
2782 #else
2783 # define NEED_FIXUP_POINTER 0
2784 # define FIXUP_POINTER(p)
2785 #endif
2787 #if !defined(MARK_BIT_PER_GRANULE) && !defined(MARK_BIT_PER_OBJ)
2788 # define MARK_BIT_PER_GRANULE /* Usually faster */
2789 #endif
2791 /* Some static sanity tests. */
2792 #if defined(MARK_BIT_PER_GRANULE) && defined(MARK_BIT_PER_OBJ)
2793 # error Define only one of MARK_BIT_PER_GRANULE and MARK_BIT_PER_OBJ.
2794 #endif
2796 #if defined(STACK_GROWS_UP) && defined(STACK_GROWS_DOWN)
2797 # error "Only one of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
2798 #endif
2799 #if !defined(STACK_GROWS_UP) && !defined(STACK_GROWS_DOWN)
2800 # error "One of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
2801 #endif
2803 #if defined(REDIRECT_MALLOC) && defined(THREADS) && !defined(LINUX)
2804 # error "REDIRECT_MALLOC with THREADS works at most on Linux."
2805 #endif
2807 #ifdef GC_PRIVATE_H
2808 /* This relies on some type definitions from gc_priv.h, from */
2809 /* where it's normally included. */
2810 /* */
2811 /* How to get heap memory from the OS: */
2812 /* Note that sbrk()-like allocation is preferred, since it */
2813 /* usually makes it possible to merge consecutively allocated */
2814 /* chunks. It also avoids unintended recursion with */
2815 /* REDIRECT_MALLOC macro defined. */
2816 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2817 /* 0 is taken to mean failure. */
2818 /* In the case os USE_MMAP, the argument must also be a */
2819 /* physical page size. */
2820 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2821 /* though we should perhaps take advantage of the case in which */
2822 /* does. */
2823 struct hblk; /* See gc_priv.h. */
2824 # if defined(PCR)
2825 char * real_malloc(size_t bytes);
2826 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)(bytes) + GC_page_size) \
2827 + GC_page_size-1)
2828 # elif defined(OS2)
2829 void * os2_alloc(size_t bytes);
2830 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)(bytes) \
2831 + GC_page_size) + GC_page_size-1)
2832 # elif defined(NEXT) || defined(DOS4GW) || defined(NONSTOP) \
2833 || (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) \
2834 || (defined(SOLARIS) && !defined(USE_MMAP)) || defined(RTEMS) \
2835 || defined(__CC_ARM)
2836 # define GET_MEM(bytes) HBLKPTR((size_t)calloc(1, \
2837 (size_t)(bytes) + GC_page_size) \
2838 + GC_page_size - 1)
2839 # elif defined(MSWIN32) || defined(CYGWIN32)
2840 ptr_t GC_win32_get_mem(GC_word bytes);
2841 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2842 # elif defined(MACOS)
2843 # if defined(USE_TEMPORARY_MEMORY)
2844 Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory);
2845 # define GET_MEM(bytes) HBLKPTR( \
2846 GC_MacTemporaryNewPtr((bytes) + GC_page_size, true) \
2847 + GC_page_size-1)
2848 # else
2849 # define GET_MEM(bytes) HBLKPTR(NewPtrClear((bytes) + GC_page_size) \
2850 + GC_page_size-1)
2851 # endif
2852 # elif defined(MSWINCE)
2853 ptr_t GC_wince_get_mem(GC_word bytes);
2854 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2855 # elif defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2856 void *GC_amiga_get_mem(size_t size);
2857 # define GET_MEM(bytes) HBLKPTR((size_t) \
2858 GC_amiga_get_mem((size_t)(bytes) + GC_page_size) \
2859 + GC_page_size-1)
2860 # elif defined(SN_TARGET_PS3)
2861 void *ps3_get_mem(size_t size);
2862 # define GET_MEM(bytes) (struct hblk*)ps3_get_mem(bytes)
2863 # else
2864 ptr_t GC_unix_get_mem(GC_word bytes);
2865 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2866 # endif
2867 #endif /* GC_PRIVATE_H */
2869 #endif /* GCCONFIG_H */