[compiler-rt] [compiler-rt][rtsan] pathconf/fpathconf interception. (PR #134495)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 5 05:57:34 PDT 2025


https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/134495

None

>From f59fffdfbcee3bedac3ba7b3c9a1be1db516d876 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 5 Apr 2025 13:56:37 +0100
Subject: [PATCH] [compiler-rt][rtsan] pathconf/fpathconf interception.

---
 compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp   | 12 ++++++++++++
 .../rtsan/tests/rtsan_test_interceptors_posix.cpp    | 12 ++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index e8cea21ddf9aa..7c7c7e138a652 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -712,6 +712,16 @@ INTERCEPTOR(mode_t, umask, mode_t cmask) {
   return REAL(umask)(cmask);
 }
 
+INTERCEPTOR(long, pathconf, const char *path, int name) {
+  __rtsan_notify_intercepted_call("pathconf");
+  return REAL(pathconf)(path, name);
+}
+
+INTERCEPTOR(long, fpathconf, int fildes, int name) {
+  __rtsan_notify_intercepted_call("fpathconf");
+  return REAL(fpathconf)(fildes, name);
+}
+
 // Concurrency
 #if SANITIZER_APPLE
 #pragma clang diagnostic push
@@ -1596,6 +1606,8 @@ void __rtsan::InitializeInterceptors() {
   INTERCEPT_FUNCTION(mkdir);
   INTERCEPT_FUNCTION(rmdir);
   INTERCEPT_FUNCTION(umask);
+  INTERCEPT_FUNCTION(pathconf);
+  INTERCEPT_FUNCTION(fpathconf);
   INTERCEPT_FUNCTION(ioctl);
 
   RTSAN_MAYBE_INTERCEPT_OSSPINLOCKLOCK;
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..dd55da54f8646 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -793,6 +793,18 @@ TEST_F(RtsanOpenedFileTest, FchmodDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }
 
+TEST_F(RtsanFileTest, PathconfDiesWhenRealtime) {
+  auto Func = [this]() { pathconf(GetTemporaryFilePath(), _PC_LINK_MAX); };
+  ExpectRealtimeDeath(Func, "pathconf");
+  ExpectNonRealtimeSurvival(Func);
+}
+
+TEST_F(RtsanOpenedFileTest, FpathconfDiesWhenRealtime) {
+  auto Func = [this]() { fpathconf(GetOpenFd(), _PC_LINK_MAX); };
+  ExpectRealtimeDeath(Func, "fpathconf");
+  ExpectNonRealtimeSurvival(Func);
+}
+
 TEST(TestRtsanInterceptors, UmaskDiesWhenRealtime) {
   auto Func = []() { umask(0); };
   ExpectRealtimeDeath(Func, "umask");



More information about the llvm-commits mailing list