[compiler-rt] a8fb2d0 - [compiler-rt][rtsan] adding unlink/unlinkat interception. (#128292)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 23 01:17:52 PST 2025


Author: David CARLIER
Date: 2025-02-23T09:17:48Z
New Revision: a8fb2d0c1c0d7fd719dd8078bc1c52214298ace1

URL: https://github.com/llvm/llvm-project/commit/a8fb2d0c1c0d7fd719dd8078bc1c52214298ace1
DIFF: https://github.com/llvm/llvm-project/commit/a8fb2d0c1c0d7fd719dd8078bc1c52214298ace1.diff

LOG: [compiler-rt][rtsan] adding unlink/unlinkat interception. (#128292)

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 410da0748b433..5b9e992639f55 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -275,6 +275,16 @@ INTERCEPTOR(ssize_t, readlinkat, int dirfd, const char *pathname, char *buf,
 #define RTSAN_MAYBE_INTERCEPT_READLINKAT
 #endif
 
+INTERCEPTOR(int, unlink, const char *pathname) {
+  __rtsan_notify_intercepted_call("unlink");
+  return REAL(unlink)(pathname);
+}
+
+INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
+  __rtsan_notify_intercepted_call("unlinkat");
+  return REAL(unlinkat)(fd, pathname, flag);
+}
+
 // Streams
 
 INTERCEPTOR(FILE *, fopen, const char *path, const char *mode) {
@@ -1425,6 +1435,8 @@ void __rtsan::InitializeInterceptors() {
   INTERCEPT_FUNCTION(fchdir);
   RTSAN_MAYBE_INTERCEPT_READLINK;
   RTSAN_MAYBE_INTERCEPT_READLINKAT;
+  INTERCEPT_FUNCTION(unlink);
+  INTERCEPT_FUNCTION(unlinkat);
   INTERCEPT_FUNCTION(fopen);
   RTSAN_MAYBE_INTERCEPT_FOPEN64;
   RTSAN_MAYBE_INTERCEPT_FREOPEN64;

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 98d27caae94b8..d1c5a94c12213 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -863,6 +863,18 @@ TEST_F(RtsanOpenedFileTest, FwriteDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }
 
+TEST_F(RtsanOpenedFileTest, UnlinkDiesWhenRealtime) {
+  auto Func = [&]() { unlink(GetTemporaryFilePath()); };
+  ExpectRealtimeDeath(Func, "unlink");
+  ExpectNonRealtimeSurvival(Func);
+}
+
+TEST_F(RtsanOpenedFileTest, UnlinkatDiesWhenRealtime) {
+  auto Func = [&]() { unlinkat(0, GetTemporaryFilePath(), 0); };
+  ExpectRealtimeDeath(Func, "unlinkat");
+  ExpectNonRealtimeSurvival(Func);
+}
+
 TEST_F(RtsanFileTest, FcloseDiesWhenRealtime) {
   FILE *f = fopen(GetTemporaryFilePath(), "w");
   EXPECT_THAT(f, Ne(nullptr));


        


More information about the llvm-commits mailing list