dbg_mlc.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. /*
  2. * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  3. * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved.
  4. * Copyright (c) 1997 by Silicon Graphics. All rights reserved.
  5. * Copyright (c) 1999-2004 Hewlett-Packard Development Company, L.P.
  6. * Copyright (C) 2007 Free Software Foundation, Inc
  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. #include "private/dbg_mlc.h"
  18. void GC_default_print_heap_obj_proc();
  19. GC_API void GC_register_finalizer_no_order
  20. GC_PROTO((GC_PTR obj, GC_finalization_proc fn, GC_PTR cd,
  21. GC_finalization_proc *ofn, GC_PTR *ocd));
  22. #ifndef SHORT_DBG_HDRS
  23. /* Check whether object with base pointer p has debugging info */
  24. /* p is assumed to point to a legitimate object in our part */
  25. /* of the heap. */
  26. /* This excludes the check as to whether the back pointer is */
  27. /* odd, which is added by the GC_HAS_DEBUG_INFO macro. */
  28. /* Note that if DBG_HDRS_ALL is set, uncollectable objects */
  29. /* on free lists may not have debug information set. Thus it's */
  30. /* not always safe to return TRUE, even if the client does */
  31. /* its part. */
  32. GC_bool GC_has_other_debug_info(p)
  33. ptr_t p;
  34. {
  35. register oh * ohdr = (oh *)p;
  36. register ptr_t body = (ptr_t)(ohdr + 1);
  37. register word sz = GC_size((ptr_t) ohdr);
  38. if (HBLKPTR((ptr_t)ohdr) != HBLKPTR((ptr_t)body)
  39. || sz < DEBUG_BYTES + EXTRA_BYTES) {
  40. return(FALSE);
  41. }
  42. if (ohdr -> oh_sz == sz) {
  43. /* Object may have had debug info, but has been deallocated */
  44. return(FALSE);
  45. }
  46. if (ohdr -> oh_sf == (START_FLAG ^ (word)body)) return(TRUE);
  47. if (((word *)ohdr)[BYTES_TO_WORDS(sz)-1] == (END_FLAG ^ (word)body)) {
  48. return(TRUE);
  49. }
  50. return(FALSE);
  51. }
  52. #endif
  53. #ifdef KEEP_BACK_PTRS
  54. # include <stdlib.h>
  55. # if defined(LINUX) || defined(SUNOS4) || defined(SUNOS5) \
  56. || defined(HPUX) || defined(IRIX5) || defined(OSF1)
  57. # define RANDOM() random()
  58. # else
  59. # define RANDOM() (long)rand()
  60. # endif
  61. /* Store back pointer to source in dest, if that appears to be possible. */
  62. /* This is not completely safe, since we may mistakenly conclude that */
  63. /* dest has a debugging wrapper. But the error probability is very */
  64. /* small, and this shouldn't be used in production code. */
  65. /* We assume that dest is the real base pointer. Source will usually */
  66. /* be a pointer to the interior of an object. */
  67. void GC_store_back_pointer(ptr_t source, ptr_t dest)
  68. {
  69. if (GC_HAS_DEBUG_INFO(dest)) {
  70. ((oh *)dest) -> oh_back_ptr = HIDE_BACK_PTR(source);
  71. }
  72. }
  73. void GC_marked_for_finalization(ptr_t dest) {
  74. GC_store_back_pointer(MARKED_FOR_FINALIZATION, dest);
  75. }
  76. /* Store information about the object referencing dest in *base_p */
  77. /* and *offset_p. */
  78. /* source is root ==> *base_p = address, *offset_p = 0 */
  79. /* source is heap object ==> *base_p != 0, *offset_p = offset */
  80. /* Returns 1 on success, 0 if source couldn't be determined. */
  81. /* Dest can be any address within a heap object. */
  82. GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p)
  83. {
  84. oh * hdr = (oh *)GC_base(dest);
  85. ptr_t bp;
  86. ptr_t bp_base;
  87. if (!GC_HAS_DEBUG_INFO((ptr_t) hdr)) return GC_NO_SPACE;
  88. bp = REVEAL_POINTER(hdr -> oh_back_ptr);
  89. if (MARKED_FOR_FINALIZATION == bp) return GC_FINALIZER_REFD;
  90. if (MARKED_FROM_REGISTER == bp) return GC_REFD_FROM_REG;
  91. if (NOT_MARKED == bp) return GC_UNREFERENCED;
  92. # if ALIGNMENT == 1
  93. /* Heuristically try to fix off by 1 errors we introduced by */
  94. /* insisting on even addresses. */
  95. {
  96. ptr_t alternate_ptr = bp + 1;
  97. ptr_t target = *(ptr_t *)bp;
  98. ptr_t alternate_target = *(ptr_t *)alternate_ptr;
  99. if (alternate_target >= GC_least_plausible_heap_addr
  100. && alternate_target <= GC_greatest_plausible_heap_addr
  101. && (target < GC_least_plausible_heap_addr
  102. || target > GC_greatest_plausible_heap_addr)) {
  103. bp = alternate_ptr;
  104. }
  105. }
  106. # endif
  107. bp_base = GC_base(bp);
  108. if (0 == bp_base) {
  109. *base_p = bp;
  110. *offset_p = 0;
  111. return GC_REFD_FROM_ROOT;
  112. } else {
  113. if (GC_HAS_DEBUG_INFO(bp_base)) bp_base += sizeof(oh);
  114. *base_p = bp_base;
  115. *offset_p = bp - bp_base;
  116. return GC_REFD_FROM_HEAP;
  117. }
  118. }
  119. /* Generate a random heap address. */
  120. /* The resulting address is in the heap, but */
  121. /* not necessarily inside a valid object. */
  122. void *GC_generate_random_heap_address(void)
  123. {
  124. int i;
  125. long heap_offset = RANDOM();
  126. if (GC_heapsize > RAND_MAX) {
  127. heap_offset *= RAND_MAX;
  128. heap_offset += RANDOM();
  129. }
  130. heap_offset %= GC_heapsize;
  131. /* This doesn't yield a uniform distribution, especially if */
  132. /* e.g. RAND_MAX = 1.5* GC_heapsize. But for typical cases, */
  133. /* it's not too bad. */
  134. for (i = 0; i < GC_n_heap_sects; ++ i) {
  135. int size = GC_heap_sects[i].hs_bytes;
  136. if (heap_offset < size) {
  137. return GC_heap_sects[i].hs_start + heap_offset;
  138. } else {
  139. heap_offset -= size;
  140. }
  141. }
  142. ABORT("GC_generate_random_heap_address: size inconsistency");
  143. /*NOTREACHED*/
  144. return 0;
  145. }
  146. /* Generate a random address inside a valid marked heap object. */
  147. void *GC_generate_random_valid_address(void)
  148. {
  149. ptr_t result;
  150. ptr_t base;
  151. for (;;) {
  152. result = GC_generate_random_heap_address();
  153. base = GC_base(result);
  154. if (0 == base) continue;
  155. if (!GC_is_marked(base)) continue;
  156. return result;
  157. }
  158. }
  159. /* Print back trace for p */
  160. void GC_print_backtrace(void *p)
  161. {
  162. void *current = p;
  163. int i;
  164. GC_ref_kind source;
  165. size_t offset;
  166. void *base;
  167. GC_print_heap_obj(GC_base(current));
  168. GC_err_printf0("\n");
  169. for (i = 0; ; ++i) {
  170. source = GC_get_back_ptr_info(current, &base, &offset);
  171. if (GC_UNREFERENCED == source) {
  172. GC_err_printf0("Reference could not be found\n");
  173. goto out;
  174. }
  175. if (GC_NO_SPACE == source) {
  176. GC_err_printf0("No debug info in object: Can't find reference\n");
  177. goto out;
  178. }
  179. GC_err_printf1("Reachable via %d levels of pointers from ",
  180. (unsigned long)i);
  181. switch(source) {
  182. case GC_REFD_FROM_ROOT:
  183. GC_err_printf1("root at 0x%lx\n\n", (unsigned long)base);
  184. goto out;
  185. case GC_REFD_FROM_REG:
  186. GC_err_printf0("root in register\n\n");
  187. goto out;
  188. case GC_FINALIZER_REFD:
  189. GC_err_printf0("list of finalizable objects\n\n");
  190. goto out;
  191. case GC_REFD_FROM_HEAP:
  192. GC_err_printf1("offset %ld in object:\n", (unsigned long)offset);
  193. /* Take GC_base(base) to get real base, i.e. header. */
  194. GC_print_heap_obj(GC_base(base));
  195. GC_err_printf0("\n");
  196. break;
  197. }
  198. current = base;
  199. }
  200. out:;
  201. }
  202. /* Force a garbage collection and generate a backtrace from a */
  203. /* random heap address. */
  204. void GC_generate_random_backtrace_no_gc(void)
  205. {
  206. void * current;
  207. current = GC_generate_random_valid_address();
  208. GC_printf1("\n****Chose address 0x%lx in object\n", (unsigned long)current);
  209. GC_print_backtrace(current);
  210. }
  211. void GC_generate_random_backtrace(void)
  212. {
  213. GC_gcollect();
  214. GC_generate_random_backtrace_no_gc();
  215. }
  216. #endif /* KEEP_BACK_PTRS */
  217. # define CROSSES_HBLK(p, sz) \
  218. (((word)(p + sizeof(oh) + sz - 1) ^ (word)p) >= HBLKSIZE)
  219. /* Store debugging info into p. Return displaced pointer. */
  220. /* Assumes we don't hold allocation lock. */
  221. ptr_t GC_store_debug_info(p, sz, string, integer)
  222. register ptr_t p; /* base pointer */
  223. word sz; /* bytes */
  224. GC_CONST char * string;
  225. word integer;
  226. {
  227. register word * result = (word *)((oh *)p + 1);
  228. DCL_LOCK_STATE;
  229. /* There is some argument that we should dissble signals here. */
  230. /* But that's expensive. And this way things should only appear */
  231. /* inconsistent while we're in the handler. */
  232. LOCK();
  233. GC_ASSERT(GC_size(p) >= sizeof(oh) + sz);
  234. GC_ASSERT(!(SMALL_OBJ(sz) && CROSSES_HBLK(p, sz)));
  235. # ifdef KEEP_BACK_PTRS
  236. ((oh *)p) -> oh_back_ptr = HIDE_BACK_PTR(NOT_MARKED);
  237. # endif
  238. # ifdef MAKE_BACK_GRAPH
  239. ((oh *)p) -> oh_bg_ptr = HIDE_BACK_PTR((ptr_t)0);
  240. # endif
  241. ((oh *)p) -> oh_string = string;
  242. ((oh *)p) -> oh_int = integer;
  243. # ifndef SHORT_DBG_HDRS
  244. ((oh *)p) -> oh_sz = sz;
  245. ((oh *)p) -> oh_sf = START_FLAG ^ (word)result;
  246. ((word *)p)[BYTES_TO_WORDS(GC_size(p))-1] =
  247. result[SIMPLE_ROUNDED_UP_WORDS(sz)] = END_FLAG ^ (word)result;
  248. # endif
  249. UNLOCK();
  250. return((ptr_t)result);
  251. }
  252. #ifdef DBG_HDRS_ALL
  253. /* Store debugging info into p. Return displaced pointer. */
  254. /* This version assumes we do hold the allocation lock. */
  255. ptr_t GC_store_debug_info_inner(p, sz, string, integer)
  256. register ptr_t p; /* base pointer */
  257. word sz; /* bytes */
  258. char * string;
  259. word integer;
  260. {
  261. register word * result = (word *)((oh *)p + 1);
  262. /* There is some argument that we should disable signals here. */
  263. /* But that's expensive. And this way things should only appear */
  264. /* inconsistent while we're in the handler. */
  265. GC_ASSERT(GC_size(p) >= sizeof(oh) + sz);
  266. GC_ASSERT(!(SMALL_OBJ(sz) && CROSSES_HBLK(p, sz)));
  267. # ifdef KEEP_BACK_PTRS
  268. ((oh *)p) -> oh_back_ptr = HIDE_BACK_PTR(NOT_MARKED);
  269. # endif
  270. # ifdef MAKE_BACK_GRAPH
  271. ((oh *)p) -> oh_bg_ptr = HIDE_BACK_PTR((ptr_t)0);
  272. # endif
  273. ((oh *)p) -> oh_string = string;
  274. ((oh *)p) -> oh_int = integer;
  275. # ifndef SHORT_DBG_HDRS
  276. ((oh *)p) -> oh_sz = sz;
  277. ((oh *)p) -> oh_sf = START_FLAG ^ (word)result;
  278. ((word *)p)[BYTES_TO_WORDS(GC_size(p))-1] =
  279. result[SIMPLE_ROUNDED_UP_WORDS(sz)] = END_FLAG ^ (word)result;
  280. # endif
  281. return((ptr_t)result);
  282. }
  283. #endif
  284. #ifndef SHORT_DBG_HDRS
  285. /* Check the object with debugging info at ohdr */
  286. /* return NIL if it's OK. Else return clobbered */
  287. /* address. */
  288. ptr_t GC_check_annotated_obj(ohdr)
  289. register oh * ohdr;
  290. {
  291. register ptr_t body = (ptr_t)(ohdr + 1);
  292. register word gc_sz = GC_size((ptr_t)ohdr);
  293. if (ohdr -> oh_sz + DEBUG_BYTES > gc_sz) {
  294. return((ptr_t)(&(ohdr -> oh_sz)));
  295. }
  296. if (ohdr -> oh_sf != (START_FLAG ^ (word)body)) {
  297. return((ptr_t)(&(ohdr -> oh_sf)));
  298. }
  299. if (((word *)ohdr)[BYTES_TO_WORDS(gc_sz)-1] != (END_FLAG ^ (word)body)) {
  300. return((ptr_t)((word *)ohdr + BYTES_TO_WORDS(gc_sz)-1));
  301. }
  302. if (((word *)body)[SIMPLE_ROUNDED_UP_WORDS(ohdr -> oh_sz)]
  303. != (END_FLAG ^ (word)body)) {
  304. return((ptr_t)((word *)body + SIMPLE_ROUNDED_UP_WORDS(ohdr -> oh_sz)));
  305. }
  306. return(0);
  307. }
  308. #endif /* !SHORT_DBG_HDRS */
  309. static GC_describe_type_fn GC_describe_type_fns[MAXOBJKINDS] = {0};
  310. void GC_register_describe_type_fn(kind, fn)
  311. int kind;
  312. GC_describe_type_fn fn;
  313. {
  314. GC_describe_type_fns[kind] = fn;
  315. }
  316. /* Print a type description for the object whose client-visible address */
  317. /* is p. */
  318. void GC_print_type(p)
  319. ptr_t p;
  320. {
  321. hdr * hhdr = GC_find_header(p);
  322. char buffer[GC_TYPE_DESCR_LEN + 1];
  323. int kind = hhdr -> hb_obj_kind;
  324. if (0 != GC_describe_type_fns[kind] && GC_is_marked(GC_base(p))) {
  325. /* This should preclude free list objects except with */
  326. /* thread-local allocation. */
  327. buffer[GC_TYPE_DESCR_LEN] = 0;
  328. (GC_describe_type_fns[kind])(p, buffer);
  329. GC_ASSERT(buffer[GC_TYPE_DESCR_LEN] == 0);
  330. GC_err_puts(buffer);
  331. } else {
  332. switch(kind) {
  333. case PTRFREE:
  334. GC_err_puts("PTRFREE");
  335. break;
  336. case NORMAL:
  337. GC_err_puts("NORMAL");
  338. break;
  339. case UNCOLLECTABLE:
  340. GC_err_puts("UNCOLLECTABLE");
  341. break;
  342. # ifdef ATOMIC_UNCOLLECTABLE
  343. case AUNCOLLECTABLE:
  344. GC_err_puts("ATOMIC UNCOLLECTABLE");
  345. break;
  346. # endif
  347. case STUBBORN:
  348. GC_err_puts("STUBBORN");
  349. break;
  350. default:
  351. GC_err_printf2("kind %ld, descr 0x%lx", kind, hhdr -> hb_descr);
  352. }
  353. }
  354. }
  355. void GC_print_obj(p)
  356. ptr_t p;
  357. {
  358. register oh * ohdr = (oh *)GC_base(p);
  359. GC_ASSERT(!I_HOLD_LOCK());
  360. GC_err_printf1("0x%lx (", ((unsigned long)ohdr + sizeof(oh)));
  361. GC_err_puts(ohdr -> oh_string);
  362. # ifdef SHORT_DBG_HDRS
  363. GC_err_printf1(":%ld, ", (unsigned long)(ohdr -> oh_int));
  364. # else
  365. GC_err_printf2(":%ld, sz=%ld, ", (unsigned long)(ohdr -> oh_int),
  366. (unsigned long)(ohdr -> oh_sz));
  367. # endif
  368. GC_print_type((ptr_t)(ohdr + 1));
  369. GC_err_puts(")\n");
  370. PRINT_CALL_CHAIN(ohdr);
  371. }
  372. # if defined(__STDC__) || defined(__cplusplus)
  373. void GC_debug_print_heap_obj_proc(ptr_t p)
  374. # else
  375. void GC_debug_print_heap_obj_proc(p)
  376. ptr_t p;
  377. # endif
  378. {
  379. GC_ASSERT(!I_HOLD_LOCK());
  380. if (GC_HAS_DEBUG_INFO(p)) {
  381. GC_print_obj(p);
  382. } else {
  383. GC_default_print_heap_obj_proc(p);
  384. }
  385. }
  386. #ifndef SHORT_DBG_HDRS
  387. void GC_print_smashed_obj(p, clobbered_addr)
  388. ptr_t p, clobbered_addr;
  389. {
  390. register oh * ohdr = (oh *)GC_base(p);
  391. GC_ASSERT(!I_HOLD_LOCK());
  392. GC_err_printf2("0x%lx in object at 0x%lx(", (unsigned long)clobbered_addr,
  393. (unsigned long)p);
  394. if (clobbered_addr <= (ptr_t)(&(ohdr -> oh_sz))
  395. || ohdr -> oh_string == 0) {
  396. GC_err_printf1("<smashed>, appr. sz = %ld)\n",
  397. (GC_size((ptr_t)ohdr) - DEBUG_BYTES));
  398. } else {
  399. if (ohdr -> oh_string[0] == '\0') {
  400. GC_err_puts("EMPTY(smashed?)");
  401. } else {
  402. GC_err_puts(ohdr -> oh_string);
  403. }
  404. GC_err_printf2(":%ld, sz=%ld)\n", (unsigned long)(ohdr -> oh_int),
  405. (unsigned long)(ohdr -> oh_sz));
  406. PRINT_CALL_CHAIN(ohdr);
  407. }
  408. }
  409. #endif
  410. void GC_check_heap_proc GC_PROTO((void));
  411. void GC_print_all_smashed_proc GC_PROTO((void));
  412. void GC_do_nothing() {}
  413. void GC_start_debugging()
  414. {
  415. # ifndef SHORT_DBG_HDRS
  416. GC_check_heap = GC_check_heap_proc;
  417. GC_print_all_smashed = GC_print_all_smashed_proc;
  418. # else
  419. GC_check_heap = GC_do_nothing;
  420. GC_print_all_smashed = GC_do_nothing;
  421. # endif
  422. GC_print_heap_obj = GC_debug_print_heap_obj_proc;
  423. GC_debugging_started = TRUE;
  424. GC_register_displacement((word)sizeof(oh));
  425. }
  426. size_t GC_debug_header_size = sizeof(oh);
  427. # if defined(__STDC__) || defined(__cplusplus)
  428. void GC_debug_register_displacement(GC_word offset)
  429. # else
  430. void GC_debug_register_displacement(offset)
  431. GC_word offset;
  432. # endif
  433. {
  434. GC_register_displacement(offset);
  435. GC_register_displacement((word)sizeof(oh) + offset);
  436. }
  437. # ifdef __STDC__
  438. GC_PTR GC_debug_malloc(size_t lb, GC_EXTRA_PARAMS)
  439. # else
  440. GC_PTR GC_debug_malloc(lb, s, i)
  441. size_t lb;
  442. char * s;
  443. int i;
  444. # ifdef GC_ADD_CALLER
  445. --> GC_ADD_CALLER not implemented for K&R C
  446. # endif
  447. # endif
  448. {
  449. GC_PTR result = GC_malloc(lb + DEBUG_BYTES);
  450. if (result == 0) {
  451. GC_err_printf1("GC_debug_malloc(%ld) returning NIL (",
  452. (unsigned long) lb);
  453. GC_err_puts(s);
  454. GC_err_printf1(":%ld)\n", (unsigned long)i);
  455. return(0);
  456. }
  457. if (!GC_debugging_started) {
  458. GC_start_debugging();
  459. }
  460. ADD_CALL_CHAIN(result, ra);
  461. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  462. }
  463. # ifdef __STDC__
  464. GC_PTR GC_debug_malloc_ignore_off_page(size_t lb, GC_EXTRA_PARAMS)
  465. # else
  466. GC_PTR GC_debug_malloc_ignore_off_page(lb, s, i)
  467. size_t lb;
  468. char * s;
  469. int i;
  470. # ifdef GC_ADD_CALLER
  471. --> GC_ADD_CALLER not implemented for K&R C
  472. # endif
  473. # endif
  474. {
  475. GC_PTR result = GC_malloc_ignore_off_page(lb + DEBUG_BYTES);
  476. if (result == 0) {
  477. GC_err_printf1("GC_debug_malloc_ignore_off_page(%ld) returning NIL (",
  478. (unsigned long) lb);
  479. GC_err_puts(s);
  480. GC_err_printf1(":%ld)\n", (unsigned long)i);
  481. return(0);
  482. }
  483. if (!GC_debugging_started) {
  484. GC_start_debugging();
  485. }
  486. ADD_CALL_CHAIN(result, ra);
  487. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  488. }
  489. # ifdef __STDC__
  490. GC_PTR GC_debug_malloc_atomic_ignore_off_page(size_t lb, GC_EXTRA_PARAMS)
  491. # else
  492. GC_PTR GC_debug_malloc_atomic_ignore_off_page(lb, s, i)
  493. size_t lb;
  494. char * s;
  495. int i;
  496. # ifdef GC_ADD_CALLER
  497. --> GC_ADD_CALLER not implemented for K&R C
  498. # endif
  499. # endif
  500. {
  501. GC_PTR result = GC_malloc_atomic_ignore_off_page(lb + DEBUG_BYTES);
  502. if (result == 0) {
  503. GC_err_printf1("GC_debug_malloc_atomic_ignore_off_page(%ld)"
  504. " returning NIL (", (unsigned long) lb);
  505. GC_err_puts(s);
  506. GC_err_printf1(":%ld)\n", (unsigned long)i);
  507. return(0);
  508. }
  509. if (!GC_debugging_started) {
  510. GC_start_debugging();
  511. }
  512. ADD_CALL_CHAIN(result, ra);
  513. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  514. }
  515. # ifdef DBG_HDRS_ALL
  516. /*
  517. * An allocation function for internal use.
  518. * Normally internally allocated objects do not have debug information.
  519. * But in this case, we need to make sure that all objects have debug
  520. * headers.
  521. * We assume debugging was started in collector initialization,
  522. * and we already hold the GC lock.
  523. */
  524. GC_PTR GC_debug_generic_malloc_inner(size_t lb, int k)
  525. {
  526. GC_PTR result = GC_generic_malloc_inner(lb + DEBUG_BYTES, k);
  527. if (result == 0) {
  528. GC_err_printf1("GC internal allocation (%ld bytes) returning NIL\n",
  529. (unsigned long) lb);
  530. return(0);
  531. }
  532. ADD_CALL_CHAIN(result, GC_RETURN_ADDR);
  533. return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", (word)0));
  534. }
  535. GC_PTR GC_debug_generic_malloc_inner_ignore_off_page(size_t lb, int k)
  536. {
  537. GC_PTR result = GC_generic_malloc_inner_ignore_off_page(
  538. lb + DEBUG_BYTES, k);
  539. if (result == 0) {
  540. GC_err_printf1("GC internal allocation (%ld bytes) returning NIL\n",
  541. (unsigned long) lb);
  542. return(0);
  543. }
  544. ADD_CALL_CHAIN(result, GC_RETURN_ADDR);
  545. return (GC_store_debug_info_inner(result, (word)lb, "INTERNAL", (word)0));
  546. }
  547. # endif
  548. #ifdef STUBBORN_ALLOC
  549. # ifdef __STDC__
  550. GC_PTR GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
  551. # else
  552. GC_PTR GC_debug_malloc_stubborn(lb, s, i)
  553. size_t lb;
  554. char * s;
  555. int i;
  556. # endif
  557. {
  558. GC_PTR result = GC_malloc_stubborn(lb + DEBUG_BYTES);
  559. if (result == 0) {
  560. GC_err_printf1("GC_debug_malloc(%ld) returning NIL (",
  561. (unsigned long) lb);
  562. GC_err_puts(s);
  563. GC_err_printf1(":%ld)\n", (unsigned long)i);
  564. return(0);
  565. }
  566. if (!GC_debugging_started) {
  567. GC_start_debugging();
  568. }
  569. ADD_CALL_CHAIN(result, ra);
  570. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  571. }
  572. void GC_debug_change_stubborn(p)
  573. GC_PTR p;
  574. {
  575. register GC_PTR q = GC_base(p);
  576. register hdr * hhdr;
  577. if (q == 0) {
  578. GC_err_printf1("Bad argument: 0x%lx to GC_debug_change_stubborn\n",
  579. (unsigned long) p);
  580. ABORT("GC_debug_change_stubborn: bad arg");
  581. }
  582. hhdr = HDR(q);
  583. if (hhdr -> hb_obj_kind != STUBBORN) {
  584. GC_err_printf1("GC_debug_change_stubborn arg not stubborn: 0x%lx\n",
  585. (unsigned long) p);
  586. ABORT("GC_debug_change_stubborn: arg not stubborn");
  587. }
  588. GC_change_stubborn(q);
  589. }
  590. void GC_debug_end_stubborn_change(p)
  591. GC_PTR p;
  592. {
  593. register GC_PTR q = GC_base(p);
  594. register hdr * hhdr;
  595. if (q == 0) {
  596. GC_err_printf1("Bad argument: 0x%lx to GC_debug_end_stubborn_change\n",
  597. (unsigned long) p);
  598. ABORT("GC_debug_end_stubborn_change: bad arg");
  599. }
  600. hhdr = HDR(q);
  601. if (hhdr -> hb_obj_kind != STUBBORN) {
  602. GC_err_printf1("debug_end_stubborn_change arg not stubborn: 0x%lx\n",
  603. (unsigned long) p);
  604. ABORT("GC_debug_end_stubborn_change: arg not stubborn");
  605. }
  606. GC_end_stubborn_change(q);
  607. }
  608. #else /* !STUBBORN_ALLOC */
  609. # ifdef __STDC__
  610. GC_PTR GC_debug_malloc_stubborn(size_t lb, GC_EXTRA_PARAMS)
  611. # else
  612. GC_PTR GC_debug_malloc_stubborn(lb, s, i)
  613. size_t lb;
  614. char * s;
  615. int i;
  616. # endif
  617. {
  618. return GC_debug_malloc(lb, OPT_RA s, i);
  619. }
  620. void GC_debug_change_stubborn(p)
  621. GC_PTR p;
  622. {
  623. }
  624. void GC_debug_end_stubborn_change(p)
  625. GC_PTR p;
  626. {
  627. }
  628. #endif /* !STUBBORN_ALLOC */
  629. # ifdef __STDC__
  630. GC_PTR GC_debug_malloc_atomic(size_t lb, GC_EXTRA_PARAMS)
  631. # else
  632. GC_PTR GC_debug_malloc_atomic(lb, s, i)
  633. size_t lb;
  634. char * s;
  635. int i;
  636. # endif
  637. {
  638. GC_PTR result = GC_malloc_atomic(lb + DEBUG_BYTES);
  639. if (result == 0) {
  640. GC_err_printf1("GC_debug_malloc_atomic(%ld) returning NIL (",
  641. (unsigned long) lb);
  642. GC_err_puts(s);
  643. GC_err_printf1(":%ld)\n", (unsigned long)i);
  644. return(0);
  645. }
  646. if (!GC_debugging_started) {
  647. GC_start_debugging();
  648. }
  649. ADD_CALL_CHAIN(result, ra);
  650. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  651. }
  652. # ifdef __STDC__
  653. GC_PTR GC_debug_malloc_uncollectable(size_t lb, GC_EXTRA_PARAMS)
  654. # else
  655. GC_PTR GC_debug_malloc_uncollectable(lb, s, i)
  656. size_t lb;
  657. char * s;
  658. int i;
  659. # endif
  660. {
  661. GC_PTR result = GC_malloc_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
  662. if (result == 0) {
  663. GC_err_printf1("GC_debug_malloc_uncollectable(%ld) returning NIL (",
  664. (unsigned long) lb);
  665. GC_err_puts(s);
  666. GC_err_printf1(":%ld)\n", (unsigned long)i);
  667. return(0);
  668. }
  669. if (!GC_debugging_started) {
  670. GC_start_debugging();
  671. }
  672. ADD_CALL_CHAIN(result, ra);
  673. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  674. }
  675. #ifdef ATOMIC_UNCOLLECTABLE
  676. # ifdef __STDC__
  677. GC_PTR GC_debug_malloc_atomic_uncollectable(size_t lb, GC_EXTRA_PARAMS)
  678. # else
  679. GC_PTR GC_debug_malloc_atomic_uncollectable(lb, s, i)
  680. size_t lb;
  681. char * s;
  682. int i;
  683. # endif
  684. {
  685. GC_PTR result =
  686. GC_malloc_atomic_uncollectable(lb + UNCOLLECTABLE_DEBUG_BYTES);
  687. if (result == 0) {
  688. GC_err_printf1(
  689. "GC_debug_malloc_atomic_uncollectable(%ld) returning NIL (",
  690. (unsigned long) lb);
  691. GC_err_puts(s);
  692. GC_err_printf1(":%ld)\n", (unsigned long)i);
  693. return(0);
  694. }
  695. if (!GC_debugging_started) {
  696. GC_start_debugging();
  697. }
  698. ADD_CALL_CHAIN(result, ra);
  699. return (GC_store_debug_info(result, (word)lb, s, (word)i));
  700. }
  701. #endif /* ATOMIC_UNCOLLECTABLE */
  702. # ifdef __STDC__
  703. void GC_debug_free(GC_PTR p)
  704. # else
  705. void GC_debug_free(p)
  706. GC_PTR p;
  707. # endif
  708. {
  709. register GC_PTR base;
  710. register ptr_t clobbered;
  711. if (0 == p) return;
  712. base = GC_base(p);
  713. if (base == 0) {
  714. GC_err_printf1("Attempt to free invalid pointer %lx\n",
  715. (unsigned long)p);
  716. ABORT("free(invalid pointer)");
  717. }
  718. if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
  719. GC_err_printf1(
  720. "GC_debug_free called on pointer %lx wo debugging info\n",
  721. (unsigned long)p);
  722. } else {
  723. # ifndef SHORT_DBG_HDRS
  724. clobbered = GC_check_annotated_obj((oh *)base);
  725. if (clobbered != 0) {
  726. if (((oh *)base) -> oh_sz == GC_size(base)) {
  727. GC_err_printf0(
  728. "GC_debug_free: found previously deallocated (?) object at ");
  729. } else {
  730. GC_err_printf0("GC_debug_free: found smashed location at ");
  731. }
  732. GC_print_smashed_obj(p, clobbered);
  733. }
  734. /* Invalidate size */
  735. ((oh *)base) -> oh_sz = GC_size(base);
  736. # endif /* SHORT_DBG_HDRS */
  737. }
  738. if (GC_find_leak) {
  739. GC_free(base);
  740. } else {
  741. register hdr * hhdr = HDR(p);
  742. GC_bool uncollectable = FALSE;
  743. if (hhdr -> hb_obj_kind == UNCOLLECTABLE) {
  744. uncollectable = TRUE;
  745. }
  746. # ifdef ATOMIC_UNCOLLECTABLE
  747. if (hhdr -> hb_obj_kind == AUNCOLLECTABLE) {
  748. uncollectable = TRUE;
  749. }
  750. # endif
  751. if (uncollectable) {
  752. GC_free(base);
  753. } else {
  754. size_t i;
  755. size_t obj_sz = hhdr -> hb_sz - BYTES_TO_WORDS(sizeof(oh));
  756. for (i = 0; i < obj_sz; ++i) ((word *)p)[i] = 0xdeadbeef;
  757. GC_ASSERT((word *)p + i == (word *)base + hhdr -> hb_sz);
  758. }
  759. } /* !GC_find_leak */
  760. }
  761. #ifdef THREADS
  762. extern void GC_free_inner(GC_PTR p);
  763. /* Used internally; we assume it's called correctly. */
  764. void GC_debug_free_inner(GC_PTR p)
  765. {
  766. GC_free_inner(GC_base(p));
  767. }
  768. #endif
  769. # ifdef __STDC__
  770. GC_PTR GC_debug_realloc(GC_PTR p, size_t lb, GC_EXTRA_PARAMS)
  771. # else
  772. GC_PTR GC_debug_realloc(p, lb, s, i)
  773. GC_PTR p;
  774. size_t lb;
  775. char *s;
  776. int i;
  777. # endif
  778. {
  779. register GC_PTR base = GC_base(p);
  780. register ptr_t clobbered;
  781. register GC_PTR result;
  782. register size_t copy_sz = lb;
  783. register size_t old_sz;
  784. register hdr * hhdr;
  785. if (p == 0) return(GC_debug_malloc(lb, OPT_RA s, i));
  786. if (base == 0) {
  787. GC_err_printf1(
  788. "Attempt to reallocate invalid pointer %lx\n", (unsigned long)p);
  789. ABORT("realloc(invalid pointer)");
  790. }
  791. if ((ptr_t)p - (ptr_t)base != sizeof(oh)) {
  792. GC_err_printf1(
  793. "GC_debug_realloc called on pointer %lx wo debugging info\n",
  794. (unsigned long)p);
  795. return(GC_realloc(p, lb));
  796. }
  797. hhdr = HDR(base);
  798. switch (hhdr -> hb_obj_kind) {
  799. # ifdef STUBBORN_ALLOC
  800. case STUBBORN:
  801. result = GC_debug_malloc_stubborn(lb, OPT_RA s, i);
  802. break;
  803. # endif
  804. case NORMAL:
  805. result = GC_debug_malloc(lb, OPT_RA s, i);
  806. break;
  807. case PTRFREE:
  808. result = GC_debug_malloc_atomic(lb, OPT_RA s, i);
  809. break;
  810. case UNCOLLECTABLE:
  811. result = GC_debug_malloc_uncollectable(lb, OPT_RA s, i);
  812. break;
  813. # ifdef ATOMIC_UNCOLLECTABLE
  814. case AUNCOLLECTABLE:
  815. result = GC_debug_malloc_atomic_uncollectable(lb, OPT_RA s, i);
  816. break;
  817. # endif
  818. default:
  819. GC_err_printf0("GC_debug_realloc: encountered bad kind\n");
  820. ABORT("bad kind");
  821. }
  822. # ifdef SHORT_DBG_HDRS
  823. old_sz = GC_size(base) - sizeof(oh);
  824. # else
  825. clobbered = GC_check_annotated_obj((oh *)base);
  826. if (clobbered != 0) {
  827. GC_err_printf0("GC_debug_realloc: found smashed location at ");
  828. GC_print_smashed_obj(p, clobbered);
  829. }
  830. old_sz = ((oh *)base) -> oh_sz;
  831. # endif
  832. if (old_sz < copy_sz) copy_sz = old_sz;
  833. if (result == 0) return(0);
  834. BCOPY(p, result, copy_sz);
  835. GC_debug_free(p);
  836. return(result);
  837. }
  838. #ifndef SHORT_DBG_HDRS
  839. /* List of smashed objects. We defer printing these, since we can't */
  840. /* always print them nicely with the allocation lock held. */
  841. /* We put them here instead of in GC_arrays, since it may be useful to */
  842. /* be able to look at them with the debugger. */
  843. #define MAX_SMASHED 20
  844. ptr_t GC_smashed[MAX_SMASHED];
  845. unsigned GC_n_smashed = 0;
  846. # if defined(__STDC__) || defined(__cplusplus)
  847. void GC_add_smashed(ptr_t smashed)
  848. # else
  849. void GC_add_smashed(smashed)
  850. ptr_t smashed;
  851. #endif
  852. {
  853. GC_ASSERT(GC_is_marked(GC_base(smashed)));
  854. GC_smashed[GC_n_smashed] = smashed;
  855. if (GC_n_smashed < MAX_SMASHED - 1) ++GC_n_smashed;
  856. /* In case of overflow, we keep the first MAX_SMASHED-1 */
  857. /* entries plus the last one. */
  858. GC_have_errors = TRUE;
  859. }
  860. /* Print all objects on the list. Clear the list. */
  861. void GC_print_all_smashed_proc ()
  862. {
  863. unsigned i;
  864. GC_ASSERT(!I_HOLD_LOCK());
  865. if (GC_n_smashed == 0) return;
  866. GC_err_printf0("GC_check_heap_block: found smashed heap objects:\n");
  867. for (i = 0; i < GC_n_smashed; ++i) {
  868. GC_print_smashed_obj(GC_base(GC_smashed[i]), GC_smashed[i]);
  869. GC_smashed[i] = 0;
  870. }
  871. GC_n_smashed = 0;
  872. }
  873. /* Check all marked objects in the given block for validity */
  874. /*ARGSUSED*/
  875. # if defined(__STDC__) || defined(__cplusplus)
  876. void GC_check_heap_block(register struct hblk *hbp, word dummy)
  877. # else
  878. void GC_check_heap_block(hbp, dummy)
  879. register struct hblk *hbp; /* ptr to current heap block */
  880. word dummy;
  881. # endif
  882. {
  883. register struct hblkhdr * hhdr = HDR(hbp);
  884. register word sz = hhdr -> hb_sz;
  885. register int word_no;
  886. register word *p, *plim;
  887. p = (word *)(hbp->hb_body);
  888. word_no = 0;
  889. if (sz > MAXOBJSZ) {
  890. plim = p;
  891. } else {
  892. plim = (word *)((((word)hbp) + HBLKSIZE) - WORDS_TO_BYTES(sz));
  893. }
  894. /* go through all words in block */
  895. while( p <= plim ) {
  896. if( mark_bit_from_hdr(hhdr, word_no)
  897. && GC_HAS_DEBUG_INFO((ptr_t)p)) {
  898. ptr_t clobbered = GC_check_annotated_obj((oh *)p);
  899. if (clobbered != 0) GC_add_smashed(clobbered);
  900. }
  901. word_no += sz;
  902. p += sz;
  903. }
  904. }
  905. /* This assumes that all accessible objects are marked, and that */
  906. /* I hold the allocation lock. Normally called by collector. */
  907. void GC_check_heap_proc()
  908. {
  909. # ifndef SMALL_CONFIG
  910. # ifdef ALIGN_DOUBLE
  911. GC_STATIC_ASSERT((sizeof(oh) & (2 * sizeof(word) - 1)) == 0);
  912. # else
  913. GC_STATIC_ASSERT((sizeof(oh) & (sizeof(word) - 1)) == 0);
  914. # endif
  915. # endif
  916. GC_apply_to_all_blocks(GC_check_heap_block, (word)0);
  917. }
  918. #endif /* !SHORT_DBG_HDRS */
  919. struct closure {
  920. GC_finalization_proc cl_fn;
  921. GC_PTR cl_data;
  922. };
  923. # ifdef __STDC__
  924. void * GC_make_closure(GC_finalization_proc fn, void * data)
  925. # else
  926. GC_PTR GC_make_closure(fn, data)
  927. GC_finalization_proc fn;
  928. GC_PTR data;
  929. # endif
  930. {
  931. struct closure * result =
  932. # ifdef DBG_HDRS_ALL
  933. (struct closure *) GC_debug_malloc(sizeof (struct closure),
  934. GC_EXTRAS);
  935. # else
  936. (struct closure *) GC_malloc(sizeof (struct closure));
  937. # endif
  938. result -> cl_fn = fn;
  939. result -> cl_data = data;
  940. return((GC_PTR)result);
  941. }
  942. # ifdef __STDC__
  943. void GC_debug_invoke_finalizer(void * obj, void * data)
  944. # else
  945. void GC_debug_invoke_finalizer(obj, data)
  946. char * obj;
  947. char * data;
  948. # endif
  949. {
  950. register struct closure * cl = (struct closure *) data;
  951. (*(cl -> cl_fn))((GC_PTR)((char *)obj + sizeof(oh)), cl -> cl_data);
  952. }
  953. /* Set ofn and ocd to reflect the values we got back. */
  954. static void store_old (obj, my_old_fn, my_old_cd, ofn, ocd)
  955. GC_PTR obj;
  956. GC_finalization_proc my_old_fn;
  957. struct closure * my_old_cd;
  958. GC_finalization_proc *ofn;
  959. GC_PTR *ocd;
  960. {
  961. if (0 != my_old_fn) {
  962. if (my_old_fn != GC_debug_invoke_finalizer) {
  963. GC_err_printf1("Debuggable object at 0x%lx had non-debug finalizer.\n",
  964. obj);
  965. /* This should probably be fatal. */
  966. } else {
  967. if (ofn) *ofn = my_old_cd -> cl_fn;
  968. if (ocd) *ocd = my_old_cd -> cl_data;
  969. }
  970. } else {
  971. if (ofn) *ofn = 0;
  972. if (ocd) *ocd = 0;
  973. }
  974. }
  975. # ifdef __STDC__
  976. void GC_debug_register_finalizer(GC_PTR obj, GC_finalization_proc fn,
  977. GC_PTR cd, GC_finalization_proc *ofn,
  978. GC_PTR *ocd)
  979. # else
  980. void GC_debug_register_finalizer(obj, fn, cd, ofn, ocd)
  981. GC_PTR obj;
  982. GC_finalization_proc fn;
  983. GC_PTR cd;
  984. GC_finalization_proc *ofn;
  985. GC_PTR *ocd;
  986. # endif
  987. {
  988. GC_finalization_proc my_old_fn;
  989. GC_PTR my_old_cd;
  990. ptr_t base = GC_base(obj);
  991. if (0 == base) return;
  992. if ((ptr_t)obj - base != sizeof(oh)) {
  993. GC_err_printf1(
  994. "GC_debug_register_finalizer called with non-base-pointer 0x%lx\n",
  995. obj);
  996. }
  997. if (0 == fn) {
  998. GC_register_finalizer(base, 0, 0, &my_old_fn, &my_old_cd);
  999. } else {
  1000. GC_register_finalizer(base, GC_debug_invoke_finalizer,
  1001. GC_make_closure(fn,cd), &my_old_fn, &my_old_cd);
  1002. }
  1003. store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
  1004. }
  1005. # ifdef __STDC__
  1006. void GC_debug_register_finalizer_no_order
  1007. (GC_PTR obj, GC_finalization_proc fn,
  1008. GC_PTR cd, GC_finalization_proc *ofn,
  1009. GC_PTR *ocd)
  1010. # else
  1011. void GC_debug_register_finalizer_no_order
  1012. (obj, fn, cd, ofn, ocd)
  1013. GC_PTR obj;
  1014. GC_finalization_proc fn;
  1015. GC_PTR cd;
  1016. GC_finalization_proc *ofn;
  1017. GC_PTR *ocd;
  1018. # endif
  1019. {
  1020. GC_finalization_proc my_old_fn;
  1021. GC_PTR my_old_cd;
  1022. ptr_t base = GC_base(obj);
  1023. if (0 == base) return;
  1024. if ((ptr_t)obj - base != sizeof(oh)) {
  1025. GC_err_printf1(
  1026. "GC_debug_register_finalizer_no_order called with non-base-pointer 0x%lx\n",
  1027. obj);
  1028. }
  1029. if (0 == fn) {
  1030. GC_register_finalizer_no_order(base, 0, 0, &my_old_fn, &my_old_cd);
  1031. } else {
  1032. GC_register_finalizer_no_order(base, GC_debug_invoke_finalizer,
  1033. GC_make_closure(fn,cd), &my_old_fn,
  1034. &my_old_cd);
  1035. }
  1036. store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
  1037. }
  1038. # ifdef __STDC__
  1039. void GC_debug_register_finalizer_unreachable
  1040. (GC_PTR obj, GC_finalization_proc fn,
  1041. GC_PTR cd, GC_finalization_proc *ofn,
  1042. GC_PTR *ocd)
  1043. # else
  1044. void GC_debug_register_finalizer_unreachable
  1045. (obj, fn, cd, ofn, ocd)
  1046. GC_PTR obj;
  1047. GC_finalization_proc fn;
  1048. GC_PTR cd;
  1049. GC_finalization_proc *ofn;
  1050. GC_PTR *ocd;
  1051. # endif
  1052. {
  1053. GC_finalization_proc my_old_fn;
  1054. GC_PTR my_old_cd;
  1055. ptr_t base = GC_base(obj);
  1056. if (0 == base) return;
  1057. if ((ptr_t)obj - base != sizeof(oh)) {
  1058. GC_err_printf1(
  1059. "GC_debug_register_finalizer_unreachable called with non-base-pointer 0x%lx\n",
  1060. obj);
  1061. }
  1062. if (0 == fn) {
  1063. GC_register_finalizer_unreachable(base, 0, 0, &my_old_fn, &my_old_cd);
  1064. } else {
  1065. GC_register_finalizer_unreachable(base, GC_debug_invoke_finalizer,
  1066. GC_make_closure(fn,cd), &my_old_fn,
  1067. &my_old_cd);
  1068. }
  1069. store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
  1070. }
  1071. # ifdef __STDC__
  1072. void GC_debug_register_finalizer_ignore_self
  1073. (GC_PTR obj, GC_finalization_proc fn,
  1074. GC_PTR cd, GC_finalization_proc *ofn,
  1075. GC_PTR *ocd)
  1076. # else
  1077. void GC_debug_register_finalizer_ignore_self
  1078. (obj, fn, cd, ofn, ocd)
  1079. GC_PTR obj;
  1080. GC_finalization_proc fn;
  1081. GC_PTR cd;
  1082. GC_finalization_proc *ofn;
  1083. GC_PTR *ocd;
  1084. # endif
  1085. {
  1086. GC_finalization_proc my_old_fn;
  1087. GC_PTR my_old_cd;
  1088. ptr_t base = GC_base(obj);
  1089. if (0 == base) return;
  1090. if ((ptr_t)obj - base != sizeof(oh)) {
  1091. GC_err_printf1(
  1092. "GC_debug_register_finalizer_ignore_self called with non-base-pointer 0x%lx\n",
  1093. obj);
  1094. }
  1095. if (0 == fn) {
  1096. GC_register_finalizer_ignore_self(base, 0, 0, &my_old_fn, &my_old_cd);
  1097. } else {
  1098. GC_register_finalizer_ignore_self(base, GC_debug_invoke_finalizer,
  1099. GC_make_closure(fn,cd), &my_old_fn,
  1100. &my_old_cd);
  1101. }
  1102. store_old(obj, my_old_fn, (struct closure *)my_old_cd, ofn, ocd);
  1103. }
  1104. #ifdef GC_ADD_CALLER
  1105. # define RA GC_RETURN_ADDR,
  1106. #else
  1107. # define RA
  1108. #endif
  1109. GC_PTR GC_debug_malloc_replacement(lb)
  1110. size_t lb;
  1111. {
  1112. return GC_debug_malloc(lb, RA "unknown", 0);
  1113. }
  1114. GC_PTR GC_debug_realloc_replacement(p, lb)
  1115. GC_PTR p;
  1116. size_t lb;
  1117. {
  1118. return GC_debug_realloc(p, lb, RA "unknown", 0);
  1119. }