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