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