Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Mar 19, 2020
1 parent 5b68a72 commit 0689e8a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions crates/api/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ impl Func {
// Create our actual trampoline function which translates from a bunch
// of bit patterns on the stack to actual instances of `Val` being
// passed to the given function.
let func = Box::new(move |caller_vmctx, values_vec: *mut i128| {
let func = Box::new(move |caller_vmctx, values_vec: *mut u128| {
// We have a dynamic guarantee that `values_vec` has the right
// number of arguments and the right types of arguments. As a result
// we should be able to safely run through them all and read them.
let mut args = Vec::with_capacity(ty_clone.params().len());
for (i, ty) in ty_clone.params().iter().enumerate() {
unsafe {
args.push(Val::read_value_from(values_vec.offset(i as isize), ty));
args.push(Val::read_value_from(values_vec.add(i), ty));
}
}
let mut returns = vec![Val::null(); ty_clone.results().len()];
Expand Down Expand Up @@ -532,7 +532,7 @@ impl Func {
ptr::null_mut(),
self.trampoline,
self.export.address,
values_vec.as_mut_ptr() as *mut u8,
values_vec.as_mut_ptr(),
)
} {
return Err(Trap::from_jit(error));
Expand Down
8 changes: 4 additions & 4 deletions crates/api/src/trampoline/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use wasmtime_jit::{native, CodeMemory};
use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody, VMTrampoline};

struct TrampolineState {
func: Box<dyn Fn(*mut VMContext, *mut i128) -> Result<(), Trap>>,
func: Box<dyn Fn(*mut VMContext, *mut u128) -> Result<(), Trap>>,
#[allow(dead_code)]
code_memory: CodeMemory,
}

unsafe extern "C" fn stub_fn(
vmctx: *mut VMContext,
caller_vmctx: *mut VMContext,
values_vec: *mut i128,
values_vec: *mut u128,
) {
// Here we are careful to use `catch_unwind` to ensure Rust panics don't
// unwind past us. The primary reason for this is that Rust considers it UB
Expand Down Expand Up @@ -69,7 +69,7 @@ unsafe extern "C" fn stub_fn(
unsafe fn call_stub(
vmctx: *mut VMContext,
caller_vmctx: *mut VMContext,
values_vec: *mut i128,
values_vec: *mut u128,
) -> Result<(), Trap> {
let instance = InstanceHandle::from_vmctx(vmctx);
let state = &instance
Expand Down Expand Up @@ -201,7 +201,7 @@ fn make_trampoline(

pub fn create_handle_with_function(
ft: &FuncType,
func: Box<dyn Fn(*mut VMContext, *mut i128) -> Result<(), Trap>>,
func: Box<dyn Fn(*mut VMContext, *mut u128) -> Result<(), Trap>>,
store: &Store,
) -> Result<(InstanceHandle, VMTrampoline)> {
let isa = {
Expand Down
2 changes: 1 addition & 1 deletion crates/api/src/trampoline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use wasmtime_runtime::{VMContext, VMFunctionBody, VMTrampoline};

pub fn generate_func_export(
ft: &FuncType,
func: Box<dyn Fn(*mut VMContext, *mut i128) -> Result<(), Trap>>,
func: Box<dyn Fn(*mut VMContext, *mut u128) -> Result<(), Trap>>,
store: &Store,
) -> Result<(
wasmtime_runtime::InstanceHandle,
Expand Down
4 changes: 2 additions & 2 deletions crates/api/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Val {
}
}

pub(crate) unsafe fn write_value_to(&self, p: *mut i128) {
pub(crate) unsafe fn write_value_to(&self, p: *mut u128) {
match self {
Val::I32(i) => ptr::write(p as *mut i32, *i),
Val::I64(i) => ptr::write(p as *mut i64, *i),
Expand All @@ -91,7 +91,7 @@ impl Val {
}
}

pub(crate) unsafe fn read_value_from(p: *const i128, ty: &ValType) -> Val {
pub(crate) unsafe fn read_value_from(p: *const u128, ty: &ValType) -> Val {
match ty {
ValType::I32 => Val::I32(ptr::read(p as *const i32)),
ValType::I64 => Val::I64(ptr::read(p as *const i64)),
Expand Down
8 changes: 2 additions & 6 deletions crates/runtime/src/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::any::Any;
use std::cell::Cell;
use std::error::Error;
use std::fmt;
use std::mem;
use std::ptr;
use wasmtime_environ::ir;

Expand Down Expand Up @@ -172,13 +171,10 @@ pub unsafe fn wasmtime_call_trampoline(
caller_vmctx: *mut VMContext,
trampoline: VMTrampoline,
callee: *const VMFunctionBody,
values_vec: *mut u8,
values_vec: *mut u128,
) -> Result<(), Trap> {
catch_traps(vmctx, || {
mem::transmute::<
_,
extern "C" fn(*mut VMContext, *mut VMContext, *const VMFunctionBody, *mut u8),
>(trampoline)(vmctx, caller_vmctx, callee, values_vec)
trampoline(vmctx, caller_vmctx, callee, values_vec)
})
}

Expand Down

0 comments on commit 0689e8a

Please sign in to comment.