Skip to content

Commit 7353c7f

Browse files
Andy Rossnashif
authored andcommitted
kernel/userspace: Move syscall_frame field to thread struct
The syscall exception frame was stored on the CPU struct during syscall execution, but that's not right. System calls might "feel like" exceptions, but they're actually perfectly normal kernel mode code and can be preempted and migrated between CPUs at any time. Put the field on the thread struct. Signed-off-by: Andy Ross <[email protected]>
1 parent 8153144 commit 7353c7f

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

include/kernel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,11 @@ struct k_thread {
597597
struct _mem_domain_info mem_domain_info;
598598
/** Base address of thread stack */
599599
k_thread_stack_t *stack_obj;
600+
/** current syscall frame pointer */
601+
void *syscall_frame;
600602
#endif /* CONFIG_USERSPACE */
601603

604+
602605
#if defined(CONFIG_USE_SWITCH)
603606
/* When using __switch() a few previously arch-specific items
604607
* become part of the core OS

include/kernel_structs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ struct _cpu {
110110
/* one assigned idle thread per CPU */
111111
struct k_thread *idle_thread;
112112

113-
#ifdef CONFIG_USERSPACE
114-
/* current syscall frame pointer */
115-
void *syscall_frame;
116-
#endif
117-
118113
#if (CONFIG_NUM_METAIRQ_PRIORITIES > 0) && (CONFIG_NUM_COOP_PRIORITIES > 0)
119114
/* Coop thread preempted by current metairq, or NULL */
120115
struct k_thread *metairq_preempted;

include/syscall_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ extern int z_user_string_copy(char *dst, const char *src, size_t maxlen);
259259
#define Z_OOPS(expr) \
260260
do { \
261261
if (expr) { \
262-
arch_syscall_oops(_current_cpu->syscall_frame); \
262+
arch_syscall_oops(_current->syscall_frame); \
263263
} \
264264
} while (false)
265265

kernel/userspace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ static uintptr_t handler_bad_syscall(uintptr_t bad_id, uintptr_t arg2,
760760
void *ssf)
761761
{
762762
LOG_ERR("Bad system call id %" PRIuPTR " invoked", bad_id);
763-
arch_syscall_oops(_current_cpu->syscall_frame);
763+
arch_syscall_oops(_current->syscall_frame);
764764
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
765765
}
766766

@@ -769,7 +769,7 @@ static uintptr_t handler_no_syscall(uintptr_t arg1, uintptr_t arg2,
769769
uintptr_t arg5, uintptr_t arg6, void *ssf)
770770
{
771771
LOG_ERR("Unimplemented system call");
772-
arch_syscall_oops(_current_cpu->syscall_frame);
772+
arch_syscall_oops(_current->syscall_frame);
773773
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */
774774
}
775775

scripts/gen_syscalls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def marshall_defs(func_name, func_type, args):
255255
else:
256256
mrsh += "\t\t" + "uintptr_t arg3, uintptr_t arg4, void *more, void *ssf)\n"
257257
mrsh += "{\n"
258-
mrsh += "\t" + "_current_cpu->syscall_frame = ssf;\n"
258+
mrsh += "\t" + "_current->syscall_frame = ssf;\n"
259259

260260
for unused_arg in range(nmrsh, 6):
261261
mrsh += "\t(void) arg%d;\t/* unused */\n" % unused_arg

0 commit comments

Comments
 (0)