Changeset View
Changeset View
Standalone View
Standalone View
sys/tools/makesyscalls.lua
Show All 29 Lines | |||||
-- carefully crafted modules for it that mimic interfaces provided by modules | -- carefully crafted modules for it that mimic interfaces provided by modules | ||||
-- available in ports. Currently, this script is compatible with lua from ports | -- available in ports. Currently, this script is compatible with lua from ports | ||||
-- along with the compatible luafilesystem and lua-posix modules. | -- along with the compatible luafilesystem and lua-posix modules. | ||||
local lfs = require("lfs") | local lfs = require("lfs") | ||||
local unistd = require("posix.unistd") | local unistd = require("posix.unistd") | ||||
local savesyscall = -1 | local savesyscall = -1 | ||||
local maxsyscall = -1 | local maxsyscall = -1 | ||||
local structs = {} | |||||
local generated_tag = "@" .. "generated" | local generated_tag = "@" .. "generated" | ||||
-- Default configuration; any of these may get replaced by a configuration file | -- Default configuration; any of these may get replaced by a configuration file | ||||
-- optionally specified. | -- optionally specified. | ||||
local config = { | local config = { | ||||
os_id_keyword = "FreeBSD", -- obsolete, ignored on input, not generated | os_id_keyword = "FreeBSD", -- obsolete, ignored on input, not generated | ||||
abi_func_prefix = "", | abi_func_prefix = "", | ||||
libsysmap = "/dev/null", | libsysmap = "/dev/null", | ||||
libsys_h = "/dev/null", | |||||
sysnames = "syscalls.c", | sysnames = "syscalls.c", | ||||
sysproto = "../sys/sysproto.h", | sysproto = "../sys/sysproto.h", | ||||
sysproto_h = "_SYS_SYSPROTO_H_", | sysproto_h = "_SYS_SYSPROTO_H_", | ||||
syshdr = "../sys/syscall.h", | syshdr = "../sys/syscall.h", | ||||
sysmk = "/dev/null", | sysmk = "/dev/null", | ||||
syssw = "init_sysent.c", | syssw = "init_sysent.c", | ||||
syscallprefix = "SYS_", | syscallprefix = "SYS_", | ||||
switchname = "sysent", | switchname = "sysent", | ||||
Show All 28 Lines | |||||
local cleantmp = true | local cleantmp = true | ||||
local tmpspace = "/tmp/sysent." .. unistd.getpid() .. "/" | local tmpspace = "/tmp/sysent." .. unistd.getpid() .. "/" | ||||
local output_files = { | local output_files = { | ||||
"sysnames", | "sysnames", | ||||
"syshdr", | "syshdr", | ||||
"sysmk", | "sysmk", | ||||
"libsysmap", | "libsysmap", | ||||
"libsys_h", | |||||
"syssw", | "syssw", | ||||
"systrace", | "systrace", | ||||
"sysproto", | "sysproto", | ||||
} | } | ||||
-- These ones we'll create temporary files for; generation purposes. | -- These ones we'll create temporary files for; generation purposes. | ||||
local temp_files = { | local temp_files = { | ||||
"libsys_h_type", | |||||
"libsys_h_func", | |||||
"sysaue", | "sysaue", | ||||
"sysdcl", | "sysdcl", | ||||
"syscompat", | "syscompat", | ||||
"syscompatdcl", | "syscompatdcl", | ||||
"sysent", | "sysent", | ||||
"sysinc", | "sysinc", | ||||
"sysarg", | "sysarg", | ||||
"sysprotoend", | "sysprotoend", | ||||
▲ Show 20 Lines • Show All 824 Lines • ▼ Show 20 Lines | if funcalias == "yield" then | ||||
return | return | ||||
end | end | ||||
if funcalias ~= "exit" and funcalias ~= "vfork" then | if funcalias ~= "exit" and funcalias ~= "vfork" then | ||||
write_line("libsysmap", string.format("\t_%s;\n", | write_line("libsysmap", string.format("\t_%s;\n", | ||||
funcalias)) | funcalias)) | ||||
end | end | ||||
write_line("libsysmap", string.format("\t__sys_%s;\n", | write_line("libsysmap", string.format("\t__sys_%s;\n", | ||||
funcalias)) | funcalias)) | ||||
if flags & known_flags.SYSMUX == 0 then | |||||
local argstr_type = "" | |||||
local argstr_var = "" | |||||
local comma = "" | |||||
if #funcargs == 0 then | |||||
argstr_type = "void" | |||||
argstr_var = "void" | |||||
end | end | ||||
for _, v in ipairs(funcargs) do | |||||
local argname, argtype = v.name, v.type | |||||
argstr_type = argstr_type .. comma .. argtype | |||||
argstr_var = argstr_var .. comma .. argtype .. " " .. argname | |||||
comma = ", " | |||||
-- Accumulate a list of struct types for | |||||
-- forward decls. We can't do this in | |||||
-- process_args because we don't want compat | |||||
-- types in userspace even as no-op. | |||||
if isptrtype(argtype) then | |||||
local is_struct = false | |||||
for word in argtype:gmatch("[^ *]+") do | |||||
if is_struct then | |||||
structs[word] = word | |||||
break | |||||
end | end | ||||
if word == "struct" then | |||||
is_struct = true | |||||
-- next word is the name | |||||
end | |||||
end | |||||
end | |||||
end | |||||
write_line("libsys_h_type", | |||||
string.format("typedef %s (__sys_%s_t)(%s);\n", | |||||
syscallret, funcalias, argstr_type)) | |||||
write_line("libsys_h_func", | |||||
string.format("%s __sys_%s(%s);\n", | |||||
syscallret, funcalias, argstr_var)) | |||||
end | |||||
end | |||||
end | |||||
local function handle_obsol(sysnum, funcname, comment) | local function handle_obsol(sysnum, funcname, comment) | ||||
write_line("sysent", | write_line("sysent", | ||||
"\t{ .sy_narg = 0, .sy_call = (sy_call_t *)nosys, " .. | "\t{ .sy_narg = 0, .sy_call = (sy_call_t *)nosys, " .. | ||||
".sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT },") | ".sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_ABSENT },") | ||||
align_sysent_comment(34) | align_sysent_comment(34) | ||||
write_line("sysent", string.format("/* %d = obsolete %s */\n", | write_line("sysent", string.format("/* %d = obsolete %s */\n", | ||||
sysnum, comment)) | sysnum, comment)) | ||||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | -- end | ||||
if sysend ~= nil then | if sysend ~= nil then | ||||
maxsyscall = sysend | maxsyscall = sysend | ||||
elseif sysnum ~= nil then | elseif sysnum ~= nil then | ||||
maxsyscall = sysnum | maxsyscall = sysnum | ||||
end | end | ||||
end | end | ||||
local function pairsByKeys (t, f) | |||||
local a = {} | |||||
for n in pairs(t) do table.insert(a, n) end | |||||
table.sort(a, f) | |||||
local i = 0 -- iterator variable | |||||
local iter = function () -- iterator function | |||||
i = i + 1 | |||||
if a[i] == nil then return nil | |||||
else return a[i], t[a[i]] | |||||
end | |||||
end | |||||
return iter | |||||
end | |||||
-- Entry point | -- Entry point | ||||
if #arg < 1 or #arg > 2 then | if #arg < 1 or #arg > 2 then | ||||
error("usage: " .. arg[0] .. " input-file <config-file>") | error("usage: " .. arg[0] .. " input-file <config-file>") | ||||
end | end | ||||
local sysfile, configfile = arg[1], arg[2] | local sysfile, configfile = arg[1], arg[2] | ||||
▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | |||||
write_line("libsysmap", string.format([[/* | write_line("libsysmap", string.format([[/* | ||||
* FreeBSD system call symbols. | * FreeBSD system call symbols. | ||||
* DO NOT EDIT-- this file is automatically %s. | * DO NOT EDIT-- this file is automatically %s. | ||||
*/ | */ | ||||
FBSDprivate_1.0 { | FBSDprivate_1.0 { | ||||
]], generated_tag)) | ]], generated_tag)) | ||||
write_line("libsys_h", string.format([[/* | |||||
* Public system call stubs provided by libsys. | |||||
* | |||||
* Do not use directly, include <libsys.h> instead. | |||||
* | |||||
* DO NOT EDIT-- this file is automatically %s. | |||||
*/ | |||||
#ifndef __LIBSYS_H_ | |||||
#define __LIBSYS_H_ | |||||
#include <sys/_cpuset.h> | |||||
#include <sys/_domainset.h> | |||||
#include <sys/_ffcounter.h> | |||||
#include <sys/_semaphore.h> | |||||
#include <sys/_sigaltstack.h> | |||||
#include <machine/ucontext.h> /* for mcontext_t */ | |||||
#include <sys/_ucontext.h> | |||||
#include <sys/wait.h> | |||||
]], generated_tag)) | |||||
write_line("systrace", string.format([[/* | write_line("systrace", string.format([[/* | ||||
* System call argument to DTrace register array converstion. | * System call argument to DTrace register array converstion. | ||||
* | * | ||||
* DO NOT EDIT-- this file is automatically %s. | * DO NOT EDIT-- this file is automatically %s. | ||||
* This file is part of the DTrace syscall provider. | * This file is part of the DTrace syscall provider. | ||||
*/ | */ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | default: | ||||
break; | break; | ||||
}; | }; | ||||
if (p != NULL) | if (p != NULL) | ||||
strlcpy(desc, p, descsz); | strlcpy(desc, p, descsz); | ||||
} | } | ||||
]]) | ]]) | ||||
-- Finish up; output | -- Finish up; output | ||||
table.sort(structs) | |||||
for name,_ in pairsByKeys(structs) do | |||||
write_line("libsys_h", string.format("struct %s;\n", name)) | |||||
end | |||||
write_line("libsys_h", "union semun;\n\n__BEGIN_DECLS\n") | |||||
write_line("libsys_h", read_file("libsys_h_type")) | |||||
write_line("libsys_h", "\n") | |||||
write_line("libsys_h", read_file("libsys_h_func")) | |||||
write_line("libsys_h", "__END_DECLS\n\n#endif /* __LIBSYS_H_ */\n") | |||||
write_line("syssw", read_file("sysinc")) | write_line("syssw", read_file("sysinc")) | ||||
write_line("syssw", read_file("sysent")) | write_line("syssw", read_file("sysent")) | ||||
write_line("sysproto", read_file("sysarg")) | write_line("sysproto", read_file("sysarg")) | ||||
write_line("sysproto", read_file("sysdcl")) | write_line("sysproto", read_file("sysdcl")) | ||||
for _, v in pairs(compat_options) do | for _, v in pairs(compat_options) do | ||||
write_line("sysproto", read_file(v.tmp)) | write_line("sysproto", read_file(v.tmp)) | ||||
write_line("sysproto", read_file(v.dcltmp)) | write_line("sysproto", read_file(v.dcltmp)) | ||||
Show All 20 Lines |