diff options
author | daan <daanl@outlook.com> | 2022-01-10 16:21:15 -0800 |
---|---|---|
committer | daan <daanl@outlook.com> | 2022-01-10 16:21:15 -0800 |
commit | a74c05c6c0cda3fb4d1aa515dc36aea5e08d2c65 (patch) | |
tree | edb187811e35f786f6f58a50530c28f917cea134 | |
parent | a763b6310dbbecc92ed549dba757690381195853 (diff) | |
parent | 05c2a51211bd5b952483d7eccb22dc5d5428155a (diff) |
Merge branch 'dev' into dev-slice
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | bin/mimalloc-redirect.dll | bin | 55808 -> 56832 bytes | |||
-rw-r--r-- | bin/mimalloc-redirect.lib | bin | 2874 -> 2874 bytes | |||
-rw-r--r-- | bin/mimalloc-redirect32.dll | bin | 39424 -> 40448 bytes | |||
-rw-r--r-- | bin/mimalloc-redirect32.lib | bin | 2928 -> 2928 bytes | |||
-rw-r--r-- | bin/minject.exe | bin | 0 -> 20992 bytes | |||
-rw-r--r-- | bin/minject32.exe | bin | 0 -> 17920 bytes | |||
-rw-r--r-- | include/mimalloc-types.h | 6 | ||||
-rw-r--r-- | src/init.c | 22 | ||||
-rw-r--r-- | src/region.c | 2 | ||||
-rw-r--r-- | test/main-override.cpp | 4 |
12 files changed, 21 insertions, 15 deletions
diff --git a/.gitattributes b/.gitattributes index 1534e77..0332e03 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,3 +9,4 @@ *.patch binary *.dll binary *.lib binary +*.exe binary diff --git a/CMakeLists.txt b/CMakeLists.txt index 29243b4..353d171 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -337,6 +337,7 @@ if (MI_BUILD_STATIC) endif() install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_objdir} LIBRARY) + install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir}) endif() # install include files diff --git a/bin/mimalloc-redirect.dll b/bin/mimalloc-redirect.dll Binary files differindex b7bf1d0..83b6bd4 100644 --- a/bin/mimalloc-redirect.dll +++ b/bin/mimalloc-redirect.dll diff --git a/bin/mimalloc-redirect.lib b/bin/mimalloc-redirect.lib Binary files differindex 550db8e..059fb87 100644 --- a/bin/mimalloc-redirect.lib +++ b/bin/mimalloc-redirect.lib diff --git a/bin/mimalloc-redirect32.dll b/bin/mimalloc-redirect32.dll Binary files differindex 7ba303a..2892d45 100644 --- a/bin/mimalloc-redirect32.dll +++ b/bin/mimalloc-redirect32.dll diff --git a/bin/mimalloc-redirect32.lib b/bin/mimalloc-redirect32.lib Binary files differindex 6617306..7dadab3 100644 --- a/bin/mimalloc-redirect32.lib +++ b/bin/mimalloc-redirect32.lib diff --git a/bin/minject.exe b/bin/minject.exe Binary files differnew file mode 100644 index 0000000..e576c71 --- /dev/null +++ b/bin/minject.exe diff --git a/bin/minject32.exe b/bin/minject32.exe Binary files differnew file mode 100644 index 0000000..1eb8a75 --- /dev/null +++ b/bin/minject32.exe diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index 957115c..4136428 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -447,9 +447,15 @@ struct mi_heap_s { // Debug // ------------------------------------------------------ +#if !defined(MI_DEBUG_UNINIT) #define MI_DEBUG_UNINIT (0xD0) +#endif +#if !defined(MI_DEBUG_FREED) #define MI_DEBUG_FREED (0xDF) +#endif +#if !defined(MI_DEBUG_PADDING) #define MI_DEBUG_PADDING (0xDE) +#endif #if (MI_DEBUG) // use our own assertion to print without memory allocation @@ -520,14 +520,14 @@ void mi_process_init(void) mi_attr_noexcept { #endif _mi_verbose_message("secure level: %d\n", MI_SECURE); mi_thread_init(); -#if defined(_WIN32) && !defined(MI_SHARED_LIB) - /* When building as a static lib the FLS cleanup happens to early for the main thread. - * To avoid that set the FLS value for the main thread to NULL; the eventual - * mi_fls_done() execution won't call _mi_thread_done(). - * The latter function is later called explicitly from mi_process_done(). - * See GitHub issue #508 for more background and explanation. */ + + #if defined(_WIN32) && !defined(MI_SHARED_LIB) + // When building as a static lib the FLS cleanup happens to early for the main thread. + // To avoid this, set the FLS value for the main thread to NULL so the fls cleanup + // will not call _mi_thread_done on the (still executing) main thread. See issue #508. FlsSetValue(mi_fls_key, NULL); -#endif + #endif + mi_stats_reset(); // only call stat reset *after* thread init (or the heap tld == NULL) if (mi_option_is_enabled(mi_option_reserve_huge_os_pages)) { @@ -557,9 +557,7 @@ static void mi_process_done(void) { process_done = true; #if defined(_WIN32) && !defined(MI_SHARED_LIB) - // Explicitly clean up main thread. See comment in mi_process_init() for reason - _mi_thread_done(_mi_heap_default); - FlsFree(mi_fls_key); // call thread-done on all threads to prevent dangling callback pointer if statically linked with a DLL; Issue #208 + FlsFree(mi_fls_key); // call thread-done on all threads (except the main thread) to prevent dangling callback pointer if statically linked with a DLL; Issue #208 #endif #if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB) @@ -600,7 +598,7 @@ static void mi_process_done(void) { mi_process_load(); return 0; } - typedef int(*_crt_cb)(void); + typedef int(*_mi_crt_callback_t)(void); #if defined(_M_X64) || defined(_M_ARM64) __pragma(comment(linker, "/include:" "_mi_msvc_initu")) #pragma section(".CRT$XIU", long, read) @@ -608,7 +606,7 @@ static void mi_process_done(void) { __pragma(comment(linker, "/include:" "__mi_msvc_initu")) #endif #pragma data_seg(".CRT$XIU") - extern "C" _crt_cb _mi_msvc_initu[] = { &_mi_process_init }; + extern "C" _mi_crt_callback_t _mi_msvc_initu[] = { &_mi_process_init }; #pragma data_seg() #elif defined(__cplusplus) diff --git a/src/region.c b/src/region.c index f864f73..2d73025 100644 --- a/src/region.c +++ b/src/region.c @@ -94,7 +94,7 @@ typedef struct mem_region_s { mi_bitmap_field_t commit; // track if committed per block mi_bitmap_field_t reset; // track if reset per block _Atomic(size_t) arena_memid; // if allocated from a (huge page) arena - size_t padding; // round to 8 fields + _Atomic(size_t) padding; // round to 8 fields (needs to be atomic for msvc, see issue #508) } mem_region_t; // The region map diff --git a/test/main-override.cpp b/test/main-override.cpp index 8834f2c..e0dba5a 100644 --- a/test/main-override.cpp +++ b/test/main-override.cpp @@ -50,7 +50,7 @@ int main() { tsan_numa_test(); strdup_test(); - //test_mt_shutdown(); + test_mt_shutdown(); //fail_aslr(); bench_alloc_large(); mi_stats_print(NULL); @@ -76,7 +76,7 @@ public: static void various_tests() { atexit(free_p); void* p1 = malloc(78); - void* p2 = mi_malloc_aligned(16, 24); + void* p2 = mi_malloc_aligned(24, 16); free(p1); p1 = malloc(8); char* s = mi_strdup("hello\n"); |