Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/tools/syscalls/scripts/syscall_h.lua
39530 views
1
#!/usr/libexec/flua
2
--
3
-- SPDX-License-Identifier: BSD-2-Clause
4
--
5
-- Copyright (c) 2024 Tyler Baxter <[email protected]>
6
-- Copyright (c) 2023 Warner Losh <[email protected]>
7
-- Copyright (c) 2019 Kyle Evans <[email protected]>
8
--
9
10
-- Setup to be a module, or ran as its own script.
11
local syscall_h = {}
12
local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.
13
if script then
14
-- Add library root to the package path.
15
local path = arg[0]:gsub("/[^/]+.lua$", "")
16
package.path = package.path .. ";" .. path .. "/../?.lua"
17
end
18
19
local FreeBSDSyscall = require("core.freebsd-syscall")
20
local generator = require("tools.generator")
21
22
-- File has not been decided yet; config will decide file. Default defined as
23
-- /dev/null.
24
syscall_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.
29
function 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
if config.syshdr_extra then
42
gen:write(string.format("%s\n\n", config.syshdr_extra))
43
end
44
45
for _, v in pairs(s) do
46
local c = v:compatLevel()
47
if v.num > max then
48
max = v.num
49
end
50
if v.type.UNIMPL then
51
goto skip
52
elseif v.type.RESERVED then
53
goto skip
54
elseif v.type.NODEF then
55
goto skip
56
elseif v.type.STD or v.type.NOSTD or v.type.SYSMUX or
57
c >= 7 then
58
gen:write(string.format("#define\t%s%s%s\t%d\n",
59
config.syscallprefix, v:compatPrefix(), v.name,
60
v.num))
61
elseif c >= 0 then
62
local comment
63
if c == 0 then
64
comment = "obsolete"
65
elseif c == 3 then
66
comment = "old"
67
else
68
comment = "freebsd" .. c
69
end
70
gen:write(string.format("\t\t\t\t/* %d is %s %s */\n",
71
v.num, comment, v.name))
72
end
73
::skip::
74
end
75
gen:write(string.format("#define\t%sMAXSYSCALL\t%d\n",
76
config.syscallprefix, max + 1))
77
end
78
79
-- Entry of script:
80
if script then
81
local config = require("config")
82
83
if #arg < 1 or #arg > 2 then
84
error("usage: " .. arg[0] .. " syscall.master")
85
end
86
87
local sysfile, configfile = arg[1], arg[2]
88
89
config.merge(configfile)
90
config.mergeCompat()
91
92
-- The parsed system call table.
93
local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}
94
95
syscall_h.file = config.syshdr -- change file here
96
syscall_h.generate(tbl, config, syscall_h.file)
97
end
98
99
-- Return the module.
100
return syscall_h
101
102