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
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. */
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
45 #if defined(__SYMBIAN32__) && !defined(SYMBIAN)
48 # pragma data_seg(".data2")
52 /* First a unified test for Linux: */
53 # if (defined(linux) || defined(__linux__) || defined(PLATFORM_ANDROID)) \
54 && !defined(LINUX) && !defined(__native_client__)
58 /* And one for NetBSD: */
59 # if defined(__NetBSD__)
63 /* And one for OpenBSD: */
64 # if defined(__OpenBSD__)
68 /* And one for FreeBSD: */
69 # if (defined(__FreeBSD__) || defined(__DragonFly__) \
70 || defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
74 /* And one for Darwin: */
75 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
79 /* Determine the machine type: */
80 # if defined(__native_client__)
83 # define mach_type_known
85 # if defined(__arm) || defined(__arm__) || defined(__thumb__)
87 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
88 && !defined(DARWIN) && !defined(_WIN32) && !defined(__CEGCC__) \
91 # define mach_type_known
94 # if defined(sun) && defined(mc68000)
95 # error SUNOS4 no longer supported
97 # if defined(hp9000s300)
98 # error M68K based HP machines no longer supported.
100 # if defined(OPENBSD) && defined(m68k)
101 /* FIXME: Should we remove this case? */
103 # define mach_type_known
105 # if defined(OPENBSD) && defined(__sparc__)
107 # define mach_type_known
109 # if defined(OPENBSD) && defined(__arm__)
111 # define mach_type_known
113 # if defined(OPENBSD) && defined(__sh__)
115 # define mach_type_known
117 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
119 # define mach_type_known
121 # if defined(NETBSD) && defined(__powerpc__)
123 # define mach_type_known
125 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
127 # define mach_type_known
129 # if defined(NETBSD) && defined(__sh__)
131 # define mach_type_known
133 # if defined(vax) || defined(__vax__)
140 # define mach_type_known
142 # if defined(__NetBSD__) && defined(__vax__)
144 # define mach_type_known
146 # if defined(mips) || defined(__mips) || defined(_mips)
148 # if defined(nec_ews) || defined(_nec_ews)
151 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD) \
153 # if defined(ultrix) || defined(__ultrix)
156 # define IRIX5 /* or IRIX 6.X */
159 # if defined(__NetBSD__) && defined(__MIPSEL__)
162 # define mach_type_known
164 # if defined(DGUX) && (defined(i386) || defined(__i386__))
169 # define mach_type_known
171 # if defined(sequent) && (defined(i386) || defined(__i386__))
174 # define mach_type_known
176 # if defined(sun) && (defined(i386) || defined(__i386__))
179 # define mach_type_known
181 # if defined(sun) && defined(__amd64)
184 # define mach_type_known
186 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
189 # define mach_type_known
192 # error IBM PC/RT no longer supported.
194 # if defined(sun) && (defined(sparc) || defined(__sparc))
196 /* Test for SunOS 5.x */
199 # define mach_type_known
201 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
202 && !defined(__OpenBSD__) && !defined(__NetBSD__) \
203 && !defined(__FreeBSD__) && !defined(__DragonFly__)
206 # define mach_type_known
211 # define mach_type_known
213 # if defined(__NetBSD__) && defined(__sparc__)
215 # define mach_type_known
217 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
218 /* The above test may need refinement */
220 # if defined(_SCO_ELF)
225 # define mach_type_known
227 # if defined(_AUX_SOURCE)
228 # error A/UX no longer supported
230 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
231 || defined(hppa) || defined(__hppa__)
233 # if !defined(LINUX) && !defined(HPUX) && !defined(OPENBSD)
236 # define mach_type_known
238 # if defined(__ia64) && (defined(_HPUX_SOURCE) || defined(__HP_aCC))
243 # define mach_type_known
245 # if defined(__BEOS__) && defined(_X86_)
248 # define mach_type_known
250 # if defined(OPENBSD) && defined(__amd64__)
252 # define mach_type_known
254 # if defined(LINUX) && (defined(i386) || defined(__i386__))
256 # define mach_type_known
258 # if defined(LINUX) && defined(__x86_64__)
260 # define mach_type_known
262 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
264 # define mach_type_known
266 # if defined(LINUX) && (defined(__arm) || defined(__arm__))
268 # define mach_type_known
270 # if defined(LINUX) && defined(__cris__)
274 # define mach_type_known
276 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) \
277 || defined(powerpc64) || defined(__powerpc64__))
279 # define mach_type_known
281 # if defined(LINUX) && defined(__mc68000__)
283 # define mach_type_known
285 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
287 # define mach_type_known
289 # if defined(LINUX) && defined(__sh__)
291 # define mach_type_known
293 # if defined(LINUX) && defined(__avr32__)
295 # define mach_type_known
297 # if defined(LINUX) && defined(__m32r__)
299 # define mach_type_known
301 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
303 # define mach_type_known
305 # if defined(__alpha) || defined(__alpha__)
307 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
309 # define OSF1 /* a.k.a Digital Unix */
311 # define mach_type_known
313 # if defined(_AMIGA) && !defined(AMIGA)
318 # define mach_type_known
320 # if defined(THINK_C) \
321 || (defined(__MWERKS__) && !defined(__powerc) && !defined(SYMBIAN))
324 # define mach_type_known
326 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__) \
330 # define mach_type_known
332 # if defined(__OpenBSD__) && defined(__powerpc__)
335 # define mach_type_known
338 # if defined(__ppc__) || defined(__ppc64__)
340 # define mach_type_known
341 # elif defined(__x86_64__) || defined(__x86_64)
343 # define mach_type_known
344 # elif defined(__i386__)
346 # define mach_type_known
347 # elif defined(__arm__)
349 # define mach_type_known
350 # define DARWIN_DONT_PARSE_STACK
353 # if defined(__rtems__) && (defined(i386) || defined(__i386__))
356 # define mach_type_known
358 # if defined(NeXT) && defined(mc68000)
361 # define mach_type_known
363 # if defined(NeXT) && (defined(i386) || defined(__i386__))
366 # define mach_type_known
368 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
371 # define mach_type_known
373 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
375 # define mach_type_known
377 # if defined(FREEBSD) && defined(__x86_64__)
379 # define mach_type_known
381 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
383 # define mach_type_known
385 # if defined(__NetBSD__) && defined(__x86_64__)
387 # define mach_type_known
389 # if defined(FREEBSD) && defined(__sparc__)
391 # define mach_type_known
393 # if defined(bsdi) && (defined(i386) || defined(__i386__))
396 # define mach_type_known
398 # if !defined(mach_type_known) && defined(__386BSD__)
401 # define mach_type_known
403 # if defined(_CX_UX) && defined(_M88K)
406 # define mach_type_known
408 # if defined(DGUX) && defined(m88k)
411 # define mach_type_known
413 # if defined(_WIN32_WCE) || defined(__CEGCC__) || defined(__MINGW32CE__)
414 /* SH3, SH4, MIPS already defined for corresponding architectures */
415 # if defined(SH3) || defined(SH4)
418 # if defined(x86) || defined(__i386__)
421 # if defined(_M_ARM) || defined(ARM) || defined(_ARM_)
425 # define mach_type_known
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)
435 # define MSWIN32 /* or Win64 */
436 # define mach_type_known
438 # if defined(_MSC_VER) && defined(_M_IA64)
440 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
441 /* variants as a different platform. */
444 # if defined(__DJGPP__)
447 # define DJGPP /* MSDOS running the DJGPP port of GCC */
449 # define mach_type_known
451 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
454 # define mach_type_known
456 # if defined(__MINGW32__) && !defined(mach_type_known)
459 # define mach_type_known
461 # if defined(__BORLANDC__)
464 # define mach_type_known
466 # if defined(_UTS) && !defined(mach_type_known)
469 # define mach_type_known
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. */
476 # if defined(__embedded__) && defined(PPC)
479 # define mach_type_known
482 # if defined(__WATCOMC__) && defined(__386__)
484 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
485 # if defined(__OS2__)
488 # if defined(__WINDOWS_386__) || defined(__NT__)
495 # define mach_type_known
497 # if defined(__s390__) && defined(LINUX)
499 # define mach_type_known
501 # if defined(__GNU__)
502 # if defined(__i386__)
503 /* The Debian Hurd running on generic PC */
506 # define mach_type_known
509 # if defined(__TANDEM)
510 /* Nonstop S-series */
511 /* FIXME: Should recognize Integrity series? */
514 # define mach_type_known
516 # if defined(__hexagon__) && defined(LINUX)
518 # define mach_type_known
521 # if defined(SYMBIAN)
522 # define mach_type_known
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."
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 */
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 */
560 /* ARM32 ==> Intel StrongARM */
561 /* IA64 ==> Intel IPF */
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 */
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
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)
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
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)
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
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 */ \
706 && !defined(__clang__) /* since no-op in clang (3.0) */
707 # define HAVE_BUILTIN_UNWIND_INIT
711 # define MACH_TYPE "SYMBIAN"
712 # define OS_TYPE "SYMBIAN"
713 # define CPP_WORDSZ 32
715 # define DATASTART NULL
716 # define DATAEND NULL
719 # define STACK_GRAN 0x1000000
721 # define MACH_TYPE "M68K"
724 /* FIXME: Should we remove this case? */
725 # define OS_TYPE "OPENBSD"
728 extern ptr_t GC_data_start
;
729 # define DATASTART GC_data_start
730 # define DYNAMIC_LOADING
733 # define DATASTART ((ptr_t)(etext))
737 # define OS_TYPE "NETBSD"
740 extern ptr_t GC_data_start
;
741 # define DATASTART GC_data_start
742 # define DYNAMIC_LOADING
745 # define DATASTART ((ptr_t)(etext))
749 # define OS_TYPE "LINUX"
750 # define LINUX_STACKBOTTOM
751 # define MPROTECT_VDB
753 # define DYNAMIC_LOADING
754 # include <features.h>
755 # if defined(__GLIBC__) && __GLIBC__ >= 2
756 # define SEARCH_FOR_DATA_START
758 # ifdef PLATFORM_ANDROID
759 # define __environ environ
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 */
773 # define DATAEND (ptr_t)(_end)
776 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
780 # define OS_TYPE "AMIGA"
781 /* STACKBOTTOM and DATASTART handled specially */
783 # define DATAEND /* not needed */
784 # define GETPAGESIZE() 4096
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
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 */
805 # if defined(POWERPC)
806 # define MACH_TYPE "POWERPC"
808 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
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 */
818 # if defined(__powerpc64__)
820 # define CPP_WORDSZ 64
822 # define HBLKSIZE 4096
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
834 # define DATAEND (ptr_t)(_end)
837 # define OS_TYPE "DARWIN"
838 # define DYNAMIC_LOADING
839 # if defined(__ppc64__)
841 # define CPP_WORDSZ 64
842 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
843 # define CACHE_LINE_SIZE 64
845 # define HBLKSIZE 4096
849 # define STACKBOTTOM ((ptr_t) 0xc0000000)
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())
858 # define USE_MMAP_ANON
859 # define MPROTECT_VDB
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)))
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
874 # define OS_TYPE "OPENBSD"
876 # ifdef GC_OPENBSD_THREADS
877 # define UTHREAD_SP_OFFSET 268
879 # include <sys/param.h>
880 # include <uvm/uvm_extern.h>
881 # define STACKBOTTOM ((ptr_t) USRSTACK)
883 extern int __data_start
[];
884 # define DATASTART ((ptr_t)__data_start)
886 # define DATAEND ((ptr_t)(&_end))
887 # define DYNAMIC_LOADING
890 # if defined(__powerpc64__)
892 # define CPP_WORDSZ 64
894 # define HBLKSIZE 4096
899 # define OS_TYPE "FREEBSD"
900 # ifndef GC_FREEBSD_THREADS
901 # define MPROTECT_VDB
903 # define SIG_SUSPEND SIGUSR1
904 # define SIG_THR_RESTART SIGUSR2
905 # define FREEBSD_STACKBOTTOM
907 # define DYNAMIC_LOADING
910 ptr_t
GC_FreeBSDGetDataStart(size_t, ptr_t
);
911 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
912 # define DATASTART_IS_FUNC
916 # define OS_TYPE "NETBSD"
918 extern ptr_t GC_data_start
;
919 # define DATASTART GC_data_start
920 # define DYNAMIC_LOADING
922 # ifdef SN_TARGET_PS3
924 # define CPP_WORDSZ 32
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. */
936 # define OS_TYPE "AIX"
937 # undef ALIGNMENT /* in case it's defined */
939 /* DOB: some AIX installs stupidly define IA64 in */
940 /* /usr/include/sys/systemcfg.h */
943 # define CPP_WORDSZ 64
944 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
947 # define CPP_WORDSZ 32
948 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
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))
965 # define DYNAMIC_LOADING
966 /* For really old versions of AIX, this may have to be removed. */
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. */
977 # define STACK_GRAN 0x10000000
983 # define MACH_TYPE "VAX"
984 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
986 # define DATASTART ((ptr_t)(etext))
988 # define OS_TYPE "BSD"
990 /* HEURISTIC2 may be OK, but it's hard to test. */
993 # define OS_TYPE "ULTRIX"
994 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
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
1005 # define ALIGNMENT 4 /* Required by hardware */
1006 # define CPP_WORDSZ 32
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. */
1011 # define OS_TYPE "SOLARIS"
1012 extern int _etext
[];
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)
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. */
1026 # define HEAP_START (ptr_t)0x40000000
1028 # define HEAP_START DATAEND
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 */
1036 # include <sys/vmparam.h>
1038 /* This should work everywhere, but doesn't. */
1039 # define STACKBOTTOM ((ptr_t) USRSTACK)
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
1050 # define OS_TYPE "DRSNX"
1051 ptr_t
GC_SysVGetDataStart(size_t, ptr_t
);
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
1060 # define OS_TYPE "LINUX"
1062 # define DYNAMIC_LOADING
1064 Linux Sparc
/a
.out
not supported
1067 extern int _etext
[];
1068 # define DATAEND (ptr_t)(_end)
1070 ptr_t
GC_SysVGetDataStart(size_t, ptr_t
);
1072 # define DATASTART GC_SysVGetDataStart(0x100000, (ptr_t)_etext)
1074 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1076 # define DATASTART_IS_FUNC
1077 # define LINUX_STACKBOTTOM
1080 # define OS_TYPE "OPENBSD"
1081 # ifdef GC_OPENBSD_THREADS
1082 # define UTHREAD_SP_OFFSET 232
1084 # include <sys/param.h>
1085 # include <uvm/uvm_extern.h>
1086 # define STACKBOTTOM ((ptr_t) USRSTACK)
1088 extern int __data_start
[];
1089 # define DATASTART ((ptr_t)__data_start)
1091 # define DATAEND ((ptr_t)(&_end))
1092 # define DYNAMIC_LOADING
1095 # define OS_TYPE "NETBSD"
1098 extern ptr_t GC_data_start
;
1099 # define DATASTART GC_data_start
1100 # define DYNAMIC_LOADING
1102 extern char etext
[];
1103 # define DATASTART ((ptr_t)(etext))
1107 # define OS_TYPE "FREEBSD"
1108 # define SIG_SUSPEND SIGUSR1
1109 # define SIG_THR_RESTART SIGUSR2
1110 # define FREEBSD_STACKBOTTOM
1112 # define DYNAMIC_LOADING
1114 extern char etext
[];
1115 extern char edata
[];
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))
1128 # define MACH_TYPE "I386"
1129 # if defined(__LP64__) || defined(_WIN64)
1130 # error This should be handled as X86_64
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. */
1139 # define OS_TYPE "SEQUENT"
1141 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1142 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1145 # define OS_TYPE "BEOS"
1147 # define GETPAGESIZE() B_PAGE_SIZE
1149 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
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
1171 # define MPROTECT_VDB
1173 # define DYNAMIC_LOADING
1174 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
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. */
1182 # define HEAP_START (ptr_t)0x40000000
1184 # define HEAP_START DATAEND
1188 # define OS_TYPE "SCO"
1190 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1192 +((word)etext & 0xfff))
1193 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1196 # define OS_TYPE "SCO_ELF"
1198 # define DATASTART ((ptr_t)(etext))
1199 # define STACKBOTTOM ((ptr_t) 0x08048000)
1200 # define DYNAMIC_LOADING
1201 # define ELF_CLASS ELFCLASS32
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
1212 # include <unistd.h>
1213 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1214 # define DYNAMIC_LOADING
1218 # define MAP_FAILED (void *) ((word)-1)
1220 # define HEAP_START (ptr_t)0x40000000
1222 # define HEAP_START DATAEND
1227 # define OS_TYPE "NACL"
1229 /* #define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff)) */
1230 # define DATASTART ((ptr_t)0x10000000)
1232 # define DATAEND (_end)
1234 # define STACK_GRAN 0x10000
1236 # define GETPAGESIZE() 65536
1237 # ifndef MAX_NACL_GC_THREADS
1238 # define MAX_NACL_GC_THREADS 1024
1243 # define OS_TYPE "LINUX"
1244 # define LINUX_STACKBOTTOM
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. */
1254 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1255 # define MPROTECT_VDB
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. */
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 */
1265 # define DYNAMIC_LOADING
1266 # ifdef UNDEFINED /* includes ro data */
1267 extern int _etext
[];
1268 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1270 # include <features.h>
1271 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1272 || defined(PLATFORM_ANDROID)
1273 # define SEARCH_FOR_DATA_START
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. */
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
1295 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
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)))
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)))
1321 # define OS_TYPE "CYGWIN32"
1322 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1323 # define DATAEND ((ptr_t)GC_DATAEND)
1325 # define STACK_GRAN 0x10000
1327 # define NEED_FIND_LIMIT
1328 # define USE_MMAP_ANON
1332 # define OS_TYPE "OS2"
1333 /* STACKBOTTOM and DATASTART are handled specially in */
1334 /* os_dep.c. OS2 actually has the right */
1336 # define DATAEND /* not needed */
1339 # define OS_TYPE "MSWIN32"
1340 /* STACKBOTTOM and DATASTART are handled specially in */
1342 # define MPROTECT_VDB
1344 # define DATAEND /* not needed */
1347 # define OS_TYPE "MSWINCE"
1348 # define DATAEND /* not needed */
1351 # define OS_TYPE "DJGPP"
1352 # include "stubinfo.h"
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. */
1362 # define OS_TYPE "OPENBSD"
1363 # ifdef GC_OPENBSD_THREADS
1364 # define UTHREAD_SP_OFFSET 176
1366 # include <sys/param.h>
1367 # include <uvm/uvm_extern.h>
1368 # define STACKBOTTOM ((ptr_t) USRSTACK)
1370 extern int __data_start
[];
1371 # define DATASTART ((ptr_t)__data_start)
1373 # define DATAEND ((ptr_t)(&_end))
1374 # define DYNAMIC_LOADING
1377 # define OS_TYPE "FREEBSD"
1378 # ifndef GC_FREEBSD_THREADS
1379 # define MPROTECT_VDB
1382 # define SIG_SUSPEND (32+6)
1383 # define SIG_THR_RESTART (32+5)
1385 # define DATAEND (ptr_t)(_end)
1387 # define SIG_SUSPEND SIGUSR1
1388 # define SIG_THR_RESTART SIGUSR2
1389 /* SIGTSTP and SIGCONT could be used alternatively. */
1391 # define FREEBSD_STACKBOTTOM
1393 # define DYNAMIC_LOADING
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
1401 # define OS_TYPE "NETBSD"
1403 # define DYNAMIC_LOADING
1407 # define OS_TYPE "THREE86BSD"
1410 # define OS_TYPE "BSDI"
1412 # if defined(NETBSD) || defined(THREE86BSD) || defined(BSDI)
1414 extern char etext
[];
1415 # define DATASTART ((ptr_t)(etext))
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 */
1425 # define OS_TYPE "RTEMS"
1426 # include <sys/unistd.h>
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
1438 # define OS_TYPE "DOS4GW"
1439 extern long __nullarea
;
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)
1453 # define OS_TYPE "HURD"
1454 # define STACK_GROWS_DOWN
1456 # define SIG_SUSPEND SIGUSR1
1457 # define SIG_THR_RESTART SIGUSR2
1458 # define SEARCH_FOR_DATA_START
1460 # define DATAEND ((ptr_t) (_end))
1461 /* # define MPROTECT_VDB Not quite working yet? */
1462 # define DYNAMIC_LOADING
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)
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 */
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 */
1499 # define MACH_TYPE "MIPS"
1501 # define OS_TYPE "LINUX"
1502 # define DYNAMIC_LOADING
1504 # define DATAEND (ptr_t)(_end)
1505 # pragma weak __data_start
1506 extern int __data_start
[];
1507 # define DATASTART ((ptr_t)(__data_start))
1509 # define CPP_WORDSZ _MIPS_SZPTR
1510 # define ALIGNMENT (_MIPS_SZPTR/8)
1512 # define ALIGNMENT 4
1515 # define HBLKSIZE 4096
1517 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1518 # define LINUX_STACKBOTTOM
1520 # define STACKBOTTOM ((ptr_t)0x7fff8000)
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)
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) \
1540 # define DATAEND2 (ptr_t)(end)
1541 # define ALIGNMENT 4
1543 # define OS_TYPE "EWS4800"
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
1555 extern int _fdata
[];
1556 # define DATASTART ((ptr_t)(_fdata))
1558 # define HEAP_START (ptr_t)0x30000000
1560 # define HEAP_START DATASTART
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. */
1571 # define CPP_WORDSZ _MIPS_SZPTR
1572 # define ALIGNMENT (_MIPS_SZPTR/8)
1574 # define ALIGNMENT 4
1576 # define DYNAMIC_LOADING
1579 # define OS_TYPE "MSWINCE"
1580 # define ALIGNMENT 4
1581 # define DATAEND /* not needed */
1583 # if defined(NETBSD)
1584 # define OS_TYPE "NETBSD"
1585 # define ALIGNMENT 4
1588 extern ptr_t GC_data_start
;
1589 # define DATASTART GC_data_start
1590 # define NEED_FIND_LIMIT
1591 # define DYNAMIC_LOADING
1593 # define DATASTART ((ptr_t) 0x10000000)
1594 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1598 # define OS_TYPE "OPENBSD"
1599 # define ALIGNMENT 4
1600 # ifdef GC_OPENBSD_THREADS
1601 # define UTHREAD_SP_OFFSET 808
1603 # include <sys/param.h>
1604 # include <uvm/uvm_extern.h>
1605 # define STACKBOTTOM ((ptr_t) USRSTACK)
1607 extern int _fdata
[];
1608 # define DATASTART ((ptr_t)_fdata)
1610 # define DATAEND ((ptr_t)(&_end))
1611 # define DYNAMIC_LOADING
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)
1625 # define MACH_TYPE "HP_PA"
1627 # define CPP_WORDSZ 64
1628 # define ALIGNMENT 8
1630 # define CPP_WORDSZ 32
1631 # define ALIGNMENT 4
1633 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS) \
1634 && !defined(OPENBSD) && !defined(LINUX) /* For now. */
1635 # define MPROTECT_VDB
1637 # define STACK_GROWS_UP
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 */
1650 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
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)
1658 # define DYNAMIC_LOADING
1659 # include <unistd.h>
1660 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1662 # define PREFETCH(x) { \
1663 register long addr = (long)(x); \
1664 (void) _asm ("LDW", 0, 0, addr, 0); \
1669 # define OS_TYPE "LINUX"
1670 # define LINUX_STACKBOTTOM
1671 # define DYNAMIC_LOADING
1672 # define SEARCH_FOR_DATA_START
1674 # define DATAEND (ptr_t)(&_end)
1677 # define OS_TYPE "OPENBSD"
1678 # ifdef GC_OPENBSD_THREADS
1679 # define UTHREAD_SP_OFFSET 520
1681 # include <sys/param.h>
1682 # include <uvm/uvm_extern.h>
1683 # define STACKBOTTOM ((ptr_t) USRSTACK)
1685 extern int __data_start
[];
1686 # define DATASTART ((ptr_t)__data_start)
1688 # define DATAEND ((ptr_t)(&_end))
1689 # define DYNAMIC_LOADING
1694 # define MACH_TYPE "ALPHA"
1695 # define ALIGNMENT 8
1696 # define CPP_WORDSZ 64
1698 # define OS_TYPE "NETBSD"
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
1708 # define OS_TYPE "OPENBSD"
1709 # define ELF_CLASS ELFCLASS64
1710 # ifdef GC_OPENBSD_THREADS
1711 # define UTHREAD_SP_OFFSET 816
1713 # include <sys/param.h>
1714 # include <uvm/uvm_extern.h>
1715 # define STACKBOTTOM ((ptr_t) USRSTACK)
1717 extern int __data_start
[];
1718 # define DATASTART ((ptr_t)__data_start)
1720 # define DATAEND ((ptr_t)(&_end))
1721 # define DYNAMIC_LOADING
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
1731 # define DYNAMIC_LOADING
1733 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1734 extern char etext
[];
1735 extern char edata
[];
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))
1746 # define OS_TYPE "OSF1"
1747 # define DATASTART ((ptr_t) 0x140000000)
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
1766 # define DYNAMIC_LOADING
1769 # define OS_TYPE "LINUX"
1770 # define LINUX_STACKBOTTOM
1772 # define SEARCH_FOR_DATA_START
1773 # define DYNAMIC_LOADING
1775 # define DATASTART ((ptr_t) 0x140000000)
1778 # define DATAEND (ptr_t)(_end)
1779 # define MPROTECT_VDB
1780 /* Has only been superficially tested. May not */
1781 /* work on all versions. */
1786 # define MACH_TYPE "IA64"
1789 # define CPP_WORDSZ 32
1790 /* Requires 8 byte alignment for malloc */
1791 # define ALIGNMENT 4
1794 # error --> unknown ABI
1796 # define CPP_WORDSZ 64
1797 /* Requires 16 byte alignment for malloc */
1798 # define ALIGNMENT 8
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!!! */
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 */
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
1840 # define DYNAMIC_LOADING
1842 /* In the Intel compiler environment, we seem to end up with */
1843 /* statically linked executables and an undefined reference */
1846 # define MPROTECT_VDB
1847 /* Requires Linux 2.3.47 or later. */
1849 # define DATAEND (ptr_t)(_end)
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)))
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 */
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 */
1874 # define DATAEND /* not needed */
1875 # if defined(_WIN64)
1876 # define CPP_WORDSZ 64
1878 # define CPP_WORDSZ 32 /* Is this possible? */
1880 # define ALIGNMENT 8
1885 # define MACH_TYPE "M88K"
1886 # define ALIGNMENT 4
1889 # define OS_TYPE "CX_UX"
1890 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
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
1898 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
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 */
1907 # define OS_TYPE "UTS4"
1909 extern int _etext
[];
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)
1920 # define MACH_TYPE "S390"
1922 # define ALIGNMENT 4
1923 # define CPP_WORDSZ 32
1925 # define ALIGNMENT 8
1926 # define CPP_WORDSZ 64
1928 # define HBLKSIZE 4096
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))
1938 # define DATAEND (ptr_t)(_end)
1939 # define CACHE_LINE_SIZE 256
1940 # define GETPAGESIZE() 4096
1945 # define CPP_WORDSZ 32
1946 # define MACH_TYPE "ARM32"
1947 # define ALIGNMENT 4
1949 # define OS_TYPE "NETBSD"
1952 extern ptr_t GC_data_start
;
1953 # define DATASTART GC_data_start
1954 # define DYNAMIC_LOADING
1956 extern char etext
[];
1957 # define DATASTART ((ptr_t)(etext))
1961 # define OS_TYPE "LINUX"
1962 # define LINUX_STACKBOTTOM
1964 # define STACK_GRAN 0x10000000
1966 # define DYNAMIC_LOADING
1967 # include <features.h>
1968 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1969 || defined(PLATFORM_ANDROID)
1970 # define SEARCH_FOR_DATA_START
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. */
1984 # define DATAEND (ptr_t)(_end)
1987 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1991 # define OS_TYPE "MSWINCE"
1992 # define DATAEND /* not needed */
1996 # define OS_TYPE "DARWIN"
1997 # ifndef GC_DONT_REGISTER_MAIN_STATIC_DATA
1998 # define DYNAMIC_LOADING
2000 # define DATASTART ((ptr_t) get_etext())
2001 # define DATAEND ((ptr_t) get_end())
2002 # define STACKBOTTOM ((ptr_t) 0x30000000)
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
2018 # define ALIGNMENT 4
2019 # define OS_TYPE "OPENBSD"
2020 # ifdef GC_OPENBSD_THREADS
2021 # define UTHREAD_SP_OFFSET 176
2023 # include <sys/param.h>
2024 # include <uvm/uvm_extern.h>
2025 # define STACKBOTTOM ((ptr_t) USRSTACK)
2027 extern int __data_start
[];
2028 # define DATASTART ((ptr_t)__data_start)
2030 # define DATAEND ((ptr_t)(&_end))
2031 # define DYNAMIC_LOADING
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__))
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
2052 # define DATAEND (ptr_t)(_end)
2055 # if defined(SH) && !defined(SH4)
2056 # define MACH_TYPE "SH"
2057 # define ALIGNMENT 4
2059 # define OS_TYPE "MSWINCE"
2060 # define DATAEND /* not needed */
2063 # define OS_TYPE "LINUX"
2064 # define LINUX_STACKBOTTOM
2065 # define DYNAMIC_LOADING
2066 # define SEARCH_FOR_DATA_START
2068 # define DATAEND (ptr_t)(_end)
2071 # define OS_TYPE "NETBSD"
2073 extern ptr_t GC_data_start
;
2074 # define DATASTART GC_data_start
2075 # define DYNAMIC_LOADING
2078 # define OS_TYPE "OPENBSD"
2079 # ifdef GC_OPENBSD_THREADS
2080 # define UTHREAD_SP_OFFSET 332
2082 # include <sys/param.h>
2083 # include <uvm/uvm_extern.h>
2084 # define STACKBOTTOM ((ptr_t) USRSTACK)
2086 extern int __data_start
[];
2087 # define DATASTART ((ptr_t)__data_start)
2089 # define DATAEND ((ptr_t)(&_end))
2090 # define DYNAMIC_LOADING
2095 # define MACH_TYPE "SH4"
2096 # define OS_TYPE "MSWINCE"
2097 # define ALIGNMENT 4
2098 # define DATAEND /* not needed */
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
2110 # define DATAEND (_end)
2114 # define CPP_WORDSZ 32
2115 # define MACH_TYPE "M32R"
2116 # define ALIGNMENT 4
2118 # define OS_TYPE "LINUX"
2119 # define LINUX_STACKBOTTOM
2121 # define STACK_GRAN 0x10000000
2122 # define DYNAMIC_LOADING
2123 # define SEARCH_FOR_DATA_START
2125 # define DATAEND (ptr_t)(_end)
2130 # define MACH_TYPE "X86_64"
2132 # define ALIGNMENT 4
2133 # define CPP_WORDSZ 32
2135 # define ALIGNMENT 8
2136 # define CPP_WORDSZ 64
2139 # define HBLKSIZE 4096
2141 # define CACHE_LINE_SIZE 64
2143 # define OS_TYPE "OPENBSD"
2144 # define ELF_CLASS ELFCLASS64
2145 # ifdef GC_OPENBSD_THREADS
2146 # define UTHREAD_SP_OFFSET 400
2148 # include <sys/param.h>
2149 # include <uvm/uvm_extern.h>
2150 # define STACKBOTTOM ((ptr_t) USRSTACK)
2152 extern int __data_start
[];
2153 # define DATASTART ((ptr_t)__data_start)
2155 # define DATAEND ((ptr_t)(&_end))
2156 # define DYNAMIC_LOADING
2159 # define OS_TYPE "LINUX"
2160 # define LINUX_STACKBOTTOM
2161 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2162 # define MPROTECT_VDB
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. */
2169 # define DYNAMIC_LOADING
2170 # ifdef UNDEFINED /* includes ro data */
2171 extern int _etext
[];
2172 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
2174 # include <features.h>
2175 # define SEARCH_FOR_DATA_START
2177 # define DATAEND (ptr_t)(_end)
2180 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
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)
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
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)
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
2215 # define OS_TYPE "FREEBSD"
2216 # ifndef GC_FREEBSD_THREADS
2217 # define MPROTECT_VDB
2220 # define SIG_SUSPEND (32+6)
2221 # define SIG_THR_RESTART (32+5)
2223 # define DATAEND (ptr_t)(_end)
2225 # define SIG_SUSPEND SIGUSR1
2226 # define SIG_THR_RESTART SIGUSR2
2227 /* SIGTSTP and SIGCONT could be used alternatively. */
2229 # define FREEBSD_STACKBOTTOM
2231 # define DYNAMIC_LOADING
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
2239 # define OS_TYPE "NETBSD"
2242 extern ptr_t GC_data_start
;
2243 # define DATASTART GC_data_start
2244 # define DYNAMIC_LOADING
2246 # define SEARCH_FOR_DATA_START
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 */
2265 # include <sys/vmparam.h>
2267 /* This should work everywhere, but doesn't. */
2268 # define STACKBOTTOM ((ptr_t) USRSTACK)
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
2278 # define MPROTECT_VDB
2280 # define DYNAMIC_LOADING
2281 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
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. */
2289 # define HEAP_START (ptr_t)0x40000000
2291 # define HEAP_START DATAEND
2295 # define OS_TYPE "MSWIN32"
2296 /* STACKBOTTOM and DATASTART are handled specially in */
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
2304 # define DATAEND /* not needed */
2306 # endif /* X86_64 */
2309 # define CPP_WORDSZ 32
2310 # define MACH_TYPE "HEXAGON"
2311 # define ALIGNMENT 4
2313 # define OS_TYPE "LINUX"
2314 # define LINUX_STACKBOTTOM
2315 # define MPROTECT_VDB
2317 # define DYNAMIC_LOADING
2318 # include <features.h>
2319 # if defined(__GLIBC__) && __GLIBC__ >= 2
2320 # define SEARCH_FOR_DATA_START
2322 # error --> unknown Hexagon libc configuration
2325 # define DATAEND (ptr_t)(_end)
2327 # error --> bad Hexagon Linux configuration
2330 # error --> unknown Hexagon OS configuration
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
2340 /* This may still fail on some architectures like IA64. */
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
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
2377 #ifndef STACK_GROWS_UP
2378 # define STACK_GROWS_DOWN
2382 # define CPP_WORDSZ 32
2391 # define DATAEND (ptr_t)(end)
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
2402 #if (defined(SVR4) || defined(PLATFORM_ANDROID)) && !defined(GETPAGESIZE)
2403 # include <unistd.h>
2404 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
2408 # if defined(SOLARIS) || defined(IRIX5) || defined(LINUX) \
2409 || defined(NETBSD) || defined(FREEBSD) || defined(HPUX)
2410 # include <unistd.h>
2412 # define GETPAGESIZE() getpagesize()
2415 #if defined(SOLARIS) || defined(DRSNX) || defined(UTS4)
2416 /* OS has SVR4 generic features. */
2417 /* Probably others also qualify. */
2421 #if defined(SOLARIS) || defined(DRSNX)
2422 /* OS has SOLARIS style semi-undocumented interface */
2423 /* to dynamic loader. */
2425 /* OS has SOLARIS style signal handlers. */
2433 #if defined(FREEBSD) && (defined(__DragonFly__) || __FreeBSD__ >= 4 \
2434 || (__FreeBSD_kernel__ >= 4))
2438 #if !defined(GC_EXPLICIT_SIGNALS_UNBLOCK) && defined(SUNOS5SIGS) \
2439 && !defined(GC_NO_PTHREAD_SIGMASK)
2440 # define GC_EXPLICIT_SIGNALS_UNBLOCK
2443 #ifdef GC_NETBSD_THREADS
2444 # define SIGRTMIN 33
2445 # define SIGRTMAX 63
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. */
2455 #if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2456 # error --> bad word size
2460 # error --> undefined ALIGNMENT
2464 # undef DYNAMIC_LOADING
2469 # undef MPROTECT_VDB
2473 #if !defined(STACKBOTTOM) && (defined(ECOS) || defined(NOSYS))
2474 # error --> undefined STACKBOTTOM
2477 #ifdef IGNORE_DYNAMIC_LOADING
2478 # undef DYNAMIC_LOADING
2481 #if defined(SMALL_CONFIG) && !defined(GC_DISABLE_INCREMENTAL)
2482 /* Presumably not worth the space it takes. */
2483 # define GC_DISABLE_INCREMENTAL
2486 #if (defined(MSWIN32) || defined(MSWINCE)) && !defined(USE_WINALLOC)
2487 /* USE_WINALLOC is only an option for Cygwin. */
2488 # define USE_WINALLOC
2495 #if defined(GC_DISABLE_INCREMENTAL) || defined(MANUAL_VDB)
2497 # undef MPROTECT_VDB
2502 #ifdef GC_DISABLE_INCREMENTAL
2506 #ifdef USE_GLOBAL_ALLOC
2507 /* Cannot pass MEM_WRITE_WATCH to GlobalAlloc(). */
2512 /* FIXME: Remove this undef if possible. */
2513 # undef MPROTECT_VDB /* Can't deal with address space holes. */
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). */
2522 /* #undef GWW_VDB - handled in os_dep.c */
2526 /* Multi-VDB mode is not implemented. */
2527 # undef MPROTECT_VDB
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
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
2546 # define PREFETCH(x)
2547 # define NO_PREFETCH
2550 #ifndef PREFETCH_FOR_WRITE
2551 # define PREFETCH_FOR_WRITE(x)
2552 # define NO_PREFETCH_FOR_WRITE
2555 #ifndef CACHE_LINE_SIZE
2556 # define CACHE_LINE_SIZE 32 /* Wild guess */
2560 # ifndef NO_DEBUGGING
2561 # define STATIC /* ignore to aid profiling and possibly debugging */
2563 # define STATIC static
2567 #if defined(LINUX) && (defined(USE_PROC_FOR_LIBRARIES) || defined(IA64) \
2568 || !defined(SMALL_CONFIG))
2569 # define NEED_PROC_MAPS
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. */
2581 #if defined(SEARCH_FOR_DATA_START)
2582 extern ptr_t GC_data_start
;
2583 # define DATASTART GC_data_start
2586 #ifndef CLEAR_DOUBLE
2587 # define CLEAR_DOUBLE(x) (((word*)(x))[0] = 0, ((word*)(x))[1] = 0)
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
2597 #if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2598 # error --> inconsistent configuration
2600 #if defined(GC_LINUX_THREADS) && !defined(LINUX) && !defined(NACL)
2601 # error --> inconsistent configuration
2603 #if defined(GC_NETBSD_THREADS) && !defined(NETBSD)
2604 # error --> inconsistent configuration
2606 #if defined(GC_FREEBSD_THREADS) && !defined(FREEBSD)
2607 # error --> inconsistent configuration
2609 #if defined(GC_SOLARIS_THREADS) && !defined(SOLARIS)
2610 # error --> inconsistent configuration
2612 #if defined(GC_HPUX_THREADS) && !defined(HPUX)
2613 # error --> inconsistent configuration
2615 #if defined(GC_AIX_THREADS) && !defined(_AIX)
2616 # error --> inconsistent configuration
2618 #if defined(GC_GNU_THREADS) && !defined(HURD)
2619 # error --> inconsistent configuration
2621 #if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32) \
2622 && !defined(MSWINCE)
2623 # error --> inconsistent configuration
2626 #if defined(PCR) || defined(GC_WIN32_THREADS) || defined(GC_PTHREADS) \
2627 || defined(SN_TARGET_PS3)
2631 #if defined(PARALLEL_MARK) && !defined(THREADS)
2632 # error "invalid config - PARALLEL_MARK requires GC_THREADS"
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
2653 # define IF_CANCEL(x) x
2655 # define IF_CANCEL(x) /* empty */
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
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
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
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
2686 #if defined(MSWINCE) && !defined(__CEGCC__) && !defined(NO_GETENV)
2690 #if (defined(NO_GETENV) || defined(MSWINCE)) && !defined(NO_GETENV_WIN32)
2691 # define NO_GETENV_WIN32
2695 # if defined(_WIN64) && !defined(__GNUC__)
2696 # define STRTOULL _strtoui64
2697 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
2698 # define STRTOULL strtoull
2700 /* strtoul() fits since sizeof(long) >= sizeof(word). */
2701 # define STRTOULL strtoul
2703 #endif /* !STRTOULL */
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
2711 # define GC_WORD_C(val) ((word)val##UL)
2713 #endif /* !GC_WORD_C */
2716 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2717 /* include assembly code to do it well. */
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. */
2729 # define CAN_SAVE_CALL_ARGS
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
2738 #if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2739 && defined(GC_CAN_SAVE_CALL_STACKS)
2740 # define SAVE_CALL_CHAIN
2742 #ifdef SAVE_CALL_CHAIN
2743 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2744 # define NARGS SAVE_CALL_NARGS
2746 # define NARGS 0 /* Number of arguments to save for each call. */
2749 #ifdef SAVE_CALL_CHAIN
2750 # ifndef SAVE_CALL_COUNT
2751 # define NFRAMES 6 /* Number of frames to save. Even for */
2752 /* alignment reasons. */
2754 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2756 # define NEED_CALLINFO
2757 #endif /* SAVE_CALL_CHAIN */
2758 #ifdef GC_ADD_CALLER
2761 # define NEED_CALLINFO
2764 #if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2765 # define DBG_HDRS_ALL
2768 #if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2769 # define POINTER_SHIFT 0
2772 #if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2773 # define POINTER_MASK ((GC_word)(-1))
2776 #if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2777 # define FIXUP_POINTER(p) (p = ((p) & POINTER_MASK) << POINTER_SHIFT)
2780 #if defined(FIXUP_POINTER)
2781 # define NEED_FIXUP_POINTER 1
2783 # define NEED_FIXUP_POINTER 0
2784 # define FIXUP_POINTER(p)
2787 #if !defined(MARK_BIT_PER_GRANULE) && !defined(MARK_BIT_PER_OBJ)
2788 # define MARK_BIT_PER_GRANULE /* Usually faster */
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.
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."
2799 #if !defined(STACK_GROWS_UP) && !defined(STACK_GROWS_DOWN)
2800 # error "One of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
2803 #if defined(REDIRECT_MALLOC) && defined(THREADS) && !defined(LINUX)
2804 # error "REDIRECT_MALLOC with THREADS works at most on Linux."
2808 /* This relies on some type definitions from gc_priv.h, from */
2809 /* where it's normally included. */
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 */
2823 struct hblk
; /* See gc_priv.h. */
2825 char * real_malloc(size_t bytes
);
2826 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)(bytes) + GC_page_size) \
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) \
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) \
2849 # define GET_MEM(bytes) HBLKPTR(NewPtrClear((bytes) + GC_page_size) \
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) \
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)
2864 ptr_t
GC_unix_get_mem(GC_word bytes
);
2865 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2867 #endif /* GC_PRIVATE_H */
2869 #endif /* GCCONFIG_H */