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.
21 /* Machine dependent parameters. Some tuning parameters can be found */
22 /* near the top of gc_private.h. */
24 /* Machine specific parts contributed by various people. See README file. */
26 /* First a unified test for Linux: */
27 # if defined(linux) || defined(__linux__)
31 /* And one for NetBSD: */
32 # if defined(__NetBSD__)
36 /* Determine the machine type: */
37 # if defined(sun) && defined(mc68000)
40 # define mach_type_known
42 # if defined(hp9000s300)
45 # define mach_type_known
47 # if defined(__OpenBSD__) && defined(m68k)
50 # define mach_type_known
52 # if defined(__OpenBSD__) && defined(__sparc__)
55 # define mach_type_known
57 # if defined(__NetBSD__) && defined(m68k)
59 # define mach_type_known
61 # if defined(__NetBSD__) && defined(__powerpc__)
63 # define mach_type_known
65 # if defined(__NetBSD__) && defined(__arm32__)
67 # define mach_type_known
76 # define mach_type_known
78 # if defined(mips) || defined(__mips)
81 # if defined(ultrix) || defined(__ultrix) || defined(__NetBSD__)
84 # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
85 || defined(__SYSTYPE_SVR4__)
86 # define IRIX5 /* or IRIX 6.X */
88 # define RISCOS /* or IRIX 4.X */
92 # if defined(__NetBSD__) && defined(__MIPSEL__)
95 # define mach_type_known
97 # if defined(sequent) && (defined(i386) || defined(__i386__))
100 # define mach_type_known
102 # if defined(sun) && (defined(i386) || defined(__i386__))
105 # define mach_type_known
107 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
110 # define mach_type_known
114 # define mach_type_known
116 # if defined(sun) && (defined(sparc) || defined(__sparc))
118 /* Test for SunOS 5.x */
125 # define mach_type_known
127 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
128 && !defined(__OpenBSD__) && !(__NetBSD__)
131 # define mach_type_known
135 # define mach_type_known
137 # if defined(__NetBSD__) && defined(__sparc__)
139 # define mach_type_known
141 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
142 /* The above test may need refinement */
144 # if defined(_SCO_ELF)
149 # define mach_type_known
151 # if defined(_AUX_SOURCE)
154 # define mach_type_known
156 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
157 || defined(hppa) || defined(__hppa__)
162 # define mach_type_known
164 # if defined(__BEOS__) && defined(_X86_)
167 # define mach_type_known
169 # if defined(LINUX) && (defined(i386) || defined(__i386__))
171 # define mach_type_known
173 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
175 # define mach_type_known
177 # if defined(LINUX) && defined(powerpc)
179 # define mach_type_known
181 # if defined(LINUX) && defined(__mc68000__)
183 # define mach_type_known
185 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
187 # define mach_type_known
189 # if defined(LINUX) && defined(__arm__)
191 # define mach_type_known
193 # if defined(LINUX) && defined(__sh__)
195 # define mach_type_known
197 # if defined(__alpha) || defined(__alpha__)
199 # if !defined(LINUX) && !defined(NETBSD)
200 # define OSF1 /* a.k.a Digital Unix */
202 # define mach_type_known
204 # if defined(_AMIGA) && !defined(AMIGA)
209 # define mach_type_known
211 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
214 # define mach_type_known
216 # if defined(__MWERKS__) && defined(__powerc)
219 # define mach_type_known
221 # if defined(macosx) || \
222 defined(__APPLE__) && defined(__MACH__) && defined(__ppc__)
225 # define mach_type_known
227 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
230 --> Not really supported, but at least we recognize it.
232 # if defined(NeXT) && defined(mc68000)
235 # define mach_type_known
237 # if defined(NeXT) && (defined(i386) || defined(__i386__))
240 # define mach_type_known
242 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
245 # define mach_type_known
247 # if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
250 # define mach_type_known
252 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
254 # define mach_type_known
256 # if defined(bsdi) && (defined(i386) || defined(__i386__))
259 # define mach_type_known
261 # if !defined(mach_type_known) && defined(__386BSD__)
264 # define mach_type_known
266 # if defined(_CX_UX) && defined(_M88K)
269 # define mach_type_known
274 # define mach_type_known
276 # if defined(_WIN32_WCE)
277 /* SH3, SH4, MIPS already defined for corresponding architectures */
278 # if defined(SH3) || defined(SH4)
288 # define mach_type_known
290 # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
291 || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
293 # define MSWIN32 /* or Win32s */
294 # define mach_type_known
297 # if defined(__DJGPP__)
300 # define DJGPP /* MSDOS running the DJGPP port of GCC */
302 # define mach_type_known
304 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
307 # define mach_type_known
309 # if defined(__MINGW32__)
312 # define mach_type_known
314 # if defined(__BORLANDC__)
317 # define mach_type_known
319 # if defined(_UTS) && !defined(mach_type_known)
322 # define mach_type_known
326 # define mach_type_known
328 # if defined(__embedded__) && defined(PPC)
331 # define mach_type_known
334 # if defined(__WATCOMC__) && defined(__386__)
336 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
337 # if defined(__OS2__)
340 # if defined(__WINDOWS_386__) || defined(__NT__)
347 # define mach_type_known
349 # if defined(__s390__) && defined(LINUX)
351 # define mach_type_known
354 /* Feel free to add more clauses here */
356 /* Or manually define the machine type here. A machine type is */
357 /* characterized by the architecture. Some */
358 /* machine types are further subdivided by OS. */
359 /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
360 /* Note that SGI IRIX is treated identically to RISCOS. */
361 /* SYSV on an M68K actually means A/UX. */
362 /* The distinction in these cases is usually the stack starting address */
363 # ifndef mach_type_known
364 --> unknown machine type
366 /* Mapping is: M68K ==> Motorola 680X0 */
367 /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
368 /* MACOS and AMIGA variants) */
369 /* I386 ==> Intel 386 */
370 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
371 /* FREEBSD, THREE86BSD, MSWIN32, */
372 /* BSDI,SUNOS5, NEXT, other variants) */
373 /* NS32K ==> Encore Multimax */
374 /* MIPS ==> R2000 or R3000 */
375 /* (RISCOS, ULTRIX variants) */
376 /* VAX ==> DEC VAX */
377 /* (BSD, ULTRIX variants) */
378 /* RS6000 ==> IBM RS/6000 AIX3.X */
379 /* RT ==> IBM PC/RT */
380 /* HP_PA ==> HP9000/700 & /800 */
382 /* SPARC ==> SPARC v7/v8/v9 */
383 /* (SUNOS4, SUNOS5, LINUX, */
384 /* DRSNX variants) */
385 /* ALPHA ==> DEC Alpha */
386 /* (OSF1 and LINUX variants) */
387 /* M88K ==> Motorola 88XX0 */
388 /* (CX_UX and DGUX) */
389 /* S370 ==> 370-like machine */
390 /* running Amdahl UTS4 */
391 /* or a 390 running LINUX */
392 /* ARM32 ==> Intel StrongARM */
393 /* IA64 ==> Intel IA64 */
395 /* SH ==> Hitachi SuperH */
396 /* (LINUX & MSWINCE) */
400 * For each architecture and OS, the following need to be defined:
402 * CPP_WORD_SZ is a simple integer constant representing the word size.
403 * in bits. We assume byte addressibility, where a byte has 8 bits.
404 * We also assume CPP_WORD_SZ is either 32 or 64.
405 * (We care about the length of pointers, not hardware
406 * bus widths. Thus a 64 bit processor with a C compiler that uses
407 * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
409 * MACH_TYPE is a string representation of the machine type.
410 * OS_TYPE is analogous for the OS.
412 * ALIGNMENT is the largest N, such that
413 * all pointer are guaranteed to be aligned on N byte boundaries.
414 * defining it to be 1 will always work, but perform poorly.
416 * DATASTART is the beginning of the data segment.
417 * On UNIX systems, the collector will scan the area between DATASTART
418 * and DATAEND for root pointers.
420 * DATAEND, if not &end.
422 * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
425 * STACKBOTTOM is the cool end of the stack, which is usually the
426 * highest address in the stack.
427 * Under PCR or OS/2, we have other ways of finding thread stacks.
428 * For each machine, the following should:
429 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
430 * 2) define exactly one of
431 * STACKBOTTOM (should be defined to be an expression)
434 * If either of the last two macros are defined, then STACKBOTTOM is computed
435 * during collector startup using one of the following two heuristics:
436 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
437 * the next multiple of STACK_GRAN.
438 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
439 * in small steps (decrement if STACK_GROWS_UP), and read the value
440 * at each location. Remember the value when the first
441 * Segmentation violation or Bus error is signalled. Round that
442 * to the nearest plausible page boundary, and use that instead
445 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
446 * the value of environ is a pointer that can serve as STACKBOTTOM.
447 * I expect that HEURISTIC2 can be replaced by this approach, which
448 * interferes far less with debugging. However it has the disadvantage
449 * that it's confused by a putenv call before the collector is initialized.
450 * This could be dealt with by intercepting putenv ...
452 * If no expression for STACKBOTTOM can be found, and neither of the above
453 * heuristics are usable, the collector can still be used with all of the above
454 * undefined, provided one of the following is done:
455 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
456 * without reference to STACKBOTTOM. This is appropriate for use in
457 * conjunction with thread packages, since there will be multiple stacks.
458 * (Allocating thread stacks in the heap, and treating them as ordinary
459 * heap data objects is also possible as a last resort. However, this is
460 * likely to introduce significant amounts of excess storage retention
461 * unless the dead parts of the thread stacks are periodically cleared.)
462 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
463 * If the author of the client code controls the main program, this is
464 * easily accomplished by introducing a new main program, setting
465 * GC_stackbottom to the address of a local variable, and then calling
466 * the original main program. The new main program would read something
469 * # include "gc_private.h"
471 * main(argc, argv, envp)
473 * char **argv, **envp;
477 * GC_stackbottom = (ptr_t)(&dummy);
478 * return(real_main(argc, argv, envp));
482 * Each architecture may also define the style of virtual dirty bit
483 * implementation to be used:
484 * MPROTECT_VDB: Write protect the heap and catch faults.
485 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
487 * An architecture may define DYNAMIC_LOADING if dynamic_load.c
488 * defined GC_register_dynamic_libraries() for the architecture.
490 * An architecture may define PREFETCH(x) to preload the cache with *x.
491 * This defaults to a no-op.
493 * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
495 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
496 * clear the two words at GC_malloc-aligned address x. By default,
497 * word stores of 0 are used instead.
501 # define STACK_GRAN 0x1000000
503 # define MACH_TYPE "M68K"
506 # define OS_TYPE "OPENBSD"
509 # define DATASTART ((ptr_t)(&etext))
512 # define OS_TYPE "NETBSD"
515 # define DATASTART ((ptr_t)(&etext))
518 # define OS_TYPE "LINUX"
519 # define STACKBOTTOM ((ptr_t)0xf0000000)
520 # define MPROTECT_VDB
522 # define DYNAMIC_LOADING
523 # include <features.h>
524 # if defined(__GLIBC__)&& __GLIBC__>=2
525 # define LINUX_DATA_START
527 extern char **__environ;
528 # define DATASTART ((ptr_t)(&__environ))
529 /* hideous kludge: __environ is the first */
530 /* word in crt0.o, and delimits the start */
531 /* of the data segment, no matter which */
532 /* ld options were passed through. */
533 /* We could use _etext instead, but that */
534 /* would include .rodata, which may */
535 /* contain large read-only data tables */
536 /* that we'd rather not scan. */
537 # endif /* !GLIBC2 */
539 # define DATAEND (&_end)
542 # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
546 # define OS_TYPE "SUNOS4"
548 # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ffff) & ~0x1ffff))
549 # define HEURISTIC1 /* differs */
550 # define DYNAMIC_LOADING
553 # define OS_TYPE "HP"
555 # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
556 # define STACKBOTTOM ((ptr_t) 0xffeffffc)
557 /* empirically determined. seems to work. */
559 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
562 # define OS_TYPE "SYSV"
564 # define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \
566 +((word)&etext & 0x1fff))
567 /* This only works for shared-text binaries with magic number 0413.
568 The other sorts of SysV binaries put the data at the end of the text,
569 in which case the default of &etext would work. Unfortunately,
570 handling both would require having the magic-number available.
573 # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
574 /* The stack starts at the top of memory, but */
575 /* 0x0 cannot be used as setjump_test complains */
576 /* that the stack direction is incorrect. Two */
577 /* bytes down from 0x0 should be safe enough. */
579 # include <sys/mmu.h>
580 # define GETPAGESIZE() PAGESIZE /* Is this still right? */
583 # define OS_TYPE "AMIGA"
584 /* STACKBOTTOM and DATASTART handled specially */
586 # define DATAEND /* not needed */
587 # define GETPAGESIZE() 4096
593 # define OS_TYPE "MACOS"
594 /* see os_dep.c for details of global data segments. */
595 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
596 # define DATAEND /* not needed */
597 # define GETPAGESIZE() 4096
600 # define OS_TYPE "NEXT"
601 # define DATASTART ((ptr_t) get_etext())
602 # define STACKBOTTOM ((ptr_t) 0x4000000)
603 # define DATAEND /* not needed */
608 # define MACH_TYPE "POWERPC"
610 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
614 # define OS_TYPE "MACOS"
615 /* see os_dep.c for details of global data segments. */
616 # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
617 # define DATAEND /* not needed */
620 # define ALIGNMENT 4 /* Guess. Can someone verify? */
621 /* This was 2, but that didn't sound right. */
622 # define OS_TYPE "LINUX"
624 # define DYNAMIC_LOADING
626 # define STACK_GRAN 0x10000000
627 /* Stack usually starts at 0x80000000 */
628 # define LINUX_DATA_START
630 # define DATAEND (&_end)
633 /* There are reasons to suspect this may not be reliable. */
635 # define OS_TYPE "MACOSX"
636 # define DATASTART ((ptr_t) get_etext())
637 # define STACKBOTTOM ((ptr_t) 0xc0000000)
638 # define DATAEND /* not needed */
639 # define MPROTECT_VDB
641 # define GETPAGESIZE() getpagesize()
645 # define OS_TYPE "NETBSD"
648 # define DATASTART GC_data_start
649 # define DYNAMIC_LOADING
653 # define OS_TYPE "NOSYS"
654 extern void __end, __dso_handle;
655 # define DATASTART (&__dso_handle) /* OK, that's ugly. */
656 # define DATAEND (&__end)
657 /* Stack starts at 0xE0000000 for the simulator. */
659 # define STACK_GRAN 0x10000000
665 # define MACH_TYPE "VAX"
666 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
668 # define DATASTART ((ptr_t)(&etext))
670 # define OS_TYPE "BSD"
672 /* HEURISTIC2 may be OK, but it's hard to test. */
675 # define OS_TYPE "ULTRIX"
676 # define STACKBOTTOM ((ptr_t) 0x7fffc800)
681 # define MACH_TYPE "RT"
683 # define DATASTART ((ptr_t) 0x10000000)
684 # define STACKBOTTOM ((ptr_t) 0x1fffd800)
688 # define MACH_TYPE "SPARC"
689 # if defined(__arch64__) || defined(__sparcv9)
692 # define ALIGNMENT 4 /* Required by hardware */
694 # define ALIGN_DOUBLE
696 # define OS_TYPE "SUNOS5"
699 extern char * GC_SysVGetDataStart();
700 # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
701 # define DATAEND (&_end)
706 # define HEAP_START (ptr_t)0x40000000
708 # define HEAP_START DATAEND
711 /* HEURISTIC1 reportedly no longer works under 2.7. */
712 /* HEURISTIC2 probably works, but this appears to be preferable. */
713 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
714 /* installations that's undefined. We work around this with a */
716 # include <sys/vmparam.h>
718 /* This should work everywhere, but doesn't. */
719 # define STACKBOTTOM USRSTACK
724 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
725 /* getpagesize() appeared to be missing from at least one */
726 /* Solaris 5.4 installation. Weird. */
727 # define DYNAMIC_LOADING
730 # define OS_TYPE "SUNOS4"
731 /* [If you have a weak stomach, don't read this.] */
732 /* We would like to use: */
733 /* # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1fff) & ~0x1fff)) */
734 /* This fails occasionally, due to an ancient, but very */
735 /* persistent ld bug. &etext is set 32 bytes too high. */
736 /* We instead read the text segment size from the a.out */
737 /* header, which happens to be mapped into our address space */
738 /* at the start of the text segment. The detective work here */
739 /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
740 /* Serpette of INRIA. */
741 /* This assumes ZMAGIC, i.e. demand-loadable executables. */
742 # define TEXTSTART 0x2000
743 # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
744 # define MPROTECT_VDB
746 # define DYNAMIC_LOADING
749 # define CPP_WORDSZ 32
750 # define OS_TYPE "DRSNX"
751 extern char * GC_SysVGetDataStart();
753 # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext)
754 # define MPROTECT_VDB
755 # define STACKBOTTOM ((ptr_t) 0xdfff0000)
756 # define DYNAMIC_LOADING
759 # define OS_TYPE "LINUX"
761 # define DYNAMIC_LOADING
763 Linux Sparc/a.out not supported
767 # define DATAEND (&_end)
770 # define STACKBOTTOM ((ptr_t) 0x80000000000ULL)
771 # define DATASTART (ptr_t)GC_SysVGetDataStart(0x100000, &_etext)
772 # define CPP_WORDSZ 64
774 # define STACKBOTTOM ((ptr_t) 0xf0000000)
775 # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
779 # define OS_TYPE "OPENBSD"
780 # define STACKBOTTOM ((ptr_t) 0xf8000000)
782 # define DATASTART ((ptr_t)(&etext))
785 # define OS_TYPE "NETBSD"
788 # define DATASTART GC_data_start
789 # define DYNAMIC_LOADING
792 # define DATASTART ((ptr_t)(&etext))
798 # define MACH_TYPE "I386"
799 # define ALIGNMENT 4 /* Appears to hold for all "32 bit" compilers */
800 /* except Borland. The -a4 option fixes */
802 /* Ivan Demakov: For Watcom the option is -zp4. */
803 # ifndef SMALL_CONFIG
804 # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
805 /* improvement on Pentiums. */
808 # define OS_TYPE "SEQUENT"
810 # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
811 # define STACKBOTTOM ((ptr_t) 0x3ffff000)
814 # define OS_TYPE "BEOS"
816 # define GETPAGESIZE() B_PAGE_SIZE
818 # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
821 # define OS_TYPE "SUNOS5"
822 extern int etext, _start;
823 extern char * GC_SysVGetDataStart();
824 # define DATASTART GC_SysVGetDataStart(0x1000, &etext)
825 /* # define STACKBOTTOM ((ptr_t)(&_start)) worked through 2.7, */
826 /* but reportedly breaks under 2.8. It appears that the stack */
827 /* base is a property of the executable, so this should not break */
828 /* old executables. */
829 /* HEURISTIC2 probably works, but this appears to be preferable. */
830 # include <sys/vmparam.h>
831 # define STACKBOTTOM USRSTACK
832 /** At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
833 /*# define PROC_VDB*/
834 # define DYNAMIC_LOADING
839 # define HEAP_START (ptr_t)0x40000000
841 # define HEAP_START DATAEND
845 # define OS_TYPE "SCO"
847 # define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \
849 +((word)&etext & 0xfff))
850 # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
853 # define OS_TYPE "SCO_ELF"
855 # define DATASTART ((ptr_t)(&etext))
856 # define STACKBOTTOM ((ptr_t) 0x08048000)
857 # define DYNAMIC_LOADING
858 # define ELF_CLASS ELFCLASS32
861 # define OS_TYPE "LINUX"
862 # define LINUX_STACKBOTTOM
866 # define STACK_GRAN 0x10000000
867 /* STACKBOTTOM is usually 0xc0000000, but this changes with */
868 /* different kernel configurations. In particular, systems */
869 /* with 2GB physical memory will usually move the user */
870 /* address space limit, and hence initial SP to 0x80000000. */
872 # if !defined(LINUX_THREADS) || !defined(REDIRECT_MALLOC)
873 # define MPROTECT_VDB
875 /* We seem to get random errors in incremental mode, */
876 /* possibly because Linux threads is itself a malloc client */
877 /* and can't deal with the signals. */
880 # define DYNAMIC_LOADING
881 # ifdef UNDEFINED /* includes ro data */
883 # define DATASTART ((ptr_t)((((word) (&_etext)) + 0xfff) & ~0xfff))
885 # include <features.h>
886 # if defined(__GLIBC__) && __GLIBC__ >= 2
887 # define LINUX_DATA_START
889 extern char **__environ;
890 # define DATASTART ((ptr_t)(&__environ))
891 /* hideous kludge: __environ is the first */
892 /* word in crt0.o, and delimits the start */
893 /* of the data segment, no matter which */
894 /* ld options were passed through. */
895 /* We could use _etext instead, but that */
896 /* would include .rodata, which may */
897 /* contain large read-only data tables */
898 /* that we'd rather not scan. */
901 # define DATAEND (&_end)
904 # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
906 # ifdef USE_I686_PREFETCH
907 # define PREFETCH(x) \
908 __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
909 /* Empirically prefetcht0 is much more effective at reducing */
910 /* cache miss stalls for the targetted load instructions. But it */
911 /* seems to interfere enough with other cache traffic that the net */
912 /* result is worse than prefetchnta. */
914 /* Using prefetches for write seems to have a slight negative */
915 /* impact on performance, at least for a PIII/500. */
916 # define PREFETCH_FOR_WRITE(x) \
917 __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
920 # ifdef USE_3DNOW_PREFETCH
921 # define PREFETCH(x) \
922 __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
923 # define PREFETCH_FOR_WRITE(x) \
924 __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
928 # define OS_TYPE "CYGWIN32"
929 extern int _data_start__;
930 extern int _data_end__;
931 extern int _bss_start__;
932 extern int _bss_end__;
933 /* For binutils 2.9.1, we have */
934 /* DATASTART = _data_start__ */
935 /* DATAEND = _bss_end__ */
936 /* whereas for some earlier versions it was */
937 /* DATASTART = _bss_start__ */
938 /* DATAEND = _data_end__ */
939 /* To get it right for both, we take the */
940 /* minumum/maximum of the two. */
941 # define MAX(x,y) ((x) > (y) ? (x) : (y))
942 # define MIN(x,y) ((x) < (y) ? (x) : (y))
943 # define DATASTART ((ptr_t) MIN(&_data_start__, &_bss_start__))
944 # define DATAEND ((ptr_t) MAX(&_data_end__, &_bss_end__))
946 # define STACK_GRAN 0x10000
950 # define OS_TYPE "OS2"
951 /* STACKBOTTOM and DATASTART are handled specially in */
952 /* os_dep.c. OS2 actually has the right */
954 # define DATAEND /* not needed */
955 # define USE_GENERIC_PUSH_REGS
958 # define OS_TYPE "MSWIN32"
959 /* STACKBOTTOM and DATASTART are handled specially in */
962 # define MPROTECT_VDB
964 # define DATAEND /* not needed */
967 # define OS_TYPE "MSWINCE"
968 # define DATAEND /* not needed */
971 # define OS_TYPE "DJGPP"
972 # include "stubinfo.h"
975 extern int __djgpp_stack_limit;
976 # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ff) & ~0x1ff))
977 /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
979 # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
980 /* This may not be right. */
983 # define OS_TYPE "OPENBSD"
986 # define OS_TYPE "FREEBSD"
987 # define MPROTECT_VDB
988 # define FREEBSD_STACKBOTTOM
991 # define OS_TYPE "NETBSD"
994 # define OS_TYPE "THREE86BSD"
997 # define OS_TYPE "BSDI"
999 # if defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1000 || defined(THREE86BSD) || defined(BSDI)
1003 # define DATASTART ((ptr_t)(&etext))
1006 # define OS_TYPE "NEXT"
1007 # define DATASTART ((ptr_t) get_etext())
1008 # define STACKBOTTOM ((ptr_t)0xc0000000)
1009 # define DATAEND /* not needed */
1012 # define OS_TYPE "DOS4GW"
1013 extern long __nullarea;
1015 extern char *_STACKTOP;
1016 /* Depending on calling conventions Watcom C either precedes
1017 or does not precedes with undescore names of C-variables.
1018 Make sure startup code variables always have the same names. */
1019 #pragma aux __nullarea "*";
1020 #pragma aux _end "*";
1021 # define STACKBOTTOM ((ptr_t) _STACKTOP)
1022 /* confused? me too. */
1023 # define DATASTART ((ptr_t) &__nullarea)
1024 # define DATAEND ((ptr_t) &_end)
1029 # define MACH_TYPE "NS32K"
1030 # define ALIGNMENT 4
1031 extern char **environ;
1032 # define DATASTART ((ptr_t)(&environ))
1033 /* hideous kludge: environ is the first */
1034 /* word in crt0.o, and delimits the start */
1035 /* of the data segment, no matter which */
1036 /* ld options were passed through. */
1037 # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1041 # define MACH_TYPE "MIPS"
1042 /* # define STACKBOTTOM ((ptr_t)0x7fff8000) sometimes also works. */
1044 /* This was developed for a linuxce style platform. Probably */
1045 /* needs to be tweaked for workstation class machines. */
1046 # define OS_TYPE "LINUX"
1047 extern int __data_start;
1048 # define DATASTART ((ptr_t)(&__data_start))
1049 # define ALIGNMENT 4
1050 # define USE_GENERIC_PUSH_REGS 1
1051 # define STACKBOTTOM 0x80000000
1052 /* In many cases, this should probably use LINUX_STACKBOTTOM */
1053 /* instead. But some kernel versions seem to give the wrong */
1054 /* value from /proc. */
1058 # define DATASTART (ptr_t)0x10000000
1059 /* Could probably be slightly higher since */
1060 /* startup code allocates lots of stuff. */
1061 # define OS_TYPE "ULTRIX"
1062 # define ALIGNMENT 4
1066 # define DATASTART (ptr_t)0x10000000
1067 # define OS_TYPE "RISCOS"
1068 # define ALIGNMENT 4 /* Required by hardware */
1073 # define DATASTART ((ptr_t)(&_fdata))
1075 # define HEAP_START (ptr_t)0x30000000
1077 # define HEAP_START DATASTART
1079 /* Lowest plausible heap address. */
1080 /* In the MMAP case, we map there. */
1081 /* In either case it is used to identify */
1082 /* heap sections so they're not */
1083 /* considered as roots. */
1084 # define OS_TYPE "IRIX5"
1085 # define MPROTECT_VDB
1087 # define CPP_WORDSZ _MIPS_SZPTR
1088 # define ALIGNMENT (_MIPS_SZPTR/8)
1089 # if CPP_WORDSZ != 64
1090 # define ALIGN_DOUBLE
1093 # define ALIGNMENT 4
1094 # define ALIGN_DOUBLE
1096 # define DYNAMIC_LOADING
1099 # define OS_TYPE "MSWINCE"
1100 # define ALIGNMENT 4
1101 # define DATAEND /* not needed */
1103 # if defined(NETBSD)
1104 /* This also checked for __MIPSEL__ . Why? NETBSD recognition */
1105 /* should be handled at the top of the file. */
1106 # define ALIGNMENT 4
1107 # define OS_TYPE "NETBSD"
1109 # define USE_GENERIC_PUSH_REGS 1
1112 # define DATASTART GC_data_start
1113 # define NEED_FIND_LIMIT
1114 # define DYNAMIC_LOADING
1116 # define DATASTART ((ptr_t) 0x10000000)
1117 # define STACKBOTTOM ((ptr_t) 0x7ffff000)
1123 # define MACH_TYPE "RS6000"
1124 # define ALIGNMENT 4
1125 # define DATASTART ((ptr_t)0x20000000)
1127 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1128 # define DYNAMIC_LOADING
1129 /* For really old versions of AIX, this may have to be removed. */
1133 # define MACH_TYPE "HP_PA"
1134 # define OS_TYPE "HPUX"
1136 # define CPP_WORDSZ 64
1137 # define ALIGNMENT 8
1139 # define CPP_WORDSZ 32
1140 # define ALIGNMENT 4
1141 # define ALIGN_DOUBLE
1143 # if !defined(GC_HPUX_THREADS) && !defined(HPUX_THREADS) \
1144 && !defined(GC_LINUX_THREADS) && !defined(LINUX_THREADS)
1145 # ifndef LINUX /* For now. */
1146 # define MPROTECT_VDB
1149 # define GENERIC_COMPARE_AND_SWAP
1150 /* No compare-and-swap instruction. Use pthread mutexes */
1151 /* when we absolutely have to. */
1152 # ifdef PARALLEL_MARK
1153 # define USE_MARK_BYTES
1154 /* Minimize compare-and-swap usage. */
1157 # define STACK_GROWS_UP
1159 extern int __data_start;
1160 # define DATASTART ((ptr_t)(&__data_start))
1162 /* The following appears to work for 7xx systems running HP/UX */
1163 /* 9.xx Furthermore, it might result in much faster */
1164 /* collections than HEURISTIC2, which may involve scanning */
1165 /* segments that directly precede the stack. It is not the */
1166 /* default, since it may not work on older machine/OS */
1167 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1169 # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1171 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1172 /* to this. Note that the GC must be initialized before the */
1173 /* first putenv call. */
1174 extern char ** environ;
1175 # define STACKBOTTOM ((ptr_t)environ)
1177 # define DYNAMIC_LOADING
1178 # include <unistd.h>
1179 # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1181 # define PREFETCH(x) { \
1182 register long addr = (long)(x); \
1183 (void) _asm ("LDW", 0, 0, addr, 0); \
1188 # define OS_TYPE "LINUX"
1189 # define LINUX_STACKBOTTOM
1190 # define DYNAMIC_LOADING
1191 # define LINUX_DATA_START
1193 # define DATAEND (&_end)
1198 # define MACH_TYPE "ALPHA"
1199 # define ALIGNMENT 8
1201 # define OS_TYPE "NETBSD"
1203 # define DATASTART GC_data_start
1204 # define ELFCLASS32 32
1205 # define ELFCLASS64 64
1206 # define ELF_CLASS ELFCLASS64
1207 # define CPP_WORDSZ 64
1208 # define DYNAMIC_LOADING
1211 # define OS_TYPE "OSF1"
1212 # define DATASTART ((ptr_t) 0x140000000)
1214 # define DATAEND ((ptr_t) &_end)
1215 extern char ** environ;
1216 /* round up from the value of environ to the nearest page boundary */
1217 /* Probably breaks if putenv is called before collector */
1218 /* initialization. */
1219 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1220 /* # define HEURISTIC2 */
1221 /* Normally HEURISTIC2 is too conervative, since */
1222 /* the text segment immediately follows the stack. */
1223 /* Hence we give an upper pound. */
1224 /* This is currently unused, since we disabled HEURISTIC2 */
1226 # define HEURISTIC2_LIMIT ((ptr_t)((word)(&__start) & ~(getpagesize()-1)))
1227 # define CPP_WORDSZ 64
1228 # define MPROTECT_VDB
1229 # define DYNAMIC_LOADING
1232 # define OS_TYPE "LINUX"
1233 # define CPP_WORDSZ 64
1234 # define STACKBOTTOM ((ptr_t) 0x120000000)
1236 # define SEARCH_FOR_DATA_START
1237 # define DATASTART GC_data_start
1238 # define DYNAMIC_LOADING
1240 # define DATASTART ((ptr_t) 0x140000000)
1243 # define DATAEND (&_end)
1244 # define MPROTECT_VDB
1245 /* Has only been superficially tested. May not */
1246 /* work on all versions. */
1251 # define MACH_TYPE "IA64"
1252 # define ALIGN_DOUBLE
1253 /* Requires 16 byte alignment for malloc */
1254 # define ALIGNMENT 8
1255 # define USE_GENERIC_PUSH_REGS
1256 /* We need to get preserved registers in addition to register */
1257 /* windows. That's easiest to do with setjmp. */
1258 # ifdef PARALLEL_MARK
1259 # define USE_MARK_BYTES
1260 /* Compare-and-exchange is too expensive to use for */
1261 /* setting mark bits. */
1267 # define OS_TYPE "LINUX"
1268 # define CPP_WORDSZ 64
1269 /* The following works on NUE and older kernels: */
1270 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1271 /* This does not work on NUE: */
1272 # define LINUX_STACKBOTTOM
1273 /* We also need the base address of the register stack */
1274 /* backing store. This is computed in */
1275 /* GC_linux_register_stack_base based on the following */
1277 # define BACKING_STORE_ALIGNMENT 0x100000
1278 # define BACKING_STORE_DISPLACEMENT 0x80000000
1279 extern char * GC_register_stackbottom;
1280 # define BACKING_STORE_BASE ((ptr_t)GC_register_stackbottom)
1281 # define SEARCH_FOR_DATA_START
1282 # define DATASTART GC_data_start
1283 # define DYNAMIC_LOADING
1284 # define MPROTECT_VDB
1285 /* Requires Linux 2.3.47 or later. */
1287 # define DATAEND (&_end)
1289 # define PREFETCH(x) \
1290 __asm__ (" lfetch [%0]": : "r"((void *)(x)))
1291 # define PREFETCH_FOR_WRITE(x) \
1292 __asm__ (" lfetch.excl [%0]": : "r"((void *)(x)))
1293 # define CLEAR_DOUBLE(x) \
1294 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1300 # define MACH_TYPE "M88K"
1301 # define ALIGNMENT 4
1302 # define ALIGN_DOUBLE
1305 # define OS_TYPE "CX_UX"
1306 # define DATASTART ((((word)&etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1309 # define OS_TYPE "DGUX"
1310 extern char * GC_SysVGetDataStart();
1311 # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext)
1313 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1317 # define MACH_TYPE "S370"
1318 # define ALIGNMENT 4 /* Required by hardware */
1319 # define USE_GENERIC_PUSH_REGS
1321 # define OS_TYPE "UTS4"
1325 extern char * GC_SysVGetDataStart();
1326 # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
1327 # define DATAEND (&_end)
1331 # define OS_TYPE "LINUX"
1333 # define DYNAMIC_LOADING
1334 extern int __data_start;
1335 # define DATASTART ((ptr_t)(&__data_start))
1340 # define ALIGNMENT 4
1342 # define DATASTART ((ptr_t)(&_etext))
1347 # define CPP_WORDSZ 32
1348 # define MACH_TYPE "ARM32"
1349 # define ALIGNMENT 4
1351 # define OS_TYPE "NETBSD"
1354 # define DATASTART ((ptr_t)(&etext))
1355 # define USE_GENERIC_PUSH_REGS
1358 # define OS_TYPE "LINUX"
1361 # define STACK_GRAN 0x10000000
1362 # define USE_GENERIC_PUSH_REGS
1364 # define DYNAMIC_LOADING
1365 # include <features.h>
1366 # if defined(__GLIBC__) && __GLIBC__ >= 2
1367 # define LINUX_DATA_START
1369 extern char **__environ;
1370 # define DATASTART ((ptr_t)(&__environ))
1371 /* hideous kludge: __environ is the first */
1372 /* word in crt0.o, and delimits the start */
1373 /* of the data segment, no matter which */
1374 /* ld options were passed through. */
1375 /* We could use _etext instead, but that */
1376 /* would include .rodata, which may */
1377 /* contain large read-only data tables */
1378 /* that we'd rather not scan. */
1381 # define DATAEND (&_end)
1384 # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
1388 # define OS_TYPE "MSWINCE"
1389 # define DATAEND /* not needed */
1394 # define MACH_TYPE "SH"
1395 # define ALIGNMENT 4
1397 # define OS_TYPE "MSWINCE"
1398 # define DATAEND /* not needed */
1401 # define OS_TYPE "LINUX"
1402 # define STACKBOTTOM ((ptr_t) 0x7c000000)
1403 # define USE_GENERIC_PUSH_REGS
1404 # define DYNAMIC_LOADING
1405 # define LINUX_DATA_START
1407 # define DATAEND (&_end)
1412 # define MACH_TYPE "SH4"
1413 # define OS_TYPE "MSWINCE"
1414 # define ALIGNMENT 4
1415 # define DATAEND /* not needed */
1418 #ifdef LINUX_DATA_START
1419 /* Some Linux distributions arrange to define __data_start. Some */
1420 /* define data_start as a weak symbol. The latter is technically */
1421 /* broken, since the user program may define data_start, in which */
1422 /* case we lose. Nonetheless, we try both, prefering __data_start. */
1423 /* We assume gcc. */
1424 # pragma weak __data_start
1425 extern int __data_start;
1426 # pragma weak data_start
1427 extern int data_start;
1428 # define DATASTART ((ptr_t)(&__data_start != 0? &__data_start : &data_start))
1431 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1432 /* Rld appears to allocate some memory with its own allocator, and */
1433 /* some through malloc, which might be redirected. To make this */
1434 /* work with collectable memory, we have to scan memory allocated */
1435 /* by rld's internal malloc. */
1436 # define USE_PROC_FOR_LIBRARIES
1439 # ifndef STACK_GROWS_UP
1440 # define STACK_GROWS_DOWN
1444 # define CPP_WORDSZ 32
1453 # define DATAEND (&end)
1456 # if defined(SVR4) && !defined(GETPAGESIZE)
1457 # include <unistd.h>
1458 # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1461 # ifndef GETPAGESIZE
1462 # if defined(SUNOS5) || defined(IRIX5)
1463 # include <unistd.h>
1465 # define GETPAGESIZE() getpagesize()
1468 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1469 /* OS has SVR4 generic features. Probably others also qualify. */
1473 # if defined(SUNOS5) || defined(DRSNX)
1474 /* OS has SUNOS5 style semi-undocumented interface to dynamic */
1477 /* OS has SUNOS5 style signal handlers. */
1485 # if defined(SVR4) || defined(LINUX) || defined(IRIX) || defined(HPUX) \
1486 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1487 || defined(BSD) || defined(AIX) || defined(MACOSX) || defined(OSF1)
1488 # define UNIX_LIKE /* Basic Unix-like system calls work. */
1491 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1496 # undef DYNAMIC_LOADING
1501 # undef MPROTECT_VDB
1506 /* Postponed for now. */
1508 # undef MPROTECT_VDB
1511 # ifdef SMALL_CONFIG
1512 /* Presumably not worth the space it takes. */
1514 # undef MPROTECT_VDB
1518 # undef MPROTECT_VDB /* Can't deal with address space holes. */
1521 # ifdef PARALLEL_MARK
1522 # undef MPROTECT_VDB /* For now. */
1525 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
1526 # define DEFAULT_VDB
1530 # define PREFETCH(x)
1531 # define NO_PREFETCH
1534 # ifndef PREFETCH_FOR_WRITE
1535 # define PREFETCH_FOR_WRITE(x)
1536 # define NO_PREFETCH_FOR_WRITE
1539 # ifndef CACHE_LINE_SIZE
1540 # define CACHE_LINE_SIZE 32 /* Wild guess */
1543 # ifndef CLEAR_DOUBLE
1544 # define CLEAR_DOUBLE(x) \
1545 ((word*)x)[0] = 0; \
1547 # endif /* CLEAR_DOUBLE */
1549 /* Internally to the collector we test only the XXX_THREADS macros */
1550 /* not the GC_XXX_THREADS versions. Here we make sure the latter */
1551 /* are treated as equivalent. */
1552 #if defined(GC_SOLARIS_THREADS) && !defined(_SOLARIS_THREADS)
1553 # define _SOLARIS_THREADS
1555 #if defined(GC_SOLARIS_THREADS) && !defined(_SOLARIS_PTHREADS)
1556 # define _SOLARIS_PTHREADS
1558 #if defined(GC_IRIX_THREADS) && !defined(IRIX_THREADS)
1559 # define IRIX_THREADS
1561 #if defined(GC_LINUX_THREADS) && !defined(LINUX_THREADS)
1562 # define LINUX_THREADS
1564 #if defined(GC_WIN32_THREADS) && !defined(WIN32_THREADS)
1565 # define WIN32_THREADS
1567 #if defined(GC_HPUX_THREADS) && !defined(HPUX_THREADS)
1568 # define HPUX_THREADS
1570 #if defined(GC_OSF1_THREADS) && !defined(OSF1_THREADS)
1571 # define OSF1_THREADS
1574 /* Internally we use SOLARIS_THREADS to test for either old or pthreads. */
1575 # if defined(_SOLARIS_PTHREADS) && !defined(SOLARIS_THREADS)
1576 # define SOLARIS_THREADS
1578 # if defined(IRIX_THREADS) && !defined(IRIX5)
1579 --> inconsistent configuration
1581 # if defined(LINUX_THREADS) && !defined(LINUX)
1582 --> inconsistent configuration
1584 # if defined(SOLARIS_THREADS) && !defined(SUNOS5)
1585 --> inconsistent configuration
1587 # if defined(HPUX_THREADS) && !defined(HPUX)
1588 --> inconsistent configuration
1590 # if defined(PCR) || defined(SRC_M3) || \
1591 defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || \
1592 defined(IRIX_THREADS) || defined(LINUX_THREADS) || \
1593 defined(HPUX_THREADS) || defined(OSF1_THREADS)
1597 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(MACOSX) \
1598 || defined(LINT) || defined(MSWINCE) \
1599 || (defined(I386) && defined(__LCC__))
1600 /* Use setjmp based hack to mark from callee-save registers. */
1601 /* The define should move to the individual platform */
1603 # define USE_GENERIC_PUSH_REGS
1605 # if defined(I386) && defined(LINUX)
1606 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
1607 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
1608 # ifdef SAVE_CALL_COUNT
1609 # define SAVE_CALL_CHAIN
1613 # define SAVE_CALL_CHAIN
1614 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
1615 /* include assembly code to do it well. */
1618 # endif /* GCCONFIG_H */