Path: blob/main/sys/tools/syscalls/scripts/syscalls_map.lua
39530 views
#!/usr/libexec/flua1--2-- SPDX-License-Identifier: BSD-2-Clause3--4-- Copyright (c) 2024 SRI International5-- Copyright (c) 2024 Tyler Baxter <[email protected]>6-- Copyright (c) 2023 Warner Losh <[email protected]>7-- Copyright (c) 2019 Kyle Evans <[email protected]>8--910-- Setup to be a module, or ran as its own script.11local syscalls_map = {}12local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.13if script then14-- Add library root to the package path.15local path = arg[0]:gsub("/[^/]+.lua$", "")16package.path = package.path .. ";" .. path .. "/../?.lua"17end1819local FreeBSDSyscall = require("core.freebsd-syscall")20local generator = require("tools.generator")2122-- File has not been decided yet; config will decide file. Default defined as23-- /dev/null.24syscalls_map.file = "/dev/null"2526function syscalls_map.generate(tbl, config, fh)27-- Grab the master system calls table.28local s = tbl.syscalls2930-- Bind the generator to the parameter file.31local gen = generator:new({}, fh)3233-- Write the generated preamble.34gen:preamble("FreeBSD system call symbols.")3536gen:write(string.format("FBSDprivate_1.0 {\n"))3738for _, v in pairs(s) do39gen:write(v.prolog)40if v:native() and not v.type.NODEF and not v.type.NOLIB then41if v.name ~= "_exit" and v.name ~= "vfork" then42gen:write(string.format("\t_%s;\n", v.name))43end44gen:write(string.format("\t__sys_%s;\n", v.name))45end46end47gen:write(tbl.epilog)4849-- End50gen:write("};\n")51end5253-- Entry of script:54if script then55local config = require("config")5657if #arg < 1 or #arg > 2 then58error("usage: " .. arg[0] .. " syscall.master")59end6061local sysfile, configfile = arg[1], arg[2]6263config.merge(configfile)64config.mergeCompat()6566-- The parsed syscall table.67local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}6869syscalls_map.file = config.libsysmap -- change file here70syscalls_map.generate(tbl, config, syscalls_map.file)71end7273-- Return the module.74return syscalls_map757677