mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:06:44 +00:00
compiler-rt: sanitizer_common: use close_range() instead of looping (#114442)
_SC_OPEN_MAX is quite high on FreeBSD, which makes this close() loop a quite obvious problem when attempting to do any kind of debugging in a process that uses StartSubprocess. Switch to using close_range(2) instead to close them all in a single syscall and dramatically reduce the runtime and syscall trace noise Linux has an equivalent syscall, but I do not have the capacity to test that it works there, so this is limited to SANITIZER_FREEBSD for the time being.
This commit is contained in:
parent
0019d06185
commit
2606a58bc0
@ -256,6 +256,11 @@ int internal_madvise(uptr addr, uptr length, int advice) {
|
||||
return internal_syscall(SYSCALL(madvise), addr, length, advice);
|
||||
}
|
||||
|
||||
# if SANITIZER_FREEBSD
|
||||
uptr internal_close_range(fd_t lowfd, fd_t highfd, int flags) {
|
||||
return internal_syscall(SYSCALL(close_range), lowfd, highfd, flags);
|
||||
}
|
||||
# endif
|
||||
uptr internal_close(fd_t fd) { return internal_syscall(SYSCALL(close), fd); }
|
||||
|
||||
uptr internal_open(const char *filename, int flags) {
|
||||
|
@ -28,6 +28,9 @@ namespace __sanitizer {
|
||||
// Don't use directly, use __sanitizer::OpenFile() instead.
|
||||
uptr internal_open(const char *filename, int flags);
|
||||
uptr internal_open(const char *filename, int flags, u32 mode);
|
||||
# if SANITIZER_FREEBSD
|
||||
uptr internal_close_range(fd_t lowfd, fd_t highfd, int flags);
|
||||
# endif
|
||||
uptr internal_close(fd_t fd);
|
||||
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count);
|
||||
|
@ -543,7 +543,11 @@ 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
|
||||
|
||||
internal_execve(program, const_cast<char **>(&argv[0]),
|
||||
const_cast<char *const *>(envp));
|
||||
|
Loading…
x
Reference in New Issue
Block a user