Skip to content

Commit

Permalink
Merge branch 'master' into feature/more-wasi-syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMcCaskey authored Aug 7, 2019
2 parents a1a3447 + bd31422 commit b8f8a63
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ jobs:
VERSION=$(cat ./artifacts/version)
# VERSION_TAG=${CIRCLE_TAG}
VERSION_TAG=$(cat ./artifacts/git_version)
LATEST_VERSION_PUBLISHED_ON_CRATES=$(curl -s https://raw.githubusercontent.com/rust-lang/crates.io-index/master/wa/sm/wasmer-runtime | tail -n 1 | sed 's/.*"vers":"\([^"]*\)".*/\1/')
if ( [ $VERSION_TAG -ne $LATEST_VERSION_PUBLISHED_ON_CRATES ] ) then { echo "Could not detect version published to crates.io; make sure we've published the crates before publishing the Wasmer binary"; exit 1; } else { true; } fi
rm ./artifacts/version
rm ./artifacts/git_version
# VERSION_TAG=$(git describe --exact-match --tags)
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ All PRs to the Wasmer repository must add to this file.
Blocks of changes will separated by version increments.

## **[Unreleased]**

Special thanks to @YaronWittenstein @penberg for their contributions.

- [#608](https://github.com/wasmerio/wasmer/issues/608) Implement wasi syscalls `fd_allocate`, `fd_sync`, `fd_pread`, `path_link`, `path_filestat_set_times`; update WASI fs API in a WIP way; reduce coupling of WASI code to host filesystem; make debug messages from WASI more readable; improve rights-checking when calling syscalls; implement reference counting on inodes; misc bug fixes and improvements
- [#616](https://github.com/wasmerio/wasmer/issues/616) Create the import object separately from instance instantiation in `runtime-c-api`
- [#620](https://github.com/wasmerio/wasmer/issues/620) Replace one `throw()` with `noexcept` in llvm backend
- [#618](https://github.com/wasmerio/wasmer/issues/618) Implement `InternalEvent::Breakpoint` in the llvm backend to allow metering in llvm
- [#615](https://github.com/wasmerio/wasmer/issues/615) Eliminate `FunctionEnvironment` construction in `feed_event()` speeding up to 70% of compilation in clif
- [#609](https://github.com/wasmerio/wasmer/issues/609) Update dependencies
- [#602](https://github.com/wasmerio/wasmer/issues/602) C api extract instance context from instance
- [#590](https://github.com/wasmerio/wasmer/issues/590) Error visibility changes in wasmer-c-api
- [#589](https://github.com/wasmerio/wasmer/issues/589) Make `wasmer_byte_array` fields `public` in wasmer-c-api

## 0.6.0 - 2019-07-31
- [#603](https://github.com/wasmerio/wasmer/pull/603) Update Wapm-cli, bump version numbers
Expand Down
74 changes: 29 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions examples/no_abi_simple_plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extern "C" {
fn it_works() -> i32;
}

#[no_mangle]
pub fn plugin_entrypoint(n: i32) -> i32 {
let result = unsafe { it_works() };
result + n
}

fn main() {}
Binary file added examples/no_abi_simple_plugin.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions lib/emscripten/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ pub fn is_emscripten_module(module: &Module) -> bool {
}

pub fn get_emscripten_table_size(module: &Module) -> (u32, Option<u32>) {
assert!(
module.info().imported_tables.len() > 0,
"Emscripten requires at least one imported table"
);
let (_, table) = &module.info().imported_tables[ImportedTableIndex::new(0)];
(table.minimum, table.maximum)
}

pub fn get_emscripten_memory_size(module: &Module) -> (Pages, Option<Pages>, bool) {
assert!(
module.info().imported_tables.len() > 0,
"Emscripten requires at least one imported memory"
);
let (_, memory) = &module.info().imported_memories[ImportedMemoryIndex::new(0)];
(memory.minimum, memory.maximum, memory.shared)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/llvm-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ winapi = { version = "0.3.7", features = ["memoryapi"] }
[build-dependencies]
cc = "1.0"
lazy_static = "1.3.0"
regex = "1.2.0"
regex = "1.2.1"
semver = "0.9"
rustc_version = "0.2.3"

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/wasmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void wasmer_module_destroy(wasmer_module_t *module);

/**
* Given:
* A prepared `wasmer svm` import-object
* A prepared `wasmer` import-object
* A compiled wasmer module
* Instantiates a wasmer instance
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/wasmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ wasmer_result_t wasmer_module_deserialize(wasmer_module_t **module,
void wasmer_module_destroy(wasmer_module_t *module);

/// Given:
/// A prepared `wasmer svm` import-object
/// A prepared `wasmer` import-object
/// A compiled wasmer module
/// Instantiates a wasmer instance
wasmer_result_t wasmer_module_import_instantiate(wasmer_instance_t **instance,
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ version = "0.11.1"
[dependencies.serde-bench]
version = "0.0.7"
[dependencies.blake2b_simd]
version = "0.5.5"
version = "0.5.6"
[dependencies.digest]
version = "0.8.1"

Expand All @@ -47,7 +47,7 @@ winapi = { version = "0.3.7", features = ["memoryapi"] }
field-offset = "0.1.1"

[build-dependencies]
blake2b_simd = "0.5.5"
blake2b_simd = "0.5.6"
rustc_version = "0.2.3"
cc = "1.0"

Expand Down
33 changes: 25 additions & 8 deletions lib/runtime-core/src/backing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,23 @@ pub struct LocalBacking {
}

impl LocalBacking {
pub(crate) fn new(module: &ModuleInner, imports: &ImportBacking, vmctx: *mut vm::Ctx) -> Self {
pub(crate) fn new(
module: &ModuleInner,
imports: &ImportBacking,
vmctx: *mut vm::Ctx,
) -> LinkResult<Self> {
let mut memories = Self::generate_memories(module);
let mut tables = Self::generate_tables(module);
let mut globals = Self::generate_globals(module, imports);

let vm_memories = Self::finalize_memories(module, imports, &mut memories);
let vm_memories = Self::finalize_memories(module, imports, &mut memories)?;
let vm_tables = Self::finalize_tables(module, imports, &mut tables, vmctx);
let vm_globals = Self::finalize_globals(&mut globals);

let dynamic_sigindices = Self::generate_sigindices(&module.info);
let local_functions = Self::generate_local_functions(module);

Self {
Ok(Self {
memories,
tables,
globals,
Expand All @@ -80,7 +84,7 @@ impl LocalBacking {
local_functions,

internals: Internals([0; INTERNALS_SIZE]),
}
})
}

fn generate_local_functions(module: &ModuleInner) -> BoxedMap<LocalFuncIndex, *const vm::Func> {
Expand Down Expand Up @@ -124,7 +128,7 @@ impl LocalBacking {
module: &ModuleInner,
imports: &ImportBacking,
memories: &mut SliceMap<LocalMemoryIndex, Memory>,
) -> BoxedMap<LocalMemoryIndex, *mut vm::LocalMemory> {
) -> LinkResult<BoxedMap<LocalMemoryIndex, *mut vm::LocalMemory>> {
// For each init that has some data...
for init in module
.info
Expand All @@ -148,7 +152,12 @@ impl LocalBacking {
LocalOrImport::Local(local_memory_index) => {
let memory_desc = module.info.memories[local_memory_index];
let data_top = init_base + init.data.len();
assert!(memory_desc.minimum.bytes().0 >= data_top);

if memory_desc.minimum.bytes().0 < data_top || data_top < init_base {
return Err(vec![LinkError::Generic {
message: "data segment does not fit".to_string(),
}]);
}

let mem = &memories[local_memory_index];
for (mem_byte, data_byte) in mem.view()[init_base..init_base + init.data.len()]
Expand All @@ -163,6 +172,14 @@ impl LocalBacking {
// we think the imported memory is.
unsafe {
let local_memory = &*imports.vm_memories[imported_memory_index];

let data_top = init_base + init.data.len();
if local_memory.bound < data_top || data_top < init_base {
return Err(vec![LinkError::Generic {
message: "data segment does not fit".to_string(),
}]);
}

let memory_slice =
slice::from_raw_parts_mut(local_memory.base, local_memory.bound);

Expand All @@ -174,11 +191,11 @@ impl LocalBacking {
}
}

memories
Ok(memories
.iter_mut()
.map(|(_, mem)| mem.vm_local_memory())
.collect::<Map<_, _>>()
.into_boxed_map()
.into_boxed_map())
}

fn generate_tables(module: &ModuleInner) -> BoxedMap<LocalTableIndex, Table> {
Expand Down
6 changes: 6 additions & 0 deletions lib/runtime-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub enum LinkError {
expected: GlobalDescriptor,
found: GlobalDescriptor,
},
Generic {
message: String,
},
}

impl PartialEq for LinkError {
Expand Down Expand Up @@ -107,6 +110,9 @@ impl std::fmt::Display for LinkError {
LinkError::IncorrectTableDescriptor{namespace, name,expected,found} => {
write!(f, "Incorrect table descriptor, namespace: {}, name: {}, expected table descriptor: {:?}, found table descriptor: {:?}", namespace, name, expected, found)
},
LinkError::Generic { message } => {
write!(f, "{}", message)
},
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Instance {
Box::new(mem::MaybeUninit::<vm::Ctx>::zeroed());

let import_backing = ImportBacking::new(&module, &imports, vmctx.as_mut_ptr())?;
let backing = LocalBacking::new(&module, &import_backing, vmctx.as_mut_ptr());
let backing = LocalBacking::new(&module, &import_backing, vmctx.as_mut_ptr())?;

let mut inner = Box::pin(InstanceInner {
backing,
Expand Down
4 changes: 4 additions & 0 deletions lib/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ default-backend-cranelift = ["cranelift"]
[[bench]]
name = "nginx"
harness = false

[[bench]]
name = "many_instances"
harness = false
84 changes: 84 additions & 0 deletions lib/runtime/benches/many_instances.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#[macro_use]
extern crate criterion;
use criterion::Criterion;
use tempfile::tempdir;
use wasmer_runtime::{
cache::{Cache, FileSystemCache, WasmHash},
compile, func, imports, instantiate, validate, ImportObject,
};
use wasmer_runtime_core::vm::Ctx;

fn it_works(_ctx: &mut Ctx) -> i32 {
5
}

static SIMPLE_WASM: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../examples/no_abi_simple_plugin.wasm"
));

fn hashing_benchmark(c: &mut Criterion) {
c.bench_function("HASH", |b| b.iter(|| WasmHash::generate(SIMPLE_WASM)));
}

fn validate_benchmark(c: &mut Criterion) {
c.bench_function("validate", |b| b.iter(|| validate(SIMPLE_WASM)));
}

fn compile_benchmark(c: &mut Criterion) {
c.bench_function("compile", |b| b.iter(|| compile(SIMPLE_WASM)));
}

fn create_instance_benchmark(c: &mut Criterion) {
let imports = imports!(
"env" => {
"it_works" => func!(it_works),
},
);
c.bench_function("instantiate", move |b| {
b.iter(|| instantiate(&SIMPLE_WASM[..], &imports).unwrap())
});
}

fn create_instance_from_cache_benchmark(c: &mut Criterion) {
let imports = imports!(
"env" => {
"it_works" => func!(it_works),
},
);
let tempdir = tempdir().unwrap();
let mut cache = unsafe {
FileSystemCache::new(tempdir.path()).expect("unable to create file system cache")
};
let module = compile(SIMPLE_WASM).unwrap();
let hash = WasmHash::generate(SIMPLE_WASM);
cache
.store(hash, module)
.expect("unable to store into cache");
c.bench_function("instantiate from cache", move |b| {
b.iter(|| {
let module = cache.load(hash).unwrap();
module.instantiate(&imports).unwrap();
})
});
}

fn calling_fn_benchmark(c: &mut Criterion) {
let imports = imports!(
"env" => {
"it_works" => func!(it_works),
},
);
let instance = instantiate(SIMPLE_WASM, &imports).unwrap();
c.bench_function("calling fn", move |b| {
let entry_point = instance.func::<(i32), i32>("plugin_entrypoint").unwrap();
b.iter(|| entry_point.call(2).unwrap())
});
}

criterion_group! {
name = instance_bench;
config = Criterion::default().sample_size(20);
targets = compile_benchmark, validate_benchmark, hashing_benchmark, create_instance_from_cache_benchmark, calling_fn_benchmark, create_instance_benchmark,
}
criterion_main!(instance_bench);
2 changes: 1 addition & 1 deletion lib/win-exception-handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ libc = "0.2.60"
[build-dependencies]
cmake = "0.1.40"
bindgen = "0.51.0"
regex = "1.2.0"
regex = "1.2.1"
6 changes: 6 additions & 0 deletions src/installer/wasmer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ WizardSmallImageFile=media\wizard_logo_small.bmp
SetupIconFile=media\wizard_logo.ico
DisableWelcomePage=no

[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName: "WASMER_DIR"; \
ValueData: "{%USERPROFILE}\.wasmer"; Flags: preservestringtype
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName: "WASMER_CACHE_DIR"; \
ValueData: "{%USERPROFILE}\.wasmer\cache"; Flags: preservestringtype

[Files]
Source: "..\..\target\release\wasmer.exe"; DestDir: "{app}\bin"
Source: "..\..\wapm-cli\target\release\wapm.exe"; DestDir: "{app}\bin"
Expand Down

0 comments on commit b8f8a63

Please sign in to comment.