[compiler-rt] [compiler-rt] Replace direct calls to pipe with internal_pipe (PR #97186)

Sirui Mu via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 29 19:49:12 PDT 2024


https://github.com/Lancern updated https://github.com/llvm/llvm-project/pull/97186

>From 9bd90729f7bed26002df3f0d484cc21f30a782bb Mon Sep 17 00:00:00 2001
From: Sirui Mu <msrlancern at gmail.com>
Date: Sun, 30 Jun 2024 10:48:25 +0800
Subject: [PATCH] [compiler-rt] Replace direct calls to pipe with internal_pipe

This patch tries to resolve google/sanitizers#1106 by introducing a new
internal_pipe function which will not be intercepted by TSAN.
---
 compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp         | 4 ++++
 compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp           | 2 ++
 compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp        | 5 +++++
 compiler-rt/lib/sanitizer_common/sanitizer_posix.h           | 2 ++
 compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp | 2 +-
 5 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 12df3ef73da4b..c70a689c7e599 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -796,6 +796,10 @@ uptr internal_lseek(fd_t fd, OFF_T offset, int whence) {
   return internal_syscall(SYSCALL(lseek), fd, offset, whence);
 }
 
+uptr internal_pipe(fd_t pipefd[2]) {
+  return internal_syscall(SYSCALL(pipe), pipefd);
+}
+
 #    if SANITIZER_LINUX
 uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
   return internal_syscall(SYSCALL(prctl), option, arg2, arg3, arg4, arg5);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
index cbdf3e95925bf..58d94a0748915 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp
@@ -213,6 +213,8 @@ uptr internal_unlink(const char *path) {
   return unlink(path);
 }
 
+uptr internal_pipe(fd_t fildes[2]) { return pipe(fildes); }
+
 uptr internal_sched_yield() {
   return sched_yield();
 }
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
index 5e601bdcde1e5..eff8ceb3b60b9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_netbsd.cpp
@@ -204,6 +204,11 @@ uptr internal_rename(const char *oldpath, const char *newpath) {
   return _REAL(rename, oldpath, newpath);
 }
 
+uptr internal_pipe(fd_t fildes[2]) {
+  DEFINE__REAL(int, pipe, int a[2]);
+  return _REAL(pipe, fildes);
+}
+
 uptr internal_sched_yield() {
   CHECK(&_sys_sched_yield);
   return _sys_sched_yield();
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_posix.h
index 14617e4771bec..c0a93eabda57d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.h
@@ -56,6 +56,8 @@ uptr internal_unlink(const char *path);
 uptr internal_rename(const char *oldpath, const char *newpath);
 uptr internal_lseek(fd_t fd, OFF_T offset, int whence);
 
+uptr internal_pipe(fd_t pipefd[2]);
+
 #if SANITIZER_NETBSD
 uptr internal_ptrace(int request, int pid, void *addr, int data);
 #else
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
index ece2d7d63dd61..93c49fa1dafa4 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
@@ -293,7 +293,7 @@ bool IsAccessibleMemoryRange(uptr beg, uptr size) {
   // Checking too large memory ranges is slow.
   CHECK_LT(size, page_size * 10);
   int sock_pair[2];
-  if (pipe(sock_pair))
+  if (internal_pipe(sock_pair))
     return false;
   uptr bytes_written =
       internal_write(sock_pair[1], reinterpret_cast<void *>(beg), size);



More information about the llvm-commits mailing list