Skip to content
Merged
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
24 changes: 24 additions & 0 deletions compiler-rt/lib/radsan/radsan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <os/lock.h>
#endif

#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC
#include <malloc.h>
#endif

#include <fcntl.h>
#include <pthread.h>
#include <stdarg.h>
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <os/lock.h>
#endif

#if SANITIZER_INTERCEPT_MEMALIGN || SANITIZER_INTERCEPT_PVALLOC
#include <malloc.h>
#endif

#include <atomic>
#include <chrono>
#include <thread>
Expand Down Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a general sense of what we want the "full compilation test" vs these unit tests? When is it necessary to have a full lit test vs just having these unit tests?

May be good to standardize around when we think both are necessary. (this is outside of the scope of this review, and does not block it)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - I think this warrants a proper discussion. Maximising both test coverage and maintainability is a delicate art form! I do have an opinion that is best expressed in the form of some analogies - but it'll be easiest to explain on a call. Let's schedule a time!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it to the list for our next chat :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Looking forward to hearing your opinions too of course!

}
#endif

/*
Sleeping
*/
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/radsan/tests/radsan_test_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ template <typename Function>
}

template <typename Function>
void expectRealtimeDeath(
Function &&func, const char* intercepted_method_name = nullptr) {
void expectRealtimeDeath(Function &&func,
const char *intercepted_method_name = nullptr) {

using namespace testing;

Expand Down