Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makesyscalls: restore support for cpp in input #1575

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.inc1
Original file line number Diff line number Diff line change
Expand Up @@ -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/test

sysent: .PHONY
.for _dir in ${_sysent_dirs}
Expand Down
8 changes: 5 additions & 3 deletions sys/kern/syscalls.master
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@
; timet_ Object contains a time_t and varies between i386 and other
; ABIs.

; #include's, #defines's, etc. may be included, and are copied to the output
; files. However, #ifdef, etc will be copied, but any lines that don't start
; with # will not. Caveat Emptor.
; #include's, #defines's, etc. may be included, and are copied to a
; limited set of output files. Before the first syscalls, #include lines will
; be copied and %%ABI_HEADERS%% expanded. Between system call entries,
; all lines beginning with # will be copied. Caveat Emptor.
; WARNING: this functionality is deprecated.

#include <sys/param.h>
#include <sys/sysent.h>
Expand Down
29 changes: 24 additions & 5 deletions sys/tools/syscalls/core/freebsd-syscall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
end

local incs = ""
local defs = ""
local prolog = ""
local first = true
local cpp_warned = false
local s
for line in fh:lines() do
line = line:gsub(commentExpr, "") -- Strip any comments.
Expand Down Expand Up @@ -80,12 +82,23 @@
if h ~= nil and h ~= "" then
incs = incs .. h .. "\n"
end
elseif line:match("^#%s*define") then
defs = defs .. line.. "\n"
elseif line:match("^#") then
util.abort(1, "Unsupported cpp op " .. line)
if not cpp_warned then
util.warn("use of non-include cpp " ..
"directives is deprecated")
cpp_warned = true
end
prolog = prolog .. line .. "\n"
else
s = syscall:new()

Check warning on line 93 in sys/tools/syscalls/core/freebsd-syscall.lua

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
if first then
self.prolog = prolog
s.prolog = ""
first = false
else
s.prolog = prolog
end
prolog = ""
if s:add(line) then
-- Append to system call list.
for t in s:iter() do
Expand Down Expand Up @@ -114,7 +127,13 @@

assert(fh:close())
self.includes = incs
self.defines = defs
self.epilog = prolog

if self.prolog ~= "" then
util.warn("non-include pre-processor directives in the " ..
"config prolog will not appear in generated output:\n" ..
self.prolog)
end
end

function FreeBSDSyscall:findStructs()
Expand Down
3 changes: 3 additions & 0 deletions sys/tools/syscalls/scripts/init_sysent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct sysent %s[] = {
-- based on the type of system call.
local comment = v.name

gen:write(v.prolog);

-- Handle non-compat:
if v:native() then
gen:write(string.format(
Expand Down Expand Up @@ -163,6 +165,7 @@ struct sysent %s[] = {

gen:write(string.format("\t/* %d = %s */\n", v.num, comment))
end
gen:write(tbl.epilog)

-- End
gen:write("};\n")
Expand Down
18 changes: 4 additions & 14 deletions sys/tools/syscalls/scripts/syscall_mk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,17 @@
gen:write("MIASM = \\\n") -- preamble
for _, v in pairs(s) do
local c = v:compatLevel()
local bs = " \\"
idx = idx + 1
if v:native() and not v.type.NODEF and not v.type.NOLIB then
if (v:native() or c >= 7) and not v.type.NODEF and not v.type.NOLIB then
if idx >= size then
-- At last system call, no backslash.
gen:write(string.format("\t%s.o\n", v:symbol()))
else
-- Normal behavior.
gen:write(string.format("\t%s.o \\\n", v:symbol()))
end
-- Handle compat (everything >= FREEBSD3):
elseif c >= 7 and not v.type.NODEF and not v.type.NOLIB then
if idx >= size then
-- At last system call, no backslash.
gen:write(string.format("\t%s.o\n", v:symbol()))
else
-- Normal behavior.
gen:write(string.format("\t%s.o \\\n", v:symbol()))
bs = ""
end
gen:write(string.format("\t%s.o%s\n", v:symbol(), bs))
end
end
end

Check warning on line 56 in sys/tools/syscalls/scripts/syscall_mk.lua

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line

-- Entry of script:
if script then
Expand Down
4 changes: 4 additions & 0 deletions sys/tools/syscalls/scripts/syscalls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function syscalls.generate(tbl, config, fh)
for _, v in pairs(s) do
--print("num " .. v.num .. " name " .. v.name)
local c = v:compatLevel()

gen:write(v.prolog);

if v:native() then
gen:write(string.format([[
"%s", /* %d = %s */
Expand Down Expand Up @@ -80,6 +83,7 @@ function syscalls.generate(tbl, config, fh)

end
end
gen:write(tbl.epilog)
-- End
gen:write("};\n")
end
Expand Down
4 changes: 3 additions & 1 deletion sys/tools/syscalls/scripts/syscalls_map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ function syscalls_map.generate(tbl, config, fh)
gen:write(string.format("FBSDprivate_1.0 {\n"))

for _, v in pairs(s) do
--print("num " .. v.num .. " name " .. v.name)
gen:write(v.prolog)
if v:native() and not v.type.NODEF and not v.type.NOLIB then
if v.name ~= "exit" and v.name ~= "vfork" then
gen:write(string.format("\t_%s;\n", v.name))
end
gen:write(string.format("\t__sys_%s;\n", v.name))
end
end
gen:write(tbl.epilog)

-- End
gen:write("};\n")
end
Expand Down
12 changes: 12 additions & 0 deletions sys/tools/syscalls/scripts/sysproto_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ struct thread;
-- intuitive).
local audit_idx = 10000 -- this should do

gen:write(v.prolog)
gen:store(v.prolog, 1)
for _, w in pairs(config.compat_options) do
gen:store(v.prolog, w.compatlevel * 10)
end

-- Handle non-compat:
if v:native() then
-- All these negation conditions are because (in
Expand Down Expand Up @@ -202,6 +208,12 @@ struct %s {
end_idx)
end

gen:write(tbl.epilog)
gen:store(tbl.epilog, 1)
for _, w in pairs(config.compat_options) do
gen:store(tbl.epilog, w.compatlevel * 10)
end

if gen.storage_levels ~= nil then
gen:writeStorage()
end
Expand Down
9 changes: 9 additions & 0 deletions sys/tools/syscalls/scripts/systrace_args.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)

for _, v in pairs(s) do

gen:write(v.prolog);
gen:store(v.prolog, 1);
gen:store(v.prolog, 2);

-- Handle non compat:
if v:native() then
gen:write(string.format([[
Expand Down Expand Up @@ -212,13 +216,16 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
end
end

gen:write(tbl.epilog)
gen:write([[
default:
*n_args = 0;
break;
};
}
]])

gen:store(tbl.epilog, 1)
gen:store([[
default:
break;
Expand All @@ -227,6 +234,8 @@ systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
strlcpy(desc, p, descsz);
}
]], 1)

gen:store(tbl.epilog, 2)
gen:store([[
default:
break;
Expand Down
3 changes: 3 additions & 0 deletions sys/tools/syscalls/test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GENERATED_PREFIX= test_

.include "../../../conf/sysent.mk"
11 changes: 11 additions & 0 deletions sys/tools/syscalls/test/syscalls.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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"
libsysmap="test_syscalls.map"
compat_set=""
26 changes: 26 additions & 0 deletions sys/tools/syscalls/test/syscalls.master
Original file line number Diff line number Diff line change
@@ -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
63 changes: 63 additions & 0 deletions sys/tools/syscalls/test/test_proto.h
Original file line number Diff line number Diff line change
@@ -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_ */
10 changes: 10 additions & 0 deletions sys/tools/syscalls/test/test_syscall.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions sys/tools/syscalls/test/test_syscalls.c
Original file line number Diff line number Diff line change
@@ -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
};
18 changes: 18 additions & 0 deletions sys/tools/syscalls/test/test_syscalls.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* FreeBSD system call symbols.
*
* DO NOT EDIT-- this file is automatically @generated.
*/

FBSDprivate_1.0 {
#ifdef PLATFORM_FOO
_syscall1;
__sys_syscall1;
#else
#endif
#ifdef PLATFORM_FOO
#else
_syscall2;
__sys_syscall2;
#endif
};

Check warning on line 18 in sys/tools/syscalls/test/test_syscalls.map

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
Loading
Loading