[compiler-rt] b2b3cb5 - [compiler-rt][rtsan] memffd_create for linux interception. (#132571)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 23 13:37:52 PDT 2025
Author: David CARLIER
Date: 2025-03-23T20:37:48Z
New Revision: b2b3cb5f76f15d38e67f70124d275a5696bfdb83
URL: https://github.com/llvm/llvm-project/commit/b2b3cb5f76f15d38e67f70124d275a5696bfdb83
DIFF: https://github.com/llvm/llvm-project/commit/b2b3cb5f76f15d38e67f70124d275a5696bfdb83.diff
LOG: [compiler-rt][rtsan] memffd_create for linux interception. (#132571)
Added:
Modified:
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Removed:
################################################################################
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
*/
More information about the llvm-commits
mailing list