Misc yanix fixes (#715)

* Correctly handle possibly misaligned pointers in readdir

This reapplies #615, which was inadvertently reverted.

* Tidy up unneeded `self::` qualifiers.

* Make Dir's contents private.

Also remove the `unsafe` from `impl_iter`. With `Dir`'s field being
private, we can rely on the pointer being only what we've assigned to
it.

* Make `poll`'s timeout argument a `libc::c_int`.

This clarifies that there are no subsequent conversions before calling the
underlying libc API.

* Use clock_gettime instead of clock_getres to get the time.

* Mark FileType::from_raw as safe.

It handles unknown values, so it can be marked safe.
This commit is contained in:
Dan Gohman
2019-12-16 13:34:22 -08:00
committed by GitHub
parent e21016f773
commit c2ba419409
11 changed files with 40 additions and 26 deletions

View File

@@ -4,16 +4,16 @@ use cfg_if::cfg_if;
cfg_if! {
if #[cfg(unix)] {
mod unix;
pub(crate) use self::unix::*;
pub use self::unix::preopen_dir;
pub(crate) use unix::*;
pub use unix::preopen_dir;
pub(crate) fn errno_from_host(err: i32) -> wasi::__wasi_errno_t {
host_impl::errno_from_nix(yanix::Errno::from_i32(err)).as_wasi_errno()
}
} else if #[cfg(windows)] {
mod windows;
pub(crate) use self::windows::*;
pub use self::windows::preopen_dir;
pub(crate) use windows::*;
pub use windows::preopen_dir;
pub(crate) fn errno_from_host(err: i32) -> wasi::__wasi_errno_t {
host_impl::errno_from_win(winx::winerror::WinError::from_u32(err as u32))

View File

@@ -3,7 +3,7 @@
use crate::hostcalls_impl::{ClockEventData, FdEventData};
use crate::sys::host_impl;
use crate::{wasi, Error, Result};
use yanix::clock::{clock_getres, ClockId};
use yanix::clock::{clock_getres, clock_gettime, ClockId};
fn wasi_clock_id_to_unix(clock_id: wasi::__wasi_clockid_t) -> Result<ClockId> {
// convert the supported clocks to libc types, or return EINVAL
@@ -39,7 +39,7 @@ pub(crate) fn clock_res_get(clock_id: wasi::__wasi_clockid_t) -> Result<wasi::__
pub(crate) fn clock_time_get(clock_id: wasi::__wasi_clockid_t) -> Result<wasi::__wasi_timestamp_t> {
let clock_id = wasi_clock_id_to_unix(clock_id)?;
let timespec = clock_getres(clock_id)?;
let timespec = clock_gettime(clock_id)?;
// convert to nanoseconds, returning EOVERFLOW in case of overflow; this is freelancing a bit
// from the spec but seems like it'll be an unusual situation to hit