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
30 /* Fake ptr_t declaration, just to avoid compilation errors. */
31 /* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
32 typedef struct GC_undefined_struct * ptr_t;
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__)
47 /* And one for NetBSD: */
48 # if defined(__NetBSD__)
52 /* And one for OpenBSD: */
53 # if defined(__OpenBSD__)
57 /* And one for FreeBSD: */
58 # if defined(__FreeBSD__)
62 /* Determine the machine type: */
63 # if defined(__arm__) || defined(__thumb__)
65 # if !defined(LINUX) && !defined(NETBSD)
67 # define mach_type_known
70 # if defined(sun) && defined(mc68000)
73 # define mach_type_known
75 # if defined(hp9000s300)
78 # define mach_type_known
80 # if defined(OPENBSD) && defined(m68k)
82 # define mach_type_known
84 # if defined(OPENBSD) && defined(__sparc__)
86 # define mach_type_known
88 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
90 # define mach_type_known
92 # if defined(NETBSD) && defined(__powerpc__)
94 # define mach_type_known
96 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
98 # define mach_type_known
107 # define mach_type_known
109 # if defined(__NetBSD__) && defined(__vax__)
111 # define mach_type_known
113 # if defined(mips) || defined(__mips) || defined(_mips)
115 # if defined(nec_ews) || defined(_nec_ews)
118 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
119 # if defined(ultrix) || defined(__ultrix)
122 # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
123 || defined(__SYSTYPE_SVR4__)
124 # define IRIX5 /* or IRIX 6.X */
126 # define RISCOS /* or IRIX 4.X */
130 # define mach_type_known
132 # if defined(DGUX) && (defined(i386) || defined(__i386__))
137 # define mach_type_known
139 # if defined(sequent) && (defined(i386) || defined(__i386__))
142 # define mach_type_known
144 # if defined(sun) && (defined(i386) || defined(__i386__))
147 # define mach_type_known
149 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
152 # define mach_type_known
156 # define mach_type_known
158 # if defined(sun) && (defined(sparc) || defined(__sparc))
160 /* Test for SunOS 5.x */
167 # define mach_type_known
169 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
170 && !defined(__OpenBSD__) && !(__NetBSD__)
173 # define mach_type_known
177 # define mach_type_known
179 # if defined(__NetBSD__) && defined(__sparc__)
181 # define mach_type_known
183 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
184 /* The above test may need refinement */
186 # if defined(_SCO_ELF)
191 # define mach_type_known
193 # if defined(_AUX_SOURCE)
196 # define mach_type_known
198 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
199 || defined(hppa) || defined(__hppa__)
204 # define mach_type_known
206 # if defined(__ia64) && defined(_HPUX_SOURCE)
209 # define mach_type_known
211 # if defined(__BEOS__) && defined(_X86_)
214 # define mach_type_known
216 # if defined(LINUX) && (defined(i386) || defined(__i386__))
218 # define mach_type_known
220 # if defined(LINUX) && defined(__x86_64__)
222 # define mach_type_known
224 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
226 # define mach_type_known
228 # if defined(LINUX) && defined(__arm__)
230 # define mach_type_known
232 # if defined(LINUX) && defined(__cris__)
236 # define mach_type_known
238 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || defined(powerpc64) || defined(__powerpc64__))
240 # define mach_type_known
242 # if defined(LINUX) && defined(__mc68000__)
244 # define mach_type_known
246 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
248 # define mach_type_known
250 # if defined(LINUX) && defined(__arm__)
252 # define mach_type_known
254 # if defined(LINUX) && defined(__sh__)
256 # define mach_type_known
258 # if defined(LINUX) && defined(__m32r__)
260 # define mach_type_known
262 # if defined(__alpha) || defined(__alpha__)
264 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
265 # define OSF1 /* a.k.a Digital Unix */
267 # define mach_type_known
269 # if defined(_AMIGA) && !defined(AMIGA)
274 # define mach_type_known
276 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
279 # define mach_type_known
281 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
284 # define mach_type_known
286 # if defined(macosx) \
287 || defined(__APPLE__) && defined(__MACH__) && defined(__ppc__) \
288 || defined(__APPLE__) && defined(__MACH__) && defined(__ppc64__)
291 # define mach_type_known
293 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
296 --> Not really supported, but at least we recognize it.
298 # if defined(NeXT) && defined(mc68000)
301 # define mach_type_known
303 # if defined(NeXT) && (defined(i386) || defined(__i386__))
306 # define mach_type_known
308 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
311 # define mach_type_known
313 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
315 # define mach_type_known
317 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
319 # define mach_type_known
321 # if defined(__NetBSD__) && defined(__x86_64__)
323 # define mach_type_known
325 # if defined(bsdi) && (defined(i386) || defined(__i386__))
328 # define mach_type_known
330 # if !defined(mach_type_known) && defined(__386BSD__)
333 # define mach_type_known
335 # if defined(_CX_UX) && defined(_M88K)
338 # define mach_type_known
340 # if defined(DGUX) && defined(m88k)
343 # define mach_type_known
345 # if defined(_WIN32_WCE)
346 /* SH3, SH4, MIPS already defined for corresponding architectures */
347 # if defined(SH3) || defined(SH4)
357 # define mach_type_known
359 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
360 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
362 # define MSWIN32 /* or Win32s */
363 # define mach_type_known
365 # if defined(_MSC_VER) && defined(_M_IA64)
367 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
368 /* variants as a differnt platform. */
371 # if defined(__DJGPP__)
374 # define DJGPP /* MSDOS running the DJGPP port of GCC */
376 # define mach_type_known
378 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
381 # define mach_type_known
383 # if defined(__MINGW32__)
386 # define mach_type_known
388 # if defined(__BORLANDC__)
391 # define mach_type_known
393 # if defined(_UTS) && !defined(mach_type_known)
396 # define mach_type_known
400 # define mach_type_known
402 # if defined(__embedded__) && defined(PPC)
405 # define mach_type_known
408 # if defined(__WATCOMC__) && defined(__386__)
410 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
411 # if defined(__OS2__)
414 # if defined(__WINDOWS_386__) || defined(__NT__)
421 # define mach_type_known
423 # if defined(__s390__) && defined(LINUX)
425 # define mach_type_known
427 # if defined(__GNU__)
428 # if defined(__i386__)
429 /* The Debian Hurd running on generic PC */
432 # define mach_type_known
436 /* Feel free to add more clauses here */
438 /* Or manually define the machine type here. A machine type is */
439 /* characterized by the architecture. Some */
440 /* machine types are further subdivided by OS. */
441 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
442 /* Note that SGI IRIX is treated identically to RISCOS. */
443 /* SYSV on an M68K actually means A/UX. */
444 /* The distinction in these cases is usually the stack starting address */
445 # ifndef mach_type_known
446 --> unknown machine type
448 /* Mapping is: M68K ==> Motorola 680X0 */
449 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
450 /* MACOS and AMIGA variants) */
451 /* I386 ==> Intel 386 */
452 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
453 /* FREEBSD, THREE86BSD, MSWIN32, */
454 /* BSDI,SUNOS5, NEXT, other variants) */
455 /* NS32K ==> Encore Multimax */
456 /* MIPS ==> R2000 or R3000 */
457 /* (RISCOS, ULTRIX variants) */
458 /* VAX ==> DEC VAX */
459 /* (BSD, ULTRIX variants) */
460 /* RS6000 ==> IBM RS/6000 AIX3.X */
461 /* RT ==> IBM PC/RT */
462 /* HP_PA ==> HP9000/700 & /800 */
464 /* SPARC ==> SPARC v7/v8/v9 */
465 /* (SUNOS4, SUNOS5, LINUX, */
466 /* DRSNX variants) */
467 /* ALPHA ==> DEC Alpha */
468 /* (OSF1 and LINUX variants) */
469 /* M88K ==> Motorola 88XX0 */
470 /* (CX_UX and DGUX) */
471 /* S370 ==> 370-like machine */
472 /* running Amdahl UTS4 */
473 /* S390 ==> 390-like machine */
475 /* ARM32 ==> Intel StrongARM */
476 /* IA64 ==> Intel IPF */
478 /* (LINUX and HPUX) */
479 /* SH ==> Hitachi SuperH */
480 /* (LINUX & MSWINCE) */
481 /* X86_64 ==> AMD x86-64 */
482 /* POWERPC ==> IBM/Apple PowerPC */
483 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
484 /* LINUX, NETBSD, NOSYS variants) */
485 /* CRIS ==> Axis Etrax */
486 /* M32R ==> Renesas M32R */
490 * For each architecture and OS, the following need to be defined:
492 * CPP_WORD_SZ is a simple integer constant representing the word size.
493 * in bits. We assume byte addressibility, where a byte has 8 bits.
494 * We also assume CPP_WORD_SZ is either 32 or 64.
495 * (We care about the length of pointers, not hardware
496 * bus widths. Thus a 64 bit processor with a C compiler that uses
497 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
499 * MACH_TYPE is a string representation of the machine type.
500 * OS_TYPE is analogous for the OS.
502 * ALIGNMENT is the largest N, such that
503 * all pointer are guaranteed to be aligned on N byte boundaries.
504 * defining it to be 1 will always work, but perform poorly.
506 * DATASTART is the beginning of the data segment.
507 * On some platforms SEARCH_FOR_DATA_START is defined.
508 * SEARCH_FOR_DATASTART will cause GC_data_start to
509 * be set to an address determined by accessing data backwards from _end
510 * until an unmapped page is found. DATASTART will be defined to be
512 * On UNIX-like systems, the collector will scan the area between DATASTART
513 * and DATAEND for root pointers.
515 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
516 * RTH suggests gaining access to linker script synth'd values with
517 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
518 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
519 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
520 * without any special options.
522 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
525 * STACKBOTTOM is the cool end of the stack, which is usually the
526 * highest address in the stack.
527 * Under PCR or OS/2, we have other ways of finding thread stacks.
528 * For each machine, the following should:
529 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
530 * 2) define exactly one of
531 * STACKBOTTOM (should be defined to be an expression)
535 * If STACKBOTTOM is defined, then it's value will be used directly as the
536 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
537 * with a method appropriate for most Linux systems. Currently we look
538 * first for __libc_stack_end, and if that fails read it from /proc.
539 * If either of the last two macros are defined, then STACKBOTTOM is computed
540 * during collector startup using one of the following two heuristics:
541 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
542 * the next multiple of STACK_GRAN.
543 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
544 * in small steps (decrement if STACK_GROWS_UP), and read the value
545 * at each location. Remember the value when the first
546 * Segmentation violation or Bus error is signalled. Round that
547 * to the nearest plausible page boundary, and use that instead
550 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
551 * the value of environ is a pointer that can serve as STACKBOTTOM.
552 * I expect that HEURISTIC2 can be replaced by this approach, which
553 * interferes far less with debugging. However it has the disadvantage
554 * that it's confused by a putenv call before the collector is initialized.
555 * This could be dealt with by intercepting putenv ...
557 * If no expression for STACKBOTTOM can be found, and neither of the above
558 * heuristics are usable, the collector can still be used with all of the above
559 * undefined, provided one of the following is done:
560 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
561 * without reference to STACKBOTTOM. This is appropriate for use in
562 * conjunction with thread packages, since there will be multiple stacks.
563 * (Allocating thread stacks in the heap, and treating them as ordinary
564 * heap data objects is also possible as a last resort. However, this is
565 * likely to introduce significant amounts of excess storage retention
566 * unless the dead parts of the thread stacks are periodically cleared.)
567 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
568 * If the author of the client code controls the main program, this is
569 * easily accomplished by introducing a new main program, setting
570 * GC_stackbottom to the address of a local variable, and then calling
571 * the original main program. The new main program would read something
574 * # include "gc_private.h"
576 * main(argc, argv, envp)
578 * char **argv, **envp;
582 * GC_stackbottom = (ptr_t)(&dummy);
583 * return(real_main(argc, argv, envp));
587 * Each architecture may also define the style of virtual dirty bit
588 * implementation to be used:
589 * MPROTECT_VDB: Write protect the heap and catch faults.
590 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
592 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
593 * defined GC_register_dynamic_libraries() for the architecture.
595 * An architecture may define PREFETCH(x) to preload the cache with *x.
596 * This defaults to a no-op.
598 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
600 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
601 * clear the two words at GC_malloc-aligned address x. By default,
602 * word stores of 0 are used instead.
604 * HEAP_START may be defined as the initial address hint for mmap-based
608 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
609 * to push the relevant registers onto the stack. This generally makes
610 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
612 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
613 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
614 && !defined(__INTEL_COMPILER)
615 # define HAVE_BUILTIN_UNWIND_INIT
618 # define STACK_GRAN 0x1000000
620 # define MACH_TYPE "M68K"
623 # define OS_TYPE "OPENBSD"
626 # define DATASTART GC_data_start
627 # define DYNAMIC_LOADING
630 # define DATASTART ((ptr_t)(etext))
632 # define USE_GENERIC_PUSH_REGS
635 # define OS_TYPE "NETBSD"
638 # define DATASTART GC_data_start
639 # define DYNAMIC_LOADING
642 # define DATASTART ((ptr_t)(etext))
644 # define USE_GENERIC_PUSH_REGS
647 # define OS_TYPE "LINUX"
648 # define STACKBOTTOM ((ptr_t)0xf0000000)
649 # define USE_GENERIC_PUSH_REGS
651 /* We never got around to the assembly version. */
652 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
654 # define DYNAMIC_LOADING
655 # include <features.h>
656 # if defined(__GLIBC__)&& __GLIBC__>=2
657 # define SEARCH_FOR_DATA_START
659 extern char **__environ;
660 # define DATASTART ((ptr_t)(&__environ))
661 /* hideous kludge: __environ is the first */
662 /* word in crt0.o, and delimits the start */
663 /* of the data segment, no matter which */
664 /* ld options were passed through. */
665 /* We could use _etext instead, but that */
666 /* would include .rodata, which may */
667 /* contain large read-only data tables */
668 /* that we'd rather not scan. */
669 # endif /* !GLIBC2 */
671 # define DATAEND (_end)
674 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
678 # define OS_TYPE "SUNOS4"
680 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
681 # define HEURISTIC1 /* differs */
682 # define DYNAMIC_LOADING
685 # define OS_TYPE "HP"
687 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
688 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
689 /* empirically determined. seems to work. */
691 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
694 # define OS_TYPE "SYSV"
696 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
698 +((word)etext & 0x1fff))
699 /* This only works for shared-text binaries with magic number 0413.
700 The other sorts of SysV binaries put the data at the end of the text,
701 in which case the default of etext would work. Unfortunately,
702 handling both would require having the magic-number available.
705 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
706 /* The stack starts at the top of memory, but */
707 /* 0x0 cannot be used as setjump_test complains */
708 /* that the stack direction is incorrect. Two */
709 /* bytes down from 0x0 should be safe enough. */
711 # include <sys/mmu.h>
712 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
715 # define OS_TYPE "AMIGA"
716 /* STACKBOTTOM and DATASTART handled specially */
718 # define DATAEND /* not needed */
719 # define GETPAGESIZE() 4096
725 # define OS_TYPE "MACOS"
726 /* see os_dep.c for details of global data segments. */
727 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
728 # define DATAEND /* not needed */
729 # define GETPAGESIZE() 4096
732 # define OS_TYPE "NEXT"
733 # define DATASTART ((ptr_t) get_etext())
734 # define STACKBOTTOM ((ptr_t) 0x4000000)
735 # define DATAEND /* not needed */
740 # define MACH_TYPE "POWERPC"
742 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
746 # define OS_TYPE "MACOS"
747 /* see os_dep.c for details of global data segments. */
748 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
749 # define DATAEND /* not needed */
752 # if (defined (powerpc64) || defined(__powerpc64__))
754 # define CPP_WORDSZ 64
758 # define OS_TYPE "LINUX"
759 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
760 /* executable on a 64 bit kernel. */
761 # define LINUX_STACKBOTTOM
762 # define DYNAMIC_LOADING
763 # define SEARCH_FOR_DATA_START
765 # define DATAEND (_end)
768 # if (defined (__ppc64__))
770 # define CPP_WORDSZ 64
774 # define OS_TYPE "DARWIN"
775 # define DYNAMIC_LOADING
776 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
777 These aren't used when dyld support is enabled (it is by default) */
778 # define DATASTART ((ptr_t) get_etext())
779 # define DATAEND ((ptr_t) get_end())
780 # define STACKBOTTOM ((ptr_t) 0xc0000000)
782 # define USE_MMAP_ANON
783 # define USE_ASM_PUSH_REGS
784 /* This is potentially buggy. It needs more testing. See the comments in
786 # define MPROTECT_VDB
788 # define GETPAGESIZE() getpagesize()
789 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
790 /* The performance impact of prefetches is untested */
791 # define PREFETCH(x) \
792 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
793 # define PREFETCH_FOR_WRITE(x) \
794 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
796 /* There seems to be some issues with trylock hanging on darwin. This
797 should be looked into some more */
798 # define NO_PTHREAD_TRYLOCK
802 # define OS_TYPE "NETBSD"
805 # define DATASTART GC_data_start
806 # define DYNAMIC_LOADING
810 # define OS_TYPE "NOSYS"
811 extern void __end[], __dso_handle[];
812 # define DATASTART (__dso_handle) /* OK, that's ugly. */
813 # define DATAEND (__end)
814 /* Stack starts at 0xE0000000 for the simulator. */
816 # define STACK_GRAN 0x10000000
822 # define MACH_TYPE "VAX"
823 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
825 # define DATASTART ((ptr_t)(etext))
827 # define OS_TYPE "BSD"
829 /* HEURISTIC2 may be OK, but it's hard to test. */
832 # define OS_TYPE "ULTRIX"
833 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
838 # define MACH_TYPE "RT"
840 # define DATASTART ((ptr_t) 0x10000000)
841 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
845 # define MACH_TYPE "SPARC"
846 # if defined(__arch64__) || defined(__sparcv9)
848 # define CPP_WORDSZ 64
849 # define ELF_CLASS ELFCLASS64
851 # define ALIGNMENT 4 /* Required by hardware */
852 # define CPP_WORDSZ 32
854 # define ALIGN_DOUBLE
856 # define OS_TYPE "SUNOS5"
859 extern ptr_t GC_SysVGetDataStart();
860 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
861 # define DATAEND (_end)
862 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
864 /* Otherwise we now use calloc. Mmap may result in the */
865 /* heap interleaved with thread stacks, which can result in */
866 /* excessive blacklisting. Sbrk is unusable since it */
867 /* doesn't interact correctly with the system malloc. */
870 # define HEAP_START (ptr_t)0x40000000
872 # define HEAP_START DATAEND
875 /* HEURISTIC1 reportedly no longer works under 2.7. */
876 /* HEURISTIC2 probably works, but this appears to be preferable. */
877 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
878 /* installations that's undefined. We work around this with a */
880 # include <sys/vmparam.h>
882 /* This should work everywhere, but doesn't. */
883 # define STACKBOTTOM USRSTACK
888 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
889 /* getpagesize() appeared to be missing from at least one */
890 /* Solaris 5.4 installation. Weird. */
891 # define DYNAMIC_LOADING
894 # define OS_TYPE "SUNOS4"
895 /* [If you have a weak stomach, don't read this.] */
896 /* We would like to use: */
897 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
898 /* This fails occasionally, due to an ancient, but very */
899 /* persistent ld bug. etext is set 32 bytes too high. */
900 /* We instead read the text segment size from the a.out */
901 /* header, which happens to be mapped into our address space */
902 /* at the start of the text segment. The detective work here */
903 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
904 /* Serpette of INRIA. */
905 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
906 # define TEXTSTART 0x2000
907 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
908 # define MPROTECT_VDB
910 # define DYNAMIC_LOADING
913 # define OS_TYPE "DRSNX"
914 extern ptr_t GC_SysVGetDataStart();
916 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
917 # define MPROTECT_VDB
918 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
919 # define DYNAMIC_LOADING
922 # define OS_TYPE "LINUX"
924 # define DYNAMIC_LOADING
926 Linux Sparc/a.out not supported
930 # define DATAEND (_end)
932 extern ptr_t GC_SysVGetDataStart();
934 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
936 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
938 # define LINUX_STACKBOTTOM
941 # define OS_TYPE "OPENBSD"
942 # define STACKBOTTOM ((ptr_t) 0xf8000000)
944 # define DATASTART ((ptr_t)(etext))
947 # define OS_TYPE "NETBSD"
950 # define DATASTART GC_data_start
951 # define DYNAMIC_LOADING
954 # define DATASTART ((ptr_t)(etext))
960 # define MACH_TYPE "I386"
961 # if defined(__LP64__) || defined(_WIN64)
962 # define CPP_WORDSZ 64
965 # define CPP_WORDSZ 32
967 /* Appears to hold for all "32 bit" compilers */
968 /* except Borland. The -a4 option fixes */
970 /* Ivan Demakov: For Watcom the option is -zp4. */
972 # ifndef SMALL_CONFIG
973 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
974 /* improvement on Pentiums. */
976 # ifdef HAVE_BUILTIN_UNWIND_INIT
977 # define USE_GENERIC_PUSH_REGS
980 # define OS_TYPE "SEQUENT"
982 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
983 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
986 # define OS_TYPE "BEOS"
988 # define GETPAGESIZE() B_PAGE_SIZE
990 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
993 # define OS_TYPE "SUNOS5"
994 extern int _etext[], _end[];
995 extern ptr_t GC_SysVGetDataStart();
996 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
997 # define DATAEND (_end)
998 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
999 /* but reportedly breaks under 2.8. It appears that the stack */
1000 /* base is a property of the executable, so this should not break */
1001 /* old executables. */
1002 /* HEURISTIC2 probably works, but this appears to be preferable. */
1003 # include <sys/vm.h>
1004 # define STACKBOTTOM USRSTACK
1005 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1006 /* It appears to be fixed in 2.8 and 2.9. */
1007 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1010 # define DYNAMIC_LOADING
1011 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1013 /* Otherwise we now use calloc. Mmap may result in the */
1014 /* heap interleaved with thread stacks, which can result in */
1015 /* excessive blacklisting. Sbrk is unusable since it */
1016 /* doesn't interact correctly with the system malloc. */
1019 # define HEAP_START (ptr_t)0x40000000
1021 # define HEAP_START DATAEND
1025 # define OS_TYPE "SCO"
1027 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1029 +((word)etext & 0xfff))
1030 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1033 # define OS_TYPE "SCO_ELF"
1035 # define DATASTART ((ptr_t)(etext))
1036 # define STACKBOTTOM ((ptr_t) 0x08048000)
1037 # define DYNAMIC_LOADING
1038 # define ELF_CLASS ELFCLASS32
1041 # define OS_TYPE "DGUX"
1042 extern int _etext, _end;
1043 extern ptr_t GC_SysVGetDataStart();
1044 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1045 # define DATAEND (&_end)
1046 # define STACK_GROWS_DOWN
1048 # include <unistd.h>
1049 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1050 # define DYNAMIC_LOADING
1053 # endif /* USE_MMAP */
1054 # define MAP_FAILED (void *) -1
1056 # define HEAP_START (ptr_t)0x40000000
1057 # else /* USE_MMAP */
1058 # define HEAP_START DATAEND
1059 # endif /* USE_MMAP */
1064 /* The Intel compiler doesn't like inline assembly */
1065 # define USE_GENERIC_PUSH_REGS
1067 # define OS_TYPE "LINUX"
1068 # define LINUX_STACKBOTTOM
1072 # define STACK_GRAN 0x10000000
1073 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1074 /* different kernel configurations. In particular, systems */
1075 /* with 2GB physical memory will usually move the user */
1076 /* address space limit, and hence initial SP to 0x80000000. */
1078 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1079 # define MPROTECT_VDB
1081 /* We seem to get random errors in incremental mode, */
1082 /* possibly because Linux threads is itself a malloc client */
1083 /* and can't deal with the signals. */
1085 # define HEAP_START (ptr_t)0x1000
1086 /* This encourages mmap to give us low addresses, */
1087 /* thus allowing the heap to grow to ~3GB */
1089 # define DYNAMIC_LOADING
1090 # ifdef UNDEFINED /* includes ro data */
1091 extern int _etext[];
1092 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1094 # include <features.h>
1095 # if defined(__GLIBC__) && __GLIBC__ >= 2
1096 # define SEARCH_FOR_DATA_START
1098 extern char **__environ;
1099 # define DATASTART ((ptr_t)(&__environ))
1100 /* hideous kludge: __environ is the first */
1101 /* word in crt0.o, and delimits the start */
1102 /* of the data segment, no matter which */
1103 /* ld options were passed through. */
1104 /* We could use _etext instead, but that */
1105 /* would include .rodata, which may */
1106 /* contain large read-only data tables */
1107 /* that we'd rather not scan. */
1110 # define DATAEND (_end)
1113 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1115 # ifdef USE_I686_PREFETCH
1116 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1117 /* for the next rtelease. */
1118 # define PREFETCH(x) \
1119 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1120 /* Empirically prefetcht0 is much more effective at reducing */
1121 /* cache miss stalls for the targetted load instructions. But it */
1122 /* seems to interfere enough with other cache traffic that the net */
1123 /* result is worse than prefetchnta. */
1125 /* Using prefetches for write seems to have a slight negative */
1126 /* impact on performance, at least for a PIII/500. */
1127 # define PREFETCH_FOR_WRITE(x) \
1128 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1131 # ifdef USE_3DNOW_PREFETCH
1132 # define PREFETCH(x) \
1133 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1134 # define PREFETCH_FOR_WRITE(x) \
1135 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1139 # define OS_TYPE "CYGWIN32"
1140 extern int _data_start__[];
1141 extern int _data_end__[];
1142 extern int _bss_start__[];
1143 extern int _bss_end__[];
1144 /* For binutils 2.9.1, we have */
1145 /* DATASTART = _data_start__ */
1146 /* DATAEND = _bss_end__ */
1147 /* whereas for some earlier versions it was */
1148 /* DATASTART = _bss_start__ */
1149 /* DATAEND = _data_end__ */
1150 /* To get it right for both, we take the */
1151 /* minumum/maximum of the two. */
1153 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1156 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1158 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1159 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1161 # define STACK_GRAN 0x10000
1165 # define OS_TYPE "OS2"
1166 /* STACKBOTTOM and DATASTART are handled specially in */
1167 /* os_dep.c. OS2 actually has the right */
1169 # define DATAEND /* not needed */
1170 # define USE_GENERIC_PUSH_REGS
1173 # define OS_TYPE "MSWIN32"
1174 /* STACKBOTTOM and DATASTART are handled specially in */
1176 # ifndef __WATCOMC__
1177 # define MPROTECT_VDB
1179 # define DATAEND /* not needed */
1182 # define OS_TYPE "MSWINCE"
1183 # define DATAEND /* not needed */
1186 # define OS_TYPE "DJGPP"
1187 # include "stubinfo.h"
1190 extern int __djgpp_stack_limit;
1191 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1192 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1194 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1195 /* This may not be right. */
1198 # define OS_TYPE "OPENBSD"
1201 # define OS_TYPE "FREEBSD"
1202 # ifndef GC_FREEBSD_THREADS
1203 # define MPROTECT_VDB
1205 # define SIG_SUSPEND SIGUSR1
1206 # define SIG_THR_RESTART SIGUSR2
1207 # define FREEBSD_STACKBOTTOM
1209 # define DYNAMIC_LOADING
1211 extern char etext[];
1212 extern char * GC_FreeBSDGetDataStart();
1213 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1216 # define OS_TYPE "NETBSD"
1218 # define DYNAMIC_LOADING
1222 # define OS_TYPE "THREE86BSD"
1225 # define OS_TYPE "BSDI"
1227 # if defined(OPENBSD) || defined(NETBSD) \
1228 || defined(THREE86BSD) || defined(BSDI)
1230 extern char etext[];
1231 # define DATASTART ((ptr_t)(etext))
1234 # define OS_TYPE "NEXT"
1235 # define DATASTART ((ptr_t) get_etext())
1236 # define STACKBOTTOM ((ptr_t)0xc0000000)
1237 # define DATAEND /* not needed */
1240 # define OS_TYPE "DOS4GW"
1241 extern long __nullarea;
1243 extern char *_STACKTOP;
1244 /* Depending on calling conventions Watcom C either precedes
1245 or does not precedes with undescore names of C-variables.
1246 Make sure startup code variables always have the same names. */
1247 #pragma aux __nullarea "*";
1248 #pragma aux _end "*";
1249 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1250 /* confused? me too. */
1251 # define DATASTART ((ptr_t) &__nullarea)
1252 # define DATAEND ((ptr_t) &_end)
1255 # define OS_TYPE "HURD"
1256 # define STACK_GROWS_DOWN
1258 extern int __data_start[];
1259 # define DATASTART ( (ptr_t) (__data_start))
1261 # define DATAEND ( (ptr_t) (_end))
1262 /* # define MPROTECT_VDB Not quite working yet? */
1263 # define DYNAMIC_LOADING
1268 # define MACH_TYPE "NS32K"
1269 # define ALIGNMENT 4
1270 extern char **environ;
1271 # define DATASTART ((ptr_t)(&environ))
1272 /* hideous kludge: environ is the first */
1273 /* word in crt0.o, and delimits the start */
1274 /* of the data segment, no matter which */
1275 /* ld options were passed through. */
1276 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1280 # define MACH_TYPE "MIPS"
1282 /* This was developed for a linuxce style platform. Probably */
1283 /* needs to be tweaked for workstation class machines. */
1284 # define OS_TYPE "LINUX"
1285 # define DYNAMIC_LOADING
1287 # define DATAEND (_end)
1288 extern int __data_start[];
1289 # define DATASTART ((ptr_t)(__data_start))
1290 # define ALIGNMENT 4
1291 # define USE_GENERIC_PUSH_REGS
1292 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1293 # define LINUX_STACKBOTTOM
1295 # define STACKBOTTOM 0x80000000
1300 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1301 extern int _fdata[], _end[];
1302 # define DATASTART ((ptr_t)_fdata)
1303 # define DATAEND ((ptr_t)_end)
1304 # define CPP_WORDSZ _MIPS_SZPTR
1305 # define ALIGNMENT (_MIPS_SZPTR/8)
1307 extern int etext[], edata[], end[];
1308 extern int _DYNAMIC_LINKING[], _gp[];
1309 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1310 + ((word)etext & 0xffff)))
1311 # define DATAEND (edata)
1312 # define DATASTART2 (_DYNAMIC_LINKING \
1313 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1315 # define DATAEND2 (end)
1316 # define ALIGNMENT 4
1318 # define OS_TYPE "EWS4800"
1319 # define USE_GENERIC_PUSH_REGS 1
1323 # define DATASTART (ptr_t)0x10000000
1324 /* Could probably be slightly higher since */
1325 /* startup code allocates lots of stuff. */
1326 # define OS_TYPE "ULTRIX"
1327 # define ALIGNMENT 4
1331 # define DATASTART (ptr_t)0x10000000
1332 # define OS_TYPE "RISCOS"
1333 # define ALIGNMENT 4 /* Required by hardware */
1337 extern int _fdata[];
1338 # define DATASTART ((ptr_t)(_fdata))
1340 # define HEAP_START (ptr_t)0x30000000
1342 # define HEAP_START DATASTART
1344 /* Lowest plausible heap address. */
1345 /* In the MMAP case, we map there. */
1346 /* In either case it is used to identify */
1347 /* heap sections so they're not */
1348 /* considered as roots. */
1349 # define OS_TYPE "IRIX5"
1350 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1351 /* of recent breakage. */
1353 # define CPP_WORDSZ _MIPS_SZPTR
1354 # define ALIGNMENT (_MIPS_SZPTR/8)
1355 # if CPP_WORDSZ != 64
1356 # define ALIGN_DOUBLE
1359 # define ALIGNMENT 4
1360 # define ALIGN_DOUBLE
1362 # define DYNAMIC_LOADING
1365 # define OS_TYPE "MSWINCE"
1366 # define ALIGNMENT 4
1367 # define DATAEND /* not needed */
1369 # if defined(NETBSD)
1370 # define OS_TYPE "NETBSD"
1371 # define ALIGNMENT 4
1373 # define USE_GENERIC_PUSH_REGS
1376 # define DATASTART GC_data_start
1377 # define NEED_FIND_LIMIT
1378 # define DYNAMIC_LOADING
1380 # define DATASTART ((ptr_t) 0x10000000)
1381 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1387 # define MACH_TYPE "RS6000"
1392 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1395 # define ALIGNMENT 8
1396 # define CPP_WORDSZ 64
1397 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1399 # define ALIGNMENT 4
1400 # define CPP_WORDSZ 32
1401 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1403 /* From AIX linker man page:
1404 _text Specifies the first location of the program.
1405 _etext Specifies the first location after the program.
1406 _data Specifies the first location of the data.
1407 _edata Specifies the first location after the initialized data
1408 _end or end Specifies the first location after all data.
1410 extern int _data[], _end[];
1411 # define DATASTART ((ptr_t)((ulong)_data))
1412 # define DATAEND ((ptr_t)((ulong)_end))
1414 # define USE_GENERIC_PUSH_REGS
1415 # define DYNAMIC_LOADING
1416 /* For really old versions of AIX, this may have to be removed. */
1420 # define MACH_TYPE "HP_PA"
1422 # define CPP_WORDSZ 64
1423 # define ALIGNMENT 8
1425 # define CPP_WORDSZ 32
1426 # define ALIGNMENT 4
1427 # define ALIGN_DOUBLE
1429 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1430 # ifndef LINUX /* For now. */
1431 # define MPROTECT_VDB
1434 # define GENERIC_COMPARE_AND_SWAP
1435 /* No compare-and-swap instruction. Use pthread mutexes */
1436 /* when we absolutely have to. */
1437 # ifdef PARALLEL_MARK
1438 # define USE_MARK_BYTES
1439 /* Minimize compare-and-swap usage. */
1442 # define STACK_GROWS_UP
1444 # define OS_TYPE "HPUX"
1445 extern int __data_start[];
1446 # define DATASTART ((ptr_t)(__data_start))
1448 /* The following appears to work for 7xx systems running HP/UX */
1449 /* 9.xx Furthermore, it might result in much faster */
1450 /* collections than HEURISTIC2, which may involve scanning */
1451 /* segments that directly precede the stack. It is not the */
1452 /* default, since it may not work on older machine/OS */
1453 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1455 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1457 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1458 /* to this. Note that the GC must be initialized before the */
1459 /* first putenv call. */
1460 extern char ** environ;
1461 # define STACKBOTTOM ((ptr_t)environ)
1463 # define DYNAMIC_LOADING
1464 # include <unistd.h>
1465 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1467 # define PREFETCH(x) { \
1468 register long addr = (long)(x); \
1469 (void) _asm ("LDW", 0, 0, addr, 0); \
1474 # define OS_TYPE "LINUX"
1475 # define LINUX_STACKBOTTOM
1476 # define DYNAMIC_LOADING
1477 # define SEARCH_FOR_DATA_START
1479 # define DATAEND (&_end)
1484 # define MACH_TYPE "ALPHA"
1485 # define ALIGNMENT 8
1486 # define CPP_WORDSZ 64
1488 # define USE_GENERIC_PUSH_REGS
1489 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1490 /* fp registers in some cases when the target is a 21264. The assembly */
1491 /* code doesn't handle that yet, and version dependencies make that a */
1492 /* bit tricky. Do the easy thing for now. */
1495 # define OS_TYPE "NETBSD"
1497 # define DATASTART GC_data_start
1498 # define ELFCLASS32 32
1499 # define ELFCLASS64 64
1500 # define ELF_CLASS ELFCLASS64
1501 # define DYNAMIC_LOADING
1504 # define OS_TYPE "OPENBSD"
1506 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1507 # define DATASTART GC_data_start
1508 # define ELFCLASS32 32
1509 # define ELFCLASS64 64
1510 # define ELF_CLASS ELFCLASS64
1511 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1512 # define DATASTART ((ptr_t) 0x140000000)
1516 # define OS_TYPE "FREEBSD"
1517 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1518 # define SIG_SUSPEND SIGUSR1
1519 # define SIG_THR_RESTART SIGUSR2
1520 # define FREEBSD_STACKBOTTOM
1522 # define DYNAMIC_LOADING
1524 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1525 extern char etext[];
1526 extern char edata[];
1528 # define NEED_FIND_LIMIT
1529 # define DATASTART ((ptr_t)(&etext))
1530 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1531 # define DATASTART2 ((ptr_t)(&edata))
1532 # define DATAEND2 ((ptr_t)(&end))
1535 # define OS_TYPE "OSF1"
1536 # define DATASTART ((ptr_t) 0x140000000)
1538 # define DATAEND ((ptr_t) &_end)
1539 extern char ** environ;
1540 /* round up from the value of environ to the nearest page boundary */
1541 /* Probably breaks if putenv is called before collector */
1542 /* initialization. */
1543 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1544 /* # define HEURISTIC2 */
1545 /* Normally HEURISTIC2 is too conervative, since */
1546 /* the text segment immediately follows the stack. */
1547 /* Hence we give an upper pound. */
1548 /* This is currently unused, since we disabled HEURISTIC2 */
1549 extern int __start[];
1550 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1551 # ifndef GC_OSF1_THREADS
1552 /* Unresolved signal issues with threads. */
1553 # define MPROTECT_VDB
1555 # define DYNAMIC_LOADING
1558 # define OS_TYPE "LINUX"
1559 # define LINUX_STACKBOTTOM
1561 # define SEARCH_FOR_DATA_START
1562 # define DYNAMIC_LOADING
1564 # define DATASTART ((ptr_t) 0x140000000)
1567 # define DATAEND (_end)
1568 # define MPROTECT_VDB
1569 /* Has only been superficially tested. May not */
1570 /* work on all versions. */
1575 # define MACH_TYPE "IA64"
1576 # define USE_GENERIC_PUSH_REGS
1577 /* We need to get preserved registers in addition to register */
1578 /* windows. That's easiest to do with setjmp. */
1579 # ifdef PARALLEL_MARK
1580 # define USE_MARK_BYTES
1581 /* Compare-and-exchange is too expensive to use for */
1582 /* setting mark bits. */
1586 # define CPP_WORDSZ 32
1587 # define ALIGN_DOUBLE
1588 /* Requires 8 byte alignment for malloc */
1589 # define ALIGNMENT 4
1594 # define CPP_WORDSZ 64
1595 # define ALIGN_DOUBLE
1596 /* Requires 16 byte alignment for malloc */
1597 # define ALIGNMENT 8
1599 # define OS_TYPE "HPUX"
1600 extern int __data_start[];
1601 # define DATASTART ((ptr_t)(__data_start))
1602 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1603 /* to this. Note that the GC must be initialized before the */
1604 /* first putenv call. */
1605 extern char ** environ;
1606 # define STACKBOTTOM ((ptr_t)environ)
1607 # define HPUX_STACKBOTTOM
1608 # define DYNAMIC_LOADING
1609 # include <unistd.h>
1610 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1611 /* The following was empirically determined, and is probably */
1612 /* not very robust. */
1613 /* Note that the backing store base seems to be at a nice */
1614 /* address minus one page. */
1615 # define BACKING_STORE_DISPLACEMENT 0x1000000
1616 # define BACKING_STORE_ALIGNMENT 0x1000
1617 extern ptr_t GC_register_stackbottom;
1618 # define BACKING_STORE_BASE GC_register_stackbottom
1619 /* Known to be wrong for recent HP/UX versions!!! */
1622 # define CPP_WORDSZ 64
1623 # define ALIGN_DOUBLE
1624 /* Requires 16 byte alignment for malloc */
1625 # define ALIGNMENT 8
1626 # define OS_TYPE "LINUX"
1627 /* The following works on NUE and older kernels: */
1628 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1629 /* This does not work on NUE: */
1630 # define LINUX_STACKBOTTOM
1631 /* We also need the base address of the register stack */
1632 /* backing store. This is computed in */
1633 /* GC_linux_register_stack_base based on the following */
1635 # define BACKING_STORE_ALIGNMENT 0x100000
1636 # define BACKING_STORE_DISPLACEMENT 0x80000000
1637 extern ptr_t GC_register_stackbottom;
1638 # define BACKING_STORE_BASE GC_register_stackbottom
1639 # define SEARCH_FOR_DATA_START
1641 # define DYNAMIC_LOADING
1643 /* In the Intel compiler environment, we seem to end up with */
1644 /* statically linked executables and an undefined reference */
1647 # define MPROTECT_VDB
1648 /* Requires Linux 2.3.47 or later. */
1650 # define DATAEND (_end)
1652 # ifndef __INTEL_COMPILER
1653 # define PREFETCH(x) \
1654 __asm__ (" lfetch [%0]": : "r"(x))
1655 # define PREFETCH_FOR_WRITE(x) \
1656 __asm__ (" lfetch.excl [%0]": : "r"(x))
1657 # define CLEAR_DOUBLE(x) \
1658 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1660 # include <ia64intrin.h>
1661 # define PREFETCH(x) \
1662 __lfetch(__lfhint_none, (x))
1663 # define PREFETCH_FOR_WRITE(x) \
1664 __lfetch(__lfhint_nta, (x))
1665 # define CLEAR_DOUBLE(x) \
1666 __stf_spill((void *)(x), 0)
1667 # endif // __INTEL_COMPILER
1671 /* FIXME: This is a very partial guess. There is no port, yet. */
1672 # define OS_TYPE "MSWIN32"
1673 /* STACKBOTTOM and DATASTART are handled specially in */
1675 # define DATAEND /* not needed */
1676 # if defined(_WIN64)
1677 # define CPP_WORDSZ 64
1679 # define CPP_WORDSZ 32 /* Is this possible? */
1681 # define ALIGNMENT 8
1686 # define MACH_TYPE "M88K"
1687 # define ALIGNMENT 4
1688 # define ALIGN_DOUBLE
1691 # define OS_TYPE "CX_UX"
1692 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1695 # define OS_TYPE "DGUX"
1696 extern ptr_t GC_SysVGetDataStart();
1697 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1699 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1703 /* If this still works, and if anyone cares, this should probably */
1704 /* be moved to the S390 category. */
1705 # define MACH_TYPE "S370"
1706 # define ALIGNMENT 4 /* Required by hardware */
1707 # define USE_GENERIC_PUSH_REGS
1709 # define OS_TYPE "UTS4"
1711 extern int _etext[];
1713 extern ptr_t GC_SysVGetDataStart();
1714 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1715 # define DATAEND (_end)
1721 # define MACH_TYPE "S390"
1722 # define USE_GENERIC_PUSH_REGS
1724 # define ALIGNMENT 4
1725 # define CPP_WORDSZ 32
1727 # define ALIGNMENT 8
1728 # define CPP_WORDSZ 64
1729 # define HBLKSIZE 4096
1732 # define OS_TYPE "LINUX"
1733 # define LINUX_STACKBOTTOM
1734 # define DYNAMIC_LOADING
1735 extern int __data_start[];
1736 # define DATASTART ((ptr_t)(__data_start))
1738 # define DATAEND (_end)
1739 # define CACHE_LINE_SIZE 256
1740 # define GETPAGESIZE() 4096
1745 # define ALIGNMENT 4
1746 extern int _etext[];
1747 # define DATASTART ((ptr_t)(_etext))
1752 # define CPP_WORDSZ 32
1753 # define MACH_TYPE "ARM32"
1754 # define ALIGNMENT 4
1756 # define OS_TYPE "NETBSD"
1759 # define DATASTART GC_data_start
1760 # define DYNAMIC_LOADING
1762 extern char etext[];
1763 # define DATASTART ((ptr_t)(etext))
1765 # define USE_GENERIC_PUSH_REGS
1768 # define OS_TYPE "LINUX"
1771 # define STACK_GRAN 0x10000000
1772 # define USE_GENERIC_PUSH_REGS
1774 # define DYNAMIC_LOADING
1775 # include <features.h>
1776 # if defined(__GLIBC__) && __GLIBC__ >= 2
1777 # define SEARCH_FOR_DATA_START
1779 extern char **__environ;
1780 # define DATASTART ((ptr_t)(&__environ))
1781 /* hideous kludge: __environ is the first */
1782 /* word in crt0.o, and delimits the start */
1783 /* of the data segment, no matter which */
1784 /* ld options were passed through. */
1785 /* We could use _etext instead, but that */
1786 /* would include .rodata, which may */
1787 /* contain large read-only data tables */
1788 /* that we'd rather not scan. */
1791 # define DATAEND (_end)
1794 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1798 # define OS_TYPE "MSWINCE"
1799 # define DATAEND /* not needed */
1802 /* __data_start is usually defined in the target linker script. */
1803 extern int __data_start[];
1804 # define DATASTART (ptr_t)(__data_start)
1805 # define USE_GENERIC_PUSH_REGS
1806 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1807 extern void *__stack_base__;
1808 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1813 # define MACH_TYPE "CRIS"
1814 # define CPP_WORDSZ 32
1815 # define ALIGNMENT 1
1816 # define OS_TYPE "LINUX"
1817 # define DYNAMIC_LOADING
1818 # define LINUX_STACKBOTTOM
1819 # define USE_GENERIC_PUSH_REGS
1820 # define SEARCH_FOR_DATA_START
1822 # define DATAEND (_end)
1826 # define MACH_TYPE "SH"
1827 # define ALIGNMENT 4
1829 # define OS_TYPE "MSWINCE"
1830 # define DATAEND /* not needed */
1833 # define OS_TYPE "LINUX"
1834 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1835 # define USE_GENERIC_PUSH_REGS
1836 # define DYNAMIC_LOADING
1837 # define SEARCH_FOR_DATA_START
1839 # define DATAEND (_end)
1844 # define MACH_TYPE "SH4"
1845 # define OS_TYPE "MSWINCE"
1846 # define ALIGNMENT 4
1847 # define DATAEND /* not needed */
1851 # define CPP_WORDSZ 32
1852 # define MACH_TYPE "M32R"
1853 # define ALIGNMENT 4
1855 # define OS_TYPE "LINUX"
1856 # define LINUX_STACKBOTTOM
1858 # define STACK_GRAN 0x10000000
1859 # define USE_GENERIC_PUSH_REGS
1860 # define DYNAMIC_LOADING
1861 # define SEARCH_FOR_DATA_START
1863 # define DATAEND (_end)
1868 # define MACH_TYPE "X86_64"
1869 # define ALIGNMENT 8
1870 # define CPP_WORDSZ 64
1872 # define HBLKSIZE 4096
1874 # define CACHE_LINE_SIZE 64
1875 # define USE_GENERIC_PUSH_REGS
1877 # define OS_TYPE "LINUX"
1878 # define LINUX_STACKBOTTOM
1879 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1880 # define MPROTECT_VDB
1882 /* We seem to get random errors in incremental mode, */
1883 /* possibly because Linux threads is itself a malloc client */
1884 /* and can't deal with the signals. */
1887 # define DYNAMIC_LOADING
1888 # ifdef UNDEFINED /* includes ro data */
1889 extern int _etext[];
1890 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1892 # include <features.h>
1893 # define SEARCH_FOR_DATA_START
1895 # define DATAEND (_end)
1898 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1900 # if defined(__GNUC__) && __GNUC >= 3
1901 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1902 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1906 # define OS_TYPE "NETBSD"
1908 # define DYNAMIC_LOADING
1911 extern char etext[];
1912 # define SEARCH_FOR_DATA_START
1916 #if defined(LINUX) && defined(USE_MMAP)
1917 /* The kernel may do a somewhat better job merging mappings etc. */
1918 /* with anonymous mappings. */
1919 # define USE_MMAP_ANON
1922 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1923 /* Rld appears to allocate some memory with its own allocator, and */
1924 /* some through malloc, which might be redirected. To make this */
1925 /* work with collectable memory, we have to scan memory allocated */
1926 /* by rld's internal malloc. */
1927 # define USE_PROC_FOR_LIBRARIES
1930 # ifndef STACK_GROWS_UP
1931 # define STACK_GROWS_DOWN
1935 # define CPP_WORDSZ 32
1944 # define DATAEND (end)
1947 # if defined(SVR4) && !defined(GETPAGESIZE)
1948 # include <unistd.h>
1949 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1952 # ifndef GETPAGESIZE
1953 # if defined(SUNOS5) || defined(IRIX5)
1954 # include <unistd.h>
1956 # define GETPAGESIZE() getpagesize()
1959 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1960 /* OS has SVR4 generic features. Probably others also qualify. */
1964 # if defined(SUNOS5) || defined(DRSNX)
1965 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1968 /* OS has SUNOS5 style signal handlers. */
1976 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
1980 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
1981 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1982 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
1983 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
1984 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1987 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1992 # undef DYNAMIC_LOADING
1997 # undef MPROTECT_VDB
2002 /* Postponed for now. */
2004 # undef MPROTECT_VDB
2007 # ifdef SMALL_CONFIG
2008 /* Presumably not worth the space it takes. */
2010 # undef MPROTECT_VDB
2014 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2017 # ifdef PARALLEL_MARK
2018 # undef MPROTECT_VDB /* For now. */
2021 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2022 # define DEFAULT_VDB
2026 # define PREFETCH(x)
2027 # define NO_PREFETCH
2030 # ifndef PREFETCH_FOR_WRITE
2031 # define PREFETCH_FOR_WRITE(x)
2032 # define NO_PREFETCH_FOR_WRITE
2035 # ifndef CACHE_LINE_SIZE
2036 # define CACHE_LINE_SIZE 32 /* Wild guess */
2040 # define REGISTER_LIBRARIES_EARLY
2041 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2042 /* lock. This isn't safe after the world has stopped. So we must */
2043 /* call GC_register_dynamic_libraries before stopping the world. */
2044 /* For performance reasons, this may be beneficial on other */
2045 /* platforms as well, though it should be avoided in win32. */
2048 # if defined(SEARCH_FOR_DATA_START)
2049 extern ptr_t GC_data_start;
2050 # define DATASTART GC_data_start
2053 # ifndef CLEAR_DOUBLE
2054 # define CLEAR_DOUBLE(x) \
2055 ((word*)x)[0] = 0; \
2057 # endif /* CLEAR_DOUBLE */
2059 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2060 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2061 # define GC_SOLARIS_THREADS
2064 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2065 --> inconsistent configuration
2067 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2068 --> inconsistent configuration
2070 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2071 --> inconsistent configuration
2073 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2074 --> inconsistent configuration
2076 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2077 --> inconsistent configuration
2079 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2080 --> inconsistent configuration
2083 # if defined(PCR) || defined(SRC_M3) || \
2084 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2085 defined(GC_PTHREADS)
2089 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
2090 || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2091 || (defined(I386) && defined(__LCC__))
2092 /* Use setjmp based hack to mark from callee-save registers. */
2093 /* The define should move to the individual platform */
2095 # define USE_GENERIC_PUSH_REGS
2098 # if defined(MSWINCE)
2103 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2104 /* include assembly code to do it well. */
2107 /* Can we save call chain in objects for debugging? */
2108 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2109 /* frame) to reasonable values for the platform. */
2110 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2111 /* at build time, though we feel free to adjust it slightly. */
2112 /* Define NEED_CALLINFO if we either save the call stack or */
2113 /* GC_ADD_CALLER is defined. */
2114 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2117 # define CAN_SAVE_CALL_ARGS
2119 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2120 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2121 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2122 # define CAN_SAVE_CALL_ARGS
2125 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2126 && defined(GC_CAN_SAVE_CALL_STACKS)
2127 # define SAVE_CALL_CHAIN
2129 # ifdef SAVE_CALL_CHAIN
2130 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2131 # define NARGS SAVE_CALL_NARGS
2133 # define NARGS 0 /* Number of arguments to save for each call. */
2136 # ifdef SAVE_CALL_CHAIN
2137 # ifndef SAVE_CALL_COUNT
2138 # define NFRAMES 6 /* Number of frames to save. Even for */
2139 /* alignment reasons. */
2141 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2143 # define NEED_CALLINFO
2144 # endif /* SAVE_CALL_CHAIN */
2145 # ifdef GC_ADD_CALLER
2148 # define NEED_CALLINFO
2151 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2152 # define DBG_HDRS_ALL
2155 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2156 # define POINTER_SHIFT 0
2159 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2160 # define POINTER_MASK ((GC_word)(-1))
2163 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2164 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2167 # if defined(FIXUP_POINTER)
2168 # define NEED_FIXUP_POINTER 1
2170 # define NEED_FIXUP_POINTER 0
2171 # define FIXUP_POINTER(p)
2175 /* This relies on some type definitions from gc_priv.h, from */
2176 /* where it's normally included. */
2178 /* How to get heap memory from the OS: */
2179 /* Note that sbrk()-like allocation is preferred, since it */
2180 /* usually makes it possible to merge consecutively allocated */
2181 /* chunks. It also avoids unintented recursion with */
2182 /* -DREDIRECT_MALLOC. */
2183 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2184 /* 0 is taken to mean failure. */
2185 /* In the case os USE_MMAP, the argument must also be a */
2186 /* physical page size. */
2187 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2188 /* though we should perhaps take advantage of the case in which */
2190 struct hblk; /* See gc_priv.h. */
2192 char * real_malloc();
2193 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2197 void * os2_alloc(size_t bytes);
2198 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2202 # if defined(NEXT) || defined(DOS4GW) || \
2203 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2204 (defined(SUNOS5) && !defined(USE_MMAP))
2205 # define GET_MEM(bytes) HBLKPTR((size_t) \
2206 calloc(1, (size_t)bytes + GC_page_size) \
2210 extern ptr_t GC_win32_get_mem();
2211 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2214 # if defined(USE_TEMPORARY_MEMORY)
2215 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2216 Boolean clearMemory);
2217 # define GET_MEM(bytes) HBLKPTR( \
2218 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2221 # define GET_MEM(bytes) HBLKPTR( \
2222 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2226 extern ptr_t GC_wince_get_mem();
2227 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2229 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2230 extern void *GC_amiga_get_mem(size_t size);
2231 # define GET_MEM(bytes) HBLKPTR((size_t) \
2232 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2235 extern ptr_t GC_unix_get_mem();
2236 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2245 #endif /* GC_PRIVATE_H */
2247 # endif /* GCCONFIG_H */