PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 1ms

/libs/headers/gc/private/gcconfig.h

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