Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F156479288
D56408.id175568.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D56408.id175568.diff
View Options
diff --git a/sys/tools/syscalls/scripts/syscall_json.lua b/sys/tools/syscalls/scripts/syscall_json.lua
new file mode 100644
--- /dev/null
+++ b/sys/tools/syscalls/scripts/syscall_json.lua
@@ -0,0 +1,138 @@
+#!/usr/libexec/flua
+--
+-- SPDX-License-Identifier: BSD-2-Clause
+--
+-- Copyright (c) 2026 Warner Losh <imp@bsdimp.com>
+--
+
+-- Setup to be a module, or ran as its own script.
+local syscall_json = {}
+local script = not pcall(debug.getlocal, 4, 1) -- TRUE if script.
+if script then
+ -- Add library root to the package path.
+ local path = arg[0]:gsub("/[^/]+.lua$", "")
+ package.path = package.path .. ";" .. path .. "/../?.lua"
+end
+
+local FreeBSDSyscall = require("core.freebsd-syscall")
+local ucl = require("ucl")
+
+-- File has not been decided yet; config will decide file. Default defined as
+-- /dev/null.
+syscall_json.file = "/dev/null"
+
+-- Convert the type flags set (table with flag=true entries) to a sorted list.
+local function flagsToList(typetbl)
+ local flags = {}
+ for k, _ in pairs(typetbl) do
+ table.insert(flags, k)
+ end
+ table.sort(flags)
+ return flags
+end
+
+-- Convert a single syscall object to a plain table suitable for JSON export.
+-- Much of the data is available only as a method call.
+local function syscallToTable(v)
+ local entry = {
+ num = v.num,
+ name = v.name or "",
+ alias = v.alias or "",
+ audit = v.audit or "",
+ flags = flagsToList(v.type),
+ compat_level = v:compatLevel(),
+ compat_prefix = v:compatPrefix(),
+ symbol = v:symbol(),
+ ret = v.ret or "",
+ rettype = v.rettype or "int",
+ cap = v.cap or "0",
+ thr = v.thr or "SY_THR_STATIC",
+ changes_abi = v.changes_abi or false,
+ noproto = v.noproto or false,
+ args_size = v.args_size or "0",
+ arg_alias = v.arg_alias or "",
+ }
+
+ -- Export arguments with annotations.
+ local args = {}
+ if v.args ~= nil then
+ for _, a in ipairs(v.args) do
+ arg = {
+ type = a.type,
+ name = a.name,
+ }
+ if a.annotation ~= nil and a.annotation ~= "" then
+ arg.annotation = a.annotation
+ end
+ table.insert(args, arg)
+ end
+ end
+ entry.args = args
+
+ -- Export altname/alttag/rettype if present (loadable syscalls).
+ if v.altname ~= nil then
+ entry.altname = v.altname
+ end
+ if v.alttag ~= nil then
+ entry.alttag = v.alttag
+ end
+
+ return entry
+end
+
+function syscall_json.generate(tbl, config, fh)
+ -- Build the syscalls array.
+ local syscalls = {}
+ for _, v in pairs(tbl.syscalls) do
+ table.insert(syscalls, syscallToTable(v))
+ end
+
+ -- Build the structs data into a nicer structure
+ local structs = {}
+ if tbl.structs ~= nil then
+ for k, _ in pairs(tbl.structs) do
+ table.insert(structs, k)
+ end
+ table.sort(structs)
+ end
+
+ local root = {
+ syscalls = syscalls,
+ structs = structs,
+ }
+
+ local json = ucl.to_json(root)
+
+ -- Write to file or stdout.
+ if fh ~= nil and fh ~= "/dev/null" then
+ local f = assert(io.open(fh, "w+"))
+ assert(f:write(json))
+ assert(f:write("\n"))
+ assert(f:close())
+ else
+ io.write(json)
+ io.write("\n")
+ end
+end
+
+-- Entry of script:
+if script then
+ local config = require("config")
+
+ if #arg < 1 or #arg > 2 then
+ error("usage: " .. arg[0] .. " syscall.master [config]")
+ end
+
+ local sysfile, configfile = arg[1], arg[2]
+
+ config.merge(configfile)
+ config.mergeCompat()
+
+ -- The parsed system call table.
+ local tbl = FreeBSDSyscall:new{sysfile = sysfile, config = config}
+
+ syscall_json.generate(tbl, config, syscall_json.file)
+end
+
+-- Return the module.
+return syscall_json
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 14, 11:05 PM (5 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31609108
Default Alt Text
D56408.id175568.diff (3 KB)
Attached To
Mode
D56408: syscall: Create a script to export the data as json
Attached
Detach File
Event Timeline
Log In to Comment