kernel: use uintptr_t for syscall arguments
We need to pass system call args using a register-width
data type and not hard-code this to u32_t.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
diff --git a/doc/reference/usermode/syscalls.rst b/doc/reference/usermode/syscalls.rst
index b59dce3..0ae042a 100644
--- a/doc/reference/usermode/syscalls.rst
+++ b/doc/reference/usermode/syscalls.rst
@@ -149,7 +149,7 @@
{
#ifdef CONFIG_USERSPACE
if (z_syscall_trap()) {
- z_arch_syscall_invoke3(*(u32_t *)&sem, *(u32_t *)&initial_count, *(u32_t *)&limit, K_SYSCALL_K_SEM_INIT);
+ z_arch_syscall_invoke3(*(uintptr_t *)&sem, *(uintptr_t *)&initial_count, *(uintptr_t *)&limit, K_SYSCALL_K_SEM_INIT);
return;
}
compiler_barrier();
diff --git a/include/arch/arc/syscall.h b/include/arch/arc/syscall.h
index 751ded8..a3b7cf2 100644
--- a/include/arch/arc/syscall.h
+++ b/include/arch/arc/syscall.h
@@ -38,9 +38,10 @@
* just for enabling CONFIG_USERSPACE on arc w/o errors.
*/
-static inline u32_t z_arch_syscall_invoke6(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6,
- u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -62,8 +63,10 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke5(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -84,8 +87,9 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke4(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -105,8 +109,9 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke3(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -124,7 +129,8 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke2(u32_t arg1, u32_t arg2, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -141,7 +147,7 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke1(u32_t arg1, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke1(uintptr_t arg1, uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r6 __asm__("r6") = call_id;
@@ -157,7 +163,7 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke0(u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke0(uintptr_t call_id)
{
register u32_t ret __asm__("r0");
register u32_t r6 __asm__("r6") = call_id;
diff --git a/include/arch/arm/syscall.h b/include/arch/arm/syscall.h
index 9ebbd20..f727fff 100644
--- a/include/arch/arm/syscall.h
+++ b/include/arch/arm/syscall.h
@@ -36,9 +36,10 @@
/* Syscall invocation macros. arm-specific machine constraints used to ensure
* args land in the proper registers.
*/
-static inline u32_t z_arch_syscall_invoke6(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6,
- u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -58,8 +59,10 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke5(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -78,8 +81,9 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke4(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -97,8 +101,9 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke3(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -114,7 +119,8 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke2(u32_t arg1, u32_t arg2, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r1 __asm__("r1") = arg2;
@@ -129,7 +135,8 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke1(u32_t arg1, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke1(uintptr_t arg1,
+ uintptr_t call_id)
{
register u32_t ret __asm__("r0") = arg1;
register u32_t r6 __asm__("r6") = call_id;
@@ -142,7 +149,7 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke0(u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke0(uintptr_t call_id)
{
register u32_t ret __asm__("r0");
register u32_t r6 __asm__("r6") = call_id;
diff --git a/include/arch/x86/ia32/syscall.h b/include/arch/x86/ia32/syscall.h
index 81d56c4..6ed00a5 100644
--- a/include/arch/x86/ia32/syscall.h
+++ b/include/arch/x86/ia32/syscall.h
@@ -34,9 +34,10 @@
* z_x86_syscall_entry_stub in userspace.S
*/
-static inline u32_t z_arch_syscall_invoke6(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6,
- u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6,
+ uintptr_t call_id)
{
u32_t ret;
@@ -52,8 +53,10 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke5(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5,
+ uintptr_t call_id)
{
u32_t ret;
@@ -65,8 +68,9 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke4(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t call_id)
{
u32_t ret;
@@ -78,8 +82,9 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke3(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3,
+ uintptr_t call_id)
{
u32_t ret;
@@ -90,7 +95,8 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke2(u32_t arg1, u32_t arg2, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t call_id)
{
u32_t ret;
@@ -102,7 +108,8 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke1(u32_t arg1, u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke1(uintptr_t arg1,
+ uintptr_t call_id)
{
u32_t ret;
@@ -114,7 +121,7 @@
return ret;
}
-static inline u32_t z_arch_syscall_invoke0(u32_t call_id)
+static inline uintptr_t z_arch_syscall_invoke0(uintptr_t call_id)
{
u32_t ret;
diff --git a/include/sys/arch_inlines.h b/include/sys/arch_inlines.h
index 824c358..6e04fad 100644
--- a/include/sys/arch_inlines.h
+++ b/include/sys/arch_inlines.h
@@ -350,7 +350,7 @@
* @param call_id System call ID
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke0(u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke0(uintptr_t call_id);
/**
* Invoke a system call with 1 argument.
@@ -362,7 +362,8 @@
* kernel-side dispatch table
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke1(u32_t arg1, u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke1(uintptr_t arg1,
+ uintptr_t call_id);
/**
* Invoke a system call with 2 arguments.
@@ -375,8 +376,8 @@
* kernel-side dispatch table
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke2(u32_t arg1, u32_t arg2,
- u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke2(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t call_id);
/**
* Invoke a system call with 3 arguments.
@@ -390,8 +391,9 @@
* kernel-side dispatch table
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke3(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke3(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3,
+ uintptr_t call_id);
/**
* Invoke a system call with 4 arguments.
@@ -406,8 +408,9 @@
* kernel-side dispatch table
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke4(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke4(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t call_id);
/**
* Invoke a system call with 5 arguments.
@@ -423,9 +426,10 @@
* kernel-side dispatch table
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke5(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5,
- u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke5(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5,
+ uintptr_t call_id);
/**
* Invoke a system call with 6 arguments.
@@ -442,9 +446,10 @@
* kernel-side dispatch table
* @return Return value of the system call. Void system calls return 0 here.
*/
-static inline u32_t z_arch_syscall_invoke6(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6,
- u32_t call_id);
+static inline uintptr_t z_arch_syscall_invoke6(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6,
+ uintptr_t call_id);
/**
* Indicate whether we are currently running in user mode
diff --git a/include/syscall.h b/include/syscall.h
index a9dea2c..28b6227 100644
--- a/include/syscall.h
+++ b/include/syscall.h
@@ -83,9 +83,10 @@
* return void
*
*/
-typedef u32_t (*_k_syscall_handler_t)(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6,
- void *ssf);
+typedef uintptr_t (*_k_syscall_handler_t)(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6,
+ void *ssf);
/* True if a syscall function must trap to the kernel, usually a
* compile-time decision.
diff --git a/kernel/userspace.c b/kernel/userspace.c
index 8064d17..3dce339 100644
--- a/kernel/userspace.c
+++ b/kernel/userspace.c
@@ -20,6 +20,7 @@
#include <app_memory/app_memdomain.h>
#include <sys/libc-hooks.h>
#include <sys/mutex.h>
+#include <inttypes.h>
#ifdef Z_LIBC_PARTITION_EXISTS
K_APPMEM_PARTITION_DEFINE(z_libc_partition);
@@ -753,16 +754,19 @@
* Default handlers if otherwise unimplemented
*/
-static u32_t handler_bad_syscall(u32_t bad_id, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
+static uintptr_t handler_bad_syscall(uintptr_t bad_id, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6,
+ void *ssf)
{
- LOG_ERR("Bad system call id %u invoked", bad_id);
+ LOG_ERR("Bad system call id %" PRIuPTR " invoked", bad_id);
z_arch_syscall_oops(_current_cpu->syscall_frame);
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
}
-static u32_t handler_no_syscall(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
+static uintptr_t handler_no_syscall(uintptr_t arg1, uintptr_t arg2,
+ uintptr_t arg3, uintptr_t arg4,
+ uintptr_t arg5, uintptr_t arg6, void *ssf)
{
LOG_ERR("Unimplemented system call");
z_arch_syscall_oops(_current_cpu->syscall_frame);
diff --git a/scripts/gen_syscalls.py b/scripts/gen_syscalls.py
index 3fc9f09..0b070b4 100755
--- a/scripts/gen_syscalls.py
+++ b/scripts/gen_syscalls.py
@@ -64,7 +64,7 @@
#ifndef _ASMLANGUAGE
-#include <zephyr/types.h>
+#include <stdint.h>
#endif /* _ASMLANGUAGE */
@@ -107,14 +107,14 @@
"""
handler_template = """
-extern u32_t z_hdlr_%s(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6, void *ssf);
+extern uintptr_t z_hdlr_%s(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3,
+ uintptr_t arg4, uintptr_t arg5, uintptr_t arg6, void *ssf);
"""
weak_template = """
__weak ALIAS_OF(handler_no_syscall)
-u32_t %s(u32_t arg1, u32_t arg2, u32_t arg3,
- u32_t arg4, u32_t arg5, u32_t arg6, void *ssf);
+uintptr_t %s(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3,
+ uintptr_t arg4, uintptr_t arg5, uintptr_t arg6, void *ssf);
"""
@@ -149,7 +149,7 @@
# but it doesn't matter as long as they are consistently
# generated.
def union_decl(type):
- return "union { struct { u32_t lo, hi; } split; %s val; }" % type
+ return "union { struct { uintptr_t lo, hi; } split; %s val; }" % type
def wrapper_defs(func_name, func_type, args):
ret64 = func_type in types64
@@ -163,10 +163,10 @@
mrsh_args.append("parm%d.split.hi" % nsplit)
nsplit += 1
else:
- mrsh_args.append("*(u32_t *)&" + argname)
+ mrsh_args.append("*(uintptr_t *)&" + argname)
if ret64:
- mrsh_args.append("(u32_t)&ret64")
+ mrsh_args.append("(uintptr_t)&ret64")
decl_arglist = ", ".join([" ".join(argrec) for argrec in args])
@@ -183,10 +183,10 @@
wrap += "\t\t" + "parm%d.val = %s;\n" % (parmnum, argname)
if len(mrsh_args) > 6:
- wrap += "\t\t" + "u32_t more[] = {\n"
+ wrap += "\t\t" + "uintptr_t more[] = {\n"
wrap += "\t\t\t" + (",\n\t\t\t".join(mrsh_args[5:])) + "\n"
wrap += "\t\t" + "};\n"
- mrsh_args[5:] = ["(u32_t) &more"]
+ mrsh_args[5:] = ["(uintptr_t) &more"]
syscall_id = "K_SYSCALL_" + func_name.upper()
invoke = ("z_arch_syscall_invoke%d(%s)"
@@ -225,12 +225,12 @@
if mrsh_num < 5 or total <= 6:
return "arg%d" % mrsh_num
else:
- return "(((u32_t *)more)[%d])" % (mrsh_num - 5)
+ return "(((uintptr_t *)more)[%d])" % (mrsh_num - 5)
def marshall_defs(func_name, func_type, args):
mrsh_name = "z_mrsh_" + func_name
- nmrsh = 0 # number of marshalled u32_t parameter
+ nmrsh = 0 # number of marshalled uintptr_t parameter
vrfy_parms = [] # list of (arg_num, mrsh_or_parm_num, bool_is_split)
split_parms = [] # list of a (arg_num, mrsh_num) for each split
for i, (argtype, _) in enumerate(args):
@@ -249,11 +249,11 @@
decl_arglist = ", ".join([" ".join(argrec) for argrec in args])
mrsh = "extern %s z_vrfy_%s(%s);\n" % (func_type, func_name, decl_arglist)
- mrsh += "u32_t %s(u32_t arg0, u32_t arg1, u32_t arg2,\n" % mrsh_name
+ mrsh += "uintptr_t %s(uintptr_t arg0, uintptr_t arg1, uintptr_t arg2,\n" % mrsh_name
if nmrsh <= 6:
- mrsh += "\t\t" + "u32_t arg3, u32_t arg4, u32_t arg5, void *ssf)\n"
+ mrsh += "\t\t" + "uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, void *ssf)\n"
else:
- mrsh += "\t\t" + "u32_t arg3, u32_t arg4, void *more, void *ssf)\n"
+ mrsh += "\t\t" + "uintptr_t arg3, uintptr_t arg4, void *more, void *ssf)\n"
mrsh += "{\n"
mrsh += "\t" + "_current_cpu->syscall_frame = ssf;\n"
@@ -262,7 +262,7 @@
if nmrsh > 6:
mrsh += ("\tZ_OOPS(Z_SYSCALL_MEMORY_READ(more, "
- + str(nmrsh - 6) + " * sizeof(u32_t)));\n")
+ + str(nmrsh - 6) + " * sizeof(uintptr_t)));\n")
for i, split_rec in enumerate(split_parms):
arg_num, mrsh_num = split_rec
@@ -293,7 +293,7 @@
mrsh += "\t" + "*%s = ret;\n" % ptr
mrsh += "\t" + "return 0;\n"
else:
- mrsh += "\t" + "return (u32_t) ret;\n"
+ mrsh += "\t" + "return (uintptr_t) ret;\n"
mrsh += "}\n"
@@ -384,7 +384,7 @@
if not name in noweak])
# The "noweak" ones just get a regular declaration
- weak_defines += "\n".join(["extern u32_t %s(u32_t arg1, u32_t arg2, u32_t arg3, u32_t arg4, u32_t arg5, u32_t arg6, void *ssf);"
+ weak_defines += "\n".join(["extern uintptr_t %s(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6, void *ssf);"
% s for s in noweak])
fp.write(table_template % (weak_defines,