mirror of
https://github.com/fluencelabs/wasmer
synced 2025-05-03 22:32:14 +00:00
Merge #1213
1213: Fixed WASI isatty r=syrusakbary a=syrusakbary <!-- Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test: https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests --> # Description Current WASI implementation returns a wrong response when libc `isatty` is used for `stdin`, `stdout` or `stderr`. This PR fixes it. <!-- Provide details regarding the change including motivation, links to related issues, and the context of the PR. --> # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Syrus <me@syrusakbary.com> Co-authored-by: Syrus Akbary <me@syrusakbary.com>
This commit is contained in:
commit
1d3ae6a00e
@ -2,6 +2,7 @@
|
||||
|
||||
## **[Unreleased]**
|
||||
|
||||
- [#1213](https://github.com/wasmerio/wasmer/pull/1213) Fixed WASI `fdstat` to detect `isatty` properly.
|
||||
- [#1192](https://github.com/wasmerio/wasmer/pull/1192) Use `ExceptionCode` for error representation.
|
||||
- [#1191](https://github.com/wasmerio/wasmer/pull/1191) Fix singlepass miscompilation on `Operator::CallIndirect`.
|
||||
- [#1180](https://github.com/wasmerio/wasmer/pull/1180) Fix compilation for target `x86_64-unknown-linux-musl`.
|
||||
|
15
lib/wasi-tests/tests/wasitests/isatty.rs
Normal file
15
lib/wasi-tests/tests/wasitests/isatty.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// !!! THIS IS A GENERATED FILE !!!
|
||||
// ANY MANUAL EDITS MAY BE OVERWRITTEN AT ANY TIME
|
||||
// Files autogenerated with cargo build (build/wasitests.rs).
|
||||
|
||||
#[test]
|
||||
fn test_isatty() {
|
||||
assert_wasi_output!(
|
||||
"../../wasitests/isatty.wasm",
|
||||
"isatty",
|
||||
vec![],
|
||||
vec![],
|
||||
vec![],
|
||||
"../../wasitests/isatty.out"
|
||||
);
|
||||
}
|
@ -18,6 +18,7 @@ mod file_metadata;
|
||||
mod fs_sandbox_test;
|
||||
mod fseek;
|
||||
mod hello;
|
||||
mod isatty;
|
||||
mod mapdir;
|
||||
mod path_link;
|
||||
mod path_rename;
|
||||
|
3
lib/wasi-tests/wasitests/isatty.out
Normal file
3
lib/wasi-tests/wasitests/isatty.out
Normal file
@ -0,0 +1,3 @@
|
||||
stdin: 1
|
||||
stdout: 1
|
||||
stderr: 1
|
20
lib/wasi-tests/wasitests/isatty.rs
Normal file
20
lib/wasi-tests/wasitests/isatty.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// We don't have access to libc, so we just use isatty
|
||||
// as an external function
|
||||
// use libc::isatty;
|
||||
|
||||
extern "C" {
|
||||
pub fn isatty(fd: i32) -> i32;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(target = "wasi")] {
|
||||
println!("stdin: {}", unsafe { isatty(0) });
|
||||
println!("stdout: {}", unsafe { isatty(1) });
|
||||
println!("stderr: {}", unsafe { isatty(2) });
|
||||
}
|
||||
#[cfg(not(target = "wasi"))] {
|
||||
println!("stdin: 1");
|
||||
println!("stdout: 1");
|
||||
println!("stderr: 1");
|
||||
}
|
||||
}
|
BIN
lib/wasi-tests/wasitests/isatty.wasm
Executable file
BIN
lib/wasi-tests/wasitests/isatty.wasm
Executable file
Binary file not shown.
@ -1045,12 +1045,28 @@ impl WasiFs {
|
||||
|
||||
pub fn fdstat(&self, fd: __wasi_fd_t) -> Result<__wasi_fdstat_t, __wasi_errno_t> {
|
||||
match fd {
|
||||
__WASI_STDOUT_FILENO => {
|
||||
__WASI_STDIN_FILENO => {
|
||||
return Ok(__wasi_fdstat_t {
|
||||
fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE,
|
||||
fs_flags: 0,
|
||||
fs_rights_base: ALL_RIGHTS,
|
||||
fs_rights_inheriting: ALL_RIGHTS,
|
||||
fs_rights_base: STDIN_DEFAULT_RIGHTS,
|
||||
fs_rights_inheriting: 0,
|
||||
})
|
||||
}
|
||||
__WASI_STDOUT_FILENO => {
|
||||
return Ok(__wasi_fdstat_t {
|
||||
fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE,
|
||||
fs_flags: __WASI_FDFLAG_APPEND,
|
||||
fs_rights_base: STDOUT_DEFAULT_RIGHTS,
|
||||
fs_rights_inheriting: 0,
|
||||
})
|
||||
}
|
||||
__WASI_STDERR_FILENO => {
|
||||
return Ok(__wasi_fdstat_t {
|
||||
fs_filetype: __WASI_FILETYPE_CHARACTER_DEVICE,
|
||||
fs_flags: __WASI_FDFLAG_APPEND,
|
||||
fs_rights_base: STDERR_DEFAULT_RIGHTS,
|
||||
fs_rights_inheriting: 0,
|
||||
})
|
||||
}
|
||||
_ => (),
|
||||
|
@ -1221,7 +1221,14 @@ pub fn fd_write(
|
||||
iovs_len: u32,
|
||||
nwritten: WasmPtr<u32>,
|
||||
) -> __wasi_errno_t {
|
||||
debug!("wasi::fd_write: fd={}", fd);
|
||||
// If we are writing to stdout or stderr
|
||||
// we skip debug to not pollute the stdout/err
|
||||
// and do debugging happily after :)
|
||||
if fd != __WASI_STDOUT_FILENO && fd != __WASI_STDERR_FILENO {
|
||||
debug!("wasi::fd_write: fd={}", fd);
|
||||
} else {
|
||||
trace!("wasi::fd_write: fd={}", fd);
|
||||
}
|
||||
let (memory, state) = get_memory_and_wasi_state(ctx, 0);
|
||||
let iovs_arr_cell = wasi_try!(iovs.deref(memory, 0, iovs_len));
|
||||
let nwritten_cell = wasi_try!(nwritten.deref(memory));
|
||||
|
Loading…
x
Reference in New Issue
Block a user