Remove trap registration from wasmtime crate (#903)
Our trampoline shims no longer have traps baked into them so this is largely all dead code now at this point.
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
//! Support for a calling of an imported function.
|
//! Support for a calling of an imported function.
|
||||||
|
|
||||||
use super::create_handle::create_handle;
|
use super::create_handle::create_handle;
|
||||||
use super::trap::TrapSink;
|
|
||||||
use crate::{Callable, FuncType, Store, Trap, Val};
|
use crate::{Callable, FuncType, Store, Trap, Val};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::panic::{self, AssertUnwindSafe};
|
use std::panic::{self, AssertUnwindSafe};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wasmtime_environ::entity::{EntityRef, PrimaryMap};
|
use wasmtime_environ::entity::{EntityRef, PrimaryMap};
|
||||||
@@ -14,7 +12,7 @@ use wasmtime_environ::ir::types;
|
|||||||
use wasmtime_environ::isa::TargetIsa;
|
use wasmtime_environ::isa::TargetIsa;
|
||||||
use wasmtime_environ::wasm::{DefinedFuncIndex, FuncIndex};
|
use wasmtime_environ::wasm::{DefinedFuncIndex, FuncIndex};
|
||||||
use wasmtime_environ::{
|
use wasmtime_environ::{
|
||||||
ir, settings, CompiledFunction, CompiledFunctionUnwindInfo, Export, Module, TrapInformation,
|
ir, settings, CompiledFunction, CompiledFunctionUnwindInfo, Export, Module,
|
||||||
};
|
};
|
||||||
use wasmtime_jit::trampoline::ir::{
|
use wasmtime_jit::trampoline::ir::{
|
||||||
ExternalName, Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind,
|
ExternalName, Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind,
|
||||||
@@ -23,46 +21,17 @@ use wasmtime_jit::trampoline::{
|
|||||||
binemit, pretty_error, Context, FunctionBuilder, FunctionBuilderContext,
|
binemit, pretty_error, Context, FunctionBuilder, FunctionBuilderContext,
|
||||||
};
|
};
|
||||||
use wasmtime_jit::{native, CodeMemory};
|
use wasmtime_jit::{native, CodeMemory};
|
||||||
use wasmtime_runtime::{
|
use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody};
|
||||||
get_mut_trap_registry, InstanceHandle, TrapRegistrationGuard, VMContext, VMFunctionBody,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TrampolineState {
|
struct TrampolineState {
|
||||||
func: Rc<dyn Callable + 'static>,
|
func: Rc<dyn Callable + 'static>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
code_memory: CodeMemory,
|
code_memory: CodeMemory,
|
||||||
trap_registration_guards: Vec<TrapRegistrationGuard>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TrampolineState {
|
impl TrampolineState {
|
||||||
fn new(
|
fn new(func: Rc<dyn Callable + 'static>, code_memory: CodeMemory) -> Self {
|
||||||
func: Rc<dyn Callable + 'static>,
|
TrampolineState { func, code_memory }
|
||||||
code_memory: CodeMemory,
|
|
||||||
func_addr: *const VMFunctionBody,
|
|
||||||
func_traps: &[TrapInformation],
|
|
||||||
) -> Self {
|
|
||||||
let mut trap_registry = get_mut_trap_registry();
|
|
||||||
let mut trap_registration_guards = Vec::new();
|
|
||||||
for trap_desc in func_traps.iter() {
|
|
||||||
let func_addr = func_addr as *const u8 as usize;
|
|
||||||
let offset = usize::try_from(trap_desc.code_offset).unwrap();
|
|
||||||
let trap_addr = func_addr + offset;
|
|
||||||
let guard =
|
|
||||||
trap_registry.register_trap(trap_addr, trap_desc.source_loc, trap_desc.trap_code);
|
|
||||||
trap_registration_guards.push(guard);
|
|
||||||
}
|
|
||||||
TrampolineState {
|
|
||||||
func,
|
|
||||||
code_memory,
|
|
||||||
trap_registration_guards,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for TrampolineState {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
// We must deregister traps before freeing the code memory.
|
|
||||||
self.trap_registration_guards.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +121,7 @@ fn make_trampoline(
|
|||||||
fn_builder_ctx: &mut FunctionBuilderContext,
|
fn_builder_ctx: &mut FunctionBuilderContext,
|
||||||
call_id: u32,
|
call_id: u32,
|
||||||
signature: &ir::Signature,
|
signature: &ir::Signature,
|
||||||
) -> (*const VMFunctionBody, Vec<TrapInformation>) {
|
) -> *const VMFunctionBody {
|
||||||
// Mostly reverse copy of the similar method from wasmtime's
|
// Mostly reverse copy of the similar method from wasmtime's
|
||||||
// wasmtime-jit/src/compiler.rs.
|
// wasmtime-jit/src/compiler.rs.
|
||||||
let pointer_type = isa.pointer_type();
|
let pointer_type = isa.pointer_type();
|
||||||
@@ -250,7 +219,7 @@ fn make_trampoline(
|
|||||||
|
|
||||||
let mut code_buf: Vec<u8> = Vec::new();
|
let mut code_buf: Vec<u8> = Vec::new();
|
||||||
let mut reloc_sink = binemit::TrampolineRelocSink {};
|
let mut reloc_sink = binemit::TrampolineRelocSink {};
|
||||||
let mut trap_sink = TrapSink::new();
|
let mut trap_sink = binemit::NullTrapSink {};
|
||||||
let mut stackmap_sink = binemit::NullStackmapSink {};
|
let mut stackmap_sink = binemit::NullStackmapSink {};
|
||||||
context
|
context
|
||||||
.compile_and_emit(
|
.compile_and_emit(
|
||||||
@@ -265,17 +234,14 @@ fn make_trampoline(
|
|||||||
|
|
||||||
let unwind_info = CompiledFunctionUnwindInfo::new(isa, &context);
|
let unwind_info = CompiledFunctionUnwindInfo::new(isa, &context);
|
||||||
|
|
||||||
let traps = trap_sink.traps;
|
code_memory
|
||||||
|
|
||||||
let addr = code_memory
|
|
||||||
.allocate_for_function(&CompiledFunction {
|
.allocate_for_function(&CompiledFunction {
|
||||||
body: code_buf,
|
body: code_buf,
|
||||||
jt_offsets: context.func.jt_offsets,
|
jt_offsets: context.func.jt_offsets,
|
||||||
unwind_info,
|
unwind_info,
|
||||||
})
|
})
|
||||||
.expect("allocate_for_function")
|
.expect("allocate_for_function")
|
||||||
.as_ptr();
|
.as_ptr()
|
||||||
(addr, traps)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_handle_with_function(
|
pub fn create_handle_with_function(
|
||||||
@@ -306,7 +272,7 @@ pub fn create_handle_with_function(
|
|||||||
module
|
module
|
||||||
.exports
|
.exports
|
||||||
.insert("trampoline".to_string(), Export::Function(func_id));
|
.insert("trampoline".to_string(), Export::Function(func_id));
|
||||||
let (trampoline, traps) = make_trampoline(
|
let trampoline = make_trampoline(
|
||||||
isa.as_ref(),
|
isa.as_ref(),
|
||||||
&mut code_memory,
|
&mut code_memory,
|
||||||
&mut fn_builder_ctx,
|
&mut fn_builder_ctx,
|
||||||
@@ -317,7 +283,7 @@ pub fn create_handle_with_function(
|
|||||||
|
|
||||||
finished_functions.push(trampoline);
|
finished_functions.push(trampoline);
|
||||||
|
|
||||||
let trampoline_state = TrampolineState::new(func.clone(), code_memory, trampoline, &traps);
|
let trampoline_state = TrampolineState::new(func.clone(), code_memory);
|
||||||
|
|
||||||
create_handle(
|
create_handle(
|
||||||
module,
|
module,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ mod func;
|
|||||||
mod global;
|
mod global;
|
||||||
mod memory;
|
mod memory;
|
||||||
mod table;
|
mod table;
|
||||||
mod trap;
|
|
||||||
|
|
||||||
use self::func::create_handle_with_function;
|
use self::func::create_handle_with_function;
|
||||||
use self::global::create_global;
|
use self::global::create_global;
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
use wasmtime_environ::ir::{SourceLoc, TrapCode};
|
|
||||||
use wasmtime_environ::TrapInformation;
|
|
||||||
use wasmtime_jit::trampoline::binemit;
|
|
||||||
|
|
||||||
pub(crate) struct TrapSink {
|
|
||||||
pub traps: Vec<TrapInformation>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TrapSink {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { traps: Vec::new() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl binemit::TrapSink for TrapSink {
|
|
||||||
fn trap(
|
|
||||||
&mut self,
|
|
||||||
code_offset: binemit::CodeOffset,
|
|
||||||
source_loc: SourceLoc,
|
|
||||||
trap_code: TrapCode,
|
|
||||||
) {
|
|
||||||
self.traps.push(TrapInformation {
|
|
||||||
code_offset,
|
|
||||||
source_loc,
|
|
||||||
trap_code,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@ pub use cranelift_codegen::Context;
|
|||||||
pub use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
|
pub use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
|
||||||
|
|
||||||
pub mod binemit {
|
pub mod binemit {
|
||||||
|
pub use cranelift_codegen::binemit::NullTrapSink;
|
||||||
pub use cranelift_codegen::binemit::{CodeOffset, NullStackmapSink, TrapSink};
|
pub use cranelift_codegen::binemit::{CodeOffset, NullStackmapSink, TrapSink};
|
||||||
|
|
||||||
use cranelift_codegen::{binemit, ir};
|
use cranelift_codegen::{binemit, ir};
|
||||||
|
|||||||
Reference in New Issue
Block a user