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