From 9239a574f87d40166e62533f1c86feb3545ae98f Mon Sep 17 00:00:00 2001 From: struct Date: Fri, 16 Dec 2022 09:43:18 -0500 Subject: [PATCH] cleanup destruction of threads --- Makefile | 2 +- src/iso_alloc.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cd754f6..82843a3 100644 --- a/Makefile +++ b/Makefile @@ -181,7 +181,7 @@ AUTO_CTOR_DTOR = -DAUTO_CTOR_DTOR=1 ## Unmap user and bitmap in the destructor. You probably ## don't want this as theres no guarantee the IsoAlloc ## destructor will be called last and other destructors -## that call free will segfault +## may reference objects within these pages ISO_DTOR_CLEANUP = -DISO_DTOR_CLEANUP=0 ## Register a signal handler for SIGSEGV that inspects si_addr diff --git a/src/iso_alloc.c b/src/iso_alloc.c index f2acd03..5e1f8fa 100644 --- a/src/iso_alloc.c +++ b/src/iso_alloc.c @@ -1989,9 +1989,20 @@ INTERNAL_HIDDEN void _iso_alloc_destroy(void) { unmap_guarded_pages(_root->chunk_lookup_table, CHUNK_TO_ZONE_TABLE_SZ); unmap_guarded_pages(_root->chunk_quarantine, ROUND_UP_PAGE(CHUNK_QUARANTINE_SZ * sizeof(uintptr_t))); unmap_guarded_pages(zone_cache, ROUND_UP_PAGE(ZONE_CACHE_SZ * sizeof(_tzc))); + +#if THREAD_SUPPORT && !USE_SPINLOCK + UNLOCK_BIG_ZONE(); + pthread_mutex_destroy(&_root->big_zone_busy_mutex); +#endif + unmap_guarded_pages(_root, sizeof(iso_alloc_root)); #endif UNLOCK_ROOT(); + +#if ISO_DTOR_CLEANUP && THREAD_SUPPORT && !USE_SPINLOCK + pthread_mutex_destroy(&sane_cache_mutex); + pthread_mutex_destroy(&root_busy_mutex); +#endif } #if UNIT_TESTING