]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/include/stack_macros.h
Roll up the minor changes checked into svn since V10.0.0 into new V10.0.1 ready for...
[freertos] / FreeRTOS / Source / include / stack_macros.h
1 /*\r
2  * FreeRTOS Kernel V10.0.1\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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 #ifndef STACK_MACROS_H\r
29 #define STACK_MACROS_H\r
30 \r
31 /*\r
32  * Call the stack overflow hook function if the stack of the task being swapped\r
33  * out is currently overflowed, or looks like it might have overflowed in the\r
34  * past.\r
35  *\r
36  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\r
37  * the current stack state only - comparing the current top of stack value to\r
38  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\r
39  * will also cause the last few stack bytes to be checked to ensure the value\r
40  * to which the bytes were set when the task was created have not been\r
41  * overwritten.  Note this second test does not guarantee that an overflowed\r
42  * stack will always be recognised.\r
43  */\r
44 \r
45 /*-----------------------------------------------------------*/\r
46 \r
47 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )\r
48 \r
49         /* Only the current stack state is to be checked. */\r
50         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \\r
51         {                                                                                                                                                                                                       \\r
52                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
53                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
54                 {                                                                                                                                                                                               \\r
55                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \\r
56                 }                                                                                                                                                                                               \\r
57         }\r
58 \r
59 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
60 /*-----------------------------------------------------------*/\r
61 \r
62 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )\r
63 \r
64         /* Only the current stack state is to be checked. */\r
65         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \\r
66         {                                                                                                                                                                                                       \\r
67                                                                                                                                                                                                                 \\r
68                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
69                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \\r
70                 {                                                                                                                                                                                               \\r
71                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \\r
72                 }                                                                                                                                                                                               \\r
73         }\r
74 \r
75 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
76 /*-----------------------------------------------------------*/\r
77 \r
78 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\r
79 \r
80         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \\r
81         {                                                                                                                                                                                                       \\r
82                 const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack;                                                 \\r
83                 const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5;                                                                                  \\r
84                                                                                                                                                                                                                 \\r
85                 if( ( pulStack[ 0 ] != ulCheckValue ) ||                                                                                                \\r
86                         ( pulStack[ 1 ] != ulCheckValue ) ||                                                                                            \\r
87                         ( pulStack[ 2 ] != ulCheckValue ) ||                                                                                            \\r
88                         ( pulStack[ 3 ] != ulCheckValue ) )                                                                                             \\r
89                 {                                                                                                                                                                                               \\r
90                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \\r
91                 }                                                                                                                                                                                               \\r
92         }\r
93 \r
94 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
95 /*-----------------------------------------------------------*/\r
96 \r
97 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
98 \r
99         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                          \\r
100         {                                                                                                                                                                                                                                                                       \\r
101         int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack;                                                                                                                                         \\r
102         static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
103                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
104                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
105                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
106                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };       \\r
107                                                                                                                                                                                                                                                                                 \\r
108                                                                                                                                                                                                                                                                                 \\r
109                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                 \\r
110                                                                                                                                                                                                                                                                                 \\r
111                 /* Has the extremity of the task stack ever been written over? */                                                                                                                               \\r
112                 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                   \\r
113                 {                                                                                                                                                                                                                                                               \\r
114                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                       \\r
115                 }                                                                                                                                                                                                                                                               \\r
116         }\r
117 \r
118 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
119 /*-----------------------------------------------------------*/\r
120 \r
121 /* Remove stack overflow macro if not being used. */\r
122 #ifndef taskCHECK_FOR_STACK_OVERFLOW\r
123         #define taskCHECK_FOR_STACK_OVERFLOW()\r
124 #endif\r
125 \r
126 \r
127 \r
128 #endif /* STACK_MACROS_H */\r
129 \r