Skip to content

Commit

Permalink
Updated vm code to trap handle
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed May 25, 2021
1 parent 24c5ad0 commit a1854f4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ deny = [
]
# Certain crates/versions that will be skipped when doing duplicate detection.
skip = [
{ name = "cfg-if", version = "=0.1.10" },
{ name = "strsim", version = "=0.8.0" },
{ name = "semver", version = "=0.9.0" },
{ name = "semver-parser", version = "=0.7.0" },
Expand Down
4 changes: 2 additions & 2 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ wasmer-engine = { path = "../engine", version = "1.0.2" }
wasmer-engine-jit = { path = "../engine-jit", version = "1.0.2", optional = true }
wasmer-engine-native = { path = "../engine-native", version = "1.0.2", optional = true }
wasmer-types = { path = "../types", version = "1.0.2" }
indexmap = { version = "1.4", features = ["serde-1"] }
cfg-if = "0.1"
indexmap = { version = "1.6", features = ["serde-1"] }
cfg-if = "1.0"
wat = { version = "1.0", optional = true }
thiserror = "1.0"
more-asserts = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion lib/engine-jit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ wasmer-vm = { path = "../vm", version = "1.0.2", features = ["enable-rkyv"] }
wasmer-engine = { path = "../engine", version = "1.0.2" }
# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" }
region = "2.2"
cfg-if = "0.1"
cfg-if = "1.0"
leb128 = "0.2"
rkyv = "0.6.1"
loupe = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion lib/engine-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ wasmer-vm = { path = "../vm", version = "1.0.2", features = ["enable-rkyv"] }
wasmer-engine = { path = "../engine", version = "1.0.2" }
wasmer-object = { path = "../object", version = "1.0.2" }
serde = { version = "1.0", features = ["derive", "rc"] }
cfg-if = "0.1"
cfg-if = "1.0"
tracing = "0.1"
leb128 = "0.2"
libloading = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion lib/engine-object-file/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ wasmer-vm = { path = "../vm", version = "1.0.2" }
wasmer-engine = { path = "../engine", version = "1.0.2" }
wasmer-object = { path = "../object", version = "1.0.2" }
serde = { version = "1.0", features = ["derive", "rc"] }
cfg-if = "0.1"
cfg-if = "1.0"
tracing = "0.1"
bincode = "1.3"
leb128 = "0.2"
Expand Down
25 changes: 13 additions & 12 deletions lib/engine/src/trap/frame_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct GlobalFrameInfoRegistration {
key: usize,
}

#[derive(Debug)]
struct ModuleInfoFrameInfo {
start: usize,
functions: BTreeMap<usize, FunctionInfo>,
Expand All @@ -74,10 +75,11 @@ impl ModuleInfoFrameInfo {
/// Gets a function given a pc
fn function_info(&self, pc: usize) -> Option<&FunctionInfo> {
let (end, func) = self.functions.range(pc..).next()?;
if pc < func.start || *end < pc {
return None;
if func.start <= pc && pc < *end {
return Some(func);
} else {
None
}
Some(func)
}
}

Expand Down Expand Up @@ -127,14 +129,12 @@ impl GlobalFrameInfo {
}
};

// In debug mode for now assert that we found a mapping for `pc` within
// the function, because otherwise something is buggy along the way and
// not accounting for all the instructions. This isn't super critical
// though so we can omit this check in release mode.
debug_assert!(pos.is_some(), "failed to find instruction for {:x}", pc);

let instr = match pos {
Some(pos) => instr_map.instructions[pos].srcloc,
// Some compilers don't emit yet the full trap information for each of
// the instructions (such as LLVM).
// In case no specific instruction is found, we return by default the
// start offset of the function.
None => instr_map.start_srcloc,
};
let func_index = module.module.func_index(func.local_index);
Expand All @@ -161,10 +161,11 @@ impl GlobalFrameInfo {
/// Gets a module given a pc
fn module_info(&self, pc: usize) -> Option<&ModuleInfoFrameInfo> {
let (end, module_info) = self.ranges.range(pc..).next()?;
if pc < module_info.start || *end < pc {
return None;
if module_info.start <= pc && pc < *end {
Some(module_info)
} else {
None
}
Some(module_info)
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2018"
[dependencies]
serde = { version = "1.0", features = ["derive"], optional = true, default-features = false }
thiserror = "1.0"
indexmap = { version = "1.4", features = ["serde-1"] }
indexmap = { version = "1.6", features = ["serde-1"] }
rkyv = { version = "0.6.1", optional = true }
loupe = "0.1"

Expand Down
4 changes: 2 additions & 2 deletions lib/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ wasmer-types = { path = "../types", version = "1.0.2" }
region = "2.2"
libc = { version = "^0.2", default-features = false }
memoffset = "0.6"
indexmap = { version = "1.4", features = ["serde-1"] }
indexmap = { version = "1.6", features = ["serde-1"] }
thiserror = "1.0"
more-asserts = "0.2"
cfg-if = "0.1"
cfg-if = "1.0"
backtrace = "0.3"
serde = { version = "1.0", features = ["derive", "rc"] }
rkyv = { version = "0.6.1", optional = true}
Expand Down
5 changes: 5 additions & 0 deletions lib/vm/src/trap/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ impl<'a> CallThreadState<'a> {
return 1 as *const _;
}

// If this fault wasn't in wasm code, then it's not our problem
if unsafe { !IS_WASM_PC(pc as _) } {
return ptr::null();
}

// TODO: stack overflow can happen at any random time (i.e. in malloc()
// in memory.grow) and it's really hard to determine if the cause was
// stack overflow and if it happened in WebAssembly module.
Expand Down

0 comments on commit a1854f4

Please sign in to comment.