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