mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 05:01:33 +00:00
Merge master into feature/llvm-backend
This commit is contained in:
@ -32,7 +32,7 @@ impl IsExport for Export {
|
||||
/// },
|
||||
/// };
|
||||
///
|
||||
/// fn foo(n: i32, _: &mut Ctx) -> i32 {
|
||||
/// fn foo(_: &mut Ctx, n: i32) -> i32 {
|
||||
/// n
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -38,7 +38,7 @@ macro_rules! func {
|
||||
/// },
|
||||
/// };
|
||||
///
|
||||
/// fn foo(n: i32, _: &mut Ctx) -> i32 {
|
||||
/// fn foo(_: &mut Ctx, n: i32) -> i32 {
|
||||
/// n
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -150,7 +150,8 @@ impl Drop for Memory {
|
||||
fn drop(&mut self) {
|
||||
if !self.ptr.is_null() {
|
||||
let success = unsafe { VirtualFree(self.ptr as _, self.size, MEM_DECOMMIT) };
|
||||
assert_eq!(success, 0, "failed to unmap memory: {}", errno::errno());
|
||||
// If the function succeeds, the return value is nonzero.
|
||||
assert_eq!(success, 1, "failed to unmap memory: {}", errno::errno());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,9 +138,9 @@ impl<A: WasmExternType> WasmTypeList for (A,) {
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
unsafe fn call<Rets: WasmTypeList>(self, f: *const (), ctx: *mut Ctx) -> Rets {
|
||||
let f: extern "C" fn(A, *mut Ctx) -> Rets = mem::transmute(f);
|
||||
let f: extern "C" fn(*mut Ctx, A) -> Rets = mem::transmute(f);
|
||||
let (a,) = self;
|
||||
f(a, ctx)
|
||||
f(ctx, a)
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,24 +175,24 @@ macro_rules! impl_traits {
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
unsafe fn call<Rets: WasmTypeList>(self, f: *const (), ctx: *mut Ctx) -> Rets {
|
||||
let f: extern fn( $( $x, )* *mut Ctx) -> Rets::CStruct = mem::transmute(f);
|
||||
let f: extern fn(*mut Ctx $( ,$x )*) -> Rets::CStruct = mem::transmute(f);
|
||||
#[allow(unused_parens)]
|
||||
let ( $( $x ),* ) = self;
|
||||
let c_struct = f( $( $x, )* ctx);
|
||||
let c_struct = f(ctx $( ,$x )*);
|
||||
Rets::from_c_struct(c_struct)
|
||||
}
|
||||
}
|
||||
|
||||
impl< $( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly<Rets>, FN: Fn( $( $x, )* &mut Ctx) -> Trap> ExternalFunction<($( $x ),*), Rets> for FN {
|
||||
impl< $( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly<Rets>, FN: Fn( &mut Ctx $( ,$x )* ) -> Trap> ExternalFunction<($( $x ),*), Rets> for FN {
|
||||
#[allow(non_snake_case)]
|
||||
fn to_raw(&self) -> *const () {
|
||||
assert_eq!(mem::size_of::<Self>(), 0, "you cannot use a closure that captures state for `Func`.");
|
||||
|
||||
extern fn wrap<$( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly<Rets>, FN: Fn( $( $x, )* &mut Ctx) -> Trap>( $( $x: $x, )* ctx: &mut Ctx) -> Rets::CStruct {
|
||||
extern fn wrap<$( $x: WasmExternType, )* Rets: WasmTypeList, Trap: TrapEarly<Rets>, FN: Fn( &mut Ctx $( ,$x )* ) -> Trap>( ctx: &mut Ctx $( ,$x: $x )* ) -> Rets::CStruct {
|
||||
let f: FN = unsafe { mem::transmute_copy(&()) };
|
||||
|
||||
let msg = match panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
f( $( $x, )* ctx).report()
|
||||
f( ctx $( ,$x )* ).report()
|
||||
})) {
|
||||
Ok(Ok(returns)) => return returns.into_c_struct(),
|
||||
Ok(Err(err)) => err,
|
||||
@ -271,7 +271,7 @@ mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_call() {
|
||||
fn foo(a: i32, b: i32, _ctx: &mut Ctx) -> (i32, i32) {
|
||||
fn foo(_ctx: &mut Ctx, a: i32, b: i32) -> (i32, i32) {
|
||||
(a, b)
|
||||
}
|
||||
|
||||
@ -282,7 +282,7 @@ mod tests {
|
||||
fn test_imports() {
|
||||
use crate::{func, imports};
|
||||
|
||||
fn foo(a: i32, _ctx: &mut Ctx) -> i32 {
|
||||
fn foo(_ctx: &mut Ctx, a: i32) -> i32 {
|
||||
a
|
||||
}
|
||||
|
||||
|
@ -169,6 +169,7 @@ enum InnerFunc {}
|
||||
/// Used to provide type safety (ish) for passing around function pointers.
|
||||
/// The typesystem ensures this cannot be dereferenced since an
|
||||
/// empty enum cannot actually exist.
|
||||
#[repr(C)]
|
||||
pub struct Func(InnerFunc);
|
||||
|
||||
/// An imported function, which contains the vmctx that owns this function.
|
||||
|
@ -13,9 +13,9 @@ use crate::{
|
||||
// +****************************+
|
||||
|
||||
pub unsafe extern "C" fn local_static_memory_grow(
|
||||
ctx: &mut vm::Ctx,
|
||||
memory_index: LocalMemoryIndex,
|
||||
delta: Pages,
|
||||
ctx: &mut vm::Ctx,
|
||||
) -> i32 {
|
||||
let local_memory = *ctx.memories.add(memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut StaticMemory;
|
||||
@ -28,8 +28,8 @@ pub unsafe extern "C" fn local_static_memory_grow(
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn local_static_memory_size(
|
||||
memory_index: LocalMemoryIndex,
|
||||
ctx: &vm::Ctx,
|
||||
memory_index: LocalMemoryIndex,
|
||||
) -> Pages {
|
||||
let local_memory = *ctx.memories.add(memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut StaticMemory;
|
||||
@ -38,9 +38,9 @@ pub unsafe extern "C" fn local_static_memory_size(
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn local_dynamic_memory_grow(
|
||||
ctx: &mut vm::Ctx,
|
||||
memory_index: LocalMemoryIndex,
|
||||
delta: Pages,
|
||||
ctx: &mut vm::Ctx,
|
||||
) -> i32 {
|
||||
let local_memory = *ctx.memories.add(memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut DynamicMemory;
|
||||
@ -53,8 +53,8 @@ pub unsafe extern "C" fn local_dynamic_memory_grow(
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn local_dynamic_memory_size(
|
||||
memory_index: LocalMemoryIndex,
|
||||
ctx: &vm::Ctx,
|
||||
memory_index: LocalMemoryIndex,
|
||||
) -> Pages {
|
||||
let local_memory = *ctx.memories.add(memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut DynamicMemory;
|
||||
@ -67,9 +67,9 @@ pub unsafe extern "C" fn local_dynamic_memory_size(
|
||||
// +****************************+
|
||||
|
||||
pub unsafe extern "C" fn imported_static_memory_grow(
|
||||
ctx: &mut vm::Ctx,
|
||||
import_memory_index: ImportedMemoryIndex,
|
||||
delta: Pages,
|
||||
ctx: &mut vm::Ctx,
|
||||
) -> i32 {
|
||||
let local_memory = *ctx.imported_memories.add(import_memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut StaticMemory;
|
||||
@ -82,8 +82,8 @@ pub unsafe extern "C" fn imported_static_memory_grow(
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn imported_static_memory_size(
|
||||
import_memory_index: ImportedMemoryIndex,
|
||||
ctx: &vm::Ctx,
|
||||
import_memory_index: ImportedMemoryIndex,
|
||||
) -> Pages {
|
||||
let local_memory = *ctx.imported_memories.add(import_memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut StaticMemory;
|
||||
@ -92,9 +92,9 @@ pub unsafe extern "C" fn imported_static_memory_size(
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn imported_dynamic_memory_grow(
|
||||
ctx: &mut vm::Ctx,
|
||||
memory_index: ImportedMemoryIndex,
|
||||
delta: Pages,
|
||||
ctx: &mut vm::Ctx,
|
||||
) -> i32 {
|
||||
let local_memory = *ctx.imported_memories.add(memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut DynamicMemory;
|
||||
@ -107,8 +107,8 @@ pub unsafe extern "C" fn imported_dynamic_memory_grow(
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn imported_dynamic_memory_size(
|
||||
memory_index: ImportedMemoryIndex,
|
||||
ctx: &vm::Ctx,
|
||||
memory_index: ImportedMemoryIndex,
|
||||
) -> Pages {
|
||||
let local_memory = *ctx.imported_memories.add(memory_index.index());
|
||||
let memory = (*local_memory).memory as *mut DynamicMemory;
|
||||
@ -121,9 +121,9 @@ pub unsafe extern "C" fn imported_dynamic_memory_size(
|
||||
// +****************************+
|
||||
|
||||
pub unsafe extern "C" fn local_table_grow(
|
||||
ctx: &mut vm::Ctx,
|
||||
table_index: LocalTableIndex,
|
||||
delta: u32,
|
||||
ctx: &mut vm::Ctx,
|
||||
) -> i32 {
|
||||
let _ = table_index;
|
||||
let _ = delta;
|
||||
@ -131,7 +131,7 @@ pub unsafe extern "C" fn local_table_grow(
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub unsafe extern "C" fn local_table_size(table_index: LocalTableIndex, ctx: &vm::Ctx) -> u32 {
|
||||
pub unsafe extern "C" fn local_table_size(ctx: &vm::Ctx, table_index: LocalTableIndex) -> u32 {
|
||||
let _ = table_index;
|
||||
let _ = ctx;
|
||||
unimplemented!()
|
||||
|
Reference in New Issue
Block a user