diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index f093862462796..b139f628703f9 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -1031,6 +1031,17 @@ INTERCEPTOR(int, shm_unlink, const char *name) { return REAL(shm_unlink)(name); } +#if !SANITIZER_APPLE +// is supported by freebsd too +INTERCEPTOR(int, memfd_create, const char *path, unsigned int flags) { + __rtsan_notify_intercepted_call("memfd_create"); + return REAL(memfd_create)(path, flags); +} +#define RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE INTERCEPT_FUNCTION(memfd_create) +#else +#define RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE +#endif + // Sockets INTERCEPTOR(int, getaddrinfo, const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { @@ -1465,6 +1476,7 @@ void __rtsan::InitializeInterceptors() { INTERCEPT_FUNCTION(mincore); INTERCEPT_FUNCTION(shm_open); INTERCEPT_FUNCTION(shm_unlink); + RTSAN_MAYBE_INTERCEPT_MEMFD_CREATE; RTSAN_MAYBE_INTERCEPT_MEMALIGN; RTSAN_MAYBE_INTERCEPT_PVALLOC; diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp index 9ef6887a9c848..321cc4f0c78f1 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -302,6 +302,14 @@ TEST(TestRtsanInterceptors, ShmUnlinkDiesWhenRealtime) { ExpectNonRealtimeSurvival(Func); } +#if !SANITIZER_APPLE +TEST(TestRtsanInterceptors, MemfdCreateDiesWhenRealtime) { + auto Func = []() { memfd_create("/rtsan_test_memfd_create", MFD_CLOEXEC); }; + ExpectRealtimeDeath(Func, "memfd_create"); + ExpectNonRealtimeSurvival(Func); +} +#endif + /* Sleeping */