Debian Codegraph @

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