base: add error checking macros
Define there options for runtime error handling: - assert on all errors (ASSERT_ON_ERRORS) - no runtime checks (no asserts, no runtime error handling) (NO_RUNTIME_CHECKS) - full runtime error handling (the default) (RUNTIME_ERROR_CHECKS) Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
b536dc20c6
commit
22b95a2047
3 changed files with 49 additions and 0 deletions
|
@ -257,6 +257,28 @@ config COMPILER_OPT
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "Error checking behavior for CHECK macro"
|
||||||
|
default RUNTIME_ERROR_CHECKS
|
||||||
|
|
||||||
|
config ASSERT_ON_ERRORS
|
||||||
|
bool "Assert on all errors"
|
||||||
|
help
|
||||||
|
Assert on errors covered with the CHECK macro.
|
||||||
|
|
||||||
|
config NO_RUNTIME_CHECKS
|
||||||
|
bool "No runtime error checks"
|
||||||
|
help
|
||||||
|
Do not do any runtime checks or asserts when using the CHECK macro.
|
||||||
|
|
||||||
|
config RUNTIME_ERROR_CHECKS
|
||||||
|
bool "Enable runtime error checks"
|
||||||
|
help
|
||||||
|
Always perform runtime checks covered with the CHECK macro. This
|
||||||
|
option is the default and the only option used during testing.
|
||||||
|
|
||||||
|
endchoice
|
||||||
|
|
||||||
menu "Build Options"
|
menu "Build Options"
|
||||||
|
|
||||||
config KERNEL_BIN_NAME
|
config KERNEL_BIN_NAME
|
||||||
|
|
|
@ -172,6 +172,7 @@ config HW_STACK_PROTECTION
|
||||||
config USERSPACE
|
config USERSPACE
|
||||||
bool "User mode threads"
|
bool "User mode threads"
|
||||||
depends on ARCH_HAS_USERSPACE
|
depends on ARCH_HAS_USERSPACE
|
||||||
|
depends on RUNTIME_ERROR_CHECKS
|
||||||
help
|
help
|
||||||
When enabled, threads may be created or dropped down to user mode,
|
When enabled, threads may be created or dropped down to user mode,
|
||||||
which has significantly restricted permissions and must interact
|
which has significantly restricted permissions and must interact
|
||||||
|
|
26
include/sys/check.h
Normal file
26
include/sys/check.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef ZEPHYR_INCLUDE_SYS_CHECK_H_
|
||||||
|
#define ZEPHYR_INCLUDE_SYS_CHECK_H_
|
||||||
|
|
||||||
|
#include <sys/__assert.h>
|
||||||
|
|
||||||
|
#if defined(CONFIG_ASSERT_ON_ERRORS)
|
||||||
|
#define CHECKIF(expr) \
|
||||||
|
__ASSERT_NO_MSG(!(expr)); \
|
||||||
|
if (0)
|
||||||
|
#elif defined(CONFIG_NO_RUNTIME_CHECKS)
|
||||||
|
#define CHECKIF(...) \
|
||||||
|
if (0)
|
||||||
|
#else
|
||||||
|
#define CHECKIF(expr) \
|
||||||
|
if (expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* ZEPHYR_INCLUDE_SYS_CHECK_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue