git: 53fae788f229 - main - sys: syscalls: add a test syscall definition file
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 18 Feb 2025 22:04:55 UTC
The branch main has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=53fae788f229903df04b2963399afb0dce03b78b
commit 53fae788f229903df04b2963399afb0dce03b78b
Author: Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-02-18 22:02:19 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2025-02-18 22:02:19 +0000
sys: syscalls: add a test syscall definition file
This exercises some subset of the preprocessor that would be nice to
still support.
Pull Request: https://github.com/freebsd/freebsd-src/pull/1575
---
Makefile.inc1 | 3 +-
sys/tools/syscalls/examples/cpp/Makefile | 3 +
sys/tools/syscalls/examples/cpp/syscalls.conf | 10 +++
sys/tools/syscalls/examples/cpp/syscalls.master | 26 +++++++
sys/tools/syscalls/examples/cpp/test_proto.h | 63 +++++++++++++++
sys/tools/syscalls/examples/cpp/test_syscall.h | 10 +++
sys/tools/syscalls/examples/cpp/test_syscalls.c | 19 +++++
sys/tools/syscalls/examples/cpp/test_sysent.c | 26 +++++++
.../syscalls/examples/cpp/test_systrace_args.c | 91 ++++++++++++++++++++++
9 files changed, 250 insertions(+), 1 deletion(-)
diff --git a/Makefile.inc1 b/Makefile.inc1
index 4383b4bfe30a..c9a4fee236aa 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -1604,7 +1604,8 @@ _sysent_dirs+= sys/compat/freebsd32
_sysent_dirs+= sys/amd64/linux \
sys/amd64/linux32 \
sys/arm64/linux \
- sys/i386/linux
+ sys/i386/linux \
+ sys/tools/syscalls/examples/cpp
sysent: .PHONY
.for _dir in ${_sysent_dirs}
diff --git a/sys/tools/syscalls/examples/cpp/Makefile b/sys/tools/syscalls/examples/cpp/Makefile
new file mode 100644
index 000000000000..cc691a1e2f85
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/Makefile
@@ -0,0 +1,3 @@
+GENERATED_PREFIX= test_
+
+.include "../../../../conf/sysent.mk"
diff --git a/sys/tools/syscalls/examples/cpp/syscalls.conf b/sys/tools/syscalls/examples/cpp/syscalls.conf
new file mode 100644
index 000000000000..7fc15b6bb01f
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/syscalls.conf
@@ -0,0 +1,10 @@
+sysnames="test_syscalls.c"
+sysproto="test_proto.h"
+sysproto_h=_TEST_SYSPROTO_H_
+syshdr="test_syscall.h"
+syssw="test_sysent.c"
+syscallprefix="TEST_SYS_"
+switchname="test_sysent"
+namesname="test_syscallnames"
+systrace="test_systrace_args.c"
+compat_set=""
diff --git a/sys/tools/syscalls/examples/cpp/syscalls.master b/sys/tools/syscalls/examples/cpp/syscalls.master
new file mode 100644
index 000000000000..4986ad41fc6a
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/syscalls.master
@@ -0,0 +1,26 @@
+#include <sys/param.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
+
+0 AUE_NULL UNIMPL unimpl_syscall0
+
+; Scenario #1: Vendor uses a reserved slot on just a single platform
+#ifdef PLATFORM_FOO
+1 AUE_NULL STD {
+ int syscall1(
+ int arg1
+ );
+ }
+#else
+1 AUE_NULL RESERVED
+#endif
+
+; Scenario #2: The other way around; vendor obsoletes a syscall on newer
+; platforms
+#ifdef PLATFORM_FOO
+2 AUE_NULL OBSOL syscall2
+#else
+2 AUE_NULL STD {
+ int syscall2(void);
+ }
+#endif
diff --git a/sys/tools/syscalls/examples/cpp/test_proto.h b/sys/tools/syscalls/examples/cpp/test_proto.h
new file mode 100644
index 000000000000..db1f507b8be0
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/test_proto.h
@@ -0,0 +1,63 @@
+/*
+ * System call prototypes.
+ *
+ * DO NOT EDIT-- this file is automatically @generated.
+ */
+
+#ifndef _TEST_SYSPROTO_H_
+#define _TEST_SYSPROTO_H_
+
+#include <sys/types.h>
+#include <sys/signal.h>
+#include <sys/cpuset.h>
+#include <sys/domainset.h>
+#include <sys/_ffcounter.h>
+#include <sys/_semaphore.h>
+#include <sys/ucontext.h>
+#include <sys/wait.h>
+
+#include <bsm/audit_kevents.h>
+
+struct proc;
+
+struct thread;
+
+#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \
+ 0 : sizeof(syscallarg_t) - sizeof(t))
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define PADL_(t) 0
+#define PADR_(t) PAD_(t)
+#else
+#define PADL_(t) PAD_(t)
+#define PADR_(t) 0
+#endif
+
+#ifdef PLATFORM_FOO
+struct syscall1_args {
+ char arg1_l_[PADL_(int)]; int arg1; char arg1_r_[PADR_(int)];
+};
+#else
+#endif
+#ifdef PLATFORM_FOO
+#else
+struct syscall2_args {
+ syscallarg_t dummy;
+};
+#endif
+#ifdef PLATFORM_FOO
+int sys_syscall1(struct thread *, struct syscall1_args *);
+#else
+#endif
+#ifdef PLATFORM_FOO
+#else
+int sys_syscall2(struct thread *, struct syscall2_args *);
+#endif
+#define TEST_SYS_AUE_syscall1 AUE_NULL
+#define TEST_SYS_AUE_syscall2 AUE_NULL
+
+#undef PAD_
+#undef PADL_
+#undef PADR_
+
+#endif /* !_TEST_SYSPROTO_H_ */
diff --git a/sys/tools/syscalls/examples/cpp/test_syscall.h b/sys/tools/syscalls/examples/cpp/test_syscall.h
new file mode 100644
index 000000000000..026e82d9ac62
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/test_syscall.h
@@ -0,0 +1,10 @@
+/*
+ * System call numbers.
+ *
+ * DO NOT EDIT-- this file is automatically @generated.
+ */
+
+#define TEST_SYS_syscall1 1
+ /* 2 is obsolete syscall2 */
+#define TEST_SYS_syscall2 2
+#define TEST_SYS_MAXSYSCALL 3
diff --git a/sys/tools/syscalls/examples/cpp/test_syscalls.c b/sys/tools/syscalls/examples/cpp/test_syscalls.c
new file mode 100644
index 000000000000..0e73c8223507
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/test_syscalls.c
@@ -0,0 +1,19 @@
+/*
+ * System call names.
+ *
+ * DO NOT EDIT-- this file is automatically @generated.
+ */
+
+const char *test_syscallnames[] = {
+ "#0", /* 0 = unimpl_syscall0 */
+#ifdef PLATFORM_FOO
+ "syscall1", /* 1 = syscall1 */
+#else
+ "#1", /* 1 = reserved for local use */
+#endif
+#ifdef PLATFORM_FOO
+ "obs_syscall2", /* 2 = obsolete syscall2 */
+#else
+ "syscall2", /* 2 = syscall2 */
+#endif
+};
diff --git a/sys/tools/syscalls/examples/cpp/test_sysent.c b/sys/tools/syscalls/examples/cpp/test_sysent.c
new file mode 100644
index 000000000000..18d2b0fd9712
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/test_sysent.c
@@ -0,0 +1,26 @@
+/*
+ * System call switch table.
+ *
+ * DO NOT EDIT-- this file is automatically @generated.
+ */
+
+#include <sys/param.h>
+#include <sys/sysent.h>
+#include <sys/sysproto.h>
+
+#define AS(name) (sizeof(struct name) / sizeof(syscallarg_t))
+
+/* The casts are bogus but will do for now. */
+struct sysent test_sysent[] = {
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 0 = unimpl_syscall0 */
+#ifdef PLATFORM_FOO
+ { .sy_narg = AS(syscall1_args), .sy_call = (sy_call_t *)sys_syscall1, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 1 = syscall1 */
+#else
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 1 = reserved for local use */
+#endif
+#ifdef PLATFORM_FOO
+ { .sy_narg = 0, .sy_call = (sy_call_t *)nosys, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT }, /* 2 = obsolete syscall2 */
+#else
+ { .sy_narg = 0, .sy_call = (sy_call_t *)sys_syscall2, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 2 = syscall2 */
+#endif
+};
diff --git a/sys/tools/syscalls/examples/cpp/test_systrace_args.c b/sys/tools/syscalls/examples/cpp/test_systrace_args.c
new file mode 100644
index 000000000000..74d0aa0ee862
--- /dev/null
+++ b/sys/tools/syscalls/examples/cpp/test_systrace_args.c
@@ -0,0 +1,91 @@
+/*
+ * System call argument to DTrace register array conversion.
+ *
+ * This file is part of the DTrace syscall provider.
+ *
+ * DO NOT EDIT-- this file is automatically @generated.
+ */
+
+static void
+systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
+{
+ int64_t *iarg = (int64_t *)uarg;
+ int a = 0;
+ switch (sysnum) {
+#ifdef PLATFORM_FOO
+ /* syscall1 */
+ case 1: {
+ struct syscall1_args *p = params;
+ iarg[a++] = p->arg1; /* int */
+ *n_args = 1;
+ break;
+ }
+#else
+#endif
+#ifdef PLATFORM_FOO
+#else
+ /* syscall2 */
+ case 2: {
+ *n_args = 0;
+ break;
+ }
+#endif
+ default:
+ *n_args = 0;
+ break;
+ };
+}
+static void
+systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
+{
+ const char *p = NULL;
+ switch (sysnum) {
+#ifdef PLATFORM_FOO
+ /* syscall1 */
+ case 1:
+ switch (ndx) {
+ case 0:
+ p = "int";
+ break;
+ default:
+ break;
+ };
+ break;
+#else
+#endif
+#ifdef PLATFORM_FOO
+#else
+ /* syscall2 */
+ case 2:
+ break;
+#endif
+ default:
+ break;
+ };
+ if (p != NULL)
+ strlcpy(desc, p, descsz);
+}
+static void
+systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
+{
+ const char *p = NULL;
+ switch (sysnum) {
+#ifdef PLATFORM_FOO
+ /* syscall1 */
+ case 1:
+ if (ndx == 0 || ndx == 1)
+ p = "int";
+ break;
+#else
+#endif
+#ifdef PLATFORM_FOO
+#else
+ /* syscall2 */
+ case 2:
+#endif
+ default:
+ break;
+ };
+ if (p != NULL)
+ strlcpy(desc, p, descsz);
+}