Skip to content

Commit

Permalink
Merge branch 'master' into backend-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary authored Jan 10, 2020
2 parents f353ac0 + 50f3079 commit 9ca9770
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#1128](https://github.com/wasmerio/wasmer/pull/1128) Fix a crash when a host function is missing and the `allow_missing_functions` flag is enabled
- [#1099](https://github.com/wasmerio/wasmer/pull/1099) Remove `backend::Backend` from `wasmer_runtime_core`
- [#1097](https://github.com/wasmerio/wasmer/pull/1097) Move inline breakpoint outside of runtime backend
- [#1095](https://github.com/wasmerio/wasmer/pull/1095) Update to cranelift 0.52.
Expand Down
71 changes: 54 additions & 17 deletions Cargo.lock

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

27 changes: 20 additions & 7 deletions lib/runtime-c-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,31 @@ fn main() {

let mut pre_header = r#"
#if !defined(WASMER_H_MACROS)
#define WASMER_H_MACROS
#if defined(MSVC)
#if defined(_M_AMD64)
#define ARCH_X86_64
// Define the `ARCH_X86_X64` constant.
#if defined(MSVC) && defined(_M_AMD64)
# define ARCH_X86_64
#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__)
# define ARCH_X86_64
#endif
// Compatibility with non-Clang compilers.
#if !defined(__has_attribute)
# define __has_attribute(x) 0
#endif
#if defined(GCC) || defined(__GNUC__) || defined(__clang__)
#if defined(__x86_64__)
#define ARCH_X86_64
// Compatibility with non-Clang compilers.
#if !defined(__has_declspec_attribute)
# define __has_declspec_attribute(x) 0
#endif
// Define the `DEPRECATED` macro.
#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated)
# define DEPRECATED(message) __attribute__((deprecated(message)))
#elif defined(MSVC) || __has_declspec_attribute(deprecated)
# define DEPRECATED(message) __declspec(deprecated(message))
#endif
"#
Expand All @@ -41,7 +54,7 @@ fn main() {
pre_header += "#define WASMER_EMSCRIPTEN_ENABLED\n";
}

// close pre header
// Close pre header.
pre_header += "#endif // WASMER_H_MACROS\n";

// Generate the C bindings in the `OUT_DIR`.
Expand Down
25 changes: 19 additions & 6 deletions lib/runtime-c-api/wasmer.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@

#if !defined(WASMER_H_MACROS)

#define WASMER_H_MACROS

#if defined(MSVC)
#if defined(_M_AMD64)
#define ARCH_X86_64
// Define the `ARCH_X86_X64` constant.
#if defined(MSVC) && defined(_M_AMD64)
# define ARCH_X86_64
#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__)
# define ARCH_X86_64
#endif

// Compatibility with non-Clang compilers.
#if !defined(__has_attribute)
# define __has_attribute(x) 0
#endif

#if defined(GCC) || defined(__GNUC__) || defined(__clang__)
#if defined(__x86_64__)
#define ARCH_X86_64
// Compatibility with non-Clang compilers.
#if !defined(__has_declspec_attribute)
# define __has_declspec_attribute(x) 0
#endif

// Define the `DEPRECATED` macro.
#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated)
# define DEPRECATED(message) __attribute__((deprecated(message)))
#elif defined(MSVC) || __has_declspec_attribute(deprecated)
# define DEPRECATED(message) __declspec(deprecated(message))
#endif

#define WASMER_WASI_ENABLED
Expand Down
25 changes: 19 additions & 6 deletions lib/runtime-c-api/wasmer.hh
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@

#if !defined(WASMER_H_MACROS)

#define WASMER_H_MACROS

#if defined(MSVC)
#if defined(_M_AMD64)
#define ARCH_X86_64
// Define the `ARCH_X86_X64` constant.
#if defined(MSVC) && defined(_M_AMD64)
# define ARCH_X86_64
#elif (defined(GCC) || defined(__GNUC__) || defined(__clang__)) && defined(__x86_64__)
# define ARCH_X86_64
#endif

// Compatibility with non-Clang compilers.
#if !defined(__has_attribute)
# define __has_attribute(x) 0
#endif

#if defined(GCC) || defined(__GNUC__) || defined(__clang__)
#if defined(__x86_64__)
#define ARCH_X86_64
// Compatibility with non-Clang compilers.
#if !defined(__has_declspec_attribute)
# define __has_declspec_attribute(x) 0
#endif

// Define the `DEPRECATED` macro.
#if defined(GCC) || defined(__GNUC__) || __has_attribute(deprecated)
# define DEPRECATED(message) __attribute__((deprecated(message)))
#elif defined(MSVC) || __has_declspec_attribute(deprecated)
# define DEPRECATED(message) __declspec(deprecated(message))
#endif

#define WASMER_WASI_ENABLED
Expand Down
26 changes: 18 additions & 8 deletions lib/runtime-core/src/backing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ use crate::{
sig_registry::SigRegistry,
structures::{BoxedMap, Map, SliceMap, TypedIndex},
table::Table,
typed_func::{always_trap, Func},
types::{
ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex,
Initializer, LocalFuncIndex, LocalGlobalIndex, LocalMemoryIndex, LocalOrImport,
LocalTableIndex, SigIndex, Value,
},
vm,
};
use std::{
fmt::Debug,
ptr::{self, NonNull},
slice,
};
use std::{fmt::Debug, ptr::NonNull, slice};

/// Size of the array for internal instance usage
pub const INTERNALS_SIZE: usize = 256;
Expand Down Expand Up @@ -563,7 +560,11 @@ impl Drop for ImportBacking {
fn drop(&mut self) {
// Properly drop the `vm::FuncCtx` in `vm::ImportedFunc`.
for (_imported_func_index, imported_func) in (*self.vm_functions).iter_mut() {
let _: Box<vm::FuncCtx> = unsafe { Box::from_raw(imported_func.func_ctx.as_ptr()) };
let func_ctx_ptr = imported_func.func_ctx.as_ptr();

if !func_ctx_ptr.is_null() {
let _: Box<vm::FuncCtx> = unsafe { Box::from_raw(func_ctx_ptr) };
}
}
}
}
Expand Down Expand Up @@ -650,9 +651,18 @@ fn import_functions(
}
None => {
if imports.allow_missing_functions {
let always_trap = Func::new(always_trap);

functions.push(vm::ImportedFunc {
func: ptr::null(),
func_ctx: unsafe { NonNull::new_unchecked(ptr::null_mut()) }, // TODO: Non-sense…
func: always_trap.get_vm_func().as_ptr(),
func_ctx: NonNull::new(Box::into_raw(Box::new(vm::FuncCtx {
// ^^^^^^^^ `vm::FuncCtx` is purposely leaked.
// It is dropped by the specific `Drop`
// implementation of `ImportBacking`.
vmctx: NonNull::new(vmctx).expect("`vmctx` must not be null."),
func_env: None,
})))
.unwrap(),
});
} else {
link_errors.push(LinkError::ImportNotFound {
Expand Down
16 changes: 11 additions & 5 deletions lib/runtime-core/src/typed_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ where
_phantom: PhantomData,
}
}

/// Get the underlying func pointer.
pub fn get_vm_func(&self) -> NonNull<vm::Func> {
self.func
}
}

impl<'a, Args, Rets> Func<'a, Args, Rets, Host>
Expand Down Expand Up @@ -303,6 +298,11 @@ where
pub fn returns(&self) -> &'static [Type] {
Rets::types()
}

/// Get the underlying func pointer.
pub fn get_vm_func(&self) -> NonNull<vm::Func> {
self.func
}
}

impl WasmTypeList for Infallible {
Expand Down Expand Up @@ -733,6 +733,12 @@ where
}
}

/// Function that always fails. It can be used as a placeholder when a
/// host function is missing for instance.
pub(crate) fn always_trap() -> Result<(), &'static str> {
Err("not implemented")
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 9ca9770

Please sign in to comment.