Skip to content

Commit

Permalink
Merge branch 'master' into fix-runtime-c-api-error-length
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed May 13, 2019
2 parents 216e000 + b222731 commit b050144
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 65 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ Blocks of changes will separated by version increments.
## **[Unreleased]**

- [#432](https://github.com/wasmerio/wasmer/pull/432) Fix returned value of `wasmer_last_error_message` in the runtime C API
- [#429](https://github.com/wasmerio/wasmer/pull/429) Get wasi::path_filestat_get working for some programs; misc. minor WASI FS improvements
- [#413](https://github.com/wasmerio/wasmer/pull/413) Update LLVM backend to use new parser codegen traits

## 0.4.1 - 2018-05-06
Expand Down
2 changes: 2 additions & 0 deletions lib/clif-backend/src/lib.rs
@@ -1,3 +1,5 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

mod cache;
mod func_env;
mod libcalls;
Expand Down
2 changes: 2 additions & 0 deletions lib/emscripten/src/lib.rs
@@ -1,3 +1,5 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

#[macro_use]
extern crate wasmer_runtime_core;

Expand Down
3 changes: 2 additions & 1 deletion lib/emscripten/src/syscalls/unix.rs
@@ -1,4 +1,6 @@
use crate::varargs::VarArgs;
#[cfg(target_os = "macos")]
use libc::size_t;
/// NOTE: TODO: These syscalls only support wasm_32 for now because they assume offsets are u32
/// Syscall list: https://www.cs.utexas.edu/~bismith/test/syscalls/syscalls32.html
use libc::{
Expand Down Expand Up @@ -53,7 +55,6 @@ use libc::{
sendto,
setpgid,
setsockopt,
size_t,
sockaddr,
socket,
socklen_t,
Expand Down
1 change: 1 addition & 0 deletions lib/llvm-backend/src/lib.rs
@@ -1,3 +1,4 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]
#![cfg_attr(nightly, feature(unwind_attributes))]

mod backend;
Expand Down
2 changes: 1 addition & 1 deletion lib/llvm-backend/src/platform/unix.rs
Expand Up @@ -34,7 +34,7 @@ pub unsafe fn visit_fde(addr: *mut u8, size: usize, visitor: extern "C" fn(*mut
}

#[cfg(not(target_os = "macos"))]
pub unsafe fn visit_fde(addr: *mut u8, size: usize, visitor: extern "C" fn(*mut u8)) {
pub unsafe fn visit_fde(addr: *mut u8, _size: usize, visitor: extern "C" fn(*mut u8)) {
visitor(addr);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/middleware-common/src/call_trace.rs
Expand Up @@ -10,7 +10,7 @@ impl FunctionMiddleware for CallTrace {
fn feed_event<'a, 'b: 'a>(
&mut self,
op: Event<'a, 'b>,
module_info: &ModuleInfo,
_module_info: &ModuleInfo,
sink: &mut EventSink<'a, 'b>,
) -> Result<(), Self::Error> {
match op {
Expand Down
2 changes: 2 additions & 0 deletions lib/middleware-common/src/lib.rs
@@ -1 +1,3 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

pub mod call_trace;
2 changes: 2 additions & 0 deletions lib/runtime-abi/src/lib.rs
@@ -1,3 +1,5 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

#[cfg(not(target_os = "windows"))]
#[macro_use]
extern crate failure;
Expand Down
2 changes: 2 additions & 0 deletions lib/runtime-c-api/src/lib.rs
@@ -1,3 +1,5 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

extern crate wasmer_runtime;
extern crate wasmer_runtime_core;

Expand Down
3 changes: 1 addition & 2 deletions lib/runtime-core/src/codegen.rs
@@ -1,6 +1,6 @@
use crate::{
backend::RunnableModule,
backend::{sys::Memory, Backend, CacheGen, Compiler, CompilerConfig, Token},
backend::{Backend, CacheGen, Compiler, CompilerConfig, Token},
cache::{Artifact, Error as CacheError},
error::{CompileError, CompileResult},
module::{ModuleInfo, ModuleInner},
Expand Down Expand Up @@ -35,7 +35,6 @@ impl fmt::Debug for InternalEvent {
InternalEvent::Breakpoint(_) => write!(f, "Breakpoint"),
InternalEvent::SetInternal(_) => write!(f, "SetInternal"),
InternalEvent::GetInternal(_) => write!(f, "GetInternal"),
_ => panic!("unknown event"),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/runtime-core/src/lib.rs
@@ -1,3 +1,4 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]
#![cfg_attr(nightly, feature(unwind_attributes))]

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions lib/runtime-core/src/typed_func.rs
Expand Up @@ -247,7 +247,7 @@ impl<A: WasmExternType> WasmTypeList for (A,) {
type CStruct = S1<A>;
type RetArray = [u64; 1];
fn from_ret_array(array: Self::RetArray) -> Self {
(WasmExternType::from_native(NativeWasmType::from_bits(
(WasmExternType::from_native(NativeWasmType::from_binary(
array[0],
)),)
}
Expand All @@ -274,7 +274,7 @@ impl<A: WasmExternType> WasmTypeList for (A,) {
ctx: *mut Ctx,
) -> Result<Rets, RuntimeError> {
let (a,) = self;
let args = [a.to_native().to_bits()];
let args = [a.to_native().to_binary()];
let mut rets = Rets::empty_ret_array();
let mut trap = WasmTrapInfo::Unknown;
let mut user_error = None;
Expand Down Expand Up @@ -322,7 +322,7 @@ macro_rules! impl_traits {
fn from_ret_array(array: Self::RetArray) -> Self {
#[allow(non_snake_case)]
let [ $( $x ),* ] = array;
( $( WasmExternType::from_native(NativeWasmType::from_bits($x)) ),* )
( $( WasmExternType::from_native(NativeWasmType::from_binary($x)) ),* )
}
fn empty_ret_array() -> Self::RetArray {
[0; count_idents!( $( $x ),* )]
Expand All @@ -344,7 +344,7 @@ macro_rules! impl_traits {
unsafe fn call<Rets: WasmTypeList>(self, f: NonNull<vm::Func>, wasm: Wasm, ctx: *mut Ctx) -> Result<Rets, RuntimeError> {
#[allow(unused_parens)]
let ( $( $x ),* ) = self;
let args = [ $( $x.to_native().to_bits() ),* ];
let args = [ $( $x.to_native().to_binary()),* ];
let mut rets = Rets::empty_ret_array();
let mut trap = WasmTrapInfo::Unknown;
let mut user_error = None;
Expand Down
83 changes: 69 additions & 14 deletions lib/runtime-core/src/types.rs
Expand Up @@ -76,44 +76,44 @@ where
Self: Sized,
{
const TYPE: Type;
fn from_bits(bits: u64) -> Self;
fn to_bits(self) -> u64;
fn from_binary(bits: u64) -> Self;
fn to_binary(self) -> u64;
}

unsafe impl NativeWasmType for i32 {
const TYPE: Type = Type::I32;
fn from_bits(bits: u64) -> Self {
fn from_binary(bits: u64) -> Self {
bits as _
}
fn to_bits(self) -> u64 {
fn to_binary(self) -> u64 {
self as _
}
}
unsafe impl NativeWasmType for i64 {
const TYPE: Type = Type::I64;
fn from_bits(bits: u64) -> Self {
fn from_binary(bits: u64) -> Self {
bits as _
}
fn to_bits(self) -> u64 {
fn to_binary(self) -> u64 {
self as _
}
}
unsafe impl NativeWasmType for f32 {
const TYPE: Type = Type::F32;
fn from_bits(bits: u64) -> Self {
bits as _
fn from_binary(bits: u64) -> Self {
f32::from_bits(bits as u32)
}
fn to_bits(self) -> u64 {
self as _
fn to_binary(self) -> u64 {
self.to_bits() as _
}
}
unsafe impl NativeWasmType for f64 {
const TYPE: Type = Type::F64;
fn from_bits(bits: u64) -> Self {
bits as _
fn from_binary(bits: u64) -> Self {
f64::from_bits(bits)
}
fn to_bits(self) -> u64 {
self as _
fn to_binary(self) -> u64 {
self.to_bits()
}
}

Expand Down Expand Up @@ -516,3 +516,58 @@ where
}
}
}

#[cfg(test)]
mod tests {
use crate::types::NativeWasmType;
use crate::types::WasmExternType;

#[test]
fn test_native_types_round_trip() {
assert_eq!(
42i32,
i32::from_native(i32::from_binary((42i32).to_native().to_binary()))
);

assert_eq!(
-42i32,
i32::from_native(i32::from_binary((-42i32).to_native().to_binary()))
);

use std::i64;
let xi64 = i64::MAX;
assert_eq!(
xi64,
i64::from_native(i64::from_binary((xi64).to_native().to_binary()))
);
let yi64 = i64::MIN;
assert_eq!(
yi64,
i64::from_native(i64::from_binary((yi64).to_native().to_binary()))
);

assert_eq!(
16.5f32,
f32::from_native(f32::from_binary((16.5f32).to_native().to_binary()))
);

assert_eq!(
-16.5f32,
f32::from_native(f32::from_binary((-16.5f32).to_native().to_binary()))
);

use std::f64;
let xf64: f64 = f64::MAX;
assert_eq!(
xf64,
f64::from_native(f64::from_binary((xf64).to_native().to_binary()))
);

let yf64: f64 = f64::MIN;
assert_eq!(
yf64,
f64::from_native(f64::from_binary((yf64).to_native().to_binary()))
);
}

}
2 changes: 2 additions & 0 deletions lib/runtime/src/lib.rs
@@ -1,3 +1,5 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

//! Wasmer-runtime is a library that makes embedding WebAssembly
//! in your application easy, efficient, and safe.
//!
Expand Down
12 changes: 6 additions & 6 deletions lib/singlepass-backend/src/codegen_x64.rs
Expand Up @@ -212,10 +212,10 @@ impl RunnableModule for X64ExecutionContext {
user_error: *mut Option<Box<dyn Any>>,
num_params_plus_one: Option<NonNull<c_void>>,
) -> bool {
let rm: &Box<dyn RunnableModule> = &unsafe { &*(*ctx).module }.runnable_module;
let execution_context = unsafe {
::std::mem::transmute_copy::<&dyn RunnableModule, &X64ExecutionContext>(&&**rm)
};
let rm: &Box<dyn RunnableModule> = &(&*(*ctx).module).runnable_module;
let execution_context =
::std::mem::transmute_copy::<&dyn RunnableModule, &X64ExecutionContext>(&&**rm);

let args = ::std::slice::from_raw_parts(
args,
num_params_plus_one.unwrap().as_ptr() as usize - 1,
Expand Down Expand Up @@ -478,7 +478,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
Ok(())
}

unsafe fn from_cache(artifact: Artifact, _: Token) -> Result<ModuleInner, CacheError> {
unsafe fn from_cache(_artifact: Artifact, _: Token) -> Result<ModuleInner, CacheError> {
Err(CacheError::Unknown(
"the singlepass compiler API doesn't support caching yet".to_string(),
))
Expand Down Expand Up @@ -1409,7 +1409,7 @@ impl FunctionCodeGenerator<CodegenError> for X64FunctionCode {
Ok(())
}

fn begin_body(&mut self, module_info: &ModuleInfo) -> Result<(), CodegenError> {
fn begin_body(&mut self, _module_info: &ModuleInfo) -> Result<(), CodegenError> {
let a = self.assembler.as_mut().unwrap();
a.emit_push(Size::S64, Location::GPR(GPR::RBP));
a.emit_mov(Size::S64, Location::GPR(GPR::RSP), Location::GPR(GPR::RBP));
Expand Down
1 change: 1 addition & 0 deletions lib/singlepass-backend/src/lib.rs
@@ -1,3 +1,4 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]
#![feature(proc_macro_hygiene)]

#[cfg(not(any(
Expand Down
2 changes: 2 additions & 0 deletions lib/wasi/src/lib.rs
@@ -1,3 +1,5 @@
#![deny(unused_imports, unused_variables, unused_unsafe, unreachable_patterns)]

#[macro_use]
extern crate log;

Expand Down

0 comments on commit b050144

Please sign in to comment.