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