Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 04 May 2026 07:17:09 +0000
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 2157c0e19672 - stable/15 - tests/sys/arch/amd64: add a program to check INT $0x80 behavior on amd64
Message-ID:  <69f847f5.4065f.4f827677@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2157c0e19672e341130e0444ac6d902966da0a26

commit 2157c0e19672e341130e0444ac6d902966da0a26
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-04-27 04:23:36 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-05-04 07:16:40 +0000

    tests/sys/arch/amd64: add a program to check INT $0x80 behavior on amd64
    
    (cherry picked from commit 2c2ec6bbc9cc7762a250ffe903bda6c2e44d25ff)
---
 tests/sys/arch/amd64/Makefile  |  7 ++++
 tests/sys/arch/amd64/int0x80.c | 94 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)

diff --git a/tests/sys/arch/amd64/Makefile b/tests/sys/arch/amd64/Makefile
new file mode 100644
index 000000000000..34f3c90c4082
--- /dev/null
+++ b/tests/sys/arch/amd64/Makefile
@@ -0,0 +1,7 @@
+TESTSDIR=	${TESTSBASE}/sys/arch/amd64
+
+PLAIN_TESTS_C+=	int0x80
+
+BINDIR=		${TESTSDIR}
+
+.include <bsd.test.mk>
diff --git a/tests/sys/arch/amd64/int0x80.c b/tests/sys/arch/amd64/int0x80.c
new file mode 100644
index 000000000000..e03462a6dccd
--- /dev/null
+++ b/tests/sys/arch/amd64/int0x80.c
@@ -0,0 +1,94 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright 2026 The FreeBSD Foundation
+ *
+ * This software were developed by
+ * Konstantin Belousov <kib@FreeBSD.org> under sponsorship from
+ * the FreeBSD Foundation.
+ */
+
+#include <sys/syscall.h>
+#include <err.h>
+#include <signal.h>
+#include <stdatomic.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifndef __amd64__
+#error "amd64 only"
+#endif
+
+/*
+ * The check to see how "INT $0x80" behaves for amd64 native ABI
+ * processes.  Before bd8edba0792b71be3f8ed5dea9c22287e95c986a it
+ * executed syscalls with amd64 calling conventions.  After that
+ * revision, it should raise SIGBUS.
+ */
+
+static uintptr_t int0x80_loc;
+static int signo;
+extern char after_int0x80[];
+
+static void
+sigill_action(int signo1, siginfo_t *si __unused, void *uctxv)
+{
+	ucontext_t *uctx = uctxv;
+
+	signo = signo1;
+	int0x80_loc = uctx->uc_mcontext.mc_rip;
+}
+
+static int
+fire(void)
+{
+	int res;
+
+	asm volatile(
+	    ".globl\tafter_int0x80\n"
+	    "\tint\t$0x80\n"
+	    "after_int0x80:"
+	    : "=a" (res)
+	    : "%0" (SYS_getpid)
+	    : "rdx", "memory", "cc");
+	return (res);
+}
+
+int
+main(void)
+{
+	struct sigaction sa;
+	char signame[SIG2STR_MAX];
+	int pid, res;
+
+	res = 0;
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_sigaction = sigill_action;
+	sa.sa_flags = SA_SIGINFO;
+	if (sigaction(SIGBUS, &sa, NULL) == -1)
+		err(1, "catching SIGBUS");
+
+	pid = fire();
+	atomic_signal_fence(memory_order_seq_cst);
+	if (int0x80_loc == 0) {
+		printf("int $0x80 does not raise SIGBUS\n");
+		if (pid == getpid())
+			printf("and syscall worked\n");
+		else
+			printf("but syscall did not worked\n");
+		res = 1;
+	} else {
+		sig2str(signo, signame);
+		printf("int $0x80 raises SIG%s\n", signame);
+		if (int0x80_loc == (uintptr_t)after_int0x80) {
+			printf("at expected location\n");
+		} else {
+			printf("not at expected location\n");
+			res = 1;
+		}
+	}
+	exit(res);
+}


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f847f5.4065f.4f827677>