Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
error.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 BayLibre, SAS
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_
15#define ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_
16
17#include <arch/riscv/syscall.h>
18#include <arch/riscv/exp.h>
19#include <stdbool.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#ifdef CONFIG_USERSPACE
26
27/*
28 * Kernel features like canary (software stack guard) are built
29 * with an argument to bypass the test before syscall (test if CPU
30 * is running in user or kernel) and directly execute the function.
31 * Then if this kind of code wishes to trigger a CPU exception,
32 * the implemented syscall is useless because the function is directly
33 * called even if the CPU is running in user (which happens during
34 * sanity check). To fix that, I bypass the generated test code by writing
35 * the test myself to remove the bypass ability.
36 */
37
38#define ARCH_EXCEPT(reason_p) do { \
39 if (k_is_user_context()) { \
40 arch_syscall_invoke1(reason_p, \
41 K_SYSCALL_USER_FAULT); \
42 } else { \
43 compiler_barrier(); \
44 z_impl_user_fault(reason_p); \
45 } \
46 CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ \
47 } while (false)
48#else
49/*
50 * Raise an illegal instruction exception so that mepc will hold expected value in
51 * exception handler, and generated coredump can reconstruct the failing stack.
52 * Store reason_p in register t6, marker in t5
53 */
54#define ARCH_EXCEPT_MARKER 0x00DEAD00
55#define ARCH_EXCEPT(reason_p) do { \
56 __asm__ volatile("addi t5, %[marker], 0" \
57 : : [marker] "r" (ARCH_EXCEPT_MARKER)); \
58 __asm__ volatile("addi t6, %[reason], 0" \
59 : : [reason] "r" (reason_p)); \
60 __asm__ volatile("unimp"); \
61 } while (false)
62#endif
63
64__syscall void user_fault(unsigned int reason);
65
66#include <syscalls/error.h>
67
68#ifdef __cplusplus
69}
70#endif
71
72#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_ */
RISCV specific syscall header.
void user_fault(unsigned int reason)
RISCV public exception handling.