1#!/usr/libexec/flua 2-- 3-- SPDX-License-Identifier: BSD-2-Clause 4-- 5-- Copyright (c) 2024 Tyler Baxter <agge@FreeBSD.org> 6-- Copyright (c) 2023 Warner Losh <imp@bsdimp.com> 7-- Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org> 8-- 9 10-- Setup to be a module, or ran as its own script. 11local syscall_h = {} 12local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script. 13if script then 14 -- Add library root to the package path. 15 local path = arg[0]:gsub("/[^/]+.lua$", "") 16 package.path = package.path .. ";" .. path .. "/../?.lua" 17end 18 19local FreeBSDSyscall = require("core.freebsd-syscall") 20local generator = require("tools.generator") 21 22-- File has not been decided yet; config will decide file. Default defined as 23-- /dev/null. 24syscall_h.file = "/dev/null" 25 26-- Libc has all the STD, NOSTD and SYSMUX system calls in it, as well as 27-- replaced system calls dating back to FreeBSD 7. We are lucky that the 28-- system call filename is just the base symbol name for it. 29function syscall_h.generate(tbl, config, fh) 30 -- Grab the master system calls table, and prepare bookkeeping for 31 -- the max system call number. 32 local s = tbl.syscalls 33 local max = 0 34 35 -- Bind the generator to the parameter file. 36 local gen = generator:new({}, fh) 37 38 -- Write the generated preamble. 39 gen:preamble("System call numbers.") 40 41 for _, v in pairs(s) do 42 local c = v:compatLevel() 43 if v.num > max then 44 max = v.num 45 end 46 if v.type.UNIMPL then 47 goto skip 48 elseif v.type.RESERVED then 49 goto skip 50 elseif v.type.NODEF then 51 goto skip 52 elseif v.type.STD or v.type.NOSTD or v.type.SYSMUX or 53 c >= 7 then 54 gen:write(string.format("#define\t%s%s%s\t%d\n", 55 config.syscallprefix, v:compatPrefix(), v.name, 56 v.num)) 57 elseif c >= 0 then 58 local comment 59 if c == 0 then 60 comment = "obsolete" 61 elseif c == 3 then 62 comment = "old" 63 else 64 comment = "freebsd" .. c 65 end 66 gen:write(string.format("\t\t\t\t/* %d is %s %s */\n", 67 v.num, comment, v.name)) 68 end 69 ::skip:: 70 end 71 gen:write(string.format("#define\t%sMAXSYSCALL\t%d\n", 72 config.syscallprefix, max + 1)) 73end 74 75-- Entry of script: 76if script then 77 local config = require("config") 78 79 if #arg < 1 or #arg > 2 then 80 error("usage: " .. arg[0] .. " syscall.master") 81 end 82 83 local sysfile, configfile = arg[1], arg[2] 84 85 config.merge(configfile) 86 config.mergeCompat() 87 88 -- The parsed system call table. 89 local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config} 90 91 syscall_h.file = config.syshdr -- change file here 92 syscall_h.generate(tbl, config, syscall_h.file) 93end 94 95-- Return the module. 96return syscall_h 97