Skip to content

Commit

Permalink
Merge branch 'master' into feature/clif-cgapi
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish authored May 30, 2019
2 parents 921e950 + 5d63c96 commit b2e37ce
Show file tree
Hide file tree
Showing 19 changed files with 446 additions and 94 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ build_script:
- rename target wapm-cli-target
- cd ..
- move wapm-cli\wapm-cli-target wapm-cli-target
- cargo build --release --manifest-path lib/runtime-c-api/Cargo.toml

test_script:
- cargo test --manifest-path lib/spectests/Cargo.toml --features clif
Expand Down
14 changes: 13 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ jobs:
echo "${CIRCLE_TAG}" >> artifacts/git_version
make build-install
cp ./wasmer.tar.gz ./artifacts/$(./binary-name.sh)
- run:
name: Dynamic library
command: |
cargo build --release --manifest-path lib/runtime-c-api/Cargo.toml
cp target/release/libwasmer_runtime_c_api.so ./artifacts
- persist_to_workspace:
root: .
paths:
Expand Down Expand Up @@ -278,6 +283,13 @@ jobs:
cp ./wasmer.tar.gz ./artifacts/$(./binary-name.sh)
# VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2)
# echo "${VERSION}" >> artifacts/version
- run:
name: Generate dynamic library for the runtime C API
command: |
export PATH="$HOME/.cargo/bin:$PATH"
cargo build --release --manifest-path lib/runtime-c-api/Cargo.toml
install_name_tool -id "@rpath/libwasmer_runtime_c_api.dylib" target/release/libwasmer_runtime_c_api.dylib
cp target/release/libwasmer_runtime_c_api.dylib ./artifacts
- persist_to_workspace:
root: .
paths:
Expand Down Expand Up @@ -351,7 +363,7 @@ jobs:
# VERSION_TAG=$(git describe --exact-match --tags)
#if [ "$VERSION" == "$VERSION_TAG" ]; then
# echo "Versions match, publishing to Github"
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -soft ${VERSION} ./artifacts/
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${VERSION} ./artifacts/ || true
#else
# echo "Versions don't match. Wasmer output version (wasmer --version) is ${VERSION} while Git tag is ${VERSION_TAG}"
# exit 1
Expand Down
7 changes: 6 additions & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Wasmer uses the following components:

- [Cranelift](https://github.com/cranestation/cranelift): for compiling Wasm binaries to machine code
- Compiler backends: for compiling Wasm binaries to machine code ([more info here](https://github.com/wasmerio/wasmer/tree/master/lib#backends))
- [wabt](https://github.com/pepyakin/wabt-rs): for transforming `.wast` files to `.wasm` and running WebAssembly spec tests
- [wasmparser](https://github.com/yurydelendik/wasmparser.rs): for parsing the `.wasm` files and translating them into WebAssembly modules

Expand Down Expand Up @@ -67,3 +67,8 @@ Once that's finished, we will have a `Instance` function that will be ready to e

Wasmer's Emscripten integration tries to wrap (and emulate) all the different syscalls that Emscripten needs.
We provide this integration by filling the `import_object` with the Emscripten functions, while instantiating the WebAssembly Instance.

## WASI

Wasmer's WASI integration implements all the different syscalls that WASI needs.
We provide this integration by filling the `import_object` with the WASI functions, while instantiating the WebAssembly Instance.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#470](https://github.com/wasmerio/wasmer/pull/470) Add mapdir support to Emscripten, implement getdents for Unix
- [#467](https://github.com/wasmerio/wasmer/pull/467) `wasmer_instantiate` returns better error messages in the runtime C API
- [#463](https://github.com/wasmerio/wasmer/pull/463) Fix bug in WASI path_open allowing one level above preopened dir to be accessed
- [#461](https://github.com/wasmerio/wasmer/pull/461) Prevent passing negative lengths in various places in the runtime C API
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ curl https://get.wasmer.io -sSfL | sh

Wasmer runtime can also be embedded in different languages, so you can use WebAssembly anywhere ✨:

* [**Rust**](https://github.com/wasmerio/wasmer-rust-example)
* [🦀 **Rust**](https://github.com/wasmerio/wasmer-rust-example)
* [**C/C++**](https://github.com/wasmerio/wasmer-c-api)
* [**🐘 PHP**](https://github.com/wasmerio/php-ext-wasm)
* [**🐍 Python**](https://github.com/wasmerio/python-ext-wasm)
* [**💎 Ruby**](https://github.com/wasmerio/ruby-ext-wasm)
* [**🐹 Go**](https://github.com/wasmerio/go-ext-wasm)

### Usage

Expand Down
19 changes: 19 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Security Policy

## Supported Versions

While in beta, the latest published version of `wasmer` (`0.x`) will be supported with security updates.

| Version | Supported |
| ------- | ------------------ |
| 0.x | :white_check_mark: |

## Reporting a Vulnerability

The Wasmer team and community take security bugs in Wasmer seriously.
We appreciate your efforts to responsibly disclose your findings, and will make every effort to acknowledge your contributions.

To report a security issue, email [email protected] and include the word "SECURITY" in the subject line.

The Wasmer team will send a response indicating the next steps in handling your report.
After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance.
7 changes: 4 additions & 3 deletions lib/emscripten/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ edition = "2018"
build = "build/mod.rs"

[dependencies]
wasmer-runtime-core = { path = "../runtime-core", version = "0.4.2" }
byteorder = "1"
hashbrown = "0.1"
lazy_static = "1.2.0"
libc = "0.2.49"
byteorder = "1"
time = "0.1.41"
wasmer-clif-backend = { path = "../clif-backend", version = "0.4.2" }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.4.2", optional = true }
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 }

[target.'cfg(windows)'.dependencies]
rand = "0.6"
Expand Down
40 changes: 40 additions & 0 deletions lib/emscripten/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub use self::unix::*;
#[cfg(windows)]
pub use self::windows::*;

use libc::c_char;

use crate::{allocate_on_stack, EmscriptenData};
use std::os::raw::c_int;
use wasmer_runtime_core::vm::Ctx;
Expand Down Expand Up @@ -112,3 +114,41 @@ pub fn ___assert_fail(_ctx: &mut Ctx, _a: c_int, _b: c_int, _c: c_int, _d: c_int
// TODO: Implement like emscripten expects regarding memory/page size
// TODO raise an error
}

pub fn _pathconf(ctx: &mut Ctx, path_addr: c_int, name: c_int) -> c_int {
debug!(
"emscripten::_pathconf {} {} - UNIMPLEMENTED",
path_addr, name
);
let _path = emscripten_memory_pointer!(ctx.memory(0), path_addr) as *const c_char;
match name {
0 => 32000,
1 | 2 | 3 => 255,
4 | 5 | 16 | 17 | 18 => 4096,
6 | 7 | 20 => 1,
8 => 0,
9 | 10 | 11 | 12 | 14 | 15 | 19 => -1,
13 => 64,
_ => {
// ___setErrNo(22);
-1
}
}
}

pub fn _fpathconf(_ctx: &mut Ctx, _fildes: c_int, name: c_int) -> c_int {
debug!("emscripten::_fpathconf {} {}", _fildes, name);
match name {
0 => 32000,
1 | 2 | 3 => 255,
4 | 5 | 16 | 17 | 18 => 4096,
6 | 7 | 20 => 1,
8 => 0,
9 | 10 | 11 | 12 | 14 | 15 | 19 => -1,
13 => 64,
_ => {
// ___setErrNo(22);
-1
}
}
}
16 changes: 14 additions & 2 deletions lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#[macro_use]
extern crate wasmer_runtime_core;

use hashbrown::HashMap;
use lazy_static::lazy_static;
use std::cell::UnsafeCell;
use std::path::PathBuf;
use std::{f64, ffi::c_void};
use wasmer_runtime_core::{
error::CallResult,
Expand Down Expand Up @@ -141,10 +143,14 @@ pub struct EmscriptenData<'a> {
pub stack_save: Option<Func<'a, (), i32>>,
pub stack_restore: Option<Func<'a, (i32)>>,
pub set_threw: Option<Func<'a, (i32, i32)>>,
pub mapped_dirs: HashMap<String, PathBuf>,
}

impl<'a> EmscriptenData<'a> {
pub fn new(instance: &'a mut Instance) -> EmscriptenData<'a> {
pub fn new(
instance: &'a mut Instance,
mapped_dirs: HashMap<String, PathBuf>,
) -> EmscriptenData<'a> {
let malloc = instance.func("_malloc").unwrap();
let free = instance.func("_free").unwrap();
let memalign = instance.func("_memalign").ok();
Expand Down Expand Up @@ -272,6 +278,7 @@ impl<'a> EmscriptenData<'a> {
stack_save,
stack_restore,
set_threw,
mapped_dirs,
}
}
}
Expand All @@ -282,8 +289,9 @@ pub fn run_emscripten_instance(
path: &str,
args: Vec<&str>,
entrypoint: Option<String>,
mapped_dirs: Vec<(String, PathBuf)>,
) -> CallResult<()> {
let mut data = EmscriptenData::new(instance);
let mut data = EmscriptenData::new(instance, mapped_dirs.into_iter().collect());
let data_ptr = &mut data as *mut _ as *mut c_void;
instance.context_mut().data = data_ptr;

Expand Down Expand Up @@ -545,6 +553,8 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_sysconf" => func!(crate::env::_sysconf),
"_getaddrinfo" => func!(crate::env::_getaddrinfo),
"_times" => func!(crate::env::_times),
"_pathconf" => func!(crate::env::_pathconf),
"_fpathconf" => func!(crate::env::_fpathconf),

// Syscalls
"___syscall1" => func!(crate::syscalls::___syscall1),
Expand Down Expand Up @@ -687,6 +697,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_asctime_r" => func!(crate::time::_asctime_r),
"_localtime" => func!(crate::time::_localtime),
"_time" => func!(crate::time::_time),
"_timegm" => func!(crate::time::_timegm),
"_strftime" => func!(crate::time::_strftime),
"_strftime_l" => func!(crate::time::_strftime_l),
"_localtime_r" => func!(crate::time::_localtime_r),
Expand All @@ -705,6 +716,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
"_llvm_exp2_f32" => func!(crate::math::_llvm_exp2_f32),
"_llvm_exp2_f64" => func!(crate::math::_llvm_exp2_f64),
"_llvm_trunc_f64" => func!(crate::math::_llvm_trunc_f64),
"_llvm_fma_f64" => func!(crate::math::_llvm_fma_f64),
"_emscripten_random" => func!(crate::math::_emscripten_random),

// Jump
Expand Down
5 changes: 5 additions & 0 deletions lib/emscripten/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub fn _llvm_trunc_f64(_ctx: &mut Ctx, value: f64) -> f64 {
value.trunc()
}

pub fn _llvm_fma_f64(_ctx: &mut Ctx, value: f64, a: f64, b: f64) -> f64 {
debug!("emscripten::_llvm_fma_f64");
value.mul_add(a, b)
}

pub fn _emscripten_random(_ctx: &mut Ctx) -> f64 {
debug!("emscripten::_emscripten_random");
-1.0
Expand Down
Loading

0 comments on commit b2e37ce

Please sign in to comment.