Skip to content

Commit 8e1b683

Browse files
committed
Fix: Check for WFET support on macOS
1 parent 35f696c commit 8e1b683

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

include/fork_union.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,13 +1532,21 @@ inline capabilities_t cpu_capabilities() noexcept {
15321532
// Basic YIELD is always available on AArch64
15331533
caps = static_cast<capabilities_t>(caps | capability_arm64_yield_k);
15341534

1535-
// Check for WFET support via ID_AA64ISAR2_EL1 register
1536-
std::uint64_t id_aa64isar2_el0;
1535+
// Use sysctl to check for WFET support on Apple platforms
1536+
#if defined(__APPLE__)
1537+
int wfet_support = 0;
1538+
size_t size = sizeof(wfet_support);
1539+
if (sysctlbyname("hw.optional.arm.FEAT_WFxT", &wfet_support, &size, NULL, 0) == 0 && wfet_support)
1540+
caps = static_cast<capabilities_t>(caps | capability_arm64_wfet_k);
1541+
#else
1542+
// On non-Apple ARM systems, try to read the system register
1543+
// Note: This may fail on some systems where userspace access is restricted
1544+
std::uint64_t id_aa64isar2_el0 = 0;
15371545
__asm__ __volatile__("mrs %0, ID_AA64ISAR2_EL0" : "=r"(id_aa64isar2_el0) : : "memory");
1538-
15391546
// WFET is bits [3:0], value 2 indicates WFET support
15401547
std::uint64_t const wfet_field = id_aa64isar2_el0 & 0xF;
15411548
if (wfet_field >= 2) caps = static_cast<capabilities_t>(caps | capability_arm64_wfet_k);
1549+
#endif
15421550

15431551
#elif _FU_DETECT_ARCH_RISC5
15441552

0 commit comments

Comments
 (0)