Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler-rt/lib/radsan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/radsan/radsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <unistd.h>

extern "C" {

RADSAN_EXPORT void radsan_init() { radsan::initialiseInterceptors(); }

RADSAN_EXPORT void radsan_realtime_enter() {
Expand All @@ -29,4 +30,5 @@ RADSAN_EXPORT void radsan_off() {
RADSAN_EXPORT void radsan_on() {
radsan::getContextForThisThread().bypassPop();
}

}
3 changes: 3 additions & 0 deletions compiler-rt/lib/radsan/radsan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#endif

#if SANITIZER_APPLE
#include <Availability.h>
#include <libkern/OSAtomic.h>
#include <os/lock.h>
#endif
Expand Down Expand Up @@ -261,10 +262,12 @@ INTERCEPTOR(void *, valloc, SIZE_T size) {
return REAL(valloc)(size);
}

#if (!SANITIZER_APPLE || __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_15)
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
radsan::expectNotRealtime("aligned_alloc");
return REAL(aligned_alloc)(alignment, size);
}
#endif

INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) {
radsan::expectNotRealtime("posix_memalign");
Expand Down
5 changes: 0 additions & 5 deletions compiler-rt/lib/radsan/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ 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)
endif()

Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/radsan/tests/radsan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ TEST(TestRadsan, unlockingAMutexDiesWhenRealtime) {
expectNonrealtimeSurvival(func);
}

#if (!SANITIZER_APPLE || __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12)
TEST(TestRadsan, lockingASharedMutexDiesWhenRealtime) {
auto mutex = std::shared_mutex();
auto func = [&]() { mutex.lock(); };
Expand Down Expand Up @@ -127,6 +128,7 @@ TEST(TestRadsan, sharedUnlockingASharedMutexDiesWhenRealtime) {
expectRealtimeDeath(func);
expectNonrealtimeSurvival(func);
}
#endif

TEST(TestRadsan, launchingAThreadDiesWhenRealtime) {
auto func = [&]() {
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ TEST(TestRadsanInterceptors, vallocDiesWhenRealtime) {
expectNonrealtimeSurvival(func);
}

#if (!SANITIZER_APPLE || __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_15)
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) {
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/radsan/tests/radsan_test_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ template <typename Function>
}

template <typename Function>
void expectRealtimeDeath(
Function &&func, std::optional<std::string> intercepted_method_name = {}) {
void expectRealtimeDeath(Function &&func,
std::string intercepted_method_name = {}) {

using namespace testing;

auto expected_error_substr = [&]() -> std::string {
return intercepted_method_name.has_value()
return !intercepted_method_name.empty()
? "Real-time violation: intercepted call to real-time unsafe "
"function `" +
intercepted_method_name.value() + "`"
intercepted_method_name + "`"
: "";
};

Expand Down