From 764aa44598f3669952ce65d064f14ac725671116 Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 19 Apr 2024 09:38:40 -0700 Subject: [PATCH 1/3] remove macOS preprocessor macros that do not exist (anymore). issue #879 --- src/prim/unix/prim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index 87ad63b1..9c4ecd4b 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -42,8 +42,8 @@ terms of the MIT license. A copy of the license can be found in the file #elif defined(__APPLE__) #include #include - #if !TARGET_IOS_IPHONE && !TARGET_IOS_SIMULATOR - #include + #if !defined(TARGET_OS_OSX) || TARGET_OS_OSX // see issue #879, used to be (!TARGET_IOS_IPHONE && !TARGET_IOS_SIMULATOR) + #include // VM_MAKE_TAG, VM_FLAGS_SUPERPAGE_SIZE_2MB, etc. #endif #if !defined(MAC_OS_X_VERSION_10_7) #define MAC_OS_X_VERSION_10_7 1070 From 06b510c42d23e19602c595e5172bd7363a73714d Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 19 Apr 2024 09:41:24 -0700 Subject: [PATCH 2/3] fix build pipeline for ASAN --- test/test-api.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test-api.c b/test/test-api.c index 6dd2bc7f..8b6378bf 100644 --- a/test/test-api.c +++ b/test/test-api.c @@ -295,11 +295,13 @@ int main(void) { // --------------------------------------------------- // various // --------------------------------------------------- + #if !defined(MI_TRACK_ASAN) // realpath may leak with ASAN enabled (as the ASAN allocator intercepts it) CHECK_BODY("realpath") { char* s = mi_realpath( ".", NULL ); // printf("realpath: %s\n",s); mi_free(s); }; + #endif CHECK("stl_allocator1", test_stl_allocator1()); CHECK("stl_allocator2", test_stl_allocator2()); From 5050b630389bb4d2013d1e82cc1b2c2d9b65b963 Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 19 Apr 2024 09:53:21 -0700 Subject: [PATCH 3/3] define MI_MAX_ALLOC_SIZE as PTRDIFF_MAX (related to #877) --- include/mimalloc/types.h | 2 ++ src/page.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index adfd7838..5d219d68 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -195,6 +195,8 @@ typedef int32_t mi_ssize_t; // Alignments over MI_BLOCK_ALIGNMENT_MAX are allocated in dedicated huge page segments #define MI_BLOCK_ALIGNMENT_MAX (MI_SEGMENT_SIZE >> 1) +// we never allocate more than PTRDIFF_MAX (see also ) +#define MI_MAX_ALLOC_SIZE PTRDIFF_MAX // ------------------------------------------------------ // Mimalloc pages contain allocated blocks diff --git a/src/page.c b/src/page.c index efcd8d91..3b3ba2f9 100644 --- a/src/page.c +++ b/src/page.c @@ -857,7 +857,7 @@ static mi_page_t* mi_find_page(mi_heap_t* heap, size_t size, size_t huge_alignme // huge allocation? const size_t req_size = size - MI_PADDING_SIZE; // correct for padding_size in case of an overflow on `size` if mi_unlikely(req_size > (MI_LARGE_OBJ_SIZE_MAX - MI_PADDING_SIZE) || huge_alignment > 0) { - if mi_unlikely(req_size > PTRDIFF_MAX) { // we don't allocate more than PTRDIFF_MAX (see ) + if mi_unlikely(req_size > MI_MAX_ALLOC_SIZE) { _mi_error_message(EOVERFLOW, "allocation request is too large (%zu bytes)\n", req_size); return NULL; }