Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/tools/syscalls/scripts/syscalls_map.lua
39530 views
1
#!/usr/libexec/flua
2
--
3
-- SPDX-License-Identifier: BSD-2-Clause
4
--
5
-- Copyright (c) 2024 SRI International
6
-- Copyright (c) 2024 Tyler Baxter <[email protected]>
7
-- Copyright (c) 2023 Warner Losh <[email protected]>
8
-- Copyright (c) 2019 Kyle Evans <[email protected]>
9
--
10
11
-- Setup to be a module, or ran as its own script.
12
local syscalls_map = {}
13
local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.
14
if script then
15
-- Add library root to the package path.
16
local path = arg[0]:gsub("/[^/]+.lua$", "")
17
package.path = package.path .. ";" .. path .. "/../?.lua"
18
end
19
20
local FreeBSDSyscall = require("core.freebsd-syscall")
21
local generator = require("tools.generator")
22
23
-- File has not been decided yet; config will decide file. Default defined as
24
-- /dev/null.
25
syscalls_map.file = "/dev/null"
26
27
function syscalls_map.generate(tbl, config, fh)
28
-- Grab the master system calls table.
29
local s = tbl.syscalls
30
31
-- Bind the generator to the parameter file.
32
local gen = generator:new({}, fh)
33
34
-- Write the generated preamble.
35
gen:preamble("FreeBSD system call symbols.")
36
37
gen:write(string.format("FBSDprivate_1.0 {\n"))
38
39
for _, v in pairs(s) do
40
gen:write(v.prolog)
41
if v:native() and not v.type.NODEF and not v.type.NOLIB then
42
if v.name ~= "_exit" and v.name ~= "vfork" then
43
gen:write(string.format("\t_%s;\n", v.name))
44
end
45
gen:write(string.format("\t__sys_%s;\n", v.name))
46
end
47
end
48
gen:write(tbl.epilog)
49
50
-- End
51
gen:write("};\n")
52
end
53
54
-- Entry of script:
55
if script then
56
local config = require("config")
57
58
if #arg < 1 or #arg > 2 then
59
error("usage: " .. arg[0] .. " syscall.master")
60
end
61
62
local sysfile, configfile = arg[1], arg[2]
63
64
config.merge(configfile)
65
config.mergeCompat()
66
67
-- The parsed syscall table.
68
local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}
69
70
syscalls_map.file = config.libsysmap -- change file here
71
syscalls_map.generate(tbl, config, syscalls_map.file)
72
end
73
74
-- Return the module.
75
return syscalls_map
76
77