Skip to content

Conversation

@cjappl
Copy link
Contributor

@cjappl cjappl commented Nov 5, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Chris Apple (cjappl)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/114908.diff

1 Files Affected:

  • (modified) compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp (+13-26)
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 8ed933fad51b11..bf7ea4ffe8599c 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -41,23 +41,10 @@
 #include <sys/uio.h>
 
 #if _FILE_OFFSET_BITS == 64 && SANITIZER_GLIBC
-const char *const kCreatFunctionName = "creat64";
-const char *const kFcntlFunctionName = "fcntl64";
-const char *const kFopenFunctionName = "fopen64";
-const char *const kOpenAtFunctionName = "openat64";
-const char *const kOpenFunctionName = "open64";
-const char *const kPreadFunctionName = "pread64";
-const char *const kPwriteFunctionName = "pwrite64";
-const char *const kMmapFunctionName = "mmap64";
+// Under these conditions, some system calls are `foo64` instead of `foo`
+#define MAYBE_APPEND_64(func) func "64"
 #else
-const char *const kCreatFunctionName = "creat";
-const char *const kFcntlFunctionName = "fcntl";
-const char *const kFopenFunctionName = "fopen";
-const char *const kOpenAtFunctionName = "openat";
-const char *const kOpenFunctionName = "open";
-const char *const kPreadFunctionName = "pread";
-const char *const kPwriteFunctionName = "pwrite";
-const char *const kMmapFunctionName = "mmap";
+#define MAYBE_APPEND_64(func) func
 #endif
 
 using namespace testing;
@@ -187,7 +174,7 @@ TEST(TestRtsanInterceptors, MmapDiesWhenRealtime) {
     void *_ = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
                    MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   };
-  ExpectRealtimeDeath(Func, kMmapFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("mmap"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -244,13 +231,13 @@ TEST(TestRtsanInterceptors, NanosleepDiesWhenRealtime) {
 
 TEST_F(RtsanFileTest, OpenDiesWhenRealtime) {
   auto Func = [this]() { open(GetTemporaryFilePath(), O_RDONLY); };
-  ExpectRealtimeDeath(Func, kOpenFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("open"));
   ExpectNonRealtimeSurvival(Func);
 }
 
 TEST_F(RtsanFileTest, OpenatDiesWhenRealtime) {
   auto Func = [this]() { openat(0, GetTemporaryFilePath(), O_RDONLY); };
-  ExpectRealtimeDeath(Func, kOpenAtFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("openat"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -275,13 +262,13 @@ TEST_F(RtsanFileTest, OpenCreatesFileWithProperMode) {
 
 TEST_F(RtsanFileTest, CreatDiesWhenRealtime) {
   auto Func = [this]() { creat(GetTemporaryFilePath(), S_IWOTH | S_IROTH); };
-  ExpectRealtimeDeath(Func, kCreatFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("creat"));
   ExpectNonRealtimeSurvival(Func);
 }
 
 TEST(TestRtsanInterceptors, FcntlDiesWhenRealtime) {
   auto Func = []() { fcntl(0, F_GETFL); };
-  ExpectRealtimeDeath(Func, kFcntlFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -300,7 +287,7 @@ TEST_F(RtsanFileTest, FcntlFlockDiesWhenRealtime) {
     ASSERT_THAT(fcntl(fd, F_GETLK, &lock), Eq(0));
     ASSERT_THAT(lock.l_type, F_UNLCK);
   };
-  ExpectRealtimeDeath(Func, kFcntlFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
   ExpectNonRealtimeSurvival(Func);
 
   close(fd);
@@ -322,7 +309,7 @@ TEST_F(RtsanFileTest, FcntlSetFdDiesWhenRealtime) {
     ASSERT_THAT(fcntl(fd, F_GETFD), Eq(old_flags));
   };
 
-  ExpectRealtimeDeath(Func, kFcntlFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fcntl"));
   ExpectNonRealtimeSurvival(Func);
 
   close(fd);
@@ -340,7 +327,7 @@ TEST_F(RtsanFileTest, FopenDiesWhenRealtime) {
     EXPECT_THAT(f, Ne(nullptr));
   };
 
-  ExpectRealtimeDeath(Func, kFopenFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("fopen"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -428,7 +415,7 @@ TEST_F(RtsanOpenedFileTest, PreadDiesWhenRealtime) {
     char c{};
     pread(GetOpenFd(), &c, 1, 0);
   };
-  ExpectRealtimeDeath(Func, kPreadFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pread"));
   ExpectNonRealtimeSurvival(Func);
 }
 
@@ -447,7 +434,7 @@ TEST_F(RtsanOpenedFileTest, PwriteDiesWhenRealtime) {
     char c = 'a';
     pwrite(GetOpenFd(), &c, 1, 0);
   };
-  ExpectRealtimeDeath(Func, kPwriteFunctionName);
+  ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pwrite"));
   ExpectNonRealtimeSurvival(Func);
 }
 

@cjappl cjappl merged commit a5e1898 into llvm:main Nov 5, 2024
10 checks passed
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants