OSDN Git Service

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