Skip to content

Commit 475c28e

Browse files
jkotasam11
andauthored
Enable aligned_alloc on macOS (#94298)
* Enable aligned_alloc on macOS Fixes #54296 Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
1 parent ab2d63b commit 475c28e

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/native/libs/System.Native/pal_memory.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
void* SystemNative_AlignedAlloc(uintptr_t alignment, uintptr_t size)
2727
{
2828
#if HAVE_ALIGNED_ALLOC
29-
// We want to prefer the standardized aligned_alloc function. However
30-
// it cannot be used on __APPLE__ since we target 10.13 and it was
31-
// only added in 10.15, but we might be compiling on a 10.15 box.
29+
// We want to prefer the standardized aligned_alloc function.
3230
return aligned_alloc(alignment, size);
3331
#elif HAVE_POSIX_MEMALIGN
3432
void* result = NULL;

src/native/libs/configure.cmake

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -581,23 +581,22 @@ if(CLR_CMAKE_TARGET_IOS)
581581
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
582582
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
583583
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
584-
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
585-
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
584+
set(HAVE_CLOCK_MONOTONIC 1)
585+
set(HAVE_CLOCK_REALTIME 1)
586586
unset(HAVE_FORK) # exists but blocked by kernel
587587
elseif(CLR_CMAKE_TARGET_MACCATALYST)
588588
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
589-
# TODO: test to see if these all actually hold true on Mac Catalyst
590589
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
591590
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
592-
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
593-
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
591+
set(HAVE_CLOCK_MONOTONIC 1)
592+
set(HAVE_CLOCK_REALTIME 1)
594593
unset(HAVE_FORK) # exists but blocked by kernel
595594
elseif(CLR_CMAKE_TARGET_TVOS)
596595
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
597596
unset(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP)
598597
unset(HAVE_ALIGNED_ALLOC) # only exists on iOS 13+
599-
unset(HAVE_CLOCK_MONOTONIC) # only exists on iOS 10+
600-
unset(HAVE_CLOCK_REALTIME) # only exists on iOS 10+
598+
set(HAVE_CLOCK_MONOTONIC 1)
599+
set(HAVE_CLOCK_REALTIME 1)
601600
unset(HAVE_FORK) # exists but blocked by kernel
602601
elseif(CLR_CMAKE_TARGET_ANDROID)
603602
# Manually set results from check_c_source_runs() since it's not possible to actually run it during CMake configure checking
@@ -608,14 +607,10 @@ elseif(CLR_CMAKE_TARGET_ANDROID)
608607
elseif(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
609608
set(HAVE_FORK 0)
610609
else()
611-
if(CLR_CMAKE_TARGET_OSX)
612-
unset(HAVE_ALIGNED_ALLOC) # only exists on OSX 10.15+
613-
else()
614-
check_symbol_exists(
615-
aligned_alloc
616-
stdlib.h
617-
HAVE_ALIGNED_ALLOC)
618-
endif()
610+
check_symbol_exists(
611+
aligned_alloc
612+
stdlib.h
613+
HAVE_ALIGNED_ALLOC)
619614

620615
check_c_source_runs(
621616
"

0 commit comments

Comments
 (0)