This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow preopen file descriptors to be closed. (#96)
* Allow preopen file descriptors to be closed. This ports the test updates from bytecodealliance/wasmtime#5828 to the preview2-prototype and implements the ability to close preopened file descriptors. * Fix compilation on Windows.
- Loading branch information
1 parent
42e2a49
commit 0c6290c
Showing
7 changed files
with
81 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{env, process}; | ||
use wasi_tests::{assert_errno, open_scratch_directory}; | ||
|
||
unsafe fn test_overwrite_preopen(dir_fd: wasi::Fd) { | ||
let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd; | ||
|
||
assert!(dir_fd > pre_fd, "dir_fd number"); | ||
|
||
let old_dir_filestat = wasi::fd_filestat_get(dir_fd).expect("failed fd_filestat_get"); | ||
|
||
// Try to renumber over a preopened directory handle. | ||
wasi::fd_renumber(dir_fd, pre_fd).expect("renumbering over a preopened file descriptor"); | ||
|
||
// Ensure that pre_fd is still open. | ||
let new_dir_filestat = wasi::fd_filestat_get(pre_fd).expect("failed fd_filestat_get"); | ||
|
||
// Ensure that we renumbered. | ||
assert_eq!(old_dir_filestat.dev, new_dir_filestat.dev); | ||
assert_eq!(old_dir_filestat.ino, new_dir_filestat.ino); | ||
|
||
// Ensure that dir_fd is closed. | ||
assert_errno!( | ||
wasi::fd_fdstat_get(dir_fd).expect_err("failed fd_fdstat_get"), | ||
wasi::ERRNO_BADF | ||
); | ||
} | ||
|
||
fn main() { | ||
let mut args = env::args(); | ||
let prog = args.next().unwrap(); | ||
let arg = if let Some(arg) = args.next() { | ||
arg | ||
} else { | ||
eprintln!("usage: {} <scratch directory>", prog); | ||
process::exit(1); | ||
}; | ||
|
||
// Open scratch directory | ||
let dir_fd = match open_scratch_directory(&arg) { | ||
Ok(dir_fd) => dir_fd, | ||
Err(err) => { | ||
eprintln!("{}", err); | ||
process::exit(1) | ||
} | ||
}; | ||
|
||
// Run the tests. | ||
unsafe { test_overwrite_preopen(dir_fd) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters