Path: blob/main/sys/tools/syscalls/scripts/syscall_h.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 syscall_h = {}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.23syscall_h.file = "/dev/null"2425-- Libc has all the STD, NOSTD and SYSMUX system calls in it, as well as26-- replaced system calls dating back to FreeBSD 7. We are lucky that the27-- system call filename is just the base symbol name for it.28function syscall_h.generate(tbl, config, fh)29-- Grab the master system calls table, and prepare bookkeeping for30-- the max system call number.31local s = tbl.syscalls32local max = 03334-- Bind the generator to the parameter file.35local gen = generator:new({}, fh)3637-- Write the generated preamble.38gen:preamble("System call numbers.")3940if config.syshdr_extra then41gen:write(string.format("%s\n\n", config.syshdr_extra))42end4344for _, v in pairs(s) do45local c = v:compatLevel()46if v.num > max then47max = v.num48end49if v.type.UNIMPL then50goto skip51elseif v.type.RESERVED then52goto skip53elseif v.type.NODEF then54goto skip55elseif v.type.STD or v.type.NOSTD or v.type.SYSMUX or56c >= 7 then57gen:write(string.format("#define\t%s%s%s\t%d\n",58config.syscallprefix, v:compatPrefix(), v.name,59v.num))60elseif c >= 0 then61local comment62if c == 0 then63comment = "obsolete"64elseif c == 3 then65comment = "old"66else67comment = "freebsd" .. c68end69gen:write(string.format("\t\t\t\t/* %d is %s %s */\n",70v.num, comment, v.name))71end72::skip::73end74gen:write(string.format("#define\t%sMAXSYSCALL\t%d\n",75config.syscallprefix, max + 1))76end7778-- Entry of script:79if script then80local config = require("config")8182if #arg < 1 or #arg > 2 then83error("usage: " .. arg[0] .. " syscall.master")84end8586local sysfile, configfile = arg[1], arg[2]8788config.merge(configfile)89config.mergeCompat()9091-- The parsed system call table.92local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}9394syscall_h.file = config.syshdr -- change file here95syscall_h.generate(tbl, config, syscall_h.file)96end9798-- Return the module.99return syscall_h100101102