Skip to content

Commit

Permalink
Enable aligned_alloc on macOS (#94298)
Browse files Browse the repository at this point in the history
* Enable aligned_alloc on macOS

Fixes #54296

Co-authored-by: Adeel Mujahid <[email protected]>
  • Loading branch information
jkotas and am11 authored Nov 14, 2023
1 parent ab2d63b commit 475c28e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/native/libs/System.Native/pal_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
void* SystemNative_AlignedAlloc(uintptr_t alignment, uintptr_t size)
{
#if HAVE_ALIGNED_ALLOC
// We want to prefer the standardized aligned_alloc function. However
// it cannot be used on __APPLE__ since we target 10.13 and it was
// only added in 10.15, but we might be compiling on a 10.15 box.
// We want to prefer the standardized aligned_alloc function.
return aligned_alloc(alignment, size);
#elif HAVE_POSIX_MEMALIGN
void* result = NULL;
Expand Down
25 changes: 10 additions & 15 deletions src/native/libs/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -581,23 +581,22 @@ if(CLR_CMAKE_TARGET_IOS)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_MACCATALYST)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
# TODO: test to see if these all actually hold true on Mac Catalyst
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_TVOS)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
set(HAVE_CLOCK_MONOTONIC 1)
set(HAVE_CLOCK_REALTIME 1)
unset(HAVE_FORK) # exists but blocked by kernel
elseif(CLR_CMAKE_TARGET_ANDROID)
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
Expand All @@ -608,14 +607,10 @@ elseif(CLR_CMAKE_TARGET_ANDROID)
elseif(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
set(HAVE_FORK 0)
else()
if(CLR_CMAKE_TARGET_OSX)
unset(HAVE_ALIGNED_ALLOC) # only exists on OSX 10.15+
else()
check_symbol_exists(
aligned_alloc
stdlib.h
HAVE_ALIGNED_ALLOC)
endif()
check_symbol_exists(
aligned_alloc
stdlib.h
HAVE_ALIGNED_ALLOC)

check_c_source_runs(
"
Expand Down

0 comments on commit 475c28e

Please sign in to comment.