Unlike assertions, these APIs are active at all times. The kernel will treat these errors in the same way as fatal CPU exceptions. Ultimately, the policy of what to do with these errors is implemented in _SysFatalErrorHandler. If the archtecture supports it, a real CPU exception can be triggered which will provide a complete register dump and PC value when the problem occurs. This will provide more helpful information than a fake exception stack frame (_default_esf) passed to the arch-specific exception handling code. Issue: ZEP-843 Change-Id: I8f136905c05bb84772e1c5ed53b8e920d24eb6fd Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
56 lines
1.4 KiB
C
56 lines
1.4 KiB
C
/*
|
|
* Copyright (c) 2012-2014 Wind River Systems, Inc.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @brief Compiler stack protection (kernel part)
|
|
*
|
|
* This module provides functions to support compiler stack protection
|
|
* using canaries. This feature is enabled with configuration
|
|
* CONFIG_STACK_CANARIES=y.
|
|
*
|
|
* When this feature is enabled, the compiler generated code refers to
|
|
* function __stack_chk_fail and global variable __stack_chk_guard.
|
|
*/
|
|
|
|
#include <toolchain.h> /* compiler specific configurations */
|
|
|
|
#include <kernel_structs.h>
|
|
#include <toolchain.h>
|
|
#include <sections.h>
|
|
#include <kernel.h>
|
|
|
|
/**
|
|
*
|
|
* @brief Stack canary error handler
|
|
*
|
|
* This function is invoked when a stack canary error is detected.
|
|
*
|
|
* @return Does not return
|
|
*/
|
|
void FUNC_NORETURN _StackCheckHandler(void)
|
|
{
|
|
/* Stack canary error is a software fatal condition; treat it as such.
|
|
*/
|
|
_k_except_reason(_NANO_ERR_STACK_CHK_FAIL);
|
|
}
|
|
|
|
/* Global variable */
|
|
|
|
/*
|
|
* Symbol referenced by GCC compiler generated code for canary value.
|
|
* The canary value gets initialized in _Cstart().
|
|
*/
|
|
void __noinit *__stack_chk_guard;
|
|
|
|
/**
|
|
*
|
|
* @brief Referenced by GCC compiler generated code
|
|
*
|
|
* This routine is invoked when a stack canary error is detected, indicating
|
|
* a buffer overflow or stack corruption problem.
|
|
*/
|
|
FUNC_ALIAS(_StackCheckHandler, __stack_chk_fail, void);
|