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
621 /* We never got around to the assembly version. */
622 /* # define MPROTECT_VDB - Reported to not work 9/17/01 */
624 # define DYNAMIC_LOADING
625 # include <features.h>
626 # if defined(__GLIBC__)&& __GLIBC__>=2
627 # define SEARCH_FOR_DATA_START
629 extern char **__environ
;
630 # define DATASTART ((ptr_t)(&__environ))
631 /* hideous kludge: __environ is the first */
632 /* word in crt0.o, and delimits the start */
633 /* of the data segment, no matter which */
634 /* ld options were passed through. */
635 /* We could use _etext instead, but that */
636 /* would include .rodata, which may */
637 /* contain large read-only data tables */
638 /* that we'd rather not scan. */
639 # endif /* !GLIBC2 */
641 # define DATAEND (_end)
644 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
648 # define OS_TYPE "SUNOS4"
650 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
651 # define HEURISTIC1 /* differs */
652 # define DYNAMIC_LOADING
655 # define OS_TYPE "HP"
657 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
658 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
659 /* empirically determined. seems to work. */
661 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
664 # define OS_TYPE "SYSV"
666 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
668 +((word)etext & 0x1fff))
669 /* This only works for shared-text binaries with magic number 0413.
670 The other sorts of SysV binaries put the data at the end of the text,
671 in which case the default of etext would work. Unfortunately,
672 handling both would require having the magic-number available.
675 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
676 /* The stack starts at the top of memory, but */
677 /* 0x0 cannot be used as setjump_test complains */
678 /* that the stack direction is incorrect. Two */
679 /* bytes down from 0x0 should be safe enough. */
681 # include <sys/mmu.h>
682 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
685 # define OS_TYPE "AMIGA"
686 /* STACKBOTTOM and DATASTART handled specially */
688 # define DATAEND /* not needed */
689 # define GETPAGESIZE() 4096
695 # define OS_TYPE "MACOS"
696 /* see os_dep.c for details of global data segments. */
697 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
698 # define DATAEND /* not needed */
699 # define GETPAGESIZE() 4096
702 # define OS_TYPE "NEXT"
703 # define DATASTART ((ptr_t) get_etext())
704 # define STACKBOTTOM ((ptr_t) 0x4000000)
705 # define DATAEND /* not needed */
710 # define MACH_TYPE "POWERPC"
712 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
716 # define OS_TYPE "MACOS"
717 /* see os_dep.c for details of global data segments. */
718 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
719 # define DATAEND /* not needed */
722 # if (defined (powerpc64) || defined(__powerpc64__))
724 # define CPP_WORDSZ 64
728 # define OS_TYPE "LINUX"
729 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
730 /* executable on a 64 bit kernel. */
731 # define LINUX_STACKBOTTOM
732 # define DYNAMIC_LOADING
733 # define SEARCH_FOR_DATA_START
735 # define DATAEND (_end)
739 # define OS_TYPE "DARWIN"
740 # define DYNAMIC_LOADING
741 /* XXX: see get_end(3), get_etext() and get_end() should not be used.
742 These aren't used when dyld support is enabled (it is by default) */
743 # define DATASTART ((ptr_t) get_etext())
744 # define DATAEND ((ptr_t) get_end())
745 # define STACKBOTTOM ((ptr_t) 0xc0000000)
747 # define USE_MMAP_ANON
748 # define USE_ASM_PUSH_REGS
749 /* This is potentially buggy. It needs more testing. See the comments in
751 # define MPROTECT_VDB
753 # define GETPAGESIZE() getpagesize()
754 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
755 /* The performance impact of prefetches is untested */
756 # define PREFETCH(x) \
757 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
758 # define PREFETCH_FOR_WRITE(x) \
759 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
761 /* There seems to be some issues with trylock hanging on darwin. This
762 should be looked into some more */
763 # define NO_PTHREAD_TRYLOCK
767 # define OS_TYPE "NETBSD"
770 # define DATASTART GC_data_start
771 # define DYNAMIC_LOADING
775 # define OS_TYPE "NOSYS"
776 extern void __end
[], __dso_handle
[];
777 # define DATASTART (__dso_handle) /* OK, that's ugly. */
778 # define DATAEND (__end)
779 /* Stack starts at 0xE0000000 for the simulator. */
781 # define STACK_GRAN 0x10000000
787 # define MACH_TYPE "VAX"
788 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
790 # define DATASTART ((ptr_t)(etext))
792 # define OS_TYPE "BSD"
794 /* HEURISTIC2 may be OK, but it's hard to test. */
797 # define OS_TYPE "ULTRIX"
798 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
803 # define MACH_TYPE "RT"
805 # define DATASTART ((ptr_t) 0x10000000)
806 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
810 # define MACH_TYPE "SPARC"
811 # if defined(__arch64__) || defined(__sparcv9)
813 # define CPP_WORDSZ 64
814 # define ELF_CLASS ELFCLASS64
816 # define ALIGNMENT 4 /* Required by hardware */
817 # define CPP_WORDSZ 32
819 # define ALIGN_DOUBLE
821 # define OS_TYPE "SUNOS5"
824 extern ptr_t
GC_SysVGetDataStart();
825 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
826 # define DATAEND (_end)
827 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
829 /* Otherwise we now use calloc. Mmap may result in the */
830 /* heap interleaved with thread stacks, which can result in */
831 /* excessive blacklisting. Sbrk is unusable since it */
832 /* doesn't interact correctly with the system malloc. */
835 # define HEAP_START (ptr_t)0x40000000
837 # define HEAP_START DATAEND
840 /* HEURISTIC1 reportedly no longer works under 2.7. */
841 /* HEURISTIC2 probably works, but this appears to be preferable. */
842 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
843 /* installations that's undefined. We work around this with a */
845 # include <sys/vmparam.h>
847 /* This should work everywhere, but doesn't. */
848 # define STACKBOTTOM USRSTACK
853 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
854 /* getpagesize() appeared to be missing from at least one */
855 /* Solaris 5.4 installation. Weird. */
856 # define DYNAMIC_LOADING
859 # define OS_TYPE "SUNOS4"
860 /* [If you have a weak stomach, don't read this.] */
861 /* We would like to use: */
862 /* # define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
863 /* This fails occasionally, due to an ancient, but very */
864 /* persistent ld bug. etext is set 32 bytes too high. */
865 /* We instead read the text segment size from the a.out */
866 /* header, which happens to be mapped into our address space */
867 /* at the start of the text segment. The detective work here */
868 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
869 /* Serpette of INRIA. */
870 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
871 # define TEXTSTART 0x2000
872 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
873 # define MPROTECT_VDB
875 # define DYNAMIC_LOADING
878 # define OS_TYPE "DRSNX"
879 extern ptr_t
GC_SysVGetDataStart();
881 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
882 # define MPROTECT_VDB
883 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
884 # define DYNAMIC_LOADING
887 # define OS_TYPE "LINUX"
889 # define DYNAMIC_LOADING
891 Linux Sparc
/a
.out
not supported
895 # define DATAEND (_end)
897 extern ptr_t
GC_SysVGetDataStart();
899 # define DATASTART GC_SysVGetDataStart(0x100000, _etext)
900 /* libc_stack_end is not set reliably for sparc64 */
901 # define STACKBOTTOM ((ptr_t) 0x80000000000ULL)
903 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
904 # define LINUX_STACKBOTTOM
908 # define OS_TYPE "OPENBSD"
909 # define STACKBOTTOM ((ptr_t) 0xf8000000)
911 # define DATASTART ((ptr_t)(etext))
914 # define OS_TYPE "NETBSD"
917 # define DATASTART GC_data_start
918 # define DYNAMIC_LOADING
921 # define DATASTART ((ptr_t)(etext))
927 # define MACH_TYPE "I386"
928 # define ALIGNMENT 4 /* Appears to hold for all "32 bit" compilers */
929 /* except Borland. The -a4 option fixes */
931 /* Ivan Demakov: For Watcom the option is -zp4. */
932 # ifndef SMALL_CONFIG
933 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
934 /* improvement on Pentiums. */
936 # ifdef HAVE_BUILTIN_UNWIND_INIT
937 # define USE_GENERIC_PUSH_REGS
940 # define OS_TYPE "SEQUENT"
942 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
943 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
946 # define OS_TYPE "BEOS"
948 # define GETPAGESIZE() B_PAGE_SIZE
950 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
953 # define OS_TYPE "SUNOS5"
954 extern int _etext
[], _end
[];
955 extern ptr_t
GC_SysVGetDataStart();
956 # define DATASTART GC_SysVGetDataStart(0x1000, _etext)
957 # define DATAEND (_end)
958 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
959 /* but reportedly breaks under 2.8. It appears that the stack */
960 /* base is a property of the executable, so this should not break */
961 /* old executables. */
962 /* HEURISTIC2 probably works, but this appears to be preferable. */
964 # define STACKBOTTOM USRSTACK
965 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
966 /* It appears to be fixed in 2.8 and 2.9. */
967 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
970 # define DYNAMIC_LOADING
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
985 # define OS_TYPE "SCO"
987 # define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
989 +((word)etext & 0xfff))
990 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
993 # define OS_TYPE "SCO_ELF"
995 # define DATASTART ((ptr_t)(etext))
996 # define STACKBOTTOM ((ptr_t) 0x08048000)
997 # define DYNAMIC_LOADING
998 # define ELF_CLASS ELFCLASS32
1001 # define OS_TYPE "DGUX"
1002 extern int _etext
, _end
;
1003 extern ptr_t
GC_SysVGetDataStart();
1004 # define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1005 # define DATAEND (&_end)
1006 # define STACK_GROWS_DOWN
1008 # include <unistd.h>
1009 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1010 # define DYNAMIC_LOADING
1013 # endif /* USE_MMAP */
1014 # define MAP_FAILED (void *) -1
1016 # define HEAP_START (ptr_t)0x40000000
1017 # else /* USE_MMAP */
1018 # define HEAP_START DATAEND
1019 # endif /* USE_MMAP */
1024 /* The Intel compiler doesn't like inline assembly */
1025 # define USE_GENERIC_PUSH_REGS
1027 # define OS_TYPE "LINUX"
1028 # define LINUX_STACKBOTTOM
1032 # define STACK_GRAN 0x10000000
1033 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
1034 /* different kernel configurations. In particular, systems */
1035 /* with 2GB physical memory will usually move the user */
1036 /* address space limit, and hence initial SP to 0x80000000. */
1038 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1039 # define MPROTECT_VDB
1041 /* We seem to get random errors in incremental mode, */
1042 /* possibly because Linux threads is itself a malloc client */
1043 /* and can't deal with the signals. */
1045 # define HEAP_START 0x1000
1046 /* This encourages mmap to give us low addresses, */
1047 /* thus allowing the heap to grow to ~3GB */
1049 # define DYNAMIC_LOADING
1050 # ifdef UNDEFINED /* includes ro data */
1051 extern int _etext
[];
1052 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1054 # include <features.h>
1055 # if defined(__GLIBC__) && __GLIBC__ >= 2
1056 # define SEARCH_FOR_DATA_START
1058 extern char **__environ
;
1059 # define DATASTART ((ptr_t)(&__environ))
1060 /* hideous kludge: __environ is the first */
1061 /* word in crt0.o, and delimits the start */
1062 /* of the data segment, no matter which */
1063 /* ld options were passed through. */
1064 /* We could use _etext instead, but that */
1065 /* would include .rodata, which may */
1066 /* contain large read-only data tables */
1067 /* that we'd rather not scan. */
1070 # define DATAEND (_end)
1073 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1075 # ifdef USE_I686_PREFETCH
1076 # define PREFETCH(x) \
1077 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1078 /* Empirically prefetcht0 is much more effective at reducing */
1079 /* cache miss stalls for the targetted load instructions. But it */
1080 /* seems to interfere enough with other cache traffic that the net */
1081 /* result is worse than prefetchnta. */
1083 /* Using prefetches for write seems to have a slight negative */
1084 /* impact on performance, at least for a PIII/500. */
1085 # define PREFETCH_FOR_WRITE(x) \
1086 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1089 # ifdef USE_3DNOW_PREFETCH
1090 # define PREFETCH(x) \
1091 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1092 # define PREFETCH_FOR_WRITE(x) \
1093 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1097 # define OS_TYPE "CYGWIN32"
1098 extern int _data_start__
[];
1099 extern int _data_end__
[];
1100 extern int _bss_start__
[];
1101 extern int _bss_end__
[];
1102 /* For binutils 2.9.1, we have */
1103 /* DATASTART = _data_start__ */
1104 /* DATAEND = _bss_end__ */
1105 /* whereas for some earlier versions it was */
1106 /* DATASTART = _bss_start__ */
1107 /* DATAEND = _data_end__ */
1108 /* To get it right for both, we take the */
1109 /* minumum/maximum of the two. */
1111 # define MAX(x,y) ((x) > (y) ? (x) : (y))
1114 # define MIN(x,y) ((x) < (y) ? (x) : (y))
1116 # define DATASTART ((ptr_t) MIN(_data_start__, _bss_start__))
1117 # define DATAEND ((ptr_t) MAX(_data_end__, _bss_end__))
1119 # define STACK_GRAN 0x10000
1123 # define OS_TYPE "OS2"
1124 /* STACKBOTTOM and DATASTART are handled specially in */
1125 /* os_dep.c. OS2 actually has the right */
1127 # define DATAEND /* not needed */
1128 # define USE_GENERIC_PUSH_REGS
1131 # define OS_TYPE "MSWIN32"
1132 /* STACKBOTTOM and DATASTART are handled specially in */
1134 # ifndef __WATCOMC__
1135 # define MPROTECT_VDB
1137 # define DATAEND /* not needed */
1140 # define OS_TYPE "MSWINCE"
1141 # define DATAEND /* not needed */
1144 # define OS_TYPE "DJGPP"
1145 # include "stubinfo.h"
1148 extern int __djgpp_stack_limit
;
1149 # define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1150 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1152 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1153 /* This may not be right. */
1156 # define OS_TYPE "OPENBSD"
1159 # define OS_TYPE "FREEBSD"
1160 # ifndef GC_FREEBSD_THREADS
1161 # define MPROTECT_VDB
1163 # define SIG_SUSPEND SIGUSR1
1164 # define SIG_THR_RESTART SIGUSR2
1165 # define FREEBSD_STACKBOTTOM
1167 # define DYNAMIC_LOADING
1169 extern char etext
[];
1170 extern char * GC_FreeBSDGetDataStart();
1171 # define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1174 # define OS_TYPE "NETBSD"
1176 # define DYNAMIC_LOADING
1180 # define OS_TYPE "THREE86BSD"
1183 # define OS_TYPE "BSDI"
1185 # if defined(OPENBSD) || defined(NETBSD) \
1186 || defined(THREE86BSD) || defined(BSDI)
1188 extern char etext
[];
1189 # define DATASTART ((ptr_t)(etext))
1192 # define OS_TYPE "NEXT"
1193 # define DATASTART ((ptr_t) get_etext())
1194 # define STACKBOTTOM ((ptr_t)0xc0000000)
1195 # define DATAEND /* not needed */
1198 # define OS_TYPE "DOS4GW"
1199 extern long __nullarea
;
1201 extern char *_STACKTOP
;
1202 /* Depending on calling conventions Watcom C either precedes
1203 or does not precedes with undescore names of C-variables.
1204 Make sure startup code variables always have the same names. */
1205 #pragma aux __nullarea "*";
1206 #pragma aux _end "*";
1207 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1208 /* confused? me too. */
1209 # define DATASTART ((ptr_t) &__nullarea)
1210 # define DATAEND ((ptr_t) &_end)
1213 # define OS_TYPE "HURD"
1214 # define STACK_GROWS_DOWN
1216 extern int __data_start
[];
1217 # define DATASTART ( (ptr_t) (__data_start))
1219 # define DATAEND ( (ptr_t) (_end))
1220 /* # define MPROTECT_VDB Not quite working yet? */
1221 # define DYNAMIC_LOADING
1226 # define MACH_TYPE "NS32K"
1227 # define ALIGNMENT 4
1228 extern char **environ
;
1229 # define DATASTART ((ptr_t)(&environ))
1230 /* hideous kludge: environ is the first */
1231 /* word in crt0.o, and delimits the start */
1232 /* of the data segment, no matter which */
1233 /* ld options were passed through. */
1234 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1238 # define MACH_TYPE "MIPS"
1240 /* This was developed for a linuxce style platform. Probably */
1241 /* needs to be tweaked for workstation class machines. */
1242 # define OS_TYPE "LINUX"
1243 # define DYNAMIC_LOADING
1245 # define DATAEND (_end)
1246 extern int __data_start
[];
1247 # define DATASTART ((ptr_t)(__data_start))
1248 # define ALIGNMENT 4
1249 # define USE_GENERIC_PUSH_REGS
1250 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1251 # define LINUX_STACKBOTTOM
1253 # define STACKBOTTOM 0x80000000
1258 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1259 extern int _fdata
[], _end
[];
1260 # define DATASTART ((ptr_t)_fdata)
1261 # define DATAEND ((ptr_t)_end)
1262 # define CPP_WORDSZ _MIPS_SZPTR
1263 # define ALIGNMENT (_MIPS_SZPTR/8)
1265 extern int etext
[], edata
[], end
[];
1266 extern int _DYNAMIC_LINKING
[], _gp
[];
1267 # define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1268 + ((word)etext & 0xffff)))
1269 # define DATAEND (edata)
1270 # define DATASTART2 (_DYNAMIC_LINKING \
1271 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1273 # define DATAEND2 (end)
1274 # define ALIGNMENT 4
1276 # define OS_TYPE "EWS4800"
1277 # define USE_GENERIC_PUSH_REGS 1
1281 # define DATASTART (ptr_t)0x10000000
1282 /* Could probably be slightly higher since */
1283 /* startup code allocates lots of stuff. */
1284 # define OS_TYPE "ULTRIX"
1285 # define ALIGNMENT 4
1289 # define DATASTART (ptr_t)0x10000000
1290 # define OS_TYPE "RISCOS"
1291 # define ALIGNMENT 4 /* Required by hardware */
1295 extern int _fdata
[];
1296 # define DATASTART ((ptr_t)(_fdata))
1298 # define HEAP_START (ptr_t)0x30000000
1300 # define HEAP_START DATASTART
1302 /* Lowest plausible heap address. */
1303 /* In the MMAP case, we map there. */
1304 /* In either case it is used to identify */
1305 /* heap sections so they're not */
1306 /* considered as roots. */
1307 # define OS_TYPE "IRIX5"
1308 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1309 /* of recent breakage. */
1311 # define CPP_WORDSZ _MIPS_SZPTR
1312 # define ALIGNMENT (_MIPS_SZPTR/8)
1313 # if CPP_WORDSZ != 64
1314 # define ALIGN_DOUBLE
1317 # define ALIGNMENT 4
1318 # define ALIGN_DOUBLE
1320 # define DYNAMIC_LOADING
1323 # define OS_TYPE "MSWINCE"
1324 # define ALIGNMENT 4
1325 # define DATAEND /* not needed */
1327 # if defined(NETBSD)
1328 # define OS_TYPE "NETBSD"
1329 # define ALIGNMENT 4
1331 # define USE_GENERIC_PUSH_REGS
1334 # define DATASTART GC_data_start
1335 # define NEED_FIND_LIMIT
1336 # define DYNAMIC_LOADING
1338 # define DATASTART ((ptr_t) 0x10000000)
1339 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1345 # define MACH_TYPE "RS6000"
1350 # undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1353 # define ALIGNMENT 8
1354 # define CPP_WORDSZ 64
1355 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1357 # define ALIGNMENT 4
1358 # define CPP_WORDSZ 32
1359 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1361 /* From AIX linker man page:
1362 _text Specifies the first location of the program.
1363 _etext Specifies the first location after the program.
1364 _data Specifies the first location of the data.
1365 _edata Specifies the first location after the initialized data
1366 _end or end Specifies the first location after all data.
1368 extern int _data
[], _end
[];
1369 # define DATASTART ((ptr_t)((ulong)_data))
1370 # define DATAEND ((ptr_t)((ulong)_end))
1372 # define USE_GENERIC_PUSH_REGS
1373 # define DYNAMIC_LOADING
1374 /* For really old versions of AIX, this may have to be removed. */
1378 # define MACH_TYPE "HP_PA"
1380 # define CPP_WORDSZ 64
1381 # define ALIGNMENT 8
1383 # define CPP_WORDSZ 32
1384 # define ALIGNMENT 4
1385 # define ALIGN_DOUBLE
1387 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1388 # ifndef LINUX /* For now. */
1389 # define MPROTECT_VDB
1392 # define GENERIC_COMPARE_AND_SWAP
1393 /* No compare-and-swap instruction. Use pthread mutexes */
1394 /* when we absolutely have to. */
1395 # ifdef PARALLEL_MARK
1396 # define USE_MARK_BYTES
1397 /* Minimize compare-and-swap usage. */
1400 # define STACK_GROWS_UP
1402 # define OS_TYPE "HPUX"
1403 extern int __data_start
[];
1404 # define DATASTART ((ptr_t)(__data_start))
1406 /* The following appears to work for 7xx systems running HP/UX */
1407 /* 9.xx Furthermore, it might result in much faster */
1408 /* collections than HEURISTIC2, which may involve scanning */
1409 /* segments that directly precede the stack. It is not the */
1410 /* default, since it may not work on older machine/OS */
1411 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1413 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1415 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1416 /* to this. Note that the GC must be initialized before the */
1417 /* first putenv call. */
1418 extern char ** environ
;
1419 # define STACKBOTTOM ((ptr_t)environ)
1421 # define DYNAMIC_LOADING
1422 # include <unistd.h>
1423 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1425 # define PREFETCH(x) { \
1426 register long addr = (long)(x); \
1427 (void) _asm ("LDW", 0, 0, addr, 0); \
1432 # define OS_TYPE "LINUX"
1433 # define LINUX_STACKBOTTOM
1434 # define DYNAMIC_LOADING
1435 # define SEARCH_FOR_DATA_START
1437 # define DATAEND (&_end)
1442 # define MACH_TYPE "ALPHA"
1443 # define ALIGNMENT 8
1444 # define CPP_WORDSZ 64
1446 # define USE_GENERIC_PUSH_REGS
1447 /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1448 /* fp registers in some cases when the target is a 21264. The assembly */
1449 /* code doesn't handle that yet, and version dependencies make that a */
1450 /* bit tricky. Do the easy thing for now. */
1453 # define OS_TYPE "NETBSD"
1455 # define DATASTART GC_data_start
1456 # define ELFCLASS32 32
1457 # define ELFCLASS64 64
1458 # define ELF_CLASS ELFCLASS64
1459 # define DYNAMIC_LOADING
1462 # define OS_TYPE "OPENBSD"
1464 # ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1465 # define DATASTART GC_data_start
1466 # define ELFCLASS32 32
1467 # define ELFCLASS64 64
1468 # define ELF_CLASS ELFCLASS64
1469 # else /* ECOFF, until OpenBSD/Alpha 2.7 */
1470 # define DATASTART ((ptr_t) 0x140000000)
1474 # define OS_TYPE "FREEBSD"
1475 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1476 # define SIG_SUSPEND SIGUSR1
1477 # define SIG_THR_RESTART SIGUSR2
1478 # define FREEBSD_STACKBOTTOM
1480 # define DYNAMIC_LOADING
1482 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1483 extern char etext
[];
1484 extern char edata
[];
1486 # define NEED_FIND_LIMIT
1487 # define DATASTART ((ptr_t)(&etext))
1488 # define DATAEND (GC_find_limit (DATASTART, TRUE))
1489 # define DATASTART2 ((ptr_t)(&edata))
1490 # define DATAEND2 ((ptr_t)(&end))
1493 # define OS_TYPE "OSF1"
1494 # define DATASTART ((ptr_t) 0x140000000)
1496 # define DATAEND ((ptr_t) &_end)
1497 extern char ** environ
;
1498 /* round up from the value of environ to the nearest page boundary */
1499 /* Probably breaks if putenv is called before collector */
1500 /* initialization. */
1501 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1502 /* # define HEURISTIC2 */
1503 /* Normally HEURISTIC2 is too conervative, since */
1504 /* the text segment immediately follows the stack. */
1505 /* Hence we give an upper pound. */
1506 /* This is currently unused, since we disabled HEURISTIC2 */
1507 extern int __start
[];
1508 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1509 # ifndef GC_OSF1_THREADS
1510 /* Unresolved signal issues with threads. */
1511 # define MPROTECT_VDB
1513 # define DYNAMIC_LOADING
1516 # define OS_TYPE "LINUX"
1517 # define STACKBOTTOM ((ptr_t) 0x120000000)
1519 # define SEARCH_FOR_DATA_START
1520 # define DYNAMIC_LOADING
1522 # define DATASTART ((ptr_t) 0x140000000)
1525 # define DATAEND (_end)
1526 # define MPROTECT_VDB
1527 /* Has only been superficially tested. May not */
1528 /* work on all versions. */
1533 # define MACH_TYPE "IA64"
1534 # define USE_GENERIC_PUSH_REGS
1535 /* We need to get preserved registers in addition to register */
1536 /* windows. That's easiest to do with setjmp. */
1537 # ifdef PARALLEL_MARK
1538 # define USE_MARK_BYTES
1539 /* Compare-and-exchange is too expensive to use for */
1540 /* setting mark bits. */
1544 # define CPP_WORDSZ 32
1545 # define ALIGN_DOUBLE
1546 /* Requires 8 byte alignment for malloc */
1547 # define ALIGNMENT 4
1552 # define CPP_WORDSZ 64
1553 # define ALIGN_DOUBLE
1554 /* Requires 16 byte alignment for malloc */
1555 # define ALIGNMENT 8
1557 # define OS_TYPE "HPUX"
1558 extern int __data_start
[];
1559 # define DATASTART ((ptr_t)(__data_start))
1560 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1561 /* to this. Note that the GC must be initialized before the */
1562 /* first putenv call. */
1563 extern char ** environ
;
1564 # define STACKBOTTOM ((ptr_t)environ)
1565 # define DYNAMIC_LOADING
1566 # include <unistd.h>
1567 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1568 /* The following was empirically determined, and is probably */
1569 /* not very robust. */
1570 /* Note that the backing store base seems to be at a nice */
1571 /* address minus one page. */
1572 # define BACKING_STORE_DISPLACEMENT 0x1000000
1573 # define BACKING_STORE_ALIGNMENT 0x1000
1574 # define BACKING_STORE_BASE \
1575 (ptr_t)(((word)GC_stackbottom - BACKING_STORE_DISPLACEMENT - 1) \
1576 & ~(BACKING_STORE_ALIGNMENT - 1))
1579 # define CPP_WORDSZ 64
1580 # define ALIGN_DOUBLE
1581 /* Requires 16 byte alignment for malloc */
1582 # define ALIGNMENT 8
1583 # define OS_TYPE "LINUX"
1584 /* The following works on NUE and older kernels: */
1585 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1586 /* This does not work on NUE: */
1587 # define LINUX_STACKBOTTOM
1588 /* We also need the base address of the register stack */
1589 /* backing store. This is computed in */
1590 /* GC_linux_register_stack_base based on the following */
1592 # define BACKING_STORE_ALIGNMENT 0x100000
1593 # define BACKING_STORE_DISPLACEMENT 0x80000000
1594 extern char * GC_register_stackbottom
;
1595 # define BACKING_STORE_BASE ((ptr_t)GC_register_stackbottom)
1596 # define SEARCH_FOR_DATA_START
1598 # define DYNAMIC_LOADING
1600 /* In the Intel compiler environment, we seem to end up with */
1601 /* statically linked executables and an undefined reference */
1604 # define MPROTECT_VDB
1605 /* Requires Linux 2.3.47 or later. */
1607 # define DATAEND (_end)
1609 # define PREFETCH(x) \
1610 __asm__ (" lfetch [%0]": : "r"((void *)(x)))
1611 # define PREFETCH_FOR_WRITE(x) \
1612 __asm__ (" lfetch.excl [%0]": : "r"((void *)(x)))
1613 # define CLEAR_DOUBLE(x) \
1614 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1620 # define MACH_TYPE "M88K"
1621 # define ALIGNMENT 4
1622 # define ALIGN_DOUBLE
1625 # define OS_TYPE "CX_UX"
1626 # define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1629 # define OS_TYPE "DGUX"
1630 extern ptr_t
GC_SysVGetDataStart();
1631 # define DATASTART GC_SysVGetDataStart(0x10000, etext)
1633 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1637 /* If this still works, and if anyone cares, this should probably */
1638 /* be moved to the S390 category. */
1639 # define MACH_TYPE "S370"
1640 # define ALIGNMENT 4 /* Required by hardware */
1641 # define USE_GENERIC_PUSH_REGS
1643 # define OS_TYPE "UTS4"
1645 extern int _etext
[];
1647 extern ptr_t
GC_SysVGetDataStart();
1648 # define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1649 # define DATAEND (_end)
1655 # define MACH_TYPE "S390"
1656 # define USE_GENERIC_PUSH_REGS
1658 # define ALIGNMENT 4
1659 # define CPP_WORDSZ 32
1661 # define ALIGNMENT 8
1662 # define CPP_WORDSZ 64
1663 # define HBLKSIZE 4096
1666 # define OS_TYPE "LINUX"
1667 # define LINUX_STACKBOTTOM
1668 # define DYNAMIC_LOADING
1669 extern int __data_start
[];
1670 # define DATASTART ((ptr_t)(__data_start))
1672 # define DATAEND (_end)
1673 # define CACHE_LINE_SIZE 256
1674 # define GETPAGESIZE() 4096
1679 # define ALIGNMENT 4
1680 extern int _etext
[];
1681 # define DATASTART ((ptr_t)(_etext))
1686 # define CPP_WORDSZ 32
1687 # define MACH_TYPE "ARM32"
1688 # define ALIGNMENT 4
1690 # define OS_TYPE "NETBSD"
1693 # define DATASTART GC_data_start
1694 # define DYNAMIC_LOADING
1696 extern char etext
[];
1697 # define DATASTART ((ptr_t)(etext))
1699 # define USE_GENERIC_PUSH_REGS
1702 # define OS_TYPE "LINUX"
1705 # define STACK_GRAN 0x10000000
1706 # define USE_GENERIC_PUSH_REGS
1708 # define DYNAMIC_LOADING
1709 # include <features.h>
1710 # if defined(__GLIBC__) && __GLIBC__ >= 2
1711 # define SEARCH_FOR_DATA_START
1713 extern char **__environ
;
1714 # define DATASTART ((ptr_t)(&__environ))
1715 /* hideous kludge: __environ is the first */
1716 /* word in crt0.o, and delimits the start */
1717 /* of the data segment, no matter which */
1718 /* ld options were passed through. */
1719 /* We could use _etext instead, but that */
1720 /* would include .rodata, which may */
1721 /* contain large read-only data tables */
1722 /* that we'd rather not scan. */
1725 # define DATAEND (_end)
1728 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1732 # define OS_TYPE "MSWINCE"
1733 # define DATAEND /* not needed */
1736 /* __data_start is usually defined in the target linker script. */
1737 extern int __data_start
[];
1738 # define DATASTART (ptr_t)(__data_start)
1739 # define USE_GENERIC_PUSH_REGS
1740 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1741 extern void *__stack_base__
;
1742 # define STACKBOTTOM ((ptr_t) (__stack_base__))
1747 # define MACH_TYPE "SH"
1748 # define ALIGNMENT 4
1750 # define OS_TYPE "MSWINCE"
1751 # define DATAEND /* not needed */
1754 # define OS_TYPE "LINUX"
1755 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1756 # define USE_GENERIC_PUSH_REGS
1757 # define DYNAMIC_LOADING
1758 # define SEARCH_FOR_DATA_START
1760 # define DATAEND (_end)
1765 # define MACH_TYPE "SH4"
1766 # define OS_TYPE "MSWINCE"
1767 # define ALIGNMENT 4
1768 # define DATAEND /* not needed */
1772 # define MACH_TYPE "X86_64"
1773 # define ALIGNMENT 8
1774 # define CPP_WORDSZ 64
1776 # define HBLKSIZE 4096
1778 # define CACHE_LINE_SIZE 64
1779 # define USE_GENERIC_PUSH_REGS
1781 # define OS_TYPE "LINUX"
1782 # define LINUX_STACKBOTTOM
1783 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1784 # define MPROTECT_VDB
1786 /* We seem to get random errors in incremental mode, */
1787 /* possibly because Linux threads is itself a malloc client */
1788 /* and can't deal with the signals. */
1791 # define DYNAMIC_LOADING
1792 # ifdef UNDEFINED /* includes ro data */
1793 extern int _etext
[];
1794 # define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1796 # include <features.h>
1797 # define SEARCH_FOR_DATA_START
1799 # define DATAEND (_end)
1802 # define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1804 # if defined(__GNUC__) && __GNUC__ >= 3
1805 # define PREFETCH(x) __builtin_prefetch ((x), 0, 0)
1806 # define PREFETCH_FOR_WRITE(x) __builtin_prefetch ((x), 1)
1811 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1812 /* Rld appears to allocate some memory with its own allocator, and */
1813 /* some through malloc, which might be redirected. To make this */
1814 /* work with collectable memory, we have to scan memory allocated */
1815 /* by rld's internal malloc. */
1816 # define USE_PROC_FOR_LIBRARIES
1819 # ifndef STACK_GROWS_UP
1820 # define STACK_GROWS_DOWN
1824 # define CPP_WORDSZ 32
1833 # define DATAEND (end)
1836 # if defined(SVR4) && !defined(GETPAGESIZE)
1837 # include <unistd.h>
1838 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1841 # ifndef GETPAGESIZE
1842 # if defined(SUNOS5) || defined(IRIX5)
1843 # include <unistd.h>
1845 # define GETPAGESIZE() getpagesize()
1848 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1849 /* OS has SVR4 generic features. Probably others also qualify. */
1853 # if defined(SUNOS5) || defined(DRSNX)
1854 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1857 /* OS has SUNOS5 style signal handlers. */
1865 # if defined(SVR4) || defined(LINUX) || defined(IRIX) || defined(HPUX) \
1866 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1867 || defined(DGUX) || defined(BSD) \
1868 || defined(_AIX) || defined(DARWIN) || defined(OSF1)
1869 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1872 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1877 # undef DYNAMIC_LOADING
1882 # undef MPROTECT_VDB
1887 /* Postponed for now. */
1889 # undef MPROTECT_VDB
1892 # ifdef SMALL_CONFIG
1893 /* Presumably not worth the space it takes. */
1895 # undef MPROTECT_VDB
1899 # undef MPROTECT_VDB /* Can't deal with address space holes. */
1902 # ifdef PARALLEL_MARK
1903 # undef MPROTECT_VDB /* For now. */
1906 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
1907 # define DEFAULT_VDB
1911 # define PREFETCH(x)
1912 # define NO_PREFETCH
1915 # ifndef PREFETCH_FOR_WRITE
1916 # define PREFETCH_FOR_WRITE(x)
1917 # define NO_PREFETCH_FOR_WRITE
1920 # ifndef CACHE_LINE_SIZE
1921 # define CACHE_LINE_SIZE 32 /* Wild guess */
1925 # define REGISTER_LIBRARIES_EARLY
1926 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
1927 /* lock. This isn't safe after the world has stopped. So we must */
1928 /* call GC_register_dynamic_libraries before stopping the world. */
1929 /* For performance reasons, this may be beneficial on other */
1930 /* platforms as well, though it should be avoided in win32. */
1933 # if defined(SEARCH_FOR_DATA_START)
1934 extern ptr_t GC_data_start
;
1935 # define DATASTART GC_data_start
1938 # ifndef CLEAR_DOUBLE
1939 # define CLEAR_DOUBLE(x) \
1940 ((word*)x)[0] = 0; \
1942 # endif /* CLEAR_DOUBLE */
1944 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
1945 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
1946 # define GC_SOLARIS_THREADS
1949 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
1950 --> inconsistent configuration
1952 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
1953 --> inconsistent configuration
1955 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
1956 --> inconsistent configuration
1958 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
1959 --> inconsistent configuration
1961 # if defined(GC_AIX_THREADS) && !defined(_AIX)
1962 --> inconsistent configuration
1964 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
1965 --> inconsistent configuration
1968 # if defined(PCR) || defined(SRC_M3) || \
1969 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
1970 defined(GC_PTHREADS)
1974 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(DARWIN) \
1975 || defined(LINT) || defined(MSWINCE) || defined(ARM32) \
1976 || (defined(I386) && defined(__LCC__))
1977 /* Use setjmp based hack to mark from callee-save registers. */
1978 /* The define should move to the individual platform */
1980 # define USE_GENERIC_PUSH_REGS
1984 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
1985 /* include assembly code to do it well. */
1988 /* Can we save call chain in objects for debugging? */
1989 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
1990 /* frame) to reasonable values for the platform. */
1991 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
1992 /* at build time, though we feel free to adjust it slightly. */
1993 /* Define NEED_CALLINFO if we either save the call stack or */
1994 /* GC_ADD_CALLER is defined. */
1995 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
1998 # define CAN_SAVE_CALL_ARGS
2000 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2001 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2002 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2003 # define CAN_SAVE_CALL_ARGS
2006 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2007 && defined(GC_CAN_SAVE_CALL_STACKS)
2008 # define SAVE_CALL_CHAIN
2010 # ifdef SAVE_CALL_CHAIN
2011 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2012 # define NARGS SAVE_CALL_NARGS
2014 # define NARGS 0 /* Number of arguments to save for each call. */
2017 # ifdef SAVE_CALL_CHAIN
2018 # ifndef SAVE_CALL_COUNT
2019 # define NFRAMES 6 /* Number of frames to save. Even for */
2020 /* alignment reasons. */
2022 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2024 # define NEED_CALLINFO
2025 # endif /* SAVE_CALL_CHAIN */
2026 # ifdef GC_ADD_CALLER
2029 # define NEED_CALLINFO
2032 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2033 # define DBG_HDRS_ALL
2036 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2037 # define POINTER_SHIFT 0
2040 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2041 # define POINTER_MASK ((GC_word)(-1))
2044 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2045 # define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2048 # if defined(FIXUP_POINTER)
2049 # define NEED_FIXUP_POINTER 1
2051 # define NEED_FIXUP_POINTER 0
2052 # define FIXUP_POINTER(p)
2056 /* This relies on some type definitions from gc_priv.h, from */
2057 /* where it's normally included. */
2059 /* How to get heap memory from the OS: */
2060 /* Note that sbrk()-like allocation is preferred, since it */
2061 /* usually makes it possible to merge consecutively allocated */
2062 /* chunks. It also avoids unintented recursion with */
2063 /* -DREDIRECT_MALLOC. */
2064 /* GET_MEM() returns a HLKSIZE aligned chunk. */
2065 /* 0 is taken to mean failure. */
2066 /* In the case os USE_MMAP, the argument must also be a */
2067 /* physical page size. */
2068 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2069 /* though we should perhaps take advantage of the case in which */
2071 struct hblk
; /* See gc_priv.h. */
2073 char * real_malloc();
2074 # define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2078 void * os2_alloc(size_t bytes
);
2079 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2083 # if defined(NEXT) || defined(DOS4GW) || \
2084 (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2085 (defined(SUNOS5) && !defined(USE_MMAP))
2086 # define GET_MEM(bytes) HBLKPTR((size_t) \
2087 calloc(1, (size_t)bytes + GC_page_size) \
2091 extern ptr_t
GC_win32_get_mem();
2092 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2095 # if defined(USE_TEMPORARY_MEMORY)
2096 extern Ptr
GC_MacTemporaryNewPtr(size_t size
,
2097 Boolean clearMemory
);
2098 # define GET_MEM(bytes) HBLKPTR( \
2099 GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2102 # define GET_MEM(bytes) HBLKPTR( \
2103 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2107 extern ptr_t
GC_wince_get_mem();
2108 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2110 # if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2111 extern void *GC_amiga_get_mem(size_t size
);
2112 # define GET_MEM(bytes) HBLKPTR((size_t) \
2113 GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2116 extern ptr_t
GC_unix_get_mem();
2117 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2126 #endif /* GC_PRIVATE_H */
2128 # endif /* GCCONFIG_H */