Truly independent web browser
LibJS: Register the unwind info of JIT code on Windows
Aliaksandr Kalenik917838aa598d
diff --git a/Libraries/LibJS/Rust/src/jit/executable_memory.rs b/Libraries/LibJS/Rust/src/jit/executable_memory.rsindex a47bf12eee2..02a5e30c77f 100644--- a/Libraries/LibJS/Rust/src/jit/executable_memory.rs+++ b/Libraries/LibJS/Rust/src/jit/executable_memory.rs@@ -133,6 +133,16 @@ impl Chunk {{let chunk = windows_code_memory::reserve(size);assert!(!chunk.is_null(), "reserving JIT code memory failed");+ // NB: The range starts at the chunk's first code, whose prologue the unwind info then describes (see+ // `JitState::entry_trampoline()`).+ let unwind_range = windows_code_memory::CodeRange {+ start: CHUNK_HEADER_SIZE as u32,+ end: u32::try_from(size).expect("a chunk of JIT code is smaller than 4 GiB"),+ frame_layout: windows_code_memory::FrameLayout::RbpAtSavedRbp,+ };+ // SAFETY: The chunk was just reserved, so it has no unwind info yet and no code runs in it.+ let added = unsafe { windows_code_memory::add_unwind_info(chunk, &[unwind_range]) };+ assert!(added, "registering the unwind info of JIT code failed");Self {start: chunk,size,@@ -194,6 +204,7 @@ impl Drop for Chunk {// SAFETY: As above.#[cfg(windows)]unsafe {+ windows_code_memory::delete_unwind_info(self.start);windows_code_memory::release(self.start);}}diff --git a/Libraries/LibJS/Rust/src/jit/mod.rs b/Libraries/LibJS/Rust/src/jit/mod.rsindex c82ebf18812..af396957698 100644--- a/Libraries/LibJS/Rust/src/jit/mod.rs+++ b/Libraries/LibJS/Rust/src/jit/mod.rs@@ -416,8 +416,15 @@ impl JitState {.get_or_init(|| {let code = libjs_jit::codegen::generate_entry_trampoline::<libjs_jit::asm::MacroAssembler>().expect("the entry trampoline can be generated");+ // NB: On Windows, the trampoline goes first in a chunk of its own, whose unwind info then describes+ // its prologue: native code calls it, and keeps no frame pointer that a stack walk from the+ // prologue could take for the trampoline's.+ #[cfg(windows)]+ let allocator = Rc::new(RefCell::new(CodeAllocator::default()));+ #[cfg(not(windows))]+ let allocator = Rc::clone(&self.code_allocator);let memory = ExecutableMemory::allocate(- &self.code_allocator,+ &allocator,&[code.as_slice()],&["entry trampoline"],self.options.perf_map,