diff --git a/compiler-rt/lib/radsan/radsan_interceptors.cpp b/compiler-rt/lib/radsan/radsan_interceptors.cpp index 4fce565e502dd..53f28f0e98269 100644 --- a/compiler-rt/lib/radsan/radsan_interceptors.cpp +++ b/compiler-rt/lib/radsan/radsan_interceptors.cpp @@ -23,6 +23,10 @@ #include #endif +#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC +#include +#endif + #include #include #include @@ -277,6 +281,20 @@ INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) { return REAL(posix_memalign)(memptr, alignment, size); } +#if SANITIZER_INTERCEPT_MEMALIGN +INTERCEPTOR(void *, memalign, size_t alignment, size_t size) { + radsan::expectNotRealtime("memalign"); + return REAL(memalign)(alignment, size); +} +#endif + +#if SANITIZER_INTERCEPT_PVALLOC +INTERCEPTOR(void *, pvalloc, size_t size) { + radsan::expectNotRealtime("pvalloc"); + return REAL(pvalloc)(size); +} +#endif + /* Sockets */ @@ -338,6 +356,12 @@ void initialiseInterceptors() { INTERCEPT_FUNCTION(valloc); RADSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC; INTERCEPT_FUNCTION(posix_memalign); +#if SANITIZER_INTERCEPT_MEMALIGN + INTERCEPT_FUNCTION(memalign); +#endif +#if SANITIZER_INTERCEPT_PVALLOC + INTERCEPT_FUNCTION(pvalloc); +#endif INTERCEPT_FUNCTION(open); INTERCEPT_FUNCTION(openat); diff --git a/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp b/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp index 0881d452cf6fe..183306a18726d 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp +++ b/compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp @@ -18,6 +18,10 @@ #include #endif +#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC +#include +#endif + #include #include #include @@ -116,6 +120,22 @@ TEST(TestRadsanInterceptors, posixMemalignDiesWhenRealtime) { expectNonrealtimeSurvival(func); } +#if SANITIZER_INTERCEPT_MEMALIGN +TEST(TestRadsanInterceptors, memalignDiesWhenRealtime) { + auto func = []() { EXPECT_NE(memalign(2, 2048), nullptr); }; + expectRealtimeDeath(func, "memalign"); + expectNonrealtimeSurvival(func); +} +#endif + +#if SANITIZER_INTERCEPT_PVALLOC +TEST(TestRadsanInterceptors, pvallocDiesWhenRealtime) { + auto func = []() { EXPECT_NE(pvalloc(2048), nullptr); }; + expectRealtimeDeath(func, "pvalloc"); + expectNonrealtimeSurvival(func); +} +#endif + /* Sleeping */ diff --git a/compiler-rt/lib/radsan/tests/radsan_test_utilities.h b/compiler-rt/lib/radsan/tests/radsan_test_utilities.h index 8a5c674b8065d..fb50ee77156e9 100644 --- a/compiler-rt/lib/radsan/tests/radsan_test_utilities.h +++ b/compiler-rt/lib/radsan/tests/radsan_test_utilities.h @@ -19,8 +19,8 @@ template } template -void expectRealtimeDeath( - Function &&func, const char* intercepted_method_name = nullptr) { +void expectRealtimeDeath(Function &&func, + const char *intercepted_method_name = nullptr) { using namespace testing;