Skip to main content

luaur_code_gen/functions/
is_unwind_supported.rs

1use crate::macros::codegen_target_a_64::CODEGEN_TARGET_A64;
2use crate::macros::codegen_target_x_64::CODEGEN_TARGET_X64;
3
4pub fn is_unwind_supported() -> bool {
5    #[cfg(all(
6        target_os = "windows",
7        any(target_arch = "x86_64", target_arch = "x86")
8    ))]
9    {
10        true
11    }
12
13    #[cfg(all(
14        target_os = "macos",
15        target_arch = "aarch64",
16        not(target_os = "windows")
17    ))]
18    {
19        // libunwind on macOS 12 and earlier (which maps to osrelease 21) assumes JIT
20        // frames use pointer authentication without a way to override that.
21        // Check kern.osrelease >= 22.
22        use std::process::Command;
23
24        let output = Command::new("sysctl")
25            .arg("-n")
26            .arg("kern.osrelease")
27            .output();
28
29        match output {
30            Ok(out) if out.status.success() => {
31                let ver = String::from_utf8_lossy(&out.stdout);
32                let ver = ver.trim();
33                matches!(ver.parse::<u32>(), Ok(n) if n >= 22)
34            }
35            _ => false,
36        }
37    }
38
39    #[cfg(all(
40        any(target_os = "linux", target_os = "macos"),
41        any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"),
42        not(target_os = "windows"),
43        not(all(target_os = "macos", target_arch = "aarch64"))
44    ))]
45    {
46        true
47    }
48
49    #[cfg(not(any(
50        all(
51            target_os = "windows",
52            any(target_arch = "x86_64", target_arch = "x86")
53        ),
54        all(target_os = "macos", target_arch = "aarch64"),
55        all(
56            any(target_os = "linux", target_os = "macos"),
57            any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"),
58            not(all(target_os = "macos", target_arch = "aarch64"))
59        )
60    )))]
61    {
62        false
63    }
64}