luaur-code-gen 0.1.3

Native (A64/X64) code generation for Luau (Rust).
Documentation
use crate::records::unw_dynamic_unwind_sections_t::unw_dynamic_unwind_sections_t;

pub fn find_dynamic_unwind_sections(addr: usize, info: &mut unw_dynamic_unwind_sections_t) -> i32 {
    // Define a minimal mach header for JIT'd code.
    // The original C++ uses a 64-bit Mach-O header; this Rust translation mirrors only the values that are written to the unwind callback.
    // The constants are set to match the C++: MH_MAGIC_64, CPU_TYPE_ARM64, CPU_SUBTYPE_ARM64_ALL, MH_DYLIB.
    //
    // NOTE: This is architecture-specific native code; wasm builds should not rely on it.

    #[repr(C)]
    struct mach_header_64 {
        magic: u32,
        cputype: i32,
        cpusubtype: i32,
        filetype: u32,
    }

    const MH_MAGIC_64: u32 = 0xfeedfacf;
    const CPU_TYPE_ARM64: i32 = 0x0100000c;
    const CPU_SUBTYPE_ARM64_ALL: i32 = 0x00000000;
    const MH_DYLIB: u32 = 0x6;

    static K_FAKE_MACH_HEADER: mach_header_64 = mach_header_64 {
        magic: MH_MAGIC_64,
        cputype: CPU_TYPE_ARM64,
        cpusubtype: CPU_SUBTYPE_ARM64_ALL,
        filetype: MH_DYLIB,
    };

    info.dso_base = &K_FAKE_MACH_HEADER as *const _ as usize;
    info.dwarf_section = 0;
    info.dwarf_section_length = 0;
    info.compact_unwind_section = 0;
    info.compact_unwind_section_length = 0;
    let _ = addr;

    1
}