Skip to content

Commit

Permalink
Fix ADD_CALL_CHAIN() placement to follow GC_store_debug_info_inner call
Browse files Browse the repository at this point in the history
Issue #613 (bdwgc).

This might be important for the case of malloc redirection as
backtrace() need to be called without the allocator lock held.

* dbg_mlc.c (store_debug_info, GC_debug_generic_malloc_inner): Call
ADD_CALL_CHAIN() right after GC_store_debug_info_inner() call (instead
of before it).
* gcj_mlc.c (GC_debug_gcj_malloc): Likewise.
* dbg_mlc.c (GC_debug_generic_malloc_inner): Declare result local
variable.
  • Loading branch information
ivmai committed Mar 19, 2024
1 parent 63c7fd7 commit f4f943b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions dbg_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ static void *store_debug_info(void *base, size_t lb,
LOCK();
if (!GC_debugging_started)
GC_start_debugging_inner();
ADD_CALL_CHAIN(base, ra);
result = GC_store_debug_info_inner(base, (word)lb, s, i);
ADD_CALL_CHAIN(base, ra);
UNLOCK();
return result;
}
Expand Down Expand Up @@ -570,7 +570,7 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int k, GC_EXTRA_PARAMS)
GC_INNER void * GC_debug_generic_malloc_inner(size_t lb, int k,
unsigned flags)
{
void *base;
void *base, *result;

GC_ASSERT(I_HOLD_LOCK());
base = GC_generic_malloc_inner(SIZET_SAT_ADD(lb, DEBUG_BYTES), k, flags);
Expand All @@ -581,8 +581,9 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int k, GC_EXTRA_PARAMS)
}
if (!GC_debugging_started)
GC_start_debugging_inner();
result = GC_store_debug_info_inner(base, (word)lb, "INTERNAL", 0);
ADD_CALL_CHAIN(base, GC_RETURN_ADDR);
return GC_store_debug_info_inner(base, (word)lb, "INTERNAL", 0);
return result;
}
#endif /* DBG_HDRS_ALL */

Expand Down
2 changes: 1 addition & 1 deletion gcj_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_debug_gcj_malloc(size_t lb,
if (!GC_debugging_started) {
GC_start_debugging_inner();
}
ADD_CALL_CHAIN(base, ra);
result = GC_store_debug_info_inner(base, (word)lb, s, i);
ADD_CALL_CHAIN(base, ra);
UNLOCK();
GC_dirty(result);
REACHABLE_AFTER_DIRTY(ptr_to_struct_containing_descr);
Expand Down

0 comments on commit f4f943b

Please sign in to comment.