Skip to content

Commit 586bb92

Browse files
Flavio Ceolincarlescufi
authored andcommitted
xtensa: userspace: Add syscall for user exception
Trigger exception on Xtensa requires kernel privileges. Add a new syscall that is used when ARCH_EXCEPT is invoked from userspace. Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 75936d8 commit 586bb92

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

arch/xtensa/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/arch/xtensa/arch.h)
34
set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-xtensa-le)
45
add_subdirectory(core)

arch/xtensa/core/fatal.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,24 @@ FUNC_NORETURN void arch_syscall_oops(void *ssf)
149149
z_xtensa_fatal_error(K_ERR_KERNEL_OOPS, esf);
150150
CODE_UNREACHABLE;
151151
}
152+
153+
#ifdef CONFIG_USERSPACE
154+
void z_impl_xtensa_user_fault(unsigned int reason)
155+
{
156+
if ((_current->base.user_options & K_USER) != 0) {
157+
if ((reason != K_ERR_KERNEL_OOPS) &&
158+
(reason != K_ERR_STACK_CHK_FAIL)) {
159+
reason = K_ERR_KERNEL_OOPS;
160+
}
161+
}
162+
xtensa_arch_except(reason);
163+
}
164+
165+
static void z_vrfy_xtensa_user_fault(unsigned int reason)
166+
{
167+
z_impl_xtensa_user_fault(reason);
168+
}
169+
170+
#include <syscalls/xtensa_user_fault_mrsh.c>
171+
172+
#endif /* CONFIG_USERSPACE */

include/zephyr/arch/xtensa/arch.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <zephyr/arch/common/sys_io.h>
2424
#include <zephyr/arch/common/ffs.h>
2525
#include <zephyr/sw_isr_table.h>
26+
#include <zephyr/arch/xtensa/syscall.h>
2627
#include <zephyr/arch/xtensa/thread.h>
2728
#include <zephyr/arch/xtensa/irq.h>
2829
#include <xtensa/config/core.h>
@@ -54,11 +55,31 @@ struct arch_mem_domain {
5455

5556
extern void xtensa_arch_except(int reason_p);
5657

58+
#ifdef CONFIG_USERSPACE
59+
60+
#define ARCH_EXCEPT(reason_p) do { \
61+
if (k_is_user_context()) { \
62+
arch_syscall_invoke1(reason_p, \
63+
K_SYSCALL_XTENSA_USER_FAULT); \
64+
} else { \
65+
xtensa_arch_except(reason_p); \
66+
} \
67+
CODE_UNREACHABLE; \
68+
} while (false)
69+
70+
#else
71+
5772
#define ARCH_EXCEPT(reason_p) do { \
5873
xtensa_arch_except(reason_p); \
5974
CODE_UNREACHABLE; \
6075
} while (false)
6176

77+
#endif
78+
79+
__syscall void xtensa_user_fault(unsigned int reason);
80+
81+
#include <syscalls/arch.h>
82+
6283
/* internal routine documented in C file, needed by IRQ_CONNECT() macro */
6384
extern void z_irq_priority_set(uint32_t irq, uint32_t prio, uint32_t flags);
6485

0 commit comments

Comments
 (0)