Skip to content

Commit

Permalink
feat: wasi-types does not define WasmPtr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Jun 10, 2021
1 parent 8d73745 commit cfd4008
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/wasi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "README.md"
edition = "2018"

[dependencies]
wasmer = { path = "../api", version = "2.0.0-rc2" }
wasmer-types = { path = "../types", version = "2.0.0-rc2" }
serde = { version = "1.0", features = ["derive"] }
byteorder = "1.3"
time = "0.1"
2 changes: 1 addition & 1 deletion lib/wasi-types/src/directory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::*;
use std::mem;
use wasmer::ValueType;
use wasmer_types::ValueType;

pub type __wasi_dircookie_t = u64;
pub const __WASI_DIRCOOKIE_START: u64 = 0;
Expand Down
1 change: 1 addition & 0 deletions lib/wasi-types/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::*;
use std::fmt;
use wasmer_types::ValueType;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi-types/src/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use serde::{Deserialize, Serialize};
use std::fmt;
use wasmer::ValueType;
use wasmer_types::ValueType;

pub type __wasi_device_t = u64;

Expand Down
7 changes: 3 additions & 4 deletions lib/wasi-types/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::*;
use wasmer::ValueType;
use wasmer_types::ValueType;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct __wasi_ciovec_t {
pub buf: WasmPtr<u8, Array>,
pub buf: u32,
pub buf_len: u32,
}

Expand All @@ -13,7 +12,7 @@ unsafe impl ValueType for __wasi_ciovec_t {}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct __wasi_iovec_t {
pub buf: WasmPtr<u8, Array>,
pub buf: u32,
pub buf_len: u32,
}

Expand Down
2 changes: 0 additions & 2 deletions lib/wasi-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod error;
mod event;
mod file;
mod io;
mod ptr;
mod signal;
mod subscription;
mod time;
Expand All @@ -27,7 +26,6 @@ pub use error::*;
pub use event::*;
pub use file::*;
pub use io::*;
pub use ptr::*;
pub use signal::*;
pub use subscription::*;
pub use versions::*;
Expand Down
1 change: 1 addition & 0 deletions lib/wasi-types/src/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::*;
use std::convert::TryFrom;
use std::fmt;
use wasmer_types::ValueType;

pub type __wasi_subclockflags_t = u16;
pub const __WASI_SUBSCRIPTION_CLOCK_ABSTIME: u16 = 1 << 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi-types/src/versions/snapshot0.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::*;
use serde::{Deserialize, Serialize};
use std::fmt;
use wasmer::ValueType;
use wasmer_types::ValueType;

pub type __wasi_linkcount_t = u32;

Expand Down
4 changes: 1 addition & 3 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
#[macro_use]
mod macros;
mod ptr {
pub use wasmer_wasi_types::{Array, WasmPtr};
}
mod ptr;
mod state;
mod syscalls;
mod utils;
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi-types/src/ptr.rs → lib/wasi/src/ptr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This is a wrapper around the `WasmPtr` abstraction that returns __WASI_EFAULT
//! if memory access failed
use crate::{__wasi_errno_t, __WASI_EFAULT};
use crate::syscalls::types::{__wasi_errno_t, __WASI_EFAULT};
use std::{cell::Cell, fmt};
pub use wasmer::{Array, FromToNativeWasmType, Item, Memory, ValueType, WasmPtr as BaseWasmPtr};

Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn write_bytes_inner<T: Write>(
let mut bytes_written = 0;
for iov in iovs_arr_cell {
let iov_inner = iov.get();
let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?;
let bytes = WasmPtr::<u8, Array>::new(iov_inner.buf).deref(memory, 0, iov_inner.buf_len)?;
write_loc
.write_all(&bytes.iter().map(|b_cell| b_cell.get()).collect::<Vec<u8>>())
.map_err(|_| __WASI_EIO)?;
Expand Down Expand Up @@ -82,7 +82,7 @@ fn read_bytes<T: Read>(

for iov in iovs_arr_cell {
let iov_inner = iov.get();
let bytes = iov_inner.buf.deref(memory, 0, iov_inner.buf_len)?;
let bytes = WasmPtr::<u8, Array>::new(iov_inner.buf).deref(memory, 0, iov_inner.buf_len)?;
let mut raw_bytes: &mut [u8] =
unsafe { &mut *(bytes as *const [_] as *mut [_] as *mut [u8]) };
bytes_read += reader.read(raw_bytes).map_err(|_| __WASI_EIO)? as u32;
Expand Down

0 comments on commit cfd4008

Please sign in to comment.