[compiler-rt] [compiler-rt][rtsan] rename/renameat interception (PR #135884)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 15 16:53:27 PDT 2025
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/135884
None
>From 496b6ae440f149c7d3fb2a4a56b9fce89973c773 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Wed, 16 Apr 2025 00:52:37 +0100
Subject: [PATCH] [compiler-rt][rtsan] rename/renameat interception
---
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 13 +++++++++++++
.../rtsan/tests/rtsan_test_interceptors_posix.cpp | 14 ++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index e8cea21ddf9aa..61fb7585e4bed 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -295,6 +295,17 @@ INTERCEPTOR(int, unlinkat, int fd, const char *pathname, int flag) {
return REAL(unlinkat)(fd, pathname, flag);
}
+INTERCEPTOR(int, rename, const char *oldpath, const char *newpath) {
+ __rtsan_notify_intercepted_call("rename");
+ return REAL(rename)(oldpath, newpath);
+}
+
+INTERCEPTOR(int, renameat, int oldfd, const char *oldpath, int newfd,
+ const char *newpath) {
+ __rtsan_notify_intercepted_call("renameat");
+ return REAL(renameat)(oldfd, oldpath, newfd, newpath);
+}
+
INTERCEPTOR(int, truncate, const char *pathname, off_t length) {
__rtsan_notify_intercepted_call("truncate");
return REAL(truncate)(pathname, length);
@@ -1534,6 +1545,8 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_READLINKAT;
INTERCEPT_FUNCTION(unlink);
INTERCEPT_FUNCTION(unlinkat);
+ INTERCEPT_FUNCTION(rename);
+ INTERCEPT_FUNCTION(renameat);
INTERCEPT_FUNCTION(symlink);
INTERCEPT_FUNCTION(symlinkat);
INTERCEPT_FUNCTION(truncate);
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 048da5858d665..885264a3a7c2e 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -885,6 +885,20 @@ TEST_F(RtsanOpenedFileTest, UnlinkatDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+TEST_F(RtsanOpenedFileTest, RenameDiesWhenRealtime) {
+ auto Func = [&]() { rename(GetTemporaryFilePath(), "/tmp/rename_rtsan"); };
+ ExpectRealtimeDeath(Func, "rename");
+ ExpectNonRealtimeSurvival(Func);
+}
+
+TEST_F(RtsanOpenedFileTest, RenameatDiesWhenRealtime) {
+ auto Func = [&]() {
+ renameat(-1, GetTemporaryFilePath(), -1, "/tmp/renameat_rtsan");
+ };
+ ExpectRealtimeDeath(Func, "renameat");
+ ExpectNonRealtimeSurvival(Func);
+}
+
TEST_F(RtsanOpenedFileTest, TruncateDiesWhenRealtime) {
auto Func = [&]() { truncate(GetTemporaryFilePath(), 16); };
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("truncate"));
More information about the llvm-commits
mailing list