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(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
244 # define mach_type_known
246 # if defined(LINUX) && defined(__mc68000__)
248 # define mach_type_known
250 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
252 # define mach_type_known
254 # if defined(LINUX) && defined(__arm__)
256 # define mach_type_known
258 # if defined(LINUX) && defined(__sh__)
260 # define mach_type_known
262 # if defined(LINUX) && defined(__m32r__)
264 # define mach_type_known
266 # if defined(__alpha) || defined(__alpha__)
268 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
269 # define OSF1 /* a.k.a Digital Unix */
271 # define mach_type_known
273 # if defined(_AMIGA) && !defined(AMIGA)
278 # define mach_type_known
280 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
283 # define mach_type_known
285 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
288 # define mach_type_known
290 # if defined(macosx) \
291 || defined(__APPLE__) && defined(__MACH__) && defined(__ppc__) \
292 || defined(__APPLE__) && defined(__MACH__) && defined(__ppc64__)
295 # define mach_type_known
297 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
300 --> Not really supported, but at least we recognize it.
302 # if defined(NeXT) && defined(mc68000)
305 # define mach_type_known
307 # if defined(NeXT) && (defined(i386) || defined(__i386__))
310 # define mach_type_known
312 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
315 # define mach_type_known
317 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
319 # define mach_type_known
321 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
323 # define mach_type_known
325 # if defined(__NetBSD__) && defined(__x86_64__)
327 # define mach_type_known
329 # if defined(bsdi) && (defined(i386) || defined(__i386__))
332 # define mach_type_known
334 # if !defined(mach_type_known) && defined(__386BSD__)
337 # define mach_type_known
339 # if defined(_CX_UX) && defined(_M88K)
342 # define mach_type_known
344 # if defined(DGUX) && defined(m88k)
347 # define mach_type_known
349 # if defined(_WIN32_WCE)
350 /* SH3, SH4, MIPS already defined for corresponding architectures */
351 # if defined(SH3) || defined(SH4)
361 # define mach_type_known
363 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
364 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
366 # define MSWIN32 /* or Win32s */
367 # define mach_type_known
369 # if defined(_MSC_VER) && defined(_M_IA64)
371 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
372 /* variants as a differnt platform. */
375 # if defined(__DJGPP__)
378 # define DJGPP /* MSDOS running the DJGPP port of GCC */
380 # define mach_type_known
382 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
385 # define mach_type_known
387 # if defined(__MINGW32__)
390 # define mach_type_known
392 # if defined(__BORLANDC__)
395 # define mach_type_known
397 # if defined(_UTS) && !defined(mach_type_known)
400 # define mach_type_known
404 # define mach_type_known
406 # if defined(__embedded__) && defined(PPC)
409 # define mach_type_known
412 # if defined(__WATCOMC__) && defined(__386__)
414 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
415 # if defined(__OS2__)
418 # if defined(__WINDOWS_386__) || defined(__NT__)
425 # define mach_type_known
427 # if defined(__s390__) && defined(LINUX)
429 # define mach_type_known
431 # if defined(__GNU__)
432 # if defined(__i386__)
433 /* The Debian Hurd running on generic PC */
436 # define mach_type_known
440 /* Feel free to add more clauses here */
442 /* Or manually define the machine type here. A machine type is */
443 /* characterized by the architecture. Some */
444 /* machine types are further subdivided by OS. */
445 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
446 /* Note that SGI IRIX is treated identically to RISCOS. */
447 /* SYSV on an M68K actually means A/UX. */
448 /* The distinction in these cases is usually the stack starting address */
449 # ifndef mach_type_known
450 --> unknown machine type
452 /* Mapping is: M68K ==> Motorola 680X0 */
453 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
454 /* MACOS and AMIGA variants) */
455 /* I386 ==> Intel 386 */
456 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
457 /* FREEBSD, THREE86BSD, MSWIN32, */
458 /* BSDI,SUNOS5, NEXT, other variants) */
459 /* NS32K ==> Encore Multimax */
460 /* MIPS ==> R2000 or R3000 */
461 /* (RISCOS, ULTRIX variants) */
462 /* VAX ==> DEC VAX */
463 /* (BSD, ULTRIX variants) */
464 /* RS6000 ==> IBM RS/6000 AIX3.X */
465 /* RT ==> IBM PC/RT */
466 /* HP_PA ==> HP9000/700 & /800 */
468 /* SPARC ==> SPARC v7/v8/v9 */
469 /* (SUNOS4, SUNOS5, LINUX, */
470 /* DRSNX variants) */
471 /* ALPHA ==> DEC Alpha */
472 /* (OSF1 and LINUX variants) */
473 /* M88K ==> Motorola 88XX0 */
474 /* (CX_UX and DGUX) */
475 /* S370 ==> 370-like machine */
476 /* running Amdahl UTS4 */
477 /* S390 ==> 390-like machine */
479 /* ARM32 ==> Intel StrongARM */
480 /* IA64 ==> Intel IPF */
482 /* (LINUX and HPUX) */
483 /* SH ==> Hitachi SuperH */
484 /* (LINUX & MSWINCE) */
485 /* X86_64 ==> AMD x86-64 */
486 /* POWERPC ==> IBM/Apple PowerPC */
487 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
488 /* LINUX, NETBSD, NOSYS variants) */
489 /* CRIS ==> Axis Etrax */
490 /* M32R ==> Renesas M32R */
494 * For each architecture and OS, the following need to be defined:
496 * CPP_WORD_SZ is a simple integer constant representing the word size.
497 * in bits. We assume byte addressibility, where a byte has 8 bits.
498 * We also assume CPP_WORD_SZ is either 32 or 64.
499 * (We care about the length of pointers, not hardware
500 * bus widths. Thus a 64 bit processor with a C compiler that uses
501 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
503 * MACH_TYPE is a string representation of the machine type.
504 * OS_TYPE is analogous for the OS.
506 * ALIGNMENT is the largest N, such that
507 * all pointer are guaranteed to be aligned on N byte boundaries.
508 * defining it to be 1 will always work, but perform poorly.
510 * DATASTART is the beginning of the data segment.
511 * On some platforms SEARCH_FOR_DATA_START is defined.
512 * SEARCH_FOR_DATASTART will cause GC_data_start to
513 * be set to an address determined by accessing data backwards from _end
514 * until an unmapped page is found. DATASTART will be defined to be
516 * On UNIX-like systems, the collector will scan the area between DATASTART
517 * and DATAEND for root pointers.
519 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
520 * RTH suggests gaining access to linker script synth'd values with
521 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
522 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
523 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
524 * without any special options.
526 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
529 * STACKBOTTOM is the cool end of the stack, which is usually the
530 * highest address in the stack.
531 * Under PCR or OS/2, we have other ways of finding thread stacks.
532 * For each machine, the following should:
533 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
534 * 2) define exactly one of
535 * STACKBOTTOM (should be defined to be an expression)
539 * If STACKBOTTOM is defined, then it's value will be used directly as the
540 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
541 * with a method appropriate for most Linux systems. Currently we look
542 * first for __libc_stack_end, and if that fails read it from /proc.
543 * If either of the last two macros are defined, then STACKBOTTOM is computed
544 * during collector startup using one of the following two heuristics:
545 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
546 * the next multiple of STACK_GRAN.
547 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
548 * in small steps (decrement if STACK_GROWS_UP), and read the value
549 * at each location. Remember the value when the first
550 * Segmentation violation or Bus error is signalled. Round that
551 * to the nearest plausible page boundary, and use that instead
554 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
555 * the value of environ is a pointer that can serve as STACKBOTTOM.
556 * I expect that HEURISTIC2 can be replaced by this approach, which
557 * interferes far less with debugging. However it has the disadvantage
558 * that it's confused by a putenv call before the collector is initialized.
559 * This could be dealt with by intercepting putenv ...
561 * If no expression for STACKBOTTOM can be found, and neither of the above
562 * heuristics are usable, the collector can still be used with all of the above
563 * undefined, provided one of the following is done:
564 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
565 * without reference to STACKBOTTOM. This is appropriate for use in
566 * conjunction with thread packages, since there will be multiple stacks.
567 * (Allocating thread stacks in the heap, and treating them as ordinary
568 * heap data objects is also possible as a last resort. However, this is
569 * likely to introduce significant amounts of excess storage retention
570 * unless the dead parts of the thread stacks are periodically cleared.)
571 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
572 * If the author of the client code controls the main program, this is
573 * easily accomplished by introducing a new main program, setting
574 * GC_stackbottom to the address of a local variable, and then calling
575 * the original main program. The new main program would read something
578 * # include "gc_private.h"
580 * main(argc, argv, envp)
582 * char **argv, **envp;
586 * GC_stackbottom = (ptr_t)(&dummy);
587 * return(real_main(argc, argv, envp));
591 * Each architecture may also define the style of virtual dirty bit
592 * implementation to be used:
593 * MPROTECT_VDB: Write protect the heap and catch faults.
594 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
596 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
597 * defined GC_register_dynamic_libraries() for the architecture.
599 * An architecture may define PREFETCH(x) to preload the cache with *x.
600 * This defaults to a no-op.
602 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
604 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
605 * clear the two words at GC_malloc-aligned address x. By default,
606 * word stores of 0 are used instead.
608 * HEAP_START may be defined as the initial address hint for mmap-based
612 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
613 * to push the relevant registers onto the stack. This generally makes
614 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
616 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
617 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
618 && !defined(__INTEL_COMPILER)
619 # define HAVE_BUILTIN_UNWIND_INIT
622 # define STACK_GRAN 0x1000000
624 # define MACH_TYPE "M68K"
627 # define OS_TYPE "OPENBSD"
630 # define DATASTART GC_data_start
631 # define DYNAMIC_LOADING
634 # define DATASTART ((ptr_t)(etext))
636 # define USE_GENERIC_PUSH_REGS
639 # define OS_TYPE "NETBSD"
642 # define DATASTART GC_data_start
643 # define DYNAMIC_LOADING
646 # define DATASTART ((ptr_t)(etext))
648 # define USE_GENERIC_PUSH_REGS
651 # define OS_TYPE "LINUX"
652 # define STACKBOTTOM ((ptr_t)0xf0000000)
653 # define USE_GENERIC_PUSH_REGS
655 /* We never got around to the assembly version. */
656 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
658 # define DYNAMIC_LOADING
659 # include <features.h>
660 # if defined(__GLIBC__)&& __GLIBC__>=2
661 # define SEARCH_FOR_DATA_START
663 extern char **__environ;
664 # define DATASTART ((ptr_t)(&__environ))
665 /* hideous kludge: __environ is the first */
666 /* word in crt0.o, and delimits the start */
667 /* of the data segment, no matter which */
668 /* ld options were passed through. */
669 /* We could use _etext instead, but that */
670 /* would include .rodata, which may */
671 /* contain large read-only data tables */
672 /* that we'd rather not scan. */
673 # endif /* !GLIBC2 */
675 # define DATAEND (_end)
678 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
682 # define OS_TYPE "SUNOS4"
684 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
685 # define HEURISTIC1 /* differs */
686 # define DYNAMIC_LOADING
689 # define OS_TYPE "HP"
691 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
692 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
693 /* empirically determined. seems to work. */
695 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
698 # define OS_TYPE "SYSV"
700 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
702 +((word)etext & 0x1fff))
703 /* This only works for shared-text binaries with magic number 0413.
704 The other sorts of SysV binaries put the data at the end of the text,
705 in which case the default of etext would work. Unfortunately,
706 handling both would require having the magic-number available.
709 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
710 /* The stack starts at the top of memory, but */
711 /* 0x0 cannot be used as setjump_test complains */
712 /* that the stack direction is incorrect. Two */
713 /* bytes down from 0x0 should be safe enough. */
715 # include <sys/mmu.h>
716 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
719 # define OS_TYPE "AMIGA"
720 /* STACKBOTTOM and DATASTART handled specially */
722 # define DATAEND /* not needed */
723 # define GETPAGESIZE() 4096
729 # define OS_TYPE "MACOS"
730 /* see os_dep.c for details of global data segments. */
731 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
732 # define DATAEND /* not needed */
733 # define GETPAGESIZE() 4096
736 # define OS_TYPE "NEXT"
737 # define DATASTART ((ptr_t) get_etext())
738 # define STACKBOTTOM ((ptr_t) 0x4000000)
739 # define DATAEND /* not needed */
744 # define MACH_TYPE "POWERPC"
746 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
750 # define OS_TYPE "MACOS"
751 /* see os_dep.c for details of global data segments. */
752 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
753 # define DATAEND /* not needed */
756 # if (defined (powerpc64) || defined(__powerpc64__))
758 # define CPP_WORDSZ 64
759 # define HBLKSIZE 4096
763 # define OS_TYPE "LINUX"
764 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
765 /* executable on a 64 bit kernel. */
766 # define LINUX_STACKBOTTOM
767 # define DYNAMIC_LOADING
768 # define SEARCH_FOR_DATA_START
770 # define DATAEND (_end)
773 # if (defined (__ppc64__))
775 # define CPP_WORDSZ 64
779 # define OS_TYPE "DARWIN"
780 # define DYNAMIC_LOADING
781 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
782 These aren't used when dyld support is enabled (it is by default) */
783 # define DATASTART ((ptr_t) get_etext())
784 # define DATAEND ((ptr_t) get_end())
785 # define STACKBOTTOM ((ptr_t) 0xc0000000)
787 # define USE_MMAP_ANON
788 # define USE_ASM_PUSH_REGS
789 /* This is potentially buggy. It needs more testing. See the comments in
791 # define MPROTECT_VDB
793 # define GETPAGESIZE() getpagesize()
794 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
795 /* The performance impact of prefetches is untested */
796 # define PREFETCH(x) \
797 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
798 # define PREFETCH_FOR_WRITE(x) \
799 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
801 /* There seems to be some issues with trylock hanging on darwin. This
802 should be looked into some more */
803 # define NO_PTHREAD_TRYLOCK
807 # define OS_TYPE "FREEBSD"
808 # ifndef GC_FREEBSD_THREADS
809 # define MPROTECT_VDB
811 # define SIG_SUSPEND SIGUSR1
812 # define SIG_THR_RESTART SIGUSR2
813 # define FREEBSD_STACKBOTTOM
815 # define DYNAMIC_LOADING
818 extern char * GC_FreeBSDGetDataStart();
819 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
823 # define OS_TYPE "NETBSD"
826 # define DATASTART GC_data_start
827 # define DYNAMIC_LOADING
831 # define OS_TYPE "NOSYS"
832 extern void __end[], __dso_handle[];
833 # define DATASTART (__dso_handle) /* OK, that's ugly. */
834 # define DATAEND (__end)
835 /* Stack starts at 0xE0000000 for the simulator. */
837 # define STACK_GRAN 0x10000000
843 # define MACH_TYPE "VAX"
844 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
846 # define DATASTART ((ptr_t)(etext))
848 # define OS_TYPE "BSD"
850 /* HEURISTIC2 may be OK, but it's hard to test. */
853 # define OS_TYPE "ULTRIX"
854 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
859 # define MACH_TYPE "RT"
861 # define DATASTART ((ptr_t) 0x10000000)
862 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
866 # define MACH_TYPE "SPARC"
867 # if defined(__arch64__) || defined(__sparcv9)
869 # define CPP_WORDSZ 64
870 # define ELF_CLASS ELFCLASS64
872 # define ALIGNMENT 4 /* Required by hardware */
873 # define CPP_WORDSZ 32
875 # define ALIGN_DOUBLE
877 # define OS_TYPE "SUNOS5"
880 extern ptr_t GC_SysVGetDataStart();
881 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
882 # define DATAEND (_end)
883 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
885 /* Otherwise we now use calloc. Mmap may result in the */
886 /* heap interleaved with thread stacks, which can result in */
887 /* excessive blacklisting. Sbrk is unusable since it */
888 /* doesn't interact correctly with the system malloc. */
891 # define HEAP_START (ptr_t)0x40000000
893 # define HEAP_START DATAEND
896 /* HEURISTIC1 reportedly no longer works under 2.7. */
897 /* HEURISTIC2 probably works, but this appears to be preferable. */
898 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
899 /* installations that's undefined. We work around this with a */
901 # include <sys/vmparam.h>
903 /* This should work everywhere, but doesn't. */
904 # define STACKBOTTOM USRSTACK
909 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
910 /* getpagesize() appeared to be missing from at least one */
911 /* Solaris 5.4 installation. Weird. */
912 # define DYNAMIC_LOADING
915 # define OS_TYPE "SUNOS4"
916 /* [If you have a weak stomach, don't read this.] */
917 /* We would like to use: */
918 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
919 /* This fails occasionally, due to an ancient, but very */
920 /* persistent ld bug. etext is set 32 bytes too high. */
921 /* We instead read the text segment size from the a.out */
922 /* header, which happens to be mapped into our address space */
923 /* at the start of the text segment. The detective work here */
924 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
925 /* Serpette of INRIA. */
926 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
927 # define TEXTSTART 0x2000
928 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
929 # define MPROTECT_VDB
931 # define DYNAMIC_LOADING
934 # define OS_TYPE "DRSNX"
935 extern ptr_t GC_SysVGetDataStart();
937 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
938 # define MPROTECT_VDB
939 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
940 # define DYNAMIC_LOADING
943 # define OS_TYPE "LINUX"
945 # define DYNAMIC_LOADING
947 Linux Sparc/a.out not supported
951 # define DATAEND (_end)
953 extern ptr_t GC_SysVGetDataStart();
955 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
957 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
959 # define LINUX_STACKBOTTOM
962 # define OS_TYPE "OPENBSD"
963 # define STACKBOTTOM ((ptr_t) 0xf8000000)
965 # define DATASTART ((ptr_t)(etext))
968 # define OS_TYPE "NETBSD"
971 # define DATASTART GC_data_start
972 # define DYNAMIC_LOADING
975 # define DATASTART ((ptr_t)(etext))
981 # define MACH_TYPE "I386"
982 # if defined(__LP64__) || defined(_WIN64)
983 # define CPP_WORDSZ 64
986 # define CPP_WORDSZ 32
988 /* Appears to hold for all "32 bit" compilers */
989 /* except Borland. The -a4 option fixes */
991 /* Ivan Demakov: For Watcom the option is -zp4. */
993 # ifndef SMALL_CONFIG
994 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
995 /* improvement on Pentiums. */
997 # ifdef HAVE_BUILTIN_UNWIND_INIT
998 # define USE_GENERIC_PUSH_REGS
1001 # define OS_TYPE "SEQUENT"
1003 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1004 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1007 # define OS_TYPE "BEOS"
1009 # define GETPAGESIZE() B_PAGE_SIZE
1011 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1014 # define OS_TYPE "SUNOS5"
1015 extern int _etext[], _end[];
1016 extern ptr_t GC_SysVGetDataStart();
1017 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
1018 # define DATAEND (_end)
1019 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1020 /* but reportedly breaks under 2.8. It appears that the stack */
1021 /* base is a property of the executable, so this should not break */
1022 /* old executables. */
1023 /* HEURISTIC2 probably works, but this appears to be preferable. */
1024 # include <sys/vm.h>
1025 # define STACKBOTTOM USRSTACK
1026 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1027 /* It appears to be fixed in 2.8 and 2.9. */
1028 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1031 # define DYNAMIC_LOADING
1032 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1034 /* Otherwise we now use calloc. Mmap may result in the */
1035 /* heap interleaved with thread stacks, which can result in */
1036 /* excessive blacklisting. Sbrk is unusable since it */
1037 /* doesn't interact correctly with the system malloc. */
1040 # define HEAP_START (ptr_t)0x40000000
1042 # define HEAP_START DATAEND
1046 # define OS_TYPE "SCO"
1048 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1050 +((word)etext & 0xfff))
1051 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1054 # define OS_TYPE "SCO_ELF"
1056 # define DATASTART ((ptr_t)(etext))
1057 # define STACKBOTTOM ((ptr_t) 0x08048000)
1058 # define DYNAMIC_LOADING
1059 # define ELF_CLASS ELFCLASS32
1062 # define OS_TYPE "DGUX"
1063 extern int _etext, _end;
1064 extern ptr_t GC_SysVGetDataStart();
1065 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1066 # define DATAEND (&_end)
1067 # define STACK_GROWS_DOWN
1069 # include <unistd.h>
1070 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1071 # define DYNAMIC_LOADING
1074 # endif /* USE_MMAP */
1075 # define MAP_FAILED (void *) -1
1077 # define HEAP_START (ptr_t)0x40000000
1078 # else /* USE_MMAP */
1079 # define HEAP_START DATAEND
1080 # endif /* USE_MMAP */
1085 /* The Intel compiler doesn't like inline assembly */
1086 # define USE_GENERIC_PUSH_REGS
1088 # define OS_TYPE "LINUX"
1089 # define LINUX_STACKBOTTOM
1093 # define STACK_GRAN 0x10000000
1094 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1095 /* different kernel configurations. In particular, systems */
1096 /* with 2GB physical memory will usually move the user */
1097 /* address space limit, and hence initial SP to 0x80000000. */
1099 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1100 # define MPROTECT_VDB
1102 /* We seem to get random errors in incremental mode, */
1103 /* possibly because Linux threads is itself a malloc client */
1104 /* and can't deal with the signals. */
1106 # define HEAP_START (ptr_t)0x1000
1107 /* This encourages mmap to give us low addresses, */
1108 /* thus allowing the heap to grow to ~3GB */
1110 # define DYNAMIC_LOADING
1111 # ifdef UNDEFINED /* includes ro data */
1112 extern int _etext[];
1113 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1115 # include <features.h>
1116 # if defined(__GLIBC__) && __GLIBC__ >= 2
1117 # define SEARCH_FOR_DATA_START
1119 extern char **__environ;
1120 # define DATASTART ((ptr_t)(&__environ))
1121 /* hideous kludge: __environ is the first */
1122 /* word in crt0.o, and delimits the start */
1123 /* of the data segment, no matter which */
1124 /* ld options were passed through. */
1125 /* We could use _etext instead, but that */
1126 /* would include .rodata, which may */
1127 /* contain large read-only data tables */
1128 /* that we'd rather not scan. */
1131 # define DATAEND (_end)
1134 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1136 # ifdef USE_I686_PREFETCH
1137 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1138 /* for the next rtelease. */
1139 # define PREFETCH(x) \
1140 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1141 /* Empirically prefetcht0 is much more effective at reducing */
1142 /* cache miss stalls for the targetted load instructions. But it */
1143 /* seems to interfere enough with other cache traffic that the net */
1144 /* result is worse than prefetchnta. */
1146 /* Using prefetches for write seems to have a slight negative */
1147 /* impact on performance, at least for a PIII/500. */
1148 # define PREFETCH_FOR_WRITE(x) \
1149 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1152 # ifdef USE_3DNOW_PREFETCH
1153 # define PREFETCH(x) \
1154 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1155 # define PREFETCH_FOR_WRITE(x) \
1156 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1160 # define OS_TYPE "CYGWIN32"
1161 extern int _data_start__[];
1162 extern int _data_end__[];
1163 extern int _bss_start__[];
1164 extern int _bss_end__[];
1165 /* For binutils 2.9.1, we have */
1166 /* DATASTART = _data_start__ */
1167 /* DATAEND = _bss_end__ */
1168 /* whereas for some earlier versions it was */
1169 /* DATASTART = _bss_start__ */
1170 /* DATAEND = _data_end__ */
1171 /* To get it right for both, we take the */
1172 /* minumum/maximum of the two. */
1174 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1177 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1179 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1180 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1182 # define STACK_GRAN 0x10000
1186 # define OS_TYPE "OS2"
1187 /* STACKBOTTOM and DATASTART are handled specially in */
1188 /* os_dep.c. OS2 actually has the right */
1190 # define DATAEND /* not needed */
1191 # define USE_GENERIC_PUSH_REGS
1194 # define OS_TYPE "MSWIN32"
1195 /* STACKBOTTOM and DATASTART are handled specially in */
1197 # ifndef __WATCOMC__
1198 # define MPROTECT_VDB
1200 # define DATAEND /* not needed */
1203 # define OS_TYPE "MSWINCE"
1204 # define DATAEND /* not needed */
1207 # define OS_TYPE "DJGPP"
1208 # include "stubinfo.h"
1211 extern int __djgpp_stack_limit;
1212 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1213 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1215 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1216 /* This may not be right. */
1219 # define OS_TYPE "OPENBSD"
1222 # define OS_TYPE "FREEBSD"
1223 # ifndef GC_FREEBSD_THREADS
1224 # define MPROTECT_VDB
1226 # define SIG_SUSPEND SIGUSR1
1227 # define SIG_THR_RESTART SIGUSR2
1228 # define FREEBSD_STACKBOTTOM
1230 # define DYNAMIC_LOADING
1232 extern char etext[];
1233 extern char * GC_FreeBSDGetDataStart();
1234 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1237 # define OS_TYPE "NETBSD"
1239 # define DYNAMIC_LOADING
1243 # define OS_TYPE "THREE86BSD"
1246 # define OS_TYPE "BSDI"
1248 # if defined(OPENBSD) || defined(NETBSD) \
1249 || defined(THREE86BSD) || defined(BSDI)
1251 extern char etext[];
1252 # define DATASTART ((ptr_t)(etext))
1255 # define OS_TYPE "NEXT"
1256 # define DATASTART ((ptr_t) get_etext())
1257 # define STACKBOTTOM ((ptr_t)0xc0000000)
1258 # define DATAEND /* not needed */
1261 # define OS_TYPE "DOS4GW"
1262 extern long __nullarea;
1264 extern char *_STACKTOP;
1265 /* Depending on calling conventions Watcom C either precedes
1266 or does not precedes with undescore names of C-variables.
1267 Make sure startup code variables always have the same names. */
1268 #pragma aux __nullarea "*";
1269 #pragma aux _end "*";
1270 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1271 /* confused? me too. */
1272 # define DATASTART ((ptr_t) &__nullarea)
1273 # define DATAEND ((ptr_t) &_end)
1276 # define OS_TYPE "HURD"
1277 # define STACK_GROWS_DOWN
1279 extern int __data_start[];
1280 # define DATASTART ( (ptr_t) (__data_start))
1282 # define DATAEND ( (ptr_t) (_end))
1283 /* # define MPROTECT_VDB Not quite working yet? */
1284 # define DYNAMIC_LOADING
1289 # define MACH_TYPE "NS32K"
1290 # define ALIGNMENT 4
1291 extern char **environ;
1292 # define DATASTART ((ptr_t)(&environ))
1293 /* hideous kludge: environ is the first */
1294 /* word in crt0.o, and delimits the start */
1295 /* of the data segment, no matter which */
1296 /* ld options were passed through. */
1297 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1301 # define MACH_TYPE "MIPS"
1303 /* This was developed for a linuxce style platform. Probably */
1304 /* needs to be tweaked for workstation class machines. */
1305 # define OS_TYPE "LINUX"
1306 # define DYNAMIC_LOADING
1308 # define DATAEND (_end)
1309 extern int __data_start[];
1310 # define DATASTART ((ptr_t)(__data_start))
1311 # define ALIGNMENT 4
1312 # define USE_GENERIC_PUSH_REGS
1313 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1314 # define LINUX_STACKBOTTOM
1316 # define STACKBOTTOM 0x80000000
1321 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1322 extern int _fdata[], _end[];
1323 # define DATASTART ((ptr_t)_fdata)
1324 # define DATAEND ((ptr_t)_end)
1325 # define CPP_WORDSZ _MIPS_SZPTR
1326 # define ALIGNMENT (_MIPS_SZPTR/8)
1328 extern int etext[], edata[], end[];
1329 extern int _DYNAMIC_LINKING[], _gp[];
1330 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1331 + ((word)etext & 0xffff)))
1332 # define DATAEND (edata)
1333 # define DATASTART2 (_DYNAMIC_LINKING \
1334 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1336 # define DATAEND2 (end)
1337 # define ALIGNMENT 4
1339 # define OS_TYPE "EWS4800"
1340 # define USE_GENERIC_PUSH_REGS 1
1344 # define DATASTART (ptr_t)0x10000000
1345 /* Could probably be slightly higher since */
1346 /* startup code allocates lots of stuff. */
1347 # define OS_TYPE "ULTRIX"
1348 # define ALIGNMENT 4
1352 # define DATASTART (ptr_t)0x10000000
1353 # define OS_TYPE "RISCOS"
1354 # define ALIGNMENT 4 /* Required by hardware */
1358 extern int _fdata[];
1359 # define DATASTART ((ptr_t)(_fdata))
1361 # define HEAP_START (ptr_t)0x30000000
1363 # define HEAP_START DATASTART
1365 /* Lowest plausible heap address. */
1366 /* In the MMAP case, we map there. */
1367 /* In either case it is used to identify */
1368 /* heap sections so they're not */
1369 /* considered as roots. */
1370 # define OS_TYPE "IRIX5"
1371 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1372 /* of recent breakage. */
1374 # define CPP_WORDSZ _MIPS_SZPTR
1375 # define ALIGNMENT (_MIPS_SZPTR/8)
1376 # if CPP_WORDSZ != 64
1377 # define ALIGN_DOUBLE
1380 # define ALIGNMENT 4
1381 # define ALIGN_DOUBLE
1383 # define DYNAMIC_LOADING
1386 # define OS_TYPE "MSWINCE"
1387 # define ALIGNMENT 4
1388 # define DATAEND /* not needed */
1390 # if defined(NETBSD)
1391 # define OS_TYPE "NETBSD"
1392 # define ALIGNMENT 4
1394 # define USE_GENERIC_PUSH_REGS
1397 # define DATASTART GC_data_start
1398 # define NEED_FIND_LIMIT
1399 # define DYNAMIC_LOADING
1401 # define DATASTART ((ptr_t) 0x10000000)
1402 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1408 # define MACH_TYPE "RS6000"
1413 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1416 # define ALIGNMENT 8
1417 # define CPP_WORDSZ 64
1418 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1420 # define ALIGNMENT 4
1421 # define CPP_WORDSZ 32
1422 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1424 /* From AIX linker man page:
1425 _text Specifies the first location of the program.
1426 _etext Specifies the first location after the program.
1427 _data Specifies the first location of the data.
1428 _edata Specifies the first location after the initialized data
1429 _end or end Specifies the first location after all data.
1431 extern int _data[], _end[];
1432 # define DATASTART ((ptr_t)((ulong)_data))
1433 # define DATAEND ((ptr_t)((ulong)_end))
1435 # define USE_GENERIC_PUSH_REGS
1436 # define DYNAMIC_LOADING
1437 /* For really old versions of AIX, this may have to be removed. */
1441 # define MACH_TYPE "HP_PA"
1443 # define CPP_WORDSZ 64
1444 # define ALIGNMENT 8
1446 # define CPP_WORDSZ 32
1447 # define ALIGNMENT 4
1448 # define ALIGN_DOUBLE
1450 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1451 # ifndef LINUX /* For now. */
1452 # define MPROTECT_VDB
1455 # define GENERIC_COMPARE_AND_SWAP
1456 /* No compare-and-swap instruction. Use pthread mutexes */
1457 /* when we absolutely have to. */
1458 # ifdef PARALLEL_MARK
1459 # define USE_MARK_BYTES
1460 /* Minimize compare-and-swap usage. */
1463 # define STACK_GROWS_UP
1465 # define OS_TYPE "HPUX"
1466 extern int __data_start[];
1467 # define DATASTART ((ptr_t)(__data_start))
1469 /* The following appears to work for 7xx systems running HP/UX */
1470 /* 9.xx Furthermore, it might result in much faster */
1471 /* collections than HEURISTIC2, which may involve scanning */
1472 /* segments that directly precede the stack. It is not the */
1473 /* default, since it may not work on older machine/OS */
1474 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1476 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1478 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1479 /* to this. Note that the GC must be initialized before the */
1480 /* first putenv call. */
1481 extern char ** environ;
1482 # define STACKBOTTOM ((ptr_t)environ)
1484 # define DYNAMIC_LOADING
1485 # include <unistd.h>
1486 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1488 # define PREFETCH(x) { \
1489 register long addr = (long)(x); \
1490 (void) _asm ("LDW", 0, 0, addr, 0); \
1495 # define OS_TYPE "LINUX"
1496 # define LINUX_STACKBOTTOM
1497 # define DYNAMIC_LOADING
1498 # define SEARCH_FOR_DATA_START
1500 # define DATAEND (&_end)
1505 # define MACH_TYPE "ALPHA"
1506 # define ALIGNMENT 8
1507 # define CPP_WORDSZ 64
1509 # define USE_GENERIC_PUSH_REGS
1510 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1511 /* fp registers in some cases when the target is a 21264. The assembly */
1512 /* code doesn't handle that yet, and version dependencies make that a */
1513 /* bit tricky. Do the easy thing for now. */
1516 # define OS_TYPE "NETBSD"
1518 # define DATASTART GC_data_start
1519 # define ELFCLASS32 32
1520 # define ELFCLASS64 64
1521 # define ELF_CLASS ELFCLASS64
1522 # define DYNAMIC_LOADING
1525 # define OS_TYPE "OPENBSD"
1527 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1528 # define DATASTART GC_data_start
1529 # define ELFCLASS32 32
1530 # define ELFCLASS64 64
1531 # define ELF_CLASS ELFCLASS64
1532 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1533 # define DATASTART ((ptr_t) 0x140000000)
1537 # define OS_TYPE "FREEBSD"
1538 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1539 # define SIG_SUSPEND SIGUSR1
1540 # define SIG_THR_RESTART SIGUSR2
1541 # define FREEBSD_STACKBOTTOM
1543 # define DYNAMIC_LOADING
1545 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1546 extern char etext[];
1547 extern char edata[];
1549 # define NEED_FIND_LIMIT
1550 # define DATASTART ((ptr_t)(&etext))
1551 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1552 # define DATASTART2 ((ptr_t)(&edata))
1553 # define DATAEND2 ((ptr_t)(&end))
1556 # define OS_TYPE "OSF1"
1557 # define DATASTART ((ptr_t) 0x140000000)
1559 # define DATAEND ((ptr_t) &_end)
1560 extern char ** environ;
1561 /* round up from the value of environ to the nearest page boundary */
1562 /* Probably breaks if putenv is called before collector */
1563 /* initialization. */
1564 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1565 /* # define HEURISTIC2 */
1566 /* Normally HEURISTIC2 is too conervative, since */
1567 /* the text segment immediately follows the stack. */
1568 /* Hence we give an upper pound. */
1569 /* This is currently unused, since we disabled HEURISTIC2 */
1570 extern int __start[];
1571 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1572 # ifndef GC_OSF1_THREADS
1573 /* Unresolved signal issues with threads. */
1574 # define MPROTECT_VDB
1576 # define DYNAMIC_LOADING
1579 # define OS_TYPE "LINUX"
1580 # define LINUX_STACKBOTTOM
1582 # define SEARCH_FOR_DATA_START
1583 # define DYNAMIC_LOADING
1585 # define DATASTART ((ptr_t) 0x140000000)
1588 # define DATAEND (_end)
1589 # define MPROTECT_VDB
1590 /* Has only been superficially tested. May not */
1591 /* work on all versions. */
1596 # define MACH_TYPE "IA64"
1597 # define USE_GENERIC_PUSH_REGS
1598 /* We need to get preserved registers in addition to register */
1599 /* windows. That's easiest to do with setjmp. */
1600 # ifdef PARALLEL_MARK
1601 # define USE_MARK_BYTES
1602 /* Compare-and-exchange is too expensive to use for */
1603 /* setting mark bits. */
1607 # define CPP_WORDSZ 32
1608 # define ALIGN_DOUBLE
1609 /* Requires 8 byte alignment for malloc */
1610 # define ALIGNMENT 4
1615 # define CPP_WORDSZ 64
1616 # define ALIGN_DOUBLE
1617 /* Requires 16 byte alignment for malloc */
1618 # define ALIGNMENT 8
1620 # define OS_TYPE "HPUX"
1621 extern int __data_start[];
1622 # define DATASTART ((ptr_t)(__data_start))
1623 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1624 /* to this. Note that the GC must be initialized before the */
1625 /* first putenv call. */
1626 extern char ** environ;
1627 # define STACKBOTTOM ((ptr_t)environ)
1628 # define HPUX_STACKBOTTOM
1629 # define DYNAMIC_LOADING
1630 # include <unistd.h>
1631 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1632 /* The following was empirically determined, and is probably */
1633 /* not very robust. */
1634 /* Note that the backing store base seems to be at a nice */
1635 /* address minus one page. */
1636 # define BACKING_STORE_DISPLACEMENT 0x1000000
1637 # define BACKING_STORE_ALIGNMENT 0x1000
1638 extern ptr_t GC_register_stackbottom;
1639 # define BACKING_STORE_BASE GC_register_stackbottom
1640 /* Known to be wrong for recent HP/UX versions!!! */
1643 # define CPP_WORDSZ 64
1644 # define ALIGN_DOUBLE
1645 /* Requires 16 byte alignment for malloc */
1646 # define ALIGNMENT 8
1647 # define OS_TYPE "LINUX"
1648 /* The following works on NUE and older kernels: */
1649 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1650 /* This does not work on NUE: */
1651 # define LINUX_STACKBOTTOM
1652 /* We also need the base address of the register stack */
1653 /* backing store. This is computed in */
1654 /* GC_linux_register_stack_base based on the following */
1656 # define BACKING_STORE_ALIGNMENT 0x100000
1657 # define BACKING_STORE_DISPLACEMENT 0x80000000
1658 extern ptr_t GC_register_stackbottom;
1659 # define BACKING_STORE_BASE GC_register_stackbottom
1660 # define SEARCH_FOR_DATA_START
1662 # define DYNAMIC_LOADING
1664 /* In the Intel compiler environment, we seem to end up with */
1665 /* statically linked executables and an undefined reference */
1668 # define MPROTECT_VDB
1669 /* Requires Linux 2.3.47 or later. */
1671 # define DATAEND (_end)
1673 # ifndef __INTEL_COMPILER
1674 # define PREFETCH(x) \
1675 __asm__ (" lfetch [%0]": : "r"(x))
1676 # define PREFETCH_FOR_WRITE(x) \
1677 __asm__ (" lfetch.excl [%0]": : "r"(x))
1678 # define CLEAR_DOUBLE(x) \
1679 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1681 # include <ia64intrin.h>
1682 # define PREFETCH(x) \
1683 __lfetch(__lfhint_none, (x))
1684 # define PREFETCH_FOR_WRITE(x) \
1685 __lfetch(__lfhint_nta, (x))
1686 # define CLEAR_DOUBLE(x) \
1687 __stf_spill((void *)(x), 0)
1688 # endif // __INTEL_COMPILER
1692 /* FIXME: This is a very partial guess. There is no port, yet. */
1693 # define OS_TYPE "MSWIN32"
1694 /* STACKBOTTOM and DATASTART are handled specially in */
1696 # define DATAEND /* not needed */
1697 # if defined(_WIN64)
1698 # define CPP_WORDSZ 64
1700 # define CPP_WORDSZ 32 /* Is this possible? */
1702 # define ALIGNMENT 8
1707 # define MACH_TYPE "M88K"
1708 # define ALIGNMENT 4
1709 # define ALIGN_DOUBLE
1712 # define OS_TYPE "CX_UX"
1713 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1716 # define OS_TYPE "DGUX"
1717 extern ptr_t GC_SysVGetDataStart();
1718 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1720 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1724 /* If this still works, and if anyone cares, this should probably */
1725 /* be moved to the S390 category. */
1726 # define MACH_TYPE "S370"
1727 # define ALIGNMENT 4 /* Required by hardware */
1728 # define USE_GENERIC_PUSH_REGS
1730 # define OS_TYPE "UTS4"
1732 extern int _etext[];
1734 extern ptr_t GC_SysVGetDataStart();
1735 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1736 # define DATAEND (_end)
1742 # define MACH_TYPE "S390"
1743 # define USE_GENERIC_PUSH_REGS
1745 # define ALIGNMENT 4
1746 # define CPP_WORDSZ 32
1748 # define ALIGNMENT 8
1749 # define CPP_WORDSZ 64
1750 # define HBLKSIZE 4096
1753 # define OS_TYPE "LINUX"
1754 # define LINUX_STACKBOTTOM
1755 # define DYNAMIC_LOADING
1756 extern int __data_start[];
1757 # define DATASTART ((ptr_t)(__data_start))
1759 # define DATAEND (_end)
1760 # define CACHE_LINE_SIZE 256
1761 # define GETPAGESIZE() 4096
1766 # define ALIGNMENT 4
1767 extern int _etext[];
1768 # define DATASTART ((ptr_t)(_etext))
1773 # define CPP_WORDSZ 32
1774 # define MACH_TYPE "ARM32"
1775 # define ALIGNMENT 4
1777 # define OS_TYPE "NETBSD"
1780 # define DATASTART GC_data_start
1781 # define DYNAMIC_LOADING
1783 extern char etext[];
1784 # define DATASTART ((ptr_t)(etext))
1786 # define USE_GENERIC_PUSH_REGS
1789 # define OS_TYPE "LINUX"
1790 # define LINUX_STACKBOTTOM
1792 # define STACK_GRAN 0x10000000
1793 # define USE_GENERIC_PUSH_REGS
1795 # define DYNAMIC_LOADING
1796 # include <features.h>
1797 # if defined(__GLIBC__) && __GLIBC__ >= 2
1798 # define SEARCH_FOR_DATA_START
1800 extern char **__environ;
1801 # define DATASTART ((ptr_t)(&__environ))
1802 /* hideous kludge: __environ is the first */
1803 /* word in crt0.o, and delimits the start */
1804 /* of the data segment, no matter which */
1805 /* ld options were passed through. */
1806 /* We could use _etext instead, but that */
1807 /* would include .rodata, which may */
1808 /* contain large read-only data tables */
1809 /* that we'd rather not scan. */
1812 # define DATAEND (_end)
1815 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1819 # define OS_TYPE "MSWINCE"
1820 # define DATAEND /* not needed */
1823 /* __data_start is usually defined in the target linker script. */
1824 extern int __data_start[];
1825 # define DATASTART (ptr_t)(__data_start)
1826 # define USE_GENERIC_PUSH_REGS
1827 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1828 extern void *__stack_base__;
1829 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1834 # define MACH_TYPE "CRIS"
1835 # define CPP_WORDSZ 32
1836 # define ALIGNMENT 1
1837 # define OS_TYPE "LINUX"
1838 # define DYNAMIC_LOADING
1839 # define LINUX_STACKBOTTOM
1840 # define USE_GENERIC_PUSH_REGS
1841 # define SEARCH_FOR_DATA_START
1843 # define DATAEND (_end)
1847 # define MACH_TYPE "SH"
1848 # define ALIGNMENT 4
1850 # define OS_TYPE "MSWINCE"
1851 # define DATAEND /* not needed */
1854 # define OS_TYPE "LINUX"
1855 # define LINUX_STACKBOTTOM
1856 # define USE_GENERIC_PUSH_REGS
1857 # define DYNAMIC_LOADING
1858 # define SEARCH_FOR_DATA_START
1860 # define DATAEND (_end)
1865 # define MACH_TYPE "SH4"
1866 # define OS_TYPE "MSWINCE"
1867 # define ALIGNMENT 4
1868 # define DATAEND /* not needed */
1872 # define CPP_WORDSZ 32
1873 # define MACH_TYPE "M32R"
1874 # define ALIGNMENT 4
1876 # define OS_TYPE "LINUX"
1877 # define LINUX_STACKBOTTOM
1879 # define STACK_GRAN 0x10000000
1880 # define USE_GENERIC_PUSH_REGS
1881 # define DYNAMIC_LOADING
1882 # define SEARCH_FOR_DATA_START
1884 # define DATAEND (_end)
1889 # define MACH_TYPE "X86_64"
1890 # define ALIGNMENT 8
1891 # define CPP_WORDSZ 64
1893 # define HBLKSIZE 4096
1895 # define CACHE_LINE_SIZE 64
1896 # define USE_GENERIC_PUSH_REGS
1898 # define OS_TYPE "LINUX"
1899 # define LINUX_STACKBOTTOM
1900 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1901 # define MPROTECT_VDB
1903 /* We seem to get random errors in incremental mode, */
1904 /* possibly because Linux threads is itself a malloc client */
1905 /* and can't deal with the signals. */
1908 # define DYNAMIC_LOADING
1909 # ifdef UNDEFINED /* includes ro data */
1910 extern int _etext[];
1911 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1913 # include <features.h>
1914 # define SEARCH_FOR_DATA_START
1916 # define DATAEND (_end)
1919 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1921 # if defined(__GNUC__) && __GNUC >= 3
1922 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1923 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1927 # define OS_TYPE "NETBSD"
1929 # define DYNAMIC_LOADING
1932 extern char etext[];
1933 # define SEARCH_FOR_DATA_START
1937 #if defined(LINUX) && defined(USE_MMAP)
1938 /* The kernel may do a somewhat better job merging mappings etc. */
1939 /* with anonymous mappings. */
1940 # define USE_MMAP_ANON
1943 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1944 /* Rld appears to allocate some memory with its own allocator, and */
1945 /* some through malloc, which might be redirected. To make this */
1946 /* work with collectable memory, we have to scan memory allocated */
1947 /* by rld's internal malloc. */
1948 # define USE_PROC_FOR_LIBRARIES
1951 # ifndef STACK_GROWS_UP
1952 # define STACK_GROWS_DOWN
1956 # define CPP_WORDSZ 32
1965 # define DATAEND (end)
1968 # if defined(SVR4) && !defined(GETPAGESIZE)
1969 # include <unistd.h>
1970 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1973 # ifndef GETPAGESIZE
1974 # if defined(SUNOS5) || defined(IRIX5)
1975 # include <unistd.h>
1977 # define GETPAGESIZE() getpagesize()
1980 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1981 /* OS has SVR4 generic features. Probably others also qualify. */
1985 # if defined(SUNOS5) || defined(DRSNX)
1986 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1989 /* OS has SUNOS5 style signal handlers. */
1997 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
2001 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2002 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2003 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
2004 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
2005 # define UNIX_LIKE /* Basic Unix-like system calls work. */
2008 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2013 # undef DYNAMIC_LOADING
2018 # undef MPROTECT_VDB
2023 /* Postponed for now. */
2025 # undef MPROTECT_VDB
2028 # ifdef SMALL_CONFIG
2029 /* Presumably not worth the space it takes. */
2031 # undef MPROTECT_VDB
2035 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2038 # ifdef PARALLEL_MARK
2039 # undef MPROTECT_VDB /* For now. */
2042 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2043 # define DEFAULT_VDB
2047 # define PREFETCH(x)
2048 # define NO_PREFETCH
2051 # ifndef PREFETCH_FOR_WRITE
2052 # define PREFETCH_FOR_WRITE(x)
2053 # define NO_PREFETCH_FOR_WRITE
2056 # ifndef CACHE_LINE_SIZE
2057 # define CACHE_LINE_SIZE 32 /* Wild guess */
2061 # define REGISTER_LIBRARIES_EARLY
2062 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2063 /* lock. This isn't safe after the world has stopped. So we must */
2064 /* call GC_register_dynamic_libraries before stopping the world. */
2065 /* For performance reasons, this may be beneficial on other */
2066 /* platforms as well, though it should be avoided in win32. */
2069 # if defined(SEARCH_FOR_DATA_START)
2070 extern ptr_t GC_data_start;
2071 # define DATASTART GC_data_start
2074 # ifndef CLEAR_DOUBLE
2075 # define CLEAR_DOUBLE(x) \
2076 ((word*)x)[0] = 0; \
2078 # endif /* CLEAR_DOUBLE */
2080 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2081 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2082 # define GC_SOLARIS_THREADS
2085 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2086 --> inconsistent configuration
2088 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2089 --> inconsistent configuration
2091 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2092 --> inconsistent configuration
2094 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2095 --> inconsistent configuration
2097 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2098 --> inconsistent configuration
2100 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2101 --> inconsistent configuration
2104 # if defined(PCR) || defined(SRC_M3) || \
2105 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2106 defined(GC_PTHREADS)
2110 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
2111 || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2112 || (defined(I386) && defined(__LCC__))
2113 /* Use setjmp based hack to mark from callee-save registers. */
2114 /* The define should move to the individual platform */
2116 # define USE_GENERIC_PUSH_REGS
2119 # if defined(MSWINCE)
2124 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2125 /* include assembly code to do it well. */
2128 /* Can we save call chain in objects for debugging? */
2129 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2130 /* frame) to reasonable values for the platform. */
2131 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2132 /* at build time, though we feel free to adjust it slightly. */
2133 /* Define NEED_CALLINFO if we either save the call stack or */
2134 /* GC_ADD_CALLER is defined. */
2135 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2138 # define CAN_SAVE_CALL_ARGS
2140 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2141 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2142 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2143 # define CAN_SAVE_CALL_ARGS
2146 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2147 && defined(GC_CAN_SAVE_CALL_STACKS)
2148 # define SAVE_CALL_CHAIN
2150 # ifdef SAVE_CALL_CHAIN
2151 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2152 # define NARGS SAVE_CALL_NARGS
2154 # define NARGS 0 /* Number of arguments to save for each call. */
2157 # ifdef SAVE_CALL_CHAIN
2158 # ifndef SAVE_CALL_COUNT
2159 # define NFRAMES 6 /* Number of frames to save. Even for */
2160 /* alignment reasons. */
2162 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2164 # define NEED_CALLINFO
2165 # endif /* SAVE_CALL_CHAIN */
2166 # ifdef GC_ADD_CALLER
2169 # define NEED_CALLINFO
2172 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2173 # define DBG_HDRS_ALL
2176 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2177 # define POINTER_SHIFT 0
2180 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2181 # define POINTER_MASK ((GC_word)(-1))
2184 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2185 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2188 # if defined(FIXUP_POINTER)
2189 # define NEED_FIXUP_POINTER 1
2191 # define NEED_FIXUP_POINTER 0
2192 # define FIXUP_POINTER(p)
2196 /* This relies on some type definitions from gc_priv.h, from */
2197 /* where it's normally included. */
2199 /* How to get heap memory from the OS: */
2200 /* Note that sbrk()-like allocation is preferred, since it */
2201 /* usually makes it possible to merge consecutively allocated */
2202 /* chunks. It also avoids unintented recursion with */
2203 /* -DREDIRECT_MALLOC. */
2204 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2205 /* 0 is taken to mean failure. */
2206 /* In the case os USE_MMAP, the argument must also be a */
2207 /* physical page size. */
2208 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2209 /* though we should perhaps take advantage of the case in which */
2211 struct hblk; /* See gc_priv.h. */
2213 char * real_malloc();
2214 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2218 void * os2_alloc(size_t bytes);
2219 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2223 # if defined(NEXT) || defined(DOS4GW) || \
2224 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2225 (defined(SUNOS5) && !defined(USE_MMAP))
2226 # define GET_MEM(bytes) HBLKPTR((size_t) \
2227 calloc(1, (size_t)bytes + GC_page_size) \
2231 extern ptr_t GC_win32_get_mem();
2232 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2235 # if defined(USE_TEMPORARY_MEMORY)
2236 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2237 Boolean clearMemory);
2238 # define GET_MEM(bytes) HBLKPTR( \
2239 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2242 # define GET_MEM(bytes) HBLKPTR( \
2243 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2247 extern ptr_t GC_wince_get_mem();
2248 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2250 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2251 extern void *GC_amiga_get_mem(size_t size);
2252 # define GET_MEM(bytes) HBLKPTR((size_t) \
2253 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2256 extern ptr_t GC_unix_get_mem();
2257 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2266 #endif /* GC_PRIVATE_H */
2268 # endif /* GCCONFIG_H */