Skip to main content

luaur_code_gen/functions/
destroy_block_unwind_info.rs

1use crate::functions::visit_fde_entries::visit_fde_entries;
2use crate::macros::codegen_assert::CODEGEN_ASSERT;
3use crate::macros::codegen_target_a_64::CODEGEN_TARGET_A64;
4use crate::macros::codegen_target_x_64::CODEGEN_TARGET_X64;
5
6#[cfg(target_os = "windows")]
7extern "system" {
8    fn RtlDeleteFunctionTable(function_table: *mut core::ffi::c_void) -> i32;
9}
10
11#[cfg(any(target_os = "linux", target_os = "macos"))]
12extern "C" {
13    fn __deregister_frame(begin: *const core::ffi::c_void);
14}
15
16pub unsafe extern "C" fn destroy_block_unwind_info(
17    context: *mut core::ffi::c_void,
18    unwind_data: *mut core::ffi::c_void,
19) {
20    #[cfg(target_os = "windows")]
21    {
22        if CODEGEN_TARGET_X64 {
23            let result = unsafe { RtlDeleteFunctionTable(unwind_data) };
24            if result == 0 {
25                CODEGEN_ASSERT!(false);
26            }
27        }
28    }
29
30    #[cfg(any(target_os = "linux", target_os = "macos"))]
31    {
32        if CODEGEN_TARGET_X64 || CODEGEN_TARGET_A64 {
33            unsafe {
34                visit_fde_entries(unwind_data as *mut core::ffi::c_char, __deregister_frame);
35            }
36        }
37    }
38}