arch: introduce exc_handle.h
Defines some common macros and data structures for declaring text section ranges with fixup handler addresses if an exception occurs. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
a10d178078
commit
3369a5ed07
1 changed files with 45 additions and 0 deletions
45
include/exc_handle.h
Normal file
45
include/exc_handle.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Intel Corporation.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _ZEPHYR_EXC_HANDLE_H_
|
||||
#define _ZEPHYR_EXC_HANDLE_H_
|
||||
|
||||
/*
|
||||
* This is used by some architectures to define code ranges which may
|
||||
* perform operations that could generate a CPU exception that should not
|
||||
* be fatal. Instead, the exception should return but set the program
|
||||
* counter to a 'fixup' memory address which will gracefully error out.
|
||||
*
|
||||
* For example, in the case where user mode passes in a C string via
|
||||
* system call, the length of that string needs to be measured. A specially
|
||||
* written assembly language version of strlen (z_arch_user_string_len)
|
||||
* defines start and end symbols where the memory in the string is examined;
|
||||
* if this generates a fault, jumping to the fixup symbol within the same
|
||||
* function will return an error result to the caller.
|
||||
*
|
||||
* To ensure precise control of the state of registers and the stack pointer,
|
||||
* these functions need to be written in assembly.
|
||||
*
|
||||
* The arch-specific fault handling code will define an array of these
|
||||
* z_exc_handle structures and return from the exception with the PC updated
|
||||
* to the fixup address if a match is found.
|
||||
*/
|
||||
|
||||
struct z_exc_handle {
|
||||
void *start;
|
||||
void *end;
|
||||
void *fixup;
|
||||
};
|
||||
|
||||
#define Z_EXC_HANDLE(name) \
|
||||
{ &name ## _fault_start, &name ## _fault_end, &name ## _fixup }
|
||||
|
||||
#define Z_EXC_DECLARE(name) \
|
||||
extern void (*name ## _fault_start)(void); \
|
||||
extern void (*name ## _fault_end)(void); \
|
||||
extern void (*name ## _fixup)(void)
|
||||
|
||||
#endif /* _ZEPHYR_EXC_HANDLE_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue