Rewrite majority of impl reusing libstd (#34)
* Rewrite FdEntry reusing as much libstd as possible
* Use the new FdEntry, FdObject, Descriptor struct in *nix impl
* Adapt Windows impl
* Remove unnecessary check in fd_read
Check `host_nread == 0` caused premature FdEntry closure and removal
which ultimately was resulting in an attempt at "double closing" of
the same file descriptor at the end of the Wasm program:
...
fd_close(fd=4)
-> errno=WASI_ESUCCESS
fd_close(fd=4)
-> errno=WASI_EBADF
* Use libstd vectored IO
* Use std:🧵:yield_now to implement sched_yield
* Add logging to integration tests
* Add preliminary support for host-specific errors
* Operate on std::fs::File in path_get on *nix
* Add cross-platform RawString type encapsulating OsStrExt
* Fix Windows build
* Update Travis and README to Rust v1.36
* Remove unused winx::handle::close helper
* Refactor Descriptor into raw handles/fds
* Strip readlinkat in prep for path_get host-independent
* Strip openat in prep for path_get host-independent
* Move ManuallyDrop up one level from Descriptor to FdObject
* Make (c)iovec host fns unsafe
* Swap unwraps/expects for Results in fdentry_impl on nix
* Rewrite fd_pread/write and implement for Win
* Use File::sync_all to impl fd_sync
* Use File::sync_data to impl fd_datasync
* Rewind file cursor after fd_p{read, write} on Windows
* Add fd_p{read, write} tests
* Handle errors instead of panicking in path_get
* Use File::set_len to impl fd_allocate
* Add test for fd_allocate
* Replace all panics with Results
* Document the point of RawString
This commit is contained in:
@@ -35,10 +35,11 @@ pub fn args_get(
|
||||
|
||||
argv.push(arg_ptr);
|
||||
|
||||
argv_buf_offset = if let Some(new_offset) = argv_buf_offset.checked_add(
|
||||
wasm32::uintptr_t::try_from(arg_bytes.len())
|
||||
.expect("cast overflow would have been caught by `enc_slice_of` above"),
|
||||
) {
|
||||
argv_buf_offset = if let Some(new_offset) =
|
||||
argv_buf_offset.checked_add(match wasm32::uintptr_t::try_from(arg_bytes.len()) {
|
||||
Ok(len) => len,
|
||||
Err(_) => return return_enc_errno(host::__WASI_EOVERFLOW),
|
||||
}) {
|
||||
new_offset
|
||||
} else {
|
||||
return return_enc_errno(host::__WASI_EOVERFLOW);
|
||||
@@ -113,10 +114,11 @@ pub fn environ_get(
|
||||
|
||||
environ.push(env_ptr);
|
||||
|
||||
environ_buf_offset = if let Some(new_offset) = environ_buf_offset.checked_add(
|
||||
wasm32::uintptr_t::try_from(env_bytes.len())
|
||||
.expect("cast overflow would have been caught by `enc_slice_of` above"),
|
||||
) {
|
||||
environ_buf_offset = if let Some(new_offset) =
|
||||
environ_buf_offset.checked_add(match wasm32::uintptr_t::try_from(env_bytes.len()) {
|
||||
Ok(len) => len,
|
||||
Err(_) => return return_enc_errno(host::__WASI_EOVERFLOW),
|
||||
}) {
|
||||
new_offset
|
||||
} else {
|
||||
return return_enc_errno(host::__WASI_EOVERFLOW);
|
||||
@@ -314,10 +316,7 @@ pub fn poll_oneoff(
|
||||
pub fn sched_yield() -> wasm32::__wasi_errno_t {
|
||||
trace!("sched_yield()");
|
||||
|
||||
let ret = match hostcalls_impl::sched_yield() {
|
||||
Ok(()) => host::__WASI_ESUCCESS,
|
||||
Err(e) => e,
|
||||
};
|
||||
std::thread::yield_now();
|
||||
|
||||
return_enc_errno(ret)
|
||||
return_enc_errno(host::__WASI_ESUCCESS)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user