Support fd_fdstat_get and fd_renumber on stdin/stdout/stderr (#631)
* Support fd_fdstat_get on stdin/stdout/stderr. Add a routine for obtaining an `OsFile` containing a file descriptor for stdin/stdout/stderr so that we can do fd_fdstat_get on them. * Add a testcase for fd_fdstat_get etc. on stdin etc. * Don't dup file descriptors in fd_renumber. * Fix compilation on macOS * Rename OsFile to OsHandle This commits renames `OsFile` to `OsHandle` which seems to make more sense semantically as it is permitted to hold a valid OS handle to OS entities other than simply file/dir (e.g., socket, stream, etc.). As such, this commit also renames methods on `Descriptor` struct from `as_actual_file` to `as_file` as this in reality does pertain ops on FS entities such as files/dirs, and `as_file` to `as_os_handle` as in this case it can be anything, from file, through a socket, to a stream. * Fix compilation on Linux * Introduce `OsHandleRef` for borrowing OS resources. To prevent a `ManuallyDrop<OsHandleRef>` from outliving the resource it holds on to, create an `OsHandleRef` class parameterized on the lifetime of the `Descriptor`. * Fix scoping to pub-priv and backport to snapshot_0
This commit is contained in:
31
crates/test-programs/wasi-tests/src/bin/stdio.rs
Normal file
31
crates/test-programs/wasi-tests/src/bin/stdio.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use libc;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get;
|
||||
|
||||
unsafe fn test_stdio() {
|
||||
for fd in &[
|
||||
wasi_unstable::STDIN_FD,
|
||||
wasi_unstable::STDOUT_FD,
|
||||
wasi_unstable::STDERR_FD,
|
||||
] {
|
||||
let mut fdstat: wasi_unstable::FdStat = MaybeUninit::zeroed().assume_init();
|
||||
let status = wasi_fd_fdstat_get(*fd, &mut fdstat);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"fd_fdstat_get on stdio"
|
||||
);
|
||||
|
||||
assert!(
|
||||
wasi_unstable::fd_renumber(*fd, *fd + 100).is_ok(),
|
||||
"renumbering stdio",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Run the tests.
|
||||
unsafe { test_stdio() }
|
||||
}
|
||||
Reference in New Issue
Block a user