2019-11-17 14:08:19 +00:00
|
|
|
--
|
|
|
|
-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
--
|
|
|
|
-- Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org>
|
|
|
|
--
|
|
|
|
-- Redistribution and use in source and binary forms, with or without
|
|
|
|
-- modification, are permitted provided that the following conditions
|
|
|
|
-- are met:
|
|
|
|
-- 1. Redistributions of source code must retain the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer.
|
|
|
|
-- 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
-- notice, this list of conditions and the following disclaimer in the
|
|
|
|
-- documentation and/or other materials provided with the distribution.
|
|
|
|
--
|
|
|
|
-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
-- SUCH DAMAGE.
|
|
|
|
--
|
|
|
|
-- $FreeBSD$
|
|
|
|
--
|
|
|
|
|
|
|
|
|
|
|
|
-- We generally assume that this script will be run by flua, however we've
|
|
|
|
-- carefully crafted modules for it that mimic interfaces provided by modules
|
|
|
|
-- available in ports. Currently, this script is compatible with lua from ports
|
|
|
|
-- along with the compatible luafilesystem and lua-posix modules.
|
|
|
|
local lfs = require("lfs")
|
|
|
|
local unistd = require("posix.unistd")
|
|
|
|
|
2020-08-04 21:49:13 +00:00
|
|
|
local savesyscall = -1
|
|
|
|
local maxsyscall = -1
|
2019-11-17 14:08:19 +00:00
|
|
|
local generated_tag = "@" .. "generated"
|
|
|
|
|
|
|
|
-- Default configuration; any of these may get replaced by a configuration file
|
|
|
|
-- optionally specified.
|
|
|
|
local config = {
|
|
|
|
os_id_keyword = "FreeBSD",
|
|
|
|
abi_func_prefix = "",
|
|
|
|
sysnames = "syscalls.c",
|
|
|
|
sysproto = "../sys/sysproto.h",
|
|
|
|
sysproto_h = "_SYS_SYSPROTO_H_",
|
|
|
|
syshdr = "../sys/syscall.h",
|
|
|
|
sysmk = "../sys/syscall.mk",
|
|
|
|
syssw = "init_sysent.c",
|
|
|
|
syscallprefix = "SYS_",
|
|
|
|
switchname = "sysent",
|
|
|
|
namesname = "syscallnames",
|
|
|
|
systrace = "systrace_args.c",
|
|
|
|
capabilities_conf = "capabilities.conf",
|
|
|
|
capenabled = {},
|
2021-12-09 04:37:28 +00:00
|
|
|
compat_set = "native",
|
2019-11-17 14:08:19 +00:00
|
|
|
mincompat = 0,
|
|
|
|
abi_type_suffix = "",
|
|
|
|
abi_flags = "",
|
|
|
|
abi_flags_mask = 0,
|
2021-11-22 22:36:56 +00:00
|
|
|
abi_headers = "",
|
2021-11-22 22:36:57 +00:00
|
|
|
abi_intptr_t = "intptr_t",
|
2021-11-22 22:36:57 +00:00
|
|
|
abi_size_t = "size_t",
|
|
|
|
abi_u_long = "u_long",
|
|
|
|
abi_long = "long",
|
|
|
|
abi_semid_t = "semid_t",
|
2021-11-22 22:36:57 +00:00
|
|
|
abi_ptr_array_t = "",
|
2019-11-17 14:08:19 +00:00
|
|
|
ptr_intptr_t_cast = "intptr_t",
|
2021-11-22 22:36:58 +00:00
|
|
|
syscall_abi_change = "",
|
|
|
|
sys_abi_change = {},
|
|
|
|
syscall_no_abi_change = "",
|
|
|
|
sys_no_abi_change = {},
|
2021-11-22 22:36:57 +00:00
|
|
|
obsol = "",
|
|
|
|
obsol_dict = {},
|
|
|
|
unimpl = "",
|
|
|
|
unimpl_dict = {},
|
2019-11-17 14:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local config_modified = {}
|
|
|
|
local cleantmp = true
|
|
|
|
local tmpspace = "/tmp/sysent." .. unistd.getpid() .. "/"
|
|
|
|
|
2020-01-10 18:22:14 +00:00
|
|
|
local output_files = {
|
2019-11-17 14:08:19 +00:00
|
|
|
"sysnames",
|
|
|
|
"syshdr",
|
|
|
|
"sysmk",
|
|
|
|
"syssw",
|
|
|
|
"systrace",
|
2020-01-10 18:22:14 +00:00
|
|
|
"sysproto",
|
2019-11-17 14:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- These ones we'll create temporary files for; generation purposes.
|
|
|
|
local temp_files = {
|
|
|
|
"sysaue",
|
|
|
|
"sysdcl",
|
|
|
|
"syscompat",
|
|
|
|
"syscompatdcl",
|
|
|
|
"sysent",
|
|
|
|
"sysinc",
|
|
|
|
"sysarg",
|
|
|
|
"sysprotoend",
|
|
|
|
"systracetmp",
|
|
|
|
"systraceret",
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Opened files
|
|
|
|
local files = {}
|
|
|
|
|
|
|
|
local function cleanup()
|
|
|
|
for _, v in pairs(files) do
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(v:close())
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
if cleantmp then
|
|
|
|
if lfs.dir(tmpspace) then
|
|
|
|
for fname in lfs.dir(tmpspace) do
|
2021-01-27 17:46:15 +00:00
|
|
|
if fname ~= "." and fname ~= ".." then
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(os.remove(tmpspace .. "/" ..
|
|
|
|
fname))
|
2021-01-27 17:46:15 +00:00
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if lfs.attributes(tmpspace) and not lfs.rmdir(tmpspace) then
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(io.stderr:write("Failed to clean up tmpdir: " ..
|
|
|
|
tmpspace .. "\n"))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
else
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(io.stderr:write("Temp files left in " .. tmpspace ..
|
|
|
|
"\n"))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function abort(status, msg)
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(io.stderr:write(msg .. "\n"))
|
2019-11-17 14:08:19 +00:00
|
|
|
cleanup()
|
|
|
|
os.exit(status)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Each entry should have a value so we can represent abi flags as a bitmask
|
|
|
|
-- for convenience. One may also optionally provide an expr; this gets applied
|
|
|
|
-- to each argument type to indicate whether this argument is subject to ABI
|
|
|
|
-- change given the configured flags.
|
|
|
|
local known_abi_flags = {
|
|
|
|
long_size = {
|
|
|
|
value = 0x00000001,
|
2021-11-22 22:36:56 +00:00
|
|
|
exprs = {
|
|
|
|
"_Contains[a-z_]*_long_",
|
2021-11-22 22:36:57 +00:00
|
|
|
"^long [a-z0-9_]+$",
|
|
|
|
"long [*]",
|
|
|
|
"size_t [*]",
|
|
|
|
-- semid_t is not included because it is only used
|
|
|
|
-- as an argument or written out individually and
|
|
|
|
-- said writes are handled by the ksem framework.
|
|
|
|
-- Technically a sign-extension issue exists for
|
|
|
|
-- arguments, but because semid_t is actually a file
|
|
|
|
-- descriptor negative 32-bit values are invalid
|
|
|
|
-- regardless of sign-extension.
|
2021-11-22 22:36:56 +00:00
|
|
|
},
|
2019-11-17 14:08:19 +00:00
|
|
|
},
|
|
|
|
time_t_size = {
|
|
|
|
value = 0x00000002,
|
2021-11-22 22:36:56 +00:00
|
|
|
exprs = {
|
|
|
|
"_Contains[a-z_]*_timet_",
|
|
|
|
},
|
2019-11-17 14:08:19 +00:00
|
|
|
},
|
|
|
|
pointer_args = {
|
|
|
|
value = 0x00000004,
|
|
|
|
},
|
|
|
|
pointer_size = {
|
|
|
|
value = 0x00000008,
|
2021-11-22 22:36:56 +00:00
|
|
|
exprs = {
|
|
|
|
"_Contains[a-z_]*_ptr_",
|
2021-11-22 22:36:57 +00:00
|
|
|
"[*][*]",
|
2021-11-22 22:36:56 +00:00
|
|
|
},
|
2019-11-17 14:08:19 +00:00
|
|
|
},
|
2021-11-22 22:36:57 +00:00
|
|
|
pair_64bit = {
|
|
|
|
value = 0x00000010,
|
|
|
|
exprs = {
|
|
|
|
"^dev_t[ ]*$",
|
|
|
|
"^id_t[ ]*$",
|
|
|
|
"^off_t[ ]*$",
|
|
|
|
},
|
|
|
|
},
|
2019-11-17 14:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local known_flags = {
|
|
|
|
STD = 0x00000001,
|
|
|
|
OBSOL = 0x00000002,
|
2021-01-26 18:27:44 +00:00
|
|
|
RESERVED = 0x00000004,
|
|
|
|
UNIMPL = 0x00000008,
|
|
|
|
NODEF = 0x00000010,
|
|
|
|
NOARGS = 0x00000020,
|
|
|
|
NOPROTO = 0x00000040,
|
|
|
|
NOSTD = 0x00000080,
|
|
|
|
NOTSTATIC = 0x00000100,
|
2021-09-01 20:54:38 +00:00
|
|
|
CAPENABLED = 0x00000200,
|
2021-11-29 22:03:00 +00:00
|
|
|
SYSMUX = 0x00000400,
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
-- Compat flags start from here. We have plenty of space.
|
|
|
|
}
|
|
|
|
|
2021-12-09 04:37:28 +00:00
|
|
|
-- All compat option entries should have five entries:
|
2019-11-17 14:08:19 +00:00
|
|
|
-- definition: The preprocessor macro that will be set for this
|
|
|
|
-- compatlevel: The level this compatibility should be included at. This
|
|
|
|
-- generally represents the version of FreeBSD that it is compatible
|
|
|
|
-- with, but ultimately it's just the level of mincompat in which it's
|
|
|
|
-- included.
|
|
|
|
-- flag: The name of the flag in syscalls.master.
|
|
|
|
-- prefix: The prefix to use for _args and syscall prototype. This will be
|
|
|
|
-- used as-is, without "_" or any other character appended.
|
|
|
|
-- descr: The description of this compat option in init_sysent.c comments.
|
|
|
|
-- The special "stdcompat" entry will cause the other five to be autogenerated.
|
2021-12-09 04:37:28 +00:00
|
|
|
local compat_option_sets = {
|
|
|
|
native = {
|
|
|
|
{
|
|
|
|
definition = "COMPAT_43",
|
|
|
|
compatlevel = 3,
|
|
|
|
flag = "COMPAT",
|
|
|
|
prefix = "o",
|
|
|
|
descr = "old",
|
|
|
|
},
|
|
|
|
{ stdcompat = "FREEBSD4" },
|
|
|
|
{ stdcompat = "FREEBSD6" },
|
|
|
|
{ stdcompat = "FREEBSD7" },
|
|
|
|
{ stdcompat = "FREEBSD10" },
|
|
|
|
{ stdcompat = "FREEBSD11" },
|
|
|
|
{ stdcompat = "FREEBSD12" },
|
|
|
|
{ stdcompat = "FREEBSD13" },
|
2019-11-17 14:08:19 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-12-09 04:37:28 +00:00
|
|
|
-- compat_options will be resolved to a set from the configuration.
|
|
|
|
local compat_options
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
local function trim(s, char)
|
|
|
|
if s == nil then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
if char == nil then
|
|
|
|
char = "%s"
|
|
|
|
end
|
|
|
|
return s:gsub("^" .. char .. "+", ""):gsub(char .. "+$", "")
|
|
|
|
end
|
|
|
|
|
|
|
|
-- config looks like a shell script; in fact, the previous makesyscalls.sh
|
|
|
|
-- script actually sourced it in. It had a pretty common format, so we should
|
|
|
|
-- be fine to make various assumptions
|
|
|
|
local function process_config(file)
|
|
|
|
local cfg = {}
|
2019-12-06 22:45:36 +00:00
|
|
|
local comment_line_expr = "^%s*#.*"
|
|
|
|
-- We capture any whitespace padding here so we can easily advance to
|
|
|
|
-- the end of the line as needed to check for any trailing bogus bits.
|
|
|
|
-- Alternatively, we could drop the whitespace and instead try to
|
|
|
|
-- use a pattern to strip out the meaty part of the line, but then we
|
|
|
|
-- would need to sanitize the line for potentially special characters.
|
2021-12-09 04:37:28 +00:00
|
|
|
local line_expr = "^([%w%p]+%s*)=(%s*[`\"]?[^\"`]*[`\"]?)"
|
2019-11-17 14:08:19 +00:00
|
|
|
|
2021-01-27 18:12:33 +00:00
|
|
|
if not file then
|
2019-11-17 14:08:19 +00:00
|
|
|
return nil, "No file given"
|
|
|
|
end
|
|
|
|
|
2021-01-27 18:12:33 +00:00
|
|
|
local fh = assert(io.open(file))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
for nextline in fh:lines() do
|
2019-12-06 22:45:36 +00:00
|
|
|
-- Strip any whole-line comments
|
|
|
|
nextline = nextline:gsub(comment_line_expr, "")
|
2019-11-17 14:08:19 +00:00
|
|
|
-- Parse it into key, value pairs
|
2019-12-06 22:45:36 +00:00
|
|
|
local key, value = nextline:match(line_expr)
|
2019-11-17 14:08:19 +00:00
|
|
|
if key ~= nil and value ~= nil then
|
2019-12-06 22:45:36 +00:00
|
|
|
local kvp = key .. "=" .. value
|
|
|
|
key = trim(key)
|
|
|
|
value = trim(value)
|
|
|
|
local delim = value:sub(1,1)
|
2021-09-24 01:04:36 +00:00
|
|
|
if delim == '"' then
|
2019-12-06 22:45:36 +00:00
|
|
|
local trailing_context
|
2021-09-24 01:04:36 +00:00
|
|
|
|
2019-12-06 22:45:36 +00:00
|
|
|
-- Strip off the key/value part
|
|
|
|
trailing_context = nextline:sub(kvp:len() + 1)
|
|
|
|
-- Strip off any trailing comment
|
|
|
|
trailing_context = trailing_context:gsub("#.*$",
|
|
|
|
"")
|
|
|
|
-- Strip off leading/trailing whitespace
|
|
|
|
trailing_context = trim(trailing_context)
|
|
|
|
if trailing_context ~= "" then
|
|
|
|
print(trailing_context)
|
|
|
|
abort(1, "Malformed line: " .. nextline)
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
|
2019-12-06 22:45:36 +00:00
|
|
|
value = trim(value, delim)
|
2019-11-17 14:08:19 +00:00
|
|
|
else
|
2019-12-06 22:45:36 +00:00
|
|
|
-- Strip off potential comments
|
|
|
|
value = value:gsub("#.*$", "")
|
|
|
|
-- Strip off any padding whitespace
|
|
|
|
value = trim(value)
|
|
|
|
if value:match("%s") then
|
|
|
|
abort(1, "Malformed config line: " ..
|
|
|
|
nextline)
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
cfg[key] = value
|
2019-12-06 22:45:36 +00:00
|
|
|
elseif not nextline:match("^%s*$") then
|
|
|
|
-- Make sure format violations don't get overlooked
|
|
|
|
-- here, but ignore blank lines. Comments are already
|
|
|
|
-- stripped above.
|
|
|
|
abort(1, "Malformed config line: " .. nextline)
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(io.close(fh))
|
2019-11-17 14:08:19 +00:00
|
|
|
return cfg
|
|
|
|
end
|
|
|
|
|
|
|
|
local function grab_capenabled(file, open_fail_ok)
|
|
|
|
local capentries = {}
|
|
|
|
local commentExpr = "#.*"
|
|
|
|
|
|
|
|
if file == nil then
|
|
|
|
print "No file"
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local fh = io.open(file)
|
|
|
|
if fh == nil then
|
|
|
|
if not open_fail_ok then
|
|
|
|
abort(1, "Failed to open " .. file)
|
|
|
|
end
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
for nextline in fh:lines() do
|
|
|
|
-- Strip any comments
|
|
|
|
nextline = nextline:gsub(commentExpr, "")
|
|
|
|
if nextline ~= "" then
|
|
|
|
capentries[nextline] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(io.close(fh))
|
2019-11-17 14:08:19 +00:00
|
|
|
return capentries
|
|
|
|
end
|
|
|
|
|
|
|
|
local function process_compat()
|
|
|
|
local nval = 0
|
|
|
|
for _, v in pairs(known_flags) do
|
|
|
|
if v > nval then
|
|
|
|
nval = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nval = nval << 1
|
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
if v.stdcompat ~= nil then
|
|
|
|
local stdcompat = v.stdcompat
|
|
|
|
v.definition = "COMPAT_" .. stdcompat:upper()
|
|
|
|
v.compatlevel = tonumber(stdcompat:match("([0-9]+)$"))
|
|
|
|
v.flag = stdcompat:gsub("FREEBSD", "COMPAT")
|
|
|
|
v.prefix = stdcompat:lower() .. "_"
|
|
|
|
v.descr = stdcompat:lower()
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
local tmpname = "sys" .. v.flag:lower()
|
2019-11-17 14:08:19 +00:00
|
|
|
local dcltmpname = tmpname .. "dcl"
|
|
|
|
files[tmpname] = io.tmpfile()
|
|
|
|
files[dcltmpname] = io.tmpfile()
|
2023-04-20 22:15:57 +00:00
|
|
|
v.tmp = tmpname
|
|
|
|
v.dcltmp = dcltmpname
|
2019-11-17 14:08:19 +00:00
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
known_flags[v.flag] = nval
|
|
|
|
v.mask = nval
|
2019-11-17 14:08:19 +00:00
|
|
|
nval = nval << 1
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
v.count = 0
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function process_abi_flags()
|
2023-04-20 22:15:57 +00:00
|
|
|
local flags, mask = config.abi_flags, 0
|
2019-11-17 14:08:19 +00:00
|
|
|
for txtflag in flags:gmatch("([^|]+)") do
|
|
|
|
if known_abi_flags[txtflag] == nil then
|
|
|
|
abort(1, "Unknown abi_flag: " .. txtflag)
|
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
mask = mask | known_abi_flags[txtflag].value
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
config.abi_flags_mask = mask
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:57 +00:00
|
|
|
local function process_obsol()
|
2023-04-20 22:15:57 +00:00
|
|
|
local obsol = config.obsol
|
2021-11-22 22:36:57 +00:00
|
|
|
for syscall in obsol:gmatch("([^ ]+)") do
|
2023-04-20 22:15:57 +00:00
|
|
|
config.obsol_dict[syscall] = true
|
2021-11-22 22:36:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function process_unimpl()
|
2023-04-20 22:15:57 +00:00
|
|
|
local unimpl = config.unimpl
|
2021-11-22 22:36:57 +00:00
|
|
|
for syscall in unimpl:gmatch("([^ ]+)") do
|
2023-04-20 22:15:57 +00:00
|
|
|
config.unimpl_dict[syscall] = true
|
2021-11-22 22:36:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:58 +00:00
|
|
|
local function process_syscall_abi_change()
|
2023-04-20 22:15:57 +00:00
|
|
|
local changes_abi = config.syscall_abi_change
|
2021-11-22 22:36:58 +00:00
|
|
|
for syscall in changes_abi:gmatch("([^ ]+)") do
|
2023-04-20 22:15:57 +00:00
|
|
|
config.sys_abi_change[syscall] = true
|
2021-11-22 22:36:58 +00:00
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
local no_changes = config.syscall_no_abi_change
|
2021-11-22 22:36:58 +00:00
|
|
|
for syscall in no_changes:gmatch("([^ ]+)") do
|
2023-04-20 22:15:57 +00:00
|
|
|
config.sys_no_abi_change[syscall] = true
|
2021-11-22 22:36:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
local function abi_changes(name)
|
|
|
|
if known_abi_flags[name] == nil then
|
|
|
|
abort(1, "abi_changes: unknown flag: " .. name)
|
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
return config.abi_flags_mask & known_abi_flags[name].value ~= 0
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function strip_abi_prefix(funcname)
|
2023-04-20 22:15:57 +00:00
|
|
|
local abiprefix = config.abi_func_prefix
|
2019-11-17 14:08:19 +00:00
|
|
|
local stripped_name
|
2021-11-17 20:12:21 +00:00
|
|
|
if funcname == nil then
|
|
|
|
return nil
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
if abiprefix ~= "" and funcname:find("^" .. abiprefix) then
|
|
|
|
stripped_name = funcname:gsub("^" .. abiprefix, "")
|
|
|
|
else
|
|
|
|
stripped_name = funcname
|
|
|
|
end
|
|
|
|
|
|
|
|
return stripped_name
|
|
|
|
end
|
|
|
|
|
|
|
|
local function read_file(tmpfile)
|
|
|
|
if files[tmpfile] == nil then
|
|
|
|
print("Not found: " .. tmpfile)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local fh = files[tmpfile]
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(fh:seek("set"))
|
|
|
|
return assert(fh:read("a"))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function write_line(tmpfile, line)
|
|
|
|
if files[tmpfile] == nil then
|
|
|
|
print("Not found: " .. tmpfile)
|
|
|
|
return
|
|
|
|
end
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(files[tmpfile]:write(line))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function write_line_pfile(tmppat, line)
|
|
|
|
for k in pairs(files) do
|
|
|
|
if k:match(tmppat) ~= nil then
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(files[k]:write(line))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:57 +00:00
|
|
|
-- Check both literal intptr_t and the abi version because this needs
|
|
|
|
-- to work both before and after the substitution
|
2019-11-17 14:08:19 +00:00
|
|
|
local function isptrtype(type)
|
2021-11-22 22:36:56 +00:00
|
|
|
return type:find("*") or type:find("caddr_t") or
|
2023-04-20 22:15:57 +00:00
|
|
|
type:find("intptr_t") or type:find(config.abi_intptr_t)
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:57 +00:00
|
|
|
local function isptrarraytype(type)
|
|
|
|
return type:find("[*][*]") or type:find("[*][ ]*const[ ]*[*]")
|
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:57 +00:00
|
|
|
-- Find types that are always 64-bits wide
|
|
|
|
local function is64bittype(type)
|
|
|
|
return type:find("^dev_t[ ]*$") or type:find("^id_t[ ]*$") or type:find("^off_t[ ]*$")
|
|
|
|
end
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
local process_syscall_def
|
|
|
|
|
|
|
|
-- These patterns are processed in order on any line that isn't empty.
|
|
|
|
local pattern_table = {
|
|
|
|
{
|
2023-04-20 22:15:57 +00:00
|
|
|
pattern = "%s*$" .. config.os_id_keyword,
|
2019-11-17 14:08:19 +00:00
|
|
|
process = function(_, _)
|
|
|
|
-- Ignore... ID tag
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dump_prevline = true,
|
|
|
|
pattern = "^#%s*include",
|
|
|
|
process = function(line)
|
|
|
|
line = line .. "\n"
|
2023-04-20 22:16:06 +00:00
|
|
|
write_line("sysinc", line)
|
2019-11-17 14:08:19 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dump_prevline = true,
|
|
|
|
pattern = "^#",
|
|
|
|
process = function(line)
|
2020-08-04 21:49:13 +00:00
|
|
|
if line:find("^#%s*if") then
|
|
|
|
savesyscall = maxsyscall
|
|
|
|
elseif line:find("^#%s*else") then
|
|
|
|
maxsyscall = savesyscall
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
line = line .. "\n"
|
2023-04-20 22:16:06 +00:00
|
|
|
write_line("sysent", line)
|
|
|
|
write_line("sysdcl", line)
|
|
|
|
write_line("sysarg", line)
|
|
|
|
write_line_pfile("syscompat[0-9]*$", line)
|
|
|
|
write_line("sysnames", line)
|
|
|
|
write_line_pfile("systrace.*", line)
|
2019-11-17 14:08:19 +00:00
|
|
|
end,
|
|
|
|
},
|
2021-11-22 22:36:56 +00:00
|
|
|
{
|
|
|
|
dump_prevline = true,
|
|
|
|
pattern = "%%ABI_HEADERS%%",
|
|
|
|
process = function()
|
2023-04-20 22:15:57 +00:00
|
|
|
if config.abi_headers ~= "" then
|
2023-04-20 22:16:16 +00:00
|
|
|
local line = config.abi_headers .. "\n"
|
2023-04-20 22:16:06 +00:00
|
|
|
write_line("sysinc", line)
|
2021-11-22 22:36:56 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
2019-11-17 14:08:19 +00:00
|
|
|
{
|
|
|
|
-- Buffer anything else
|
|
|
|
pattern = ".+",
|
|
|
|
process = function(line, prevline)
|
|
|
|
local incomplete = line:find("\\$") ~= nil
|
|
|
|
-- Lines that end in \ get the \ stripped
|
|
|
|
-- Lines that start with a syscall number, prepend \n
|
|
|
|
line = trim(line):gsub("\\$", "")
|
|
|
|
if line:find("^[0-9]") and prevline then
|
|
|
|
process_syscall_def(prevline)
|
|
|
|
prevline = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
prevline = (prevline or '') .. line
|
|
|
|
incomplete = incomplete or prevline:find(",$") ~= nil
|
|
|
|
incomplete = incomplete or prevline:find("{") ~= nil and
|
|
|
|
prevline:find("}") == nil
|
|
|
|
if prevline:find("^[0-9]") and not incomplete then
|
|
|
|
process_syscall_def(prevline)
|
|
|
|
prevline = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return prevline
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
local function process_sysfile(file)
|
|
|
|
local capentries = {}
|
|
|
|
local commentExpr = "^%s*;.*"
|
|
|
|
|
|
|
|
if file == nil then
|
|
|
|
print "No file"
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local fh = io.open(file)
|
|
|
|
if fh == nil then
|
|
|
|
print("Failed to open " .. file)
|
|
|
|
return {}
|
|
|
|
end
|
|
|
|
|
|
|
|
local function do_match(nextline, prevline)
|
|
|
|
local pattern, handler, dump
|
|
|
|
for _, v in pairs(pattern_table) do
|
2023-04-20 22:15:57 +00:00
|
|
|
pattern = v.pattern
|
|
|
|
handler = v.process
|
|
|
|
dump = v.dump_prevline
|
2019-11-17 14:08:19 +00:00
|
|
|
if nextline:match(pattern) then
|
|
|
|
if dump and prevline then
|
|
|
|
process_syscall_def(prevline)
|
|
|
|
prevline = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return handler(nextline, prevline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
abort(1, "Failed to handle: " .. nextline)
|
|
|
|
end
|
|
|
|
|
|
|
|
local prevline
|
|
|
|
for nextline in fh:lines() do
|
|
|
|
-- Strip any comments
|
|
|
|
nextline = nextline:gsub(commentExpr, "")
|
|
|
|
if nextline ~= "" then
|
|
|
|
prevline = do_match(nextline, prevline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Dump any remainder
|
|
|
|
if prevline ~= nil and prevline:find("^[0-9]") then
|
|
|
|
process_syscall_def(prevline)
|
|
|
|
end
|
|
|
|
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(io.close(fh))
|
2019-11-17 14:08:19 +00:00
|
|
|
return capentries
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_mask(flags)
|
|
|
|
local mask = 0
|
|
|
|
for _, v in ipairs(flags) do
|
|
|
|
if known_flags[v] == nil then
|
|
|
|
abort(1, "Checking for unknown flag " .. v)
|
|
|
|
end
|
|
|
|
|
|
|
|
mask = mask | known_flags[v]
|
|
|
|
end
|
|
|
|
|
|
|
|
return mask
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_mask_pat(pflags)
|
|
|
|
local mask = 0
|
|
|
|
for k, v in pairs(known_flags) do
|
|
|
|
if k:find(pflags) then
|
|
|
|
mask = mask | v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return mask
|
|
|
|
end
|
|
|
|
|
|
|
|
local function align_sysent_comment(col)
|
|
|
|
write_line("sysent", "\t")
|
|
|
|
col = col + 8 - col % 8
|
|
|
|
while col < 56 do
|
|
|
|
write_line("sysent", "\t")
|
|
|
|
col = col + 8
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function strip_arg_annotations(arg)
|
2021-11-22 22:36:58 +00:00
|
|
|
arg = arg:gsub("_Contains_[^ ]*[_)] ?", "")
|
2019-11-17 14:08:19 +00:00
|
|
|
arg = arg:gsub("_In[^ ]*[_)] ?", "")
|
|
|
|
arg = arg:gsub("_Out[^ ]*[_)] ?", "")
|
|
|
|
return trim(arg)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function check_abi_changes(arg)
|
|
|
|
for k, v in pairs(known_abi_flags) do
|
2023-04-20 22:15:57 +00:00
|
|
|
local exprs = v.exprs
|
2021-11-22 22:36:56 +00:00
|
|
|
if abi_changes(k) and exprs ~= nil then
|
|
|
|
for _, e in pairs(exprs) do
|
|
|
|
if arg:find(e) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function process_args(args)
|
|
|
|
local funcargs = {}
|
2021-11-22 22:36:58 +00:00
|
|
|
local changes_abi = false
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
for arg in args:gmatch("([^,]+)") do
|
2021-11-22 22:36:58 +00:00
|
|
|
local arg_abi_change = check_abi_changes(arg)
|
|
|
|
changes_abi = changes_abi or arg_abi_change
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
arg = strip_arg_annotations(arg)
|
|
|
|
|
|
|
|
local argname = arg:match("([^* ]+)$")
|
|
|
|
|
|
|
|
-- argtype is... everything else.
|
|
|
|
local argtype = trim(arg:gsub(argname .. "$", ""), nil)
|
|
|
|
|
|
|
|
if argtype == "" and argname == "void" then
|
|
|
|
goto out
|
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:58 +00:00
|
|
|
-- is64bittype() needs a bare type so check it after argname
|
|
|
|
-- is removed
|
|
|
|
changes_abi = changes_abi or (abi_changes("pair_64bit") and is64bittype(argtype))
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
argtype = argtype:gsub("intptr_t", config.abi_intptr_t)
|
|
|
|
argtype = argtype:gsub("semid_t", config.abi_semid_t)
|
2021-11-22 22:36:57 +00:00
|
|
|
if isptrtype(argtype) then
|
2023-04-20 22:15:57 +00:00
|
|
|
argtype = argtype:gsub("size_t", config.abi_size_t)
|
|
|
|
argtype = argtype:gsub("^long", config.abi_long);
|
|
|
|
argtype = argtype:gsub("^u_long", config.abi_u_long);
|
|
|
|
argtype = argtype:gsub("^const u_long", "const " .. config.abi_u_long);
|
2021-11-22 22:36:57 +00:00
|
|
|
elseif argtype:find("^long$") then
|
2023-04-20 22:15:57 +00:00
|
|
|
argtype = config.abi_long
|
2021-11-22 22:36:57 +00:00
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
if isptrarraytype(argtype) and config.abi_ptr_array_t ~= "" then
|
2021-11-22 22:36:57 +00:00
|
|
|
-- `* const *` -> `**`
|
|
|
|
argtype = argtype:gsub("[*][ ]*const[ ]*[*]", "**")
|
|
|
|
-- e.g., `struct aiocb **` -> `uint32_t *`
|
2023-04-20 22:15:57 +00:00
|
|
|
argtype = argtype:gsub("[^*]*[*]", config.abi_ptr_array_t .. " ", 1)
|
2021-11-22 22:36:57 +00:00
|
|
|
end
|
2021-11-22 22:36:57 +00:00
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
-- XX TODO: Forward declarations? See: sysstubfwd in CheriBSD
|
2021-11-22 22:36:58 +00:00
|
|
|
if arg_abi_change then
|
2023-04-20 22:15:57 +00:00
|
|
|
local abi_type_suffix = config.abi_type_suffix
|
2019-11-17 14:08:19 +00:00
|
|
|
argtype = argtype:gsub("(struct [^ ]*)", "%1" ..
|
|
|
|
abi_type_suffix)
|
|
|
|
argtype = argtype:gsub("(union [^ ]*)", "%1" ..
|
|
|
|
abi_type_suffix)
|
|
|
|
end
|
|
|
|
|
2021-11-22 22:36:57 +00:00
|
|
|
if abi_changes("pair_64bit") and is64bittype(argtype) then
|
|
|
|
if #funcargs % 2 == 1 then
|
|
|
|
funcargs[#funcargs + 1] = {
|
|
|
|
type = "int",
|
|
|
|
name = "_pad",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
funcargs[#funcargs + 1] = {
|
|
|
|
type = "uint32_t",
|
|
|
|
name = argname .. "1",
|
|
|
|
}
|
|
|
|
funcargs[#funcargs + 1] = {
|
|
|
|
type = "uint32_t",
|
|
|
|
name = argname .. "2",
|
|
|
|
}
|
|
|
|
else
|
|
|
|
funcargs[#funcargs + 1] = {
|
|
|
|
type = argtype,
|
|
|
|
name = argname,
|
|
|
|
}
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
::out::
|
2021-11-22 22:36:58 +00:00
|
|
|
return funcargs, changes_abi
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
|
|
|
|
auditev, syscallret, funcname, funcalias, funcargs, argalias)
|
|
|
|
local argssize
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.SYSMUX ~= 0 then
|
2021-11-29 22:03:00 +00:00
|
|
|
argssize = "0"
|
2023-04-20 22:15:57 +00:00
|
|
|
elseif #funcargs > 0 or flags & known_flags.NODEF ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
argssize = "AS(" .. argalias .. ")"
|
|
|
|
else
|
|
|
|
argssize = "0"
|
|
|
|
end
|
|
|
|
|
|
|
|
write_line("systrace", string.format([[
|
|
|
|
/* %s */
|
|
|
|
case %d: {
|
|
|
|
]], funcname, sysnum))
|
|
|
|
write_line("systracetmp", string.format([[
|
|
|
|
/* %s */
|
|
|
|
case %d:
|
|
|
|
]], funcname, sysnum))
|
|
|
|
write_line("systraceret", string.format([[
|
|
|
|
/* %s */
|
|
|
|
case %d:
|
|
|
|
]], funcname, sysnum))
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if #funcargs > 0 and flags & known_flags.SYSMUX == 0 then
|
2021-05-12 20:11:44 +00:00
|
|
|
write_line("systracetmp", "\t\tswitch (ndx) {\n")
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("systrace", string.format(
|
|
|
|
"\t\tstruct %s *p = params;\n", argalias))
|
|
|
|
|
2021-11-22 22:36:57 +00:00
|
|
|
|
|
|
|
local argtype, argname, desc, padding
|
|
|
|
padding = ""
|
2019-11-17 14:08:19 +00:00
|
|
|
for idx, arg in ipairs(funcargs) do
|
2023-04-20 22:15:57 +00:00
|
|
|
argtype = arg.type
|
|
|
|
argname = arg.name
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
argtype = trim(argtype:gsub("__restrict$", ""), nil)
|
2021-11-22 22:36:57 +00:00
|
|
|
if argtype == "int" and argname == "_pad" and abi_changes("pair_64bit") then
|
|
|
|
write_line("systracetmp", "#ifdef PAD64_REQUIRED\n")
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
-- Pointer arg?
|
|
|
|
if argtype:find("*") then
|
2021-11-22 22:36:57 +00:00
|
|
|
desc = "userland " .. argtype
|
2019-11-17 14:08:19 +00:00
|
|
|
else
|
2021-11-22 22:36:57 +00:00
|
|
|
desc = argtype;
|
|
|
|
end
|
|
|
|
write_line("systracetmp", string.format(
|
|
|
|
"\t\tcase %d%s:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n",
|
|
|
|
idx - 1, padding, desc))
|
|
|
|
if argtype == "int" and argname == "_pad" and abi_changes("pair_64bit") then
|
|
|
|
padding = " - _P_"
|
|
|
|
write_line("systracetmp", "#define _P_ 0\n#else\n#define _P_ 1\n#endif\n")
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if isptrtype(argtype) then
|
|
|
|
write_line("systrace", string.format(
|
2021-11-22 22:36:57 +00:00
|
|
|
"\t\tuarg[a++] = (%s)p->%s; /* %s */\n",
|
2023-04-20 22:15:57 +00:00
|
|
|
config.ptr_intptr_t_cast,
|
2019-11-17 14:08:19 +00:00
|
|
|
argname, argtype))
|
|
|
|
elseif argtype == "union l_semun" then
|
|
|
|
write_line("systrace", string.format(
|
2021-11-22 22:36:57 +00:00
|
|
|
"\t\tuarg[a++] = p->%s.buf; /* %s */\n",
|
|
|
|
argname, argtype))
|
2019-11-17 14:08:19 +00:00
|
|
|
elseif argtype:sub(1,1) == "u" or argtype == "size_t" then
|
|
|
|
write_line("systrace", string.format(
|
2021-11-22 22:36:57 +00:00
|
|
|
"\t\tuarg[a++] = p->%s; /* %s */\n",
|
|
|
|
argname, argtype))
|
2019-11-17 14:08:19 +00:00
|
|
|
else
|
2021-11-22 22:36:57 +00:00
|
|
|
if argtype == "int" and argname == "_pad" and abi_changes("pair_64bit") then
|
|
|
|
write_line("systrace", "#ifdef PAD64_REQUIRED\n")
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("systrace", string.format(
|
2021-11-22 22:36:57 +00:00
|
|
|
"\t\tiarg[a++] = p->%s; /* %s */\n",
|
|
|
|
argname, argtype))
|
|
|
|
if argtype == "int" and argname == "_pad" and abi_changes("pair_64bit") then
|
|
|
|
write_line("systrace", "#endif\n")
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
write_line("systracetmp",
|
|
|
|
"\t\tdefault:\n\t\t\tbreak;\n\t\t};\n")
|
2021-11-22 22:36:57 +00:00
|
|
|
if padding ~= "" then
|
|
|
|
write_line("systracetmp", "#undef _P_\n\n")
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("systraceret", string.format([[
|
|
|
|
if (ndx == 0 || ndx == 1)
|
|
|
|
p = "%s";
|
|
|
|
break;
|
|
|
|
]], syscallret))
|
|
|
|
end
|
2021-11-29 22:03:00 +00:00
|
|
|
local n_args = #funcargs
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.SYSMUX ~= 0 then
|
2021-11-29 22:03:00 +00:00
|
|
|
n_args = 0
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("systrace", string.format(
|
2021-11-29 22:03:00 +00:00
|
|
|
"\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", n_args))
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("systracetmp", "\t\tbreak;\n")
|
|
|
|
|
|
|
|
local nargflags = get_mask({"NOARGS", "NOPROTO", "NODEF"})
|
|
|
|
if flags & nargflags == 0 then
|
|
|
|
if #funcargs > 0 then
|
|
|
|
write_line("sysarg", string.format("struct %s {\n",
|
|
|
|
argalias))
|
|
|
|
for _, v in ipairs(funcargs) do
|
2023-04-20 22:15:57 +00:00
|
|
|
local argname, argtype = v.name, v.type
|
2021-11-22 22:36:57 +00:00
|
|
|
if argtype == "int" and argname == "_pad" and abi_changes("pair_64bit") then
|
|
|
|
write_line("sysarg", "#ifdef PAD64_REQUIRED\n")
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysarg", string.format(
|
|
|
|
"\tchar %s_l_[PADL_(%s)]; %s %s; char %s_r_[PADR_(%s)];\n",
|
|
|
|
argname, argtype,
|
|
|
|
argtype, argname,
|
|
|
|
argname, argtype))
|
2021-11-22 22:36:57 +00:00
|
|
|
if argtype == "int" and argname == "_pad" and abi_changes("pair_64bit") then
|
|
|
|
write_line("sysarg", "#endif\n")
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
write_line("sysarg", "};\n")
|
|
|
|
else
|
|
|
|
write_line("sysarg", string.format(
|
2022-03-28 18:43:03 +00:00
|
|
|
"struct %s {\n\tsyscallarg_t dummy;\n};\n", argalias))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local protoflags = get_mask({"NOPROTO", "NODEF"})
|
|
|
|
if flags & protoflags == 0 then
|
|
|
|
if funcname == "nosys" or funcname == "lkmnosys" or
|
|
|
|
funcname == "sysarch" or funcname:find("^freebsd") or
|
2021-09-12 22:50:39 +00:00
|
|
|
funcname:find("^linux") then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysdcl", string.format(
|
|
|
|
"%s\t%s(struct thread *, struct %s *)",
|
|
|
|
rettype, funcname, argalias))
|
|
|
|
else
|
|
|
|
write_line("sysdcl", string.format(
|
|
|
|
"%s\tsys_%s(struct thread *, struct %s *)",
|
|
|
|
rettype, funcname, argalias))
|
|
|
|
end
|
|
|
|
write_line("sysdcl", ";\n")
|
|
|
|
write_line("sysaue", string.format("#define\t%sAUE_%s\t%s\n",
|
2023-04-20 22:15:57 +00:00
|
|
|
config.syscallprefix, funcalias, auditev))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2020-09-25 09:34:00 +00:00
|
|
|
write_line("sysent",
|
|
|
|
string.format("\t{ .sy_narg = %s, .sy_call = (sy_call_t *)", argssize))
|
2019-11-17 14:08:19 +00:00
|
|
|
local column = 8 + 2 + #argssize + 15
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.SYSMUX ~= 0 then
|
2021-11-29 22:03:00 +00:00
|
|
|
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
|
2023-04-20 22:15:57 +00:00
|
|
|
elseif flags & known_flags.NOSTD ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysent", string.format(
|
2020-09-25 09:34:00 +00:00
|
|
|
"lkmressys, .sy_auevent = AUE_NULL, " ..
|
|
|
|
".sy_flags = %s, .sy_thrcnt = SY_THR_ABSENT },",
|
2019-11-17 14:08:19 +00:00
|
|
|
sysflags))
|
|
|
|
column = column + #"lkmressys" + #"AUE_NULL" + 3
|
|
|
|
else
|
|
|
|
if funcname == "nosys" or funcname == "lkmnosys" or
|
|
|
|
funcname == "sysarch" or funcname:find("^freebsd") or
|
2021-09-12 22:50:39 +00:00
|
|
|
funcname:find("^linux") then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysent", string.format(
|
2020-09-25 09:34:00 +00:00
|
|
|
"%s, .sy_auevent = %s, .sy_flags = %s, .sy_thrcnt = %s },",
|
2019-11-17 14:08:19 +00:00
|
|
|
funcname, auditev, sysflags, thr_flag))
|
|
|
|
column = column + #funcname + #auditev + #sysflags + 3
|
|
|
|
else
|
|
|
|
write_line("sysent", string.format(
|
2020-09-25 09:34:00 +00:00
|
|
|
"sys_%s, .sy_auevent = %s, .sy_flags = %s, .sy_thrcnt = %s },",
|
2019-11-17 14:08:19 +00:00
|
|
|
funcname, auditev, sysflags, thr_flag))
|
|
|
|
column = column + #funcname + #auditev + #sysflags + 7
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
align_sysent_comment(column)
|
|
|
|
write_line("sysent", string.format("/* %d = %s */\n",
|
|
|
|
sysnum, funcalias))
|
|
|
|
write_line("sysnames", string.format("\t\"%s\",\t\t\t/* %d = %s */\n",
|
|
|
|
funcalias, sysnum, funcalias))
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.NODEF == 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("syshdr", string.format("#define\t%s%s\t%d\n",
|
2023-04-20 22:15:57 +00:00
|
|
|
config.syscallprefix, funcalias, sysnum))
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysmk", string.format(" \\\n\t%s.o",
|
|
|
|
funcalias))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function handle_obsol(sysnum, funcname, comment)
|
|
|
|
write_line("sysent",
|
2020-09-25 09:34:00 +00:00
|
|
|
"\t{ .sy_narg = 0, .sy_call = (sy_call_t *)nosys, " ..
|
|
|
|
".sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT },")
|
2019-11-17 14:08:19 +00:00
|
|
|
align_sysent_comment(34)
|
|
|
|
|
|
|
|
write_line("sysent", string.format("/* %d = obsolete %s */\n",
|
|
|
|
sysnum, comment))
|
|
|
|
write_line("sysnames", string.format(
|
|
|
|
"\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
|
|
|
|
funcname, sysnum, comment))
|
|
|
|
write_line("syshdr", string.format("\t\t\t\t/* %d is obsolete %s */\n",
|
|
|
|
sysnum, comment))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function handle_compat(sysnum, thr_flag, flags, sysflags, rettype,
|
|
|
|
auditev, funcname, funcalias, funcargs, argalias)
|
|
|
|
local argssize, out, outdcl, wrap, prefix, descr
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if #funcargs > 0 or flags & known_flags.NODEF ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
argssize = "AS(" .. argalias .. ")"
|
|
|
|
else
|
|
|
|
argssize = "0"
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & v.mask ~= 0 then
|
|
|
|
if config.mincompat > v.compatlevel then
|
2019-11-17 14:08:19 +00:00
|
|
|
funcname = strip_abi_prefix(funcname)
|
2023-04-20 22:15:57 +00:00
|
|
|
funcname = v.prefix .. funcname
|
2019-11-17 14:08:19 +00:00
|
|
|
return handle_obsol(sysnum, funcname, funcname)
|
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
v.count = v.count + 1
|
|
|
|
out = v.tmp
|
|
|
|
outdcl = v.dcltmp
|
|
|
|
wrap = v.flag:lower()
|
|
|
|
prefix = v.prefix
|
|
|
|
descr = v.descr
|
2019-11-17 14:08:19 +00:00
|
|
|
goto compatdone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
::compatdone::
|
|
|
|
local dprotoflags = get_mask({"NOPROTO", "NODEF"})
|
2023-04-20 22:15:57 +00:00
|
|
|
local nargflags = dprotoflags | known_flags.NOARGS
|
2019-11-17 14:08:19 +00:00
|
|
|
if #funcargs > 0 and flags & nargflags == 0 then
|
|
|
|
write_line(out, string.format("struct %s {\n", argalias))
|
|
|
|
for _, v in ipairs(funcargs) do
|
2023-04-20 22:15:57 +00:00
|
|
|
local argname, argtype = v.name, v.type
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line(out, string.format(
|
|
|
|
"\tchar %s_l_[PADL_(%s)]; %s %s; char %s_r_[PADR_(%s)];\n",
|
|
|
|
argname, argtype,
|
|
|
|
argtype, argname,
|
|
|
|
argname, argtype))
|
|
|
|
end
|
|
|
|
write_line(out, "};\n")
|
|
|
|
elseif flags & nargflags == 0 then
|
|
|
|
write_line("sysarg", string.format(
|
2022-03-28 18:43:03 +00:00
|
|
|
"struct %s {\n\tsyscallarg_t dummy;\n};\n", argalias))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
if flags & dprotoflags == 0 then
|
|
|
|
write_line(outdcl, string.format(
|
|
|
|
"%s\t%s%s(struct thread *, struct %s *);\n",
|
|
|
|
rettype, prefix, funcname, argalias))
|
|
|
|
write_line("sysaue", string.format(
|
2023-04-20 22:15:57 +00:00
|
|
|
"#define\t%sAUE_%s%s\t%s\n", config.syscallprefix,
|
2019-11-17 14:08:19 +00:00
|
|
|
prefix, funcname, auditev))
|
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.NOSTD ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysent", string.format(
|
2020-09-25 09:34:00 +00:00
|
|
|
"\t{ .sy_narg = %s, .sy_call = (sy_call_t *)%s, " ..
|
|
|
|
".sy_auevent = %s, .sy_flags = 0, " ..
|
|
|
|
".sy_thrcnt = SY_THR_ABSENT },",
|
2019-11-17 14:08:19 +00:00
|
|
|
"0", "lkmressys", "AUE_NULL"))
|
|
|
|
align_sysent_comment(8 + 2 + #"0" + 15 + #"lkmressys" +
|
|
|
|
#"AUE_NULL" + 3)
|
|
|
|
else
|
|
|
|
write_line("sysent", string.format(
|
2020-09-25 09:34:00 +00:00
|
|
|
"\t{ %s(%s,%s), .sy_auevent = %s, .sy_flags = %s, .sy_thrcnt = %s },",
|
2019-11-17 14:08:19 +00:00
|
|
|
wrap, argssize, funcname, auditev, sysflags, thr_flag))
|
|
|
|
align_sysent_comment(8 + 9 + #argssize + 1 + #funcname +
|
|
|
|
#auditev + #sysflags + 4)
|
|
|
|
end
|
|
|
|
|
|
|
|
write_line("sysent", string.format("/* %d = %s %s */\n",
|
|
|
|
sysnum, descr, funcalias))
|
|
|
|
write_line("sysnames", string.format(
|
|
|
|
"\t\"%s.%s\",\t\t/* %d = %s %s */\n",
|
|
|
|
wrap, funcalias, sysnum, descr, funcalias))
|
|
|
|
-- Do not provide freebsdN_* symbols in libc for < FreeBSD 7
|
|
|
|
local nosymflags = get_mask({"COMPAT", "COMPAT4", "COMPAT6"})
|
|
|
|
if flags & nosymflags ~= 0 then
|
|
|
|
write_line("syshdr", string.format(
|
|
|
|
"\t\t\t\t/* %d is %s %s */\n",
|
|
|
|
sysnum, descr, funcalias))
|
2023-04-20 22:15:57 +00:00
|
|
|
elseif flags & known_flags.NODEF == 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("syshdr", string.format("#define\t%s%s%s\t%d\n",
|
2023-04-20 22:15:57 +00:00
|
|
|
config.syscallprefix, prefix, funcalias, sysnum))
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysmk", string.format(" \\\n\t%s%s.o",
|
|
|
|
prefix, funcalias))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function handle_unimpl(sysnum, sysstart, sysend, comment)
|
|
|
|
if sysstart == nil and sysend == nil then
|
|
|
|
sysstart = tonumber(sysnum)
|
|
|
|
sysend = tonumber(sysnum)
|
|
|
|
end
|
|
|
|
|
|
|
|
sysnum = sysstart
|
|
|
|
while sysnum <= sysend do
|
|
|
|
write_line("sysent", string.format(
|
2020-09-25 09:34:00 +00:00
|
|
|
"\t{ .sy_narg = 0, .sy_call = (sy_call_t *)nosys, " ..
|
|
|
|
".sy_auevent = AUE_NULL, .sy_flags = 0, " ..
|
|
|
|
".sy_thrcnt = SY_THR_ABSENT },\t\t\t/* %d = %s */\n",
|
2019-11-17 14:08:19 +00:00
|
|
|
sysnum, comment))
|
|
|
|
write_line("sysnames", string.format(
|
|
|
|
"\t\"#%d\",\t\t\t/* %d = %s */\n",
|
|
|
|
sysnum, sysnum, comment))
|
|
|
|
sysnum = sysnum + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-20 22:16:16 +00:00
|
|
|
local function handle_reserved(sysnum, sysstart, sysend)
|
2021-01-26 18:27:44 +00:00
|
|
|
handle_unimpl(sysnum, sysstart, sysend, "reserved for local use")
|
|
|
|
end
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
process_syscall_def = function(line)
|
|
|
|
local sysstart, sysend, flags, funcname, sysflags
|
|
|
|
local thr_flag, syscallret
|
|
|
|
local orig = line
|
|
|
|
flags = 0
|
|
|
|
thr_flag = "SY_THR_STATIC"
|
|
|
|
|
|
|
|
-- Parse out the interesting information first
|
|
|
|
local initialExpr = "^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s*"
|
|
|
|
local sysnum, auditev, allflags = line:match(initialExpr)
|
|
|
|
|
|
|
|
if sysnum == nil or auditev == nil or allflags == nil then
|
|
|
|
-- XXX TODO: Better?
|
|
|
|
abort(1, "Completely malformed: " .. line)
|
|
|
|
end
|
|
|
|
|
|
|
|
if sysnum:find("-") then
|
|
|
|
sysstart, sysend = sysnum:match("^([%d]+)-([%d]+)$")
|
|
|
|
if sysstart == nil or sysend == nil then
|
|
|
|
abort(1, "Malformed range: " .. sysnum)
|
|
|
|
end
|
|
|
|
sysnum = nil
|
|
|
|
sysstart = tonumber(sysstart)
|
|
|
|
sysend = tonumber(sysend)
|
2020-08-04 21:49:13 +00:00
|
|
|
if sysstart ~= maxsyscall + 1 then
|
|
|
|
abort(1, "syscall number out of sync, missing " ..
|
|
|
|
maxsyscall + 1)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
sysnum = tonumber(sysnum)
|
|
|
|
if sysnum ~= maxsyscall + 1 then
|
|
|
|
abort(1, "syscall number out of sync, missing " ..
|
|
|
|
maxsyscall + 1)
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Split flags
|
|
|
|
for flag in allflags:gmatch("([^|]+)") do
|
|
|
|
if known_flags[flag] == nil then
|
|
|
|
abort(1, "Unknown flag " .. flag .. " for " .. sysnum)
|
|
|
|
end
|
|
|
|
flags = flags | known_flags[flag]
|
|
|
|
end
|
|
|
|
|
2021-01-26 18:27:44 +00:00
|
|
|
if (flags & get_mask({"RESERVED", "UNIMPL"})) == 0 and sysnum == nil then
|
|
|
|
abort(1, "Range only allowed with RESERVED and UNIMPL: " .. line)
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if (flags & known_flags.NOTSTATIC) ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
thr_flag = "SY_THR_ABSENT"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Strip earlier bits out, leave declaration + alt
|
|
|
|
line = line:gsub("^.+" .. allflags .. "%s*", "")
|
|
|
|
|
|
|
|
local decl_fnd = line:find("^{") ~= nil
|
|
|
|
if decl_fnd and line:find("}") == nil then
|
|
|
|
abort(1, "Malformed, no closing brace: " .. line)
|
|
|
|
end
|
|
|
|
|
|
|
|
local decl, alt
|
|
|
|
if decl_fnd then
|
|
|
|
line = line:gsub("^{", "")
|
|
|
|
decl, alt = line:match("([^}]*)}[%s]*(.*)$")
|
|
|
|
else
|
|
|
|
alt = line
|
|
|
|
end
|
|
|
|
|
|
|
|
if decl == nil and alt == nil then
|
|
|
|
abort(1, "Malformed bits: " .. line)
|
|
|
|
end
|
|
|
|
|
|
|
|
local funcalias, funcomment, argalias, rettype, args
|
|
|
|
if not decl_fnd and alt ~= nil and alt ~= "" then
|
|
|
|
-- Peel off one entry for name
|
|
|
|
funcname = trim(alt:match("^([^%s]+)"), nil)
|
|
|
|
alt = alt:gsub("^([^%s]+)[%s]*", "")
|
|
|
|
end
|
|
|
|
-- Do we even need it?
|
|
|
|
if flags & get_mask({"OBSOL", "UNIMPL"}) ~= 0 then
|
|
|
|
local NF = 0
|
|
|
|
for _ in orig:gmatch("[^%s]+") do
|
|
|
|
NF = NF + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
funcomment = funcname or ''
|
|
|
|
if NF < 6 then
|
|
|
|
funcomment = funcomment .. " " .. alt
|
|
|
|
end
|
|
|
|
|
|
|
|
funcomment = trim(funcomment)
|
|
|
|
|
|
|
|
-- if funcname ~= nil then
|
|
|
|
-- else
|
|
|
|
-- funcomment = trim(alt)
|
|
|
|
-- end
|
|
|
|
goto skipalt
|
|
|
|
end
|
|
|
|
|
|
|
|
if alt ~= nil and alt ~= "" then
|
|
|
|
local altExpr = "^([^%s]+)%s+([^%s]+)%s+([^%s]+)"
|
|
|
|
funcalias, argalias, rettype = alt:match(altExpr)
|
|
|
|
funcalias = trim(funcalias)
|
|
|
|
if funcalias == nil or argalias == nil or rettype == nil then
|
|
|
|
abort(1, "Malformed alt: " .. line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if decl_fnd then
|
|
|
|
-- Don't clobber rettype set in the alt information
|
|
|
|
if rettype == nil then
|
|
|
|
rettype = "int"
|
|
|
|
end
|
|
|
|
-- Peel off the return type
|
|
|
|
syscallret = line:match("([^%s]+)%s")
|
|
|
|
line = line:match("[^%s]+%s(.+)")
|
|
|
|
-- Pointer incoming
|
|
|
|
if line:sub(1,1) == "*" then
|
|
|
|
syscallret = syscallret .. " "
|
|
|
|
end
|
|
|
|
while line:sub(1,1) == "*" do
|
|
|
|
line = line:sub(2)
|
|
|
|
syscallret = syscallret .. "*"
|
|
|
|
end
|
|
|
|
funcname = line:match("^([^(]+)%(")
|
|
|
|
if funcname == nil then
|
|
|
|
abort(1, "Not a signature? " .. line)
|
|
|
|
end
|
|
|
|
args = line:match("^[^(]+%((.+)%)[^)]*$")
|
2019-12-11 19:32:52 +00:00
|
|
|
args = trim(args, '[,%s]')
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
::skipalt::
|
|
|
|
|
|
|
|
if funcname == nil then
|
|
|
|
funcname = funcalias
|
|
|
|
end
|
|
|
|
|
|
|
|
funcname = trim(funcname)
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if config.obsol_dict[funcname] then
|
2021-11-22 22:36:57 +00:00
|
|
|
local compat_prefix = ""
|
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & v.mask ~= 0 then
|
|
|
|
compat_prefix = v.prefix
|
2021-11-22 22:36:57 +00:00
|
|
|
goto obsol_compat_done
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::obsol_compat_done::
|
|
|
|
args = nil
|
2023-04-20 22:15:57 +00:00
|
|
|
flags = known_flags.OBSOL
|
2021-11-22 22:36:57 +00:00
|
|
|
funcomment = compat_prefix .. funcname
|
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
if config.unimpl_dict[funcname] then
|
|
|
|
flags = known_flags.UNIMPL
|
2021-11-22 22:36:57 +00:00
|
|
|
funcomment = funcname
|
|
|
|
end
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
sysflags = "0"
|
|
|
|
|
|
|
|
-- NODEF events do not get audited
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.NODEF ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
auditev = 'AUE_NULL'
|
|
|
|
end
|
|
|
|
|
|
|
|
-- If applicable; strip the ABI prefix from the name
|
|
|
|
local stripped_name = strip_abi_prefix(funcname)
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.CAPENABLED ~= 0 or
|
|
|
|
config.capenabled[funcname] ~= nil or
|
|
|
|
config.capenabled[stripped_name] ~= nil then
|
2019-11-17 14:08:19 +00:00
|
|
|
sysflags = "SYF_CAPENABLED"
|
|
|
|
end
|
|
|
|
|
|
|
|
local funcargs = {}
|
2021-11-22 22:36:58 +00:00
|
|
|
local changes_abi = false
|
2019-11-17 14:08:19 +00:00
|
|
|
if args ~= nil then
|
2021-11-22 22:36:58 +00:00
|
|
|
funcargs, changes_abi = process_args(args)
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
if config.sys_no_abi_change[funcname] then
|
2021-11-22 22:36:58 +00:00
|
|
|
changes_abi = false
|
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
local noproto = config.abi_flags ~= "" and not changes_abi
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
local argprefix = ''
|
2021-11-22 22:36:58 +00:00
|
|
|
local funcprefix = ''
|
2019-11-17 14:08:19 +00:00
|
|
|
if abi_changes("pointer_args") then
|
|
|
|
for _, v in ipairs(funcargs) do
|
2023-04-20 22:15:57 +00:00
|
|
|
if isptrtype(v.type) then
|
|
|
|
if config.sys_no_abi_change[funcname] then
|
2021-11-22 22:36:58 +00:00
|
|
|
print("WARNING: " .. funcname ..
|
|
|
|
" in syscall_no_abi_change, but pointers args are present")
|
|
|
|
end
|
2021-11-22 22:36:58 +00:00
|
|
|
changes_abi = true
|
2019-11-17 14:08:19 +00:00
|
|
|
goto ptrfound
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::ptrfound::
|
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
if config.sys_abi_change[funcname] then
|
2021-11-22 22:36:58 +00:00
|
|
|
changes_abi = true
|
|
|
|
end
|
2021-11-22 22:36:58 +00:00
|
|
|
if changes_abi then
|
|
|
|
-- argalias should be:
|
|
|
|
-- COMPAT_PREFIX + ABI Prefix + funcname
|
2023-04-20 22:15:57 +00:00
|
|
|
argprefix = config.abi_func_prefix
|
|
|
|
funcprefix = config.abi_func_prefix
|
2021-11-22 22:36:58 +00:00
|
|
|
funcalias = funcprefix .. funcname
|
|
|
|
noproto = false
|
|
|
|
end
|
2021-11-22 22:36:58 +00:00
|
|
|
if funcname ~= nil then
|
|
|
|
funcname = funcprefix .. funcname
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
if funcalias == nil or funcalias == "" then
|
|
|
|
funcalias = funcname
|
|
|
|
end
|
|
|
|
|
|
|
|
if argalias == nil and funcname ~= nil then
|
2021-11-22 22:36:58 +00:00
|
|
|
argalias = funcname .. "_args"
|
2019-11-17 14:08:19 +00:00
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
local mask = v.mask
|
2019-11-17 14:08:19 +00:00
|
|
|
if (flags & mask) ~= 0 then
|
|
|
|
-- Multiple aliases doesn't seem to make
|
|
|
|
-- sense.
|
2023-04-20 22:15:57 +00:00
|
|
|
argalias = v.prefix .. argalias
|
2019-11-17 14:08:19 +00:00
|
|
|
goto out
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::out::
|
|
|
|
elseif argalias ~= nil then
|
|
|
|
argalias = argprefix .. argalias
|
|
|
|
end
|
|
|
|
|
|
|
|
local ncompatflags = get_mask({"STD", "NODEF", "NOARGS", "NOPROTO",
|
|
|
|
"NOSTD"})
|
|
|
|
local compatflags = get_mask_pat("COMPAT.*")
|
2023-04-20 22:15:57 +00:00
|
|
|
if noproto or flags & known_flags.SYSMUX ~= 0 then
|
|
|
|
flags = flags | known_flags.NOPROTO;
|
2021-11-22 22:36:58 +00:00
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.OBSOL ~= 0 then
|
2021-11-22 22:36:57 +00:00
|
|
|
handle_obsol(sysnum, funcname, funcomment)
|
2023-04-20 22:15:57 +00:00
|
|
|
elseif flags & known_flags.RESERVED ~= 0 then
|
2021-11-22 22:36:57 +00:00
|
|
|
handle_reserved(sysnum, sysstart, sysend)
|
2023-04-20 22:15:57 +00:00
|
|
|
elseif flags & known_flags.UNIMPL ~= 0 then
|
2021-11-22 22:36:57 +00:00
|
|
|
handle_unimpl(sysnum, sysstart, sysend, funcomment)
|
|
|
|
elseif flags & compatflags ~= 0 then
|
2023-04-20 22:15:57 +00:00
|
|
|
if flags & known_flags.STD ~= 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
abort(1, "Incompatible COMPAT/STD: " .. line)
|
|
|
|
end
|
|
|
|
handle_compat(sysnum, thr_flag, flags, sysflags, rettype,
|
|
|
|
auditev, funcname, funcalias, funcargs, argalias)
|
|
|
|
elseif flags & ncompatflags ~= 0 then
|
|
|
|
handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
|
|
|
|
auditev, syscallret, funcname, funcalias, funcargs,
|
|
|
|
argalias)
|
|
|
|
else
|
|
|
|
abort(1, "Bad flags? " .. line)
|
|
|
|
end
|
|
|
|
|
2020-08-04 21:49:13 +00:00
|
|
|
if sysend ~= nil then
|
|
|
|
maxsyscall = sysend
|
|
|
|
elseif sysnum ~= nil then
|
|
|
|
maxsyscall = sysnum
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Entry point
|
|
|
|
|
|
|
|
if #arg < 1 or #arg > 2 then
|
2021-01-27 18:12:33 +00:00
|
|
|
error("usage: " .. arg[0] .. " input-file <config-file>")
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local sysfile, configfile = arg[1], arg[2]
|
|
|
|
|
|
|
|
-- process_config either returns nil and a message, or a
|
|
|
|
-- table that we should merge into the global config
|
|
|
|
if configfile ~= nil then
|
2021-01-27 18:12:33 +00:00
|
|
|
local res = assert(process_config(configfile))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
for k, v in pairs(res) do
|
|
|
|
if v ~= config[k] then
|
|
|
|
config[k] = v
|
|
|
|
config_modified[k] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
local compat_set = config.compat_set
|
2021-12-09 04:37:28 +00:00
|
|
|
if compat_set ~= "" then
|
|
|
|
if not compat_option_sets[compat_set] then
|
|
|
|
abort(1, "Undefined compat set: " .. compat_set)
|
|
|
|
end
|
|
|
|
|
|
|
|
compat_options = compat_option_sets[compat_set]
|
|
|
|
else
|
|
|
|
compat_options = {}
|
|
|
|
end
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
-- We ignore errors here if we're relying on the default configuration.
|
2023-04-20 22:15:57 +00:00
|
|
|
if not config_modified.capenabled then
|
|
|
|
config.capenabled = grab_capenabled(config.capabilities_conf,
|
|
|
|
config_modified.capabilities_conf == nil)
|
|
|
|
elseif config.capenabled ~= "" then
|
2019-11-17 14:08:19 +00:00
|
|
|
-- Due to limitations in the config format mostly, we'll have a comma
|
|
|
|
-- separated list. Parse it into lines
|
|
|
|
local capenabled = {}
|
2023-04-20 22:15:57 +00:00
|
|
|
-- print("here: " .. config.capenabled)
|
|
|
|
for sysc in config.capenabled:gmatch("([^,]+)") do
|
2019-11-17 14:08:19 +00:00
|
|
|
capenabled[sysc] = true
|
|
|
|
end
|
2023-04-20 22:15:57 +00:00
|
|
|
config.capenabled = capenabled
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
process_compat()
|
|
|
|
process_abi_flags()
|
2021-11-22 22:36:58 +00:00
|
|
|
process_syscall_abi_change()
|
2021-11-22 22:36:57 +00:00
|
|
|
process_obsol()
|
|
|
|
process_unimpl()
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
if not lfs.mkdir(tmpspace) then
|
2021-01-27 18:12:33 +00:00
|
|
|
error("Failed to create tempdir " .. tmpspace)
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2021-01-27 18:12:33 +00:00
|
|
|
-- XXX Revisit the error handling here, we should probably move the rest of this
|
|
|
|
-- into a function that we pcall() so we can catch the errors and clean up
|
|
|
|
-- gracefully.
|
2019-11-17 14:08:19 +00:00
|
|
|
for _, v in ipairs(temp_files) do
|
|
|
|
local tmpname = tmpspace .. v
|
|
|
|
files[v] = io.open(tmpname, "w+")
|
2021-01-27 18:12:33 +00:00
|
|
|
-- XXX Revisit these with a pcall() + error handler
|
|
|
|
if not files[v] then
|
|
|
|
abort(1, "Failed to open temp file: " .. tmpname)
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2020-01-10 18:22:14 +00:00
|
|
|
for _, v in ipairs(output_files) do
|
|
|
|
local tmpname = tmpspace .. v
|
|
|
|
files[v] = io.open(tmpname, "w+")
|
2021-01-27 18:12:33 +00:00
|
|
|
-- XXX Revisit these with a pcall() + error handler
|
|
|
|
if not files[v] then
|
|
|
|
abort(1, "Failed to open temp output file: " .. tmpname)
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Write out all of the preamble bits
|
|
|
|
write_line("sysent", string.format([[
|
|
|
|
|
|
|
|
/* The casts are bogus but will do for now. */
|
|
|
|
struct sysent %s[] = {
|
2023-04-20 22:15:57 +00:00
|
|
|
]], config.switchname))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("syssw", string.format([[/*
|
|
|
|
* System call switch table.
|
|
|
|
*
|
|
|
|
* DO NOT EDIT-- this file is automatically %s.
|
|
|
|
* $%s$
|
|
|
|
*/
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
]], generated_tag, config.os_id_keyword))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("sysarg", string.format([[/*
|
|
|
|
* System call prototypes.
|
|
|
|
*
|
|
|
|
* DO NOT EDIT-- this file is automatically %s.
|
|
|
|
* $%s$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef %s
|
|
|
|
#define %s
|
|
|
|
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/acl.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;
|
|
|
|
|
2022-03-28 18:43:03 +00:00
|
|
|
#define PAD_(t) (sizeof(syscallarg_t) <= sizeof(t) ? \
|
|
|
|
0 : sizeof(syscallarg_t) - sizeof(t))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
]], generated_tag, config.os_id_keyword, config.sysproto_h,
|
|
|
|
config.sysproto_h))
|
2021-11-22 22:36:57 +00:00
|
|
|
if abi_changes("pair_64bit") then
|
|
|
|
write_line("sysarg", string.format([[
|
|
|
|
#if !defined(PAD64_REQUIRED) && !defined(__amd64__)
|
|
|
|
#define PAD64_REQUIRED
|
|
|
|
#endif
|
|
|
|
]]))
|
|
|
|
end
|
|
|
|
if abi_changes("pair_64bit") then
|
|
|
|
write_line("systrace", string.format([[
|
|
|
|
#if !defined(PAD64_REQUIRED) && !defined(__amd64__)
|
|
|
|
#define PAD64_REQUIRED
|
|
|
|
#endif
|
|
|
|
]]))
|
|
|
|
end
|
2019-11-17 14:08:19 +00:00
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
write_line(v.tmp, string.format("\n#ifdef %s\n\n", v.definition))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
write_line("sysnames", string.format([[/*
|
|
|
|
* System call names.
|
|
|
|
*
|
|
|
|
* DO NOT EDIT-- this file is automatically %s.
|
|
|
|
* $%s$
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *%s[] = {
|
2023-04-20 22:15:57 +00:00
|
|
|
]], generated_tag, config.os_id_keyword, config.namesname))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("syshdr", string.format([[/*
|
|
|
|
* System call numbers.
|
|
|
|
*
|
|
|
|
* DO NOT EDIT-- this file is automatically %s.
|
|
|
|
* $%s$
|
|
|
|
*/
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
]], generated_tag, config.os_id_keyword))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("sysmk", string.format([[# FreeBSD system call object files.
|
|
|
|
# DO NOT EDIT-- this file is automatically %s.
|
|
|
|
# $%s$
|
2023-04-20 22:15:57 +00:00
|
|
|
MIASM = ]], generated_tag, config.os_id_keyword))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("systrace", string.format([[/*
|
|
|
|
* System call argument to DTrace register array converstion.
|
|
|
|
*
|
|
|
|
* DO NOT EDIT-- this file is automatically %s.
|
|
|
|
* $%s$
|
|
|
|
* This file is part of the DTrace syscall provider.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
systrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)
|
|
|
|
{
|
2021-05-12 20:11:44 +00:00
|
|
|
int64_t *iarg = (int64_t *)uarg;
|
2021-11-22 22:36:57 +00:00
|
|
|
int a = 0;
|
2019-11-17 14:08:19 +00:00
|
|
|
switch (sysnum) {
|
2023-04-20 22:15:57 +00:00
|
|
|
]], generated_tag, config.os_id_keyword))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("systracetmp", [[static void
|
|
|
|
systrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
|
|
|
|
{
|
|
|
|
const char *p = NULL;
|
|
|
|
switch (sysnum) {
|
|
|
|
]])
|
|
|
|
|
|
|
|
write_line("systraceret", [[static void
|
|
|
|
systrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)
|
|
|
|
{
|
|
|
|
const char *p = NULL;
|
|
|
|
switch (sysnum) {
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Processing the sysfile will parse out the preprocessor bits and put them into
|
|
|
|
-- the appropriate place. Any syscall-looking lines get thrown into the sysfile
|
|
|
|
-- buffer, one per line, for later processing once they're all glued together.
|
|
|
|
process_sysfile(sysfile)
|
|
|
|
|
|
|
|
write_line("sysinc",
|
2022-03-28 18:43:03 +00:00
|
|
|
"\n#define AS(name) (sizeof(struct name) / sizeof(syscallarg_t))\n")
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
if v.count > 0 then
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("sysinc", string.format([[
|
|
|
|
|
|
|
|
#ifdef %s
|
2021-05-12 20:11:44 +00:00
|
|
|
#define %s(n, name) .sy_narg = n, .sy_call = (sy_call_t *)__CONCAT(%s, name)
|
2019-11-17 14:08:19 +00:00
|
|
|
#else
|
2020-09-25 09:34:00 +00:00
|
|
|
#define %s(n, name) .sy_narg = 0, .sy_call = (sy_call_t *)nosys
|
2019-11-17 14:08:19 +00:00
|
|
|
#endif
|
2023-04-20 22:15:57 +00:00
|
|
|
]], v.definition, v.flag:lower(), v.prefix, v.flag:lower()))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
2023-04-20 22:15:57 +00:00
|
|
|
write_line(v.dcltmp, string.format("\n#endif /* %s */\n\n",
|
|
|
|
v.definition))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
write_line("sysprotoend", string.format([[
|
|
|
|
|
|
|
|
#undef PAD_
|
|
|
|
#undef PADL_
|
|
|
|
#undef PADR_
|
|
|
|
|
|
|
|
#endif /* !%s */
|
2023-04-20 22:15:57 +00:00
|
|
|
]], config.sysproto_h))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("sysmk", "\n")
|
|
|
|
write_line("sysent", "};\n")
|
|
|
|
write_line("sysnames", "};\n")
|
|
|
|
-- maxsyscall is the highest seen; MAXSYSCALL should be one higher
|
|
|
|
write_line("syshdr", string.format("#define\t%sMAXSYSCALL\t%d\n",
|
2023-04-20 22:15:57 +00:00
|
|
|
config.syscallprefix, maxsyscall + 1))
|
2019-11-17 14:08:19 +00:00
|
|
|
write_line("systrace", [[
|
|
|
|
default:
|
|
|
|
*n_args = 0;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
]])
|
|
|
|
|
|
|
|
write_line("systracetmp", [[
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
if (p != NULL)
|
|
|
|
strlcpy(desc, p, descsz);
|
|
|
|
}
|
|
|
|
]])
|
|
|
|
|
|
|
|
write_line("systraceret", [[
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
if (p != NULL)
|
|
|
|
strlcpy(desc, p, descsz);
|
|
|
|
}
|
|
|
|
]])
|
|
|
|
|
|
|
|
-- Finish up; output
|
|
|
|
write_line("syssw", read_file("sysinc"))
|
|
|
|
write_line("syssw", read_file("sysent"))
|
|
|
|
|
2020-01-10 18:22:14 +00:00
|
|
|
write_line("sysproto", read_file("sysarg"))
|
|
|
|
write_line("sysproto", read_file("sysdcl"))
|
2019-11-17 14:08:19 +00:00
|
|
|
for _, v in pairs(compat_options) do
|
2023-04-20 22:15:57 +00:00
|
|
|
write_line("sysproto", read_file(v.tmp))
|
|
|
|
write_line("sysproto", read_file(v.dcltmp))
|
2019-11-17 14:08:19 +00:00
|
|
|
end
|
2020-01-10 18:22:14 +00:00
|
|
|
write_line("sysproto", read_file("sysaue"))
|
|
|
|
write_line("sysproto", read_file("sysprotoend"))
|
2019-11-17 14:08:19 +00:00
|
|
|
|
|
|
|
write_line("systrace", read_file("systracetmp"))
|
|
|
|
write_line("systrace", read_file("systraceret"))
|
|
|
|
|
2020-01-10 18:22:14 +00:00
|
|
|
for _, v in ipairs(output_files) do
|
|
|
|
local target = config[v]
|
|
|
|
if target ~= "/dev/null" then
|
2021-01-27 18:12:33 +00:00
|
|
|
local fh = assert(io.open(target, "w+"))
|
2020-01-10 18:22:14 +00:00
|
|
|
if fh == nil then
|
|
|
|
abort(1, "Failed to open '" .. target .. "'")
|
|
|
|
end
|
2021-01-27 18:12:33 +00:00
|
|
|
assert(fh:write(read_file(v)))
|
|
|
|
assert(fh:close())
|
2020-01-10 18:22:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-17 14:08:19 +00:00
|
|
|
cleanup()
|