2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
5 * Copyright (c) 2000-2004 Hewlett-Packard Development Company, L.P.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
18 * This header is private to the gc. It is almost always included from
19 * gc_priv.h. However it is possible to include it by itself if just the
20 * configuration macros are needed. In that
21 * case, a few declarations relying on types declared in gc_priv.h will be
30 /* Fake ptr_t declaration, just to avoid compilation errors. */
31 /* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
32 typedef struct GC_undefined_struct * ptr_t;
35 /* Machine dependent parameters. Some tuning parameters can be found */
36 /* near the top of gc_private.h. */
38 /* Machine specific parts contributed by various people. See README file. */
40 /* First a unified test for Linux: */
41 # if defined(linux) || defined(__linux__)
47 /* And one for NetBSD: */
48 # if defined(__NetBSD__)
52 /* And one for OpenBSD: */
53 # if defined(__OpenBSD__)
57 /* And one for FreeBSD: */
58 # if defined(__FreeBSD__)
62 /* Determine the machine type: */
63 # if defined(__arm__) || defined(__thumb__)
65 # if !defined(LINUX) && !defined(NETBSD)
67 # define mach_type_known
70 # if defined(sun) && defined(mc68000)
73 # define mach_type_known
75 # if defined(hp9000s300)
78 # define mach_type_known
80 # if defined(OPENBSD) && defined(m68k)
82 # define mach_type_known
84 # if defined(OPENBSD) && defined(__sparc__)
86 # define mach_type_known
88 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
90 # define mach_type_known
92 # if defined(NETBSD) && defined(__powerpc__)
94 # define mach_type_known
96 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
98 # define mach_type_known
107 # define mach_type_known
109 # if defined(__NetBSD__) && defined(__vax__)
111 # define mach_type_known
113 # if defined(mips) || defined(__mips) || defined(_mips)
115 # if defined(nec_ews) || defined(_nec_ews)
118 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
119 # if defined(ultrix) || defined(__ultrix)
122 # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
123 || defined(__SYSTYPE_SVR4__)
124 # define IRIX5 /* or IRIX 6.X */
126 # define RISCOS /* or IRIX 4.X */
130 # define mach_type_known
132 # if defined(DGUX) && (defined(i386) || defined(__i386__))
137 # define mach_type_known
139 # if defined(sequent) && (defined(i386) || defined(__i386__))
142 # define mach_type_known
144 # if defined(sun) && (defined(i386) || defined(__i386__))
147 # define mach_type_known
149 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
152 # define mach_type_known
156 # define mach_type_known
158 # if defined(sun) && (defined(sparc) || defined(__sparc))
160 /* Test for SunOS 5.x */
167 # define mach_type_known
169 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
170 && !defined(__OpenBSD__) && !(__NetBSD__)
173 # define mach_type_known
177 # define mach_type_known
179 # if defined(__NetBSD__) && defined(__sparc__)
181 # define mach_type_known
183 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
184 /* The above test may need refinement */
186 # if defined(_SCO_ELF)
191 # define mach_type_known
193 # if defined(_AUX_SOURCE)
196 # define mach_type_known
198 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
199 || defined(hppa) || defined(__hppa__)
204 # define mach_type_known
206 # if defined(__ia64) && defined(_HPUX_SOURCE)
209 # define mach_type_known
211 # if defined(__BEOS__) && defined(_X86_)
214 # define mach_type_known
216 # if defined(LINUX) && (defined(i386) || defined(__i386__))
218 # define mach_type_known
220 # if defined(LINUX) && defined(__x86_64__)
222 # define mach_type_known
224 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
226 # define mach_type_known
228 # if defined(LINUX) && defined(__arm__)
230 # define mach_type_known
232 # if defined(LINUX) && defined(__cris__)
236 # define mach_type_known
238 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || defined(powerpc64) || defined(__powerpc64__))
240 # define mach_type_known
242 # if defined(LINUX) && defined(__mc68000__)
244 # define mach_type_known
246 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
248 # define mach_type_known
250 # if defined(LINUX) && defined(__arm__)
252 # define mach_type_known
254 # if defined(LINUX) && defined(__sh__)
256 # define mach_type_known
258 # if defined(LINUX) && defined(__m32r__)
260 # define mach_type_known
262 # if defined(__alpha) || defined(__alpha__)
264 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
265 # define OSF1 /* a.k.a Digital Unix */
267 # define mach_type_known
269 # if defined(_AMIGA) && !defined(AMIGA)
274 # define mach_type_known
276 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
279 # define mach_type_known
281 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
284 # define mach_type_known
286 # if defined(macosx) \
287 || defined(__APPLE__) && defined(__MACH__) && defined(__ppc__) \
288 || defined(__APPLE__) && defined(__MACH__) && defined(__ppc64__)
291 # define mach_type_known
293 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
296 --> Not really supported, but at least we recognize it.
298 # if defined(NeXT) && defined(mc68000)
301 # define mach_type_known
303 # if defined(NeXT) && (defined(i386) || defined(__i386__))
306 # define mach_type_known
308 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
311 # define mach_type_known
313 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
315 # define mach_type_known
317 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
319 # define mach_type_known
321 # if defined(__NetBSD__) && defined(__x86_64__)
323 # define mach_type_known
325 # if defined(bsdi) && (defined(i386) || defined(__i386__))
328 # define mach_type_known
330 # if !defined(mach_type_known) && defined(__386BSD__)
333 # define mach_type_known
335 # if defined(_CX_UX) && defined(_M88K)
338 # define mach_type_known
340 # if defined(DGUX) && defined(m88k)
343 # define mach_type_known
345 # if defined(_WIN32_WCE)
346 /* SH3, SH4, MIPS already defined for corresponding architectures */
347 # if defined(SH3) || defined(SH4)
357 # define mach_type_known
359 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
360 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
362 # define MSWIN32 /* or Win32s */
363 # define mach_type_known
365 # if defined(_MSC_VER) && defined(_M_IA64)
367 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
368 /* variants as a differnt platform. */
371 # if defined(__DJGPP__)
374 # define DJGPP /* MSDOS running the DJGPP port of GCC */
376 # define mach_type_known
378 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
381 # define mach_type_known
383 # if defined(__MINGW32__)
386 # define mach_type_known
388 # if defined(__BORLANDC__)
391 # define mach_type_known
393 # if defined(_UTS) && !defined(mach_type_known)
396 # define mach_type_known
400 # define mach_type_known
402 # if defined(__embedded__) && defined(PPC)
405 # define mach_type_known
408 # if defined(__WATCOMC__) && defined(__386__)
410 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
411 # if defined(__OS2__)
414 # if defined(__WINDOWS_386__) || defined(__NT__)
421 # define mach_type_known
423 # if defined(__s390__) && defined(LINUX)
425 # define mach_type_known
427 # if defined(__GNU__)
428 # if defined(__i386__)
429 /* The Debian Hurd running on generic PC */
432 # define mach_type_known
436 /* Feel free to add more clauses here */
438 /* Or manually define the machine type here. A machine type is */
439 /* characterized by the architecture. Some */
440 /* machine types are further subdivided by OS. */
441 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
442 /* Note that SGI IRIX is treated identically to RISCOS. */
443 /* SYSV on an M68K actually means A/UX. */
444 /* The distinction in these cases is usually the stack starting address */
445 # ifndef mach_type_known
446 --> unknown machine type
448 /* Mapping is: M68K ==> Motorola 680X0 */
449 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
450 /* MACOS and AMIGA variants) */
451 /* I386 ==> Intel 386 */
452 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
453 /* FREEBSD, THREE86BSD, MSWIN32, */
454 /* BSDI,SUNOS5, NEXT, other variants) */
455 /* NS32K ==> Encore Multimax */
456 /* MIPS ==> R2000 or R3000 */
457 /* (RISCOS, ULTRIX variants) */
458 /* VAX ==> DEC VAX */
459 /* (BSD, ULTRIX variants) */
460 /* RS6000 ==> IBM RS/6000 AIX3.X */
461 /* RT ==> IBM PC/RT */
462 /* HP_PA ==> HP9000/700 & /800 */
464 /* SPARC ==> SPARC v7/v8/v9 */
465 /* (SUNOS4, SUNOS5, LINUX, */
466 /* DRSNX variants) */
467 /* ALPHA ==> DEC Alpha */
468 /* (OSF1 and LINUX variants) */
469 /* M88K ==> Motorola 88XX0 */
470 /* (CX_UX and DGUX) */
471 /* S370 ==> 370-like machine */
472 /* running Amdahl UTS4 */
473 /* S390 ==> 390-like machine */
475 /* ARM32 ==> Intel StrongARM */
476 /* IA64 ==> Intel IPF */
478 /* (LINUX and HPUX) */
479 /* SH ==> Hitachi SuperH */
480 /* (LINUX & MSWINCE) */
481 /* X86_64 ==> AMD x86-64 */
482 /* POWERPC ==> IBM/Apple PowerPC */
483 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
484 /* LINUX, NETBSD, NOSYS variants) */
485 /* CRIS ==> Axis Etrax */
486 /* M32R ==> Renesas M32R */
490 * For each architecture and OS, the following need to be defined:
492 * CPP_WORD_SZ is a simple integer constant representing the word size.
493 * in bits. We assume byte addressibility, where a byte has 8 bits.
494 * We also assume CPP_WORD_SZ is either 32 or 64.
495 * (We care about the length of pointers, not hardware
496 * bus widths. Thus a 64 bit processor with a C compiler that uses
497 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
499 * MACH_TYPE is a string representation of the machine type.
500 * OS_TYPE is analogous for the OS.
502 * ALIGNMENT is the largest N, such that
503 * all pointer are guaranteed to be aligned on N byte boundaries.
504 * defining it to be 1 will always work, but perform poorly.
506 * DATASTART is the beginning of the data segment.
507 * On some platforms SEARCH_FOR_DATA_START is defined.
508 * SEARCH_FOR_DATASTART will cause GC_data_start to
509 * be set to an address determined by accessing data backwards from _end
510 * until an unmapped page is found. DATASTART will be defined to be
512 * On UNIX-like systems, the collector will scan the area between DATASTART
513 * and DATAEND for root pointers.
515 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
516 * RTH suggests gaining access to linker script synth'd values with
517 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
518 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
519 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
520 * without any special options.
522 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
525 * STACKBOTTOM is the cool end of the stack, which is usually the
526 * highest address in the stack.
527 * Under PCR or OS/2, we have other ways of finding thread stacks.
528 * For each machine, the following should:
529 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
530 * 2) define exactly one of
531 * STACKBOTTOM (should be defined to be an expression)
535 * If STACKBOTTOM is defined, then it's value will be used directly as the
536 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
537 * with a method appropriate for most Linux systems. Currently we look
538 * first for __libc_stack_end, and if that fails read it from /proc.
539 * If either of the last two macros are defined, then STACKBOTTOM is computed
540 * during collector startup using one of the following two heuristics:
541 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
542 * the next multiple of STACK_GRAN.
543 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
544 * in small steps (decrement if STACK_GROWS_UP), and read the value
545 * at each location. Remember the value when the first
546 * Segmentation violation or Bus error is signalled. Round that
547 * to the nearest plausible page boundary, and use that instead
550 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
551 * the value of environ is a pointer that can serve as STACKBOTTOM.
552 * I expect that HEURISTIC2 can be replaced by this approach, which
553 * interferes far less with debugging. However it has the disadvantage
554 * that it's confused by a putenv call before the collector is initialized.
555 * This could be dealt with by intercepting putenv ...
557 * If no expression for STACKBOTTOM can be found, and neither of the above
558 * heuristics are usable, the collector can still be used with all of the above
559 * undefined, provided one of the following is done:
560 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
561 * without reference to STACKBOTTOM. This is appropriate for use in
562 * conjunction with thread packages, since there will be multiple stacks.
563 * (Allocating thread stacks in the heap, and treating them as ordinary
564 * heap data objects is also possible as a last resort. However, this is
565 * likely to introduce significant amounts of excess storage retention
566 * unless the dead parts of the thread stacks are periodically cleared.)
567 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
568 * If the author of the client code controls the main program, this is
569 * easily accomplished by introducing a new main program, setting
570 * GC_stackbottom to the address of a local variable, and then calling
571 * the original main program. The new main program would read something
574 * # include "gc_private.h"
576 * main(argc, argv, envp)
578 * char **argv, **envp;
582 * GC_stackbottom = (ptr_t)(&dummy);
583 * return(real_main(argc, argv, envp));
587 * Each architecture may also define the style of virtual dirty bit
588 * implementation to be used:
589 * MPROTECT_VDB: Write protect the heap and catch faults.
590 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
592 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
593 * defined GC_register_dynamic_libraries() for the architecture.
595 * An architecture may define PREFETCH(x) to preload the cache with *x.
596 * This defaults to a no-op.
598 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
600 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
601 * clear the two words at GC_malloc-aligned address x. By default,
602 * word stores of 0 are used instead.
604 * HEAP_START may be defined as the initial address hint for mmap-based
608 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
609 * to push the relevant registers onto the stack. This generally makes
610 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
612 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
613 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
614 && !defined(__INTEL_COMPILER)
615 # define HAVE_BUILTIN_UNWIND_INIT
618 # define STACK_GRAN 0x1000000
620 # define MACH_TYPE "M68K"
623 # define OS_TYPE "OPENBSD"
626 # define DATASTART GC_data_start
627 # define DYNAMIC_LOADING
630 # define DATASTART ((ptr_t)(etext))
632 # define USE_GENERIC_PUSH_REGS
635 # define OS_TYPE "NETBSD"
638 # define DATASTART GC_data_start
639 # define DYNAMIC_LOADING
642 # define DATASTART ((ptr_t)(etext))
644 # define USE_GENERIC_PUSH_REGS
647 # define OS_TYPE "LINUX"
648 # define STACKBOTTOM ((ptr_t)0xf0000000)
649 # define USE_GENERIC_PUSH_REGS
651 /* We never got around to the assembly version. */
652 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
654 # define DYNAMIC_LOADING
655 # include <features.h>
656 # if defined(__GLIBC__)&& __GLIBC__>=2
657 # define SEARCH_FOR_DATA_START
659 extern char **__environ;
660 # define DATASTART ((ptr_t)(&__environ))
661 /* hideous kludge: __environ is the first */
662 /* word in crt0.o, and delimits the start */
663 /* of the data segment, no matter which */
664 /* ld options were passed through. */
665 /* We could use _etext instead, but that */
666 /* would include .rodata, which may */
667 /* contain large read-only data tables */
668 /* that we'd rather not scan. */
669 # endif /* !GLIBC2 */
671 # define DATAEND (_end)
674 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
678 # define OS_TYPE "SUNOS4"
680 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
681 # define HEURISTIC1 /* differs */
682 # define DYNAMIC_LOADING
685 # define OS_TYPE "HP"
687 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
688 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
689 /* empirically determined. seems to work. */
691 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
694 # define OS_TYPE "SYSV"
696 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
698 +((word)etext & 0x1fff))
699 /* This only works for shared-text binaries with magic number 0413.
700 The other sorts of SysV binaries put the data at the end of the text,
701 in which case the default of etext would work. Unfortunately,
702 handling both would require having the magic-number available.
705 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
706 /* The stack starts at the top of memory, but */
707 /* 0x0 cannot be used as setjump_test complains */
708 /* that the stack direction is incorrect. Two */
709 /* bytes down from 0x0 should be safe enough. */
711 # include <sys/mmu.h>
712 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
715 # define OS_TYPE "AMIGA"
716 /* STACKBOTTOM and DATASTART handled specially */
718 # define DATAEND /* not needed */
719 # define GETPAGESIZE() 4096
725 # define OS_TYPE "MACOS"
726 /* see os_dep.c for details of global data segments. */
727 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
728 # define DATAEND /* not needed */
729 # define GETPAGESIZE() 4096
732 # define OS_TYPE "NEXT"
733 # define DATASTART ((ptr_t) get_etext())
734 # define STACKBOTTOM ((ptr_t) 0x4000000)
735 # define DATAEND /* not needed */
740 # define MACH_TYPE "POWERPC"
742 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
746 # define OS_TYPE "MACOS"
747 /* see os_dep.c for details of global data segments. */
748 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
749 # define DATAEND /* not needed */
752 # if (defined (powerpc64) || defined(__powerpc64__))
754 # define CPP_WORDSZ 64
755 # define HBLKSIZE 4096
759 # define OS_TYPE "LINUX"
760 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
761 /* executable on a 64 bit kernel. */
762 # define LINUX_STACKBOTTOM
763 # define DYNAMIC_LOADING
764 # define SEARCH_FOR_DATA_START
766 # define DATAEND (_end)
769 # if (defined (__ppc64__))
771 # define CPP_WORDSZ 64
775 # define OS_TYPE "DARWIN"
776 # define DYNAMIC_LOADING
777 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
778 These aren't used when dyld support is enabled (it is by default) */
779 # define DATASTART ((ptr_t) get_etext())
780 # define DATAEND ((ptr_t) get_end())
781 # define STACKBOTTOM ((ptr_t) 0xc0000000)
783 # define USE_MMAP_ANON
784 # define USE_ASM_PUSH_REGS
785 /* This is potentially buggy. It needs more testing. See the comments in
787 # define MPROTECT_VDB
789 # define GETPAGESIZE() getpagesize()
790 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
791 /* The performance impact of prefetches is untested */
792 # define PREFETCH(x) \
793 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
794 # define PREFETCH_FOR_WRITE(x) \
795 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
797 /* There seems to be some issues with trylock hanging on darwin. This
798 should be looked into some more */
799 # define NO_PTHREAD_TRYLOCK
803 # define OS_TYPE "NETBSD"
806 # define DATASTART GC_data_start
807 # define DYNAMIC_LOADING
811 # define OS_TYPE "NOSYS"
812 extern void __end[], __dso_handle[];
813 # define DATASTART (__dso_handle) /* OK, that's ugly. */
814 # define DATAEND (__end)
815 /* Stack starts at 0xE0000000 for the simulator. */
817 # define STACK_GRAN 0x10000000
823 # define MACH_TYPE "VAX"
824 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
826 # define DATASTART ((ptr_t)(etext))
828 # define OS_TYPE "BSD"
830 /* HEURISTIC2 may be OK, but it's hard to test. */
833 # define OS_TYPE "ULTRIX"
834 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
839 # define MACH_TYPE "RT"
841 # define DATASTART ((ptr_t) 0x10000000)
842 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
846 # define MACH_TYPE "SPARC"
847 # if defined(__arch64__) || defined(__sparcv9)
849 # define CPP_WORDSZ 64
850 # define ELF_CLASS ELFCLASS64
852 # define ALIGNMENT 4 /* Required by hardware */
853 # define CPP_WORDSZ 32
855 # define ALIGN_DOUBLE
857 # define OS_TYPE "SUNOS5"
860 extern ptr_t GC_SysVGetDataStart();
861 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
862 # define DATAEND (_end)
863 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
865 /* Otherwise we now use calloc. Mmap may result in the */
866 /* heap interleaved with thread stacks, which can result in */
867 /* excessive blacklisting. Sbrk is unusable since it */
868 /* doesn't interact correctly with the system malloc. */
871 # define HEAP_START (ptr_t)0x40000000
873 # define HEAP_START DATAEND
876 /* HEURISTIC1 reportedly no longer works under 2.7. */
877 /* HEURISTIC2 probably works, but this appears to be preferable. */
878 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
879 /* installations that's undefined. We work around this with a */
881 # include <sys/vmparam.h>
883 /* This should work everywhere, but doesn't. */
884 # define STACKBOTTOM USRSTACK
889 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
890 /* getpagesize() appeared to be missing from at least one */
891 /* Solaris 5.4 installation. Weird. */
892 # define DYNAMIC_LOADING
895 # define OS_TYPE "SUNOS4"
896 /* [If you have a weak stomach, don't read this.] */
897 /* We would like to use: */
898 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
899 /* This fails occasionally, due to an ancient, but very */
900 /* persistent ld bug. etext is set 32 bytes too high. */
901 /* We instead read the text segment size from the a.out */
902 /* header, which happens to be mapped into our address space */
903 /* at the start of the text segment. The detective work here */
904 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
905 /* Serpette of INRIA. */
906 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
907 # define TEXTSTART 0x2000
908 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
909 # define MPROTECT_VDB
911 # define DYNAMIC_LOADING
914 # define OS_TYPE "DRSNX"
915 extern ptr_t GC_SysVGetDataStart();
917 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
918 # define MPROTECT_VDB
919 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
920 # define DYNAMIC_LOADING
923 # define OS_TYPE "LINUX"
925 # define DYNAMIC_LOADING
927 Linux Sparc/a.out not supported
931 # define DATAEND (_end)
933 extern ptr_t GC_SysVGetDataStart();
935 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
937 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
939 # define LINUX_STACKBOTTOM
942 # define OS_TYPE "OPENBSD"
943 # define STACKBOTTOM ((ptr_t) 0xf8000000)
945 # define DATASTART ((ptr_t)(etext))
948 # define OS_TYPE "NETBSD"
951 # define DATASTART GC_data_start
952 # define DYNAMIC_LOADING
955 # define DATASTART ((ptr_t)(etext))
961 # define MACH_TYPE "I386"
962 # if defined(__LP64__) || defined(_WIN64)
963 # define CPP_WORDSZ 64
966 # define CPP_WORDSZ 32
968 /* Appears to hold for all "32 bit" compilers */
969 /* except Borland. The -a4 option fixes */
971 /* Ivan Demakov: For Watcom the option is -zp4. */
973 # ifndef SMALL_CONFIG
974 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
975 /* improvement on Pentiums. */
977 # ifdef HAVE_BUILTIN_UNWIND_INIT
978 # define USE_GENERIC_PUSH_REGS
981 # define OS_TYPE "SEQUENT"
983 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
984 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
987 # define OS_TYPE "BEOS"
989 # define GETPAGESIZE() B_PAGE_SIZE
991 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
994 # define OS_TYPE "SUNOS5"
995 extern int _etext[], _end[];
996 extern ptr_t GC_SysVGetDataStart();
997 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
998 # define DATAEND (_end)
999 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1000 /* but reportedly breaks under 2.8. It appears that the stack */
1001 /* base is a property of the executable, so this should not break */
1002 /* old executables. */
1003 /* HEURISTIC2 probably works, but this appears to be preferable. */
1004 # include <sys/vm.h>
1005 # define STACKBOTTOM USRSTACK
1006 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1007 /* It appears to be fixed in 2.8 and 2.9. */
1008 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1011 # define DYNAMIC_LOADING
1012 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1014 /* Otherwise we now use calloc. Mmap may result in the */
1015 /* heap interleaved with thread stacks, which can result in */
1016 /* excessive blacklisting. Sbrk is unusable since it */
1017 /* doesn't interact correctly with the system malloc. */
1020 # define HEAP_START (ptr_t)0x40000000
1022 # define HEAP_START DATAEND
1026 # define OS_TYPE "SCO"
1028 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1030 +((word)etext & 0xfff))
1031 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1034 # define OS_TYPE "SCO_ELF"
1036 # define DATASTART ((ptr_t)(etext))
1037 # define STACKBOTTOM ((ptr_t) 0x08048000)
1038 # define DYNAMIC_LOADING
1039 # define ELF_CLASS ELFCLASS32
1042 # define OS_TYPE "DGUX"
1043 extern int _etext, _end;
1044 extern ptr_t GC_SysVGetDataStart();
1045 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1046 # define DATAEND (&_end)
1047 # define STACK_GROWS_DOWN
1049 # include <unistd.h>
1050 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1051 # define DYNAMIC_LOADING
1054 # endif /* USE_MMAP */
1055 # define MAP_FAILED (void *) -1
1057 # define HEAP_START (ptr_t)0x40000000
1058 # else /* USE_MMAP */
1059 # define HEAP_START DATAEND
1060 # endif /* USE_MMAP */
1065 /* The Intel compiler doesn't like inline assembly */
1066 # define USE_GENERIC_PUSH_REGS
1068 # define OS_TYPE "LINUX"
1069 # define LINUX_STACKBOTTOM
1073 # define STACK_GRAN 0x10000000
1074 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1075 /* different kernel configurations. In particular, systems */
1076 /* with 2GB physical memory will usually move the user */
1077 /* address space limit, and hence initial SP to 0x80000000. */
1079 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1080 # define MPROTECT_VDB
1082 /* We seem to get random errors in incremental mode, */
1083 /* possibly because Linux threads is itself a malloc client */
1084 /* and can't deal with the signals. */
1086 # define HEAP_START (ptr_t)0x1000
1087 /* This encourages mmap to give us low addresses, */
1088 /* thus allowing the heap to grow to ~3GB */
1090 # define DYNAMIC_LOADING
1091 # ifdef UNDEFINED /* includes ro data */
1092 extern int _etext[];
1093 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1095 # include <features.h>
1096 # if defined(__GLIBC__) && __GLIBC__ >= 2
1097 # define SEARCH_FOR_DATA_START
1099 extern char **__environ;
1100 # define DATASTART ((ptr_t)(&__environ))
1101 /* hideous kludge: __environ is the first */
1102 /* word in crt0.o, and delimits the start */
1103 /* of the data segment, no matter which */
1104 /* ld options were passed through. */
1105 /* We could use _etext instead, but that */
1106 /* would include .rodata, which may */
1107 /* contain large read-only data tables */
1108 /* that we'd rather not scan. */
1111 # define DATAEND (_end)
1114 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1116 # ifdef USE_I686_PREFETCH
1117 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1118 /* for the next rtelease. */
1119 # define PREFETCH(x) \
1120 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1121 /* Empirically prefetcht0 is much more effective at reducing */
1122 /* cache miss stalls for the targetted load instructions. But it */
1123 /* seems to interfere enough with other cache traffic that the net */
1124 /* result is worse than prefetchnta. */
1126 /* Using prefetches for write seems to have a slight negative */
1127 /* impact on performance, at least for a PIII/500. */
1128 # define PREFETCH_FOR_WRITE(x) \
1129 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1132 # ifdef USE_3DNOW_PREFETCH
1133 # define PREFETCH(x) \
1134 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1135 # define PREFETCH_FOR_WRITE(x) \
1136 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1140 # define OS_TYPE "CYGWIN32"
1141 extern int _data_start__[];
1142 extern int _data_end__[];
1143 extern int _bss_start__[];
1144 extern int _bss_end__[];
1145 /* For binutils 2.9.1, we have */
1146 /* DATASTART = _data_start__ */
1147 /* DATAEND = _bss_end__ */
1148 /* whereas for some earlier versions it was */
1149 /* DATASTART = _bss_start__ */
1150 /* DATAEND = _data_end__ */
1151 /* To get it right for both, we take the */
1152 /* minumum/maximum of the two. */
1154 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1157 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1159 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1160 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1162 # define STACK_GRAN 0x10000
1166 # define OS_TYPE "OS2"
1167 /* STACKBOTTOM and DATASTART are handled specially in */
1168 /* os_dep.c. OS2 actually has the right */
1170 # define DATAEND /* not needed */
1171 # define USE_GENERIC_PUSH_REGS
1174 # define OS_TYPE "MSWIN32"
1175 /* STACKBOTTOM and DATASTART are handled specially in */
1177 # ifndef __WATCOMC__
1178 # define MPROTECT_VDB
1180 # define DATAEND /* not needed */
1183 # define OS_TYPE "MSWINCE"
1184 # define DATAEND /* not needed */
1187 # define OS_TYPE "DJGPP"
1188 # include "stubinfo.h"
1191 extern int __djgpp_stack_limit;
1192 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1193 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1195 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1196 /* This may not be right. */
1199 # define OS_TYPE "OPENBSD"
1202 # define OS_TYPE "FREEBSD"
1203 # ifndef GC_FREEBSD_THREADS
1204 # define MPROTECT_VDB
1206 # define SIG_SUSPEND SIGUSR1
1207 # define SIG_THR_RESTART SIGUSR2
1208 # define FREEBSD_STACKBOTTOM
1210 # define DYNAMIC_LOADING
1212 extern char etext[];
1213 extern char * GC_FreeBSDGetDataStart();
1214 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1217 # define OS_TYPE "NETBSD"
1219 # define DYNAMIC_LOADING
1223 # define OS_TYPE "THREE86BSD"
1226 # define OS_TYPE "BSDI"
1228 # if defined(OPENBSD) || defined(NETBSD) \
1229 || defined(THREE86BSD) || defined(BSDI)
1231 extern char etext[];
1232 # define DATASTART ((ptr_t)(etext))
1235 # define OS_TYPE "NEXT"
1236 # define DATASTART ((ptr_t) get_etext())
1237 # define STACKBOTTOM ((ptr_t)0xc0000000)
1238 # define DATAEND /* not needed */
1241 # define OS_TYPE "DOS4GW"
1242 extern long __nullarea;
1244 extern char *_STACKTOP;
1245 /* Depending on calling conventions Watcom C either precedes
1246 or does not precedes with undescore names of C-variables.
1247 Make sure startup code variables always have the same names. */
1248 #pragma aux __nullarea "*";
1249 #pragma aux _end "*";
1250 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1251 /* confused? me too. */
1252 # define DATASTART ((ptr_t) &__nullarea)
1253 # define DATAEND ((ptr_t) &_end)
1256 # define OS_TYPE "HURD"
1257 # define STACK_GROWS_DOWN
1259 extern int __data_start[];
1260 # define DATASTART ( (ptr_t) (__data_start))
1262 # define DATAEND ( (ptr_t) (_end))
1263 /* # define MPROTECT_VDB Not quite working yet? */
1264 # define DYNAMIC_LOADING
1269 # define MACH_TYPE "NS32K"
1270 # define ALIGNMENT 4
1271 extern char **environ;
1272 # define DATASTART ((ptr_t)(&environ))
1273 /* hideous kludge: environ is the first */
1274 /* word in crt0.o, and delimits the start */
1275 /* of the data segment, no matter which */
1276 /* ld options were passed through. */
1277 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1281 # define MACH_TYPE "MIPS"
1283 /* This was developed for a linuxce style platform. Probably */
1284 /* needs to be tweaked for workstation class machines. */
1285 # define OS_TYPE "LINUX"
1286 # define DYNAMIC_LOADING
1288 # define DATAEND (_end)
1289 extern int __data_start[];
1290 # define DATASTART ((ptr_t)(__data_start))
1291 # define ALIGNMENT 4
1292 # define USE_GENERIC_PUSH_REGS
1293 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1294 # define LINUX_STACKBOTTOM
1296 # define STACKBOTTOM 0x80000000
1301 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1302 extern int _fdata[], _end[];
1303 # define DATASTART ((ptr_t)_fdata)
1304 # define DATAEND ((ptr_t)_end)
1305 # define CPP_WORDSZ _MIPS_SZPTR
1306 # define ALIGNMENT (_MIPS_SZPTR/8)
1308 extern int etext[], edata[], end[];
1309 extern int _DYNAMIC_LINKING[], _gp[];
1310 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1311 + ((word)etext & 0xffff)))
1312 # define DATAEND (edata)
1313 # define DATASTART2 (_DYNAMIC_LINKING \
1314 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1316 # define DATAEND2 (end)
1317 # define ALIGNMENT 4
1319 # define OS_TYPE "EWS4800"
1320 # define USE_GENERIC_PUSH_REGS 1
1324 # define DATASTART (ptr_t)0x10000000
1325 /* Could probably be slightly higher since */
1326 /* startup code allocates lots of stuff. */
1327 # define OS_TYPE "ULTRIX"
1328 # define ALIGNMENT 4
1332 # define DATASTART (ptr_t)0x10000000
1333 # define OS_TYPE "RISCOS"
1334 # define ALIGNMENT 4 /* Required by hardware */
1338 extern int _fdata[];
1339 # define DATASTART ((ptr_t)(_fdata))
1341 # define HEAP_START (ptr_t)0x30000000
1343 # define HEAP_START DATASTART
1345 /* Lowest plausible heap address. */
1346 /* In the MMAP case, we map there. */
1347 /* In either case it is used to identify */
1348 /* heap sections so they're not */
1349 /* considered as roots. */
1350 # define OS_TYPE "IRIX5"
1351 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1352 /* of recent breakage. */
1354 # define CPP_WORDSZ _MIPS_SZPTR
1355 # define ALIGNMENT (_MIPS_SZPTR/8)
1356 # if CPP_WORDSZ != 64
1357 # define ALIGN_DOUBLE
1360 # define ALIGNMENT 4
1361 # define ALIGN_DOUBLE
1363 # define DYNAMIC_LOADING
1366 # define OS_TYPE "MSWINCE"
1367 # define ALIGNMENT 4
1368 # define DATAEND /* not needed */
1370 # if defined(NETBSD)
1371 # define OS_TYPE "NETBSD"
1372 # define ALIGNMENT 4
1374 # define USE_GENERIC_PUSH_REGS
1377 # define DATASTART GC_data_start
1378 # define NEED_FIND_LIMIT
1379 # define DYNAMIC_LOADING
1381 # define DATASTART ((ptr_t) 0x10000000)
1382 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1388 # define MACH_TYPE "RS6000"
1393 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1396 # define ALIGNMENT 8
1397 # define CPP_WORDSZ 64
1398 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1400 # define ALIGNMENT 4
1401 # define CPP_WORDSZ 32
1402 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1404 /* From AIX linker man page:
1405 _text Specifies the first location of the program.
1406 _etext Specifies the first location after the program.
1407 _data Specifies the first location of the data.
1408 _edata Specifies the first location after the initialized data
1409 _end or end Specifies the first location after all data.
1411 extern int _data[], _end[];
1412 # define DATASTART ((ptr_t)((ulong)_data))
1413 # define DATAEND ((ptr_t)((ulong)_end))
1415 # define USE_GENERIC_PUSH_REGS
1416 # define DYNAMIC_LOADING
1417 /* For really old versions of AIX, this may have to be removed. */
1421 # define MACH_TYPE "HP_PA"
1423 # define CPP_WORDSZ 64
1424 # define ALIGNMENT 8
1426 # define CPP_WORDSZ 32
1427 # define ALIGNMENT 4
1428 # define ALIGN_DOUBLE
1430 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1431 # ifndef LINUX /* For now. */
1432 # define MPROTECT_VDB
1435 # define GENERIC_COMPARE_AND_SWAP
1436 /* No compare-and-swap instruction. Use pthread mutexes */
1437 /* when we absolutely have to. */
1438 # ifdef PARALLEL_MARK
1439 # define USE_MARK_BYTES
1440 /* Minimize compare-and-swap usage. */
1443 # define STACK_GROWS_UP
1445 # define OS_TYPE "HPUX"
1446 extern int __data_start[];
1447 # define DATASTART ((ptr_t)(__data_start))
1449 /* The following appears to work for 7xx systems running HP/UX */
1450 /* 9.xx Furthermore, it might result in much faster */
1451 /* collections than HEURISTIC2, which may involve scanning */
1452 /* segments that directly precede the stack. It is not the */
1453 /* default, since it may not work on older machine/OS */
1454 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1456 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1458 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1459 /* to this. Note that the GC must be initialized before the */
1460 /* first putenv call. */
1461 extern char ** environ;
1462 # define STACKBOTTOM ((ptr_t)environ)
1464 # define DYNAMIC_LOADING
1465 # include <unistd.h>
1466 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1468 # define PREFETCH(x) { \
1469 register long addr = (long)(x); \
1470 (void) _asm ("LDW", 0, 0, addr, 0); \
1475 # define OS_TYPE "LINUX"
1476 # define LINUX_STACKBOTTOM
1477 # define DYNAMIC_LOADING
1478 # define SEARCH_FOR_DATA_START
1480 # define DATAEND (&_end)
1485 # define MACH_TYPE "ALPHA"
1486 # define ALIGNMENT 8
1487 # define CPP_WORDSZ 64
1489 # define USE_GENERIC_PUSH_REGS
1490 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1491 /* fp registers in some cases when the target is a 21264. The assembly */
1492 /* code doesn't handle that yet, and version dependencies make that a */
1493 /* bit tricky. Do the easy thing for now. */
1496 # define OS_TYPE "NETBSD"
1498 # define DATASTART GC_data_start
1499 # define ELFCLASS32 32
1500 # define ELFCLASS64 64
1501 # define ELF_CLASS ELFCLASS64
1502 # define DYNAMIC_LOADING
1505 # define OS_TYPE "OPENBSD"
1507 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1508 # define DATASTART GC_data_start
1509 # define ELFCLASS32 32
1510 # define ELFCLASS64 64
1511 # define ELF_CLASS ELFCLASS64
1512 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1513 # define DATASTART ((ptr_t) 0x140000000)
1517 # define OS_TYPE "FREEBSD"
1518 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1519 # define SIG_SUSPEND SIGUSR1
1520 # define SIG_THR_RESTART SIGUSR2
1521 # define FREEBSD_STACKBOTTOM
1523 # define DYNAMIC_LOADING
1525 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1526 extern char etext[];
1527 extern char edata[];
1529 # define NEED_FIND_LIMIT
1530 # define DATASTART ((ptr_t)(&etext))
1531 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1532 # define DATASTART2 ((ptr_t)(&edata))
1533 # define DATAEND2 ((ptr_t)(&end))
1536 # define OS_TYPE "OSF1"
1537 # define DATASTART ((ptr_t) 0x140000000)
1539 # define DATAEND ((ptr_t) &_end)
1540 extern char ** environ;
1541 /* round up from the value of environ to the nearest page boundary */
1542 /* Probably breaks if putenv is called before collector */
1543 /* initialization. */
1544 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1545 /* # define HEURISTIC2 */
1546 /* Normally HEURISTIC2 is too conervative, since */
1547 /* the text segment immediately follows the stack. */
1548 /* Hence we give an upper pound. */
1549 /* This is currently unused, since we disabled HEURISTIC2 */
1550 extern int __start[];
1551 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1552 # ifndef GC_OSF1_THREADS
1553 /* Unresolved signal issues with threads. */
1554 # define MPROTECT_VDB
1556 # define DYNAMIC_LOADING
1559 # define OS_TYPE "LINUX"
1560 # define LINUX_STACKBOTTOM
1562 # define SEARCH_FOR_DATA_START
1563 # define DYNAMIC_LOADING
1565 # define DATASTART ((ptr_t) 0x140000000)
1568 # define DATAEND (_end)
1569 # define MPROTECT_VDB
1570 /* Has only been superficially tested. May not */
1571 /* work on all versions. */
1576 # define MACH_TYPE "IA64"
1577 # define USE_GENERIC_PUSH_REGS
1578 /* We need to get preserved registers in addition to register */
1579 /* windows. That's easiest to do with setjmp. */
1580 # ifdef PARALLEL_MARK
1581 # define USE_MARK_BYTES
1582 /* Compare-and-exchange is too expensive to use for */
1583 /* setting mark bits. */
1587 # define CPP_WORDSZ 32
1588 # define ALIGN_DOUBLE
1589 /* Requires 8 byte alignment for malloc */
1590 # define ALIGNMENT 4
1595 # define CPP_WORDSZ 64
1596 # define ALIGN_DOUBLE
1597 /* Requires 16 byte alignment for malloc */
1598 # define ALIGNMENT 8
1600 # define OS_TYPE "HPUX"
1601 extern int __data_start[];
1602 # define DATASTART ((ptr_t)(__data_start))
1603 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1604 /* to this. Note that the GC must be initialized before the */
1605 /* first putenv call. */
1606 extern char ** environ;
1607 # define STACKBOTTOM ((ptr_t)environ)
1608 # define HPUX_STACKBOTTOM
1609 # define DYNAMIC_LOADING
1610 # include <unistd.h>
1611 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1612 /* The following was empirically determined, and is probably */
1613 /* not very robust. */
1614 /* Note that the backing store base seems to be at a nice */
1615 /* address minus one page. */
1616 # define BACKING_STORE_DISPLACEMENT 0x1000000
1617 # define BACKING_STORE_ALIGNMENT 0x1000
1618 extern ptr_t GC_register_stackbottom;
1619 # define BACKING_STORE_BASE GC_register_stackbottom
1620 /* Known to be wrong for recent HP/UX versions!!! */
1623 # define CPP_WORDSZ 64
1624 # define ALIGN_DOUBLE
1625 /* Requires 16 byte alignment for malloc */
1626 # define ALIGNMENT 8
1627 # define OS_TYPE "LINUX"
1628 /* The following works on NUE and older kernels: */
1629 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1630 /* This does not work on NUE: */
1631 # define LINUX_STACKBOTTOM
1632 /* We also need the base address of the register stack */
1633 /* backing store. This is computed in */
1634 /* GC_linux_register_stack_base based on the following */
1636 # define BACKING_STORE_ALIGNMENT 0x100000
1637 # define BACKING_STORE_DISPLACEMENT 0x80000000
1638 extern ptr_t GC_register_stackbottom;
1639 # define BACKING_STORE_BASE GC_register_stackbottom
1640 # define SEARCH_FOR_DATA_START
1642 # define DYNAMIC_LOADING
1644 /* In the Intel compiler environment, we seem to end up with */
1645 /* statically linked executables and an undefined reference */
1648 # define MPROTECT_VDB
1649 /* Requires Linux 2.3.47 or later. */
1651 # define DATAEND (_end)
1653 # ifndef __INTEL_COMPILER
1654 # define PREFETCH(x) \
1655 __asm__ (" lfetch [%0]": : "r"(x))
1656 # define PREFETCH_FOR_WRITE(x) \
1657 __asm__ (" lfetch.excl [%0]": : "r"(x))
1658 # define CLEAR_DOUBLE(x) \
1659 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1661 # include <ia64intrin.h>
1662 # define PREFETCH(x) \
1663 __lfetch(__lfhint_none, (x))
1664 # define PREFETCH_FOR_WRITE(x) \
1665 __lfetch(__lfhint_nta, (x))
1666 # define CLEAR_DOUBLE(x) \
1667 __stf_spill((void *)(x), 0)
1668 # endif // __INTEL_COMPILER
1672 /* FIXME: This is a very partial guess. There is no port, yet. */
1673 # define OS_TYPE "MSWIN32"
1674 /* STACKBOTTOM and DATASTART are handled specially in */
1676 # define DATAEND /* not needed */
1677 # if defined(_WIN64)
1678 # define CPP_WORDSZ 64
1680 # define CPP_WORDSZ 32 /* Is this possible? */
1682 # define ALIGNMENT 8
1687 # define MACH_TYPE "M88K"
1688 # define ALIGNMENT 4
1689 # define ALIGN_DOUBLE
1692 # define OS_TYPE "CX_UX"
1693 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1696 # define OS_TYPE "DGUX"
1697 extern ptr_t GC_SysVGetDataStart();
1698 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1700 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1704 /* If this still works, and if anyone cares, this should probably */
1705 /* be moved to the S390 category. */
1706 # define MACH_TYPE "S370"
1707 # define ALIGNMENT 4 /* Required by hardware */
1708 # define USE_GENERIC_PUSH_REGS
1710 # define OS_TYPE "UTS4"
1712 extern int _etext[];
1714 extern ptr_t GC_SysVGetDataStart();
1715 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1716 # define DATAEND (_end)
1722 # define MACH_TYPE "S390"
1723 # define USE_GENERIC_PUSH_REGS
1725 # define ALIGNMENT 4
1726 # define CPP_WORDSZ 32
1728 # define ALIGNMENT 8
1729 # define CPP_WORDSZ 64
1730 # define HBLKSIZE 4096
1733 # define OS_TYPE "LINUX"
1734 # define LINUX_STACKBOTTOM
1735 # define DYNAMIC_LOADING
1736 extern int __data_start[];
1737 # define DATASTART ((ptr_t)(__data_start))
1739 # define DATAEND (_end)
1740 # define CACHE_LINE_SIZE 256
1741 # define GETPAGESIZE() 4096
1746 # define ALIGNMENT 4
1747 extern int _etext[];
1748 # define DATASTART ((ptr_t)(_etext))
1753 # define CPP_WORDSZ 32
1754 # define MACH_TYPE "ARM32"
1755 # define ALIGNMENT 4
1757 # define OS_TYPE "NETBSD"
1760 # define DATASTART GC_data_start
1761 # define DYNAMIC_LOADING
1763 extern char etext[];
1764 # define DATASTART ((ptr_t)(etext))
1766 # define USE_GENERIC_PUSH_REGS
1769 # define OS_TYPE "LINUX"
1772 # define STACK_GRAN 0x10000000
1773 # define USE_GENERIC_PUSH_REGS
1775 # define DYNAMIC_LOADING
1776 # include <features.h>
1777 # if defined(__GLIBC__) && __GLIBC__ >= 2
1778 # define SEARCH_FOR_DATA_START
1780 extern char **__environ;
1781 # define DATASTART ((ptr_t)(&__environ))
1782 /* hideous kludge: __environ is the first */
1783 /* word in crt0.o, and delimits the start */
1784 /* of the data segment, no matter which */
1785 /* ld options were passed through. */
1786 /* We could use _etext instead, but that */
1787 /* would include .rodata, which may */
1788 /* contain large read-only data tables */
1789 /* that we'd rather not scan. */
1792 # define DATAEND (_end)
1795 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1799 # define OS_TYPE "MSWINCE"
1800 # define DATAEND /* not needed */
1803 /* __data_start is usually defined in the target linker script. */
1804 extern int __data_start[];
1805 # define DATASTART (ptr_t)(__data_start)
1806 # define USE_GENERIC_PUSH_REGS
1807 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1808 extern void *__stack_base__;
1809 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1814 # define MACH_TYPE "CRIS"
1815 # define CPP_WORDSZ 32
1816 # define ALIGNMENT 1
1817 # define OS_TYPE "LINUX"
1818 # define DYNAMIC_LOADING
1819 # define LINUX_STACKBOTTOM
1820 # define USE_GENERIC_PUSH_REGS
1821 # define SEARCH_FOR_DATA_START
1823 # define DATAEND (_end)
1827 # define MACH_TYPE "SH"
1828 # define ALIGNMENT 4
1830 # define OS_TYPE "MSWINCE"
1831 # define DATAEND /* not needed */
1834 # define OS_TYPE "LINUX"
1835 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1836 # define USE_GENERIC_PUSH_REGS
1837 # define DYNAMIC_LOADING
1838 # define SEARCH_FOR_DATA_START
1840 # define DATAEND (_end)
1845 # define MACH_TYPE "SH4"
1846 # define OS_TYPE "MSWINCE"
1847 # define ALIGNMENT 4
1848 # define DATAEND /* not needed */
1852 # define CPP_WORDSZ 32
1853 # define MACH_TYPE "M32R"
1854 # define ALIGNMENT 4
1856 # define OS_TYPE "LINUX"
1857 # define LINUX_STACKBOTTOM
1859 # define STACK_GRAN 0x10000000
1860 # define USE_GENERIC_PUSH_REGS
1861 # define DYNAMIC_LOADING
1862 # define SEARCH_FOR_DATA_START
1864 # define DATAEND (_end)
1869 # define MACH_TYPE "X86_64"
1870 # define ALIGNMENT 8
1871 # define CPP_WORDSZ 64
1873 # define HBLKSIZE 4096
1875 # define CACHE_LINE_SIZE 64
1876 # define USE_GENERIC_PUSH_REGS
1878 # define OS_TYPE "LINUX"
1879 # define LINUX_STACKBOTTOM
1880 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1881 # define MPROTECT_VDB
1883 /* We seem to get random errors in incremental mode, */
1884 /* possibly because Linux threads is itself a malloc client */
1885 /* and can't deal with the signals. */
1888 # define DYNAMIC_LOADING
1889 # ifdef UNDEFINED /* includes ro data */
1890 extern int _etext[];
1891 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1893 # include <features.h>
1894 # define SEARCH_FOR_DATA_START
1896 # define DATAEND (_end)
1899 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1901 # if defined(__GNUC__) && __GNUC >= 3
1902 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1903 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1907 # define OS_TYPE "NETBSD"
1909 # define DYNAMIC_LOADING
1912 extern char etext[];
1913 # define SEARCH_FOR_DATA_START
1917 #if defined(LINUX) && defined(USE_MMAP)
1918 /* The kernel may do a somewhat better job merging mappings etc. */
1919 /* with anonymous mappings. */
1920 # define USE_MMAP_ANON
1923 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1924 /* Rld appears to allocate some memory with its own allocator, and */
1925 /* some through malloc, which might be redirected. To make this */
1926 /* work with collectable memory, we have to scan memory allocated */
1927 /* by rld's internal malloc. */
1928 # define USE_PROC_FOR_LIBRARIES
1931 # ifndef STACK_GROWS_UP
1932 # define STACK_GROWS_DOWN
1936 # define CPP_WORDSZ 32
1945 # define DATAEND (end)
1948 # if defined(SVR4) && !defined(GETPAGESIZE)
1949 # include <unistd.h>
1950 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1953 # ifndef GETPAGESIZE
1954 # if defined(SUNOS5) || defined(IRIX5)
1955 # include <unistd.h>
1957 # define GETPAGESIZE() getpagesize()
1960 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1961 /* OS has SVR4 generic features. Probably others also qualify. */
1965 # if defined(SUNOS5) || defined(DRSNX)
1966 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1969 /* OS has SUNOS5 style signal handlers. */
1977 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
1981 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
1982 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1983 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
1984 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
1985 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1988 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1993 # undef DYNAMIC_LOADING
1998 # undef MPROTECT_VDB
2003 /* Postponed for now. */
2005 # undef MPROTECT_VDB
2008 # ifdef SMALL_CONFIG
2009 /* Presumably not worth the space it takes. */
2011 # undef MPROTECT_VDB
2015 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2018 # ifdef PARALLEL_MARK
2019 # undef MPROTECT_VDB /* For now. */
2022 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2023 # define DEFAULT_VDB
2027 # define PREFETCH(x)
2028 # define NO_PREFETCH
2031 # ifndef PREFETCH_FOR_WRITE
2032 # define PREFETCH_FOR_WRITE(x)
2033 # define NO_PREFETCH_FOR_WRITE
2036 # ifndef CACHE_LINE_SIZE
2037 # define CACHE_LINE_SIZE 32 /* Wild guess */
2041 # define REGISTER_LIBRARIES_EARLY
2042 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2043 /* lock. This isn't safe after the world has stopped. So we must */
2044 /* call GC_register_dynamic_libraries before stopping the world. */
2045 /* For performance reasons, this may be beneficial on other */
2046 /* platforms as well, though it should be avoided in win32. */
2049 # if defined(SEARCH_FOR_DATA_START)
2050 extern ptr_t GC_data_start;
2051 # define DATASTART GC_data_start
2054 # ifndef CLEAR_DOUBLE
2055 # define CLEAR_DOUBLE(x) \
2056 ((word*)x)[0] = 0; \
2058 # endif /* CLEAR_DOUBLE */
2060 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2061 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2062 # define GC_SOLARIS_THREADS
2065 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2066 --> inconsistent configuration
2068 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2069 --> inconsistent configuration
2071 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2072 --> inconsistent configuration
2074 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2075 --> inconsistent configuration
2077 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2078 --> inconsistent configuration
2080 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2081 --> inconsistent configuration
2084 # if defined(PCR) || defined(SRC_M3) || \
2085 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2086 defined(GC_PTHREADS)
2090 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
2091 || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2092 || (defined(I386) && defined(__LCC__))
2093 /* Use setjmp based hack to mark from callee-save registers. */
2094 /* The define should move to the individual platform */
2096 # define USE_GENERIC_PUSH_REGS
2099 # if defined(MSWINCE)
2104 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2105 /* include assembly code to do it well. */
2108 /* Can we save call chain in objects for debugging? */
2109 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2110 /* frame) to reasonable values for the platform. */
2111 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2112 /* at build time, though we feel free to adjust it slightly. */
2113 /* Define NEED_CALLINFO if we either save the call stack or */
2114 /* GC_ADD_CALLER is defined. */
2115 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2118 # define CAN_SAVE_CALL_ARGS
2120 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2121 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2122 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2123 # define CAN_SAVE_CALL_ARGS
2126 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2127 && defined(GC_CAN_SAVE_CALL_STACKS)
2128 # define SAVE_CALL_CHAIN
2130 # ifdef SAVE_CALL_CHAIN
2131 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2132 # define NARGS SAVE_CALL_NARGS
2134 # define NARGS 0 /* Number of arguments to save for each call. */
2137 # ifdef SAVE_CALL_CHAIN
2138 # ifndef SAVE_CALL_COUNT
2139 # define NFRAMES 6 /* Number of frames to save. Even for */
2140 /* alignment reasons. */
2142 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2144 # define NEED_CALLINFO
2145 # endif /* SAVE_CALL_CHAIN */
2146 # ifdef GC_ADD_CALLER
2149 # define NEED_CALLINFO
2152 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2153 # define DBG_HDRS_ALL
2156 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2157 # define POINTER_SHIFT 0
2160 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2161 # define POINTER_MASK ((GC_word)(-1))
2164 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2165 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2168 # if defined(FIXUP_POINTER)
2169 # define NEED_FIXUP_POINTER 1
2171 # define NEED_FIXUP_POINTER 0
2172 # define FIXUP_POINTER(p)
2176 /* This relies on some type definitions from gc_priv.h, from */
2177 /* where it's normally included. */
2179 /* How to get heap memory from the OS: */
2180 /* Note that sbrk()-like allocation is preferred, since it */
2181 /* usually makes it possible to merge consecutively allocated */
2182 /* chunks. It also avoids unintented recursion with */
2183 /* -DREDIRECT_MALLOC. */
2184 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2185 /* 0 is taken to mean failure. */
2186 /* In the case os USE_MMAP, the argument must also be a */
2187 /* physical page size. */
2188 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2189 /* though we should perhaps take advantage of the case in which */
2191 struct hblk; /* See gc_priv.h. */
2193 char * real_malloc();
2194 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2198 void * os2_alloc(size_t bytes);
2199 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2203 # if defined(NEXT) || defined(DOS4GW) || \
2204 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2205 (defined(SUNOS5) && !defined(USE_MMAP))
2206 # define GET_MEM(bytes) HBLKPTR((size_t) \
2207 calloc(1, (size_t)bytes + GC_page_size) \
2211 extern ptr_t GC_win32_get_mem();
2212 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2215 # if defined(USE_TEMPORARY_MEMORY)
2216 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2217 Boolean clearMemory);
2218 # define GET_MEM(bytes) HBLKPTR( \
2219 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2222 # define GET_MEM(bytes) HBLKPTR( \
2223 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2227 extern ptr_t GC_wince_get_mem();
2228 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2230 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2231 extern void *GC_amiga_get_mem(size_t size);
2232 # define GET_MEM(bytes) HBLKPTR((size_t) \
2233 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2236 extern ptr_t GC_unix_get_mem();
2237 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2246 #endif /* GC_PRIVATE_H */
2248 # endif /* GCCONFIG_H */