Skip to content

Commit

Permalink
Try #2491:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jul 25, 2021
2 parents 51fdf66 + 1855700 commit e58385a
Show file tree
Hide file tree
Showing 34 changed files with 29,015 additions and 1,074 deletions.
64 changes: 61 additions & 3 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ members = [
"lib/engine-dylib",
"lib/engine-staticlib",
"lib/object",
"lib/vfs",
"lib/vm",
"lib/wasi",
"lib/wasi-types",
Expand All @@ -54,6 +55,7 @@ members = [
"tests/integration/cli",
"fuzz",
]
resolver = "2"

[build-dependencies]
test-generator = { path = "tests/lib/test-generator" }
Expand Down Expand Up @@ -280,4 +282,4 @@ required-features = ["cranelift"]
[[example]]
name = "features"
path = "examples/features.rs"
required-features = ["cranelift"]
required-features = ["cranelift"]
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ endif
all: build-wasmer build-capi

build-wasmer:
cargo build --release --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer
cargo build --release --manifest-path lib/cli/Cargo.toml --features "debug" $(compiler_features) --bin wasmer

build-wasmer-debug:
cargo build --manifest-path lib/cli/Cargo.toml $(compiler_features) --bin wasmer
Expand Down Expand Up @@ -500,9 +500,13 @@ test-packages:
cargo test --manifest-path lib/compiler-singlepass/Cargo.toml --release --no-default-features --features=std
cargo test --manifest-path lib/cli/Cargo.toml $(compiler_features) --release

test-js:
test-js: test-js-api test-js-wasi

test-js-api:
cd lib/api && wasm-pack test --node -- --no-default-features --features js-default,wat

test-js-wasi:
cd lib/wasi && wasm-pack test --node -- --no-default-features --features=test-js

#####
#
Expand Down
19 changes: 14 additions & 5 deletions lib/api/src/js/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ impl<T: Copy, Ty> WasmPtr<T, Ty> {
}
}

#[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)
}

/// Methods for `WasmPtr`s to data that can be dereferenced, namely to types
/// that implement [`ValueType`], meaning that they're valid for all possible
/// bit patterns.
Expand All @@ -102,7 +109,8 @@ impl<T: Copy + ValueType> WasmPtr<T, Item> {
if total_len > memory.size().bytes().0 || mem::size_of::<T>() == 0 {
return None;
}
let subarray = memory.uint8view().subarray(self.offset, total_len as u32);
let offset = align_pointer(self.offset as usize, mem::align_of::<T>()) as u32;
let subarray = memory.uint8view().subarray(offset, total_len as u32);
Some(WasmCell::new(subarray))
}
}
Expand Down Expand Up @@ -132,13 +140,14 @@ impl<T: Copy + ValueType> WasmPtr<T, Array> {
return None;
}

let offset = align_pointer(self.offset as usize, mem::align_of::<T>()) as u32;

Some(
(0..length)
.map(|i| {
let subarray = memory.uint8view().subarray(
self.offset + i * item_size,
self.offset + (i + 1) * item_size,
);
let subarray = memory
.uint8view()
.subarray(offset + i * item_size, offset + (i + 1) * item_size);
WasmCell::new(subarray)
})
.collect::<Vec<_>>(),
Expand Down
5 changes: 5 additions & 0 deletions lib/api/src/sys/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ impl Memory {
unsafe { MemoryView::new(base as _, length as u32) }
}

/// A uint8view
pub fn uint8view(&self) -> MemoryView<u8> {
self.view()
}

pub(crate) fn from_vm_export(store: &Store, vm_memory: VMMemory) -> Self {
Self {
store: store.clone(),
Expand Down
2 changes: 1 addition & 1 deletion lib/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wasmer-engine-universal = { version = "2.0.0", path = "../engine-universal", opt
wasmer-engine-dylib = { version = "2.0.0", path = "../engine-dylib", optional = true }
wasmer-engine-staticlib = { version = "2.0.0", path = "../engine-staticlib", optional = true }
wasmer-middlewares = { version = "2.0.0", path = "../middlewares", optional = true }
wasmer-wasi = { version = "2.0.0", path = "../wasi", optional = true }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features = false, features = ["host_fs"], optional = true }
wasmer-types = { version = "2.0.0", path = "../types" }
enumset = "1.0"
cfg-if = "1.0"
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ wasmer-engine-universal = { version = "2.0.0", path = "../engine-universal", opt
wasmer-engine-dylib = { version = "2.0.0", path = "../engine-dylib", optional = true }
wasmer-engine-staticlib = { version = "2.0.0", path = "../engine-staticlib", optional = true }
wasmer-vm = { version = "2.0.0", path = "../vm" }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features = false, optional = true }
wasmer-wasi = { version = "2.0.0", path = "../wasi", default-features = false, features = ["host_fs"], optional = true }
wasmer-wasi-experimental-io-devices = { version = "2.0.0", path = "../wasi-experimental-io-devices", optional = true }
wasmer-wast = { version = "2.0.0", path = "../../tests/lib/wast", optional = true }
wasmer-cache = { version = "2.0.0", path = "../cache", optional = true }
wasmer-types = { version = "2.0.0", path = "../types" }
wasmer-vfs = { version = "2.0.0", path = "../vfs" }
atty = "0.2"
colored = "2.0"
anyhow = "1.0"
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub struct Run {
#[structopt(long = "debug", short = "d")]
debug: bool,

#[structopt(short, long, parse(from_occurrences))]
verbose: u8,

/// Application arguments
#[structopt(name = "--", multiple = true)]
args: Vec<String>,
Expand All @@ -74,7 +77,7 @@ impl Run {
pub fn execute(&self) -> Result<()> {
#[cfg(feature = "debug")]
if self.debug {
logging::set_up_logging().unwrap();
logging::set_up_logging(self.verbose).unwrap();
}
self.inner_execute().with_context(|| {
format!(
Expand Down
12 changes: 10 additions & 2 deletions lib/cli/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
//! Logging functions for the debug feature.
use crate::utils::wasmer_should_print_color;
use anyhow::Result;
use fern::colors::{Color, ColoredLevelConfig};
use std::time;

/// The debug level
pub type DebugLevel = log::LevelFilter;

/// Subroutine to instantiate the loggers
pub fn set_up_logging() -> Result<(), String> {
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
let colors_line = ColoredLevelConfig::new()
.error(Color::Red)
.warn(Color::Yellow)
.trace(Color::BrightBlack);
let should_color = wasmer_should_print_color();

let colors_level = colors_line.info(Color::Green);
let level = match verbose {
1 => DebugLevel::Debug,
2 | _ => DebugLevel::Trace,
};
let dispatch = fern::Dispatch::new()
.level(log::LevelFilter::Debug)
.level(level)
.chain({
let base = if should_color {
fern::Dispatch::new().format(move |out, message, record| {
Expand Down
2 changes: 1 addition & 1 deletion lib/engine/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub trait Artifact: Send + Sync + Upcastable + MemoryUsage {
}

// Implementation of `Upcastable` taken from https://users.rust-lang.org/t/why-does-downcasting-not-work-for-subtraits/33286/7 .
/// Trait needed to get downcasting from `WasiFile` to work.
/// Trait needed to get downcasting of `Engine`s to work.
pub trait Upcastable {
fn upcast_any_ref(&'_ self) -> &'_ dyn Any;
fn upcast_any_mut(&'_ mut self) -> &'_ mut dyn Any;
Expand Down
33 changes: 17 additions & 16 deletions lib/types/src/memory_view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::lib::std::cell::Cell;
use crate::lib::std::marker::PhantomData;
use crate::lib::std::ops::Deref;
use crate::lib::std::ops::{Bound, RangeBounds};
// use crate::lib::std::ops::{Bound, RangeBounds};
use crate::lib::std::slice;
use crate::lib::std::sync::atomic::{
AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicU16, AtomicU32, AtomicU64, AtomicU8,
Expand Down Expand Up @@ -69,28 +69,29 @@ where
}

/// Creates a subarray view from this MemoryView.
pub fn subarray(&self, range: impl RangeBounds<usize>) -> Self {
let start: usize = match range.start_bound() {
Bound::Unbounded => 0,
Bound::Included(start) => *start,
Bound::Excluded(start) => *start + 1,
};
let end: usize = match range.end_bound() {
Bound::Unbounded => self.length,
Bound::Included(end) => *end,
Bound::Excluded(end) => *end - 1,
};
// pub fn subarray(&self, range: impl RangeBounds<usize>) -> Self {
// let start: usize = match range.start_bound() {
// Bound::Unbounded => 0,
// Bound::Included(start) => *start,
// Bound::Excluded(start) => *start + 1,
// };
// let end: usize = match range.end_bound() {
// Bound::Unbounded => self.length,
// Bound::Included(end) => *end,
// Bound::Excluded(end) => *end - 1,
// };
pub fn subarray(&self, start: u32, end: u32) -> Self {
assert!(
start < self.length,
(start as usize) < self.length,
"The range start is bigger than current length"
);
assert!(
end < self.length,
(end as usize) < self.length,
"The range end is bigger than current length"
);
Self {
ptr: unsafe { self.ptr.add(start) },
length: (end - start),
ptr: unsafe { self.ptr.add(start as usize) },
length: (end - start) as usize,
_phantom: PhantomData,
}
}
Expand Down
22 changes: 22 additions & 0 deletions lib/vfs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "wasmer-vfs"
version = "2.0.0"
description = "Wasmer Virtual FileSystem"
authors = ["Wasmer Engineering Team <[email protected]>"]
license = "MIT"
edition = "2018"

[dependencies]
libc = { version = "^0.2", default-features = false, optional = true }
thiserror = "1"
tracing = { version = "0.1" }
typetag = { version = "0.1", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }

[features]
host_fs = ["libc"]
mem_fs = []
enable-serde = [
"serde",
"typetag"
]
Loading

0 comments on commit e58385a

Please sign in to comment.