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 # if defined(__ppc__) || defined(__ppc64__)
317 # define mach_type_known
318 # elif defined(__i386__)
320 # define mach_type_known
321 # define DARWIN_DONT_PARSE_STACK
322 # define OS_TYPE "DARWIN"
323 # define DYNAMIC_LOADING
324 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
325 These aren't used when dyld support is enabled (it is by default) */
326 # define DATASTART ((ptr_t) get_etext())
327 # define DATAEND ((ptr_t) get_end())
328 # define STACKBOTTOM ((ptr_t) 0xc0000000)
330 # define USE_MMAP_ANON
331 # define USE_ASM_PUSH_REGS
332 /* This is potentially buggy. It needs more testing. See the comments in
333 os_dep.c. It relies on threads to track writes. */
334 # ifdef GC_DARWIN_THREADS
335 /* # define MPROTECT_VDB -- diabled for now. May work for some apps. */
338 # define GETPAGESIZE() getpagesize()
339 # elif defined(__arm__)
341 # define mach_type_known
342 # define DARWIN_DONT_PARSE_STACK
343 # define GC_DONT_REGISTER_MAIN_STATIC_DATA
344 # elif defined(__x86_64)
346 # define mach_type_known
349 # if defined(NeXT) && defined(mc68000)
352 # define mach_type_known
354 # if defined(NeXT) && (defined(i386) || defined(__i386__))
357 # define mach_type_known
359 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
362 # define mach_type_known
364 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
366 # define mach_type_known
368 # if defined(FREEBSD) && defined(__x86_64__)
370 # define mach_type_known
372 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
374 # define mach_type_known
376 # if defined(__NetBSD__) && defined(__x86_64__)
378 # define mach_type_known
380 # if defined(FREEBSD) && defined(__sparc__)
382 # define mach_type_known
384 # if defined(bsdi) && (defined(i386) || defined(__i386__))
387 # define mach_type_known
389 # if !defined(mach_type_known) && defined(__386BSD__)
392 # define mach_type_known
394 # if defined(_CX_UX) && defined(_M88K)
397 # define mach_type_known
399 # if defined(DGUX) && defined(m88k)
402 # define mach_type_known
404 # if defined(_WIN32_WCE)
405 /* SH3, SH4, MIPS already defined for corresponding architectures */
406 # if defined(SH3) || defined(SH4)
416 # define mach_type_known
418 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
419 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
420 # if defined(__LP64__) || defined(_WIN64)
425 # define MSWIN32 /* or Win64 */
426 # define mach_type_known
428 # if defined(_MSC_VER) && defined(_M_IA64)
430 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
431 /* variants as a differnt platform. */
434 # if defined(__DJGPP__)
437 # define DJGPP /* MSDOS running the DJGPP port of GCC */
439 # define mach_type_known
441 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
444 # define mach_type_known
446 # if defined(__MINGW32__)
449 # define mach_type_known
451 # if defined(__BORLANDC__)
454 # define mach_type_known
456 # if defined(_UTS) && !defined(mach_type_known)
459 # define mach_type_known
463 # define mach_type_known
465 # if defined(__embedded__) && defined(PPC)
468 # define mach_type_known
471 # if defined(__WATCOMC__) && defined(__386__)
473 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
474 # if defined(__OS2__)
477 # if defined(__WINDOWS_386__) || defined(__NT__)
484 # define mach_type_known
486 # if defined(__s390__) && defined(LINUX)
488 # define mach_type_known
490 # if defined(__GNU__)
491 # if defined(__i386__)
492 /* The Debian Hurd running on generic PC */
495 # define mach_type_known
499 /* Feel free to add more clauses here */
501 /* Or manually define the machine type here. A machine type is */
502 /* characterized by the architecture. Some */
503 /* machine types are further subdivided by OS. */
504 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
505 /* Note that SGI IRIX is treated identically to RISCOS. */
506 /* SYSV on an M68K actually means A/UX. */
507 /* The distinction in these cases is usually the stack starting address */
508 # ifndef mach_type_known
509 --> unknown machine type
511 /* Mapping is: M68K ==> Motorola 680X0 */
512 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
513 /* MACOS and AMIGA variants) */
514 /* I386 ==> Intel 386 */
515 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
516 /* FREEBSD, THREE86BSD, MSWIN32, */
517 /* BSDI,SUNOS5, NEXT, other variants) */
518 /* NS32K ==> Encore Multimax */
519 /* MIPS ==> R2000 or R3000 */
520 /* (RISCOS, ULTRIX variants) */
521 /* VAX ==> DEC VAX */
522 /* (BSD, ULTRIX variants) */
523 /* RS6000 ==> IBM RS/6000 AIX3.X */
524 /* RT ==> IBM PC/RT */
525 /* HP_PA ==> HP9000/700 & /800 */
527 /* SPARC ==> SPARC v7/v8/v9 */
528 /* (SUNOS4, SUNOS5, LINUX, */
529 /* DRSNX variants) */
530 /* ALPHA ==> DEC Alpha */
531 /* (OSF1 and LINUX variants) */
532 /* M88K ==> Motorola 88XX0 */
533 /* (CX_UX and DGUX) */
534 /* S370 ==> 370-like machine */
535 /* running Amdahl UTS4 */
536 /* S390 ==> 390-like machine */
538 /* ARM32 ==> Intel StrongARM */
539 /* IA64 ==> Intel IPF */
541 /* (LINUX and HPUX) */
542 /* SH ==> Hitachi SuperH */
543 /* (LINUX & MSWINCE) */
544 /* X86_64 ==> AMD x86-64 */
545 /* POWERPC ==> IBM/Apple PowerPC */
546 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
547 /* LINUX, NETBSD, NOSYS variants) */
548 /* Handles 32 and 64-bit variants. */
549 /* AIX should be handled here, but */
550 /* that's called an RS6000. */
551 /* CRIS ==> Axis Etrax */
552 /* M32R ==> Renesas M32R */
556 * For each architecture and OS, the following need to be defined:
558 * CPP_WORDSZ is a simple integer constant representing the word size.
559 * in bits. We assume byte addressibility, where a byte has 8 bits.
560 * We also assume CPP_WORDSZ is either 32 or 64.
561 * (We care about the length of pointers, not hardware
562 * bus widths. Thus a 64 bit processor with a C compiler that uses
563 * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
565 * MACH_TYPE is a string representation of the machine type.
566 * OS_TYPE is analogous for the OS.
568 * ALIGNMENT is the largest N, such that
569 * all pointer are guaranteed to be aligned on N byte boundaries.
570 * defining it to be 1 will always work, but perform poorly.
572 * DATASTART is the beginning of the data segment.
573 * On some platforms SEARCH_FOR_DATA_START is defined.
574 * SEARCH_FOR_DATASTART will cause GC_data_start to
575 * be set to an address determined by accessing data backwards from _end
576 * until an unmapped page is found. DATASTART will be defined to be
578 * On UNIX-like systems, the collector will scan the area between DATASTART
579 * and DATAEND for root pointers.
581 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
582 * RTH suggests gaining access to linker script synth'd values with
583 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
584 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
585 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
586 * without any special options.
588 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
591 * STACKBOTTOM is the cool end of the stack, which is usually the
592 * highest address in the stack.
593 * Under PCR or OS/2, we have other ways of finding thread stacks.
594 * For each machine, the following should:
595 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
596 * 2) define exactly one of
597 * STACKBOTTOM (should be defined to be an expression)
601 * If STACKBOTTOM is defined, then it's value will be used directly as the
602 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
603 * with a method appropriate for most Linux systems. Currently we look
604 * first for __libc_stack_end, and if that fails read it from /proc.
605 * If either of the last two macros are defined, then STACKBOTTOM is computed
606 * during collector startup using one of the following two heuristics:
607 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
608 * the next multiple of STACK_GRAN.
609 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
610 * in small steps (decrement if STACK_GROWS_UP), and read the value
611 * at each location. Remember the value when the first
612 * Segmentation violation or Bus error is signalled. Round that
613 * to the nearest plausible page boundary, and use that instead
616 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
617 * the value of environ is a pointer that can serve as STACKBOTTOM.
618 * I expect that HEURISTIC2 can be replaced by this approach, which
619 * interferes far less with debugging. However it has the disadvantage
620 * that it's confused by a putenv call before the collector is initialized.
621 * This could be dealt with by intercepting putenv ...
623 * If no expression for STACKBOTTOM can be found, and neither of the above
624 * heuristics are usable, the collector can still be used with all of the above
625 * undefined, provided one of the following is done:
626 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
627 * without reference to STACKBOTTOM. This is appropriate for use in
628 * conjunction with thread packages, since there will be multiple stacks.
629 * (Allocating thread stacks in the heap, and treating them as ordinary
630 * heap data objects is also possible as a last resort. However, this is
631 * likely to introduce significant amounts of excess storage retention
632 * unless the dead parts of the thread stacks are periodically cleared.)
633 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
634 * If the author of the client code controls the main program, this is
635 * easily accomplished by introducing a new main program, setting
636 * GC_stackbottom to the address of a local variable, and then calling
637 * the original main program. The new main program would read something
640 * # include "gc_private.h"
642 * main(argc, argv, envp)
644 * char **argv, **envp;
648 * GC_stackbottom = (ptr_t)(&dummy);
649 * return(real_main(argc, argv, envp));
653 * Each architecture may also define the style of virtual dirty bit
654 * implementation to be used:
655 * MPROTECT_VDB: Write protect the heap and catch faults.
656 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
658 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
659 * defined GC_register_dynamic_libraries() for the architecture.
661 * An architecture may define PREFETCH(x) to preload the cache with *x.
662 * This defaults to a no-op.
664 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
666 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
667 * clear the two words at GC_malloc-aligned address x. By default,
668 * word stores of 0 are used instead.
670 * HEAP_START may be defined as the initial address hint for mmap-based
674 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
675 * to push the relevant registers onto the stack. This generally makes
676 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
678 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
679 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
680 && !defined(__INTEL_COMPILER) \
681 && !defined(__PATHCC__)
682 # define HAVE_BUILTIN_UNWIND_INIT
685 # define STACK_GRAN 0x1000000
687 # define MACH_TYPE "M68K"
690 # define OS_TYPE "OPENBSD"
693 # define DATASTART GC_data_start
694 # define DYNAMIC_LOADING
697 # define DATASTART ((ptr_t)(etext))
699 # define USE_GENERIC_PUSH_REGS
702 # define OS_TYPE "NETBSD"
705 # define DATASTART GC_data_start
706 # define DYNAMIC_LOADING
709 # define DATASTART ((ptr_t)(etext))
711 # define USE_GENERIC_PUSH_REGS
714 # define OS_TYPE "LINUX"
715 # define STACKBOTTOM ((ptr_t)0xf0000000)
716 # define USE_GENERIC_PUSH_REGS
717 /* We never got around to the assembly version. */
718 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
720 # define DYNAMIC_LOADING
721 # include <features.h>
722 # if defined(__GLIBC__)&& __GLIBC__>=2
723 # define SEARCH_FOR_DATA_START
725 # if defined(PLATFORM_ANDROID)
726 # define __environ environ
728 extern char **__environ;
729 # define DATASTART ((ptr_t)(&__environ))
730 /* hideous kludge: __environ is the first */
731 /* word in crt0.o, and delimits the start */
732 /* of the data segment, no matter which */
733 /* ld options were passed through. */
734 /* We could use _etext instead, but that */
735 /* would include .rodata, which may */
736 /* contain large read-only data tables */
737 /* that we'd rather not scan. */
738 # endif /* !GLIBC2 */
740 # define DATAEND (_end)
743 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
747 # define OS_TYPE "SUNOS4"
749 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
750 # define HEURISTIC1 /* differs */
751 # define DYNAMIC_LOADING
754 # define OS_TYPE "HP"
756 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
757 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
758 /* empirically determined. seems to work. */
760 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
763 # define OS_TYPE "SYSV"
765 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
767 +((word)etext & 0x1fff))
768 /* This only works for shared-text binaries with magic number 0413.
769 The other sorts of SysV binaries put the data at the end of the text,
770 in which case the default of etext would work. Unfortunately,
771 handling both would require having the magic-number available.
774 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
775 /* The stack starts at the top of memory, but */
776 /* 0x0 cannot be used as setjump_test complains */
777 /* that the stack direction is incorrect. Two */
778 /* bytes down from 0x0 should be safe enough. */
780 # include <sys/mmu.h>
781 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
784 # define OS_TYPE "AMIGA"
785 /* STACKBOTTOM and DATASTART handled specially */
787 # define DATAEND /* not needed */
788 # define GETPAGESIZE() 4096
794 # define OS_TYPE "MACOS"
795 /* see os_dep.c for details of global data segments. */
796 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
797 # define DATAEND /* not needed */
798 # define GETPAGESIZE() 4096
801 # define OS_TYPE "NEXT"
802 # define DATASTART ((ptr_t) get_etext())
803 # define STACKBOTTOM ((ptr_t) 0x4000000)
804 # define DATAEND /* not needed */
808 # if defined(POWERPC)
809 # define MACH_TYPE "POWERPC"
811 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
815 # define OS_TYPE "MACOS"
816 /* see os_dep.c for details of global data segments. */
817 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
818 # define DATAEND /* not needed */
822 # if defined(__powerpc64__)
824 # define CPP_WORDSZ 64
826 # define HBLKSIZE 4096
831 # define OS_TYPE "LINUX"
832 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
833 /* executable on a 64 bit kernel. */
834 # define LINUX_STACKBOTTOM
835 # define DYNAMIC_LOADING
836 # define SEARCH_FOR_DATA_START
838 # define DATAEND (_end)
843 # define CPP_WORDSZ 64
847 # define OS_TYPE "DARWIN"
848 # define DYNAMIC_LOADING
849 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
850 These aren't used when dyld support is enabled (it is by default) */
851 # define DATASTART ((ptr_t) get_etext())
852 # define DATAEND ((ptr_t) get_end())
853 # define STACKBOTTOM ((ptr_t) 0xc0000000)
855 # define USE_MMAP_ANON
856 # define USE_ASM_PUSH_REGS
857 /* This is potentially buggy. It needs more testing. See the comments in
858 os_dep.c. It relies on threads to track writes. */
859 # ifdef GC_DARWIN_THREADS
860 /* # define MPROTECT_VDB -- diabled for now. May work for some apps. */
863 # define GETPAGESIZE() getpagesize()
864 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
865 /* The performance impact of prefetches is untested */
866 # define PREFETCH(x) \
867 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
868 # define PREFETCH_FOR_WRITE(x) \
869 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
871 /* There seems to be some issues with trylock hanging on darwin. This
872 should be looked into some more */
873 # define NO_PTHREAD_TRYLOCK
877 # define OS_TYPE "FREEBSD"
878 # ifndef GC_FREEBSD_THREADS
879 # define MPROTECT_VDB
881 # define SIG_SUSPEND SIGUSR1
882 # define SIG_THR_RESTART SIGUSR2
883 # define FREEBSD_STACKBOTTOM
885 # define DYNAMIC_LOADING
888 extern char * GC_FreeBSDGetDataStart();
889 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
893 # define OS_TYPE "NETBSD"
896 # define DATASTART GC_data_start
897 # define DYNAMIC_LOADING
899 # ifdef SN_TARGET_PS3
901 # define CPP_WORDSZ 32
904 // extern int _dso_handle[];
905 extern int __bss_start;
907 # define DATAEND (_end)
908 # define DATASTART (__bss_start)
909 # define STACKBOTTOM ((ptr_t) ps3_get_stack_bottom ())
910 # define USE_GENERIC_PUSHREGS
915 # define OS_TYPE "NOSYS"
916 extern void __end[], __dso_handle[];
917 # define DATASTART (__dso_handle) /* OK, that's ugly. */
918 # define DATAEND (__end)
919 /* Stack starts at 0xE0000000 for the simulator. */
921 # define STACK_GRAN 0x10000000
927 # define MACH_TYPE "VAX"
928 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
930 # define DATASTART ((ptr_t)(etext))
932 # define OS_TYPE "BSD"
934 /* HEURISTIC2 may be OK, but it's hard to test. */
937 # define OS_TYPE "ULTRIX"
938 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
943 # define MACH_TYPE "RT"
945 # define DATASTART ((ptr_t) 0x10000000)
946 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
950 # define MACH_TYPE "SPARC"
951 # if defined(__arch64__) || defined(__sparcv9)
953 # define CPP_WORDSZ 64
954 # define ELF_CLASS ELFCLASS64
956 # define ALIGNMENT 4 /* Required by hardware */
957 # define CPP_WORDSZ 32
959 # define ALIGN_DOUBLE
960 # ifdef _FILE_OFFSET_BITS
961 # undef _FILE_OFFSET_BITS /* libelf.h & procfs.h doesn't compile with large file support */
962 # define _FILE_OFFSET_BITS 32
965 # define OS_TYPE "SUNOS5"
968 extern ptr_t GC_SysVGetDataStart();
969 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
970 # define DATAEND (_end)
971 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
973 /* Otherwise we now use calloc. Mmap may result in the */
974 /* heap interleaved with thread stacks, which can result in */
975 /* excessive blacklisting. Sbrk is unusable since it */
976 /* doesn't interact correctly with the system malloc. */
979 # define HEAP_START (ptr_t)0x40000000
981 # define HEAP_START DATAEND
984 /* HEURISTIC1 reportedly no longer works under 2.7. */
985 /* HEURISTIC2 probably works, but this appears to be preferable. */
986 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
987 /* installations that's undefined. We work around this with a */
989 # include <sys/vmparam.h>
991 /* This should work everywhere, but doesn't. */
992 # define STACKBOTTOM USRSTACK
997 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
998 /* getpagesize() appeared to be missing from at least one */
999 /* Solaris 5.4 installation. Weird. */
1000 # define DYNAMIC_LOADING
1003 # define OS_TYPE "SUNOS4"
1004 /* [If you have a weak stomach, don't read this.] */
1005 /* We would like to use: */
1006 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
1007 /* This fails occasionally, due to an ancient, but very */
1008 /* persistent ld bug. etext is set 32 bytes too high. */
1009 /* We instead read the text segment size from the a.out */
1010 /* header, which happens to be mapped into our address space */
1011 /* at the start of the text segment. The detective work here */
1012 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
1013 /* Serpette of INRIA. */
1014 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
1015 # define TEXTSTART 0x2000
1016 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
1017 # define MPROTECT_VDB
1019 # define DYNAMIC_LOADING
1022 # define OS_TYPE "DRSNX"
1023 extern ptr_t GC_SysVGetDataStart();
1025 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1026 # define MPROTECT_VDB
1027 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
1028 # define DYNAMIC_LOADING
1031 # define OS_TYPE "LINUX"
1033 # define DYNAMIC_LOADING
1035 Linux Sparc/a.out not supported
1038 # include <features.h>
1039 # if defined(__GLIBC__) && __GLIBC__ >= 2
1040 # define SEARCH_FOR_DATA_START
1042 extern char **__environ;
1043 # define DATASTART ((ptr_t)(&__environ))
1044 /* hideous kludge: __environ is the first */
1045 /* word in crt0.o, and delimits the start */
1046 /* of the data segment, no matter which */
1047 /* ld options were passed through. */
1048 /* We could use _etext instead, but that */
1049 /* would include .rodata, which may */
1050 /* contain large read-only data tables */
1051 /* that we'd rather not scan. */
1054 # define DATAEND (_end)
1055 # define LINUX_STACKBOTTOM
1058 # define OS_TYPE "OPENBSD"
1059 # define STACKBOTTOM ((ptr_t) 0xf8000000)
1061 # define DATASTART ((ptr_t)(etext))
1064 # define OS_TYPE "NETBSD"
1067 # define DATASTART GC_data_start
1068 # define DYNAMIC_LOADING
1070 extern char etext[];
1071 # define DATASTART ((ptr_t)(etext))
1075 # define OS_TYPE "FREEBSD"
1076 # define SIG_SUSPEND SIGUSR1
1077 # define SIG_THR_RESTART SIGUSR2
1078 # define FREEBSD_STACKBOTTOM
1080 # define DYNAMIC_LOADING
1082 extern char etext[];
1083 extern char edata[];
1085 # define NEED_FIND_LIMIT
1086 # define DATASTART ((ptr_t)(&etext))
1087 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1088 # define DATASTART2 ((ptr_t)(&edata))
1089 # define DATAEND2 ((ptr_t)(&end))
1094 # if defined( NACL )
1095 # define MACH_TYPE "NACL"
1096 # define CPP_WORDSZ 32
1097 # define ALIGNMENT 4
1099 # define MACH_TYPE "I386"
1100 # if defined(__LP64__) || defined(_WIN64)
1101 # define CPP_WORDSZ 64
1102 # define ALIGNMENT 8
1104 # define CPP_WORDSZ 32
1105 # define ALIGNMENT 4
1107 /* Appears to hold for all "32 bit" compilers */
1108 /* except Borland. The -a4 option fixes */
1110 /* Ivan Demakov: For Watcom the option is -zp4. */
1112 # ifndef SMALL_CONFIG
1113 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
1114 /* improvement on Pentiums. */
1116 # ifdef HAVE_BUILTIN_UNWIND_INIT
1117 # define USE_GENERIC_PUSH_REGS
1120 # define OS_TYPE "SEQUENT"
1122 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1123 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
1126 # define OS_TYPE "BEOS"
1128 # define GETPAGESIZE() B_PAGE_SIZE
1130 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1133 # define OS_TYPE "SUNOS5"
1134 extern int _etext[], _end[];
1135 extern ptr_t GC_SysVGetDataStart();
1136 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
1137 # define DATAEND (_end)
1138 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1139 /* but reportedly breaks under 2.8. It appears that the stack */
1140 /* base is a property of the executable, so this should not break */
1141 /* old executables. */
1142 /* HEURISTIC2 probably works, but this appears to be preferable. */
1143 # include <sys/vm.h>
1144 # define STACKBOTTOM USRSTACK
1145 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1146 /* It appears to be fixed in 2.8 and 2.9. */
1147 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1148 /* Reading of dirty bits doesn't seem to work even in solaris 10 */
1149 /*# define PROC_VDB */
1151 # define DYNAMIC_LOADING
1152 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1154 /* Otherwise we now use calloc. Mmap may result in the */
1155 /* heap interleaved with thread stacks, which can result in */
1156 /* excessive blacklisting. Sbrk is unusable since it */
1157 /* doesn't interact correctly with the system malloc. */
1160 # define HEAP_START (ptr_t)0x40000000
1162 # define HEAP_START DATAEND
1166 # define OS_TYPE "SCO"
1168 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1170 +((word)etext & 0xfff))
1171 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1174 # define OS_TYPE "SCO_ELF"
1176 # define DATASTART ((ptr_t)(etext))
1177 # define STACKBOTTOM ((ptr_t) 0x08048000)
1178 # define DYNAMIC_LOADING
1179 # define ELF_CLASS ELFCLASS32
1182 # define OS_TYPE "DGUX"
1183 extern int _etext, _end;
1184 extern ptr_t GC_SysVGetDataStart();
1185 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1186 # define DATAEND (&_end)
1187 # define STACK_GROWS_DOWN
1189 # include <unistd.h>
1190 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1191 # define DYNAMIC_LOADING
1194 # endif /* USE_MMAP */
1195 # define MAP_FAILED (void *) -1
1197 # define HEAP_START (ptr_t)0x40000000
1198 # else /* USE_MMAP */
1199 # define HEAP_START DATAEND
1200 # endif /* USE_MMAP */
1203 # define OS_TYPE "NACL"
1205 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1207 # define DATAEND (_end)
1210 # endif /* STACK_GRAN */
1211 # define STACK_GRAN 0x10000
1219 # ifdef USE_MMAP_ANON
1220 # undef USE_MMAP_ANON
1222 # ifdef USE_MMAP_FIXED
1223 # undef USE_MMAP_FIXED
1225 # define GETPAGESIZE() 65536
1226 # define MAX_NACL_GC_THREADS 1024
1230 /* The Intel compiler doesn't like inline assembly */
1231 # define USE_GENERIC_PUSH_REGS
1233 # define OS_TYPE "LINUX"
1234 # define LINUX_STACKBOTTOM
1238 # define STACK_GRAN 0x10000000
1239 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1240 /* different kernel configurations. In particular, systems */
1241 /* with 2GB physical memory will usually move the user */
1242 /* address space limit, and hence initial SP to 0x80000000. */
1244 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1245 # define MPROTECT_VDB
1247 /* We seem to get random errors in incremental mode, */
1248 /* possibly because Linux threads is itself a malloc client */
1249 /* and can't deal with the signals. */
1251 # define HEAP_START (ptr_t)0x1000
1252 /* This encourages mmap to give us low addresses, */
1253 /* thus allowing the heap to grow to ~3GB */
1255 # define DYNAMIC_LOADING
1256 # ifdef UNDEFINED /* includes ro data */
1257 extern int _etext[];
1258 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1260 # include <features.h>
1261 # if defined(__GLIBC__) && __GLIBC__ >= 2
1262 # define SEARCH_FOR_DATA_START
1264 extern char **__environ;
1265 # define DATASTART ((ptr_t)(&__environ))
1266 /* hideous kludge: __environ is the first */
1267 /* word in crt0.o, and delimits the start */
1268 /* of the data segment, no matter which */
1269 /* ld options were passed through. */
1270 /* We could use _etext instead, but that */
1271 /* would include .rodata, which may */
1272 /* contain large read-only data tables */
1273 /* that we'd rather not scan. */
1276 # define DATAEND (_end)
1279 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1281 # ifdef USE_I686_PREFETCH
1282 /* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1283 /* for the next rtelease. */
1284 # define PREFETCH(x) \
1285 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1286 /* Empirically prefetcht0 is much more effective at reducing */
1287 /* cache miss stalls for the targetted load instructions. But it */
1288 /* seems to interfere enough with other cache traffic that the net */
1289 /* result is worse than prefetchnta. */
1291 /* Using prefetches for write seems to have a slight negative */
1292 /* impact on performance, at least for a PIII/500. */
1293 # define PREFETCH_FOR_WRITE(x) \
1294 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1297 # ifdef USE_3DNOW_PREFETCH
1298 # define PREFETCH(x) \
1299 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1300 # define PREFETCH_FOR_WRITE(x) \
1301 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1305 # define OS_TYPE "CYGWIN32"
1306 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1307 # define DATAEND ((ptr_t)GC_DATAEND)
1309 # define STACK_GRAN 0x10000
1313 # define OS_TYPE "OS2"
1314 /* STACKBOTTOM and DATASTART are handled specially in */
1315 /* os_dep.c. OS2 actually has the right */
1317 # define DATAEND /* not needed */
1318 # define USE_GENERIC_PUSH_REGS
1321 # define OS_TYPE "MSWIN32"
1322 /* STACKBOTTOM and DATASTART are handled specially in */
1324 # ifndef __WATCOMC__
1325 # define MPROTECT_VDB
1327 # define DATAEND /* not needed */
1330 # define OS_TYPE "MSWINCE"
1331 # define DATAEND /* not needed */
1334 # define OS_TYPE "DJGPP"
1335 # include "stubinfo.h"
1338 extern int __djgpp_stack_limit;
1339 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1340 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1342 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1343 /* This may not be right. */
1346 # define OS_TYPE "OPENBSD"
1347 # ifdef GC_OPENBSD_THREADS
1348 # define UTHREAD_SP_OFFSET 192
1350 # include <sys/param.h>
1351 # include <uvm/uvm_extern.h>
1352 # define STACKBOTTOM USRSTACK
1354 extern int __data_start[];
1355 # define DATASTART ((ptr_t)(__data_start))
1357 # define DATAEND ((ptr_t)(&_end))
1358 # define DYNAMIC_LOADING
1361 # define OS_TYPE "FREEBSD"
1362 # ifndef GC_FREEBSD_THREADS
1363 # define MPROTECT_VDB
1365 # define SIG_SUSPEND SIGTSTP
1366 # define SIG_THR_RESTART SIGCONT
1367 # define FREEBSD_STACKBOTTOM
1369 # define DYNAMIC_LOADING
1371 extern char etext[];
1372 extern char * GC_FreeBSDGetDataStart();
1373 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1376 # define OS_TYPE "NETBSD"
1378 # define DYNAMIC_LOADING
1382 # define OS_TYPE "THREE86BSD"
1385 # define OS_TYPE "BSDI"
1387 # if defined(OPENBSD) || defined(NETBSD) \
1388 || defined(THREE86BSD) || defined(BSDI)
1390 extern char etext[];
1391 # define DATASTART ((ptr_t)(etext))
1394 # define OS_TYPE "NEXT"
1395 # define DATASTART ((ptr_t) get_etext())
1396 # define STACKBOTTOM ((ptr_t)0xc0000000)
1397 # define DATAEND /* not needed */
1400 # define OS_TYPE "DOS4GW"
1401 extern long __nullarea;
1403 extern char *_STACKTOP;
1404 /* Depending on calling conventions Watcom C either precedes
1405 or does not precedes with undescore names of C-variables.
1406 Make sure startup code variables always have the same names. */
1407 #pragma aux __nullarea "*";
1408 #pragma aux _end "*";
1409 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1410 /* confused? me too. */
1411 # define DATASTART ((ptr_t) &__nullarea)
1412 # define DATAEND ((ptr_t) &_end)
1415 # define OS_TYPE "HURD"
1416 # define STACK_GROWS_DOWN
1418 extern int __data_start[];
1419 # define DATASTART ( (ptr_t) (__data_start))
1421 # define DATAEND ( (ptr_t) (_end))
1422 /* # define MPROTECT_VDB Not quite working yet? */
1423 # define DYNAMIC_LOADING
1428 # define MACH_TYPE "NS32K"
1429 # define ALIGNMENT 4
1430 extern char **environ;
1431 # define DATASTART ((ptr_t)(&environ))
1432 /* hideous kludge: environ is the first */
1433 /* word in crt0.o, and delimits the start */
1434 /* of the data segment, no matter which */
1435 /* ld options were passed through. */
1436 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1440 # define MACH_TYPE "MIPS"
1442 /* This was developed for a linuxce style platform. Probably */
1443 /* needs to be tweaked for workstation class machines. */
1444 # define OS_TYPE "LINUX"
1445 # define DYNAMIC_LOADING
1447 # define DATAEND (_end)
1448 extern int __data_start[];
1449 # define DATASTART ((ptr_t)(__data_start))
1450 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1451 # define ALIGNMENT 8
1452 # define CPP_WORDSZ 64
1454 # define ALIGNMENT 4
1456 # define USE_GENERIC_PUSH_REGS
1457 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1458 # define LINUX_STACKBOTTOM
1460 # define STACKBOTTOM 0x80000000
1465 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1466 extern int _fdata[], _end[];
1467 # define DATASTART ((ptr_t)_fdata)
1468 # define DATAEND ((ptr_t)_end)
1469 # define CPP_WORDSZ _MIPS_SZPTR
1470 # define ALIGNMENT (_MIPS_SZPTR/8)
1472 extern int etext[], edata[], end[];
1473 extern int _DYNAMIC_LINKING[], _gp[];
1474 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1475 + ((word)etext & 0xffff)))
1476 # define DATAEND (edata)
1477 # define DATASTART2 (_DYNAMIC_LINKING \
1478 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1480 # define DATAEND2 (end)
1481 # define ALIGNMENT 4
1483 # define OS_TYPE "EWS4800"
1484 # define USE_GENERIC_PUSH_REGS 1
1488 # define DATASTART (ptr_t)0x10000000
1489 /* Could probably be slightly higher since */
1490 /* startup code allocates lots of stuff. */
1491 # define OS_TYPE "ULTRIX"
1492 # define ALIGNMENT 4
1496 # define DATASTART (ptr_t)0x10000000
1497 # define OS_TYPE "RISCOS"
1498 # define ALIGNMENT 4 /* Required by hardware */
1502 extern int _fdata[];
1503 # define DATASTART ((ptr_t)(_fdata))
1505 # define HEAP_START (ptr_t)0x30000000
1507 # define HEAP_START DATASTART
1509 /* Lowest plausible heap address. */
1510 /* In the MMAP case, we map there. */
1511 /* In either case it is used to identify */
1512 /* heap sections so they're not */
1513 /* considered as roots. */
1514 # define OS_TYPE "IRIX5"
1515 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1516 /* of recent breakage. */
1518 # define CPP_WORDSZ _MIPS_SZPTR
1519 # define ALIGNMENT (_MIPS_SZPTR/8)
1520 # if CPP_WORDSZ != 64
1521 # define ALIGN_DOUBLE
1524 # define ALIGNMENT 4
1525 # define ALIGN_DOUBLE
1527 # define DYNAMIC_LOADING
1530 # define OS_TYPE "MSWINCE"
1531 # define ALIGNMENT 4
1532 # define DATAEND /* not needed */
1534 # if defined(NETBSD)
1535 # define ALIGNMENT 4
1536 # define OS_TYPE "NETBSD"
1538 # define USE_GENERIC_PUSH_REGS
1541 # define DATASTART GC_data_start
1542 # define NEED_FIND_LIMIT
1543 # define DYNAMIC_LOADING
1545 # define DATASTART ((ptr_t) 0x10000000)
1546 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1552 # define MACH_TYPE "RS6000"
1557 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1560 # define ALIGNMENT 8
1561 # define CPP_WORDSZ 64
1562 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1564 # define ALIGNMENT 4
1565 # define CPP_WORDSZ 32
1566 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1569 # define USE_MMAP_ANON
1570 /* From AIX linker man page:
1571 _text Specifies the first location of the program.
1572 _etext Specifies the first location after the program.
1573 _data Specifies the first location of the data.
1574 _edata Specifies the first location after the initialized data
1575 _end or end Specifies the first location after all data.
1577 extern int _data[], _end[];
1578 # define DATASTART ((ptr_t)((ulong)_data))
1579 # define DATAEND ((ptr_t)((ulong)_end))
1581 # define USE_GENERIC_PUSH_REGS
1582 # define DYNAMIC_LOADING
1583 /* For really old versions of AIX, this may have to be removed. */
1587 # define MACH_TYPE "HP_PA"
1589 # define CPP_WORDSZ 64
1590 # define ALIGNMENT 8
1592 # define CPP_WORDSZ 32
1593 # define ALIGNMENT 4
1594 # define ALIGN_DOUBLE
1596 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1597 # ifndef LINUX /* For now. */
1598 # define MPROTECT_VDB
1601 # define GENERIC_COMPARE_AND_SWAP
1602 /* No compare-and-swap instruction. Use pthread mutexes */
1603 /* when we absolutely have to. */
1604 # ifdef PARALLEL_MARK
1605 # define USE_MARK_BYTES
1606 /* Minimize compare-and-swap usage. */
1609 # define STACK_GROWS_UP
1611 # define OS_TYPE "HPUX"
1612 extern int __data_start[];
1613 # define DATASTART ((ptr_t)(__data_start))
1615 /* The following appears to work for 7xx systems running HP/UX */
1616 /* 9.xx Furthermore, it might result in much faster */
1617 /* collections than HEURISTIC2, which may involve scanning */
1618 /* segments that directly precede the stack. It is not the */
1619 /* default, since it may not work on older machine/OS */
1620 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1622 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1624 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1625 /* to this. Note that the GC must be initialized before the */
1626 /* first putenv call. */
1627 extern char ** environ;
1628 # define STACKBOTTOM ((ptr_t)environ)
1630 # define DYNAMIC_LOADING
1631 # include <unistd.h>
1632 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1634 # define PREFETCH(x) { \
1635 register long addr = (long)(x); \
1636 (void) _asm ("LDW", 0, 0, addr, 0); \
1641 # define OS_TYPE "LINUX"
1642 # define LINUX_STACKBOTTOM
1643 # define DYNAMIC_LOADING
1644 # define SEARCH_FOR_DATA_START
1646 # define DATAEND (&_end)
1651 # define MACH_TYPE "ALPHA"
1652 # define ALIGNMENT 8
1653 # define CPP_WORDSZ 64
1655 # define USE_GENERIC_PUSH_REGS
1656 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1657 /* fp registers in some cases when the target is a 21264. The assembly */
1658 /* code doesn't handle that yet, and version dependencies make that a */
1659 /* bit tricky. Do the easy thing for now. */
1662 # define OS_TYPE "NETBSD"
1664 # define DATASTART GC_data_start
1665 # define ELFCLASS32 32
1666 # define ELFCLASS64 64
1667 # define ELF_CLASS ELFCLASS64
1668 # define DYNAMIC_LOADING
1671 # define OS_TYPE "OPENBSD"
1673 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1674 # define DATASTART GC_data_start
1675 # define ELFCLASS32 32
1676 # define ELFCLASS64 64
1677 # define ELF_CLASS ELFCLASS64
1678 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1679 # define DATASTART ((ptr_t) 0x140000000)
1683 # define OS_TYPE "FREEBSD"
1684 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1685 # define SIG_SUSPEND SIGTSTP
1686 # define SIG_THR_RESTART SIGCONT
1687 # define FREEBSD_STACKBOTTOM
1689 # define DYNAMIC_LOADING
1691 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1692 extern char etext[];
1693 extern char edata[];
1695 # define NEED_FIND_LIMIT
1696 # define DATASTART ((ptr_t)(&etext))
1697 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1698 # define DATASTART2 ((ptr_t)(&edata))
1699 # define DATAEND2 ((ptr_t)(&end))
1702 # define OS_TYPE "OSF1"
1703 # define DATASTART ((ptr_t) 0x140000000)
1705 # define DATAEND ((ptr_t) &_end)
1706 extern char ** environ;
1707 /* round up from the value of environ to the nearest page boundary */
1708 /* Probably breaks if putenv is called before collector */
1709 /* initialization. */
1710 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1711 /* # define HEURISTIC2 */
1712 /* Normally HEURISTIC2 is too conervative, since */
1713 /* the text segment immediately follows the stack. */
1714 /* Hence we give an upper pound. */
1715 /* This is currently unused, since we disabled HEURISTIC2 */
1716 extern int __start[];
1717 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1718 # ifndef GC_OSF1_THREADS
1719 /* Unresolved signal issues with threads. */
1720 # define MPROTECT_VDB
1722 # define DYNAMIC_LOADING
1725 # define OS_TYPE "LINUX"
1726 # define LINUX_STACKBOTTOM
1728 # define SEARCH_FOR_DATA_START
1729 # define DYNAMIC_LOADING
1731 # define DATASTART ((ptr_t) 0x140000000)
1734 # define DATAEND (_end)
1735 # define MPROTECT_VDB
1736 /* Has only been superficially tested. May not */
1737 /* work on all versions. */
1742 # define MACH_TYPE "IA64"
1743 # define USE_GENERIC_PUSH_REGS
1744 /* We need to get preserved registers in addition to register */
1745 /* windows. That's easiest to do with setjmp. */
1746 # ifdef PARALLEL_MARK
1747 # define USE_MARK_BYTES
1748 /* Compare-and-exchange is too expensive to use for */
1749 /* setting mark bits. */
1753 # define CPP_WORDSZ 32
1754 # define ALIGN_DOUBLE
1755 /* Requires 8 byte alignment for malloc */
1756 # define ALIGNMENT 4
1761 # define CPP_WORDSZ 64
1762 # define ALIGN_DOUBLE
1763 /* Requires 16 byte alignment for malloc */
1764 # define ALIGNMENT 8
1766 # define OS_TYPE "HPUX"
1767 extern int __data_start[];
1768 # define DATASTART ((ptr_t)(__data_start))
1769 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1770 /* to this. Note that the GC must be initialized before the */
1771 /* first putenv call. */
1772 extern char ** environ;
1773 # define STACKBOTTOM ((ptr_t)environ)
1774 # define HPUX_STACKBOTTOM
1775 # define DYNAMIC_LOADING
1776 # include <unistd.h>
1777 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1778 /* The following was empirically determined, and is probably */
1779 /* not very robust. */
1780 /* Note that the backing store base seems to be at a nice */
1781 /* address minus one page. */
1782 # define BACKING_STORE_DISPLACEMENT 0x1000000
1783 # define BACKING_STORE_ALIGNMENT 0x1000
1784 extern ptr_t GC_register_stackbottom;
1785 # define BACKING_STORE_BASE GC_register_stackbottom
1786 /* Known to be wrong for recent HP/UX versions!!! */
1789 # define CPP_WORDSZ 64
1790 # define ALIGN_DOUBLE
1791 /* Requires 16 byte alignment for malloc */
1792 # define ALIGNMENT 8
1793 # define OS_TYPE "LINUX"
1794 /* The following works on NUE and older kernels: */
1795 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1796 /* This does not work on NUE: */
1797 # define LINUX_STACKBOTTOM
1798 /* We also need the base address of the register stack */
1799 /* backing store. This is computed in */
1800 /* GC_linux_register_stack_base based on the following */
1802 # define BACKING_STORE_ALIGNMENT 0x100000
1803 # define BACKING_STORE_DISPLACEMENT 0x80000000
1804 extern ptr_t GC_register_stackbottom;
1805 # define BACKING_STORE_BASE GC_register_stackbottom
1806 # define SEARCH_FOR_DATA_START
1808 # define DYNAMIC_LOADING
1810 /* In the Intel compiler environment, we seem to end up with */
1811 /* statically linked executables and an undefined reference */
1814 # define MPROTECT_VDB
1815 /* Requires Linux 2.3.47 or later. */
1817 # define DATAEND (_end)
1819 # ifndef __INTEL_COMPILER
1820 # define PREFETCH(x) \
1821 __asm__ (" lfetch [%0]": : "r"(x))
1822 # define PREFETCH_FOR_WRITE(x) \
1823 __asm__ (" lfetch.excl [%0]": : "r"(x))
1824 # define CLEAR_DOUBLE(x) \
1825 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1827 # include <ia64intrin.h>
1828 # define PREFETCH(x) \
1829 __lfetch(__lfhint_none, (x))
1830 # define PREFETCH_FOR_WRITE(x) \
1831 __lfetch(__lfhint_nta, (x))
1832 # define CLEAR_DOUBLE(x) \
1833 __stf_spill((void *)(x), 0)
1834 # endif // __INTEL_COMPILER
1838 /* FIXME: This is a very partial guess. There is no port, yet. */
1839 # define OS_TYPE "MSWIN32"
1840 /* STACKBOTTOM and DATASTART are handled specially in */
1842 # define DATAEND /* not needed */
1843 # if defined(_WIN64)
1844 # define CPP_WORDSZ 64
1846 # define CPP_WORDSZ 32 /* Is this possible? */
1848 # define ALIGNMENT 8
1853 # define MACH_TYPE "M88K"
1854 # define ALIGNMENT 4
1855 # define ALIGN_DOUBLE
1858 # define OS_TYPE "CX_UX"
1859 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1862 # define OS_TYPE "DGUX"
1863 extern ptr_t GC_SysVGetDataStart();
1864 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1866 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1870 /* If this still works, and if anyone cares, this should probably */
1871 /* be moved to the S390 category. */
1872 # define MACH_TYPE "S370"
1873 # define ALIGNMENT 4 /* Required by hardware */
1874 # define USE_GENERIC_PUSH_REGS
1876 # define OS_TYPE "UTS4"
1878 extern int _etext[];
1880 extern ptr_t GC_SysVGetDataStart();
1881 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1882 # define DATAEND (_end)
1888 # define MACH_TYPE "S390"
1889 # define USE_GENERIC_PUSH_REGS
1891 # define ALIGNMENT 4
1892 # define CPP_WORDSZ 32
1894 # define ALIGNMENT 8
1895 # define CPP_WORDSZ 64
1898 # define HBLKSIZE 4096
1901 # define OS_TYPE "LINUX"
1902 # define LINUX_STACKBOTTOM
1903 # define DYNAMIC_LOADING
1904 extern int __data_start[];
1905 # define DATASTART ((ptr_t)(__data_start))
1907 # define DATAEND (_end)
1908 # define CACHE_LINE_SIZE 256
1909 # define GETPAGESIZE() 4096
1914 # define ALIGNMENT 4
1915 extern int _etext[];
1916 # define DATASTART ((ptr_t)(_etext))
1921 # define CPP_WORDSZ 32
1922 # define MACH_TYPE "ARM32"
1923 # define ALIGNMENT 4
1925 # define OS_TYPE "NETBSD"
1928 # define DATASTART GC_data_start
1929 # define DYNAMIC_LOADING
1931 extern char etext[];
1932 # define DATASTART ((ptr_t)(etext))
1934 # define USE_GENERIC_PUSH_REGS
1937 # define OS_TYPE "LINUX"
1938 # define LINUX_STACKBOTTOM
1940 # define STACK_GRAN 0x10000000
1941 # define USE_GENERIC_PUSH_REGS
1943 # define DYNAMIC_LOADING
1944 # include <features.h>
1945 # if defined(__GLIBC__) && __GLIBC__ >= 2
1946 # define SEARCH_FOR_DATA_START
1947 # elif defined(PLATFORM_ANDROID)
1948 # define SEARCH_FOR_DATA_START
1950 extern char **__environ;
1951 # define DATASTART ((ptr_t)(&__environ))
1952 /* hideous kludge: __environ is the first */
1953 /* word in crt0.o, and delimits the start */
1954 /* of the data segment, no matter which */
1955 /* ld options were passed through. */
1956 /* We could use _etext instead, but that */
1957 /* would include .rodata, which may */
1958 /* contain large read-only data tables */
1959 /* that we'd rather not scan. */
1962 # define DATAEND (_end)
1965 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1969 # define OS_TYPE "MSWINCE"
1970 # define DATAEND /* not needed */
1973 # define OS_TYPE "DARWIN"
1974 # define DATASTART ((ptr_t) get_etext())
1975 # define DATAEND ((ptr_t) get_end())
1976 # define STACKBOTTOM ((ptr_t) 0x30000000)
1978 # define USE_MMAP_ANON
1982 /* __data_start is usually defined in the target linker script. */
1983 extern int __data_start[];
1984 # define DATASTART (ptr_t)(__data_start)
1985 # define USE_GENERIC_PUSH_REGS
1986 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1987 extern void *__stack_base__;
1988 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1993 # define MACH_TYPE "CRIS"
1994 # define CPP_WORDSZ 32
1995 # define ALIGNMENT 1
1996 # define OS_TYPE "LINUX"
1997 # define DYNAMIC_LOADING
1998 # define LINUX_STACKBOTTOM
1999 # define USE_GENERIC_PUSH_REGS
2000 # define SEARCH_FOR_DATA_START
2002 # define DATAEND (_end)
2006 # define MACH_TYPE "SH"
2007 # define ALIGNMENT 4
2009 # define OS_TYPE "MSWINCE"
2010 # define DATAEND /* not needed */
2013 # define OS_TYPE "LINUX"
2014 # define LINUX_STACKBOTTOM
2015 # define USE_GENERIC_PUSH_REGS
2016 # define DYNAMIC_LOADING
2017 # define SEARCH_FOR_DATA_START
2019 # define DATAEND (_end)
2022 # define OS_TYPE "NETBSD"
2024 # define DATASTART GC_data_start
2025 # define USE_GENERIC_PUSH_REGS
2026 # define DYNAMIC_LOADING
2031 # define MACH_TYPE "SH4"
2032 # define OS_TYPE "MSWINCE"
2033 # define ALIGNMENT 4
2034 # define DATAEND /* not needed */
2038 # define CPP_WORDSZ 32
2039 # define MACH_TYPE "M32R"
2040 # define ALIGNMENT 4
2042 # define OS_TYPE "LINUX"
2043 # define LINUX_STACKBOTTOM
2045 # define STACK_GRAN 0x10000000
2046 # define USE_GENERIC_PUSH_REGS
2047 # define DYNAMIC_LOADING
2048 # define SEARCH_FOR_DATA_START
2050 # define DATAEND (_end)
2055 # define MACH_TYPE "X86_64"
2056 # define ALIGNMENT 8
2057 # define CPP_WORDSZ 64
2059 # define HBLKSIZE 4096
2061 # define CACHE_LINE_SIZE 64
2062 # define USE_GENERIC_PUSH_REGS
2064 # define OS_TYPE "LINUX"
2065 # define LINUX_STACKBOTTOM
2067 # define FALLBACK_TO_MMAP
2069 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2070 # define MPROTECT_VDB
2072 /* We seem to get random errors in incremental mode, */
2073 /* possibly because Linux threads is itself a malloc client */
2074 /* and can't deal with the signals. */
2077 # define DYNAMIC_LOADING
2078 # ifdef UNDEFINED /* includes ro data */
2079 extern int _etext[];
2080 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
2082 # include <features.h>
2083 # define SEARCH_FOR_DATA_START
2085 # define DATAEND (_end)
2088 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
2090 # if defined(__GNUC__) && __GNUC >= 3
2091 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
2092 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
2096 # define OS_TYPE "DARWIN"
2097 # define DARWIN_DONT_PARSE_STACK
2098 # define DYNAMIC_LOADING
2099 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
2100 These aren't used when dyld support is enabled (it is by default) */
2101 # define DATASTART ((ptr_t) get_etext())
2102 # define DATAEND ((ptr_t) get_end())
2103 # define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
2107 # define USE_MMAP_ANON
2108 # ifdef GC_DARWIN_THREADS
2109 # define MPROTECT_VDB
2111 # include <unistd.h>
2112 # define GETPAGESIZE() getpagesize()
2113 /* There seems to be some issues with trylock hanging on darwin. This
2114 should be looked into some more */
2117 # define OS_TYPE "FREEBSD"
2118 # ifndef GC_FREEBSD_THREADS
2119 # define MPROTECT_VDB
2121 # define SIG_SUSPEND SIGTSTP
2122 # define SIG_THR_RESTART SIGCONT
2123 # define NEED_FIND_LIMIT
2124 # define FREEBSD_STACKBOTTOM
2126 # define DYNAMIC_LOADING
2128 extern char etext[];
2129 extern char * GC_FreeBSDGetDataStart();
2130 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
2133 # define OS_TYPE "NETBSD"
2135 # define DYNAMIC_LOADING
2138 extern char etext[];
2139 # define SEARCH_FOR_DATA_START
2142 # define OS_TYPE "OPENBSD"
2143 # define ELF_CLASS ELFCLASS64
2144 # ifdef GC_OPENBSD_THREADS
2145 # define UTHREAD_SP_OFFSET 400
2147 # include <sys/param.h>
2148 # include <uvm/uvm_extern.h>
2149 # define STACKBOTTOM USRSTACK
2151 extern int __data_start[];
2152 # define DATASTART ((ptr_t)(__data_start))
2154 # define DATAEND ((ptr_t)(&_end))
2155 # define DYNAMIC_LOADING
2159 #if defined(LINUX) && defined(USE_MMAP)
2160 /* The kernel may do a somewhat better job merging mappings etc. */
2161 /* with anonymous mappings. */
2162 # define USE_MMAP_ANON
2165 #if defined(LINUX) && defined(REDIRECT_MALLOC)
2166 /* Rld appears to allocate some memory with its own allocator, and */
2167 /* some through malloc, which might be redirected. To make this */
2168 /* work with collectable memory, we have to scan memory allocated */
2169 /* by rld's internal malloc. */
2170 # define USE_PROC_FOR_LIBRARIES
2173 # ifndef STACK_GROWS_UP
2174 # define STACK_GROWS_DOWN
2178 # define CPP_WORDSZ 32
2187 # define DATAEND (end)
2190 # if defined(SVR4) && !defined(GETPAGESIZE)
2191 # include <unistd.h>
2192 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
2195 # ifndef GETPAGESIZE
2196 # if defined(SUNOS5) || defined(IRIX5)
2197 # include <unistd.h>
2199 # define GETPAGESIZE() getpagesize()
2202 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
2203 /* OS has SVR4 generic features. Probably others also qualify. */
2207 # if defined(SUNOS5) || defined(DRSNX)
2208 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
2211 /* OS has SUNOS5 style signal handlers. */
2219 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
2223 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2224 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2225 || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
2226 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
2227 # define UNIX_LIKE /* Basic Unix-like system calls work. */
2230 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2235 # undef DYNAMIC_LOADING
2240 # undef MPROTECT_VDB
2245 /* Postponed for now. */
2247 # undef MPROTECT_VDB
2250 # ifdef SMALL_CONFIG
2251 /* Presumably not worth the space it takes. */
2253 # undef MPROTECT_VDB
2257 # undef MPROTECT_VDB /* Can't deal with address space holes. */
2260 # ifdef PARALLEL_MARK
2261 # undef MPROTECT_VDB /* For now. */
2264 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2265 # define DEFAULT_VDB
2269 # define PREFETCH(x)
2270 # define NO_PREFETCH
2273 # ifndef PREFETCH_FOR_WRITE
2274 # define PREFETCH_FOR_WRITE(x)
2275 # define NO_PREFETCH_FOR_WRITE
2278 # ifndef CACHE_LINE_SIZE
2279 # define CACHE_LINE_SIZE 32 /* Wild guess */
2283 # define REGISTER_LIBRARIES_EARLY
2284 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
2285 /* lock. This isn't safe after the world has stopped. So we must */
2286 /* call GC_register_dynamic_libraries before stopping the world. */
2287 /* For performance reasons, this may be beneficial on other */
2288 /* platforms as well, though it should be avoided in win32. */
2291 # if defined(SEARCH_FOR_DATA_START)
2292 extern ptr_t GC_data_start;
2293 # define DATASTART GC_data_start
2296 # ifndef CLEAR_DOUBLE
2297 # define CLEAR_DOUBLE(x) \
2298 ((word*)x)[0] = 0; \
2300 # endif /* CLEAR_DOUBLE */
2302 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2303 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2304 # define GC_SOLARIS_THREADS
2307 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2308 --> inconsistent configuration
2310 # if defined(GC_LINUX_THREADS) && !(defined(LINUX) || defined(NACL))
2311 --> inconsistent configuration
2313 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2314 --> inconsistent configuration
2316 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2317 --> inconsistent configuration
2319 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2320 --> inconsistent configuration
2322 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2323 --> inconsistent configuration
2326 # if defined(PCR) || defined(SRC_M3) || \
2327 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2328 defined(GC_PTHREADS) || defined(SN_TARGET_PS3)
2332 # if defined(HP_PA) || defined(M88K) \
2333 || defined(POWERPC) && !defined(DARWIN) \
2334 || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2335 || (defined(I386) && defined(__LCC__))
2336 /* Use setjmp based hack to mark from callee-save registers. */
2337 /* The define should move to the individual platform */
2339 # define USE_GENERIC_PUSH_REGS
2342 # if defined(MSWINCE)
2347 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2348 /* include assembly code to do it well. */
2351 /* Can we save call chain in objects for debugging? */
2352 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2353 /* frame) to reasonable values for the platform. */
2354 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2355 /* at build time, though we feel free to adjust it slightly. */
2356 /* Define NEED_CALLINFO if we either save the call stack or */
2357 /* GC_ADD_CALLER is defined. */
2358 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2361 # define CAN_SAVE_CALL_ARGS
2363 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2364 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2365 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2366 # define CAN_SAVE_CALL_ARGS
2369 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2370 && defined(GC_CAN_SAVE_CALL_STACKS)
2371 # define SAVE_CALL_CHAIN
2373 # ifdef SAVE_CALL_CHAIN
2374 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2375 # define NARGS SAVE_CALL_NARGS
2377 # define NARGS 0 /* Number of arguments to save for each call. */
2380 # ifdef SAVE_CALL_CHAIN
2381 # ifndef SAVE_CALL_COUNT
2382 # define NFRAMES 6 /* Number of frames to save. Even for */
2383 /* alignment reasons. */
2385 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2387 # define NEED_CALLINFO
2388 # endif /* SAVE_CALL_CHAIN */
2389 # ifdef GC_ADD_CALLER
2392 # define NEED_CALLINFO
2395 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2396 # define DBG_HDRS_ALL
2399 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2400 # define POINTER_SHIFT 0
2403 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2404 # define POINTER_MASK ((GC_word)(-1))
2407 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2408 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2411 # if defined(FIXUP_POINTER)
2412 # define NEED_FIXUP_POINTER 1
2414 # define NEED_FIXUP_POINTER 0
2415 # define FIXUP_POINTER(p)
2419 /* This relies on some type definitions from gc_priv.h, from */
2420 /* where it's normally included. */
2422 /* How to get heap memory from the OS: */
2423 /* Note that sbrk()-like allocation is preferred, since it */
2424 /* usually makes it possible to merge consecutively allocated */
2425 /* chunks. It also avoids unintented recursion with */
2426 /* -DREDIRECT_MALLOC. */
2427 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2428 /* 0 is taken to mean failure. */
2429 /* In the case os USE_MMAP, the argument must also be a */
2430 /* physical page size. */
2431 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2432 /* though we should perhaps take advantage of the case in which */
2434 struct hblk; /* See gc_priv.h. */
2436 char * real_malloc();
2437 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2441 void * os2_alloc(size_t bytes);
2442 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2446 # if defined(NEXT) || defined(DOS4GW) || \
2447 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2448 (defined(SUNOS5) && !defined(USE_MMAP))
2449 # define GET_MEM(bytes) HBLKPTR((size_t) \
2450 calloc(1, (size_t)bytes + GC_page_size) \
2454 extern ptr_t GC_win32_get_mem();
2455 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2458 # if defined(USE_TEMPORARY_MEMORY)
2459 extern Ptr GC_MacTemporaryNewPtr(size_t size,
2460 Boolean clearMemory);
2461 # define GET_MEM(bytes) HBLKPTR( \
2462 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2465 # define GET_MEM(bytes) HBLKPTR( \
2466 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2470 extern ptr_t GC_wince_get_mem();
2471 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2473 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2474 extern void *GC_amiga_get_mem(size_t size);
2475 # define GET_MEM(bytes) HBLKPTR((size_t) \
2476 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2479 # if defined(SN_TARGET_PS3)
2480 extern void *ps3_get_mem (size_t size);
2481 # define GET_MEM(bytes) (struct hblk*) ps3_get_mem (bytes)
2483 extern ptr_t GC_unix_get_mem();
2484 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2494 #endif /* GC_PRIVATE_H */
2496 #if defined(_AIX) && !defined(__GNUC__) && !defined(__STDC__)
2497 /* IBMs xlc compiler doesn't appear to follow the convention of */
2498 /* defining __STDC__ to be zero in extended mode. */
2502 # endif /* GCCONFIG_H */