Skip to content

Commit

Permalink
Moved GlobalFrameInfo to codeMemory (fixes #3793)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Jun 26, 2023
1 parent 660645e commit cdfad46
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
41 changes: 34 additions & 7 deletions lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex
use wasmer_vm::{InstanceAllocator, StoreObjects, TrapHandlerFn, VMConfig, VMExtern, VMInstance};

pub struct AllocatedArtifact {
/// Some(_) only if this is not a deserialized static artifact
frame_info_registered: bool,
// frame_info_registered is not staying there but transfered to InnerEnginge / CodeMemory
frame_info_registration: Option<GlobalFrameInfoRegistration>,
finished_functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>,
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
Expand Down Expand Up @@ -304,16 +305,20 @@ impl Artifact {
id: Default::default(),
artifact,
allocated: Some(AllocatedArtifact {
frame_info_registered: false,
frame_info_registration: None,
finished_functions,
finished_function_call_trampolines,
finished_dynamic_function_trampolines,
signatures,
frame_info_registration: None,
finished_function_lengths,
}),
};

artifact.register_frame_info();
artifact.internal_register_frame_info();
if let Some(frame_info) = artifact.transfert_frame_info_registration() {
engine_inner.register_frame_info(frame_info);
}

Ok(artifact)
}
Expand Down Expand Up @@ -381,14 +386,18 @@ impl ArtifactCreate for Artifact {
impl Artifact {
/// Register thie `Artifact` stack frame information into the global scope.
///
/// This is required to ensure that any traps can be properly symbolicated.
/// This is not required anymore as it's done automaticaly when creating by 'Artifact::from_parts'
#[deprecated(since = "4.1.0", note = "done automaticaly by Artifact::from_parts")]
pub fn register_frame_info(&mut self) {
self.internal_register_frame_info()
}

fn internal_register_frame_info(&mut self) {
if self
.allocated
.as_ref()
.expect("It must be allocated")
.frame_info_registration
.is_some()
.frame_info_registered
{
return; // already done
}
Expand Down Expand Up @@ -425,6 +434,23 @@ impl Artifact {
&finished_function_extents,
frame_infos.clone(),
);

self.allocated
.as_mut()
.expect("It must be allocated")
.frame_info_registered = true;
}

/// The GlobalFrameInfoRegistration needs to be transfered to EngineInner if
/// deprecated register_frame_info has been used.
pub fn transfert_frame_info_registration(&mut self) -> Option<GlobalFrameInfoRegistration> {
let frame_info_registration = &mut self
.allocated
.as_mut()
.expect("It must be allocated")
.frame_info_registration;

frame_info_registration.take()
}

/// Returns the functions allocated in memory or this `Artifact`
Expand Down Expand Up @@ -895,14 +921,15 @@ impl Artifact {
id: Default::default(),
artifact,
allocated: Some(AllocatedArtifact {
frame_info_registered: false,
frame_info_registration: None,
finished_functions: finished_functions.into_boxed_slice(),
finished_function_call_trampolines: finished_function_call_trampolines
.into_boxed_slice(),
finished_dynamic_function_trampolines: finished_dynamic_function_trampolines
.into_boxed_slice(),
signatures: signatures.into_boxed_slice(),
finished_function_lengths,
frame_info_registration: None,
}),
})
}
Expand Down
9 changes: 9 additions & 0 deletions lib/compiler/src/engine/code_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//! Memory management for executable code.
use super::unwind::UnwindRegistry;
use crate::GlobalFrameInfoRegistration;
use wasmer_types::{CompiledFunctionUnwindInfo, CustomSection, FunctionBody};
use wasmer_vm::{Mmap, VMFunctionBody};

Expand All @@ -19,6 +20,8 @@ const DATA_SECTION_ALIGNMENT: usize = 64;

/// Memory manager for executable code.
pub struct CodeMemory {
// frame info is placed first, to ensure it's dropped before the mmap
frame_info_registration: Option<GlobalFrameInfoRegistration>,
unwind_registry: UnwindRegistry,
mmap: Mmap,
start_of_nonexecutable_pages: usize,
Expand All @@ -31,6 +34,7 @@ impl CodeMemory {
unwind_registry: UnwindRegistry::new(),
mmap: Mmap::new(),
start_of_nonexecutable_pages: 0,
frame_info_registration: None,
}
}

Expand Down Expand Up @@ -207,6 +211,11 @@ impl CodeMemory {
let body_ptr = byte_ptr as *mut [VMFunctionBody];
unsafe { &mut *body_ptr }
}

/// Register the frame info, so it's free when the mememory gets freed
pub fn register_frame_info(&mut self, frame_info: GlobalFrameInfoRegistration) {
self.frame_info_registration = Some(frame_info);
}
}

fn round_up(size: usize, multiple: usize) -> usize {
Expand Down
11 changes: 11 additions & 0 deletions lib/compiler/src/engine/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::Artifact;
use crate::BaseTunables;
#[cfg(not(target_arch = "wasm32"))]
use crate::CodeMemory;
#[cfg(not(target_arch = "wasm32"))]
use crate::GlobalFrameInfoRegistration;
#[cfg(feature = "compiler")]
use crate::{Compiler, CompilerConfig};
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -442,6 +444,15 @@ impl EngineInner {
pub fn signatures(&self) -> &SignatureRegistry {
&self.signatures
}

#[cfg(not(target_arch = "wasm32"))]
/// Register the frame info for the code memory
pub(crate) fn register_frame_info(&mut self, frame_info: GlobalFrameInfoRegistration) {
self.code_memory
.last_mut()
.unwrap()
.register_frame_info(frame_info);
}
}

#[cfg(feature = "compiler")]
Expand Down

0 comments on commit cdfad46

Please sign in to comment.