}
#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 <sys/types.h>
+#include <sys/sysctl.h>
+
+#include <machine/armreg.h>
+#include <machine/cpu.h>
+
+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
{
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;