Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/host_env/src/crt_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ pub fn close(fd: Owned) -> io::Result<()> {
_close(fd.into_raw())
}

pub fn closerange(fd_low: Raw, fd_high: Raw) {
for fd in fd_low..fd_high {
// The range can contain closed descriptors, so it cannot use Owned.
let _ = _close(fd);
}
}

pub fn ftruncate(fd: Borrowed<'_>, len: Offset) -> io::Result<()> {
let ret = unsafe { suppress_iph!(c::ftruncate(fd.as_raw(), len)) };
// On Windows, _chsize_s returns 0 on success, or a positive error code (errno value) on failure.
Expand Down
2 changes: 2 additions & 0 deletions crates/host_env/src/crt_fd_unsupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ pub fn close(_fd: Owned) -> io::Result<()> {
Err(ebadf())
}

pub fn closerange(_fd_low: Raw, _fd_high: Raw) {}

pub fn ftruncate(_fd: Borrowed<'_>, _len: Offset) -> io::Result<()> {
Err(ebadf())
}
Expand Down
6 changes: 5 additions & 1 deletion crates/host_env/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,11 @@ pub fn device_encoding(_fd: i32) -> Option<String> {
}

pub fn exit(code: i32) -> ! {
std::process::exit(code)
// These callers require immediate termination without C exit handlers.
cfg_select! {
any(unix, windows, target_os = "wasi") => unsafe { libc::_exit(code) },
_ => std::process::exit(code),
}
}

/// Wrapper around the C `abort()` call: terminates the process abnormally.
Expand Down
6 changes: 1 addition & 5 deletions crates/vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,7 @@ pub(super) mod _os {

#[pyfunction]
fn closerange(fd_low: i32, fd_high: i32) {
for fileno in fd_low..fd_high {
if let Ok(fd) = unsafe { crt_fd::Owned::try_from_raw(fileno) } {
drop(fd);
}
}
crt_fd::closerange(fd_low, fd_high);
}

#[cfg(any(unix, windows, target_os = "wasi"))]
Expand Down
Loading