mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 00:00:49 +00:00
Merge branch 'master' into fix/table-import-memory-repr-rebased
# Conflicts: # .circleci/config.yml # install.sh # src/build_spectests.rs # src/linkers/emscripten/abort.rs # src/linkers/emscripten/mod.rs # src/linkers/mod.rs # src/main.rs # src/webassembly/instance.rs # src/webassembly/memory.rs # src/webassembly/mod.rs # src/webassembly/module.rs
This commit is contained in:
commit
7977d09fc7
@ -10,7 +10,6 @@ jobs:
|
||||
keys:
|
||||
- v4-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}
|
||||
- run: sudo apt-get install -y cmake
|
||||
- run: rustup default nightly-2018-10-07
|
||||
- run: make test
|
||||
- run:
|
||||
command: |
|
||||
@ -50,9 +49,9 @@ jobs:
|
||||
tar xf cmake-3.4.1-Darwin-x86_64.tar.gz
|
||||
export PATH="`pwd`/cmake-3.4.1-Darwin-x86_64/CMake.app/Contents/bin:$PATH"
|
||||
- run:
|
||||
name: Install Rust Nightly
|
||||
name: Install Rust
|
||||
command: |
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2018-10-07
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
cargo --version
|
||||
- run:
|
||||
|
27
Cargo.lock
generated
27
Cargo.lock
generated
@ -238,6 +238,11 @@ dependencies = [
|
||||
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.43"
|
||||
source = "git+https://github.com/rust-lang/libc#5cc006652a242c35b6fe5b615ccd39d9356a2346"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.43"
|
||||
@ -436,11 +441,6 @@ dependencies = [
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.4.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.7.0"
|
||||
@ -578,18 +578,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "wabt"
|
||||
version = "0.6.0"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wabt-sys"
|
||||
version = "0.4.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -606,18 +606,17 @@ dependencies = [
|
||||
"cranelift-wasm 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.43 (git+https://github.com/rust-lang/libc)",
|
||||
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"region 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"structopt 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-lexicon 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wabt 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"wasmparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -679,6 +678,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
|
||||
"checksum libc 0.2.43 (git+https://github.com/rust-lang/libc)" = "<none>"
|
||||
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
|
||||
"checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f"
|
||||
"checksum mach 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2fd13ee2dd61cc82833ba05ade5a30bb3d63f7ced605ef827063c63078302de9"
|
||||
@ -703,7 +703,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9"
|
||||
"checksum serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "31569d901045afbff7a9479f793177fe9259819aff10ab4f89ef69bbc5f567fe"
|
||||
"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce"
|
||||
"checksum spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ceac490aa12c567115b40b7b7fceca03a6c9d53d5defea066123debc83c5dc1f"
|
||||
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
|
||||
"checksum structopt 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ca85f2c9a5a1e2d5ac686fc0be48e40f8ad803f5bbe31f692ff71eb2dd8aad45"
|
||||
"checksum structopt-derive 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "1383e5db585da799a5c4acc496c5c868e18bf82e658c00c75cc91038fa26b55f"
|
||||
@ -722,8 +721,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||
"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
|
||||
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
||||
"checksum wabt 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0768faf932f2898c0a7545edee648fefa716906a2e143009addf4959d2335a75"
|
||||
"checksum wabt-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4aaa9a8fa0d698315da5611f3e113a1e688fbb8d6fa0dd9510dfa023f665e9dc"
|
||||
"checksum wabt 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5b24b2494bd6077dff717f41523f6e3e0161d58f578198589a6a6c8b314cb763"
|
||||
"checksum wabt-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "122aefe1d22c067cce1dc5d20d89d1ca47ce0eb10120246a3e2340863f9e6ddd"
|
||||
"checksum wasmparser 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc6511bad33610d7798f80d48e10495a6eb4f1e39306b0bb340b2de0816c4ca"
|
||||
"checksum wasmparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2a75e0c3fe9a4d4fd91901348a5be05ba4791e29dda89e8596bfe87900ba7edc"
|
||||
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
|
||||
|
11
Cargo.toml
11
Cargo.toml
@ -2,7 +2,7 @@
|
||||
name = "wasmer"
|
||||
version = "0.1.0"
|
||||
authors = ["Syrus Akbary <me@syrusakbary.com>"]
|
||||
edition = "2018"
|
||||
# edition = "2018"
|
||||
repository = "https://github.com/wafoundation/wasmer"
|
||||
publish = true
|
||||
description = "High-Performance WebAssembly JIT interpreter"
|
||||
@ -34,18 +34,19 @@ serde_derive = "1.0.55"
|
||||
tempdir = "0.3.7"
|
||||
error-chain = "0.12.0"
|
||||
structopt = "0.2.11"
|
||||
wabt = "0.6.0"
|
||||
wabt = "0.7.1"
|
||||
wasmparser = "0.20.0"
|
||||
region = "0.3.0"
|
||||
memmap = "0.6.2"
|
||||
spin = "0.4.10"
|
||||
# spin = "0.4.10"
|
||||
log = "0.4.5"
|
||||
target-lexicon = { version = "0.0.3", default-features = false }
|
||||
libc = "0.2"
|
||||
# libc = "0.2"
|
||||
libc = { git = "https://github.com/rust-lang/libc" }
|
||||
nix = "0.11"
|
||||
|
||||
[build-dependencies]
|
||||
wabt = "0.6.0"
|
||||
wabt = "0.7.1"
|
||||
|
||||
# [dev-dependencies]
|
||||
# libffi = "0.6.4"
|
||||
|
@ -29,9 +29,6 @@ To build this project you will need Rust and Cargo.
|
||||
git clone https://github.com/wafoundation/wasmer.git
|
||||
cd wasmer
|
||||
|
||||
# Use rust nightly (we use 2018-10-07 as latest are failing)
|
||||
rustup default nightly-2018-10-07
|
||||
|
||||
# install tools
|
||||
# make sure that `python` is accessible.
|
||||
cargo install
|
||||
@ -44,7 +41,7 @@ Thanks to [spectests](https://github.com/WAFoundation/wasmer/tree/master/spectes
|
||||
Tests can be run with:
|
||||
|
||||
```sh
|
||||
cargo test
|
||||
make test
|
||||
```
|
||||
|
||||
If you need to re-generate the Rust tests from the spectests
|
||||
|
BIN
examples/pypyjs.wasm
Normal file
BIN
examples/pypyjs.wasm
Normal file
Binary file not shown.
5
examples/trap.wat
Normal file
5
examples/trap.wat
Normal file
@ -0,0 +1,5 @@
|
||||
(module
|
||||
(func $main (export "main") (result i32)
|
||||
(i32.div_s (i32.const 0) (i32.const 0))
|
||||
)
|
||||
)
|
16
install.sh
16
install.sh
@ -227,22 +227,22 @@ wasmer_install() {
|
||||
|
||||
printf "${reset}Installing Wasmer!$reset\n"
|
||||
printf "
|
||||
${magenta3}###${reset}
|
||||
${magenta3}#####${reset}
|
||||
${magenta2}### ${magenta3}######${reset}
|
||||
${magenta2}###### ${magenta3}#############${reset}
|
||||
${magenta1}#${magenta2} ####### ${magenta3}##############${reset}
|
||||
${magenta1}#####${magenta2} #############${magenta3}#########${reset}
|
||||
${magenta1} ${magenta2} ${magenta3}###${reset}
|
||||
${magenta1} ${magenta2} ${magenta3}#####${reset}
|
||||
${magenta1} ${magenta2}### ${magenta3}######${reset}
|
||||
${magenta1} ${magenta2}###### ${magenta3}#############${reset}
|
||||
${magenta1}# ${magenta2}####### ${magenta3}##############${reset}
|
||||
${magenta1}##### ${magenta2}#############${magenta3}#########${reset}
|
||||
${magenta1}######${magenta2}###############${magenta3}#######${reset}
|
||||
${magenta1}############${magenta2}#########${magenta3}#######${reset}
|
||||
${magenta1}##############${magenta2}#######${magenta3}#######${reset}
|
||||
${magenta1}##############${magenta2}#######${magenta3}#######${reset}
|
||||
${magenta1}##############${magenta2}#######${magenta3}#######${reset}
|
||||
${magenta1}##############${magenta2}####### ${magenta3}###${reset}
|
||||
${magenta1}##############${magenta2}#######${magenta3} ###${reset}
|
||||
${magenta1}##############${magenta2}#######
|
||||
${magenta1}###########${magenta2} ###
|
||||
${magenta1}########${magenta2}
|
||||
${magenta1}####${reset}
|
||||
${magenta1}####${reset}
|
||||
|
||||
"
|
||||
# if [ -d "$HOME/.wasmer" ]; then
|
||||
|
@ -1,6 +1,8 @@
|
||||
//! This file will run at build time to autogenerate Rust tests based on
|
||||
//! WebAssembly spec tests. It will convert the files indicated in TESTS
|
||||
//! from "/spectests/{MODULE}.wast" to "/src/spectests/{MODULE}.rs".
|
||||
extern crate wabt;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
@ -206,8 +208,7 @@ fn test_module_{}() {{
|
||||
module,
|
||||
module,
|
||||
calls.join("\n ")
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
}
|
||||
self.module_calls.remove(&module);
|
||||
@ -216,7 +217,8 @@ fn test_module_{}() {{
|
||||
fn visit_module(&mut self, module: &ModuleBinary, _name: &Option<String>) {
|
||||
let wasm_binary: Vec<u8> = module.clone().into_vec();
|
||||
let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
|
||||
self.flush_module_calls(self.last_module);
|
||||
let last_module = self.last_module;
|
||||
self.flush_module_calls(last_module);
|
||||
self.last_module = self.last_module + 1;
|
||||
// self.module_calls.insert(self.last_module, vec![]);
|
||||
self.buffer.push_str(
|
||||
@ -232,8 +234,7 @@ fn test_module_{}() {{
|
||||
.replace("\n", "\n ")
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\""),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
|
||||
// We set the start call to the module
|
||||
@ -244,8 +245,7 @@ fn test_module_{}() {{
|
||||
result_object.instance.start();
|
||||
}}\n",
|
||||
start_module_call
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
self.module_calls
|
||||
.entry(self.last_module)
|
||||
@ -256,6 +256,7 @@ fn test_module_{}() {{
|
||||
fn visit_assert_invalid(&mut self, module: &ModuleBinary) {
|
||||
let wasm_binary: Vec<u8> = module.clone().into_vec();
|
||||
// let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
|
||||
let command_name = self.command_name();
|
||||
self.buffer.push_str(
|
||||
format!(
|
||||
"#[test]
|
||||
@ -264,13 +265,12 @@ fn {}_assert_invalid() {{
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), \"WASM should not compile as is invalid\");
|
||||
}}\n",
|
||||
self.command_name(),
|
||||
command_name,
|
||||
wasm_binary,
|
||||
// We do this to ident four spaces back
|
||||
// String::from_utf8_lossy(&wasm_binary),
|
||||
// wast_string.replace("\n", "\n "),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -312,8 +312,7 @@ fn {}_assert_invalid() {{
|
||||
func_return,
|
||||
args_values.join(", "),
|
||||
assertion,
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
self.module_calls
|
||||
.entry(self.last_module)
|
||||
@ -370,8 +369,7 @@ fn {}_assert_invalid() {{
|
||||
func_return,
|
||||
args_values.join(", "),
|
||||
assertion,
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
self.module_calls
|
||||
.entry(self.last_module)
|
||||
@ -386,6 +384,7 @@ fn {}_assert_invalid() {{
|
||||
|
||||
fn visit_assert_malformed(&mut self, module: &ModuleBinary) {
|
||||
let wasm_binary: Vec<u8> = module.clone().into_vec();
|
||||
let command_name = self.command_name();
|
||||
// let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
|
||||
self.buffer.push_str(
|
||||
format!(
|
||||
@ -395,13 +394,12 @@ fn {}_assert_malformed() {{
|
||||
let compilation = compile(wasm_binary.to_vec());
|
||||
assert!(compilation.is_err(), \"WASM should not compile as is malformed\");
|
||||
}}\n",
|
||||
self.command_name(),
|
||||
command_name,
|
||||
wasm_binary,
|
||||
// We do this to ident four spaces back
|
||||
// String::from_utf8_lossy(&wasm_binary),
|
||||
// wast_string.replace("\n", "\n "),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -465,8 +463,7 @@ fn {}_assert_malformed() {{
|
||||
func_return,
|
||||
args_values.join(", "),
|
||||
assertion,
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
Some(func_name)
|
||||
// let mut module_calls = self.module_calls.get(&self.last_module).unwrap();
|
||||
@ -521,8 +518,7 @@ fn {}() {{
|
||||
trap_func_name,
|
||||
self.last_module,
|
||||
action_fn_name.unwrap(),
|
||||
)
|
||||
.as_str(),
|
||||
).as_str(),
|
||||
);
|
||||
|
||||
// We don't group trap calls as they may cause memory faults
|
||||
|
@ -1,9 +1,7 @@
|
||||
|
||||
use crate::webassembly::Instance;
|
||||
use std::process;
|
||||
|
||||
|
||||
pub extern "C" fn abort(_code: i32, _instance: &Instance) {
|
||||
process::abort();
|
||||
// abort!("Aborted")
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::webassembly::{ImportObject, ImportValue};
|
||||
|
||||
mod abort;
|
||||
mod printf;
|
||||
mod putchar;
|
||||
mod abort;
|
||||
|
||||
pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
|
||||
let mut import_object = ImportObject::new();
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
pub mod emscripten;
|
||||
|
||||
pub use self::emscripten::generate_emscripten_env;
|
||||
|
36
src/main.rs
36
src/main.rs
@ -1,19 +1,19 @@
|
||||
#![feature(test, libc, core_intrinsics)]
|
||||
|
||||
extern crate test;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
extern crate cranelift_codegen;
|
||||
extern crate cranelift_entity;
|
||||
extern crate cranelift_native;
|
||||
extern crate cranelift_wasm;
|
||||
extern crate libc;
|
||||
extern crate memmap;
|
||||
extern crate region;
|
||||
extern crate structopt;
|
||||
extern crate wabt;
|
||||
extern crate wasmparser;
|
||||
#[macro_use]
|
||||
extern crate target_lexicon;
|
||||
extern crate nix;
|
||||
extern crate spin;
|
||||
use std::error::Error;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
@ -21,7 +21,6 @@ use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
use structopt::StructOpt;
|
||||
use wabt::wat2wasm;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
@ -51,7 +50,7 @@ struct Run {
|
||||
}
|
||||
|
||||
/// Read the contents of a file
|
||||
fn read_file_contents(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
fn read_file_contents(path: &PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
let mut file = File::open(path)?;
|
||||
file.read_to_end(&mut buffer)?;
|
||||
@ -60,16 +59,22 @@ fn read_file_contents(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
|
||||
/// Execute a WASM/WAT file
|
||||
fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> {
|
||||
let mut wasm_binary: Vec<u8> =
|
||||
read_file_contents(wasm_path).map_err(|err| String::from(err.description()))?;
|
||||
let mut wasm_binary: Vec<u8> = read_file_contents(&wasm_path).map_err(|err| {
|
||||
format!(
|
||||
"Can't read the file {}: {}",
|
||||
wasm_path.as_os_str().to_string_lossy(),
|
||||
err
|
||||
)
|
||||
})?;
|
||||
if !webassembly::utils::is_wasm_binary(&wasm_binary) {
|
||||
wasm_binary = wat2wasm(wasm_binary).map_err(|err| String::from(err.description()))?;
|
||||
wasm_binary = wabt::wat2wasm(wasm_binary)
|
||||
.map_err(|err| format!("Can't convert from wast to wasm: {:?}", err))?;
|
||||
}
|
||||
|
||||
let import_object = linkers::generate_emscripten_env();
|
||||
let webassembly::ResultObject { module, instance } =
|
||||
webassembly::instantiate(wasm_binary, import_object)
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
.map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?;
|
||||
|
||||
webassembly::utils::print_instance_offsets(&instance);
|
||||
|
||||
@ -79,9 +84,8 @@ fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> {
|
||||
Some(&webassembly::Export::Function(index)) => index,
|
||||
_ => panic!("Main function not found"),
|
||||
});
|
||||
let main: fn(&webassembly::Instance) -> i32 = get_instance_function!(instance, func_index);
|
||||
let result = main(&instance);
|
||||
println!("RESULT {}", result);
|
||||
let main: fn(&webassembly::Instance) = get_instance_function!(instance, func_index);
|
||||
main(&instance);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -89,8 +93,8 @@ fn run(options: Run) {
|
||||
match execute_wasm(options.path.clone()) {
|
||||
Ok(()) => {}
|
||||
Err(message) => {
|
||||
let name = options.path.as_os_str().to_string_lossy();
|
||||
println!("error while executing {}: {}", name, message);
|
||||
// let name = options.path.as_os_str().to_string_lossy();
|
||||
println!("{}", message);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,11 @@
|
||||
//! Please read more about this here: https://github.com/CraneStation/wasmtime/issues/15
|
||||
//! This code is inspired by: https://github.com/pepyakin/wasmtime/commit/625a2b6c0815b21996e111da51b9664feb174622
|
||||
use nix::sys::signal::{
|
||||
sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
|
||||
sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
|
||||
};
|
||||
|
||||
static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27];
|
||||
|
||||
pub unsafe fn install_sighandler() {
|
||||
let sa = SigAction::new(
|
||||
SigHandler::Handler(signal_trap_handler),
|
||||
@ -18,22 +20,29 @@ pub unsafe fn install_sighandler() {
|
||||
sigaction(SIGILL, &sa).unwrap();
|
||||
sigaction(SIGSEGV, &sa).unwrap();
|
||||
sigaction(SIGBUS, &sa).unwrap();
|
||||
let result = setjmp((&mut SETJMP_BUFFER[..]).as_mut_ptr() as *mut ::nix::libc::c_void);
|
||||
if result != 0 {
|
||||
panic!("Signal Error: {}", result);
|
||||
let signum = setjmp((&mut SETJMP_BUFFER[..]).as_mut_ptr() as *mut ::nix::libc::c_void);
|
||||
if signum != 0 {
|
||||
let signal = Signal::from_c_int(signum).unwrap();
|
||||
match signal {
|
||||
SIGFPE => panic!("floating-point exception"),
|
||||
SIGILL => panic!("illegal instruction"),
|
||||
SIGSEGV => panic!("segmentation violation"),
|
||||
SIGBUS => panic!("bus error"),
|
||||
_ => panic!("signal error: {:?}", signal),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static mut SETJMP_BUFFER: [::nix::libc::c_int; 27] = [0; 27];
|
||||
extern "C" {
|
||||
fn setjmp(env: *mut ::nix::libc::c_void) -> ::nix::libc::c_int;
|
||||
fn longjmp(env: *mut ::nix::libc::c_void, val: ::nix::libc::c_int);
|
||||
}
|
||||
extern "C" fn signal_trap_handler(_: ::nix::libc::c_int) {
|
||||
|
||||
extern "C" fn signal_trap_handler(signum: ::nix::libc::c_int) {
|
||||
unsafe {
|
||||
longjmp(
|
||||
(&mut SETJMP_BUFFER).as_mut_ptr() as *mut ::nix::libc::c_void,
|
||||
3,
|
||||
signum,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"16u_bad\" (func 27))
|
||||
(export \"16s_bad\" (func 28))
|
||||
(export \"32_bad\" (func 29))
|
||||
(data (i32.const 0) \"abcdefghijklmnopqrstuvwxyz\"))
|
||||
(data (;0;) (i32.const 0) \"abcdefghijklmnopqrstuvwxyz\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -1545,7 +1545,7 @@ fn create_module_2() -> ResultObject {
|
||||
(export \"32u_bad\" (func 39))
|
||||
(export \"32s_bad\" (func 40))
|
||||
(export \"64_bad\" (func 41))
|
||||
(data (i32.const 0) \"abcdefghijklmnopqrstuvwxyz\"))
|
||||
(data (;0;) (i32.const 0) \"abcdefghijklmnopqrstuvwxyz\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -3260,7 +3260,7 @@ fn create_module_3() -> ResultObject {
|
||||
(export \"32_good4\" (func 3))
|
||||
(export \"32_good5\" (func 4))
|
||||
(export \"32_bad\" (func 5))
|
||||
(data (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\a0\\7f\\01\\00\\d0\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\a0\\7f\\01\\00\\d0\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -3554,7 +3554,7 @@ fn create_module_4() -> ResultObject {
|
||||
(export \"64_good4\" (func 3))
|
||||
(export \"64_good5\" (func 4))
|
||||
(export \"64_bad\" (func 5))
|
||||
(data (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\f4\\7f\\01\\00\\00\\00\\00\\00\\fc\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\00\\f4\\7f\\01\\00\\00\\00\\00\\00\\fc\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -519,7 +519,7 @@ fn test_module_14() {
|
||||
fn create_module_15() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 0)
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -540,7 +540,7 @@ fn test_module_15() {
|
||||
fn create_module_16() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(table (;0;) 0 anyfunc)
|
||||
(elem (i32.const 0)))
|
||||
(elem (;0;) (i32.const 0)))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -530,7 +530,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"break-repeated\" (func 41))
|
||||
(export \"break-inner\" (func 42))
|
||||
(export \"effects\" (func 43))
|
||||
(elem (i32.const 0) 19))
|
||||
(elem (;0;) (i32.const 0) 19))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -562,7 +562,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"nested-br_if-value-cond\" (func 58))
|
||||
(export \"nested-br_table-value\" (func 59))
|
||||
(export \"nested-br_table-value-index\" (func 60))
|
||||
(elem (i32.const 0) 30))
|
||||
(elem (;0;) (i32.const 0) 30))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -574,7 +574,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"nested-br_if-value-cond\" (func 51))
|
||||
(export \"nested-br_table-value\" (func 52))
|
||||
(export \"nested-br_table-value-index\" (func 53))
|
||||
(elem (i32.const 0) 36))
|
||||
(elem (;0;) (i32.const 0) 36))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -781,7 +781,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"nested-br_table-value\" (func 66))
|
||||
(export \"nested-br_table-value-index\" (func 67))
|
||||
(export \"nested-br_table-loop-block\" (func 68))
|
||||
(elem (i32.const 0) 37))
|
||||
(elem (;0;) (i32.const 0) 37))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -316,7 +316,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"as-tee_local-value\" (func 51))
|
||||
(export \"as-set_global-value\" (func 52))
|
||||
(export \"as-load-operand\" (func 53))
|
||||
(elem (i32.const 0) 40))
|
||||
(elem (;0;) (i32.const 0) 40))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -512,7 +512,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"as-tee_local-value\" (func 63))
|
||||
(export \"as-set_global-value\" (func 64))
|
||||
(export \"as-load-operand\" (func 65))
|
||||
(elem (i32.const 0) 0 1 2 3 4 5 6 7 10 8 11 9 35 36 43 44 45 46 47 12 13 14 15 37 38 39 40 41 42))
|
||||
(elem (;0;) (i32.const 0) 0 1 2 3 4 5 6 7 10 8 11 9 35 36 43 44 45 46 47 12 13 14 15 37 38 39 40 41 42))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -19,18 +19,18 @@ use super::_common::{
|
||||
fn create_module_1() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 1)
|
||||
(data (i32.const 0) \"\")
|
||||
(data (i32.const 1) \"abcd\")
|
||||
(data (i32.const 0) \"\")
|
||||
(data (i32.const 0) \"abc\")
|
||||
(data (i32.const 0) \"\")
|
||||
(data (i32.const 1) \"abcd\")
|
||||
(data (i32.const 0) \"\")
|
||||
(data (i32.const 0) \"abc\")
|
||||
(data (i32.const 0) \"\")
|
||||
(data (i32.const 1) \"abcd\")
|
||||
(data (i32.const 0) \"\")
|
||||
(data (i32.const 0) \"abc\"))
|
||||
(data (;0;) (i32.const 0) \"\")
|
||||
(data (;1;) (i32.const 1) \"abcd\")
|
||||
(data (;2;) (i32.const 0) \"\")
|
||||
(data (;3;) (i32.const 0) \"abc\")
|
||||
(data (;4;) (i32.const 0) \"\")
|
||||
(data (;5;) (i32.const 1) \"abcd\")
|
||||
(data (;6;) (i32.const 0) \"\")
|
||||
(data (;7;) (i32.const 0) \"abc\")
|
||||
(data (;8;) (i32.const 0) \"\")
|
||||
(data (;9;) (i32.const 1) \"abcd\")
|
||||
(data (;10;) (i32.const 0) \"\")
|
||||
(data (;11;) (i32.const 0) \"abc\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -51,7 +51,7 @@ fn test_module_1() {
|
||||
fn create_module_2() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 1)
|
||||
(data (i32.const 0) \"a\"))
|
||||
(data (;0;) (i32.const 0) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -72,7 +72,7 @@ fn test_module_2() {
|
||||
fn create_module_3() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 1))
|
||||
(data (i32.const 0) \"a\"))
|
||||
(data (;0;) (i32.const 0) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -93,11 +93,11 @@ fn test_module_3() {
|
||||
fn create_module_4() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 1)
|
||||
(data (i32.const 0) \"a\")
|
||||
(data (i32.const 3) \"b\")
|
||||
(data (i32.const 100) \"cde\")
|
||||
(data (i32.const 5) \"x\")
|
||||
(data (i32.const 3) \"c\"))
|
||||
(data (;0;) (i32.const 0) \"a\")
|
||||
(data (;1;) (i32.const 3) \"b\")
|
||||
(data (;2;) (i32.const 100) \"cde\")
|
||||
(data (;3;) (i32.const 5) \"x\")
|
||||
(data (;4;) (i32.const 3) \"c\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -118,12 +118,12 @@ fn test_module_4() {
|
||||
fn create_module_5() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 1))
|
||||
(data (i32.const 0) \"a\")
|
||||
(data (i32.const 1) \"b\")
|
||||
(data (i32.const 2) \"cde\")
|
||||
(data (i32.const 3) \"f\")
|
||||
(data (i32.const 2) \"g\")
|
||||
(data (i32.const 1) \"h\"))
|
||||
(data (;0;) (i32.const 0) \"a\")
|
||||
(data (;1;) (i32.const 1) \"b\")
|
||||
(data (;2;) (i32.const 2) \"cde\")
|
||||
(data (;3;) (i32.const 3) \"f\")
|
||||
(data (;4;) (i32.const 2) \"g\")
|
||||
(data (;5;) (i32.const 1) \"h\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -144,8 +144,8 @@ fn test_module_5() {
|
||||
fn create_module_6() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 1)
|
||||
(data (i32.const 0) \"a\")
|
||||
(data (i32.const 65535) \"b\"))
|
||||
(data (;0;) (i32.const 0) \"a\")
|
||||
(data (;1;) (i32.const 65535) \"b\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -166,8 +166,8 @@ fn test_module_6() {
|
||||
fn create_module_7() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 1))
|
||||
(data (i32.const 0) \"a\")
|
||||
(data (i32.const 65535) \"b\"))
|
||||
(data (;0;) (i32.const 0) \"a\")
|
||||
(data (;1;) (i32.const 65535) \"b\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -188,7 +188,7 @@ fn test_module_7() {
|
||||
fn create_module_8() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 2)
|
||||
(data (i32.const 131071) \"a\"))
|
||||
(data (;0;) (i32.const 131071) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -209,7 +209,7 @@ fn test_module_8() {
|
||||
fn create_module_9() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 0)
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -230,7 +230,7 @@ fn test_module_9() {
|
||||
fn create_module_10() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 0))
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -251,7 +251,7 @@ fn test_module_10() {
|
||||
fn create_module_11() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 0 0)
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -272,7 +272,7 @@ fn test_module_11() {
|
||||
fn create_module_12() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 1)
|
||||
(data (i32.const 65536) \"\"))
|
||||
(data (;0;) (i32.const 65536) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -293,7 +293,7 @@ fn test_module_12() {
|
||||
fn create_module_13() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 0)
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -314,7 +314,7 @@ fn test_module_13() {
|
||||
fn create_module_14() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 0))
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -335,7 +335,7 @@ fn test_module_14() {
|
||||
fn create_module_15() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(memory (;0;) 0 0)
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -356,7 +356,7 @@ fn test_module_15() {
|
||||
fn create_module_16() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 0))
|
||||
(data (i32.const 0) \"a\"))
|
||||
(data (;0;) (i32.const 0) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -377,7 +377,7 @@ fn test_module_16() {
|
||||
fn create_module_17() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 0 3))
|
||||
(data (i32.const 0) \"a\"))
|
||||
(data (;0;) (i32.const 0) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -398,7 +398,7 @@ fn test_module_17() {
|
||||
fn create_module_18() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 0))
|
||||
(data (i32.const 1) \"a\"))
|
||||
(data (;0;) (i32.const 1) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -419,7 +419,7 @@ fn test_module_18() {
|
||||
fn create_module_19() -> ResultObject {
|
||||
let module_str = "(module
|
||||
(import \"spectest\" \"memory\" (memory (;0;) 0 3))
|
||||
(data (i32.const 1) \"a\"))
|
||||
(data (;0;) (i32.const 1) \"a\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
File diff suppressed because one or more lines are too long
@ -45,7 +45,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"f32.store\" (func 2))
|
||||
(export \"i32.store\" (func 3))
|
||||
(export \"reset\" (func 4))
|
||||
(data (i32.const 0) \"\\00\\00\\a0\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\00\\00\\a0\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -277,7 +277,7 @@ fn create_module_2() -> ResultObject {
|
||||
(export \"f64.store\" (func 2))
|
||||
(export \"i64.store\" (func 3))
|
||||
(export \"reset\" (func 4))
|
||||
(data (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\f4\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\f4\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -509,7 +509,7 @@ fn create_module_3() -> ResultObject {
|
||||
(export \"f32.store\" (func 2))
|
||||
(export \"i32.store\" (func 3))
|
||||
(export \"reset\" (func 4))
|
||||
(data (i32.const 0) \"\\00\\00\\00\\a0\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\00\\00\\00\\a0\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -741,7 +741,7 @@ fn create_module_4() -> ResultObject {
|
||||
(export \"f64.store\" (func 2))
|
||||
(export \"i64.store\" (func 3))
|
||||
(export \"reset\" (func 4))
|
||||
(data (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\00\\f4\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\00\\00\\00\\00\\00\\00\\00\\f4\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -973,7 +973,7 @@ fn create_module_5() -> ResultObject {
|
||||
(export \"f32.store\" (func 2))
|
||||
(export \"i32.store\" (func 3))
|
||||
(export \"reset\" (func 4))
|
||||
(data (i32.const 0) \"\\01\\00\\d0\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\01\\00\\d0\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -1205,7 +1205,7 @@ fn create_module_6() -> ResultObject {
|
||||
(export \"f64.store\" (func 2))
|
||||
(export \"i64.store\" (func 3))
|
||||
(export \"reset\" (func 4))
|
||||
(data (i32.const 0) \"\\01\\00\\00\\00\\00\\00\\fc\\7f\"))
|
||||
(data (;0;) (i32.const 0) \"\\01\\00\\00\\00\\00\\00\\fc\\7f\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -1359,7 +1359,7 @@ fn create_module_3() -> ResultObject {
|
||||
(export \"signature-implicit-reused\" (func 8))
|
||||
(export \"signature-explicit-duplicate\" (func 9))
|
||||
(export \"signature-implicit-duplicate\" (func 10))
|
||||
(elem (i32.const 0) 4 2 1 4 0 5 6))
|
||||
(elem (;0;) (i32.const 0) 4 2 1 4 0 5 6))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -194,7 +194,7 @@ fn create_module_2() -> ResultObject {
|
||||
(table (;0;) 7 7 anyfunc)
|
||||
(export \"callt\" (func 5))
|
||||
(export \"callu\" (func 6))
|
||||
(elem (i32.const 0) 0 1 2 3 4 0 2))
|
||||
(elem (;0;) (i32.const 0) 0 1 2 3 4 0 2))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -533,7 +533,7 @@ fn create_module_3() -> ResultObject {
|
||||
call_indirect (type 0))
|
||||
(table (;0;) 2 2 anyfunc)
|
||||
(export \"callt\" (func 2))
|
||||
(elem (i32.const 0) 0 1))
|
||||
(elem (;0;) (i32.const 0) 0 1))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -269,7 +269,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"as-unary-operand\" (func 42))
|
||||
(export \"as-binary-operand\" (func 43))
|
||||
(export \"as-compare-operand\" (func 44))
|
||||
(elem (i32.const 0) 26))
|
||||
(elem (;0;) (i32.const 0) 26))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -635,7 +635,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"break-bare\" (func 36))
|
||||
(export \"break-value\" (func 37))
|
||||
(export \"effects\" (func 38))
|
||||
(elem (i32.const 0) 16))
|
||||
(elem (;0;) (i32.const 0) 16))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -959,7 +959,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"f64_select\" (func 127))
|
||||
(export \"br_if\" (func 128))
|
||||
(export \"br_table\" (func 129))
|
||||
(elem (i32.const 0) 0 1 2 3 4 5 6 7))
|
||||
(elem (;0;) (i32.const 0) 0 1 2 3 4 5 6 7))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -667,7 +667,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"while\" (func 42))
|
||||
(export \"for\" (func 43))
|
||||
(export \"nesting\" (func 44))
|
||||
(elem (i32.const 0) 16))
|
||||
(elem (;0;) (i32.const 0) 16))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -119,7 +119,7 @@ fn create_module_5() -> ResultObject {
|
||||
memory.size)
|
||||
(memory (;0;) 0 0)
|
||||
(export \"memsize\" (func 0))
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -157,7 +157,7 @@ fn create_module_6() -> ResultObject {
|
||||
memory.size)
|
||||
(memory (;0;) 0 0)
|
||||
(export \"memsize\" (func 0))
|
||||
(data (i32.const 0) \"\"))
|
||||
(data (;0;) (i32.const 0) \"\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -195,7 +195,7 @@ fn create_module_7() -> ResultObject {
|
||||
memory.size)
|
||||
(memory (;0;) 1 1)
|
||||
(export \"memsize\" (func 0))
|
||||
(data (i32.const 0) \"x\"))
|
||||
(data (;0;) (i32.const 0) \"x\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -632,7 +632,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"as-store-mid\" (func 80))
|
||||
(export \"as-store-last\" (func 81))
|
||||
(export \"as-store-everywhere\" (func 82))
|
||||
(elem (i32.const 0) 61))
|
||||
(elem (;0;) (i32.const 0) 61))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -412,7 +412,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"as-compare-right\" (func 56))
|
||||
(export \"as-convert-operand\" (func 57))
|
||||
(export \"as-memory.grow-size\" (func 58))
|
||||
(elem (i32.const 0) 36))
|
||||
(elem (;0;) (i32.const 0) 36))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -63,7 +63,7 @@ fn create_module_1() -> ResultObject {
|
||||
(export \"inc\" (func 0))
|
||||
(export \"get\" (func 1))
|
||||
(start 2)
|
||||
(data (i32.const 0) \"A\"))
|
||||
(data (;0;) (i32.const 0) \"A\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
@ -169,7 +169,7 @@ fn create_module_2() -> ResultObject {
|
||||
(export \"inc\" (func 0))
|
||||
(export \"get\" (func 1))
|
||||
(start 2)
|
||||
(data (i32.const 0) \"A\"))
|
||||
(data (;0;) (i32.const 0) \"A\"))
|
||||
";
|
||||
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
|
||||
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
|
||||
|
@ -24,6 +24,7 @@ use super::memory::LinearMemory;
|
||||
use super::module::Export;
|
||||
use super::module::Module;
|
||||
use super::relocation::{Reloc, RelocSink, RelocationType};
|
||||
use super::math_intrinsics;
|
||||
|
||||
type TablesSlice = UncheckedSlice<BoundedSlice<usize>>;
|
||||
type MemoriesSlice = UncheckedSlice<BoundedSlice<u8>>;
|
||||
@ -57,7 +58,7 @@ fn get_function_addr(
|
||||
let func_pointer = if index < len {
|
||||
import_functions[index]
|
||||
} else {
|
||||
(&functions[func_index.index() - len]).as_ptr()
|
||||
(functions[index - len]).as_ptr()
|
||||
};
|
||||
func_pointer
|
||||
}
|
||||
@ -119,9 +120,9 @@ pub struct InstanceOptions {
|
||||
pub mock_missing_imports: bool,
|
||||
}
|
||||
|
||||
extern fn mock_fn() -> i32 {
|
||||
return 0;
|
||||
}
|
||||
// extern fn mock_fn() -> i32 {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
impl Instance {
|
||||
pub const TABLES_OFFSET: usize = 0; // 0 on 64-bit | 0 on 32-bit
|
||||
@ -134,7 +135,7 @@ impl Instance {
|
||||
pub fn new(
|
||||
module: &Module,
|
||||
import_object: ImportObject<&str, &str>,
|
||||
options: InstanceOptions,
|
||||
_options: InstanceOptions,
|
||||
) -> Result<Instance, ErrorKind> {
|
||||
let mut tables: Vec<Vec<usize>> = Vec::new();
|
||||
let mut memories: Vec<LinearMemory> = Vec::new();
|
||||
@ -244,28 +245,28 @@ impl Instance {
|
||||
grow_memory as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::CeilF32) => {
|
||||
_ceilf32 as isize
|
||||
math_intrinsics::ceilf32 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::FloorF32) => {
|
||||
_floorf32 as isize
|
||||
math_intrinsics::floorf32 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::TruncF32) => {
|
||||
_truncf32 as isize
|
||||
math_intrinsics::truncf32 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::NearestF32) => {
|
||||
_nearbyintf32 as isize
|
||||
math_intrinsics::nearbyintf32 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::CeilF64) => {
|
||||
_ceilf64 as isize
|
||||
math_intrinsics::ceilf64 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::FloorF64) => {
|
||||
_floorf64 as isize
|
||||
math_intrinsics::floorf64 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::TruncF64) => {
|
||||
_truncf64 as isize
|
||||
math_intrinsics::truncf64 as isize
|
||||
},
|
||||
RelocationType::LibCall(LibCall::NearestF64) => {
|
||||
_nearbyintf64 as isize
|
||||
math_intrinsics::nearbyintf64 as isize
|
||||
},
|
||||
_ => unimplemented!()
|
||||
// RelocationType::Intrinsic(name) => {
|
||||
@ -297,7 +298,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
// Looping through and getting the imported objects
|
||||
for (key, value) in import_object.map {
|
||||
for (_key, value) in import_object.map {
|
||||
match value {
|
||||
ImportValue::Memory(value) =>
|
||||
imported_memories.push(value),
|
||||
@ -420,7 +421,7 @@ impl Instance {
|
||||
.info
|
||||
.start_func
|
||||
.or_else(|| match module.info.exports.get("main") {
|
||||
Some(Export::Function(index)) => Some(index.to_owned()),
|
||||
Some(Export::Function(index)) => Some(*index),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
@ -522,44 +523,3 @@ extern "C" fn current_memory(memory_index: u32, instance: &mut Instance) -> u32
|
||||
let memory = &instance.memories[memory_index as usize];
|
||||
memory.current_size() as u32
|
||||
}
|
||||
|
||||
// Because of this bug https://github.com/rust-lang/rust/issues/34123
|
||||
// We create internal functions for it
|
||||
|
||||
use std::intrinsics::{
|
||||
ceilf32, ceilf64, floorf32, floorf64, nearbyintf32, nearbyintf64, truncf32, truncf64,
|
||||
};
|
||||
|
||||
// F32
|
||||
unsafe extern "C" fn _ceilf32(x: f32) -> f32 {
|
||||
ceilf32(x)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn _floorf32(x: f32) -> f32 {
|
||||
floorf32(x)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn _truncf32(x: f32) -> f32 {
|
||||
truncf32(x)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn _nearbyintf32(x: f32) -> f32 {
|
||||
nearbyintf32(x)
|
||||
}
|
||||
|
||||
// F64
|
||||
unsafe extern "C" fn _ceilf64(x: f64) -> f64 {
|
||||
ceilf64(x)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn _floorf64(x: f64) -> f64 {
|
||||
floorf64(x)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn _truncf64(x: f64) -> f64 {
|
||||
truncf64(x)
|
||||
}
|
||||
|
||||
unsafe extern "C" fn _nearbyintf64(x: f64) -> f64 {
|
||||
nearbyintf64(x)
|
||||
}
|
||||
|
41
src/webassembly/math_intrinsics.rs
Normal file
41
src/webassembly/math_intrinsics.rs
Normal file
@ -0,0 +1,41 @@
|
||||
// F32
|
||||
#[inline]
|
||||
pub extern "C" fn ceilf32(x: f32) -> f32 {
|
||||
x.ceil()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub extern "C" fn floorf32(x: f32) -> f32 {
|
||||
x.floor()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub extern "C" fn truncf32(x: f32) -> f32 {
|
||||
x.trunc()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub extern "C" fn nearbyintf32(x: f32) -> f32 {
|
||||
x.round()
|
||||
}
|
||||
|
||||
// F64
|
||||
#[inline]
|
||||
pub extern "C" fn ceilf64(x: f64) -> f64 {
|
||||
x.ceil()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub extern "C" fn floorf64(x: f64) -> f64 {
|
||||
x.floor()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub extern "C" fn truncf64(x: f64) -> f64 {
|
||||
x.trunc()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub extern "C" fn nearbyintf64(x: f64) -> f64 {
|
||||
x.round()
|
||||
}
|
@ -5,11 +5,13 @@ pub mod memory;
|
||||
pub mod module;
|
||||
pub mod relocation;
|
||||
pub mod utils;
|
||||
pub mod math_intrinsics;
|
||||
|
||||
use std::panic;
|
||||
use std::str::FromStr;
|
||||
use target_lexicon;
|
||||
use wasmparser;
|
||||
use wasmparser::WasmDecoder;
|
||||
|
||||
pub use self::errors::{Error, ErrorKind};
|
||||
pub use self::import_object::{ImportObject, ImportValue};
|
||||
@ -46,7 +48,13 @@ pub fn instantiate(
|
||||
) -> Result<ResultObject, ErrorKind> {
|
||||
let module = compile(buffer_source)?;
|
||||
debug!("webassembly - creating instance");
|
||||
let instance = Instance::new(&module, import_object, InstanceOptions { mock_missing_imports: true })?;
|
||||
let instance = Instance::new(
|
||||
&module,
|
||||
import_object,
|
||||
InstanceOptions {
|
||||
mock_missing_imports: true,
|
||||
},
|
||||
)?;
|
||||
debug!("webassembly - instance created");
|
||||
Ok(ResultObject { module, instance })
|
||||
}
|
||||
@ -73,11 +81,9 @@ pub fn instantiate_streaming(
|
||||
/// webassembly::CompileError.
|
||||
pub fn compile(buffer_source: Vec<u8>) -> Result<Module, ErrorKind> {
|
||||
// TODO: This should be automatically validated when creating the Module
|
||||
let valid = validate(&buffer_source);
|
||||
debug!("webassembly - valid {:?}", valid);
|
||||
if !valid {
|
||||
return Err(ErrorKind::CompileError("Module not valid".to_string()));
|
||||
}
|
||||
debug!("webassembly - validating module");
|
||||
validate_or_error(&buffer_source)?;
|
||||
|
||||
debug!("webassembly - creating module");
|
||||
let module = Module::from_bytes(buffer_source, triple!("x86_64"), None)?;
|
||||
debug!("webassembly - module created");
|
||||
@ -89,8 +95,25 @@ pub fn compile(buffer_source: Vec<u8>) -> Result<Module, ErrorKind> {
|
||||
/// array of WebAssembly binary code, returning whether the bytes
|
||||
/// form a valid wasm module (true) or not (false).
|
||||
/// Params:
|
||||
/// * `buffer_source`: A `Vec<u8>` containing the
|
||||
/// * `buffer_source`: A `&[u8]` containing the
|
||||
/// binary code of the .wasm module you want to compile.
|
||||
pub fn validate(buffer_source: &Vec<u8>) -> bool {
|
||||
wasmparser::validate(buffer_source, None)
|
||||
pub fn validate(buffer_source: &[u8]) -> bool {
|
||||
validate_or_error(buffer_source).is_ok()
|
||||
}
|
||||
|
||||
pub fn validate_or_error(bytes: &[u8]) -> Result<(), ErrorKind> {
|
||||
let mut parser = wasmparser::ValidatingParser::new(bytes, None);
|
||||
loop {
|
||||
let state = parser.read();
|
||||
match *state {
|
||||
wasmparser::ParserState::EndWasm => return Ok(()),
|
||||
wasmparser::ParserState::Error(err) => {
|
||||
return Err(ErrorKind::CompileError(format!(
|
||||
"Validation error: {}",
|
||||
err.message
|
||||
)))
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
|
||||
|
||||
// Based on the index provided, we need to know the offset into memories array
|
||||
// Each element in the memories array has a size of (ptr_size * 2)
|
||||
let memory_data_offset = (memory_index as usize * ptr_size * 2) as i32;
|
||||
let memory_data_offset = 0; // (memory_index as usize * ptr_size * 2) as i32;
|
||||
|
||||
// Load value at the (base + memory_data_offset)
|
||||
// which is the address of data_pointer.memories[index].data
|
||||
|
Loading…
x
Reference in New Issue
Block a user