From: kettenis Date: Tue, 30 Jul 2024 09:07:00 +0000 (+0000) Subject: On arm64, check whether the CPU has the BT feature to determine the expected X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0ecb11e11f01aec558a75bd6fa0ddb4f77836c1a;p=openbsd On arm64, check whether the CPU has the BT feature to determine the expected outcome of the test. --- diff --git a/regress/sys/btcfi/foobar.c b/regress/sys/btcfi/foobar.c index 8ed60c1d876..5efbfec6f24 100644 --- a/regress/sys/btcfi/foobar.c +++ b/regress/sys/btcfi/foobar.c @@ -22,14 +22,43 @@ handler(int sig, siginfo_t *si, void *context) } #if defined(__amd64__) + static int -has_cet_ibt(void) +has_btcfi(void) { uint32_t d; asm("cpuid" : "=d" (d) : "a" (7), "c" (0)); return (d & (1U << 20)) ? 1 : 0; } + +#elif defined(__aarch64__) + +#include +#include + +#include +#include + +static int +has_btcfi(void) +{ + int mib[] = { CTL_MACHDEP, CPU_ID_AA64PFR1 }; + uint64_t id_aa64pfr1 = 0; + size_t size = sizeof(id_aa64pfr1); + + sysctl(mib, 2, &id_aa64pfr1, &size, NULL, 0); + return ID_AA64PFR1_BT(id_aa64pfr1) >= ID_AA64PFR1_BT_IMPL; +} + +#else + +static int +has_btcfi(void) +{ + return 0; +} + #endif int @@ -37,13 +66,11 @@ main(void) { struct sigaction sa; -#if defined(__amd64__) - if (!has_cet_ibt()) { + if (!has_btcfi()) { printf("Unsupported CPU\n"); printf("SKIPPED\n"); exit(0); } -#endif sa.sa_sigaction = handler; sa.sa_mask = 0;