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