Skip to content

Commit

Permalink
Merge branch 'master' into ventuzelo/fix-800-index-oob-backing
Browse files Browse the repository at this point in the history
  • Loading branch information
pventuzelo authored Sep 23, 2019
2 parents acf8dc7 + 7d9e6d8 commit 4a47ea8
Show file tree
Hide file tree
Showing 41 changed files with 422 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ links to related issues, and the context of the PR.

# Review

- [ ] Create a short description of the the change in the CHANGELOG.md file
- [ ] Add a short description of the the change to the CHANGELOG.md file
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#821](https://github.com/wasmerio/wasmer/issues/821) Remove patch version on most deps Cargo manifests. This gives Wasmer library users more control over which versions of the deps they use.
- [#820](https://github.com/wasmerio/wasmer/issues/820) Remove null-pointer checks in `WasmPtr` from runtime-core, re-add them in Emscripten
- [#803](https://github.com/wasmerio/wasmer/issues/803) Add method to `Ctx` to invoke functions by their `TableIndex`
- [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model.
- [#788](https://github.com/wasmerio/wasmer/pull/788) Use union merge on the changelog file.
- [#785](https://github.com/wasmerio/wasmer/pull/785) Include Apache license file for spectests.
Expand Down
69 changes: 0 additions & 69 deletions Cargo.lock

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

16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ include = [
]

[dependencies]
byteorder = "1.3.2"
errno = "0.2.4"
structopt = "0.3.0"
byteorder = "1.3"
errno = "0.2"
structopt = "0.3"
wabt = "0.9.1"
wasmer-clif-backend = { path = "lib/clif-backend" }
wasmer-singlepass-backend = { path = "lib/singlepass-backend", optional = true }
Expand Down Expand Up @@ -58,13 +58,13 @@ members = [
"lib/wasi-tests",
"lib/emscripten-tests",
"lib/middleware-common-tests",
"examples/plugin-for-example"
"examples/plugin-for-example",
]

[build-dependencies]
wabt = "0.9.1"
glob = "0.3.0"
rustc_version = "0.2.3"
glob = "0.3"
rustc_version = "0.2"

[dev-dependencies]
serde = { version = "1", features = ["derive"] } # used by the plugin example
Expand Down Expand Up @@ -105,3 +105,7 @@ managed = ["backend-singlepass", "wasmer-runtime-core/managed"]
[[example]]
name = "plugin"
crate-type = ["bin"]

[[example]]
name = "callback"
crate-type = ["bin"]
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: spectests emtests clean build install lint precommit docs
.PHONY: spectests emtests clean build install lint precommit docs examples

# Generate files
generate-spectests:
Expand Down Expand Up @@ -111,12 +111,16 @@ test: spectests emtests middleware wasitests circleci-clean test-rest


# Integration tests
integration-tests: release-clif
integration-tests: release-clif examples
echo "Running Integration Tests"
./integration_tests/lua/test.sh
./integration_tests/nginx/test.sh
./integration_tests/cowsay/test.sh

examples:
cargo run --example plugin
cargo run --example callback


# Utils
lint:
Expand Down
5 changes: 5 additions & 0 deletions examples/callback-guest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Call back guest

This is part of the `callback` example. This Wasm module passes host imports and its own functions to the Wasm host to execute.

See `examples/callback.rs` for the host
24 changes: 24 additions & 0 deletions examples/callback-guest/callback-guest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern "C" {
fn call_guest_fn(f: u32) -> u32;
fn call_guest_fn2(f: u32) -> u32;
fn host_callback() -> u32;
}

#[no_mangle]
fn test_callback() -> u32 {
42
}

#[no_mangle]
fn test_callback2() -> u32 {
45
}

fn main() {
unsafe { call_guest_fn(test_callback as usize as u32) };
unsafe { call_guest_fn(host_callback as usize as u32) };
unsafe { call_guest_fn(test_callback2 as usize as u32) };
unsafe { call_guest_fn2(test_callback2 as usize as u32) };
unsafe { call_guest_fn2(test_callback as usize as u32) };
unsafe { call_guest_fn2(host_callback as usize as u32) };
}
Binary file added examples/callback-guest/callback-guest.wasm
Binary file not shown.
46 changes: 46 additions & 0 deletions examples/callback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/// This example demonstrates the use of callbacks: calling functions (Host and Wasm)
/// passed to us from the Wasm via hostcall
use wasmer_runtime::{compile_with, compiler_for_backend, func, imports, Backend, Ctx};
use wasmer_runtime_core::{structures::TypedIndex, types::TableIndex};

static WASM: &'static str = "examples/callback-guest/callback-guest.wasm";

/// This function matches our arbitrarily decided callback signature
/// in this example we'll only call functions that take no arguments and return one value
fn host_callback(_ctx: &mut Ctx) -> u32 {
55
}

fn call_guest_fn(ctx: &mut Ctx, guest_fn: u32) -> u32 {
// We get a TableIndex from our raw value passed in
let guest_fn_typed = TableIndex::new(guest_fn as usize);
// and use it to call the corresponding function
let result = ctx.call_with_table_index(guest_fn_typed, &[]).unwrap();

println!("Guest fn {} returned {:?}", guest_fn, result);

0
}

fn main() {
let wasm_bytes =
std::fs::read(WASM).expect(&format!("Could not read in WASM plugin at {}", WASM));

let imports = imports! {
"env" => {
"call_guest_fn" => func!(call_guest_fn),
"call_guest_fn2" => func!(call_guest_fn),
"host_callback" => func!(host_callback),
},
};

let compiler = compiler_for_backend(Backend::default()).unwrap();
let module = compile_with(&wasm_bytes[..], compiler.as_ref()).unwrap();
let instance = module
.instantiate(&imports)
.expect("failed to instantiate wasm module");

let entry_point = instance.func::<(u32, u32), u32>("main").unwrap();

entry_point.call(0, 0).expect("START");
}
16 changes: 8 additions & 8 deletions lib/clif-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ cranelift-codegen = { version = "0.31" }
cranelift-entity = { version = "0.31" }
cranelift-frontend = { package = "wasmer-clif-fork-frontend", version = "0.33" }
cranelift-wasm = { package = "wasmer-clif-fork-wasm", version = "0.33" }
target-lexicon = "0.4.0"
target-lexicon = "0.4"
wasmparser = "0.35.1"
byteorder = "1.3.2"
nix = "0.15.0"
byteorder = "1.3"
nix = "0.15"
libc = "0.2.60"
rayon = "1.1.0"
rayon = "1.1"

# Dependencies for caching.
[dependencies.serde]
version = "1.0.99"
version = "1.0"
features = ["rc"]
[dependencies.serde_derive]
version = "1.0.98"
version = "1.0"
[dependencies.serde_bytes]
version = "0.11.2"
version = "0.11"
[dependencies.serde-bench]
version = "0.0.7"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.8", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] }
winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] }
wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.7.0" }

[features]
Expand Down
2 changes: 1 addition & 1 deletion lib/emscripten-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wabt = "0.9.1"
wasmer-dev-utils = { path = "../dev-utils", version = "0.7.0"}

[build-dependencies]
glob = "0.3.0"
glob = "0.3"

[features]
clif = []
Expand Down
8 changes: 4 additions & 4 deletions lib/emscripten/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ repository = "https://github.com/wasmerio/wasmer"
edition = "2018"

[dependencies]
byteorder = "1.3.2"
lazy_static = "1.4.0"
byteorder = "1.3"
lazy_static = "1.4"
libc = "0.2.60"
time = "0.1.42"
time = "0.1"
wasmer-runtime-core = { path = "../runtime-core", version = "0.7.0" }

[target.'cfg(windows)'.dependencies]
rand = "0.7.0"
rand = "0.7"

[features]
debug = ["wasmer-runtime-core/debug"]
Loading

0 comments on commit 4a47ea8

Please sign in to comment.