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