[compiler-rt] [sanitizer] Make internal_close_range available on all POSIX platforms (PR #191971)

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 09:38:11 PDT 2026


================
@@ -562,11 +562,10 @@ pid_t StartSubprocess(const char *program, const char *const argv[],
       internal_close(stderr_fd);
     }
 
-#  if SANITIZER_FREEBSD
-    internal_close_range(3, ~static_cast<fd_t>(0), 0);
-#  else
-    for (int fd = sysconf(_SC_OPEN_MAX); fd > 2; fd--) internal_close(fd);
-#  endif
+    // Use close_range to avoid a slow loop when RLIMIT_NOFILE is high.
+    // Falls back to the loop if not available on this platform/kernel.
+    if (internal_close_range(3, ~static_cast<fd_t>(0), 0) != 0)
+      for (int fd = sysconf(_SC_OPEN_MAX); fd > 2; fd--) internal_close(fd);
----------------
thurstond wrote:

Nit: please move this into a separate pull request. That way, the rest of this pull request cleanly matches the title "Make internal_close_range available on all POSIX platforms".

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


More information about the llvm-commits mailing list