mirror of
https://github.com/opnsense/src.git
synced 2026-06-06 15:22:34 -04:00
* main.lua replicates the functionality of makesyscalls.lua
* Individual files are generated by their associated module
* Modules can be called as standalone scripts to generate a specific
file
* Data and procedures are performed by objects instead of procedual code
* Bitmasks are replaced by declarative types
* Temporary files are no longer produced, writing is stored in memory
* Comments provide explanation to functions and semantics
Google Summer of Code 2024 Final Work Product
Co-authored-by: Warner Losh <imp@freebsd.org>
Co-authored-by: Kyle Evans <kevans@freebsd.org>
Co-authored-by: Brooks Davis <brooks@freebsd.org>
Sponsored by: Google (GSoC 24)
Pull Request: https://github.com/freebsd/freebsd-src/pull/1362
Signed-off-by: agge3 <sterspark@gmail.com>
97 lines
2.6 KiB
Lua
Executable file
97 lines
2.6 KiB
Lua
Executable file
#!/usr/libexec/flua
|
|
--
|
|
-- SPDX-License-Identifier: BSD-2-Clause
|
|
--
|
|
-- Copyright (c) 2024 Tyler Baxter <agge@FreeBSD.org>
|
|
-- Copyright (c) 2023 Warner Losh <imp@bsdimp.com>
|
|
-- Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org>
|
|
--
|
|
|
|
-- Setup to be a module, or ran as its own script.
|
|
local syscall_h = {}
|
|
local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.
|
|
if script then
|
|
-- Add library root to the package path.
|
|
local path = arg[0]:gsub("/[^/]+.lua$", "")
|
|
package.path = package.path .. ";" .. path .. "/../?.lua"
|
|
end
|
|
|
|
local FreeBSDSyscall = require("core.freebsd-syscall")
|
|
local generator = require("tools.generator")
|
|
|
|
-- File has not been decided yet; config will decide file. Default defined as
|
|
-- /dev/null.
|
|
syscall_h.file = "/dev/null"
|
|
|
|
-- Libc has all the STD, NOSTD and SYSMUX system calls in it, as well as
|
|
-- replaced system calls dating back to FreeBSD 7. We are lucky that the
|
|
-- system call filename is just the base symbol name for it.
|
|
function syscall_h.generate(tbl, config, fh)
|
|
-- Grab the master system calls table, and prepare bookkeeping for
|
|
-- the max system call number.
|
|
local s = tbl.syscalls
|
|
local max = 0
|
|
|
|
-- Bind the generator to the parameter file.
|
|
local gen = generator:new({}, fh)
|
|
|
|
-- Write the generated preamble.
|
|
gen:preamble("System call numbers.")
|
|
|
|
for _, v in pairs(s) do
|
|
local c = v:compatLevel()
|
|
if v.num > max then
|
|
max = v.num
|
|
end
|
|
if v.type.UNIMPL then
|
|
goto skip
|
|
elseif v.type.RESERVED then
|
|
goto skip
|
|
elseif v.type.NODEF then
|
|
goto skip
|
|
elseif v.type.STD or v.type.NOSTD or v.type.SYSMUX or
|
|
c >= 7 then
|
|
gen:write(string.format("#define\t%s%s%s\t%d\n",
|
|
config.syscallprefix, v:compatPrefix(), v.name,
|
|
v.num))
|
|
elseif c >= 0 then
|
|
local comment
|
|
if c == 0 then
|
|
comment = "obsolete"
|
|
elseif c == 3 then
|
|
comment = "old"
|
|
else
|
|
comment = "freebsd" .. c
|
|
end
|
|
gen:write(string.format("\t\t\t\t/* %d is %s %s */\n",
|
|
v.num, comment, v.name))
|
|
end
|
|
::skip::
|
|
end
|
|
gen:write(string.format("#define\t%sMAXSYSCALL\t%d\n",
|
|
config.syscallprefix, max + 1))
|
|
end
|
|
|
|
-- Entry of script:
|
|
if script then
|
|
local config = require("config")
|
|
|
|
if #arg < 1 or #arg > 2 then
|
|
error("usage: " .. arg[0] .. " syscall.master")
|
|
end
|
|
|
|
local sysfile, configfile = arg[1], arg[2]
|
|
|
|
config.merge(configfile)
|
|
config.mergeCompat()
|
|
config.mergeCapability()
|
|
|
|
-- The parsed system call table.
|
|
local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}
|
|
|
|
syscall_h.file = config.syshdr -- change file here
|
|
syscall_h.generate(tbl, config, syscall_h.file)
|
|
end
|
|
|
|
-- Return the module.
|
|
return syscall_h
|