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