2
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
4
* Copyright (c) 1996 by Silicon Graphics. All rights reserved.
5
* Copyright (c) 2000-2004 Hewlett-Packard Development Company, L.P.
7
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10
* Permission is hereby granted to use or copy this program
11
* for any purpose, provided the above notices are retained on all copies.
12
* Permission to modify the code and to distribute modified code is granted,
13
* provided the above notices are retained, and a notice that the code was
14
* modified is included with the above copyright notice.
18
* This header is private to the gc. It is almost always included from
19
* gc_priv.h. However it is possible to include it by itself if just the
20
* configuration macros are needed. In that
21
* case, a few declarations relying on types declared in gc_priv.h will be
30
/* Fake ptr_t declaration, just to avoid compilation errors. */
31
/* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
32
typedef struct GC_undefined_struct * ptr_t;
33
# include <stddef.h> /* For size_t etc. */
36
/* Machine dependent parameters. Some tuning parameters can be found */
37
/* near the top of gc_private.h. */
39
/* Machine specific parts contributed by various people. See README file. */
41
/* First a unified test for Linux: */
42
# if defined(linux) || defined(__linux__)
48
/* And one for NetBSD: */
49
# if defined(__NetBSD__)
53
/* And one for OpenBSD: */
54
# if defined(__OpenBSD__)
58
/* And one for FreeBSD: */
59
# if (defined(__FreeBSD__) || defined(__DragonFly__) || \
60
defined(__FreeBSD_kernel__)) && !defined(FREEBSD)
64
/* Determine the machine type: */
65
# if defined(__arm__) || defined(__thumb__)
67
# if !defined(LINUX) && !defined(NETBSD)
69
# define mach_type_known
72
# if defined(sun) && defined(mc68000)
73
# error SUNOS4 no longer supported
75
# if defined(hp9000s300)
76
# error M68K based HP machines no longer supported.
78
# if defined(OPENBSD) && defined(m68k)
80
# define mach_type_known
82
# if defined(OPENBSD) && defined(__sparc__)
84
# define mach_type_known
86
# if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
88
# define mach_type_known
90
# if defined(NETBSD) && defined(__powerpc__)
92
# define mach_type_known
94
# if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
96
# define mach_type_known
98
# if defined(NETBSD) && defined(__sh__)
100
# define mach_type_known
109
# define mach_type_known
111
# if defined(__NetBSD__) && defined(__vax__)
113
# define mach_type_known
115
# if defined(mips) || defined(__mips) || defined(_mips)
117
# if defined(nec_ews) || defined(_nec_ews)
120
# if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
121
# if defined(ultrix) || defined(__ultrix)
124
# define IRIX5 /* or IRIX 6.X */
127
# if defined(__NetBSD__) && defined(__MIPSEL__)
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(sun) && defined(__amd64)
152
# define mach_type_known
154
# if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
157
# define mach_type_known
160
# error IBM PC/RT no longer supported.
162
# if defined(sun) && (defined(sparc) || defined(__sparc))
164
/* Test for SunOS 5.x */
167
# define mach_type_known
169
# if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
170
&& !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__) \
171
&& !defined(__DragonFly__)
174
# define mach_type_known
179
# define mach_type_known
181
# if defined(__NetBSD__) && defined(__sparc__)
183
# define mach_type_known
185
# if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
186
/* The above test may need refinement */
188
# if defined(_SCO_ELF)
193
# define mach_type_known
195
# if defined(_AUX_SOURCE)
196
# error A/UX no longer supported
198
# if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
199
|| defined(hppa) || defined(__hppa__)
201
# if !defined(LINUX) && !defined(HPUX)
204
# define mach_type_known
206
# if defined(__ia64) && defined(_HPUX_SOURCE)
211
# define mach_type_known
213
# if defined(__BEOS__) && defined(_X86_)
216
# define mach_type_known
218
# if defined(LINUX) && (defined(i386) || defined(__i386__))
220
# define mach_type_known
222
# if defined(LINUX) && defined(__x86_64__)
224
# define mach_type_known
226
# if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
228
# define mach_type_known
230
# if defined(LINUX) && defined(__arm__)
232
# define mach_type_known
234
# if defined(LINUX) && defined(__cris__)
238
# define mach_type_known
240
# if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || \
241
defined(powerpc64) || defined(__powerpc64__))
243
# define mach_type_known
245
# if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
247
# define mach_type_known
249
# if defined(LINUX) && defined(__mc68000__)
251
# define mach_type_known
253
# if defined(LINUX) && (defined(sparc) || defined(__sparc__))
255
# define mach_type_known
257
# if defined(LINUX) && defined(__arm__)
259
# define mach_type_known
261
# if defined(LINUX) && defined(__sh__)
263
# define mach_type_known
265
# if defined(LINUX) && defined(__m32r__)
267
# define mach_type_known
269
# if defined(__alpha) || defined(__alpha__)
271
# if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
272
# define OSF1 /* a.k.a Digital Unix */
274
# define mach_type_known
276
# if defined(_AMIGA) && !defined(AMIGA)
281
# define mach_type_known
283
# if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
286
# define mach_type_known
288
# if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
291
# define mach_type_known
293
# if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
295
# if defined(__ppc__) || defined(__ppc64__)
297
# define mach_type_known
299
# if defined(__i386__)
301
# define mach_type_known
304
# if defined(NeXT) && defined(mc68000)
307
# define mach_type_known
309
# if defined(NeXT) && (defined(i386) || defined(__i386__))
312
# define mach_type_known
314
# if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
317
# define mach_type_known
319
# if defined(FREEBSD) && (defined(i386) || defined(__i386__))
321
# define mach_type_known
323
# if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
325
# define mach_type_known
327
# if defined(__NetBSD__) && defined(__x86_64__)
329
# define mach_type_known
331
# if defined(FREEBSD) && defined(__sparc__)
333
# define mach_type_known
335
# if defined(bsdi) && (defined(i386) || defined(__i386__))
338
# define mach_type_known
340
# if !defined(mach_type_known) && defined(__386BSD__)
343
# define mach_type_known
345
# if defined(_CX_UX) && defined(_M88K)
348
# define mach_type_known
350
# if defined(DGUX) && defined(m88k)
353
# define mach_type_known
355
# if defined(_WIN32_WCE)
356
/* SH3, SH4, MIPS already defined for corresponding architectures */
357
# if defined(SH3) || defined(SH4)
367
# define mach_type_known
369
# if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
370
|| defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
372
# define MSWIN32 /* or Win32s */
373
# define mach_type_known
375
# if defined(_MSC_VER) && defined(_M_IA64)
377
# define MSWIN32 /* Really win64, but we don't treat 64-bit */
378
/* variants as a differnt platform. */
381
# if defined(__DJGPP__)
384
# define DJGPP /* MSDOS running the DJGPP port of GCC */
386
# define mach_type_known
388
# if defined(__CYGWIN32__) || defined(__CYGWIN__)
391
# define mach_type_known
393
# if defined(__MINGW32__)
396
# define mach_type_known
398
# if defined(__BORLANDC__)
401
# define mach_type_known
403
# if defined(_UTS) && !defined(mach_type_known)
406
# define mach_type_known
409
# error PicoJava no longer supported
410
/* The implementation had problems, and I haven't heard of users */
411
/* in ages. If you want it resurrected, let me know. */
413
# if defined(__embedded__) && defined(PPC)
416
# define mach_type_known
419
# if defined(__WATCOMC__) && defined(__386__)
421
# if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
422
# if defined(__OS2__)
425
# if defined(__WINDOWS_386__) || defined(__NT__)
432
# define mach_type_known
434
# if defined(__s390__) && defined(LINUX)
436
# define mach_type_known
438
# if defined(__GNU__)
439
# if defined(__i386__)
440
/* The Debian Hurd running on generic PC */
443
# define mach_type_known
446
# if defined(__TANDEM)
447
/* Nonstop S-series */
448
/* FIXME: Should recognize Integrity series? */
451
# define mach_type_known
454
/* Feel free to add more clauses here */
456
/* Or manually define the machine type here. A machine type is */
457
/* characterized by the architecture. Some */
458
/* machine types are further subdivided by OS. */
459
/* Macros such as LINUX, FREEBSD, etc. distinguish them. */
460
/* SYSV on an M68K actually means A/UX. */
461
/* The distinction in these cases is usually the stack starting address */
462
# ifndef mach_type_known
463
--> unknown machine type
465
/* Mapping is: M68K ==> Motorola 680X0 */
466
/* (NEXT, and SYSV (A/UX), */
467
/* MACOS and AMIGA variants) */
468
/* I386 ==> Intel 386 */
469
/* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
470
/* FREEBSD, THREE86BSD, MSWIN32, */
471
/* BSDI,SOLARIS, NEXT, other variants) */
472
/* NS32K ==> Encore Multimax */
473
/* MIPS ==> R2000 through R14K */
474
/* (many variants) */
475
/* VAX ==> DEC VAX */
476
/* (BSD, ULTRIX variants) */
477
/* HP_PA ==> HP9000/700 & /800 */
479
/* SPARC ==> SPARC v7/v8/v9 */
480
/* (SOLARIS, LINUX, DRSNX variants) */
481
/* ALPHA ==> DEC Alpha */
482
/* (OSF1 and LINUX variants) */
483
/* M88K ==> Motorola 88XX0 */
484
/* (CX_UX and DGUX) */
485
/* S370 ==> 370-like machine */
486
/* running Amdahl UTS4 */
487
/* S390 ==> 390-like machine */
489
/* ARM32 ==> Intel StrongARM */
490
/* IA64 ==> Intel IPF */
492
/* (LINUX and HPUX) */
493
/* SH ==> Hitachi SuperH */
494
/* (LINUX & MSWINCE) */
495
/* X86_64 ==> AMD x86-64 */
496
/* POWERPC ==> IBM/Apple PowerPC */
497
/* (MACOS(<=9),DARWIN(incl.MACOSX),*/
498
/* LINUX, NETBSD, AIX, NOSYS */
500
/* Handles 32 and 64-bit variants. */
501
/* CRIS ==> Axis Etrax */
502
/* M32R ==> Renesas M32R */
506
* For each architecture and OS, the following need to be defined:
508
* CPP_WORDSZ is a simple integer constant representing the word size.
509
* in bits. We assume byte addressibility, where a byte has 8 bits.
510
* We also assume CPP_WORDSZ is either 32 or 64.
511
* (We care about the length of pointers, not hardware
512
* bus widths. Thus a 64 bit processor with a C compiler that uses
513
* 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
515
* MACH_TYPE is a string representation of the machine type.
516
* OS_TYPE is analogous for the OS.
518
* ALIGNMENT is the largest N, such that
519
* all pointer are guaranteed to be aligned on N byte boundaries.
520
* defining it to be 1 will always work, but perform poorly.
522
* DATASTART is the beginning of the data segment.
523
* On some platforms SEARCH_FOR_DATA_START is defined.
524
* SEARCH_FOR_DATASTART will cause GC_data_start to
525
* be set to an address determined by accessing data backwards from _end
526
* until an unmapped page is found. DATASTART will be defined to be
528
* On UNIX-like systems, the collector will scan the area between DATASTART
529
* and DATAEND for root pointers.
531
* DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
532
* RTH suggests gaining access to linker script synth'd values with
533
* this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
534
* Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
535
* cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
536
* without any special options.
538
* STACKBOTTOM is the cool end of the stack, which is usually the
539
* highest address in the stack.
540
* Under PCR or OS/2, we have other ways of finding thread stacks.
541
* For each machine, the following should:
542
* 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
543
* 2) define exactly one of
544
* STACKBOTTOM (should be defined to be an expression)
548
* If STACKBOTTOM is defined, then it's value will be used directly as the
549
* stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
550
* with a method appropriate for most Linux systems. Currently we look
551
* first for __libc_stack_end, and if that fails read it from /proc.
552
* If either of the last two macros are defined, then STACKBOTTOM is computed
553
* during collector startup using one of the following two heuristics:
554
* HEURISTIC1: Take an address inside GC_init's frame, and round it up to
555
* the next multiple of STACK_GRAN.
556
* HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
557
* in small steps (decrement if STACK_GROWS_UP), and read the value
558
* at each location. Remember the value when the first
559
* Segmentation violation or Bus error is signalled. Round that
560
* to the nearest plausible page boundary, and use that instead
563
* Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
564
* the value of environ is a pointer that can serve as STACKBOTTOM.
565
* I expect that HEURISTIC2 can be replaced by this approach, which
566
* interferes far less with debugging. However it has the disadvantage
567
* that it's confused by a putenv call before the collector is initialized.
568
* This could be dealt with by intercepting putenv ...
570
* If no expression for STACKBOTTOM can be found, and neither of the above
571
* heuristics are usable, the collector can still be used with all of the above
572
* undefined, provided one of the following is done:
573
* 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
574
* without reference to STACKBOTTOM. This is appropriate for use in
575
* conjunction with thread packages, since there will be multiple stacks.
576
* (Allocating thread stacks in the heap, and treating them as ordinary
577
* heap data objects is also possible as a last resort. However, this is
578
* likely to introduce significant amounts of excess storage retention
579
* unless the dead parts of the thread stacks are periodically cleared.)
580
* 2) Client code may set GC_stackbottom before calling any GC_ routines.
581
* If the author of the client code controls the main program, this is
582
* easily accomplished by introducing a new main program, setting
583
* GC_stackbottom to the address of a local variable, and then calling
584
* the original main program. The new main program would read something
587
* # include "gc_private.h"
589
* main(argc, argv, envp)
591
* char **argv, **envp;
595
* GC_stackbottom = (ptr_t)(&dummy);
596
* return(real_main(argc, argv, envp));
600
* Each architecture may also define the style of virtual dirty bit
601
* implementation to be used:
602
* MPROTECT_VDB: Write protect the heap and catch faults.
603
* GWW_VDB: Use win32 GetWriteWatch primitive.
604
* PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
606
* The first and second one may be combined, in which case a runtime
607
* selection will be made, based on GetWriteWatch availability.
609
* An architecture may define DYNAMIC_LOADING if dynamic_load.c
610
* defined GC_register_dynamic_libraries() for the architecture.
612
* An architecture may define PREFETCH(x) to preload the cache with *x.
613
* This defaults to a no-op.
615
* PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
617
* An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
618
* clear the two words at GC_malloc-aligned address x. By default,
619
* word stores of 0 are used instead.
621
* HEAP_START may be defined as the initial address hint for mmap-based
625
/* If we are using a recent version of gcc, we can use __builtin_unwind_init()
626
* to push the relevant registers onto the stack.
628
# if defined(__GNUC__) && ((__GNUC__ >= 3) || \
629
(__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
630
&& !defined(__INTEL_COMPILER) && !defined(__PATHCC__)
631
# define HAVE_BUILTIN_UNWIND_INIT
634
# define STACK_GRAN 0x1000000
636
# define MACH_TYPE "M68K"
639
# define OS_TYPE "OPENBSD"
642
# define DATASTART GC_data_start
643
# define DYNAMIC_LOADING
646
# define DATASTART ((ptr_t)(etext))
650
# define OS_TYPE "NETBSD"
653
# define DATASTART GC_data_start
654
# define DYNAMIC_LOADING
657
# define DATASTART ((ptr_t)(etext))
661
# define OS_TYPE "LINUX"
662
# define STACKBOTTOM ((ptr_t)0xf0000000)
663
/* # define MPROTECT_VDB - Reported to not work 9/17/01 */
665
# define DYNAMIC_LOADING
666
# include <features.h>
667
# if defined(__GLIBC__)&& __GLIBC__>=2
668
# define SEARCH_FOR_DATA_START
670
extern char **__environ;
671
# define DATASTART ((ptr_t)(&__environ))
672
/* hideous kludge: __environ is the first */
673
/* word in crt0.o, and delimits the start */
674
/* of the data segment, no matter which */
675
/* ld options were passed through. */
676
/* We could use _etext instead, but that */
677
/* would include .rodata, which may */
678
/* contain large read-only data tables */
679
/* that we'd rather not scan. */
680
# endif /* !GLIBC2 */
682
# define DATAEND (_end)
685
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
689
# define OS_TYPE "AMIGA"
690
/* STACKBOTTOM and DATASTART handled specially */
692
# define DATAEND /* not needed */
693
# define GETPAGESIZE() 4096
699
# define OS_TYPE "MACOS"
700
/* see os_dep.c for details of global data segments. */
701
# define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
702
# define DATAEND /* not needed */
703
# define GETPAGESIZE() 4096
706
# define OS_TYPE "NEXT"
707
# define DATASTART ((ptr_t) get_etext())
708
# define STACKBOTTOM ((ptr_t) 0x4000000)
709
# define DATAEND /* not needed */
713
# if defined(POWERPC)
714
# define MACH_TYPE "POWERPC"
716
# define ALIGNMENT 2 /* Still necessary? Could it be 4? */
720
# define OS_TYPE "MACOS"
721
/* see os_dep.c for details of global data segments. */
722
# define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
723
# define DATAEND /* not needed */
726
# if defined(__powerpc64__)
728
# define CPP_WORDSZ 64
730
# define HBLKSIZE 4096
735
# define OS_TYPE "LINUX"
736
/* HEURISTIC1 has been reliably reported to fail for a 32-bit */
737
/* executable on a 64 bit kernel. */
738
# define LINUX_STACKBOTTOM
739
# define DYNAMIC_LOADING
740
# define SEARCH_FOR_DATA_START
742
# define DATAEND (_end)
747
# define CPP_WORDSZ 64
751
# define OS_TYPE "DARWIN"
752
# define DYNAMIC_LOADING
753
/* XXX: see get_end(3), get_etext() and get_end() should not be used.
754
These aren't used when dyld support is enabled (it is by default) */
755
# define DATASTART ((ptr_t) get_etext())
756
# define DATAEND ((ptr_t) get_end())
757
# define STACKBOTTOM ((ptr_t) 0xc0000000)
759
# define USE_MMAP_ANON
760
# ifdef GC_DARWIN_THREADS
761
/* This is potentially buggy. It needs more testing. See the comments in
762
os_dep.c. It relies on threads to track writes. */
763
# define MPROTECT_VDB
766
# define GETPAGESIZE() getpagesize()
767
# if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
768
/* The performance impact of prefetches is untested */
769
# define PREFETCH(x) \
770
__asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
771
# define PREFETCH_FOR_WRITE(x) \
772
__asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
774
/* There seems to be some issues with trylock hanging on darwin. This
775
should be looked into some more */
776
# define NO_PTHREAD_TRYLOCK
780
# define OS_TYPE "FREEBSD"
781
# ifndef GC_FREEBSD_THREADS
782
# define MPROTECT_VDB
784
# define SIG_SUSPEND SIGUSR1
785
# define SIG_THR_RESTART SIGUSR2
786
# define FREEBSD_STACKBOTTOM
788
# define DYNAMIC_LOADING
791
extern char * GC_FreeBSDGetDataStart();
792
# define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
796
# define OS_TYPE "NETBSD"
799
# define DATASTART GC_data_start
800
# define DYNAMIC_LOADING
803
# define OS_TYPE "AIX"
804
# undef ALIGNMENT /* in case it's defined */
807
/* DOB: some AIX installs stupidly define IA64 in */
808
/* /usr/include/sys/systemcfg.h */
812
# define CPP_WORDSZ 64
813
# define STACKBOTTOM ((ptr_t)0x1000000000000000)
816
# define CPP_WORDSZ 32
817
# define STACKBOTTOM ((ptr_t)((ulong)&errno))
820
# define USE_MMAP_ANON
821
/* From AIX linker man page:
822
_text Specifies the first location of the program.
823
_etext Specifies the first location after the program.
824
_data Specifies the first location of the data.
825
_edata Specifies the first location after the initialized data
826
_end or end Specifies the first location after all data.
828
extern int _data[], _end[];
829
# define DATASTART ((ptr_t)((ulong)_data))
830
# define DATAEND ((ptr_t)((ulong)_end))
832
# define DYNAMIC_LOADING
833
/* For really old versions of AIX, this may have to be removed. */
838
# define OS_TYPE "NOSYS"
839
extern void __end[], __dso_handle[];
840
# define DATASTART (__dso_handle) /* OK, that's ugly. */
841
# define DATAEND (__end)
842
/* Stack starts at 0xE0000000 for the simulator. */
844
# define STACK_GRAN 0x10000000
850
# define MACH_TYPE "VAX"
851
# define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
853
# define DATASTART ((ptr_t)(etext))
855
# define OS_TYPE "BSD"
857
/* HEURISTIC2 may be OK, but it's hard to test. */
860
# define OS_TYPE "ULTRIX"
861
# define STACKBOTTOM ((ptr_t) 0x7fffc800)
866
# define MACH_TYPE "SPARC"
867
# if defined(__arch64__) || defined(__sparcv9)
869
# define CPP_WORDSZ 64
870
# define ELF_CLASS ELFCLASS64
872
# define ALIGNMENT 4 /* Required by hardware */
873
# define CPP_WORDSZ 32
875
/* Don't define USE_ASM_PUSH_REGS. We do use an asm helper, but */
876
/* not to push the registers on the mark stack. */
878
# define OS_TYPE "SOLARIS"
881
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
882
# define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
883
# define DATAEND (_end)
884
# if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
886
/* Otherwise we now use calloc. Mmap may result in the */
887
/* heap interleaved with thread stacks, which can result in */
888
/* excessive blacklisting. Sbrk is unusable since it */
889
/* doesn't interact correctly with the system malloc. */
892
# define HEAP_START (ptr_t)0x40000000
894
# define HEAP_START DATAEND
897
/* HEURISTIC1 reportedly no longer works under 2.7. */
898
/* HEURISTIC2 probably works, but this appears to be preferable. */
899
/* Apparently USRSTACK is defined to be USERLIMIT, but in some */
900
/* installations that's undefined. We work around this with a */
902
# include <sys/vmparam.h>
904
/* This should work everywhere, but doesn't. */
905
# define STACKBOTTOM USRSTACK
910
# define GETPAGESIZE() sysconf(_SC_PAGESIZE)
911
/* getpagesize() appeared to be missing from at least one */
912
/* Solaris 5.4 installation. Weird. */
913
# define DYNAMIC_LOADING
916
# define OS_TYPE "DRSNX"
917
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
919
# define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
920
# define MPROTECT_VDB
921
# define STACKBOTTOM ((ptr_t) 0xdfff0000)
922
# define DYNAMIC_LOADING
925
# define OS_TYPE "LINUX"
927
# define DYNAMIC_LOADING
929
Linux Sparc/a.out not supported
933
# define DATAEND (_end)
935
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
937
# define DATASTART GC_SysVGetDataStart(0x100000, (ptr_t)_etext)
939
# define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
941
# define LINUX_STACKBOTTOM
944
# define OS_TYPE "OPENBSD"
945
# define STACKBOTTOM ((ptr_t) 0xf8000000)
947
# define DATASTART ((ptr_t)(etext))
950
# define OS_TYPE "NETBSD"
953
# define DATASTART GC_data_start
954
# define DYNAMIC_LOADING
957
# define DATASTART ((ptr_t)(etext))
961
# define OS_TYPE "FREEBSD"
962
# define SIG_SUSPEND SIGUSR1
963
# define SIG_THR_RESTART SIGUSR2
964
# define FREEBSD_STACKBOTTOM
966
# define DYNAMIC_LOADING
971
# define NEED_FIND_LIMIT
972
# define DATASTART ((ptr_t)(&etext))
973
# define DATAEND (GC_find_limit (DATASTART, TRUE))
974
# define DATASTART2 ((ptr_t)(&edata))
975
# define DATAEND2 ((ptr_t)(&end))
980
# define MACH_TYPE "I386"
981
# if defined(__LP64__) || defined(_WIN64)
982
# define CPP_WORDSZ 64
985
# define CPP_WORDSZ 32
987
/* Appears to hold for all "32 bit" compilers */
988
/* except Borland. The -a4 option fixes */
990
/* Ivan Demakov: For Watcom the option is -zp4. */
993
# define OS_TYPE "SEQUENT"
995
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
996
# define STACKBOTTOM ((ptr_t) 0x3ffff000)
999
# define OS_TYPE "BEOS"
1001
# define GETPAGESIZE() B_PAGE_SIZE
1003
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1006
# define OS_TYPE "SOLARIS"
1007
extern int _etext[], _end[];
1008
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1009
# define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
1010
# define DATAEND (_end)
1011
/* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1012
/* but reportedly breaks under 2.8. It appears that the stack */
1013
/* base is a property of the executable, so this should not break */
1014
/* old executables. */
1015
/* HEURISTIC2 probably works, but this appears to be preferable. */
1016
# include <sys/vm.h>
1017
# define STACKBOTTOM USRSTACK
1018
/* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1019
/* It appears to be fixed in 2.8 and 2.9. */
1020
# ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1023
# define DYNAMIC_LOADING
1024
# if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1026
/* Otherwise we now use calloc. Mmap may result in the */
1027
/* heap interleaved with thread stacks, which can result in */
1028
/* excessive blacklisting. Sbrk is unusable since it */
1029
/* doesn't interact correctly with the system malloc. */
1032
# define HEAP_START (ptr_t)0x40000000
1034
# define HEAP_START DATAEND
1038
# define OS_TYPE "SCO"
1040
# define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1042
+((word)etext & 0xfff))
1043
# define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1046
# define OS_TYPE "SCO_ELF"
1048
# define DATASTART ((ptr_t)(etext))
1049
# define STACKBOTTOM ((ptr_t) 0x08048000)
1050
# define DYNAMIC_LOADING
1051
# define ELF_CLASS ELFCLASS32
1054
# define OS_TYPE "DGUX"
1055
extern int _etext, _end;
1056
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1057
# define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)(&_etext))
1058
# define DATAEND (&_end)
1059
# define STACK_GROWS_DOWN
1061
# include <unistd.h>
1062
# define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1063
# define DYNAMIC_LOADING
1066
# endif /* USE_MMAP */
1067
# define MAP_FAILED (void *) -1
1069
# define HEAP_START (ptr_t)0x40000000
1070
# else /* USE_MMAP */
1071
# define HEAP_START DATAEND
1072
# endif /* USE_MMAP */
1076
# define OS_TYPE "LINUX"
1077
# define LINUX_STACKBOTTOM
1081
# define STACK_GRAN 0x10000000
1082
/* STACKBOTTOM is usually 0xc0000000, but this changes with */
1083
/* different kernel configurations. In particular, systems */
1084
/* with 2GB physical memory will usually move the user */
1085
/* address space limit, and hence initial SP to 0x80000000. */
1087
# if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1088
# define MPROTECT_VDB
1090
/* We seem to get random errors in incremental mode, */
1091
/* possibly because Linux threads is itself a malloc client */
1092
/* and can't deal with the signals. */
1094
# define HEAP_START (ptr_t)0x1000
1095
/* This encourages mmap to give us low addresses, */
1096
/* thus allowing the heap to grow to ~3GB */
1098
# define DYNAMIC_LOADING
1099
# ifdef UNDEFINED /* includes ro data */
1100
extern int _etext[];
1101
# define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1103
# include <features.h>
1104
# if defined(__GLIBC__) && __GLIBC__ >= 2
1105
# define SEARCH_FOR_DATA_START
1107
extern char **__environ;
1108
# define DATASTART ((ptr_t)(&__environ))
1109
/* hideous kludge: __environ is the first */
1110
/* word in crt0.o, and delimits the start */
1111
/* of the data segment, no matter which */
1112
/* ld options were passed through. */
1113
/* We could use _etext instead, but that */
1114
/* would include .rodata, which may */
1115
/* contain large read-only data tables */
1116
/* that we'd rather not scan. */
1119
# define DATAEND (_end)
1122
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1124
# ifdef USE_I686_PREFETCH
1125
/* FIXME: Thus should use __builtin_prefetch, but we'll leave that */
1126
/* for the next rtelease. */
1127
# define PREFETCH(x) \
1128
__asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
1129
/* Empirically prefetcht0 is much more effective at reducing */
1130
/* cache miss stalls for the targetted load instructions. But it */
1131
/* seems to interfere enough with other cache traffic that the net */
1132
/* result is worse than prefetchnta. */
1134
/* Using prefetches for write seems to have a slight negative */
1135
/* impact on performance, at least for a PIII/500. */
1136
# define PREFETCH_FOR_WRITE(x) \
1137
__asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
1140
# ifdef USE_3DNOW_PREFETCH
1141
# define PREFETCH(x) \
1142
__asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
1143
# define PREFETCH_FOR_WRITE(x) \
1144
__asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
1148
# define OS_TYPE "CYGWIN32"
1149
# define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1150
# define DATAEND ((ptr_t)GC_DATAEND)
1152
# define STACK_GRAN 0x10000
1156
# define OS_TYPE "OS2"
1157
/* STACKBOTTOM and DATASTART are handled specially in */
1158
/* os_dep.c. OS2 actually has the right */
1160
# define DATAEND /* not needed */
1163
# define OS_TYPE "MSWIN32"
1164
/* STACKBOTTOM and DATASTART are handled specially in */
1166
# if !defined(__WATCOMC__)
1167
# define MPROTECT_VDB
1168
/* We also avoided doing this in the past with GC_WIN32_THREADS */
1169
/* Hopefully that's fixed. */
1171
# if _MSC_VER >= 1300 /* .NET, i.e. > VisualStudio 6 */
1174
# define DATAEND /* not needed */
1177
# define OS_TYPE "MSWINCE"
1178
# define DATAEND /* not needed */
1181
# define OS_TYPE "DJGPP"
1182
# include "stubinfo.h"
1185
extern int __djgpp_stack_limit;
1186
# define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1187
/* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1189
# define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1190
/* This may not be right. */
1193
# define OS_TYPE "OPENBSD"
1196
# define OS_TYPE "FREEBSD"
1197
# ifndef GC_FREEBSD_THREADS
1198
# define MPROTECT_VDB
1201
# define SIG_SUSPEND (32+6)
1202
# define SIG_THR_RESTART (32+5)
1204
# define DATAEND (_end)
1206
# define SIG_SUSPEND SIGUSR1
1207
# define SIG_THR_RESTART SIGUSR2
1209
# define FREEBSD_STACKBOTTOM
1211
# define DYNAMIC_LOADING
1213
extern char etext[];
1214
extern char * GC_FreeBSDGetDataStart(size_t, ptr_t);
1215
# define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
1218
# define OS_TYPE "NETBSD"
1220
# define DYNAMIC_LOADING
1224
# define OS_TYPE "THREE86BSD"
1227
# define OS_TYPE "BSDI"
1229
# if defined(OPENBSD) || defined(NETBSD) \
1230
|| defined(THREE86BSD) || defined(BSDI)
1232
extern char etext[];
1233
# define DATASTART ((ptr_t)(etext))
1236
# define OS_TYPE "NEXT"
1237
# define DATASTART ((ptr_t) get_etext())
1238
# define STACKBOTTOM ((ptr_t)0xc0000000)
1239
# define DATAEND /* not needed */
1242
# define OS_TYPE "DOS4GW"
1243
extern long __nullarea;
1245
extern char *_STACKTOP;
1246
/* Depending on calling conventions Watcom C either precedes
1247
or does not precedes with undescore names of C-variables.
1248
Make sure startup code variables always have the same names. */
1249
#pragma aux __nullarea "*";
1250
#pragma aux _end "*";
1251
# define STACKBOTTOM ((ptr_t) _STACKTOP)
1252
/* confused? me too. */
1253
# define DATASTART ((ptr_t) &__nullarea)
1254
# define DATAEND ((ptr_t) &_end)
1257
# define OS_TYPE "HURD"
1258
# define STACK_GROWS_DOWN
1260
extern int __data_start[];
1261
# define DATASTART ( (ptr_t) (__data_start))
1263
# define DATAEND ( (ptr_t) (_end))
1264
/* # define MPROTECT_VDB Not quite working yet? */
1265
# define DYNAMIC_LOADING
1268
# define OS_TYPE "DARWIN"
1269
# define DARWIN_DONT_PARSE_STACK
1270
# define DYNAMIC_LOADING
1271
/* XXX: see get_end(3), get_etext() and get_end() should not be used.
1272
These aren't used when dyld support is enabled (it is by default) */
1273
# define DATASTART ((ptr_t) get_etext())
1274
# define DATAEND ((ptr_t) get_end())
1275
# define STACKBOTTOM ((ptr_t) 0xc0000000)
1277
# define USE_MMAP_ANON
1278
/* This is potentially buggy. It needs more testing. See the comments in
1279
os_dep.c. It relies on threads to track writes. */
1280
# ifdef GC_DARWIN_THREADS
1281
/* # define MPROTECT_VDB -- disabled for now. May work for some apps. */
1283
# include <unistd.h>
1284
# define GETPAGESIZE() getpagesize()
1285
/* There seems to be some issues with trylock hanging on darwin. This
1286
should be looked into some more */
1287
# define NO_PTHREAD_TRYLOCK
1288
# endif /* DARWIN */
1292
# define MACH_TYPE "NS32K"
1293
# define ALIGNMENT 4
1294
extern char **environ;
1295
# define DATASTART ((ptr_t)(&environ))
1296
/* hideous kludge: environ is the first */
1297
/* word in crt0.o, and delimits the start */
1298
/* of the data segment, no matter which */
1299
/* ld options were passed through. */
1300
# define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1304
# define MACH_TYPE "MIPS"
1306
/* This was developed for a linuxce style platform. Probably */
1307
/* needs to be tweaked for workstation class machines. */
1308
# define OS_TYPE "LINUX"
1309
# define DYNAMIC_LOADING
1311
# define DATAEND (_end)
1312
extern int __data_start[];
1313
# define DATASTART ((ptr_t)(__data_start))
1314
# define ALIGNMENT 4
1315
# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1316
# define LINUX_STACKBOTTOM
1318
# define STACKBOTTOM 0x80000000
1323
# if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1324
extern int _fdata[], _end[];
1325
# define DATASTART ((ptr_t)_fdata)
1326
# define DATAEND ((ptr_t)_end)
1327
# define CPP_WORDSZ _MIPS_SZPTR
1328
# define ALIGNMENT (_MIPS_SZPTR/8)
1330
extern int etext[], edata[], end[];
1331
extern int _DYNAMIC_LINKING[], _gp[];
1332
# define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1333
+ ((word)etext & 0xffff)))
1334
# define DATAEND (edata)
1335
# define DATASTART2 (_DYNAMIC_LINKING \
1336
? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1338
# define DATAEND2 (end)
1339
# define ALIGNMENT 4
1341
# define OS_TYPE "EWS4800"
1345
# define DATASTART (ptr_t)0x10000000
1346
/* Could probably be slightly higher since */
1347
/* startup code allocates lots of stuff. */
1348
# define OS_TYPE "ULTRIX"
1349
# define ALIGNMENT 4
1353
extern int _fdata[];
1354
# define DATASTART ((ptr_t)(_fdata))
1356
# define HEAP_START (ptr_t)0x30000000
1358
# define HEAP_START DATASTART
1360
/* Lowest plausible heap address. */
1361
/* In the MMAP case, we map there. */
1362
/* In either case it is used to identify */
1363
/* heap sections so they're not */
1364
/* considered as roots. */
1365
# define OS_TYPE "IRIX5"
1366
/*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1367
/* of recent breakage. */
1369
# define CPP_WORDSZ _MIPS_SZPTR
1370
# define ALIGNMENT (_MIPS_SZPTR/8)
1372
# define ALIGNMENT 4
1374
# define DYNAMIC_LOADING
1377
# define OS_TYPE "MSWINCE"
1378
# define ALIGNMENT 4
1379
# define DATAEND /* not needed */
1381
# if defined(NETBSD)
1382
# define OS_TYPE "NETBSD"
1383
# define ALIGNMENT 4
1387
# define DATASTART GC_data_start
1388
# define NEED_FIND_LIMIT
1389
# define DYNAMIC_LOADING
1391
# define DATASTART ((ptr_t) 0x10000000)
1392
# define STACKBOTTOM ((ptr_t) 0x7ffff000)
1395
# if defined(NONSTOP)
1396
# define CPP_WORDSZ 32
1397
# define OS_TYPE "NONSTOP"
1398
# define ALIGNMENT 4
1399
# define DATASTART ((ptr_t) 0x08000000)
1401
# define DATAEND (_end)
1402
# define STACKBOTTOM ((ptr_t) 0x4fffffff)
1403
# define USE_GENERIC_PUSH_REGS
1408
# define MACH_TYPE "HP_PA"
1410
# define CPP_WORDSZ 64
1411
# define ALIGNMENT 8
1413
# define CPP_WORDSZ 32
1414
# define ALIGNMENT 4
1416
# if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1417
# ifndef LINUX /* For now. */
1418
# define MPROTECT_VDB
1421
# define GENERIC_COMPARE_AND_SWAP
1422
/* No compare-and-swap instruction. Use pthread mutexes */
1423
/* when we absolutely have to. */
1424
# ifdef PARALLEL_MARK
1425
# define USE_MARK_BYTES
1426
/* Minimize compare-and-swap usage. */
1429
# define STACK_GROWS_UP
1431
# define OS_TYPE "HPUX"
1432
extern int __data_start[];
1433
# define DATASTART ((ptr_t)(__data_start))
1435
/* The following appears to work for 7xx systems running HP/UX */
1436
/* 9.xx Furthermore, it might result in much faster */
1437
/* collections than HEURISTIC2, which may involve scanning */
1438
/* segments that directly precede the stack. It is not the */
1439
/* default, since it may not work on older machine/OS */
1440
/* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1442
# define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
1444
/* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1445
/* to this. Note that the GC must be initialized before the */
1446
/* first putenv call. */
1447
extern char ** environ;
1448
# define STACKBOTTOM ((ptr_t)environ)
1450
# define DYNAMIC_LOADING
1451
# include <unistd.h>
1452
# define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1454
# define PREFETCH(x) { \
1455
register long addr = (long)(x); \
1456
(void) _asm ("LDW", 0, 0, addr, 0); \
1461
# define OS_TYPE "LINUX"
1462
# define LINUX_STACKBOTTOM
1463
# define DYNAMIC_LOADING
1464
# define SEARCH_FOR_DATA_START
1466
# define DATAEND (&_end)
1471
# define MACH_TYPE "ALPHA"
1472
# define ALIGNMENT 8
1473
# define CPP_WORDSZ 64
1475
# define OS_TYPE "NETBSD"
1477
# define DATASTART GC_data_start
1478
# define ELFCLASS32 32
1479
# define ELFCLASS64 64
1480
# define ELF_CLASS ELFCLASS64
1481
# define DYNAMIC_LOADING
1484
# define OS_TYPE "OPENBSD"
1486
# ifdef __ELF__ /* since OpenBSD/Alpha 2.9 */
1487
# define DATASTART GC_data_start
1488
# define ELFCLASS32 32
1489
# define ELFCLASS64 64
1490
# define ELF_CLASS ELFCLASS64
1491
# else /* ECOFF, until OpenBSD/Alpha 2.7 */
1492
# define DATASTART ((ptr_t) 0x140000000)
1496
# define OS_TYPE "FREEBSD"
1497
/* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1498
# define SIG_SUSPEND SIGUSR1
1499
# define SIG_THR_RESTART SIGUSR2
1500
# define FREEBSD_STACKBOTTOM
1502
# define DYNAMIC_LOADING
1504
/* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1505
extern char etext[];
1506
extern char edata[];
1508
# define NEED_FIND_LIMIT
1509
# define DATASTART ((ptr_t)(&etext))
1510
# define DATAEND (GC_find_limit (DATASTART, TRUE))
1511
# define DATASTART2 ((ptr_t)(&edata))
1512
# define DATAEND2 ((ptr_t)(&end))
1515
# define OS_TYPE "OSF1"
1516
# define DATASTART ((ptr_t) 0x140000000)
1518
# define DATAEND ((ptr_t) &_end)
1519
extern char ** environ;
1520
/* round up from the value of environ to the nearest page boundary */
1521
/* Probably breaks if putenv is called before collector */
1522
/* initialization. */
1523
# define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1524
/* # define HEURISTIC2 */
1525
/* Normally HEURISTIC2 is too conervative, since */
1526
/* the text segment immediately follows the stack. */
1527
/* Hence we give an upper pound. */
1528
/* This is currently unused, since we disabled HEURISTIC2 */
1529
extern int __start[];
1530
# define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1531
# ifndef GC_OSF1_THREADS
1532
/* Unresolved signal issues with threads. */
1533
# define MPROTECT_VDB
1535
# define DYNAMIC_LOADING
1538
# define OS_TYPE "LINUX"
1539
# define LINUX_STACKBOTTOM
1541
# define SEARCH_FOR_DATA_START
1542
# define DYNAMIC_LOADING
1544
# define DATASTART ((ptr_t) 0x140000000)
1547
# define DATAEND (_end)
1548
# define MPROTECT_VDB
1549
/* Has only been superficially tested. May not */
1550
/* work on all versions. */
1555
# define MACH_TYPE "IA64"
1558
# define CPP_WORDSZ 32
1559
/* Requires 8 byte alignment for malloc */
1560
# define ALIGNMENT 4
1565
# define CPP_WORDSZ 64
1566
/* Requires 16 byte alignment for malloc */
1567
# define ALIGNMENT 8
1569
# define OS_TYPE "HPUX"
1570
extern int __data_start[];
1571
# define DATASTART ((ptr_t)(__data_start))
1572
/* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1573
/* to this. Note that the GC must be initialized before the */
1574
/* first putenv call. */
1575
extern char ** environ;
1576
# define STACKBOTTOM ((ptr_t)environ)
1577
# define HPUX_STACKBOTTOM
1578
# define DYNAMIC_LOADING
1579
# include <unistd.h>
1580
# define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1581
/* The following was empirically determined, and is probably */
1582
/* not very robust. */
1583
/* Note that the backing store base seems to be at a nice */
1584
/* address minus one page. */
1585
# define BACKING_STORE_DISPLACEMENT 0x1000000
1586
# define BACKING_STORE_ALIGNMENT 0x1000
1587
extern ptr_t GC_register_stackbottom;
1588
# define BACKING_STORE_BASE GC_register_stackbottom
1589
/* Known to be wrong for recent HP/UX versions!!! */
1592
# define CPP_WORDSZ 64
1593
# define ALIGNMENT 8
1594
# define OS_TYPE "LINUX"
1595
/* The following works on NUE and older kernels: */
1596
/* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
1597
/* This does not work on NUE: */
1598
# define LINUX_STACKBOTTOM
1599
/* We also need the base address of the register stack */
1600
/* backing store. This is computed in */
1601
/* GC_linux_register_stack_base based on the following */
1603
# define BACKING_STORE_ALIGNMENT 0x100000
1604
# define BACKING_STORE_DISPLACEMENT 0x80000000
1605
extern ptr_t GC_register_stackbottom;
1606
# define BACKING_STORE_BASE GC_register_stackbottom
1607
# define SEARCH_FOR_DATA_START
1609
# define DYNAMIC_LOADING
1611
/* In the Intel compiler environment, we seem to end up with */
1612
/* statically linked executables and an undefined reference */
1615
# define MPROTECT_VDB
1616
/* Requires Linux 2.3.47 or later. */
1618
# define DATAEND (_end)
1620
# ifndef __INTEL_COMPILER
1621
# define PREFETCH(x) \
1622
__asm__ (" lfetch [%0]": : "r"(x))
1623
# define PREFETCH_FOR_WRITE(x) \
1624
__asm__ (" lfetch.excl [%0]": : "r"(x))
1625
# define CLEAR_DOUBLE(x) \
1626
__asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
1628
# include <ia64intrin.h>
1629
# define PREFETCH(x) \
1630
__lfetch(__lfhint_none, (x))
1631
# define PREFETCH_FOR_WRITE(x) \
1632
__lfetch(__lfhint_nta, (x))
1633
# define CLEAR_DOUBLE(x) \
1634
__stf_spill((void *)(x), 0)
1635
# endif /* __INTEL_COMPILER */
1639
/* FIXME: This is a very partial guess. There is no port, yet. */
1640
# define OS_TYPE "MSWIN32"
1641
/* STACKBOTTOM and DATASTART are handled specially in */
1643
# define DATAEND /* not needed */
1644
# if defined(_WIN64)
1645
# define CPP_WORDSZ 64
1647
# define CPP_WORDSZ 32 /* Is this possible? */
1649
# define ALIGNMENT 8
1650
# define STRTOULL _strtoui64
1655
# define MACH_TYPE "M88K"
1656
# define ALIGNMENT 4
1659
# define OS_TYPE "CX_UX"
1660
# define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1663
# define OS_TYPE "DGUX"
1664
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1665
# define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
1667
# define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1671
/* If this still works, and if anyone cares, this should probably */
1672
/* be moved to the S390 category. */
1673
# define MACH_TYPE "S370"
1674
# define ALIGNMENT 4 /* Required by hardware */
1676
# define OS_TYPE "UTS4"
1678
extern int _etext[];
1680
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1681
# define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1682
# define DATAEND (_end)
1688
# define MACH_TYPE "S390"
1690
# define ALIGNMENT 4
1691
# define CPP_WORDSZ 32
1693
# define ALIGNMENT 8
1694
# define CPP_WORDSZ 64
1696
# define HBLKSIZE 4096
1700
# define OS_TYPE "LINUX"
1701
# define LINUX_STACKBOTTOM
1702
# define DYNAMIC_LOADING
1703
extern int __data_start[];
1704
# define DATASTART ((ptr_t)(__data_start))
1706
# define DATAEND (_end)
1707
# define CACHE_LINE_SIZE 256
1708
# define GETPAGESIZE() 4096
1713
# define CPP_WORDSZ 32
1714
# define MACH_TYPE "ARM32"
1715
# define ALIGNMENT 4
1717
# define OS_TYPE "NETBSD"
1720
# define DATASTART GC_data_start
1721
# define DYNAMIC_LOADING
1723
extern char etext[];
1724
# define DATASTART ((ptr_t)(etext))
1728
# define OS_TYPE "LINUX"
1729
# define LINUX_STACKBOTTOM
1731
# define STACK_GRAN 0x10000000
1733
# define DYNAMIC_LOADING
1734
# include <features.h>
1735
# if defined(__GLIBC__) && __GLIBC__ >= 2
1736
# define SEARCH_FOR_DATA_START
1738
extern char **__environ;
1739
# define DATASTART ((ptr_t)(&__environ))
1740
/* hideous kludge: __environ is the first */
1741
/* word in crt0.o, and delimits the start */
1742
/* of the data segment, no matter which */
1743
/* ld options were passed through. */
1744
/* We could use _etext instead, but that */
1745
/* would include .rodata, which may */
1746
/* contain large read-only data tables */
1747
/* that we'd rather not scan. */
1750
# define DATAEND (_end)
1753
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1757
# define OS_TYPE "MSWINCE"
1758
# define DATAEND /* not needed */
1761
/* __data_start is usually defined in the target linker script. */
1762
extern int __data_start[];
1763
# define DATASTART (ptr_t)(__data_start)
1764
/* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
1765
extern void *__stack_base__;
1766
# define STACKBOTTOM ((ptr_t) (__stack_base__))
1771
# define MACH_TYPE "CRIS"
1772
# define CPP_WORDSZ 32
1773
# define ALIGNMENT 1
1774
# define OS_TYPE "LINUX"
1775
# define DYNAMIC_LOADING
1776
# define LINUX_STACKBOTTOM
1777
# define SEARCH_FOR_DATA_START
1779
# define DATAEND (_end)
1783
# define MACH_TYPE "SH"
1784
# define ALIGNMENT 4
1786
# define OS_TYPE "MSWINCE"
1787
# define DATAEND /* not needed */
1790
# define OS_TYPE "LINUX"
1791
# define LINUX_STACKBOTTOM
1792
# define DYNAMIC_LOADING
1793
# define SEARCH_FOR_DATA_START
1795
# define DATAEND (_end)
1798
# define OS_TYPE "NETBSD"
1800
# define DATASTART GC_data_start
1801
# define DYNAMIC_LOADING
1806
# define MACH_TYPE "SH4"
1807
# define OS_TYPE "MSWINCE"
1808
# define ALIGNMENT 4
1809
# define DATAEND /* not needed */
1813
# define CPP_WORDSZ 32
1814
# define MACH_TYPE "M32R"
1815
# define ALIGNMENT 4
1817
# define OS_TYPE "LINUX"
1818
# define LINUX_STACKBOTTOM
1820
# define STACK_GRAN 0x10000000
1821
# define DYNAMIC_LOADING
1822
# define SEARCH_FOR_DATA_START
1824
# define DATAEND (_end)
1829
# define MACH_TYPE "X86_64"
1830
# define ALIGNMENT 8
1831
# define CPP_WORDSZ 64
1833
# define HBLKSIZE 4096
1835
# define CACHE_LINE_SIZE 64
1837
# define OS_TYPE "LINUX"
1838
# define LINUX_STACKBOTTOM
1839
# if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1840
# define MPROTECT_VDB
1842
/* We seem to get random errors in incremental mode, */
1843
/* possibly because Linux threads is itself a malloc client */
1844
/* and can't deal with the signals. */
1847
# define DYNAMIC_LOADING
1848
# ifdef UNDEFINED /* includes ro data */
1849
extern int _etext[];
1850
# define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1852
# include <features.h>
1853
# define SEARCH_FOR_DATA_START
1855
# define DATAEND (_end)
1858
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1860
# if defined(__GNUC__) && __GNUC__ >= 3
1861
# define PREFETCH(x) __builtin_prefetch((x), 0, 0)
1862
# define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
1866
# define OS_TYPE "FREEBSD"
1867
# ifndef GC_FREEBSD_THREADS
1868
# define MPROTECT_VDB
1871
# define SIG_SUSPEND (32+6)
1872
# define SIG_THR_RESTART (32+5)
1874
# define DATAEND (_end)
1876
# define SIG_SUSPEND SIGUSR1
1877
# define SIG_THR_RESTART SIGUSR2
1879
# define FREEBSD_STACKBOTTOM
1881
# define DYNAMIC_LOADING
1883
extern char etext[];
1884
extern char * GC_FreeBSDGetDataStart();
1885
# define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1888
# define OS_TYPE "NETBSD"
1890
# define DYNAMIC_LOADING
1893
extern char etext[];
1894
# define SEARCH_FOR_DATA_START
1897
# define OS_TYPE "SOLARIS"
1898
# define ELF_CLASS ELFCLASS64
1899
extern int _etext[], _end[];
1900
extern ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1901
# define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
1902
# define DATAEND (_end)
1903
/* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1904
/* but reportedly breaks under 2.8. It appears that the stack */
1905
/* base is a property of the executable, so this should not break */
1906
/* old executables. */
1907
/* HEURISTIC2 probably works, but this appears to be preferable. */
1908
/* Apparently USRSTACK is defined to be USERLIMIT, but in some */
1909
/* installations that's undefined. We work around this with a */
1911
# include <sys/vmparam.h>
1913
/* This should work everywhere, but doesn't. */
1914
# define STACKBOTTOM USRSTACK
1918
/* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1919
/* It appears to be fixed in 2.8 and 2.9. */
1920
# ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1923
# define DYNAMIC_LOADING
1924
# if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1926
/* Otherwise we now use calloc. Mmap may result in the */
1927
/* heap interleaved with thread stacks, which can result in */
1928
/* excessive blacklisting. Sbrk is unusable since it */
1929
/* doesn't interact correctly with the system malloc. */
1932
# define HEAP_START (ptr_t)0x40000000
1934
# define HEAP_START DATAEND
1939
#if defined(LINUX) && defined(USE_MMAP)
1940
/* The kernel may do a somewhat better job merging mappings etc. */
1941
/* with anonymous mappings. */
1942
# define USE_MMAP_ANON
1945
#if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC)
1946
/* Nptl allocates thread stacks with mmap, which is fine. But it */
1947
/* keeps a cache of thread stacks. Thread stacks contain the */
1948
/* thread control blocks. These in turn contain a pointer to */
1949
/* (sizeof (void *) from the beginning of) the dtv for thread-local */
1950
/* storage, which is calloc allocated. If we don't scan the cached */
1951
/* thread stacks, we appear to lose the dtv. This tends to */
1952
/* result in something that looks like a bogus dtv count, which */
1953
/* tends to result in a memset call on a block that is way too */
1954
/* large. Sometimes we're lucky and the process just dies ... */
1955
/* There seems to be a similar issue with some other memory */
1956
/* allocated by the dynamic loader. */
1957
/* This can be avoided by either: */
1958
/* - Defining USE_PROC_FOR_LIBRARIES here. */
1959
/* That performs very poorly, precisely because we end up */
1960
/* scanning cached stacks. */
1961
/* - Have calloc look at its callers. That is currently what we do.*/
1962
/* In spite of the fact that it is gross and disgusting. */
1963
/* # define USE_PROC_FOR_LIBRARIES */
1966
# ifndef STACK_GROWS_UP
1967
# define STACK_GROWS_DOWN
1971
# define CPP_WORDSZ 32
1980
# define DATAEND (end)
1983
# if defined(SVR4) && !defined(GETPAGESIZE)
1984
# include <unistd.h>
1985
# define GETPAGESIZE() sysconf(_SC_PAGESIZE)
1988
# ifndef GETPAGESIZE
1989
# if defined(SOLARIS) || defined(IRIX5) || defined(LINUX) \
1990
|| defined(NETBSD) || defined(FREEBSD) || defined(HPUX)
1991
# include <unistd.h>
1993
# define GETPAGESIZE() getpagesize()
1996
# if defined(SOLARIS) || defined(DRSNX) || defined(UTS4)
1997
/* OS has SVR4 generic features. */
1998
/* Probably others also qualify. */
2002
# if defined(SOLARIS) || defined(DRSNX)
2003
/* OS has SOLARIS style semi-undocumented interface */
2004
/* to dynamic loader. */
2006
/* OS has SOLARIS style signal handlers. */
2014
# if defined(FREEBSD) && \
2015
(defined(__DragonFly__) || __FreeBSD__ >= 4 || (__FreeBSD_kernel__ >= 4))
2019
# ifdef GC_NETBSD_THREADS
2020
# define SIGRTMIN 33
2021
# define SIGRTMAX 63
2024
# if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2025
|| defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2026
|| defined(DGUX) || defined(BSD) \
2027
|| defined(AIX) || defined(DARWIN) || defined(OSF1)
2028
# define UNIX_LIKE /* Basic Unix-like system calls work. */
2031
# if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2036
# undef DYNAMIC_LOADING
2041
# undef MPROTECT_VDB
2046
/* Postponed for now. */
2048
# undef MPROTECT_VDB
2051
# ifdef SMALL_CONFIG
2052
/* Presumably not worth the space it takes. */
2054
# undef MPROTECT_VDB
2058
# undef MPROTECT_VDB /* Can't deal with address space holes. */
2061
# ifdef PARALLEL_MARK
2062
# undef MPROTECT_VDB /* For now. */
2065
# if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB) \
2066
&& !defined(GWW_VDB)
2067
# define DEFAULT_VDB
2071
# define PREFETCH(x)
2072
# define NO_PREFETCH
2075
# ifndef PREFETCH_FOR_WRITE
2076
# define PREFETCH_FOR_WRITE(x)
2077
# define NO_PREFETCH_FOR_WRITE
2080
# ifndef CACHE_LINE_SIZE
2081
# define CACHE_LINE_SIZE 32 /* Wild guess */
2084
# if defined(LINUX) || defined(__GLIBC__)
2085
# define REGISTER_LIBRARIES_EARLY
2086
/* We sometimes use dl_iterate_phdr, which may acquire an internal */
2087
/* lock. This isn't safe after the world has stopped. So we must */
2088
/* call GC_register_dynamic_libraries before stopping the world. */
2089
/* For performance reasons, this may be beneficial on other */
2090
/* platforms as well, though it should be avoided in win32. */
2093
# if defined(SEARCH_FOR_DATA_START)
2094
extern ptr_t GC_data_start;
2095
# define DATASTART GC_data_start
2098
# ifndef CLEAR_DOUBLE
2099
# define CLEAR_DOUBLE(x) \
2100
((word*)x)[0] = 0; \
2102
# endif /* CLEAR_DOUBLE */
2104
# if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
2105
&& !defined(INCLUDE_LINUX_THREAD_DESCR)
2106
/* Will not work, since libc and the dynamic loader use thread */
2107
/* locals, sometimes as the only reference. */
2108
# define INCLUDE_LINUX_THREAD_DESCR
2111
# if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2112
--> inconsistent configuration
2114
# if defined(GC_LINUX_THREADS) && !defined(LINUX)
2115
--> inconsistent configuration
2117
# if defined(GC_NETBSD_THREADS) && !defined(NETBSD)
2118
--> inconsistent configuration
2120
# if defined(GC_SOLARIS_THREADS) && !defined(SOLARIS)
2121
--> inconsistent configuration
2123
# if defined(GC_HPUX_THREADS) && !defined(HPUX)
2124
--> inconsistent configuration
2126
# if defined(GC_AIX_THREADS) && !defined(_AIX)
2127
--> inconsistent configuration
2129
# if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2130
--> inconsistent configuration
2133
# if defined(PCR) || defined(SRC_M3) || \
2134
defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2135
defined(GC_PTHREADS)
2139
# if !defined(USE_MARK_BITS) && !defined(USE_MARK_BYTES)
2140
# if defined(THREADS) && defined(PARALLEL_MARK)
2141
# define USE_MARK_BYTES
2143
# define USE_MARK_BITS
2147
# if defined(MSWINCE)
2152
# define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
2153
/* include assembly code to do it well. */
2156
/* Can we save call chain in objects for debugging? */
2157
/* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
2158
/* frame) to reasonable values for the platform. */
2159
/* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
2160
/* at build time, though we feel free to adjust it slightly. */
2161
/* Define NEED_CALLINFO if we either save the call stack or */
2162
/* GC_ADD_CALLER is defined. */
2163
/* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
2166
# define CAN_SAVE_CALL_ARGS
2168
#if (defined(I386) || defined(X86_64)) && (defined(LINUX) || defined(__GLIBC__))
2169
/* SAVE_CALL_CHAIN is supported if the code is compiled to save */
2170
/* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
2171
# define CAN_SAVE_CALL_ARGS
2174
# if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2175
&& defined(GC_CAN_SAVE_CALL_STACKS)
2176
# define SAVE_CALL_CHAIN
2178
# ifdef SAVE_CALL_CHAIN
2179
# if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2180
# define NARGS SAVE_CALL_NARGS
2182
# define NARGS 0 /* Number of arguments to save for each call. */
2185
# ifdef SAVE_CALL_CHAIN
2186
# ifndef SAVE_CALL_COUNT
2187
# define NFRAMES 6 /* Number of frames to save. Even for */
2188
/* alignment reasons. */
2190
# define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2192
# define NEED_CALLINFO
2193
# endif /* SAVE_CALL_CHAIN */
2194
# ifdef GC_ADD_CALLER
2197
# define NEED_CALLINFO
2200
# if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2201
# define DBG_HDRS_ALL
2204
# if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2205
# define POINTER_SHIFT 0
2208
# if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2209
# define POINTER_MASK ((GC_word)(-1))
2212
# if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2213
# define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2216
# if defined(FIXUP_POINTER)
2217
# define NEED_FIXUP_POINTER 1
2219
# define NEED_FIXUP_POINTER 0
2220
# define FIXUP_POINTER(p)
2223
# if !defined(MARK_BIT_PER_GRANULE) && !defined(MARK_BIT_PER_OBJ)
2224
# define MARK_BIT_PER_GRANULE /* Usually faster */
2227
# if defined(MARK_BIT_PER_GRANULE) && defined(MARK_BIT_PER_OBJ)
2228
# error Define only one of MARK_BIT_PER_GRANULE and MARK_BIT_PER_OBJ.
2232
/* This relies on some type definitions from gc_priv.h, from */
2233
/* where it's normally included. */
2235
/* How to get heap memory from the OS: */
2236
/* Note that sbrk()-like allocation is preferred, since it */
2237
/* usually makes it possible to merge consecutively allocated */
2238
/* chunks. It also avoids unintented recursion with */
2239
/* -DREDIRECT_MALLOC. */
2240
/* GET_MEM() returns a HLKSIZE aligned chunk. */
2241
/* 0 is taken to mean failure. */
2242
/* In the case os USE_MMAP, the argument must also be a */
2243
/* physical page size. */
2244
/* GET_MEM is currently not assumed to retrieve 0 filled space, */
2245
/* though we should perhaps take advantage of the case in which */
2247
struct hblk; /* See gc_priv.h. */
2249
char * real_malloc();
2250
# define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2253
void * os2_alloc(size_t bytes);
2254
# define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2257
# elif defined(NEXT) || defined(DOS4GW) || defined(NONSTOP) || \
2258
(defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2259
(defined(SOLARIS) && !defined(USE_MMAP))
2260
# define GET_MEM(bytes) HBLKPTR((size_t) calloc(1, (size_t)bytes + GC_page_size) \
2262
# elif defined(MSWIN32)
2263
extern ptr_t GC_win32_get_mem();
2264
# define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2265
# elif defined(MACOS)
2266
# if defined(USE_TEMPORARY_MEMORY)
2267
extern Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory);
2268
# define GET_MEM(bytes) HBLKPTR( \
2269
GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2272
# define GET_MEM(bytes) HBLKPTR( \
2273
NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2275
# elif defined(MSWINCE)
2276
extern ptr_t GC_wince_get_mem();
2277
# define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2278
# elif defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2279
extern void *GC_amiga_get_mem(size_t size);
2280
# define GET_MEM(bytes) HBLKPTR((size_t) \
2281
GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2284
extern ptr_t GC_unix_get_mem();
2285
# define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2288
#endif /* GC_PRIVATE_H */
2290
# endif /* GCCONFIG_H */