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(__alpha) || defined(__alpha__)
254 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
255 # define OSF1 /* a.k.a Digital Unix */
257 # define mach_type_known
259 # if defined(_AMIGA) && !defined(AMIGA)
264 # define mach_type_known
266 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
269 # define mach_type_known
271 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
274 # define mach_type_known
276 # if defined(macosx) || \
277 defined(__APPLE__) && defined(__MACH__) && defined(__ppc__)
280 # define mach_type_known
282 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
285 --> Not really supported, but at least we recognize it.
287 # if defined(NeXT) && defined(mc68000)
290 # define mach_type_known
292 # if defined(NeXT) && (defined(i386) || defined(__i386__))
295 # define mach_type_known
297 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
300 # define mach_type_known
302 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
304 # define mach_type_known
306 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
308 # define mach_type_known
310 # if defined(__NetBSD__) && defined(__x86_64__)
312 # define mach_type_known
314 # if defined(bsdi) && (defined(i386) || defined(__i386__))
317 # define mach_type_known
319 # if !defined(mach_type_known) && defined(__386BSD__)
322 # define mach_type_known
324 # if defined(_CX_UX) && defined(_M88K)
327 # define mach_type_known
329 # if defined(DGUX) && defined(m88k)
332 # define mach_type_known
334 # if defined(_WIN32_WCE)
335 /* SH3, SH4, MIPS already defined for corresponding architectures */
336 # if defined(SH3) || defined(SH4)
346 # define mach_type_known
348 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
349 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
351 # define MSWIN32 /* or Win32s */
352 # define mach_type_known
354 # if defined(_MSC_VER) && defined(_M_IA64)
356 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
357 /* variants as a differnt platform. */
360 # if defined(__DJGPP__)
363 # define DJGPP /* MSDOS running the DJGPP port of GCC */
365 # define mach_type_known
367 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
370 # define mach_type_known
372 # if defined(__MINGW32__)
375 # define mach_type_known
377 # if defined(__BORLANDC__)
380 # define mach_type_known
382 # if defined(_UTS) && !defined(mach_type_known)
385 # define mach_type_known
389 # define mach_type_known
391 # if defined(__embedded__) && defined(PPC)
394 # define mach_type_known
397 # if defined(__WATCOMC__) && defined(__386__)
399 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
400 # if defined(__OS2__)
403 # if defined(__WINDOWS_386__) || defined(__NT__)
410 # define mach_type_known
412 # if defined(__s390__) && defined(LINUX)
414 # define mach_type_known
416 # if defined(__GNU__)
417 # if defined(__i386__)
418 /* The Debian Hurd running on generic PC */
421 # define mach_type_known
425 /* Feel free to add more clauses here */
427 /* Or manually define the machine type here. A machine type is */
428 /* characterized by the architecture. Some */
429 /* machine types are further subdivided by OS. */
430 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
431 /* Note that SGI IRIX is treated identically to RISCOS. */
432 /* SYSV on an M68K actually means A/UX. */
433 /* The distinction in these cases is usually the stack starting address */
434 # ifndef mach_type_known
435 --> unknown machine type
437 /* Mapping is: M68K ==> Motorola 680X0 */
438 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
439 /* MACOS and AMIGA variants) */
440 /* I386 ==> Intel 386 */
441 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
442 /* FREEBSD, THREE86BSD, MSWIN32, */
443 /* BSDI,SUNOS5, NEXT, other variants) */
444 /* NS32K ==> Encore Multimax */
445 /* MIPS ==> R2000 or R3000 */
446 /* (RISCOS, ULTRIX variants) */
447 /* VAX ==> DEC VAX */
448 /* (BSD, ULTRIX variants) */
449 /* RS6000 ==> IBM RS/6000 AIX3.X */
450 /* RT ==> IBM PC/RT */
451 /* HP_PA ==> HP9000/700 & /800 */
453 /* SPARC ==> SPARC v7/v8/v9 */
454 /* (SUNOS4, SUNOS5, LINUX, */
455 /* DRSNX variants) */
456 /* ALPHA ==> DEC Alpha */
457 /* (OSF1 and LINUX variants) */
458 /* M88K ==> Motorola 88XX0 */
459 /* (CX_UX and DGUX) */
460 /* S370 ==> 370-like machine */
461 /* running Amdahl UTS4 */
462 /* S390 ==> 390-like machine */
464 /* ARM32 ==> Intel StrongARM */
465 /* IA64 ==> Intel IPF */
467 /* (LINUX and HPUX) */
468 /* SH ==> Hitachi SuperH */
469 /* (LINUX & MSWINCE) */
470 /* X86_64 ==> AMD x86-64 */
471 /* POWERPC ==> IBM/Apple PowerPC */
472 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
473 /* LINUX, NETBSD, NOSYS variants) */
477 * For each architecture and OS, the following need to be defined:
479 * CPP_WORD_SZ is a simple integer constant representing the word size.
480 * in bits. We assume byte addressibility, where a byte has 8 bits.
481 * We also assume CPP_WORD_SZ is either 32 or 64.
482 * (We care about the length of pointers, not hardware
483 * bus widths. Thus a 64 bit processor with a C compiler that uses
484 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
486 * MACH_TYPE is a string representation of the machine type.
487 * OS_TYPE is analogous for the OS.
489 * ALIGNMENT is the largest N, such that
490 * all pointer are guaranteed to be aligned on N byte boundaries.
491 * defining it to be 1 will always work, but perform poorly.
493 * DATASTART is the beginning of the data segment.
494 * On some platforms SEARCH_FOR_DATA_START is defined.
495 * SEARCH_FOR_DATASTART will cause GC_data_start to
496 * be set to an address determined by accessing data backwards from _end
497 * until an unmapped page is found. DATASTART will be defined to be
499 * On UNIX-like systems, the collector will scan the area between DATASTART
500 * and DATAEND for root pointers.
502 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
503 * RTH suggests gaining access to linker script synth'd values with
504 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
505 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
506 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
507 * without any special options.
509 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
512 * STACKBOTTOM is the cool end of the stack, which is usually the
513 * highest address in the stack.
514 * Under PCR or OS/2, we have other ways of finding thread stacks.
515 * For each machine, the following should:
516 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
517 * 2) define exactly one of
518 * STACKBOTTOM (should be defined to be an expression)
522 * If STACKBOTTOM is defined, then it's value will be used directly as the
523 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
524 * with a method appropriate for most Linux systems. Currently we look
525 * first for __libc_stack_end, and if that fails read it from /proc.
526 * If either of the last two macros are defined, then STACKBOTTOM is computed
527 * during collector startup using one of the following two heuristics:
528 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
529 * the next multiple of STACK_GRAN.
530 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
531 * in small steps (decrement if STACK_GROWS_UP), and read the value
532 * at each location. Remember the value when the first
533 * Segmentation violation or Bus error is signalled. Round that
534 * to the nearest plausible page boundary, and use that instead
537 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
538 * the value of environ is a pointer that can serve as STACKBOTTOM.
539 * I expect that HEURISTIC2 can be replaced by this approach, which
540 * interferes far less with debugging. However it has the disadvantage
541 * that it's confused by a putenv call before the collector is initialized.
542 * This could be dealt with by intercepting putenv ...
544 * If no expression for STACKBOTTOM can be found, and neither of the above
545 * heuristics are usable, the collector can still be used with all of the above
546 * undefined, provided one of the following is done:
547 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
548 * without reference to STACKBOTTOM. This is appropriate for use in
549 * conjunction with thread packages, since there will be multiple stacks.
550 * (Allocating thread stacks in the heap, and treating them as ordinary
551 * heap data objects is also possible as a last resort. However, this is
552 * likely to introduce significant amounts of excess storage retention
553 * unless the dead parts of the thread stacks are periodically cleared.)
554 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
555 * If the author of the client code controls the main program, this is
556 * easily accomplished by introducing a new main program, setting
557 * GC_stackbottom to the address of a local variable, and then calling
558 * the original main program. The new main program would read something
561 * # include "gc_private.h"
563 * main(argc, argv, envp)
565 * char **argv, **envp;
569 * GC_stackbottom = (ptr_t)(&dummy);
570 * return(real_main(argc, argv, envp));
574 * Each architecture may also define the style of virtual dirty bit
575 * implementation to be used:
576 * MPROTECT_VDB: Write protect the heap and catch faults.
577 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
579 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
580 * defined GC_register_dynamic_libraries() for the architecture.
582 * An architecture may define PREFETCH(x) to preload the cache with *x.
583 * This defaults to a no-op.
585 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
587 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
588 * clear the two words at GC_malloc-aligned address x. By default,
589 * word stores of 0 are used instead.
591 * HEAP_START may be defined as the initial address hint for mmap-based
595 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
596 * to push the relevant registers onto the stack. This generally makes
597 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
599 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
600 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
601 && !defined(__INTEL_COMPILER)
602 # define HAVE_BUILTIN_UNWIND_INIT
605 # define STACK_GRAN 0x1000000
607 # define MACH_TYPE "M68K"
610 # define OS_TYPE "OPENBSD"
613 # define DATASTART GC_data_start
614 # define DYNAMIC_LOADING
617 # define DATASTART ((ptr_t)(etext))
619 # define USE_GENERIC_PUSH_REGS
622 # define OS_TYPE "NETBSD"
625 # define DATASTART GC_data_start
626 # define DYNAMIC_LOADING
629 # define DATASTART ((ptr_t)(etext))
631 # define USE_GENERIC_PUSH_REGS
634 # define OS_TYPE "LINUX"
635 # define STACKBOTTOM ((ptr_t)0xf0000000)
636 # define USE_GENERIC_PUSH_REGS
638 /* We never got around to the assembly version. */
639 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
641 # define DYNAMIC_LOADING
642 # include <features.h>
643 # if defined(__GLIBC__)&& __GLIBC__>=2
644 # define SEARCH_FOR_DATA_START
646 extern char **__environ;
647 # define DATASTART ((ptr_t)(&__environ))
648 /* hideous kludge: __environ is the first */
649 /* word in crt0.o, and delimits the start */
650 /* of the data segment, no matter which */
651 /* ld options were passed through. */
652 /* We could use _etext instead, but that */
653 /* would include .rodata, which may */
654 /* contain large read-only data tables */
655 /* that we'd rather not scan. */
656 # endif /* !GLIBC2 */
658 # define DATAEND (_end)
661 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
665 # define OS_TYPE "SUNOS4"
667 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
668 # define HEURISTIC1 /* differs */
669 # define DYNAMIC_LOADING
672 # define OS_TYPE "HP"
674 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
675 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
676 /* empirically determined. seems to work. */
678 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
681 # define OS_TYPE "SYSV"
683 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
685 +((word)etext & 0x1fff))
686 /* This only works for shared-text binaries with magic number 0413.
687 The other sorts of SysV binaries put the data at the end of the text,
688 in which case the default of etext would work. Unfortunately,
689 handling both would require having the magic-number available.
692 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
693 /* The stack starts at the top of memory, but */
694 /* 0x0 cannot be used as setjump_test complains */
695 /* that the stack direction is incorrect. Two */
696 /* bytes down from 0x0 should be safe enough. */
698 # include <sys/mmu.h>
699 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
702 # define OS_TYPE "AMIGA"
703 /* STACKBOTTOM and DATASTART handled specially */
705 # define DATAEND /* not needed */
706 # define GETPAGESIZE() 4096
712 # define OS_TYPE "MACOS"
713 /* see os_dep.c for details of global data segments. */
714 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
715 # define DATAEND /* not needed */
716 # define GETPAGESIZE() 4096
719 # define OS_TYPE "NEXT"
720 # define DATASTART ((ptr_t) get_etext())
721 # define STACKBOTTOM ((ptr_t) 0x4000000)
722 # define DATAEND /* not needed */
727 # define MACH_TYPE "POWERPC"
729 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
733 # define OS_TYPE "MACOS"
734 /* see os_dep.c for details of global data segments. */
735 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
736 # define DATAEND /* not needed */
739 # if (defined (powerpc64) || defined(__powerpc64__))
741 # define CPP_WORDSZ 64
745 # define OS_TYPE "LINUX"
746 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
747 /* executable on a 64 bit kernel. */
748 # define LINUX_STACKBOTTOM
749 # define DYNAMIC_LOADING
750 # define SEARCH_FOR_DATA_START
752 # define DATAEND (_end)
756 # define OS_TYPE "DARWIN"
757 # define DYNAMIC_LOADING
758 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
759 These aren't used when dyld support is enabled (it is by default) */
760 # define DATASTART ((ptr_t) get_etext())
761 # define DATAEND ((ptr_t) get_end())
762 # define STACKBOTTOM ((ptr_t) 0xc0000000)
764 # define USE_MMAP_ANON
765 # define USE_ASM_PUSH_REGS
766 /* This is potentially buggy. It needs more testing. See the comments in
768 # define MPROTECT_VDB
770 # define GETPAGESIZE() getpagesize()
771 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
772 /* The performance impact of prefetches is untested */
773 # define PREFETCH(x) \
774 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
775 # define PREFETCH_FOR_WRITE(x) \
776 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
778 /* There seems to be some issues with trylock hanging on darwin. This
779 should be looked into some more */
780 # define NO_PTHREAD_TRYLOCK
784 # define OS_TYPE "NETBSD"
787 # define DATASTART GC_data_start
788 # define DYNAMIC_LOADING
792 # define OS_TYPE "NOSYS"
793 extern void __end[], __dso_handle[];
794 # define DATASTART (__dso_handle) /* OK, that's ugly. */
795 # define DATAEND (__end)
796 /* Stack starts at 0xE0000000 for the simulator. */
798 # define STACK_GRAN 0x10000000
804 # define MACH_TYPE "VAX"
805 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
807 # define DATASTART ((ptr_t)(etext))
809 # define OS_TYPE "BSD"
811 /* HEURISTIC2 may be OK, but it's hard to test. */
814 # define OS_TYPE "ULTRIX"
815 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
820 # define MACH_TYPE "RT"
822 # define DATASTART ((ptr_t) 0x10000000)
823 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
827 # define MACH_TYPE "SPARC"
828 # if defined(__arch64__) || defined(__sparcv9)
830 # define CPP_WORDSZ 64
831 # define ELF_CLASS ELFCLASS64
833 # define ALIGNMENT 4 /* Required by hardware */
834 # define CPP_WORDSZ 32
836 # define ALIGN_DOUBLE
838 # define OS_TYPE "SUNOS5"
841 extern ptr_t GC_SysVGetDataStart();
842 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
843 # define DATAEND (_end)
844 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
846 /* Otherwise we now use calloc. Mmap may result in the */
847 /* heap interleaved with thread stacks, which can result in */
848 /* excessive blacklisting. Sbrk is unusable since it */
849 /* doesn't interact correctly with the system malloc. */
852 # define HEAP_START (ptr_t)0x40000000
854 # define HEAP_START DATAEND
857 /* HEURISTIC1 reportedly no longer works under 2.7. */
858 /* HEURISTIC2 probably works, but this appears to be preferable. */
859 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
860 /* installations that's undefined. We work around this with a */
862 # include <sys/vmparam.h>
864 /* This should work everywhere, but doesn't. */
865 # define STACKBOTTOM USRSTACK
870 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
871 /* getpagesize() appeared to be missing from at least one */
872 /* Solaris 5.4 installation. Weird. */
873 # define DYNAMIC_LOADING
876 # define OS_TYPE "SUNOS4"
877 /* [If you have a weak stomach, don't read this.] */
878 /* We would like to use: */
879 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
880 /* This fails occasionally, due to an ancient, but very */
881 /* persistent ld bug. etext is set 32 bytes too high. */
882 /* We instead read the text segment size from the a.out */
883 /* header, which happens to be mapped into our address space */
884 /* at the start of the text segment. The detective work here */
885 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
886 /* Serpette of INRIA. */
887 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
888 # define TEXTSTART 0x2000
889 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
890 # define MPROTECT_VDB
892 # define DYNAMIC_LOADING
895 # define OS_TYPE "DRSNX"
896 extern ptr_t GC_SysVGetDataStart();
898 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
899 # define MPROTECT_VDB
900 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
901 # define DYNAMIC_LOADING
904 # define OS_TYPE "LINUX"
906 # define DYNAMIC_LOADING
908 Linux Sparc/a.out not supported
912 # define DATAEND (_end)
914 extern ptr_t GC_SysVGetDataStart();
916 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
917 /* libc_stack_end is not set reliably for sparc64 */
918 # define STACKBOTTOM ((ptr_t) 0x80000000000ULL)
920 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
921 # define LINUX_STACKBOTTOM
925 # define OS_TYPE "OPENBSD"
926 # define STACKBOTTOM ((ptr_t) 0xf8000000)
928 # define DATASTART ((ptr_t)(etext))
931 # define OS_TYPE "NETBSD"
934 # define DATASTART GC_data_start
935 # define DYNAMIC_LOADING
938 # define DATASTART ((ptr_t)(etext))
944 # define MACH_TYPE "I386"
945 # if defined(__LP64__) || defined(_WIN64)
946 # define CPP_WORDSZ 64
949 # define CPP_WORDSZ 32
951 /* Appears to hold for all "32 bit" compilers */
952 /* except Borland. The -a4 option fixes */
954 /* Ivan Demakov: For Watcom the option is -zp4. */
956 # ifndef SMALL_CONFIG
957 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
958 /* improvement on Pentiums. */
960 # ifdef HAVE_BUILTIN_UNWIND_INIT
961 # define USE_GENERIC_PUSH_REGS
964 # define OS_TYPE "SEQUENT"
966 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
967 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
970 # define OS_TYPE "BEOS"
972 # define GETPAGESIZE() B_PAGE_SIZE
974 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
977 # define OS_TYPE "SUNOS5"
978 extern int _etext[], _end[];
979 extern ptr_t GC_SysVGetDataStart();
980 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
981 # define DATAEND (_end)
982 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
983 /* but reportedly breaks under 2.8. It appears that the stack */
984 /* base is a property of the executable, so this should not break */
985 /* old executables. */
986 /* HEURISTIC2 probably works, but this appears to be preferable. */
988 # define STACKBOTTOM USRSTACK
989 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
990 /* It appears to be fixed in 2.8 and 2.9. */
991 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
994 # define DYNAMIC_LOADING
995 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
997 /* Otherwise we now use calloc. Mmap may result in the */
998 /* heap interleaved with thread stacks, which can result in */
999 /* excessive blacklisting. Sbrk is unusable since it */
1000 /* doesn't interact correctly with the system malloc. */
1003 # define HEAP_START (ptr_t)0x40000000
1005 # define HEAP_START DATAEND
1009 # define OS_TYPE "SCO"
1011 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1013 +((word)etext & 0xfff))
1014 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1017 # define OS_TYPE "SCO_ELF"
1019 # define DATASTART ((ptr_t)(etext))
1020 # define STACKBOTTOM ((ptr_t) 0x08048000)
1021 # define DYNAMIC_LOADING
1022 # define ELF_CLASS ELFCLASS32
1025 # define OS_TYPE "DGUX"
1026 extern int _etext, _end;
1027 extern ptr_t GC_SysVGetDataStart();
1028 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1029 # define DATAEND (&_end)
1030 # define STACK_GROWS_DOWN
1032 # include <unistd.h>
1033 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1034 # define DYNAMIC_LOADING
1037 # endif /* USE_MMAP */
1038 # define MAP_FAILED (void *) -1
1040 # define HEAP_START (ptr_t)0x40000000
1041 # else /* USE_MMAP */
1042 # define HEAP_START DATAEND
1043 # endif /* USE_MMAP */
1048 /* The Intel compiler doesn't like inline assembly */
1049 # define USE_GENERIC_PUSH_REGS
1051 # define OS_TYPE "LINUX"
1052 # define LINUX_STACKBOTTOM
1056 # define STACK_GRAN 0x10000000
1057 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1058 /* different kernel configurations. In particular, systems */
1059 /* with 2GB physical memory will usually move the user */
1060 /* address space limit, and hence initial SP to 0x80000000. */
1062 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1063 # define MPROTECT_VDB
1065 /* We seem to get random errors in incremental mode, */
1066 /* possibly because Linux threads is itself a malloc client */
1067 /* and can't deal with the signals. */
1069 # define HEAP_START (ptr_t)0x1000
1070 /* This encourages mmap to give us low addresses, */
1071 /* thus allowing the heap to grow to ~3GB */
1073 # define DYNAMIC_LOADING
1074 # ifdef UNDEFINED /* includes ro data */
1075 extern int _etext[];
1076 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1078 # include <features.h>
1079 # if defined(__GLIBC__) && __GLIBC__ >= 2
1080 # define SEARCH_FOR_DATA_START
1082 extern char **__environ;
1083 # define DATASTART ((ptr_t)(&__environ))
1084 /* hideous kludge: __environ is the first */
1085 /* word in crt0.o, and delimits the start */
1086 /* of the data segment, no matter which */
1087 /* ld options were passed through. */
1088 /* We could use _etext instead, but that */
1089 /* would include .rodata, which may */
1090 /* contain large read-only data tables */
1091 /* that we'd rather not scan. */
1094 # define DATAEND (_end)
1097 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1099 # ifdef USE_I686_PREFETCH
1100 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1101 /* for the next rtelease. */
1102 # define PREFETCH(x) \
1103 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1104 /* Empirically prefetcht0 is much more effective at reducing */
1105 /* cache miss stalls for the targetted load instructions. But it */
1106 /* seems to interfere enough with other cache traffic that the net */
1107 /* result is worse than prefetchnta. */
1109 /* Using prefetches for write seems to have a slight negative */
1110 /* impact on performance, at least for a PIII/500. */
1111 # define PREFETCH_FOR_WRITE(x) \
1112 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1115 # ifdef USE_3DNOW_PREFETCH
1116 # define PREFETCH(x) \
1117 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1118 # define PREFETCH_FOR_WRITE(x) \
1119 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1123 # define OS_TYPE "CYGWIN32"
1124 extern int _data_start__[];
1125 extern int _data_end__[];
1126 extern int _bss_start__[];
1127 extern int _bss_end__[];
1128 /* For binutils 2.9.1, we have */
1129 /* DATASTART = _data_start__ */
1130 /* DATAEND = _bss_end__ */
1131 /* whereas for some earlier versions it was */
1132 /* DATASTART = _bss_start__ */
1133 /* DATAEND = _data_end__ */
1134 /* To get it right for both, we take the */
1135 /* minumum/maximum of the two. */
1137 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1140 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1142 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1143 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1145 # define STACK_GRAN 0x10000
1149 # define OS_TYPE "OS2"
1150 /* STACKBOTTOM and DATASTART are handled specially in */
1151 /* os_dep.c. OS2 actually has the right */
1153 # define DATAEND /* not needed */
1154 # define USE_GENERIC_PUSH_REGS
1157 # define OS_TYPE "MSWIN32"
1158 /* STACKBOTTOM and DATASTART are handled specially in */
1160 # ifndef __WATCOMC__
1161 # define MPROTECT_VDB
1163 # define DATAEND /* not needed */
1166 # define OS_TYPE "MSWINCE"
1167 # define DATAEND /* not needed */
1170 # define OS_TYPE "DJGPP"
1171 # include "stubinfo.h"
1174 extern int __djgpp_stack_limit;
1175 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1176 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1178 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1179 /* This may not be right. */
1182 # define OS_TYPE "OPENBSD"
1185 # define OS_TYPE "FREEBSD"
1186 # ifndef GC_FREEBSD_THREADS
1187 # define MPROTECT_VDB
1189 # define SIG_SUSPEND SIGUSR1
1190 # define SIG_THR_RESTART SIGUSR2
1191 # define FREEBSD_STACKBOTTOM
1193 # define DYNAMIC_LOADING
1195 extern char etext[];
1196 extern char * GC_FreeBSDGetDataStart();
1197 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1200 # define OS_TYPE "NETBSD"
1202 # define DYNAMIC_LOADING
1206 # define OS_TYPE "THREE86BSD"
1209 # define OS_TYPE "BSDI"
1211 # if defined(OPENBSD) || defined(NETBSD) \
1212 || defined(THREE86BSD) || defined(BSDI)
1214 extern char etext[];
1215 # define DATASTART ((ptr_t)(etext))
1218 # define OS_TYPE "NEXT"
1219 # define DATASTART ((ptr_t) get_etext())
1220 # define STACKBOTTOM ((ptr_t)0xc0000000)
1221 # define DATAEND /* not needed */
1224 # define OS_TYPE "DOS4GW"
1225 extern long __nullarea;
1227 extern char *_STACKTOP;
1228 /* Depending on calling conventions Watcom C either precedes
1229 or does not precedes with undescore names of C-variables.
1230 Make sure startup code variables always have the same names. */
1231 #pragma aux __nullarea "*";
1232 #pragma aux _end "*";
1233 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1234 /* confused? me too. */
1235 # define DATASTART ((ptr_t) &__nullarea)
1236 # define DATAEND ((ptr_t) &_end)
1239 # define OS_TYPE "HURD"
1240 # define STACK_GROWS_DOWN
1242 extern int __data_start[];
1243 # define DATASTART ( (ptr_t) (__data_start))
1245 # define DATAEND ( (ptr_t) (_end))
1246 /* # define MPROTECT_VDB Not quite working yet? */
1247 # define DYNAMIC_LOADING
1252 # define MACH_TYPE "NS32K"
1253 # define ALIGNMENT 4
1254 extern char **environ;
1255 # define DATASTART ((ptr_t)(&environ))
1256 /* hideous kludge: environ is the first */
1257 /* word in crt0.o, and delimits the start */
1258 /* of the data segment, no matter which */
1259 /* ld options were passed through. */
1260 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1264 # define MACH_TYPE "MIPS"
1266 /* This was developed for a linuxce style platform. Probably */
1267 /* needs to be tweaked for workstation class machines. */
1268 # define OS_TYPE "LINUX"
1269 # define DYNAMIC_LOADING
1271 # define DATAEND (_end)
1272 extern int __data_start[];
1273 # define DATASTART ((ptr_t)(__data_start))
1274 # define ALIGNMENT 4
1275 # define USE_GENERIC_PUSH_REGS
1276 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1277 # define LINUX_STACKBOTTOM
1279 # define STACKBOTTOM 0x80000000
1284 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1285 extern int _fdata[], _end[];
1286 # define DATASTART ((ptr_t)_fdata)
1287 # define DATAEND ((ptr_t)_end)
1288 # define CPP_WORDSZ _MIPS_SZPTR
1289 # define ALIGNMENT (_MIPS_SZPTR/8)
1291 extern int etext[], edata[], end[];
1292 extern int _DYNAMIC_LINKING[], _gp[];
1293 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1294 + ((word)etext & 0xffff)))
1295 # define DATAEND (edata)
1296 # define DATASTART2 (_DYNAMIC_LINKING \
1297 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1299 # define DATAEND2 (end)
1300 # define ALIGNMENT 4
1302 # define OS_TYPE "EWS4800"
1303 # define USE_GENERIC_PUSH_REGS 1
1307 # define DATASTART (ptr_t)0x10000000
1308 /* Could probably be slightly higher since */
1309 /* startup code allocates lots of stuff. */
1310 # define OS_TYPE "ULTRIX"
1311 # define ALIGNMENT 4
1315 # define DATASTART (ptr_t)0x10000000
1316 # define OS_TYPE "RISCOS"
1317 # define ALIGNMENT 4 /* Required by hardware */
1321 extern int _fdata[];
1322 # define DATASTART ((ptr_t)(_fdata))
1324 # define HEAP_START (ptr_t)0x30000000
1326 # define HEAP_START DATASTART
1328 /* Lowest plausible heap address. */
1329 /* In the MMAP case, we map there. */
1330 /* In either case it is used to identify */
1331 /* heap sections so they're not */
1332 /* considered as roots. */
1333 # define OS_TYPE "IRIX5"
1334 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1335 /* of recent breakage. */
1337 # define CPP_WORDSZ _MIPS_SZPTR
1338 # define ALIGNMENT (_MIPS_SZPTR/8)
1339 # if CPP_WORDSZ != 64
1340 # define ALIGN_DOUBLE
1343 # define ALIGNMENT 4
1344 # define ALIGN_DOUBLE
1346 # define DYNAMIC_LOADING
1349 # define OS_TYPE "MSWINCE"
1350 # define ALIGNMENT 4
1351 # define DATAEND /* not needed */
1353 # if defined(NETBSD)
1354 # define OS_TYPE "NETBSD"
1355 # define ALIGNMENT 4
1357 # define USE_GENERIC_PUSH_REGS
1360 # define DATASTART GC_data_start
1361 # define NEED_FIND_LIMIT
1362 # define DYNAMIC_LOADING
1364 # define DATASTART ((ptr_t) 0x10000000)
1365 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1371 # define MACH_TYPE "RS6000"
1376 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1379 # define ALIGNMENT 8
1380 # define CPP_WORDSZ 64
1381 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1383 # define ALIGNMENT 4
1384 # define CPP_WORDSZ 32
1385 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1387 /* From AIX linker man page:
1388 _text Specifies the first location of the program.
1389 _etext Specifies the first location after the program.
1390 _data Specifies the first location of the data.
1391 _edata Specifies the first location after the initialized data
1392 _end or end Specifies the first location after all data.
1394 extern int _data[], _end[];
1395 # define DATASTART ((ptr_t)((ulong)_data))
1396 # define DATAEND ((ptr_t)((ulong)_end))
1398 # define USE_GENERIC_PUSH_REGS
1399 # define DYNAMIC_LOADING
1400 /* For really old versions of AIX, this may have to be removed. */
1404 # define MACH_TYPE "HP_PA"
1406 # define CPP_WORDSZ 64
1407 # define ALIGNMENT 8
1409 # define CPP_WORDSZ 32
1410 # define ALIGNMENT 4
1411 # define ALIGN_DOUBLE
1413 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1414 # ifndef LINUX /* For now. */
1415 # define MPROTECT_VDB
1418 # define GENERIC_COMPARE_AND_SWAP
1419 /* No compare-and-swap instruction. Use pthread mutexes */
1420 /* when we absolutely have to. */
1421 # ifdef PARALLEL_MARK
1422 # define USE_MARK_BYTES
1423 /* Minimize compare-and-swap usage. */
1426 # define STACK_GROWS_UP
1428 # define OS_TYPE "HPUX"
1429 extern int __data_start[];
1430 # define DATASTART ((ptr_t)(__data_start))
1432 /* The following appears to work for 7xx systems running HP/UX */
1433 /* 9.xx Furthermore, it might result in much faster */
1434 /* collections than HEURISTIC2, which may involve scanning */
1435 /* segments that directly precede the stack. It is not the */
1436 /* default, since it may not work on older machine/OS */
1437 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1439 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1441 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1442 /* to this. Note that the GC must be initialized before the */
1443 /* first putenv call. */
1444 extern char ** environ;
1445 # define STACKBOTTOM ((ptr_t)environ)
1447 # define DYNAMIC_LOADING
1448 # include <unistd.h>
1449 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1451 # define PREFETCH(x) { \
1452 register long addr = (long)(x); \
1453 (void) _asm ("LDW", 0, 0, addr, 0); \
1458 # define OS_TYPE "LINUX"
1459 # define LINUX_STACKBOTTOM
1460 # define DYNAMIC_LOADING
1461 # define SEARCH_FOR_DATA_START
1463 # define DATAEND (&_end)
1468 # define MACH_TYPE "ALPHA"
1469 # define ALIGNMENT 8
1470 # define CPP_WORDSZ 64
1472 # define USE_GENERIC_PUSH_REGS
1473 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1474 /* fp registers in some cases when the target is a 21264. The assembly */
1475 /* code doesn't handle that yet, and version dependencies make that a */
1476 /* bit tricky. Do the easy thing for now. */
1479 # define OS_TYPE "NETBSD"
1481 # define DATASTART GC_data_start
1482 # define ELFCLASS32 32
1483 # define ELFCLASS64 64
1484 # define ELF_CLASS ELFCLASS64
1485 # define DYNAMIC_LOADING
1488 # define OS_TYPE "OPENBSD"
1490 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1491 # define DATASTART GC_data_start
1492 # define ELFCLASS32 32
1493 # define ELFCLASS64 64
1494 # define ELF_CLASS ELFCLASS64
1495 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1496 # define DATASTART ((ptr_t) 0x140000000)
1500 # define OS_TYPE "FREEBSD"
1501 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1502 # define SIG_SUSPEND SIGUSR1
1503 # define SIG_THR_RESTART SIGUSR2
1504 # define FREEBSD_STACKBOTTOM
1506 # define DYNAMIC_LOADING
1508 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1509 extern char etext[];
1510 extern char edata[];
1512 # define NEED_FIND_LIMIT
1513 # define DATASTART ((ptr_t)(&etext))
1514 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1515 # define DATASTART2 ((ptr_t)(&edata))
1516 # define DATAEND2 ((ptr_t)(&end))
1519 # define OS_TYPE "OSF1"
1520 # define DATASTART ((ptr_t) 0x140000000)
1522 # define DATAEND ((ptr_t) &_end)
1523 extern char ** environ;
1524 /* round up from the value of environ to the nearest page boundary */
1525 /* Probably breaks if putenv is called before collector */
1526 /* initialization. */
1527 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1528 /* # define HEURISTIC2 */
1529 /* Normally HEURISTIC2 is too conervative, since */
1530 /* the text segment immediately follows the stack. */
1531 /* Hence we give an upper pound. */
1532 /* This is currently unused, since we disabled HEURISTIC2 */
1533 extern int __start[];
1534 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1535 # ifndef GC_OSF1_THREADS
1536 /* Unresolved signal issues with threads. */
1537 # define MPROTECT_VDB
1539 # define DYNAMIC_LOADING
1542 # define OS_TYPE "LINUX"
1543 # define STACKBOTTOM ((ptr_t) 0x120000000)
1545 # define SEARCH_FOR_DATA_START
1546 # define DYNAMIC_LOADING
1548 # define DATASTART ((ptr_t) 0x140000000)
1551 # define DATAEND (_end)
1552 # define MPROTECT_VDB
1553 /* Has only been superficially tested. May not */
1554 /* work on all versions. */
1559 # define MACH_TYPE "IA64"
1560 # define USE_GENERIC_PUSH_REGS
1561 /* We need to get preserved registers in addition to register */
1562 /* windows. That's easiest to do with setjmp. */
1563 # ifdef PARALLEL_MARK
1564 # define USE_MARK_BYTES
1565 /* Compare-and-exchange is too expensive to use for */
1566 /* setting mark bits. */
1570 # define CPP_WORDSZ 32
1571 # define ALIGN_DOUBLE
1572 /* Requires 8 byte alignment for malloc */
1573 # define ALIGNMENT 4
1578 # define CPP_WORDSZ 64
1579 # define ALIGN_DOUBLE
1580 /* Requires 16 byte alignment for malloc */
1581 # define ALIGNMENT 8
1583 # define OS_TYPE "HPUX"
1584 extern int __data_start[];
1585 # define DATASTART ((ptr_t)(__data_start))
1586 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1587 /* to this. Note that the GC must be initialized before the */
1588 /* first putenv call. */
1589 extern char ** environ;
1590 # define STACKBOTTOM ((ptr_t)environ)
1591 # define HPUX_STACKBOTTOM
1592 # define DYNAMIC_LOADING
1593 # include <unistd.h>
1594 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1595 /* The following was empirically determined, and is probably */
1596 /* not very robust. */
1597 /* Note that the backing store base seems to be at a nice */
1598 /* address minus one page. */
1599 # define BACKING_STORE_DISPLACEMENT 0x1000000
1600 # define BACKING_STORE_ALIGNMENT 0x1000
1601 extern ptr_t GC_register_stackbottom;
1602 # define BACKING_STORE_BASE GC_register_stackbottom
1603 /* Known to be wrong for recent HP/UX versions!!! */
1606 # define CPP_WORDSZ 64
1607 # define ALIGN_DOUBLE
1608 /* Requires 16 byte alignment for malloc */
1609 # define ALIGNMENT 8
1610 # define OS_TYPE "LINUX"
1611 /* The following works on NUE and older kernels: */
1612 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1613 /* This does not work on NUE: */
1614 # define LINUX_STACKBOTTOM
1615 /* We also need the base address of the register stack */
1616 /* backing store. This is computed in */
1617 /* GC_linux_register_stack_base based on the following */
1619 # define BACKING_STORE_ALIGNMENT 0x100000
1620 # define BACKING_STORE_DISPLACEMENT 0x80000000
1621 extern ptr_t GC_register_stackbottom;
1622 # define BACKING_STORE_BASE GC_register_stackbottom
1623 # define SEARCH_FOR_DATA_START
1625 # define DYNAMIC_LOADING
1627 /* In the Intel compiler environment, we seem to end up with */
1628 /* statically linked executables and an undefined reference */
1631 # define MPROTECT_VDB
1632 /* Requires Linux 2.3.47 or later. */
1634 # define DATAEND (_end)
1636 # ifndef __INTEL_COMPILER
1637 # define PREFETCH(x) \
1638 __asm__ (" lfetch [%0]": : "r"(x))
1639 # define PREFETCH_FOR_WRITE(x) \
1640 __asm__ (" lfetch.excl [%0]": : "r"(x))
1641 # define CLEAR_DOUBLE(x) \
1642 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1644 # include <ia64intrin.h>
1645 # define PREFETCH(x) \
1646 __lfetch(__lfhint_none, (x))
1647 # define PREFETCH_FOR_WRITE(x) \
1648 __lfetch(__lfhint_nta, (x))
1649 # define CLEAR_DOUBLE(x) \
1650 __stf_spill((void *)(x), 0)
1651 # endif // __INTEL_COMPILER
1655 /* FIXME: This is a very partial guess. There is no port, yet. */
1656 # define OS_TYPE "MSWIN32"
1657 /* STACKBOTTOM and DATASTART are handled specially in */
1659 # define DATAEND /* not needed */
1660 # if defined(_WIN64)
1661 # define CPP_WORDSZ 64
1663 # define CPP_WORDSZ 32 /* Is this possible? */
1665 # define ALIGNMENT 8
1670 # define MACH_TYPE "M88K"
1671 # define ALIGNMENT 4
1672 # define ALIGN_DOUBLE
1675 # define OS_TYPE "CX_UX"
1676 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1679 # define OS_TYPE "DGUX"
1680 extern ptr_t GC_SysVGetDataStart();
1681 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1683 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1687 /* If this still works, and if anyone cares, this should probably */
1688 /* be moved to the S390 category. */
1689 # define MACH_TYPE "S370"
1690 # define ALIGNMENT 4 /* Required by hardware */
1691 # define USE_GENERIC_PUSH_REGS
1693 # define OS_TYPE "UTS4"
1695 extern int _etext[];
1697 extern ptr_t GC_SysVGetDataStart();
1698 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1699 # define DATAEND (_end)
1705 # define MACH_TYPE "S390"
1706 # define USE_GENERIC_PUSH_REGS
1708 # define ALIGNMENT 4
1709 # define CPP_WORDSZ 32
1711 # define ALIGNMENT 8
1712 # define CPP_WORDSZ 64
1713 # define HBLKSIZE 4096
1716 # define OS_TYPE "LINUX"
1717 # define LINUX_STACKBOTTOM
1718 # define DYNAMIC_LOADING
1719 extern int __data_start[];
1720 # define DATASTART ((ptr_t)(__data_start))
1722 # define DATAEND (_end)
1723 # define CACHE_LINE_SIZE 256
1724 # define GETPAGESIZE() 4096
1729 # define ALIGNMENT 4
1730 extern int _etext[];
1731 # define DATASTART ((ptr_t)(_etext))
1736 # define CPP_WORDSZ 32
1737 # define MACH_TYPE "ARM32"
1738 # define ALIGNMENT 4
1740 # define OS_TYPE "NETBSD"
1743 # define DATASTART GC_data_start
1744 # define DYNAMIC_LOADING
1746 extern char etext[];
1747 # define DATASTART ((ptr_t)(etext))
1749 # define USE_GENERIC_PUSH_REGS
1752 # define OS_TYPE "LINUX"
1755 # define STACK_GRAN 0x10000000
1756 # define USE_GENERIC_PUSH_REGS
1758 # define DYNAMIC_LOADING
1759 # include <features.h>
1760 # if defined(__GLIBC__) && __GLIBC__ >= 2
1761 # define SEARCH_FOR_DATA_START
1763 extern char **__environ;
1764 # define DATASTART ((ptr_t)(&__environ))
1765 /* hideous kludge: __environ is the first */
1766 /* word in crt0.o, and delimits the start */
1767 /* of the data segment, no matter which */
1768 /* ld options were passed through. */
1769 /* We could use _etext instead, but that */
1770 /* would include .rodata, which may */
1771 /* contain large read-only data tables */
1772 /* that we'd rather not scan. */
1775 # define DATAEND (_end)
1778 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1782 # define OS_TYPE "MSWINCE"
1783 # define DATAEND /* not needed */
1786 /* __data_start is usually defined in the target linker script. */
1787 extern int __data_start[];
1788 # define DATASTART (ptr_t)(__data_start)
1789 # define USE_GENERIC_PUSH_REGS
1790 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1791 extern void *__stack_base__;
1792 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1797 # define MACH_TYPE "SH"
1798 # define ALIGNMENT 4
1800 # define OS_TYPE "MSWINCE"
1801 # define DATAEND /* not needed */
1804 # define OS_TYPE "LINUX"
1805 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1806 # define USE_GENERIC_PUSH_REGS
1807 # define DYNAMIC_LOADING
1808 # define SEARCH_FOR_DATA_START
1810 # define DATAEND (_end)
1815 # define MACH_TYPE "SH4"
1816 # define OS_TYPE "MSWINCE"
1817 # define ALIGNMENT 4
1818 # define DATAEND /* not needed */
1822 # define MACH_TYPE "X86_64"
1823 # define ALIGNMENT 8
1824 # define CPP_WORDSZ 64
1826 # define HBLKSIZE 4096
1828 # define CACHE_LINE_SIZE 64
1829 # define USE_GENERIC_PUSH_REGS
1831 # define OS_TYPE "LINUX"
1832 # define LINUX_STACKBOTTOM
1833 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1834 # define MPROTECT_VDB
1836 /* We seem to get random errors in incremental mode, */
1837 /* possibly because Linux threads is itself a malloc client */
1838 /* and can't deal with the signals. */
1841 # define DYNAMIC_LOADING
1842 # ifdef UNDEFINED /* includes ro data */
1843 extern int _etext[];
1844 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1846 # include <features.h>
1847 # define SEARCH_FOR_DATA_START
1849 # define DATAEND (_end)
1852 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1854 # if defined(__GNUC__) && __GNUC >= 3
1855 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1856 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1860 # define OS_TYPE "NETBSD"
1862 # define DYNAMIC_LOADING
1865 extern char etext[];
1866 # define SEARCH_FOR_DATA_START
1870 #if defined(LINUX) && defined(USE_MMAP)
1871 /* The kernel may do a somewhat better job merging mappings etc. */
1872 /* with anonymous mappings. */
1873 # define USE_MMAP_ANON
1876 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1877 /* Rld appears to allocate some memory with its own allocator, and */
1878 /* some through malloc, which might be redirected. To make this */
1879 /* work with collectable memory, we have to scan memory allocated */
1880 /* by rld's internal malloc. */
1881 # define USE_PROC_FOR_LIBRARIES
1884 # ifndef STACK_GROWS_UP
1885 # define STACK_GROWS_DOWN
1889 # define CPP_WORDSZ 32
1898 # define DATAEND (end)
1901 # if defined(SVR4) && !defined(GETPAGESIZE)
1902 # include <unistd.h>
1903 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1906 # ifndef GETPAGESIZE
1907 # if defined(SUNOS5) || defined(IRIX5)
1908 # include <unistd.h>
1910 # define GETPAGESIZE() getpagesize()
1913 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1914 /* OS has SVR4 generic features. Probably others also qualify. */
1918 # if defined(SUNOS5) || defined(DRSNX)
1919 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1922 /* OS has SUNOS5 style signal handlers. */
1930 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
1934 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
1935 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1936 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
1937 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
1938 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1941 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1946 # undef DYNAMIC_LOADING
1951 # undef MPROTECT_VDB
1956 /* Postponed for now. */
1958 # undef MPROTECT_VDB
1961 # ifdef SMALL_CONFIG
1962 /* Presumably not worth the space it takes. */
1964 # undef MPROTECT_VDB
1968 # undef MPROTECT_VDB /* Can't deal with address space holes. */
1971 # ifdef PARALLEL_MARK
1972 # undef MPROTECT_VDB /* For now. */
1975 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
1976 # define DEFAULT_VDB
1980 # define PREFETCH(x)
1981 # define NO_PREFETCH
1984 # ifndef PREFETCH_FOR_WRITE
1985 # define PREFETCH_FOR_WRITE(x)
1986 # define NO_PREFETCH_FOR_WRITE
1989 # ifndef CACHE_LINE_SIZE
1990 # define CACHE_LINE_SIZE 32 /* Wild guess */
1994 # define REGISTER_LIBRARIES_EARLY
1995 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
1996 /* lock. This isn't safe after the world has stopped. So we must */
1997 /* call GC_register_dynamic_libraries before stopping the world. */
1998 /* For performance reasons, this may be beneficial on other */
1999 /* platforms as well, though it should be avoided in win32. */
2002 # if defined(SEARCH_FOR_DATA_START)
2003 extern ptr_t GC_data_start;
2004 # define DATASTART GC_data_start
2007 # ifndef CLEAR_DOUBLE
2008 # define CLEAR_DOUBLE(x) \
2009 ((word*)x)[0] = 0; \
2011 # endif /* CLEAR_DOUBLE */
2013 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2014 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2015 # define GC_SOLARIS_THREADS
2018 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2019 --> inconsistent configuration
2021 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2022 --> inconsistent configuration
2024 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2025 --> inconsistent configuration
2027 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2028 --> inconsistent configuration
2030 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2031 --> inconsistent configuration
2033 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2034 --> inconsistent configuration
2037 # if defined(PCR) || defined(SRC_M3) || \
2038 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2039 defined(GC_PTHREADS)
2043 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
2044 || defined(LINT) || defined(MSWINCE) || defined(ARM32) \
2045 || (defined(I386) && defined(__LCC__))
2046 /* Use setjmp based hack to mark from callee-save registers. */
2047 /* The define should move to the individual platform */
2049 # define USE_GENERIC_PUSH_REGS
2052 # if defined(MSWINCE)
2057 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2058 /* include assembly code to do it well. */
2061 /* Can we save call chain in objects for debugging? */
2062 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2063 /* frame) to reasonable values for the platform. */
2064 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2065 /* at build time, though we feel free to adjust it slightly. */
2066 /* Define NEED_CALLINFO if we either save the call stack or */
2067 /* GC_ADD_CALLER is defined. */
2068 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2071 # define CAN_SAVE_CALL_ARGS
2073 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2074 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2075 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2076 # define CAN_SAVE_CALL_ARGS
2079 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2080 && defined(GC_CAN_SAVE_CALL_STACKS)
2081 # define SAVE_CALL_CHAIN
2083 # ifdef SAVE_CALL_CHAIN
2084 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2085 # define NARGS SAVE_CALL_NARGS
2087 # define NARGS 0 /* Number of arguments to save for each call. */
2090 # ifdef SAVE_CALL_CHAIN
2091 # ifndef SAVE_CALL_COUNT
2092 # define NFRAMES 6 /* Number of frames to save. Even for */
2093 /* alignment reasons. */
2095 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2097 # define NEED_CALLINFO
2098 # endif /* SAVE_CALL_CHAIN */
2099 # ifdef GC_ADD_CALLER
2102 # define NEED_CALLINFO
2105 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2106 # define DBG_HDRS_ALL
2109 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2110 # define POINTER_SHIFT 0
2113 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2114 # define POINTER_MASK ((GC_word)(-1))
2117 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2118 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2121 # if defined(FIXUP_POINTER)
2122 # define NEED_FIXUP_POINTER 1
2124 # define NEED_FIXUP_POINTER 0
2125 # define FIXUP_POINTER(p)
2129 /* This relies on some type definitions from gc_priv.h, from */
2130 /* where it's normally included. */
2132 /* How to get heap memory from the OS: */
2133 /* Note that sbrk()-like allocation is preferred, since it */
2134 /* usually makes it possible to merge consecutively allocated */
2135 /* chunks. It also avoids unintented recursion with */
2136 /* -DREDIRECT_MALLOC. */
2137 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2138 /* 0 is taken to mean failure. */
2139 /* In the case os USE_MMAP, the argument must also be a */
2140 /* physical page size. */
2141 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2142 /* though we should perhaps take advantage of the case in which */
2144 struct hblk; /* See gc_priv.h. */
2146 char * real_malloc();
2147 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2151 void * os2_alloc(size_t bytes);
2152 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2156 # if defined(NEXT) || defined(DOS4GW) || \
2157 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2158 (defined(SUNOS5) && !defined(USE_MMAP))
2159 # define GET_MEM(bytes) HBLKPTR((size_t) \
2160 calloc(1, (size_t)bytes + GC_page_size) \
2164 extern ptr_t GC_win32_get_mem();
2165 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2168 # if defined(USE_TEMPORARY_MEMORY)
2169 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2170 Boolean clearMemory);
2171 # define GET_MEM(bytes) HBLKPTR( \
2172 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2175 # define GET_MEM(bytes) HBLKPTR( \
2176 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2180 extern ptr_t GC_wince_get_mem();
2181 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2183 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2184 extern void *GC_amiga_get_mem(size_t size);
2185 # define GET_MEM(bytes) HBLKPTR((size_t) \
2186 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2189 extern ptr_t GC_unix_get_mem();
2190 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2199 #endif /* GC_PRIVATE_H */
2201 # endif /* GCCONFIG_H */