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