Sync with lucet-wasi (#106)

* Open /dev/null for writing as well as reading.

Port this fix to wasi-common:

b905c44483

* Remove all remaining uses of `std::mem::uninitialized`.

Patch inspired by:

2d6519d051

* Replace libc::memcpy() calls with std::ptr::copy_nonoverlapping()

Port this fix to wasi-common:

a3f3a33e9b

* Pass `WasiError` by value.

It's a `u16` underneath, so we can pass it by value.

* Avoid unnecessary explicit lifetime parameters.

* Use immutable references rather than mutable references.

Patch inspired by:

54baa4c38c
This commit is contained in:
Dan Gohman
2019-09-30 10:22:11 -07:00
committed by Jakub Konka
parent d33036a3b5
commit a679412dd0
9 changed files with 46 additions and 29 deletions

View File

@@ -62,7 +62,7 @@ pub(crate) fn fd_readdir(
cookie: host::__wasi_dircookie_t,
) -> Result<usize> {
use crate::sys::unix::bsd::osfile::DirStream;
use libc::{fdopendir, memcpy, readdir, rewinddir, seekdir, telldir};
use libc::{fdopendir, readdir, rewinddir, seekdir, telldir};
use nix::errno::Errno;
use std::mem::ManuallyDrop;
use std::sync::Mutex;
@@ -129,9 +129,9 @@ pub(crate) fn fd_readdir(
host_buf_offset += std::mem::size_of_val(&entry);
let name_ptr = unsafe { *host_entry }.d_name.as_ptr();
unsafe {
memcpy(
host_buf_ptr.offset(host_buf_offset.try_into()?) as *mut _,
std::ptr::copy_nonoverlapping(
name_ptr as *const _,
host_buf_ptr.offset(host_buf_offset.try_into()?) as *mut _,
name_len,
)
};