OSDN Git Service

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