Skip to main content

luaur_code_gen/functions/
find_dynamic_unwind_sections.rs

1use crate::records::unw_dynamic_unwind_sections_t::unw_dynamic_unwind_sections_t;
2
3pub fn find_dynamic_unwind_sections(addr: usize, info: &mut unw_dynamic_unwind_sections_t) -> i32 {
4    // Define a minimal mach header for JIT'd code.
5    // The original C++ uses a 64-bit Mach-O header; this Rust translation mirrors only the values that are written to the unwind callback.
6    // The constants are set to match the C++: MH_MAGIC_64, CPU_TYPE_ARM64, CPU_SUBTYPE_ARM64_ALL, MH_DYLIB.
7    //
8    // NOTE: This is architecture-specific native code; wasm builds should not rely on it.
9
10    #[repr(C)]
11    struct mach_header_64 {
12        magic: u32,
13        cputype: i32,
14        cpusubtype: i32,
15        filetype: u32,
16    }
17
18    const MH_MAGIC_64: u32 = 0xfeedfacf;
19    const CPU_TYPE_ARM64: i32 = 0x0100000c;
20    const CPU_SUBTYPE_ARM64_ALL: i32 = 0x00000000;
21    const MH_DYLIB: u32 = 0x6;
22
23    static K_FAKE_MACH_HEADER: mach_header_64 = mach_header_64 {
24        magic: MH_MAGIC_64,
25        cputype: CPU_TYPE_ARM64,
26        cpusubtype: CPU_SUBTYPE_ARM64_ALL,
27        filetype: MH_DYLIB,
28    };
29
30    info.dso_base = &K_FAKE_MACH_HEADER as *const _ as usize;
31    info.dwarf_section = 0;
32    info.dwarf_section_length = 0;
33    info.compact_unwind_section = 0;
34    info.compact_unwind_section_length = 0;
35    let _ = addr;
36
37    1
38}