makesyscalls: handle longs in ABI compat

Replace long-derived types with their abi equivalent where
required by the target ABI. There are two cases:
 - All pointers to types that go from 64-bit to 32-bit between the
   default ABI and the target ABI.
 - Signed arguments that go from 64-bit to 32-bit (these require
   sign-extension before passing to general kernel ABIs).

This adds four new config variables: abi_long, semid_t, abi_size_t,
and abi_u_long which default to long, size_t, and u_long respectively.

Reviewed by:	kevans
This commit is contained in:
Brooks Davis 2021-11-22 22:36:57 +00:00
parent b85fb39047
commit 0a4e16446b

View File

@ -62,6 +62,10 @@ local config = {
abi_flags_mask = 0,
abi_headers = "",
abi_intptr_t = "intptr_t",
abi_size_t = "size_t",
abi_u_long = "u_long",
abi_long = "long",
abi_semid_t = "semid_t",
ptr_intptr_t_cast = "intptr_t",
}
@ -134,6 +138,16 @@ local known_abi_flags = {
value = 0x00000001,
exprs = {
"_Contains[a-z_]*_long_",
"^long [a-z0-9_]+$",
"long [*]",
"size_t [*]",
-- semid_t is not included because it is only used
-- as an argument or written out individually and
-- said writes are handled by the ksem framework.
-- Technically a sign-extension issue exists for
-- arguments, but because semid_t is actually a file
-- descriptor negative 32-bit values are invalid
-- regardless of sign-extension.
},
},
time_t_size = {
@ -603,6 +617,15 @@ local function process_args(args)
end
argtype = argtype:gsub("intptr_t", config["abi_intptr_t"])
argtype = argtype:gsub("semid_t", config["abi_semid_t"])
if isptrtype(argtype) then
argtype = argtype:gsub("size_t", config["abi_size_t"])
argtype = argtype:gsub("^long", config["abi_long"]);
argtype = argtype:gsub("^u_long", config["abi_u_long"]);
argtype = argtype:gsub("^const u_long", "const " .. config["abi_u_long"]);
elseif argtype:find("^long$") then
argtype = config["abi_long"]
end
-- XX TODO: Forward declarations? See: sysstubfwd in CheriBSD
if abi_change then