gc_os_dep.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /*
  2. * Copyright 1988, 1989, 2010 Hans-J. Boehm, Alan J. Demers
  3. * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
  4. * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
  5. * Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved.
  6. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2006, 2008 Free Software Foundation
  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. * Copied from gc5.2, files "os_dep.c", "gc_priv.h", "mark.c" and "gcconfig.h",
  20. * and modified for Guile by Marius Vollmer.
  21. */
  22. #ifdef HAVE_CONFIG_H
  23. # include <config.h>
  24. #endif
  25. #include <ctype.h>
  26. #include "libguile/gc.h"
  27. #include "libguile/scmconfig.h"
  28. #ifdef HAVE_LIBC_STACK_END
  29. extern void *__libc_stack_end;
  30. void *
  31. scm_get_stack_base ()
  32. {
  33. return __libc_stack_end;
  34. }
  35. #else
  36. #define ABORT(msg) abort ()
  37. typedef char * ptr_t; /* A generic pointer to which we can add */
  38. /* byte displacements. */
  39. /* Preferably identical to caddr_t, if it */
  40. /* exists. */
  41. /* Define word and signed_word to be unsigned and signed types of the */
  42. /* size as char * or void *. There seems to be no way to do this */
  43. /* even semi-portably. The following is probably no better/worse */
  44. /* than almost anything else. */
  45. /* The ANSI standard suggests that size_t and ptr_diff_t might be */
  46. /* better choices. But those appear to have incorrect definitions */
  47. /* on may systems. Notably "typedef int size_t" seems to be both */
  48. /* frequent and WRONG. */
  49. typedef unsigned long GC_word;
  50. typedef long GC_signed_word;
  51. typedef GC_word word;
  52. typedef GC_signed_word signed_word;
  53. typedef int GC_bool;
  54. # define TRUE 1
  55. # define FALSE 0
  56. #if defined(__STDC__)
  57. # include <stdlib.h>
  58. # if !(defined( sony_news ) )
  59. # include <stddef.h>
  60. # endif
  61. # define VOLATILE volatile
  62. #else
  63. # ifdef MSWIN32
  64. # include <stdlib.h>
  65. # endif
  66. # define VOLATILE
  67. #endif
  68. /* Machine dependent parameters. Some tuning parameters can be found */
  69. /* near the top of gc_private.h. */
  70. /* Machine specific parts contributed by various people. See README file. */
  71. /* First a unified test for Linux: */
  72. # if defined(linux) || defined(__linux__)
  73. # define LINUX
  74. # endif
  75. /* Determine the machine type: */
  76. # if defined(sun) && defined(mc68000)
  77. # define M68K
  78. # define SUNOS4
  79. # define mach_type_known
  80. # endif
  81. # if defined(hp9000s300)
  82. # define M68K
  83. # define HP
  84. # define mach_type_known
  85. # endif
  86. # if defined(__OpenBSD__) && defined(m68k)
  87. # define M68K
  88. # define OPENBSD
  89. # define mach_type_known
  90. # endif
  91. # if defined(__OpenBSD__) && defined(__sparc__)
  92. # define SPARC
  93. # define OPENBSD
  94. # define mach_type_known
  95. # endif
  96. # if defined(__NetBSD__) && defined(__alpha__)
  97. # define ALPHA
  98. # define NETBSD
  99. # define mach_type_known
  100. # endif
  101. # if defined(__NetBSD__) && defined(__powerpc__)
  102. # define POWERPC
  103. # define NETBSD
  104. # define mach_type_known
  105. # endif
  106. /* in netbsd 2.0 only __m68k__ is defined, not m68k */
  107. # if defined(__NetBSD__) && (defined(m68k) || defined(__m68k__))
  108. # define M68K
  109. # define NETBSD
  110. # define mach_type_known
  111. # endif
  112. /* in netbsd 2.0 only __arm__ is defined, not arm32 */
  113. # if defined(__NetBSD__) && (defined(arm32) || defined(__arm__))
  114. # define ARM32
  115. # define NETBSD
  116. # define mach_type_known
  117. # endif
  118. # if defined(__NetBSD__) && defined(__sparc__)
  119. # define SPARC
  120. # define NETBSD
  121. # define mach_type_known
  122. # endif
  123. # if defined(vax)
  124. # define VAX
  125. # ifdef ultrix
  126. # define ULTRIX
  127. # else
  128. # define BSD
  129. # endif
  130. # define mach_type_known
  131. # endif
  132. # if defined(mips) || defined(__mips)
  133. # define MIPS
  134. # if !defined(LINUX)
  135. # if defined(ultrix) || defined(__ultrix) || defined(__NetBSD__)
  136. # define ULTRIX
  137. # else
  138. # if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
  139. || defined(__SYSTYPE_SVR4__)
  140. # define IRIX5 /* or IRIX 6.X */
  141. # else
  142. # define RISCOS /* or IRIX 4.X */
  143. # endif
  144. # endif
  145. # endif /* !LINUX */
  146. # define mach_type_known
  147. # endif
  148. # if defined(sequent) && defined(i386)
  149. # define I386
  150. # define SEQUENT
  151. # define mach_type_known
  152. # endif
  153. # if defined(sun) && defined(i386)
  154. # define I386
  155. # define SUNOS5
  156. # define mach_type_known
  157. # endif
  158. # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
  159. # define I386
  160. # define OS2
  161. # define mach_type_known
  162. # endif
  163. # if defined(ibm032)
  164. # define RT
  165. # define mach_type_known
  166. # endif
  167. # if defined(sun) && (defined(sparc) || defined(__sparc))
  168. # define SPARC
  169. /* Test for SunOS 5.x */
  170. # include <errno.h>
  171. # ifdef ECHRNG
  172. # define SUNOS5
  173. # else
  174. # define SUNOS4
  175. # endif
  176. # define mach_type_known
  177. # endif
  178. # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
  179. && !defined(__OpenBSD__)
  180. # define SPARC
  181. # define DRSNX
  182. # define mach_type_known
  183. # endif
  184. # if defined(_IBMR2)
  185. # define RS6000
  186. # define mach_type_known
  187. # endif
  188. # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
  189. /* The above test may need refinement */
  190. # define I386
  191. # if defined(_SCO_ELF)
  192. # define SCO_ELF
  193. # else
  194. # define SCO
  195. # endif
  196. # define mach_type_known
  197. # endif
  198. # if defined(_AUX_SOURCE)
  199. # define M68K
  200. # define SYSV
  201. # define mach_type_known
  202. # endif
  203. # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
  204. || defined(hppa) || defined(__hppa__)
  205. # define HP_PA
  206. # ifndef LINUX
  207. # define HPUX
  208. # endif
  209. # define mach_type_known
  210. # endif
  211. # if defined(LINUX) && (defined(i386) || defined(__i386__))
  212. # define I386
  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(powerpc)
  220. # define POWERPC
  221. # define mach_type_known
  222. # endif
  223. # if defined(LINUX) && defined(__mc68000__)
  224. # define M68K
  225. # define mach_type_known
  226. # endif
  227. # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
  228. # define SPARC
  229. # define mach_type_known
  230. # endif
  231. # if defined(LINUX) && (defined(arm) || defined (__arm__))
  232. # define ARM32
  233. # define mach_type_known
  234. # endif
  235. # if defined(__alpha) || defined(__alpha__)
  236. # define ALPHA
  237. # if !defined(LINUX) && !defined (NETBSD)
  238. # define OSF1 /* a.k.a Digital Unix */
  239. # endif
  240. # define mach_type_known
  241. # endif
  242. # if defined(_AMIGA) && !defined(AMIGA)
  243. # define AMIGA
  244. # endif
  245. # ifdef AMIGA
  246. # define M68K
  247. # define mach_type_known
  248. # endif
  249. # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
  250. # define M68K
  251. # define MACOS
  252. # define mach_type_known
  253. # endif
  254. # if defined(__MWERKS__) && defined(__powerc)
  255. # define POWERPC
  256. # define MACOS
  257. # define mach_type_known
  258. # endif
  259. # if defined(macosx) || \
  260. (defined(__APPLE__) && defined(__MACH__) && defined(__ppc__))
  261. # define MACOSX
  262. # define POWERPC
  263. # define mach_type_known
  264. # endif
  265. # if defined(NeXT) && defined(mc68000)
  266. # define M68K
  267. # define NEXT
  268. # define mach_type_known
  269. # endif
  270. # if defined(NeXT) && defined(i386)
  271. # define I386
  272. # define NEXT
  273. # define mach_type_known
  274. # endif
  275. # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
  276. # define I386
  277. # define OPENBSD
  278. # define mach_type_known
  279. # endif
  280. # if defined(__FreeBSD__) && defined(i386)
  281. # define I386
  282. # define FREEBSD
  283. # define mach_type_known
  284. # endif
  285. # if defined(__NetBSD__) && defined(i386)
  286. # define I386
  287. # define NETBSD
  288. # define mach_type_known
  289. # endif
  290. # if defined(bsdi) && defined(i386)
  291. # define I386
  292. # define BSDI
  293. # define mach_type_known
  294. # endif
  295. # if !defined(mach_type_known) && defined(__386BSD__)
  296. # define I386
  297. # define THREE86BSD
  298. # define mach_type_known
  299. # endif
  300. # if defined(_CX_UX) && defined(_M88K)
  301. # define M88K
  302. # define CX_UX
  303. # define mach_type_known
  304. # endif
  305. # if defined(DGUX)
  306. # define M88K
  307. /* DGUX defined */
  308. # define mach_type_known
  309. # endif
  310. # if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
  311. || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
  312. # define I386
  313. # define MSWIN32 /* or Win32s */
  314. # define mach_type_known
  315. # endif
  316. # if defined(__DJGPP__)
  317. # define I386
  318. # ifndef DJGPP
  319. # define DJGPP /* MSDOS running the DJGPP port of GCC */
  320. # endif
  321. # define mach_type_known
  322. # endif
  323. # if defined(__CYGWIN32__) || defined(__CYGWIN__)
  324. # define I386
  325. # define CYGWIN32
  326. # define mach_type_known
  327. # endif
  328. # if defined(__MINGW32__)
  329. # define I386
  330. # define MSWIN32
  331. # define mach_type_known
  332. # endif
  333. # if defined(__BORLANDC__)
  334. # define I386
  335. # define MSWIN32
  336. # define mach_type_known
  337. # endif
  338. # if defined(_UTS) && !defined(mach_type_known)
  339. # define S370
  340. # define UTS4
  341. # define mach_type_known
  342. # endif
  343. # if defined(__pj__)
  344. # define PJ
  345. # define mach_type_known
  346. # endif
  347. /* Ivan Demakov */
  348. # if defined(__WATCOMC__) && defined(__386__)
  349. # define I386
  350. # if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
  351. # if defined(__OS2__)
  352. # define OS2
  353. # else
  354. # if defined(__WINDOWS_386__) || defined(__NT__)
  355. # define MSWIN32
  356. # else
  357. # define DOS4GW
  358. # endif
  359. # endif
  360. # endif
  361. # define mach_type_known
  362. # endif
  363. # if defined(__s390__) && defined(LINUX)
  364. # define S370
  365. # define mach_type_known
  366. # endif
  367. # if defined(__GNU__)
  368. # define I386
  369. # define GNU
  370. # define mach_type_known
  371. # endif
  372. # if defined(__SCO_VERSION__)
  373. # define I386
  374. # define SYSV
  375. # define mach_type_known
  376. # endif
  377. /* Feel free to add more clauses here */
  378. /* Or manually define the machine type here. A machine type is */
  379. /* characterized by the architecture. Some */
  380. /* machine types are further subdivided by OS. */
  381. /* the macros ULTRIX, RISCOS, and BSD to distinguish. */
  382. /* Note that SGI IRIX is treated identically to RISCOS. */
  383. /* SYSV on an M68K actually means A/UX. */
  384. /* The distinction in these cases is usually the stack starting address */
  385. # ifndef mach_type_known
  386. void *
  387. scm_get_stack_base ()
  388. {
  389. ABORT ("Can't determine stack base");
  390. return NULL;
  391. }
  392. # else
  393. /* Mapping is: M68K ==> Motorola 680X0 */
  394. /* (SUNOS4,HP,NEXT, and SYSV (A/UX), */
  395. /* MACOS and AMIGA variants) */
  396. /* I386 ==> Intel 386 */
  397. /* (SEQUENT, OS2, SCO, LINUX, NETBSD, */
  398. /* FREEBSD, THREE86BSD, MSWIN32, */
  399. /* BSDI,SUNOS5, NEXT, other variants) */
  400. /* NS32K ==> Encore Multimax */
  401. /* MIPS ==> R2000 or R3000 */
  402. /* (RISCOS, ULTRIX variants) */
  403. /* VAX ==> DEC VAX */
  404. /* (BSD, ULTRIX variants) */
  405. /* RS6000 ==> IBM RS/6000 AIX3.X */
  406. /* RT ==> IBM PC/RT */
  407. /* HP_PA ==> HP9000/700 & /800 */
  408. /* HP/UX */
  409. /* SPARC ==> SPARC under SunOS */
  410. /* (SUNOS4, SUNOS5, */
  411. /* DRSNX variants) */
  412. /* ALPHA ==> DEC Alpha */
  413. /* (OSF1 and LINUX variants) */
  414. /* M88K ==> Motorola 88XX0 */
  415. /* (CX_UX and DGUX) */
  416. /* S370 ==> 370-like machine */
  417. /* running Amdahl UTS4 */
  418. /* ARM32 ==> Intel StrongARM */
  419. /* IA64 ==> Intel IA64 */
  420. /* (e.g. Itanium) */
  421. /*
  422. * For each architecture and OS, the following need to be defined:
  423. *
  424. * CPP_WORD_SZ is a simple integer constant representing the word size.
  425. * in bits. We assume byte addressibility, where a byte has 8 bits.
  426. * We also assume CPP_WORD_SZ is either 32 or 64.
  427. * (We care about the length of pointers, not hardware
  428. * bus widths. Thus a 64 bit processor with a C compiler that uses
  429. * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
  430. *
  431. * MACH_TYPE is a string representation of the machine type.
  432. * OS_TYPE is analogous for the OS.
  433. *
  434. * ALIGNMENT is the largest N, such that
  435. * all pointer are guaranteed to be aligned on N byte boundaries.
  436. * defining it to be 1 will always work, but perform poorly.
  437. *
  438. * DATASTART is the beginning of the data segment.
  439. * On UNIX systems, the collector will scan the area between DATASTART
  440. * and DATAEND for root pointers.
  441. *
  442. * DATAEND, if not &end.
  443. *
  444. * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
  445. * the pointer size.
  446. *
  447. * STACKBOTTOM is the cool end of the stack, which is usually the
  448. * highest address in the stack.
  449. * Under PCR or OS/2, we have other ways of finding thread stacks.
  450. * For each machine, the following should:
  451. * 1) define SCM_STACK_GROWS_UP if the stack grows toward higher addresses, and
  452. * 2) define exactly one of
  453. * STACKBOTTOM (should be defined to be an expression)
  454. * HEURISTIC1
  455. * HEURISTIC2
  456. * If either of the last two macros are defined, then STACKBOTTOM is computed
  457. * during collector startup using one of the following two heuristics:
  458. * HEURISTIC1: Take an address inside GC_init's frame, and round it up to
  459. * the next multiple of STACK_GRAN.
  460. * HEURISTIC2: Take an address inside GC_init's frame, increment it repeatedly
  461. * in small steps (decrement if SCM_STACK_GROWS_UP), and read the value
  462. * at each location. Remember the value when the first
  463. * Segmentation violation or Bus error is signalled. Round that
  464. * to the nearest plausible page boundary, and use that instead
  465. * of STACKBOTTOM.
  466. *
  467. * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
  468. * the value of environ is a pointer that can serve as STACKBOTTOM.
  469. * I expect that HEURISTIC2 can be replaced by this approach, which
  470. * interferes far less with debugging.
  471. *
  472. * If no expression for STACKBOTTOM can be found, and neither of the above
  473. * heuristics are usable, the collector can still be used with all of the above
  474. * undefined, provided one of the following is done:
  475. * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
  476. * without reference to STACKBOTTOM. This is appropriate for use in
  477. * conjunction with thread packages, since there will be multiple stacks.
  478. * (Allocating thread stacks in the heap, and treating them as ordinary
  479. * heap data objects is also possible as a last resort. However, this is
  480. * likely to introduce significant amounts of excess storage retention
  481. * unless the dead parts of the thread stacks are periodically cleared.)
  482. * 2) Client code may set GC_stackbottom before calling any GC_ routines.
  483. * If the author of the client code controls the main program, this is
  484. * easily accomplished by introducing a new main program, setting
  485. * GC_stackbottom to the address of a local variable, and then calling
  486. * the original main program. The new main program would read something
  487. * like:
  488. *
  489. * # include "gc_private.h"
  490. *
  491. * main(argc, argv, envp)
  492. * int argc;
  493. * char **argv, **envp;
  494. * {
  495. * int dummy;
  496. *
  497. * GC_stackbottom = (ptr_t)(&dummy);
  498. * return(real_main(argc, argv, envp));
  499. * }
  500. *
  501. *
  502. * Each architecture may also define the style of virtual dirty bit
  503. * implementation to be used:
  504. * MPROTECT_VDB: Write protect the heap and catch faults.
  505. * PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
  506. *
  507. * An architecture may define DYNAMIC_LOADING if dynamic_load.c
  508. * defined GC_register_dynamic_libraries() for the architecture.
  509. *
  510. * An architecture may define PREFETCH(x) to preload the cache with *x.
  511. * This defaults to a no-op.
  512. *
  513. * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
  514. *
  515. * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
  516. * clear the two words at GC_malloc-aligned address x. By default,
  517. * word stores of 0 are used instead.
  518. */
  519. # define STACK_GRAN 0x1000000
  520. # ifdef M68K
  521. # define MACH_TYPE "M68K"
  522. # define ALIGNMENT 2
  523. # ifdef OPENBSD
  524. # define OS_TYPE "OPENBSD"
  525. # define HEURISTIC2
  526. extern char etext;
  527. # define DATASTART ((ptr_t)(&etext))
  528. # endif
  529. # ifdef NETBSD
  530. # define OS_TYPE "NETBSD"
  531. # define HEURISTIC2
  532. extern char etext;
  533. # define DATASTART ((ptr_t)(&etext))
  534. # endif
  535. # ifdef LINUX
  536. # define OS_TYPE "LINUX"
  537. # define STACKBOTTOM ((ptr_t)0xf0000000)
  538. # define MPROTECT_VDB
  539. # ifdef __ELF__
  540. # define DYNAMIC_LOADING
  541. extern char **__environ;
  542. # define DATASTART ((ptr_t)(&__environ))
  543. /* hideous kludge: __environ is the first */
  544. /* word in crt0.o, and delimits the start */
  545. /* of the data segment, no matter which */
  546. /* ld options were passed through. */
  547. /* We could use _etext instead, but that */
  548. /* would include .rodata, which may */
  549. /* contain large read-only data tables */
  550. /* that we'd rather not scan. */
  551. extern int _end;
  552. # define DATAEND (&_end)
  553. # else
  554. extern int etext;
  555. # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
  556. # endif
  557. # endif
  558. # ifdef SUNOS4
  559. # define OS_TYPE "SUNOS4"
  560. extern char etext;
  561. # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ffff) & ~0x1ffff))
  562. # define HEURISTIC1 /* differs */
  563. # define DYNAMIC_LOADING
  564. # endif
  565. # ifdef HP
  566. # define OS_TYPE "HP"
  567. extern char etext;
  568. # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
  569. # define STACKBOTTOM ((ptr_t) 0xffeffffc)
  570. /* empirically determined. seems to work. */
  571. # include <unistd.h>
  572. # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
  573. # endif
  574. # ifdef SYSV
  575. # define OS_TYPE "SYSV"
  576. extern etext;
  577. # define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \
  578. & ~0x3fffff) \
  579. +((word)&etext & 0x1fff))
  580. /* This only works for shared-text binaries with magic number 0413.
  581. The other sorts of SysV binaries put the data at the end of the text,
  582. in which case the default of &etext would work. Unfortunately,
  583. handling both would require having the magic-number available.
  584. -- Parag
  585. */
  586. # define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
  587. /* The stack starts at the top of memory, but */
  588. /* 0x0 cannot be used as setjump_test complains */
  589. /* that the stack direction is incorrect. Two */
  590. /* bytes down from 0x0 should be safe enough. */
  591. /* --Parag */
  592. # include <sys/mmu.h>
  593. # define GETPAGESIZE() PAGESIZE /* Is this still right? */
  594. # endif
  595. # ifdef AMIGA
  596. # define OS_TYPE "AMIGA"
  597. /* STACKBOTTOM and DATASTART handled specially */
  598. /* in os_dep.c */
  599. # define DATAEND /* not needed */
  600. # define GETPAGESIZE() 4096
  601. # endif
  602. # ifdef MACOS
  603. # ifndef __LOWMEM__
  604. # include <LowMem.h>
  605. # endif
  606. # define OS_TYPE "MACOS"
  607. /* see os_dep.c for details of global data segments. */
  608. # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
  609. # define DATAEND /* not needed */
  610. # define GETPAGESIZE() 4096
  611. # endif
  612. # ifdef NEXT
  613. # define OS_TYPE "NEXT"
  614. # define DATASTART ((ptr_t) get_etext())
  615. # define STACKBOTTOM ((ptr_t) 0x4000000)
  616. # define DATAEND /* not needed */
  617. # endif
  618. # endif
  619. # ifdef POWERPC
  620. # define MACH_TYPE "POWERPC"
  621. # ifdef MACOS
  622. # define ALIGNMENT 2 /* Still necessary? Could it be 4? */
  623. # ifndef __LOWMEM__
  624. # include <LowMem.h>
  625. # endif
  626. # define OS_TYPE "MACOS"
  627. /* see os_dep.c for details of global data segments. */
  628. # define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
  629. # define DATAEND /* not needed */
  630. # endif
  631. # ifdef LINUX
  632. # define ALIGNMENT 4 /* Guess. Can someone verify? */
  633. /* This was 2, but that didn't sound right. */
  634. # define OS_TYPE "LINUX"
  635. # define HEURISTIC1
  636. # define DYNAMIC_LOADING
  637. # undef STACK_GRAN
  638. # define STACK_GRAN 0x10000000
  639. /* Stack usually starts at 0x80000000 */
  640. # define LINUX_DATA_START
  641. extern int _end;
  642. # define DATAEND (&_end)
  643. # endif
  644. # ifdef MACOSX
  645. # define ALIGNMENT 4
  646. # define OS_TYPE "MACOSX"
  647. # define DATASTART ((ptr_t) get_etext())
  648. # define STACKBOTTOM ((ptr_t) 0xc0000000)
  649. # define DATAEND /* not needed */
  650. # endif
  651. # endif
  652. # ifdef VAX
  653. # define MACH_TYPE "VAX"
  654. # define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
  655. extern char etext;
  656. # define DATASTART ((ptr_t)(&etext))
  657. # ifdef BSD
  658. # define OS_TYPE "BSD"
  659. # define HEURISTIC1
  660. /* HEURISTIC2 may be OK, but it's hard to test. */
  661. # endif
  662. # ifdef ULTRIX
  663. # define OS_TYPE "ULTRIX"
  664. # define STACKBOTTOM ((ptr_t) 0x7fffc800)
  665. # endif
  666. # endif
  667. # ifdef RT
  668. # define MACH_TYPE "RT"
  669. # define ALIGNMENT 4
  670. # define DATASTART ((ptr_t) 0x10000000)
  671. # define STACKBOTTOM ((ptr_t) 0x1fffd800)
  672. # endif
  673. # ifdef SPARC
  674. # define MACH_TYPE "SPARC"
  675. # define ALIGNMENT 4 /* Required by hardware */
  676. # define ALIGN_DOUBLE
  677. extern int etext;
  678. # ifdef SUNOS5
  679. # define OS_TYPE "SUNOS5"
  680. # define OS_TYPE "SUNOS5"
  681. extern int _etext[], _end[];
  682. ptr_t GC_SysVGetDataStart(size_t, ptr_t);
  683. # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
  684. # define DATAEND (ptr_t)(_end)
  685. /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
  686. /* but reportedly breaks under 2.8. It appears that the stack */
  687. /* base is a property of the executable, so this should not break */
  688. /* old executables. */
  689. /* HEURISTIC2 probably works, but this appears to be preferable. */
  690. # include <sys/vm.h>
  691. # define STACKBOTTOM ((ptr_t) USRSTACK)
  692. # ifndef USE_MMAP
  693. # define USE_MMAP
  694. # endif
  695. # ifdef USE_MMAP
  696. # define HEAP_START (ptr_t)0x40000000
  697. # else
  698. # define HEAP_START DATAEND
  699. # endif
  700. # define PROC_VDB
  701. /* HEURISTIC1 reportedly no longer works under 2.7. Thus we */
  702. /* switched to HEURISTIC2, eventhough it creates some debugging */
  703. /* issues. */
  704. # define HEURISTIC2
  705. # include <unistd.h>
  706. # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
  707. /* getpagesize() appeared to be missing from at least one */
  708. /* Solaris 5.4 installation. Weird. */
  709. # define DYNAMIC_LOADING
  710. # endif
  711. # ifdef SUNOS4
  712. # define OS_TYPE "SUNOS4"
  713. /* [If you have a weak stomach, don't read this.] */
  714. /* We would like to use: */
  715. /* # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1fff) & ~0x1fff)) */
  716. /* This fails occasionally, due to an ancient, but very */
  717. /* persistent ld bug. &etext is set 32 bytes too high. */
  718. /* We instead read the text segment size from the a.out */
  719. /* header, which happens to be mapped into our address space */
  720. /* at the start of the text segment. The detective work here */
  721. /* was done by Robert Ehrlich, Manuel Serrano, and Bernard */
  722. /* Serpette of INRIA. */
  723. /* This assumes ZMAGIC, i.e. demand-loadable executables. */
  724. # define TEXTSTART 0x2000
  725. # define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
  726. # define MPROTECT_VDB
  727. # define HEURISTIC1
  728. # define DYNAMIC_LOADING
  729. # endif
  730. # ifdef DRSNX
  731. # define CPP_WORDSZ 32
  732. # define OS_TYPE "DRSNX"
  733. extern char * GC_SysVGetDataStart();
  734. extern int etext;
  735. # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext)
  736. # define MPROTECT_VDB
  737. # define STACKBOTTOM ((ptr_t) 0xdfff0000)
  738. # define DYNAMIC_LOADING
  739. # endif
  740. # ifdef LINUX
  741. # define OS_TYPE "LINUX"
  742. # ifdef __ELF__
  743. # define LINUX_DATA_START
  744. # define DYNAMIC_LOADING
  745. # else
  746. Linux Sparc non elf ?
  747. # endif
  748. extern int _end;
  749. # define DATAEND (&_end)
  750. # define SVR4
  751. # define STACKBOTTOM ((ptr_t) 0xf0000000)
  752. # endif
  753. # ifdef OPENBSD
  754. # define OS_TYPE "OPENBSD"
  755. # define STACKBOTTOM ((ptr_t) 0xf8000000)
  756. # define DATASTART ((ptr_t)(&etext))
  757. # endif
  758. # endif
  759. # ifdef I386
  760. # define MACH_TYPE "I386"
  761. # define ALIGNMENT 4 /* Appears to hold for all "32 bit" compilers */
  762. /* except Borland. The -a4 option fixes */
  763. /* Borland. */
  764. /* Ivan Demakov: For Watcom the option is -zp4. */
  765. # ifndef SMALL_CONFIG
  766. # define ALIGN_DOUBLE /* Not strictly necessary, but may give speed */
  767. /* improvement on Pentiums. */
  768. # endif
  769. # ifdef SEQUENT
  770. # define OS_TYPE "SEQUENT"
  771. extern int etext;
  772. # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
  773. # define STACKBOTTOM ((ptr_t) 0x3ffff000)
  774. # endif
  775. # ifdef SUNOS5
  776. # define OS_TYPE "SUNOS5"
  777. extern int _etext[], _end[];
  778. ptr_t GC_SysVGetDataStart(size_t, ptr_t);
  779. # define DATASTART GC_SysVGetDataStart(0x1000, (ptr_t)_etext)
  780. # define DATAEND (ptr_t)(_end)
  781. /* # define STACKBOTTOM ((ptr_t)(_start)) worked through 2.7, */
  782. /* but reportedly breaks under 2.8. It appears that the stack */
  783. /* base is a property of the executable, so this should not break */
  784. /* old executables. */
  785. /* HEURISTIC2 probably works, but this appears to be preferable. */
  786. # include <sys/vm.h>
  787. # define STACKBOTTOM ((ptr_t) USRSTACK)
  788. /** At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
  789. /*# define PROC_VDB*/
  790. # define DYNAMIC_LOADING
  791. # ifndef USE_MMAP
  792. # define USE_MMAP
  793. # endif
  794. # ifdef USE_MMAP
  795. # define HEAP_START (ptr_t)0x40000000
  796. # else
  797. # define HEAP_START DATAEND
  798. # endif
  799. # endif
  800. # ifdef SCO
  801. # define OS_TYPE "SCO"
  802. extern int etext;
  803. # define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \
  804. & ~0x3fffff) \
  805. +((word)&etext & 0xfff))
  806. # define STACKBOTTOM ((ptr_t) 0x7ffffffc)
  807. # endif
  808. # ifdef SCO_ELF
  809. # define OS_TYPE "SCO_ELF"
  810. extern int etext;
  811. # define DATASTART ((ptr_t)(&etext))
  812. # define STACKBOTTOM ((ptr_t) 0x08048000)
  813. # define DYNAMIC_LOADING
  814. # define ELF_CLASS ELFCLASS32
  815. # endif
  816. # ifdef LINUX
  817. # define OS_TYPE "LINUX"
  818. # define LINUX_STACKBOTTOM
  819. # if 0
  820. # define HEURISTIC1
  821. # undef STACK_GRAN
  822. # define STACK_GRAN 0x10000000
  823. /* STACKBOTTOM is usually 0xc0000000, but this changes with */
  824. /* different kernel configurations. In particular, systems */
  825. /* with 2GB physical memory will usually move the user */
  826. /* address space limit, and hence initial SP to 0x80000000. */
  827. # endif
  828. # if !defined(LINUX_THREADS) || !defined(REDIRECT_MALLOC)
  829. # define MPROTECT_VDB
  830. # else
  831. /* We seem to get random errors in incremental mode, */
  832. /* possibly because Linux threads is itself a malloc client */
  833. /* and can't deal with the signals. */
  834. # endif
  835. # ifdef __ELF__
  836. # define DYNAMIC_LOADING
  837. # ifdef UNDEFINED /* includes ro data */
  838. extern int _etext;
  839. # define DATASTART ((ptr_t)((((word) (&_etext)) + 0xfff) & ~0xfff))
  840. # endif
  841. # include <features.h>
  842. # if defined(__GLIBC__) && __GLIBC__ >= 2
  843. # define LINUX_DATA_START
  844. # else
  845. extern char **__environ;
  846. # define DATASTART ((ptr_t)(&__environ))
  847. /* hideous kludge: __environ is the first */
  848. /* word in crt0.o, and delimits the start */
  849. /* of the data segment, no matter which */
  850. /* ld options were passed through. */
  851. /* We could use _etext instead, but that */
  852. /* would include .rodata, which may */
  853. /* contain large read-only data tables */
  854. /* that we'd rather not scan. */
  855. # endif
  856. extern int _end;
  857. # define DATAEND (&_end)
  858. # else
  859. extern int etext;
  860. # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
  861. # endif
  862. # ifdef USE_I686_PREFETCH
  863. # define PREFETCH(x) \
  864. __asm__ __volatile__ (" prefetchnta %0": : "m"(*(char *)(x)))
  865. /* Empirically prefetcht0 is much more effective at reducing */
  866. /* cache miss stalls for the targetted load instructions. But it */
  867. /* seems to interfere enough with other cache traffic that the net */
  868. /* result is worse than prefetchnta. */
  869. # if 0
  870. /* Using prefetches for write seems to have a slight negative */
  871. /* impact on performance, at least for a PIII/500. */
  872. # define PREFETCH_FOR_WRITE(x) \
  873. __asm__ __volatile__ (" prefetcht0 %0": : "m"(*(char *)(x)))
  874. # endif
  875. # endif
  876. # ifdef USE_3DNOW_PREFETCH
  877. # define PREFETCH(x) \
  878. __asm__ __volatile__ (" prefetch %0": : "m"(*(char *)(x)))
  879. # define PREFETCH_FOR_WRITE(x)
  880. __asm__ __volatile__ (" prefetchw %0": : "m"(*(char *)(x)))
  881. # endif
  882. # endif
  883. # ifdef CYGWIN32
  884. # define OS_TYPE "CYGWIN32"
  885. extern int _data_start__;
  886. extern int _data_end__;
  887. extern int _bss_start__;
  888. extern int _bss_end__;
  889. /* For binutils 2.9.1, we have */
  890. /* DATASTART = _data_start__ */
  891. /* DATAEND = _bss_end__ */
  892. /* whereas for some earlier versions it was */
  893. /* DATASTART = _bss_start__ */
  894. /* DATAEND = _data_end__ */
  895. /* To get it right for both, we take the */
  896. /* minumum/maximum of the two. */
  897. # define MAX(x,y) ((x) > (y) ? (x) : (y))
  898. # define MIN(x,y) ((x) < (y) ? (x) : (y))
  899. # define DATASTART ((ptr_t) MIN(&_data_start__, &_bss_start__))
  900. # define DATAEND ((ptr_t) MAX(&_data_end__, &_bss_end__))
  901. # undef STACK_GRAN
  902. # define STACK_GRAN 0x10000
  903. # define HEURISTIC1
  904. # endif
  905. # ifdef OS2
  906. # define OS_TYPE "OS2"
  907. /* STACKBOTTOM and DATASTART are handled specially in */
  908. /* os_dep.c. OS2 actually has the right */
  909. /* system call! */
  910. # define DATAEND /* not needed */
  911. # endif
  912. # ifdef MSWIN32
  913. # define OS_TYPE "MSWIN32"
  914. /* STACKBOTTOM and DATASTART are handled specially in */
  915. /* os_dep.c. */
  916. # ifndef __WATCOMC__
  917. # define MPROTECT_VDB
  918. # endif
  919. # define DATAEND /* not needed */
  920. # endif
  921. # ifdef DJGPP
  922. # define OS_TYPE "DJGPP"
  923. # include "stubinfo.h"
  924. extern int etext;
  925. extern int _stklen;
  926. extern int __djgpp_stack_limit;
  927. # define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ff) & ~0x1ff))
  928. /* # define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
  929. + _stklen)) */
  930. # define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
  931. /* This may not be right. */
  932. # endif
  933. # ifdef OPENBSD
  934. # define OS_TYPE "OPENBSD"
  935. # endif
  936. # ifdef FREEBSD
  937. # define OS_TYPE "FREEBSD"
  938. # define MPROTECT_VDB
  939. # endif
  940. # ifdef NETBSD
  941. # define OS_TYPE "NETBSD"
  942. # endif
  943. # ifdef THREE86BSD
  944. # define OS_TYPE "THREE86BSD"
  945. # endif
  946. # ifdef BSDI
  947. # define OS_TYPE "BSDI"
  948. # endif
  949. # if defined(OPENBSD) || defined(FREEBSD) || defined(NETBSD) \
  950. || defined(THREE86BSD) || defined(BSDI)
  951. # define HEURISTIC2
  952. extern char etext;
  953. # define DATASTART ((ptr_t)(&etext))
  954. # endif
  955. # ifdef NEXT
  956. # define OS_TYPE "NEXT"
  957. # define DATASTART ((ptr_t) get_etext())
  958. # define STACKBOTTOM ((ptr_t)0xc0000000)
  959. # define DATAEND /* not needed */
  960. # endif
  961. # ifdef DOS4GW
  962. # define OS_TYPE "DOS4GW"
  963. extern long __nullarea;
  964. extern char _end;
  965. extern char *_STACKTOP;
  966. /* Depending on calling conventions Watcom C either precedes
  967. or does not precedes with undescore names of C-variables.
  968. Make sure startup code variables always have the same names. */
  969. #pragma aux __nullarea "*";
  970. #pragma aux _end "*";
  971. # define STACKBOTTOM ((ptr_t) _STACKTOP)
  972. /* confused? me too. */
  973. # define DATASTART ((ptr_t) &__nullarea)
  974. # define DATAEND ((ptr_t) &_end)
  975. # endif
  976. # ifdef GNU
  977. # define OS_TYPE "GNU"
  978. # endif
  979. # endif
  980. # ifdef NS32K
  981. # define MACH_TYPE "NS32K"
  982. # define ALIGNMENT 4
  983. extern char **environ;
  984. # define DATASTART ((ptr_t)(&environ))
  985. /* hideous kludge: environ is the first */
  986. /* word in crt0.o, and delimits the start */
  987. /* of the data segment, no matter which */
  988. /* ld options were passed through. */
  989. # define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
  990. # endif
  991. # ifdef MIPS
  992. # define MACH_TYPE "MIPS"
  993. # ifdef LINUX
  994. # define CPP_WORDSZ _MIPS_SZPTR
  995. # define OS_TYPE "LINUX"
  996. # define ALIGNMENT 4
  997. # define ALIGN_DOUBLE
  998. extern int _fdata;
  999. # define DATASTART ((ptr_t)(&_fdata))
  1000. extern int _end;
  1001. # define DATAEND ((ptr_t)(&_end))
  1002. # define STACKBOTTOM ((ptr_t)0x7fff8000)
  1003. # define USE_GENERIC_PUSH_REGS 1
  1004. # define DYNAMIC_LOADING
  1005. # endif /* Linux */
  1006. # ifdef ULTRIX
  1007. # define HEURISTIC2
  1008. # define DATASTART (ptr_t)0x10000000
  1009. /* Could probably be slightly higher since */
  1010. /* startup code allocates lots of stuff. */
  1011. # define OS_TYPE "ULTRIX"
  1012. # define ALIGNMENT 4
  1013. # endif
  1014. # ifdef RISCOS
  1015. # define HEURISTIC2
  1016. # define DATASTART (ptr_t)0x10000000
  1017. # define OS_TYPE "RISCOS"
  1018. # define ALIGNMENT 4 /* Required by hardware */
  1019. # endif
  1020. # ifdef IRIX5
  1021. # define HEURISTIC2
  1022. extern int _fdata;
  1023. # define DATASTART ((ptr_t)(&_fdata))
  1024. # ifdef USE_MMAP
  1025. # define HEAP_START (ptr_t)0x30000000
  1026. # else
  1027. # define HEAP_START DATASTART
  1028. # endif
  1029. /* Lowest plausible heap address. */
  1030. /* In the MMAP case, we map there. */
  1031. /* In either case it is used to identify */
  1032. /* heap sections so they're not */
  1033. /* considered as roots. */
  1034. # define OS_TYPE "IRIX5"
  1035. # define MPROTECT_VDB
  1036. # ifdef _MIPS_SZPTR
  1037. # define CPP_WORDSZ _MIPS_SZPTR
  1038. # define ALIGNMENT (_MIPS_SZPTR/8)
  1039. # if CPP_WORDSZ != 64
  1040. # define ALIGN_DOUBLE
  1041. # endif
  1042. # else
  1043. # define ALIGNMENT 4
  1044. # define ALIGN_DOUBLE
  1045. # endif
  1046. # define DYNAMIC_LOADING
  1047. # endif
  1048. # endif
  1049. # ifdef RS6000
  1050. # define MACH_TYPE "RS6000"
  1051. # define ALIGNMENT 4
  1052. # define DATASTART ((ptr_t)0x20000000)
  1053. extern int errno;
  1054. # define STACKBOTTOM ((ptr_t)((ulong)&errno))
  1055. # define DYNAMIC_LOADING
  1056. /* For really old versions of AIX, this may have to be removed. */
  1057. # endif
  1058. # ifdef HP_PA
  1059. /* OS is assumed to be HP/UX */
  1060. # define MACH_TYPE "HP_PA"
  1061. # define OS_TYPE "HPUX"
  1062. # ifdef __LP64__
  1063. # define CPP_WORDSZ 64
  1064. # define ALIGNMENT 8
  1065. # else
  1066. # define CPP_WORDSZ 32
  1067. # define ALIGNMENT 4
  1068. # define ALIGN_DOUBLE
  1069. # endif
  1070. extern int __data_start;
  1071. # define DATASTART ((ptr_t)(&__data_start))
  1072. # if 0
  1073. /* The following appears to work for 7xx systems running HP/UX */
  1074. /* 9.xx Furthermore, it might result in much faster */
  1075. /* collections than HEURISTIC2, which may involve scanning */
  1076. /* segments that directly precede the stack. It is not the */
  1077. /* default, since it may not work on older machine/OS */
  1078. /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
  1079. /* this.) */
  1080. # define STACKBOTTOM ((ptr_t) 0x7b033000) /* from /etc/conf/h/param.h */
  1081. # else
  1082. /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2 */
  1083. /* to this. We'll probably do this on other platforms, too. */
  1084. /* For now I'll use it where I can test it. */
  1085. extern char ** environ;
  1086. # define STACKBOTTOM ((ptr_t)environ)
  1087. # endif
  1088. # ifndef SCM_STACK_GROWS_UP /* don't fight with scmconfig.h */
  1089. # define SCM_STACK_GROWS_UP 1
  1090. # endif
  1091. # define DYNAMIC_LOADING
  1092. # ifndef HPUX_THREADS
  1093. # define MPROTECT_VDB
  1094. # endif
  1095. # include <unistd.h>
  1096. # define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
  1097. # endif
  1098. # ifdef ALPHA
  1099. # define MACH_TYPE "ALPHA"
  1100. # define ALIGNMENT 8
  1101. # define USE_GENERIC_PUSH_REGS
  1102. /* Gcc and probably the DEC/Compaq compiler spill pointers to preserved */
  1103. /* fp registers in some cases when the target is a 21264. The assembly */
  1104. /* code doesn't handle that yet, and version dependencies make that a */
  1105. /* bit tricky. Do the easy thing for now. */
  1106. # ifdef OSF1
  1107. # define OS_TYPE "OSF1"
  1108. # define DATASTART ((ptr_t) 0x140000000)
  1109. extern int _end;
  1110. # define DATAEND ((ptr_t) &_end)
  1111. # define HEURISTIC2
  1112. /* Normally HEURISTIC2 is too conervative, since */
  1113. /* the text segment immediately follows the stack. */
  1114. /* Hence we give an upper pound. */
  1115. extern int __start;
  1116. # define HEURISTIC2_LIMIT ((ptr_t)((word)(&__start) & ~(getpagesize()-1)))
  1117. # define CPP_WORDSZ 64
  1118. # define MPROTECT_VDB
  1119. # define DYNAMIC_LOADING
  1120. # endif
  1121. # ifdef LINUX
  1122. # define OS_TYPE "LINUX"
  1123. # define CPP_WORDSZ 64
  1124. # define STACKBOTTOM ((ptr_t) 0x120000000)
  1125. # ifdef __ELF__
  1126. # define LINUX_DATA_START
  1127. # define DYNAMIC_LOADING
  1128. /* This doesn't work if the collector is in a dynamic library. */
  1129. # else
  1130. # define DATASTART ((ptr_t) 0x140000000)
  1131. # endif
  1132. extern int _end;
  1133. # define DATAEND (&_end)
  1134. # define MPROTECT_VDB
  1135. /* Has only been superficially tested. May not */
  1136. /* work on all versions. */
  1137. # endif
  1138. # endif
  1139. # ifdef IA64
  1140. # define MACH_TYPE "IA64"
  1141. # define ALIGN_DOUBLE
  1142. /* Requires 16 byte alignment for malloc */
  1143. # define ALIGNMENT 8
  1144. # define USE_GENERIC_PUSH_REGS
  1145. /* We need to get preserved registers in addition to register windows. */
  1146. /* That's easiest to do with setjmp. */
  1147. # ifdef HPUX
  1148. --> needs work
  1149. # endif
  1150. # ifdef LINUX
  1151. # define OS_TYPE "LINUX"
  1152. # define CPP_WORDSZ 64
  1153. /* This should really be done through /proc, but that */
  1154. /* requires we run on an IA64 kernel. */
  1155. # define STACKBOTTOM ((ptr_t) 0xa000000000000000l)
  1156. /* We also need the base address of the register stack */
  1157. /* backing store. There is probably a better way to */
  1158. /* get that, too ... */
  1159. # define BACKING_STORE_BASE ((ptr_t) 0x9fffffff80000000l)
  1160. # if 1
  1161. # define SEARCH_FOR_DATA_START
  1162. # define DATASTART GC_data_start
  1163. # else
  1164. extern int data_start;
  1165. # define DATASTART ((ptr_t)(&data_start))
  1166. # endif
  1167. # define DYNAMIC_LOADING
  1168. # define MPROTECT_VDB
  1169. /* Requires Linux 2.3.47 or later. */
  1170. extern int _end;
  1171. # define DATAEND (&_end)
  1172. # define PREFETCH(x) \
  1173. __asm__ (" lfetch [%0]": : "r"((void *)(x)))
  1174. # define PREFETCH_FOR_WRITE(x) \
  1175. __asm__ (" lfetch.excl [%0]": : "r"((void *)(x)))
  1176. # define CLEAR_DOUBLE(x) \
  1177. __asm__ (" stf.spill [%0]=f0": : "r"((void *)(x)))
  1178. # endif
  1179. # endif
  1180. # ifdef M88K
  1181. # define MACH_TYPE "M88K"
  1182. # define ALIGNMENT 4
  1183. # define ALIGN_DOUBLE
  1184. extern int etext;
  1185. # ifdef CX_UX
  1186. # define OS_TYPE "CX_UX"
  1187. # define DATASTART ((((word)&etext + 0x3fffff) & ~0x3fffff) + 0x10000)
  1188. # endif
  1189. # ifdef DGUX
  1190. # define OS_TYPE "DGUX"
  1191. extern char * GC_SysVGetDataStart();
  1192. # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext)
  1193. # endif
  1194. # define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
  1195. # endif
  1196. # ifdef S370
  1197. # define MACH_TYPE "S370"
  1198. # define OS_TYPE "UTS4"
  1199. # define ALIGNMENT 4 /* Required by hardware */
  1200. extern int etext;
  1201. extern int _etext;
  1202. extern int _end;
  1203. extern char * GC_SysVGetDataStart();
  1204. # define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
  1205. # define DATAEND (&_end)
  1206. # define HEURISTIC2
  1207. # endif
  1208. # if defined(PJ)
  1209. # define ALIGNMENT 4
  1210. extern int _etext;
  1211. # define DATASTART ((ptr_t)(&_etext))
  1212. # define HEURISTIC1
  1213. # endif
  1214. # ifdef ARM32
  1215. # define CPP_WORDSZ 32
  1216. # define MACH_TYPE "ARM32"
  1217. # define ALIGNMENT 4
  1218. # ifdef NETBSD
  1219. # define OS_TYPE "NETBSD"
  1220. # define HEURISTIC2
  1221. extern char etext;
  1222. # define DATASTART ((ptr_t)(&etext))
  1223. # define USE_GENERIC_PUSH_REGS
  1224. # endif
  1225. # ifdef LINUX
  1226. # define OS_TYPE "LINUX"
  1227. # define HEURISTIC1
  1228. # undef STACK_GRAN
  1229. # define STACK_GRAN 0x10000000
  1230. # define USE_GENERIC_PUSH_REGS
  1231. # ifdef __ELF__
  1232. # define DYNAMIC_LOADING
  1233. # include <features.h>
  1234. # if defined(__GLIBC__) && __GLIBC__ >= 2
  1235. # define LINUX_DATA_START
  1236. # else
  1237. extern char **__environ;
  1238. # define DATASTART ((ptr_t)(&__environ))
  1239. /* hideous kludge: __environ is the first */
  1240. /* word in crt0.o, and delimits the start */
  1241. /* of the data segment, no matter which */
  1242. /* ld options were passed through. */
  1243. /* We could use _etext instead, but that */
  1244. /* would include .rodata, which may */
  1245. /* contain large read-only data tables */
  1246. /* that we'd rather not scan. */
  1247. # endif
  1248. extern int _end;
  1249. # define DATAEND (&_end)
  1250. # else
  1251. extern int etext;
  1252. # define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
  1253. # endif
  1254. # endif
  1255. #endif
  1256. #ifdef LINUX_DATA_START
  1257. /* Some Linux distributions arrange to define __data_start. Some */
  1258. /* define data_start as a weak symbol. The latter is technically */
  1259. /* broken, since the user program may define data_start, in which */
  1260. /* case we lose. Nonetheless, we try both, prefering __data_start. */
  1261. /* We assume gcc. */
  1262. # pragma weak __data_start
  1263. extern int __data_start;
  1264. # pragma weak data_start
  1265. extern int data_start;
  1266. # define DATASTART ((ptr_t)(&__data_start != 0? &__data_start : &data_start))
  1267. #endif
  1268. # if SCM_STACK_GROWS_UP
  1269. # define STACK_GROWS_DOWN 0
  1270. # else
  1271. # define STACK_GROWS_DOWN 1
  1272. #endif
  1273. # ifndef CPP_WORDSZ
  1274. # define CPP_WORDSZ 32
  1275. # endif
  1276. # ifndef OS_TYPE
  1277. # define OS_TYPE ""
  1278. # endif
  1279. # ifndef DATAEND
  1280. extern int end;
  1281. # define DATAEND (&end)
  1282. # endif
  1283. # if defined(SVR4) && !defined(GETPAGESIZE)
  1284. # include <unistd.h>
  1285. # define GETPAGESIZE() sysconf(_SC_PAGESIZE)
  1286. # endif
  1287. # ifndef GETPAGESIZE
  1288. # if defined(SUNOS5) || defined(IRIX5)
  1289. # include <unistd.h>
  1290. # endif
  1291. # define GETPAGESIZE() getpagesize()
  1292. # endif
  1293. # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
  1294. /* OS has SVR4 generic features. Probably others also qualify. */
  1295. # define SVR4
  1296. # endif
  1297. # if defined(SUNOS5) || defined(DRSNX)
  1298. /* OS has SUNOS5 style semi-undocumented interface to dynamic */
  1299. /* loader. */
  1300. # define SUNOS5DL
  1301. /* OS has SUNOS5 style signal handlers. */
  1302. # define SUNOS5SIGS
  1303. # endif
  1304. # if defined(HPUX)
  1305. # define SUNOS5SIGS
  1306. # endif
  1307. # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
  1308. -> bad word size
  1309. # endif
  1310. # ifdef PCR
  1311. # undef DYNAMIC_LOADING
  1312. # undef STACKBOTTOM
  1313. # undef HEURISTIC1
  1314. # undef HEURISTIC2
  1315. # undef PROC_VDB
  1316. # undef MPROTECT_VDB
  1317. # define PCR_VDB
  1318. # endif
  1319. # ifdef SRC_M3
  1320. /* Postponed for now. */
  1321. # undef PROC_VDB
  1322. # undef MPROTECT_VDB
  1323. # endif
  1324. # ifdef SMALL_CONFIG
  1325. /* Presumably not worth the space it takes. */
  1326. # undef PROC_VDB
  1327. # undef MPROTECT_VDB
  1328. # endif
  1329. # ifdef USE_MUNMAP
  1330. # undef MPROTECT_VDB /* Can't deal with address space holes. */
  1331. # endif
  1332. # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
  1333. # define DEFAULT_VDB
  1334. # endif
  1335. # ifndef PREFETCH
  1336. # define PREFETCH(x)
  1337. # define NO_PREFETCH
  1338. # endif
  1339. # ifndef PREFETCH_FOR_WRITE
  1340. # define PREFETCH_FOR_WRITE(x)
  1341. # define NO_PREFETCH_FOR_WRITE
  1342. # endif
  1343. # ifndef CACHE_LINE_SIZE
  1344. # define CACHE_LINE_SIZE 32 /* Wild guess */
  1345. # endif
  1346. # ifndef CLEAR_DOUBLE
  1347. # define CLEAR_DOUBLE(x) \
  1348. ((word*)x)[0] = 0; \
  1349. ((word*)x)[1] = 0;
  1350. # endif /* CLEAR_DOUBLE */
  1351. # if defined(_SOLARIS_PTHREADS) && !defined(SOLARIS_THREADS)
  1352. # define SOLARIS_THREADS
  1353. # endif
  1354. # if defined(IRIX_THREADS) && !defined(IRIX5)
  1355. --> inconsistent configuration
  1356. # endif
  1357. # if defined(IRIX_JDK_THREADS) && !defined(IRIX5)
  1358. --> inconsistent configuration
  1359. # endif
  1360. # if defined(LINUX_THREADS) && !defined(LINUX)
  1361. --> inconsistent configuration
  1362. # endif
  1363. # if defined(SOLARIS_THREADS) && !defined(SUNOS5)
  1364. --> inconsistent configuration
  1365. # endif
  1366. # if defined(HPUX_THREADS) && !defined(HPUX)
  1367. --> inconsistent configuration
  1368. # endif
  1369. # if defined(PCR) || defined(SRC_M3) || \
  1370. defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || \
  1371. defined(IRIX_THREADS) || defined(LINUX_THREADS) || \
  1372. defined(IRIX_JDK_THREADS) || defined(HPUX_THREADS)
  1373. # define THREADS
  1374. # endif
  1375. # if defined(HP_PA) || defined(M88K) || defined(POWERPC) \
  1376. || (defined(I386) && defined(OS2)) || defined(UTS4) || defined(LINT)
  1377. /* Use setjmp based hack to mark from callee-save registers. */
  1378. # define USE_GENERIC_PUSH_REGS
  1379. # endif
  1380. # if defined(SPARC) && !defined(LINUX)
  1381. # define SAVE_CALL_CHAIN
  1382. # define ASM_CLEAR_CODE /* Stack clearing is crucial, and we */
  1383. /* include assembly code to do it well. */
  1384. # endif
  1385. # if defined(LINUX) && !defined(POWERPC)
  1386. # if 0
  1387. # include <linux/version.h>
  1388. # if (LINUX_VERSION_CODE <= 0x10400)
  1389. /* Ugly hack to get struct sigcontext_struct definition. Required */
  1390. /* for some early 1.3.X releases. Will hopefully go away soon. */
  1391. /* in some later Linux releases, asm/sigcontext.h may have to */
  1392. /* be included instead. */
  1393. # define __KERNEL__
  1394. # include <asm/signal.h>
  1395. # undef __KERNEL__
  1396. # endif
  1397. # else
  1398. /* Kernels prior to 2.1.1 defined struct sigcontext_struct instead of */
  1399. /* struct sigcontext. libc6 (glibc2) uses "struct sigcontext" in */
  1400. /* prototypes, so we have to include the top-level sigcontext.h to */
  1401. /* make sure the former gets defined to be the latter if appropriate. */
  1402. # include <features.h>
  1403. # if 2 <= __GLIBC__
  1404. # if 2 == __GLIBC__ && 0 == __GLIBC_MINOR__
  1405. /* glibc 2.1 no longer has sigcontext.h. But signal.h */
  1406. /* has the right declaration for glibc 2.1. */
  1407. # include <sigcontext.h>
  1408. # endif /* 0 == __GLIBC_MINOR__ */
  1409. # else /* not 2 <= __GLIBC__ */
  1410. /* libc5 doesn't have <sigcontext.h>: go directly with the kernel */
  1411. /* one. Check LINUX_VERSION_CODE to see which we should reference. */
  1412. # include <asm/sigcontext.h>
  1413. # endif /* 2 <= __GLIBC__ */
  1414. # endif
  1415. # endif
  1416. # if !defined(OS2) && !defined(PCR) && !defined(AMIGA) && !defined(MACOS)
  1417. # include <sys/types.h>
  1418. # if !defined(MSWIN32) && !defined(SUNOS4)
  1419. # include <unistd.h>
  1420. # endif
  1421. # endif
  1422. # include <signal.h>
  1423. /* Blatantly OS dependent routines, except for those that are related */
  1424. /* to dynamic loading. */
  1425. # if !defined(THREADS) && !defined(STACKBOTTOM) && defined(HEURISTIC2)
  1426. # define NEED_FIND_LIMIT
  1427. # endif
  1428. # if defined(IRIX_THREADS) || defined(HPUX_THREADS)
  1429. # define NEED_FIND_LIMIT
  1430. # endif
  1431. # if (defined(SUNOS4) && defined(DYNAMIC_LOADING)) && !defined(PCR)
  1432. # define NEED_FIND_LIMIT
  1433. # endif
  1434. # if (defined(SVR4) || defined(AUX) || defined(DGUX)) && !defined(PCR)
  1435. # define NEED_FIND_LIMIT
  1436. # endif
  1437. # if defined(LINUX) && \
  1438. (defined(POWERPC) || defined(SPARC) || defined(ALPHA) || defined(IA64) \
  1439. || defined(MIPS))
  1440. # define NEED_FIND_LIMIT
  1441. # endif
  1442. #ifdef NEED_FIND_LIMIT
  1443. # include <setjmp.h>
  1444. #endif
  1445. #ifdef FREEBSD
  1446. # include <machine/trap.h>
  1447. #endif
  1448. #ifdef AMIGA
  1449. # include <proto/exec.h>
  1450. # include <proto/dos.h>
  1451. # include <dos/dosextens.h>
  1452. # include <workbench/startup.h>
  1453. #endif
  1454. #ifdef MSWIN32
  1455. # define WIN32_LEAN_AND_MEAN
  1456. # define NOSERVICE
  1457. # include <windows.h>
  1458. #endif
  1459. #ifdef MACOS
  1460. # include <Processes.h>
  1461. #endif
  1462. #ifdef IRIX5
  1463. # include <sys/uio.h>
  1464. # include <malloc.h> /* for locking */
  1465. #endif
  1466. #ifdef USE_MMAP
  1467. # include <sys/types.h>
  1468. # include <sys/mman.h>
  1469. # include <sys/stat.h>
  1470. # include <fcntl.h>
  1471. #endif
  1472. #ifdef SUNOS5SIGS
  1473. # include <sys/siginfo.h>
  1474. # undef setjmp
  1475. # undef longjmp
  1476. # define setjmp(env) sigsetjmp(env, 1)
  1477. # define longjmp(env, val) siglongjmp(env, val)
  1478. # define jmp_buf sigjmp_buf
  1479. #endif
  1480. #ifdef DJGPP
  1481. /* Apparently necessary for djgpp 2.01. May casuse problems with */
  1482. /* other versions. */
  1483. typedef long unsigned int caddr_t;
  1484. #endif
  1485. #ifdef PCR
  1486. # include "il/PCR_IL.h"
  1487. # include "th/PCR_ThCtl.h"
  1488. # include "mm/PCR_MM.h"
  1489. #endif
  1490. #if !defined(NO_EXECUTE_PERMISSION)
  1491. # define OPT_PROT_EXEC PROT_EXEC
  1492. #else
  1493. # define OPT_PROT_EXEC 0
  1494. #endif
  1495. # ifdef OS2
  1496. # include <stddef.h>
  1497. # if !defined(__IBMC__) && !defined(__WATCOMC__) /* e.g. EMX */
  1498. # else /* IBM's compiler */
  1499. /* A kludge to get around what appears to be a header file bug */
  1500. # ifndef WORD
  1501. # define WORD unsigned short
  1502. # endif
  1503. # ifndef DWORD
  1504. # define DWORD unsigned long
  1505. # endif
  1506. # define EXE386 1
  1507. # include <newexe.h>
  1508. # include <exe386.h>
  1509. # endif /* __IBMC__ */
  1510. # define INCL_DOSEXCEPTIONS
  1511. # define INCL_DOSPROCESS
  1512. # define INCL_DOSERRORS
  1513. # define INCL_DOSMODULEMGR
  1514. # define INCL_DOSMEMMGR
  1515. # include <os2.h>
  1516. # endif /*!OS/2 */
  1517. /*
  1518. * Find the base of the stack.
  1519. * Used only in single-threaded environment.
  1520. * With threads, GC_mark_roots needs to know how to do this.
  1521. * Called with allocator lock held.
  1522. */
  1523. # ifdef MSWIN32
  1524. # define is_writable(prot) ((prot) == PAGE_READWRITE \
  1525. || (prot) == PAGE_WRITECOPY \
  1526. || (prot) == PAGE_EXECUTE_READWRITE \
  1527. || (prot) == PAGE_EXECUTE_WRITECOPY)
  1528. /* Return the number of bytes that are writable starting at p. */
  1529. /* The pointer p is assumed to be page aligned. */
  1530. /* If base is not 0, *base becomes the beginning of the */
  1531. /* allocation region containing p. */
  1532. static word GC_get_writable_length(ptr_t p, ptr_t *base)
  1533. {
  1534. MEMORY_BASIC_INFORMATION buf;
  1535. word result;
  1536. word protect;
  1537. result = VirtualQuery(p, &buf, sizeof(buf));
  1538. if (result != sizeof(buf)) ABORT("Weird VirtualQuery result");
  1539. if (base != 0) *base = (ptr_t)(buf.AllocationBase);
  1540. protect = (buf.Protect & ~(PAGE_GUARD | PAGE_NOCACHE));
  1541. if (!is_writable(protect)) {
  1542. return(0);
  1543. }
  1544. if (buf.State != MEM_COMMIT) return(0);
  1545. return(buf.RegionSize);
  1546. }
  1547. void *scm_get_stack_base()
  1548. {
  1549. int dummy;
  1550. ptr_t sp = (ptr_t)(&dummy);
  1551. ptr_t trunc_sp;
  1552. word size;
  1553. static word GC_page_size = 0;
  1554. if (!GC_page_size) {
  1555. SYSTEM_INFO sysinfo;
  1556. GetSystemInfo(&sysinfo);
  1557. GC_page_size = sysinfo.dwPageSize;
  1558. }
  1559. trunc_sp = (ptr_t)((word)sp & ~(GC_page_size - 1));
  1560. size = GC_get_writable_length(trunc_sp, 0);
  1561. return(trunc_sp + size);
  1562. }
  1563. # else
  1564. # ifdef OS2
  1565. void *scm_get_stack_base()
  1566. {
  1567. PTIB ptib;
  1568. PPIB ppib;
  1569. if (DosGetInfoBlocks(&ptib, &ppib) != NO_ERROR) {
  1570. GC_err_printf0("DosGetInfoBlocks failed\n");
  1571. ABORT("DosGetInfoBlocks failed\n");
  1572. }
  1573. return((ptr_t)(ptib -> tib_pstacklimit));
  1574. }
  1575. # else
  1576. # ifdef AMIGA
  1577. void *scm_get_stack_base()
  1578. {
  1579. struct Process *proc = (struct Process*)SysBase->ThisTask;
  1580. /* Reference: Amiga Guru Book Pages: 42,567,574 */
  1581. if (proc->pr_Task.tc_Node.ln_Type==NT_PROCESS
  1582. && proc->pr_CLI != NULL) {
  1583. /* first ULONG is StackSize */
  1584. /*longPtr = proc->pr_ReturnAddr;
  1585. size = longPtr[0];*/
  1586. return (char *)proc->pr_ReturnAddr + sizeof(ULONG);
  1587. } else {
  1588. return (char *)proc->pr_Task.tc_SPUpper;
  1589. }
  1590. }
  1591. #if 0 /* old version */
  1592. void *scm_get_stack_base()
  1593. {
  1594. extern struct WBStartup *_WBenchMsg;
  1595. extern long __base;
  1596. extern long __stack;
  1597. struct Task *task;
  1598. struct Process *proc;
  1599. struct CommandLineInterface *cli;
  1600. long size;
  1601. if ((task = FindTask(0)) == 0) {
  1602. GC_err_puts("Cannot find own task structure\n");
  1603. ABORT("task missing");
  1604. }
  1605. proc = (struct Process *)task;
  1606. cli = BADDR(proc->pr_CLI);
  1607. if (_WBenchMsg != 0 || cli == 0) {
  1608. size = (char *)task->tc_SPUpper - (char *)task->tc_SPLower;
  1609. } else {
  1610. size = cli->cli_DefaultStack * 4;
  1611. }
  1612. return (ptr_t)(__base + GC_max(size, __stack));
  1613. }
  1614. #endif /* 0 */
  1615. # else /* !AMIGA, !OS2, ... */
  1616. # ifdef NEED_FIND_LIMIT
  1617. /* Some tools to implement HEURISTIC2 */
  1618. # define MIN_PAGE_SIZE 256 /* Smallest conceivable page size, bytes */
  1619. /* static */ jmp_buf GC_jmp_buf;
  1620. /*ARGSUSED*/
  1621. static void GC_fault_handler(sig)
  1622. int sig;
  1623. {
  1624. longjmp(GC_jmp_buf, 1);
  1625. }
  1626. # ifdef __STDC__
  1627. typedef void (*handler)(int);
  1628. # else
  1629. typedef void (*handler)();
  1630. # endif
  1631. # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1)
  1632. static struct sigaction old_segv_act;
  1633. # if defined(_sigargs) || defined(HPUX) /* !Irix6.x */
  1634. static struct sigaction old_bus_act;
  1635. # endif
  1636. # else
  1637. static handler old_segv_handler, old_bus_handler;
  1638. # endif
  1639. static void GC_setup_temporary_fault_handler()
  1640. {
  1641. # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1)
  1642. struct sigaction act;
  1643. act.sa_handler = GC_fault_handler;
  1644. act.sa_flags = SA_RESTART | SA_NODEFER;
  1645. /* The presence of SA_NODEFER represents yet another gross */
  1646. /* hack. Under Solaris 2.3, siglongjmp doesn't appear to */
  1647. /* interact correctly with -lthread. We hide the confusion */
  1648. /* by making sure that signal handling doesn't affect the */
  1649. /* signal mask. */
  1650. (void) sigemptyset(&act.sa_mask);
  1651. # ifdef IRIX_THREADS
  1652. /* Older versions have a bug related to retrieving and */
  1653. /* and setting a handler at the same time. */
  1654. (void) sigaction(SIGSEGV, 0, &old_segv_act);
  1655. (void) sigaction(SIGSEGV, &act, 0);
  1656. # else
  1657. (void) sigaction(SIGSEGV, &act, &old_segv_act);
  1658. # if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \
  1659. || defined(HPUX)
  1660. /* Under Irix 5.x or HP/UX, we may get SIGBUS. */
  1661. /* Pthreads doesn't exist under Irix 5.x, so we */
  1662. /* don't have to worry in the threads case. */
  1663. (void) sigaction(SIGBUS, &act, &old_bus_act);
  1664. # endif
  1665. # endif /* IRIX_THREADS */
  1666. # else
  1667. old_segv_handler = signal(SIGSEGV, GC_fault_handler);
  1668. # ifdef SIGBUS
  1669. old_bus_handler = signal(SIGBUS, GC_fault_handler);
  1670. # endif
  1671. # endif
  1672. }
  1673. static void GC_reset_fault_handler()
  1674. {
  1675. # if defined(SUNOS5SIGS) || defined(IRIX5) || defined(OSF1)
  1676. (void) sigaction(SIGSEGV, &old_segv_act, 0);
  1677. # if defined(IRIX5) && defined(_sigargs) /* Irix 5.x, not 6.x */ \
  1678. || defined(HPUX)
  1679. (void) sigaction(SIGBUS, &old_bus_act, 0);
  1680. # endif
  1681. # else
  1682. (void) signal(SIGSEGV, old_segv_handler);
  1683. # ifdef SIGBUS
  1684. (void) signal(SIGBUS, old_bus_handler);
  1685. # endif
  1686. # endif
  1687. }
  1688. /* Single argument version, robust against whole program analysis. */
  1689. static void
  1690. GC_noop1(x)
  1691. word x;
  1692. {
  1693. static VOLATILE word sink;
  1694. sink = x;
  1695. }
  1696. /* Return the first nonaddressible location > p (up) or */
  1697. /* the smallest location q s.t. [q,p] is addressible (!up). */
  1698. static ptr_t GC_find_limit(p, up)
  1699. ptr_t p;
  1700. GC_bool up;
  1701. {
  1702. static VOLATILE ptr_t result;
  1703. /* Needs to be static, since otherwise it may not be */
  1704. /* preserved across the longjmp. Can safely be */
  1705. /* static since it's only called once, with the */
  1706. /* allocation lock held. */
  1707. GC_setup_temporary_fault_handler();
  1708. if (setjmp(GC_jmp_buf) == 0) {
  1709. result = (ptr_t)(((word)(p))
  1710. & ~(MIN_PAGE_SIZE-1));
  1711. for (;;) {
  1712. if (up) {
  1713. result += MIN_PAGE_SIZE;
  1714. } else {
  1715. result -= MIN_PAGE_SIZE;
  1716. }
  1717. GC_noop1((word)(*result));
  1718. }
  1719. }
  1720. GC_reset_fault_handler();
  1721. if (!up) {
  1722. result += MIN_PAGE_SIZE;
  1723. }
  1724. return(result);
  1725. }
  1726. # endif
  1727. #ifdef LINUX_STACKBOTTOM
  1728. #include <sys/types.h>
  1729. #include <sys/stat.h>
  1730. #include <fcntl.h>
  1731. # define STAT_SKIP 27 /* Number of fields preceding startstack */
  1732. /* field in /proc/self/stat */
  1733. static ptr_t GC_linux_stack_base(void)
  1734. {
  1735. /* We read the stack base value from /proc/self/stat. We do this */
  1736. /* using direct I/O system calls in order to avoid calling malloc */
  1737. /* in case REDIRECT_MALLOC is defined. */
  1738. # define STAT_BUF_SIZE 4096
  1739. # ifdef USE_LD_WRAP
  1740. # define STAT_READ __real_read
  1741. # else
  1742. # define STAT_READ read
  1743. # endif
  1744. char stat_buf[STAT_BUF_SIZE];
  1745. int f;
  1746. char c;
  1747. word result = 0;
  1748. size_t i, buf_offset = 0;
  1749. f = open("/proc/self/stat", O_RDONLY);
  1750. if (f < 0 || STAT_READ(f, stat_buf, STAT_BUF_SIZE) < 2 * STAT_SKIP) {
  1751. ABORT("Couldn't read /proc/self/stat");
  1752. }
  1753. c = stat_buf[buf_offset++];
  1754. /* Skip the required number of fields. This number is hopefully */
  1755. /* constant across all Linux implementations. */
  1756. for (i = 0; i < STAT_SKIP; ++i) {
  1757. while (isspace(c)) c = stat_buf[buf_offset++];
  1758. while (!isspace(c)) c = stat_buf[buf_offset++];
  1759. }
  1760. while (isspace(c)) c = stat_buf[buf_offset++];
  1761. while (isdigit(c)) {
  1762. result *= 10;
  1763. result += c - '0';
  1764. c = stat_buf[buf_offset++];
  1765. }
  1766. close(f);
  1767. if (result < 0x10000000) ABORT("Absurd stack bottom value");
  1768. return (ptr_t)result;
  1769. }
  1770. #endif /* LINUX_STACKBOTTOM */
  1771. void *scm_get_stack_base()
  1772. {
  1773. word dummy;
  1774. void *result;
  1775. result = &dummy; /* initialize to silence compiler */
  1776. # define STACKBOTTOM_ALIGNMENT_M1 ((word)STACK_GRAN - 1)
  1777. # ifdef STACKBOTTOM
  1778. return(STACKBOTTOM);
  1779. # else
  1780. # ifdef HEURISTIC1
  1781. # if STACK_GROWS_DOWN
  1782. result = (ptr_t)((((word)(&dummy))
  1783. + STACKBOTTOM_ALIGNMENT_M1)
  1784. & ~STACKBOTTOM_ALIGNMENT_M1);
  1785. # else
  1786. result = (ptr_t)(((word)(&dummy))
  1787. & ~STACKBOTTOM_ALIGNMENT_M1);
  1788. # endif
  1789. # endif /* HEURISTIC1 */
  1790. # ifdef LINUX_STACKBOTTOM
  1791. result = GC_linux_stack_base();
  1792. # endif
  1793. # ifdef HEURISTIC2
  1794. # if STACK_GROWS_DOWN
  1795. result = GC_find_limit((ptr_t)(&dummy), TRUE);
  1796. # ifdef HEURISTIC2_LIMIT
  1797. if ((ptr_t)result > HEURISTIC2_LIMIT
  1798. && (ptr_t)(&dummy) < HEURISTIC2_LIMIT) {
  1799. result = HEURISTIC2_LIMIT;
  1800. }
  1801. # endif
  1802. # else
  1803. result = GC_find_limit((ptr_t)(&dummy), FALSE);
  1804. # ifdef HEURISTIC2_LIMIT
  1805. if (result < HEURISTIC2_LIMIT
  1806. && (ptr_t)(&dummy) > HEURISTIC2_LIMIT) {
  1807. result = HEURISTIC2_LIMIT;
  1808. }
  1809. # endif
  1810. # endif
  1811. # endif /* HEURISTIC2 */
  1812. # if STACK_GROWS_DOWN
  1813. if (result == 0) result = (ptr_t)(signed_word)(-sizeof(ptr_t));
  1814. # endif
  1815. return(result);
  1816. # endif /* STACKBOTTOM */
  1817. }
  1818. # endif /* ! AMIGA */
  1819. # endif /* ! OS2 */
  1820. # endif /* ! MSWIN32 */
  1821. #endif /* mach_type_known */
  1822. #endif /* ! HAVE_LIBC_STACK_END */