[compiler-rt] [rtsan] NFC: Add comment about O_NONBLOCK behavior (PR #116189)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 01:37:30 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Chris Apple (cjappl)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp (+10-12) 


``````````diff
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index c3fcd4f2da85ce..3a1b1f6524745f 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -60,8 +60,11 @@ struct DlsymAlloc : public DlSymAllocator<DlsymAlloc> {
 // Filesystem
 
 INTERCEPTOR(int, open, const char *path, int oflag, ...) {
-  // TODO Establish whether we should intercept here if the flag contains
-  // O_NONBLOCK
+  // We do not early exit if O_NONBLOCK is set.
+  // O_NONBLOCK **does not prevent the syscall** it simply sets the FD to be in
+  // nonblocking mode, which is a different concept than our
+  // [[clang::nonblocking]], and is not rt-safe. This behavior was confirmed
+  // using Instruments on Darwin with a simple test program
   __rtsan_notify_intercepted_call("open");
 
   if (OpenReadsVaArgs(oflag)) {
@@ -77,8 +80,7 @@ INTERCEPTOR(int, open, const char *path, int oflag, ...) {
 
 #if SANITIZER_INTERCEPT_OPEN64
 INTERCEPTOR(int, open64, const char *path, int oflag, ...) {
-  // TODO Establish whether we should intercept here if the flag contains
-  // O_NONBLOCK
+  // See comment above about O_NONBLOCK
   __rtsan_notify_intercepted_call("open64");
 
   if (OpenReadsVaArgs(oflag)) {
@@ -97,8 +99,7 @@ INTERCEPTOR(int, open64, const char *path, int oflag, ...) {
 #endif // SANITIZER_INTERCEPT_OPEN64
 
 INTERCEPTOR(int, openat, int fd, const char *path, int oflag, ...) {
-  // TODO Establish whether we should intercept here if the flag contains
-  // O_NONBLOCK
+  // See comment above about O_NONBLOCK
   __rtsan_notify_intercepted_call("openat");
 
   if (OpenReadsVaArgs(oflag)) {
@@ -114,8 +115,7 @@ INTERCEPTOR(int, openat, int fd, const char *path, int oflag, ...) {
 
 #if SANITIZER_INTERCEPT_OPENAT64
 INTERCEPTOR(int, openat64, int fd, const char *path, int oflag, ...) {
-  // TODO Establish whether we should intercept here if the flag contains
-  // O_NONBLOCK
+  // See comment above about O_NONBLOCK
   __rtsan_notify_intercepted_call("openat64");
 
   if (OpenReadsVaArgs(oflag)) {
@@ -134,8 +134,7 @@ INTERCEPTOR(int, openat64, int fd, const char *path, int oflag, ...) {
 #endif // SANITIZER_INTERCEPT_OPENAT64
 
 INTERCEPTOR(int, creat, const char *path, mode_t mode) {
-  // TODO Establish whether we should intercept here if the flag contains
-  // O_NONBLOCK
+  // See comment above about O_NONBLOCK
   __rtsan_notify_intercepted_call("creat");
   const int result = REAL(creat)(path, mode);
   return result;
@@ -143,8 +142,7 @@ INTERCEPTOR(int, creat, const char *path, mode_t mode) {
 
 #if SANITIZER_INTERCEPT_CREAT64
 INTERCEPTOR(int, creat64, const char *path, mode_t mode) {
-  // TODO Establish whether we should intercept here if the flag contains
-  // O_NONBLOCK
+  // See comment above about O_NONBLOCK
   __rtsan_notify_intercepted_call("creat64");
   const int result = REAL(creat64)(path, mode);
   return result;

``````````

</details>


https://github.com/llvm/llvm-project/pull/116189


More information about the llvm-commits mailing list