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(powerpc) || defined(__powerpc__) || defined(powerpc64) || defined(__powerpc64__))
234 # define mach_type_known
236 # if defined(LINUX) && defined(__mc68000__)
238 # define mach_type_known
240 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
242 # define mach_type_known
244 # if defined(LINUX) && defined(__arm__)
246 # define mach_type_known
248 # if defined(LINUX) && defined(__sh__)
250 # define mach_type_known
252 # if defined(LINUX) && defined(__m32r__)
254 # define mach_type_known
256 # if defined(__alpha) || defined(__alpha__)
258 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
259 # define OSF1 /* a.k.a Digital Unix */
261 # define mach_type_known
263 # if defined(_AMIGA) && !defined(AMIGA)
268 # define mach_type_known
270 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
273 # define mach_type_known
275 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
278 # define mach_type_known
280 # if defined(macosx) || \
281 defined(__APPLE__) && defined(__MACH__) && defined(__ppc__)
284 # define mach_type_known
286 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
289 --> Not really supported
, but at least we recognize it
.
291 # if defined(NeXT) && defined(mc68000)
294 # define mach_type_known
296 # if defined(NeXT) && (defined(i386) || defined(__i386__))
299 # define mach_type_known
301 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
304 # define mach_type_known
306 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
308 # define mach_type_known
310 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
312 # define mach_type_known
314 # if defined(__NetBSD__) && defined(__x86_64__)
316 # define mach_type_known
318 # if defined(bsdi) && (defined(i386) || defined(__i386__))
321 # define mach_type_known
323 # if !defined(mach_type_known) && defined(__386BSD__)
326 # define mach_type_known
328 # if defined(_CX_UX) && defined(_M88K)
331 # define mach_type_known
333 # if defined(DGUX) && defined(m88k)
336 # define mach_type_known
338 # if defined(_WIN32_WCE)
339 /* SH3, SH4, MIPS already defined for corresponding architectures */
340 # if defined(SH3) || defined(SH4)
350 # define mach_type_known
352 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
353 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
355 # define MSWIN32 /* or Win32s */
356 # define mach_type_known
358 # if defined(_MSC_VER) && defined(_M_IA64)
360 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
361 /* variants as a differnt platform. */
364 # if defined(__DJGPP__)
367 # define DJGPP /* MSDOS running the DJGPP port of GCC */
369 # define mach_type_known
371 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
374 # define mach_type_known
376 # if defined(__MINGW32__)
379 # define mach_type_known
381 # if defined(__BORLANDC__)
384 # define mach_type_known
386 # if defined(_UTS) && !defined(mach_type_known)
389 # define mach_type_known
393 # define mach_type_known
395 # if defined(__embedded__) && defined(PPC)
398 # define mach_type_known
401 # if defined(__WATCOMC__) && defined(__386__)
403 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
404 # if defined(__OS2__)
407 # if defined(__WINDOWS_386__) || defined(__NT__)
414 # define mach_type_known
416 # if defined(__s390__) && defined(LINUX)
418 # define mach_type_known
420 # if defined(__GNU__)
421 # if defined(__i386__)
422 /* The Debian Hurd running on generic PC */
425 # define mach_type_known
429 /* Feel free to add more clauses here */
431 /* Or manually define the machine type here. A machine type is */
432 /* characterized by the architecture. Some */
433 /* machine types are further subdivided by OS. */
434 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
435 /* Note that SGI IRIX is treated identically to RISCOS. */
436 /* SYSV on an M68K actually means A/UX. */
437 /* The distinction in these cases is usually the stack starting address */
438 # ifndef mach_type_known
439 --> unknown machine type
441 /* Mapping is: M68K ==> Motorola 680X0 */
442 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
443 /* MACOS and AMIGA variants) */
444 /* I386 ==> Intel 386 */
445 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
446 /* FREEBSD, THREE86BSD, MSWIN32, */
447 /* BSDI,SUNOS5, NEXT, other variants) */
448 /* NS32K ==> Encore Multimax */
449 /* MIPS ==> R2000 or R3000 */
450 /* (RISCOS, ULTRIX variants) */
451 /* VAX ==> DEC VAX */
452 /* (BSD, ULTRIX variants) */
453 /* RS6000 ==> IBM RS/6000 AIX3.X */
454 /* RT ==> IBM PC/RT */
455 /* HP_PA ==> HP9000/700 & /800 */
457 /* SPARC ==> SPARC v7/v8/v9 */
458 /* (SUNOS4, SUNOS5, LINUX, */
459 /* DRSNX variants) */
460 /* ALPHA ==> DEC Alpha */
461 /* (OSF1 and LINUX variants) */
462 /* M88K ==> Motorola 88XX0 */
463 /* (CX_UX and DGUX) */
464 /* S370 ==> 370-like machine */
465 /* running Amdahl UTS4 */
466 /* S390 ==> 390-like machine */
468 /* ARM32 ==> Intel StrongARM */
469 /* IA64 ==> Intel IPF */
471 /* (LINUX and HPUX) */
472 /* SH ==> Hitachi SuperH */
473 /* (LINUX & MSWINCE) */
474 /* X86_64 ==> AMD x86-64 */
475 /* POWERPC ==> IBM/Apple PowerPC */
476 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
477 /* LINUX, NETBSD, NOSYS variants) */
481 * For each architecture and OS, the following need to be defined:
483 * CPP_WORD_SZ is a simple integer constant representing the word size.
484 * in bits. We assume byte addressibility, where a byte has 8 bits.
485 * We also assume CPP_WORD_SZ is either 32 or 64.
486 * (We care about the length of pointers, not hardware
487 * bus widths. Thus a 64 bit processor with a C compiler that uses
488 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
490 * MACH_TYPE is a string representation of the machine type.
491 * OS_TYPE is analogous for the OS.
493 * ALIGNMENT is the largest N, such that
494 * all pointer are guaranteed to be aligned on N byte boundaries.
495 * defining it to be 1 will always work, but perform poorly.
497 * DATASTART is the beginning of the data segment.
498 * On some platforms SEARCH_FOR_DATA_START is defined.
499 * SEARCH_FOR_DATASTART will cause GC_data_start to
500 * be set to an address determined by accessing data backwards from _end
501 * until an unmapped page is found. DATASTART will be defined to be
503 * On UNIX-like systems, the collector will scan the area between DATASTART
504 * and DATAEND for root pointers.
506 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
507 * RTH suggests gaining access to linker script synth'd values with
508 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
509 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
510 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
511 * without any special options.
513 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
516 * STACKBOTTOM is the cool end of the stack, which is usually the
517 * highest address in the stack.
518 * Under PCR or OS/2, we have other ways of finding thread stacks.
519 * For each machine, the following should:
520 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
521 * 2) define exactly one of
522 * STACKBOTTOM (should be defined to be an expression)
526 * If STACKBOTTOM is defined, then it's value will be used directly as the
527 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
528 * with a method appropriate for most Linux systems. Currently we look
529 * first for __libc_stack_end, and if that fails read it from /proc.
530 * If either of the last two macros are defined, then STACKBOTTOM is computed
531 * during collector startup using one of the following two heuristics:
532 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
533 * the next multiple of STACK_GRAN.
534 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
535 * in small steps (decrement if STACK_GROWS_UP), and read the value
536 * at each location. Remember the value when the first
537 * Segmentation violation or Bus error is signalled. Round that
538 * to the nearest plausible page boundary, and use that instead
541 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
542 * the value of environ is a pointer that can serve as STACKBOTTOM.
543 * I expect that HEURISTIC2 can be replaced by this approach, which
544 * interferes far less with debugging. However it has the disadvantage
545 * that it's confused by a putenv call before the collector is initialized.
546 * This could be dealt with by intercepting putenv ...
548 * If no expression for STACKBOTTOM can be found, and neither of the above
549 * heuristics are usable, the collector can still be used with all of the above
550 * undefined, provided one of the following is done:
551 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
552 * without reference to STACKBOTTOM. This is appropriate for use in
553 * conjunction with thread packages, since there will be multiple stacks.
554 * (Allocating thread stacks in the heap, and treating them as ordinary
555 * heap data objects is also possible as a last resort. However, this is
556 * likely to introduce significant amounts of excess storage retention
557 * unless the dead parts of the thread stacks are periodically cleared.)
558 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
559 * If the author of the client code controls the main program, this is
560 * easily accomplished by introducing a new main program, setting
561 * GC_stackbottom to the address of a local variable, and then calling
562 * the original main program. The new main program would read something
565 * # include "gc_private.h"
567 * main(argc, argv, envp)
569 * char **argv, **envp;
573 * GC_stackbottom = (ptr_t)(&dummy);
574 * return(real_main(argc, argv, envp));
578 * Each architecture may also define the style of virtual dirty bit
579 * implementation to be used:
580 * MPROTECT_VDB: Write protect the heap and catch faults.
581 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
583 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
584 * defined GC_register_dynamic_libraries() for the architecture.
586 * An architecture may define PREFETCH(x) to preload the cache with *x.
587 * This defaults to a no-op.
589 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
591 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
592 * clear the two words at GC_malloc-aligned address x. By default,
593 * word stores of 0 are used instead.
595 * HEAP_START may be defined as the initial address hint for mmap-based
599 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
600 * to push the relevant registers onto the stack. This generally makes
601 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
603 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
604 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
605 && !defined(__INTEL_COMPILER)
606 # define HAVE_BUILTIN_UNWIND_INIT
609 # define STACK_GRAN 0x1000000
611 # define MACH_TYPE "M68K"
614 # define OS_TYPE "OPENBSD"
617 # define DATASTART GC_data_start
618 # define DYNAMIC_LOADING
621 # define DATASTART ((ptr_t)(etext))
623 # define USE_GENERIC_PUSH_REGS
626 # define OS_TYPE "NETBSD"
629 # define DATASTART GC_data_start
630 # define DYNAMIC_LOADING
633 # define DATASTART ((ptr_t)(etext))
635 # define USE_GENERIC_PUSH_REGS
638 # define OS_TYPE "LINUX"
639 # define STACKBOTTOM ((ptr_t)0xf0000000)
640 # define USE_GENERIC_PUSH_REGS
642 /* We never got around to the assembly version. */
643 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
645 # define DYNAMIC_LOADING
646 # include <features.h>
647 # if defined(__GLIBC__)&& __GLIBC__>=2
648 # define SEARCH_FOR_DATA_START
650 extern char **__environ
;
651 # define DATASTART ((ptr_t)(&__environ))
652 /* hideous kludge: __environ is the first */
653 /* word in crt0.o, and delimits the start */
654 /* of the data segment, no matter which */
655 /* ld options were passed through. */
656 /* We could use _etext instead, but that */
657 /* would include .rodata, which may */
658 /* contain large read-only data tables */
659 /* that we'd rather not scan. */
660 # endif /* !GLIBC2 */
662 # define DATAEND (_end)
665 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
669 # define OS_TYPE "SUNOS4"
671 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
672 # define HEURISTIC1 /* differs */
673 # define DYNAMIC_LOADING
676 # define OS_TYPE "HP"
678 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
679 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
680 /* empirically determined. seems to work. */
682 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
685 # define OS_TYPE "SYSV"
687 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
689 +((word)etext & 0x1fff))
690 /* This only works for shared-text binaries with magic number 0413.
691 The other sorts of SysV binaries put the data at the end of the text,
692 in which case the default of etext would work. Unfortunately,
693 handling both would require having the magic-number available.
696 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
697 /* The stack starts at the top of memory, but */
698 /* 0x0 cannot be used as setjump_test complains */
699 /* that the stack direction is incorrect. Two */
700 /* bytes down from 0x0 should be safe enough. */
702 # include <sys/mmu.h>
703 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
706 # define OS_TYPE "AMIGA"
707 /* STACKBOTTOM and DATASTART handled specially */
709 # define DATAEND /* not needed */
710 # define GETPAGESIZE() 4096
716 # define OS_TYPE "MACOS"
717 /* see os_dep.c for details of global data segments. */
718 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
719 # define DATAEND /* not needed */
720 # define GETPAGESIZE() 4096
723 # define OS_TYPE "NEXT"
724 # define DATASTART ((ptr_t) get_etext())
725 # define STACKBOTTOM ((ptr_t) 0x4000000)
726 # define DATAEND /* not needed */
731 # define MACH_TYPE "POWERPC"
733 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
737 # define OS_TYPE "MACOS"
738 /* see os_dep.c for details of global data segments. */
739 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
740 # define DATAEND /* not needed */
743 # if (defined (powerpc64) || defined(__powerpc64__))
745 # define CPP_WORDSZ 64
749 # define OS_TYPE "LINUX"
750 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
751 /* executable on a 64 bit kernel. */
752 # define LINUX_STACKBOTTOM
753 # define DYNAMIC_LOADING
754 # define SEARCH_FOR_DATA_START
756 # define DATAEND (_end)
760 # define OS_TYPE "DARWIN"
761 # define DYNAMIC_LOADING
762 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
763 These aren't used when dyld support is enabled (it is by default) */
764 # define DATASTART ((ptr_t) get_etext())
765 # define DATAEND ((ptr_t) get_end())
766 # define STACKBOTTOM ((ptr_t) 0xc0000000)
768 # define USE_MMAP_ANON
769 # define USE_ASM_PUSH_REGS
770 /* This is potentially buggy. It needs more testing. See the comments in
772 # define MPROTECT_VDB
774 # define GETPAGESIZE() getpagesize()
775 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
776 /* The performance impact of prefetches is untested */
777 # define PREFETCH(x) \
778 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
779 # define PREFETCH_FOR_WRITE(x) \
780 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
782 /* There seems to be some issues with trylock hanging on darwin. This
783 should be looked into some more */
784 # define NO_PTHREAD_TRYLOCK
788 # define OS_TYPE "NETBSD"
791 # define DATASTART GC_data_start
792 # define DYNAMIC_LOADING
796 # define OS_TYPE "NOSYS"
797 extern void __end
[], __dso_handle
[];
798 # define DATASTART (__dso_handle) /* OK, that's ugly. */
799 # define DATAEND (__end)
800 /* Stack starts at 0xE0000000 for the simulator. */
802 # define STACK_GRAN 0x10000000
808 # define MACH_TYPE "VAX"
809 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
811 # define DATASTART ((ptr_t)(etext))
813 # define OS_TYPE "BSD"
815 /* HEURISTIC2 may be OK, but it's hard to test. */
818 # define OS_TYPE "ULTRIX"
819 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
824 # define MACH_TYPE "RT"
826 # define DATASTART ((ptr_t) 0x10000000)
827 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
831 # define MACH_TYPE "SPARC"
832 # if defined(__arch64__) || defined(__sparcv9)
834 # define CPP_WORDSZ 64
835 # define ELF_CLASS ELFCLASS64
837 # define ALIGNMENT 4 /* Required by hardware */
838 # define CPP_WORDSZ 32
840 # define ALIGN_DOUBLE
842 # define OS_TYPE "SUNOS5"
845 extern ptr_t
GC_SysVGetDataStart();
846 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
847 # define DATAEND (_end)
848 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
850 /* Otherwise we now use calloc. Mmap may result in the */
851 /* heap interleaved with thread stacks, which can result in */
852 /* excessive blacklisting. Sbrk is unusable since it */
853 /* doesn't interact correctly with the system malloc. */
856 # define HEAP_START (ptr_t)0x40000000
858 # define HEAP_START DATAEND
861 /* HEURISTIC1 reportedly no longer works under 2.7. */
862 /* HEURISTIC2 probably works, but this appears to be preferable. */
863 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
864 /* installations that's undefined. We work around this with a */
866 # include <sys/vmparam.h>
868 /* This should work everywhere, but doesn't. */
869 # define STACKBOTTOM USRSTACK
874 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
875 /* getpagesize() appeared to be missing from at least one */
876 /* Solaris 5.4 installation. Weird. */
877 # define DYNAMIC_LOADING
880 # define OS_TYPE "SUNOS4"
881 /* [If you have a weak stomach, don't read this.] */
882 /* We would like to use: */
883 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
884 /* This fails occasionally, due to an ancient, but very */
885 /* persistent ld bug. etext is set 32 bytes too high. */
886 /* We instead read the text segment size from the a.out */
887 /* header, which happens to be mapped into our address space */
888 /* at the start of the text segment. The detective work here */
889 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
890 /* Serpette of INRIA. */
891 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
892 # define TEXTSTART 0x2000
893 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
894 # define MPROTECT_VDB
896 # define DYNAMIC_LOADING
899 # define OS_TYPE "DRSNX"
900 extern ptr_t
GC_SysVGetDataStart();
902 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
903 # define MPROTECT_VDB
904 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
905 # define DYNAMIC_LOADING
908 # define OS_TYPE "LINUX"
910 # define DYNAMIC_LOADING
912 Linux Sparc
/a
.out
not supported
916 # define DATAEND (_end)
918 extern ptr_t
GC_SysVGetDataStart();
920 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
921 /* libc_stack_end is not set reliably for sparc64 */
922 # define STACKBOTTOM ((ptr_t) 0x80000000000ULL)
924 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
925 # define LINUX_STACKBOTTOM
929 # define OS_TYPE "OPENBSD"
930 # define STACKBOTTOM ((ptr_t) 0xf8000000)
932 # define DATASTART ((ptr_t)(etext))
935 # define OS_TYPE "NETBSD"
938 # define DATASTART GC_data_start
939 # define DYNAMIC_LOADING
942 # define DATASTART ((ptr_t)(etext))
948 # define MACH_TYPE "I386"
949 # if defined(__LP64__) || defined(_WIN64)
950 # define CPP_WORDSZ 64
953 # define CPP_WORDSZ 32
955 /* Appears to hold for all "32 bit" compilers */
956 /* except Borland. The -a4 option fixes */
958 /* Ivan Demakov: For Watcom the option is -zp4. */
960 # ifndef SMALL_CONFIG
961 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
962 /* improvement on Pentiums. */
964 # ifdef HAVE_BUILTIN_UNWIND_INIT
965 # define USE_GENERIC_PUSH_REGS
968 # define OS_TYPE "SEQUENT"
970 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
971 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
974 # define OS_TYPE "BEOS"
976 # define GETPAGESIZE() B_PAGE_SIZE
978 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
981 # define OS_TYPE "SUNOS5"
982 extern int _etext
[], _end
[];
983 extern ptr_t
GC_SysVGetDataStart();
984 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
985 # define DATAEND (_end)
986 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
987 /* but reportedly breaks under 2.8. It appears that the stack */
988 /* base is a property of the executable, so this should not break */
989 /* old executables. */
990 /* HEURISTIC2 probably works, but this appears to be preferable. */
992 # define STACKBOTTOM USRSTACK
993 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
994 /* It appears to be fixed in 2.8 and 2.9. */
995 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
998 # define DYNAMIC_LOADING
999 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1001 /* Otherwise we now use calloc. Mmap may result in the */
1002 /* heap interleaved with thread stacks, which can result in */
1003 /* excessive blacklisting. Sbrk is unusable since it */
1004 /* doesn't interact correctly with the system malloc. */
1007 # define HEAP_START (ptr_t)0x40000000
1009 # define HEAP_START DATAEND
1013 # define OS_TYPE "SCO"
1015 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1017 +((word)etext & 0xfff))
1018 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1021 # define OS_TYPE "SCO_ELF"
1023 # define DATASTART ((ptr_t)(etext))
1024 # define STACKBOTTOM ((ptr_t) 0x08048000)
1025 # define DYNAMIC_LOADING
1026 # define ELF_CLASS ELFCLASS32
1029 # define OS_TYPE "DGUX"
1030 extern int _etext
, _end
;
1031 extern ptr_t
GC_SysVGetDataStart();
1032 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1033 # define DATAEND (&_end)
1034 # define STACK_GROWS_DOWN
1036 # include <unistd.h>
1037 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1038 # define DYNAMIC_LOADING
1041 # endif /* USE_MMAP */
1042 # define MAP_FAILED (void *) -1
1044 # define HEAP_START (ptr_t)0x40000000
1045 # else /* USE_MMAP */
1046 # define HEAP_START DATAEND
1047 # endif /* USE_MMAP */
1052 /* The Intel compiler doesn't like inline assembly */
1053 # define USE_GENERIC_PUSH_REGS
1055 # define OS_TYPE "LINUX"
1056 # define LINUX_STACKBOTTOM
1060 # define STACK_GRAN 0x10000000
1061 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1062 /* different kernel configurations. In particular, systems */
1063 /* with 2GB physical memory will usually move the user */
1064 /* address space limit, and hence initial SP to 0x80000000. */
1066 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1067 # define MPROTECT_VDB
1069 /* We seem to get random errors in incremental mode, */
1070 /* possibly because Linux threads is itself a malloc client */
1071 /* and can't deal with the signals. */
1073 # define HEAP_START (ptr_t)0x1000
1074 /* This encourages mmap to give us low addresses, */
1075 /* thus allowing the heap to grow to ~3GB */
1077 # define DYNAMIC_LOADING
1078 # ifdef UNDEFINED /* includes ro data */
1079 extern int _etext
[];
1080 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1082 # include <features.h>
1083 # if defined(__GLIBC__) && __GLIBC__ >= 2
1084 # define SEARCH_FOR_DATA_START
1086 extern char **__environ
;
1087 # define DATASTART ((ptr_t)(&__environ))
1088 /* hideous kludge: __environ is the first */
1089 /* word in crt0.o, and delimits the start */
1090 /* of the data segment, no matter which */
1091 /* ld options were passed through. */
1092 /* We could use _etext instead, but that */
1093 /* would include .rodata, which may */
1094 /* contain large read-only data tables */
1095 /* that we'd rather not scan. */
1098 # define DATAEND (_end)
1101 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1103 # ifdef USE_I686_PREFETCH
1104 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1105 /* for the next rtelease. */
1106 # define PREFETCH(x) \
1107 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1108 /* Empirically prefetcht0 is much more effective at reducing */
1109 /* cache miss stalls for the targetted load instructions. But it */
1110 /* seems to interfere enough with other cache traffic that the net */
1111 /* result is worse than prefetchnta. */
1113 /* Using prefetches for write seems to have a slight negative */
1114 /* impact on performance, at least for a PIII/500. */
1115 # define PREFETCH_FOR_WRITE(x) \
1116 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1119 # ifdef USE_3DNOW_PREFETCH
1120 # define PREFETCH(x) \
1121 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1122 # define PREFETCH_FOR_WRITE(x) \
1123 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1127 # define OS_TYPE "CYGWIN32"
1128 extern int _data_start__
[];
1129 extern int _data_end__
[];
1130 extern int _bss_start__
[];
1131 extern int _bss_end__
[];
1132 /* For binutils 2.9.1, we have */
1133 /* DATASTART = _data_start__ */
1134 /* DATAEND = _bss_end__ */
1135 /* whereas for some earlier versions it was */
1136 /* DATASTART = _bss_start__ */
1137 /* DATAEND = _data_end__ */
1138 /* To get it right for both, we take the */
1139 /* minumum/maximum of the two. */
1141 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1144 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1146 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1147 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1149 # define STACK_GRAN 0x10000
1153 # define OS_TYPE "OS2"
1154 /* STACKBOTTOM and DATASTART are handled specially in */
1155 /* os_dep.c. OS2 actually has the right */
1157 # define DATAEND /* not needed */
1158 # define USE_GENERIC_PUSH_REGS
1161 # define OS_TYPE "MSWIN32"
1162 /* STACKBOTTOM and DATASTART are handled specially in */
1164 # ifndef __WATCOMC__
1165 # define MPROTECT_VDB
1167 # define DATAEND /* not needed */
1170 # define OS_TYPE "MSWINCE"
1171 # define DATAEND /* not needed */
1174 # define OS_TYPE "DJGPP"
1175 # include "stubinfo.h"
1178 extern int __djgpp_stack_limit
;
1179 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1180 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1182 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1183 /* This may not be right. */
1186 # define OS_TYPE "OPENBSD"
1189 # define OS_TYPE "FREEBSD"
1190 # ifndef GC_FREEBSD_THREADS
1191 # define MPROTECT_VDB
1193 # define SIG_SUSPEND SIGUSR1
1194 # define SIG_THR_RESTART SIGUSR2
1195 # define FREEBSD_STACKBOTTOM
1197 # define DYNAMIC_LOADING
1199 extern char etext
[];
1200 extern char * GC_FreeBSDGetDataStart();
1201 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1204 # define OS_TYPE "NETBSD"
1206 # define DYNAMIC_LOADING
1210 # define OS_TYPE "THREE86BSD"
1213 # define OS_TYPE "BSDI"
1215 # if defined(OPENBSD) || defined(NETBSD) \
1216 || defined(THREE86BSD) || defined(BSDI)
1218 extern char etext
[];
1219 # define DATASTART ((ptr_t)(etext))
1222 # define OS_TYPE "NEXT"
1223 # define DATASTART ((ptr_t) get_etext())
1224 # define STACKBOTTOM ((ptr_t)0xc0000000)
1225 # define DATAEND /* not needed */
1228 # define OS_TYPE "DOS4GW"
1229 extern long __nullarea
;
1231 extern char *_STACKTOP
;
1232 /* Depending on calling conventions Watcom C either precedes
1233 or does not precedes with undescore names of C-variables.
1234 Make sure startup code variables always have the same names. */
1235 #pragma aux __nullarea "*";
1236 #pragma aux _end "*";
1237 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1238 /* confused? me too. */
1239 # define DATASTART ((ptr_t) &__nullarea)
1240 # define DATAEND ((ptr_t) &_end)
1243 # define OS_TYPE "HURD"
1244 # define STACK_GROWS_DOWN
1246 extern int __data_start
[];
1247 # define DATASTART ( (ptr_t) (__data_start))
1249 # define DATAEND ( (ptr_t) (_end))
1250 /* # define MPROTECT_VDB Not quite working yet? */
1251 # define DYNAMIC_LOADING
1256 # define MACH_TYPE "NS32K"
1257 # define ALIGNMENT 4
1258 extern char **environ
;
1259 # define DATASTART ((ptr_t)(&environ))
1260 /* hideous kludge: environ is the first */
1261 /* word in crt0.o, and delimits the start */
1262 /* of the data segment, no matter which */
1263 /* ld options were passed through. */
1264 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1268 # define MACH_TYPE "MIPS"
1270 /* This was developed for a linuxce style platform. Probably */
1271 /* needs to be tweaked for workstation class machines. */
1272 # define OS_TYPE "LINUX"
1273 # define DYNAMIC_LOADING
1275 # define DATAEND (_end)
1276 extern int __data_start
[];
1277 # define DATASTART ((ptr_t)(__data_start))
1278 # define ALIGNMENT 4
1279 # define USE_GENERIC_PUSH_REGS
1280 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1281 # define LINUX_STACKBOTTOM
1283 # define STACKBOTTOM 0x80000000
1288 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1289 extern int _fdata
[], _end
[];
1290 # define DATASTART ((ptr_t)_fdata)
1291 # define DATAEND ((ptr_t)_end)
1292 # define CPP_WORDSZ _MIPS_SZPTR
1293 # define ALIGNMENT (_MIPS_SZPTR/8)
1295 extern int etext
[], edata
[], end
[];
1296 extern int _DYNAMIC_LINKING
[], _gp
[];
1297 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1298 + ((word)etext & 0xffff)))
1299 # define DATAEND (edata)
1300 # define DATASTART2 (_DYNAMIC_LINKING \
1301 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1303 # define DATAEND2 (end)
1304 # define ALIGNMENT 4
1306 # define OS_TYPE "EWS4800"
1307 # define USE_GENERIC_PUSH_REGS 1
1311 # define DATASTART (ptr_t)0x10000000
1312 /* Could probably be slightly higher since */
1313 /* startup code allocates lots of stuff. */
1314 # define OS_TYPE "ULTRIX"
1315 # define ALIGNMENT 4
1319 # define DATASTART (ptr_t)0x10000000
1320 # define OS_TYPE "RISCOS"
1321 # define ALIGNMENT 4 /* Required by hardware */
1325 extern int _fdata
[];
1326 # define DATASTART ((ptr_t)(_fdata))
1328 # define HEAP_START (ptr_t)0x30000000
1330 # define HEAP_START DATASTART
1332 /* Lowest plausible heap address. */
1333 /* In the MMAP case, we map there. */
1334 /* In either case it is used to identify */
1335 /* heap sections so they're not */
1336 /* considered as roots. */
1337 # define OS_TYPE "IRIX5"
1338 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1339 /* of recent breakage. */
1341 # define CPP_WORDSZ _MIPS_SZPTR
1342 # define ALIGNMENT (_MIPS_SZPTR/8)
1343 # if CPP_WORDSZ != 64
1344 # define ALIGN_DOUBLE
1347 # define ALIGNMENT 4
1348 # define ALIGN_DOUBLE
1350 # define DYNAMIC_LOADING
1353 # define OS_TYPE "MSWINCE"
1354 # define ALIGNMENT 4
1355 # define DATAEND /* not needed */
1357 # if defined(NETBSD)
1358 # define OS_TYPE "NETBSD"
1359 # define ALIGNMENT 4
1361 # define USE_GENERIC_PUSH_REGS
1364 # define DATASTART GC_data_start
1365 # define NEED_FIND_LIMIT
1366 # define DYNAMIC_LOADING
1368 # define DATASTART ((ptr_t) 0x10000000)
1369 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1375 # define MACH_TYPE "RS6000"
1380 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1383 # define ALIGNMENT 8
1384 # define CPP_WORDSZ 64
1385 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1387 # define ALIGNMENT 4
1388 # define CPP_WORDSZ 32
1389 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1391 /* From AIX linker man page:
1392 _text Specifies the first location of the program.
1393 _etext Specifies the first location after the program.
1394 _data Specifies the first location of the data.
1395 _edata Specifies the first location after the initialized data
1396 _end or end Specifies the first location after all data.
1398 extern int _data
[], _end
[];
1399 # define DATASTART ((ptr_t)((ulong)_data))
1400 # define DATAEND ((ptr_t)((ulong)_end))
1402 # define USE_GENERIC_PUSH_REGS
1403 # define DYNAMIC_LOADING
1404 /* For really old versions of AIX, this may have to be removed. */
1408 # define MACH_TYPE "HP_PA"
1410 # define CPP_WORDSZ 64
1411 # define ALIGNMENT 8
1413 # define CPP_WORDSZ 32
1414 # define ALIGNMENT 4
1415 # define ALIGN_DOUBLE
1417 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1418 # ifndef LINUX /* For now. */
1419 # define MPROTECT_VDB
1422 # define GENERIC_COMPARE_AND_SWAP
1423 /* No compare-and-swap instruction. Use pthread mutexes */
1424 /* when we absolutely have to. */
1425 # ifdef PARALLEL_MARK
1426 # define USE_MARK_BYTES
1427 /* Minimize compare-and-swap usage. */
1430 # define STACK_GROWS_UP
1432 # define OS_TYPE "HPUX"
1433 extern int __data_start
[];
1434 # define DATASTART ((ptr_t)(__data_start))
1436 /* The following appears to work for 7xx systems running HP/UX */
1437 /* 9.xx Furthermore, it might result in much faster */
1438 /* collections than HEURISTIC2, which may involve scanning */
1439 /* segments that directly precede the stack. It is not the */
1440 /* default, since it may not work on older machine/OS */
1441 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1443 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1445 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1446 /* to this. Note that the GC must be initialized before the */
1447 /* first putenv call. */
1448 extern char ** environ
;
1449 # define STACKBOTTOM ((ptr_t)environ)
1451 # define DYNAMIC_LOADING
1452 # include <unistd.h>
1453 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1455 # define PREFETCH(x) { \
1456 register long addr = (long)(x); \
1457 (void) _asm ("LDW", 0, 0, addr, 0); \
1462 # define OS_TYPE "LINUX"
1463 # define LINUX_STACKBOTTOM
1464 # define DYNAMIC_LOADING
1465 # define SEARCH_FOR_DATA_START
1467 # define DATAEND (&_end)
1472 # define MACH_TYPE "ALPHA"
1473 # define ALIGNMENT 8
1474 # define CPP_WORDSZ 64
1476 # define USE_GENERIC_PUSH_REGS
1477 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1478 /* fp registers in some cases when the target is a 21264. The assembly */
1479 /* code doesn't handle that yet, and version dependencies make that a */
1480 /* bit tricky. Do the easy thing for now. */
1483 # define OS_TYPE "NETBSD"
1485 # define DATASTART GC_data_start
1486 # define ELFCLASS32 32
1487 # define ELFCLASS64 64
1488 # define ELF_CLASS ELFCLASS64
1489 # define DYNAMIC_LOADING
1492 # define OS_TYPE "OPENBSD"
1494 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1495 # define DATASTART GC_data_start
1496 # define ELFCLASS32 32
1497 # define ELFCLASS64 64
1498 # define ELF_CLASS ELFCLASS64
1499 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1500 # define DATASTART ((ptr_t) 0x140000000)
1504 # define OS_TYPE "FREEBSD"
1505 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1506 # define SIG_SUSPEND SIGUSR1
1507 # define SIG_THR_RESTART SIGUSR2
1508 # define FREEBSD_STACKBOTTOM
1510 # define DYNAMIC_LOADING
1512 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1513 extern char etext
[];
1514 extern char edata
[];
1516 # define NEED_FIND_LIMIT
1517 # define DATASTART ((ptr_t)(&etext))
1518 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1519 # define DATASTART2 ((ptr_t)(&edata))
1520 # define DATAEND2 ((ptr_t)(&end))
1523 # define OS_TYPE "OSF1"
1524 # define DATASTART ((ptr_t) 0x140000000)
1526 # define DATAEND ((ptr_t) &_end)
1527 extern char ** environ
;
1528 /* round up from the value of environ to the nearest page boundary */
1529 /* Probably breaks if putenv is called before collector */
1530 /* initialization. */
1531 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1532 /* # define HEURISTIC2 */
1533 /* Normally HEURISTIC2 is too conervative, since */
1534 /* the text segment immediately follows the stack. */
1535 /* Hence we give an upper pound. */
1536 /* This is currently unused, since we disabled HEURISTIC2 */
1537 extern int __start
[];
1538 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1539 # ifndef GC_OSF1_THREADS
1540 /* Unresolved signal issues with threads. */
1541 # define MPROTECT_VDB
1543 # define DYNAMIC_LOADING
1546 # define OS_TYPE "LINUX"
1547 # define STACKBOTTOM ((ptr_t) 0x120000000)
1549 # define SEARCH_FOR_DATA_START
1550 # define DYNAMIC_LOADING
1552 # define DATASTART ((ptr_t) 0x140000000)
1555 # define DATAEND (_end)
1556 # define MPROTECT_VDB
1557 /* Has only been superficially tested. May not */
1558 /* work on all versions. */
1563 # define MACH_TYPE "IA64"
1564 # define USE_GENERIC_PUSH_REGS
1565 /* We need to get preserved registers in addition to register */
1566 /* windows. That's easiest to do with setjmp. */
1567 # ifdef PARALLEL_MARK
1568 # define USE_MARK_BYTES
1569 /* Compare-and-exchange is too expensive to use for */
1570 /* setting mark bits. */
1574 # define CPP_WORDSZ 32
1575 # define ALIGN_DOUBLE
1576 /* Requires 8 byte alignment for malloc */
1577 # define ALIGNMENT 4
1582 # define CPP_WORDSZ 64
1583 # define ALIGN_DOUBLE
1584 /* Requires 16 byte alignment for malloc */
1585 # define ALIGNMENT 8
1587 # define OS_TYPE "HPUX"
1588 extern int __data_start
[];
1589 # define DATASTART ((ptr_t)(__data_start))
1590 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1591 /* to this. Note that the GC must be initialized before the */
1592 /* first putenv call. */
1593 extern char ** environ
;
1594 # define STACKBOTTOM ((ptr_t)environ)
1595 # define HPUX_STACKBOTTOM
1596 # define DYNAMIC_LOADING
1597 # include <unistd.h>
1598 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1599 /* The following was empirically determined, and is probably */
1600 /* not very robust. */
1601 /* Note that the backing store base seems to be at a nice */
1602 /* address minus one page. */
1603 # define BACKING_STORE_DISPLACEMENT 0x1000000
1604 # define BACKING_STORE_ALIGNMENT 0x1000
1605 extern ptr_t GC_register_stackbottom
;
1606 # define BACKING_STORE_BASE GC_register_stackbottom
1607 /* Known to be wrong for recent HP/UX versions!!! */
1610 # define CPP_WORDSZ 64
1611 # define ALIGN_DOUBLE
1612 /* Requires 16 byte alignment for malloc */
1613 # define ALIGNMENT 8
1614 # define OS_TYPE "LINUX"
1615 /* The following works on NUE and older kernels: */
1616 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1617 /* This does not work on NUE: */
1618 # define LINUX_STACKBOTTOM
1619 /* We also need the base address of the register stack */
1620 /* backing store. This is computed in */
1621 /* GC_linux_register_stack_base based on the following */
1623 # define BACKING_STORE_ALIGNMENT 0x100000
1624 # define BACKING_STORE_DISPLACEMENT 0x80000000
1625 extern ptr_t GC_register_stackbottom
;
1626 # define BACKING_STORE_BASE GC_register_stackbottom
1627 # define SEARCH_FOR_DATA_START
1629 # define DYNAMIC_LOADING
1631 /* In the Intel compiler environment, we seem to end up with */
1632 /* statically linked executables and an undefined reference */
1635 # define MPROTECT_VDB
1636 /* Requires Linux 2.3.47 or later. */
1638 # define DATAEND (_end)
1640 # ifndef __INTEL_COMPILER
1641 # define PREFETCH(x) \
1642 __asm__ (" lfetch [%0]": : "r"(x))
1643 # define PREFETCH_FOR_WRITE(x) \
1644 __asm__ (" lfetch.excl [%0]": : "r"(x))
1645 # define CLEAR_DOUBLE(x) \
1646 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1648 # include <ia64intrin.h>
1649 # define PREFETCH(x) \
1650 __lfetch(__lfhint_none, (x))
1651 # define PREFETCH_FOR_WRITE(x) \
1652 __lfetch(__lfhint_nta, (x))
1653 # define CLEAR_DOUBLE(x) \
1654 __stf_spill((void *)(x), 0)
1655 # endif // __INTEL_COMPILER
1659 /* FIXME: This is a very partial guess. There is no port, yet. */
1660 # define OS_TYPE "MSWIN32"
1661 /* STACKBOTTOM and DATASTART are handled specially in */
1663 # define DATAEND /* not needed */
1664 # if defined(_WIN64)
1665 # define CPP_WORDSZ 64
1667 # define CPP_WORDSZ 32 /* Is this possible? */
1669 # define ALIGNMENT 8
1674 # define MACH_TYPE "M88K"
1675 # define ALIGNMENT 4
1676 # define ALIGN_DOUBLE
1679 # define OS_TYPE "CX_UX"
1680 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1683 # define OS_TYPE "DGUX"
1684 extern ptr_t
GC_SysVGetDataStart();
1685 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1687 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1691 /* If this still works, and if anyone cares, this should probably */
1692 /* be moved to the S390 category. */
1693 # define MACH_TYPE "S370"
1694 # define ALIGNMENT 4 /* Required by hardware */
1695 # define USE_GENERIC_PUSH_REGS
1697 # define OS_TYPE "UTS4"
1699 extern int _etext
[];
1701 extern ptr_t
GC_SysVGetDataStart();
1702 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1703 # define DATAEND (_end)
1709 # define MACH_TYPE "S390"
1710 # define USE_GENERIC_PUSH_REGS
1712 # define ALIGNMENT 4
1713 # define CPP_WORDSZ 32
1715 # define ALIGNMENT 8
1716 # define CPP_WORDSZ 64
1717 # define HBLKSIZE 4096
1720 # define OS_TYPE "LINUX"
1721 # define LINUX_STACKBOTTOM
1722 # define DYNAMIC_LOADING
1723 extern int __data_start
[];
1724 # define DATASTART ((ptr_t)(__data_start))
1726 # define DATAEND (_end)
1727 # define CACHE_LINE_SIZE 256
1728 # define GETPAGESIZE() 4096
1733 # define ALIGNMENT 4
1734 extern int _etext
[];
1735 # define DATASTART ((ptr_t)(_etext))
1740 # define CPP_WORDSZ 32
1741 # define MACH_TYPE "ARM32"
1742 # define ALIGNMENT 4
1744 # define OS_TYPE "NETBSD"
1747 # define DATASTART GC_data_start
1748 # define DYNAMIC_LOADING
1750 extern char etext
[];
1751 # define DATASTART ((ptr_t)(etext))
1753 # define USE_GENERIC_PUSH_REGS
1756 # define OS_TYPE "LINUX"
1759 # define STACK_GRAN 0x10000000
1760 # define USE_GENERIC_PUSH_REGS
1762 # define DYNAMIC_LOADING
1763 # include <features.h>
1764 # if defined(__GLIBC__) && __GLIBC__ >= 2
1765 # define SEARCH_FOR_DATA_START
1767 extern char **__environ
;
1768 # define DATASTART ((ptr_t)(&__environ))
1769 /* hideous kludge: __environ is the first */
1770 /* word in crt0.o, and delimits the start */
1771 /* of the data segment, no matter which */
1772 /* ld options were passed through. */
1773 /* We could use _etext instead, but that */
1774 /* would include .rodata, which may */
1775 /* contain large read-only data tables */
1776 /* that we'd rather not scan. */
1779 # define DATAEND (_end)
1782 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1786 # define OS_TYPE "MSWINCE"
1787 # define DATAEND /* not needed */
1790 /* __data_start is usually defined in the target linker script. */
1791 extern int __data_start
[];
1792 # define DATASTART (ptr_t)(__data_start)
1793 # define USE_GENERIC_PUSH_REGS
1794 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1795 extern void *__stack_base__
;
1796 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1801 # define MACH_TYPE "SH"
1802 # define ALIGNMENT 4
1804 # define OS_TYPE "MSWINCE"
1805 # define DATAEND /* not needed */
1808 # define OS_TYPE "LINUX"
1809 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1810 # define USE_GENERIC_PUSH_REGS
1811 # define DYNAMIC_LOADING
1812 # define SEARCH_FOR_DATA_START
1814 # define DATAEND (_end)
1819 # define MACH_TYPE "SH4"
1820 # define OS_TYPE "MSWINCE"
1821 # define ALIGNMENT 4
1822 # define DATAEND /* not needed */
1826 # define CPP_WORDSZ 32
1827 # define MACH_TYPE "M32R"
1828 # define ALIGNMENT 4
1830 # define OS_TYPE "LINUX"
1831 # define LINUX_STACKBOTTOM
1833 # define STACK_GRAN 0x10000000
1834 # define USE_GENERIC_PUSH_REGS
1835 # define DYNAMIC_LOADING
1836 # define SEARCH_FOR_DATA_START
1838 # define DATAEND (_end)
1843 # define MACH_TYPE "X86_64"
1844 # define ALIGNMENT 8
1845 # define CPP_WORDSZ 64
1847 # define HBLKSIZE 4096
1849 # define CACHE_LINE_SIZE 64
1850 # define USE_GENERIC_PUSH_REGS
1852 # define OS_TYPE "LINUX"
1853 # define LINUX_STACKBOTTOM
1854 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1855 # define MPROTECT_VDB
1857 /* We seem to get random errors in incremental mode, */
1858 /* possibly because Linux threads is itself a malloc client */
1859 /* and can't deal with the signals. */
1862 # define DYNAMIC_LOADING
1863 # ifdef UNDEFINED /* includes ro data */
1864 extern int _etext
[];
1865 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1867 # include <features.h>
1868 # define SEARCH_FOR_DATA_START
1870 # define DATAEND (_end)
1873 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1875 # if defined(__GNUC__) && __GNUC >= 3
1876 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1877 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1881 # define OS_TYPE "NETBSD"
1883 # define DYNAMIC_LOADING
1886 extern char etext
[];
1887 # define SEARCH_FOR_DATA_START
1891 #if defined(LINUX) && defined(USE_MMAP)
1892 /* The kernel may do a somewhat better job merging mappings etc. */
1893 /* with anonymous mappings. */
1894 # define USE_MMAP_ANON
1897 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1898 /* Rld appears to allocate some memory with its own allocator, and */
1899 /* some through malloc, which might be redirected. To make this */
1900 /* work with collectable memory, we have to scan memory allocated */
1901 /* by rld's internal malloc. */
1902 # define USE_PROC_FOR_LIBRARIES
1905 # ifndef STACK_GROWS_UP
1906 # define STACK_GROWS_DOWN
1910 # define CPP_WORDSZ 32
1919 # define DATAEND (end)
1922 # if defined(SVR4) && !defined(GETPAGESIZE)
1923 # include <unistd.h>
1924 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1927 # ifndef GETPAGESIZE
1928 # if defined(SUNOS5) || defined(IRIX5)
1929 # include <unistd.h>
1931 # define GETPAGESIZE() getpagesize()
1934 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1935 /* OS has SVR4 generic features. Probably others also qualify. */
1939 # if defined(SUNOS5) || defined(DRSNX)
1940 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1943 /* OS has SUNOS5 style signal handlers. */
1951 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
1955 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
1956 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1957 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
1958 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
1959 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1962 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1967 # undef DYNAMIC_LOADING
1972 # undef MPROTECT_VDB
1977 /* Postponed for now. */
1979 # undef MPROTECT_VDB
1982 # ifdef SMALL_CONFIG
1983 /* Presumably not worth the space it takes. */
1985 # undef MPROTECT_VDB
1989 # undef MPROTECT_VDB /* Can't deal with address space holes. */
1992 # ifdef PARALLEL_MARK
1993 # undef MPROTECT_VDB /* For now. */
1996 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
1997 # define DEFAULT_VDB
2001 # define PREFETCH(x)
2002 # define NO_PREFETCH
2005 # ifndef PREFETCH_FOR_WRITE
2006 # define PREFETCH_FOR_WRITE(x)
2007 # define NO_PREFETCH_FOR_WRITE
2010 # ifndef CACHE_LINE_SIZE
2011 # define CACHE_LINE_SIZE 32 /* Wild guess */
2015 # define REGISTER_LIBRARIES_EARLY
2016 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2017 /* lock. This isn't safe after the world has stopped. So we must */
2018 /* call GC_register_dynamic_libraries before stopping the world. */
2019 /* For performance reasons, this may be beneficial on other */
2020 /* platforms as well, though it should be avoided in win32. */
2023 # if defined(SEARCH_FOR_DATA_START)
2024 extern ptr_t GC_data_start
;
2025 # define DATASTART GC_data_start
2028 # ifndef CLEAR_DOUBLE
2029 # define CLEAR_DOUBLE(x) \
2030 ((word*)x)[0] = 0; \
2032 # endif /* CLEAR_DOUBLE */
2034 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2035 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2036 # define GC_SOLARIS_THREADS
2039 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2040 --> inconsistent configuration
2042 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2043 --> inconsistent configuration
2045 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2046 --> inconsistent configuration
2048 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2049 --> inconsistent configuration
2051 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2052 --> inconsistent configuration
2054 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2055 --> inconsistent configuration
2058 # if defined(PCR) || defined(SRC_M3) || \
2059 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2060 defined(GC_PTHREADS)
2064 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
2065 || defined(LINT) || defined(MSWINCE) || defined(ARM32) \
2066 || (defined(I386) && defined(__LCC__))
2067 /* Use setjmp based hack to mark from callee-save registers. */
2068 /* The define should move to the individual platform */
2070 # define USE_GENERIC_PUSH_REGS
2073 # if defined(MSWINCE)
2078 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2079 /* include assembly code to do it well. */
2082 /* Can we save call chain in objects for debugging? */
2083 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2084 /* frame) to reasonable values for the platform. */
2085 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2086 /* at build time, though we feel free to adjust it slightly. */
2087 /* Define NEED_CALLINFO if we either save the call stack or */
2088 /* GC_ADD_CALLER is defined. */
2089 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2092 # define CAN_SAVE_CALL_ARGS
2094 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2095 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2096 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2097 # define CAN_SAVE_CALL_ARGS
2100 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2101 && defined(GC_CAN_SAVE_CALL_STACKS)
2102 # define SAVE_CALL_CHAIN
2104 # ifdef SAVE_CALL_CHAIN
2105 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2106 # define NARGS SAVE_CALL_NARGS
2108 # define NARGS 0 /* Number of arguments to save for each call. */
2111 # ifdef SAVE_CALL_CHAIN
2112 # ifndef SAVE_CALL_COUNT
2113 # define NFRAMES 6 /* Number of frames to save. Even for */
2114 /* alignment reasons. */
2116 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2118 # define NEED_CALLINFO
2119 # endif /* SAVE_CALL_CHAIN */
2120 # ifdef GC_ADD_CALLER
2123 # define NEED_CALLINFO
2126 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2127 # define DBG_HDRS_ALL
2130 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2131 # define POINTER_SHIFT 0
2134 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2135 # define POINTER_MASK ((GC_word)(-1))
2138 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2139 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2142 # if defined(FIXUP_POINTER)
2143 # define NEED_FIXUP_POINTER 1
2145 # define NEED_FIXUP_POINTER 0
2146 # define FIXUP_POINTER(p)
2150 /* This relies on some type definitions from gc_priv.h, from */
2151 /* where it's normally included. */
2153 /* How to get heap memory from the OS: */
2154 /* Note that sbrk()-like allocation is preferred, since it */
2155 /* usually makes it possible to merge consecutively allocated */
2156 /* chunks. It also avoids unintented recursion with */
2157 /* -DREDIRECT_MALLOC. */
2158 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2159 /* 0 is taken to mean failure. */
2160 /* In the case os USE_MMAP, the argument must also be a */
2161 /* physical page size. */
2162 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2163 /* though we should perhaps take advantage of the case in which */
2165 struct hblk
; /* See gc_priv.h. */
2167 char * real_malloc();
2168 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2172 void * os2_alloc(size_t bytes
);
2173 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2177 # if defined(NEXT) || defined(DOS4GW) || \
2178 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2179 (defined(SUNOS5) && !defined(USE_MMAP))
2180 # define GET_MEM(bytes) HBLKPTR((size_t) \
2181 calloc(1, (size_t)bytes + GC_page_size) \
2185 extern ptr_t
GC_win32_get_mem();
2186 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2189 # if defined(USE_TEMPORARY_MEMORY)
2190 extern Ptr
GC_MacTemporaryNewPtr(size_t size
,
2191 Boolean clearMemory
);
2192 # define GET_MEM(bytes) HBLKPTR( \
2193 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2196 # define GET_MEM(bytes) HBLKPTR( \
2197 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2201 extern ptr_t
GC_wince_get_mem();
2202 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2204 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2205 extern void *GC_amiga_get_mem(size_t size
);
2206 # define GET_MEM(bytes) HBLKPTR((size_t) \
2207 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2210 extern ptr_t
GC_unix_get_mem();
2211 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2220 #endif /* GC_PRIVATE_H */
2222 # endif /* GCCONFIG_H */