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__) && !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
100 # if defined(NETBSD) && defined(__sh__)
102 # define mach_type_known
111 # define mach_type_known
113 # if defined(__NetBSD__) && defined(__vax__)
115 # define mach_type_known
117 # if defined(mips) || defined(__mips) || defined(_mips)
119 # if defined(nec_ews) || defined(_nec_ews)
122 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
123 # if defined(ultrix) || defined(__ultrix)
126 # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
127 || defined(__SYSTYPE_SVR4__)
128 # define IRIX5 /* or IRIX 6.X */
130 # define RISCOS /* or IRIX 4.X */
134 # if defined(__NetBSD__) && defined(__MIPSEL__)
137 # define mach_type_known
139 # if defined(DGUX) && (defined(i386) || defined(__i386__))
144 # define mach_type_known
146 # if defined(sequent) && (defined(i386) || defined(__i386__))
149 # define mach_type_known
151 # if defined(sun) && (defined(i386) || defined(__i386__))
154 # define mach_type_known
156 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
159 # define mach_type_known
163 # define mach_type_known
165 # if defined(sun) && (defined(sparc) || defined(__sparc))
167 /* Test for SunOS 5.x */
174 # define mach_type_known
176 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
177 && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
180 # define mach_type_known
184 # define mach_type_known
186 # if defined(__NetBSD__) && defined(__sparc__)
188 # define mach_type_known
190 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
191 /* The above test may need refinement */
193 # if defined(_SCO_ELF)
198 # define mach_type_known
200 # if defined(_AUX_SOURCE)
203 # define mach_type_known
205 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
206 || defined(hppa) || defined(__hppa__)
208 # if !defined(LINUX) && !defined(HPUX)
211 # define mach_type_known
213 # if defined(__ia64) && defined(_HPUX_SOURCE)
218 # define mach_type_known
220 # if defined(__BEOS__) && defined(_X86_)
223 # define mach_type_known
225 # if defined(LINUX) && (defined(i386) || defined(__i386__))
227 # define mach_type_known
229 # if defined(LINUX) && defined(__x86_64__)
231 # define mach_type_known
233 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
235 # define mach_type_known
237 # if defined(LINUX) && defined(__arm__)
239 # define mach_type_known
241 # if defined(LINUX) && defined(__cris__)
245 # define mach_type_known
247 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || \
248 defined(powerpc64) || defined(__powerpc64__))
250 # define mach_type_known
252 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
254 # define mach_type_known
256 # if defined(LINUX) && defined(__mc68000__)
258 # define mach_type_known
260 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
262 # define mach_type_known
264 # if defined(LINUX) && defined(__arm__)
266 # define mach_type_known
268 # if defined(LINUX) && defined(__sh__)
270 # define mach_type_known
272 # if defined(LINUX) && defined(__m32r__)
274 # define mach_type_known
276 # if defined(__alpha) || defined(__alpha__)
278 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
279 # define OSF1 /* a.k.a Digital Unix */
281 # define mach_type_known
283 # if defined(_AMIGA) && !defined(AMIGA)
288 # define mach_type_known
290 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
293 # define mach_type_known
295 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
298 # define mach_type_known
300 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
302 # if defined(__ppc__) || defined(__ppc64__)
304 # define mach_type_known
305 # elif defined(__i386__)
307 --> Not really supported, but at least we recognize it.
310 # if defined(NeXT) && defined(mc68000)
313 # define mach_type_known
315 # if defined(NeXT) && (defined(i386) || defined(__i386__))
318 # define mach_type_known
320 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
323 # define mach_type_known
325 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
327 # define mach_type_known
329 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
331 # define mach_type_known
333 # if defined(__NetBSD__) && defined(__x86_64__)
335 # define mach_type_known
337 # if defined(FREEBSD) && defined(__sparc__)
339 # define mach_type_known
341 # if defined(bsdi) && (defined(i386) || defined(__i386__))
344 # define mach_type_known
346 # if !defined(mach_type_known) && defined(__386BSD__)
349 # define mach_type_known
351 # if defined(_CX_UX) && defined(_M88K)
354 # define mach_type_known
356 # if defined(DGUX) && defined(m88k)
359 # define mach_type_known
361 # if defined(_WIN32_WCE)
362 /* SH3, SH4, MIPS already defined for corresponding architectures */
363 # if defined(SH3) || defined(SH4)
373 # define mach_type_known
375 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
376 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
378 # define MSWIN32 /* or Win32s */
379 # define mach_type_known
381 # if defined(_MSC_VER) && defined(_M_IA64)
383 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
384 /* variants as a differnt platform. */
387 # if defined(__DJGPP__)
390 # define DJGPP /* MSDOS running the DJGPP port of GCC */
392 # define mach_type_known
394 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
397 # define mach_type_known
399 # if defined(__MINGW32__)
402 # define mach_type_known
404 # if defined(__BORLANDC__)
407 # define mach_type_known
409 # if defined(_UTS) && !defined(mach_type_known)
412 # define mach_type_known
416 # define mach_type_known
418 # if defined(__embedded__) && defined(PPC)
421 # define mach_type_known
424 # if defined(__WATCOMC__) && defined(__386__)
426 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
427 # if defined(__OS2__)
430 # if defined(__WINDOWS_386__) || defined(__NT__)
437 # define mach_type_known
439 # if defined(__s390__) && defined(LINUX)
441 # define mach_type_known
443 # if defined(__GNU__)
444 # if defined(__i386__)
445 /* The Debian Hurd running on generic PC */
448 # define mach_type_known
452 /* Feel free to add more clauses here */
454 /* Or manually define the machine type here. A machine type is */
455 /* characterized by the architecture. Some */
456 /* machine types are further subdivided by OS. */
457 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
458 /* Note that SGI IRIX is treated identically to RISCOS. */
459 /* SYSV on an M68K actually means A/UX. */
460 /* The distinction in these cases is usually the stack starting address */
461 # ifndef mach_type_known
462 --> unknown machine type
464 /* Mapping is: M68K ==> Motorola 680X0 */
465 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
466 /* MACOS and AMIGA variants) */
467 /* I386 ==> Intel 386 */
468 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
469 /* FREEBSD, THREE86BSD, MSWIN32, */
470 /* BSDI,SUNOS5, NEXT, other variants) */
471 /* NS32K ==> Encore Multimax */
472 /* MIPS ==> R2000 or R3000 */
473 /* (RISCOS, ULTRIX variants) */
474 /* VAX ==> DEC VAX */
475 /* (BSD, ULTRIX variants) */
476 /* RS6000 ==> IBM RS/6000 AIX3.X */
477 /* RT ==> IBM PC/RT */
478 /* HP_PA ==> HP9000/700 & /800 */
480 /* SPARC ==> SPARC v7/v8/v9 */
481 /* (SUNOS4, SUNOS5, LINUX, */
482 /* DRSNX variants) */
483 /* ALPHA ==> DEC Alpha */
484 /* (OSF1 and LINUX variants) */
485 /* M88K ==> Motorola 88XX0 */
486 /* (CX_UX and DGUX) */
487 /* S370 ==> 370-like machine */
488 /* running Amdahl UTS4 */
489 /* S390 ==> 390-like machine */
491 /* ARM32 ==> Intel StrongARM */
492 /* IA64 ==> Intel IPF */
494 /* (LINUX and HPUX) */
495 /* SH ==> Hitachi SuperH */
496 /* (LINUX & MSWINCE) */
497 /* X86_64 ==> AMD x86-64 */
498 /* POWERPC ==> IBM/Apple PowerPC */
499 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
500 /* LINUX, NETBSD, NOSYS variants) */
501 /* Handles 32 and 64-bit variants. */
502 /* AIX should be handled here, but */
503 /* that's called an RS6000. */
504 /* CRIS ==> Axis Etrax */
505 /* M32R ==> Renesas M32R */
509 * For each architecture and OS, the following need to be defined:
511 * CPP_WORDSZ is a simple integer constant representing the word size.
512 * in bits. We assume byte addressibility, where a byte has 8 bits.
513 * We also assume CPP_WORDSZ is either 32 or 64.
514 * (We care about the length of pointers, not hardware
515 * bus widths. Thus a 64 bit processor with a C compiler that uses
516 * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
518 * MACH_TYPE is a string representation of the machine type.
519 * OS_TYPE is analogous for the OS.
521 * ALIGNMENT is the largest N, such that
522 * all pointer are guaranteed to be aligned on N byte boundaries.
523 * defining it to be 1 will always work, but perform poorly.
525 * DATASTART is the beginning of the data segment.
526 * On some platforms SEARCH_FOR_DATA_START is defined.
527 * SEARCH_FOR_DATASTART will cause GC_data_start to
528 * be set to an address determined by accessing data backwards from _end
529 * until an unmapped page is found. DATASTART will be defined to be
531 * On UNIX-like systems, the collector will scan the area between DATASTART
532 * and DATAEND for root pointers.
534 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
535 * RTH suggests gaining access to linker script synth'd values with
536 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
537 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
538 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
539 * without any special options.
541 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
544 * STACKBOTTOM is the cool end of the stack, which is usually the
545 * highest address in the stack.
546 * Under PCR or OS/2, we have other ways of finding thread stacks.
547 * For each machine, the following should:
548 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
549 * 2) define exactly one of
550 * STACKBOTTOM (should be defined to be an expression)
554 * If STACKBOTTOM is defined, then it's value will be used directly as the
555 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
556 * with a method appropriate for most Linux systems. Currently we look
557 * first for __libc_stack_end, and if that fails read it from /proc.
558 * If either of the last two macros are defined, then STACKBOTTOM is computed
559 * during collector startup using one of the following two heuristics:
560 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
561 * the next multiple of STACK_GRAN.
562 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
563 * in small steps (decrement if STACK_GROWS_UP), and read the value
564 * at each location. Remember the value when the first
565 * Segmentation violation or Bus error is signalled. Round that
566 * to the nearest plausible page boundary, and use that instead
569 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
570 * the value of environ is a pointer that can serve as STACKBOTTOM.
571 * I expect that HEURISTIC2 can be replaced by this approach, which
572 * interferes far less with debugging. However it has the disadvantage
573 * that it's confused by a putenv call before the collector is initialized.
574 * This could be dealt with by intercepting putenv ...
576 * If no expression for STACKBOTTOM can be found, and neither of the above
577 * heuristics are usable, the collector can still be used with all of the above
578 * undefined, provided one of the following is done:
579 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
580 * without reference to STACKBOTTOM. This is appropriate for use in
581 * conjunction with thread packages, since there will be multiple stacks.
582 * (Allocating thread stacks in the heap, and treating them as ordinary
583 * heap data objects is also possible as a last resort. However, this is
584 * likely to introduce significant amounts of excess storage retention
585 * unless the dead parts of the thread stacks are periodically cleared.)
586 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
587 * If the author of the client code controls the main program, this is
588 * easily accomplished by introducing a new main program, setting
589 * GC_stackbottom to the address of a local variable, and then calling
590 * the original main program. The new main program would read something
593 * # include "gc_private.h"
595 * main(argc, argv, envp)
597 * char **argv, **envp;
601 * GC_stackbottom = (ptr_t)(&dummy);
602 * return(real_main(argc, argv, envp));
606 * Each architecture may also define the style of virtual dirty bit
607 * implementation to be used:
608 * MPROTECT_VDB: Write protect the heap and catch faults.
609 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
611 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
612 * defined GC_register_dynamic_libraries() for the architecture.
614 * An architecture may define PREFETCH(x) to preload the cache with *x.
615 * This defaults to a no-op.
617 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
619 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
620 * clear the two words at GC_malloc-aligned address x. By default,
621 * word stores of 0 are used instead.
623 * HEAP_START may be defined as the initial address hint for mmap-based
627 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
628 * to push the relevant registers onto the stack. This generally makes
629 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
631 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
632 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
633 && !defined(__INTEL_COMPILER) \
634 && !defined(__PATHCC__)
635 # define HAVE_BUILTIN_UNWIND_INIT
638 # define STACK_GRAN 0x1000000
640 # define MACH_TYPE "M68K"
643 # define OS_TYPE "OPENBSD"
646 # define DATASTART GC_data_start
647 # define DYNAMIC_LOADING
650 # define DATASTART ((ptr_t)(etext))
652 # define USE_GENERIC_PUSH_REGS
655 # define OS_TYPE "NETBSD"
658 # define DATASTART GC_data_start
659 # define DYNAMIC_LOADING
662 # define DATASTART ((ptr_t)(etext))
664 # define USE_GENERIC_PUSH_REGS
667 # define OS_TYPE "LINUX"
668 # define STACKBOTTOM ((ptr_t)0xf0000000)
669 # define USE_GENERIC_PUSH_REGS
670 /* We never got around to the assembly version. */
671 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
673 # define DYNAMIC_LOADING
674 # include <features.h>
675 # if defined(__GLIBC__)&& __GLIBC__>=2
676 # define SEARCH_FOR_DATA_START
678 extern char **__environ;
679 # define DATASTART ((ptr_t)(&__environ))
680 /* hideous kludge: __environ is the first */
681 /* word in crt0.o, and delimits the start */
682 /* of the data segment, no matter which */
683 /* ld options were passed through. */
684 /* We could use _etext instead, but that */
685 /* would include .rodata, which may */
686 /* contain large read-only data tables */
687 /* that we'd rather not scan. */
688 # endif /* !GLIBC2 */
690 # define DATAEND (_end)
693 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
697 # define OS_TYPE "SUNOS4"
699 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
700 # define HEURISTIC1 /* differs */
701 # define DYNAMIC_LOADING
704 # define OS_TYPE "HP"
706 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
707 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
708 /* empirically determined. seems to work. */
710 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
713 # define OS_TYPE "SYSV"
715 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
717 +((word)etext & 0x1fff))
718 /* This only works for shared-text binaries with magic number 0413.
719 The other sorts of SysV binaries put the data at the end of the text,
720 in which case the default of etext would work. Unfortunately,
721 handling both would require having the magic-number available.
724 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
725 /* The stack starts at the top of memory, but */
726 /* 0x0 cannot be used as setjump_test complains */
727 /* that the stack direction is incorrect. Two */
728 /* bytes down from 0x0 should be safe enough. */
730 # include <sys/mmu.h>
731 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
734 # define OS_TYPE "AMIGA"
735 /* STACKBOTTOM and DATASTART handled specially */
737 # define DATAEND /* not needed */
738 # define GETPAGESIZE() 4096
744 # define OS_TYPE "MACOS"
745 /* see os_dep.c for details of global data segments. */
746 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
747 # define DATAEND /* not needed */
748 # define GETPAGESIZE() 4096
751 # define OS_TYPE "NEXT"
752 # define DATASTART ((ptr_t) get_etext())
753 # define STACKBOTTOM ((ptr_t) 0x4000000)
754 # define DATAEND /* not needed */
758 # if defined(POWERPC)
759 # define MACH_TYPE "POWERPC"
761 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
765 # define OS_TYPE "MACOS"
766 /* see os_dep.c for details of global data segments. */
767 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
768 # define DATAEND /* not needed */
771 # if defined(__powerpc64__)
773 # define CPP_WORDSZ 64
775 # define HBLKSIZE 4096
780 # define OS_TYPE "LINUX"
781 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
782 /* executable on a 64 bit kernel. */
783 # define LINUX_STACKBOTTOM
784 # define DYNAMIC_LOADING
785 # define SEARCH_FOR_DATA_START
787 # define DATAEND (_end)
792 # define CPP_WORDSZ 64
796 # define OS_TYPE "DARWIN"
797 # define DYNAMIC_LOADING
798 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
799 These aren't used when dyld support is enabled (it is by default) */
800 # define DATASTART ((ptr_t) get_etext())
801 # define DATAEND ((ptr_t) get_end())
802 # define STACKBOTTOM ((ptr_t) 0xc0000000)
804 # define USE_MMAP_ANON
805 # define USE_ASM_PUSH_REGS
806 /* This is potentially buggy. It needs more testing. See the comments in
807 os_dep.c. It relies on threads to track writes. */
808 # ifdef GC_DARWIN_THREADS
809 /* # define MPROTECT_VDB -- diabled for now. May work for some apps. */
812 # define GETPAGESIZE() getpagesize()
813 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
814 /* The performance impact of prefetches is untested */
815 # define PREFETCH(x) \
816 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
817 # define PREFETCH_FOR_WRITE(x) \
818 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
820 /* There seems to be some issues with trylock hanging on darwin. This
821 should be looked into some more */
822 # define NO_PTHREAD_TRYLOCK
826 # define OS_TYPE "FREEBSD"
827 # ifndef GC_FREEBSD_THREADS
828 # define MPROTECT_VDB
830 # define SIG_SUSPEND SIGUSR1
831 # define SIG_THR_RESTART SIGUSR2
832 # define FREEBSD_STACKBOTTOM
834 # define DYNAMIC_LOADING
837 extern char * GC_FreeBSDGetDataStart();
838 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
842 # define OS_TYPE "NETBSD"
845 # define DATASTART GC_data_start
846 # define DYNAMIC_LOADING
850 # define OS_TYPE "NOSYS"
851 extern void __end[], __dso_handle[];
852 # define DATASTART (__dso_handle) /* OK, that's ugly. */
853 # define DATAEND (__end)
854 /* Stack starts at 0xE0000000 for the simulator. */
856 # define STACK_GRAN 0x10000000
862 # define MACH_TYPE "VAX"
863 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
865 # define DATASTART ((ptr_t)(etext))
867 # define OS_TYPE "BSD"
869 /* HEURISTIC2 may be OK, but it's hard to test. */
872 # define OS_TYPE "ULTRIX"
873 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
878 # define MACH_TYPE "RT"
880 # define DATASTART ((ptr_t) 0x10000000)
881 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
885 # define MACH_TYPE "SPARC"
886 # if defined(__arch64__) || defined(__sparcv9)
888 # define CPP_WORDSZ 64
889 # define ELF_CLASS ELFCLASS64
891 # define ALIGNMENT 4 /* Required by hardware */
892 # define CPP_WORDSZ 32
894 # define ALIGN_DOUBLE
895 # ifdef _FILE_OFFSET_BITS
896 # undef _FILE_OFFSET_BITS /* libelf.h & procfs.h doesn't compile with large file support */
897 # define _FILE_OFFSET_BITS 32
900 # define OS_TYPE "SUNOS5"
903 extern ptr_t GC_SysVGetDataStart();
904 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
905 # define DATAEND (_end)
906 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
908 /* Otherwise we now use calloc. Mmap may result in the */
909 /* heap interleaved with thread stacks, which can result in */
910 /* excessive blacklisting. Sbrk is unusable since it */
911 /* doesn't interact correctly with the system malloc. */
914 # define HEAP_START (ptr_t)0x40000000
916 # define HEAP_START DATAEND
919 /* HEURISTIC1 reportedly no longer works under 2.7. */
920 /* HEURISTIC2 probably works, but this appears to be preferable. */
921 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
922 /* installations that's undefined. We work around this with a */
924 # include <sys/vmparam.h>
926 /* This should work everywhere, but doesn't. */
927 # define STACKBOTTOM USRSTACK
932 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
933 /* getpagesize() appeared to be missing from at least one */
934 /* Solaris 5.4 installation. Weird. */
935 # define DYNAMIC_LOADING
938 # define OS_TYPE "SUNOS4"
939 /* [If you have a weak stomach, don't read this.] */
940 /* We would like to use: */
941 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
942 /* This fails occasionally, due to an ancient, but very */
943 /* persistent ld bug. etext is set 32 bytes too high. */
944 /* We instead read the text segment size from the a.out */
945 /* header, which happens to be mapped into our address space */
946 /* at the start of the text segment. The detective work here */
947 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
948 /* Serpette of INRIA. */
949 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
950 # define TEXTSTART 0x2000
951 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
952 # define MPROTECT_VDB
954 # define DYNAMIC_LOADING
957 # define OS_TYPE "DRSNX"
958 extern ptr_t GC_SysVGetDataStart();
960 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
961 # define MPROTECT_VDB
962 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
963 # define DYNAMIC_LOADING
966 # define OS_TYPE "LINUX"
968 # define DYNAMIC_LOADING
970 Linux Sparc/a.out not supported
974 # define DATAEND (_end)
976 extern ptr_t GC_SysVGetDataStart();
978 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
980 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
982 # define LINUX_STACKBOTTOM
985 # define OS_TYPE "OPENBSD"
986 # define STACKBOTTOM ((ptr_t) 0xf8000000)
988 # define DATASTART ((ptr_t)(etext))
991 # define OS_TYPE "NETBSD"
994 # define DATASTART GC_data_start
995 # define DYNAMIC_LOADING
998 # define DATASTART ((ptr_t)(etext))
1002 # define OS_TYPE "FREEBSD"
1003 # define SIG_SUSPEND SIGUSR1
1004 # define SIG_THR_RESTART SIGUSR2
1005 # define FREEBSD_STACKBOTTOM
1007 # define DYNAMIC_LOADING
1009 extern char etext[];
1010 extern char edata[];
1012 # define NEED_FIND_LIMIT
1013 # define DATASTART ((ptr_t)(&etext))
1014 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1015 # define DATASTART2 ((ptr_t)(&edata))
1016 # define DATAEND2 ((ptr_t)(&end))
1021 # define MACH_TYPE "I386"
1022 # if defined(__LP64__) || defined(_WIN64)
1023 # define CPP_WORDSZ 64
1024 # define ALIGNMENT 8
1026 # define CPP_WORDSZ 32
1027 # define ALIGNMENT 4
1028 /* Appears to hold for all "32 bit" compilers */
1029 /* except Borland. The -a4 option fixes */
1031 /* Ivan Demakov: For Watcom the option is -zp4. */
1033 # ifndef SMALL_CONFIG
1034 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
1035 /* improvement on Pentiums. */
1037 # ifdef HAVE_BUILTIN_UNWIND_INIT
1038 # define USE_GENERIC_PUSH_REGS
1041 # define OS_TYPE "SEQUENT"
1043 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1044 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1047 # define OS_TYPE "BEOS"
1049 # define GETPAGESIZE() B_PAGE_SIZE
1051 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1054 # define OS_TYPE "SUNOS5"
1055 extern int _etext[], _end[];
1056 extern ptr_t GC_SysVGetDataStart();
1057 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
1058 # define DATAEND (_end)
1059 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1060 /* but reportedly breaks under 2.8. It appears that the stack */
1061 /* base is a property of the executable, so this should not break */
1062 /* old executables. */
1063 /* HEURISTIC2 probably works, but this appears to be preferable. */
1064 # include <sys/vm.h>
1065 # define STACKBOTTOM USRSTACK
1066 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1067 /* It appears to be fixed in 2.8 and 2.9. */
1068 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1069 /* Reading of dirty bits doesn't seem to work even in solaris 10 */
1070 /*# define PROC_VDB */
1072 # define DYNAMIC_LOADING
1073 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1075 /* Otherwise we now use calloc. Mmap may result in the */
1076 /* heap interleaved with thread stacks, which can result in */
1077 /* excessive blacklisting. Sbrk is unusable since it */
1078 /* doesn't interact correctly with the system malloc. */
1081 # define HEAP_START (ptr_t)0x40000000
1083 # define HEAP_START DATAEND
1087 # define OS_TYPE "SCO"
1089 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1091 +((word)etext & 0xfff))
1092 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1095 # define OS_TYPE "SCO_ELF"
1097 # define DATASTART ((ptr_t)(etext))
1098 # define STACKBOTTOM ((ptr_t) 0x08048000)
1099 # define DYNAMIC_LOADING
1100 # define ELF_CLASS ELFCLASS32
1103 # define OS_TYPE "DGUX"
1104 extern int _etext, _end;
1105 extern ptr_t GC_SysVGetDataStart();
1106 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1107 # define DATAEND (&_end)
1108 # define STACK_GROWS_DOWN
1110 # include <unistd.h>
1111 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1112 # define DYNAMIC_LOADING
1115 # endif /* USE_MMAP */
1116 # define MAP_FAILED (void *) -1
1118 # define HEAP_START (ptr_t)0x40000000
1119 # else /* USE_MMAP */
1120 # define HEAP_START DATAEND
1121 # endif /* USE_MMAP */
1126 /* The Intel compiler doesn't like inline assembly */
1127 # define USE_GENERIC_PUSH_REGS
1129 # define OS_TYPE "LINUX"
1130 # define LINUX_STACKBOTTOM
1134 # define STACK_GRAN 0x10000000
1135 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1136 /* different kernel configurations. In particular, systems */
1137 /* with 2GB physical memory will usually move the user */
1138 /* address space limit, and hence initial SP to 0x80000000. */
1140 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1141 # define MPROTECT_VDB
1143 /* We seem to get random errors in incremental mode, */
1144 /* possibly because Linux threads is itself a malloc client */
1145 /* and can't deal with the signals. */
1147 # define HEAP_START (ptr_t)0x1000
1148 /* This encourages mmap to give us low addresses, */
1149 /* thus allowing the heap to grow to ~3GB */
1151 # define DYNAMIC_LOADING
1152 # ifdef UNDEFINED /* includes ro data */
1153 extern int _etext[];
1154 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1156 # include <features.h>
1157 # if defined(__GLIBC__) && __GLIBC__ >= 2
1158 # define SEARCH_FOR_DATA_START
1160 extern char **__environ;
1161 # define DATASTART ((ptr_t)(&__environ))
1162 /* hideous kludge: __environ is the first */
1163 /* word in crt0.o, and delimits the start */
1164 /* of the data segment, no matter which */
1165 /* ld options were passed through. */
1166 /* We could use _etext instead, but that */
1167 /* would include .rodata, which may */
1168 /* contain large read-only data tables */
1169 /* that we'd rather not scan. */
1172 # define DATAEND (_end)
1175 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1177 # ifdef USE_I686_PREFETCH
1178 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1179 /* for the next rtelease. */
1180 # define PREFETCH(x) \
1181 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1182 /* Empirically prefetcht0 is much more effective at reducing */
1183 /* cache miss stalls for the targetted load instructions. But it */
1184 /* seems to interfere enough with other cache traffic that the net */
1185 /* result is worse than prefetchnta. */
1187 /* Using prefetches for write seems to have a slight negative */
1188 /* impact on performance, at least for a PIII/500. */
1189 # define PREFETCH_FOR_WRITE(x) \
1190 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1193 # ifdef USE_3DNOW_PREFETCH
1194 # define PREFETCH(x) \
1195 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1196 # define PREFETCH_FOR_WRITE(x) \
1197 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1201 # define OS_TYPE "CYGWIN32"
1202 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1203 # define DATAEND ((ptr_t)GC_DATAEND)
1205 # define STACK_GRAN 0x10000
1209 # define OS_TYPE "OS2"
1210 /* STACKBOTTOM and DATASTART are handled specially in */
1211 /* os_dep.c. OS2 actually has the right */
1213 # define DATAEND /* not needed */
1214 # define USE_GENERIC_PUSH_REGS
1217 # define OS_TYPE "MSWIN32"
1218 /* STACKBOTTOM and DATASTART are handled specially in */
1220 # ifndef __WATCOMC__
1221 # define MPROTECT_VDB
1223 # define DATAEND /* not needed */
1226 # define OS_TYPE "MSWINCE"
1227 # define DATAEND /* not needed */
1230 # define OS_TYPE "DJGPP"
1231 # include "stubinfo.h"
1234 extern int __djgpp_stack_limit;
1235 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1236 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1238 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1239 /* This may not be right. */
1242 # define OS_TYPE "OPENBSD"
1245 # define OS_TYPE "FREEBSD"
1246 # ifndef GC_FREEBSD_THREADS
1247 # define MPROTECT_VDB
1249 # define SIG_SUSPEND SIGTSTP
1250 # define SIG_THR_RESTART SIGCONT
1251 # define FREEBSD_STACKBOTTOM
1253 # define DYNAMIC_LOADING
1255 extern char etext[];
1256 extern char * GC_FreeBSDGetDataStart();
1257 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1260 # define OS_TYPE "NETBSD"
1262 # define DYNAMIC_LOADING
1266 # define OS_TYPE "THREE86BSD"
1269 # define OS_TYPE "BSDI"
1271 # if defined(OPENBSD) || defined(NETBSD) \
1272 || defined(THREE86BSD) || defined(BSDI)
1274 extern char etext[];
1275 # define DATASTART ((ptr_t)(etext))
1278 # define OS_TYPE "NEXT"
1279 # define DATASTART ((ptr_t) get_etext())
1280 # define STACKBOTTOM ((ptr_t)0xc0000000)
1281 # define DATAEND /* not needed */
1284 # define OS_TYPE "DOS4GW"
1285 extern long __nullarea;
1287 extern char *_STACKTOP;
1288 /* Depending on calling conventions Watcom C either precedes
1289 or does not precedes with undescore names of C-variables.
1290 Make sure startup code variables always have the same names. */
1291 #pragma aux __nullarea "*";
1292 #pragma aux _end "*";
1293 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1294 /* confused? me too. */
1295 # define DATASTART ((ptr_t) &__nullarea)
1296 # define DATAEND ((ptr_t) &_end)
1299 # define OS_TYPE "HURD"
1300 # define STACK_GROWS_DOWN
1302 extern int __data_start[];
1303 # define DATASTART ( (ptr_t) (__data_start))
1305 # define DATAEND ( (ptr_t) (_end))
1306 /* # define MPROTECT_VDB Not quite working yet? */
1307 # define DYNAMIC_LOADING
1312 # define MACH_TYPE "NS32K"
1313 # define ALIGNMENT 4
1314 extern char **environ;
1315 # define DATASTART ((ptr_t)(&environ))
1316 /* hideous kludge: environ is the first */
1317 /* word in crt0.o, and delimits the start */
1318 /* of the data segment, no matter which */
1319 /* ld options were passed through. */
1320 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1324 # define MACH_TYPE "MIPS"
1326 /* This was developed for a linuxce style platform. Probably */
1327 /* needs to be tweaked for workstation class machines. */
1328 # define OS_TYPE "LINUX"
1329 # define DYNAMIC_LOADING
1331 # define DATAEND (_end)
1332 extern int __data_start[];
1333 # define DATASTART ((ptr_t)(__data_start))
1334 # define ALIGNMENT 4
1335 # define USE_GENERIC_PUSH_REGS
1336 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1337 # define LINUX_STACKBOTTOM
1339 # define STACKBOTTOM 0x80000000
1344 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1345 extern int _fdata[], _end[];
1346 # define DATASTART ((ptr_t)_fdata)
1347 # define DATAEND ((ptr_t)_end)
1348 # define CPP_WORDSZ _MIPS_SZPTR
1349 # define ALIGNMENT (_MIPS_SZPTR/8)
1351 extern int etext[], edata[], end[];
1352 extern int _DYNAMIC_LINKING[], _gp[];
1353 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1354 + ((word)etext & 0xffff)))
1355 # define DATAEND (edata)
1356 # define DATASTART2 (_DYNAMIC_LINKING \
1357 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1359 # define DATAEND2 (end)
1360 # define ALIGNMENT 4
1362 # define OS_TYPE "EWS4800"
1363 # define USE_GENERIC_PUSH_REGS 1
1367 # define DATASTART (ptr_t)0x10000000
1368 /* Could probably be slightly higher since */
1369 /* startup code allocates lots of stuff. */
1370 # define OS_TYPE "ULTRIX"
1371 # define ALIGNMENT 4
1375 # define DATASTART (ptr_t)0x10000000
1376 # define OS_TYPE "RISCOS"
1377 # define ALIGNMENT 4 /* Required by hardware */
1381 extern int _fdata[];
1382 # define DATASTART ((ptr_t)(_fdata))
1384 # define HEAP_START (ptr_t)0x30000000
1386 # define HEAP_START DATASTART
1388 /* Lowest plausible heap address. */
1389 /* In the MMAP case, we map there. */
1390 /* In either case it is used to identify */
1391 /* heap sections so they're not */
1392 /* considered as roots. */
1393 # define OS_TYPE "IRIX5"
1394 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1395 /* of recent breakage. */
1397 # define CPP_WORDSZ _MIPS_SZPTR
1398 # define ALIGNMENT (_MIPS_SZPTR/8)
1399 # if CPP_WORDSZ != 64
1400 # define ALIGN_DOUBLE
1403 # define ALIGNMENT 4
1404 # define ALIGN_DOUBLE
1406 # define DYNAMIC_LOADING
1409 # define OS_TYPE "MSWINCE"
1410 # define ALIGNMENT 4
1411 # define DATAEND /* not needed */
1413 # if defined(NETBSD)
1414 # define ALIGNMENT 4
1415 # define OS_TYPE "NETBSD"
1417 # define USE_GENERIC_PUSH_REGS
1420 # define DATASTART GC_data_start
1421 # define NEED_FIND_LIMIT
1422 # define DYNAMIC_LOADING
1424 # define DATASTART ((ptr_t) 0x10000000)
1425 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1431 # define MACH_TYPE "RS6000"
1436 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1439 # define ALIGNMENT 8
1440 # define CPP_WORDSZ 64
1441 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1443 # define ALIGNMENT 4
1444 # define CPP_WORDSZ 32
1445 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1448 # define USE_MMAP_ANON
1449 /* From AIX linker man page:
1450 _text Specifies the first location of the program.
1451 _etext Specifies the first location after the program.
1452 _data Specifies the first location of the data.
1453 _edata Specifies the first location after the initialized data
1454 _end or end Specifies the first location after all data.
1456 extern int _data[], _end[];
1457 # define DATASTART ((ptr_t)((ulong)_data))
1458 # define DATAEND ((ptr_t)((ulong)_end))
1460 # define USE_GENERIC_PUSH_REGS
1461 # define DYNAMIC_LOADING
1462 /* For really old versions of AIX, this may have to be removed. */
1466 # define MACH_TYPE "HP_PA"
1468 # define CPP_WORDSZ 64
1469 # define ALIGNMENT 8
1471 # define CPP_WORDSZ 32
1472 # define ALIGNMENT 4
1473 # define ALIGN_DOUBLE
1475 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1476 # ifndef LINUX /* For now. */
1477 # define MPROTECT_VDB
1480 # define GENERIC_COMPARE_AND_SWAP
1481 /* No compare-and-swap instruction. Use pthread mutexes */
1482 /* when we absolutely have to. */
1483 # ifdef PARALLEL_MARK
1484 # define USE_MARK_BYTES
1485 /* Minimize compare-and-swap usage. */
1488 # define STACK_GROWS_UP
1490 # define OS_TYPE "HPUX"
1491 extern int __data_start[];
1492 # define DATASTART ((ptr_t)(__data_start))
1494 /* The following appears to work for 7xx systems running HP/UX */
1495 /* 9.xx Furthermore, it might result in much faster */
1496 /* collections than HEURISTIC2, which may involve scanning */
1497 /* segments that directly precede the stack. It is not the */
1498 /* default, since it may not work on older machine/OS */
1499 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1501 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1503 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1504 /* to this. Note that the GC must be initialized before the */
1505 /* first putenv call. */
1506 extern char ** environ;
1507 # define STACKBOTTOM ((ptr_t)environ)
1509 # define DYNAMIC_LOADING
1510 # include <unistd.h>
1511 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1513 # define PREFETCH(x) { \
1514 register long addr = (long)(x); \
1515 (void) _asm ("LDW", 0, 0, addr, 0); \
1520 # define OS_TYPE "LINUX"
1521 # define LINUX_STACKBOTTOM
1522 # define DYNAMIC_LOADING
1523 # define SEARCH_FOR_DATA_START
1525 # define DATAEND (&_end)
1530 # define MACH_TYPE "ALPHA"
1531 # define ALIGNMENT 8
1532 # define CPP_WORDSZ 64
1534 # define USE_GENERIC_PUSH_REGS
1535 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1536 /* fp registers in some cases when the target is a 21264. The assembly */
1537 /* code doesn't handle that yet, and version dependencies make that a */
1538 /* bit tricky. Do the easy thing for now. */
1541 # define OS_TYPE "NETBSD"
1543 # define DATASTART GC_data_start
1544 # define ELFCLASS32 32
1545 # define ELFCLASS64 64
1546 # define ELF_CLASS ELFCLASS64
1547 # define DYNAMIC_LOADING
1550 # define OS_TYPE "OPENBSD"
1552 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1553 # define DATASTART GC_data_start
1554 # define ELFCLASS32 32
1555 # define ELFCLASS64 64
1556 # define ELF_CLASS ELFCLASS64
1557 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1558 # define DATASTART ((ptr_t) 0x140000000)
1562 # define OS_TYPE "FREEBSD"
1563 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1564 # define SIG_SUSPEND SIGTSTP
1565 # define SIG_THR_RESTART SIGCONT
1566 # define FREEBSD_STACKBOTTOM
1568 # define DYNAMIC_LOADING
1570 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1571 extern char etext[];
1572 extern char edata[];
1574 # define NEED_FIND_LIMIT
1575 # define DATASTART ((ptr_t)(&etext))
1576 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1577 # define DATASTART2 ((ptr_t)(&edata))
1578 # define DATAEND2 ((ptr_t)(&end))
1581 # define OS_TYPE "OSF1"
1582 # define DATASTART ((ptr_t) 0x140000000)
1584 # define DATAEND ((ptr_t) &_end)
1585 extern char ** environ;
1586 /* round up from the value of environ to the nearest page boundary */
1587 /* Probably breaks if putenv is called before collector */
1588 /* initialization. */
1589 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1590 /* # define HEURISTIC2 */
1591 /* Normally HEURISTIC2 is too conervative, since */
1592 /* the text segment immediately follows the stack. */
1593 /* Hence we give an upper pound. */
1594 /* This is currently unused, since we disabled HEURISTIC2 */
1595 extern int __start[];
1596 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1597 # ifndef GC_OSF1_THREADS
1598 /* Unresolved signal issues with threads. */
1599 # define MPROTECT_VDB
1601 # define DYNAMIC_LOADING
1604 # define OS_TYPE "LINUX"
1605 # define LINUX_STACKBOTTOM
1607 # define SEARCH_FOR_DATA_START
1608 # define DYNAMIC_LOADING
1610 # define DATASTART ((ptr_t) 0x140000000)
1613 # define DATAEND (_end)
1614 # define MPROTECT_VDB
1615 /* Has only been superficially tested. May not */
1616 /* work on all versions. */
1621 # define MACH_TYPE "IA64"
1622 # define USE_GENERIC_PUSH_REGS
1623 /* We need to get preserved registers in addition to register */
1624 /* windows. That's easiest to do with setjmp. */
1625 # ifdef PARALLEL_MARK
1626 # define USE_MARK_BYTES
1627 /* Compare-and-exchange is too expensive to use for */
1628 /* setting mark bits. */
1632 # define CPP_WORDSZ 32
1633 # define ALIGN_DOUBLE
1634 /* Requires 8 byte alignment for malloc */
1635 # define ALIGNMENT 4
1640 # define CPP_WORDSZ 64
1641 # define ALIGN_DOUBLE
1642 /* Requires 16 byte alignment for malloc */
1643 # define ALIGNMENT 8
1645 # define OS_TYPE "HPUX"
1646 extern int __data_start[];
1647 # define DATASTART ((ptr_t)(__data_start))
1648 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1649 /* to this. Note that the GC must be initialized before the */
1650 /* first putenv call. */
1651 extern char ** environ;
1652 # define STACKBOTTOM ((ptr_t)environ)
1653 # define HPUX_STACKBOTTOM
1654 # define DYNAMIC_LOADING
1655 # include <unistd.h>
1656 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1657 /* The following was empirically determined, and is probably */
1658 /* not very robust. */
1659 /* Note that the backing store base seems to be at a nice */
1660 /* address minus one page. */
1661 # define BACKING_STORE_DISPLACEMENT 0x1000000
1662 # define BACKING_STORE_ALIGNMENT 0x1000
1663 extern ptr_t GC_register_stackbottom;
1664 # define BACKING_STORE_BASE GC_register_stackbottom
1665 /* Known to be wrong for recent HP/UX versions!!! */
1668 # define CPP_WORDSZ 64
1669 # define ALIGN_DOUBLE
1670 /* Requires 16 byte alignment for malloc */
1671 # define ALIGNMENT 8
1672 # define OS_TYPE "LINUX"
1673 /* The following works on NUE and older kernels: */
1674 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1675 /* This does not work on NUE: */
1676 # define LINUX_STACKBOTTOM
1677 /* We also need the base address of the register stack */
1678 /* backing store. This is computed in */
1679 /* GC_linux_register_stack_base based on the following */
1681 # define BACKING_STORE_ALIGNMENT 0x100000
1682 # define BACKING_STORE_DISPLACEMENT 0x80000000
1683 extern ptr_t GC_register_stackbottom;
1684 # define BACKING_STORE_BASE GC_register_stackbottom
1685 # define SEARCH_FOR_DATA_START
1687 # define DYNAMIC_LOADING
1689 /* In the Intel compiler environment, we seem to end up with */
1690 /* statically linked executables and an undefined reference */
1693 # define MPROTECT_VDB
1694 /* Requires Linux 2.3.47 or later. */
1696 # define DATAEND (_end)
1698 # ifndef __INTEL_COMPILER
1699 # define PREFETCH(x) \
1700 __asm__ (" lfetch [%0]": : "r"(x))
1701 # define PREFETCH_FOR_WRITE(x) \
1702 __asm__ (" lfetch.excl [%0]": : "r"(x))
1703 # define CLEAR_DOUBLE(x) \
1704 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1706 # include <ia64intrin.h>
1707 # define PREFETCH(x) \
1708 __lfetch(__lfhint_none, (x))
1709 # define PREFETCH_FOR_WRITE(x) \
1710 __lfetch(__lfhint_nta, (x))
1711 # define CLEAR_DOUBLE(x) \
1712 __stf_spill((void *)(x), 0)
1713 # endif // __INTEL_COMPILER
1717 /* FIXME: This is a very partial guess. There is no port, yet. */
1718 # define OS_TYPE "MSWIN32"
1719 /* STACKBOTTOM and DATASTART are handled specially in */
1721 # define DATAEND /* not needed */
1722 # if defined(_WIN64)
1723 # define CPP_WORDSZ 64
1725 # define CPP_WORDSZ 32 /* Is this possible? */
1727 # define ALIGNMENT 8
1732 # define MACH_TYPE "M88K"
1733 # define ALIGNMENT 4
1734 # define ALIGN_DOUBLE
1737 # define OS_TYPE "CX_UX"
1738 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1741 # define OS_TYPE "DGUX"
1742 extern ptr_t GC_SysVGetDataStart();
1743 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1745 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1749 /* If this still works, and if anyone cares, this should probably */
1750 /* be moved to the S390 category. */
1751 # define MACH_TYPE "S370"
1752 # define ALIGNMENT 4 /* Required by hardware */
1753 # define USE_GENERIC_PUSH_REGS
1755 # define OS_TYPE "UTS4"
1757 extern int _etext[];
1759 extern ptr_t GC_SysVGetDataStart();
1760 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1761 # define DATAEND (_end)
1767 # define MACH_TYPE "S390"
1768 # define USE_GENERIC_PUSH_REGS
1770 # define ALIGNMENT 4
1771 # define CPP_WORDSZ 32
1773 # define ALIGNMENT 8
1774 # define CPP_WORDSZ 64
1777 # define HBLKSIZE 4096
1780 # define OS_TYPE "LINUX"
1781 # define LINUX_STACKBOTTOM
1782 # define DYNAMIC_LOADING
1783 extern int __data_start[];
1784 # define DATASTART ((ptr_t)(__data_start))
1786 # define DATAEND (_end)
1787 # define CACHE_LINE_SIZE 256
1788 # define GETPAGESIZE() 4096
1793 # define ALIGNMENT 4
1794 extern int _etext[];
1795 # define DATASTART ((ptr_t)(_etext))
1800 # define CPP_WORDSZ 32
1801 # define MACH_TYPE "ARM32"
1802 # define ALIGNMENT 4
1804 # define OS_TYPE "NETBSD"
1807 # define DATASTART GC_data_start
1808 # define DYNAMIC_LOADING
1810 extern char etext[];
1811 # define DATASTART ((ptr_t)(etext))
1813 # define USE_GENERIC_PUSH_REGS
1816 # define OS_TYPE "LINUX"
1817 # define LINUX_STACKBOTTOM
1819 # define STACK_GRAN 0x10000000
1820 # define USE_GENERIC_PUSH_REGS
1822 # define DYNAMIC_LOADING
1823 # include <features.h>
1824 # if defined(__GLIBC__) && __GLIBC__ >= 2
1825 # define SEARCH_FOR_DATA_START
1827 extern char **__environ;
1828 # define DATASTART ((ptr_t)(&__environ))
1829 /* hideous kludge: __environ is the first */
1830 /* word in crt0.o, and delimits the start */
1831 /* of the data segment, no matter which */
1832 /* ld options were passed through. */
1833 /* We could use _etext instead, but that */
1834 /* would include .rodata, which may */
1835 /* contain large read-only data tables */
1836 /* that we'd rather not scan. */
1839 # define DATAEND (_end)
1842 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1846 # define OS_TYPE "MSWINCE"
1847 # define DATAEND /* not needed */
1850 /* __data_start is usually defined in the target linker script. */
1851 extern int __data_start[];
1852 # define DATASTART (ptr_t)(__data_start)
1853 # define USE_GENERIC_PUSH_REGS
1854 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1855 extern void *__stack_base__;
1856 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1861 # define MACH_TYPE "CRIS"
1862 # define CPP_WORDSZ 32
1863 # define ALIGNMENT 1
1864 # define OS_TYPE "LINUX"
1865 # define DYNAMIC_LOADING
1866 # define LINUX_STACKBOTTOM
1867 # define USE_GENERIC_PUSH_REGS
1868 # define SEARCH_FOR_DATA_START
1870 # define DATAEND (_end)
1874 # define MACH_TYPE "SH"
1875 # define ALIGNMENT 4
1877 # define OS_TYPE "MSWINCE"
1878 # define DATAEND /* not needed */
1881 # define OS_TYPE "LINUX"
1882 # define LINUX_STACKBOTTOM
1883 # define USE_GENERIC_PUSH_REGS
1884 # define DYNAMIC_LOADING
1885 # define SEARCH_FOR_DATA_START
1887 # define DATAEND (_end)
1890 # define OS_TYPE "NETBSD"
1892 # define DATASTART GC_data_start
1893 # define USE_GENERIC_PUSH_REGS
1894 # define DYNAMIC_LOADING
1899 # define MACH_TYPE "SH4"
1900 # define OS_TYPE "MSWINCE"
1901 # define ALIGNMENT 4
1902 # define DATAEND /* not needed */
1906 # define CPP_WORDSZ 32
1907 # define MACH_TYPE "M32R"
1908 # define ALIGNMENT 4
1910 # define OS_TYPE "LINUX"
1911 # define LINUX_STACKBOTTOM
1913 # define STACK_GRAN 0x10000000
1914 # define USE_GENERIC_PUSH_REGS
1915 # define DYNAMIC_LOADING
1916 # define SEARCH_FOR_DATA_START
1918 # define DATAEND (_end)
1923 # define MACH_TYPE "X86_64"
1924 # define ALIGNMENT 8
1925 # define CPP_WORDSZ 64
1927 # define HBLKSIZE 4096
1929 # define CACHE_LINE_SIZE 64
1930 # define USE_GENERIC_PUSH_REGS
1932 # define OS_TYPE "LINUX"
1933 # define LINUX_STACKBOTTOM
1935 # define FALLBACK_TO_MMAP
1937 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1938 # define MPROTECT_VDB
1940 /* We seem to get random errors in incremental mode, */
1941 /* possibly because Linux threads is itself a malloc client */
1942 /* and can't deal with the signals. */
1945 # define DYNAMIC_LOADING
1946 # ifdef UNDEFINED /* includes ro data */
1947 extern int _etext[];
1948 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1950 # include <features.h>
1951 # define SEARCH_FOR_DATA_START
1953 # define DATAEND (_end)
1956 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1958 # if defined(__GNUC__) && __GNUC >= 3
1959 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1960 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1964 # define OS_TYPE "NETBSD"
1966 # define DYNAMIC_LOADING
1969 extern char etext[];
1970 # define SEARCH_FOR_DATA_START
1974 #if defined(LINUX) && defined(USE_MMAP)
1975 /* The kernel may do a somewhat better job merging mappings etc. */
1976 /* with anonymous mappings. */
1977 # define USE_MMAP_ANON
1980 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1981 /* Rld appears to allocate some memory with its own allocator, and */
1982 /* some through malloc, which might be redirected. To make this */
1983 /* work with collectable memory, we have to scan memory allocated */
1984 /* by rld's internal malloc. */
1985 # define USE_PROC_FOR_LIBRARIES
1988 # ifndef STACK_GROWS_UP
1989 # define STACK_GROWS_DOWN
1993 # define CPP_WORDSZ 32
2002 # define DATAEND (end)
2005 # if defined(SVR4) && !defined(GETPAGESIZE)
2006 # include <unistd.h>
2007 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
2010 # ifndef GETPAGESIZE
2011 # if defined(SUNOS5) || defined(IRIX5)
2012 # include <unistd.h>
2014 # define GETPAGESIZE() getpagesize()
2017 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
2018 /* OS has SVR4 generic features. Probably others also qualify. */
2022 # if defined(SUNOS5) || defined(DRSNX)
2023 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
2026 /* OS has SUNOS5 style signal handlers. */
2034 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
2038 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2039 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2040 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
2041 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
2042 # define UNIX_LIKE /* Basic Unix-like system calls work. */
2045 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2050 # undef DYNAMIC_LOADING
2055 # undef MPROTECT_VDB
2060 /* Postponed for now. */
2062 # undef MPROTECT_VDB
2065 # ifdef SMALL_CONFIG
2066 /* Presumably not worth the space it takes. */
2068 # undef MPROTECT_VDB
2072 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2075 # ifdef PARALLEL_MARK
2076 # undef MPROTECT_VDB /* For now. */
2079 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2080 # define DEFAULT_VDB
2084 # define PREFETCH(x)
2085 # define NO_PREFETCH
2088 # ifndef PREFETCH_FOR_WRITE
2089 # define PREFETCH_FOR_WRITE(x)
2090 # define NO_PREFETCH_FOR_WRITE
2093 # ifndef CACHE_LINE_SIZE
2094 # define CACHE_LINE_SIZE 32 /* Wild guess */
2098 # define REGISTER_LIBRARIES_EARLY
2099 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2100 /* lock. This isn't safe after the world has stopped. So we must */
2101 /* call GC_register_dynamic_libraries before stopping the world. */
2102 /* For performance reasons, this may be beneficial on other */
2103 /* platforms as well, though it should be avoided in win32. */
2106 # if defined(SEARCH_FOR_DATA_START)
2107 extern ptr_t GC_data_start;
2108 # define DATASTART GC_data_start
2111 # ifndef CLEAR_DOUBLE
2112 # define CLEAR_DOUBLE(x) \
2113 ((word*)x)[0] = 0; \
2115 # endif /* CLEAR_DOUBLE */
2117 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2118 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2119 # define GC_SOLARIS_THREADS
2122 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2123 --> inconsistent configuration
2125 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2126 --> inconsistent configuration
2128 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2129 --> inconsistent configuration
2131 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2132 --> inconsistent configuration
2134 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2135 --> inconsistent configuration
2137 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2138 --> inconsistent configuration
2141 # if defined(PCR) || defined(SRC_M3) || \
2142 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2143 defined(GC_PTHREADS)
2147 # if defined(HP_PA) || defined(M88K) \
2148 || defined(POWERPC) && !defined(DARWIN) \
2149 || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2150 || (defined(I386) && defined(__LCC__))
2151 /* Use setjmp based hack to mark from callee-save registers. */
2152 /* The define should move to the individual platform */
2154 # define USE_GENERIC_PUSH_REGS
2157 # if defined(MSWINCE)
2162 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2163 /* include assembly code to do it well. */
2166 /* Can we save call chain in objects for debugging? */
2167 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2168 /* frame) to reasonable values for the platform. */
2169 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2170 /* at build time, though we feel free to adjust it slightly. */
2171 /* Define NEED_CALLINFO if we either save the call stack or */
2172 /* GC_ADD_CALLER is defined. */
2173 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2176 # define CAN_SAVE_CALL_ARGS
2178 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2179 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2180 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2181 # define CAN_SAVE_CALL_ARGS
2184 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2185 && defined(GC_CAN_SAVE_CALL_STACKS)
2186 # define SAVE_CALL_CHAIN
2188 # ifdef SAVE_CALL_CHAIN
2189 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2190 # define NARGS SAVE_CALL_NARGS
2192 # define NARGS 0 /* Number of arguments to save for each call. */
2195 # ifdef SAVE_CALL_CHAIN
2196 # ifndef SAVE_CALL_COUNT
2197 # define NFRAMES 6 /* Number of frames to save. Even for */
2198 /* alignment reasons. */
2200 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2202 # define NEED_CALLINFO
2203 # endif /* SAVE_CALL_CHAIN */
2204 # ifdef GC_ADD_CALLER
2207 # define NEED_CALLINFO
2210 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2211 # define DBG_HDRS_ALL
2214 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2215 # define POINTER_SHIFT 0
2218 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2219 # define POINTER_MASK ((GC_word)(-1))
2222 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2223 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2226 # if defined(FIXUP_POINTER)
2227 # define NEED_FIXUP_POINTER 1
2229 # define NEED_FIXUP_POINTER 0
2230 # define FIXUP_POINTER(p)
2234 /* This relies on some type definitions from gc_priv.h, from */
2235 /* where it's normally included. */
2237 /* How to get heap memory from the OS: */
2238 /* Note that sbrk()-like allocation is preferred, since it */
2239 /* usually makes it possible to merge consecutively allocated */
2240 /* chunks. It also avoids unintented recursion with */
2241 /* -DREDIRECT_MALLOC. */
2242 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2243 /* 0 is taken to mean failure. */
2244 /* In the case os USE_MMAP, the argument must also be a */
2245 /* physical page size. */
2246 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2247 /* though we should perhaps take advantage of the case in which */
2249 struct hblk; /* See gc_priv.h. */
2251 char * real_malloc();
2252 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2256 void * os2_alloc(size_t bytes);
2257 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2261 # if defined(NEXT) || defined(DOS4GW) || \
2262 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2263 (defined(SUNOS5) && !defined(USE_MMAP))
2264 # define GET_MEM(bytes) HBLKPTR((size_t) \
2265 calloc(1, (size_t)bytes + GC_page_size) \
2269 extern ptr_t GC_win32_get_mem();
2270 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2273 # if defined(USE_TEMPORARY_MEMORY)
2274 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2275 Boolean clearMemory);
2276 # define GET_MEM(bytes) HBLKPTR( \
2277 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2280 # define GET_MEM(bytes) HBLKPTR( \
2281 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2285 extern ptr_t GC_wince_get_mem();
2286 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2288 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2289 extern void *GC_amiga_get_mem(size_t size);
2290 # define GET_MEM(bytes) HBLKPTR((size_t) \
2291 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2294 extern ptr_t GC_unix_get_mem();
2295 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2304 #endif /* GC_PRIVATE_H */
2306 #if defined(_AIX) && !defined(__GNUC__) && !defined(__STDC__)
2307 /* IBMs xlc compiler doesn't appear to follow the convention of */
2308 /* defining __STDC__ to be zero in extended mode. */
2312 # endif /* GCCONFIG_H */