Merge remote-tracking branch 'origin/master' into feature/osr

This commit is contained in:
losfair
2019-06-24 23:35:47 +08:00
49 changed files with 1018 additions and 344 deletions

View File

@ -35,9 +35,9 @@ jobs:
name: Install lint deps
command: |
git config --global --unset url."ssh://git@github.com".insteadOf || true
rustup toolchain install nightly-2019-02-27
rustup toolchain install nightly-2019-05-20
rustup component add rustfmt
rustup component add clippy --toolchain=nightly-2019-02-27 || cargo +nightly-2019-02-27 install --git https://github.com/rust-lang/rust-clippy/ --force clippy
rustup component add clippy --toolchain=nightly-2019-05-20 || cargo +nightly-2019-05-20 install --git https://github.com/rust-lang/rust-clippy/ --force clippy
- run:
name: Execute lints
command: |

View File

@ -6,6 +6,16 @@ Blocks of changes will separated by version increments.
## **[Unreleased]**
## 0.5.0 - 2019-06-17
- [#471](https://github.com/wasmerio/wasmer/pull/471) Added missing functions to run Python. Improved Emscripten bindings
- [#494](https://github.com/wasmerio/wasmer/pull/494) Remove deprecated type aliases from libc in the runtime C API
- [#493](https://github.com/wasmerio/wasmer/pull/493) `wasmer_module_instantiate` has better error messages in the runtime C API
- [#474](https://github.com/wasmerio/wasmer/pull/474) Set the install name of the dylib to `@rpath`
- [#490](https://github.com/wasmerio/wasmer/pull/490) Add MiddlewareChain and StreamingCompiler to runtime
- [#487](https://github.com/wasmerio/wasmer/pull/487) Fix stack offset check in singlepass backend
- [#450](https://github.com/wasmerio/wasmer/pull/450) Added Metering
- [#481](https://github.com/wasmerio/wasmer/pull/481) Added context trampoline into runtime
- [#484](https://github.com/wasmerio/wasmer/pull/484) Fix bugs in emscripten socket syscalls
- [#476](https://github.com/wasmerio/wasmer/pull/476) Fix bug with wasi::environ_get, fix off by one error in wasi::environ_sizes_get
- [#470](https://github.com/wasmerio/wasmer/pull/470) Add mapdir support to Emscripten, implement getdents for Unix

102
Cargo.lock generated
View File

@ -1355,7 +1355,7 @@ dependencies = [
[[package]]
name = "wasmer"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1364,21 +1364,21 @@ dependencies = [
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.4.2",
"wasmer-dev-utils 0.4.2",
"wasmer-emscripten 0.4.2",
"wasmer-clif-backend 0.5.0",
"wasmer-dev-utils 0.5.0",
"wasmer-emscripten 0.5.0",
"wasmer-kernel-loader 0.1.0",
"wasmer-llvm-backend 0.4.2",
"wasmer-middleware-common 0.4.2",
"wasmer-runtime 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"wasmer-wasi 0.4.2",
"wasmer-llvm-backend 0.5.0",
"wasmer-middleware-common 0.5.0",
"wasmer-runtime 0.5.0",
"wasmer-runtime-core 0.5.0",
"wasmer-singlepass-backend 0.5.0",
"wasmer-wasi 0.5.0",
]
[[package]]
name = "wasmer-clif-backend"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cranelift-codegen 0.30.0 (git+https://github.com/wasmerio/cranelift.git?rev=84ec31b0fdfc10db491ef950815ee2961db057cb)",
@ -1395,22 +1395,22 @@ dependencies = [
"serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.4.2",
"wasmer-win-exception-handler 0.4.2",
"wasmer-runtime-core 0.5.0",
"wasmer-win-exception-handler 0.5.0",
"wasmparser 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasmer-dev-utils"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasmer-emscripten"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1420,11 +1420,11 @@ dependencies = [
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.4.2",
"wasmer-dev-utils 0.4.2",
"wasmer-llvm-backend 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"wasmer-clif-backend 0.5.0",
"wasmer-dev-utils 0.5.0",
"wasmer-llvm-backend 0.5.0",
"wasmer-runtime-core 0.5.0",
"wasmer-singlepass-backend 0.5.0",
]
[[package]]
@ -1432,12 +1432,12 @@ name = "wasmer-kernel-loader"
version = "0.1.0"
dependencies = [
"libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.4.2",
"wasmer-runtime-core 0.5.0",
]
[[package]]
name = "wasmer-llvm-backend"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"capstone 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1452,50 +1452,50 @@ dependencies = [
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.4.2",
"wasmer-runtime-core 0.5.0",
"wasmparser 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasmer-middleware-common"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.4.2",
"wasmer-llvm-backend 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"wasmer-clif-backend 0.5.0",
"wasmer-llvm-backend 0.5.0",
"wasmer-runtime-core 0.5.0",
"wasmer-singlepass-backend 0.5.0",
]
[[package]]
name = "wasmer-runtime"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.4.2",
"wasmer-llvm-backend 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"wasmer-clif-backend 0.5.0",
"wasmer-llvm-backend 0.5.0",
"wasmer-runtime-core 0.5.0",
"wasmer-singlepass-backend 0.5.0",
]
[[package]]
name = "wasmer-runtime-c-api"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"cbindgen 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-runtime 0.5.0",
"wasmer-runtime-core 0.5.0",
]
[[package]]
name = "wasmer-runtime-core"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"blake2b_simd 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1521,7 +1521,7 @@ dependencies = [
[[package]]
name = "wasmer-singlepass-backend"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"dynasm 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1531,24 +1531,24 @@ dependencies = [
"libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.4.2",
"wasmer-runtime-core 0.5.0",
"wasmparser 0.29.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasmer-spectests"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.4.2",
"wasmer-llvm-backend 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"wasmer-clif-backend 0.5.0",
"wasmer-llvm-backend 0.5.0",
"wasmer-runtime-core 0.5.0",
"wasmer-singlepass-backend 0.5.0",
]
[[package]]
name = "wasmer-wasi"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"generational-arena 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1557,22 +1557,22 @@ dependencies = [
"libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.4.2",
"wasmer-dev-utils 0.4.2",
"wasmer-runtime-core 0.4.2",
"wasmer-singlepass-backend 0.4.2",
"wasmer-clif-backend 0.5.0",
"wasmer-dev-utils 0.5.0",
"wasmer-runtime-core 0.5.0",
"wasmer-singlepass-backend 0.5.0",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasmer-win-exception-handler"
version = "0.4.2"
version = "0.5.0"
dependencies = [
"bindgen 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-runtime-core 0.4.2",
"wasmer-runtime-core 0.5.0",
"winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer"
version = "0.4.2"
version = "0.5.0"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
edition = "2018"
repository = "https://github.com/wasmerio/wasmer"

View File

@ -32,7 +32,7 @@ integration-tests: release
lint:
cargo fmt --all -- --check
cargo +nightly-2019-02-27 clippy --all
cargo +nightly-2019-05-20 clippy --all
precommit: lint test
@ -104,3 +104,8 @@ extra-debug-release:
publish-release:
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/
# cargo install cargo-deps
# must install graphviz for `dot`
dep-graph:
cargo deps --optional-deps --filter wasmer-wasi wasmer-kernel-loader wasmer-dev-utils wasmer-llvm-backend wasmer-emscripten wasmer-runtime-core wasmer-runtime wasmer-middleware-common wasmer-singlepass-backend wasmer-clif-backend wasmer --manifest-path Cargo.toml | dot -Tpng > wasmer_depgraph.png

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-clif-backend"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime Cranelift compiler backend"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer"
edition = "2018"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
cranelift-native = { git = "https://github.com/wasmerio/cranelift.git", rev = "84ec31b0fdfc10db491ef950815ee2961db057cb" }
cranelift-codegen = { git = "https://github.com/wasmerio/cranelift.git", rev = "84ec31b0fdfc10db491ef950815ee2961db057cb" }
cranelift-entity = { git = "https://github.com/wasmerio/cranelift.git", rev = "84ec31b0fdfc10db491ef950815ee2961db057cb" }
@ -34,7 +34,7 @@ version = "0.0.7"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "minwindef", "minwinbase", "winnt"] }
wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.4.2" }
wasmer-win-exception-handler = { path = "../win-exception-handler", version = "0.5.0" }
[features]
debug = ["wasmer-runtime-core/debug"]

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-dev-utils"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime core library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-emscripten"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime emscripten implementation library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -14,17 +14,17 @@ hashbrown = "0.1"
lazy_static = "1.2.0"
libc = "0.2.49"
time = "0.1.41"
wasmer-clif-backend = { path = "../clif-backend", version = "0.4.2" }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.4.2", optional = true }
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
wasmer-clif-backend = { path = "../clif-backend", version = "0.5.0" }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.0", optional = true }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.0", optional = true }
[target.'cfg(windows)'.dependencies]
rand = "0.6"
[dev-dependencies]
wabt = "0.7.2"
wasmer-dev-utils = { path = "../dev-utils", version = "0.4.2"}
wasmer-dev-utils = { path = "../dev-utils", version = "0.5.0"}
[build-dependencies]
glob = "0.2.11"

View File

@ -5,6 +5,15 @@ use crate::env::get_emscripten_data;
use libc::getdtablesize;
use wasmer_runtime_core::vm::Ctx;
pub fn asm_const_i(_ctx: &mut Ctx, _val: i32) -> i32 {
debug!("emscripten::asm_const_i: {}", _val);
0
}
pub fn exit_with_live_runtime(_ctx: &mut Ctx) {
debug!("emscripten::exit_with_live_runtime");
}
pub fn setTempRet0(ctx: &mut Ctx, val: i32) {
debug!("emscripten::setTempRet0: {}", val);
get_emscripten_data(ctx).temp_ret_0 = val;
@ -59,10 +68,6 @@ pub fn _dladdr(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_dladdr");
0
}
pub fn _pthread_attr_init(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_attr_init({})", _a);
0
}
pub fn _pthread_attr_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_attr_destroy");
0
@ -82,58 +87,24 @@ pub fn _pthread_attr_getstack(
// HEAP32[stacksize >> 2] = TOTAL_STACK;
0
}
pub fn _pthread_attr_init(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_attr_init({})", _a);
0
}
pub fn _pthread_attr_setstacksize(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_attr_setstacksize");
0
}
pub fn _pthread_cleanup_pop(_ctx: &mut Ctx, _a: i32) -> () {
debug!("emscripten::_pthread_cleanup_pop");
}
pub fn _pthread_cleanup_push(_ctx: &mut Ctx, _a: i32, _b: i32) -> () {
debug!("emscripten::_pthread_cleanup_push");
}
pub fn _pthread_cond_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_cond_destroy");
0
}
pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::_pthread_cond_timedwait");
0
}
pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_getspecific");
0
}
pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr);
0
}
pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_setspecific");
0
}
pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_once");
0
}
pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_key_create");
0
}
pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_destroy({})", _rwlock);
0
}
pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr);
0
}
pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock);
0
}
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
debug!("emscripten::_pthread_create");
0
}
pub fn _pthread_detach(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_detach");
0
}
pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_join");
0
}
pub fn _pthread_cond_init(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_cond_init");
0
@ -142,6 +113,10 @@ pub fn _pthread_cond_signal(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_cond_signal");
0
}
pub fn _pthread_cond_timedwait(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::_pthread_cond_timedwait");
0
}
pub fn _pthread_cond_wait(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_cond_wait");
0
@ -158,6 +133,37 @@ pub fn _pthread_condattr_setclock(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_condattr_setclock");
0
}
pub fn _pthread_create(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32, _d: i32) -> i32 {
debug!("emscripten::_pthread_create");
0
}
pub fn _pthread_detach(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_detach");
0
}
pub fn _pthread_equal(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_equal");
0
}
pub fn _pthread_exit(_ctx: &mut Ctx, _a: i32) -> () {
debug!("emscripten::_pthread_exit");
}
pub fn _pthread_getattr_np(_ctx: &mut Ctx, _thread: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_getattr_np({}, {})", _thread, _attr);
0
}
pub fn _pthread_getspecific(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_getspecific");
0
}
pub fn _pthread_join(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_join");
0
}
pub fn _pthread_key_create(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_key_create");
0
}
pub fn _pthread_mutex_destroy(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_mutex_destroy");
0
@ -178,6 +184,18 @@ pub fn _pthread_mutexattr_settype(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_mutexattr_settype");
0
}
pub fn _pthread_once(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_once");
0
}
pub fn _pthread_rwlock_destroy(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_destroy({})", _rwlock);
0
}
pub fn _pthread_rwlock_init(_ctx: &mut Ctx, _rwlock: i32, _attr: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_init({}, {})", _rwlock, _attr);
0
}
pub fn _pthread_rwlock_rdlock(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_rdlock");
0
@ -186,10 +204,22 @@ pub fn _pthread_rwlock_unlock(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_unlock");
0
}
pub fn _pthread_rwlock_wrlock(_ctx: &mut Ctx, _rwlock: i32) -> i32 {
debug!("emscripten::_pthread_rwlock_wrlock({})", _rwlock);
0
}
pub fn _pthread_setcancelstate(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_setcancelstate");
0
}
pub fn _pthread_setspecific(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::_pthread_setspecific");
0
}
pub fn _pthread_sigmask(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::_pthread_sigmask");
0
}
pub fn ___gxx_personality_v0(
_ctx: &mut Ctx,
_a: i32,
@ -222,6 +252,10 @@ pub fn _gethostbyaddr(_ctx: &mut Ctx, _addr: i32, _addrlen: i32, _atype: i32) ->
debug!("emscripten::gethostbyaddr");
0
}
pub fn _gethostbyname(_ctx: &mut Ctx, _name: i32) -> i32 {
debug!("emscripten::gethostbyname_r");
0
}
pub fn _gethostbyname_r(
_ctx: &mut Ctx,
_name: i32,

View File

@ -8,6 +8,26 @@ pub fn ___cxa_allocate_exception(ctx: &mut Ctx, size: u32) -> u32 {
env::call_malloc(ctx, size as _)
}
pub fn ___cxa_current_primary_exception(_ctx: &mut Ctx) -> u32 {
debug!("emscripten::___cxa_current_primary_exception");
unimplemented!()
}
pub fn ___cxa_decrement_exception_refcount(_ctx: &mut Ctx, _a: u32) {
debug!("emscripten::___cxa_decrement_exception_refcount({})", _a);
unimplemented!()
}
pub fn ___cxa_increment_exception_refcount(_ctx: &mut Ctx, _a: u32) {
debug!("emscripten::___cxa_increment_exception_refcount({})", _a);
unimplemented!()
}
pub fn ___cxa_rethrow_primary_exception(_ctx: &mut Ctx, _a: u32) {
debug!("emscripten::___cxa_rethrow_primary_exception({})", _a);
unimplemented!()
}
/// emscripten: ___cxa_throw
/// TODO: We don't have support for exceptions yet
pub fn ___cxa_throw(ctx: &mut Ctx, _ptr: u32, _ty: u32, _destructor: u32) {

View File

@ -0,0 +1,6 @@
use wasmer_runtime_core::vm::Ctx;
pub fn addr(_ctx: &mut Ctx, _cp: i32) -> i32 {
debug!("inet::addr({})", _cp);
0
}

View File

@ -1,4 +1,7 @@
use libc::{chroot as _chroot, printf as _printf};
use super::super::env::call_malloc;
use super::super::utils::copy_cstr_into_wasm;
use libc::{chroot as _chroot, getpwuid as _getpwuid, printf as _printf};
use std::mem;
use wasmer_runtime_core::vm::Ctx;
@ -24,7 +27,40 @@ pub fn chroot(ctx: &mut Ctx, name_ptr: i32) -> i32 {
}
/// getpwuid
pub fn getpwuid(_ctx: &mut Ctx, _uid: i32) -> i32 {
debug!("emscripten::getpwuid");
#[allow(clippy::cast_ptr_alignment)]
pub fn getpwuid(ctx: &mut Ctx, uid: i32) -> i32 {
debug!("emscripten::getpwuid {}", uid);
#[repr(C)]
struct GuestPasswd {
pw_name: u32,
pw_passwd: u32,
pw_uid: u32,
pw_gid: u32,
pw_gecos: u32,
pw_dir: u32,
pw_shell: u32,
}
unsafe {
let passwd = &*_getpwuid(uid as _);
let passwd_struct_offset = call_malloc(ctx, mem::size_of::<GuestPasswd>() as _);
let passwd_struct_ptr =
emscripten_memory_pointer!(ctx.memory(0), passwd_struct_offset) as *mut GuestPasswd;
assert_eq!(
passwd_struct_ptr as usize % std::mem::align_of::<GuestPasswd>(),
0
);
(*passwd_struct_ptr).pw_name = copy_cstr_into_wasm(ctx, passwd.pw_name);
(*passwd_struct_ptr).pw_passwd = copy_cstr_into_wasm(ctx, passwd.pw_passwd);
(*passwd_struct_ptr).pw_gecos = copy_cstr_into_wasm(ctx, passwd.pw_gecos);
(*passwd_struct_ptr).pw_dir = copy_cstr_into_wasm(ctx, passwd.pw_dir);
(*passwd_struct_ptr).pw_shell = copy_cstr_into_wasm(ctx, passwd.pw_shell);
(*passwd_struct_ptr).pw_uid = passwd.pw_uid;
(*passwd_struct_ptr).pw_gid = passwd.pw_gid;
passwd_struct_offset as _
}
// unsafe { _getpwuid(uid as _) as _}
// 0
}

View File

@ -24,6 +24,13 @@ use wasmer_runtime_core::{
Func, Instance, IsExport, Module,
};
#[cfg(unix)]
use ::libc::DIR as libcDIR;
// We use a placeholder for windows
#[cfg(not(unix))]
type libcDIR = u8;
#[macro_use]
mod macros;
@ -35,8 +42,10 @@ mod errno;
mod exception;
mod exec;
mod exit;
mod inet;
mod io;
mod jmp;
mod libc;
mod linking;
mod lock;
mod math;
@ -47,6 +56,7 @@ mod storage;
mod syscalls;
mod time;
mod ucontext;
mod unistd;
mod utils;
mod varargs;
@ -80,6 +90,7 @@ pub struct EmscriptenData<'a> {
pub memset: Func<'a, (u32, u32, u32), u32>,
pub stack_alloc: Func<'a, u32, u32>,
pub jumps: Vec<UnsafeCell<[u32; 27]>>,
pub opened_dirs: HashMap<i32, Box<*mut libcDIR>>,
pub dyn_call_i: Option<Func<'a, i32, i32>>,
pub dyn_call_ii: Option<Func<'a, (i32, i32), i32>>,
@ -221,6 +232,8 @@ impl<'a> EmscriptenData<'a> {
memset,
stack_alloc,
jumps: Vec::new(),
opened_dirs: HashMap::new(),
dyn_call_i,
dyn_call_ii,
dyn_call_iii,
@ -508,13 +521,18 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"STACKTOP" => Global::new(Value::I32(globals.data.stacktop as i32)),
"STACK_MAX" => Global::new(Value::I32(globals.data.stack_max as i32)),
"DYNAMICTOP_PTR" => Global::new(Value::I32(globals.data.dynamictop_ptr as i32)),
"fb" => Global::new(Value::I32(globals.data.table_base as i32)),
"tableBase" => Global::new(Value::I32(globals.data.table_base as i32)),
"__table_base" => Global::new(Value::I32(globals.data.table_base as i32)),
"ABORT" => Global::new(Value::I32(globals.data.abort as i32)),
"gb" => Global::new(Value::I32(globals.data.memory_base as i32)),
"memoryBase" => Global::new(Value::I32(globals.data.memory_base as i32)),
"__memory_base" => Global::new(Value::I32(globals.data.memory_base as i32)),
"tempDoublePtr" => Global::new(Value::I32(globals.data.temp_double_ptr as i32)),
// inet
"_inet_addr" => func!(crate::inet::addr),
// IO
"printf" => func!(crate::io::printf),
"putchar" => func!(crate::io::putchar),
@ -565,15 +583,24 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___syscall9" => func!(crate::syscalls::___syscall9),
"___syscall10" => func!(crate::syscalls::___syscall10),
"___syscall12" => func!(crate::syscalls::___syscall12),
"___syscall14" => func!(crate::syscalls::___syscall14),
"___syscall15" => func!(crate::syscalls::___syscall15),
"___syscall20" => func!(crate::syscalls::___syscall20),
"___syscall21" => func!(crate::syscalls::___syscall21),
"___syscall25" => func!(crate::syscalls::___syscall25),
"___syscall29" => func!(crate::syscalls::___syscall29),
"___syscall32" => func!(crate::syscalls::___syscall32),
"___syscall33" => func!(crate::syscalls::___syscall33),
"___syscall34" => func!(crate::syscalls::___syscall34),
"___syscall36" => func!(crate::syscalls::___syscall36),
"___syscall39" => func!(crate::syscalls::___syscall39),
"___syscall38" => func!(crate::syscalls::___syscall38),
"___syscall40" => func!(crate::syscalls::___syscall40),
"___syscall41" => func!(crate::syscalls::___syscall41),
"___syscall42" => func!(crate::syscalls::___syscall42),
"___syscall51" => func!(crate::syscalls::___syscall51),
"___syscall52" => func!(crate::syscalls::___syscall52),
"___syscall53" => func!(crate::syscalls::___syscall53),
"___syscall54" => func!(crate::syscalls::___syscall54),
"___syscall57" => func!(crate::syscalls::___syscall57),
"___syscall60" => func!(crate::syscalls::___syscall60),
@ -586,23 +613,36 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___syscall85" => func!(crate::syscalls::___syscall85),
"___syscall91" => func!(crate::syscalls::___syscall91),
"___syscall94" => func!(crate::syscalls::___syscall94),
"___syscall96" => func!(crate::syscalls::___syscall96),
"___syscall97" => func!(crate::syscalls::___syscall97),
"___syscall102" => func!(crate::syscalls::___syscall102),
"___syscall110" => func!(crate::syscalls::___syscall110),
"___syscall114" => func!(crate::syscalls::___syscall114),
"___syscall118" => func!(crate::syscalls::___syscall118),
"___syscall121" => func!(crate::syscalls::___syscall121),
"___syscall122" => func!(crate::syscalls::___syscall122),
"___syscall125" => func!(crate::syscalls::___syscall125),
"___syscall132" => func!(crate::syscalls::___syscall132),
"___syscall133" => func!(crate::syscalls::___syscall133),
"___syscall140" => func!(crate::syscalls::___syscall140),
"___syscall142" => func!(crate::syscalls::___syscall142),
"___syscall144" => func!(crate::syscalls::___syscall144),
"___syscall145" => func!(crate::syscalls::___syscall145),
"___syscall146" => func!(crate::syscalls::___syscall146),
"___syscall147" => func!(crate::syscalls::___syscall147),
"___syscall148" => func!(crate::syscalls::___syscall148),
"___syscall150" => func!(crate::syscalls::___syscall150),
"___syscall151" => func!(crate::syscalls::___syscall151),
"___syscall152" => func!(crate::syscalls::___syscall152),
"___syscall153" => func!(crate::syscalls::___syscall153),
"___syscall163" => func!(crate::syscalls::___syscall163),
"___syscall168" => func!(crate::syscalls::___syscall168),
"___syscall180" => func!(crate::syscalls::___syscall180),
"___syscall181" => func!(crate::syscalls::___syscall181),
"___syscall183" => func!(crate::syscalls::___syscall183),
"___syscall191" => func!(crate::syscalls::___syscall191),
"___syscall192" => func!(crate::syscalls::___syscall192),
"___syscall193" => func!(crate::syscalls::___syscall193),
"___syscall194" => func!(crate::syscalls::___syscall194),
"___syscall195" => func!(crate::syscalls::___syscall195),
"___syscall196" => func!(crate::syscalls::___syscall196),
@ -614,19 +654,38 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___syscall202" => func!(crate::syscalls::___syscall202),
"___syscall205" => func!(crate::syscalls::___syscall205),
"___syscall207" => func!(crate::syscalls::___syscall207),
"___syscall209" => func!(crate::syscalls::___syscall209),
"___syscall211" => func!(crate::syscalls::___syscall211),
"___syscall212" => func!(crate::syscalls::___syscall212),
"___syscall218" => func!(crate::syscalls::___syscall218),
"___syscall219" => func!(crate::syscalls::___syscall219),
"___syscall220" => func!(crate::syscalls::___syscall220),
"___syscall221" => func!(crate::syscalls::___syscall221),
"___syscall268" => func!(crate::syscalls::___syscall268),
"___syscall269" => func!(crate::syscalls::___syscall269),
"___syscall272" => func!(crate::syscalls::___syscall272),
"___syscall295" => func!(crate::syscalls::___syscall295),
"___syscall296" => func!(crate::syscalls::___syscall296),
"___syscall297" => func!(crate::syscalls::___syscall297),
"___syscall298" => func!(crate::syscalls::___syscall298),
"___syscall300" => func!(crate::syscalls::___syscall300),
"___syscall301" => func!(crate::syscalls::___syscall301),
"___syscall302" => func!(crate::syscalls::___syscall302),
"___syscall303" => func!(crate::syscalls::___syscall303),
"___syscall304" => func!(crate::syscalls::___syscall304),
"___syscall305" => func!(crate::syscalls::___syscall305),
"___syscall306" => func!(crate::syscalls::___syscall306),
"___syscall307" => func!(crate::syscalls::___syscall307),
"___syscall308" => func!(crate::syscalls::___syscall308),
"___syscall320" => func!(crate::syscalls::___syscall320),
"___syscall324" => func!(crate::syscalls::___syscall324),
"___syscall330" => func!(crate::syscalls::___syscall330),
"___syscall331" => func!(crate::syscalls::___syscall331),
"___syscall333" => func!(crate::syscalls::___syscall333),
"___syscall334" => func!(crate::syscalls::___syscall334),
"___syscall337" => func!(crate::syscalls::___syscall337),
"___syscall340" => func!(crate::syscalls::___syscall340),
"___syscall345" => func!(crate::syscalls::___syscall345),
// Process
"abort" => func!(crate::process::em_abort),
@ -655,9 +714,17 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_setitimer" => func!(crate::process::_setitimer),
"_usleep" => func!(crate::process::_usleep),
"_nanosleep" => func!(crate::process::_nanosleep),
"_utime" => func!(crate::process::_utime),
"_utimes" => func!(crate::process::_utimes),
"_wait" => func!(crate::process::_wait),
"_wait3" => func!(crate::process::_wait3),
"_wait4" => func!(crate::process::_wait4),
"_waitid" => func!(crate::process::_waitid),
"_waitpid" => func!(crate::process::_waitpid),
// Emscripten
"_emscripten_asm_const_i" => func!(crate::emscripten_target::asm_const_i),
"_emscripten_exit_with_live_runtime" => func!(crate::emscripten_target::exit_with_live_runtime),
// Signal
"_sigemptyset" => func!(crate::signal::_sigemptyset),
@ -681,6 +748,10 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
// Exception
"___cxa_allocate_exception" => func!(crate::exception::___cxa_allocate_exception),
"___cxa_current_primary_exception" => func!(crate::exception::___cxa_current_primary_exception),
"___cxa_decrement_exception_refcount" => func!(crate::exception::___cxa_decrement_exception_refcount),
"___cxa_increment_exception_refcount" => func!(crate::exception::___cxa_increment_exception_refcount),
"___cxa_rethrow_primary_exception" => func!(crate::exception::___cxa_rethrow_primary_exception),
"___cxa_throw" => func!(crate::exception::___cxa_throw),
"___cxa_begin_catch" => func!(crate::exception::___cxa_begin_catch),
"___cxa_end_catch" => func!(crate::exception::___cxa_end_catch),
@ -689,7 +760,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
// Time
"_gettimeofday" => func!(crate::time::_gettimeofday),
"_clock_getres" => func!(crate::time::_clock_getres),
"_clock_gettime" => func!(crate::time::_clock_gettime),
"_clock_settime" => func!(crate::time::_clock_settime),
"___clock_gettime" => func!(crate::time::_clock_gettime),
"_clock" => func!(crate::time::_clock),
"_difftime" => func!(crate::time::_difftime),
@ -707,6 +780,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
// Math
"f64-rem" => func!(crate::math::f64_rem),
"_llvm_copysign_f32" => func!(crate::math::_llvm_copysign_f32),
"_llvm_copysign_f64" => func!(crate::math::_llvm_copysign_f64),
"_llvm_log10_f64" => func!(crate::math::_llvm_log10_f64),
"_llvm_log2_f64" => func!(crate::math::_llvm_log2_f64),
"_llvm_log10_f32" => func!(crate::math::_llvm_log10_f32),
@ -728,6 +803,22 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
// Bitwise
"_llvm_bswap_i64" => func!(crate::bitwise::_llvm_bswap_i64),
// libc
"_execv" => func!(crate::libc::execv),
"_endpwent" => func!(crate::libc::endpwent),
"_fexecve" => func!(crate::libc::fexecve),
"_fpathconf" => func!(crate::libc::fpathconf),
"_getitimer" => func!(crate::libc::getitimer),
"_getpwent" => func!(crate::libc::getpwent),
"_killpg" => func!(crate::libc::killpg),
"_pathconf" => func!(crate::libc::pathconf),
"_siginterrupt" => func!(crate::signal::_siginterrupt),
"_setpwent" => func!(crate::libc::setpwent),
"_sigismember" => func!(crate::libc::sigismember),
"_sigpending" => func!(crate::libc::sigpending),
"___libc_current_sigrtmax" => func!(crate::libc::current_sigrtmax),
"___libc_current_sigrtmin" => func!(crate::libc::current_sigrtmin),
// Linking
"_dlclose" => func!(crate::linking::_dlclose),
"_dlerror" => func!(crate::linking::_dlerror),
@ -759,40 +850,47 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"___cxa_free_exception" => func!(crate::emscripten_target::___cxa_free_exception),
"___resumeException" => func!(crate::emscripten_target::___resumeException),
"_dladdr" => func!(crate::emscripten_target::_dladdr),
"_pthread_create" => func!(crate::emscripten_target::_pthread_create),
"_pthread_detach" => func!(crate::emscripten_target::_pthread_detach),
"_pthread_join" => func!(crate::emscripten_target::_pthread_join),
"_pthread_attr_init" => func!(crate::emscripten_target::_pthread_attr_init),
"_pthread_attr_destroy" => func!(crate::emscripten_target::_pthread_attr_destroy),
"_pthread_attr_getstack" => func!(crate::emscripten_target::_pthread_attr_getstack),
"_pthread_cond_init" => func!(crate::emscripten_target::_pthread_cond_init),
"_pthread_attr_init" => func!(crate::emscripten_target::_pthread_attr_init),
"_pthread_attr_setstacksize" => func!(crate::emscripten_target::_pthread_attr_setstacksize),
"_pthread_cleanup_pop" => func!(crate::emscripten_target::_pthread_cleanup_pop),
"_pthread_cleanup_push" => func!(crate::emscripten_target::_pthread_cleanup_push),
"_pthread_cond_destroy" => func!(crate::emscripten_target::_pthread_cond_destroy),
"_pthread_cond_init" => func!(crate::emscripten_target::_pthread_cond_init),
"_pthread_cond_signal" => func!(crate::emscripten_target::_pthread_cond_signal),
"_pthread_cond_timedwait" => func!(crate::emscripten_target::_pthread_cond_timedwait),
"_pthread_cond_wait" => func!(crate::emscripten_target::_pthread_cond_wait),
"_pthread_condattr_destroy" => func!(crate::emscripten_target::_pthread_condattr_destroy),
"_pthread_condattr_init" => func!(crate::emscripten_target::_pthread_condattr_init),
"_pthread_condattr_setclock" => func!(crate::emscripten_target::_pthread_condattr_setclock),
"_pthread_create" => func!(crate::emscripten_target::_pthread_create),
"_pthread_detach" => func!(crate::emscripten_target::_pthread_detach),
"_pthread_equal" => func!(crate::emscripten_target::_pthread_equal),
"_pthread_exit" => func!(crate::emscripten_target::_pthread_exit),
"_pthread_getattr_np" => func!(crate::emscripten_target::_pthread_getattr_np),
"_pthread_getspecific" => func!(crate::emscripten_target::_pthread_getspecific),
"_pthread_join" => func!(crate::emscripten_target::_pthread_join),
"_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create),
"_pthread_mutex_destroy" => func!(crate::emscripten_target::_pthread_mutex_destroy),
"_pthread_mutex_init" => func!(crate::emscripten_target::_pthread_mutex_init),
"_pthread_mutexattr_destroy" => func!(crate::emscripten_target::_pthread_mutexattr_destroy),
"_pthread_mutexattr_init" => func!(crate::emscripten_target::_pthread_mutexattr_init),
"_pthread_mutexattr_settype" => func!(crate::emscripten_target::_pthread_mutexattr_settype),
"_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
"_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate),
"_pthread_getspecific" => func!(crate::emscripten_target::_pthread_getspecific),
"_pthread_getattr_np" => func!(crate::emscripten_target::_pthread_getattr_np),
"_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific),
"_pthread_once" => func!(crate::emscripten_target::_pthread_once),
"_pthread_key_create" => func!(crate::emscripten_target::_pthread_key_create),
"_pthread_rwlock_destroy" => func!(crate::emscripten_target::_pthread_rwlock_destroy),
"_pthread_rwlock_init" => func!(crate::emscripten_target::_pthread_rwlock_init),
"_pthread_rwlock_rdlock" => func!(crate::emscripten_target::_pthread_rwlock_rdlock),
"_pthread_rwlock_unlock" => func!(crate::emscripten_target::_pthread_rwlock_unlock),
"_pthread_rwlock_wrlock" => func!(crate::emscripten_target::_pthread_rwlock_wrlock),
"_pthread_setcancelstate" => func!(crate::emscripten_target::_pthread_setcancelstate),
"_pthread_setspecific" => func!(crate::emscripten_target::_pthread_setspecific),
"_pthread_sigmask" => func!(crate::emscripten_target::_pthread_sigmask),
"___gxx_personality_v0" => func!(crate::emscripten_target::___gxx_personality_v0),
"_gai_strerror" => func!(crate::emscripten_target::_gai_strerror),
"_getdtablesize" => func!(crate::emscripten_target::_getdtablesize),
"_gethostbyaddr" => func!(crate::emscripten_target::_gethostbyaddr),
"_gethostbyname" => func!(crate::emscripten_target::_gethostbyname),
"_gethostbyname_r" => func!(crate::emscripten_target::_gethostbyname_r),
"_getloadavg" => func!(crate::emscripten_target::_getloadavg),
"_getnameinfo" => func!(crate::emscripten_target::_getnameinfo),
@ -841,6 +939,9 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_makecontext" => func!(crate::ucontext::_makecontext),
"_setcontext" => func!(crate::ucontext::_setcontext),
"_swapcontext" => func!(crate::ucontext::_swapcontext),
// unistd
"_confstr" => func!(crate::unistd::confstr),
};
for null_func_name in globals.null_func_names.iter() {

View File

@ -0,0 +1,78 @@
extern crate libc;
extern crate wasmer_runtime_core;
#[cfg(unix)]
use std::convert::TryInto;
use wasmer_runtime_core::vm::Ctx;
pub fn current_sigrtmax(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::current_sigrtmax");
0
}
pub fn current_sigrtmin(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::current_sigrtmin");
0
}
pub fn endpwent(_ctx: &mut Ctx) {
debug!("emscripten::endpwent");
}
pub fn execv(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::execv");
0
}
pub fn fexecve(_ctx: &mut Ctx, _a: i32, _b: i32, _c: i32) -> i32 {
debug!("emscripten::fexecve");
0
}
pub fn fpathconf(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::fpathconf");
0
}
pub fn getitimer(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::getitimer");
0
}
pub fn getpwent(_ctx: &mut Ctx) -> i32 {
debug!("emscripten::getpwent");
0
}
pub fn killpg(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::killpg");
0
}
#[cfg(unix)]
pub fn pathconf(ctx: &mut Ctx, path_ptr: i32, name: i32) -> i32 {
debug!("emscripten::pathconf");
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const i8;
unsafe { libc::pathconf(path, name).try_into().unwrap() }
}
#[cfg(not(unix))]
pub fn pathconf(_ctx: &mut Ctx, _path_ptr: i32, _name: i32) -> i32 {
debug!("emscripten::pathconf");
0
}
pub fn setpwent(_ctx: &mut Ctx) {
debug!("emscripten::setpwent");
}
pub fn sigismember(_ctx: &mut Ctx, _a: i32, _b: i32) -> i32 {
debug!("emscripten::sigismember");
0
}
pub fn sigpending(_ctx: &mut Ctx, _a: i32) -> i32 {
debug!("emscripten::sigpending");
0
}

View File

@ -0,0 +1,9 @@
extern crate libm;
extern crate wasmer_runtime_core;
use libm::fma;
use wasmer_runtime_core::vm::Ctx;
pub fn fma_f64(_ctx: &mut Ctx, x: f64, y: f64, z: f64) -> f64 {
fma(x, y, z)
}

View File

@ -1,5 +1,13 @@
use wasmer_runtime_core::vm::Ctx;
pub fn _llvm_copysign_f32(_ctx: &mut Ctx, x: f64, y: f64) -> f64 {
x.copysign(y)
}
pub fn _llvm_copysign_f64(_ctx: &mut Ctx, x: f64, y: f64) -> f64 {
x.copysign(y)
}
/// emscripten: _llvm_log10_f64
pub fn _llvm_log10_f64(_ctx: &mut Ctx, value: f64) -> f64 {
debug!("emscripten::_llvm_log10_f64");

View File

@ -131,11 +131,36 @@ pub fn _nanosleep(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
pub fn _utime(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_utime");
-1
}
pub fn _utimes(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::_utimes");
-1
}
pub fn _wait(_ctx: &mut Ctx, _one: i32) -> i32 {
debug!("emscripten::_wait");
-1
}
pub fn _wait3(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_wait3");
-1
}
pub fn _wait4(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
debug!("emscripten::_wait4");
-1
}
pub fn _waitid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32, _d: i32) -> i32 {
debug!("emscripten::_waitid");
-1
}
pub fn _waitpid(_ctx: &mut Ctx, _one: i32, _two: i32, _three: i32) -> i32 {
debug!("emscripten::_waitpid");
-1

View File

@ -16,6 +16,11 @@ pub fn _sigaction(_ctx: &mut Ctx, _signum: u32, _act: u32, _oldact: u32) -> i32
0
}
pub fn _siginterrupt(_ctx: &mut Ctx, _a: u32, _b: u32) -> i32 {
debug!("emscripten::_siginterrupt {}, {}", _a, _b);
0
}
#[allow(clippy::cast_ptr_alignment)]
pub fn _sigaddset(ctx: &mut Ctx, set: u32, signum: u32) -> i32 {
debug!("emscripten::_sigaddset {}, {}", set, signum);

View File

@ -27,6 +27,7 @@ use libc::{
exit,
fstat,
getpid,
// readlink,
// iovec,
lseek,
off_t,
@ -39,9 +40,11 @@ use libc::{
// writev,
stat,
write,
// readlink,
};
use wasmer_runtime_core::vm::Ctx;
use wasmer_runtime_core::{
memory::ptr::{Array, WasmPtr},
vm::Ctx,
};
use super::env;
use std::cell::Cell;
@ -77,7 +80,7 @@ pub fn ___syscall3(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
pub fn ___syscall4(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall4 (write) {}", _which);
let fd: i32 = varargs.get(ctx);
let buf: u32 = varargs.get(ctx);
let buf: i32 = varargs.get(ctx);
let count: i32 = varargs.get(ctx);
debug!("=> fd: {}, buf: {}, count: {}", fd, buf, count);
let buf_addr = emscripten_memory_pointer!(ctx.memory(0), buf) as *const c_void;
@ -116,6 +119,11 @@ pub fn ___syscall10(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
pub fn ___syscall14(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall14");
-1
}
pub fn ___syscall15(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall15");
-1
@ -127,6 +135,36 @@ pub fn ___syscall20(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
unsafe { getpid() }
}
pub fn ___syscall21(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall21");
-1
}
pub fn ___syscall25(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall25");
-1
}
pub fn ___syscall29(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall29");
-1
}
pub fn ___syscall32(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall32");
-1
}
pub fn ___syscall33(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall33");
-1
}
pub fn ___syscall36(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall36");
-1
}
// rename
pub fn ___syscall38(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall38 (rename)");
@ -193,6 +231,21 @@ pub fn ___syscall42(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
result
}
pub fn ___syscall51(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall51");
-1
}
pub fn ___syscall52(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall52");
-1
}
pub fn ___syscall53(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall53");
-1
}
pub fn ___syscall60(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall60");
-1
@ -257,6 +310,11 @@ pub fn ___syscall91(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
0
}
pub fn ___syscall96(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall96");
-1
}
pub fn ___syscall97(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall97");
-1
@ -267,24 +325,76 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
pub fn ___syscall121(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall121");
-1
}
pub fn ___syscall125(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall125");
-1
}
pub fn ___syscall132(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall132");
-1
}
pub fn ___syscall133(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall133");
-1
}
pub fn ___syscall144(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall144");
-1
}
pub fn ___syscall147(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall147");
-1
}
pub fn ___syscall150(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall150");
-1
}
pub fn ___syscall151(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall151");
-1
}
pub fn ___syscall152(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall152");
-1
}
pub fn ___syscall153(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall153");
-1
}
pub fn ___syscall163(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall163");
-1
}
// getcwd
pub fn ___syscall183(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall183");
let buf_offset: c_int = varargs.get(ctx);
let buf_offset: WasmPtr<libc::c_char, Array> = varargs.get(ctx);
let _size: c_int = varargs.get(ctx);
let path = get_current_directory(ctx);
let path_string = path.unwrap().display().to_string();
let len = path_string.len();
unsafe {
let pointer_to_buffer =
emscripten_memory_pointer!(ctx.memory(0), buf_offset) as *mut libc::c_char;
let slice = slice::from_raw_parts_mut(pointer_to_buffer, len.clone());
for (byte, loc) in path_string.bytes().zip(slice.iter_mut()) {
*loc = byte as _;
let buf_writer = buf_offset.deref(ctx.memory(0), 0, len as u32 + 1).unwrap();
for (i, byte) in path_string.bytes().enumerate() {
buf_writer[i].set(byte as i8);
}
*pointer_to_buffer.add(len.clone()) = 0;
}
buf_offset
buf_writer[len].set(0);
buf_offset.offset() as i32
}
// mmap2
@ -446,8 +556,8 @@ pub fn ___syscall191(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
0
}
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 - stub");
pub fn ___syscall193(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall193");
-1
}
@ -501,6 +611,21 @@ pub fn ___syscall197(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
0
}
pub fn ___syscall209(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall209");
-1
}
pub fn ___syscall211(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall211");
-1
}
pub fn ___syscall218(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall218");
-1
}
// fcntl64
pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall221 (fcntl64) {}", _which);
@ -524,6 +649,11 @@ pub fn ___syscall268(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
pub fn ___syscall269(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall269");
-1
}
pub fn ___syscall272(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall272");
-1
@ -534,22 +664,92 @@ pub fn ___syscall295(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
pub fn ___syscall296(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall296");
-1
}
pub fn ___syscall297(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall297");
-1
}
pub fn ___syscall298(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall298");
-1
}
pub fn ___syscall300(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall300");
-1
}
pub fn ___syscall301(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall301");
-1
}
pub fn ___syscall302(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall302");
-1
}
pub fn ___syscall303(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall303");
-1
}
pub fn ___syscall304(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall304");
-1
}
pub fn ___syscall305(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall305");
-1
}
pub fn ___syscall306(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall306");
-1
}
pub fn ___syscall307(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall307");
-1
}
pub fn ___syscall308(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall308");
-1
}
// utimensat
pub fn ___syscall320(_ctx: &mut Ctx, _which: c_int, mut _varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall320 (utimensat), {}", _which);
0
}
pub fn ___syscall331(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall331");
-1
}
pub fn ___syscall333(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall333");
-1
}
pub fn ___syscall334(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall334");
-1
}
pub fn ___syscall337(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall337");
-1
}
// prlimit64
pub fn ___syscall340(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
debug!("emscripten::___syscall340 (prlimit64), {}", _which);
@ -576,3 +776,8 @@ pub fn ___syscall340(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
0
}
pub fn ___syscall345(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall345");
-1
}

View File

@ -26,6 +26,7 @@ use libc::{
getrusage,
getsockname,
getsockopt,
getuid,
gid_t,
in_addr_t,
in_port_t,
@ -74,6 +75,9 @@ use libc::{
SO_REUSEADDR,
TIOCGWINSZ,
};
#[allow(unused_imports)]
use std::ffi::CStr;
use wasmer_runtime_core::vm::Ctx;
use crate::utils;
@ -845,39 +849,65 @@ pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
0
}
// getuid
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 (getuid)");
let uid = unsafe { getuid() as _ };
debug!(" => {}", uid);
uid
}
// getdents
// dirent structure is
// i64, i64, u16 (280), i8, [i8; 256]
pub fn ___syscall220(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
debug!("emscripten::___syscall220");
use super::super::env::get_emscripten_data;
let fd: i32 = varargs.get(ctx);
let dirp_addr: i32 = varargs.get(ctx);
let count: u32 = varargs.get(ctx);
debug!(
"emscripten::___syscall220 (getdents) {} {} {}",
fd, dirp_addr, count
);
let dirp = emscripten_memory_pointer!(ctx.memory(0), dirp_addr) as *mut u8;
let mut opened_dirs = &mut get_emscripten_data(ctx).opened_dirs;
// need to persist stream across calls?
let dir: *mut libc::DIR = unsafe { libc::fdopendir(fd) };
// let dir: *mut libc::DIR = unsafe { libc::fdopendir(fd) };
let mut dir = &*opened_dirs
.entry(fd)
.or_insert_with(|| unsafe { Box::new(libc::fdopendir(fd)) });
let mut pos = 0;
let offset = 280;
let offset = 256 + 12;
while pos + offset <= count as usize {
let dirent = unsafe { readdir(dir) };
let dirent = unsafe { readdir(**dir) };
if dirent.is_null() {
break;
}
#[allow(clippy::cast_ptr_alignment)]
unsafe {
*(dirp.add(pos) as *mut u64) = (*dirent).d_ino;
*(dirp.add(pos + 8) as *mut u64) = pos as u64 + offset as u64;
*(dirp.add(pos + 16) as *mut u16) = offset as u16;
*(dirp.add(pos + 18) as *mut u8) = (*dirent).d_type;
let upper_bound = std::cmp::min((*dirent).d_reclen, 254) as usize;
*(dirp.add(pos) as *mut u32) = (*dirent).d_ino as u32;
*(dirp.add(pos + 4) as *mut u32) = pos as u32;
*(dirp.add(pos + 8) as *mut u16) = offset as u16;
*(dirp.add(pos + 10) as *mut u8) = (*dirent).d_type;
let upper_bound = std::cmp::min((*dirent).d_reclen, 255) as usize;
let mut i = 0;
while i < upper_bound {
*(dirp.add(pos + 19 + i) as *mut i8) = (*dirent).d_name[i];
*(dirp.add(pos + 11 + i) as *mut i8) = (*dirent).d_name[i];
i += 1;
}
*(dirp.add(pos + 19 + i) as *mut i8) = 0 as i8;
// We set the termination string char
*(dirp.add(pos + 11 + i) as *mut i8) = 0 as i8;
debug!(
" => file {}",
CStr::from_ptr(dirp.add(pos + 11) as *const i8)
.to_str()
.unwrap()
);
}
pos += offset;
}

View File

@ -261,6 +261,12 @@ pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
-1
}
// getuid
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall199 (getuid)");
-1
}
// getdents
pub fn ___syscall220(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
debug!("emscripten::___syscall220");

View File

@ -1,5 +1,6 @@
use super::utils::{copy_cstr_into_wasm, write_to_buf};
use libc::{c_char, c_int};
// use libc::{c_char, c_int, clock_getres, clock_settime};
use std::mem;
use std::time::SystemTime;
@ -69,6 +70,12 @@ pub fn _gettimeofday(ctx: &mut Ctx, tp: c_int, tz: c_int) -> c_int {
0
}
pub fn _clock_getres(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 {
debug!("emscripten::_clock_getres");
// clock_getres(clk_id, tp)
0
}
/// emscripten: _clock_gettime
#[allow(clippy::cast_ptr_alignment)]
pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int {
@ -103,6 +110,12 @@ pub fn _clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int {
0
}
pub fn _clock_settime(_ctx: &mut Ctx, _clk_id: i32, _tp: i32) -> i32 {
debug!("emscripten::_clock_settime");
// clock_settime(clk_id, tp)
0
}
/// emscripten: ___clock_gettime
pub fn ___clock_gettime(ctx: &mut Ctx, clk_id: clockid_t, tp: c_int) -> c_int {
debug!("emscripten::___clock_gettime {} {}", clk_id, tp);

View File

@ -0,0 +1,6 @@
use wasmer_runtime_core::vm::Ctx;
pub fn confstr(_ctx: &mut Ctx, _name: i32, _buf_pointer: i32, _len: i32) -> i32 {
debug!("unistd::confstr({}, {}, {})", _name, _buf_pointer, _len);
0
}

View File

@ -1,11 +1,11 @@
[package]
name = "wasmer-llvm-backend"
version = "0.4.2"
version = "0.5.0"
authors = ["Lachlan Sneff <lachlan.sneff@gmail.com>"]
edition = "2018"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
inkwell = { git = "https://github.com/wasmerio/inkwell", branch = "llvm7-0" }
wasmparser = "0.29.2"
hashbrown = "0.1.8"

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-middleware-common"
version = "0.4.2"
version = "0.5.0"
repository = "https://github.com/wasmerio/wasmer"
description = "Wasmer runtime common middlewares"
license = "MIT"
@ -9,9 +9,9 @@ edition = "2018"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core" }
wasmer-clif-backend = { path = "../clif-backend", version = "0.4.2" }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.4.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
wasmer-clif-backend = { path = "../clif-backend", version = "0.5.0" }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.0", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.0", optional = true }
[dev-dependencies]
wabt = "0.7.4"

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-runtime-abi"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime core library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-runtime-c-api"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer C API library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -16,11 +16,11 @@ libc = "0.2"
[dependencies.wasmer-runtime]
path = "../runtime"
version = "0.4.2"
version = "0.5.0"
[dependencies.wasmer-runtime-core]
path = "../runtime-core"
version = "0.4.2"
version = "0.5.0"
[features]
debug = ["wasmer-runtime/debug"]

View File

@ -11,7 +11,7 @@ use crate::{
value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
wasmer_byte_array, wasmer_result_t,
};
use libc::{c_int, uint32_t};
use libc::c_int;
use std::{ptr, slice};
use wasmer_runtime::{Instance, Memory, Module, Value};
use wasmer_runtime_core::{export::Export, module::ExportIndex};
@ -196,12 +196,12 @@ pub unsafe extern "C" fn wasmer_export_kind(
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_export_func_params_arity(
func: *const wasmer_export_func_t,
result: *mut uint32_t,
result: *mut u32,
) -> wasmer_result_t {
let named_export = &*(func as *const NamedExport);
let export = &named_export.export;
if let Export::Function { ref signature, .. } = *export {
*result = signature.params().len() as uint32_t;
*result = signature.params().len() as u32;
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
@ -222,7 +222,7 @@ pub unsafe extern "C" fn wasmer_export_func_params_arity(
pub unsafe extern "C" fn wasmer_export_func_params(
func: *const wasmer_export_func_t,
params: *mut wasmer_value_tag,
params_len: uint32_t,
params_len: u32,
) -> wasmer_result_t {
let named_export = &*(func as *const NamedExport);
let export = &named_export.export;
@ -252,7 +252,7 @@ pub unsafe extern "C" fn wasmer_export_func_params(
pub unsafe extern "C" fn wasmer_export_func_returns(
func: *const wasmer_export_func_t,
returns: *mut wasmer_value_tag,
returns_len: uint32_t,
returns_len: u32,
) -> wasmer_result_t {
let named_export = &*(func as *const NamedExport);
let export = &named_export.export;
@ -281,12 +281,12 @@ pub unsafe extern "C" fn wasmer_export_func_returns(
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_export_func_returns_arity(
func: *const wasmer_export_func_t,
result: *mut uint32_t,
result: *mut u32,
) -> wasmer_result_t {
let named_export = &*(func as *const NamedExport);
let export = &named_export.export;
if let Export::Function { ref signature, .. } = *export {
*result = signature.returns().len() as uint32_t;
*result = signature.returns().len() as u32;
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {

View File

@ -8,7 +8,7 @@ use crate::{
value::wasmer_value_tag,
wasmer_byte_array, wasmer_result_t,
};
use libc::{c_uint, uint32_t};
use libc::c_uint;
use std::{ffi::c_void, ptr, slice, sync::Arc};
use wasmer_runtime::Module;
use wasmer_runtime_core::{
@ -222,11 +222,11 @@ pub unsafe extern "C" fn wasmer_import_descriptor_kind(
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_import_func_params_arity(
func: *const wasmer_import_func_t,
result: *mut uint32_t,
result: *mut u32,
) -> wasmer_result_t {
let export = &*(func as *const Export);
if let Export::Function { ref signature, .. } = *export {
*result = signature.params().len() as uint32_t;
*result = signature.params().len() as u32;
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {
@ -329,11 +329,11 @@ pub unsafe extern "C" fn wasmer_import_func_returns(
#[allow(clippy::cast_ptr_alignment)]
pub unsafe extern "C" fn wasmer_import_func_returns_arity(
func: *const wasmer_import_func_t,
result: *mut uint32_t,
result: *mut u32,
) -> wasmer_result_t {
let export = &*(func as *const Export);
if let Export::Function { ref signature, .. } = *export {
*result = signature.returns().len() as uint32_t;
*result = signature.returns().len() as u32;
wasmer_result_t::WASMER_OK
} else {
update_last_error(CApiError {

View File

@ -8,7 +8,7 @@ use crate::{
value::{wasmer_value, wasmer_value_t, wasmer_value_tag},
wasmer_result_t,
};
use libc::{c_char, c_int, c_void, uint32_t, uint8_t};
use libc::{c_char, c_int, c_void};
use std::{collections::HashMap, ffi::CStr, slice};
use wasmer_runtime::{Ctx, Global, ImportObject, Instance, Memory, Table, Value};
use wasmer_runtime_core::{export::Export, import::Namespace};
@ -29,8 +29,8 @@ pub struct wasmer_instance_context_t;
#[no_mangle]
pub unsafe extern "C" fn wasmer_instantiate(
instance: *mut *mut wasmer_instance_t,
wasm_bytes: *mut uint8_t,
wasm_bytes_len: uint32_t,
wasm_bytes: *mut u8,
wasm_bytes_len: u32,
imports: *mut wasmer_import_t,
imports_len: c_int,
) -> wasmer_result_t {
@ -121,9 +121,9 @@ pub unsafe extern "C" fn wasmer_instance_call(
instance: *mut wasmer_instance_t,
name: *const c_char,
params: *const wasmer_value_t,
params_len: uint32_t,
params_len: u32,
results: *mut wasmer_value_t,
results_len: uint32_t,
results_len: u32,
) -> wasmer_result_t {
if instance.is_null() {
update_last_error(CApiError {
@ -225,7 +225,7 @@ pub extern "C" fn wasmer_instance_context_data_set(
#[no_mangle]
pub extern "C" fn wasmer_instance_context_memory(
ctx: *const wasmer_instance_context_t,
_memory_idx: uint32_t,
_memory_idx: u32,
) -> *const wasmer_memory_t {
let ctx = unsafe { &*(ctx as *const Ctx) };
let memory = ctx.memory(0);

View File

@ -85,8 +85,6 @@
extern crate wasmer_runtime;
extern crate wasmer_runtime_core;
use libc::{uint32_t, uint8_t};
pub mod error;
pub mod export;
pub mod global;
@ -108,18 +106,18 @@ pub enum wasmer_result_t {
#[repr(C)]
pub struct wasmer_limits_t {
pub min: uint32_t,
pub min: u32,
pub max: wasmer_limit_option_t,
}
#[repr(C)]
pub struct wasmer_limit_option_t {
pub has_some: bool,
pub some: uint32_t,
pub some: u32,
}
#[repr(C)]
pub struct wasmer_byte_array {
bytes: *const uint8_t,
bytes_len: uint32_t,
bytes: *const u8,
bytes_len: u32,
}

View File

@ -1,7 +1,6 @@
//! Create, read, write, grow, destroy memory of an instance.
use crate::{error::update_last_error, wasmer_limits_t, wasmer_result_t};
use libc::{uint32_t, uint8_t};
use std::cell::Cell;
use wasmer_runtime::Memory;
use wasmer_runtime_core::{
@ -57,10 +56,7 @@ pub unsafe extern "C" fn wasmer_memory_new(
/// and `wasmer_last_error_message` to get an error message.
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_grow(
memory: *mut wasmer_memory_t,
delta: uint32_t,
) -> wasmer_result_t {
pub extern "C" fn wasmer_memory_grow(memory: *mut wasmer_memory_t, delta: u32) -> wasmer_result_t {
let memory = unsafe { &*(memory as *mut Memory) };
let delta_result = memory.grow(Pages(delta));
match delta_result {
@ -75,7 +71,7 @@ pub extern "C" fn wasmer_memory_grow(
/// Returns the current length in pages of the given memory
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_length(memory: *const wasmer_memory_t) -> uint32_t {
pub extern "C" fn wasmer_memory_length(memory: *const wasmer_memory_t) -> u32 {
let memory = unsafe { &*(memory as *const Memory) };
let Pages(len) = memory.size();
len
@ -84,7 +80,7 @@ pub extern "C" fn wasmer_memory_length(memory: *const wasmer_memory_t) -> uint32
/// Gets the start pointer to the bytes within a Memory
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_data(mem: *const wasmer_memory_t) -> *mut uint8_t {
pub extern "C" fn wasmer_memory_data(mem: *const wasmer_memory_t) -> *mut u8 {
let memory = unsafe { &*(mem as *const Memory) };
memory.view::<u8>()[..].as_ptr() as *mut Cell<u8> as *mut u8
}
@ -92,10 +88,10 @@ pub extern "C" fn wasmer_memory_data(mem: *const wasmer_memory_t) -> *mut uint8_
/// Gets the size in bytes of a Memory
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_memory_data_length(mem: *mut wasmer_memory_t) -> uint32_t {
pub extern "C" fn wasmer_memory_data_length(mem: *mut wasmer_memory_t) -> u32 {
let memory = mem as *mut Memory;
let Bytes(len) = unsafe { (*memory).size().bytes() };
len as uint32_t
len as u32
}
/// Frees memory for the given Memory

View File

@ -7,7 +7,7 @@ use crate::{
instance::wasmer_instance_t,
wasmer_byte_array, wasmer_result_t,
};
use libc::{c_int, uint32_t, uint8_t};
use libc::c_int;
use std::{collections::HashMap, slice};
use wasmer_runtime::{compile, default_compiler, Global, ImportObject, Memory, Module, Table};
use wasmer_runtime_core::{cache::Artifact, export::Export, import::Namespace, load_cache_with};
@ -28,8 +28,8 @@ pub struct wasmer_serialized_module_t;
#[no_mangle]
pub unsafe extern "C" fn wasmer_compile(
module: *mut *mut wasmer_module_t,
wasm_bytes: *mut uint8_t,
wasm_bytes_len: uint32_t,
wasm_bytes: *mut u8,
wasm_bytes_len: u32,
) -> wasmer_result_t {
let bytes: &[u8] = slice::from_raw_parts_mut(wasm_bytes, wasm_bytes_len as usize);
let result = compile(bytes);
@ -47,10 +47,7 @@ pub unsafe extern "C" fn wasmer_compile(
/// Returns true for valid wasm bytes and false for invalid bytes
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub unsafe extern "C" fn wasmer_validate(
wasm_bytes: *const uint8_t,
wasm_bytes_len: uint32_t,
) -> bool {
pub unsafe extern "C" fn wasmer_validate(wasm_bytes: *const u8, wasm_bytes_len: u32) -> bool {
if wasm_bytes.is_null() {
return false;
}
@ -129,14 +126,14 @@ pub unsafe extern "C" fn wasmer_module_instantiate(
}
let module = &*(module as *const Module);
let new_instance = if let Ok(res) = module.instantiate(&import_object) {
res
} else {
update_last_error(CApiError {
msg: "error instantiating from module".to_string(),
});
let new_instance = match module.instantiate(&import_object) {
Ok(instance) => instance,
Err(error) => {
update_last_error(error);
return wasmer_result_t::WASMER_ERROR;
}
};
*instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t;
wasmer_result_t::WASMER_OK
}
@ -206,8 +203,8 @@ pub unsafe extern "C" fn wasmer_serialized_module_bytes(
#[no_mangle]
pub unsafe extern "C" fn wasmer_serialized_module_from_bytes(
serialized_module: *mut *mut wasmer_serialized_module_t,
serialized_module_bytes: *const uint8_t,
serialized_module_bytes_length: uint32_t,
serialized_module_bytes: *const u8,
serialized_module_bytes_length: u32,
) -> wasmer_result_t {
if serialized_module.is_null() {
update_last_error(CApiError {

View File

@ -1,7 +1,6 @@
//! Create, grow, destroy tables of an instance.
use crate::{error::update_last_error, wasmer_limits_t, wasmer_result_t};
use libc::uint32_t;
use wasmer_runtime::Table;
use wasmer_runtime_core::types::{ElementType, TableDescriptor};
@ -53,10 +52,7 @@ pub unsafe extern "C" fn wasmer_table_new(
/// and `wasmer_last_error_message` to get an error message.
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_table_grow(
table: *mut wasmer_table_t,
delta: uint32_t,
) -> wasmer_result_t {
pub extern "C" fn wasmer_table_grow(table: *mut wasmer_table_t, delta: u32) -> wasmer_result_t {
let table = unsafe { &*(table as *mut Table) };
let delta_result = table.grow(delta);
match delta_result {
@ -71,7 +67,7 @@ pub extern "C" fn wasmer_table_grow(
/// Returns the current length of the given Table
#[allow(clippy::cast_ptr_alignment)]
#[no_mangle]
pub extern "C" fn wasmer_table_length(table: *mut wasmer_table_t) -> uint32_t {
pub extern "C" fn wasmer_table_length(table: *mut wasmer_table_t) -> u32 {
let table = unsafe { &*(table as *mut Table) };
table.size()
}

View File

@ -1,6 +1,5 @@
//! Create and map Rust to WebAssembly values.
use libc::{int32_t, int64_t};
use wasmer_runtime::Value;
use wasmer_runtime_core::types::Type;
@ -18,8 +17,8 @@ pub enum wasmer_value_tag {
#[derive(Clone, Copy)]
#[allow(non_snake_case)]
pub union wasmer_value {
pub I32: int32_t,
pub I64: int64_t,
pub I32: i32,
pub I64: i64,
pub F32: f32,
pub F64: f64,
}

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-runtime-core"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime core library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]

View File

@ -89,7 +89,7 @@ pub trait RunnableModule: Send + Sync {
None
}
/// A wasm trampoline contains the necesarry data to dynamically call an exported wasm function.
/// A wasm trampoline contains the necessary data to dynamically call an exported wasm function.
/// Given a particular signature index, we are returned a trampoline that is matched with that
/// signature and an invoke function that can call the trampoline.
fn get_trampoline(&self, info: &ModuleInfo, sig_index: SigIndex) -> Option<Wasm>;

View File

@ -139,7 +139,7 @@ impl LocalBacking {
if let Value::I32(x) = imports.globals[import_global_index].get() {
x as u32
} else {
panic!("unsupported global type for initialzer")
panic!("unsupported global type for initializer")
}
}
} as usize;
@ -210,7 +210,7 @@ impl LocalBacking {
if let Value::I32(x) = imports.globals[import_global_index].get() {
x as u32
} else {
panic!("unsupported global type for initialzer")
panic!("unsupported global type for initializer")
}
}
} as usize;

View File

@ -10,7 +10,7 @@ use crate::{
};
use std::{
cell::{Cell, RefCell},
fmt, mem, ptr,
fmt, mem,
rc::Rc,
};
@ -21,6 +21,7 @@ pub use self::view::{Atomically, MemoryView};
mod atomic;
mod dynamic;
pub mod ptr;
mod static_;
mod view;
@ -221,9 +222,9 @@ struct UnsharedMemoryInternal {
impl UnsharedMemory {
pub fn new(desc: MemoryDescriptor) -> Result<Self, CreationError> {
let mut local = vm::LocalMemory {
base: ptr::null_mut(),
base: std::ptr::null_mut(),
bound: 0,
memory: ptr::null_mut(),
memory: std::ptr::null_mut(),
};
let storage = match desc.memory_type() {

View File

@ -0,0 +1,125 @@
//! A reusable pointer abstraction for getting memory from the guest's memory.
//!
//! This abstraction is safe: it ensures the memory is in bounds and that the pointer
//! is aligned (avoiding undefined behavior).
//!
//! Therefore, you should use this abstraction whenever possible to avoid memory
//! related bugs when implementing an ABI.
use crate::{
memory::Memory,
types::{ValueType, WasmExternType},
};
use std::{cell::Cell, fmt, marker::PhantomData, mem};
pub struct Array;
pub struct Item;
#[repr(transparent)]
pub struct WasmPtr<T: Copy, Ty = Item> {
offset: u32,
_phantom: PhantomData<(T, Ty)>,
}
impl<T: Copy, Ty> WasmPtr<T, Ty> {
#[inline]
pub fn new(offset: u32) -> Self {
Self {
offset,
_phantom: PhantomData,
}
}
#[inline]
pub fn offset(self) -> u32 {
self.offset
}
}
#[inline(always)]
fn align_pointer(ptr: usize, align: usize) -> usize {
// clears bits below aligment amount (assumes power of 2) to align pointer
debug_assert!(align.count_ones() == 1);
ptr & !(align - 1)
}
impl<T: Copy + ValueType> WasmPtr<T, Item> {
#[inline]
pub fn deref<'a>(self, memory: &'a Memory) -> Option<&'a Cell<T>> {
if (self.offset as usize) + mem::size_of::<T>() >= memory.size().bytes().0 {
return None;
}
unsafe {
let cell_ptr = align_pointer(
memory.view::<u8>().as_ptr().add(self.offset as usize) as usize,
mem::align_of::<T>(),
) as *const Cell<T>;
Some(&*cell_ptr)
}
}
}
impl<T: Copy + ValueType> WasmPtr<T, Array> {
#[inline]
pub fn deref<'a>(self, memory: &'a Memory, index: u32, length: u32) -> Option<&'a [Cell<T>]> {
// gets the size of the item in the array with padding added such that
// for any index, we will always result an aligned memory access
let item_size = mem::size_of::<T>() + (mem::size_of::<T>() % mem::align_of::<T>());
let slice_full_len = index as usize + length as usize;
if (self.offset as usize) + (item_size * slice_full_len) >= memory.size().bytes().0 {
return None;
}
unsafe {
let cell_ptr = align_pointer(
memory.view::<u8>().as_ptr().add(self.offset as usize) as usize,
mem::align_of::<T>(),
) as *const Cell<T>;
let cell_ptrs = &std::slice::from_raw_parts(cell_ptr, slice_full_len)
[index as usize..slice_full_len];
Some(cell_ptrs)
}
}
}
unsafe impl<T: Copy, Ty> WasmExternType for WasmPtr<T, Ty> {
type Native = i32;
fn to_native(self) -> Self::Native {
self.offset as i32
}
fn from_native(n: Self::Native) -> Self {
Self {
offset: n as u32,
_phantom: PhantomData,
}
}
}
unsafe impl<T: Copy, Ty> ValueType for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> Clone for WasmPtr<T, Ty> {
fn clone(&self) -> Self {
Self {
offset: self.offset,
_phantom: PhantomData,
}
}
}
impl<T: Copy, Ty> Copy for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> PartialEq for WasmPtr<T, Ty> {
fn eq(&self, other: &Self) -> bool {
self.offset == other.offset
}
}
impl<T: Copy, Ty> Eq for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> fmt::Debug for WasmPtr<T, Ty> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "WasmPtr({:#x})", self.offset)
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-runtime"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -9,17 +9,17 @@ edition = "2018"
readme = "README.md"
[dependencies]
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.0", optional = true }
lazy_static = "1.2.0"
memmap = "0.7.0"
[dependencies.wasmer-runtime-core]
path = "../runtime-core"
version = "0.4.2"
version = "0.5.0"
[dependencies.wasmer-clif-backend]
path = "../clif-backend"
version = "0.4.2"
version = "0.5.0"
optional = true
[dev-dependencies]

View File

@ -76,6 +76,7 @@
//! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
//! [`compile_with`]: fn.compile_with.html
pub use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
pub use wasmer_runtime_core::export::Export;
pub use wasmer_runtime_core::global::Global;
pub use wasmer_runtime_core::import::ImportObject;

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-singlepass-backend"
version = "0.4.2"
version = "0.5.0"
repository = "https://github.com/wasmerio/wasmer"
description = "Wasmer runtime single pass compiler backend"
license = "MIT"
@ -8,7 +8,7 @@ authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
edition = "2018"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
wasmparser = "0.29.2"
dynasm = "0.3.2"
dynasmrt = "0.3.1"

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-spectests"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer spectests library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -9,10 +9,10 @@ edition = "2018"
build = "build/mod.rs"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-clif-backend = { path = "../clif-backend", version = "0.4.2" }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.4.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
wasmer-clif-backend = { path = "../clif-backend", version = "0.5.0" }
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.5.0", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.0", optional = true }
[build-dependencies]
wabt = "0.7.2"

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-wasi"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime WASI implementation library"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -9,7 +9,7 @@ edition = "2018"
build = "build/mod.rs"
[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
libc = "0.2.50"
rand = "0.6.5"
# wasmer-runtime-abi = { path = "../runtime-abi" }
@ -18,7 +18,7 @@ generational-arena = "0.2.2"
log = "0.4.6"
byteorder = "1.3.1"
# hack to get tests to work
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.5.0", optional = true }
[target.'cfg(windows)'.dependencies]
winapi = "0.3"
@ -27,8 +27,8 @@ winapi = "0.3"
glob = "0.2.11"
[dev-dependencies]
wasmer-clif-backend = { path = "../clif-backend", version = "0.4.2" }
wasmer-dev-utils = { path = "../dev-utils", version = "0.4.2"}
wasmer-clif-backend = { path = "../clif-backend", version = "0.5.0" }
wasmer-dev-utils = { path = "../dev-utils", version = "0.5.0"}
[features]
clif = []

View File

@ -1,114 +1,78 @@
//! This is a wrapper around the `WasmPtr` abstraction that returns __WASI_EFAULT
//! if memory access failed
use crate::syscalls::types::{__wasi_errno_t, __WASI_EFAULT};
use std::{cell::Cell, fmt, marker::PhantomData, mem};
use std::{cell::Cell, fmt};
pub use wasmer_runtime_core::memory::ptr::Array;
use wasmer_runtime_core::{
memory::Memory,
memory::{ptr, Memory},
types::{ValueType, WasmExternType},
};
pub struct Array;
pub struct Item;
#[repr(transparent)]
pub struct WasmPtr<T: Copy, Ty = Item> {
offset: u32,
_phantom: PhantomData<(T, Ty)>,
pub struct WasmPtr<T: Copy, Ty = ptr::Item>(ptr::WasmPtr<T, Ty>);
unsafe impl<T: Copy, Ty> ValueType for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> Copy for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> Clone for WasmPtr<T, Ty> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<T: Copy, Ty> fmt::Debug for WasmPtr<T, Ty> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self.0)
}
}
unsafe impl<T: Copy, Ty> WasmExternType for WasmPtr<T, Ty> {
type Native = <ptr::WasmPtr<T, Ty> as WasmExternType>::Native;
fn to_native(self) -> Self::Native {
self.0.to_native()
}
fn from_native(n: Self::Native) -> Self {
Self(ptr::WasmPtr::from_native(n))
}
}
impl<T: Copy, Ty> PartialEq for WasmPtr<T, Ty> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl<T: Copy, Ty> Eq for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> WasmPtr<T, Ty> {
#[inline]
#[inline(always)]
pub fn new(offset: u32) -> Self {
Self {
offset,
_phantom: PhantomData,
}
Self(ptr::WasmPtr::new(offset))
}
#[inline]
#[inline(always)]
pub fn offset(self) -> u32 {
self.offset
self.0.offset()
}
}
impl<T: Copy + ValueType> WasmPtr<T, Item> {
#[inline]
impl<T: Copy + ValueType> WasmPtr<T, ptr::Item> {
#[inline(always)]
pub fn deref<'a>(self, memory: &'a Memory) -> Result<&'a Cell<T>, __wasi_errno_t> {
if (self.offset as usize) + mem::size_of::<T>() >= memory.size().bytes().0 {
return Err(__WASI_EFAULT);
}
unsafe {
// clears bits below aligment amount (assumes power of 2) to align pointer
let aligner = |ptr: usize, align: usize| ptr & !(align - 1);
let cell_ptr = aligner(
memory.view::<u8>().as_ptr().add(self.offset as usize) as usize,
mem::align_of::<T>(),
) as *const Cell<T>;
Ok(&*cell_ptr)
}
self.0.deref(memory).ok_or(__WASI_EFAULT)
}
}
impl<T: Copy + ValueType> WasmPtr<T, Array> {
#[inline]
impl<T: Copy + ValueType> WasmPtr<T, ptr::Array> {
#[inline(always)]
pub fn deref<'a>(
self,
memory: &'a Memory,
index: u32,
length: u32,
) -> Result<&'a [Cell<T>], __wasi_errno_t> {
if (self.offset as usize) + (mem::size_of::<T>() * ((index + length) as usize))
>= memory.size().bytes().0
{
return Err(__WASI_EFAULT);
}
unsafe {
let cell_ptrs = memory.view::<T>().get_unchecked(
((self.offset as usize) / mem::size_of::<T>()) + (index as usize)
..((self.offset() as usize) / mem::size_of::<T>())
+ ((index + length) as usize),
) as *const _;
Ok(&*cell_ptrs)
}
}
}
unsafe impl<T: Copy, Ty> WasmExternType for WasmPtr<T, Ty> {
type Native = i32;
fn to_native(self) -> Self::Native {
self.offset as i32
}
fn from_native(n: Self::Native) -> Self {
Self {
offset: n as u32,
_phantom: PhantomData,
}
}
}
unsafe impl<T: Copy, Ty> ValueType for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> Clone for WasmPtr<T, Ty> {
fn clone(&self) -> Self {
Self {
offset: self.offset,
_phantom: PhantomData,
}
}
}
impl<T: Copy, Ty> Copy for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> PartialEq for WasmPtr<T, Ty> {
fn eq(&self, other: &Self) -> bool {
self.offset == other.offset
}
}
impl<T: Copy, Ty> Eq for WasmPtr<T, Ty> {}
impl<T: Copy, Ty> fmt::Debug for WasmPtr<T, Ty> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "WasmPtr({:#x})", self.offset)
self.0.deref(memory, index, length).ok_or(__WASI_EFAULT)
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-win-exception-handler"
version = "0.4.2"
version = "0.5.0"
description = "Wasmer runtime exception handling for Windows"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]
@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer"
edition = "2018"
[target.'cfg(windows)'.dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.5.0" }
winapi = { version = "0.3", features = ["winbase", "errhandlingapi", "minwindef", "minwinbase", "winnt"] }
libc = "0.2.49"

View File

@ -1,5 +1,5 @@
PREVIOUS_VERSION='0.4.1'
NEXT_VERSION='0.4.2'
PREVIOUS_VERSION='0.4.2'
NEXT_VERSION='0.5.0'
# quick hack
fd Cargo.toml --exec sed -i '' "s/version = \"$PREVIOUS_VERSION\"/version = \"$NEXT_VERSION\"/"