From 826918beaa9f941c945aff95f4df273934be3268 Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:52:34 -0800 Subject: [PATCH 1/6] Add aligned alloc behind 10.15 flag --- compiler-rt/lib/radsan/CMakeLists.txt | 1 - compiler-rt/lib/radsan/radsan_interceptors.cpp | 7 ++++++- compiler-rt/lib/radsan/tests/CMakeLists.txt | 4 ---- .../sanitizer_common/sanitizer_platform_interceptors.h | 10 +++++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/radsan/CMakeLists.txt b/compiler-rt/lib/radsan/CMakeLists.txt index c77971b00aa87..1cff9be14e272 100644 --- a/compiler-rt/lib/radsan/CMakeLists.txt +++ b/compiler-rt/lib/radsan/CMakeLists.txt @@ -27,7 +27,6 @@ set(RADSAN_LINK_LIBS ${COMPILER_RT_CXX_LINK_LIBS}) if(APPLE) - list(APPEND RADSAN_CFLAGS -mmacosx-version-min=10.15) add_compiler_rt_object_libraries(RTRadsan OS ${SANITIZER_COMMON_SUPPORTED_OS} ARCHS ${RADSAN_SUPPORTED_ARCH} diff --git a/compiler-rt/lib/radsan/radsan_interceptors.cpp b/compiler-rt/lib/radsan/radsan_interceptors.cpp index 490b3045626b2..42b27b669e10c 100644 --- a/compiler-rt/lib/radsan/radsan_interceptors.cpp +++ b/compiler-rt/lib/radsan/radsan_interceptors.cpp @@ -261,10 +261,15 @@ INTERCEPTOR(void *, valloc, SIZE_T size) { return REAL(valloc)(size); } +#if SANITIZER_INTERCEPT_ALIGNED_ALLOC INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) { radsan::expectNotRealtime("aligned_alloc"); return REAL(aligned_alloc)(alignment, size); } +#define RADSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc) +#else +#define RADSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC +#endif INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) { radsan::expectNotRealtime("posix_memalign"); @@ -330,7 +335,7 @@ void initialiseInterceptors() { INTERCEPT_FUNCTION(realloc); INTERCEPT_FUNCTION(reallocf); INTERCEPT_FUNCTION(valloc); - INTERCEPT_FUNCTION(aligned_alloc); + RADSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC; INTERCEPT_FUNCTION(posix_memalign); INTERCEPT_FUNCTION(open); diff --git a/compiler-rt/lib/radsan/tests/CMakeLists.txt b/compiler-rt/lib/radsan/tests/CMakeLists.txt index 4da5255b53ccc..6454c7f0da045 100644 --- a/compiler-rt/lib/radsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/radsan/tests/CMakeLists.txt @@ -41,10 +41,6 @@ if (APPLE) list(APPEND RADSAN_UNITTEST_LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}) list(APPEND RADSAN_UNITTEST_LINK_FLAGS ${DARWIN_osx_LINK_FLAGS}) list(APPEND RADSAN_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS}) - # aligned_alloc is only available in macOS 10.15 and later. This is a temporary - # solution that we're running with until we have a full understanding of what - # macOS versions we wish to support. - list(APPEND RADSAN_UNITTEST_CFLAGS -mmacosx-version-min=10.15) else() #append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic RADSAN_UNITTEST_LINK_FLAGS) list(APPEND RADSAN_UNITTEST_LINK_FLAGS -latomic) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index c740778b6228f..57e5d1014a23e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -492,7 +492,7 @@ #define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID) #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64) #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX -#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC) +#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!(SI_MAC) || !SI_MAC_DEPLOYMENT_BELOW_10_15) #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD) #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WCSLEN 1 @@ -523,6 +523,14 @@ #else #define SI_MAC_DEPLOYMENT_BELOW_10_10 0 #endif + +#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500 +#define SI_MAC_DEPLOYMENT_BELOW_10_15 1 +#else +#define SI_MAC_DEPLOYMENT_BELOW_10_15 0 +#endif + #define SANITIZER_INTERCEPT_READLINKAT \ (SI_POSIX && !SI_MAC_DEPLOYMENT_BELOW_10_10) From ae1988cab954ffe0f0bfb9b4f8a63714607b1186 Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:18:41 -0800 Subject: [PATCH 2/6] Added tests, fixed compilation errors for older version of OSX --- compiler-rt/lib/radsan/tests/radsan_test.cpp | 14 ++++++++++++++ .../lib/radsan/tests/radsan_test_interceptors.cpp | 3 +++ .../lib/radsan/tests/radsan_test_utilities.h | 9 ++++----- .../sanitizer_platform_interceptors.h | 9 +++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/compiler-rt/lib/radsan/tests/radsan_test.cpp b/compiler-rt/lib/radsan/tests/radsan_test.cpp index 7d3e0c5540ff0..a90dd96a52936 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test.cpp +++ b/compiler-rt/lib/radsan/tests/radsan_test.cpp @@ -11,6 +11,7 @@ #include "radsan_test_utilities.h" #include #include +#include #include #include @@ -98,6 +99,9 @@ TEST(TestRadsan, unlockingAMutexDiesWhenRealtime) { expectNonrealtimeSurvival(func); } + +#if SANITIZER_INTERCEPT_SHARED_MUTEX + TEST(TestRadsan, lockingASharedMutexDiesWhenRealtime) { auto mutex = std::shared_mutex(); auto func = [&]() { mutex.lock(); }; @@ -128,6 +132,8 @@ TEST(TestRadsan, sharedUnlockingASharedMutexDiesWhenRealtime) { expectNonrealtimeSurvival(func); } +#endif // SANITIZER_INTERCEPT_SHARED_MUTEX + TEST(TestRadsan, launchingAThreadDiesWhenRealtime) { auto func = [&]() { auto t = std::thread([]() {}); @@ -181,6 +187,14 @@ TEST(TestRadsan, printfDiesWhenRealtime) { expectNonrealtimeSurvival(func); } +#if SANITIZER_INTERCEPT_ALIGNED_ALLOC +TEST(TestRadsan, alignedAllocDiesWhenRealtime) { + auto func = []() { auto ptr = aligned_alloc(16, 16); }; + expectRealtimeDeath(func); + expectNonrealtimeSurvival(func); +} +#endif + TEST(TestRadsan, throwingAnExceptionDiesWhenRealtime) { auto func = [&]() { try { diff --git a/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp b/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp index b7d8286cfb4c9..47782c53cffa0 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp +++ b/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp @@ -9,6 +9,7 @@ #include "gtest/gtest.h" #include +#include #include "radsan_test_utilities.h" @@ -66,11 +67,13 @@ TEST(TestRadsanInterceptors, vallocDiesWhenRealtime) { expectNonrealtimeSurvival(func); } +#if SANITIZER_INTERCEPT_ALIGNED_ALLOC TEST(TestRadsanInterceptors, alignedAllocDiesWhenRealtime) { auto func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); }; expectRealtimeDeath(func, "aligned_alloc"); expectNonrealtimeSurvival(func); } +#endif // free_sized and free_aligned_sized (both C23) are not yet supported TEST(TestRadsanInterceptors, freeDiesWhenRealtime) { diff --git a/compiler-rt/lib/radsan/tests/radsan_test_utilities.h b/compiler-rt/lib/radsan/tests/radsan_test_utilities.h index d7db09816b2e7..8a5c674b8065d 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test_utilities.h +++ b/compiler-rt/lib/radsan/tests/radsan_test_utilities.h @@ -9,8 +9,7 @@ #pragma once #include "gmock/gmock.h" - -#include +#include namespace radsan_testing { @@ -21,15 +20,15 @@ template template void expectRealtimeDeath( - Function &&func, std::optional intercepted_method_name = {}) { + Function &&func, const char* intercepted_method_name = nullptr) { using namespace testing; auto expected_error_substr = [&]() -> std::string { - return intercepted_method_name.has_value() + return intercepted_method_name != nullptr ? "Real-time violation: intercepted call to real-time unsafe " "function `" + - intercepted_method_name.value() + "`" + std::string(intercepted_method_name) + "`" : ""; }; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 57e5d1014a23e..a3c34267fe2ce 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -493,6 +493,7 @@ #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64) #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!(SI_MAC) || !SI_MAC_DEPLOYMENT_BELOW_10_15) +#define SANITIZER_INTERCEPT_SHARED_MUTEX (!(SI_MAC) || !SI_MAC_DEPLOYMENT_BELOW_10_12) #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD) #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WCSLEN 1 @@ -524,6 +525,14 @@ #define SI_MAC_DEPLOYMENT_BELOW_10_10 0 #endif +#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200 +#define SI_MAC_DEPLOYMENT_BELOW_10_12 1 +#else +#define SI_MAC_DEPLOYMENT_BELOW_10_12 0 +#endif + + #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500 #define SI_MAC_DEPLOYMENT_BELOW_10_15 1 From 67f4bbcf94897b1a93aabd92393c66787d5b6261 Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:51:21 -0800 Subject: [PATCH 3/6] All tests pass on 10.15 --- compiler-rt/cmake/config-ix.cmake | 5 +---- compiler-rt/lib/radsan/radsan_interceptors.cpp | 1 + compiler-rt/lib/radsan/tests/radsan_test.cpp | 2 +- .../sanitizer_platform_interceptors.h | 16 ++++++++-------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index 87701a83b8fbd..d9da538b1d8d6 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -458,13 +458,10 @@ if(APPLE) else() set(SANITIZER_MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION}) endif() + if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7") message(FATAL_ERROR "macOS deployment target '${SANITIZER_MIN_OSX_VERSION}' is too old.") endif() - if(SANITIZER_MIN_OSX_VERSION VERSION_GREATER ${DEFAULT_SANITIZER_MIN_OSX_VERSION}) - message(WARNING "macOS deployment target '${SANITIZER_MIN_OSX_VERSION}' is too new, setting to '${DEFAULT_SANITIZER_MIN_OSX_VERSION}' instead.") - set(SANITIZER_MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION}) - endif() endif() # We're setting the flag manually for each target OS diff --git a/compiler-rt/lib/radsan/radsan_interceptors.cpp b/compiler-rt/lib/radsan/radsan_interceptors.cpp index 42b27b669e10c..4fce565e502dd 100644 --- a/compiler-rt/lib/radsan/radsan_interceptors.cpp +++ b/compiler-rt/lib/radsan/radsan_interceptors.cpp @@ -9,6 +9,7 @@ #include "radsan/radsan_interceptors.h" #include "sanitizer_common/sanitizer_platform.h" +#include "sanitizer_common/sanitizer_platform_interceptors.h" #include "interception/interception.h" #include "radsan/radsan_context.h" diff --git a/compiler-rt/lib/radsan/tests/radsan_test.cpp b/compiler-rt/lib/radsan/tests/radsan_test.cpp index a90dd96a52936..140ce20e20179 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test.cpp +++ b/compiler-rt/lib/radsan/tests/radsan_test.cpp @@ -189,7 +189,7 @@ TEST(TestRadsan, printfDiesWhenRealtime) { #if SANITIZER_INTERCEPT_ALIGNED_ALLOC TEST(TestRadsan, alignedAllocDiesWhenRealtime) { - auto func = []() { auto ptr = aligned_alloc(16, 16); }; + auto func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 16)); }; expectRealtimeDeath(func); expectNonrealtimeSurvival(func); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index a3c34267fe2ce..4f19b45216b57 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -492,8 +492,8 @@ #define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID) #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64) #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX -#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!(SI_MAC) || !SI_MAC_DEPLOYMENT_BELOW_10_15) -#define SANITIZER_INTERCEPT_SHARED_MUTEX (!(SI_MAC) || !SI_MAC_DEPLOYMENT_BELOW_10_12) +#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!(SI_MAC) || SI_MAC_DEPLOYMENT_AT_LEAST_10_15) +#define SANITIZER_INTERCEPT_SHARED_MUTEX (!(SI_MAC) || SI_MAC_DEPLOYMENT_AT_LEAST_10_12) #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD) #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WCSLEN 1 @@ -526,18 +526,18 @@ #endif #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101200 -#define SI_MAC_DEPLOYMENT_BELOW_10_12 1 + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 101200 +#define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 1 #else -#define SI_MAC_DEPLOYMENT_BELOW_10_12 0 +#define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 0 #endif #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101500 -#define SI_MAC_DEPLOYMENT_BELOW_10_15 1 + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 101500 +#define SI_MAC_DEPLOYMENT_AT_LEAST_10_15 1 #else -#define SI_MAC_DEPLOYMENT_BELOW_10_15 0 +#define SI_MAC_DEPLOYMENT_AT_LEAST_10_15 0 #endif #define SANITIZER_INTERCEPT_READLINKAT \ From 2713b4311e5cd363dfc22ee507200fdab4d7743f Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Mon, 4 Dec 2023 11:27:09 -0800 Subject: [PATCH 4/6] Fix 'at least' macros, test --- compiler-rt/cmake/config-ix.cmake | 16 +++++++++++----- .../sanitizer_platform_interceptors.h | 5 ++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index d9da538b1d8d6..5c671dee94401 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -446,22 +446,28 @@ if(APPLE) # Note: In order to target x86_64h on OS X the minimum deployment target must # be 10.8 or higher. + set(SANITIZER_MIN_OSX_VERSION "" CACHE STRING + "Minimum OS X version to target (e.g. 10.15) for sanitizers.") + set(DEFAULT_SANITIZER_MIN_OSX_VERSION 10.10) set(DARWIN_osx_MIN_VER_FLAG "-mmacosx-version-min") - if(NOT SANITIZER_MIN_OSX_VERSION) + if(SANITIZER_MIN_OSX_VERSION STREQUAL "") string(REGEX MATCH "${DARWIN_osx_MIN_VER_FLAG}=([.0-9]+)" MACOSX_VERSION_MIN_FLAG "${CMAKE_CXX_FLAGS}") if(MACOSX_VERSION_MIN_FLAG) - set(SANITIZER_MIN_OSX_VERSION "${CMAKE_MATCH_1}") + set(MIN_OSX_VERSION "${CMAKE_MATCH_1}") elseif(CMAKE_OSX_DEPLOYMENT_TARGET) - set(SANITIZER_MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET}) + set(MIN_OSX_VERSION ${CMAKE_OSX_DEPLOYMENT_TARGET}) else() - set(SANITIZER_MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION}) + set(MIN_OSX_VERSION ${DEFAULT_SANITIZER_MIN_OSX_VERSION}) endif() - if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7") + if(MIN_OSX_VERSION VERSION_LESS "10.7") message(FATAL_ERROR "macOS deployment target '${SANITIZER_MIN_OSX_VERSION}' is too old.") endif() + + set(SANITIZER_MIN_OSX_VERSION "${MIN_OSX_VERSION}" CACHE STRING + "Minimum OS X version to target (e.g. 10.15) for sanitizers." FORCE) endif() # We're setting the flag manually for each target OS diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index 4f19b45216b57..fb10e30718fc1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -526,15 +526,14 @@ #endif #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 101200 + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200 #define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 1 #else #define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 0 #endif - #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 101500 + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 #define SI_MAC_DEPLOYMENT_AT_LEAST_10_15 1 #else #define SI_MAC_DEPLOYMENT_AT_LEAST_10_15 0 From 27842a0a651cd3455f8a55ae29d725ba10843c3b Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:55:40 -0800 Subject: [PATCH 5/6] Moving aligned_alloc out of the higher level tests --- compiler-rt/lib/radsan/tests/radsan_test.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compiler-rt/lib/radsan/tests/radsan_test.cpp b/compiler-rt/lib/radsan/tests/radsan_test.cpp index 140ce20e20179..f4255d0416b69 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test.cpp +++ b/compiler-rt/lib/radsan/tests/radsan_test.cpp @@ -187,14 +187,6 @@ TEST(TestRadsan, printfDiesWhenRealtime) { expectNonrealtimeSurvival(func); } -#if SANITIZER_INTERCEPT_ALIGNED_ALLOC -TEST(TestRadsan, alignedAllocDiesWhenRealtime) { - auto func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 16)); }; - expectRealtimeDeath(func); - expectNonrealtimeSurvival(func); -} -#endif - TEST(TestRadsan, throwingAnExceptionDiesWhenRealtime) { auto func = [&]() { try { From d6b6a42ce6560f0a82e529e7e5397eb04f212178 Mon Sep 17 00:00:00 2001 From: Chris Apple <14171107+cjappl@users.noreply.github.com> Date: Tue, 5 Dec 2023 08:00:49 -0800 Subject: [PATCH 6/6] Review comments pt. 1 --- compiler-rt/lib/radsan/tests/radsan_test.cpp | 13 +++++++++++-- .../sanitizer_platform_interceptors.h | 8 -------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler-rt/lib/radsan/tests/radsan_test.cpp b/compiler-rt/lib/radsan/tests/radsan_test.cpp index f4255d0416b69..7ca7ec8eee87b 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test.cpp +++ b/compiler-rt/lib/radsan/tests/radsan_test.cpp @@ -21,6 +21,15 @@ #include #include +#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200 +#define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 1 +#else +#define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 0 +#endif + +#define RADSAN_TEST_SHARED_MUTEX (!(SI_MAC) || SI_MAC_DEPLOYMENT_AT_LEAST_10_12) + using namespace testing; using namespace radsan_testing; using namespace std::chrono_literals; @@ -100,7 +109,7 @@ TEST(TestRadsan, unlockingAMutexDiesWhenRealtime) { } -#if SANITIZER_INTERCEPT_SHARED_MUTEX +#if RADSAN_TEST_SHARED_MUTEX TEST(TestRadsan, lockingASharedMutexDiesWhenRealtime) { auto mutex = std::shared_mutex(); @@ -132,7 +141,7 @@ TEST(TestRadsan, sharedUnlockingASharedMutexDiesWhenRealtime) { expectNonrealtimeSurvival(func); } -#endif // SANITIZER_INTERCEPT_SHARED_MUTEX +#endif // RADSAN_TEST_SHARED_MUTEX TEST(TestRadsan, launchingAThreadDiesWhenRealtime) { auto func = [&]() { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h index fb10e30718fc1..8816ea35fc3aa 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -493,7 +493,6 @@ #define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64) #define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX #define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!(SI_MAC) || SI_MAC_DEPLOYMENT_AT_LEAST_10_15) -#define SANITIZER_INTERCEPT_SHARED_MUTEX (!(SI_MAC) || SI_MAC_DEPLOYMENT_AT_LEAST_10_12) #define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD) #define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID #define SANITIZER_INTERCEPT_WCSLEN 1 @@ -525,13 +524,6 @@ #define SI_MAC_DEPLOYMENT_BELOW_10_10 0 #endif -#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ - __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200 -#define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 1 -#else -#define SI_MAC_DEPLOYMENT_AT_LEAST_10_12 0 -#endif - #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 #define SI_MAC_DEPLOYMENT_AT_LEAST_10_15 1