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
This commit is contained in:
Kyle Evans
2025-02-18 22:02:19 +00:00
committed by Brooks Davis
parent 18457e7e25
commit 53fae788f2
9 changed files with 250 additions and 1 deletions
+2 -1
View File
@@ -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}
+3
View File
@@ -0,0 +1,3 @@
GENERATED_PREFIX= test_
.include "../../../../conf/sysent.mk"
@@ -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=""
@@ -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
@@ -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_ */
@@ -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
@@ -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
};
@@ -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
};
@@ -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);
}