2015-04-11 07:44:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012-2014 Wind River Systems, Inc.
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-12-04 23:09:39 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Compiler stack protection (kernel part)
|
|
|
|
*
|
2015-10-21 00:42:33 +08:00
|
|
|
* 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.
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-04-28 06:03:01 +08:00
|
|
|
#include <toolchain.h> /* compiler specific configurations */
|
2015-04-11 07:44:37 +08:00
|
|
|
|
2015-06-19 23:07:02 +08:00
|
|
|
#include <nano_private.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
#include <toolchain.h>
|
|
|
|
#include <sections.h>
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Stack canary error handler
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This function is invoked when a stack canary error is detected.
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return Does not return
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
void FUNC_NORETURN _StackCheckHandler(void)
|
|
|
|
{
|
|
|
|
/* Stack canary error is a software fatal condition; treat it as such.
|
|
|
|
*/
|
|
|
|
|
2015-05-09 06:12:56 +08:00
|
|
|
_NanoFatalErrorHandler(_NANO_ERR_STACK_CHK_FAIL, &_default_esf);
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Global variable */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Symbol referenced by GCC compiler generated code for canary value.
|
|
|
|
* The canary value gets initialized in _Cstart().
|
|
|
|
*/
|
|
|
|
void __noinit *__stack_chk_guard;
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Referenced by GCC compiler generated code
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine is invoked when a stack canary error is detected, indicating
|
|
|
|
* a buffer overflow or stack corruption problem.
|
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
FUNC_ALIAS(_StackCheckHandler, __stack_chk_fail, void);
|