git: d7f306c5be6f - main - makesyscalls: add a new SYSMUX type

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Mon, 29 Nov 2021 22:05:36 UTC
The branch main has been updated by brooks:

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

commit d7f306c5be6fb4b4ab4455e1d033cc9545ce015d
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2021-11-29 22:03:00 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2021-11-29 22:04:43 +0000

    makesyscalls: add a new SYSMUX type
    
    This type is for system call multiplexers (syscall(2), __syscall(2))
    that don't have a normal handler and instead are handled in the
    machine-dependent syscall code.
    
    Reviewed by:    kib, imp
---
 sys/kern/syscalls.master   |  6 ++++--
 sys/tools/makesyscalls.lua | 23 ++++++++++++++++++-----
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 693454c67eca..96541023ec28 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -13,8 +13,8 @@
 ;		there is no audit event for the call at this time. For the
 ;		case where the event exists, but we don't want auditing, the
 ;		event should be #defined to AUE_NULL in audit_kevents.h.
-;	type	one of STD, OBSOL, RESERVED, UNIMPL, COMPAT, COMPAT4, COMPAT6,
-;		COMPAT7, COMPAT11, COMPAT12, NODEF, NOARGS, NOPROTO, NOSTD
+;	type	one of STD, OBSOL, RESERVED, UNIMPL, SYSMUX, COMPAT*,
+;		NODEF, NOARGS, NOPROTO, NOSTD
 ;		The COMPAT* options may be combined with one or more NO*
 ;		options separated by '|' with no spaces (e.g. COMPAT|NOARGS)
 ;		The CAPENABLED option may be ORed into a type.
@@ -48,6 +48,8 @@
 ;		function prototype in sys/sysproto.h.  Does add a
 ;		definition to syscall.h besides adding a sysent.
 ;	NOTSTATIC syscall is loadable
+;	SYSMUX	syscall multiplexer.  No prototype, argument struct, or
+;		handler is declared or used.  Handled in MD syscall code.
 ;	CAPENABLED syscall is allowed in capability mode
 ;
 ; To support programmatic generation of both the default ABI and 32-bit compat
diff --git a/sys/tools/makesyscalls.lua b/sys/tools/makesyscalls.lua
index e8f882f6641d..4fa5727470a8 100644
--- a/sys/tools/makesyscalls.lua
+++ b/sys/tools/makesyscalls.lua
@@ -196,6 +196,7 @@ local known_flags = {
 	NOSTD		= 0x00000080,
 	NOTSTATIC	= 0x00000100,
 	CAPENABLED	= 0x00000200,
+	SYSMUX		= 0x00000400,
 
 	-- Compat flags start from here.  We have plenty of space.
 }
@@ -733,7 +734,9 @@ local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
     auditev, syscallret, funcname, funcalias, funcargs, argalias)
 	local argssize
 
-	if #funcargs > 0 or flags & known_flags["NODEF"] ~= 0 then
+	if flags & known_flags["SYSMUX"] ~= 0 then
+		argssize = "0"
+	elseif #funcargs > 0 or flags & known_flags["NODEF"] ~= 0 then
 		argssize = "AS(" .. argalias .. ")"
 	else
 		argssize = "0"
@@ -752,7 +755,7 @@ local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
 	case %d:
 ]], funcname, sysnum))
 
-	if #funcargs > 0 then
+	if #funcargs > 0 and flags & known_flags["SYSMUX"] == 0 then
 		write_line("systracetmp", "\t\tswitch (ndx) {\n")
 		write_line("systrace", string.format(
 		    "\t\tstruct %s *p = params;\n", argalias))
@@ -820,8 +823,12 @@ local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
 		break;
 ]], syscallret))
 	end
+	local n_args = #funcargs
+	if flags & known_flags["SYSMUX"] ~= 0 then
+		n_args = 0
+	end
 	write_line("systrace", string.format(
-	    "\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", #funcargs))
+	    "\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", n_args))
 	write_line("systracetmp", "\t\tbreak;\n")
 
 	local nargflags = get_mask({"NOARGS", "NOPROTO", "NODEF"})
@@ -872,7 +879,13 @@ local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
 	    string.format("\t{ .sy_narg = %s, .sy_call = (sy_call_t *)", argssize))
 	local column = 8 + 2 + #argssize + 15
 
-	if flags & known_flags["NOSTD"] ~= 0 then
+	if flags & known_flags["SYSMUX"] ~= 0 then
+		write_line("sysent", string.format(
+		    "nosys, .sy_auevent = AUE_NULL, " ..
+		    ".sy_flags = %s, .sy_thrcnt = SY_THR_STATIC },",
+		    sysflags))
+		column = column + #"nosys" + #"AUE_NULL" + 3
+	elseif flags & known_flags["NOSTD"] ~= 0 then
 		write_line("sysent", string.format(
 		    "lkmressys, .sy_auevent = AUE_NULL, " ..
 		    ".sy_flags = %s, .sy_thrcnt = SY_THR_ABSENT },",
@@ -1271,7 +1284,7 @@ process_syscall_def = function(line)
 	local ncompatflags = get_mask({"STD", "NODEF", "NOARGS", "NOPROTO",
 	    "NOSTD"})
 	local compatflags = get_mask_pat("COMPAT.*")
-	if noproto then
+	if noproto or flags & known_flags["SYSMUX"] ~= 0 then
 		flags = flags | known_flags["NOPROTO"];
 	end
 	if flags & known_flags["OBSOL"] ~= 0 then