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 /* First a unified test for Linux: */
41 # if (defined(linux) || defined(__linux__) || defined(PLATFORM_ANDROID)) \
42 && !defined(LINUX) && !defined(__native_client__)
46 /* And one for NetBSD: */
47 # if defined(__NetBSD__)
51 /* And one for OpenBSD: */
52 # if defined(__OpenBSD__)
56 /* And one for FreeBSD: */
57 # if (defined(__FreeBSD__) || defined(__DragonFly__) \
58 || defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
62 /* And one for Darwin: */
63 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
67 /* Determine the machine type: */
68 # if defined(__native_client__)
71 # define mach_type_known
73 # if defined(__arm) || defined(__arm__) || defined(__thumb__)
75 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
76 && !defined(DARWIN) && !defined(_WIN32) && !defined(__CEGCC__)
78 # define mach_type_known
81 # if defined(sun) && defined(mc68000)
82 # error SUNOS4 no longer supported
84 # if defined(hp9000s300)
85 # error M68K based HP machines no longer supported.
87 # if defined(OPENBSD) && defined(m68k)
88 /* FIXME: Should we remove this case? */
90 # define mach_type_known
92 # if defined(OPENBSD) && defined(__sparc__)
94 # define mach_type_known
96 # if defined(OPENBSD) && defined(__arm__)
98 # define mach_type_known
100 # if defined(OPENBSD) && defined(__sh__)
102 # define mach_type_known
104 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
106 # define mach_type_known
108 # if defined(NETBSD) && defined(__powerpc__)
110 # define mach_type_known
112 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
114 # define mach_type_known
116 # if defined(NETBSD) && defined(__sh__)
118 # define mach_type_known
120 # if defined(vax) || defined(__vax__)
127 # define mach_type_known
129 # if defined(__NetBSD__) && defined(__vax__)
131 # define mach_type_known
133 # if defined(mips) || defined(__mips) || defined(_mips)
135 # if defined(nec_ews) || defined(_nec_ews)
138 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD) \
140 # if defined(ultrix) || defined(__ultrix)
143 # define IRIX5 /* or IRIX 6.X */
146 # if defined(__NetBSD__) && defined(__MIPSEL__)
149 # define mach_type_known
151 # if defined(DGUX) && (defined(i386) || defined(__i386__))
156 # define mach_type_known
158 # if defined(sequent) && (defined(i386) || defined(__i386__))
161 # define mach_type_known
163 # if defined(sun) && (defined(i386) || defined(__i386__))
166 # define mach_type_known
168 # if defined(sun) && defined(__amd64)
171 # define mach_type_known
173 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
176 # define mach_type_known
179 # error IBM PC/RT no longer supported.
181 # if defined(sun) && (defined(sparc) || defined(__sparc))
183 /* Test for SunOS 5.x */
186 # define mach_type_known
188 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
189 && !defined(__OpenBSD__) && !defined(__NetBSD__) \
190 && !defined(__FreeBSD__) && !defined(__DragonFly__)
193 # define mach_type_known
198 # define mach_type_known
200 # if defined(__NetBSD__) && defined(__sparc__)
202 # define mach_type_known
204 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
205 /* The above test may need refinement */
207 # if defined(_SCO_ELF)
212 # define mach_type_known
214 # if defined(_AUX_SOURCE)
215 # error A/UX no longer supported
217 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
218 || defined(hppa) || defined(__hppa__)
220 # if !defined(LINUX) && !defined(HPUX) && !defined(OPENBSD)
223 # define mach_type_known
225 # if defined(__ia64) && (defined(_HPUX_SOURCE) || defined(__HP_aCC))
230 # define mach_type_known
232 # if defined(__BEOS__) && defined(_X86_)
235 # define mach_type_known
237 # if defined(OPENBSD) && defined(__amd64__)
239 # define mach_type_known
241 # if defined(LINUX) && (defined(i386) || defined(__i386__))
243 # define mach_type_known
245 # if defined(LINUX) && defined(__x86_64__)
247 # define mach_type_known
249 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
251 # define mach_type_known
253 # if defined(LINUX) && (defined(__arm) || defined(__arm__))
255 # define mach_type_known
257 # if defined(LINUX) && defined(__cris__)
261 # define mach_type_known
263 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) \
264 || defined(powerpc64) || defined(__powerpc64__))
266 # define mach_type_known
268 # if defined(LINUX) && defined(__mc68000__)
270 # define mach_type_known
272 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
274 # define mach_type_known
276 # if defined(LINUX) && defined(__sh__)
278 # define mach_type_known
280 # if defined(LINUX) && defined(__avr32__)
282 # define mach_type_known
284 # if defined(LINUX) && defined(__m32r__)
286 # define mach_type_known
288 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
290 # define mach_type_known
292 # if defined(__alpha) || defined(__alpha__)
294 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
296 # define OSF1 /* a.k.a Digital Unix */
298 # define mach_type_known
300 # if defined(_AMIGA) && !defined(AMIGA)
305 # define mach_type_known
307 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
310 # define mach_type_known
312 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
315 # define mach_type_known
317 # if defined(__OpenBSD__) && defined(__powerpc__)
320 # define mach_type_known
323 # if defined(__ppc__) || defined(__ppc64__)
325 # define mach_type_known
326 # elif defined(__x86_64__) || defined(__x86_64)
328 # define mach_type_known
329 # elif defined(__i386__)
331 # define mach_type_known
332 # elif defined(__arm__)
334 # define mach_type_known
335 # define DARWIN_DONT_PARSE_STACK
338 # if defined(__rtems__) && (defined(i386) || defined(__i386__))
341 # define mach_type_known
343 # if defined(NeXT) && defined(mc68000)
346 # define mach_type_known
348 # if defined(NeXT) && (defined(i386) || defined(__i386__))
351 # define mach_type_known
353 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
356 # define mach_type_known
358 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
360 # define mach_type_known
362 # if defined(FREEBSD) && defined(__x86_64__)
364 # define mach_type_known
366 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
368 # define mach_type_known
370 # if defined(__NetBSD__) && defined(__x86_64__)
372 # define mach_type_known
374 # if defined(FREEBSD) && defined(__sparc__)
376 # define mach_type_known
378 # if defined(bsdi) && (defined(i386) || defined(__i386__))
381 # define mach_type_known
383 # if !defined(mach_type_known) && defined(__386BSD__)
386 # define mach_type_known
388 # if defined(_CX_UX) && defined(_M88K)
391 # define mach_type_known
393 # if defined(DGUX) && defined(m88k)
396 # define mach_type_known
398 # if defined(_WIN32_WCE) || defined(__CEGCC__) || defined(__MINGW32CE__)
399 /* SH3, SH4, MIPS already defined for corresponding architectures */
400 # if defined(SH3) || defined(SH4)
403 # if defined(x86) || defined(__i386__)
406 # if defined(_M_ARM) || defined(ARM) || defined(_ARM_)
410 # define mach_type_known
412 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
413 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
414 # if defined(__LP64__) || defined(_WIN64)
419 # define MSWIN32 /* or Win64 */
420 # define mach_type_known
422 # if defined(_MSC_VER) && defined(_M_IA64)
424 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
425 /* variants as a different platform. */
428 # if defined(__DJGPP__)
431 # define DJGPP /* MSDOS running the DJGPP port of GCC */
433 # define mach_type_known
435 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
438 # define mach_type_known
440 # if defined(__MINGW32__) && !defined(mach_type_known)
443 # define mach_type_known
445 # if defined(__BORLANDC__)
448 # define mach_type_known
450 # if defined(_UTS) && !defined(mach_type_known)
453 # define mach_type_known
456 # error PicoJava no longer supported
457 /* The implementation had problems, and I haven't heard of users */
458 /* in ages. If you want it resurrected, let me know. */
460 # if defined(__embedded__) && defined(PPC)
463 # define mach_type_known
466 # if defined(__WATCOMC__) && defined(__386__)
468 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
469 # if defined(__OS2__)
472 # if defined(__WINDOWS_386__) || defined(__NT__)
479 # define mach_type_known
481 # if defined(__s390__) && defined(LINUX)
483 # define mach_type_known
485 # if defined(__GNU__)
486 # if defined(__i386__)
487 /* The Debian Hurd running on generic PC */
490 # define mach_type_known
493 # if defined(__TANDEM)
494 /* Nonstop S-series */
495 /* FIXME: Should recognize Integrity series? */
498 # define mach_type_known
500 # if defined(__hexagon__) && defined(LINUX)
502 # define mach_type_known
505 /* Feel free to add more clauses here */
507 /* Or manually define the machine type here. A machine type is */
508 /* characterized by the architecture. Some */
509 /* machine types are further subdivided by OS. */
510 /* Macros such as LINUX, FREEBSD, etc. distinguish them. */
511 /* SYSV on an M68K actually means A/UX. */
512 /* The distinction in these cases is usually the stack starting address */
513 # ifndef mach_type_known
514 # error "The collector has not been ported to this machine/OS combination."
516 /* Mapping is: M68K ==> Motorola 680X0 */
517 /* (NEXT, and SYSV (A/UX), */
518 /* MACOS and AMIGA variants) */
519 /* I386 ==> Intel 386 */
520 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
521 /* FREEBSD, THREE86BSD, MSWIN32, */
522 /* BSDI,SOLARIS, NEXT, other variants) */
523 /* NS32K ==> Encore Multimax */
524 /* MIPS ==> R2000 through R14K */
525 /* (many variants) */
526 /* VAX ==> DEC VAX */
527 /* (BSD, ULTRIX variants) */
528 /* HP_PA ==> HP9000/700 & /800 */
530 /* SPARC ==> SPARC v7/v8/v9 */
531 /* (SOLARIS, LINUX, DRSNX variants) */
532 /* ALPHA ==> DEC Alpha */
533 /* (OSF1 and LINUX variants) */
534 /* M88K ==> Motorola 88XX0 */
535 /* (CX_UX and DGUX) */
536 /* S370 ==> 370-like machine */
537 /* running Amdahl UTS4 */
538 /* S390 ==> 390-like machine */
540 /* ARM32 ==> Intel StrongARM */
541 /* IA64 ==> Intel IPF */
543 /* (LINUX and HPUX) */
544 /* SH ==> Hitachi SuperH */
545 /* (LINUX & MSWINCE) */
546 /* X86_64 ==> AMD x86-64 */
547 /* POWERPC ==> IBM/Apple PowerPC */
548 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
549 /* LINUX, NETBSD, AIX, NOSYS */
551 /* Handles 32 and 64-bit variants. */
552 /* CRIS ==> Axis Etrax */
553 /* M32R ==> Renesas M32R */
554 /* HEXAGON ==> Qualcomm Hexagon */
558 * For each architecture and OS, the following need to be defined:
560 * CPP_WORDSZ is a simple integer constant representing the word size.
561 * in bits. We assume byte addressability, where a byte has 8 bits.
562 * We also assume CPP_WORDSZ is either 32 or 64.
563 * (We care about the length of pointers, not hardware
564 * bus widths. Thus a 64 bit processor with a C compiler that uses
565 * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
567 * MACH_TYPE is a string representation of the machine type.
568 * OS_TYPE is analogous for the OS.
570 * ALIGNMENT is the largest N, such that
571 * all pointer are guaranteed to be aligned on N byte boundaries.
572 * defining it to be 1 will always work, but perform poorly.
574 * DATASTART is the beginning of the data segment.
575 * On some platforms SEARCH_FOR_DATA_START is defined.
576 * SEARCH_FOR_DATASTART will cause GC_data_start to
577 * be set to an address determined by accessing data backwards from _end
578 * until an unmapped page is found. DATASTART will be defined to be
580 * On UNIX-like systems, the collector will scan the area between DATASTART
581 * and DATAEND for root pointers.
583 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
584 * RTH suggests gaining access to linker script synth'd values with
585 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
586 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
587 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
588 * without any special options.
590 * STACKBOTTOM is the cool end of the stack, which is usually the
591 * highest address in the stack.
592 * Under PCR or OS/2, we have other ways of finding thread stacks.
593 * For each machine, the following should:
594 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
595 * 2) define exactly one of
596 * STACKBOTTOM (should be defined to be an expression)
600 * If STACKBOTTOM is defined, then it's value will be used directly as the
601 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
602 * with a method appropriate for most Linux systems. Currently we look
603 * first for __libc_stack_end (currently only if USE_LIBC_PRIVATES is
604 * defined), and if that fails read it from /proc. (If USE_LIBC_PRIVATES
605 * is not defined and NO_PROC_STAT is defined, we revert to HEURISTIC2.)
606 * If either of the last two macros are defined, then STACKBOTTOM is computed
607 * during collector startup using one of the following two heuristics:
608 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
609 * the next multiple of STACK_GRAN.
610 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
611 * in small steps (decrement if STACK_GROWS_UP), and read the value
612 * at each location. Remember the value when the first
613 * Segmentation violation or Bus error is signaled. Round that
614 * to the nearest plausible page boundary, and use that instead
617 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
618 * the value of environ is a pointer that can serve as STACKBOTTOM.
619 * I expect that HEURISTIC2 can be replaced by this approach, which
620 * interferes far less with debugging. However it has the disadvantage
621 * that it's confused by a putenv call before the collector is initialized.
622 * This could be dealt with by intercepting putenv ...
624 * If no expression for STACKBOTTOM can be found, and neither of the above
625 * heuristics are usable, the collector can still be used with all of the above
626 * undefined, provided one of the following is done:
627 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
628 * without reference to STACKBOTTOM. This is appropriate for use in
629 * conjunction with thread packages, since there will be multiple stacks.
630 * (Allocating thread stacks in the heap, and treating them as ordinary
631 * heap data objects is also possible as a last resort. However, this is
632 * likely to introduce significant amounts of excess storage retention
633 * unless the dead parts of the thread stacks are periodically cleared.)
634 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
635 * If the author of the client code controls the main program, this is
636 * easily accomplished by introducing a new main program, setting
637 * GC_stackbottom to the address of a local variable, and then calling
638 * the original main program. The new main program would read something
639 * like (provided real_main() is not inlined by the compiler):
641 * # include "gc_private.h"
643 * main(argc, argv, envp)
645 * char **argv, **envp;
649 * GC_stackbottom = (ptr_t)(&dummy);
650 * return(real_main(argc, argv, envp));
654 * Each architecture may also define the style of virtual dirty bit
655 * implementation to be used:
656 * MPROTECT_VDB: Write protect the heap and catch faults.
657 * GWW_VDB: Use win32 GetWriteWatch primitive.
658 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
660 * The first and second one may be combined, in which case a runtime
661 * selection will be made, based on GetWriteWatch availability.
663 * An architecture may define DYNAMIC_LOADING if dyn_load.c
664 * defined GC_register_dynamic_libraries() for the architecture.
666 * An architecture may define PREFETCH(x) to preload the cache with *x.
667 * This defaults to a no-op.
669 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
671 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
672 * clear the two words at GC_malloc-aligned address x. By default,
673 * word stores of 0 are used instead.
675 * HEAP_START may be defined as the initial address hint for mmap-based
679 /* If we are using a recent version of gcc, we can use */
680 /* __builtin_unwind_init() to push the relevant registers onto the stack. */
681 # if defined(__GNUC__) && ((__GNUC__ >= 3) \
682 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
683 && !defined(__INTEL_COMPILER) && !defined(__PATHCC__) \
684 && !defined(__clang__) /* since no-op in clang (3.0) */
685 # define HAVE_BUILTIN_UNWIND_INIT
688 # define STACK_GRAN 0x1000000
690 # define MACH_TYPE "M68K"
693 /* FIXME: Should we remove this case? */
694 # define OS_TYPE "OPENBSD"
697 extern ptr_t GC_data_start;
698 # define DATASTART GC_data_start
699 # define DYNAMIC_LOADING
702 # define DATASTART ((ptr_t)(etext))
706 # define OS_TYPE "NETBSD"
709 extern ptr_t GC_data_start;
710 # define DATASTART GC_data_start
711 # define DYNAMIC_LOADING
714 # define DATASTART ((ptr_t)(etext))
718 # define OS_TYPE "LINUX"
719 # define LINUX_STACKBOTTOM
720 # define MPROTECT_VDB
722 # define DYNAMIC_LOADING
723 # include <features.h>
724 # if defined(__GLIBC__) && __GLIBC__ >= 2
725 # define SEARCH_FOR_DATA_START
727 # ifdef PLATFORM_ANDROID
728 # define __environ environ
730 extern char **__environ;
731 # define DATASTART ((ptr_t)(&__environ))
732 /* hideous kludge: __environ is the first */
733 /* word in crt0.o, and delimits the start */
734 /* of the data segment, no matter which */
735 /* ld options were passed through. */
736 /* We could use _etext instead, but that */
737 /* would include .rodata, which may */
738 /* contain large read-only data tables */
739 /* that we'd rather not scan. */
740 # endif /* !GLIBC2 */
742 # define DATAEND (ptr_t)(_end)
745 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
749 # define OS_TYPE "AMIGA"
750 /* STACKBOTTOM and DATASTART handled specially */
752 # define DATAEND /* not needed */
753 # define GETPAGESIZE() 4096
759 # define OS_TYPE "MACOS"
760 /* see os_dep.c for details of global data segments. */
761 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
762 # define DATAEND /* not needed */
763 # define GETPAGESIZE() 4096
766 # define OS_TYPE "NEXT"
767 # define DATASTART ((ptr_t) get_etext())
768 # define DATASTART_IS_FUNC
769 # define STACKBOTTOM ((ptr_t) 0x4000000)
770 # define DATAEND /* not needed */
774 # if defined(POWERPC)
775 # define MACH_TYPE "POWERPC"
777 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
781 # define OS_TYPE "MACOS"
782 /* see os_dep.c for details of global data segments. */
783 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
784 # define DATAEND /* not needed */
787 # if defined(__powerpc64__)
789 # define CPP_WORDSZ 64
791 # define HBLKSIZE 4096
796 # define OS_TYPE "LINUX"
797 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
798 /* executable on a 64 bit kernel. */
799 # define LINUX_STACKBOTTOM
800 # define DYNAMIC_LOADING
801 # define SEARCH_FOR_DATA_START
803 # define DATAEND (ptr_t)(_end)
806 # define OS_TYPE "DARWIN"
807 # define DYNAMIC_LOADING
808 # if defined(__ppc64__)
810 # define CPP_WORDSZ 64
811 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
812 # define CACHE_LINE_SIZE 64
814 # define HBLKSIZE 4096
818 # define STACKBOTTOM ((ptr_t) 0xc0000000)
820 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
821 /* These aren't used when dyld support is enabled (it is by default). */
822 # define DATASTART ((ptr_t) get_etext())
823 # define DATAEND ((ptr_t) get_end())
827 # define USE_MMAP_ANON
828 # define MPROTECT_VDB
830 # define GETPAGESIZE() getpagesize()
831 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
832 /* The performance impact of prefetches is untested */
833 # define PREFETCH(x) \
834 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
835 # define PREFETCH_FOR_WRITE(x) \
836 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
838 /* There seems to be some issues with trylock hanging on darwin. */
839 /* This should be looked into some more. */
840 # define NO_PTHREAD_TRYLOCK
843 # define OS_TYPE "OPENBSD"
845 # ifdef GC_OPENBSD_THREADS
846 # define UTHREAD_SP_OFFSET 268
848 # include <sys/param.h>
849 # include <uvm/uvm_extern.h>
850 # define STACKBOTTOM USRSTACK
852 extern int __data_start[];
853 # define DATASTART ((ptr_t)__data_start)
855 # define DATAEND ((ptr_t)(&_end))
856 # define DYNAMIC_LOADING
859 # if defined(__powerpc64__)
861 # define CPP_WORDSZ 64
863 # define HBLKSIZE 4096
868 # define OS_TYPE "FREEBSD"
869 # ifndef GC_FREEBSD_THREADS
870 # define MPROTECT_VDB
872 # define SIG_SUSPEND SIGUSR1
873 # define SIG_THR_RESTART SIGUSR2
874 # define FREEBSD_STACKBOTTOM
876 # define DYNAMIC_LOADING
879 ptr_t GC_FreeBSDGetDataStart(size_t, ptr_t);
880 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
881 # define DATASTART_IS_FUNC
885 # define OS_TYPE "NETBSD"
887 extern ptr_t GC_data_start;
888 # define DATASTART GC_data_start
889 # define DYNAMIC_LOADING
891 # ifdef SN_TARGET_PS3
893 # define CPP_WORDSZ 32
896 extern int __bss_start;
897 # define DATAEND (ptr_t)(_end)
898 # define DATASTART (ptr_t)(__bss_start)
899 # define STACKBOTTOM ((ptr_t)ps3_get_stack_bottom())
902 # define OS_TYPE "AIX"
903 # undef ALIGNMENT /* in case it's defined */
905 /* DOB: some AIX installs stupidly define IA64 in */
906 /* /usr/include/sys/systemcfg.h */
909 # define CPP_WORDSZ 64
910 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
913 # define CPP_WORDSZ 32
914 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
919 # define USE_MMAP_ANON
920 /* From AIX linker man page:
921 _text Specifies the first location of the program.
922 _etext Specifies the first location after the program.
923 _data Specifies the first location of the data.
924 _edata Specifies the first location after the initialized data
925 _end or end Specifies the first location after all data.
927 extern int _data[], _end[];
928 # define DATASTART ((ptr_t)((ulong)_data))
929 # define DATAEND ((ptr_t)((ulong)_end))
931 # define DYNAMIC_LOADING
932 /* For really old versions of AIX, this may have to be removed. */
937 # define OS_TYPE "NOSYS"
938 extern void __end[], __dso_handle[];
939 # define DATASTART (__dso_handle) /* OK, that's ugly. */
940 # define DATAEND (ptr_t)(__end)
941 /* Stack starts at 0xE0000000 for the simulator. */
943 # define STACK_GRAN 0x10000000
949 # define MACH_TYPE "VAX"
950 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
952 # define DATASTART ((ptr_t)(etext))
954 # define OS_TYPE "BSD"
956 /* HEURISTIC2 may be OK, but it's hard to test. */
959 # define OS_TYPE "ULTRIX"
960 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
965 # define MACH_TYPE "SPARC"
966 # if defined(__arch64__) || defined(__sparcv9)
968 # define CPP_WORDSZ 64
969 # define ELF_CLASS ELFCLASS64
971 # define ALIGNMENT 4 /* Required by hardware */
972 # define CPP_WORDSZ 32
974 /* Don't define USE_ASM_PUSH_REGS. We do use an asm helper, but */
975 /* not to push the registers on the mark stack. */
977 # define OS_TYPE "SOLARIS"
980 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
981 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
982 # define DATASTART_IS_FUNC
983 # define DATAEND (ptr_t)(_end)
984 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
986 /* Otherwise we now use calloc. Mmap may result in the */
987 /* heap interleaved with thread stacks, which can result in */
988 /* excessive blacklisting. Sbrk is unusable since it */
989 /* doesn't interact correctly with the system malloc. */
992 # define HEAP_START (ptr_t)0x40000000
994 # define HEAP_START DATAEND
997 /* HEURISTIC1 reportedly no longer works under 2.7. */
998 /* HEURISTIC2 probably works, but this appears to be preferable. */
999 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
1000 /* installations that's undefined. We work around this with a */
1002 # include <sys/vmparam.h>
1004 /* This should work everywhere, but doesn't. */
1005 # define STACKBOTTOM ((ptr_t) USRSTACK)
1009 # include <unistd.h>
1010 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1011 /* getpagesize() appeared to be missing from at least one */
1012 /* Solaris 5.4 installation. Weird. */
1013 # define DYNAMIC_LOADING
1016 # define OS_TYPE "DRSNX"
1017 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1019 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
1020 # define DATASTART_IS_FUNC
1021 # define MPROTECT_VDB
1022 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
1023 # define DYNAMIC_LOADING
1026 # define OS_TYPE "LINUX"
1028 # define DYNAMIC_LOADING
1030 Linux Sparc/a.out not supported
1033 extern int _etext[];
1034 # define DATAEND (ptr_t)(_end)
1036 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1038 # define DATASTART GC_SysVGetDataStart(0x100000, (ptr_t)_etext)
1040 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1042 # define DATASTART_IS_FUNC
1043 # define LINUX_STACKBOTTOM
1046 # define OS_TYPE "OPENBSD"
1047 # ifdef GC_OPENBSD_THREADS
1048 # define UTHREAD_SP_OFFSET 232
1050 # include <sys/param.h>
1051 # include <uvm/uvm_extern.h>
1052 # define STACKBOTTOM USRSTACK
1054 extern int __data_start[];
1055 # define DATASTART ((ptr_t)__data_start)
1057 # define DATAEND ((ptr_t)(&_end))
1058 # define DYNAMIC_LOADING
1061 # define OS_TYPE "NETBSD"
1064 extern ptr_t GC_data_start;
1065 # define DATASTART GC_data_start
1066 # define DYNAMIC_LOADING
1068 extern char etext[];
1069 # define DATASTART ((ptr_t)(etext))
1073 # define OS_TYPE "FREEBSD"
1074 # define SIG_SUSPEND SIGUSR1
1075 # define SIG_THR_RESTART SIGUSR2
1076 # define FREEBSD_STACKBOTTOM
1078 # define DYNAMIC_LOADING
1080 extern char etext[];
1081 extern char edata[];
1083 # define NEED_FIND_LIMIT
1084 # define DATASTART ((ptr_t)(&etext))
1085 ptr_t GC_find_limit(ptr_t, GC_bool);
1086 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1087 # define DATAEND_IS_FUNC
1088 # define DATASTART2 ((ptr_t)(&edata))
1089 # define DATAEND2 ((ptr_t)(&end))
1094 # define MACH_TYPE "I386"
1095 # if defined(__LP64__) || defined(_WIN64)
1096 # error This should be handled as X86_64
1098 # define CPP_WORDSZ 32
1099 # define ALIGNMENT 4
1100 /* Appears to hold for all "32 bit" compilers */
1101 /* except Borland. The -a4 option fixes */
1103 /* Ivan Demakov: For Watcom the option is -zp4. */
1106 # define OS_TYPE "SEQUENT"
1108 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1109 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1112 # define OS_TYPE "BEOS"
1114 # define GETPAGESIZE() B_PAGE_SIZE
1116 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1119 # define OS_TYPE "SOLARIS"
1120 extern int _etext[], _end[];
1121 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1122 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
1123 # define DATASTART_IS_FUNC
1124 # define DATAEND (ptr_t)(_end)
1125 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1126 /* but reportedly breaks under 2.8. It appears that the stack */
1127 /* base is a property of the executable, so this should not break */
1128 /* old executables. */
1129 /* HEURISTIC2 probably works, but this appears to be preferable. */
1130 # include <sys/vm.h>
1131 # define STACKBOTTOM ((ptr_t) USRSTACK)
1132 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1133 /* It appears to be fixed in 2.8 and 2.9. */
1134 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1138 # define MPROTECT_VDB
1140 # define DYNAMIC_LOADING
1141 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1143 /* Otherwise we now use calloc. Mmap may result in the */
1144 /* heap interleaved with thread stacks, which can result in */
1145 /* excessive blacklisting. Sbrk is unusable since it */
1146 /* doesn't interact correctly with the system malloc. */
1149 # define HEAP_START (ptr_t)0x40000000
1151 # define HEAP_START DATAEND
1155 # define OS_TYPE "SCO"
1157 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1159 +((word)etext & 0xfff))
1160 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1163 # define OS_TYPE "SCO_ELF"
1165 # define DATASTART ((ptr_t)(etext))
1166 # define STACKBOTTOM ((ptr_t) 0x08048000)
1167 # define DYNAMIC_LOADING
1168 # define ELF_CLASS ELFCLASS32
1171 # define OS_TYPE "DGUX"
1172 extern int _etext, _end;
1173 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1174 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)(&_etext))
1175 # define DATASTART_IS_FUNC
1176 # define DATAEND (ptr_t)(&_end)
1177 # define STACK_GROWS_DOWN
1179 # include <unistd.h>
1180 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1181 # define DYNAMIC_LOADING
1185 # define MAP_FAILED (void *) ((word)-1)
1187 # define HEAP_START (ptr_t)0x40000000
1189 # define HEAP_START DATAEND
1194 # define OS_TYPE "NACL"
1196 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1198 # define DATAEND (_end)
1200 # define STACK_GRAN 0x10000
1202 # define GETPAGESIZE() 65536
1203 # ifndef MAX_NACL_GC_THREADS
1204 # define MAX_NACL_GC_THREADS 1024
1209 # define OS_TYPE "LINUX"
1210 # define LINUX_STACKBOTTOM
1214 # define STACK_GRAN 0x10000000
1215 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1216 /* different kernel configurations. In particular, systems */
1217 /* with 2GB physical memory will usually move the user */
1218 /* address space limit, and hence initial SP to 0x80000000. */
1220 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1221 # define MPROTECT_VDB
1223 /* We seem to get random errors in incremental mode, */
1224 /* possibly because Linux threads is itself a malloc client */
1225 /* and can't deal with the signals. */
1227 # define HEAP_START (ptr_t)0x1000
1228 /* This encourages mmap to give us low addresses, */
1229 /* thus allowing the heap to grow to ~3GB */
1231 # define DYNAMIC_LOADING
1232 # ifdef UNDEFINED /* includes ro data */
1233 extern int _etext[];
1234 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1236 # include <features.h>
1237 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1238 || defined(PLATFORM_ANDROID)
1239 # define SEARCH_FOR_DATA_START
1241 extern char **__environ;
1242 # define DATASTART ((ptr_t)(&__environ))
1243 /* hideous kludge: __environ is the first */
1244 /* word in crt0.o, and delimits the start */
1245 /* of the data segment, no matter which */
1246 /* ld options were passed through. */
1247 /* We could use _etext instead, but that */
1248 /* would include .rodata, which may */
1249 /* contain large read-only data tables */
1250 /* that we'd rather not scan. */
1253 # define DATAEND (ptr_t)(_end)
1256 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1258 # ifdef USE_I686_PREFETCH
1259 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1260 /* for the next rtelease. */
1261 # define PREFETCH(x) \
1262 __asm__ __volatile__ ("prefetchnta %0" : : "m"(*(char *)(x)))
1263 /* Empirically prefetcht0 is much more effective at reducing */
1264 /* cache miss stalls for the targeted load instructions. But it */
1265 /* seems to interfere enough with other cache traffic that the */
1266 /* net result is worse than prefetchnta. */
1267 # ifdef FORCE_WRITE_PREFETCH
1268 /* Using prefetches for write seems to have a slight negative */
1269 /* impact on performance, at least for a PIII/500. */
1270 # define PREFETCH_FOR_WRITE(x) \
1271 __asm__ __volatile__ ("prefetcht0 %0" : : "m"(*(char *)(x)))
1274 # ifdef USE_3DNOW_PREFETCH
1275 # define PREFETCH(x) \
1276 __asm__ __volatile__ ("prefetch %0" : : "m"(*(char *)(x)))
1277 # define PREFETCH_FOR_WRITE(x) \
1278 __asm__ __volatile__ ("prefetchw %0" : : "m"(*(char *)(x)))
1282 # define OS_TYPE "CYGWIN32"
1283 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1284 # define DATAEND ((ptr_t)GC_DATAEND)
1286 # define STACK_GRAN 0x10000
1288 # define NEED_FIND_LIMIT
1289 # define USE_MMAP_ANON
1293 # define OS_TYPE "OS2"
1294 /* STACKBOTTOM and DATASTART are handled specially in */
1295 /* os_dep.c. OS2 actually has the right */
1297 # define DATAEND /* not needed */
1300 # define OS_TYPE "MSWIN32"
1301 /* STACKBOTTOM and DATASTART are handled specially in */
1303 # define MPROTECT_VDB
1305 # define DATAEND /* not needed */
1308 # define OS_TYPE "MSWINCE"
1309 # define DATAEND /* not needed */
1312 # define OS_TYPE "DJGPP"
1313 # include "stubinfo.h"
1316 extern int __djgpp_stack_limit;
1317 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1318 /* #define STACKBOTTOM ((ptr_t)((word)_stubinfo+_stubinfo->size+_stklen)) */
1319 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1320 /* This may not be right. */
1323 # define OS_TYPE "OPENBSD"
1324 # ifdef GC_OPENBSD_THREADS
1325 # define UTHREAD_SP_OFFSET 176
1327 # include <sys/param.h>
1328 # include <uvm/uvm_extern.h>
1329 # define STACKBOTTOM USRSTACK
1331 extern int __data_start[];
1332 # define DATASTART ((ptr_t)__data_start)
1334 # define DATAEND ((ptr_t)(&_end))
1335 # define DYNAMIC_LOADING
1338 # define OS_TYPE "FREEBSD"
1339 # ifndef GC_FREEBSD_THREADS
1340 # define MPROTECT_VDB
1343 # define SIG_SUSPEND (32+6)
1344 # define SIG_THR_RESTART (32+5)
1346 # define DATAEND (ptr_t)(_end)
1348 # define SIG_SUSPEND SIGUSR1
1349 # define SIG_THR_RESTART SIGUSR2
1351 # define FREEBSD_STACKBOTTOM
1353 # define DYNAMIC_LOADING
1355 extern char etext[];
1356 char * GC_FreeBSDGetDataStart(size_t, ptr_t);
1357 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
1358 # define DATASTART_IS_FUNC
1361 # define OS_TYPE "NETBSD"
1363 # define DYNAMIC_LOADING
1367 # define OS_TYPE "THREE86BSD"
1370 # define OS_TYPE "BSDI"
1372 # if defined(NETBSD) || defined(THREE86BSD) || defined(BSDI)
1374 extern char etext[];
1375 # define DATASTART ((ptr_t)(etext))
1378 # define OS_TYPE "NEXT"
1379 # define DATASTART ((ptr_t) get_etext())
1380 # define DATASTART_IS_FUNC
1381 # define STACKBOTTOM ((ptr_t)0xc0000000)
1382 # define DATAEND /* not needed */
1385 # define OS_TYPE "RTEMS"
1386 # include <sys/unistd.h>
1389 void *rtems_get_stack_bottom(void);
1390 # define InitStackBottom rtems_get_stack_bottom()
1391 # define DATASTART ((ptr_t)etext)
1392 # define DATAEND ((ptr_t)end)
1393 # define STACKBOTTOM ((ptr_t)InitStackBottom)
1394 # define SIG_SUSPEND SIGUSR1
1395 # define SIG_THR_RESTART SIGUSR2
1398 # define OS_TYPE "DOS4GW"
1399 extern long __nullarea;
1401 extern char *_STACKTOP;
1402 /* Depending on calling conventions Watcom C either precedes */
1403 /* or does not precedes with underscore names of C-variables. */
1404 /* Make sure startup code variables always have the same names. */
1405 #pragma aux __nullarea "*";
1406 #pragma aux _end "*";
1407 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1408 /* confused? me too. */
1409 # define DATASTART ((ptr_t) &__nullarea)
1410 # define DATAEND ((ptr_t) &_end)
1413 # define OS_TYPE "HURD"
1414 # define STACK_GROWS_DOWN
1416 # define SIG_SUSPEND SIGUSR1
1417 # define SIG_THR_RESTART SIGUSR2
1418 # define SEARCH_FOR_DATA_START
1420 # define DATAEND ((ptr_t) (_end))
1421 /* # define MPROTECT_VDB Not quite working yet? */
1422 # define DYNAMIC_LOADING
1425 # define OS_TYPE "DARWIN"
1426 # define DARWIN_DONT_PARSE_STACK
1427 # define DYNAMIC_LOADING
1428 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
1429 /* These aren't used when dyld support is enabled (it is by default). */
1430 # define DATASTART ((ptr_t) get_etext())
1431 # define DATAEND ((ptr_t) get_end())
1432 # define STACKBOTTOM ((ptr_t) 0xc0000000)
1436 # define USE_MMAP_ANON
1437 # define MPROTECT_VDB
1438 # include <unistd.h>
1439 # define GETPAGESIZE() getpagesize()
1440 /* There seems to be some issues with trylock hanging on darwin. */
1441 /* This should be looked into some more. */
1442 # define NO_PTHREAD_TRYLOCK
1443 # endif /* DARWIN */
1447 # define MACH_TYPE "NS32K"
1448 # define ALIGNMENT 4
1449 extern char **environ;
1450 # define DATASTART ((ptr_t)(&environ))
1451 /* hideous kludge: environ is the first */
1452 /* word in crt0.o, and delimits the start */
1453 /* of the data segment, no matter which */
1454 /* ld options were passed through. */
1455 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1459 # define MACH_TYPE "MIPS"
1461 # define OS_TYPE "LINUX"
1462 # define DYNAMIC_LOADING
1464 # define DATAEND (ptr_t)(_end)
1465 extern int __data_start[];
1466 # define DATASTART ((ptr_t)(__data_start))
1468 # define CPP_WORDSZ _MIPS_SZPTR
1469 # define ALIGNMENT (_MIPS_SZPTR/8)
1471 # define ALIGNMENT 4
1474 # define HBLKSIZE 4096
1476 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1477 # define LINUX_STACKBOTTOM
1479 # define STACKBOTTOM ((ptr_t)0x7fff8000)
1484 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1485 extern int _fdata[], _end[];
1486 # define DATASTART ((ptr_t)_fdata)
1487 # define DATAEND ((ptr_t)_end)
1488 # define CPP_WORDSZ _MIPS_SZPTR
1489 # define ALIGNMENT (_MIPS_SZPTR/8)
1491 extern int etext[], edata[], end[];
1492 extern int _DYNAMIC_LINKING[], _gp[];
1493 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1494 + ((word)etext & 0xffff)))
1495 # define DATAEND (ptr_t)(edata)
1496 # define DATASTART2 (_DYNAMIC_LINKING \
1497 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1499 # define DATAEND2 (ptr_t)(end)
1500 # define ALIGNMENT 4
1502 # define OS_TYPE "EWS4800"
1506 # define DATASTART (ptr_t)0x10000000
1507 /* Could probably be slightly higher since */
1508 /* startup code allocates lots of stuff. */
1509 # define OS_TYPE "ULTRIX"
1510 # define ALIGNMENT 4
1514 extern int _fdata[];
1515 # define DATASTART ((ptr_t)(_fdata))
1517 # define HEAP_START (ptr_t)0x30000000
1519 # define HEAP_START DATASTART
1521 /* Lowest plausible heap address. */
1522 /* In the MMAP case, we map there. */
1523 /* In either case it is used to identify */
1524 /* heap sections so they're not */
1525 /* considered as roots. */
1526 # define OS_TYPE "IRIX5"
1527 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1528 /* of recent breakage. */
1530 # define CPP_WORDSZ _MIPS_SZPTR
1531 # define ALIGNMENT (_MIPS_SZPTR/8)
1533 # define ALIGNMENT 4
1535 # define DYNAMIC_LOADING
1538 # define OS_TYPE "MSWINCE"
1539 # define ALIGNMENT 4
1540 # define DATAEND /* not needed */
1542 # if defined(NETBSD)
1543 # define OS_TYPE "NETBSD"
1544 # define ALIGNMENT 4
1547 extern ptr_t GC_data_start;
1548 # define DATASTART GC_data_start
1549 # define NEED_FIND_LIMIT
1550 # define DYNAMIC_LOADING
1552 # define DATASTART ((ptr_t) 0x10000000)
1553 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1557 # define OS_TYPE "OPENBSD"
1558 # define ALIGNMENT 4
1559 # ifdef GC_OPENBSD_THREADS
1560 # define UTHREAD_SP_OFFSET 808
1562 # include <sys/param.h>
1563 # include <uvm/uvm_extern.h>
1564 # define STACKBOTTOM USRSTACK
1566 extern int _fdata[];
1567 # define DATASTART ((ptr_t)_fdata)
1569 # define DATAEND ((ptr_t)(&_end))
1570 # define DYNAMIC_LOADING
1572 # if defined(NONSTOP)
1573 # define CPP_WORDSZ 32
1574 # define OS_TYPE "NONSTOP"
1575 # define ALIGNMENT 4
1576 # define DATASTART ((ptr_t) 0x08000000)
1577 extern char **environ;
1578 # define DATAEND ((ptr_t)(environ - 0x10))
1579 # define STACKBOTTOM ((ptr_t) 0x4fffffff)
1584 # define MACH_TYPE "HP_PA"
1586 # define CPP_WORDSZ 64
1587 # define ALIGNMENT 8
1589 # define CPP_WORDSZ 32
1590 # define ALIGNMENT 4
1592 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS) \
1593 && !defined(OPENBSD) && !defined(LINUX) /* For now. */
1594 # define MPROTECT_VDB
1596 # define STACK_GROWS_UP
1598 # define OS_TYPE "HPUX"
1599 extern int __data_start[];
1600 # define DATASTART ((ptr_t)(__data_start))
1601 # ifdef USE_HPUX_FIXED_STACKBOTTOM
1602 /* The following appears to work for 7xx systems running HP/UX */
1603 /* 9.xx Furthermore, it might result in much faster */
1604 /* collections than HEURISTIC2, which may involve scanning */
1605 /* segments that directly precede the stack. It is not the */
1606 /* default, since it may not work on older machine/OS */
1607 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1609 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1611 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1612 /* to this. Note that the GC must be initialized before the */
1613 /* first putenv call. */
1614 extern char ** environ;
1615 # define STACKBOTTOM ((ptr_t)environ)
1617 # define DYNAMIC_LOADING
1618 # include <unistd.h>
1619 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1621 # define PREFETCH(x) { \
1622 register long addr = (long)(x); \
1623 (void) _asm ("LDW", 0, 0, addr, 0); \
1628 # define OS_TYPE "LINUX"
1629 # define LINUX_STACKBOTTOM
1630 # define DYNAMIC_LOADING
1631 # define SEARCH_FOR_DATA_START
1633 # define DATAEND (ptr_t)(&_end)
1636 # define OS_TYPE "OPENBSD"
1637 # ifdef GC_OPENBSD_THREADS
1638 # define UTHREAD_SP_OFFSET 520
1640 # include <sys/param.h>
1641 # include <uvm/uvm_extern.h>
1642 # define STACKBOTTOM USRSTACK
1644 extern int __data_start[];
1645 # define DATASTART ((ptr_t)__data_start)
1647 # define DATAEND ((ptr_t)(&_end))
1648 # define DYNAMIC_LOADING
1653 # define MACH_TYPE "ALPHA"
1654 # define ALIGNMENT 8
1655 # define CPP_WORDSZ 64
1657 # define OS_TYPE "NETBSD"
1659 extern ptr_t GC_data_start;
1660 # define DATASTART GC_data_start
1661 # define ELFCLASS32 32
1662 # define ELFCLASS64 64
1663 # define ELF_CLASS ELFCLASS64
1664 # define DYNAMIC_LOADING
1667 # define OS_TYPE "OPENBSD"
1668 # define ELF_CLASS ELFCLASS64
1669 # ifdef GC_OPENBSD_THREADS
1670 # define UTHREAD_SP_OFFSET 816
1672 # include <sys/param.h>
1673 # include <uvm/uvm_extern.h>
1674 # define STACKBOTTOM USRSTACK
1676 extern int __data_start[];
1677 # define DATASTART ((ptr_t)__data_start)
1679 # define DATAEND ((ptr_t)(&_end))
1680 # define DYNAMIC_LOADING
1683 # define OS_TYPE "FREEBSD"
1684 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1685 # define SIG_SUSPEND SIGUSR1
1686 # define SIG_THR_RESTART SIGUSR2
1687 # define FREEBSD_STACKBOTTOM
1689 # define DYNAMIC_LOADING
1691 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1692 extern char etext[];
1693 extern char edata[];
1695 # define NEED_FIND_LIMIT
1696 # define DATASTART ((ptr_t)(&etext))
1697 ptr_t GC_find_limit(ptr_t, GC_bool);
1698 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1699 # define DATAEND_IS_FUNC
1700 # define DATASTART2 ((ptr_t)(&edata))
1701 # define DATAEND2 ((ptr_t)(&end))
1704 # define OS_TYPE "OSF1"
1705 # define DATASTART ((ptr_t) 0x140000000)
1707 # define DATAEND ((ptr_t) &_end)
1708 extern char ** environ;
1709 /* round up from the value of environ to the nearest page boundary */
1710 /* Probably breaks if putenv is called before collector */
1711 /* initialization. */
1712 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1713 /* # define HEURISTIC2 */
1714 /* Normally HEURISTIC2 is too conservative, since */
1715 /* the text segment immediately follows the stack. */
1716 /* Hence we give an upper pound. */
1717 /* This is currently unused, since we disabled HEURISTIC2 */
1718 extern int __start[];
1719 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1720 # ifndef GC_OSF1_THREADS
1721 /* Unresolved signal issues with threads. */
1722 # define MPROTECT_VDB
1724 # define DYNAMIC_LOADING
1727 # define OS_TYPE "LINUX"
1728 # define LINUX_STACKBOTTOM
1730 # define SEARCH_FOR_DATA_START
1731 # define DYNAMIC_LOADING
1733 # define DATASTART ((ptr_t) 0x140000000)
1736 # define DATAEND (ptr_t)(_end)
1737 # define MPROTECT_VDB
1738 /* Has only been superficially tested. May not */
1739 /* work on all versions. */
1744 # define MACH_TYPE "IA64"
1747 # define CPP_WORDSZ 32
1748 /* Requires 8 byte alignment for malloc */
1749 # define ALIGNMENT 4
1752 # error --> unknown ABI
1754 # define CPP_WORDSZ 64
1755 /* Requires 16 byte alignment for malloc */
1756 # define ALIGNMENT 8
1758 # define OS_TYPE "HPUX"
1759 extern int __data_start[];
1760 # define DATASTART ((ptr_t)(__data_start))
1761 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1762 /* to this. Note that the GC must be initialized before the */
1763 /* first putenv call. */
1764 extern char ** environ;
1765 # define STACKBOTTOM ((ptr_t)environ)
1766 # define HPUX_STACKBOTTOM
1767 # define DYNAMIC_LOADING
1768 # include <unistd.h>
1769 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1770 /* The following was empirically determined, and is probably */
1771 /* not very robust. */
1772 /* Note that the backing store base seems to be at a nice */
1773 /* address minus one page. */
1774 # define BACKING_STORE_DISPLACEMENT 0x1000000
1775 # define BACKING_STORE_ALIGNMENT 0x1000
1776 extern ptr_t GC_register_stackbottom;
1777 # define BACKING_STORE_BASE GC_register_stackbottom
1778 /* Known to be wrong for recent HP/UX versions!!! */
1781 # define CPP_WORDSZ 64
1782 # define ALIGNMENT 8
1783 # define OS_TYPE "LINUX"
1784 /* The following works on NUE and older kernels: */
1785 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1786 /* This does not work on NUE: */
1787 # define LINUX_STACKBOTTOM
1788 /* We also need the base address of the register stack */
1789 /* backing store. This is computed in */
1790 /* GC_linux_register_stack_base based on the following */
1792 # define BACKING_STORE_ALIGNMENT 0x100000
1793 # define BACKING_STORE_DISPLACEMENT 0x80000000
1794 extern ptr_t GC_register_stackbottom;
1795 # define BACKING_STORE_BASE GC_register_stackbottom
1796 # define SEARCH_FOR_DATA_START
1798 # define DYNAMIC_LOADING
1800 /* In the Intel compiler environment, we seem to end up with */
1801 /* statically linked executables and an undefined reference */
1804 # define MPROTECT_VDB
1805 /* Requires Linux 2.3.47 or later. */
1807 # define DATAEND (ptr_t)(_end)
1809 # ifndef __INTEL_COMPILER
1810 # define PREFETCH(x) \
1811 __asm__ (" lfetch [%0]": : "r"(x))
1812 # define PREFETCH_FOR_WRITE(x) \
1813 __asm__ (" lfetch.excl [%0]": : "r"(x))
1814 # define CLEAR_DOUBLE(x) \
1815 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1817 # include <ia64intrin.h>
1818 # define PREFETCH(x) \
1819 __lfetch(__lfhint_none, (x))
1820 # define PREFETCH_FOR_WRITE(x) \
1821 __lfetch(__lfhint_nta, (x))
1822 # define CLEAR_DOUBLE(x) \
1823 __stf_spill((void *)(x), 0)
1824 # endif /* __INTEL_COMPILER */
1828 /* FIXME: This is a very partial guess. There is no port, yet. */
1829 # define OS_TYPE "MSWIN32"
1830 /* STACKBOTTOM and DATASTART are handled specially in */
1832 # define DATAEND /* not needed */
1833 # if defined(_WIN64)
1834 # define CPP_WORDSZ 64
1836 # define CPP_WORDSZ 32 /* Is this possible? */
1838 # define ALIGNMENT 8
1843 # define MACH_TYPE "M88K"
1844 # define ALIGNMENT 4
1847 # define OS_TYPE "CX_UX"
1848 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1851 # define OS_TYPE "DGUX"
1852 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1853 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
1854 # define DATASTART_IS_FUNC
1856 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1860 /* If this still works, and if anyone cares, this should probably */
1861 /* be moved to the S390 category. */
1862 # define MACH_TYPE "S370"
1863 # define ALIGNMENT 4 /* Required by hardware */
1865 # define OS_TYPE "UTS4"
1867 extern int _etext[];
1869 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1870 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1871 # define DATASTART_IS_FUNC
1872 # define DATAEND (ptr_t)(_end)
1878 # define MACH_TYPE "S390"
1880 # define ALIGNMENT 4
1881 # define CPP_WORDSZ 32
1883 # define ALIGNMENT 8
1884 # define CPP_WORDSZ 64
1886 # define HBLKSIZE 4096
1890 # define OS_TYPE "LINUX"
1891 # define LINUX_STACKBOTTOM
1892 # define DYNAMIC_LOADING
1893 extern int __data_start[];
1894 # define DATASTART ((ptr_t)(__data_start))
1896 # define DATAEND (ptr_t)(_end)
1897 # define CACHE_LINE_SIZE 256
1898 # define GETPAGESIZE() 4096
1903 # define CPP_WORDSZ 32
1904 # define MACH_TYPE "ARM32"
1905 # define ALIGNMENT 4
1907 # define OS_TYPE "NETBSD"
1910 extern ptr_t GC_data_start;
1911 # define DATASTART GC_data_start
1912 # define DYNAMIC_LOADING
1914 extern char etext[];
1915 # define DATASTART ((ptr_t)(etext))
1919 # define OS_TYPE "LINUX"
1920 # define LINUX_STACKBOTTOM
1922 # define STACK_GRAN 0x10000000
1924 # define DYNAMIC_LOADING
1925 # include <features.h>
1926 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1927 || defined(PLATFORM_ANDROID)
1928 # define SEARCH_FOR_DATA_START
1930 extern char **__environ;
1931 # define DATASTART ((ptr_t)(&__environ))
1932 /* hideous kludge: __environ is the first */
1933 /* word in crt0.o, and delimits the start */
1934 /* of the data segment, no matter which */
1935 /* ld options were passed through. */
1936 /* We could use _etext instead, but that */
1937 /* would include .rodata, which may */
1938 /* contain large read-only data tables */
1939 /* that we'd rather not scan. */
1942 # define DATAEND (ptr_t)(_end)
1945 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1949 # define OS_TYPE "MSWINCE"
1950 # define DATAEND /* not needed */
1954 # define OS_TYPE "DARWIN"
1955 # define DYNAMIC_LOADING
1956 # define DATASTART ((ptr_t) get_etext())
1957 # define DATAEND ((ptr_t) get_end())
1958 # define STACKBOTTOM ((ptr_t) 0x30000000)
1962 # define USE_MMAP_ANON
1963 # define MPROTECT_VDB
1964 # include <unistd.h>
1965 # define GETPAGESIZE() getpagesize()
1966 /* FIXME: There seems to be some issues with trylock hanging on */
1967 /* darwin. This should be looked into some more. */
1968 # define NO_PTHREAD_TRYLOCK
1969 # ifndef NO_DYLD_BIND_FULLY_IMAGE
1970 # define NO_DYLD_BIND_FULLY_IMAGE
1974 # define ALIGNMENT 4
1975 # define OS_TYPE "OPENBSD"
1976 # ifdef GC_OPENBSD_THREADS
1977 # define UTHREAD_SP_OFFSET 176
1979 # include <sys/param.h>
1980 # include <uvm/uvm_extern.h>
1981 # define STACKBOTTOM USRSTACK
1983 extern int __data_start[];
1984 # define DATASTART ((ptr_t)__data_start)
1986 # define DATAEND ((ptr_t)(&_end))
1987 # define DYNAMIC_LOADING
1990 /* __data_start is usually defined in the target linker script. */
1991 extern int __data_start[];
1992 # define DATASTART (ptr_t)(__data_start)
1993 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1994 extern void *__stack_base__;
1995 # define STACKBOTTOM ((ptr_t) (__stack_base__))
2000 # define MACH_TYPE "CRIS"
2001 # define CPP_WORDSZ 32
2002 # define ALIGNMENT 1
2003 # define OS_TYPE "LINUX"
2004 # define DYNAMIC_LOADING
2005 # define LINUX_STACKBOTTOM
2006 # define SEARCH_FOR_DATA_START
2008 # define DATAEND (ptr_t)(_end)
2011 # if defined(SH) && !defined(SH4)
2012 # define MACH_TYPE "SH"
2013 # define ALIGNMENT 4
2015 # define OS_TYPE "MSWINCE"
2016 # define DATAEND /* not needed */
2019 # define OS_TYPE "LINUX"
2020 # define LINUX_STACKBOTTOM
2021 # define DYNAMIC_LOADING
2022 # define SEARCH_FOR_DATA_START
2024 # define DATAEND (ptr_t)(_end)
2027 # define OS_TYPE "NETBSD"
2029 extern ptr_t GC_data_start;
2030 # define DATASTART GC_data_start
2031 # define DYNAMIC_LOADING
2034 # define OS_TYPE "OPENBSD"
2035 # ifdef GC_OPENBSD_THREADS
2036 # define UTHREAD_SP_OFFSET 332
2038 # include <sys/param.h>
2039 # include <uvm/uvm_extern.h>
2040 # define STACKBOTTOM USRSTACK
2042 extern int __data_start[];
2043 # define DATASTART ((ptr_t)__data_start)
2045 # define DATAEND ((ptr_t)(&_end))
2046 # define DYNAMIC_LOADING
2051 # define MACH_TYPE "SH4"
2052 # define OS_TYPE "MSWINCE"
2053 # define ALIGNMENT 4
2054 # define DATAEND /* not needed */
2058 # define MACH_TYPE "AVR32"
2059 # define CPP_WORDSZ 32
2060 # define ALIGNMENT 4
2061 # define OS_TYPE "LINUX"
2062 # define DYNAMIC_LOADING
2063 # define LINUX_STACKBOTTOM
2064 # define USE_GENERIC_PUSH_REGS
2065 # define SEARCH_FOR_DATA_START
2067 # define DATAEND (_end)
2071 # define CPP_WORDSZ 32
2072 # define MACH_TYPE "M32R"
2073 # define ALIGNMENT 4
2075 # define OS_TYPE "LINUX"
2076 # define LINUX_STACKBOTTOM
2078 # define STACK_GRAN 0x10000000
2079 # define DYNAMIC_LOADING
2080 # define SEARCH_FOR_DATA_START
2082 # define DATAEND (ptr_t)(_end)
2087 # define MACH_TYPE "X86_64"
2089 # define ALIGNMENT 4
2090 # define CPP_WORDSZ 32
2092 # define ALIGNMENT 8
2093 # define CPP_WORDSZ 64
2096 # define HBLKSIZE 4096
2098 # define CACHE_LINE_SIZE 64
2100 # define OS_TYPE "OPENBSD"
2101 # define ELF_CLASS ELFCLASS64
2102 # ifdef GC_OPENBSD_THREADS
2103 # define UTHREAD_SP_OFFSET 400
2105 # include <sys/param.h>
2106 # include <uvm/uvm_extern.h>
2107 # define STACKBOTTOM USRSTACK
2109 extern int __data_start[];
2110 # define DATASTART ((ptr_t)__data_start)
2112 # define DATAEND ((ptr_t)(&_end))
2113 # define DYNAMIC_LOADING
2116 # define OS_TYPE "LINUX"
2117 # define LINUX_STACKBOTTOM
2118 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2119 # define MPROTECT_VDB
2121 /* We seem to get random errors in incremental mode, */
2122 /* possibly because Linux threads is itself a malloc client */
2123 /* and can't deal with the signals. */
2126 # define DYNAMIC_LOADING
2127 # ifdef UNDEFINED /* includes ro data */
2128 extern int _etext[];
2129 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
2131 # include <features.h>
2132 # define SEARCH_FOR_DATA_START
2134 # define DATAEND (ptr_t)(_end)
2137 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
2139 # if defined(__GNUC__) && __GNUC__ >= 3
2140 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
2141 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
2143 # if defined(__GLIBC__)
2144 /* At present, there's a bug in GLibc getcontext() on */
2145 /* Linux/x64 (it clears FPU exception mask). We define this */
2146 /* macro to workaround it. */
2147 /* FIXME: This seems to be fixed in GLibc v2.14. */
2148 # define GETCONTEXT_FPU_EXCMASK_BUG
2152 # define OS_TYPE "DARWIN"
2153 # define DARWIN_DONT_PARSE_STACK
2154 # define DYNAMIC_LOADING
2155 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
2156 /* These aren't used when dyld support is enabled (it is by default) */
2157 # define DATASTART ((ptr_t) get_etext())
2158 # define DATAEND ((ptr_t) get_end())
2159 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
2163 # define USE_MMAP_ANON
2164 # define MPROTECT_VDB
2165 # include <unistd.h>
2166 # define GETPAGESIZE() getpagesize()
2167 /* There seems to be some issues with trylock hanging on darwin. */
2168 /* This should be looked into some more. */
2169 # define NO_PTHREAD_TRYLOCK
2172 # define OS_TYPE "FREEBSD"
2173 # ifndef GC_FREEBSD_THREADS
2174 # define MPROTECT_VDB
2177 # define SIG_SUSPEND (32+6)
2178 # define SIG_THR_RESTART (32+5)
2180 # define DATAEND (ptr_t)(_end)
2182 # define SIG_SUSPEND SIGUSR1
2183 # define SIG_THR_RESTART SIGUSR2
2185 # define FREEBSD_STACKBOTTOM
2187 # define DYNAMIC_LOADING
2189 extern char etext[];
2190 ptr_t GC_FreeBSDGetDataStart(size_t, ptr_t);
2191 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
2192 # define DATASTART_IS_FUNC
2195 # define OS_TYPE "NETBSD"
2198 extern ptr_t GC_data_start;
2199 # define DATASTART GC_data_start
2200 # define DYNAMIC_LOADING
2202 # define SEARCH_FOR_DATA_START
2206 # define OS_TYPE "SOLARIS"
2207 # define ELF_CLASS ELFCLASS64
2208 extern int _etext[], _end[];
2209 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
2210 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
2211 # define DATASTART_IS_FUNC
2212 # define DATAEND (ptr_t)(_end)
2213 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
2214 /* but reportedly breaks under 2.8. It appears that the stack */
2215 /* base is a property of the executable, so this should not break */
2216 /* old executables. */
2217 /* HEURISTIC2 probably works, but this appears to be preferable. */
2218 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
2219 /* installations that's undefined. We work around this with a */
2221 # include <sys/vmparam.h>
2223 /* This should work everywhere, but doesn't. */
2224 # define STACKBOTTOM ((ptr_t) USRSTACK)
2228 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
2229 /* It appears to be fixed in 2.8 and 2.9. */
2230 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
2234 # define MPROTECT_VDB
2236 # define DYNAMIC_LOADING
2237 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
2239 /* Otherwise we now use calloc. Mmap may result in the */
2240 /* heap interleaved with thread stacks, which can result in */
2241 /* excessive blacklisting. Sbrk is unusable since it */
2242 /* doesn't interact correctly with the system malloc. */
2245 # define HEAP_START (ptr_t)0x40000000
2247 # define HEAP_START DATAEND
2251 # define OS_TYPE "MSWIN32"
2252 /* STACKBOTTOM and DATASTART are handled specially in */
2254 # if !defined(__GNUC__) || defined(__INTEL_COMPILER)
2255 /* GCC does not currently support SetUnhandledExceptionFilter */
2256 /* (does not generate SEH unwinding information) on x64. */
2257 # define MPROTECT_VDB
2260 # define DATAEND /* not needed */
2262 # endif /* X86_64 */
2265 # define CPP_WORDSZ 32
2266 # define MACH_TYPE "HEXAGON"
2267 # define ALIGNMENT 4
2269 # define OS_TYPE "LINUX"
2270 # define LINUX_STACKBOTTOM
2271 # define MPROTECT_VDB
2273 # define DYNAMIC_LOADING
2274 # include <features.h>
2275 # if defined(__GLIBC__) && __GLIBC__ >= 2
2276 # define SEARCH_FOR_DATA_START
2278 # error --> unknown Hexagon libc configuration
2281 # define DATAEND (ptr_t)(_end)
2283 # error --> bad Hexagon Linux configuration
2286 # error --> unknown Hexagon OS configuration
2290 #if defined(LINUX_STACKBOTTOM) && defined(NO_PROC_STAT) \
2291 && !defined(USE_LIBC_PRIVATES)
2292 /* This combination will fail, since we have no way to get */
2293 /* the stack base. Use HEURISTIC2 instead. */
2294 # undef LINUX_STACKBOTTOM
2296 /* This may still fail on some architectures like IA64. */
2300 #if defined(LINUX) && defined(USE_MMAP)
2301 /* The kernel may do a somewhat better job merging mappings etc. */
2302 /* with anonymous mappings. */
2303 # define USE_MMAP_ANON
2306 #if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
2307 && !defined(USE_PROC_FOR_LIBRARIES)
2308 /* Nptl allocates thread stacks with mmap, which is fine. But it */
2309 /* keeps a cache of thread stacks. Thread stacks contain the */
2310 /* thread control blocks. These in turn contain a pointer to */
2311 /* (sizeof (void *) from the beginning of) the dtv for thread-local */
2312 /* storage, which is calloc allocated. If we don't scan the cached */
2313 /* thread stacks, we appear to lose the dtv. This tends to */
2314 /* result in something that looks like a bogus dtv count, which */
2315 /* tends to result in a memset call on a block that is way too */
2316 /* large. Sometimes we're lucky and the process just dies ... */
2317 /* There seems to be a similar issue with some other memory */
2318 /* allocated by the dynamic loader. */
2319 /* This should be avoidable by either: */
2320 /* - Defining USE_PROC_FOR_LIBRARIES here. */
2321 /* That performs very poorly, precisely because we end up */
2322 /* scanning cached stacks. */
2323 /* - Have calloc look at its callers. */
2324 /* In spite of the fact that it is gross and disgusting. */
2325 /* In fact neither seems to suffice, probably in part because */
2326 /* even with USE_PROC_FOR_LIBRARIES, we don't scan parts of stack */
2327 /* segments that appear to be out of bounds. Thus we actually */
2328 /* do both, which seems to yield the best results. */
2330 # define USE_PROC_FOR_LIBRARIES
2333 #ifndef STACK_GROWS_UP
2334 # define STACK_GROWS_DOWN
2338 # define CPP_WORDSZ 32
2347 # define DATAEND (ptr_t)(end)
2350 #if defined(PLATFORM_ANDROID) && !defined(THREADS) \
2351 && !defined(USE_GET_STACKBASE_FOR_MAIN)
2352 /* Always use pthread_attr_getstack on Android ("-lpthread" option is */
2353 /* not needed to be specified manually) since GC_linux_main_stack_base */
2354 /* causes app crash if invoked inside Dalvik VM. */
2355 # define USE_GET_STACKBASE_FOR_MAIN
2358 #if (defined(SVR4) || defined(PLATFORM_ANDROID)) && !defined(GETPAGESIZE)
2359 # include <unistd.h>
2360 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
2364 # if defined(SOLARIS) || defined(IRIX5) || defined(LINUX) \
2365 || defined(NETBSD) || defined(FREEBSD) || defined(HPUX)
2366 # include <unistd.h>
2368 # define GETPAGESIZE() getpagesize()
2371 #if defined(SOLARIS) || defined(DRSNX) || defined(UTS4)
2372 /* OS has SVR4 generic features. */
2373 /* Probably others also qualify. */
2377 #if defined(SOLARIS) || defined(DRSNX)
2378 /* OS has SOLARIS style semi-undocumented interface */
2379 /* to dynamic loader. */
2381 /* OS has SOLARIS style signal handlers. */
2389 #if defined(FREEBSD) && (defined(__DragonFly__) || __FreeBSD__ >= 4 \
2390 || (__FreeBSD_kernel__ >= 4))
2394 #if !defined(GC_EXPLICIT_SIGNALS_UNBLOCK) && defined(SUNOS5SIGS) \
2395 && !defined(GC_NO_PTHREAD_SIGMASK)
2396 # define GC_EXPLICIT_SIGNALS_UNBLOCK
2399 #ifdef GC_NETBSD_THREADS
2400 # define SIGRTMIN 33
2401 # define SIGRTMAX 63
2404 #if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2405 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2406 || defined(DGUX) || defined(BSD) || defined(HURD) \
2407 || defined(AIX) || defined(DARWIN) || defined(OSF1)
2408 # define UNIX_LIKE /* Basic Unix-like system calls work. */
2411 #if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2412 # error --> bad word size
2416 # error --> undefined ALIGNMENT
2420 # undef DYNAMIC_LOADING
2425 # undef MPROTECT_VDB
2429 #if !defined(STACKBOTTOM) && (defined(ECOS) || defined(NOSYS))
2430 # error --> undefined STACKBOTTOM
2433 #ifdef IGNORE_DYNAMIC_LOADING
2434 # undef DYNAMIC_LOADING
2437 #if defined(SMALL_CONFIG) && !defined(GC_DISABLE_INCREMENTAL)
2438 /* Presumably not worth the space it takes. */
2439 # define GC_DISABLE_INCREMENTAL
2442 #if defined(GC_DISABLE_INCREMENTAL) || defined(MANUAL_VDB)
2444 # undef MPROTECT_VDB
2449 #ifdef GC_DISABLE_INCREMENTAL
2453 #ifdef USE_GLOBAL_ALLOC
2454 /* Cannot pass MEM_WRITE_WATCH to GlobalAlloc(). */
2459 /* FIXME: Remove this undef if possible. */
2460 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2463 /* PARALLEL_MARK does not cause undef MPROTECT_VDB any longer. */
2465 #if defined(MPROTECT_VDB) && defined(GC_PREFER_MPROTECT_VDB)
2466 /* Choose MPROTECT_VDB manually (if multiple strategies available). */
2469 /* #undef GWW_VDB - handled in os_dep.c */
2473 /* Multi-VDB mode is not implemented. */
2474 # undef MPROTECT_VDB
2477 #if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB) \
2478 && !defined(GWW_VDB) && !defined(MANUAL_VDB) \
2479 && !defined(GC_DISABLE_INCREMENTAL)
2480 # define DEFAULT_VDB
2483 #if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HURD) \
2484 || defined(OPENBSD) || defined(ARM32) \
2485 || defined(MIPS) || defined(AVR32))) \
2486 || (defined(LINUX) && (defined(SPARC) || defined(M68K))) \
2487 || (defined(RTEMS) && defined(I386))) && !defined(NO_GETCONTEXT)
2488 # define NO_GETCONTEXT
2492 # define PREFETCH(x)
2493 # define NO_PREFETCH
2496 #ifndef PREFETCH_FOR_WRITE
2497 # define PREFETCH_FOR_WRITE(x)
2498 # define NO_PREFETCH_FOR_WRITE
2501 #ifndef CACHE_LINE_SIZE
2502 # define CACHE_LINE_SIZE 32 /* Wild guess */
2506 # ifndef NO_DEBUGGING
2507 # define STATIC /* ignore to aid profiling and possibly debugging */
2509 # define STATIC static
2513 #if defined(LINUX) && (defined(USE_PROC_FOR_LIBRARIES) || defined(IA64) \
2514 || !defined(SMALL_CONFIG))
2515 # define NEED_PROC_MAPS
2518 #if defined(LINUX) || defined(HURD) || defined(__GLIBC__)
2519 # define REGISTER_LIBRARIES_EARLY
2520 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2521 /* lock. This isn't safe after the world has stopped. So we must */
2522 /* call GC_register_dynamic_libraries before stopping the world. */
2523 /* For performance reasons, this may be beneficial on other */
2524 /* platforms as well, though it should be avoided in win32. */
2527 #if defined(SEARCH_FOR_DATA_START)
2528 extern ptr_t GC_data_start;
2529 # define DATASTART GC_data_start
2532 #ifndef CLEAR_DOUBLE
2533 # define CLEAR_DOUBLE(x) (((word*)(x))[0] = 0, ((word*)(x))[1] = 0)
2536 #if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
2537 && !defined(INCLUDE_LINUX_THREAD_DESCR)
2538 /* Will not work, since libc and the dynamic loader use thread */
2539 /* locals, sometimes as the only reference. */
2540 # define INCLUDE_LINUX_THREAD_DESCR
2543 #if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2544 # error --> inconsistent configuration
2546 #if defined(GC_LINUX_THREADS) && !defined(LINUX) && !defined(NACL)
2547 # error --> inconsistent configuration
2549 #if defined(GC_NETBSD_THREADS) && !defined(NETBSD)
2550 # error --> inconsistent configuration
2552 #if defined(GC_FREEBSD_THREADS) && !defined(FREEBSD)
2553 # error --> inconsistent configuration
2555 #if defined(GC_SOLARIS_THREADS) && !defined(SOLARIS)
2556 # error --> inconsistent configuration
2558 #if defined(GC_HPUX_THREADS) && !defined(HPUX)
2559 # error --> inconsistent configuration
2561 #if defined(GC_AIX_THREADS) && !defined(_AIX)
2562 # error --> inconsistent configuration
2564 #if defined(GC_GNU_THREADS) && !defined(HURD)
2565 # error --> inconsistent configuration
2567 #if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32) \
2568 && !defined(MSWINCE)
2569 # error --> inconsistent configuration
2572 #if defined(PCR) || defined(GC_WIN32_THREADS) || defined(GC_PTHREADS) \
2573 || defined(SN_TARGET_PS3)
2577 #if defined(UNIX_LIKE) && defined(THREADS) && !defined(NO_CANCEL_SAFE) \
2578 && !defined(PLATFORM_ANDROID)
2579 /* Make the code cancellation-safe. This basically means that we */
2580 /* ensure that cancellation requests are ignored while we are in */
2581 /* the collector. This applies only to Posix deferred cancellation; */
2582 /* we don't handle Posix asynchronous cancellation. */
2583 /* Note that this only works if pthread_setcancelstate is */
2584 /* async-signal-safe, at least in the absence of asynchronous */
2585 /* cancellation. This appears to be true for the glibc version, */
2586 /* though it is not documented. Without that assumption, there */
2587 /* seems to be no way to safely wait in a signal handler, which */
2588 /* we need to do for thread suspension. */
2589 /* Also note that little other code appears to be cancellation-safe. */
2590 /* Hence it may make sense to turn this off for performance. */
2591 # define CANCEL_SAFE
2595 # define IF_CANCEL(x) x
2597 # define IF_CANCEL(x) /* empty */
2600 #if !defined(CAN_HANDLE_FORK) && !defined(NO_HANDLE_FORK) \
2601 && ((defined(GC_PTHREADS) && !defined(HURD) && !defined(NACL) \
2602 && !defined(PLATFORM_ANDROID) && !defined(GC_WIN32_PTHREADS)) \
2603 || (defined(DARWIN) && defined(MPROTECT_VDB)) || defined(HANDLE_FORK))
2604 /* Attempts (where supported and requested) to make GC_malloc work in */
2605 /* a child process fork'ed from a multi-threaded parent. */
2606 # define CAN_HANDLE_FORK
2609 #if !defined(USE_MARK_BITS) && !defined(USE_MARK_BYTES) \
2610 && defined(PARALLEL_MARK)
2611 /* Minimize compare-and-swap usage. */
2612 # define USE_MARK_BYTES
2615 #if defined(MSWINCE) && !defined(__CEGCC__) && !defined(NO_GETENV)
2619 #if (defined(NO_GETENV) || defined(MSWINCE)) && !defined(NO_GETENV_WIN32)
2620 # define NO_GETENV_WIN32
2624 # if defined(_WIN64) && !defined(__GNUC__)
2625 # define STRTOULL _strtoui64
2626 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
2627 # define STRTOULL strtoull
2629 /* strtoul() fits since sizeof(long) >= sizeof(word). */
2630 # define STRTOULL strtoul
2632 #endif /* !STRTOULL */
2635 # if defined(_WIN64) && !defined(__GNUC__)
2636 # define GC_WORD_C(val) val##ui64
2637 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
2638 # define GC_WORD_C(val) val##ULL
2640 # define GC_WORD_C(val) ((word)val##UL)
2642 #endif /* !GC_WORD_C */
2645 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2646 /* include assembly code to do it well. */
2649 /* Can we save call chain in objects for debugging? */
2650 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2651 /* frame) to reasonable values for the platform. */
2652 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2653 /* at build time, though we feel free to adjust it slightly. */
2654 /* Define NEED_CALLINFO if we either save the call stack or */
2655 /* GC_ADD_CALLER is defined. */
2656 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2658 # define CAN_SAVE_CALL_ARGS
2660 #if (defined(I386) || defined(X86_64)) \
2661 && (defined(LINUX) || defined(__GLIBC__))
2662 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2663 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2664 # define CAN_SAVE_CALL_ARGS
2667 #if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2668 && defined(GC_CAN_SAVE_CALL_STACKS)
2669 # define SAVE_CALL_CHAIN
2671 #ifdef SAVE_CALL_CHAIN
2672 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2673 # define NARGS SAVE_CALL_NARGS
2675 # define NARGS 0 /* Number of arguments to save for each call. */
2678 #ifdef SAVE_CALL_CHAIN
2679 # ifndef SAVE_CALL_COUNT
2680 # define NFRAMES 6 /* Number of frames to save. Even for */
2681 /* alignment reasons. */
2683 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2685 # define NEED_CALLINFO
2686 #endif /* SAVE_CALL_CHAIN */
2687 #ifdef GC_ADD_CALLER
2690 # define NEED_CALLINFO
2693 #if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2694 # define DBG_HDRS_ALL
2697 #if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2698 # define POINTER_SHIFT 0
2701 #if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2702 # define POINTER_MASK ((GC_word)(-1))
2705 #if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2706 # define FIXUP_POINTER(p) (p = ((p) & POINTER_MASK) << POINTER_SHIFT)
2709 #if defined(FIXUP_POINTER)
2710 # define NEED_FIXUP_POINTER 1
2712 # define NEED_FIXUP_POINTER 0
2713 # define FIXUP_POINTER(p)
2716 #if !defined(MARK_BIT_PER_GRANULE) && !defined(MARK_BIT_PER_OBJ)
2717 # define MARK_BIT_PER_GRANULE /* Usually faster */
2720 /* Some static sanity tests. */
2721 #if defined(MARK_BIT_PER_GRANULE) && defined(MARK_BIT_PER_OBJ)
2722 # error Define only one of MARK_BIT_PER_GRANULE and MARK_BIT_PER_OBJ.
2725 #if defined(STACK_GROWS_UP) && defined(STACK_GROWS_DOWN)
2726 # error "Only one of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
2728 #if !defined(STACK_GROWS_UP) && !defined(STACK_GROWS_DOWN)
2729 # error "One of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
2732 #if defined(REDIRECT_MALLOC) && defined(THREADS) && !defined(LINUX)
2733 # error "REDIRECT_MALLOC with THREADS works at most on Linux."
2737 /* This relies on some type definitions from gc_priv.h, from */
2738 /* where it's normally included. */
2740 /* How to get heap memory from the OS: */
2741 /* Note that sbrk()-like allocation is preferred, since it */
2742 /* usually makes it possible to merge consecutively allocated */
2743 /* chunks. It also avoids unintended recursion with */
2744 /* REDIRECT_MALLOC macro defined. */
2745 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2746 /* 0 is taken to mean failure. */
2747 /* In the case os USE_MMAP, the argument must also be a */
2748 /* physical page size. */
2749 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2750 /* though we should perhaps take advantage of the case in which */
2752 struct hblk; /* See gc_priv.h. */
2754 char * real_malloc(size_t bytes);
2755 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)(bytes) + GC_page_size) \
2758 void * os2_alloc(size_t bytes);
2759 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)(bytes) \
2760 + GC_page_size) + GC_page_size-1)
2761 # elif defined(NEXT) || defined(DOS4GW) || defined(NONSTOP) \
2762 || (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) \
2763 || (defined(SOLARIS) && !defined(USE_MMAP)) || defined(RTEMS) \
2764 || defined(__CC_ARM)
2765 # define GET_MEM(bytes) HBLKPTR((size_t)calloc(1, \
2766 (size_t)(bytes) + GC_page_size) \
2768 # elif defined(MSWIN32) || defined(CYGWIN32)
2769 ptr_t GC_win32_get_mem(GC_word bytes);
2770 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2771 # elif defined(MACOS)
2772 # if defined(USE_TEMPORARY_MEMORY)
2773 Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory);
2774 # define GET_MEM(bytes) HBLKPTR( \
2775 GC_MacTemporaryNewPtr((bytes) + GC_page_size, true) \
2778 # define GET_MEM(bytes) HBLKPTR(NewPtrClear((bytes) + GC_page_size) \
2781 # elif defined(MSWINCE)
2782 ptr_t GC_wince_get_mem(GC_word bytes);
2783 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2784 # elif defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2785 void *GC_amiga_get_mem(size_t size);
2786 # define GET_MEM(bytes) HBLKPTR((size_t) \
2787 GC_amiga_get_mem((size_t)(bytes) + GC_page_size) \
2789 # elif defined(SN_TARGET_PS3)
2790 void *ps3_get_mem(size_t size);
2791 # define GET_MEM(bytes) (struct hblk*)ps3_get_mem(bytes)
2793 ptr_t GC_unix_get_mem(GC_word bytes);
2794 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2796 #endif /* GC_PRIVATE_H */
2798 #endif /* GCCONFIG_H */