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 by Hewlett-Packard Company. All rights reserved.
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
18 * This header is private to the gc. It is almost always included from
19 * gc_priv.h. However it is possible to include it by itself if just the
20 * configuration macros are needed. In that
21 * case, a few declarations relying on types declared in gc_priv.h will be
30 /* Fake ptr_t declaration, just to avoid compilation errors. */
31 /* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
32 typedef struct GC_undefined_struct
* ptr_t
;
35 /* Machine dependent parameters. Some tuning parameters can be found */
36 /* near the top of gc_private.h. */
38 /* Machine specific parts contributed by various people. See README file. */
40 /* First a unified test for Linux: */
41 # if defined(linux) || defined(__linux__)
47 /* And one for NetBSD: */
48 # if defined(__NetBSD__)
52 /* And one for OpenBSD: */
53 # if defined(__OpenBSD__)
57 /* And one for FreeBSD: */
58 # if defined(__FreeBSD__)
62 /* Determine the machine type: */
63 # if defined(__arm__) || defined(__thumb__)
65 # if !defined(LINUX) && !defined(NETBSD)
67 # define mach_type_known
70 # if defined(sun) && defined(mc68000)
73 # define mach_type_known
75 # if defined(hp9000s300)
78 # define mach_type_known
80 # if defined(OPENBSD) && defined(m68k)
82 # define mach_type_known
84 # if defined(OPENBSD) && defined(__sparc__)
86 # define mach_type_known
88 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
90 # define mach_type_known
92 # if defined(NETBSD) && defined(__powerpc__)
94 # define mach_type_known
96 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
98 # define mach_type_known
107 # define mach_type_known
109 # if defined(__NetBSD__) && defined(__vax__)
111 # define mach_type_known
113 # if defined(mips) || defined(__mips) || defined(_mips)
115 # if defined(nec_ews) || defined(_nec_ews)
118 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
119 # if defined(ultrix) || defined(__ultrix)
122 # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
123 || defined(__SYSTYPE_SVR4__)
124 # define IRIX5 /* or IRIX 6.X */
126 # define RISCOS /* or IRIX 4.X */
130 # define mach_type_known
132 # if defined(DGUX) && (defined(i386) || defined(__i386__))
137 # define mach_type_known
139 # if defined(sequent) && (defined(i386) || defined(__i386__))
142 # define mach_type_known
144 # if defined(sun) && (defined(i386) || defined(__i386__))
147 # define mach_type_known
149 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
152 # define mach_type_known
156 # define mach_type_known
158 # if defined(sun) && (defined(sparc) || defined(__sparc))
160 /* Test for SunOS 5.x */
167 # define mach_type_known
169 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
170 && !defined(__OpenBSD__) && !(__NetBSD__)
173 # define mach_type_known
177 # define mach_type_known
179 # if defined(__NetBSD__) && defined(__sparc__)
181 # define mach_type_known
183 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
184 /* The above test may need refinement */
186 # if defined(_SCO_ELF)
191 # define mach_type_known
193 # if defined(_AUX_SOURCE)
196 # define mach_type_known
198 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
199 || defined(hppa) || defined(__hppa__)
204 # define mach_type_known
206 # if defined(__ia64) && defined(_HPUX_SOURCE)
209 # define mach_type_known
211 # if defined(__BEOS__) && defined(_X86_)
214 # define mach_type_known
216 # if defined(LINUX) && (defined(i386) || defined(__i386__))
218 # define mach_type_known
220 # if defined(LINUX) && defined(__x86_64__)
222 # define mach_type_known
224 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
226 # define mach_type_known
228 # if defined(LINUX) && defined(__arm__)
230 # define mach_type_known
232 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || defined(powerpc64) || defined(__powerpc64__))
234 # define mach_type_known
236 # if defined(LINUX) && defined(__mc68000__)
238 # define mach_type_known
240 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
242 # define mach_type_known
244 # if defined(LINUX) && defined(__arm__)
246 # define mach_type_known
248 # if defined(LINUX) && defined(__sh__)
250 # define mach_type_known
252 # if defined(__alpha) || defined(__alpha__)
254 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
255 # define OSF1 /* a.k.a Digital Unix */
257 # define mach_type_known
259 # if defined(_AMIGA) && !defined(AMIGA)
264 # define mach_type_known
266 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
269 # define mach_type_known
271 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
274 # define mach_type_known
276 # if defined(macosx) || \
277 defined(__APPLE__) && defined(__MACH__) && defined(__ppc__)
280 # define mach_type_known
282 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
285 --> Not really supported
, but at least we recognize it
.
287 # if defined(NeXT) && defined(mc68000)
290 # define mach_type_known
292 # if defined(NeXT) && (defined(i386) || defined(__i386__))
295 # define mach_type_known
297 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
300 # define mach_type_known
302 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
304 # define mach_type_known
306 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
308 # define mach_type_known
310 # if defined(bsdi) && (defined(i386) || defined(__i386__))
313 # define mach_type_known
315 # if !defined(mach_type_known) && defined(__386BSD__)
318 # define mach_type_known
320 # if defined(_CX_UX) && defined(_M88K)
323 # define mach_type_known
325 # if defined(DGUX) && defined(m88k)
328 # define mach_type_known
330 # if defined(_WIN32_WCE)
331 /* SH3, SH4, MIPS already defined for corresponding architectures */
332 # if defined(SH3) || defined(SH4)
342 # define mach_type_known
344 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
345 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
347 # define MSWIN32 /* or Win32s */
348 # define mach_type_known
351 # if defined(__DJGPP__)
354 # define DJGPP /* MSDOS running the DJGPP port of GCC */
356 # define mach_type_known
358 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
361 # define mach_type_known
363 # if defined(__MINGW32__)
366 # define mach_type_known
368 # if defined(__BORLANDC__)
371 # define mach_type_known
373 # if defined(_UTS) && !defined(mach_type_known)
376 # define mach_type_known
380 # define mach_type_known
382 # if defined(__embedded__) && defined(PPC)
385 # define mach_type_known
388 # if defined(__WATCOMC__) && defined(__386__)
390 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
391 # if defined(__OS2__)
394 # if defined(__WINDOWS_386__) || defined(__NT__)
401 # define mach_type_known
403 # if defined(__s390__) && defined(LINUX)
405 # define mach_type_known
407 # if defined(__GNU__)
408 # if defined(__i386__)
409 /* The Debian Hurd running on generic PC */
412 # define mach_type_known
416 /* Feel free to add more clauses here */
418 /* Or manually define the machine type here. A machine type is */
419 /* characterized by the architecture. Some */
420 /* machine types are further subdivided by OS. */
421 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
422 /* Note that SGI IRIX is treated identically to RISCOS. */
423 /* SYSV on an M68K actually means A/UX. */
424 /* The distinction in these cases is usually the stack starting address */
425 # ifndef mach_type_known
426 --> unknown machine type
428 /* Mapping is: M68K ==> Motorola 680X0 */
429 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
430 /* MACOS and AMIGA variants) */
431 /* I386 ==> Intel 386 */
432 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
433 /* FREEBSD, THREE86BSD, MSWIN32, */
434 /* BSDI,SUNOS5, NEXT, other variants) */
435 /* NS32K ==> Encore Multimax */
436 /* MIPS ==> R2000 or R3000 */
437 /* (RISCOS, ULTRIX variants) */
438 /* VAX ==> DEC VAX */
439 /* (BSD, ULTRIX variants) */
440 /* RS6000 ==> IBM RS/6000 AIX3.X */
441 /* RT ==> IBM PC/RT */
442 /* HP_PA ==> HP9000/700 & /800 */
444 /* SPARC ==> SPARC v7/v8/v9 */
445 /* (SUNOS4, SUNOS5, LINUX, */
446 /* DRSNX variants) */
447 /* ALPHA ==> DEC Alpha */
448 /* (OSF1 and LINUX variants) */
449 /* M88K ==> Motorola 88XX0 */
450 /* (CX_UX and DGUX) */
451 /* S370 ==> 370-like machine */
452 /* running Amdahl UTS4 */
453 /* S390 ==> 390-like machine */
455 /* ARM32 ==> Intel StrongARM */
456 /* IA64 ==> Intel IPF */
458 /* (LINUX and HPUX) */
459 /* SH ==> Hitachi SuperH */
460 /* (LINUX & MSWINCE) */
461 /* X86_64 ==> AMD x86-64 */
462 /* POWERPC ==> IBM/Apple PowerPC */
463 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
464 /* LINUX, NETBSD, NOSYS variants) */
468 * For each architecture and OS, the following need to be defined:
470 * CPP_WORD_SZ is a simple integer constant representing the word size.
471 * in bits. We assume byte addressibility, where a byte has 8 bits.
472 * We also assume CPP_WORD_SZ is either 32 or 64.
473 * (We care about the length of pointers, not hardware
474 * bus widths. Thus a 64 bit processor with a C compiler that uses
475 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
477 * MACH_TYPE is a string representation of the machine type.
478 * OS_TYPE is analogous for the OS.
480 * ALIGNMENT is the largest N, such that
481 * all pointer are guaranteed to be aligned on N byte boundaries.
482 * defining it to be 1 will always work, but perform poorly.
484 * DATASTART is the beginning of the data segment.
485 * On some platforms SEARCH_FOR_DATA_START is defined.
486 * SEARCH_FOR_DATASTART will cause GC_data_start to
487 * be set to an address determined by accessing data backwards from _end
488 * until an unmapped page is found. DATASTART will be defined to be
490 * On UNIX-like systems, the collector will scan the area between DATASTART
491 * and DATAEND for root pointers.
493 * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
494 * RTH suggests gaining access to linker script synth'd values with
495 * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
496 * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
497 * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
498 * without any special options.
500 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
503 * STACKBOTTOM is the cool end of the stack, which is usually the
504 * highest address in the stack.
505 * Under PCR or OS/2, we have other ways of finding thread stacks.
506 * For each machine, the following should:
507 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
508 * 2) define exactly one of
509 * STACKBOTTOM (should be defined to be an expression)
513 * If STACKBOTTOM is defined, then it's value will be used directly as the
514 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
515 * with a method appropriate for most Linux systems. Currently we look
516 * first for __libc_stack_end, and if that fails read it from /proc.
517 * If either of the last two macros are defined, then STACKBOTTOM is computed
518 * during collector startup using one of the following two heuristics:
519 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
520 * the next multiple of STACK_GRAN.
521 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
522 * in small steps (decrement if STACK_GROWS_UP), and read the value
523 * at each location. Remember the value when the first
524 * Segmentation violation or Bus error is signalled. Round that
525 * to the nearest plausible page boundary, and use that instead
528 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
529 * the value of environ is a pointer that can serve as STACKBOTTOM.
530 * I expect that HEURISTIC2 can be replaced by this approach, which
531 * interferes far less with debugging. However it has the disadvantage
532 * that it's confused by a putenv call before the collector is initialized.
533 * This could be dealt with by intercepting putenv ...
535 * If no expression for STACKBOTTOM can be found, and neither of the above
536 * heuristics are usable, the collector can still be used with all of the above
537 * undefined, provided one of the following is done:
538 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
539 * without reference to STACKBOTTOM. This is appropriate for use in
540 * conjunction with thread packages, since there will be multiple stacks.
541 * (Allocating thread stacks in the heap, and treating them as ordinary
542 * heap data objects is also possible as a last resort. However, this is
543 * likely to introduce significant amounts of excess storage retention
544 * unless the dead parts of the thread stacks are periodically cleared.)
545 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
546 * If the author of the client code controls the main program, this is
547 * easily accomplished by introducing a new main program, setting
548 * GC_stackbottom to the address of a local variable, and then calling
549 * the original main program. The new main program would read something
552 * # include "gc_private.h"
554 * main(argc, argv, envp)
556 * char **argv, **envp;
560 * GC_stackbottom = (ptr_t)(&dummy);
561 * return(real_main(argc, argv, envp));
565 * Each architecture may also define the style of virtual dirty bit
566 * implementation to be used:
567 * MPROTECT_VDB: Write protect the heap and catch faults.
568 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
570 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
571 * defined GC_register_dynamic_libraries() for the architecture.
573 * An architecture may define PREFETCH(x) to preload the cache with *x.
574 * This defaults to a no-op.
576 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
578 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
579 * clear the two words at GC_malloc-aligned address x. By default,
580 * word stores of 0 are used instead.
582 * HEAP_START may be defined as the initial address hint for mmap-based
586 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
587 * to push the relevant registers onto the stack. This generally makes
588 * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
590 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
591 (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
592 # define HAVE_BUILTIN_UNWIND_INIT
595 # define STACK_GRAN 0x1000000
597 # define MACH_TYPE "M68K"
600 # define OS_TYPE "OPENBSD"
603 # define DATASTART ((ptr_t)(etext))
606 # define OS_TYPE "NETBSD"
609 # define DATASTART GC_data_start
610 # define DYNAMIC_LOADING
613 # define DATASTART ((ptr_t)(etext))
617 # define OS_TYPE "LINUX"
618 # define STACKBOTTOM ((ptr_t)0xf0000000)
619 # define USE_GENERIC_PUSH_REGS
620 /* We never got around to the assembly version. */
621 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
623 # define DYNAMIC_LOADING
624 # include <features.h>
625 # if defined(__GLIBC__)&& __GLIBC__>=2
626 # define SEARCH_FOR_DATA_START
628 extern char **__environ
;
629 # define DATASTART ((ptr_t)(&__environ))
630 /* hideous kludge: __environ is the first */
631 /* word in crt0.o, and delimits the start */
632 /* of the data segment, no matter which */
633 /* ld options were passed through. */
634 /* We could use _etext instead, but that */
635 /* would include .rodata, which may */
636 /* contain large read-only data tables */
637 /* that we'd rather not scan. */
638 # endif /* !GLIBC2 */
640 # define DATAEND (_end)
643 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
647 # define OS_TYPE "SUNOS4"
649 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
650 # define HEURISTIC1 /* differs */
651 # define DYNAMIC_LOADING
654 # define OS_TYPE "HP"
656 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
657 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
658 /* empirically determined. seems to work. */
660 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
663 # define OS_TYPE "SYSV"
665 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
667 +((word)etext & 0x1fff))
668 /* This only works for shared-text binaries with magic number 0413.
669 The other sorts of SysV binaries put the data at the end of the text,
670 in which case the default of etext would work. Unfortunately,
671 handling both would require having the magic-number available.
674 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
675 /* The stack starts at the top of memory, but */
676 /* 0x0 cannot be used as setjump_test complains */
677 /* that the stack direction is incorrect. Two */
678 /* bytes down from 0x0 should be safe enough. */
680 # include <sys/mmu.h>
681 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
684 # define OS_TYPE "AMIGA"
685 /* STACKBOTTOM and DATASTART handled specially */
687 # define DATAEND /* not needed */
688 # define GETPAGESIZE() 4096
694 # define OS_TYPE "MACOS"
695 /* see os_dep.c for details of global data segments. */
696 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
697 # define DATAEND /* not needed */
698 # define GETPAGESIZE() 4096
701 # define OS_TYPE "NEXT"
702 # define DATASTART ((ptr_t) get_etext())
703 # define STACKBOTTOM ((ptr_t) 0x4000000)
704 # define DATAEND /* not needed */
709 # define MACH_TYPE "POWERPC"
711 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
715 # define OS_TYPE "MACOS"
716 /* see os_dep.c for details of global data segments. */
717 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
718 # define DATAEND /* not needed */
721 # if (defined (powerpc64) || defined(__powerpc64__))
723 # define CPP_WORDSZ 64
727 # define OS_TYPE "LINUX"
728 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
729 /* executable on a 64 bit kernel. */
730 # define LINUX_STACKBOTTOM
731 # define DYNAMIC_LOADING
732 # define SEARCH_FOR_DATA_START
734 # define DATAEND (_end)
738 # define OS_TYPE "DARWIN"
739 # define DYNAMIC_LOADING
740 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
741 These aren't used when dyld support is enabled (it is by default) */
742 # define DATASTART ((ptr_t) get_etext())
743 # define DATAEND ((ptr_t) get_end())
744 # define STACKBOTTOM ((ptr_t) 0xc0000000)
746 # define USE_MMAP_ANON
747 # define USE_ASM_PUSH_REGS
748 /* This is potentially buggy. It needs more testing. See the comments in
750 # define MPROTECT_VDB
752 # define GETPAGESIZE() getpagesize()
753 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
754 /* The performance impact of prefetches is untested */
755 # define PREFETCH(x) \
756 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
757 # define PREFETCH_FOR_WRITE(x) \
758 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
760 /* There seems to be some issues with trylock hanging on darwin. This
761 should be looked into some more */
762 # define NO_PTHREAD_TRYLOCK
766 # define OS_TYPE "NETBSD"
769 # define DATASTART GC_data_start
770 # define DYNAMIC_LOADING
774 # define OS_TYPE "NOSYS"
775 extern void __end
[], __dso_handle
[];
776 # define DATASTART (__dso_handle) /* OK, that's ugly. */
777 # define DATAEND (__end)
778 /* Stack starts at 0xE0000000 for the simulator. */
780 # define STACK_GRAN 0x10000000
786 # define MACH_TYPE "VAX"
787 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
789 # define DATASTART ((ptr_t)(etext))
791 # define OS_TYPE "BSD"
793 /* HEURISTIC2 may be OK, but it's hard to test. */
796 # define OS_TYPE "ULTRIX"
797 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
802 # define MACH_TYPE "RT"
804 # define DATASTART ((ptr_t) 0x10000000)
805 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
809 # define MACH_TYPE "SPARC"
810 # if defined(__arch64__) || defined(__sparcv9)
812 # define CPP_WORDSZ 64
813 # define ELF_CLASS ELFCLASS64
815 # define ALIGNMENT 4 /* Required by hardware */
816 # define CPP_WORDSZ 32
818 # define ALIGN_DOUBLE
820 # define OS_TYPE "SUNOS5"
823 extern ptr_t
GC_SysVGetDataStart();
824 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
825 # define DATAEND (_end)
826 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
828 /* Otherwise we now use calloc. Mmap may result in the */
829 /* heap interleaved with thread stacks, which can result in */
830 /* excessive blacklisting. Sbrk is unusable since it */
831 /* doesn't interact correctly with the system malloc. */
834 # define HEAP_START (ptr_t)0x40000000
836 # define HEAP_START DATAEND
839 /* HEURISTIC1 reportedly no longer works under 2.7. */
840 /* HEURISTIC2 probably works, but this appears to be preferable. */
841 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
842 /* installations that's undefined. We work around this with a */
844 # include <sys/vmparam.h>
846 /* This should work everywhere, but doesn't. */
847 # define STACKBOTTOM USRSTACK
852 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
853 /* getpagesize() appeared to be missing from at least one */
854 /* Solaris 5.4 installation. Weird. */
855 # define DYNAMIC_LOADING
858 # define OS_TYPE "SUNOS4"
859 /* [If you have a weak stomach, don't read this.] */
860 /* We would like to use: */
861 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
862 /* This fails occasionally, due to an ancient, but very */
863 /* persistent ld bug. etext is set 32 bytes too high. */
864 /* We instead read the text segment size from the a.out */
865 /* header, which happens to be mapped into our address space */
866 /* at the start of the text segment. The detective work here */
867 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
868 /* Serpette of INRIA. */
869 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
870 # define TEXTSTART 0x2000
871 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
872 # define MPROTECT_VDB
874 # define DYNAMIC_LOADING
877 # define OS_TYPE "DRSNX"
878 extern ptr_t
GC_SysVGetDataStart();
880 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
881 # define MPROTECT_VDB
882 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
883 # define DYNAMIC_LOADING
886 # define OS_TYPE "LINUX"
888 # define DYNAMIC_LOADING
890 Linux Sparc
/a
.out
not supported
894 # define DATAEND (_end)
896 extern ptr_t
GC_SysVGetDataStart();
898 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
899 /* libc_stack_end is not set reliably for sparc64 */
900 # define STACKBOTTOM ((ptr_t) 0x80000000000ULL)
902 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
903 # define LINUX_STACKBOTTOM
907 # define OS_TYPE "OPENBSD"
908 # define STACKBOTTOM ((ptr_t) 0xf8000000)
910 # define DATASTART ((ptr_t)(etext))
913 # define OS_TYPE "NETBSD"
916 # define DATASTART GC_data_start
917 # define DYNAMIC_LOADING
920 # define DATASTART ((ptr_t)(etext))
926 # define MACH_TYPE "I386"
927 # define ALIGNMENT 4 /* Appears to hold for all "32 bit" compilers */
928 /* except Borland. The -a4 option fixes */
930 /* Ivan Demakov: For Watcom the option is -zp4. */
931 # ifndef SMALL_CONFIG
932 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
933 /* improvement on Pentiums. */
935 # ifdef HAVE_BUILTIN_UNWIND_INIT
936 # define USE_GENERIC_PUSH_REGS
939 # define OS_TYPE "SEQUENT"
941 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
942 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
945 # define OS_TYPE "BEOS"
947 # define GETPAGESIZE() B_PAGE_SIZE
949 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
952 # define OS_TYPE "SUNOS5"
953 extern int _etext
[], _end
[];
954 extern ptr_t
GC_SysVGetDataStart();
955 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
956 # define DATAEND (_end)
957 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
958 /* but reportedly breaks under 2.8. It appears that the stack */
959 /* base is a property of the executable, so this should not break */
960 /* old executables. */
961 /* HEURISTIC2 probably works, but this appears to be preferable. */
963 # define STACKBOTTOM USRSTACK
964 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
965 /* It appears to be fixed in 2.8 and 2.9. */
966 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
969 # define DYNAMIC_LOADING
970 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
972 /* Otherwise we now use calloc. Mmap may result in the */
973 /* heap interleaved with thread stacks, which can result in */
974 /* excessive blacklisting. Sbrk is unusable since it */
975 /* doesn't interact correctly with the system malloc. */
978 # define HEAP_START (ptr_t)0x40000000
980 # define HEAP_START DATAEND
984 # define OS_TYPE "SCO"
986 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
988 +((word)etext & 0xfff))
989 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
992 # define OS_TYPE "SCO_ELF"
994 # define DATASTART ((ptr_t)(etext))
995 # define STACKBOTTOM ((ptr_t) 0x08048000)
996 # define DYNAMIC_LOADING
997 # define ELF_CLASS ELFCLASS32
1000 # define OS_TYPE "DGUX"
1001 extern int _etext
, _end
;
1002 extern ptr_t
GC_SysVGetDataStart();
1003 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1004 # define DATAEND (&_end)
1005 # define STACK_GROWS_DOWN
1007 # include <unistd.h>
1008 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1009 # define DYNAMIC_LOADING
1012 # endif /* USE_MMAP */
1013 # define MAP_FAILED (void *) -1
1015 # define HEAP_START (ptr_t)0x40000000
1016 # else /* USE_MMAP */
1017 # define HEAP_START DATAEND
1018 # endif /* USE_MMAP */
1023 /* The Intel compiler doesn't like inline assembly */
1024 # define USE_GENERIC_PUSH_REGS
1026 # define OS_TYPE "LINUX"
1027 # define LINUX_STACKBOTTOM
1031 # define STACK_GRAN 0x10000000
1032 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1033 /* different kernel configurations. In particular, systems */
1034 /* with 2GB physical memory will usually move the user */
1035 /* address space limit, and hence initial SP to 0x80000000. */
1037 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1038 # define MPROTECT_VDB
1040 /* We seem to get random errors in incremental mode, */
1041 /* possibly because Linux threads is itself a malloc client */
1042 /* and can't deal with the signals. */
1044 # define HEAP_START 0x1000
1045 /* This encourages mmap to give us low addresses, */
1046 /* thus allowing the heap to grow to ~3GB */
1048 # define DYNAMIC_LOADING
1049 # ifdef UNDEFINED /* includes ro data */
1050 extern int _etext
[];
1051 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1053 # include <features.h>
1054 # if defined(__GLIBC__) && __GLIBC__ >= 2
1055 # define SEARCH_FOR_DATA_START
1057 extern char **__environ
;
1058 # define DATASTART ((ptr_t)(&__environ))
1059 /* hideous kludge: __environ is the first */
1060 /* word in crt0.o, and delimits the start */
1061 /* of the data segment, no matter which */
1062 /* ld options were passed through. */
1063 /* We could use _etext instead, but that */
1064 /* would include .rodata, which may */
1065 /* contain large read-only data tables */
1066 /* that we'd rather not scan. */
1069 # define DATAEND (_end)
1072 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1074 # ifdef USE_I686_PREFETCH
1075 # define PREFETCH(x) \
1076 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1077 /* Empirically prefetcht0 is much more effective at reducing */
1078 /* cache miss stalls for the targetted load instructions. But it */
1079 /* seems to interfere enough with other cache traffic that the net */
1080 /* result is worse than prefetchnta. */
1082 /* Using prefetches for write seems to have a slight negative */
1083 /* impact on performance, at least for a PIII/500. */
1084 # define PREFETCH_FOR_WRITE(x) \
1085 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1088 # ifdef USE_3DNOW_PREFETCH
1089 # define PREFETCH(x) \
1090 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1091 # define PREFETCH_FOR_WRITE(x) \
1092 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1096 # define OS_TYPE "CYGWIN32"
1097 extern int _data_start__
[];
1098 extern int _data_end__
[];
1099 extern int _bss_start__
[];
1100 extern int _bss_end__
[];
1101 /* For binutils 2.9.1, we have */
1102 /* DATASTART = _data_start__ */
1103 /* DATAEND = _bss_end__ */
1104 /* whereas for some earlier versions it was */
1105 /* DATASTART = _bss_start__ */
1106 /* DATAEND = _data_end__ */
1107 /* To get it right for both, we take the */
1108 /* minumum/maximum of the two. */
1110 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1113 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1115 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1116 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1118 # define STACK_GRAN 0x10000
1122 # define OS_TYPE "OS2"
1123 /* STACKBOTTOM and DATASTART are handled specially in */
1124 /* os_dep.c. OS2 actually has the right */
1126 # define DATAEND /* not needed */
1127 # define USE_GENERIC_PUSH_REGS
1130 # define OS_TYPE "MSWIN32"
1131 /* STACKBOTTOM and DATASTART are handled specially in */
1133 # ifndef __WATCOMC__
1134 # define MPROTECT_VDB
1136 # define DATAEND /* not needed */
1139 # define OS_TYPE "MSWINCE"
1140 # define DATAEND /* not needed */
1143 # define OS_TYPE "DJGPP"
1144 # include "stubinfo.h"
1147 extern int __djgpp_stack_limit
;
1148 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1149 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1151 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1152 /* This may not be right. */
1155 # define OS_TYPE "OPENBSD"
1158 # define OS_TYPE "FREEBSD"
1159 # ifndef GC_FREEBSD_THREADS
1160 # define MPROTECT_VDB
1162 # define SIG_SUSPEND SIGUSR1
1163 # define SIG_THR_RESTART SIGUSR2
1164 # define FREEBSD_STACKBOTTOM
1166 # define DYNAMIC_LOADING
1168 extern char etext
[];
1169 extern char * GC_FreeBSDGetDataStart();
1170 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1173 # define OS_TYPE "NETBSD"
1175 # define DYNAMIC_LOADING
1179 # define OS_TYPE "THREE86BSD"
1182 # define OS_TYPE "BSDI"
1184 # if defined(OPENBSD) || defined(NETBSD) \
1185 || defined(THREE86BSD) || defined(BSDI)
1187 extern char etext
[];
1188 # define DATASTART ((ptr_t)(etext))
1191 # define OS_TYPE "NEXT"
1192 # define DATASTART ((ptr_t) get_etext())
1193 # define STACKBOTTOM ((ptr_t)0xc0000000)
1194 # define DATAEND /* not needed */
1197 # define OS_TYPE "DOS4GW"
1198 extern long __nullarea
;
1200 extern char *_STACKTOP
;
1201 /* Depending on calling conventions Watcom C either precedes
1202 or does not precedes with undescore names of C-variables.
1203 Make sure startup code variables always have the same names. */
1204 #pragma aux __nullarea "*";
1205 #pragma aux _end "*";
1206 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1207 /* confused? me too. */
1208 # define DATASTART ((ptr_t) &__nullarea)
1209 # define DATAEND ((ptr_t) &_end)
1212 # define OS_TYPE "HURD"
1213 # define STACK_GROWS_DOWN
1215 extern int __data_start
[];
1216 # define DATASTART ( (ptr_t) (__data_start))
1218 # define DATAEND ( (ptr_t) (_end))
1219 /* # define MPROTECT_VDB Not quite working yet? */
1220 # define DYNAMIC_LOADING
1225 # define MACH_TYPE "NS32K"
1226 # define ALIGNMENT 4
1227 extern char **environ
;
1228 # define DATASTART ((ptr_t)(&environ))
1229 /* hideous kludge: environ is the first */
1230 /* word in crt0.o, and delimits the start */
1231 /* of the data segment, no matter which */
1232 /* ld options were passed through. */
1233 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1237 # define MACH_TYPE "MIPS"
1239 /* This was developed for a linuxce style platform. Probably */
1240 /* needs to be tweaked for workstation class machines. */
1241 # define OS_TYPE "LINUX"
1242 # define DYNAMIC_LOADING
1244 # define DATAEND (_end)
1245 extern int __data_start
[];
1246 # define DATASTART ((ptr_t)(__data_start))
1247 # define ALIGNMENT 4
1248 # define USE_GENERIC_PUSH_REGS
1249 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1250 # define LINUX_STACKBOTTOM
1252 # define STACKBOTTOM 0x80000000
1257 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1258 extern int _fdata
[], _end
[];
1259 # define DATASTART ((ptr_t)_fdata)
1260 # define DATAEND ((ptr_t)_end)
1261 # define CPP_WORDSZ _MIPS_SZPTR
1262 # define ALIGNMENT (_MIPS_SZPTR/8)
1264 extern int etext
[], edata
[], end
[];
1265 extern int _DYNAMIC_LINKING
[], _gp
[];
1266 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1267 + ((word)etext & 0xffff)))
1268 # define DATAEND (edata)
1269 # define DATASTART2 (_DYNAMIC_LINKING \
1270 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1272 # define DATAEND2 (end)
1273 # define ALIGNMENT 4
1275 # define OS_TYPE "EWS4800"
1276 # define USE_GENERIC_PUSH_REGS 1
1280 # define DATASTART (ptr_t)0x10000000
1281 /* Could probably be slightly higher since */
1282 /* startup code allocates lots of stuff. */
1283 # define OS_TYPE "ULTRIX"
1284 # define ALIGNMENT 4
1288 # define DATASTART (ptr_t)0x10000000
1289 # define OS_TYPE "RISCOS"
1290 # define ALIGNMENT 4 /* Required by hardware */
1294 extern int _fdata
[];
1295 # define DATASTART ((ptr_t)(_fdata))
1297 # define HEAP_START (ptr_t)0x30000000
1299 # define HEAP_START DATASTART
1301 /* Lowest plausible heap address. */
1302 /* In the MMAP case, we map there. */
1303 /* In either case it is used to identify */
1304 /* heap sections so they're not */
1305 /* considered as roots. */
1306 # define OS_TYPE "IRIX5"
1307 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1308 /* of recent breakage. */
1310 # define CPP_WORDSZ _MIPS_SZPTR
1311 # define ALIGNMENT (_MIPS_SZPTR/8)
1312 # if CPP_WORDSZ != 64
1313 # define ALIGN_DOUBLE
1316 # define ALIGNMENT 4
1317 # define ALIGN_DOUBLE
1319 # define DYNAMIC_LOADING
1322 # define OS_TYPE "MSWINCE"
1323 # define ALIGNMENT 4
1324 # define DATAEND /* not needed */
1326 # if defined(NETBSD)
1327 # define OS_TYPE "NETBSD"
1328 # define ALIGNMENT 4
1330 # define USE_GENERIC_PUSH_REGS
1333 # define DATASTART GC_data_start
1334 # define NEED_FIND_LIMIT
1335 # define DYNAMIC_LOADING
1337 # define DATASTART ((ptr_t) 0x10000000)
1338 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1344 # define MACH_TYPE "RS6000"
1349 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1352 # define ALIGNMENT 8
1353 # define CPP_WORDSZ 64
1354 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1356 # define ALIGNMENT 4
1357 # define CPP_WORDSZ 32
1358 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1360 /* From AIX linker man page:
1361 _text Specifies the first location of the program.
1362 _etext Specifies the first location after the program.
1363 _data Specifies the first location of the data.
1364 _edata Specifies the first location after the initialized data
1365 _end or end Specifies the first location after all data.
1367 extern int _data
[], _end
[];
1368 # define DATASTART ((ptr_t)((ulong)_data))
1369 # define DATAEND ((ptr_t)((ulong)_end))
1371 # define USE_GENERIC_PUSH_REGS
1372 # define DYNAMIC_LOADING
1373 /* For really old versions of AIX, this may have to be removed. */
1377 # define MACH_TYPE "HP_PA"
1379 # define CPP_WORDSZ 64
1380 # define ALIGNMENT 8
1382 # define CPP_WORDSZ 32
1383 # define ALIGNMENT 4
1384 # define ALIGN_DOUBLE
1386 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1387 # ifndef LINUX /* For now. */
1388 # define MPROTECT_VDB
1391 # define GENERIC_COMPARE_AND_SWAP
1392 /* No compare-and-swap instruction. Use pthread mutexes */
1393 /* when we absolutely have to. */
1394 # ifdef PARALLEL_MARK
1395 # define USE_MARK_BYTES
1396 /* Minimize compare-and-swap usage. */
1399 # define STACK_GROWS_UP
1401 # define OS_TYPE "HPUX"
1402 extern int __data_start
[];
1403 # define DATASTART ((ptr_t)(__data_start))
1405 /* The following appears to work for 7xx systems running HP/UX */
1406 /* 9.xx Furthermore, it might result in much faster */
1407 /* collections than HEURISTIC2, which may involve scanning */
1408 /* segments that directly precede the stack. It is not the */
1409 /* default, since it may not work on older machine/OS */
1410 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1412 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1414 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1415 /* to this. Note that the GC must be initialized before the */
1416 /* first putenv call. */
1417 extern char ** environ
;
1418 # define STACKBOTTOM ((ptr_t)environ)
1420 # define DYNAMIC_LOADING
1421 # include <unistd.h>
1422 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1424 # define PREFETCH(x) { \
1425 register long addr = (long)(x); \
1426 (void) _asm ("LDW", 0, 0, addr, 0); \
1431 # define OS_TYPE "LINUX"
1432 # define LINUX_STACKBOTTOM
1433 # define DYNAMIC_LOADING
1434 # define SEARCH_FOR_DATA_START
1436 # define DATAEND (&_end)
1441 # define MACH_TYPE "ALPHA"
1442 # define ALIGNMENT 8
1443 # define CPP_WORDSZ 64
1445 # define USE_GENERIC_PUSH_REGS
1446 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1447 /* fp registers in some cases when the target is a 21264. The assembly */
1448 /* code doesn't handle that yet, and version dependencies make that a */
1449 /* bit tricky. Do the easy thing for now. */
1452 # define OS_TYPE "NETBSD"
1454 # define DATASTART GC_data_start
1455 # define ELFCLASS32 32
1456 # define ELFCLASS64 64
1457 # define ELF_CLASS ELFCLASS64
1458 # define DYNAMIC_LOADING
1461 # define OS_TYPE "OPENBSD"
1463 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1464 # define DATASTART GC_data_start
1465 # define ELFCLASS32 32
1466 # define ELFCLASS64 64
1467 # define ELF_CLASS ELFCLASS64
1468 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1469 # define DATASTART ((ptr_t) 0x140000000)
1473 # define OS_TYPE "FREEBSD"
1474 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1475 # define SIG_SUSPEND SIGUSR1
1476 # define SIG_THR_RESTART SIGUSR2
1477 # define FREEBSD_STACKBOTTOM
1479 # define DYNAMIC_LOADING
1481 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1482 extern char etext
[];
1483 extern char edata
[];
1485 # define NEED_FIND_LIMIT
1486 # define DATASTART ((ptr_t)(&etext))
1487 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1488 # define DATASTART2 ((ptr_t)(&edata))
1489 # define DATAEND2 ((ptr_t)(&end))
1492 # define OS_TYPE "OSF1"
1493 # define DATASTART ((ptr_t) 0x140000000)
1495 # define DATAEND ((ptr_t) &_end)
1496 extern char ** environ
;
1497 /* round up from the value of environ to the nearest page boundary */
1498 /* Probably breaks if putenv is called before collector */
1499 /* initialization. */
1500 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1501 /* # define HEURISTIC2 */
1502 /* Normally HEURISTIC2 is too conervative, since */
1503 /* the text segment immediately follows the stack. */
1504 /* Hence we give an upper pound. */
1505 /* This is currently unused, since we disabled HEURISTIC2 */
1506 extern int __start
[];
1507 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1508 # ifndef GC_OSF1_THREADS
1509 /* Unresolved signal issues with threads. */
1510 # define MPROTECT_VDB
1512 # define DYNAMIC_LOADING
1515 # define OS_TYPE "LINUX"
1516 # define STACKBOTTOM ((ptr_t) 0x120000000)
1518 # define SEARCH_FOR_DATA_START
1519 # define DYNAMIC_LOADING
1521 # define DATASTART ((ptr_t) 0x140000000)
1524 # define DATAEND (_end)
1525 # define MPROTECT_VDB
1526 /* Has only been superficially tested. May not */
1527 /* work on all versions. */
1532 # define MACH_TYPE "IA64"
1533 # define USE_GENERIC_PUSH_REGS
1534 /* We need to get preserved registers in addition to register */
1535 /* windows. That's easiest to do with setjmp. */
1536 # ifdef PARALLEL_MARK
1537 # define USE_MARK_BYTES
1538 /* Compare-and-exchange is too expensive to use for */
1539 /* setting mark bits. */
1543 # define CPP_WORDSZ 32
1544 # define ALIGN_DOUBLE
1545 /* Requires 8 byte alignment for malloc */
1546 # define ALIGNMENT 4
1551 # define CPP_WORDSZ 64
1552 # define ALIGN_DOUBLE
1553 /* Requires 16 byte alignment for malloc */
1554 # define ALIGNMENT 8
1556 # define OS_TYPE "HPUX"
1557 extern int __data_start
[];
1558 # define DATASTART ((ptr_t)(__data_start))
1559 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1560 /* to this. Note that the GC must be initialized before the */
1561 /* first putenv call. */
1562 extern char ** environ
;
1563 # define STACKBOTTOM ((ptr_t)environ)
1564 # define DYNAMIC_LOADING
1565 # include <unistd.h>
1566 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1567 /* The following was empirically determined, and is probably */
1568 /* not very robust. */
1569 /* Note that the backing store base seems to be at a nice */
1570 /* address minus one page. */
1571 # define BACKING_STORE_DISPLACEMENT 0x1000000
1572 # define BACKING_STORE_ALIGNMENT 0x1000
1573 # define BACKING_STORE_BASE \
1574 (ptr_t)(((word)GC_stackbottom - BACKING_STORE_DISPLACEMENT - 1) \
1575 & ~(BACKING_STORE_ALIGNMENT - 1))
1578 # define CPP_WORDSZ 64
1579 # define ALIGN_DOUBLE
1580 /* Requires 16 byte alignment for malloc */
1581 # define ALIGNMENT 8
1582 # define OS_TYPE "LINUX"
1583 /* The following works on NUE and older kernels: */
1584 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1585 /* This does not work on NUE: */
1586 # define LINUX_STACKBOTTOM
1587 /* We also need the base address of the register stack */
1588 /* backing store. This is computed in */
1589 /* GC_linux_register_stack_base based on the following */
1591 # define BACKING_STORE_ALIGNMENT 0x100000
1592 # define BACKING_STORE_DISPLACEMENT 0x80000000
1593 extern char * GC_register_stackbottom
;
1594 # define BACKING_STORE_BASE ((ptr_t)GC_register_stackbottom)
1595 # define SEARCH_FOR_DATA_START
1597 # define DYNAMIC_LOADING
1599 /* In the Intel compiler environment, we seem to end up with */
1600 /* statically linked executables and an undefined reference */
1603 # define MPROTECT_VDB
1604 /* Requires Linux 2.3.47 or later. */
1606 # define DATAEND (_end)
1608 # define PREFETCH(x) \
1609 __asm__ (" lfetch [%0]": : "r"((void *)(x)))
1610 # define PREFETCH_FOR_WRITE(x) \
1611 __asm__ (" lfetch.excl [%0]": : "r"((void *)(x)))
1612 # define CLEAR_DOUBLE(x) \
1613 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1619 # define MACH_TYPE "M88K"
1620 # define ALIGNMENT 4
1621 # define ALIGN_DOUBLE
1624 # define OS_TYPE "CX_UX"
1625 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1628 # define OS_TYPE "DGUX"
1629 extern ptr_t
GC_SysVGetDataStart();
1630 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1632 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1636 /* If this still works, and if anyone cares, this should probably */
1637 /* be moved to the S390 category. */
1638 # define MACH_TYPE "S370"
1639 # define ALIGNMENT 4 /* Required by hardware */
1640 # define USE_GENERIC_PUSH_REGS
1642 # define OS_TYPE "UTS4"
1644 extern int _etext
[];
1646 extern ptr_t
GC_SysVGetDataStart();
1647 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1648 # define DATAEND (_end)
1654 # define MACH_TYPE "S390"
1655 # define USE_GENERIC_PUSH_REGS
1657 # define ALIGNMENT 4
1658 # define CPP_WORDSZ 32
1660 # define ALIGNMENT 8
1661 # define CPP_WORDSZ 64
1662 # define HBLKSIZE 4096
1665 # define OS_TYPE "LINUX"
1666 # define LINUX_STACKBOTTOM
1667 # define DYNAMIC_LOADING
1668 extern int __data_start
[];
1669 # define DATASTART ((ptr_t)(__data_start))
1671 # define DATAEND (_end)
1672 # define CACHE_LINE_SIZE 256
1673 # define GETPAGESIZE() 4096
1678 # define ALIGNMENT 4
1679 extern int _etext
[];
1680 # define DATASTART ((ptr_t)(_etext))
1685 # define CPP_WORDSZ 32
1686 # define MACH_TYPE "ARM32"
1687 # define ALIGNMENT 4
1689 # define OS_TYPE "NETBSD"
1692 # define DATASTART GC_data_start
1693 # define DYNAMIC_LOADING
1695 extern char etext
[];
1696 # define DATASTART ((ptr_t)(etext))
1698 # define USE_GENERIC_PUSH_REGS
1701 # define OS_TYPE "LINUX"
1704 # define STACK_GRAN 0x10000000
1705 # define USE_GENERIC_PUSH_REGS
1707 # define DYNAMIC_LOADING
1708 # include <features.h>
1709 # if defined(__GLIBC__) && __GLIBC__ >= 2
1710 # define SEARCH_FOR_DATA_START
1712 extern char **__environ
;
1713 # define DATASTART ((ptr_t)(&__environ))
1714 /* hideous kludge: __environ is the first */
1715 /* word in crt0.o, and delimits the start */
1716 /* of the data segment, no matter which */
1717 /* ld options were passed through. */
1718 /* We could use _etext instead, but that */
1719 /* would include .rodata, which may */
1720 /* contain large read-only data tables */
1721 /* that we'd rather not scan. */
1724 # define DATAEND (_end)
1727 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1731 # define OS_TYPE "MSWINCE"
1732 # define DATAEND /* not needed */
1735 /* __data_start is usually defined in the target linker script. */
1736 extern int __data_start
[];
1737 # define DATASTART (ptr_t)(__data_start)
1738 # define USE_GENERIC_PUSH_REGS
1739 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1740 extern void *__stack_base__
;
1741 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1746 # define MACH_TYPE "SH"
1747 # define ALIGNMENT 4
1749 # define OS_TYPE "MSWINCE"
1750 # define DATAEND /* not needed */
1753 # define OS_TYPE "LINUX"
1754 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1755 # define USE_GENERIC_PUSH_REGS
1756 # define DYNAMIC_LOADING
1757 # define SEARCH_FOR_DATA_START
1759 # define DATAEND (_end)
1764 # define MACH_TYPE "SH4"
1765 # define OS_TYPE "MSWINCE"
1766 # define ALIGNMENT 4
1767 # define DATAEND /* not needed */
1771 # define MACH_TYPE "X86_64"
1772 # define ALIGNMENT 8
1773 # define CPP_WORDSZ 64
1775 # define HBLKSIZE 4096
1777 # define CACHE_LINE_SIZE 64
1778 # define USE_GENERIC_PUSH_REGS
1780 # define OS_TYPE "LINUX"
1781 # define LINUX_STACKBOTTOM
1782 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1783 # define MPROTECT_VDB
1785 /* We seem to get random errors in incremental mode, */
1786 /* possibly because Linux threads is itself a malloc client */
1787 /* and can't deal with the signals. */
1790 # define DYNAMIC_LOADING
1791 # ifdef UNDEFINED /* includes ro data */
1792 extern int _etext
[];
1793 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1795 # include <features.h>
1796 # define SEARCH_FOR_DATA_START
1798 # define DATAEND (_end)
1801 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1803 # define PREFETCH(x) \
1804 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1805 # define PREFETCH_FOR_WRITE(x) \
1806 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1810 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1811 /* Rld appears to allocate some memory with its own allocator, and */
1812 /* some through malloc, which might be redirected. To make this */
1813 /* work with collectable memory, we have to scan memory allocated */
1814 /* by rld's internal malloc. */
1815 # define USE_PROC_FOR_LIBRARIES
1818 # ifndef STACK_GROWS_UP
1819 # define STACK_GROWS_DOWN
1823 # define CPP_WORDSZ 32
1832 # define DATAEND (end)
1835 # if defined(SVR4) && !defined(GETPAGESIZE)
1836 # include <unistd.h>
1837 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1840 # ifndef GETPAGESIZE
1841 # if defined(SUNOS5) || defined(IRIX5)
1842 # include <unistd.h>
1844 # define GETPAGESIZE() getpagesize()
1847 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1848 /* OS has SVR4 generic features. Probably others also qualify. */
1852 # if defined(SUNOS5) || defined(DRSNX)
1853 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1856 /* OS has SUNOS5 style signal handlers. */
1864 # if defined(SVR4) || defined(LINUX) || defined(IRIX) || defined(HPUX) \
1865 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1866 || defined(DGUX) || defined(BSD) \
1867 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
1868 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1871 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1876 # undef DYNAMIC_LOADING
1881 # undef MPROTECT_VDB
1886 /* Postponed for now. */
1888 # undef MPROTECT_VDB
1891 # ifdef SMALL_CONFIG
1892 /* Presumably not worth the space it takes. */
1894 # undef MPROTECT_VDB
1898 # undef MPROTECT_VDB /* Can't deal with address space holes. */
1901 # ifdef PARALLEL_MARK
1902 # undef MPROTECT_VDB /* For now. */
1905 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
1906 # define DEFAULT_VDB
1910 # define PREFETCH(x)
1911 # define NO_PREFETCH
1914 # ifndef PREFETCH_FOR_WRITE
1915 # define PREFETCH_FOR_WRITE(x)
1916 # define NO_PREFETCH_FOR_WRITE
1919 # ifndef CACHE_LINE_SIZE
1920 # define CACHE_LINE_SIZE 32 /* Wild guess */
1924 # define REGISTER_LIBRARIES_EARLY
1925 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
1926 /* lock. This isn't safe after the world has stopped. So we must */
1927 /* call GC_register_dynamic_libraries before stopping the world. */
1928 /* For performance reasons, this may be beneficial on other */
1929 /* platforms as well, though it should be avoided in win32. */
1932 # if defined(SEARCH_FOR_DATA_START)
1933 extern ptr_t GC_data_start
;
1934 # define DATASTART GC_data_start
1937 # ifndef CLEAR_DOUBLE
1938 # define CLEAR_DOUBLE(x) \
1939 ((word*)x)[0] = 0; \
1941 # endif /* CLEAR_DOUBLE */
1943 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
1944 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
1945 # define GC_SOLARIS_THREADS
1948 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
1949 --> inconsistent configuration
1951 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
1952 --> inconsistent configuration
1954 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
1955 --> inconsistent configuration
1957 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
1958 --> inconsistent configuration
1960 # if defined(GC_AIX_THREADS) && !defined(_AIX)
1961 --> inconsistent configuration
1963 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
1964 --> inconsistent configuration
1967 # if defined(PCR) || defined(SRC_M3) || \
1968 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
1969 defined(GC_PTHREADS)
1973 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
1974 || defined(LINT) || defined(MSWINCE) || defined(ARM32) \
1975 || (defined(I386) && defined(__LCC__))
1976 /* Use setjmp based hack to mark from callee-save registers. */
1977 /* The define should move to the individual platform */
1979 # define USE_GENERIC_PUSH_REGS
1983 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
1984 /* include assembly code to do it well. */
1987 /* Can we save call chain in objects for debugging? */
1988 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
1989 /* frame) to reasonable values for the platform. */
1990 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
1991 /* at build time, though we feel free to adjust it slightly. */
1992 /* Define NEED_CALLINFO if we either save the call stack or */
1993 /* GC_ADD_CALLER is defined. */
1994 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
1997 # define CAN_SAVE_CALL_ARGS
1999 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2000 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2001 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2002 # define CAN_SAVE_CALL_ARGS
2005 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2006 && defined(GC_CAN_SAVE_CALL_STACKS)
2007 # define SAVE_CALL_CHAIN
2009 # ifdef SAVE_CALL_CHAIN
2010 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2011 # define NARGS SAVE_CALL_NARGS
2013 # define NARGS 0 /* Number of arguments to save for each call. */
2016 # ifdef SAVE_CALL_CHAIN
2017 # ifndef SAVE_CALL_COUNT
2018 # define NFRAMES 6 /* Number of frames to save. Even for */
2019 /* alignment reasons. */
2021 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2023 # define NEED_CALLINFO
2024 # endif /* SAVE_CALL_CHAIN */
2025 # ifdef GC_ADD_CALLER
2028 # define NEED_CALLINFO
2031 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2032 # define DBG_HDRS_ALL
2035 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2036 # define POINTER_SHIFT 0
2039 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2040 # define POINTER_MASK ((GC_word)(-1))
2043 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2044 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2047 # if defined(FIXUP_POINTER)
2048 # define NEED_FIXUP_POINTER 1
2050 # define NEED_FIXUP_POINTER 0
2051 # define FIXUP_POINTER(p)
2055 /* This relies on some type definitions from gc_priv.h, from */
2056 /* where it's normally included. */
2058 /* How to get heap memory from the OS: */
2059 /* Note that sbrk()-like allocation is preferred, since it */
2060 /* usually makes it possible to merge consecutively allocated */
2061 /* chunks. It also avoids unintented recursion with */
2062 /* -DREDIRECT_MALLOC. */
2063 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2064 /* 0 is taken to mean failure. */
2065 /* In the case os USE_MMAP, the argument must also be a */
2066 /* physical page size. */
2067 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2068 /* though we should perhaps take advantage of the case in which */
2070 struct hblk
; /* See gc_priv.h. */
2072 char * real_malloc();
2073 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2077 void * os2_alloc(size_t bytes
);
2078 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2082 # if defined(NEXT) || defined(DOS4GW) || \
2083 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2084 (defined(SUNOS5) && !defined(USE_MMAP))
2085 # define GET_MEM(bytes) HBLKPTR((size_t) \
2086 calloc(1, (size_t)bytes + GC_page_size) \
2090 extern ptr_t
GC_win32_get_mem();
2091 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2094 # if defined(USE_TEMPORARY_MEMORY)
2095 extern Ptr
GC_MacTemporaryNewPtr(size_t size
,
2096 Boolean clearMemory
);
2097 # define GET_MEM(bytes) HBLKPTR( \
2098 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2101 # define GET_MEM(bytes) HBLKPTR( \
2102 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2106 extern ptr_t
GC_wince_get_mem();
2107 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2109 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2110 extern void *GC_amiga_get_mem(size_t size
);
2111 # define GET_MEM(bytes) HBLKPTR((size_t) \
2112 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2115 extern ptr_t
GC_unix_get_mem();
2116 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2125 #endif /* GC_PRIVATE_H */
2127 # endif /* GCCONFIG_H */