From 910eb728a3865d03d46997e8db966408f096b960 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Tue, 18 Jan 2022 11:34:51 +1300 Subject: [PATCH 1/2] macos: fix error due to const argument to mi_atomic_load_relaxed: - error: address argument to atomic operation must be a pointer to non-const _Atomic type ('const _Atomic(mi_threadid_t) *' invalid) --- src/alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alloc.c b/src/alloc.c index d9b6dd609..6367c074a 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -486,7 +486,7 @@ void mi_free(void* p) mi_attr_noexcept mi_page_t* const page = _mi_segment_page_of(segment, p); mi_block_t* const block = (mi_block_t*)p; - if (mi_likely(tid == mi_atomic_load_relaxed(&segment->thread_id) && page->flags.full_aligned == 0)) { // the thread id matches and it is not a full page, nor has aligned blocks + if (mi_likely(tid == mi_atomic_load_relaxed((_Atomic(mi_threadid_t)*)&segment->thread_id) && page->flags.full_aligned == 0)) { // the thread id matches and it is not a full page, nor has aligned blocks // local, and not full or aligned if (mi_unlikely(mi_check_is_double_free(page,block))) return; mi_check_padding(page, block); From ca64e30a6d3b3b9d60d48d00ba777a4c6de74a8b Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Tue, 18 Jan 2022 11:36:02 +1300 Subject: [PATCH 2/2] macos: aligned_alloc function and claimed_address field not present - aligned_alloc is not present on macos. comment to suppress warning. - claimed_address is not present until macos_10.14. add appropriate preprocessor guard around zone_claimed_address function and assignment. --- src/alloc-override-osx.c | 10 +++++++--- src/alloc-override.c | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/alloc-override-osx.c b/src/alloc-override-osx.c index 63297c4c9..2c6f37adc 100644 --- a/src/alloc-override-osx.c +++ b/src/alloc-override-osx.c @@ -110,11 +110,13 @@ static void zone_free_definite_size(malloc_zone_t* zone, void* p, size_t size) { zone_free(zone,p); } +#if defined(MAC_OS_X_VERSION_10_14) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 static boolean_t zone_claimed_address(malloc_zone_t* zone, void* p) { MI_UNUSED(zone); return mi_is_in_heap_region(p); } - +#endif /* ------------------------------------------------------ Introspection members @@ -211,12 +213,14 @@ static malloc_zone_t mi_malloc_zone = { .batch_malloc = &zone_batch_malloc, .batch_free = &zone_batch_free, .introspect = &mi_introspect, -#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 +#if defined(MAC_OS_X_VERSION_10_6) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 // switch to version 9+ on OSX 10.6 to support memalign. .memalign = &zone_memalign, .free_definite_size = &zone_free_definite_size, .pressure_relief = &zone_pressure_relief, - #if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + #if defined(MAC_OS_X_VERSION_10_14) && \ + MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14 .claimed_address = &zone_claimed_address, .version = 10 #else diff --git a/src/alloc-override.c b/src/alloc-override.c index 42fecbb3f..d78285a73 100644 --- a/src/alloc-override.c +++ b/src/alloc-override.c @@ -77,7 +77,7 @@ typedef struct mi_nothrow_s { int _tag; } mi_nothrow_t; MI_INTERPOSE_MI(valloc), MI_INTERPOSE_MI(malloc_size), MI_INTERPOSE_MI(malloc_good_size), - MI_INTERPOSE_MI(aligned_alloc), + //MI_INTERPOSE_MI(aligned_alloc), #ifdef MI_OSX_ZONE // we interpose malloc_default_zone in alloc-override-osx.c so we can use mi_free safely MI_INTERPOSE_MI(free),