Start of a BTCFI test.
authorkettenis <kettenis@openbsd.org>
Fri, 23 Feb 2024 21:33:51 +0000 (21:33 +0000)
committerkettenis <kettenis@openbsd.org>
Fri, 23 Feb 2024 21:33:51 +0000 (21:33 +0000)
regress/sys/btcfi/Makefile [new file with mode: 0644]
regress/sys/btcfi/foo.c [new file with mode: 0644]
regress/sys/btcfi/foobar.c [new file with mode: 0644]

diff --git a/regress/sys/btcfi/Makefile b/regress/sys/btcfi/Makefile
new file mode 100644 (file)
index 0000000..b5cdcbf
--- /dev/null
@@ -0,0 +1,22 @@
+#      $OpenBSD: Makefile,v 1.1 2024/02/23 21:33:51 kettenis Exp $
+
+.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "aarch64"
+
+PROG= foobar
+OBJS= foo.o
+
+.if ${MACHINE_ARCH} == "aarch64"
+NOBTCFI_CFLAGS= -mbranch-protection=none
+.else
+NOBTCFI_CFLAGS= -fcf-protection=none
+.endif
+
+foo.o: foo.c
+       ${COMPILE.c} ${NOBTCFI_CFLAGS} ${.CURDIR}/foo.c -o foo.o
+
+.elif make(regress) || make(all)
+regress:
+       @echo Cannot run on ${MACHINE_ARCH}.
+       @echo SKIPPED
+.endif
+.include <bsd.regress.mk>
diff --git a/regress/sys/btcfi/foo.c b/regress/sys/btcfi/foo.c
new file mode 100644 (file)
index 0000000..59630e6
--- /dev/null
@@ -0,0 +1,6 @@
+/* Public domain */
+
+void
+foo(void)
+{
+}
diff --git a/regress/sys/btcfi/foobar.c b/regress/sys/btcfi/foobar.c
new file mode 100644 (file)
index 0000000..e521979
--- /dev/null
@@ -0,0 +1,34 @@
+/* Public domain */
+
+#include <signal.h>
+#include <stdlib.h>
+
+extern void foo(void);
+void (*foobar)(void) = foo;
+
+void
+bar(void)
+{
+       foobar();
+}
+
+void
+handler(int sig, siginfo_t *si, void *context)
+{
+       if (si->si_signo == SIGILL && si->si_code == ILL_BTCFI)
+               exit(0);
+}
+
+int
+main(void)
+{
+       struct sigaction sa;
+
+       sa.sa_sigaction = handler;
+       sa.sa_mask = 0;
+       sa.sa_flags = SA_SIGINFO;
+       sigaction(SIGILL, &sa, NULL);
+
+       bar();
+       exit(1);
+}