2 * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4 * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
5 * Copyright (c) 2000-2004 Hewlett-Packard Development Company, L.P.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
18 * This header is private to the gc. It is almost always included from
19 * gc_priv.h. However it is possible to include it by itself if just the
20 * configuration macros are needed. In that
21 * case, a few declarations relying on types declared in gc_priv.h will be
30 /* Fake ptr_t declaration, just to avoid compilation errors. */
31 /* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
32 typedef struct GC_undefined_struct * ptr_t;
35 /* Machine dependent parameters. Some tuning parameters can be found */
36 /* near the top of gc_private.h. */
38 /* Machine specific parts contributed by various people. See README file. */
40 /* First a unified test for Linux: */
41 # if defined(linux) || defined(__linux__)
47 /* And one for NetBSD: */
48 # if defined(__NetBSD__)
52 /* And one for OpenBSD: */
53 # if defined(__OpenBSD__)
57 /* And one for FreeBSD: */
58 # if defined(__FreeBSD__) && !defined(FREEBSD)
62 /* And one for Darwin: */
63 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
67 /* Determine the machine type: */
68 # if defined(__native_client__)
71 # define mach_type_known
73 # if defined(__arm__) || defined(__thumb__)
75 # if !defined(LINUX) && !defined(NETBSD) && !defined(DARWIN)
77 # define mach_type_known
80 # if defined(sun) && defined(mc68000)
83 # define mach_type_known
85 # if defined(hp9000s300)
88 # define mach_type_known
90 # if defined(OPENBSD) && defined(m68k)
92 # define mach_type_known
94 # if defined(OPENBSD) && defined(__sparc__)
96 # define mach_type_known
98 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
100 # define mach_type_known
102 # if defined(NETBSD) && defined(__powerpc__)
104 # define mach_type_known
106 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
108 # define mach_type_known
110 # if defined(NETBSD) && defined(__sh__)
112 # define mach_type_known
121 # define mach_type_known
123 # if defined(__NetBSD__) && defined(__vax__)
125 # define mach_type_known
127 # if defined(mips) || defined(__mips) || defined(_mips)
129 # if defined(nec_ews) || defined(_nec_ews)
132 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
133 # if defined(ultrix) || defined(__ultrix)
136 # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
137 || defined(__SYSTYPE_SVR4__)
138 # define IRIX5 /* or IRIX 6.X */
140 # define RISCOS /* or IRIX 4.X */
144 # if defined(__NetBSD__) && defined(__MIPSEL__)
147 # define mach_type_known
149 # if defined(DGUX) && (defined(i386) || defined(__i386__))
154 # define mach_type_known
156 # if defined(sequent) && (defined(i386) || defined(__i386__))
159 # define mach_type_known
161 # if defined(sun) && (defined(i386) || defined(__i386__))
164 # define mach_type_known
166 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
169 # define mach_type_known
173 # define mach_type_known
175 # if defined(sun) && (defined(sparc) || defined(__sparc))
177 /* Test for SunOS 5.x */
184 # define mach_type_known
186 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
187 && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
190 # define mach_type_known
194 # define mach_type_known
196 # if defined(__NetBSD__) && defined(__sparc__)
198 # define mach_type_known
200 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
201 /* The above test may need refinement */
203 # if defined(_SCO_ELF)
208 # define mach_type_known
210 # if defined(_AUX_SOURCE)
213 # define mach_type_known
215 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
216 || defined(hppa) || defined(__hppa__)
218 # if !defined(LINUX) && !defined(HPUX)
221 # define mach_type_known
223 # if defined(__ia64) && defined(_HPUX_SOURCE)
228 # define mach_type_known
230 # if defined(__BEOS__) && defined(_X86_)
233 # define mach_type_known
235 # if defined(LINUX) && (defined(i386) || defined(__i386__))
237 # define mach_type_known
239 # if defined(OPENBSD) && defined(__amd64__)
241 # define mach_type_known
243 # if defined(LINUX) && defined(__x86_64__)
245 # define mach_type_known
247 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
249 # define mach_type_known
251 # if defined(LINUX) && defined(__arm__)
253 # define mach_type_known
255 # if defined(LINUX) && defined(__cris__)
259 # define mach_type_known
261 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || \
262 defined(powerpc64) || defined(__powerpc64__))
264 # define mach_type_known
266 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
268 # define mach_type_known
270 # if defined(LINUX) && defined(__mc68000__)
272 # define mach_type_known
274 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
276 # define mach_type_known
278 # if defined(LINUX) && defined(__arm__)
280 # define mach_type_known
282 # if defined(LINUX) && defined(__sh__)
284 # define mach_type_known
286 # if defined(LINUX) && defined(__m32r__)
288 # define mach_type_known
290 # if defined(__alpha) || defined(__alpha__)
292 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
293 # define OSF1 /* a.k.a Digital Unix */
295 # define mach_type_known
297 # if defined(_AMIGA) && !defined(AMIGA)
302 # define mach_type_known
304 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
307 # define mach_type_known
309 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
312 # define mach_type_known
315 # include "TargetConditionals.h"
316 # if defined(__ppc__) || defined(__ppc64__)
318 # define mach_type_known
319 # elif defined(__i386__)
321 # define mach_type_known
322 # define DARWIN_DONT_PARSE_STACK
323 # define OS_TYPE "DARWIN"
324 # if TARGET_IPHONE_SIMULATOR == 0
325 # define DYNAMIC_LOADING
327 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
328 These aren't used when dyld support is enabled (it is by default) */
329 # define DATASTART ((ptr_t) get_etext())
330 # define DATAEND ((ptr_t) get_end())
331 # define STACKBOTTOM ((ptr_t) pthread_get_stackaddr_np(pthread_self()))
335 # define USE_MMAP_ANON
336 # define USE_ASM_PUSH_REGS
337 /* This is potentially buggy. It needs more testing. See the comments in
338 os_dep.c. It relies on threads to track writes. */
339 # ifdef GC_DARWIN_THREADS
340 /* # define MPROTECT_VDB -- diabled for now. May work for some apps. */
343 # define GETPAGESIZE() getpagesize()
344 # elif defined(__arm__)
346 # define mach_type_known
347 # define DARWIN_DONT_PARSE_STACK
348 # define GC_DONT_REGISTER_MAIN_STATIC_DATA
349 # elif defined(__x86_64)
351 # define mach_type_known
354 # if defined(NeXT) && defined(mc68000)
357 # define mach_type_known
359 # if defined(NeXT) && (defined(i386) || defined(__i386__))
362 # define mach_type_known
364 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
367 # define mach_type_known
369 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
371 # define mach_type_known
373 # if defined(FREEBSD) && defined(__x86_64__)
375 # define mach_type_known
377 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
379 # define mach_type_known
381 # if defined(__NetBSD__) && defined(__x86_64__)
383 # define mach_type_known
385 # if defined(FREEBSD) && defined(__sparc__)
387 # define mach_type_known
389 # if defined(bsdi) && (defined(i386) || defined(__i386__))
392 # define mach_type_known
394 # if !defined(mach_type_known) && defined(__386BSD__)
397 # define mach_type_known
399 # if defined(_CX_UX) && defined(_M88K)
402 # define mach_type_known
404 # if defined(DGUX) && defined(m88k)
407 # define mach_type_known
409 # if defined(_WIN32_WCE)
410 /* SH3, SH4, MIPS already defined for corresponding architectures */
411 # if defined(SH3) || defined(SH4)
421 # define mach_type_known
423 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
424 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
425 # if defined(__LP64__) || defined(_WIN64)
430 # define MSWIN32 /* or Win64 */
431 # define mach_type_known
433 # if defined(_MSC_VER) && defined(_M_IA64)
435 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
436 /* variants as a differnt platform. */
439 # if defined(__DJGPP__)
442 # define DJGPP /* MSDOS running the DJGPP port of GCC */
444 # define mach_type_known
446 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
449 # define mach_type_known
451 # if defined(__MINGW32__)
454 # define mach_type_known
456 # if defined(__BORLANDC__)
459 # define mach_type_known
461 # if defined(_UTS) && !defined(mach_type_known)
464 # define mach_type_known
468 # define mach_type_known
470 # if defined(__embedded__) && defined(PPC)
473 # define mach_type_known
476 # if defined(__WATCOMC__) && defined(__386__)
478 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
479 # if defined(__OS2__)
482 # if defined(__WINDOWS_386__) || defined(__NT__)
489 # define mach_type_known
491 # if defined(__s390__) && defined(LINUX)
493 # define mach_type_known
495 # if defined(__GNU__)
496 # if defined(__i386__)
497 /* The Debian Hurd running on generic PC */
500 # define mach_type_known
504 /* Feel free to add more clauses here */
506 /* Or manually define the machine type here. A machine type is */
507 /* characterized by the architecture. Some */
508 /* machine types are further subdivided by OS. */
509 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
510 /* Note that SGI IRIX is treated identically to RISCOS. */
511 /* SYSV on an M68K actually means A/UX. */
512 /* The distinction in these cases is usually the stack starting address */
513 # ifndef mach_type_known
514 --> unknown machine type
516 /* Mapping is: M68K ==> Motorola 680X0 */
517 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
518 /* MACOS and AMIGA variants) */
519 /* I386 ==> Intel 386 */
520 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
521 /* FREEBSD, THREE86BSD, MSWIN32, */
522 /* BSDI,SUNOS5, NEXT, other variants) */
523 /* NS32K ==> Encore Multimax */
524 /* MIPS ==> R2000 or R3000 */
525 /* (RISCOS, ULTRIX variants) */
526 /* VAX ==> DEC VAX */
527 /* (BSD, ULTRIX variants) */
528 /* RS6000 ==> IBM RS/6000 AIX3.X */
529 /* RT ==> IBM PC/RT */
530 /* HP_PA ==> HP9000/700 & /800 */
532 /* SPARC ==> SPARC v7/v8/v9 */
533 /* (SUNOS4, SUNOS5, LINUX, */
534 /* DRSNX variants) */
535 /* ALPHA ==> DEC Alpha */
536 /* (OSF1 and LINUX variants) */
537 /* M88K ==> Motorola 88XX0 */
538 /* (CX_UX and DGUX) */
539 /* S370 ==> 370-like machine */
540 /* running Amdahl UTS4 */
541 /* S390 ==> 390-like machine */
543 /* ARM32 ==> Intel StrongARM */
544 /* IA64 ==> Intel IPF */
546 /* (LINUX and HPUX) */
547 /* SH ==> Hitachi SuperH */
548 /* (LINUX & MSWINCE) */
549 /* X86_64 ==> AMD x86-64 */
550 /* POWERPC ==> IBM/Apple PowerPC */
551 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
552 /* LINUX, NETBSD, NOSYS variants) */
553 /* Handles 32 and 64-bit variants. */
554 /* AIX should be handled here, but */
555 /* that's called an RS6000. */
556 /* CRIS ==> Axis Etrax */
557 /* M32R ==> Renesas M32R */
561 * For each architecture and OS, the following need to be defined:
563 * CPP_WORDSZ is a simple integer constant representing the word size.
564 * in bits. We assume byte addressibility, where a byte has 8 bits.
565 * We also assume CPP_WORDSZ is either 32 or 64.
566 * (We care about the length of pointers, not hardware
567 * bus widths. Thus a 64 bit processor with a C compiler that uses
568 * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
570 * MACH_TYPE is a string representation of the machine type.
571 * OS_TYPE is analogous for the OS.
573 * ALIGNMENT is the largest N, such that
574 * all pointer are guaranteed to be aligned on N byte boundaries.
575 * defining it to be 1 will always work, but perform poorly.
577 * DATASTART is the beginning of the data segment.
578 * On some platforms SEARCH_FOR_DATA_START is defined.
579 * SEARCH_FOR_DATASTART will cause GC_data_start to
580 * be set to an address determined by accessing data backwards from _end
581 * until an unmapped page is found. DATASTART will be defined to be
583 * On UNIX-like systems, the collector will scan the area between DATASTART
584 * and DATAEND for root pointers.
586 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
587 * RTH suggests gaining access to linker script synth'd values with
588 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
589 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
590 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
591 * without any special options.
593 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
596 * STACKBOTTOM is the cool end of the stack, which is usually the
597 * highest address in the stack.
598 * Under PCR or OS/2, we have other ways of finding thread stacks.
599 * For each machine, the following should:
600 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
601 * 2) define exactly one of
602 * STACKBOTTOM (should be defined to be an expression)
606 * If STACKBOTTOM is defined, then it's value will be used directly as the
607 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
608 * with a method appropriate for most Linux systems. Currently we look
609 * first for __libc_stack_end, and if that fails read it from /proc.
610 * If either of the last two macros are defined, then STACKBOTTOM is computed
611 * during collector startup using one of the following two heuristics:
612 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
613 * the next multiple of STACK_GRAN.
614 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
615 * in small steps (decrement if STACK_GROWS_UP), and read the value
616 * at each location. Remember the value when the first
617 * Segmentation violation or Bus error is signalled. Round that
618 * to the nearest plausible page boundary, and use that instead
621 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
622 * the value of environ is a pointer that can serve as STACKBOTTOM.
623 * I expect that HEURISTIC2 can be replaced by this approach, which
624 * interferes far less with debugging. However it has the disadvantage
625 * that it's confused by a putenv call before the collector is initialized.
626 * This could be dealt with by intercepting putenv ...
628 * If no expression for STACKBOTTOM can be found, and neither of the above
629 * heuristics are usable, the collector can still be used with all of the above
630 * undefined, provided one of the following is done:
631 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
632 * without reference to STACKBOTTOM. This is appropriate for use in
633 * conjunction with thread packages, since there will be multiple stacks.
634 * (Allocating thread stacks in the heap, and treating them as ordinary
635 * heap data objects is also possible as a last resort. However, this is
636 * likely to introduce significant amounts of excess storage retention
637 * unless the dead parts of the thread stacks are periodically cleared.)
638 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
639 * If the author of the client code controls the main program, this is
640 * easily accomplished by introducing a new main program, setting
641 * GC_stackbottom to the address of a local variable, and then calling
642 * the original main program. The new main program would read something
645 * # include "gc_private.h"
647 * main(argc, argv, envp)
649 * char **argv, **envp;
653 * GC_stackbottom = (ptr_t)(&dummy);
654 * return(real_main(argc, argv, envp));
658 * Each architecture may also define the style of virtual dirty bit
659 * implementation to be used:
660 * MPROTECT_VDB: Write protect the heap and catch faults.
661 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
663 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
664 * defined GC_register_dynamic_libraries() for the architecture.
666 * An architecture may define PREFETCH(x) to preload the cache with *x.
667 * This defaults to a no-op.
669 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
671 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
672 * clear the two words at GC_malloc-aligned address x. By default,
673 * word stores of 0 are used instead.
675 * HEAP_START may be defined as the initial address hint for mmap-based
679 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
680 * to push the relevant registers onto the stack. This generally makes
681 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
683 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
684 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
685 && !defined(__INTEL_COMPILER) \
686 && !defined(__PATHCC__)
687 # define HAVE_BUILTIN_UNWIND_INIT
690 # define STACK_GRAN 0x1000000
692 # define MACH_TYPE "M68K"
695 # define OS_TYPE "OPENBSD"
698 # define DATASTART GC_data_start
699 # define DYNAMIC_LOADING
702 # define DATASTART ((ptr_t)(etext))
704 # define USE_GENERIC_PUSH_REGS
707 # define OS_TYPE "NETBSD"
710 # define DATASTART GC_data_start
711 # define DYNAMIC_LOADING
714 # define DATASTART ((ptr_t)(etext))
716 # define USE_GENERIC_PUSH_REGS
719 # define OS_TYPE "LINUX"
720 # define STACKBOTTOM ((ptr_t)0xf0000000)
721 # define USE_GENERIC_PUSH_REGS
722 /* We never got around to the assembly version. */
723 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
725 # define DYNAMIC_LOADING
726 # include <features.h>
727 # if defined(__GLIBC__)&& __GLIBC__>=2
728 # define SEARCH_FOR_DATA_START
730 # if defined(PLATFORM_ANDROID)
731 # define __environ environ
733 extern char **__environ;
734 # define DATASTART ((ptr_t)(&__environ))
735 /* hideous kludge: __environ is the first */
736 /* word in crt0.o, and delimits the start */
737 /* of the data segment, no matter which */
738 /* ld options were passed through. */
739 /* We could use _etext instead, but that */
740 /* would include .rodata, which may */
741 /* contain large read-only data tables */
742 /* that we'd rather not scan. */
743 # endif /* !GLIBC2 */
745 # define DATAEND (_end)
748 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
752 # define OS_TYPE "SUNOS4"
754 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
755 # define HEURISTIC1 /* differs */
756 # define DYNAMIC_LOADING
759 # define OS_TYPE "HP"
761 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
762 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
763 /* empirically determined. seems to work. */
765 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
768 # define OS_TYPE "SYSV"
770 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
772 +((word)etext & 0x1fff))
773 /* This only works for shared-text binaries with magic number 0413.
774 The other sorts of SysV binaries put the data at the end of the text,
775 in which case the default of etext would work. Unfortunately,
776 handling both would require having the magic-number available.
779 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
780 /* The stack starts at the top of memory, but */
781 /* 0x0 cannot be used as setjump_test complains */
782 /* that the stack direction is incorrect. Two */
783 /* bytes down from 0x0 should be safe enough. */
785 # include <sys/mmu.h>
786 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
789 # define OS_TYPE "AMIGA"
790 /* STACKBOTTOM and DATASTART handled specially */
792 # define DATAEND /* not needed */
793 # define GETPAGESIZE() 4096
799 # define OS_TYPE "MACOS"
800 /* see os_dep.c for details of global data segments. */
801 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
802 # define DATAEND /* not needed */
803 # define GETPAGESIZE() 4096
806 # define OS_TYPE "NEXT"
807 # define DATASTART ((ptr_t) get_etext())
808 # define STACKBOTTOM ((ptr_t) 0x4000000)
809 # define DATAEND /* not needed */
813 # if defined(POWERPC)
814 # define MACH_TYPE "POWERPC"
816 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
820 # define OS_TYPE "MACOS"
821 /* see os_dep.c for details of global data segments. */
822 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
823 # define DATAEND /* not needed */
827 # if defined(__powerpc64__)
829 # define CPP_WORDSZ 64
831 # define HBLKSIZE 4096
836 # define OS_TYPE "LINUX"
837 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
838 /* executable on a 64 bit kernel. */
839 # define LINUX_STACKBOTTOM
840 # define DYNAMIC_LOADING
841 # define SEARCH_FOR_DATA_START
843 # define DATAEND (_end)
848 # define CPP_WORDSZ 64
852 # define OS_TYPE "DARWIN"
853 # define DYNAMIC_LOADING
854 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
855 These aren't used when dyld support is enabled (it is by default) */
856 # define DATASTART ((ptr_t) get_etext())
857 # define DATAEND ((ptr_t) get_end())
858 # define STACKBOTTOM ((ptr_t) 0xc0000000)
860 # define USE_MMAP_ANON
861 # define USE_ASM_PUSH_REGS
862 /* This is potentially buggy. It needs more testing. See the comments in
863 os_dep.c. It relies on threads to track writes. */
864 # ifdef GC_DARWIN_THREADS
865 /* # define MPROTECT_VDB -- diabled for now. May work for some apps. */
868 # define GETPAGESIZE() getpagesize()
869 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
870 /* The performance impact of prefetches is untested */
871 # define PREFETCH(x) \
872 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
873 # define PREFETCH_FOR_WRITE(x) \
874 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
876 /* There seems to be some issues with trylock hanging on darwin. This
877 should be looked into some more */
878 # define NO_PTHREAD_TRYLOCK
882 # define OS_TYPE "FREEBSD"
883 # ifndef GC_FREEBSD_THREADS
884 # define MPROTECT_VDB
886 # define SIG_SUSPEND SIGUSR1
887 # define SIG_THR_RESTART SIGUSR2
888 # define FREEBSD_STACKBOTTOM
890 # define DYNAMIC_LOADING
893 extern char * GC_FreeBSDGetDataStart();
894 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
898 # define OS_TYPE "NETBSD"
901 # define DATASTART GC_data_start
902 # define DYNAMIC_LOADING
904 # ifdef SN_TARGET_PS3
906 # define CPP_WORDSZ 32
909 // extern int _dso_handle[];
910 extern int __bss_start;
912 # define DATAEND (_end)
913 # define DATASTART (__bss_start)
914 # define STACKBOTTOM ((ptr_t) ps3_get_stack_bottom ())
915 # define USE_GENERIC_PUSHREGS
920 # define OS_TYPE "NOSYS"
921 extern void __end[], __dso_handle[];
922 # define DATASTART (__dso_handle) /* OK, that's ugly. */
923 # define DATAEND (__end)
924 /* Stack starts at 0xE0000000 for the simulator. */
926 # define STACK_GRAN 0x10000000
932 # define MACH_TYPE "VAX"
933 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
935 # define DATASTART ((ptr_t)(etext))
937 # define OS_TYPE "BSD"
939 /* HEURISTIC2 may be OK, but it's hard to test. */
942 # define OS_TYPE "ULTRIX"
943 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
948 # define MACH_TYPE "RT"
950 # define DATASTART ((ptr_t) 0x10000000)
951 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
955 # define MACH_TYPE "SPARC"
956 # if defined(__arch64__) || defined(__sparcv9)
958 # define CPP_WORDSZ 64
959 # define ELF_CLASS ELFCLASS64
961 # define ALIGNMENT 4 /* Required by hardware */
962 # define CPP_WORDSZ 32
964 # define ALIGN_DOUBLE
965 # ifdef _FILE_OFFSET_BITS
966 # undef _FILE_OFFSET_BITS /* libelf.h & procfs.h doesn't compile with large file support */
967 # define _FILE_OFFSET_BITS 32
970 # define OS_TYPE "SUNOS5"
973 extern ptr_t GC_SysVGetDataStart();
974 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
975 # define DATAEND (_end)
976 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
978 /* Otherwise we now use calloc. Mmap may result in the */
979 /* heap interleaved with thread stacks, which can result in */
980 /* excessive blacklisting. Sbrk is unusable since it */
981 /* doesn't interact correctly with the system malloc. */
984 # define HEAP_START (ptr_t)0x40000000
986 # define HEAP_START DATAEND
989 /* HEURISTIC1 reportedly no longer works under 2.7. */
990 /* HEURISTIC2 probably works, but this appears to be preferable. */
991 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
992 /* installations that's undefined. We work around this with a */
994 # include <sys/vmparam.h>
996 /* This should work everywhere, but doesn't. */
997 # define STACKBOTTOM USRSTACK
1001 # include <unistd.h>
1002 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1003 /* getpagesize() appeared to be missing from at least one */
1004 /* Solaris 5.4 installation. Weird. */
1005 # define DYNAMIC_LOADING
1008 # define OS_TYPE "SUNOS4"
1009 /* [If you have a weak stomach, don't read this.] */
1010 /* We would like to use: */
1011 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
1012 /* This fails occasionally, due to an ancient, but very */
1013 /* persistent ld bug. etext is set 32 bytes too high. */
1014 /* We instead read the text segment size from the a.out */
1015 /* header, which happens to be mapped into our address space */
1016 /* at the start of the text segment. The detective work here */
1017 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
1018 /* Serpette of INRIA. */
1019 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
1020 # define TEXTSTART 0x2000
1021 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
1022 # define MPROTECT_VDB
1024 # define DYNAMIC_LOADING
1027 # define OS_TYPE "DRSNX"
1028 extern ptr_t GC_SysVGetDataStart();
1030 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1031 # define MPROTECT_VDB
1032 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
1033 # define DYNAMIC_LOADING
1036 # define OS_TYPE "LINUX"
1038 # define DYNAMIC_LOADING
1040 Linux Sparc/a.out not supported
1043 # include <features.h>
1044 # if defined(__GLIBC__) && __GLIBC__ >= 2
1045 # define SEARCH_FOR_DATA_START
1047 extern char **__environ;
1048 # define DATASTART ((ptr_t)(&__environ))
1049 /* hideous kludge: __environ is the first */
1050 /* word in crt0.o, and delimits the start */
1051 /* of the data segment, no matter which */
1052 /* ld options were passed through. */
1053 /* We could use _etext instead, but that */
1054 /* would include .rodata, which may */
1055 /* contain large read-only data tables */
1056 /* that we'd rather not scan. */
1059 # define DATAEND (_end)
1060 # define LINUX_STACKBOTTOM
1063 # define OS_TYPE "OPENBSD"
1064 # define STACKBOTTOM ((ptr_t) 0xf8000000)
1066 # define DATASTART ((ptr_t)(etext))
1069 # define OS_TYPE "NETBSD"
1072 # define DATASTART GC_data_start
1073 # define DYNAMIC_LOADING
1075 extern char etext[];
1076 # define DATASTART ((ptr_t)(etext))
1080 # define OS_TYPE "FREEBSD"
1081 # define SIG_SUSPEND SIGUSR1
1082 # define SIG_THR_RESTART SIGUSR2
1083 # define FREEBSD_STACKBOTTOM
1085 # define DYNAMIC_LOADING
1087 extern char etext[];
1088 extern char edata[];
1090 # define NEED_FIND_LIMIT
1091 # define DATASTART ((ptr_t)(&etext))
1092 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1093 # define DATASTART2 ((ptr_t)(&edata))
1094 # define DATAEND2 ((ptr_t)(&end))
1099 # if defined( NACL )
1100 # define MACH_TYPE "NACL"
1101 # define CPP_WORDSZ 32
1102 # define ALIGNMENT 4
1104 # define MACH_TYPE "I386"
1105 # if defined(__LP64__) || defined(_WIN64)
1106 # define CPP_WORDSZ 64
1107 # define ALIGNMENT 8
1109 # define CPP_WORDSZ 32
1110 # define ALIGNMENT 4
1112 /* Appears to hold for all "32 bit" compilers */
1113 /* except Borland. The -a4 option fixes */
1115 /* Ivan Demakov: For Watcom the option is -zp4. */
1117 # ifndef SMALL_CONFIG
1118 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
1119 /* improvement on Pentiums. */
1121 # ifdef HAVE_BUILTIN_UNWIND_INIT
1122 # define USE_GENERIC_PUSH_REGS
1125 # define OS_TYPE "SEQUENT"
1127 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1128 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1131 # define OS_TYPE "BEOS"
1133 # define GETPAGESIZE() B_PAGE_SIZE
1135 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1138 # define OS_TYPE "SUNOS5"
1139 extern int _etext[], _end[];
1140 extern ptr_t GC_SysVGetDataStart();
1141 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
1142 # define DATAEND (_end)
1143 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1144 /* but reportedly breaks under 2.8. It appears that the stack */
1145 /* base is a property of the executable, so this should not break */
1146 /* old executables. */
1147 /* HEURISTIC2 probably works, but this appears to be preferable. */
1148 # include <sys/vm.h>
1149 # define STACKBOTTOM USRSTACK
1150 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1151 /* It appears to be fixed in 2.8 and 2.9. */
1152 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1153 /* Reading of dirty bits doesn't seem to work even in solaris 10 */
1154 /*# define PROC_VDB */
1156 # define DYNAMIC_LOADING
1157 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1159 /* Otherwise we now use calloc. Mmap may result in the */
1160 /* heap interleaved with thread stacks, which can result in */
1161 /* excessive blacklisting. Sbrk is unusable since it */
1162 /* doesn't interact correctly with the system malloc. */
1165 # define HEAP_START (ptr_t)0x40000000
1167 # define HEAP_START DATAEND
1171 # define OS_TYPE "SCO"
1173 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1175 +((word)etext & 0xfff))
1176 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1179 # define OS_TYPE "SCO_ELF"
1181 # define DATASTART ((ptr_t)(etext))
1182 # define STACKBOTTOM ((ptr_t) 0x08048000)
1183 # define DYNAMIC_LOADING
1184 # define ELF_CLASS ELFCLASS32
1187 # define OS_TYPE "DGUX"
1188 extern int _etext, _end;
1189 extern ptr_t GC_SysVGetDataStart();
1190 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1191 # define DATAEND (&_end)
1192 # define STACK_GROWS_DOWN
1194 # include <unistd.h>
1195 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1196 # define DYNAMIC_LOADING
1199 # endif /* USE_MMAP */
1200 # define MAP_FAILED (void *) -1
1202 # define HEAP_START (ptr_t)0x40000000
1203 # else /* USE_MMAP */
1204 # define HEAP_START DATAEND
1205 # endif /* USE_MMAP */
1208 # define OS_TYPE "NACL"
1210 //# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1211 # define DATASTART ((ptr_t)0x10000000)
1213 # define DATAEND (_end)
1216 # endif /* STACK_GRAN */
1217 # define STACK_GRAN 0x10000
1225 # ifdef USE_MMAP_ANON
1226 # undef USE_MMAP_ANON
1228 # ifdef USE_MMAP_FIXED
1229 # undef USE_MMAP_FIXED
1231 # define GETPAGESIZE() 65536
1232 # define MAX_NACL_GC_THREADS 1024
1236 /* The Intel compiler doesn't like inline assembly */
1237 # define USE_GENERIC_PUSH_REGS
1239 # define OS_TYPE "LINUX"
1240 # define LINUX_STACKBOTTOM
1244 # define STACK_GRAN 0x10000000
1245 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1246 /* different kernel configurations. In particular, systems */
1247 /* with 2GB physical memory will usually move the user */
1248 /* address space limit, and hence initial SP to 0x80000000. */
1250 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1251 # define MPROTECT_VDB
1253 /* We seem to get random errors in incremental mode, */
1254 /* possibly because Linux threads is itself a malloc client */
1255 /* and can't deal with the signals. */
1257 # define HEAP_START (ptr_t)0x1000
1258 /* This encourages mmap to give us low addresses, */
1259 /* thus allowing the heap to grow to ~3GB */
1261 # define DYNAMIC_LOADING
1262 # ifdef UNDEFINED /* includes ro data */
1263 extern int _etext[];
1264 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1266 # include <features.h>
1267 # if defined(__GLIBC__) && __GLIBC__ >= 2
1268 # define SEARCH_FOR_DATA_START
1270 extern char **__environ;
1271 # define DATASTART ((ptr_t)(&__environ))
1272 /* hideous kludge: __environ is the first */
1273 /* word in crt0.o, and delimits the start */
1274 /* of the data segment, no matter which */
1275 /* ld options were passed through. */
1276 /* We could use _etext instead, but that */
1277 /* would include .rodata, which may */
1278 /* contain large read-only data tables */
1279 /* that we'd rather not scan. */
1282 # define DATAEND (_end)
1285 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1287 # ifdef USE_I686_PREFETCH
1288 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1289 /* for the next rtelease. */
1290 # define PREFETCH(x) \
1291 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1292 /* Empirically prefetcht0 is much more effective at reducing */
1293 /* cache miss stalls for the targetted load instructions. But it */
1294 /* seems to interfere enough with other cache traffic that the net */
1295 /* result is worse than prefetchnta. */
1297 /* Using prefetches for write seems to have a slight negative */
1298 /* impact on performance, at least for a PIII/500. */
1299 # define PREFETCH_FOR_WRITE(x) \
1300 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1303 # ifdef USE_3DNOW_PREFETCH
1304 # define PREFETCH(x) \
1305 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1306 # define PREFETCH_FOR_WRITE(x) \
1307 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1311 # define OS_TYPE "CYGWIN32"
1312 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1313 # define DATAEND ((ptr_t)GC_DATAEND)
1315 # define STACK_GRAN 0x10000
1319 # define OS_TYPE "OS2"
1320 /* STACKBOTTOM and DATASTART are handled specially in */
1321 /* os_dep.c. OS2 actually has the right */
1323 # define DATAEND /* not needed */
1324 # define USE_GENERIC_PUSH_REGS
1327 # define OS_TYPE "MSWIN32"
1328 /* STACKBOTTOM and DATASTART are handled specially in */
1330 # ifndef __WATCOMC__
1331 # define MPROTECT_VDB
1333 # define DATAEND /* not needed */
1336 # define OS_TYPE "MSWINCE"
1337 # define DATAEND /* not needed */
1340 # define OS_TYPE "DJGPP"
1341 # include "stubinfo.h"
1344 extern int __djgpp_stack_limit;
1345 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1346 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1348 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1349 /* This may not be right. */
1352 # define OS_TYPE "OPENBSD"
1353 # ifdef GC_OPENBSD_THREADS
1354 # define UTHREAD_SP_OFFSET 192
1356 # include <sys/param.h>
1357 # include <uvm/uvm_extern.h>
1358 # define STACKBOTTOM USRSTACK
1360 extern int __data_start[];
1361 # define DATASTART ((ptr_t)(__data_start))
1363 # define DATAEND ((ptr_t)(&_end))
1364 # define DYNAMIC_LOADING
1367 # define OS_TYPE "FREEBSD"
1368 # ifndef GC_FREEBSD_THREADS
1369 # define MPROTECT_VDB
1371 # define SIG_SUSPEND SIGTSTP
1372 # define SIG_THR_RESTART SIGCONT
1373 # define FREEBSD_STACKBOTTOM
1375 # define DYNAMIC_LOADING
1377 extern char etext[];
1378 extern char * GC_FreeBSDGetDataStart();
1379 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1382 # define OS_TYPE "NETBSD"
1384 # define DYNAMIC_LOADING
1388 # define OS_TYPE "THREE86BSD"
1391 # define OS_TYPE "BSDI"
1393 # if defined(OPENBSD) || defined(NETBSD) \
1394 || defined(THREE86BSD) || defined(BSDI)
1396 extern char etext[];
1397 # define DATASTART ((ptr_t)(etext))
1400 # define OS_TYPE "NEXT"
1401 # define DATASTART ((ptr_t) get_etext())
1402 # define STACKBOTTOM ((ptr_t)0xc0000000)
1403 # define DATAEND /* not needed */
1406 # define OS_TYPE "DOS4GW"
1407 extern long __nullarea;
1409 extern char *_STACKTOP;
1410 /* Depending on calling conventions Watcom C either precedes
1411 or does not precedes with undescore names of C-variables.
1412 Make sure startup code variables always have the same names. */
1413 #pragma aux __nullarea "*";
1414 #pragma aux _end "*";
1415 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1416 /* confused? me too. */
1417 # define DATASTART ((ptr_t) &__nullarea)
1418 # define DATAEND ((ptr_t) &_end)
1421 # define OS_TYPE "HURD"
1422 # define STACK_GROWS_DOWN
1424 extern int __data_start[];
1425 # define DATASTART ( (ptr_t) (__data_start))
1427 # define DATAEND ( (ptr_t) (_end))
1428 /* # define MPROTECT_VDB Not quite working yet? */
1429 # define DYNAMIC_LOADING
1434 # define MACH_TYPE "NS32K"
1435 # define ALIGNMENT 4
1436 extern char **environ;
1437 # define DATASTART ((ptr_t)(&environ))
1438 /* hideous kludge: environ is the first */
1439 /* word in crt0.o, and delimits the start */
1440 /* of the data segment, no matter which */
1441 /* ld options were passed through. */
1442 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1446 # define MACH_TYPE "MIPS"
1448 /* This was developed for a linuxce style platform. Probably */
1449 /* needs to be tweaked for workstation class machines. */
1450 # define OS_TYPE "LINUX"
1451 # define DYNAMIC_LOADING
1453 # define DATAEND (_end)
1454 #pragma weak __data_start
1455 extern int __data_start[];
1456 # define DATASTART ((ptr_t)(__data_start))
1457 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1458 # define ALIGNMENT 8
1459 # define CPP_WORDSZ 64
1461 # define ALIGNMENT 4
1463 # define USE_GENERIC_PUSH_REGS
1464 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1465 # define LINUX_STACKBOTTOM
1467 # define STACKBOTTOM 0x80000000
1472 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1473 extern int _fdata[], _end[];
1474 # define DATASTART ((ptr_t)_fdata)
1475 # define DATAEND ((ptr_t)_end)
1476 # define CPP_WORDSZ _MIPS_SZPTR
1477 # define ALIGNMENT (_MIPS_SZPTR/8)
1479 extern int etext[], edata[], end[];
1480 extern int _DYNAMIC_LINKING[], _gp[];
1481 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1482 + ((word)etext & 0xffff)))
1483 # define DATAEND (edata)
1484 # define DATASTART2 (_DYNAMIC_LINKING \
1485 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1487 # define DATAEND2 (end)
1488 # define ALIGNMENT 4
1490 # define OS_TYPE "EWS4800"
1491 # define USE_GENERIC_PUSH_REGS 1
1495 # define DATASTART (ptr_t)0x10000000
1496 /* Could probably be slightly higher since */
1497 /* startup code allocates lots of stuff. */
1498 # define OS_TYPE "ULTRIX"
1499 # define ALIGNMENT 4
1503 # define DATASTART (ptr_t)0x10000000
1504 # define OS_TYPE "RISCOS"
1505 # define ALIGNMENT 4 /* Required by hardware */
1509 extern int _fdata[];
1510 # define DATASTART ((ptr_t)(_fdata))
1512 # define HEAP_START (ptr_t)0x30000000
1514 # define HEAP_START DATASTART
1516 /* Lowest plausible heap address. */
1517 /* In the MMAP case, we map there. */
1518 /* In either case it is used to identify */
1519 /* heap sections so they're not */
1520 /* considered as roots. */
1521 # define OS_TYPE "IRIX5"
1522 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1523 /* of recent breakage. */
1525 # define CPP_WORDSZ _MIPS_SZPTR
1526 # define ALIGNMENT (_MIPS_SZPTR/8)
1527 # if CPP_WORDSZ != 64
1528 # define ALIGN_DOUBLE
1531 # define ALIGNMENT 4
1532 # define ALIGN_DOUBLE
1534 # define DYNAMIC_LOADING
1537 # define OS_TYPE "MSWINCE"
1538 # define ALIGNMENT 4
1539 # define DATAEND /* not needed */
1541 # if defined(NETBSD)
1542 # define ALIGNMENT 4
1543 # define OS_TYPE "NETBSD"
1545 # define USE_GENERIC_PUSH_REGS
1548 # define DATASTART GC_data_start
1549 # define NEED_FIND_LIMIT
1550 # define DYNAMIC_LOADING
1552 # define DATASTART ((ptr_t) 0x10000000)
1553 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1559 # define MACH_TYPE "RS6000"
1564 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1567 # define ALIGNMENT 8
1568 # define CPP_WORDSZ 64
1569 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1571 # define ALIGNMENT 4
1572 # define CPP_WORDSZ 32
1573 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1576 # define USE_MMAP_ANON
1577 /* From AIX linker man page:
1578 _text Specifies the first location of the program.
1579 _etext Specifies the first location after the program.
1580 _data Specifies the first location of the data.
1581 _edata Specifies the first location after the initialized data
1582 _end or end Specifies the first location after all data.
1584 extern int _data[], _end[];
1585 # define DATASTART ((ptr_t)((ulong)_data))
1586 # define DATAEND ((ptr_t)((ulong)_end))
1588 # define USE_GENERIC_PUSH_REGS
1589 # define DYNAMIC_LOADING
1590 /* For really old versions of AIX, this may have to be removed. */
1594 # define MACH_TYPE "HP_PA"
1596 # define CPP_WORDSZ 64
1597 # define ALIGNMENT 8
1599 # define CPP_WORDSZ 32
1600 # define ALIGNMENT 4
1601 # define ALIGN_DOUBLE
1603 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1604 # ifndef LINUX /* For now. */
1605 # define MPROTECT_VDB
1608 # define GENERIC_COMPARE_AND_SWAP
1609 /* No compare-and-swap instruction. Use pthread mutexes */
1610 /* when we absolutely have to. */
1611 # ifdef PARALLEL_MARK
1612 # define USE_MARK_BYTES
1613 /* Minimize compare-and-swap usage. */
1616 # define STACK_GROWS_UP
1618 # define OS_TYPE "HPUX"
1619 extern int __data_start[];
1620 # define DATASTART ((ptr_t)(__data_start))
1622 /* The following appears to work for 7xx systems running HP/UX */
1623 /* 9.xx Furthermore, it might result in much faster */
1624 /* collections than HEURISTIC2, which may involve scanning */
1625 /* segments that directly precede the stack. It is not the */
1626 /* default, since it may not work on older machine/OS */
1627 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1629 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1631 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1632 /* to this. Note that the GC must be initialized before the */
1633 /* first putenv call. */
1634 extern char ** environ;
1635 # define STACKBOTTOM ((ptr_t)environ)
1637 # define DYNAMIC_LOADING
1638 # include <unistd.h>
1639 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1641 # define PREFETCH(x) { \
1642 register long addr = (long)(x); \
1643 (void) _asm ("LDW", 0, 0, addr, 0); \
1648 # define OS_TYPE "LINUX"
1649 # define LINUX_STACKBOTTOM
1650 # define DYNAMIC_LOADING
1651 # define SEARCH_FOR_DATA_START
1653 # define DATAEND (&_end)
1658 # define MACH_TYPE "ALPHA"
1659 # define ALIGNMENT 8
1660 # define CPP_WORDSZ 64
1662 # define USE_GENERIC_PUSH_REGS
1663 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1664 /* fp registers in some cases when the target is a 21264. The assembly */
1665 /* code doesn't handle that yet, and version dependencies make that a */
1666 /* bit tricky. Do the easy thing for now. */
1669 # define OS_TYPE "NETBSD"
1671 # define DATASTART GC_data_start
1672 # define ELFCLASS32 32
1673 # define ELFCLASS64 64
1674 # define ELF_CLASS ELFCLASS64
1675 # define DYNAMIC_LOADING
1678 # define OS_TYPE "OPENBSD"
1680 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1681 # define DATASTART GC_data_start
1682 # define ELFCLASS32 32
1683 # define ELFCLASS64 64
1684 # define ELF_CLASS ELFCLASS64
1685 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1686 # define DATASTART ((ptr_t) 0x140000000)
1690 # define OS_TYPE "FREEBSD"
1691 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1692 # define SIG_SUSPEND SIGTSTP
1693 # define SIG_THR_RESTART SIGCONT
1694 # define FREEBSD_STACKBOTTOM
1696 # define DYNAMIC_LOADING
1698 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1699 extern char etext[];
1700 extern char edata[];
1702 # define NEED_FIND_LIMIT
1703 # define DATASTART ((ptr_t)(&etext))
1704 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1705 # define DATASTART2 ((ptr_t)(&edata))
1706 # define DATAEND2 ((ptr_t)(&end))
1709 # define OS_TYPE "OSF1"
1710 # define DATASTART ((ptr_t) 0x140000000)
1712 # define DATAEND ((ptr_t) &_end)
1713 extern char ** environ;
1714 /* round up from the value of environ to the nearest page boundary */
1715 /* Probably breaks if putenv is called before collector */
1716 /* initialization. */
1717 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1718 /* # define HEURISTIC2 */
1719 /* Normally HEURISTIC2 is too conervative, since */
1720 /* the text segment immediately follows the stack. */
1721 /* Hence we give an upper pound. */
1722 /* This is currently unused, since we disabled HEURISTIC2 */
1723 extern int __start[];
1724 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1725 # ifndef GC_OSF1_THREADS
1726 /* Unresolved signal issues with threads. */
1727 # define MPROTECT_VDB
1729 # define DYNAMIC_LOADING
1732 # define OS_TYPE "LINUX"
1733 # define LINUX_STACKBOTTOM
1735 # define SEARCH_FOR_DATA_START
1736 # define DYNAMIC_LOADING
1738 # define DATASTART ((ptr_t) 0x140000000)
1741 # define DATAEND (_end)
1742 # define MPROTECT_VDB
1743 /* Has only been superficially tested. May not */
1744 /* work on all versions. */
1749 # define MACH_TYPE "IA64"
1750 # define USE_GENERIC_PUSH_REGS
1751 /* We need to get preserved registers in addition to register */
1752 /* windows. That's easiest to do with setjmp. */
1753 # ifdef PARALLEL_MARK
1754 # define USE_MARK_BYTES
1755 /* Compare-and-exchange is too expensive to use for */
1756 /* setting mark bits. */
1760 # define CPP_WORDSZ 32
1761 # define ALIGN_DOUBLE
1762 /* Requires 8 byte alignment for malloc */
1763 # define ALIGNMENT 4
1768 # define CPP_WORDSZ 64
1769 # define ALIGN_DOUBLE
1770 /* Requires 16 byte alignment for malloc */
1771 # define ALIGNMENT 8
1773 # define OS_TYPE "HPUX"
1774 extern int __data_start[];
1775 # define DATASTART ((ptr_t)(__data_start))
1776 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1777 /* to this. Note that the GC must be initialized before the */
1778 /* first putenv call. */
1779 extern char ** environ;
1780 # define STACKBOTTOM ((ptr_t)environ)
1781 # define HPUX_STACKBOTTOM
1782 # define DYNAMIC_LOADING
1783 # include <unistd.h>
1784 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1785 /* The following was empirically determined, and is probably */
1786 /* not very robust. */
1787 /* Note that the backing store base seems to be at a nice */
1788 /* address minus one page. */
1789 # define BACKING_STORE_DISPLACEMENT 0x1000000
1790 # define BACKING_STORE_ALIGNMENT 0x1000
1791 extern ptr_t GC_register_stackbottom;
1792 # define BACKING_STORE_BASE GC_register_stackbottom
1793 /* Known to be wrong for recent HP/UX versions!!! */
1796 # define CPP_WORDSZ 64
1797 # define ALIGN_DOUBLE
1798 /* Requires 16 byte alignment for malloc */
1799 # define ALIGNMENT 8
1800 # define OS_TYPE "LINUX"
1801 /* The following works on NUE and older kernels: */
1802 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1803 /* This does not work on NUE: */
1804 # define LINUX_STACKBOTTOM
1805 /* We also need the base address of the register stack */
1806 /* backing store. This is computed in */
1807 /* GC_linux_register_stack_base based on the following */
1809 # define BACKING_STORE_ALIGNMENT 0x100000
1810 # define BACKING_STORE_DISPLACEMENT 0x80000000
1811 extern ptr_t GC_register_stackbottom;
1812 # define BACKING_STORE_BASE GC_register_stackbottom
1813 # define SEARCH_FOR_DATA_START
1815 # define DYNAMIC_LOADING
1817 /* In the Intel compiler environment, we seem to end up with */
1818 /* statically linked executables and an undefined reference */
1821 # define MPROTECT_VDB
1822 /* Requires Linux 2.3.47 or later. */
1824 # define DATAEND (_end)
1826 # ifndef __INTEL_COMPILER
1827 # define PREFETCH(x) \
1828 __asm__ (" lfetch [%0]": : "r"(x))
1829 # define PREFETCH_FOR_WRITE(x) \
1830 __asm__ (" lfetch.excl [%0]": : "r"(x))
1831 # define CLEAR_DOUBLE(x) \
1832 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1834 # include <ia64intrin.h>
1835 # define PREFETCH(x) \
1836 __lfetch(__lfhint_none, (x))
1837 # define PREFETCH_FOR_WRITE(x) \
1838 __lfetch(__lfhint_nta, (x))
1839 # define CLEAR_DOUBLE(x) \
1840 __stf_spill((void *)(x), 0)
1841 # endif // __INTEL_COMPILER
1845 /* FIXME: This is a very partial guess. There is no port, yet. */
1846 # define OS_TYPE "MSWIN32"
1847 /* STACKBOTTOM and DATASTART are handled specially in */
1849 # define DATAEND /* not needed */
1850 # if defined(_WIN64)
1851 # define CPP_WORDSZ 64
1853 # define CPP_WORDSZ 32 /* Is this possible? */
1855 # define ALIGNMENT 8
1860 # define MACH_TYPE "M88K"
1861 # define ALIGNMENT 4
1862 # define ALIGN_DOUBLE
1865 # define OS_TYPE "CX_UX"
1866 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1869 # define OS_TYPE "DGUX"
1870 extern ptr_t GC_SysVGetDataStart();
1871 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1873 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1877 /* If this still works, and if anyone cares, this should probably */
1878 /* be moved to the S390 category. */
1879 # define MACH_TYPE "S370"
1880 # define ALIGNMENT 4 /* Required by hardware */
1881 # define USE_GENERIC_PUSH_REGS
1883 # define OS_TYPE "UTS4"
1885 extern int _etext[];
1887 extern ptr_t GC_SysVGetDataStart();
1888 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1889 # define DATAEND (_end)
1895 # define MACH_TYPE "S390"
1896 # define USE_GENERIC_PUSH_REGS
1898 # define ALIGNMENT 4
1899 # define CPP_WORDSZ 32
1901 # define ALIGNMENT 8
1902 # define CPP_WORDSZ 64
1905 # define HBLKSIZE 4096
1908 # define OS_TYPE "LINUX"
1909 # define LINUX_STACKBOTTOM
1910 # define DYNAMIC_LOADING
1911 extern int __data_start[];
1912 # define DATASTART ((ptr_t)(__data_start))
1914 # define DATAEND (_end)
1915 # define CACHE_LINE_SIZE 256
1916 # define GETPAGESIZE() 4096
1921 # define ALIGNMENT 4
1922 extern int _etext[];
1923 # define DATASTART ((ptr_t)(_etext))
1928 # define CPP_WORDSZ 32
1929 # define MACH_TYPE "ARM32"
1930 # define ALIGNMENT 4
1932 # define OS_TYPE "NETBSD"
1935 # define DATASTART GC_data_start
1936 # define DYNAMIC_LOADING
1938 extern char etext[];
1939 # define DATASTART ((ptr_t)(etext))
1941 # define USE_GENERIC_PUSH_REGS
1944 # define OS_TYPE "LINUX"
1945 # define LINUX_STACKBOTTOM
1947 # define STACK_GRAN 0x10000000
1948 # define USE_GENERIC_PUSH_REGS
1950 # define DYNAMIC_LOADING
1951 # include <features.h>
1952 # if defined(__GLIBC__) && __GLIBC__ >= 2
1953 # define SEARCH_FOR_DATA_START
1954 # elif defined(PLATFORM_ANDROID)
1955 # define SEARCH_FOR_DATA_START
1957 extern char **__environ;
1958 # define DATASTART ((ptr_t)(&__environ))
1959 /* hideous kludge: __environ is the first */
1960 /* word in crt0.o, and delimits the start */
1961 /* of the data segment, no matter which */
1962 /* ld options were passed through. */
1963 /* We could use _etext instead, but that */
1964 /* would include .rodata, which may */
1965 /* contain large read-only data tables */
1966 /* that we'd rather not scan. */
1969 # define DATAEND (_end)
1972 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1976 # define OS_TYPE "MSWINCE"
1977 # define DATAEND /* not needed */
1980 # define OS_TYPE "DARWIN"
1981 # define DATASTART ((ptr_t) get_etext())
1982 # define DATAEND ((ptr_t) get_end())
1983 # define STACKBOTTOM ((ptr_t) 0x30000000)
1985 # define USE_MMAP_ANON
1989 /* __data_start is usually defined in the target linker script. */
1990 extern int __data_start[];
1991 # define DATASTART (ptr_t)(__data_start)
1992 # define USE_GENERIC_PUSH_REGS
1993 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1994 extern void *__stack_base__;
1995 # define STACKBOTTOM ((ptr_t) (__stack_base__))
2000 # define MACH_TYPE "CRIS"
2001 # define CPP_WORDSZ 32
2002 # define ALIGNMENT 1
2003 # define OS_TYPE "LINUX"
2004 # define DYNAMIC_LOADING
2005 # define LINUX_STACKBOTTOM
2006 # define USE_GENERIC_PUSH_REGS
2007 # define SEARCH_FOR_DATA_START
2009 # define DATAEND (_end)
2013 # define MACH_TYPE "SH"
2014 # define ALIGNMENT 4
2016 # define OS_TYPE "MSWINCE"
2017 # define DATAEND /* not needed */
2020 # define OS_TYPE "LINUX"
2021 # define LINUX_STACKBOTTOM
2022 # define USE_GENERIC_PUSH_REGS
2023 # define DYNAMIC_LOADING
2024 # define SEARCH_FOR_DATA_START
2026 # define DATAEND (_end)
2029 # define OS_TYPE "NETBSD"
2031 # define DATASTART GC_data_start
2032 # define USE_GENERIC_PUSH_REGS
2033 # define DYNAMIC_LOADING
2038 # define MACH_TYPE "SH4"
2039 # define OS_TYPE "MSWINCE"
2040 # define ALIGNMENT 4
2041 # define DATAEND /* not needed */
2045 # define CPP_WORDSZ 32
2046 # define MACH_TYPE "M32R"
2047 # define ALIGNMENT 4
2049 # define OS_TYPE "LINUX"
2050 # define LINUX_STACKBOTTOM
2052 # define STACK_GRAN 0x10000000
2053 # define USE_GENERIC_PUSH_REGS
2054 # define DYNAMIC_LOADING
2055 # define SEARCH_FOR_DATA_START
2057 # define DATAEND (_end)
2062 # define MACH_TYPE "X86_64"
2063 # define ALIGNMENT 8
2064 # define CPP_WORDSZ 64
2066 # define HBLKSIZE 4096
2068 # define CACHE_LINE_SIZE 64
2069 # define USE_GENERIC_PUSH_REGS
2071 # define OS_TYPE "LINUX"
2072 # define LINUX_STACKBOTTOM
2074 # define FALLBACK_TO_MMAP
2076 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2077 # define MPROTECT_VDB
2079 /* We seem to get random errors in incremental mode, */
2080 /* possibly because Linux threads is itself a malloc client */
2081 /* and can't deal with the signals. */
2084 # define DYNAMIC_LOADING
2085 # ifdef UNDEFINED /* includes ro data */
2086 extern int _etext[];
2087 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
2089 # include <features.h>
2090 # define SEARCH_FOR_DATA_START
2092 # define DATAEND (_end)
2095 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
2097 # if defined(__GNUC__) && __GNUC >= 3
2098 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
2099 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
2103 # define OS_TYPE "DARWIN"
2104 # define DARWIN_DONT_PARSE_STACK
2105 # define DYNAMIC_LOADING
2106 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
2107 These aren't used when dyld support is enabled (it is by default) */
2108 # define DATASTART ((ptr_t) get_etext())
2109 # define DATAEND ((ptr_t) get_end())
2110 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
2114 # define USE_MMAP_ANON
2115 # ifdef GC_DARWIN_THREADS
2116 # define MPROTECT_VDB
2118 # include <unistd.h>
2119 # define GETPAGESIZE() getpagesize()
2120 /* There seems to be some issues with trylock hanging on darwin. This
2121 should be looked into some more */
2124 # define OS_TYPE "FREEBSD"
2125 # ifndef GC_FREEBSD_THREADS
2126 # define MPROTECT_VDB
2128 # define SIG_SUSPEND SIGTSTP
2129 # define SIG_THR_RESTART SIGCONT
2130 # define NEED_FIND_LIMIT
2131 # define FREEBSD_STACKBOTTOM
2133 # define DYNAMIC_LOADING
2135 extern char etext[];
2136 extern char * GC_FreeBSDGetDataStart();
2137 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
2140 # define OS_TYPE "NETBSD"
2142 # define DYNAMIC_LOADING
2145 extern char etext[];
2146 # define SEARCH_FOR_DATA_START
2149 # define OS_TYPE "OPENBSD"
2150 # define ELF_CLASS ELFCLASS64
2151 # ifdef GC_OPENBSD_THREADS
2152 # define UTHREAD_SP_OFFSET 400
2154 # include <sys/param.h>
2155 # include <uvm/uvm_extern.h>
2156 # define STACKBOTTOM USRSTACK
2158 extern int __data_start[];
2159 # define DATASTART ((ptr_t)(__data_start))
2161 # define DATAEND ((ptr_t)(&_end))
2162 # define DYNAMIC_LOADING
2166 #if defined(LINUX) && defined(USE_MMAP)
2167 /* The kernel may do a somewhat better job merging mappings etc. */
2168 /* with anonymous mappings. */
2169 # define USE_MMAP_ANON
2172 #if defined(LINUX) && defined(REDIRECT_MALLOC)
2173 /* Rld appears to allocate some memory with its own allocator, and */
2174 /* some through malloc, which might be redirected. To make this */
2175 /* work with collectable memory, we have to scan memory allocated */
2176 /* by rld's internal malloc. */
2177 # define USE_PROC_FOR_LIBRARIES
2180 # ifndef STACK_GROWS_UP
2181 # define STACK_GROWS_DOWN
2185 # define CPP_WORDSZ 32
2194 # define DATAEND (end)
2197 # if defined(SVR4) && !defined(GETPAGESIZE)
2198 # include <unistd.h>
2199 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
2202 # ifndef GETPAGESIZE
2203 # if defined(SUNOS5) || defined(IRIX5)
2204 # include <unistd.h>
2206 # define GETPAGESIZE() getpagesize()
2209 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
2210 /* OS has SVR4 generic features. Probably others also qualify. */
2214 # if defined(SUNOS5) || defined(DRSNX)
2215 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
2218 /* OS has SUNOS5 style signal handlers. */
2226 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
2230 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2231 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2232 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
2233 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
2234 # define UNIX_LIKE /* Basic Unix-like system calls work. */
2237 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2242 # undef DYNAMIC_LOADING
2247 # undef MPROTECT_VDB
2252 /* Postponed for now. */
2254 # undef MPROTECT_VDB
2257 # ifdef SMALL_CONFIG
2258 /* Presumably not worth the space it takes. */
2260 # undef MPROTECT_VDB
2264 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2267 # ifdef PARALLEL_MARK
2268 # undef MPROTECT_VDB /* For now. */
2271 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2272 # define DEFAULT_VDB
2276 # define PREFETCH(x)
2277 # define NO_PREFETCH
2280 # ifndef PREFETCH_FOR_WRITE
2281 # define PREFETCH_FOR_WRITE(x)
2282 # define NO_PREFETCH_FOR_WRITE
2285 # ifndef CACHE_LINE_SIZE
2286 # define CACHE_LINE_SIZE 32 /* Wild guess */
2290 # define REGISTER_LIBRARIES_EARLY
2291 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2292 /* lock. This isn't safe after the world has stopped. So we must */
2293 /* call GC_register_dynamic_libraries before stopping the world. */
2294 /* For performance reasons, this may be beneficial on other */
2295 /* platforms as well, though it should be avoided in win32. */
2298 # if defined(SEARCH_FOR_DATA_START)
2299 extern ptr_t GC_data_start;
2300 # define DATASTART GC_data_start
2303 # ifndef CLEAR_DOUBLE
2304 # define CLEAR_DOUBLE(x) \
2305 ((word*)x)[0] = 0; \
2307 # endif /* CLEAR_DOUBLE */
2309 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2310 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2311 # define GC_SOLARIS_THREADS
2314 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2315 --> inconsistent configuration
2317 # if defined(GC_LINUX_THREADS) && !(defined(LINUX) || defined(NACL))
2318 --> inconsistent configuration
2320 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2321 --> inconsistent configuration
2323 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2324 --> inconsistent configuration
2326 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2327 --> inconsistent configuration
2329 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2330 --> inconsistent configuration
2333 # if defined(PCR) || defined(SRC_M3) || \
2334 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2335 defined(GC_PTHREADS) || defined(SN_TARGET_PS3)
2339 # if defined(HP_PA) || defined(M88K) \
2340 || defined(POWERPC) && !defined(DARWIN) \
2341 || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2342 || (defined(I386) && defined(__LCC__))
2343 /* Use setjmp based hack to mark from callee-save registers. */
2344 /* The define should move to the individual platform */
2346 # define USE_GENERIC_PUSH_REGS
2349 # if defined(MSWINCE)
2354 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2355 /* include assembly code to do it well. */
2358 /* Can we save call chain in objects for debugging? */
2359 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2360 /* frame) to reasonable values for the platform. */
2361 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2362 /* at build time, though we feel free to adjust it slightly. */
2363 /* Define NEED_CALLINFO if we either save the call stack or */
2364 /* GC_ADD_CALLER is defined. */
2365 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2368 # define CAN_SAVE_CALL_ARGS
2370 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2371 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2372 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2373 # define CAN_SAVE_CALL_ARGS
2376 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2377 && defined(GC_CAN_SAVE_CALL_STACKS)
2378 # define SAVE_CALL_CHAIN
2380 # ifdef SAVE_CALL_CHAIN
2381 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2382 # define NARGS SAVE_CALL_NARGS
2384 # define NARGS 0 /* Number of arguments to save for each call. */
2387 # ifdef SAVE_CALL_CHAIN
2388 # ifndef SAVE_CALL_COUNT
2389 # define NFRAMES 6 /* Number of frames to save. Even for */
2390 /* alignment reasons. */
2392 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2394 # define NEED_CALLINFO
2395 # endif /* SAVE_CALL_CHAIN */
2396 # ifdef GC_ADD_CALLER
2399 # define NEED_CALLINFO
2402 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2403 # define DBG_HDRS_ALL
2406 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2407 # define POINTER_SHIFT 0
2410 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2411 # define POINTER_MASK ((GC_word)(-1))
2414 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2415 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2418 # if defined(FIXUP_POINTER)
2419 # define NEED_FIXUP_POINTER 1
2421 # define NEED_FIXUP_POINTER 0
2422 # define FIXUP_POINTER(p)
2426 /* This relies on some type definitions from gc_priv.h, from */
2427 /* where it's normally included. */
2429 /* How to get heap memory from the OS: */
2430 /* Note that sbrk()-like allocation is preferred, since it */
2431 /* usually makes it possible to merge consecutively allocated */
2432 /* chunks. It also avoids unintented recursion with */
2433 /* -DREDIRECT_MALLOC. */
2434 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2435 /* 0 is taken to mean failure. */
2436 /* In the case os USE_MMAP, the argument must also be a */
2437 /* physical page size. */
2438 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2439 /* though we should perhaps take advantage of the case in which */
2441 struct hblk; /* See gc_priv.h. */
2443 char * real_malloc();
2444 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2448 void * os2_alloc(size_t bytes);
2449 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2453 # if defined(NEXT) || defined(DOS4GW) || \
2454 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2455 (defined(SUNOS5) && !defined(USE_MMAP))
2456 # define GET_MEM(bytes) HBLKPTR((size_t) \
2457 calloc(1, (size_t)bytes + GC_page_size) \
2461 extern ptr_t GC_win32_get_mem();
2462 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2465 # if defined(USE_TEMPORARY_MEMORY)
2466 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2467 Boolean clearMemory);
2468 # define GET_MEM(bytes) HBLKPTR( \
2469 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2472 # define GET_MEM(bytes) HBLKPTR( \
2473 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2477 extern ptr_t GC_wince_get_mem();
2478 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2480 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2481 extern void *GC_amiga_get_mem(size_t size);
2482 # define GET_MEM(bytes) HBLKPTR((size_t) \
2483 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2486 # if defined(SN_TARGET_PS3)
2487 extern void *ps3_get_mem (size_t size);
2488 # define GET_MEM(bytes) (struct hblk*) ps3_get_mem (bytes)
2490 extern ptr_t GC_unix_get_mem(word size);
2491 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2501 #endif /* GC_PRIVATE_H */
2503 #if defined(_AIX) && !defined(__GNUC__) && !defined(__STDC__)
2504 /* IBMs xlc compiler doesn't appear to follow the convention of */
2505 /* defining __STDC__ to be zero in extended mode. */
2509 # endif /* GCCONFIG_H */