Use try_from replacing cast in wasmtime-wasi-c.
This commit is contained in:
@@ -17,7 +17,6 @@ cranelift-codegen = "0.30.0"
|
|||||||
cranelift-entity = "0.30.0"
|
cranelift-entity = "0.30.0"
|
||||||
cranelift-wasm = "0.30.0"
|
cranelift-wasm = "0.30.0"
|
||||||
target-lexicon = "0.3.0"
|
target-lexicon = "0.3.0"
|
||||||
cast = { version = "0.2.2", default-features = false }
|
|
||||||
log = { version = "0.4.6", default-features = false }
|
log = { version = "0.4.6", default-features = false }
|
||||||
libc = "0.2.50"
|
libc = "0.2.50"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
extern crate cast;
|
|
||||||
extern crate cranelift_codegen;
|
extern crate cranelift_codegen;
|
||||||
extern crate cranelift_entity;
|
extern crate cranelift_entity;
|
||||||
extern crate cranelift_wasm;
|
extern crate cranelift_wasm;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::host::{argv_environ_values, fd_prestats, fd_table};
|
|||||||
use crate::instantiate::WASIState;
|
use crate::instantiate::WASIState;
|
||||||
use cranelift_codegen::ir::types::{Type, I32, I64};
|
use cranelift_codegen::ir::types::{Type, I32, I64};
|
||||||
use host;
|
use host;
|
||||||
|
use std::convert::TryFrom;
|
||||||
use std::{mem, ptr, slice, str};
|
use std::{mem, ptr, slice, str};
|
||||||
use translate::*;
|
use translate::*;
|
||||||
use wasm32;
|
use wasm32;
|
||||||
@@ -170,11 +171,11 @@ syscalls! {
|
|||||||
|
|
||||||
let vmctx = &mut *vmctx;
|
let vmctx = &mut *vmctx;
|
||||||
let argv_environ = get_argv_environ(vmctx);
|
let argv_environ = get_argv_environ(vmctx);
|
||||||
let argc = match cast::u32((*argv_environ).argc) {
|
let argc = match u32::try_from((*argv_environ).argc) {
|
||||||
Ok(argc) => argc,
|
Ok(argc) => argc,
|
||||||
Err(_) => return wasm32::__WASI_ENOMEM,
|
Err(_) => return wasm32::__WASI_ENOMEM,
|
||||||
};
|
};
|
||||||
let argv_buf_size = match cast::u32((*argv_environ).argv_buf_size) {
|
let argv_buf_size = match u32::try_from((*argv_environ).argv_buf_size) {
|
||||||
Ok(argc) => argc,
|
Ok(argc) => argc,
|
||||||
Err(_) => return wasm32::__WASI_ENOMEM,
|
Err(_) => return wasm32::__WASI_ENOMEM,
|
||||||
};
|
};
|
||||||
@@ -307,11 +308,11 @@ syscalls! {
|
|||||||
|
|
||||||
let vmctx = &mut *vmctx;
|
let vmctx = &mut *vmctx;
|
||||||
let argv_environ = get_argv_environ(vmctx);
|
let argv_environ = get_argv_environ(vmctx);
|
||||||
let environ_count = match cast::u32((*argv_environ).environ_count) {
|
let environ_count = match u32::try_from((*argv_environ).environ_count) {
|
||||||
Ok(host_environ_count) => host_environ_count,
|
Ok(host_environ_count) => host_environ_count,
|
||||||
Err(_) => return wasm32::__WASI_ENOMEM,
|
Err(_) => return wasm32::__WASI_ENOMEM,
|
||||||
};
|
};
|
||||||
let environ_buf_size = match cast::u32((*argv_environ).environ_buf_size) {
|
let environ_buf_size = match u32::try_from((*argv_environ).environ_buf_size) {
|
||||||
Ok(host_environ_buf_size) => host_environ_buf_size,
|
Ok(host_environ_buf_size) => host_environ_buf_size,
|
||||||
Err(_) => return wasm32::__WASI_ENOMEM,
|
Err(_) => return wasm32::__WASI_ENOMEM,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use cast;
|
|
||||||
use cast::From as _0;
|
|
||||||
use host;
|
use host;
|
||||||
|
use std::convert::TryFrom;
|
||||||
use std::mem::{align_of, size_of, zeroed};
|
use std::mem::{align_of, size_of, zeroed};
|
||||||
use std::slice;
|
use std::slice;
|
||||||
use wasm32;
|
use wasm32;
|
||||||
@@ -85,7 +84,7 @@ pub unsafe fn decode_slice_of<T>(
|
|||||||
ptr: wasm32::uintptr_t,
|
ptr: wasm32::uintptr_t,
|
||||||
len: wasm32::size_t,
|
len: wasm32::size_t,
|
||||||
) -> Result<(*mut T, usize), host::__wasi_errno_t> {
|
) -> Result<(*mut T, usize), host::__wasi_errno_t> {
|
||||||
let len = cast::usize(len);
|
let len = usize::try_from(len).unwrap();
|
||||||
|
|
||||||
let ptr = decode_ptr(
|
let ptr = decode_ptr(
|
||||||
vmctx,
|
vmctx,
|
||||||
@@ -98,7 +97,7 @@ pub unsafe fn decode_slice_of<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_usize(len: usize) -> wasm32::size_t {
|
pub fn encode_usize(len: usize) -> wasm32::size_t {
|
||||||
cast::u32(len).unwrap()
|
u32::try_from(len).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_device(device: host::__wasi_device_t) -> wasm32::__wasi_device_t {
|
pub fn encode_device(device: host::__wasi_device_t) -> wasm32::__wasi_device_t {
|
||||||
@@ -274,7 +273,7 @@ pub unsafe fn decode_ciovec(
|
|||||||
vmctx: &mut VMContext,
|
vmctx: &mut VMContext,
|
||||||
ciovec: &wasm32::__wasi_ciovec_t,
|
ciovec: &wasm32::__wasi_ciovec_t,
|
||||||
) -> Result<host::__wasi_ciovec_t, host::__wasi_errno_t> {
|
) -> Result<host::__wasi_ciovec_t, host::__wasi_errno_t> {
|
||||||
let len = cast::usize(ciovec.buf_len);
|
let len = usize::try_from(ciovec.buf_len).unwrap();
|
||||||
Ok(host::__wasi_ciovec_t {
|
Ok(host::__wasi_ciovec_t {
|
||||||
buf: decode_ptr(vmctx, ciovec.buf, len, 1)? as *const host::void,
|
buf: decode_ptr(vmctx, ciovec.buf, len, 1)? as *const host::void,
|
||||||
buf_len: len,
|
buf_len: len,
|
||||||
@@ -285,7 +284,7 @@ pub unsafe fn decode_iovec(
|
|||||||
vmctx: &mut VMContext,
|
vmctx: &mut VMContext,
|
||||||
iovec: &wasm32::__wasi_iovec_t,
|
iovec: &wasm32::__wasi_iovec_t,
|
||||||
) -> Result<host::__wasi_iovec_t, host::__wasi_errno_t> {
|
) -> Result<host::__wasi_iovec_t, host::__wasi_errno_t> {
|
||||||
let len = cast::usize(iovec.buf_len);
|
let len = usize::try_from(iovec.buf_len).unwrap();
|
||||||
Ok(host::__wasi_iovec_t {
|
Ok(host::__wasi_iovec_t {
|
||||||
buf: decode_ptr(vmctx, iovec.buf, len, 1)? as *mut host::void,
|
buf: decode_ptr(vmctx, iovec.buf, len, 1)? as *mut host::void,
|
||||||
buf_len: len,
|
buf_len: len,
|
||||||
@@ -416,7 +415,7 @@ pub unsafe fn encode_fd_byref(
|
|||||||
fd_ptr: wasm32::uintptr_t,
|
fd_ptr: wasm32::uintptr_t,
|
||||||
fd: host::__wasi_fd_t,
|
fd: host::__wasi_fd_t,
|
||||||
) {
|
) {
|
||||||
encode_pointee::<wasm32::__wasi_fd_t>(vmctx, fd_ptr, wasm32::size_t::cast(fd))
|
encode_pointee::<wasm32::__wasi_fd_t>(vmctx, fd_ptr, wasm32::size_t::try_from(fd).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn decode_timestamp_byref(
|
pub unsafe fn decode_timestamp_byref(
|
||||||
@@ -434,7 +433,7 @@ pub unsafe fn encode_timestamp_byref(
|
|||||||
encode_pointee::<wasm32::__wasi_timestamp_t>(
|
encode_pointee::<wasm32::__wasi_timestamp_t>(
|
||||||
vmctx,
|
vmctx,
|
||||||
timestamp_ptr,
|
timestamp_ptr,
|
||||||
wasm32::__wasi_timestamp_t::cast(host_timestamp),
|
wasm32::__wasi_timestamp_t::try_from(host_timestamp).unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +452,7 @@ pub unsafe fn encode_filesize_byref(
|
|||||||
encode_pointee::<wasm32::__wasi_filesize_t>(
|
encode_pointee::<wasm32::__wasi_filesize_t>(
|
||||||
vmctx,
|
vmctx,
|
||||||
filesize_ptr,
|
filesize_ptr,
|
||||||
wasm32::__wasi_filesize_t::cast(host_filesize),
|
wasm32::__wasi_filesize_t::try_from(host_filesize).unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +471,7 @@ pub unsafe fn encode_roflags_byref(
|
|||||||
encode_pointee::<wasm32::__wasi_roflags_t>(
|
encode_pointee::<wasm32::__wasi_roflags_t>(
|
||||||
vmctx,
|
vmctx,
|
||||||
roflags_ptr,
|
roflags_ptr,
|
||||||
wasm32::__wasi_roflags_t::cast(host_roflags),
|
wasm32::__wasi_roflags_t::try_from(host_roflags).unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,7 +487,11 @@ pub unsafe fn encode_usize_byref(
|
|||||||
usize_ptr: wasm32::uintptr_t,
|
usize_ptr: wasm32::uintptr_t,
|
||||||
host_usize: usize,
|
host_usize: usize,
|
||||||
) {
|
) {
|
||||||
encode_pointee::<wasm32::size_t>(vmctx, usize_ptr, wasm32::size_t::cast(host_usize).unwrap())
|
encode_pointee::<wasm32::size_t>(
|
||||||
|
vmctx,
|
||||||
|
usize_ptr,
|
||||||
|
wasm32::size_t::try_from(host_usize).unwrap(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn decode_prestat_byref(
|
pub unsafe fn decode_prestat_byref(
|
||||||
|
|||||||
Reference in New Issue
Block a user