From d194e44fec13f92baefe66c2e2f14521627a9679 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 15 Mar 2018 23:16:36 +0300 Subject: Add assertions to ensure ADD_CALL_CHAIN is called holding the lock (code refactoring) * alloc.c (GC_collect_a_little_inner, GC_allocobj): Add assertion that the allocation lock is held. * dbg_mlc.c (GC_store_debug_info_inner): Likewise. * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner, GC_debug_generic_malloc_inner_ignore_off_page): Likewise. * finalize.c [!GC_TOGGLE_REFS_NOT_NEEDED] (ensure_toggleref_capacity): Likewise. * specific.c [USE_CUSTOM_SPECIFIC] (GC_key_create_inner): Likewise. * alloc.c (GC_allocobj): Remove comment (about the lock). * dbg_mlc.c [DBG_HDRS_ALL] (GC_debug_generic_malloc_inner): Likewise. --- dbg_mlc.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'dbg_mlc.c') diff --git a/dbg_mlc.c b/dbg_mlc.c index f087ab4b..554692be 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -277,6 +277,7 @@ GC_INNER void *GC_store_debug_info_inner(void *p, word sz GC_ATTR_UNUSED, { word * result = (word *)((oh *)p + 1); + GC_ASSERT(I_HOLD_LOCK()); GC_ASSERT(GC_size(p) >= sizeof(oh) + sz); GC_ASSERT(!(SMALL_OBJ(sz) && CROSSES_HBLK((ptr_t)p, sz))); # ifdef KEEP_BACK_PTRS @@ -577,13 +578,13 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) /* An allocation function for internal use. Normally internally */ /* allocated objects do not have debug information. But in this */ /* case, we need to make sure that all objects have debug headers. */ - /* We assume we already hold the GC lock. */ GC_INNER void * GC_debug_generic_malloc_inner(size_t lb, int k) { - void * result = GC_generic_malloc_inner( - SIZET_SAT_ADD(lb, DEBUG_BYTES), k); + void * result; - if (result == 0) { + GC_ASSERT(I_HOLD_LOCK()); + result = GC_generic_malloc_inner(SIZET_SAT_ADD(lb, DEBUG_BYTES), k); + if (NULL == result) { GC_err_printf("GC internal allocation (%lu bytes) returning NULL\n", (unsigned long) lb); return(0); @@ -598,10 +599,12 @@ STATIC void * GC_debug_generic_malloc(size_t lb, int knd, GC_EXTRA_PARAMS) GC_INNER void * GC_debug_generic_malloc_inner_ignore_off_page(size_t lb, int k) { - void * result = GC_generic_malloc_inner_ignore_off_page( - SIZET_SAT_ADD(lb, DEBUG_BYTES), k); + void * result; - if (result == 0) { + GC_ASSERT(I_HOLD_LOCK()); + result = GC_generic_malloc_inner_ignore_off_page( + SIZET_SAT_ADD(lb, DEBUG_BYTES), k); + if (NULL == result) { GC_err_printf("GC internal allocation (%lu bytes) returning NULL\n", (unsigned long) lb); return(0); -- cgit v1.2.1