luaur_code_gen/functions/visit_fde_entries.rs
1#[allow(non_snake_case)]
2pub unsafe fn visit_fde_entries(
3 pos: *mut core::ffi::c_char,
4 cb: unsafe extern "C" fn(*const core::ffi::c_void),
5) {
6 // C++ Luau uses a *weak* `__unw_add_dynamic_fde` symbol to detect Apple's
7 // libunwind: when it is present (Apple) each FDE entry is registered
8 // individually; when it is absent (Linux/other, which register the whole
9 // block once via `__register_frame`) the block is passed to `cb` directly.
10 // A weak extern static is a *strong* undefined reference in Rust and fails to
11 // link on Linux ("undefined symbol: __unw_add_dynamic_fde"), so detect the
12 // platform at compile time — which is exactly what the weak-symbol presence
13 // check amounted to.
14 #[cfg(not(target_vendor = "apple"))]
15 {
16 cb(pos as *const core::ffi::c_void);
17 }
18 #[cfg(target_vendor = "apple")]
19 {
20 let mut current_pos = pos;
21 loop {
22 let mut part_length: u32 = 0;
23 core::ptr::copy_nonoverlapping(
24 current_pos as *const u8,
25 &mut part_length as *mut u32 as *mut u8,
26 core::mem::size_of::<u32>(),
27 );
28
29 if part_length == 0 {
30 break;
31 }
32
33 let mut part_id: u32 = 0;
34 core::ptr::copy_nonoverlapping(
35 current_pos.add(4) as *const u8,
36 &mut part_id as *mut u32 as *mut u8,
37 core::mem::size_of::<u32>(),
38 );
39
40 if part_id != 0 {
41 cb(current_pos as *const core::ffi::c_void);
42 }
43
44 current_pos = current_pos.add(part_length as usize + 4);
45 }
46 }
47}