From d3314851dfd067e6b3af0afeb5143114b0da02ce Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Tue, 14 Jan 2020 14:05:31 -0800 Subject: [PATCH] tests: userspace: test syscall irq context Interrupts should not be locked when servicing a system call, and the kernel should not think we are in an interrupt handler either. Signed-off-by: Andrew Boie --- tests/kernel/mem_protect/userspace/src/main.c | 29 ++++++++++++++++++- .../mem_protect/userspace/src/test_syscall.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index 969ebe08e1c..1e29755390a 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -1151,6 +1151,32 @@ void test_oops_stackcheck(void) test_oops(K_ERR_STACK_CHK_FAIL, K_ERR_STACK_CHK_FAIL); } +void z_impl_check_syscall_context(void) +{ + int key = irq_lock(); + + irq_unlock(key); + + /* Make sure that interrupts aren't locked when handling system calls; + * key has the previous locking state before the above irq_lock() call. + */ + zassert_true(arch_irq_unlocked(key), "irqs locked during syscall"); + + /* The kernel should not think we are in ISR context either */ + zassert_false(k_is_in_isr(), "kernel reports irq context"); +} + +static inline void z_vrfy_check_syscall_context(void) +{ + return z_impl_check_syscall_context(); +} +#include + +void test_syscall_context(void) +{ + check_syscall_context(); +} + void test_main(void) { struct k_mem_partition *parts[] = {&part0, &part1, @@ -1213,7 +1239,8 @@ void test_main(void) ztest_user_unit_test(test_oops_exception), ztest_user_unit_test(test_oops_maxint), ztest_user_unit_test(test_oops_stackcheck), - ztest_unit_test(test_object_recycle) + ztest_unit_test(test_object_recycle), + ztest_user_unit_test(test_syscall_context) ); ztest_run_test_suite(userspace); } diff --git a/tests/kernel/mem_protect/userspace/src/test_syscall.h b/tests/kernel/mem_protect/userspace/src/test_syscall.h index 3fccea83b14..8aac9a94917 100644 --- a/tests/kernel/mem_protect/userspace/src/test_syscall.h +++ b/tests/kernel/mem_protect/userspace/src/test_syscall.h @@ -10,6 +10,7 @@ __syscall void stack_info_get(char **start_addr, size_t *size); __syscall int check_perms(void *addr, size_t size, int write); __syscall void missing_syscall(void); +__syscall void check_syscall_context(void); #include