Compare commits

...

5 commits

Author SHA1 Message Date
Eduard Voronkin
48304258b2
Merge 7023c205aa into fae61ed946 2025-04-14 10:09:15 +02:00
Daan
fae61ed946 fix assertion in mi_free_size (issue #754) 2025-04-13 19:56:49 -07:00
Daan
a5298dd48f Merge remote-tracking branch 'refs/remotes/origin/dev' into dev 2025-04-13 19:50:59 -07:00
Daan
7543e8989a validate pointer before assertion in mi_free_size (issue #754) 2025-04-13 19:49:47 -07:00
Eduard Voronkin
7023c205aa improve MacOS interposes to make mimalloc compile for older MacOS
I've got a failure while trying to compile with "-mmacosx-version-min=10.7" since MAC_OS_X_VERSION_MAX_ALLOWED is greater than MAC_OS_X_VERSION_10_15 but still we can't use `aligned_alloc` since of the lower bound (10.7).
I'm not sure about internal details of how `__OSX_AVAILABLE` works, but my hope is the it would only make this interpose available starting from the OS version specified.
Also, it helps me to compile mimalloc with "-mmacosx-version-min=10.7".
2025-03-06 10:26:22 -08:00
2 changed files with 13 additions and 7 deletions

View file

@ -77,18 +77,12 @@ typedef void* mi_nothrow_t;
MI_INTERPOSE_MI(calloc),
MI_INTERPOSE_MI(realloc),
MI_INTERPOSE_MI(strdup),
#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
MI_INTERPOSE_MI(strndup),
#endif
MI_INTERPOSE_MI(realpath),
MI_INTERPOSE_MI(posix_memalign),
MI_INTERPOSE_MI(reallocf),
MI_INTERPOSE_MI(valloc),
MI_INTERPOSE_FUN(malloc_size,mi_malloc_size_checked),
MI_INTERPOSE_MI(malloc_good_size),
#if defined(MAC_OS_X_VERSION_10_15) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_15
MI_INTERPOSE_MI(aligned_alloc),
#endif
#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),
@ -99,6 +93,15 @@ typedef void* mi_nothrow_t;
MI_INTERPOSE_FUN(vfree,mi_cfree),
#endif
};
__attribute__((used)) static struct mi_interpose_s _mi_interposes_10_7[]
__attribute__((section("__DATA, __interpose"))) __OSX_AVAILABLE(10.7) = {
MI_INTERPOSE_MI(strndup),
};
__attribute__((used)) static struct mi_interpose_s _mi_interposes_10_15[]
__attribute__((section("__DATA, __interpose"))) __OSX_AVAILABLE(10.15) = {
MI_INTERPOSE_MI(aligned_alloc),
};
#ifdef __cplusplus
extern "C" {

View file

@ -340,7 +340,10 @@ mi_decl_nodiscard size_t mi_usable_size(const void* p) mi_attr_noexcept {
void mi_free_size(void* p, size_t size) mi_attr_noexcept {
MI_UNUSED_RELEASE(size);
mi_assert(p == NULL || size <= _mi_usable_size(p,"mi_free_size"));
#if MI_DEBUG
const size_t available = _mi_usable_size(p,"mi_free_size");
mi_assert(p == NULL || size <= available || available == 0 /* invalid pointer */ );
#endif
mi_free(p);
}