diff --git a/cmake/mimalloc-config-version.cmake b/cmake/mimalloc-config-version.cmake index 945fbfce..385d0b7b 100644 --- a/cmake/mimalloc-config-version.cmake +++ b/cmake/mimalloc-config-version.cmake @@ -1,6 +1,6 @@ set(mi_version_major 3) set(mi_version_minor 0) -set(mi_version_patch 7) +set(mi_version_patch 8) set(mi_version ${mi_version_major}.${mi_version_minor}) set(PACKAGE_VERSION ${mi_version}) diff --git a/include/mimalloc.h b/include/mimalloc.h index d5fefbf1..9f3690c6 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file #ifndef MIMALLOC_H #define MIMALLOC_H -#define MI_MALLOC_VERSION 307 // major + 2 digits minor +#define MI_MALLOC_VERSION 308 // major + 2 digits minor // ------------------------------------------------------ // Compiler specific attributes diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index b2fbe1d1..10f802f6 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -446,7 +446,6 @@ struct mi_heap_s { size_t guarded_size_min; // minimal size for guarded objects size_t guarded_size_max; // maximal size for guarded objects size_t guarded_sample_rate; // sample rate (set to 0 to disable guarded pages) - size_t guarded_sample_seed; // starting sample count size_t guarded_sample_count; // current sample count (counting down to 0) #endif mi_page_t* pages_free_direct[MI_PAGES_DIRECT]; // optimize: array where every entry points a page with possibly free blocks in the corresponding queue for that size. diff --git a/src/alloc.c b/src/alloc.c index f1e4e9eb..e6fc16e3 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -622,7 +622,10 @@ static void* mi_block_ptr_set_guarded(mi_block_t* block, size_t obj_size) { mi_assert_internal(_mi_is_aligned(block, os_page_size)); mi_assert_internal(_mi_is_aligned(guard_page, os_page_size)); if (!page->memid.is_pinned && _mi_is_aligned(guard_page, os_page_size)) { - _mi_os_protect(guard_page, os_page_size); + const bool ok = _mi_os_protect(guard_page, os_page_size); + if (!ok) { + _mi_warning_message("failed to set a guard page behind object (object %p of size %zu)\n", block, block_size); + } } else { _mi_warning_message("unable to set a guard page behind an object due to pinned memory (large OS pages?) (object %p of size %zu)\n", block, block_size); diff --git a/src/init.c b/src/init.c index ee41d8ac..c396fa3c 100644 --- a/src/init.c +++ b/src/init.c @@ -130,7 +130,7 @@ mi_decl_cache_align const mi_heap_t _mi_heap_empty = { true, // can eager abandon 0, // tag #if MI_GUARDED - 0, 0, 0, 0, 1, // count is 1 so we never write to it (see `internal.h:mi_heap_malloc_use_guarded`) + 0, 0, 0, 1, // count is 1 so we never write to it (see `internal.h:mi_heap_malloc_use_guarded`) #endif MI_SMALL_PAGES_EMPTY, MI_PAGE_QUEUES_EMPTY, @@ -167,7 +167,7 @@ mi_decl_cache_align mi_heap_t heap_main = { true, // allow page abandon 0, // tag #if MI_GUARDED - 0, 0, 0, 0, 0, + 0, 0, 0, 0, #endif MI_SMALL_PAGES_EMPTY, MI_PAGE_QUEUES_EMPTY, @@ -189,15 +189,14 @@ mi_stats_t _mi_stats_main = { MI_STAT_VERSION, MI_STATS_NULL }; #if MI_GUARDED mi_decl_export void mi_heap_guarded_set_sample_rate(mi_heap_t* heap, size_t sample_rate, size_t seed) { - heap->guarded_sample_seed = seed; - if (heap->guarded_sample_seed == 0) { - heap->guarded_sample_seed = _mi_heap_random_next(heap); - } heap->guarded_sample_rate = sample_rate; - if (heap->guarded_sample_rate >= 1) { - heap->guarded_sample_seed = heap->guarded_sample_seed % heap->guarded_sample_rate; + heap->guarded_sample_count = sample_rate; // count down samples + if (heap->guarded_sample_rate > 1) { + if (seed == 0) { + seed = _mi_heap_random_next(heap); + } + heap->guarded_sample_count = (seed % heap->guarded_sample_rate) + 1; // start at random count between 1 and `sample_rate` } - heap->guarded_sample_count = 1 + heap->guarded_sample_seed; // count down samples } mi_decl_export void mi_heap_guarded_set_size_bound(mi_heap_t* heap, size_t min, size_t max) { diff --git a/test/main-override-static.c b/test/main-override-static.c index 201dc7e1..3e47874e 100644 --- a/test/main-override-static.c +++ b/test/main-override-static.c @@ -43,7 +43,7 @@ int main() { // corrupt_free(); // block_overflow1(); // block_overflow2(); - // test_canary_leak(); + test_canary_leak(); // test_aslr(); // invalid_free(); // test_reserved();