Skip to content

Commit

Permalink
Try #457:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed May 20, 2019
2 parents b1fa60e + 7a4b47d commit f34cb31
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 27 deletions.
12 changes: 11 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ environment:
cache:
- 'C:\Users\appveyor\.cargo'
- target
- 'wapm-cli\target'
- wapm-cli-target

install:
# # Install LLVM
Expand Down Expand Up @@ -53,7 +53,17 @@ build_script:
# Now we build wapm
- git submodule init
- git submodule update
# Cache wapm cli target in dir above to prevent breaking git submodule on windows
- if not exist wapm-cli-target mkdir wapm-cli-target
- move wapm-cli-target wapm-cli
- cd wapm-cli
- rename wapm-cli-target target
- cd ..
- cargo build --release --manifest-path wapm-cli/Cargo.toml --features telemetry
- cd wapm-cli
- rename target wapm-cli-target
- cd ..
- move wapm-cli\wapm-cli-target wapm-cli-target

test_script:
- cargo test --manifest-path lib/spectests/Cargo.toml --features clif
Expand Down
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,15 @@ jobs:
tar xf clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
rustup toolchain install nightly
rustup target add wasm32-wasi --toolchain nightly
- run: |
rustup default nightly
make test-wasi-singlepass
make test-wasi-clif
- run: rustup default nightly-2019-04-11
- run: |
export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/"
make test
make test-singlepass
make test-wasi-singlepass
make test-wasi-clif
make test-emscripten-clif
make test-emscripten-singlepass
- save_cache:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Blocks of changes will separated by version increments.

## 0.4.2 - 2019-05-16

- [#457](https://github.com/wasmerio/wasmer/pull/457) Implement file metadata for WASI, fix bugs in WASI clock code for Unix platforms
- [#416](https://github.com/wasmerio/wasmer/pull/416) Remote code loading framework
- [#449](https://github.com/wasmerio/wasmer/pull/449) Fix bugs: opening host files in filestat and opening with write permissions unconditionally in path_open
- [#442](https://github.com/wasmerio/wasmer/pull/442) Misc. WASI FS fixes and implement readdir
Expand Down
61 changes: 61 additions & 0 deletions lib/wasi/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,64 @@ pub fn host_file_type_to_wasi_file_type(file_type: fs::FileType) -> __wasi_filet
__WASI_FILETYPE_UNKNOWN
}
}

pub fn get_stat_for_kind(kind: &Kind) -> Option<__wasi_filestat_t> {
match kind {
Kind::File { handle } => match handle {
WasiFile::HostFile(hf) => {
let md = hf.metadata().ok()?;

Some(__wasi_filestat_t {
st_filetype: host_file_type_to_wasi_file_type(md.file_type()),
st_size: md.len(),
st_atim: md
.accessed()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_mtim: md
.modified()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_ctim: md
.created()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
..__wasi_filestat_t::default()
})
}
},
Kind::Dir { path, .. } => {
let md = path.metadata().ok()?;
Some(__wasi_filestat_t {
st_filetype: host_file_type_to_wasi_file_type(md.file_type()),
st_size: md.len(),
st_atim: md
.accessed()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_mtim: md
.modified()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_ctim: md
.created()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
..__wasi_filestat_t::default()
})
}
_ => None,
}
}
17 changes: 9 additions & 8 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use self::types::*;
use crate::{
ptr::{Array, WasmPtr},
state::{
host_file_type_to_wasi_file_type, Fd, InodeVal, Kind, WasiFile, WasiState, MAX_SYMLINKS,
get_stat_for_kind, host_file_type_to_wasi_file_type, Fd, InodeVal, Kind, WasiFile,
WasiState, MAX_SYMLINKS,
},
ExitCode,
};
Expand Down Expand Up @@ -187,7 +188,10 @@ pub fn clock_time_get(
precision: __wasi_timestamp_t,
time: WasmPtr<__wasi_timestamp_t>,
) -> __wasi_errno_t {
debug!("wasi::clock_time_get");
debug!(
"wasi::clock_time_get clock_id: {}, precision: {}",
clock_id, precision
);
let memory = ctx.memory(0);

let out_addr = wasi_try!(time.deref(memory));
Expand Down Expand Up @@ -1082,7 +1086,7 @@ pub fn path_create_directory(
entries: Default::default(),
};
let new_inode = state.fs.inodes.insert(InodeVal {
stat: __wasi_filestat_t::default(),
stat: wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)),
is_preopened: false,
name: path_vec[0].clone(),
kind,
Expand Down Expand Up @@ -1226,10 +1230,7 @@ pub fn path_filestat_get(
}
let final_path_metadata =
wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO));
__wasi_filestat_t {
st_filetype: host_file_type_to_wasi_file_type(final_path_metadata.file_type()),
..Default::default()
}
wasi_try!(get_stat_for_kind(&state.fs.inodes[inode].kind).ok_or(__WASI_EIO))
}
}
_ => {
Expand Down Expand Up @@ -1533,7 +1534,7 @@ pub fn path_open(

// record lazily loaded or newly created fd
let new_inode = state.fs.inodes.insert(InodeVal {
stat: __wasi_filestat_t::default(),
stat: wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)),
is_preopened: false,
name: file_name.clone(),
kind,
Expand Down
6 changes: 3 additions & 3 deletions lib/wasi/src/syscalls/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ pub struct __wasi_ciovec_t {
unsafe impl ValueType for __wasi_ciovec_t {}

pub type __wasi_clockid_t = u32;
pub const __WASI_CLOCK_MONOTONIC: u32 = 0;
pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 1;
pub const __WASI_CLOCK_REALTIME: u32 = 2;
pub const __WASI_CLOCK_REALTIME: u32 = 0;
pub const __WASI_CLOCK_MONOTONIC: u32 = 1;
pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 2;
pub const __WASI_CLOCK_THREAD_CPUTIME_ID: u32 = 3;

pub type __wasi_device_t = u64;
Expand Down
8 changes: 4 additions & 4 deletions lib/wasi/src/syscalls/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub fn platform_clock_res_get(
(clock_getres(unix_clock_id, &mut timespec_out), timespec_out)
};

resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t);
let t_out = (timespec_out.tv_sec * 1_000_000_000).wrapping_add(timespec_out.tv_nsec);
resolution.set(t_out as __wasi_timestamp_t);

// TODO: map output of clock_getres to __wasi_errno_t
__WASI_ESUCCESS
Expand All @@ -50,9 +51,8 @@ pub fn platform_clock_time_get(
)
};

// TODO: adjust output by precision...

time.set(timespec_out.tv_nsec as __wasi_timestamp_t);
let t_out = (timespec_out.tv_sec * 1_000_000_000).wrapping_add(timespec_out.tv_nsec);
time.set(t_out as __wasi_timestamp_t);

// TODO: map output of clock_gettime to __wasi_errno_t
__WASI_ESUCCESS
Expand Down
1 change: 0 additions & 1 deletion lib/wasi/tests/wasitests/file_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[test]
#[ignore]
fn test_file_metadata() {
assert_wasi_output!(
"../../wasitests/file_metadata.wasm",
Expand Down
Binary file modified lib/wasi/wasitests/create_dir
Binary file not shown.
Binary file modified lib/wasi/wasitests/create_dir.wasm
Binary file not shown.
Binary file modified lib/wasi/wasitests/file_metadata
Binary file not shown.
3 changes: 2 additions & 1 deletion lib/wasi/wasitests/file_metadata.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
is dir: false
file info: FileType(FileType { mode: 33188 }) 419 Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545288295 }) Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545243056 }) Ok(SystemTime { tv_sec: 1558132191, tv_nsec: 359031112 })
filetype: false true false
file info: 491
12 changes: 6 additions & 6 deletions lib/wasi/wasitests/file_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ fn main() {
fs::File::open("wasitests/file_metadata.rs").expect("could not find src file");
let md = this_file.metadata().unwrap();
println!("is dir: {}", md.is_dir());
let filetype = md.file_type();
println!(
"file info: {:?} {} {:?} {:?} {:?}",
md.file_type(),
md.len(),
md.modified(),
md.created(),
md.accessed()
"filetype: {} {} {}",
filetype.is_dir(),
filetype.is_file(),
filetype.is_symlink()
);
println!("file info: {} {} {}", md.len(), md.modified(), md.created());
}
Binary file modified lib/wasi/wasitests/file_metadata.wasm
Binary file not shown.
Binary file modified lib/wasi/wasitests/hello
Binary file not shown.
Binary file modified lib/wasi/wasitests/hello.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion lib/wasi/wasitests/ignores.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
file_metadata
create_dir
Binary file modified lib/wasi/wasitests/quine
Binary file not shown.
Binary file modified lib/wasi/wasitests/quine.wasm
Binary file not shown.

0 comments on commit f34cb31

Please sign in to comment.