Merge branch 'master' of http://github.com/mono/mono
[mono.git] / libgc / include / private / gcconfig.h
1 /* 
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.
6  *
7  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
9  *
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.
15  */
16
17 /*
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
22  * omitted.
23  */
24  
25 #ifndef GCCONFIG_H
26
27 # define GCCONFIG_H
28
29 # ifndef GC_PRIVATE_H
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 # endif
34
35 /* Machine dependent parameters.  Some tuning parameters can be found   */
36 /* near the top of gc_private.h.                                        */
37
38 /* Machine specific parts contributed by various people.  See README file. */
39
40 /* First a unified test for Linux: */
41 # if defined(linux) || defined(__linux__)
42 #  ifndef LINUX
43 #    define LINUX
44 #  endif
45 # endif
46
47 /* And one for NetBSD: */
48 # if defined(__NetBSD__)
49 #    define NETBSD
50 # endif
51
52 /* And one for OpenBSD: */
53 # if defined(__OpenBSD__)
54 #    define OPENBSD
55 # endif
56
57 /* And one for FreeBSD: */
58 # if defined(__FreeBSD__) && !defined(FREEBSD)
59 #    define FREEBSD
60 # endif
61
62 /* And one for Darwin: */
63 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
64 #   define DARWIN
65 # endif
66
67 /* Determine the machine type: */
68 # if defined(__arm__) || defined(__thumb__)
69 #    define ARM32
70 #    if !defined(LINUX) && !defined(NETBSD) && !defined(DARWIN)
71 #      define NOSYS
72 #      define mach_type_known
73 #    endif
74 # endif
75 # if defined(sun) && defined(mc68000)
76 #    define M68K
77 #    define SUNOS4
78 #    define mach_type_known
79 # endif
80 # if defined(hp9000s300)
81 #    define M68K
82 #    define HP
83 #    define mach_type_known
84 # endif
85 # if defined(OPENBSD) && defined(m68k)
86 #    define M68K
87 #    define mach_type_known
88 # endif
89 # if defined(OPENBSD) && defined(__sparc__)
90 #    define SPARC
91 #    define mach_type_known
92 # endif
93 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
94 #    define M68K
95 #    define mach_type_known
96 # endif
97 # if defined(NETBSD) && defined(__powerpc__)
98 #    define POWERPC
99 #    define mach_type_known
100 # endif
101 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
102 #    define ARM32
103 #    define mach_type_known
104 # endif
105 # if defined(NETBSD) && defined(__sh__)
106 #    define SH
107 #    define mach_type_known
108 # endif
109 # if defined(vax)
110 #    define VAX
111 #    ifdef ultrix
112 #       define ULTRIX
113 #    else
114 #       define BSD
115 #    endif
116 #    define mach_type_known
117 # endif
118 # if defined(__NetBSD__) && defined(__vax__)
119 #    define VAX
120 #    define mach_type_known
121 # endif
122 # if defined(mips) || defined(__mips) || defined(_mips)
123 #    define MIPS
124 #    if defined(nec_ews) || defined(_nec_ews)
125 #      define EWS4800
126 #    endif
127 #    if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD)
128 #      if defined(ultrix) || defined(__ultrix)
129 #        define ULTRIX
130 #      else
131 #        if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
132             || defined(__SYSTYPE_SVR4__)
133 #          define IRIX5   /* or IRIX 6.X */
134 #        else
135 #          define RISCOS  /* or IRIX 4.X */
136 #        endif
137 #      endif
138 #    endif /* !LINUX */
139 #    if defined(__NetBSD__) && defined(__MIPSEL__)
140 #      undef ULTRIX
141 #    endif
142 #    define mach_type_known
143 # endif
144 # if defined(DGUX) && (defined(i386) || defined(__i386__))
145 #    define I386
146 #    ifndef _USING_DGUX
147 #    define _USING_DGUX
148 #    endif
149 #    define mach_type_known
150 # endif
151 # if defined(sequent) && (defined(i386) || defined(__i386__))
152 #    define I386
153 #    define SEQUENT
154 #    define mach_type_known
155 # endif
156 # if defined(sun) && (defined(i386) || defined(__i386__))
157 #    define I386
158 #    define SUNOS5
159 #    define mach_type_known
160 # endif
161 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
162 #    define I386
163 #    define OS2
164 #    define mach_type_known
165 # endif
166 # if defined(ibm032)
167 #   define RT
168 #   define mach_type_known
169 # endif
170 # if defined(sun) && (defined(sparc) || defined(__sparc))
171 #   define SPARC
172     /* Test for SunOS 5.x */
173 #     include <errno.h>
174 #     ifdef ECHRNG
175 #       define SUNOS5
176 #     else
177 #       define SUNOS4
178 #     endif
179 #   define mach_type_known
180 # endif
181 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
182      && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
183 #   define SPARC
184 #   define DRSNX
185 #   define mach_type_known
186 # endif
187 # if defined(_IBMR2)
188 #   define RS6000
189 #   define mach_type_known
190 # endif
191 # if defined(__NetBSD__) && defined(__sparc__)
192 #   define SPARC
193 #   define mach_type_known
194 # endif
195 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
196         /* The above test may need refinement   */
197 #   define I386
198 #   if defined(_SCO_ELF)
199 #     define SCO_ELF
200 #   else
201 #     define SCO
202 #   endif
203 #   define mach_type_known
204 # endif
205 # if defined(_AUX_SOURCE)
206 #   define M68K
207 #   define SYSV
208 #   define mach_type_known
209 # endif
210 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
211      || defined(hppa) || defined(__hppa__)
212 #   define HP_PA
213 #   if !defined(LINUX) && !defined(HPUX)
214 #     define HPUX
215 #   endif
216 #   define mach_type_known
217 # endif
218 # if defined(__ia64) && defined(_HPUX_SOURCE)
219 #   define IA64
220 #   ifndef HPUX
221 #     define HPUX
222 #   endif
223 #   define mach_type_known
224 # endif
225 # if defined(__BEOS__) && defined(_X86_)
226 #    define I386
227 #    define BEOS
228 #    define mach_type_known
229 # endif
230 # if defined(LINUX) && (defined(i386) || defined(__i386__))
231 #    define I386
232 #    define mach_type_known
233 # endif
234 # if defined(LINUX) && defined(__x86_64__)
235 #    define X86_64
236 #    define mach_type_known
237 # endif
238 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
239 #    define IA64
240 #    define mach_type_known
241 # endif
242 # if defined(LINUX) && defined(__arm__)
243 #    define ARM32
244 #    define mach_type_known
245 # endif
246 # if defined(LINUX) && defined(__cris__)
247 #    ifndef CRIS
248 #       define CRIS
249 #    endif
250 #    define mach_type_known
251 # endif
252 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) || \
253                         defined(powerpc64) || defined(__powerpc64__))
254 #    define POWERPC
255 #    define mach_type_known
256 # endif
257 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
258 #    define POWERPC
259 #    define mach_type_known
260 # endif
261 # if defined(LINUX) && defined(__mc68000__)
262 #    define M68K
263 #    define mach_type_known
264 # endif
265 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
266 #    define SPARC
267 #    define mach_type_known
268 # endif
269 # if defined(LINUX) && defined(__arm__)
270 #    define ARM32
271 #    define mach_type_known
272 # endif
273 # if defined(LINUX) && defined(__sh__)
274 #    define SH
275 #    define mach_type_known
276 # endif
277 # if defined(LINUX) && defined(__m32r__)
278 #    define M32R
279 #    define mach_type_known
280 # endif
281 # if defined(__alpha) || defined(__alpha__)
282 #   define ALPHA
283 #   if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) && !defined(FREEBSD)
284 #     define OSF1       /* a.k.a Digital Unix */
285 #   endif
286 #   define mach_type_known
287 # endif
288 # if defined(_AMIGA) && !defined(AMIGA)
289 #   define AMIGA
290 # endif
291 # ifdef AMIGA 
292 #   define M68K
293 #   define mach_type_known
294 # endif
295 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
296 #   define M68K
297 #   define MACOS
298 #   define mach_type_known
299 # endif
300 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__)
301 #   define POWERPC
302 #   define MACOS
303 #   define mach_type_known
304 # endif
305 # ifdef DARWIN
306 #   if defined(__ppc__)  || defined(__ppc64__)
307 #    define POWERPC
308 #    define mach_type_known
309 #   elif defined(__i386__)
310 #    define I386
311 #    define mach_type_known
312 #    define DARWIN_DONT_PARSE_STACK
313 #    define OS_TYPE "DARWIN"
314 #    define DYNAMIC_LOADING
315      /* XXX: see get_end(3), get_etext() and get_end() should not be used.
316         These aren't used when dyld support is enabled (it is by default) */
317 #    define DATASTART ((ptr_t) get_etext())
318 #    define DATAEND     ((ptr_t) get_end())
319 #    define STACKBOTTOM ((ptr_t) 0xc0000000)
320 #    define USE_MMAP
321 #    define USE_MMAP_ANON
322 #    define USE_ASM_PUSH_REGS
323      /* This is potentially buggy. It needs more testing. See the comments in
324         os_dep.c.  It relies on threads to track writes. */
325 #    ifdef GC_DARWIN_THREADS
326 /* #       define MPROTECT_VDB -- diabled for now.  May work for some apps. */
327 #    endif
328 #    include <unistd.h>
329 #    define GETPAGESIZE() getpagesize()
330 #   elif defined(__arm__)
331 #    define ARM
332 #    define mach_type_known
333 #    define DARWIN_DONT_PARSE_STACK
334 #    define GC_DONT_REGISTER_MAIN_STATIC_DATA
335 #   elif defined(__x86_64)
336 #    define X86_64
337 #    define mach_type_known
338 #   endif
339 # endif
340 # if defined(NeXT) && defined(mc68000)
341 #   define M68K
342 #   define NEXT
343 #   define mach_type_known
344 # endif
345 # if defined(NeXT) && (defined(i386) || defined(__i386__))
346 #   define I386
347 #   define NEXT
348 #   define mach_type_known
349 # endif
350 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
351 #   define I386
352 #   define OPENBSD
353 #   define mach_type_known
354 # endif
355 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
356 #   define I386
357 #   define mach_type_known
358 # endif
359 # if defined(FREEBSD) && defined(__x86_64__)
360 #   define X86_64
361 #   define mach_type_known
362 # endif
363 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
364 #   define I386
365 #   define mach_type_known
366 # endif
367 # if defined(__NetBSD__) && defined(__x86_64__)
368 #    define X86_64
369 #    define mach_type_known
370 # endif
371 # if defined(FREEBSD) && defined(__sparc__)
372 #    define SPARC
373 #    define mach_type_known
374 #endif
375 # if defined(bsdi) && (defined(i386) || defined(__i386__))
376 #    define I386
377 #    define BSDI
378 #    define mach_type_known
379 # endif
380 # if !defined(mach_type_known) && defined(__386BSD__)
381 #   define I386
382 #   define THREE86BSD
383 #   define mach_type_known
384 # endif
385 # if defined(_CX_UX) && defined(_M88K)
386 #   define M88K
387 #   define CX_UX
388 #   define mach_type_known
389 # endif
390 # if defined(DGUX) && defined(m88k)
391 #   define M88K
392     /* DGUX defined */
393 #   define mach_type_known
394 # endif
395 # if defined(_WIN32_WCE)
396     /* SH3, SH4, MIPS already defined for corresponding architectures */
397 #   if defined(SH3) || defined(SH4)
398 #     define SH
399 #   endif
400 #   if defined(x86)
401 #     define I386
402 #   endif
403 #   if defined(ARM)
404 #     define ARM32
405 #   endif
406 #   define MSWINCE
407 #   define mach_type_known
408 # else
409 #   if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
410         || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
411 #     if defined(__LP64__) || defined(_WIN64)
412 #       define X86_64
413 #     else
414 #       define I386
415 #     endif
416 #     define MSWIN32    /* or Win64 */
417 #     define mach_type_known
418 #   endif
419 #   if defined(_MSC_VER) && defined(_M_IA64)
420 #     define IA64
421 #     define MSWIN32    /* Really win64, but we don't treat 64-bit      */
422                         /* variants as a differnt platform.             */
423 #   endif
424 # endif
425 # if defined(__DJGPP__)
426 #   define I386
427 #   ifndef DJGPP
428 #     define DJGPP  /* MSDOS running the DJGPP port of GCC */
429 #   endif
430 #   define mach_type_known
431 # endif
432 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
433 #   define I386
434 #   define CYGWIN32
435 #   define mach_type_known
436 # endif
437 # if defined(__MINGW32__)
438 #   define I386
439 #   define MSWIN32
440 #   define mach_type_known
441 # endif
442 # if defined(__BORLANDC__)
443 #   define I386
444 #   define MSWIN32
445 #   define mach_type_known
446 # endif
447 # if defined(_UTS) && !defined(mach_type_known)
448 #   define S370
449 #   define UTS4
450 #   define mach_type_known
451 # endif
452 # if defined(__pj__)
453 #   define PJ
454 #   define mach_type_known
455 # endif
456 # if defined(__embedded__) && defined(PPC)
457 #   define POWERPC
458 #   define NOSYS
459 #   define mach_type_known
460 # endif
461 /* Ivan Demakov */
462 # if defined(__WATCOMC__) && defined(__386__)
463 #   define I386
464 #   if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
465 #     if defined(__OS2__)
466 #       define OS2
467 #     else
468 #       if defined(__WINDOWS_386__) || defined(__NT__)
469 #         define MSWIN32
470 #       else
471 #         define DOS4GW
472 #       endif
473 #     endif
474 #   endif
475 #   define mach_type_known
476 # endif
477 # if defined(__s390__) && defined(LINUX)
478 #    define S390
479 #    define mach_type_known
480 # endif
481 # if defined(__GNU__)
482 #   if defined(__i386__)
483 /* The Debian Hurd running on generic PC */  
484 #     define  HURD
485 #     define  I386
486 #     define  mach_type_known
487 #    endif 
488 # endif
489
490 /* Feel free to add more clauses here */
491
492 /* Or manually define the machine type here.  A machine type is         */
493 /* characterized by the architecture.  Some                             */
494 /* machine types are further subdivided by OS.                          */
495 /* the macros ULTRIX, RISCOS, and BSD to distinguish.                   */
496 /* Note that SGI IRIX is treated identically to RISCOS.                 */
497 /* SYSV on an M68K actually means A/UX.                                 */
498 /* The distinction in these cases is usually the stack starting address */
499 # ifndef mach_type_known
500         --> unknown machine type
501 # endif
502                     /* Mapping is: M68K       ==> Motorola 680X0        */
503                     /*             (SUNOS4,HP,NEXT, and SYSV (A/UX),    */
504                     /*             MACOS and AMIGA variants)            */
505                     /*             I386       ==> Intel 386             */
506                     /*              (SEQUENT, OS2, SCO, LINUX, NETBSD,  */
507                     /*               FREEBSD, THREE86BSD, MSWIN32,      */
508                     /*               BSDI,SUNOS5, NEXT, other variants) */
509                     /*             NS32K      ==> Encore Multimax       */
510                     /*             MIPS       ==> R2000 or R3000        */
511                     /*                  (RISCOS, ULTRIX variants)       */
512                     /*             VAX        ==> DEC VAX               */
513                     /*                  (BSD, ULTRIX variants)          */
514                     /*             RS6000     ==> IBM RS/6000 AIX3.X    */
515                     /*             RT         ==> IBM PC/RT             */
516                     /*             HP_PA      ==> HP9000/700 & /800     */
517                     /*                            HP/UX, LINUX          */
518                     /*             SPARC      ==> SPARC v7/v8/v9        */
519                     /*                  (SUNOS4, SUNOS5, LINUX,         */
520                     /*                   DRSNX variants)                */
521                     /*             ALPHA      ==> DEC Alpha             */
522                     /*                  (OSF1 and LINUX variants)       */
523                     /*             M88K       ==> Motorola 88XX0        */
524                     /*                  (CX_UX and DGUX)                */
525                     /*             S370       ==> 370-like machine      */
526                     /*                  running Amdahl UTS4             */
527                     /*             S390       ==> 390-like machine      */
528                     /*                  running LINUX                   */
529                     /*             ARM32      ==> Intel StrongARM       */
530                     /*             IA64       ==> Intel IPF             */
531                     /*                            (e.g. Itanium)        */
532                     /*                  (LINUX and HPUX)                */
533                     /*             SH         ==> Hitachi SuperH        */
534                     /*                  (LINUX & MSWINCE)               */
535                     /*             X86_64     ==> AMD x86-64            */
536                     /*             POWERPC    ==> IBM/Apple PowerPC     */
537                     /*                  (MACOS(<=9),DARWIN(incl.MACOSX),*/
538                     /*                   LINUX, NETBSD, NOSYS variants) */
539                     /*                  Handles 32 and 64-bit variants. */
540                     /*                  AIX should be handled here, but */
541                     /*                  that's called an RS6000.        */
542                     /*             CRIS       ==> Axis Etrax            */
543                     /*             M32R       ==> Renesas M32R          */
544
545
546 /*
547  * For each architecture and OS, the following need to be defined:
548  *
549  * CPP_WORDSZ is a simple integer constant representing the word size.
550  * in bits.  We assume byte addressibility, where a byte has 8 bits.
551  * We also assume CPP_WORDSZ is either 32 or 64.
552  * (We care about the length of pointers, not hardware
553  * bus widths.  Thus a 64 bit processor with a C compiler that uses
554  * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
555  *
556  * MACH_TYPE is a string representation of the machine type.
557  * OS_TYPE is analogous for the OS.
558  *
559  * ALIGNMENT is the largest N, such that
560  * all pointer are guaranteed to be aligned on N byte boundaries.
561  * defining it to be 1 will always work, but perform poorly.
562  *
563  * DATASTART is the beginning of the data segment.
564  * On some platforms SEARCH_FOR_DATA_START is defined.
565  * SEARCH_FOR_DATASTART will cause GC_data_start to
566  * be set to an address determined by accessing data backwards from _end
567  * until an unmapped page is found.  DATASTART will be defined to be
568  * GC_data_start.
569  * On UNIX-like systems, the collector will scan the area between DATASTART
570  * and DATAEND for root pointers.
571  *
572  * DATAEND, if not `end' where `end' is defined as ``extern int end[];''.
573  * RTH suggests gaining access to linker script synth'd values with
574  * this idiom instead of `&end' where `end' is defined as ``extern int end;'' .
575  * Otherwise, ``GCC will assume these are in .sdata/.sbss'' and it will, e.g.,
576  * cause failures on alpha*-*-* with ``-msmall-data or -fpic'' or mips-*-*
577  * without any special options.
578  *
579  * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
580  * the pointer size.
581  *
582  * STACKBOTTOM is the cool end of the stack, which is usually the
583  * highest address in the stack.
584  * Under PCR or OS/2, we have other ways of finding thread stacks.
585  * For each machine, the following should:
586  * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
587  * 2) define exactly one of
588  *      STACKBOTTOM (should be defined to be an expression)
589  *      LINUX_STACKBOTTOM
590  *      HEURISTIC1
591  *      HEURISTIC2
592  * If STACKBOTTOM is defined, then it's value will be used directly as the
593  * stack base.  If LINUX_STACKBOTTOM is defined, then it will be determined
594  * with a method appropriate for most Linux systems.  Currently we look
595  * first for __libc_stack_end, and if that fails read it from /proc.
596  * If either of the last two macros are defined, then STACKBOTTOM is computed
597  * during collector startup using one of the following two heuristics:
598  * HEURISTIC1:  Take an address inside GC_init's frame, and round it up to
599  *              the next multiple of STACK_GRAN.
600  * HEURISTIC2:  Take an address inside GC_init's frame, increment it repeatedly
601  *              in small steps (decrement if STACK_GROWS_UP), and read the value
602  *              at each location.  Remember the value when the first
603  *              Segmentation violation or Bus error is signalled.  Round that
604  *              to the nearest plausible page boundary, and use that instead
605  *              of STACKBOTTOM.
606  *
607  * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
608  * the value of environ is a pointer that can serve as STACKBOTTOM.
609  * I expect that HEURISTIC2 can be replaced by this approach, which
610  * interferes far less with debugging.  However it has the disadvantage
611  * that it's confused by a putenv call before the collector is initialized.
612  * This could be dealt with by intercepting putenv ...
613  *
614  * If no expression for STACKBOTTOM can be found, and neither of the above
615  * heuristics are usable, the collector can still be used with all of the above
616  * undefined, provided one of the following is done:
617  * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
618  *    without reference to STACKBOTTOM.  This is appropriate for use in
619  *    conjunction with thread packages, since there will be multiple stacks.
620  *    (Allocating thread stacks in the heap, and treating them as ordinary
621  *    heap data objects is also possible as a last resort.  However, this is
622  *    likely to introduce significant amounts of excess storage retention
623  *    unless the dead parts of the thread stacks are periodically cleared.)
624  * 2) Client code may set GC_stackbottom before calling any GC_ routines.
625  *    If the author of the client code controls the main program, this is
626  *    easily accomplished by introducing a new main program, setting
627  *    GC_stackbottom to the address of a local variable, and then calling
628  *    the original main program.  The new main program would read something
629  *    like:
630  *
631  *              # include "gc_private.h"
632  *
633  *              main(argc, argv, envp)
634  *              int argc;
635  *              char **argv, **envp;
636  *              {
637  *                  int dummy;
638  *
639  *                  GC_stackbottom = (ptr_t)(&dummy);
640  *                  return(real_main(argc, argv, envp));
641  *              }
642  *
643  *
644  * Each architecture may also define the style of virtual dirty bit
645  * implementation to be used:
646  *   MPROTECT_VDB: Write protect the heap and catch faults.
647  *   PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
648  *
649  * An architecture may define DYNAMIC_LOADING if dynamic_load.c
650  * defined GC_register_dynamic_libraries() for the architecture.
651  *
652  * An architecture may define PREFETCH(x) to preload the cache with *x.
653  * This defaults to a no-op.
654  *
655  * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
656  *
657  * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
658  * clear the two words at GC_malloc-aligned address x.  By default,
659  * word stores of 0 are used instead.
660  *
661  * HEAP_START may be defined as the initial address hint for mmap-based
662  * allocation.
663  */
664
665 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
666  * to push the relevant registers onto the stack.  This generally makes
667  * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
668  */
669 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
670                            (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)) \
671                        && !defined(__INTEL_COMPILER) \
672                        && !defined(__PATHCC__)
673 #   define HAVE_BUILTIN_UNWIND_INIT
674 # endif
675
676 # define STACK_GRAN 0x1000000
677 # ifdef M68K
678 #   define MACH_TYPE "M68K"
679 #   define ALIGNMENT 2
680 #   ifdef OPENBSD
681 #       define OS_TYPE "OPENBSD"
682 #       define HEURISTIC2
683 #       ifdef __ELF__
684 #         define DATASTART GC_data_start
685 #         define DYNAMIC_LOADING
686 #       else
687           extern char etext[];
688 #         define DATASTART ((ptr_t)(etext))
689 #       endif
690 #       define USE_GENERIC_PUSH_REGS
691 #   endif
692 #   ifdef NETBSD
693 #       define OS_TYPE "NETBSD"
694 #       define HEURISTIC2
695 #       ifdef __ELF__
696 #         define DATASTART GC_data_start
697 #         define DYNAMIC_LOADING
698 #       else
699           extern char etext[];
700 #         define DATASTART ((ptr_t)(etext))
701 #       endif
702 #       define USE_GENERIC_PUSH_REGS
703 #   endif
704 #   ifdef LINUX
705 #       define OS_TYPE "LINUX"
706 #       define STACKBOTTOM ((ptr_t)0xf0000000)
707 #       define USE_GENERIC_PUSH_REGS
708                 /* We never got around to the assembly version. */
709 /* #       define MPROTECT_VDB - Reported to not work  9/17/01 */
710 #       ifdef __ELF__
711 #            define DYNAMIC_LOADING
712 #            include <features.h>
713 #            if defined(__GLIBC__)&& __GLIBC__>=2
714 #              define SEARCH_FOR_DATA_START
715 #            else /* !GLIBC2 */
716 #              if defined(PLATFORM_ANDROID)
717 #                      define __environ environ
718 #              endif
719                extern char **__environ;
720 #              define DATASTART ((ptr_t)(&__environ))
721                              /* hideous kludge: __environ is the first */
722                              /* word in crt0.o, and delimits the start */
723                              /* of the data segment, no matter which   */
724                              /* ld options were passed through.        */
725                              /* We could use _etext instead, but that  */
726                              /* would include .rodata, which may       */
727                              /* contain large read-only data tables    */
728                              /* that we'd rather not scan.             */
729 #            endif /* !GLIBC2 */
730              extern int _end[];
731 #            define DATAEND (_end)
732 #       else
733              extern int etext[];
734 #            define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
735 #       endif
736 #   endif
737 #   ifdef SUNOS4
738 #       define OS_TYPE "SUNOS4"
739         extern char etext[];
740 #       define DATASTART ((ptr_t)((((word) (etext)) + 0x1ffff) & ~0x1ffff))
741 #       define HEURISTIC1       /* differs      */
742 #       define DYNAMIC_LOADING
743 #   endif
744 #   ifdef HP
745 #       define OS_TYPE "HP"
746         extern char etext[];
747 #       define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
748 #       define STACKBOTTOM ((ptr_t) 0xffeffffc)
749                               /* empirically determined.  seems to work. */
750 #       include <unistd.h>
751 #       define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
752 #   endif
753 #   ifdef SYSV
754 #       define OS_TYPE "SYSV"
755         extern etext[];
756 #       define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
757                                    & ~0x3fffff) \
758                                   +((word)etext & 0x1fff))
759         /* This only works for shared-text binaries with magic number 0413.
760            The other sorts of SysV binaries put the data at the end of the text,
761            in which case the default of etext would work.  Unfortunately,
762            handling both would require having the magic-number available.
763                                 -- Parag
764            */
765 #       define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
766                         /* The stack starts at the top of memory, but   */
767                         /* 0x0 cannot be used as setjump_test complains */
768                         /* that the stack direction is incorrect.  Two  */
769                         /* bytes down from 0x0 should be safe enough.   */
770                         /*              --Parag                         */
771 #       include <sys/mmu.h>
772 #       define GETPAGESIZE() PAGESIZE   /* Is this still right? */
773 #   endif
774 #   ifdef AMIGA
775 #       define OS_TYPE "AMIGA"
776                 /* STACKBOTTOM and DATASTART handled specially  */
777                 /* in os_dep.c                                  */
778 #       define DATAEND  /* not needed */
779 #       define GETPAGESIZE() 4096
780 #   endif
781 #   ifdef MACOS
782 #     ifndef __LOWMEM__
783 #     include <LowMem.h>
784 #     endif
785 #     define OS_TYPE "MACOS"
786                         /* see os_dep.c for details of global data segments. */
787 #     define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
788 #     define DATAEND    /* not needed */
789 #     define GETPAGESIZE() 4096
790 #   endif
791 #   ifdef NEXT
792 #       define OS_TYPE "NEXT"
793 #       define DATASTART ((ptr_t) get_etext())
794 #       define STACKBOTTOM ((ptr_t) 0x4000000)
795 #       define DATAEND  /* not needed */
796 #   endif
797 # endif
798
799 # if defined(POWERPC)
800 #   define MACH_TYPE "POWERPC"
801 #   ifdef MACOS
802 #     define ALIGNMENT 2  /* Still necessary?  Could it be 4?   */
803 #     ifndef __LOWMEM__
804 #     include <LowMem.h>
805 #     endif
806 #     define OS_TYPE "MACOS"
807                         /* see os_dep.c for details of global data segments. */
808 #     define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
809 #     define DATAEND  /* not needed */
810 #   endif
811
812 #   ifdef LINUX
813 #     if defined(__powerpc64__)
814 #       define ALIGNMENT 8
815 #       define CPP_WORDSZ 64
816 #       ifndef HBLKSIZE
817 #         define HBLKSIZE 4096
818 #       endif
819 #     else
820 #       define ALIGNMENT 4
821 #     endif
822 #     define OS_TYPE "LINUX"
823       /* HEURISTIC1 has been reliably reported to fail for a 32-bit     */
824       /* executable on a 64 bit kernel.                                 */
825 #     define LINUX_STACKBOTTOM
826 #     define DYNAMIC_LOADING
827 #     define SEARCH_FOR_DATA_START
828       extern int _end[];
829 #     define DATAEND (_end)
830 #   endif
831 #   ifdef DARWIN
832 #     ifdef __ppc64__
833 #       define ALIGNMENT 8
834 #       define CPP_WORDSZ 64
835 #     else
836 #       define ALIGNMENT 4
837 #     endif
838 #     define OS_TYPE "DARWIN"
839 #     define DYNAMIC_LOADING
840       /* XXX: see get_end(3), get_etext() and get_end() should not be used.
841          These aren't used when dyld support is enabled (it is by default) */
842 #     define DATASTART ((ptr_t) get_etext())
843 #     define DATAEND    ((ptr_t) get_end())
844 #     define STACKBOTTOM ((ptr_t) 0xc0000000)
845 #     define USE_MMAP
846 #     define USE_MMAP_ANON
847 #     define USE_ASM_PUSH_REGS
848       /* This is potentially buggy. It needs more testing. See the comments in
849          os_dep.c.  It relies on threads to track writes. */
850 #     ifdef GC_DARWIN_THREADS
851 /* #       define MPROTECT_VDB -- diabled for now.  May work for some apps. */
852 #     endif
853 #     include <unistd.h>
854 #     define GETPAGESIZE() getpagesize()
855 #     if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
856         /* The performance impact of prefetches is untested */
857 #       define PREFETCH(x) \
858           __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
859 #       define PREFETCH_FOR_WRITE(x) \
860           __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
861 #     endif
862       /* There seems to be some issues with trylock hanging on darwin. This
863          should be looked into some more */
864 #     define NO_PTHREAD_TRYLOCK
865 #   endif
866 #   ifdef FREEBSD
867 #       define ALIGNMENT 4
868 #       define OS_TYPE "FREEBSD"
869 #       ifndef GC_FREEBSD_THREADS
870 #           define MPROTECT_VDB
871 #       endif
872 #       define SIG_SUSPEND SIGUSR1
873 #       define SIG_THR_RESTART SIGUSR2
874 #       define FREEBSD_STACKBOTTOM
875 #       ifdef __ELF__
876 #           define DYNAMIC_LOADING
877 #       endif
878         extern char etext[];
879         extern char * GC_FreeBSDGetDataStart();
880 #       define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
881 #   endif
882 #   ifdef NETBSD
883 #     define ALIGNMENT 4
884 #     define OS_TYPE "NETBSD"
885 #     define HEURISTIC2
886       extern char etext[];
887 #     define DATASTART GC_data_start
888 #     define DYNAMIC_LOADING
889 #   endif
890 #   ifdef SN_TARGET_PS3
891 #       define NO_GETENV
892 #       define CPP_WORDSZ 32
893 #       define ALIGNMENT 4
894         extern int _end [];
895 //       extern int _dso_handle[];
896                 extern int __bss_start;
897
898 #       define DATAEND (_end)
899 #       define DATASTART (__bss_start)
900 #       define STACKBOTTOM ((ptr_t) ps3_get_stack_bottom ())
901 #       define USE_GENERIC_PUSHREGS
902 #   endif
903
904 #   ifdef NOSYS
905 #     define ALIGNMENT 4
906 #     define OS_TYPE "NOSYS"
907       extern void __end[], __dso_handle[];
908 #     define DATASTART (__dso_handle)  /* OK, that's ugly.  */
909 #     define DATAEND (__end)
910         /* Stack starts at 0xE0000000 for the simulator.  */
911 #     undef STACK_GRAN
912 #     define STACK_GRAN 0x10000000
913 #     define HEURISTIC1
914 #   endif
915 # endif
916
917 # ifdef VAX
918 #   define MACH_TYPE "VAX"
919 #   define ALIGNMENT 4  /* Pointers are longword aligned by 4.2 C compiler */
920     extern char etext[];
921 #   define DATASTART ((ptr_t)(etext))
922 #   ifdef BSD
923 #       define OS_TYPE "BSD"
924 #       define HEURISTIC1
925                         /* HEURISTIC2 may be OK, but it's hard to test. */
926 #   endif
927 #   ifdef ULTRIX
928 #       define OS_TYPE "ULTRIX"
929 #       define STACKBOTTOM ((ptr_t) 0x7fffc800)
930 #   endif
931 # endif
932
933 # ifdef RT
934 #   define MACH_TYPE "RT"
935 #   define ALIGNMENT 4
936 #   define DATASTART ((ptr_t) 0x10000000)
937 #   define STACKBOTTOM ((ptr_t) 0x1fffd800)
938 # endif
939
940 # ifdef SPARC
941 #   define MACH_TYPE "SPARC"
942 #   if defined(__arch64__) || defined(__sparcv9)
943 #     define ALIGNMENT 8
944 #     define CPP_WORDSZ 64
945 #     define ELF_CLASS ELFCLASS64
946 #   else
947 #     define ALIGNMENT 4        /* Required by hardware */
948 #     define CPP_WORDSZ 32
949 #   endif
950 #   define ALIGN_DOUBLE
951 #   ifdef _FILE_OFFSET_BITS
952 #     undef _FILE_OFFSET_BITS /* libelf.h & procfs.h doesn't compile with large file support */
953 #     define _FILE_OFFSET_BITS 32
954 #   endif
955 #   ifdef SUNOS5
956 #       define OS_TYPE "SUNOS5"
957         extern int _etext[];
958         extern int _end[];
959         extern ptr_t GC_SysVGetDataStart();
960 #       define DATASTART GC_SysVGetDataStart(0x10000, _etext)
961 #       define DATAEND (_end)
962 #       if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
963 #           define USE_MMAP
964             /* Otherwise we now use calloc.  Mmap may result in the     */
965             /* heap interleaved with thread stacks, which can result in */
966             /* excessive blacklisting.  Sbrk is unusable since it       */
967             /* doesn't interact correctly with the system malloc.       */
968 #       endif
969 #       ifdef USE_MMAP
970 #         define HEAP_START (ptr_t)0x40000000
971 #       else
972 #         define HEAP_START DATAEND
973 #       endif
974 #       define PROC_VDB
975 /*      HEURISTIC1 reportedly no longer works under 2.7.                */
976 /*      HEURISTIC2 probably works, but this appears to be preferable.   */
977 /*      Apparently USRSTACK is defined to be USERLIMIT, but in some     */
978 /*      installations that's undefined.  We work around this with a     */
979 /*      gross hack:                                                     */
980 #       include <sys/vmparam.h>
981 #       ifdef USERLIMIT
982           /* This should work everywhere, but doesn't.  */
983 #         define STACKBOTTOM USRSTACK
984 #       else
985 #         define HEURISTIC2
986 #       endif
987 #       include <unistd.h>
988 #       define GETPAGESIZE()  sysconf(_SC_PAGESIZE)
989                 /* getpagesize() appeared to be missing from at least one */
990                 /* Solaris 5.4 installation.  Weird.                      */
991 #       define DYNAMIC_LOADING
992 #   endif
993 #   ifdef SUNOS4
994 #       define OS_TYPE "SUNOS4"
995         /* [If you have a weak stomach, don't read this.]               */
996         /* We would like to use:                                        */
997 /* #       define DATASTART ((ptr_t)((((word) (etext)) + 0x1fff) & ~0x1fff)) */
998         /* This fails occasionally, due to an ancient, but very         */
999         /* persistent ld bug.  etext is set 32 bytes too high.          */
1000         /* We instead read the text segment size from the a.out         */
1001         /* header, which happens to be mapped into our address space    */
1002         /* at the start of the text segment.  The detective work here   */
1003         /* was done by Robert Ehrlich, Manuel Serrano, and Bernard      */
1004         /* Serpette of INRIA.                                           */
1005         /* This assumes ZMAGIC, i.e. demand-loadable executables.       */
1006 #       define TEXTSTART 0x2000
1007 #       define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
1008 #       define MPROTECT_VDB
1009 #       define HEURISTIC1
1010 #       define DYNAMIC_LOADING
1011 #   endif
1012 #   ifdef DRSNX
1013 #       define OS_TYPE "DRSNX"
1014         extern ptr_t GC_SysVGetDataStart();
1015         extern int etext[];
1016 #       define DATASTART GC_SysVGetDataStart(0x10000, etext)
1017 #       define MPROTECT_VDB
1018 #       define STACKBOTTOM ((ptr_t) 0xdfff0000)
1019 #       define DYNAMIC_LOADING
1020 #   endif
1021 #   ifdef LINUX
1022 #     define OS_TYPE "LINUX"
1023 #     ifdef __ELF__
1024 #       define DYNAMIC_LOADING
1025 #     else
1026           Linux Sparc/a.out not supported
1027 #     endif
1028 #     define SVR4
1029 #     include <features.h>
1030 #     if defined(__GLIBC__) && __GLIBC__ >= 2
1031 #       define SEARCH_FOR_DATA_START
1032 #     else
1033           extern char **__environ;
1034 #         define DATASTART ((ptr_t)(&__environ))
1035                      /* hideous kludge: __environ is the first */
1036                      /* word in crt0.o, and delimits the start */
1037                      /* of the data segment, no matter which   */
1038                      /* ld options were passed through.        */
1039                      /* We could use _etext instead, but that  */
1040                      /* would include .rodata, which may       */
1041                      /* contain large read-only data tables    */
1042                      /* that we'd rather not scan.             */
1043 #     endif
1044       extern int _end[];
1045 #     define DATAEND (_end)
1046 #     define LINUX_STACKBOTTOM
1047 #   endif
1048 #   ifdef OPENBSD
1049 #     define OS_TYPE "OPENBSD"
1050 #     define STACKBOTTOM ((ptr_t) 0xf8000000)
1051       extern int etext[];
1052 #     define DATASTART ((ptr_t)(etext))
1053 #   endif
1054 #   ifdef NETBSD
1055 #     define OS_TYPE "NETBSD"
1056 #     define HEURISTIC2
1057 #     ifdef __ELF__
1058 #       define DATASTART GC_data_start
1059 #       define DYNAMIC_LOADING
1060 #     else
1061         extern char etext[];
1062 #       define DATASTART ((ptr_t)(etext))
1063 #     endif
1064 #   endif
1065 #   ifdef FREEBSD
1066 #       define OS_TYPE "FREEBSD"
1067 #       define SIG_SUSPEND SIGUSR1
1068 #       define SIG_THR_RESTART SIGUSR2
1069 #       define FREEBSD_STACKBOTTOM
1070 #       ifdef __ELF__
1071 #           define DYNAMIC_LOADING
1072 #       endif
1073         extern char etext[];
1074         extern char edata[];
1075         extern char end[];
1076 #       define NEED_FIND_LIMIT
1077 #       define DATASTART ((ptr_t)(&etext))
1078 #       define DATAEND (GC_find_limit (DATASTART, TRUE))
1079 #       define DATASTART2 ((ptr_t)(&edata))
1080 #       define DATAEND2 ((ptr_t)(&end))
1081 #   endif
1082 # endif
1083
1084 # ifdef I386
1085 #   define MACH_TYPE "I386"
1086 #   if defined(__LP64__) || defined(_WIN64)
1087 #     define CPP_WORDSZ 64
1088 #     define ALIGNMENT 8
1089 #   else
1090 #     define CPP_WORDSZ 32
1091 #     define ALIGNMENT 4
1092                         /* Appears to hold for all "32 bit" compilers   */
1093                         /* except Borland.  The -a4 option fixes        */
1094                         /* Borland.                                     */
1095                         /* Ivan Demakov: For Watcom the option is -zp4. */
1096 #   endif
1097 #   ifndef SMALL_CONFIG
1098 #     define ALIGN_DOUBLE /* Not strictly necessary, but may give speed   */
1099                           /* improvement on Pentiums.                     */
1100 #   endif
1101 #   ifdef HAVE_BUILTIN_UNWIND_INIT
1102 #       define USE_GENERIC_PUSH_REGS
1103 #   endif
1104 #   ifdef SEQUENT
1105 #       define OS_TYPE "SEQUENT"
1106         extern int etext[];
1107 #       define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1108 #       define STACKBOTTOM ((ptr_t) 0x3ffff000) 
1109 #   endif
1110 #   ifdef BEOS
1111 #     define OS_TYPE "BEOS"
1112 #     include <OS.h>
1113 #     define GETPAGESIZE() B_PAGE_SIZE
1114       extern int etext[];
1115 #     define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1116 #   endif
1117 #   ifdef SUNOS5
1118 #       define OS_TYPE "SUNOS5"
1119         extern int _etext[], _end[];
1120         extern ptr_t GC_SysVGetDataStart();
1121 #       define DATASTART GC_SysVGetDataStart(0x1000, _etext)
1122 #       define DATAEND (_end)
1123 /*      # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7,      */
1124 /*      but reportedly breaks under 2.8.  It appears that the stack     */
1125 /*      base is a property of the executable, so this should not break  */
1126 /*      old executables.                                                */
1127 /*      HEURISTIC2 probably works, but this appears to be preferable.   */
1128 #       include <sys/vm.h>
1129 #       define STACKBOTTOM USRSTACK
1130 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1131 /* It appears to be fixed in 2.8 and 2.9.                               */
1132 #       ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1133 /* Reading of dirty bits doesn't seem to work even in solaris 10 */
1134 /*#       define PROC_VDB */
1135 #       endif
1136 #       define DYNAMIC_LOADING
1137 #       if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1138 #           define USE_MMAP
1139             /* Otherwise we now use calloc.  Mmap may result in the     */
1140             /* heap interleaved with thread stacks, which can result in */
1141             /* excessive blacklisting.  Sbrk is unusable since it       */
1142             /* doesn't interact correctly with the system malloc.       */
1143 #       endif
1144 #       ifdef USE_MMAP
1145 #         define HEAP_START (ptr_t)0x40000000
1146 #       else
1147 #         define HEAP_START DATAEND
1148 #       endif
1149 #   endif
1150 #   ifdef SCO
1151 #       define OS_TYPE "SCO"
1152         extern int etext[];
1153 #       define DATASTART ((ptr_t)((((word) (etext)) + 0x3fffff) \
1154                                   & ~0x3fffff) \
1155                                  +((word)etext & 0xfff))
1156 #       define STACKBOTTOM ((ptr_t) 0x7ffffffc)
1157 #   endif
1158 #   ifdef SCO_ELF
1159 #       define OS_TYPE "SCO_ELF"
1160         extern int etext[];
1161 #       define DATASTART ((ptr_t)(etext))
1162 #       define STACKBOTTOM ((ptr_t) 0x08048000)
1163 #       define DYNAMIC_LOADING
1164 #       define ELF_CLASS ELFCLASS32
1165 #   endif
1166 #   ifdef DGUX
1167 #       define OS_TYPE "DGUX"
1168         extern int _etext, _end;
1169         extern ptr_t GC_SysVGetDataStart();
1170 #       define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
1171 #       define DATAEND (&_end)
1172 #       define STACK_GROWS_DOWN
1173 #       define HEURISTIC2
1174 #       include <unistd.h>
1175 #       define GETPAGESIZE()  sysconf(_SC_PAGESIZE)
1176 #       define DYNAMIC_LOADING
1177 #       ifndef USE_MMAP
1178 #         define USE_MMAP
1179 #       endif /* USE_MMAP */
1180 #       define MAP_FAILED (void *) -1
1181 #       ifdef USE_MMAP
1182 #         define HEAP_START (ptr_t)0x40000000
1183 #       else /* USE_MMAP */
1184 #         define HEAP_START DATAEND
1185 #       endif /* USE_MMAP */
1186 #   endif /* DGUX */
1187
1188 #   ifdef LINUX
1189 #       ifndef __GNUC__
1190           /* The Intel compiler doesn't like inline assembly */
1191 #         define USE_GENERIC_PUSH_REGS
1192 #       endif
1193 #       define OS_TYPE "LINUX"
1194 #       define LINUX_STACKBOTTOM
1195 #       if 0
1196 #         define HEURISTIC1
1197 #         undef STACK_GRAN
1198 #         define STACK_GRAN 0x10000000
1199           /* STACKBOTTOM is usually 0xc0000000, but this changes with   */
1200           /* different kernel configurations.  In particular, systems   */
1201           /* with 2GB physical memory will usually move the user        */
1202           /* address space limit, and hence initial SP to 0x80000000.   */
1203 #       endif
1204 #       if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1205 #           define MPROTECT_VDB
1206 #       else
1207             /* We seem to get random errors in incremental mode,        */
1208             /* possibly because Linux threads is itself a malloc client */
1209             /* and can't deal with the signals.                         */
1210 #       endif
1211 #       define HEAP_START (ptr_t)0x1000
1212                 /* This encourages mmap to give us low addresses,       */
1213                 /* thus allowing the heap to grow to ~3GB               */
1214 #       ifdef __ELF__
1215 #            define DYNAMIC_LOADING
1216 #            ifdef UNDEFINED    /* includes ro data */
1217                extern int _etext[];
1218 #              define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
1219 #            endif
1220 #            include <features.h>
1221 #            if defined(__GLIBC__) && __GLIBC__ >= 2
1222 #                define SEARCH_FOR_DATA_START
1223 #            else
1224                  extern char **__environ;
1225 #                define DATASTART ((ptr_t)(&__environ))
1226                               /* hideous kludge: __environ is the first */
1227                               /* word in crt0.o, and delimits the start */
1228                               /* of the data segment, no matter which   */
1229                               /* ld options were passed through.        */
1230                               /* We could use _etext instead, but that  */
1231                               /* would include .rodata, which may       */
1232                               /* contain large read-only data tables    */
1233                               /* that we'd rather not scan.             */
1234 #            endif
1235              extern int _end[];
1236 #            define DATAEND (_end)
1237 #       else
1238              extern int etext[];
1239 #            define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1240 #       endif
1241 #       ifdef USE_I686_PREFETCH
1242           /* FIXME: Thus should use __builtin_prefetch, but we'll leave that    */
1243           /* for the next rtelease.                                             */
1244 #         define PREFETCH(x) \
1245             __asm__ __volatile__ ("     prefetchnta     %0": : "m"(*(char *)(x)))
1246             /* Empirically prefetcht0 is much more effective at reducing        */
1247             /* cache miss stalls for the targetted load instructions.  But it   */
1248             /* seems to interfere enough with other cache traffic that the net  */
1249             /* result is worse than prefetchnta.                                */
1250 #         if 0 
1251             /* Using prefetches for write seems to have a slight negative       */
1252             /* impact on performance, at least for a PIII/500.                  */
1253 #           define PREFETCH_FOR_WRITE(x) \
1254               __asm__ __volatile__ ("   prefetcht0      %0": : "m"(*(char *)(x)))
1255 #         endif
1256 #       endif
1257 #       ifdef USE_3DNOW_PREFETCH
1258 #         define PREFETCH(x) \
1259             __asm__ __volatile__ ("     prefetch        %0": : "m"(*(char *)(x)))
1260 #         define PREFETCH_FOR_WRITE(x) \
1261             __asm__ __volatile__ ("     prefetchw       %0": : "m"(*(char *)(x)))
1262 #       endif
1263 #   endif
1264 #   ifdef CYGWIN32
1265 #       define OS_TYPE "CYGWIN32"
1266 #       define DATASTART ((ptr_t)GC_DATASTART)  /* From gc.h */
1267 #       define DATAEND   ((ptr_t)GC_DATAEND)
1268 #       undef STACK_GRAN
1269 #       define STACK_GRAN 0x10000
1270 #       define HEURISTIC1
1271 #   endif
1272 #   ifdef OS2
1273 #       define OS_TYPE "OS2"
1274                 /* STACKBOTTOM and DATASTART are handled specially in   */
1275                 /* os_dep.c. OS2 actually has the right                 */
1276                 /* system call!                                         */
1277 #       define DATAEND  /* not needed */
1278 #       define USE_GENERIC_PUSH_REGS
1279 #   endif
1280 #   ifdef MSWIN32
1281 #       define OS_TYPE "MSWIN32"
1282                 /* STACKBOTTOM and DATASTART are handled specially in   */
1283                 /* os_dep.c.                                            */
1284 #       ifndef __WATCOMC__
1285 #         define MPROTECT_VDB
1286 #       endif
1287 #       define DATAEND  /* not needed */
1288 #   endif
1289 #   ifdef MSWINCE
1290 #       define OS_TYPE "MSWINCE"
1291 #       define DATAEND  /* not needed */
1292 #   endif
1293 #   ifdef DJGPP
1294 #       define OS_TYPE "DJGPP"
1295 #       include "stubinfo.h"
1296         extern int etext[];
1297         extern int _stklen;
1298         extern int __djgpp_stack_limit;
1299 #       define DATASTART ((ptr_t)((((word) (etext)) + 0x1ff) & ~0x1ff))
1300 /* #       define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1301                                                      + _stklen)) */
1302 #       define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1303                 /* This may not be right.  */
1304 #   endif
1305 #   ifdef OPENBSD
1306 #       define OS_TYPE "OPENBSD"
1307 #   endif
1308 #   ifdef FREEBSD
1309 #       define OS_TYPE "FREEBSD"
1310 #       ifndef GC_FREEBSD_THREADS
1311 #           define MPROTECT_VDB
1312 #       endif
1313 #      define SIG_SUSPEND SIGTSTP
1314 #      define SIG_THR_RESTART SIGCONT
1315 #       define FREEBSD_STACKBOTTOM
1316 #       ifdef __ELF__
1317 #           define DYNAMIC_LOADING
1318 #       endif
1319         extern char etext[];
1320         extern char * GC_FreeBSDGetDataStart();
1321 #       define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
1322 #   endif
1323 #   ifdef NETBSD
1324 #       define OS_TYPE "NETBSD"
1325 #       ifdef __ELF__
1326 #           define DYNAMIC_LOADING
1327 #       endif
1328 #   endif
1329 #   ifdef THREE86BSD
1330 #       define OS_TYPE "THREE86BSD"
1331 #   endif
1332 #   ifdef BSDI
1333 #       define OS_TYPE "BSDI"
1334 #   endif
1335 #   if defined(OPENBSD) || defined(NETBSD) \
1336         || defined(THREE86BSD) || defined(BSDI)
1337 #       define HEURISTIC2
1338         extern char etext[];
1339 #       define DATASTART ((ptr_t)(etext))
1340 #   endif
1341 #   ifdef NEXT
1342 #       define OS_TYPE "NEXT"
1343 #       define DATASTART ((ptr_t) get_etext())
1344 #       define STACKBOTTOM ((ptr_t)0xc0000000)
1345 #       define DATAEND  /* not needed */
1346 #   endif
1347 #   ifdef DOS4GW
1348 #     define OS_TYPE "DOS4GW"
1349       extern long __nullarea;
1350       extern char _end;
1351       extern char *_STACKTOP;
1352       /* Depending on calling conventions Watcom C either precedes
1353          or does not precedes with undescore names of C-variables.
1354          Make sure startup code variables always have the same names.  */
1355       #pragma aux __nullarea "*";
1356       #pragma aux _end "*";
1357 #     define STACKBOTTOM ((ptr_t) _STACKTOP)
1358                          /* confused? me too. */
1359 #     define DATASTART ((ptr_t) &__nullarea)
1360 #     define DATAEND ((ptr_t) &_end)
1361 #   endif
1362 #   ifdef HURD
1363 #     define OS_TYPE "HURD"
1364 #     define STACK_GROWS_DOWN
1365 #     define HEURISTIC2
1366       extern int  __data_start[];
1367 #     define DATASTART ( (ptr_t) (__data_start))
1368       extern int   _end[];
1369 #     define DATAEND ( (ptr_t) (_end))
1370 /* #     define MPROTECT_VDB  Not quite working yet? */
1371 #     define DYNAMIC_LOADING
1372 #   endif
1373 # endif
1374
1375 # ifdef NS32K
1376 #   define MACH_TYPE "NS32K"
1377 #   define ALIGNMENT 4
1378     extern char **environ;
1379 #   define DATASTART ((ptr_t)(&environ))
1380                               /* hideous kludge: environ is the first   */
1381                               /* word in crt0.o, and delimits the start */
1382                               /* of the data segment, no matter which   */
1383                               /* ld options were passed through.        */
1384 #   define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1385 # endif
1386
1387 # ifdef MIPS
1388 #   define MACH_TYPE "MIPS"
1389 #   ifdef LINUX
1390       /* This was developed for a linuxce style platform.  Probably     */
1391       /* needs to be tweaked for workstation class machines.            */
1392 #     define OS_TYPE "LINUX"
1393 #     define DYNAMIC_LOADING
1394       extern int _end[];
1395 #     define DATAEND (_end)
1396       extern int __data_start[];
1397 #     define DATASTART ((ptr_t)(__data_start))
1398 #     if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1399 #        define ALIGNMENT 8
1400 #        define CPP_WORDSZ 64
1401 #     else
1402 #        define ALIGNMENT 4
1403 #     endif
1404 #     define USE_GENERIC_PUSH_REGS
1405 #     if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1406 #        define LINUX_STACKBOTTOM
1407 #     else
1408 #        define STACKBOTTOM 0x80000000
1409 #     endif
1410 #   endif /* Linux */
1411 #   ifdef EWS4800
1412 #      define HEURISTIC2
1413 #      if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1414          extern int _fdata[], _end[];
1415 #        define DATASTART ((ptr_t)_fdata)
1416 #        define DATAEND ((ptr_t)_end)
1417 #        define CPP_WORDSZ _MIPS_SZPTR
1418 #        define ALIGNMENT (_MIPS_SZPTR/8)
1419 #      else
1420          extern int etext[], edata[], end[];
1421          extern int _DYNAMIC_LINKING[], _gp[];
1422 #        define DATASTART ((ptr_t)((((word)etext + 0x3ffff) & ~0x3ffff) \
1423                + ((word)etext & 0xffff)))
1424 #        define DATAEND (edata)
1425 #        define DATASTART2 (_DYNAMIC_LINKING \
1426                ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1427                : (ptr_t)edata)
1428 #        define DATAEND2 (end)
1429 #        define ALIGNMENT 4
1430 #      endif
1431 #      define OS_TYPE "EWS4800"
1432 #      define USE_GENERIC_PUSH_REGS 1
1433 #   endif
1434 #   ifdef ULTRIX
1435 #       define HEURISTIC2
1436 #       define DATASTART (ptr_t)0x10000000
1437                               /* Could probably be slightly higher since */
1438                               /* startup code allocates lots of stuff.   */
1439 #       define OS_TYPE "ULTRIX"
1440 #       define ALIGNMENT 4
1441 #   endif
1442 #   ifdef RISCOS
1443 #       define HEURISTIC2
1444 #       define DATASTART (ptr_t)0x10000000
1445 #       define OS_TYPE "RISCOS"
1446 #       define ALIGNMENT 4  /* Required by hardware */
1447 #   endif
1448 #   ifdef IRIX5
1449 #       define HEURISTIC2
1450         extern int _fdata[];
1451 #       define DATASTART ((ptr_t)(_fdata))
1452 #       ifdef USE_MMAP
1453 #         define HEAP_START (ptr_t)0x30000000
1454 #       else
1455 #         define HEAP_START DATASTART
1456 #       endif
1457                               /* Lowest plausible heap address.         */
1458                               /* In the MMAP case, we map there.        */
1459                               /* In either case it is used to identify  */
1460                               /* heap sections so they're not           */
1461                               /* considered as roots.                   */
1462 #       define OS_TYPE "IRIX5"
1463 /*#       define MPROTECT_VDB DOB: this should work, but there is evidence */
1464 /*              of recent breakage.                                        */
1465 #       ifdef _MIPS_SZPTR
1466 #         define CPP_WORDSZ _MIPS_SZPTR
1467 #         define ALIGNMENT (_MIPS_SZPTR/8)
1468 #         if CPP_WORDSZ != 64
1469 #           define ALIGN_DOUBLE
1470 #         endif
1471 #       else
1472 #         define ALIGNMENT 4
1473 #         define ALIGN_DOUBLE
1474 #       endif
1475 #       define DYNAMIC_LOADING
1476 #   endif
1477 #   ifdef MSWINCE
1478 #       define OS_TYPE "MSWINCE"
1479 #       define ALIGNMENT 4
1480 #       define DATAEND /* not needed */
1481 #   endif
1482 #   if defined(NETBSD)
1483 #     define ALIGNMENT 4
1484 #     define OS_TYPE "NETBSD"
1485 #     define HEURISTIC2
1486 #     define USE_GENERIC_PUSH_REGS
1487 #     ifdef __ELF__
1488         extern int etext[];
1489 #       define DATASTART GC_data_start
1490 #       define NEED_FIND_LIMIT
1491 #       define DYNAMIC_LOADING
1492 #     else
1493 #       define DATASTART ((ptr_t) 0x10000000)
1494 #       define STACKBOTTOM ((ptr_t) 0x7ffff000)
1495 #     endif /* _ELF_ */
1496 #  endif
1497 # endif
1498
1499 # ifdef RS6000
1500 #   define MACH_TYPE "RS6000"
1501 #   ifdef ALIGNMENT
1502 #     undef ALIGNMENT
1503 #   endif
1504 #   ifdef IA64
1505 #     undef IA64 /* DOB: some AIX installs stupidly define IA64 in /usr/include/sys/systemcfg.h */
1506 #   endif
1507 #   ifdef __64BIT__
1508 #     define ALIGNMENT 8
1509 #     define CPP_WORDSZ 64
1510 #     define STACKBOTTOM ((ptr_t)0x1000000000000000)
1511 #   else
1512 #     define ALIGNMENT 4
1513 #     define CPP_WORDSZ 32
1514 #     define STACKBOTTOM ((ptr_t)((ulong)&errno))
1515 #   endif
1516 #   define USE_MMAP
1517 #   define USE_MMAP_ANON
1518  /* From AIX linker man page:
1519  _text Specifies the first location of the program.
1520  _etext Specifies the first location after the program.
1521  _data Specifies the first location of the data.
1522  _edata Specifies the first location after the initialized data
1523  _end or end Specifies the first location after all data.
1524  */
1525     extern int _data[], _end[];
1526 #   define DATASTART ((ptr_t)((ulong)_data))
1527 #   define DATAEND ((ptr_t)((ulong)_end))
1528     extern int errno;
1529 #   define USE_GENERIC_PUSH_REGS
1530 #   define DYNAMIC_LOADING
1531         /* For really old versions of AIX, this may have to be removed. */
1532 # endif
1533
1534 # ifdef HP_PA
1535 #   define MACH_TYPE "HP_PA"
1536 #   ifdef __LP64__
1537 #     define CPP_WORDSZ 64
1538 #     define ALIGNMENT 8
1539 #   else
1540 #     define CPP_WORDSZ 32
1541 #     define ALIGNMENT 4
1542 #     define ALIGN_DOUBLE
1543 #   endif
1544 #   if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1545 #     ifndef LINUX /* For now. */
1546 #       define MPROTECT_VDB
1547 #     endif
1548 #   else
1549 #     define GENERIC_COMPARE_AND_SWAP
1550         /* No compare-and-swap instruction.  Use pthread mutexes        */
1551         /* when we absolutely have to.                                  */
1552 #     ifdef PARALLEL_MARK
1553 #       define USE_MARK_BYTES
1554                 /* Minimize compare-and-swap usage.             */
1555 #     endif
1556 #   endif
1557 #   define STACK_GROWS_UP
1558 #   ifdef HPUX
1559 #     define OS_TYPE "HPUX"
1560       extern int __data_start[];
1561 #     define DATASTART ((ptr_t)(__data_start))
1562 #     if 0
1563         /* The following appears to work for 7xx systems running HP/UX  */
1564         /* 9.xx Furthermore, it might result in much faster             */
1565         /* collections than HEURISTIC2, which may involve scanning      */
1566         /* segments that directly precede the stack.  It is not the     */
1567         /* default, since it may not work on older machine/OS           */
1568         /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1569         /* this.)                                                       */
1570 #       define STACKBOTTOM ((ptr_t) 0x7b033000)  /* from /etc/conf/h/param.h */
1571 #     else
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 #     endif
1578 #     define DYNAMIC_LOADING
1579 #     include <unistd.h>
1580 #     define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1581 #     ifndef __GNUC__
1582 #       define PREFETCH(x)  { \
1583                               register long addr = (long)(x); \
1584                               (void) _asm ("LDW", 0, 0, addr, 0); \
1585                             }
1586 #     endif
1587 #   endif /* HPUX */
1588 #   ifdef LINUX
1589 #     define OS_TYPE "LINUX"
1590 #     define LINUX_STACKBOTTOM
1591 #     define DYNAMIC_LOADING
1592 #     define SEARCH_FOR_DATA_START
1593       extern int _end[];
1594 #     define DATAEND (&_end)
1595 #   endif /* LINUX */
1596 # endif /* HP_PA */
1597
1598 # ifdef ALPHA
1599 #   define MACH_TYPE "ALPHA"
1600 #   define ALIGNMENT 8
1601 #   define CPP_WORDSZ 64
1602 #   ifndef LINUX
1603 #     define USE_GENERIC_PUSH_REGS
1604       /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
1605       /* fp registers in some cases when the target is a 21264.  The assembly */
1606       /* code doesn't handle that yet, and version dependencies make that a   */
1607       /* bit tricky.  Do the easy thing for now.                                    */
1608 #   endif
1609 #   ifdef NETBSD
1610 #       define OS_TYPE "NETBSD"
1611 #       define HEURISTIC2
1612 #       define DATASTART GC_data_start
1613 #       define ELFCLASS32 32
1614 #       define ELFCLASS64 64
1615 #       define ELF_CLASS ELFCLASS64
1616 #       define DYNAMIC_LOADING
1617 #   endif
1618 #   ifdef OPENBSD
1619 #       define OS_TYPE "OPENBSD"
1620 #       define HEURISTIC2
1621 #       ifdef __ELF__   /* since OpenBSD/Alpha 2.9 */
1622 #          define DATASTART GC_data_start
1623 #          define ELFCLASS32 32
1624 #          define ELFCLASS64 64
1625 #          define ELF_CLASS ELFCLASS64
1626 #       else            /* ECOFF, until OpenBSD/Alpha 2.7 */
1627 #          define DATASTART ((ptr_t) 0x140000000)
1628 #       endif
1629 #   endif
1630 #   ifdef FREEBSD
1631 #       define OS_TYPE "FREEBSD"
1632 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
1633 #      define SIG_SUSPEND SIGTSTP
1634 #      define SIG_THR_RESTART SIGCONT
1635 #       define FREEBSD_STACKBOTTOM
1636 #       ifdef __ELF__
1637 #           define DYNAMIC_LOADING
1638 #       endif
1639 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
1640         extern char etext[];
1641         extern char edata[];
1642         extern char end[];
1643 #       define NEED_FIND_LIMIT
1644 #       define DATASTART ((ptr_t)(&etext))
1645 #       define DATAEND (GC_find_limit (DATASTART, TRUE))
1646 #       define DATASTART2 ((ptr_t)(&edata))
1647 #       define DATAEND2 ((ptr_t)(&end))
1648 #   endif
1649 #   ifdef OSF1
1650 #       define OS_TYPE "OSF1"
1651 #       define DATASTART ((ptr_t) 0x140000000)
1652         extern int _end[];
1653 #       define DATAEND ((ptr_t) &_end)
1654         extern char ** environ;
1655         /* round up from the value of environ to the nearest page boundary */
1656         /* Probably breaks if putenv is called before collector            */
1657         /* initialization.                                                 */
1658 #       define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1659 /* #    define HEURISTIC2 */
1660         /* Normally HEURISTIC2 is too conervative, since                */
1661         /* the text segment immediately follows the stack.              */
1662         /* Hence we give an upper pound.                                */
1663         /* This is currently unused, since we disabled HEURISTIC2       */
1664         extern int __start[];
1665 #       define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
1666 #       ifndef GC_OSF1_THREADS
1667           /* Unresolved signal issues with threads.     */
1668 #         define MPROTECT_VDB
1669 #       endif
1670 #       define DYNAMIC_LOADING
1671 #   endif
1672 #   ifdef LINUX
1673 #       define OS_TYPE "LINUX"
1674 #       define LINUX_STACKBOTTOM
1675 #       ifdef __ELF__
1676 #         define SEARCH_FOR_DATA_START
1677 #         define DYNAMIC_LOADING
1678 #       else
1679 #           define DATASTART ((ptr_t) 0x140000000)
1680 #       endif
1681         extern int _end[];
1682 #       define DATAEND (_end)
1683 #       define MPROTECT_VDB
1684                 /* Has only been superficially tested.  May not */
1685                 /* work on all versions.                        */
1686 #   endif
1687 # endif
1688
1689 # ifdef IA64
1690 #   define MACH_TYPE "IA64"
1691 #   define USE_GENERIC_PUSH_REGS
1692         /* We need to get preserved registers in addition to register   */
1693         /* windows.   That's easiest to do with setjmp.                 */
1694 #   ifdef PARALLEL_MARK
1695 #       define USE_MARK_BYTES
1696             /* Compare-and-exchange is too expensive to use for         */
1697             /* setting mark bits.                                       */
1698 #   endif
1699 #   ifdef HPUX
1700 #       ifdef _ILP32
1701 #         define CPP_WORDSZ 32
1702 #         define ALIGN_DOUBLE
1703             /* Requires 8 byte alignment for malloc */
1704 #         define ALIGNMENT 4
1705 #       else
1706 #         ifndef _LP64
1707                 ---> unknown ABI
1708 #         endif
1709 #         define CPP_WORDSZ 64
1710 #         define ALIGN_DOUBLE
1711             /* Requires 16 byte alignment for malloc */
1712 #         define ALIGNMENT 8
1713 #       endif
1714 #       define OS_TYPE "HPUX"   
1715         extern int __data_start[];
1716 #       define DATASTART ((ptr_t)(__data_start))
1717         /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2       */
1718         /* to this.  Note that the GC must be initialized before the    */
1719         /* first putenv call.                                           */
1720         extern char ** environ;
1721 #       define STACKBOTTOM ((ptr_t)environ)
1722 #       define HPUX_STACKBOTTOM
1723 #       define DYNAMIC_LOADING
1724 #       include <unistd.h>
1725 #       define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1726         /* The following was empirically determined, and is probably    */
1727         /* not very robust.                                             */
1728         /* Note that the backing store base seems to be at a nice       */
1729         /* address minus one page.                                      */
1730 #       define BACKING_STORE_DISPLACEMENT 0x1000000
1731 #       define BACKING_STORE_ALIGNMENT 0x1000
1732         extern ptr_t GC_register_stackbottom;
1733 #       define BACKING_STORE_BASE GC_register_stackbottom
1734         /* Known to be wrong for recent HP/UX versions!!!       */
1735 #   endif
1736 #   ifdef LINUX
1737 #       define CPP_WORDSZ 64
1738 #       define ALIGN_DOUBLE
1739           /* Requires 16 byte alignment for malloc */
1740 #       define ALIGNMENT 8
1741 #       define OS_TYPE "LINUX"
1742         /* The following works on NUE and older kernels:        */
1743 /* #       define STACKBOTTOM ((ptr_t) 0xa000000000000000l)     */
1744         /* This does not work on NUE:                           */
1745 #       define LINUX_STACKBOTTOM
1746         /* We also need the base address of the register stack  */
1747         /* backing store.  This is computed in                  */
1748         /* GC_linux_register_stack_base based on the following  */
1749         /* constants:                                           */
1750 #       define BACKING_STORE_ALIGNMENT 0x100000
1751 #       define BACKING_STORE_DISPLACEMENT 0x80000000
1752         extern ptr_t GC_register_stackbottom;
1753 #       define BACKING_STORE_BASE GC_register_stackbottom
1754 #       define SEARCH_FOR_DATA_START
1755 #       ifdef __GNUC__
1756 #         define DYNAMIC_LOADING
1757 #       else
1758           /* In the Intel compiler environment, we seem to end up with  */
1759           /* statically linked executables and an undefined reference   */
1760           /* to _DYNAMIC                                                */
1761 #       endif
1762 #       define MPROTECT_VDB
1763                 /* Requires Linux 2.3.47 or later.      */
1764         extern int _end[];
1765 #       define DATAEND (_end)
1766 #       ifdef __GNUC__
1767 #         ifndef __INTEL_COMPILER
1768 #           define PREFETCH(x) \
1769               __asm__ ("        lfetch  [%0]": : "r"(x))
1770 #           define PREFETCH_FOR_WRITE(x) \
1771               __asm__ ("        lfetch.excl     [%0]": : "r"(x))
1772 #           define CLEAR_DOUBLE(x) \
1773               __asm__ ("        stf.spill       [%0]=f0": : "r"((void *)(x)))
1774 #         else
1775 #           include <ia64intrin.h>
1776 #           define PREFETCH(x) \
1777               __lfetch(__lfhint_none, (x))
1778 #           define PREFETCH_FOR_WRITE(x) \
1779               __lfetch(__lfhint_nta,  (x))
1780 #           define CLEAR_DOUBLE(x) \
1781               __stf_spill((void *)(x), 0)
1782 #         endif // __INTEL_COMPILER
1783 #       endif
1784 #   endif
1785 #   ifdef MSWIN32
1786       /* FIXME: This is a very partial guess.  There is no port, yet.   */
1787 #     define OS_TYPE "MSWIN32"
1788                 /* STACKBOTTOM and DATASTART are handled specially in   */
1789                 /* os_dep.c.                                            */
1790 #     define DATAEND  /* not needed */
1791 #     if defined(_WIN64)
1792 #       define CPP_WORDSZ 64
1793 #     else
1794 #       define CPP_WORDSZ 32   /* Is this possible?     */
1795 #     endif
1796 #     define ALIGNMENT 8
1797 #   endif
1798 # endif
1799
1800 # ifdef M88K
1801 #   define MACH_TYPE "M88K"
1802 #   define ALIGNMENT 4
1803 #   define ALIGN_DOUBLE
1804     extern int etext[];
1805 #   ifdef CX_UX
1806 #       define OS_TYPE "CX_UX"
1807 #       define DATASTART ((((word)etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1808 #   endif
1809 #   ifdef  DGUX
1810 #       define OS_TYPE "DGUX"
1811         extern ptr_t GC_SysVGetDataStart();
1812 #       define DATASTART GC_SysVGetDataStart(0x10000, etext)
1813 #   endif
1814 #   define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1815 # endif
1816
1817 # ifdef S370
1818     /* If this still works, and if anyone cares, this should probably   */
1819     /* be moved to the S390 category.                                   */
1820 #   define MACH_TYPE "S370"
1821 #   define ALIGNMENT 4  /* Required by hardware */
1822 #   define USE_GENERIC_PUSH_REGS
1823 #   ifdef UTS4
1824 #       define OS_TYPE "UTS4"
1825         extern int etext[];
1826         extern int _etext[];
1827         extern int _end[];
1828         extern ptr_t GC_SysVGetDataStart();
1829 #       define DATASTART GC_SysVGetDataStart(0x10000, _etext)
1830 #       define DATAEND (_end)
1831 #       define HEURISTIC2
1832 #   endif
1833 # endif
1834
1835 # ifdef S390
1836 #   define MACH_TYPE "S390"
1837 #   define USE_GENERIC_PUSH_REGS
1838 #   ifndef __s390x__
1839 #     define ALIGNMENT 4
1840 #     define CPP_WORDSZ 32
1841 #   else
1842 #     define ALIGNMENT 8
1843 #     define CPP_WORDSZ 64
1844 #   endif
1845 #   ifndef HBLKSIZE
1846 #     define HBLKSIZE 4096
1847 #   endif
1848 #   ifdef LINUX
1849 #       define OS_TYPE "LINUX"
1850 #       define LINUX_STACKBOTTOM
1851 #       define DYNAMIC_LOADING
1852         extern int __data_start[];
1853 #       define DATASTART ((ptr_t)(__data_start))
1854     extern int _end[];
1855 #   define DATAEND (_end)
1856 #   define CACHE_LINE_SIZE 256
1857 #   define GETPAGESIZE() 4096
1858 #   endif
1859 # endif
1860
1861 # if defined(PJ)
1862 #   define ALIGNMENT 4
1863     extern int _etext[];
1864 #   define DATASTART ((ptr_t)(_etext))
1865 #   define HEURISTIC1
1866 # endif
1867
1868 # ifdef ARM32
1869 #   define CPP_WORDSZ 32
1870 #   define MACH_TYPE "ARM32"
1871 #   define ALIGNMENT 4
1872 #   ifdef NETBSD
1873 #       define OS_TYPE "NETBSD"
1874 #       define HEURISTIC2
1875 #       ifdef __ELF__
1876 #          define DATASTART GC_data_start
1877 #          define DYNAMIC_LOADING
1878 #       else
1879            extern char etext[];
1880 #          define DATASTART ((ptr_t)(etext))
1881 #       endif
1882 #       define USE_GENERIC_PUSH_REGS
1883 #   endif
1884 #   ifdef LINUX
1885 #       define OS_TYPE "LINUX"
1886 #       define LINUX_STACKBOTTOM
1887 #       undef STACK_GRAN
1888 #       define STACK_GRAN 0x10000000
1889 #       define USE_GENERIC_PUSH_REGS
1890 #       ifdef __ELF__
1891 #            define DYNAMIC_LOADING
1892 #            include <features.h>
1893 #            if defined(__GLIBC__) && __GLIBC__ >= 2
1894 #                define SEARCH_FOR_DATA_START
1895 #            elif defined(PLATFORM_ANDROID)
1896 #                define SEARCH_FOR_DATA_START
1897 #            else
1898                  extern char **__environ;
1899 #                define DATASTART ((ptr_t)(&__environ))
1900                               /* hideous kludge: __environ is the first */
1901                               /* word in crt0.o, and delimits the start */
1902                               /* of the data segment, no matter which   */
1903                               /* ld options were passed through.        */
1904                               /* We could use _etext instead, but that  */
1905                               /* would include .rodata, which may       */
1906                               /* contain large read-only data tables    */
1907                               /* that we'd rather not scan.             */
1908 #            endif
1909              extern int _end[];
1910 #            define DATAEND (_end)
1911 #       else
1912              extern int etext[];
1913 #            define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1914 #       endif
1915 #   endif
1916 #   ifdef MSWINCE
1917 #     define OS_TYPE "MSWINCE"
1918 #     define DATAEND /* not needed */
1919 #   endif
1920 #   ifdef DARWIN
1921 #     define OS_TYPE "DARWIN"
1922 #     define DATASTART ((ptr_t) get_etext())
1923 #     define DATAEND    ((ptr_t) get_end())
1924 #     define STACKBOTTOM ((ptr_t) 0x30000000)
1925 #     define USE_MMAP
1926 #     define USE_MMAP_ANON
1927 #     define USE_MUNMAP
1928 #   endif
1929 #   ifdef NOSYS
1930       /* __data_start is usually defined in the target linker script.  */
1931       extern int __data_start[];
1932 #     define DATASTART (ptr_t)(__data_start)
1933 #     define USE_GENERIC_PUSH_REGS
1934       /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S  */
1935       extern void *__stack_base__;
1936 #     define STACKBOTTOM ((ptr_t) (__stack_base__))
1937 #   endif
1938 #endif
1939
1940 # ifdef CRIS
1941 #   define MACH_TYPE "CRIS"
1942 #   define CPP_WORDSZ 32
1943 #   define ALIGNMENT 1
1944 #   define OS_TYPE "LINUX"
1945 #   define DYNAMIC_LOADING
1946 #   define LINUX_STACKBOTTOM
1947 #   define USE_GENERIC_PUSH_REGS
1948 #   define SEARCH_FOR_DATA_START
1949       extern int _end[];
1950 #   define DATAEND (_end)
1951 # endif
1952
1953 # ifdef SH
1954 #   define MACH_TYPE "SH"
1955 #   define ALIGNMENT 4
1956 #   ifdef MSWINCE
1957 #     define OS_TYPE "MSWINCE"
1958 #     define DATAEND /* not needed */
1959 #   endif
1960 #   ifdef LINUX
1961 #     define OS_TYPE "LINUX"
1962 #     define LINUX_STACKBOTTOM
1963 #     define USE_GENERIC_PUSH_REGS
1964 #     define DYNAMIC_LOADING
1965 #     define SEARCH_FOR_DATA_START
1966       extern int _end[];
1967 #     define DATAEND (_end)
1968 #   endif
1969 #   ifdef NETBSD
1970 #      define OS_TYPE "NETBSD"
1971 #      define HEURISTIC2
1972 #      define DATASTART GC_data_start
1973 #       define USE_GENERIC_PUSH_REGS
1974 #      define DYNAMIC_LOADING
1975 #   endif
1976 # endif
1977  
1978 # ifdef SH4
1979 #   define MACH_TYPE "SH4"
1980 #   define OS_TYPE "MSWINCE"
1981 #   define ALIGNMENT 4
1982 #   define DATAEND /* not needed */
1983 # endif
1984
1985 # ifdef M32R
1986 #   define CPP_WORDSZ 32
1987 #   define MACH_TYPE "M32R"
1988 #   define ALIGNMENT 4
1989 #   ifdef LINUX
1990 #     define OS_TYPE "LINUX"
1991 #     define LINUX_STACKBOTTOM
1992 #     undef STACK_GRAN
1993 #     define STACK_GRAN 0x10000000
1994 #     define USE_GENERIC_PUSH_REGS
1995 #     define DYNAMIC_LOADING
1996 #     define SEARCH_FOR_DATA_START
1997       extern int _end[];
1998 #     define DATAEND (_end)
1999 #   endif
2000 # endif
2001
2002 # ifdef X86_64
2003 #   define MACH_TYPE "X86_64"
2004 #   define ALIGNMENT 8
2005 #   define CPP_WORDSZ 64
2006 #   ifndef HBLKSIZE
2007 #     define HBLKSIZE 4096
2008 #   endif
2009 #   define CACHE_LINE_SIZE 64
2010 #   define USE_GENERIC_PUSH_REGS
2011 #   ifdef LINUX
2012 #       define OS_TYPE "LINUX"
2013 #       define LINUX_STACKBOTTOM
2014 #   ifndef USE_MMAP
2015 #       define FALLBACK_TO_MMAP
2016 #   endif
2017 #       if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2018 #           define MPROTECT_VDB
2019 #       else
2020             /* We seem to get random errors in incremental mode,        */
2021             /* possibly because Linux threads is itself a malloc client */
2022             /* and can't deal with the signals.                         */
2023 #       endif
2024 #       ifdef __ELF__
2025 #            define DYNAMIC_LOADING
2026 #            ifdef UNDEFINED    /* includes ro data */
2027                extern int _etext[];
2028 #              define DATASTART ((ptr_t)((((word) (_etext)) + 0xfff) & ~0xfff))
2029 #            endif
2030 #            include <features.h>
2031 #            define SEARCH_FOR_DATA_START
2032              extern int _end[];
2033 #            define DATAEND (_end)
2034 #       else
2035              extern int etext[];
2036 #            define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
2037 #       endif
2038 #       if defined(__GNUC__) && __GNUC >= 3
2039 #           define PREFETCH(x) __builtin_prefetch((x), 0, 0)
2040 #           define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
2041 #       endif
2042 #   endif
2043 #   ifdef DARWIN
2044 #     define OS_TYPE "DARWIN"
2045 #     define DARWIN_DONT_PARSE_STACK
2046 #     define DYNAMIC_LOADING
2047       /* XXX: see get_end(3), get_etext() and get_end() should not be used.
2048          These aren't used when dyld support is enabled (it is by default) */
2049 #     define DATASTART ((ptr_t) get_etext())
2050 #     define DATAEND    ((ptr_t) get_end())
2051 #     define STACKBOTTOM ((ptr_t) 0x7fff5fc00000)
2052 #     ifndef USE_MMAP
2053 #       define USE_MMAP
2054 #     endif
2055 #     define USE_MMAP_ANON
2056 #     ifdef GC_DARWIN_THREADS
2057 #       define MPROTECT_VDB
2058 #     endif
2059 #     include <unistd.h>
2060 #     define GETPAGESIZE() getpagesize()
2061       /* There seems to be some issues with trylock hanging on darwin. This
2062          should be looked into some more */
2063 #   endif
2064 #   ifdef FREEBSD
2065 #       define OS_TYPE "FREEBSD"
2066 #       ifndef GC_FREEBSD_THREADS
2067 #           define MPROTECT_VDB
2068 #       endif
2069 #      define SIG_SUSPEND SIGTSTP
2070 #      define SIG_THR_RESTART SIGCONT
2071 #       define NEED_FIND_LIMIT
2072 #       define FREEBSD_STACKBOTTOM
2073 #       ifdef __ELF__
2074 #           define DYNAMIC_LOADING
2075 #       endif
2076         extern char etext[];
2077         extern char * GC_FreeBSDGetDataStart();
2078 #       define DATASTART GC_FreeBSDGetDataStart(0x1000, &etext)
2079 #   endif
2080 #   ifdef NETBSD
2081 #       define OS_TYPE "NETBSD"
2082 #       ifdef __ELF__
2083 #           define DYNAMIC_LOADING
2084 #       endif
2085 #       define HEURISTIC2
2086         extern char etext[];
2087 #       define SEARCH_FOR_DATA_START
2088 #   endif
2089 # endif
2090
2091 #if defined(LINUX) && defined(USE_MMAP)
2092     /* The kernel may do a somewhat better job merging mappings etc.    */
2093     /* with anonymous mappings.                                         */
2094 #   define USE_MMAP_ANON
2095 #endif
2096
2097 #if defined(LINUX) && defined(REDIRECT_MALLOC)
2098     /* Rld appears to allocate some memory with its own allocator, and  */
2099     /* some through malloc, which might be redirected.  To make this    */
2100     /* work with collectable memory, we have to scan memory allocated   */
2101     /* by rld's internal malloc.                                        */
2102 #   define USE_PROC_FOR_LIBRARIES
2103 #endif
2104     
2105 # ifndef STACK_GROWS_UP
2106 #   define STACK_GROWS_DOWN
2107 # endif
2108
2109 # ifndef CPP_WORDSZ
2110 #   define CPP_WORDSZ 32
2111 # endif
2112
2113 # ifndef OS_TYPE
2114 #   define OS_TYPE ""
2115 # endif
2116
2117 # ifndef DATAEND
2118     extern int end[];
2119 #   define DATAEND (end)
2120 # endif
2121
2122 # if defined(SVR4) && !defined(GETPAGESIZE)
2123 #    include <unistd.h>
2124 #    define GETPAGESIZE()  sysconf(_SC_PAGESIZE)
2125 # endif
2126
2127 # ifndef GETPAGESIZE
2128 #   if defined(SUNOS5) || defined(IRIX5)
2129 #       include <unistd.h>
2130 #   endif
2131 #   define GETPAGESIZE() getpagesize()
2132 # endif
2133
2134 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
2135             /* OS has SVR4 generic features.  Probably others also qualify.     */
2136 #   define SVR4
2137 # endif
2138
2139 # if defined(SUNOS5) || defined(DRSNX)
2140             /* OS has SUNOS5 style semi-undocumented interface to dynamic       */
2141             /* loader.                                                          */
2142 #   define SUNOS5DL
2143             /* OS has SUNOS5 style signal handlers.                             */
2144 #   define SUNOS5SIGS
2145 # endif
2146
2147 # if defined(HPUX)
2148 #   define SUNOS5SIGS
2149 # endif
2150
2151 # if defined(FREEBSD) && (__FreeBSD__ >= 4)
2152 #   define SUNOS5SIGS
2153 # endif
2154
2155 # if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
2156             || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
2157             || defined(DGUX) || defined(BSD) || defined(SUNOS4) \
2158             || defined(_AIX) || defined(DARWIN) || defined(OSF1)
2159 #   define UNIX_LIKE   /* Basic Unix-like system calls work.    */
2160 # endif
2161
2162 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
2163            -> bad word size
2164 # endif
2165
2166 # ifdef PCR
2167 #   undef DYNAMIC_LOADING
2168 #   undef STACKBOTTOM
2169 #   undef HEURISTIC1
2170 #   undef HEURISTIC2
2171 #   undef PROC_VDB
2172 #   undef MPROTECT_VDB
2173 #   define PCR_VDB
2174 # endif
2175
2176 # ifdef SRC_M3
2177         /* Postponed for now. */
2178 #   undef PROC_VDB
2179 #   undef MPROTECT_VDB
2180 # endif
2181
2182 # ifdef SMALL_CONFIG
2183         /* Presumably not worth the space it takes. */
2184 #   undef PROC_VDB
2185 #   undef MPROTECT_VDB
2186 # endif
2187
2188 # ifdef USE_MUNMAP
2189 #   undef MPROTECT_VDB  /* Can't deal with address space holes. */
2190 # endif
2191
2192 # ifdef PARALLEL_MARK
2193 #   undef MPROTECT_VDB  /* For now.     */
2194 # endif
2195
2196 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
2197 #   define DEFAULT_VDB
2198 # endif
2199
2200 # ifndef PREFETCH
2201 #   define PREFETCH(x)
2202 #   define NO_PREFETCH
2203 # endif
2204
2205 # ifndef PREFETCH_FOR_WRITE
2206 #   define PREFETCH_FOR_WRITE(x)
2207 #   define NO_PREFETCH_FOR_WRITE
2208 # endif
2209
2210 # ifndef CACHE_LINE_SIZE
2211 #   define CACHE_LINE_SIZE 32   /* Wild guess   */
2212 # endif
2213
2214 # ifdef LINUX
2215 #   define REGISTER_LIBRARIES_EARLY
2216     /* We sometimes use dl_iterate_phdr, which may acquire an internal  */
2217     /* lock.  This isn't safe after the world has stopped.  So we must  */
2218     /* call GC_register_dynamic_libraries before stopping the world.    */
2219     /* For performance reasons, this may be beneficial on other         */
2220     /* platforms as well, though it should be avoided in win32.         */
2221 # endif /* LINUX */
2222
2223 # if defined(SEARCH_FOR_DATA_START)
2224     extern ptr_t GC_data_start;
2225 #   define DATASTART GC_data_start
2226 # endif
2227
2228 # ifndef CLEAR_DOUBLE
2229 #   define CLEAR_DOUBLE(x) \
2230                 ((word*)x)[0] = 0; \
2231                 ((word*)x)[1] = 0;
2232 # endif /* CLEAR_DOUBLE */
2233
2234         /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
2235 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
2236 #   define GC_SOLARIS_THREADS
2237 # endif
2238
2239 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
2240         --> inconsistent configuration
2241 # endif
2242 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
2243         --> inconsistent configuration
2244 # endif
2245 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
2246         --> inconsistent configuration
2247 # endif
2248 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
2249         --> inconsistent configuration
2250 # endif
2251 # if defined(GC_AIX_THREADS) && !defined(_AIX)
2252         --> inconsistent configuration
2253 # endif
2254 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32) && !defined(CYGWIN32)
2255         --> inconsistent configuration
2256 # endif
2257
2258 # if defined(PCR) || defined(SRC_M3) || \
2259                 defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
2260                 defined(GC_PTHREADS) || defined(SN_TARGET_PS3)
2261 #   define THREADS
2262 # endif
2263
2264 # if defined(HP_PA) || defined(M88K) \
2265              || defined(POWERPC) && !defined(DARWIN) \
2266              || defined(LINT) || defined(MSWINCE) || defined(ARM32) || defined(CRIS) \
2267              || (defined(I386) && defined(__LCC__))
2268         /* Use setjmp based hack to mark from callee-save registers.    */
2269         /* The define should move to the individual platform            */
2270         /* descriptions.                                                */
2271 #       define USE_GENERIC_PUSH_REGS
2272 # endif
2273
2274 # if defined(MSWINCE)
2275 #   define NO_GETENV
2276 # endif
2277
2278 # if defined(SPARC)
2279 #   define ASM_CLEAR_CODE       /* Stack clearing is crucial, and we    */
2280                                 /* include assembly code to do it well. */
2281 # endif
2282
2283   /* Can we save call chain in objects for debugging?                   */
2284   /* SET NFRAMES (# of saved frames) and NARGS (#of args for each       */
2285   /* frame) to reasonable values for the platform.                      */
2286   /* Set SAVE_CALL_CHAIN if we can.  SAVE_CALL_COUNT can be specified   */
2287   /* at build time, though we feel free to adjust it slightly.          */
2288   /* Define NEED_CALLINFO if we either save the call stack or           */
2289   /* GC_ADD_CALLER is defined.                                          */
2290   /* GC_CAN_SAVE_CALL_STACKS is set in gc.h.                            */
2291
2292 #if defined(SPARC)
2293 # define CAN_SAVE_CALL_ARGS
2294 #endif
2295 #if (defined(I386) || defined(X86_64)) && defined(LINUX)
2296             /* SAVE_CALL_CHAIN is supported if the code is compiled to save     */
2297             /* frame pointers by default, i.e. no -fomit-frame-pointer flag.    */
2298 # define CAN_SAVE_CALL_ARGS
2299 #endif
2300
2301 # if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
2302              && defined(GC_CAN_SAVE_CALL_STACKS)
2303 #   define SAVE_CALL_CHAIN 
2304 # endif
2305 # ifdef SAVE_CALL_CHAIN
2306 #   if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
2307 #     define NARGS SAVE_CALL_NARGS
2308 #   else
2309 #     define NARGS 0    /* Number of arguments to save for each call.   */
2310 #   endif
2311 # endif
2312 # ifdef SAVE_CALL_CHAIN
2313 #   ifndef SAVE_CALL_COUNT
2314 #     define NFRAMES 6  /* Number of frames to save. Even for           */
2315                                 /* alignment reasons.                           */
2316 #   else
2317 #     define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
2318 #   endif
2319 #   define NEED_CALLINFO
2320 # endif /* SAVE_CALL_CHAIN */
2321 # ifdef GC_ADD_CALLER
2322 #   define NFRAMES 1
2323 #   define NARGS 0
2324 #   define NEED_CALLINFO
2325 # endif
2326
2327 # if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
2328 #   define DBG_HDRS_ALL
2329 # endif
2330
2331 # if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
2332 #   define POINTER_SHIFT 0
2333 # endif
2334
2335 # if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
2336 #   define POINTER_MASK ((GC_word)(-1))
2337 # endif
2338
2339 # if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
2340 #   define FIXUP_POINTER(p) (p) = ((p) & (POINTER_MASK) << POINTER_SHIFT)
2341 # endif
2342
2343 # if defined(FIXUP_POINTER)
2344 #   define NEED_FIXUP_POINTER 1
2345 # else
2346 #   define NEED_FIXUP_POINTER 0
2347 #   define FIXUP_POINTER(p)
2348 # endif
2349
2350 #ifdef GC_PRIVATE_H
2351         /* This relies on some type definitions from gc_priv.h, from    */
2352         /* where it's normally included.                                */
2353         /*                                                              */
2354         /* How to get heap memory from the OS:                          */
2355         /* Note that sbrk()-like allocation is preferred, since it      */
2356         /* usually makes it possible to merge consecutively allocated   */
2357         /* chunks.  It also avoids unintented recursion with            */
2358         /* -DREDIRECT_MALLOC.                                           */
2359         /* GET_MEM() returns a HLKSIZE aligned chunk.                   */
2360         /* 0 is taken to mean failure.                                  */
2361         /* In the case os USE_MMAP, the argument must also be a         */
2362         /* physical page size.                                          */
2363         /* GET_MEM is currently not assumed to retrieve 0 filled space, */
2364         /* though we should perhaps take advantage of the case in which */
2365         /* does.                                                        */
2366         struct hblk;    /* See gc_priv.h.       */
2367 # ifdef PCR
2368             char * real_malloc();
2369 #   define GET_MEM(bytes) HBLKPTR(real_malloc((size_t)bytes + GC_page_size) \
2370                                           + GC_page_size-1)
2371 # else
2372 #   ifdef OS2
2373               void * os2_alloc(size_t bytes);
2374 #     define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc((size_t)bytes \
2375                                             + GC_page_size) \
2376                                             + GC_page_size-1)
2377 #   else
2378 #     if defined(NEXT) || defined(DOS4GW) || \
2379                  (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) || \
2380                  (defined(SUNOS5) && !defined(USE_MMAP))
2381 #       define GET_MEM(bytes) HBLKPTR((size_t) \
2382                                               calloc(1, (size_t)bytes + GC_page_size) \
2383                                               + GC_page_size-1)
2384 #     else
2385 #       ifdef MSWIN32
2386           extern ptr_t GC_win32_get_mem();
2387 #         define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
2388 #       else
2389 #         ifdef MACOS
2390 #           if defined(USE_TEMPORARY_MEMORY)
2391                         extern Ptr GC_MacTemporaryNewPtr(size_t size,
2392                                                          Boolean clearMemory);
2393 #               define GET_MEM(bytes) HBLKPTR( \
2394                             GC_MacTemporaryNewPtr(bytes + GC_page_size, true) \
2395                             + GC_page_size-1)
2396 #           else
2397 #                   define GET_MEM(bytes) HBLKPTR( \
2398                                 NewPtrClear(bytes + GC_page_size) + GC_page_size-1)
2399 #           endif
2400 #         else
2401 #           ifdef MSWINCE
2402               extern ptr_t GC_wince_get_mem();
2403 #             define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
2404 #           else
2405 #             if defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
2406                         extern void *GC_amiga_get_mem(size_t size);
2407 #               define GET_MEM(bytes) HBLKPTR((size_t) \
2408                           GC_amiga_get_mem((size_t)bytes + GC_page_size) \
2409                           + GC_page_size-1)
2410 #             else
2411 #           if defined(SN_TARGET_PS3)
2412                    extern void *ps3_get_mem (size_t size);
2413 #              define GET_MEM(bytes) (struct hblk*) ps3_get_mem (bytes)
2414 #           else
2415                 extern ptr_t GC_unix_get_mem();
2416 #               define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
2417 #endif
2418 #             endif
2419 #           endif
2420 #         endif
2421 #       endif
2422 #     endif
2423 #   endif
2424 # endif
2425
2426 #endif /* GC_PRIVATE_H */
2427
2428 #if defined(_AIX) && !defined(__GNUC__) && !defined(__STDC__)
2429   /* IBMs xlc compiler doesn't appear to follow the convention of       */
2430   /* defining  __STDC__ to be zero in extended mode.                    */
2431 #   define __STDC__ 0
2432 #endif
2433
2434 # endif /* GCCONFIG_H */