Debian Codegraph @

external/bdwgc/include/private/gcconfig.h

raw
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 #define GCCONFIG_H
27
28 #define MANUAL_VDB
29
30 # ifndef GC_PRIVATE_H
31 /* Fake ptr_t declaration, just to avoid compilation errors. */
32 /* This avoids many instances if "ifndef GC_PRIVATE_H" below. */
33 typedef struct GC_undefined_struct * ptr_t;
34 # include <stddef.h> /* For size_t etc. */
35 # endif
36
37 /* Note: Only wrap our own declarations, and not the included headers. */
38 /* In this case, wrap our entire file, but temporarily unwrap/rewrap */
39 /* around #includes. Types and macros do not need such wrapping, only */
40 /* the declared global data and functions. */
41 #ifdef __cplusplus
42 # define EXTERN_C_BEGIN extern "C" {
43 # define EXTERN_C_END } /* extern "C" */
44 #else
45 # define EXTERN_C_BEGIN /* empty */
46 # define EXTERN_C_END /* empty */
47 #endif
48
49 EXTERN_C_BEGIN
50
51 /* Convenient internal macro to test version of Clang. */
52 #if defined(__clang__) && defined(__clang_major__)
53 # define GC_CLANG_PREREQ(major, minor) \
54 ((__clang_major__ << 16) + __clang_minor__ >= ((major) << 16) + (minor))
55 # define GC_CLANG_PREREQ_FULL(major, minor, patchlevel) \
56 (GC_CLANG_PREREQ(major, (minor) + 1) \
57 || (__clang_major__ == (major) && __clang_minor__ == (minor) \
58 && __clang_patchlevel__ >= (patchlevel)))
59 #else
60 # define GC_CLANG_PREREQ(major, minor) 0 /* FALSE */
61 # define GC_CLANG_PREREQ_FULL(major, minor, patchlevel) 0
62 #endif
63
64 #ifdef LINT2
65 /* A macro (based on a tricky expression) to prevent false warnings */
66 /* like "Array compared to 0", "Comparison of identical expressions", */
67 /* "Untrusted loop bound" output by some static code analysis tools. */
68 /* The argument should not be a literal value. The result is */
69 /* converted to word type. (Actually, GC_word is used instead of */
70 /* word type as the latter might be undefined at the place of use.) */
71 # define COVERT_DATAFLOW(w) (~(GC_word)(w)^(~(GC_word)0))
72 #else
73 # define COVERT_DATAFLOW(w) ((GC_word)(w))
74 #endif
75
76 /* Machine dependent parameters. Some tuning parameters can be found */
77 /* near the top of gc_private.h. */
78
79 /* Machine specific parts contributed by various people. See README file. */
80
81 #if defined(__ANDROID__) && !defined(HOST_ANDROID)
82 /* __ANDROID__ macro is defined by Android NDK gcc. */
83 # define HOST_ANDROID 1
84 #endif
85
86 #if defined(HOST_ANDROID)
87 #define IGNORE_PROG_DATA_START
88 #endif
89
90 #if defined(TIZEN) && !defined(HOST_TIZEN)
91 # define HOST_TIZEN 1
92 #endif
93
94 #if defined(__SYMBIAN32__) && !defined(SYMBIAN)
95 # define SYMBIAN
96 # ifdef __WINS__
97 # pragma data_seg(".data2")
98 # endif
99 #endif
100
101 /* First a unified test for Linux: */
102 # if (defined(linux) || defined(__linux__) || defined(HOST_ANDROID)) \
103 && !defined(LINUX) && !defined(__native_client__)
104 # define LINUX
105 # endif
106
107 /* And one for QNX: */
108 # if defined(__QNX__)
109 # define I386
110 # define OS_TYPE "QNX"
111 # define SA_RESTART 0
112 # define HEURISTIC1
113 extern char etext[];
114 extern int _end[];
115 # define DATASTART ((ptr_t)(etext))
116 # define DATAEND ((ptr_t)(_end))
117 # define mach_type_known
118 # endif
119
120 /* And one for NetBSD: */
121 # if defined(__NetBSD__)
122 # define NETBSD
123 # endif
124
125 /* And one for OpenBSD: */
126 # if defined(__OpenBSD__)
127 # define OPENBSD
128 # endif
129
130 /* And one for FreeBSD: */
131 # if (defined(__FreeBSD__) || defined(__DragonFly__) \
132 || defined(__FreeBSD_kernel__)) && !defined(FREEBSD) \
133 && !defined(GC_NO_FREEBSD)
134 # define FREEBSD
135 # endif
136
137 /* And one for Darwin: */
138 # if defined(macosx) || (defined(__APPLE__) && defined(__MACH__))
139 # define DARWIN
140 EXTERN_C_END
141 # include <TargetConditionals.h>
142 EXTERN_C_BEGIN
143 # endif
144
145 /* Determine the machine type: */
146 # if defined(__native_client__)
147 # define NACL
148 # if !defined(__portable_native_client__) && !defined(__arm__)
149 # define I386
150 # define mach_type_known
151 # else
152 /* Here we will rely upon arch-specific defines. */
153 # endif
154 # endif
155 # if defined(__aarch64__)
156 # define AARCH64
157 # if !defined(LINUX) && !defined(DARWIN) && !defined(FREEBSD) \
158 && !defined(NN_BUILD_TARGET_PLATFORM_NX)
159 # define NOSYS
160 # define mach_type_known
161 # endif
162 # endif
163 # if defined(__arm) || defined(__arm__) || defined(__thumb__)
164 # define ARM32
165 # if defined(NACL)
166 # define mach_type_known
167 # elif !defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) \
168 && !defined(OPENBSD) && !defined(DARWIN) && !defined(_WIN32) \
169 && !defined(__CEGCC__) && !defined(NN_PLATFORM_CTR) \
170 && !defined(NN_BUILD_TARGET_PLATFORM_NX) \
171 && !defined(GC_NO_NOSYS) && !defined(SN_TARGET_PSP2) \
172 && !defined(SYMBIAN)
173 # define NOSYS
174 # define mach_type_known
175 # endif
176 # endif
177 # if defined(sun) && defined(mc68000) && !defined(CPPCHECK)
178 # error SUNOS4 no longer supported
179 # endif
180 # if defined(hp9000s300) && !defined(CPPCHECK)
181 # error M68K based HP machines no longer supported.
182 # endif
183 # if defined(OPENBSD) && defined(m68k)
184 /* FIXME: Should we remove this case? */
185 # define M68K
186 # define mach_type_known
187 # endif
188 # if defined(OPENBSD) && defined(__sparc__)
189 # define SPARC
190 # define mach_type_known
191 # endif
192 # if defined(OPENBSD) && defined(__arm__)
193 # define ARM32
194 # define mach_type_known
195 # endif
196 # if defined(OPENBSD) && defined(__sh__)
197 # define SH
198 # define mach_type_known
199 # endif
200 # if defined(NETBSD) && (defined(m68k) || defined(__m68k__))
201 # define M68K
202 # define mach_type_known
203 # endif
204 # if defined(NETBSD) && defined(__powerpc__)
205 # define POWERPC
206 # define mach_type_known
207 # endif
208 # if defined(NETBSD) && (defined(__arm32__) || defined(__arm__))
209 # define ARM32
210 # define mach_type_known
211 # endif
212 # if defined(NETBSD) && defined(__sh__)
213 # define SH
214 # define mach_type_known
215 # endif
216 # if defined(vax) || defined(__vax__)
217 # define VAX
218 # ifdef ultrix
219 # define ULTRIX
220 # else
221 # define BSD
222 # endif
223 # define mach_type_known
224 # endif
225 # if defined(__NetBSD__) && defined(__vax__)
226 # define VAX
227 # define mach_type_known
228 # endif
229 # if defined(mips) || defined(__mips) || defined(_mips)
230 # define MIPS
231 # if defined(nec_ews) || defined(_nec_ews)
232 # define EWS4800
233 # endif
234 # if !defined(LINUX) && !defined(EWS4800) && !defined(NETBSD) \
235 && !defined(OPENBSD)
236 # if defined(ultrix) || defined(__ultrix)
237 # define ULTRIX
238 # else
239 # define IRIX5 /* or IRIX 6.X */
240 # endif
241 # endif /* !LINUX */
242 # if defined(__NetBSD__) && defined(__MIPSEL__)
243 # undef ULTRIX
244 # endif
245 # define mach_type_known
246 # endif
247 # if defined(__NIOS2__) || defined(__NIOS2) || defined(__nios2__)
248 # define NIOS2 /* Altera NIOS2 */
249 # define mach_type_known
250 # endif
251 # if defined(__or1k__)
252 # define OR1K /* OpenRISC/or1k */
253 # define mach_type_known
254 # endif
255 # if defined(DGUX) && (defined(i386) || defined(__i386__))
256 # define I386
257 # ifndef _USING_DGUX
258 # define _USING_DGUX
259 # endif
260 # define mach_type_known
261 # endif
262 # if defined(sequent) && (defined(i386) || defined(__i386__))
263 # define I386
264 # define SEQUENT
265 # define mach_type_known
266 # endif
267 # if (defined(sun) || defined(__sun)) && (defined(i386) || defined(__i386__))
268 # define I386
269 # define SOLARIS
270 # define mach_type_known
271 # endif
272 # if (defined(sun) || defined(__sun)) && defined(__amd64)
273 # define X86_64
274 # define SOLARIS
275 # define mach_type_known
276 # endif
277 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
278 # define I386
279 # define OS2
280 # define mach_type_known
281 # endif
282 # if defined(ibm032) && !defined(CPPCHECK)
283 # error IBM PC/RT no longer supported.
284 # endif
285 # if (defined(sun) || defined(__sun)) && (defined(sparc) || defined(__sparc))
286 /* Test for SunOS 5.x */
287 EXTERN_C_END
288 # include <errno.h>
289 EXTERN_C_BEGIN
290 # define SPARC
291 # define SOLARIS
292 # define mach_type_known
293 # elif defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
294 && !defined(__OpenBSD__) && !defined(__NetBSD__) \
295 && !defined(__FreeBSD__) && !defined(__DragonFly__)
296 # define SPARC
297 # define DRSNX
298 # define mach_type_known
299 # endif
300 # if defined(_IBMR2)
301 # define POWERPC
302 # define AIX
303 # define mach_type_known
304 # endif
305 # if defined(__NetBSD__) && defined(__sparc__)
306 # define SPARC
307 # define mach_type_known
308 # endif
309 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
310 /* The above test may need refinement */
311 # define I386
312 # if defined(_SCO_ELF)
313 # define SCO_ELF
314 # else
315 # define SCO
316 # endif
317 # define mach_type_known
318 # endif
319 # if defined(_AUX_SOURCE) && !defined(CPPCHECK)
320 # error A/UX no longer supported
321 # endif
322 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
323 || defined(hppa) || defined(__hppa__)
324 # define HP_PA
325 # if !defined(LINUX) && !defined(HPUX) && !defined(OPENBSD)
326 # define HPUX
327 # endif
328 # define mach_type_known
329 # endif
330 # if defined(__ia64) && (defined(_HPUX_SOURCE) || defined(__HP_aCC))
331 # define IA64
332 # ifndef HPUX
333 # define HPUX
334 # endif
335 # define mach_type_known
336 # endif
337 # if (defined(__BEOS__) || defined(__HAIKU__)) && defined(_X86_)
338 # define I386
339 # define HAIKU
340 # define mach_type_known
341 # endif
342 # if defined(__HAIKU__) && (defined(__amd64__) || defined(__x86_64__))
343 # define X86_64
344 # define HAIKU
345 # define mach_type_known
346 # endif
347 # if defined(OPENBSD) && defined(__amd64__)
348 # define X86_64
349 # define mach_type_known
350 # endif
351 # if defined(LINUX) && (defined(i386) || defined(__i386__))
352 # define I386
353 # define mach_type_known
354 # endif
355 # if defined(LINUX) && defined(__x86_64__)
356 # define X86_64
357 # define mach_type_known
358 # endif
359 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
360 # define IA64
361 # define mach_type_known
362 # endif
363 # if defined(LINUX) && defined(__aarch64__)
364 # define AARCH64
365 # define mach_type_known
366 # endif
367 # if defined(LINUX) && (defined(__arm) || defined(__arm__))
368 # define ARM32
369 # define mach_type_known
370 # endif
371 # if defined(LINUX) && defined(__cris__)
372 # ifndef CRIS
373 # define CRIS
374 # endif
375 # define mach_type_known
376 # endif
377 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__) \
378 || defined(powerpc64) || defined(__powerpc64__))
379 # define POWERPC
380 # define mach_type_known
381 # endif
382 # if defined(LINUX) && defined(__mc68000__)
383 # define M68K
384 # define mach_type_known
385 # endif
386 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
387 # define SPARC
388 # define mach_type_known
389 # endif
390 # if defined(LINUX) && defined(__sh__)
391 # define SH
392 # define mach_type_known
393 # endif
394 # if defined(LINUX) && defined(__avr32__)
395 # define AVR32
396 # define mach_type_known
397 # endif
398 # if defined(LINUX) && defined(__m32r__)
399 # define M32R
400 # define mach_type_known
401 # endif
402 # if defined(__alpha) || defined(__alpha__)
403 # define ALPHA
404 # if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD) \
405 && !defined(FREEBSD)
406 # define OSF1 /* a.k.a Digital Unix */
407 # endif
408 # define mach_type_known
409 # endif
410 # if defined(_AMIGA) && !defined(AMIGA)
411 # define AMIGA
412 # endif
413 # ifdef AMIGA
414 # define M68K
415 # define mach_type_known
416 # endif
417 # if defined(THINK_C) \
418 || (defined(__MWERKS__) && !defined(__powerc) && !defined(SYMBIAN))
419 # define M68K
420 # define MACOS
421 # define mach_type_known
422 # endif
423 # if defined(__MWERKS__) && defined(__powerc) && !defined(__MACH__) \
424 && !defined(SYMBIAN)
425 # define POWERPC
426 # define MACOS
427 # define mach_type_known
428 # endif
429 # if defined(__OpenBSD__) && defined(__powerpc__)
430 # define POWERPC
431 # define OPENBSD
432 # define mach_type_known
433 # endif
434 # if defined(DARWIN)
435 # if defined(__ppc__) || defined(__ppc64__)
436 # define POWERPC
437 # define mach_type_known
438 # elif defined(__x86_64__) || defined(__x86_64)
439 # define X86_64
440 # define mach_type_known
441 # elif defined(__i386__)
442 # define I386
443 # define mach_type_known
444 # elif defined(__arm__)
445 # define ARM32
446 # define mach_type_known
447 # elif defined(__aarch64__)
448 # define AARCH64
449 # define mach_type_known
450 # endif
451 # endif
452 # if defined(__rtems__) && (defined(i386) || defined(__i386__))
453 # define I386
454 # define RTEMS
455 # define mach_type_known
456 # endif
457 # if defined(NeXT) && defined(mc68000)
458 # define M68K
459 # define NEXT
460 # define mach_type_known
461 # endif
462 # if defined(NeXT) && (defined(i386) || defined(__i386__))
463 # define I386
464 # define NEXT
465 # define mach_type_known
466 # endif
467 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
468 # define I386
469 # define OPENBSD
470 # define mach_type_known
471 # endif
472 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
473 # define I386
474 # define mach_type_known
475 # endif
476 # if defined(__NetBSD__) && defined(__x86_64__)
477 # define X86_64
478 # define mach_type_known
479 # endif
480 # if defined(FREEBSD) && (defined(i386) || defined(__i386__))
481 # define I386
482 # define mach_type_known
483 # endif
484 # if (defined(FREEBSD)) \
485 && (defined(__amd64__) || defined(__x86_64__))
486 # define X86_64
487 # define mach_type_known
488 # endif
489 # if defined(FREEBSD) && defined(__sparc__)
490 # define SPARC
491 # define mach_type_known
492 # endif
493 # if defined(FREEBSD) && (defined(powerpc) || defined(__powerpc__))
494 # define POWERPC
495 # define mach_type_known
496 # endif
497 # if defined(FREEBSD) && defined(__arm__)
498 # define ARM32
499 # define mach_type_known
500 # endif
501 # if defined(FREEBSD) && defined(__aarch64__)
502 # define AARCH64
503 # define mach_type_known
504 # endif
505 # if defined(FREEBSD) && (defined(mips) || defined(__mips) || defined(_mips))
506 # define MIPS
507 # define mach_type_known
508 # endif
509 # if defined(bsdi) && (defined(i386) || defined(__i386__))
510 # define I386
511 # define BSDI
512 # define mach_type_known
513 # endif
514 # if !defined(mach_type_known) && defined(__386BSD__)
515 # define I386
516 # define THREE86BSD
517 # define mach_type_known
518 # endif
519 # if defined(_CX_UX) && defined(_M88K)
520 # define M88K
521 # define CX_UX
522 # define mach_type_known
523 # endif
524 # if defined(DGUX) && defined(m88k)
525 # define M88K
526 /* DGUX defined */
527 # define mach_type_known
528 # endif
529 # if defined(_WIN32_WCE) || defined(__CEGCC__) || defined(__MINGW32CE__)
530 /* SH3, SH4, MIPS already defined for corresponding architectures */
531 # if defined(SH3) || defined(SH4)
532 # define SH
533 # endif
534 # if defined(x86) || defined(__i386__)
535 # define I386
536 # endif
537 # if defined(_M_ARM) || defined(ARM) || defined(_ARM_)
538 # define ARM32
539 # endif
540 # define MSWINCE
541 # define mach_type_known
542 # else
543 # if ((defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300)) \
544 || (defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__) \
545 && !defined(SYMBIAN))
546 # if defined(__LP64__) || defined(_M_X64)
547 # define X86_64
548 # elif defined(_M_ARM)
549 # define ARM32
550 # elif defined(_M_ARM64)
551 # define AARCH64
552 # else /* _M_IX86 */
553 # define I386
554 # endif
555 # ifdef _XBOX_ONE
556 # define MSWIN_XBOX1
557 # else
558 # define MSWIN32 /* or Win64 */
559 # if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
560 # define MSWINRT_FLAVOR
561 # endif
562 # endif
563 # define mach_type_known
564 # endif
565 # if defined(_MSC_VER) && defined(_M_IA64)
566 # define IA64
567 # define MSWIN32 /* Really win64, but we don't treat 64-bit */
568 /* variants as a different platform. */
569 # endif
570 # endif
571 # if defined(__DJGPP__)
572 # define I386
573 # ifndef DJGPP
574 # define DJGPP /* MSDOS running the DJGPP port of GCC */
575 # endif
576 # define mach_type_known
577 # endif
578 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
579 # if defined(__LP64__)
580 # define X86_64
581 # else
582 # define I386
583 # endif
584 # define CYGWIN32
585 # define mach_type_known
586 # endif
587 # if defined(__MINGW32__) && !defined(mach_type_known)
588 # define I386
589 # define MSWIN32
590 # define mach_type_known
591 # endif
592 # if defined(__BORLANDC__)
593 # define I386
594 # define MSWIN32
595 # define mach_type_known
596 # endif
597 # if defined(_UTS) && !defined(mach_type_known)
598 # define S370
599 # define UTS4
600 # define mach_type_known
601 # endif
602 # if defined(__pj__) && !defined(CPPCHECK)
603 # error PicoJava no longer supported
604 /* The implementation had problems, and I haven't heard of users */
605 /* in ages. If you want it resurrected, let me know. */
606 # endif
607 # if defined(__embedded__) && defined(PPC)
608 # define POWERPC
609 # define NOSYS
610 # define mach_type_known
611 # endif
612
613 # if defined(__WATCOMC__) && defined(__386__)
614 # define I386
615 # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
616 # if defined(__OS2__)
617 # define OS2
618 # else
619 # if defined(__WINDOWS_386__) || defined(__NT__)
620 # define MSWIN32
621 # else
622 # define DOS4GW
623 # endif
624 # endif
625 # endif
626 # define mach_type_known
627 # endif
628 # if defined(__s390__) && defined(LINUX)
629 # define S390
630 # define mach_type_known
631 # endif
632 # if defined(__GNU__)
633 # if defined(__i386__)
634 /* The Debian Hurd running on generic PC */
635 # define HURD
636 # define I386
637 # define mach_type_known
638 # endif
639 # endif
640 # if defined(__TANDEM)
641 /* Nonstop S-series */
642 /* FIXME: Should recognize Integrity series? */
643 # define MIPS
644 # define NONSTOP
645 # define mach_type_known
646 # endif
647 # if defined(__hexagon__) && defined(LINUX)
648 # define HEXAGON
649 # define mach_type_known
650 # endif
651 # if defined(__tile__) && defined(LINUX)
652 # ifdef __tilegx__
653 # define TILEGX
654 # else
655 # define TILEPRO
656 # endif
657 # define mach_type_known
658 # endif
659 # if defined(__riscv) && defined(LINUX)
660 # define RISCV
661 # define mach_type_known
662 # endif
663
664 # if defined(SN_TARGET_PSP2)
665 # define mach_type_known
666 # endif
667
668 # if defined(NN_PLATFORM_CTR)
669 # define mach_type_known
670 # endif
671
672 # if defined(NN_BUILD_TARGET_PLATFORM_NX)
673 # define NINTENDO_SWITCH
674 # define mach_type_known
675 # endif
676
677 # if defined(SYMBIAN)
678 # define mach_type_known
679 # endif
680
681 # if defined(__EMSCRIPTEN__)
682 # define I386
683 # define mach_type_known
684 # endif
685
686 /* Feel free to add more clauses here */
687
688 /* Or manually define the machine type here. A machine type is */
689 /* characterized by the architecture. Some */
690 /* machine types are further subdivided by OS. */
691 /* Macros such as LINUX, FREEBSD, etc. distinguish them. */
692 /* SYSV on an M68K actually means A/UX. */
693 /* The distinction in these cases is usually the stack starting address */
694 # if !defined(mach_type_known) && !defined(CPPCHECK)
695 # error "The collector has not been ported to this machine/OS combination."
696 # endif
697 /* Mapping is: M68K ==> Motorola 680X0 */
698 /* (NEXT, and SYSV (A/UX), */
699 /* MACOS and AMIGA variants) */
700 /* I386 ==> Intel 386 */
701 /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
702 /* FREEBSD, THREE86BSD, MSWIN32, */
703 /* BSDI, SOLARIS, NEXT and others) */
704 /* NS32K ==> Encore Multimax */
705 /* MIPS ==> R2000 through R14K */
706 /* (many variants) */
707 /* VAX ==> DEC VAX */
708 /* (BSD, ULTRIX variants) */
709 /* HP_PA ==> HP9000/700 & /800 */
710 /* HP/UX, LINUX */
711 /* SPARC ==> SPARC v7/v8/v9 */
712 /* (SOLARIS, LINUX, DRSNX variants) */
713 /* ALPHA ==> DEC Alpha */
714 /* (OSF1 and LINUX variants) */
715 /* M88K ==> Motorola 88XX0 */
716 /* (CX_UX and DGUX) */
717 /* S370 ==> 370-like machine */
718 /* running Amdahl UTS4 */
719 /* S390 ==> 390-like machine */
720 /* running LINUX */
721 /* AARCH64 ==> ARM AArch64 */
722 /* ARM32 ==> Intel StrongARM */
723 /* IA64 ==> Intel IPF */
724 /* (e.g. Itanium) */
725 /* (LINUX and HPUX) */
726 /* SH ==> Hitachi SuperH */
727 /* (LINUX & MSWINCE) */
728 /* X86_64 ==> AMD x86-64 */
729 /* POWERPC ==> IBM/Apple PowerPC */
730 /* (MACOS(<=9),DARWIN(incl.MACOSX),*/
731 /* LINUX, NETBSD, AIX, NOSYS */
732 /* variants) */
733 /* Handles 32 and 64-bit variants. */
734 /* CRIS ==> Axis Etrax */
735 /* M32R ==> Renesas M32R */
736 /* HEXAGON ==> Qualcomm Hexagon */
737 /* TILEPRO ==> Tilera TILEPro */
738 /* TILEGX ==> Tilera TILE-Gx */
739
740
741 /*
742 * For each architecture and OS, the following need to be defined:
743 *
744 * CPP_WORDSZ is a simple integer constant representing the word size.
745 * in bits. We assume byte addressability, where a byte has 8 bits.
746 * We also assume CPP_WORDSZ is either 32 or 64.
747 * (We care about the length of pointers, not hardware
748 * bus widths. Thus a 64 bit processor with a C compiler that uses
749 * 32 bit pointers should use CPP_WORDSZ of 32, not 64. Default is 32.)
750 *
751 * MACH_TYPE is a string representation of the machine type.
752 * OS_TYPE is analogous for the OS.
753 *
754 * ALIGNMENT is the largest N, such that
755 * all pointer are guaranteed to be aligned on N byte boundaries.
756 * defining it to be 1 will always work, but perform poorly.
757 *
758 * DATASTART is the beginning of the data segment.
759 * On some platforms SEARCH_FOR_DATA_START is defined.
760 * SEARCH_FOR_DATASTART will cause GC_data_start to
761 * be set to an address determined by accessing data backwards from _end
762 * until an unmapped page is found. DATASTART will be defined to be
763 * GC_data_start.
764 * On UNIX-like systems, the collector will scan the area between DATASTART
765 * and DATAEND for root pointers.
766 *
767 * DATAEND, if not "end", where "end" is defined as "extern int end[]".
768 * RTH suggests gaining access to linker script synth'd values with
769 * this idiom instead of "&end", where "end" is defined as "extern int end".
770 * Otherwise, "GCC will assume these are in .sdata/.sbss" and it will, e.g.,
771 * cause failures on alpha*-*-* with -msmall-data or -fpic or mips-*-*
772 * without any special options.
773 *
774 * STACKBOTTOM is the cool end of the stack, which is usually the
775 * highest address in the stack.
776 * Under PCR or OS/2, we have other ways of finding thread stacks.
777 * For each machine, the following should:
778 * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
779 * 2) define exactly one of
780 * STACKBOTTOM (should be defined to be an expression)
781 * LINUX_STACKBOTTOM
782 * HEURISTIC1
783 * HEURISTIC2
784 * If STACKBOTTOM is defined, then its value will be used directly as the
785 * stack base. If LINUX_STACKBOTTOM is defined, then it will be determined
786 * with a method appropriate for most Linux systems. Currently we look
787 * first for __libc_stack_end (currently only if USE_LIBC_PRIVATES is
788 * defined), and if that fails read it from /proc. (If USE_LIBC_PRIVATES
789 * is not defined and NO_PROC_STAT is defined, we revert to HEURISTIC2.)
790 * If either of the last two macros are defined, then STACKBOTTOM is computed
791 * during collector startup using one of the following two heuristics:
792 * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
793 * the next multiple of STACK_GRAN.
794 * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
795 * in small steps (decrement if STACK_GROWS_UP), and read the value
796 * at each location. Remember the value when the first
797 * Segmentation violation or Bus error is signaled. Round that
798 * to the nearest plausible page boundary, and use that instead
799 * of STACKBOTTOM.
800 *
801 * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
802 * the value of environ is a pointer that can serve as STACKBOTTOM.
803 * I expect that HEURISTIC2 can be replaced by this approach, which
804 * interferes far less with debugging. However it has the disadvantage
805 * that it's confused by a putenv call before the collector is initialized.
806 * This could be dealt with by intercepting putenv ...
807 *
808 * If no expression for STACKBOTTOM can be found, and neither of the above
809 * heuristics are usable, the collector can still be used with all of the above
810 * undefined, provided one of the following is done:
811 * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
812 * without reference to STACKBOTTOM. This is appropriate for use in
813 * conjunction with thread packages, since there will be multiple stacks.
814 * (Allocating thread stacks in the heap, and treating them as ordinary
815 * heap data objects is also possible as a last resort. However, this is
816 * likely to introduce significant amounts of excess storage retention
817 * unless the dead parts of the thread stacks are periodically cleared.)
818 * 2) Client code may set GC_stackbottom before calling any GC_ routines.
819 * If the author of the client code controls the main program, this is
820 * easily accomplished by introducing a new main program, setting
821 * GC_stackbottom to the address of a local variable, and then calling
822 * the original main program. The new main program would read something
823 * like (provided real_main() is not inlined by the compiler):
824 *
825 * #include "gc.h"
826 *
827 * main(argc, argv, envp)
828 * int argc;
829 * char **argv, **envp;
830 * {
831 * volatile int dummy;
832 *
833 * GC_stackbottom = (ptr_t)(&dummy);
834 * return(real_main(argc, argv, envp));
835 * }
836 *
837 *
838 * Each architecture may also define the style of virtual dirty bit
839 * implementation to be used:
840 * MPROTECT_VDB: Write protect the heap and catch faults.
841 * GWW_VDB: Use win32 GetWriteWatch primitive.
842 * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
843 *
844 * The first and second one may be combined, in which case a runtime
845 * selection will be made, based on GetWriteWatch availability.
846 *
847 * An architecture may define DYNAMIC_LOADING if dyn_load.c
848 * defined GC_register_dynamic_libraries() for the architecture.
849 *
850 * An architecture may define PREFETCH(x) to preload the cache with *x.
851 * This defaults to GCC built-in operation (or a no-op for other compilers).
852 *
853 * GC_PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
854 *
855 * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
856 * clear the two words at GC_malloc-aligned address x. By default,
857 * word stores of 0 are used instead.
858 *
859 * HEAP_START may be defined as the initial address hint for mmap-based
860 * allocation.
861 */
862
863 /* If available, we can use __builtin_unwind_init() to push the */
864 /* relevant registers onto the stack. */
865 # if GC_GNUC_PREREQ(2, 8) \
866 && !defined(__INTEL_COMPILER) && !defined(__PATHCC__) \
867 && !defined(__FUJITSU) /* for FX10 system */ \
868 && !(defined(POWERPC) && defined(DARWIN)) /* for MacOS X 10.3.9 */ \
869 && !defined(RTEMS) \
870 && !defined(__ARMCC_VERSION) /* does not exist in armcc gnu emu */ \
871 && !defined(__clang__) /* since no-op in clang (3.0) */
872 # define HAVE_BUILTIN_UNWIND_INIT
873 # endif
874
875 # ifdef SYMBIAN
876 # define MACH_TYPE "SYMBIAN"
877 # define OS_TYPE "SYMBIAN"
878 # define CPP_WORDSZ 32
879 # define ALIGNMENT 4
880 # define DATASTART (ptr_t)ALIGNMENT /* cannot be null */
881 # define DATAEND (ptr_t)ALIGNMENT
882 # endif
883
884 # ifdef __EMSCRIPTEN__
885 # define OS_TYPE "EMSCRIPTEN"
886 # define CPP_WORDSZ 32
887 # define ALIGNMENT 4
888 # define DATASTART (ptr_t)ALIGNMENT
889 # define DATAEND (ptr_t)ALIGNMENT
890 /* Since JavaScript/asm.js/WebAssembly is not able to access the */
891 /* function call stack or the local data stack, it is not possible */
892 /* for GC to perform its stack walking operation to find roots on */
893 /* the stack. To work around that, the clients generally only do */
894 /* BDWGC steps when the stack is empty so it is known that there */
895 /* are no objects that would be found on the stack, and BDWGC is */
896 /* compiled with stack walking disabled. */
897 # define STACK_NOT_SCANNED
898 # endif
899
900 # define STACK_GRAN 0x1000000
901 # ifdef M68K
902 # define MACH_TYPE "M68K"
903 # define ALIGNMENT 2
904 # ifdef OPENBSD
905 /* FIXME: Should we remove this case? */
906 # define OS_TYPE "OPENBSD"
907 # define HEURISTIC2
908 # ifdef __ELF__
909 extern ptr_t GC_data_start;
910 # define DATASTART GC_data_start
911 # define DYNAMIC_LOADING
912 # else
913 extern char etext[];
914 # define DATASTART ((ptr_t)(etext))
915 # endif
916 # endif
917 # ifdef NETBSD
918 # define OS_TYPE "NETBSD"
919 # define HEURISTIC2
920 # ifdef __ELF__
921 extern ptr_t GC_data_start;
922 # define DATASTART GC_data_start
923 # define DYNAMIC_LOADING
924 # else
925 extern char etext[];
926 # define DATASTART ((ptr_t)(etext))
927 # endif
928 # endif
929 # ifdef LINUX
930 # define OS_TYPE "LINUX"
931 # define LINUX_STACKBOTTOM
932 # define MPROTECT_VDB
933 # ifdef __ELF__
934 # define DYNAMIC_LOADING
935 EXTERN_C_END
936 # include <features.h>
937 EXTERN_C_BEGIN
938 # if defined(__GLIBC__) && __GLIBC__ >= 2
939 # define SEARCH_FOR_DATA_START
940 # else /* !GLIBC2 */
941 extern char **__environ;
942 # define DATASTART ((ptr_t)(&__environ))
943 /* hideous kludge: __environ is the first */
944 /* word in crt0.o, and delimits the start */
945 /* of the data segment, no matter which */
946 /* ld options were passed through. */
947 /* We could use _etext instead, but that */
948 /* would include .rodata, which may */
949 /* contain large read-only data tables */
950 /* that we'd rather not scan. */
951 # endif /* !GLIBC2 */
952 extern int _end[];
953 # define DATAEND ((ptr_t)(_end))
954 # else
955 extern int etext[];
956 # define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
957 # endif
958 # endif
959 # ifdef AMIGA
960 # define OS_TYPE "AMIGA"
961 /* STACKBOTTOM and DATASTART handled specially */
962 /* in os_dep.c */
963 # define DATAEND /* not needed */
964 # define GETPAGESIZE() 4096
965 # endif
966 # ifdef MACOS
967 # ifndef __LOWMEM__
968 EXTERN_C_END
969 # include <LowMem.h>
970 EXTERN_C_BEGIN
971 # endif
972 # define OS_TYPE "MACOS"
973 /* see os_dep.c for details of global data segments. */
974 # define STACKBOTTOM ((ptr_t)LMGetCurStackBase())
975 # define DATAEND /* not needed */
976 # define GETPAGESIZE() 4096
977 # endif
978 # ifdef NEXT
979 # define OS_TYPE "NEXT"
980 # define DATASTART ((ptr_t)get_etext())
981 # define DATASTART_IS_FUNC
982 # define STACKBOTTOM ((ptr_t)0x4000000)
983 # define DATAEND /* not needed */
984 # endif
985 # endif
986
987 # if defined(POWERPC)
988 # define MACH_TYPE "POWERPC"
989 # ifdef MACOS
990 # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
991 # ifndef __LOWMEM__
992 EXTERN_C_END
993 # include <LowMem.h>
994 EXTERN_C_BEGIN
995 # endif
996 # define OS_TYPE "MACOS"
997 /* see os_dep.c for details of global data segments. */
998 # define STACKBOTTOM ((ptr_t)LMGetCurStackBase())
999 # define DATAEND /* not needed */
1000 # endif
1001 # ifdef LINUX
1002 # if defined(__powerpc64__)
1003 # define ALIGNMENT 8
1004 # define CPP_WORDSZ 64
1005 # ifndef HBLKSIZE
1006 # define HBLKSIZE 4096
1007 # endif
1008 # else
1009 # define ALIGNMENT 4
1010 # endif
1011 # define OS_TYPE "LINUX"
1012 /* HEURISTIC1 has been reliably reported to fail for a 32-bit */
1013 /* executable on a 64 bit kernel. */
1014 # if defined(__bg__)
1015 /* The Linux Compute Node Kernel (used on BlueGene systems) */
1016 /* does not support LINUX_STACKBOTTOM way. */
1017 # define HEURISTIC2
1018 # define NO_PTHREAD_GETATTR_NP
1019 # else
1020 # define LINUX_STACKBOTTOM
1021 # endif
1022 # define DYNAMIC_LOADING
1023 # define SEARCH_FOR_DATA_START
1024 extern int _end[];
1025 # define DATAEND ((ptr_t)(_end))
1026 # endif
1027 # ifdef DARWIN
1028 # define OS_TYPE "DARWIN"
1029 # define DYNAMIC_LOADING
1030 # if defined(__ppc64__)
1031 # define ALIGNMENT 8
1032 # define CPP_WORDSZ 64
1033 # define STACKBOTTOM ((ptr_t)0x7fff5fc00000)
1034 # define CACHE_LINE_SIZE 64
1035 # ifndef HBLKSIZE
1036 # define HBLKSIZE 4096
1037 # endif
1038 # else
1039 # define ALIGNMENT 4
1040 # define STACKBOTTOM ((ptr_t)0xc0000000)
1041 # endif
1042 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
1043 /* These aren't used when dyld support is enabled (it is by default). */
1044 # define DATASTART ((ptr_t)get_etext())
1045 # define DATAEND ((ptr_t)get_end())
1046 # define USE_MMAP_ANON
1047 # define MPROTECT_VDB
1048 EXTERN_C_END
1049 # include <unistd.h>
1050 EXTERN_C_BEGIN
1051 # define GETPAGESIZE() (unsigned)getpagesize()
1052 # if defined(USE_PPC_PREFETCH) && defined(__GNUC__)
1053 /* The performance impact of prefetches is untested */
1054 # define PREFETCH(x) \
1055 __asm__ __volatile__ ("dcbt 0,%0" : : "r" ((const void *) (x)))
1056 # define GC_PREFETCH_FOR_WRITE(x) \
1057 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" ((const void *) (x)))
1058 # endif
1059 /* There seems to be some issues with trylock hanging on darwin. */
1060 /* This should be looked into some more. */
1061 # define NO_PTHREAD_TRYLOCK
1062 # endif
1063 # ifdef OPENBSD
1064 # define OS_TYPE "OPENBSD"
1065 # define ALIGNMENT 4
1066 # ifndef GC_OPENBSD_THREADS
1067 EXTERN_C_END
1068 # include <sys/param.h>
1069 # include <uvm/uvm_extern.h>
1070 EXTERN_C_BEGIN
1071 /* USRSTACK is defined in <machine/vmparam.h> but that is */
1072 /* protected by _KERNEL in <uvm/uvm_param.h> file. */
1073 # ifdef USRSTACK
1074 # define STACKBOTTOM ((ptr_t)USRSTACK)
1075 # else
1076 # define HEURISTIC2
1077 # endif
1078 # endif
1079 extern int __data_start[];
1080 # define DATASTART ((ptr_t)__data_start)
1081 extern int _end[];
1082 # define DATAEND ((ptr_t)(&_end))
1083 # define DYNAMIC_LOADING
1084 # endif
1085 # ifdef FREEBSD
1086 # if defined(__powerpc64__)
1087 # define ALIGNMENT 8
1088 # define CPP_WORDSZ 64
1089 # ifndef HBLKSIZE
1090 # define HBLKSIZE 4096
1091 # endif
1092 # else
1093 # define ALIGNMENT 4
1094 # endif
1095 # define OS_TYPE "FREEBSD"
1096 # ifndef GC_FREEBSD_THREADS
1097 # define MPROTECT_VDB
1098 # endif
1099 # define SIG_SUSPEND SIGUSR1
1100 # define SIG_THR_RESTART SIGUSR2
1101 # define FREEBSD_STACKBOTTOM
1102 # ifdef __ELF__
1103 # define DYNAMIC_LOADING
1104 # endif
1105 extern char etext[];
1106 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
1107 # define DATASTART_USES_BSDGETDATASTART
1108 # endif
1109 # ifdef NETBSD
1110 # define ALIGNMENT 4
1111 # define OS_TYPE "NETBSD"
1112 # define HEURISTIC2
1113 extern ptr_t GC_data_start;
1114 # define DATASTART GC_data_start
1115 # define DYNAMIC_LOADING
1116 # endif
1117 # ifdef SN_TARGET_PS3
1118 # define NO_GETENV
1119 # define CPP_WORDSZ 32
1120 # define ALIGNMENT 4
1121 extern int _end[];
1122 extern int __bss_start;
1123 # define DATASTART ((ptr_t)(__bss_start))
1124 # define DATAEND ((ptr_t)(_end))
1125 # define STACKBOTTOM ((ptr_t)ps3_get_stack_bottom())
1126 # define NO_PTHREAD_TRYLOCK
1127 /* Current GC LOCK() implementation for PS3 explicitly */
1128 /* use pthread_mutex_lock for some reason. */
1129 # endif
1130 # ifdef AIX
1131 # define OS_TYPE "AIX"
1132 # undef ALIGNMENT /* in case it's defined */
1133 # undef IA64
1134 /* DOB: some AIX installs stupidly define IA64 in */
1135 /* /usr/include/sys/systemcfg.h */
1136 # ifdef __64BIT__
1137 # define ALIGNMENT 8
1138 # define CPP_WORDSZ 64
1139 # define STACKBOTTOM ((ptr_t)0x1000000000000000)
1140 # else
1141 # define ALIGNMENT 4
1142 # define CPP_WORDSZ 32
1143 # define STACKBOTTOM ((ptr_t)((ulong)&errno))
1144 # endif
1145 # define USE_MMAP_ANON
1146 /* From AIX linker man page:
1147 _text Specifies the first location of the program.
1148 _etext Specifies the first location after the program.
1149 _data Specifies the first location of the data.
1150 _edata Specifies the first location after the initialized data
1151 _end or end Specifies the first location after all data.
1152 */
1153 extern int _data[], _end[];
1154 # define DATASTART ((ptr_t)((ulong)_data))
1155 # define DATAEND ((ptr_t)((ulong)_end))
1156 extern int errno;
1157 # define DYNAMIC_LOADING
1158 /* For really old versions of AIX, this may have to be removed. */
1159 # endif
1160
1161 # ifdef NOSYS
1162 # define ALIGNMENT 4
1163 # define OS_TYPE "NOSYS"
1164 extern void __end[], __dso_handle[];
1165 # define DATASTART ((ptr_t)__dso_handle) /* OK, that's ugly. */
1166 # define DATAEND ((ptr_t)(__end))
1167 /* Stack starts at 0xE0000000 for the simulator. */
1168 # undef STACK_GRAN
1169 # define STACK_GRAN 0x10000000
1170 # define HEURISTIC1
1171 # endif
1172 # endif
1173
1174 # ifdef NACL
1175 # define OS_TYPE "NACL"
1176 # if defined(__GLIBC__)
1177 # define DYNAMIC_LOADING
1178 # endif
1179 # define DATASTART ((ptr_t)0x10020000)
1180 extern int _end[];
1181 # define DATAEND ((ptr_t)_end)
1182 # undef STACK_GRAN
1183 # define STACK_GRAN 0x10000
1184 # define HEURISTIC1
1185 # define NO_PTHREAD_GETATTR_NP
1186 # define USE_MUNMAP
1187 # define USE_MMAP_ANON
1188 # define GETPAGESIZE() 65536
1189 # define MAX_NACL_GC_THREADS 1024
1190 # endif
1191
1192 # ifdef VAX
1193 # define MACH_TYPE "VAX"
1194 # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
1195 extern char etext[];
1196 # define DATASTART ((ptr_t)(etext))
1197 # ifdef BSD
1198 # define OS_TYPE "BSD"
1199 # define HEURISTIC1
1200 /* HEURISTIC2 may be OK, but it's hard to test. */
1201 # endif
1202 # ifdef ULTRIX
1203 # define OS_TYPE "ULTRIX"
1204 # define STACKBOTTOM ((ptr_t)0x7fffc800)
1205 # endif
1206 # endif
1207
1208 # ifdef SPARC
1209 # define MACH_TYPE "SPARC"
1210 # if defined(__arch64__) || defined(__sparcv9)
1211 # define ALIGNMENT 8
1212 # define CPP_WORDSZ 64
1213 # define ELF_CLASS ELFCLASS64
1214 # else
1215 # define ALIGNMENT 4 /* Required by hardware */
1216 # define CPP_WORDSZ 32
1217 # endif
1218 /* Don't define USE_ASM_PUSH_REGS. We do use an asm helper, but */
1219 /* not to push the registers on the mark stack. */
1220 # ifdef SOLARIS
1221 # define OS_TYPE "SOLARIS"
1222 extern int _etext[];
1223 extern int _end[];
1224 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1225 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1226 # define DATASTART_IS_FUNC
1227 # define DATAEND ((ptr_t)(_end))
1228 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1229 # define USE_MMAP
1230 /* Otherwise we now use calloc. Mmap may result in the */
1231 /* heap interleaved with thread stacks, which can result in */
1232 /* excessive blacklisting. Sbrk is unusable since it */
1233 /* doesn't interact correctly with the system malloc. */
1234 # endif
1235 # ifdef USE_MMAP
1236 # define HEAP_START (ptr_t)0x40000000
1237 # else
1238 # define HEAP_START DATAEND
1239 # endif
1240 # define PROC_VDB
1241 /* HEURISTIC1 reportedly no longer works under 2.7. */
1242 /* HEURISTIC2 probably works, but this appears to be preferable.*/
1243 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
1244 /* installations that's undefined. We work around this with a */
1245 /* gross hack: */
1246 EXTERN_C_END
1247 # include <sys/vmparam.h>
1248 # include <unistd.h>
1249 EXTERN_C_BEGIN
1250 # ifdef USERLIMIT
1251 /* This should work everywhere, but doesn't. */
1252 # define STACKBOTTOM ((ptr_t)USRSTACK)
1253 # else
1254 # define HEURISTIC2
1255 # endif
1256 # define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE)
1257 /* getpagesize() appeared to be missing from at least one */
1258 /* Solaris 5.4 installation. Weird. */
1259 # define DYNAMIC_LOADING
1260 # endif
1261 # ifdef DRSNX
1262 # define OS_TYPE "DRSNX"
1263 extern int etext[];
1264 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1265 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
1266 # define DATASTART_IS_FUNC
1267 # define MPROTECT_VDB
1268 # define STACKBOTTOM ((ptr_t)0xdfff0000)
1269 # define DYNAMIC_LOADING
1270 # endif
1271 # ifdef LINUX
1272 # define OS_TYPE "LINUX"
1273 # ifdef __ELF__
1274 # define DYNAMIC_LOADING
1275 # else
1276 # error --> Linux SPARC a.out not supported
1277 # endif
1278 extern int _end[];
1279 extern int _etext[];
1280 # define DATAEND ((ptr_t)(_end))
1281 # define SVR4
1282 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1283 # ifdef __arch64__
1284 # define DATASTART GC_SysVGetDataStart(0x100000, (ptr_t)_etext)
1285 # else
1286 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
1287 # endif
1288 # define DATASTART_IS_FUNC
1289 # define LINUX_STACKBOTTOM
1290 # endif
1291 # ifdef OPENBSD
1292 # define OS_TYPE "OPENBSD"
1293 # ifndef GC_OPENBSD_THREADS
1294 EXTERN_C_END
1295 # include <sys/param.h>
1296 # include <uvm/uvm_extern.h>
1297 EXTERN_C_BEGIN
1298 # ifdef USRSTACK
1299 # define STACKBOTTOM ((ptr_t)USRSTACK)
1300 # else
1301 # define HEURISTIC2
1302 # endif
1303 # endif
1304 extern int __data_start[];
1305 # define DATASTART ((ptr_t)__data_start)
1306 extern int _end[];
1307 # define DATAEND ((ptr_t)(&_end))
1308 # define DYNAMIC_LOADING
1309 # endif
1310 # ifdef NETBSD
1311 # define OS_TYPE "NETBSD"
1312 # define HEURISTIC2
1313 # ifdef __ELF__
1314 extern ptr_t GC_data_start;
1315 # define DATASTART GC_data_start
1316 # define DYNAMIC_LOADING
1317 # else
1318 extern char etext[];
1319 # define DATASTART ((ptr_t)(etext))
1320 # endif
1321 # endif
1322 # ifdef FREEBSD
1323 # define OS_TYPE "FREEBSD"
1324 # define SIG_SUSPEND SIGUSR1
1325 # define SIG_THR_RESTART SIGUSR2
1326 # define FREEBSD_STACKBOTTOM
1327 # ifdef __ELF__
1328 # define DYNAMIC_LOADING
1329 # endif
1330 extern char etext[];
1331 extern char edata[];
1332 extern char end[];
1333 # define NEED_FIND_LIMIT
1334 # define DATASTART ((ptr_t)(&etext))
1335 ptr_t GC_find_limit(ptr_t, GC_bool);
1336 # define DATAEND GC_find_limit(DATASTART, TRUE)
1337 # define DATAEND_IS_FUNC
1338 # define GC_HAVE_DATAREGION2
1339 # define DATASTART2 ((ptr_t)(&edata))
1340 # define DATAEND2 ((ptr_t)(&end))
1341 # endif
1342 # endif
1343
1344 # ifdef I386
1345 # define MACH_TYPE "I386"
1346 # if defined(__LP64__) || defined(_WIN64)
1347 # error This should be handled as X86_64
1348 # else
1349 # define CPP_WORDSZ 32
1350 # define ALIGNMENT 4
1351 /* Appears to hold for all "32 bit" compilers */
1352 /* except Borland. The -a4 option fixes */
1353 /* Borland. For Watcom the option is -zp4. */
1354 # endif
1355 # ifdef SEQUENT
1356 # define OS_TYPE "SEQUENT"
1357 extern int etext[];
1358 # define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
1359 # define STACKBOTTOM ((ptr_t)0x3ffff000)
1360 # endif
1361 # ifdef HAIKU
1362 # define OS_TYPE "HAIKU"
1363 EXTERN_C_END
1364 # include <OS.h>
1365 EXTERN_C_BEGIN
1366 # define GETPAGESIZE() (unsigned)B_PAGE_SIZE
1367 extern int etext[];
1368 # define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
1369 # define DYNAMIC_LOADING
1370 # define MPROTECT_VDB
1371 # endif
1372 # ifdef SOLARIS
1373 # define OS_TYPE "SOLARIS"
1374 extern int _etext[], _end[];
1375 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1376 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
1377 # define DATASTART_IS_FUNC
1378 # define DATAEND ((ptr_t)(_end))
1379 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
1380 /* but reportedly breaks under 2.8. It appears that the stack */
1381 /* base is a property of the executable, so this should not */
1382 /* break old executables. */
1383 /* HEURISTIC2 probably works, but this appears to be preferable.*/
1384 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
1385 /* installations that's undefined. We work around this with a */
1386 /* gross hack: */
1387 EXTERN_C_END
1388 # include <sys/vmparam.h>
1389 EXTERN_C_BEGIN
1390 # ifdef USERLIMIT
1391 /* This should work everywhere, but doesn't. */
1392 # define STACKBOTTOM ((ptr_t)USRSTACK)
1393 # else
1394 # define HEURISTIC2
1395 # endif
1396 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
1397 /* It appears to be fixed in 2.8 and 2.9. */
1398 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
1399 # define PROC_VDB
1400 # endif
1401 # ifndef GC_THREADS
1402 # define MPROTECT_VDB
1403 # endif
1404 # define DYNAMIC_LOADING
1405 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
1406 # define USE_MMAP
1407 /* Otherwise we now use calloc. Mmap may result in the */
1408 /* heap interleaved with thread stacks, which can result in */
1409 /* excessive blacklisting. Sbrk is unusable since it */
1410 /* doesn't interact correctly with the system malloc. */
1411 # endif
1412 # ifdef USE_MMAP
1413 # define HEAP_START (ptr_t)0x40000000
1414 # else
1415 # define HEAP_START DATAEND
1416 # endif
1417 # endif
1418 # ifdef SCO
1419 # define OS_TYPE "SCO"
1420 extern int etext[];
1421 # define DATASTART ((ptr_t)((((word)(etext)) + 0x3fffff) & ~0x3fffff) \
1422 + ((word)(etext) & 0xfff))
1423 # define STACKBOTTOM ((ptr_t)0x7ffffffc)
1424 # endif
1425 # ifdef SCO_ELF
1426 # define OS_TYPE "SCO_ELF"
1427 extern int etext[];
1428 # define DATASTART ((ptr_t)(etext))
1429 # define STACKBOTTOM ((ptr_t)0x08048000)
1430 # define DYNAMIC_LOADING
1431 # define ELF_CLASS ELFCLASS32
1432 # endif
1433 # ifdef DGUX
1434 # define OS_TYPE "DGUX"
1435 extern int _etext, _end;
1436 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
1437 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)(&_etext))
1438 # define DATASTART_IS_FUNC
1439 # define DATAEND ((ptr_t)(&_end))
1440 # define STACK_GROWS_DOWN
1441 # define HEURISTIC2
1442 EXTERN_C_END
1443 # include <unistd.h>
1444 EXTERN_C_BEGIN
1445 # define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE)
1446 # define DYNAMIC_LOADING
1447 # ifndef USE_MMAP
1448 # define USE_MMAP
1449 # endif
1450 # define MAP_FAILED (void *) ((word)-1)
1451 # define HEAP_START (ptr_t)0x40000000
1452 # endif /* DGUX */
1453 # ifdef LINUX
1454 # define OS_TYPE "LINUX"
1455 # define LINUX_STACKBOTTOM
1456 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
1457 # define MPROTECT_VDB
1458 # else
1459 /* We seem to get random errors in incremental mode, */
1460 /* possibly because Linux threads is itself a malloc client */
1461 /* and can't deal with the signals. */
1462 # endif
1463 # define HEAP_START (ptr_t)0x1000
1464 /* This encourages mmap to give us low addresses, */
1465 /* thus allowing the heap to grow to ~3GB */
1466 # ifdef __ELF__
1467 # define DYNAMIC_LOADING
1468 EXTERN_C_END
1469 # include <features.h>
1470 EXTERN_C_BEGIN
1471 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
1472 || defined(HOST_ANDROID) || defined(HOST_TIZEN)
1473 # define SEARCH_FOR_DATA_START
1474 # else
1475 extern char **__environ;
1476 # define DATASTART ((ptr_t)(&__environ))
1477 /* hideous kludge: __environ is the first */
1478 /* word in crt0.o, and delimits the start */
1479 /* of the data segment, no matter which */
1480 /* ld options were passed through. */
1481 /* We could use _etext instead, but that */
1482 /* would include .rodata, which may */
1483 /* contain large read-only data tables */
1484 /* that we'd rather not scan. */
1485 # endif
1486 extern int _end[];
1487 # define DATAEND ((ptr_t)(_end))
1488 # if !defined(GC_NO_SIGSETJMP) && (defined(HOST_TIZEN) \
1489 || (defined(HOST_ANDROID) \
1490 && !(GC_GNUC_PREREQ(4, 8) || GC_CLANG_PREREQ(3, 2) \
1491 || __ANDROID_API__ >= 18)))
1492 /* Older Android NDK releases lack sigsetjmp in x86 libc */
1493 /* (setjmp is used instead to find data_start). The bug */
1494 /* is fixed in Android NDK r8e (so, ok to use sigsetjmp */
1495 /* if gcc4.8+, clang3.2+ or Android API level 18+). */
1496 # define GC_NO_SIGSETJMP
1497 # endif
1498 # else
1499 extern int etext[];
1500 # define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
1501 # endif
1502 # ifdef USE_I686_PREFETCH
1503 # define PREFETCH(x) \
1504 __asm__ __volatile__ ("prefetchnta %0" : : "m"(*(char *)(x)))
1505 /* Empirically prefetcht0 is much more effective at reducing */
1506 /* cache miss stalls for the targeted load instructions. But it */
1507 /* seems to interfere enough with other cache traffic that the */
1508 /* net result is worse than prefetchnta. */
1509 # ifdef FORCE_WRITE_PREFETCH
1510 /* Using prefetches for write seems to have a slight negative */
1511 /* impact on performance, at least for a PIII/500. */
1512 # define GC_PREFETCH_FOR_WRITE(x) \
1513 __asm__ __volatile__ ("prefetcht0 %0" : : "m"(*(char *)(x)))
1514 # else
1515 # define GC_NO_PREFETCH_FOR_WRITE
1516 # endif
1517 # elif defined(USE_3DNOW_PREFETCH)
1518 # define PREFETCH(x) \
1519 __asm__ __volatile__ ("prefetch %0" : : "m"(*(char *)(x)))
1520 # define GC_PREFETCH_FOR_WRITE(x) \
1521 __asm__ __volatile__ ("prefetchw %0" : : "m"(*(char *)(x)))
1522 # endif
1523 # if defined(__GLIBC__) && !defined(__UCLIBC__)
1524 /* Workaround lock elision implementation for some glibc. */
1525 # define GLIBC_2_19_TSX_BUG
1526 EXTERN_C_END
1527 # include <gnu/libc-version.h> /* for gnu_get_libc_version() */
1528 EXTERN_C_BEGIN
1529 # endif
1530 # endif
1531 # ifdef CYGWIN32
1532 # define OS_TYPE "CYGWIN32"
1533 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
1534 # define DATAEND ((ptr_t)GC_DATAEND)
1535 # undef STACK_GRAN
1536 # define STACK_GRAN 0x10000
1537 # ifdef USE_MMAP
1538 # define NEED_FIND_LIMIT
1539 # define USE_MMAP_ANON
1540 # endif
1541 # endif
1542 # ifdef OS2
1543 # define OS_TYPE "OS2"
1544 /* STACKBOTTOM and DATASTART are handled specially in */
1545 /* os_dep.c. OS2 actually has the right */
1546 /* system call! */
1547 # define DATAEND /* not needed */
1548 # endif
1549 # ifdef MSWIN32
1550 # define OS_TYPE "MSWIN32"
1551 /* STACKBOTTOM and DATASTART are handled specially in */
1552 /* os_dep.c. */
1553 # define MPROTECT_VDB
1554 # define GWW_VDB
1555 # define DATAEND /* not needed */
1556 # endif
1557 # ifdef MSWINCE
1558 # define OS_TYPE "MSWINCE"
1559 # define DATAEND /* not needed */
1560 # endif
1561 # ifdef DJGPP
1562 # define OS_TYPE "DJGPP"
1563 EXTERN_C_END
1564 # include "stubinfo.h"
1565 EXTERN_C_BEGIN
1566 extern int etext[];
1567 extern int _stklen;
1568 extern int __djgpp_stack_limit;
1569 # define DATASTART ((ptr_t)((((word)(etext)) + 0x1ff) & ~0x1ff))
1570 /* #define STACKBOTTOM ((ptr_t)((word)_stubinfo+_stubinfo->size+_stklen)) */
1571 # define STACKBOTTOM ((ptr_t)((word)__djgpp_stack_limit + _stklen))
1572 /* This may not be right. */
1573 # endif
1574 # ifdef OPENBSD
1575 # define OS_TYPE "OPENBSD"
1576 # ifndef GC_OPENBSD_THREADS
1577 EXTERN_C_END
1578 # include <sys/param.h>
1579 # include <uvm/uvm_extern.h>
1580 EXTERN_C_BEGIN
1581 # ifdef USRSTACK
1582 # define STACKBOTTOM ((ptr_t)USRSTACK)
1583 # else
1584 # define HEURISTIC2
1585 # endif
1586 # endif
1587 extern int __data_start[];
1588 # define DATASTART ((ptr_t)__data_start)
1589 extern int _end[];
1590 # define DATAEND ((ptr_t)(&_end))
1591 # define DYNAMIC_LOADING
1592 # endif
1593 # ifdef FREEBSD
1594 # define OS_TYPE "FREEBSD"
1595 # ifndef GC_FREEBSD_THREADS
1596 # define MPROTECT_VDB
1597 # endif
1598 # ifdef __GLIBC__
1599 # define SIG_SUSPEND (32+6)
1600 # define SIG_THR_RESTART (32+5)
1601 extern int _end[];
1602 # define DATAEND ((ptr_t)(_end))
1603 # else
1604 # define SIG_SUSPEND SIGUSR1
1605 # define SIG_THR_RESTART SIGUSR2
1606 /* SIGTSTP and SIGCONT could be used alternatively. */
1607 # endif
1608 # define FREEBSD_STACKBOTTOM
1609 # ifdef __ELF__
1610 # define DYNAMIC_LOADING
1611 # endif
1612 extern char etext[];
1613 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
1614 # define DATASTART_USES_BSDGETDATASTART
1615 # endif
1616 # ifdef NETBSD
1617 # define OS_TYPE "NETBSD"
1618 # ifdef __ELF__
1619 # define DYNAMIC_LOADING
1620 # endif
1621 # endif
1622 # ifdef THREE86BSD
1623 # define OS_TYPE "THREE86BSD"
1624 # endif
1625 # ifdef BSDI
1626 # define OS_TYPE "BSDI"
1627 # endif
1628 # if defined(NETBSD) || defined(THREE86BSD) || defined(BSDI)
1629 # define HEURISTIC2
1630 extern char etext[];
1631 # define DATASTART ((ptr_t)(etext))
1632 # endif
1633 # ifdef NEXT
1634 # define OS_TYPE "NEXT"
1635 # define DATASTART ((ptr_t)get_etext())
1636 # define DATASTART_IS_FUNC
1637 # define STACKBOTTOM ((ptr_t)0xc0000000)
1638 # define DATAEND /* not needed */
1639 # endif
1640 # ifdef RTEMS
1641 # define OS_TYPE "RTEMS"
1642 EXTERN_C_END
1643 # include <sys/unistd.h>
1644 EXTERN_C_BEGIN
1645 extern int etext[];
1646 extern int end[];
1647 void *rtems_get_stack_bottom(void);
1648 # define InitStackBottom rtems_get_stack_bottom()
1649 # define DATASTART ((ptr_t)etext)
1650 # define DATAEND ((ptr_t)end)
1651 # define STACKBOTTOM ((ptr_t)InitStackBottom)
1652 # define SIG_SUSPEND SIGUSR1
1653 # define SIG_THR_RESTART SIGUSR2
1654 # endif
1655 # ifdef DOS4GW
1656 # define OS_TYPE "DOS4GW"
1657 extern long __nullarea;
1658 extern char _end;
1659 extern char *_STACKTOP;
1660 /* Depending on calling conventions Watcom C either precedes */
1661 /* or does not precedes with underscore names of C-variables. */
1662 /* Make sure startup code variables always have the same names. */
1663 #pragma aux __nullarea "*";
1664 #pragma aux _end "*";
1665 # define STACKBOTTOM ((ptr_t)_STACKTOP)
1666 /* confused? me too. */
1667 # define DATASTART ((ptr_t)(&__nullarea))
1668 # define DATAEND ((ptr_t)(&_end))
1669 # endif
1670 # ifdef HURD
1671 # define OS_TYPE "HURD"
1672 # define STACK_GROWS_DOWN
1673 # define HEURISTIC2
1674 # define SIG_SUSPEND SIGUSR1
1675 # define SIG_THR_RESTART SIGUSR2
1676 # define SEARCH_FOR_DATA_START
1677 extern int _end[];
1678 # define DATAEND ((ptr_t)(_end))
1679 /* # define MPROTECT_VDB Not quite working yet? */
1680 # define DYNAMIC_LOADING
1681 # define USE_MMAP_ANON
1682 # endif
1683 # ifdef DARWIN
1684 # define OS_TYPE "DARWIN"
1685 # define DARWIN_DONT_PARSE_STACK
1686 # ifndef GC_DONT_REGISTER_MAIN_STATIC_DATA
1687 # define DYNAMIC_LOADING
1688 # endif
1689 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
1690 /* These aren't used when dyld support is enabled (it is by default). */
1691 # define DATASTART ((ptr_t)get_etext())
1692 # define DATAEND ((ptr_t)get_end())
1693 # define STACKBOTTOM ((ptr_t)0xc0000000)
1694 # define USE_MMAP_ANON
1695 # define MPROTECT_VDB
1696 EXTERN_C_END
1697 # include <unistd.h>
1698 EXTERN_C_BEGIN
1699 # define GETPAGESIZE() (unsigned)getpagesize()
1700 /* There seems to be some issues with trylock hanging on darwin. */
1701 /* This should be looked into some more. */
1702 # define NO_PTHREAD_TRYLOCK
1703 # if TARGET_OS_IPHONE && !defined(NO_DYLD_BIND_FULLY_IMAGE)
1704 /* iPhone/iPad simulator */
1705 # define NO_DYLD_BIND_FULLY_IMAGE
1706 # endif
1707 # endif /* DARWIN */
1708 # endif
1709
1710 # ifdef NS32K
1711 # define MACH_TYPE "NS32K"
1712 # define ALIGNMENT 4
1713 extern char **environ;
1714 # define DATASTART ((ptr_t)(&environ))
1715 /* hideous kludge: environ is the first */
1716 /* word in crt0.o, and delimits the start */
1717 /* of the data segment, no matter which */
1718 /* ld options were passed through. */
1719 # define STACKBOTTOM ((ptr_t)0xfffff000) /* for Encore */
1720 # endif
1721
1722 # ifdef MIPS
1723 # define MACH_TYPE "MIPS"
1724 # ifdef LINUX
1725 # define OS_TYPE "LINUX"
1726 # define DYNAMIC_LOADING
1727 extern int _end[];
1728 # pragma weak __data_start
1729 extern int __data_start[];
1730 # define DATASTART ((ptr_t)(__data_start))
1731 # define DATAEND ((ptr_t)(_end))
1732 # ifdef _MIPS_SZPTR
1733 # define CPP_WORDSZ _MIPS_SZPTR
1734 # define ALIGNMENT (_MIPS_SZPTR/8)
1735 # else
1736 # define ALIGNMENT 4
1737 # endif
1738 # ifndef HBLKSIZE
1739 # define HBLKSIZE 4096
1740 # endif
1741 # if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 2 || __GLIBC__ > 2
1742 # define LINUX_STACKBOTTOM
1743 # else
1744 # define STACKBOTTOM ((ptr_t)0x7fff8000)
1745 # endif
1746 # endif /* Linux */
1747 # ifdef EWS4800
1748 # define HEURISTIC2
1749 # if defined(_MIPS_SZPTR) && (_MIPS_SZPTR == 64)
1750 extern int _fdata[], _end[];
1751 # define DATASTART ((ptr_t)_fdata)
1752 # define DATAEND ((ptr_t)_end)
1753 # define CPP_WORDSZ _MIPS_SZPTR
1754 # define ALIGNMENT (_MIPS_SZPTR/8)
1755 # else
1756 extern int etext[], edata[], end[];
1757 extern int _DYNAMIC_LINKING[], _gp[];
1758 # define DATASTART ((ptr_t)((((word)(etext) + 0x3ffff) & ~0x3ffff) \
1759 + ((word)(etext) & 0xffff)))
1760 # define DATAEND ((ptr_t)(edata))
1761 # define GC_HAVE_DATAREGION2
1762 # define DATASTART2 (_DYNAMIC_LINKING \
1763 ? (ptr_t)(((word)_gp + 0x8000 + 0x3ffff) & ~0x3ffff) \
1764 : (ptr_t)edata)
1765 # define DATAEND2 ((ptr_t)(end))
1766 # define ALIGNMENT 4
1767 # endif
1768 # define OS_TYPE "EWS4800"
1769 # endif
1770 # ifdef ULTRIX
1771 # define HEURISTIC2
1772 # define DATASTART ((ptr_t)0x10000000)
1773 /* Could probably be slightly higher since */
1774 /* startup code allocates lots of stuff. */
1775 # define OS_TYPE "ULTRIX"
1776 # define ALIGNMENT 4
1777 # endif
1778 # ifdef IRIX5
1779 # define HEURISTIC2
1780 extern int _fdata[];
1781 # define DATASTART ((ptr_t)(_fdata))
1782 # ifdef USE_MMAP
1783 # define HEAP_START (ptr_t)0x30000000
1784 # else
1785 # define HEAP_START DATASTART
1786 # endif
1787 /* Lowest plausible heap address. */
1788 /* In the MMAP case, we map there. */
1789 /* In either case it is used to identify */
1790 /* heap sections so they're not */
1791 /* considered as roots. */
1792 # define OS_TYPE "IRIX5"
1793 /*# define MPROTECT_VDB DOB: this should work, but there is evidence */
1794 /* of recent breakage. */
1795 # ifdef _MIPS_SZPTR
1796 # define CPP_WORDSZ _MIPS_SZPTR
1797 # define ALIGNMENT (_MIPS_SZPTR/8)
1798 # else
1799 # define ALIGNMENT 4
1800 # endif
1801 # define DYNAMIC_LOADING
1802 # endif
1803 # ifdef MSWINCE
1804 # define OS_TYPE "MSWINCE"
1805 # define ALIGNMENT 4
1806 # define DATAEND /* not needed */
1807 # endif
1808 # if defined(NETBSD)
1809 # define OS_TYPE "NETBSD"
1810 # define ALIGNMENT 4
1811 # define HEURISTIC2
1812 # ifdef __ELF__
1813 extern ptr_t GC_data_start;
1814 # define DATASTART GC_data_start
1815 # define NEED_FIND_LIMIT
1816 # define DYNAMIC_LOADING
1817 # else
1818 # define DATASTART ((ptr_t)0x10000000)
1819 # define STACKBOTTOM ((ptr_t)0x7ffff000)
1820 # endif /* _ELF_ */
1821 # endif
1822 # ifdef OPENBSD
1823 # define OS_TYPE "OPENBSD"
1824 # define ALIGNMENT 4
1825 # ifndef GC_OPENBSD_THREADS
1826 EXTERN_C_END
1827 # include <sys/param.h>
1828 # include <uvm/uvm_extern.h>
1829 EXTERN_C_BEGIN
1830 # ifdef USRSTACK
1831 # define STACKBOTTOM ((ptr_t)USRSTACK)
1832 # else
1833 # define HEURISTIC2
1834 # endif
1835 # endif
1836 extern int _fdata[];
1837 # define DATASTART ((ptr_t)_fdata)
1838 extern int _end[];
1839 # define DATAEND ((ptr_t)(&_end))
1840 # define DYNAMIC_LOADING
1841 # endif
1842 # ifdef FREEBSD
1843 # define OS_TYPE "FREEBSD"
1844 # define ALIGNMENT 4
1845 # ifndef GC_FREEBSD_THREADS
1846 # define MPROTECT_VDB
1847 # endif
1848 # define SIG_SUSPEND SIGUSR1
1849 # define SIG_THR_RESTART SIGUSR2
1850 # define FREEBSD_STACKBOTTOM
1851 # ifdef __ELF__
1852 # define DYNAMIC_LOADING
1853 # endif
1854 extern char etext[];
1855 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
1856 # define DATASTART_USES_BSDGETDATASTART
1857 # endif /* FreeBSD */
1858 # if defined(NONSTOP)
1859 # define CPP_WORDSZ 32
1860 # define OS_TYPE "NONSTOP"
1861 # define ALIGNMENT 4
1862 # define DATASTART ((ptr_t)0x08000000)
1863 extern char **environ;
1864 # define DATAEND ((ptr_t)(environ - 0x10))
1865 # define STACKBOTTOM ((ptr_t)0x4fffffff)
1866 # endif
1867 # endif
1868
1869 # ifdef NIOS2
1870 # define CPP_WORDSZ 32
1871 # define MACH_TYPE "NIOS2"
1872 # ifdef LINUX
1873 # define OS_TYPE "LINUX"
1874 # define DYNAMIC_LOADING
1875 extern int _end[];
1876 extern int __data_start[];
1877 # define DATASTART ((ptr_t)(__data_start))
1878 # define DATAEND ((ptr_t)(_end))
1879 # define ALIGNMENT 4
1880 # ifndef HBLKSIZE
1881 # define HBLKSIZE 4096
1882 # endif
1883 # define LINUX_STACKBOTTOM
1884 # endif /* Linux */
1885 # endif
1886
1887 # ifdef OR1K
1888 # define CPP_WORDSZ 32
1889 # define MACH_TYPE "OR1K"
1890 # ifdef LINUX
1891 # define OS_TYPE "LINUX"
1892 # define DYNAMIC_LOADING
1893 extern int _end[];
1894 extern int __data_start[];
1895 # define DATASTART ((ptr_t)(__data_start))
1896 # define DATAEND ((ptr_t)(_end))
1897 # define ALIGNMENT 4
1898 # ifndef HBLKSIZE
1899 # define HBLKSIZE 4096
1900 # endif
1901 # define LINUX_STACKBOTTOM
1902 # endif /* Linux */
1903 # endif
1904
1905 # ifdef HP_PA
1906 # define MACH_TYPE "HP_PA"
1907 # ifdef __LP64__
1908 # define CPP_WORDSZ 64
1909 # define ALIGNMENT 8
1910 # else
1911 # define CPP_WORDSZ 32
1912 # define ALIGNMENT 4
1913 # endif
1914 # if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS) \
1915 && !defined(OPENBSD) && !defined(LINUX) /* For now. */
1916 # define MPROTECT_VDB
1917 # endif
1918 # define STACK_GROWS_UP
1919 # ifdef HPUX
1920 # define OS_TYPE "HPUX"
1921 extern int __data_start[];
1922 # define DATASTART ((ptr_t)(__data_start))
1923 # ifdef USE_HPUX_FIXED_STACKBOTTOM
1924 /* The following appears to work for 7xx systems running HP/UX */
1925 /* 9.xx. Furthermore, it might result in much faster */
1926 /* collections than HEURISTIC2, which may involve scanning */
1927 /* segments that directly precede the stack. It is not the */
1928 /* default, since it may not work on older machine/OS */
1929 /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1930 /* this.) */
1931 # define STACKBOTTOM ((ptr_t)0x7b033000) /* from /etc/conf/h/param.h */
1932 # else
1933 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
1934 /* to this. Note that the GC must be initialized before the */
1935 /* first putenv call. */
1936 extern char ** environ;
1937 # define STACKBOTTOM ((ptr_t)environ)
1938 # endif
1939 # define DYNAMIC_LOADING
1940 EXTERN_C_END
1941 # include <unistd.h>
1942 EXTERN_C_BEGIN
1943 # define GETPAGESIZE() (unsigned)sysconf(_SC_PAGE_SIZE)
1944 # ifndef __GNUC__
1945 # define PREFETCH(x) do { \
1946 register long addr = (long)(x); \
1947 (void) _asm ("LDW", 0, 0, addr, 0); \
1948 } while (0)
1949 # endif
1950 # endif /* HPUX */
1951 # ifdef LINUX
1952 # define OS_TYPE "LINUX"
1953 # define LINUX_STACKBOTTOM
1954 # define DYNAMIC_LOADING
1955 # define SEARCH_FOR_DATA_START
1956 extern int _end[];
1957 # define DATAEND ((ptr_t)(&_end))
1958 # endif /* LINUX */
1959 # ifdef OPENBSD
1960 # define OS_TYPE "OPENBSD"
1961 # ifndef GC_OPENBSD_THREADS
1962 EXTERN_C_END
1963 # include <sys/param.h>
1964 # include <uvm/uvm_extern.h>
1965 EXTERN_C_BEGIN
1966 # ifdef USRSTACK
1967 # define STACKBOTTOM ((ptr_t)USRSTACK)
1968 # else
1969 # define HEURISTIC2
1970 # endif
1971 # endif
1972 extern int __data_start[];
1973 # define DATASTART ((ptr_t)__data_start)
1974 extern int _end[];
1975 # define DATAEND ((ptr_t)(&_end))
1976 # define DYNAMIC_LOADING
1977 # endif
1978 # endif /* HP_PA */
1979
1980 # ifdef ALPHA
1981 # define MACH_TYPE "ALPHA"
1982 # define ALIGNMENT 8
1983 # define CPP_WORDSZ 64
1984 # ifdef NETBSD
1985 # define OS_TYPE "NETBSD"
1986 # define HEURISTIC2
1987 extern ptr_t GC_data_start;
1988 # define DATASTART GC_data_start
1989 # define ELFCLASS32 32
1990 # define ELFCLASS64 64
1991 # define ELF_CLASS ELFCLASS64
1992 # define DYNAMIC_LOADING
1993 # endif
1994 # ifdef OPENBSD
1995 # define OS_TYPE "OPENBSD"
1996 # define ELF_CLASS ELFCLASS64
1997 # ifndef GC_OPENBSD_THREADS
1998 EXTERN_C_END
1999 # include <sys/param.h>
2000 # include <uvm/uvm_extern.h>
2001 EXTERN_C_BEGIN
2002 # ifdef USRSTACK
2003 # define STACKBOTTOM ((ptr_t)USRSTACK)
2004 # else
2005 # define HEURISTIC2
2006 # endif
2007 # endif
2008 extern int __data_start[];
2009 # define DATASTART ((ptr_t)__data_start)
2010 extern int _end[];
2011 # define DATAEND ((ptr_t)(&_end))
2012 # define DYNAMIC_LOADING
2013 # endif
2014 # ifdef FREEBSD
2015 # define OS_TYPE "FREEBSD"
2016 /* MPROTECT_VDB is not yet supported at all on FreeBSD/alpha. */
2017 # define SIG_SUSPEND SIGUSR1
2018 # define SIG_THR_RESTART SIGUSR2
2019 /* SIGTSTP and SIGCONT could be used alternatively. */
2020 # define FREEBSD_STACKBOTTOM
2021 # ifdef __ELF__
2022 # define DYNAMIC_LOADING
2023 # endif
2024 /* Handle unmapped hole alpha*-*-freebsd[45]* puts between etext and edata. */
2025 extern char etext[];
2026 extern char edata[];
2027 extern char end[];
2028 # define NEED_FIND_LIMIT
2029 # define DATASTART ((ptr_t)(&etext))
2030 ptr_t GC_find_limit(ptr_t, GC_bool);
2031 # define DATAEND GC_find_limit(DATASTART, TRUE)
2032 # define DATAEND_IS_FUNC
2033 # define GC_HAVE_DATAREGION2
2034 # define DATASTART2 ((ptr_t)(&edata))
2035 # define DATAEND2 ((ptr_t)(&end))
2036 # endif
2037 # ifdef OSF1
2038 # define OS_TYPE "OSF1"
2039 # define DATASTART ((ptr_t)0x140000000)
2040 extern int _end[];
2041 # define DATAEND ((ptr_t)(&_end))
2042 extern char ** environ;
2043 /* round up from the value of environ to the nearest page boundary */
2044 /* Probably breaks if putenv is called before collector */
2045 /* initialization. */
2046 # define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
2047 /* # define HEURISTIC2 */
2048 /* Normally HEURISTIC2 is too conservative, since */
2049 /* the text segment immediately follows the stack. */
2050 /* Hence we give an upper pound. */
2051 /* This is currently unused, since we disabled HEURISTIC2 */
2052 extern int __start[];
2053 # define HEURISTIC2_LIMIT ((ptr_t)((word)(__start) & ~(getpagesize()-1)))
2054 # ifndef GC_OSF1_THREADS
2055 /* Unresolved signal issues with threads. */
2056 # define MPROTECT_VDB
2057 # endif
2058 # define DYNAMIC_LOADING
2059 # endif
2060 # ifdef LINUX
2061 # define OS_TYPE "LINUX"
2062 # define LINUX_STACKBOTTOM
2063 # ifdef __ELF__
2064 # define SEARCH_FOR_DATA_START
2065 # define DYNAMIC_LOADING
2066 # else
2067 # define DATASTART ((ptr_t)0x140000000)
2068 # endif
2069 extern int _end[];
2070 # define DATAEND ((ptr_t)(_end))
2071 # define MPROTECT_VDB
2072 /* Has only been superficially tested. May not */
2073 /* work on all versions. */
2074 # endif
2075 # endif
2076
2077 # ifdef IA64
2078 # define MACH_TYPE "IA64"
2079 # ifdef HPUX
2080 # ifdef _ILP32
2081 # define CPP_WORDSZ 32
2082 /* Requires 8 byte alignment for malloc */
2083 # define ALIGNMENT 4
2084 # else
2085 # ifndef _LP64
2086 # error --> unknown ABI
2087 # endif
2088 # define CPP_WORDSZ 64
2089 /* Requires 16 byte alignment for malloc */
2090 # define ALIGNMENT 8
2091 # endif
2092 # define OS_TYPE "HPUX"
2093 extern int __data_start[];
2094 # define DATASTART ((ptr_t)(__data_start))
2095 /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
2096 /* to this. Note that the GC must be initialized before the */
2097 /* first putenv call. */
2098 extern char ** environ;
2099 # define STACKBOTTOM ((ptr_t)environ)
2100 # define HPUX_STACKBOTTOM
2101 # define DYNAMIC_LOADING
2102 EXTERN_C_END
2103 # include <unistd.h>
2104 EXTERN_C_BEGIN
2105 # define GETPAGESIZE() (unsigned)sysconf(_SC_PAGE_SIZE)
2106 /* The following was empirically determined, and is probably */
2107 /* not very robust. */
2108 /* Note that the backing store base seems to be at a nice */
2109 /* address minus one page. */
2110 # define BACKING_STORE_DISPLACEMENT 0x1000000
2111 # define BACKING_STORE_ALIGNMENT 0x1000
2112 extern ptr_t GC_register_stackbottom;
2113 # define BACKING_STORE_BASE GC_register_stackbottom
2114 /* Known to be wrong for recent HP/UX versions!!! */
2115 # endif
2116 # ifdef LINUX
2117 # define CPP_WORDSZ 64
2118 # define ALIGNMENT 8
2119 # define OS_TYPE "LINUX"
2120 /* The following works on NUE and older kernels: */
2121 /* # define STACKBOTTOM ((ptr_t) 0xa000000000000000l) */
2122 /* This does not work on NUE: */
2123 # define LINUX_STACKBOTTOM
2124 /* We also need the base address of the register stack */
2125 /* backing store. */
2126 extern ptr_t GC_register_stackbottom;
2127 # define BACKING_STORE_BASE GC_register_stackbottom
2128 # define SEARCH_FOR_DATA_START
2129 # ifdef __GNUC__
2130 # define DYNAMIC_LOADING
2131 # else
2132 /* In the Intel compiler environment, we seem to end up with */
2133 /* statically linked executables and an undefined reference */
2134 /* to _DYNAMIC */
2135 # endif
2136 # define MPROTECT_VDB
2137 /* Requires Linux 2.3.47 or later. */
2138 extern int _end[];
2139 # define DATAEND ((ptr_t)(_end))
2140 # ifdef __GNUC__
2141 # ifndef __INTEL_COMPILER
2142 # define PREFETCH(x) \
2143 __asm__ (" lfetch [%0]": : "r"(x))
2144 # define GC_PREFETCH_FOR_WRITE(x) \
2145 __asm__ (" lfetch.excl [%0]": : "r"(x))
2146 # define CLEAR_DOUBLE(x) \
2147 __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
2148 # else
2149 EXTERN_C_END
2150 # include <ia64intrin.h>
2151 EXTERN_C_BEGIN
2152 # define PREFETCH(x) __lfetch(__lfhint_none, (x))
2153 # define GC_PREFETCH_FOR_WRITE(x) __lfetch(__lfhint_nta, (x))
2154 # define CLEAR_DOUBLE(x) __stf_spill((void *)(x), 0)
2155 # endif /* __INTEL_COMPILER */
2156 # endif
2157 # endif
2158 # ifdef CYGWIN32
2159 # define OS_TYPE "CYGWIN32"
2160 # define DATASTART ((ptr_t)GC_DATASTART) /* From gc.h */
2161 # define DATAEND ((ptr_t)GC_DATAEND)
2162 # undef STACK_GRAN
2163 # define STACK_GRAN 0x10000
2164 # ifdef USE_MMAP
2165 # define NEED_FIND_LIMIT
2166 # define USE_MMAP_ANON
2167 # endif
2168 # endif
2169 # ifdef MSWIN32
2170 /* FIXME: This is a very partial guess. There is no port, yet. */
2171 # define OS_TYPE "MSWIN32"
2172 /* STACKBOTTOM and DATASTART are handled specially in */
2173 /* os_dep.c. */
2174 # define DATAEND /* not needed */
2175 # if defined(_WIN64)
2176 # define CPP_WORDSZ 64
2177 # else
2178 # define CPP_WORDSZ 32 /* Is this possible? */
2179 # endif
2180 # define ALIGNMENT 8
2181 # endif
2182 # endif
2183
2184 # ifdef M88K
2185 # define MACH_TYPE "M88K"
2186 # define ALIGNMENT 4
2187 extern int etext[];
2188 # ifdef CX_UX
2189 # define OS_TYPE "CX_UX"
2190 # define DATASTART ((ptr_t)((((word)(etext) + 0x3fffff) & ~0x3fffff) \
2191 + 0x10000))
2192 # endif
2193 # ifdef DGUX
2194 # define OS_TYPE "DGUX"
2195 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
2196 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)etext)
2197 # define DATASTART_IS_FUNC
2198 # endif
2199 # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
2200 # endif
2201
2202 # ifdef S370
2203 /* If this still works, and if anyone cares, this should probably */
2204 /* be moved to the S390 category. */
2205 # define MACH_TYPE "S370"
2206 # define ALIGNMENT 4 /* Required by hardware */
2207 # ifdef UTS4
2208 # define OS_TYPE "UTS4"
2209 extern int etext[];
2210 extern int _etext[];
2211 extern int _end[];
2212 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
2213 # define DATASTART GC_SysVGetDataStart(0x10000, (ptr_t)_etext)
2214 # define DATASTART_IS_FUNC
2215 # define DATAEND ((ptr_t)(_end))
2216 # define HEURISTIC2
2217 # endif
2218 # endif
2219
2220 # ifdef S390
2221 # define MACH_TYPE "S390"
2222 # ifndef __s390x__
2223 # define ALIGNMENT 4
2224 # define CPP_WORDSZ 32
2225 # else
2226 # define ALIGNMENT 8
2227 # define CPP_WORDSZ 64
2228 # ifndef HBLKSIZE
2229 # define HBLKSIZE 4096
2230 # endif
2231 # endif
2232 # ifdef LINUX
2233 # define OS_TYPE "LINUX"
2234 # define LINUX_STACKBOTTOM
2235 # define DYNAMIC_LOADING
2236 extern int __data_start[] __attribute__((__weak__));
2237 # define DATASTART ((ptr_t)(__data_start))
2238 extern int _end[] __attribute__((__weak__));
2239 # define DATAEND ((ptr_t)(_end))
2240 # define CACHE_LINE_SIZE 256
2241 # define GETPAGESIZE() 4096
2242 # endif
2243 # endif
2244
2245 # ifdef AARCH64
2246 # define MACH_TYPE "AARCH64"
2247 # ifdef __ILP32__
2248 # define CPP_WORDSZ 32
2249 # define ALIGNMENT 4
2250 # else
2251 # define CPP_WORDSZ 64
2252 # define ALIGNMENT 8
2253 # endif
2254 # ifndef HBLKSIZE
2255 # define HBLKSIZE 4096
2256 # endif
2257 # ifdef LINUX
2258 # define OS_TYPE "LINUX"
2259 # define LINUX_STACKBOTTOM
2260 # define DYNAMIC_LOADING
2261 extern int __data_start[];
2262 extern int _end[];
2263 # define DATASTART ((ptr_t)__data_start)
2264 # define DATAEND ((ptr_t)(&_end))
2265 # endif
2266 # ifdef DARWIN
2267 /* iOS */
2268 # define OS_TYPE "DARWIN"
2269 # define DARWIN_DONT_PARSE_STACK
2270 # ifndef GC_DONT_REGISTER_MAIN_STATIC_DATA
2271 # define DYNAMIC_LOADING
2272 # endif
2273 # define DATASTART ((ptr_t)get_etext())
2274 # define DATAEND ((ptr_t)get_end())
2275 # define STACKBOTTOM ((ptr_t)0x16fdfffff)
2276 # define USE_MMAP_ANON
2277 # define MPROTECT_VDB
2278 EXTERN_C_END
2279 # include <unistd.h>
2280 EXTERN_C_BEGIN
2281 # define GETPAGESIZE() (unsigned)getpagesize()
2282 /* FIXME: There seems to be some issues with trylock hanging on */
2283 /* darwin. This should be looked into some more. */
2284 # define NO_PTHREAD_TRYLOCK
2285 # if TARGET_OS_IPHONE && !defined(NO_DYLD_BIND_FULLY_IMAGE)
2286 # define NO_DYLD_BIND_FULLY_IMAGE
2287 # endif
2288 # endif
2289 # ifdef FREEBSD
2290 # define OS_TYPE "FREEBSD"
2291 # ifndef GC_FREEBSD_THREADS
2292 # define MPROTECT_VDB
2293 # endif
2294 # define FREEBSD_STACKBOTTOM
2295 # ifdef __ELF__
2296 # define DYNAMIC_LOADING
2297 # endif
2298 extern char etext[];
2299 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
2300 # define DATASTART_USES_BSDGETDATASTART
2301 # endif
2302 # ifdef NINTENDO_SWITCH
2303 static int zero_fd = -1;
2304 # define OPT_MAP_ANON 0
2305 extern int __bss_end[];
2306 # define NO_HANDLE_FORK
2307 # define GETPAGESIZE() 4096
2308 # define DATASTART (ptr_t)ALIGNMENT /* cannot be null */
2309 # define DATAEND (ptr_t)(&__bss_end)
2310 void *switch_get_stack_bottom(void);
2311 # define STACKBOTTOM ((ptr_t)switch_get_stack_bottom())
2312 # undef USE_MMAP
2313 # undef USE_MUNMAP
2314 # endif
2315 # ifdef NOSYS
2316 /* __data_start is usually defined in the target linker script. */
2317 extern int __data_start[];
2318 # define DATASTART ((ptr_t)__data_start)
2319 extern void *__stack_base__;
2320 # define STACKBOTTOM ((ptr_t)__stack_base__)
2321 # endif
2322 # endif
2323
2324 # ifdef ARM32
2325 # if defined(NACL)
2326 # define MACH_TYPE "NACL"
2327 # else
2328 # define MACH_TYPE "ARM32"
2329 # endif
2330 # define CPP_WORDSZ 32
2331 # define ALIGNMENT 4
2332 # ifdef NETBSD
2333 # define OS_TYPE "NETBSD"
2334 # define HEURISTIC2
2335 # ifdef __ELF__
2336 extern ptr_t GC_data_start;
2337 # define DATASTART GC_data_start
2338 # define DYNAMIC_LOADING
2339 # else
2340 extern char etext[];
2341 # define DATASTART ((ptr_t)(etext))
2342 # endif
2343 # endif
2344 # ifdef LINUX
2345 # define OS_TYPE "LINUX"
2346 # define LINUX_STACKBOTTOM
2347 # undef STACK_GRAN
2348 # define STACK_GRAN 0x10000000
2349 # ifdef __ELF__
2350 # define DYNAMIC_LOADING
2351 EXTERN_C_END
2352 # include <features.h>
2353 EXTERN_C_BEGIN
2354 # if defined(__GLIBC__) && __GLIBC__ >= 2 \
2355 || defined(HOST_ANDROID) || defined(HOST_TIZEN)
2356 # define SEARCH_FOR_DATA_START
2357 # else
2358 extern char **__environ;
2359 # define DATASTART ((ptr_t)(&__environ))
2360 /* hideous kludge: __environ is the first */
2361 /* word in crt0.o, and delimits the start */
2362 /* of the data segment, no matter which */
2363 /* ld options were passed through. */
2364 /* We could use _etext instead, but that */
2365 /* would include .rodata, which may */
2366 /* contain large read-only data tables */
2367 /* that we'd rather not scan. */
2368 # endif
2369 extern int _end[];
2370 # define DATAEND ((ptr_t)(_end))
2371 # else
2372 extern int etext[];
2373 # define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
2374 # endif
2375 # endif
2376 # ifdef MSWINCE
2377 # define OS_TYPE "MSWINCE"
2378 # define DATAEND /* not needed */
2379 # endif
2380 # ifdef FREEBSD
2381 /* FreeBSD/arm */
2382 # define OS_TYPE "FREEBSD"
2383 # ifndef GC_FREEBSD_THREADS
2384 # define MPROTECT_VDB
2385 # endif
2386 # define SIG_SUSPEND SIGUSR1
2387 # define SIG_THR_RESTART SIGUSR2
2388 # define FREEBSD_STACKBOTTOM
2389 # ifdef __ELF__
2390 # define DYNAMIC_LOADING
2391 # endif
2392 extern char etext[];
2393 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
2394 # define DATASTART_USES_BSDGETDATASTART
2395 # endif
2396 # ifdef DARWIN
2397 /* iOS */
2398 # define OS_TYPE "DARWIN"
2399 # define DARWIN_DONT_PARSE_STACK
2400 # ifndef GC_DONT_REGISTER_MAIN_STATIC_DATA
2401 # define DYNAMIC_LOADING
2402 # endif
2403 # define DATASTART ((ptr_t)get_etext())
2404 # define DATAEND ((ptr_t)get_end())
2405 # define STACKBOTTOM ((ptr_t)0x30000000)
2406 # define USE_MMAP_ANON
2407 # define MPROTECT_VDB
2408 EXTERN_C_END
2409 # include <unistd.h>
2410 EXTERN_C_BEGIN
2411 # define GETPAGESIZE() (unsigned)getpagesize()
2412 /* FIXME: There seems to be some issues with trylock hanging on */
2413 /* darwin. This should be looked into some more. */
2414 # define NO_PTHREAD_TRYLOCK
2415 # if TARGET_OS_IPHONE && !defined(NO_DYLD_BIND_FULLY_IMAGE)
2416 # define NO_DYLD_BIND_FULLY_IMAGE
2417 # endif
2418 # endif
2419 # ifdef OPENBSD
2420 # define OS_TYPE "OPENBSD"
2421 # ifndef GC_OPENBSD_THREADS
2422 EXTERN_C_END
2423 # include <sys/param.h>
2424 # include <uvm/uvm_extern.h>
2425 EXTERN_C_BEGIN
2426 # ifdef USRSTACK
2427 # define STACKBOTTOM ((ptr_t)USRSTACK)
2428 # else
2429 # define HEURISTIC2
2430 # endif
2431 # endif
2432 extern int __data_start[];
2433 # define DATASTART ((ptr_t)__data_start)
2434 extern int _end[];
2435 # define DATAEND ((ptr_t)(&_end))
2436 # define DYNAMIC_LOADING
2437 # endif
2438 # ifdef SN_TARGET_PSP2
2439 # define NO_HANDLE_FORK
2440 # define DATASTART (ptr_t)ALIGNMENT
2441 # define DATAEND (ptr_t)ALIGNMENT
2442 void *psp2_get_stack_bottom(void);
2443 # define STACKBOTTOM ((ptr_t)psp2_get_stack_bottom())
2444 # endif
2445 # ifdef NN_PLATFORM_CTR
2446 extern unsigned char Image$$ZI$$ZI$$Base[];
2447 # define DATASTART (ptr_t)(Image$$ZI$$ZI$$Base)
2448 extern unsigned char Image$$ZI$$ZI$$Limit[];
2449 # define DATAEND (ptr_t)(Image$$ZI$$ZI$$Limit)
2450 void *n3ds_get_stack_bottom(void);
2451 # define STACKBOTTOM ((ptr_t)n3ds_get_stack_bottom())
2452 # endif
2453 # ifdef NOSYS
2454 /* __data_start is usually defined in the target linker script. */
2455 extern int __data_start[];
2456 # define DATASTART ((ptr_t)(__data_start))
2457 /* __stack_base__ is set in newlib/libc/sys/arm/crt0.S */
2458 extern void *__stack_base__;
2459 # define STACKBOTTOM ((ptr_t)(__stack_base__))
2460 # endif
2461 #endif
2462
2463 # ifdef CRIS
2464 # define MACH_TYPE "CRIS"
2465 # define CPP_WORDSZ 32
2466 # define ALIGNMENT 1
2467 # define OS_TYPE "LINUX"
2468 # define DYNAMIC_LOADING
2469 # define LINUX_STACKBOTTOM
2470 # define SEARCH_FOR_DATA_START
2471 extern int _end[];
2472 # define DATAEND ((ptr_t)(_end))
2473 # endif
2474
2475 # if defined(SH) && !defined(SH4)
2476 # define MACH_TYPE "SH"
2477 # define ALIGNMENT 4
2478 # ifdef MSWINCE
2479 # define OS_TYPE "MSWINCE"
2480 # define DATAEND /* not needed */
2481 # endif
2482 # ifdef LINUX
2483 # define OS_TYPE "LINUX"
2484 # define LINUX_STACKBOTTOM
2485 # define DYNAMIC_LOADING
2486 # define SEARCH_FOR_DATA_START
2487 extern int _end[];
2488 # define DATAEND ((ptr_t)(_end))
2489 # endif
2490 # ifdef NETBSD
2491 # define OS_TYPE "NETBSD"
2492 # define HEURISTIC2
2493 extern ptr_t GC_data_start;
2494 # define DATASTART GC_data_start
2495 # define DYNAMIC_LOADING
2496 # endif
2497 # ifdef OPENBSD
2498 # define OS_TYPE "OPENBSD"
2499 # ifndef GC_OPENBSD_THREADS
2500 EXTERN_C_END
2501 # include <sys/param.h>
2502 # include <uvm/uvm_extern.h>
2503 EXTERN_C_BEGIN
2504 # ifdef USRSTACK
2505 # define STACKBOTTOM ((ptr_t)USRSTACK)
2506 # else
2507 # define HEURISTIC2
2508 # endif
2509 # endif
2510 extern int __data_start[];
2511 # define DATASTART ((ptr_t)__data_start)
2512 extern int _end[];
2513 # define DATAEND ((ptr_t)(&_end))
2514 # define DYNAMIC_LOADING
2515 # endif
2516 # endif
2517
2518 # ifdef SH4
2519 # define MACH_TYPE "SH4"
2520 # define OS_TYPE "MSWINCE"
2521 # define ALIGNMENT 4
2522 # define DATAEND /* not needed */
2523 # endif
2524
2525 # ifdef AVR32
2526 # define MACH_TYPE "AVR32"
2527 # define CPP_WORDSZ 32
2528 # define ALIGNMENT 4
2529 # define OS_TYPE "LINUX"
2530 # define DYNAMIC_LOADING
2531 # define LINUX_STACKBOTTOM
2532 # define SEARCH_FOR_DATA_START
2533 extern int _end[];
2534 # define DATAEND ((ptr_t)(_end))
2535 # endif
2536
2537 # ifdef M32R
2538 # define CPP_WORDSZ 32
2539 # define MACH_TYPE "M32R"
2540 # define ALIGNMENT 4
2541 # ifdef LINUX
2542 # define OS_TYPE "LINUX"
2543 # define LINUX_STACKBOTTOM
2544 # undef STACK_GRAN
2545 # define STACK_GRAN 0x10000000
2546 # define DYNAMIC_LOADING
2547 # define SEARCH_FOR_DATA_START
2548 extern int _end[];
2549 # define DATAEND ((ptr_t)(_end))
2550 # endif
2551 # endif
2552
2553 # ifdef X86_64
2554 # define MACH_TYPE "X86_64"
2555 # ifdef __ILP32__
2556 # define ALIGNMENT 4
2557 # define CPP_WORDSZ 32
2558 # else
2559 # define ALIGNMENT 8
2560 # define CPP_WORDSZ 64
2561 # endif
2562 # ifndef HBLKSIZE
2563 # define HBLKSIZE 4096
2564 # endif
2565 # ifndef CACHE_LINE_SIZE
2566 # define CACHE_LINE_SIZE 64
2567 # endif
2568 # ifdef PLATFORM_GETMEM
2569 # define DATASTART (ptr_t)ALIGNMENT
2570 # define DATAEND (ptr_t)ALIGNMENT
2571 EXTERN_C_END
2572 # include <pthread.h>
2573 EXTERN_C_BEGIN
2574 void *platform_get_stack_bottom(void);
2575 # define STACKBOTTOM ((ptr_t)platform_get_stack_bottom())
2576 # endif
2577 # ifdef OPENBSD
2578 # define OS_TYPE "OPENBSD"
2579 # define ELF_CLASS ELFCLASS64
2580 # ifndef GC_OPENBSD_THREADS
2581 EXTERN_C_END
2582 # include <sys/param.h>
2583 # include <uvm/uvm_extern.h>
2584 EXTERN_C_BEGIN
2585 # ifdef USRSTACK
2586 # define STACKBOTTOM ((ptr_t)USRSTACK)
2587 # else
2588 # define HEURISTIC2
2589 # endif
2590 # endif
2591 extern int __data_start[];
2592 extern int _end[];
2593 # define DATASTART ((ptr_t)__data_start)
2594 # define DATAEND ((ptr_t)(&_end))
2595 # define DYNAMIC_LOADING
2596 # endif
2597 # ifdef LINUX
2598 # define OS_TYPE "LINUX"
2599 # define LINUX_STACKBOTTOM
2600 # if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
2601 # define MPROTECT_VDB
2602 # else
2603 /* We seem to get random errors in incremental mode, */
2604 /* possibly because Linux threads is itself a malloc client */
2605 /* and can't deal with the signals. */
2606 # endif
2607 # ifdef __ELF__
2608 # define DYNAMIC_LOADING
2609 EXTERN_C_END
2610 # include <features.h>
2611 EXTERN_C_BEGIN
2612 # define SEARCH_FOR_DATA_START
2613 extern int _end[];
2614 # define DATAEND ((ptr_t)(_end))
2615 # else
2616 extern int etext[];
2617 # define DATASTART ((ptr_t)((((word)(etext)) + 0xfff) & ~0xfff))
2618 # endif
2619 # if defined(__GLIBC__) && !defined(__UCLIBC__)
2620 /* At present, there's a bug in GLibc getcontext() on */
2621 /* Linux/x64 (it clears FPU exception mask). We define this */
2622 /* macro to workaround it. */
2623 /* FIXME: This seems to be fixed in GLibc v2.14. */
2624 # define GETCONTEXT_FPU_EXCMASK_BUG
2625 # endif
2626 # if defined(__GLIBC__) && !defined(__UCLIBC__)
2627 /* Workaround lock elision implementation for some glibc. */
2628 # define GLIBC_2_19_TSX_BUG
2629 EXTERN_C_END
2630 # include <gnu/libc-version.h> /* for gnu_get_libc_version() */
2631 EXTERN_C_BEGIN
2632 # endif
2633 # endif
2634 # ifdef DARWIN
2635 # define OS_TYPE "DARWIN"
2636 # define DARWIN_DONT_PARSE_STACK
2637 # ifndef GC_DONT_REGISTER_MAIN_STATIC_DATA
2638 # define DYNAMIC_LOADING
2639 # endif
2640 /* XXX: see get_end(3), get_etext() and get_end() should not be used. */
2641 /* These aren't used when dyld support is enabled (it is by default) */
2642 # define DATASTART ((ptr_t)get_etext())
2643 # define DATAEND ((ptr_t)get_end())
2644 # define STACKBOTTOM ((ptr_t)0x7fff5fc00000)
2645 # define USE_MMAP_ANON
2646 # define MPROTECT_VDB
2647 EXTERN_C_END
2648 # include <unistd.h>
2649 EXTERN_C_BEGIN
2650 # define GETPAGESIZE() (unsigned)getpagesize()
2651 /* There seems to be some issues with trylock hanging on darwin. */
2652 /* This should be looked into some more. */
2653 # define NO_PTHREAD_TRYLOCK
2654 # if TARGET_OS_IPHONE && !defined(NO_DYLD_BIND_FULLY_IMAGE)
2655 /* iPhone/iPad simulator */
2656 # define NO_DYLD_BIND_FULLY_IMAGE
2657 # endif
2658 # endif
2659 # ifdef FREEBSD
2660 # define OS_TYPE "FREEBSD"
2661 # ifndef GC_FREEBSD_THREADS
2662 # define MPROTECT_VDB
2663 # endif
2664 # ifdef __GLIBC__
2665 # define SIG_SUSPEND (32+6)
2666 # define SIG_THR_RESTART (32+5)
2667 extern int _end[];
2668 # define DATAEND ((ptr_t)(_end))
2669 # else
2670 # define SIG_SUSPEND SIGUSR1
2671 # define SIG_THR_RESTART SIGUSR2
2672 /* SIGTSTP and SIGCONT could be used alternatively. */
2673 # endif
2674 # define FREEBSD_STACKBOTTOM
2675 # ifdef __ELF__
2676 # define DYNAMIC_LOADING
2677 # endif
2678 extern char etext[];
2679 # define DATASTART GC_FreeBSDGetDataStart(0x1000, (ptr_t)etext)
2680 # define DATASTART_USES_BSDGETDATASTART
2681 # endif
2682 # ifdef NETBSD
2683 # define OS_TYPE "NETBSD"
2684 # define HEURISTIC2
2685 # ifdef __ELF__
2686 extern ptr_t GC_data_start;
2687 # define DATASTART GC_data_start
2688 # define DYNAMIC_LOADING
2689 # else
2690 # define SEARCH_FOR_DATA_START
2691 # endif
2692 # endif
2693 # ifdef HAIKU
2694 # define OS_TYPE "HAIKU"
2695 EXTERN_C_END
2696 # include <OS.h>
2697 EXTERN_C_BEGIN
2698 # define GETPAGESIZE() (unsigned)B_PAGE_SIZE
2699 # define HEURISTIC2
2700 # define SEARCH_FOR_DATA_START
2701 # define DYNAMIC_LOADING
2702 # define MPROTECT_VDB
2703 # endif
2704 # ifdef SOLARIS
2705 # define OS_TYPE "SOLARIS"
2706 # define ELF_CLASS ELFCLASS64
2707 extern int _etext[], _end[];
2708 ptr_t GC_SysVGetDataStart(size_t, ptr_t);
2709 # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
2710 # define DATASTART_IS_FUNC
2711 # define DATAEND ((ptr_t)(_end))
2712 /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
2713 /* but reportedly breaks under 2.8. It appears that the stack */
2714 /* base is a property of the executable, so this should not */
2715 /* break old executables. */
2716 /* HEURISTIC2 probably works, but this appears to be preferable.*/
2717 /* Apparently USRSTACK is defined to be USERLIMIT, but in some */
2718 /* installations that's undefined. We work around this with a */
2719 /* gross hack: */
2720 EXTERN_C_END
2721 # include <sys/vmparam.h>
2722 EXTERN_C_BEGIN
2723 # ifdef USERLIMIT
2724 /* This should work everywhere, but doesn't. */
2725 # define STACKBOTTOM ((ptr_t)USRSTACK)
2726 # else
2727 # define HEURISTIC2
2728 # endif
2729 /* At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
2730 /* It appears to be fixed in 2.8 and 2.9. */
2731 # ifdef SOLARIS25_PROC_VDB_BUG_FIXED
2732 # define PROC_VDB
2733 # endif
2734 # ifndef GC_THREADS
2735 # define MPROTECT_VDB
2736 # endif
2737 # define DYNAMIC_LOADING
2738 # if !defined(USE_MMAP) && defined(REDIRECT_MALLOC)
2739 # define USE_MMAP
2740 /* Otherwise we now use calloc. Mmap may result in the */
2741 /* heap interleaved with thread stacks, which can result in */
2742 /* excessive blacklisting. Sbrk is unusable since it */
2743 /* doesn't interact correctly with the system malloc. */
2744 # endif
2745 # ifdef USE_MMAP
2746 # define HEAP_START (ptr_t)0x40000000
2747 # else
2748 # define HEAP_START DATAEND
2749 # endif
2750 # endif
2751 # ifdef MSWIN_XBOX1
2752 # define NO_GETENV
2753 # define DATASTART (ptr_t)ALIGNMENT
2754 # define DATAEND (ptr_t)ALIGNMENT
2755 LONG64 durango_get_stack_bottom(void);
2756 # define STACKBOTTOM ((ptr_t)durango_get_stack_bottom())
2757 # define GETPAGESIZE() 4096
2758 # ifndef USE_MMAP
2759 # define USE_MMAP
2760 # endif
2761 /* The following is from sys/mman.h: */
2762 # define PROT_NONE 0
2763 # define PROT_READ 1
2764 # define PROT_WRITE 2
2765 # define PROT_EXEC 4
2766 # define MAP_PRIVATE 2
2767 # define MAP_FIXED 0x10
2768 # define MAP_FAILED ((void *)-1)
2769 # endif
2770 # ifdef MSWIN32
2771 # define OS_TYPE "MSWIN32"
2772 /* STACKBOTTOM and DATASTART are handled specially in */
2773 /* os_dep.c. */
2774 # if !defined(__GNUC__) || defined(__INTEL_COMPILER) \
2775 || GC_GNUC_PREREQ(4, 7)
2776 /* Older GCC has not supported SetUnhandledExceptionFilter */
2777 /* properly on x64 (e.g. SEH unwinding information missed). */
2778 # define MPROTECT_VDB
2779 # endif
2780 # define GWW_VDB
2781 # ifndef DATAEND
2782 # define DATAEND /* not needed */
2783 # endif
2784 # endif
2785 # endif /* X86_64 */
2786
2787 # ifdef HEXAGON
2788 # define CPP_WORDSZ 32
2789 # define MACH_TYPE "HEXAGON"
2790 # define ALIGNMENT 4
2791 # ifdef LINUX
2792 # define OS_TYPE "LINUX"
2793 # define LINUX_STACKBOTTOM
2794 # define MPROTECT_VDB
2795 # ifdef __ELF__
2796 # define DYNAMIC_LOADING
2797 EXTERN_C_END
2798 # include <features.h>
2799 EXTERN_C_BEGIN
2800 # if defined(__GLIBC__) && __GLIBC__ >= 2
2801 # define SEARCH_FOR_DATA_START
2802 # else
2803 # error --> unknown Hexagon libc configuration
2804 # endif
2805 extern int _end[];
2806 # define DATAEND ((ptr_t)(_end))
2807 # elif !defined(CPPCHECK)
2808 # error --> bad Hexagon Linux configuration
2809 # endif
2810 # else
2811 # error --> unknown Hexagon OS configuration
2812 # endif
2813 # endif
2814
2815 # ifdef TILEPRO
2816 # define CPP_WORDSZ 32
2817 # define MACH_TYPE "TILEPro"
2818 # define ALIGNMENT 4
2819 # define PREFETCH(x) __insn_prefetch(x)
2820 # define CACHE_LINE_SIZE 64
2821 # ifdef LINUX
2822 # define OS_TYPE "LINUX"
2823 extern int __data_start[];
2824 # define DATASTART ((ptr_t)__data_start)
2825 # define LINUX_STACKBOTTOM
2826 # define DYNAMIC_LOADING
2827 # endif
2828 # endif
2829
2830 # ifdef TILEGX
2831 # define CPP_WORDSZ (__SIZEOF_POINTER__ * 8)
2832 # define MACH_TYPE "TILE-Gx"
2833 # define ALIGNMENT __SIZEOF_POINTER__
2834 # if CPP_WORDSZ < 64
2835 # define CLEAR_DOUBLE(x) (*(long long *)(x) = 0)
2836 # endif
2837 # define PREFETCH(x) __insn_prefetch_l1(x)
2838 # define CACHE_LINE_SIZE 64
2839 # ifdef LINUX
2840 # define OS_TYPE "LINUX"
2841 extern int __data_start[];
2842 # define DATASTART ((ptr_t)__data_start)
2843 # define LINUX_STACKBOTTOM
2844 # define DYNAMIC_LOADING
2845 # endif
2846 # endif
2847
2848 # ifdef RISCV
2849 # define MACH_TYPE "RISC-V"
2850 # define CPP_WORDSZ __riscv_xlen /* 32 or 64 */
2851 # define ALIGNMENT (CPP_WORDSZ/8)
2852 # ifdef LINUX
2853 # define OS_TYPE "LINUX"
2854 extern int __data_start[];
2855 # define DATASTART ((ptr_t)__data_start)
2856 # define LINUX_STACKBOTTOM
2857 # define DYNAMIC_LOADING
2858 # endif
2859 # endif /* RISCV */
2860
2861 #if defined(__GLIBC__) && !defined(DONT_USE_LIBC_PRIVATES)
2862 /* Use glibc's stack-end marker. */
2863 # define USE_LIBC_PRIVATES
2864 #endif
2865
2866 #if defined(LINUX_STACKBOTTOM) && defined(NO_PROC_STAT) \
2867 && !defined(USE_LIBC_PRIVATES)
2868 /* This combination will fail, since we have no way to get */
2869 /* the stack base. Use HEURISTIC2 instead. */
2870 # undef LINUX_STACKBOTTOM
2871 # define HEURISTIC2
2872 /* This may still fail on some architectures like IA64. */
2873 /* We tried ... */
2874 #endif
2875
2876 #if defined(USE_MMAP_ANON) && !defined(USE_MMAP)
2877 # define USE_MMAP
2878 #elif defined(LINUX) && defined(USE_MMAP)
2879 /* The kernel may do a somewhat better job merging mappings etc. */
2880 /* with anonymous mappings. */
2881 # define USE_MMAP_ANON
2882 #endif
2883
2884 #if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
2885 && !defined(USE_PROC_FOR_LIBRARIES)
2886 /* Nptl allocates thread stacks with mmap, which is fine. But it */
2887 /* keeps a cache of thread stacks. Thread stacks contain the */
2888 /* thread control blocks. These in turn contain a pointer to */
2889 /* (sizeof (void *) from the beginning of) the dtv for thread-local */
2890 /* storage, which is calloc allocated. If we don't scan the cached */
2891 /* thread stacks, we appear to lose the dtv. This tends to */
2892 /* result in something that looks like a bogus dtv count, which */
2893 /* tends to result in a memset call on a block that is way too */
2894 /* large. Sometimes we're lucky and the process just dies ... */
2895 /* There seems to be a similar issue with some other memory */
2896 /* allocated by the dynamic loader. */
2897 /* This should be avoidable by either: */
2898 /* - Defining USE_PROC_FOR_LIBRARIES here. */
2899 /* That performs very poorly, precisely because we end up */
2900 /* scanning cached stacks. */
2901 /* - Have calloc look at its callers. */
2902 /* In spite of the fact that it is gross and disgusting. */
2903 /* In fact neither seems to suffice, probably in part because */
2904 /* even with USE_PROC_FOR_LIBRARIES, we don't scan parts of stack */
2905 /* segments that appear to be out of bounds. Thus we actually */
2906 /* do both, which seems to yield the best results. */
2907 # define USE_PROC_FOR_LIBRARIES
2908 #endif
2909
2910 #ifndef STACK_GROWS_UP
2911 # define STACK_GROWS_DOWN
2912 #endif
2913
2914 #ifndef CPP_WORDSZ
2915 # define CPP_WORDSZ 32
2916 #endif
2917
2918 #ifndef OS_TYPE
2919 # define OS_TYPE ""
2920 #endif
2921
2922 #ifndef DATAEND
2923 extern int end[];
2924 # define DATAEND ((ptr_t)(end))
2925 #endif
2926
2927 /* Workaround for Android NDK clang 3.5+ (as of NDK r10e) which does */
2928 /* not provide correct _end symbol. Unfortunately, alternate __end__ */
2929 /* symbol is provided only by NDK "bfd" linker. */
2930 #if defined(HOST_ANDROID) && defined(__clang__)
2931 # undef DATAEND
2932 # pragma weak __end__
2933 extern int __end__[];
2934 # define DATAEND (__end__ != 0 ? (ptr_t)__end__ : (ptr_t)_end)
2935 #endif
2936
2937 #if (defined(SVR4) || defined(HOST_ANDROID) || defined(HOST_TIZEN)) \
2938 && !defined(GETPAGESIZE)
2939 EXTERN_C_END
2940 # include <unistd.h>
2941 EXTERN_C_BEGIN
2942 # define GETPAGESIZE() (unsigned)sysconf(_SC_PAGESIZE)
2943 #endif
2944
2945 #ifndef GETPAGESIZE
2946 # if defined(SOLARIS) || defined(IRIX5) || defined(LINUX) \
2947 || defined(NETBSD) || defined(FREEBSD) || defined(HPUX)
2948 EXTERN_C_END
2949 # include <unistd.h>
2950 EXTERN_C_BEGIN
2951 # endif
2952 # define GETPAGESIZE() (unsigned)getpagesize()
2953 #endif
2954
2955 #if defined(HOST_ANDROID) && !(__ANDROID_API__ >= 23) \
2956 && ((defined(MIPS) && (CPP_WORDSZ == 32)) \
2957 || defined(ARM32) || defined(I386) /* but not x32 */)
2958 /* tkill() exists only on arm32/mips(32)/x86. */
2959 /* NDK r11+ deprecates tkill() but keeps it for Mono clients. */
2960 /* Unity: Android NDK r13 removed this for good. We should not need it. */
2961 /*# define USE_TKILL_ON_ANDROID*/
2962 #endif
2963
2964 #if defined(SOLARIS) || defined(DRSNX) || defined(UTS4)
2965 /* OS has SVR4 generic features. */
2966 /* Probably others also qualify. */
2967 # define SVR4
2968 #endif
2969
2970 #if defined(SOLARIS) || defined(DRSNX)
2971 /* OS has SOLARIS style semi-undocumented interface */
2972 /* to dynamic loader. */
2973 # define SOLARISDL
2974 /* OS has SOLARIS style signal handlers. */
2975 # define SUNOS5SIGS
2976 #endif
2977
2978 #if defined(HPUX)
2979 # define SUNOS5SIGS
2980 #endif
2981
2982 #if defined(FREEBSD) && (defined(__DragonFly__) || __FreeBSD__ >= 4 \
2983 || (__FreeBSD_kernel__ >= 4))
2984 # define SUNOS5SIGS
2985 #endif
2986
2987 #if !defined(GC_EXPLICIT_SIGNALS_UNBLOCK) && defined(SUNOS5SIGS) \
2988 && !defined(GC_NO_PTHREAD_SIGMASK)
2989 # define GC_EXPLICIT_SIGNALS_UNBLOCK
2990 #endif
2991
2992 #if !defined(NO_SIGNALS_UNBLOCK_IN_MAIN) && defined(GC_NO_PTHREAD_SIGMASK)
2993 # define NO_SIGNALS_UNBLOCK_IN_MAIN
2994 #endif
2995
2996 #if !defined(NO_MARKER_SPECIAL_SIGMASK) \
2997 && (defined(NACL) || defined(GC_WIN32_PTHREADS))
2998 /* Either there is no pthread_sigmask(), or GC marker thread cannot */
2999 /* steal and drop user signal calls. */
3000 # define NO_MARKER_SPECIAL_SIGMASK
3001 #endif
3002
3003 #ifdef GC_NETBSD_THREADS
3004 # define SIGRTMIN 33
3005 # define SIGRTMAX 63
3006 /* It seems to be necessary to wait until threads have restarted. */
3007 /* But it is unclear why that is the case. */
3008 # define GC_NETBSD_THREADS_WORKAROUND
3009 #endif
3010
3011 #ifdef GC_OPENBSD_THREADS
3012 EXTERN_C_END
3013 # include <sys/param.h>
3014 EXTERN_C_BEGIN
3015 /* Prior to 5.2 release, OpenBSD had user threads and required */
3016 /* special handling. */
3017 # if OpenBSD < 201211
3018 # define GC_OPENBSD_UTHREADS 1
3019 # endif
3020 #endif /* GC_OPENBSD_THREADS */
3021
3022 #if defined(SVR4) || defined(LINUX) || defined(IRIX5) || defined(HPUX) \
3023 || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
3024 || defined(DGUX) || defined(BSD) || defined(HAIKU) || defined(HURD) \
3025 || defined(AIX) || defined(DARWIN) || defined(OSF1)
3026 # define UNIX_LIKE /* Basic Unix-like system calls work. */
3027 #endif
3028
3029 #if defined(CPPCHECK)
3030 # undef CPP_WORDSZ
3031 # define CPP_WORDSZ (__SIZEOF_POINTER__ * 8)
3032 #endif
3033
3034 #if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
3035 # error --> bad word size
3036 #endif
3037
3038 #if !defined(ALIGNMENT) && !defined(CPPCHECK)
3039 # error --> undefined ALIGNMENT
3040 #endif
3041
3042 #ifdef PCR
3043 # undef DYNAMIC_LOADING
3044 # undef STACKBOTTOM
3045 # undef HEURISTIC1
3046 # undef HEURISTIC2
3047 # undef PROC_VDB
3048 # undef MPROTECT_VDB
3049 # define PCR_VDB
3050 #endif
3051
3052 #if !defined(STACKBOTTOM) && (defined(ECOS) || defined(NOSYS)) \
3053 && !defined(CPPCHECK)
3054 # error --> undefined STACKBOTTOM
3055 #endif
3056
3057 #ifdef IGNORE_DYNAMIC_LOADING
3058 # undef DYNAMIC_LOADING
3059 #endif
3060
3061 #if defined(SMALL_CONFIG) && !defined(GC_DISABLE_INCREMENTAL)
3062 /* Presumably not worth the space it takes. */
3063 # define GC_DISABLE_INCREMENTAL
3064 #endif
3065
3066 #if (defined(MSWIN32) || defined(MSWINCE)) && !defined(USE_WINALLOC)
3067 /* USE_WINALLOC is only an option for Cygwin. */
3068 # define USE_WINALLOC
3069 #endif
3070
3071 #ifdef USE_WINALLOC
3072 # undef USE_MMAP
3073 #endif
3074
3075 #if defined(LINUX) || defined(FREEBSD) || defined(SOLARIS) || defined(IRIX5) \
3076 || ((defined(USE_MMAP) || defined(USE_MUNMAP)) && !defined(USE_WINALLOC))
3077 # define MMAP_SUPPORTED
3078 #endif
3079
3080 /* Xbox One (DURANGO) may not need to be this aggressive, but the */
3081 /* default is likely too lax under heavy allocation pressure. */
3082 /* The platform does not have a virtual paging system, so it does not */
3083 /* have a large virtual address space that a standard x64 platform has. */
3084 #if defined(USE_MUNMAP) && !defined(MUNMAP_THRESHOLD) \
3085 && (defined(SN_TARGET_PS3) \
3086 || defined(SN_TARGET_PSP2) || defined(MSWIN_XBOX1))
3087 # define MUNMAP_THRESHOLD 2
3088 #endif
3089
3090 #if defined(GC_DISABLE_INCREMENTAL) || defined(DEFAULT_VDB) \
3091 || defined(MANUAL_VDB)
3092 # undef GWW_VDB
3093 # undef MPROTECT_VDB
3094 # undef PCR_VDB
3095 # undef PROC_VDB
3096 #endif
3097
3098 #ifdef GC_DISABLE_INCREMENTAL
3099 # undef CHECKSUMS
3100 #endif
3101
3102 #ifdef USE_GLOBAL_ALLOC
3103 /* Cannot pass MEM_WRITE_WATCH to GlobalAlloc(). */
3104 # undef GWW_VDB
3105 #endif
3106
3107 #if defined(USE_MUNMAP) && defined(GWW_VDB)
3108 # undef MPROTECT_VDB /* TODO: Cannot deal with address space holes. */
3109 /* Else if MPROTECT_VDB is available but not GWW_VDB then decide */
3110 /* whether to disable memory unmapping or mprotect-based virtual */
3111 /* dirty bits at runtime when GC_enable_incremental is called. */
3112 #endif
3113
3114 /* PARALLEL_MARK does not cause undef MPROTECT_VDB any longer. */
3115
3116 #if defined(MPROTECT_VDB) && defined(GC_PREFER_MPROTECT_VDB)
3117 /* Choose MPROTECT_VDB manually (if multiple strategies available). */
3118 # undef PCR_VDB
3119 # undef PROC_VDB
3120 /* #undef GWW_VDB - handled in os_dep.c */
3121 #endif
3122
3123 #ifdef PROC_VDB
3124 /* Multi-VDB mode is not implemented. */
3125 # undef MPROTECT_VDB
3126 #endif
3127
3128 #if defined(SIGBUS) && !defined(HAVE_SIGBUS) && !defined(CPPCHECK)
3129 # define HAVE_SIGBUS
3130 #endif
3131
3132 #ifndef SA_SIGINFO
3133 # define NO_SA_SIGACTION
3134 #endif
3135
3136 #if defined(NO_SA_SIGACTION) && defined(MPROTECT_VDB) && !defined(DARWIN) \
3137 && !defined(MSWIN32) && !defined(MSWINCE)
3138 # undef MPROTECT_VDB
3139 #endif
3140
3141 #if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB) \
3142 && !defined(GWW_VDB) && !defined(DEFAULT_VDB) && !defined(MANUAL_VDB) \
3143 && !defined(GC_DISABLE_INCREMENTAL)
3144 # define DEFAULT_VDB
3145 #endif
3146
3147 #if ((defined(UNIX_LIKE) && (defined(DARWIN) || defined(HAIKU) \
3148 || defined(HURD) || defined(OPENBSD) \
3149 || defined(ARM32) \
3150 || defined(AVR32) || defined(MIPS) \
3151 || defined(NIOS2) || defined(OR1K))) \
3152 || (defined(LINUX) && !defined(__gnu_linux__)) \
3153 || (defined(RTEMS) && defined(I386)) || defined(HOST_ANDROID)) \
3154 && !defined(NO_GETCONTEXT)
3155 # define NO_GETCONTEXT
3156 #endif
3157
3158 #ifndef PREFETCH
3159 # if GC_GNUC_PREREQ(3, 0) && !defined(NO_PREFETCH)
3160 # define PREFETCH(x) __builtin_prefetch((x), 0, 0)
3161 # else
3162 # define PREFETCH(x) (void)0
3163 # endif
3164 #endif
3165
3166 #ifndef GC_PREFETCH_FOR_WRITE
3167 # if GC_GNUC_PREREQ(3, 0) && !defined(GC_NO_PREFETCH_FOR_WRITE)
3168 # define GC_PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
3169 # else
3170 # define GC_PREFETCH_FOR_WRITE(x) (void)0
3171 # endif
3172 #endif
3173
3174 #ifndef CACHE_LINE_SIZE
3175 # define CACHE_LINE_SIZE 32 /* Wild guess */
3176 #endif
3177
3178 #ifndef STATIC
3179 # ifndef NO_DEBUGGING
3180 # define STATIC /* ignore to aid profiling and possibly debugging */
3181 # else
3182 # define STATIC static
3183 # endif
3184 #endif
3185
3186 #if defined(LINUX) && (defined(USE_PROC_FOR_LIBRARIES) || defined(IA64) \
3187 || !defined(SMALL_CONFIG))
3188 # define NEED_PROC_MAPS
3189 #endif
3190
3191 #if defined(LINUX) || defined(HURD) || defined(__GLIBC__)
3192 # define REGISTER_LIBRARIES_EARLY
3193 /* We sometimes use dl_iterate_phdr, which may acquire an internal */
3194 /* lock. This isn't safe after the world has stopped. So we must */
3195 /* call GC_register_dynamic_libraries before stopping the world. */
3196 /* For performance reasons, this may be beneficial on other */
3197 /* platforms as well, though it should be avoided in win32. */
3198 #endif /* LINUX */
3199
3200 #if defined(SEARCH_FOR_DATA_START)
3201 extern ptr_t GC_data_start;
3202 # define DATASTART GC_data_start
3203 #endif
3204
3205 #ifndef HEAP_START
3206 # define HEAP_START ((ptr_t)0)
3207 #endif
3208
3209 #ifndef CLEAR_DOUBLE
3210 # define CLEAR_DOUBLE(x) (((word*)(x))[0] = 0, ((word*)(x))[1] = 0)
3211 #endif
3212
3213 #if defined(GC_LINUX_THREADS) && defined(REDIRECT_MALLOC) \
3214 && !defined(INCLUDE_LINUX_THREAD_DESCR)
3215 /* Will not work, since libc and the dynamic loader use thread */
3216 /* locals, sometimes as the only reference. */
3217 # define INCLUDE_LINUX_THREAD_DESCR
3218 #endif
3219
3220 #if !defined(CPPCHECK)
3221 #if defined(GC_IRIX_THREADS) && !defined(IRIX5)
3222 # error --> inconsistent configuration
3223 #endif
3224 #if defined(GC_LINUX_THREADS) && !defined(LINUX) && !defined(NACL)
3225 # error --> inconsistent configuration
3226 #endif
3227 #if defined(GC_NETBSD_THREADS) && !defined(NETBSD)
3228 # error --> inconsistent configuration
3229 #endif
3230 #if defined(GC_FREEBSD_THREADS) && !defined(FREEBSD)
3231 # error --> inconsistent configuration
3232 #endif
3233 #if defined(GC_SOLARIS_THREADS) && !defined(SOLARIS)
3234 # error --> inconsistent configuration
3235 #endif
3236 #if defined(GC_HPUX_THREADS) && !defined(HPUX)
3237 # error --> inconsistent configuration
3238 #endif
3239 #if defined(GC_AIX_THREADS) && !defined(_AIX)
3240 # error --> inconsistent configuration
3241 #endif
3242 #if defined(GC_WIN32_THREADS) && !defined(CYGWIN32) && !defined(MSWIN32) \
3243 && !defined(MSWINCE) && !defined(MSWIN_XBOX1)
3244 # error --> inconsistent configuration
3245 #endif
3246 # if defined(GC_WIN32_PTHREADS) && defined(CYGWIN32)
3247 # error --> inconsistent configuration
3248 # endif
3249 #endif /* !CPPCHECK */
3250
3251 #if defined(PCR) || defined(GC_WIN32_THREADS) || defined(GC_PTHREADS) \
3252 || defined(NN_PLATFORM_CTR) || defined(NINTENDO_SWITCH) \
3253 || defined(SN_TARGET_PS3) \
3254 || defined(SN_TARGET_PSP2)
3255 #if !defined(THREADS)
3256 # define THREADS
3257 #endif
3258 #endif
3259
3260 #if defined(PARALLEL_MARK) && !defined(THREADS) && !defined(CPPCHECK)
3261 # error "invalid config - PARALLEL_MARK requires GC_THREADS"
3262 #endif
3263
3264 #if (((defined(MSWIN32) || defined(MSWINCE)) && !defined(__GNUC__)) \
3265 || (defined(MSWIN32) && defined(I386)) /* for Win98 */ \
3266 || (defined(USE_PROC_FOR_LIBRARIES) && defined(THREADS))) \
3267 && !defined(NO_WRAP_MARK_SOME)
3268 /* Under rare conditions, we may end up marking from nonexistent */
3269 /* memory. Hence we need to be prepared to recover by running */
3270 /* GC_mark_some with a suitable handler in place. */
3271 /* TODO: Probably replace __GNUC__ above with ndef GC_PTHREADS. */
3272 /* FIXME: Should we really need it for WinCE? If yes then */
3273 /* WRAP_MARK_SOME should be also defined for CeGCC which requires */
3274 /* CPU/OS-specific code in mark_ex_handler and GC_mark_some (for */
3275 /* manual stack unwinding and exception handler installation). */
3276 # define WRAP_MARK_SOME
3277 #endif
3278
3279 #if defined(PARALLEL_MARK) && !defined(DEFAULT_STACK_MAYBE_SMALL) \
3280 && (defined(HPUX) || defined(GC_DGUX386_THREADS) \
3281 || defined(NO_GETCONTEXT) /* e.g. musl */)
3282 /* TODO: Test default stack size in configure. */
3283 # define DEFAULT_STACK_MAYBE_SMALL
3284 #endif
3285
3286 #ifdef PARALLEL_MARK
3287 /* The minimum stack size for a marker thread. */
3288 # define MIN_STACK_SIZE (8 * HBLKSIZE * sizeof(word))
3289 #endif
3290
3291 #if defined(HOST_ANDROID) && !defined(THREADS) \
3292 && !defined(USE_GET_STACKBASE_FOR_MAIN)
3293 /* Always use pthread_attr_getstack on Android ("-lpthread" option is */
3294 /* not needed to be specified manually) since GC_linux_main_stack_base */
3295 /* causes app crash if invoked inside Dalvik VM. */
3296 # define USE_GET_STACKBASE_FOR_MAIN
3297 #endif
3298
3299 /* Outline pthread primitives to use in GC_get_[main_]stack_base. */
3300 #if ((defined(FREEBSD) && defined(__GLIBC__)) /* kFreeBSD */ \
3301 || defined(LINUX) || defined(NETBSD) || defined(HOST_ANDROID)) \
3302 && !defined(NO_PTHREAD_GETATTR_NP)
3303 # define HAVE_PTHREAD_GETATTR_NP 1
3304 #elif defined(FREEBSD) && !defined(__GLIBC__) \
3305 && !defined(NO_PTHREAD_ATTR_GET_NP)
3306 # define HAVE_PTHREAD_NP_H 1 /* requires include pthread_np.h */
3307 # define HAVE_PTHREAD_ATTR_GET_NP 1
3308 #endif
3309
3310 #if defined(UNIX_LIKE) && defined(THREADS) && !defined(NO_CANCEL_SAFE) \
3311 && !defined(HOST_ANDROID)
3312 /* Make the code cancellation-safe. This basically means that we */
3313 /* ensure that cancellation requests are ignored while we are in */
3314 /* the collector. This applies only to Posix deferred cancellation; */
3315 /* we don't handle Posix asynchronous cancellation. */
3316 /* Note that this only works if pthread_setcancelstate is */
3317 /* async-signal-safe, at least in the absence of asynchronous */
3318 /* cancellation. This appears to be true for the glibc version, */
3319 /* though it is not documented. Without that assumption, there */
3320 /* seems to be no way to safely wait in a signal handler, which */
3321 /* we need to do for thread suspension. */
3322 /* Also note that little other code appears to be cancellation-safe. */
3323 /* Hence it may make sense to turn this off for performance. */
3324 # define CANCEL_SAFE
3325 #endif
3326
3327 #ifdef CANCEL_SAFE
3328 # define IF_CANCEL(x) x
3329 #else
3330 # define IF_CANCEL(x) /* empty */
3331 #endif
3332
3333 #if !defined(CAN_HANDLE_FORK) && !defined(NO_HANDLE_FORK) \
3334 && !defined(HAVE_NO_FORK) \
3335 && ((defined(GC_PTHREADS) && !defined(NACL) \
3336 && !defined(GC_WIN32_PTHREADS) && !defined(USE_WINALLOC)) \
3337 || (defined(DARWIN) && defined(MPROTECT_VDB)) || defined(HANDLE_FORK))
3338 /* Attempts (where supported and requested) to make GC_malloc work in */
3339 /* a child process fork'ed from a multi-threaded parent. */
3340 # define CAN_HANDLE_FORK
3341 #endif
3342
3343 #if defined(CAN_HANDLE_FORK) && !defined(CAN_CALL_ATFORK) \
3344 && !defined(HURD) && !defined(GC_NO_CAN_CALL_ATFORK) && !defined(HOST_TIZEN) \
3345 && (!defined(HOST_ANDROID) || __ANDROID_API__ >= 21)
3346 /* Have working pthread_atfork(). */
3347 # define CAN_CALL_ATFORK
3348 #endif
3349
3350 #if !defined(CAN_HANDLE_FORK) && !defined(HAVE_NO_FORK) \
3351 && (defined(MSWIN32) || defined(MSWINCE) || defined(DOS4GW) \
3352 || defined(OS2) || defined(SYMBIAN) /* and probably others ... */)
3353 # define HAVE_NO_FORK
3354 #endif
3355
3356 #if !defined(USE_MARK_BITS) && !defined(USE_MARK_BYTES) \
3357 && defined(PARALLEL_MARK)
3358 /* Minimize compare-and-swap usage. */
3359 # define USE_MARK_BYTES
3360 #endif
3361
3362 #if (defined(MSWINCE) && !defined(__CEGCC__) || defined(MSWINRT_FLAVOR)) \
3363 && !defined(NO_GETENV)
3364 # define NO_GETENV
3365 #endif
3366
3367 #if (defined(NO_GETENV) || defined(MSWINCE)) && !defined(NO_GETENV_WIN32)
3368 # define NO_GETENV_WIN32
3369 #endif
3370
3371 #ifndef STRTOULL
3372 # if defined(_WIN64) && !defined(__GNUC__)
3373 # define STRTOULL _strtoui64
3374 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
3375 # define STRTOULL strtoull
3376 # else
3377 /* strtoul() fits since sizeof(long) >= sizeof(word). */
3378 # define STRTOULL strtoul
3379 # endif
3380 #endif /* !STRTOULL */
3381
3382 #ifndef GC_WORD_C
3383 # if defined(_WIN64) && !defined(__GNUC__)
3384 # define GC_WORD_C(val) val##ui64
3385 # elif defined(_LLP64) || defined(__LLP64__) || defined(_WIN64)
3386 # define GC_WORD_C(val) val##ULL
3387 # else
3388 # define GC_WORD_C(val) ((word)val##UL)
3389 # endif
3390 #endif /* !GC_WORD_C */
3391
3392 #if defined(__has_feature)
3393 /* __has_feature() is supported. */
3394 # if __has_feature(address_sanitizer) && !defined(ADDRESS_SANITIZER)
3395 # define ADDRESS_SANITIZER
3396 # endif
3397 # if __has_feature(memory_sanitizer) && !defined(MEMORY_SANITIZER)
3398 # define MEMORY_SANITIZER
3399 # endif
3400 # if __has_feature(thread_sanitizer) && !defined(THREAD_SANITIZER)
3401 # define THREAD_SANITIZER
3402 # endif
3403 #else
3404 # ifdef __SANITIZE_ADDRESS__
3405 /* GCC v4.8+ */
3406 # define ADDRESS_SANITIZER
3407 # endif
3408 #endif /* !__has_feature */
3409
3410 #if defined(SPARC)
3411 # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
3412 /* include assembly code to do it well. */
3413 #endif
3414
3415 /* Can we save call chain in objects for debugging? */
3416 /* SET NFRAMES (# of saved frames) and NARGS (#of args for each */
3417 /* frame) to reasonable values for the platform. */
3418 /* Set SAVE_CALL_CHAIN if we can. SAVE_CALL_COUNT can be specified */
3419 /* at build time, though we feel free to adjust it slightly. */
3420 /* Define NEED_CALLINFO if we either save the call stack or */
3421 /* GC_ADD_CALLER is defined. */
3422 /* GC_CAN_SAVE_CALL_STACKS is set in gc.h. */
3423 #if defined(SPARC)
3424 # define CAN_SAVE_CALL_ARGS
3425 #endif
3426 #if (defined(I386) || defined(X86_64)) \
3427 && (defined(LINUX) || defined(__GLIBC__))
3428 /* SAVE_CALL_CHAIN is supported if the code is compiled to save */
3429 /* frame pointers by default, i.e. no -fomit-frame-pointer flag. */
3430 # define CAN_SAVE_CALL_ARGS
3431 #endif
3432
3433 #if defined(SAVE_CALL_COUNT) && !defined(GC_ADD_CALLER) \
3434 && defined(GC_CAN_SAVE_CALL_STACKS)
3435 # define SAVE_CALL_CHAIN
3436 #endif
3437 #ifdef SAVE_CALL_CHAIN
3438 # if defined(SAVE_CALL_NARGS) && defined(CAN_SAVE_CALL_ARGS)
3439 # define NARGS SAVE_CALL_NARGS
3440 # else
3441 # define NARGS 0 /* Number of arguments to save for each call. */
3442 # endif
3443 #endif
3444 #ifdef SAVE_CALL_CHAIN
3445 # if !defined(SAVE_CALL_COUNT) || defined(CPPCHECK)
3446 # define NFRAMES 6 /* Number of frames to save. Even for */
3447 /* alignment reasons. */
3448 # else
3449 # define NFRAMES ((SAVE_CALL_COUNT + 1) & ~1)
3450 # endif
3451 # define NEED_CALLINFO
3452 #endif /* SAVE_CALL_CHAIN */
3453 #ifdef GC_ADD_CALLER
3454 # define NFRAMES 1
3455 # define NARGS 0
3456 # define NEED_CALLINFO
3457 #endif
3458
3459 #if (defined(FREEBSD) || (defined(DARWIN) && !defined(_POSIX_C_SOURCE)) \
3460 || (defined(SOLARIS) && (!defined(_XOPEN_SOURCE) \
3461 || defined(__EXTENSIONS__))) \
3462 || defined(LINUX)) && !defined(HAVE_DLADDR)
3463 # define HAVE_DLADDR
3464 #endif
3465
3466 #if defined(MAKE_BACK_GRAPH) && !defined(DBG_HDRS_ALL)
3467 # define DBG_HDRS_ALL
3468 #endif
3469
3470 #if defined(POINTER_MASK) && !defined(POINTER_SHIFT)
3471 # define POINTER_SHIFT 0
3472 #endif
3473
3474 #if defined(POINTER_SHIFT) && !defined(POINTER_MASK)
3475 # define POINTER_MASK ((word)(-1))
3476 #endif
3477
3478 #if !defined(FIXUP_POINTER) && defined(POINTER_MASK)
3479 # if defined(CPPCHECK)
3480 # define FIXUP_POINTER(p) (p = (p) << 4) /* e.g. */
3481 # else
3482 # define FIXUP_POINTER(p) (p = ((p) & POINTER_MASK) << POINTER_SHIFT)
3483 # endif
3484 #endif
3485
3486 #if defined(FIXUP_POINTER)
3487 # define NEED_FIXUP_POINTER
3488 #else
3489 # define FIXUP_POINTER(p)
3490 #endif
3491
3492 #if !defined(MARK_BIT_PER_GRANULE) && !defined(MARK_BIT_PER_OBJ)
3493 # define MARK_BIT_PER_GRANULE /* Usually faster */
3494 #endif
3495
3496 /* Some static sanity tests. */
3497 #if !defined(CPPCHECK)
3498 #if defined(MARK_BIT_PER_GRANULE) && defined(MARK_BIT_PER_OBJ)
3499 # error Define only one of MARK_BIT_PER_GRANULE and MARK_BIT_PER_OBJ.
3500 #endif
3501
3502 #if defined(STACK_GROWS_UP) && defined(STACK_GROWS_DOWN)
3503 # error "Only one of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
3504 #endif
3505 #if !defined(STACK_GROWS_UP) && !defined(STACK_GROWS_DOWN)
3506 # error "One of STACK_GROWS_UP and STACK_GROWS_DOWN should be defd."
3507 #endif
3508
3509 #if defined(REDIRECT_MALLOC) && defined(THREADS) && !defined(LINUX) \
3510 && !defined(REDIRECT_MALLOC_IN_HEADER)
3511 # error "REDIRECT_MALLOC with THREADS works at most on Linux."
3512 #endif
3513 #endif /* !CPPCHECK */
3514
3515 #ifdef GC_PRIVATE_H
3516 /* This relies on some type definitions from gc_priv.h, from */
3517 /* where it's normally included. */
3518 /* */
3519 /* How to get heap memory from the OS: */
3520 /* Note that sbrk()-like allocation is preferred, since it */
3521 /* usually makes it possible to merge consecutively allocated */
3522 /* chunks. It also avoids unintended recursion with */
3523 /* REDIRECT_MALLOC macro defined. */
3524 /* GET_MEM() argument should be of size_t type and have */
3525 /* no side-effect. GET_MEM() returns HBLKSIZE-aligned chunk; */
3526 /* 0 is taken to mean failure. */
3527 /* In case of MMAP_SUPPORTED, the argument must also be */
3528 /* a multiple of a physical page size. */
3529 /* GET_MEM is currently not assumed to retrieve 0 filled space, */
3530 /* though we should perhaps take advantage of the case in which */
3531 /* does. */
3532 struct hblk; /* See gc_priv.h. */
3533 # if defined(PCR)
3534 char * real_malloc(size_t bytes);
3535 # define GET_MEM(bytes) HBLKPTR(real_malloc(SIZET_SAT_ADD(bytes, \
3536 GC_page_size)) \
3537 + GC_page_size-1)
3538 # elif defined(OS2)
3539 void * os2_alloc(size_t bytes);
3540 # define GET_MEM(bytes) HBLKPTR((ptr_t)os2_alloc( \
3541 SIZET_SAT_ADD(bytes, \
3542 GC_page_size)) \
3543 + GC_page_size-1)
3544 # elif defined(NEXT) || defined(DOS4GW) || defined(NONSTOP) \
3545 || (defined(AMIGA) && !defined(GC_AMIGA_FASTALLOC)) \
3546 || (defined(SOLARIS) && !defined(USE_MMAP)) || defined(RTEMS) \
3547 || defined(__CC_ARM)
3548 # define GET_MEM(bytes) HBLKPTR((size_t)calloc(1, \
3549 SIZET_SAT_ADD(bytes, \
3550 GC_page_size)) \
3551 + GC_page_size - 1)
3552 # elif defined(MSWIN_XBOX1)
3553 void *durango_get_mem(size_t bytes, size_t page_size);
3554 # define GET_MEM(bytes) (struct hblk *)durango_get_mem(bytes, 0)
3555 # elif defined(MSWIN32) || defined(CYGWIN32)
3556 ptr_t GC_win32_get_mem(size_t bytes);
3557 # define GET_MEM(bytes) (struct hblk *)GC_win32_get_mem(bytes)
3558 # elif defined(MACOS)
3559 # if defined(USE_TEMPORARY_MEMORY)
3560 Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory);
3561 # define GET_MEM(bytes) HBLKPTR(GC_MacTemporaryNewPtr( \
3562 SIZET_SAT_ADD(bytes, \
3563 GC_page_size), true) \
3564 + GC_page_size-1)
3565 # else
3566 # define GET_MEM(bytes) HBLKPTR(NewPtrClear(SIZET_SAT_ADD(bytes, \
3567 GC_page_size)) \
3568 + GC_page_size-1)
3569 # endif
3570 # elif defined(MSWINCE)
3571 ptr_t GC_wince_get_mem(size_t bytes);
3572 # define GET_MEM(bytes) (struct hblk *)GC_wince_get_mem(bytes)
3573 # elif defined(AMIGA) && defined(GC_AMIGA_FASTALLOC)
3574 void *GC_amiga_get_mem(size_t bytes);
3575 # define GET_MEM(bytes) HBLKPTR((size_t)GC_amiga_get_mem( \
3576 SIZET_SAT_ADD(bytes, \
3577 GC_page_size)) \
3578 + GC_page_size-1)
3579 # elif defined(PLATFORM_GETMEM)
3580 void *platform_get_mem(size_t bytes);
3581 # define GET_MEM(bytes) (struct hblk*)platform_get_mem(bytes)
3582 # elif defined(SN_TARGET_PS3)
3583 void *ps3_get_mem(size_t bytes);
3584 # define GET_MEM(bytes) (struct hblk*)ps3_get_mem(bytes)
3585 # elif defined(SN_TARGET_PSP2)
3586 void *psp2_get_mem(size_t bytes);
3587 # define GET_MEM(bytes) (struct hblk*)psp2_get_mem(bytes)
3588 # elif defined(NINTENDO_SWITCH)
3589 void *switch_get_mem(size_t bytes);
3590 # define GET_MEM(bytes) (struct hblk*)switch_get_mem(bytes)
3591 # elif defined(HAIKU)
3592 ptr_t GC_haiku_get_mem(size_t bytes);
3593 # define GET_MEM(bytes) (struct hblk*)GC_haiku_get_mem(bytes)
3594 # elif defined(EMSCRIPTEN_TINY)
3595 void *emmalloc_memalign(size_t alignment, size_t size);
3596 # define GET_MEM(bytes) (struct hblk*)emmalloc_memalign(GC_page_size, bytes)
3597 # else
3598 ptr_t GC_unix_get_mem(size_t bytes);
3599 # define GET_MEM(bytes) (struct hblk *)GC_unix_get_mem(bytes)
3600 # endif
3601 #endif /* GC_PRIVATE_H */
3602
3603 EXTERN_C_END
3604
3605 #ifndef SMALL_CONFIG
3606 /* We were running out of memory due to the fact that
3607 * GC has a static sized array for heap segments, and without
3608 * LARGE_CONFIG you go OOM at around 1.8 GB on 64-bit.
3609 * Note, we define it everywhere on Mono. */
3610 #define LARGE_CONFIG
3611 #endif
3612
3613 #endif /* GCCONFIG_H */