From 01b460fedb5715051397ecacbfe9d330e32528f7 Mon Sep 17 00:00:00 2001 From: Daan Date: Mon, 20 Mar 2023 13:24:11 -0700 Subject: [PATCH 1/3] add std::string test for macos --- test/main-override.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/main-override.cpp b/test/main-override.cpp index db96efb1..902cfdd4 100644 --- a/test/main-override.cpp +++ b/test/main-override.cpp @@ -36,14 +36,16 @@ static void fail_aslr(); // issue #372 static void tsan_numa_test(); // issue #414 static void strdup_test(); // issue #445 static void heap_thread_free_huge(); +static void test_std_string(); // issue #697 static void test_stl_allocators(); int main() { - mi_stats_reset(); // ignore earlier allocations - - heap_thread_free_huge(); + // mi_stats_reset(); // ignore earlier allocations + + test_std_string(); + // heap_thread_free_huge(); /* heap_thread_free_large(); heap_no_delete(); @@ -56,7 +58,7 @@ int main() { test_mt_shutdown(); */ //fail_aslr(); - mi_stats_print(NULL); + // mi_stats_print(NULL); return 0; } @@ -196,6 +198,13 @@ static void heap_no_delete() { } +// Issue #697 +static void test_std_string() { + std::string path = "/Users/xxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxx/Build/Intermediates.noindex/xxxxxxxxxxx/arm64/XX_lto.o/0.arm64.lto.o"; + std::string path1 = "/Users/xxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxx/Build/Intermediates.noindex/xxxxxxxxxxx/arm64/XX_lto.o/1.arm64.lto.o"; + std::cout << path + "\n>>> " + path1 + "\n>>> " << std::endl; +} + // Issue #204 static volatile void* global_p; From c92e9e7bf76add4b7de35de8ac243dc144b92e56 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Mon, 20 Mar 2023 14:01:09 -0700 Subject: [PATCH 2/3] add comment that thread id's should not be zero, issue #698 --- include/mimalloc/prim.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/mimalloc/prim.h b/include/mimalloc/prim.h index 97d8b45d..68f0871e 100644 --- a/include/mimalloc/prim.h +++ b/include/mimalloc/prim.h @@ -104,12 +104,13 @@ void _mi_prim_thread_associate_default_heap(mi_heap_t* heap); //------------------------------------------------------------------- -// Thread id +// Thread id: `_mi_prim_thread_id()` // // Getting the thread id should be performant as it is called in the // fast path of `_mi_free` and we specialize for various platforms as // inlined definitions. Regular code should call `init.c:_mi_thread_id()`. -// We only require _mi_prim_thread_id() to return a unique id for each thread. +// We only require _mi_prim_thread_id() to return a unique id +// for each thread (unequal to zero). //------------------------------------------------------------------- static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept; From 06f0ba232e515d9d30ab5a89ef3e929641cde61b Mon Sep 17 00:00:00 2001 From: Daan Date: Mon, 20 Mar 2023 14:23:52 -0700 Subject: [PATCH 3/3] prevent reentrancy on thread_done (issue #699) --- src/init.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/init.c b/src/init.c index 9a11f6e0..cd95526c 100644 --- a/src/init.c +++ b/src/init.c @@ -380,15 +380,24 @@ void mi_thread_done(void) mi_attr_noexcept { _mi_thread_done(NULL); } +#include + void _mi_thread_done(mi_heap_t* heap) { - mi_atomic_decrement_relaxed(&thread_count); - _mi_stat_decrease(&_mi_stats_main.threads, 1); - + // calling with NULL implies using the default heap if (heap == NULL) { heap = mi_prim_get_default_heap(); if (heap == NULL) return; } + + // prevent re-entrancy through heap_done/heap_set_default_direct (issue #699) + if (!mi_heap_is_initialized(heap)) { + return; + } + + // adjust stats + mi_atomic_decrement_relaxed(&thread_count); + _mi_stat_decrease(&_mi_stats_main.threads, 1); // check thread-id as on Windows shutdown with FLS the main (exit) thread may call this on thread-local heaps... if (heap->thread_id != _mi_thread_id()) return;