xref: /freebsd/sys/tools/syscalls/scripts/syscalls_map.lua (revision 47ef2a131091508e049ab10cad7f91a3c1342cd9)
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 <agge@FreeBSD.org>
7-- Copyright (c) 2023 Warner Losh <imp@bsdimp.com>
8-- Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org>
9--
10
11-- Setup to be a module, or ran as its own script.
12local syscalls_map = {}
13local script = not pcall(debug.getlocal, 4, 1)	-- TRUE if script.
14if script then
15	-- Add library root to the package path.
16	local path = arg[0]:gsub("/[^/]+.lua$", "")
17	package.path = package.path .. ";" .. path .. "/../?.lua"
18end
19
20local FreeBSDSyscall = require("core.freebsd-syscall")
21local generator = require("tools.generator")
22
23-- File has not been decided yet; config will decide file.  Default defined as
24-- /dev/null.
25syscalls_map.file = "/dev/null"
26
27function 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		--print("num " .. v.num .. " name " .. v.name)
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	-- End
49	gen:write("};\n")
50end
51
52-- Entry of script:
53if script then
54	local config = require("config")
55
56	if #arg < 1 or #arg > 2 then
57		error("usage: " .. arg[0] .. " syscall.master")
58	end
59
60	local sysfile, configfile = arg[1], arg[2]
61
62	config.merge(configfile)
63	config.mergeCompat()
64
65	-- The parsed syscall table.
66	local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}
67
68	syscalls_map.file = config.libsysmap	-- change file here
69	syscalls_map.generate(tbl, config, syscalls_map.file)
70end
71
72-- Return the module.
73return syscalls_map
74