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