1 /* 2 * FreeRTOS Kernel V10.2.1 3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 * this software and associated documentation files (the "Software"), to deal in 7 * the Software without restriction, including without limitation the rights to 8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 * the Software, and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in all 13 * copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * http://www.FreeRTOS.org 23 * http://aws.amazon.com/freertos 24 * 25 * 1 tab == 4 spaces! 26 */ 27 28 #ifndef STACK_MACROS_H 29 #define STACK_MACROS_H 30 31 /* 32 * Call the stack overflow hook function if the stack of the task being swapped 33 * out is currently overflowed, or looks like it might have overflowed in the 34 * past. 35 * 36 * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check 37 * the current stack state only - comparing the current top of stack value to 38 * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 39 * will also cause the last few stack bytes to be checked to ensure the value 40 * to which the bytes were set when the task was created have not been 41 * overwritten. Note this second test does not guarantee that an overflowed 42 * stack will always be recognised. 43 */ 44 45 /*-----------------------------------------------------------*/ 46 47 #if( configCHECK_FOR_STACK_OVERFLOW == 0 ) 48 49 /* FreeRTOSConfig.h is not set to check for stack overflows. */ 50 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() 51 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 52 53 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */ 54 /*-----------------------------------------------------------*/ 55 56 #if( configCHECK_FOR_STACK_OVERFLOW == 1 ) 57 58 /* FreeRTOSConfig.h is only set to use the first method of 59 overflow checking. */ 60 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 61 62 #endif 63 /*-----------------------------------------------------------*/ 64 65 #if 0 // ( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) ) 66 67 /* Only the current stack state is to be checked. */ 68 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ 69 { \ 70 /* Is the currently saved stack pointer within the stack limit? */ \ 71 if( pxCurrentTCB[ xPortGetCoreID() ]->pxTopOfStack <= pxCurrentTCB[ xPortGetCoreID() ]->pxStack ) \ 72 { \ 73 vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB[ xPortGetCoreID() ], pxCurrentTCB[ xPortGetCoreID() ]->pcTaskName ); \ 74 } \ 75 } 76 #else 77 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() 78 #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */ 79 /*-----------------------------------------------------------*/ 80 81 #if 0 // ( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) ) 82 83 /* Only the current stack state is to be checked. */ 84 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ 85 { \ 86 \ 87 /* Is the currently saved stack pointer within the stack limit? */ \ 88 if( pxCurrentTCB[ xPortGetCoreID() ]->pxTopOfStack >= pxCurrentTCB[ xPortGetCoreID() ]->pxEndOfStack ) \ 89 { \ 90 vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB[ xPortGetCoreID() ], pxCurrentTCB[ xPortGetCoreID() ]->pcTaskName ); \ 91 } \ 92 } 93 #else 94 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() 95 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ 96 /*-----------------------------------------------------------*/ 97 98 #if 0 // ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) 99 100 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ 101 { \ 102 static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 103 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 104 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 105 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 106 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 107 \ 108 \ 109 /* Has the extremity of the task stack ever been written over? */ \ 110 if( memcmp( ( void * ) pxCurrentTCB[ xPortGetCoreID() ]->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 111 { \ 112 vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB[ xPortGetCoreID() ], pxCurrentTCB[ xPortGetCoreID() ]->pcTaskName ); \ 113 } \ 114 } 115 #else 116 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 117 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 118 /*-----------------------------------------------------------*/ 119 120 #if 0 // ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) 121 122 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ 123 { \ 124 int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB[ xPortGetCoreID() ]->pxEndOfStack; \ 125 static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 126 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 127 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 128 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ 129 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ 130 \ 131 \ 132 pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ 133 \ 134 /* Has the extremity of the task stack ever been written over? */ \ 135 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ 136 { \ 137 vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB[ xPortGetCoreID() ], pxCurrentTCB[ xPortGetCoreID() ]->pcTaskName ); \ 138 } \ 139 } 140 #else 141 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() 142 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ 143 144 #endif /* STACK_MACROS_H */ 145