Path: blob/main/sys/tools/syscalls/scripts/syscalls.lua
39530 views
#!/usr/libexec/flua1--2-- SPDX-License-Identifier: BSD-2-Clause3--4-- Copyright (c) 2024 Tyler Baxter <[email protected]>5-- Copyright (c) 2023 Warner Losh <[email protected]>6-- Copyright (c) 2019 Kyle Evans <[email protected]>7--89-- Setup to be a module, or ran as its own script.10local syscalls = {}11local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.12if script then13-- Add library root to the package path.14local path = arg[0]:gsub("/[^/]+.lua$", "")15package.path = package.path .. ";" .. path .. "/../?.lua"16end1718local FreeBSDSyscall = require("core.freebsd-syscall")19local generator = require("tools.generator")2021-- File has not been decided yet; config will decide file. Default defined as22-- /dev/null.23syscalls.file = "/dev/null"2425function syscalls.generate(tbl, config, fh)26-- Grab the master system calls table.27local s = tbl.syscalls2829-- Bind the generator to the parameter file.30local gen = generator:new({}, fh)3132-- Write the generated preamble.33gen:preamble("System call names.")3435gen:write(string.format("const char *%s[] = {\n", config.namesname))3637for _, v in pairs(s) do38--print("num " .. v.num .. " name " .. v.name)39local c = v:compatLevel()4041gen:write(v.prolog);4243if v:native() then44gen:write(string.format([[45"%s", /* %d = %s */46]],47v.name, v.num, v.name))48elseif c >= 3 then49-- Lookup the info for this specific compat option.50local flag, descr51for _, opt in pairs(config.compat_options) do52if opt.compatlevel == c then53flag = opt.flag54flag = flag:lower()55descr = opt.descr56break57end58end5960gen:write(string.format([[61"%s.%s", /* %d = %s %s */62]],63flag, v.name, v.num, descr, v.name))6465elseif v.type.RESERVED then66gen:write(string.format([[67"#%d", /* %d = reserved for local use */68]],69v.num, v.num))7071elseif v.type.UNIMPL then72gen:write(string.format([[73"#%d", /* %d = %s */74]],75v.num, v.num, v.alias))7677elseif v.type.OBSOL then78gen:write(string.format([[79"obs_%s", /* %d = obsolete %s */80]],81v.name, v.num, v.name))8283end84end85gen:write(tbl.epilog)86-- End87gen:write("};\n")88end8990-- Entry of script:91if script then92local config = require("config")9394if #arg < 1 or #arg > 2 then95error("usage: " .. arg[0] .. " syscall.master")96end9798local sysfile, configfile = arg[1], arg[2]99100config.merge(configfile)101config.mergeCompat()102103-- The parsed syscall table.104local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}105106syscalls.file = config.sysnames -- change file here107syscalls.generate(tbl, config, syscalls.file)108end109110-- Return the module.111return syscalls112113114