From 0ecb11e11f01aec558a75bd6fa0ddb4f77836c1a Mon Sep 17 00:00:00 2001 From: kettenis Date: Tue, 30 Jul 2024 09:07:00 +0000 Subject: [PATCH] On arm64, check whether the CPU has the BT feature to determine the expected outcome of the test. --- regress/sys/btcfi/foobar.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) 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; -- 2.20.1