mirror of https://github.com/ARMmbed/mbed-os.git
Turn on main thread stack checking
Since the heap and stack are no longer shared, stack checking on the main thread can be turned back on. This allows stack overflows on the main thread to be caught quickly.pull/2402/head
parent
1d3d01f000
commit
81382ebdb2
|
@ -90,32 +90,6 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
|
|||
/* Task entry point. */
|
||||
p_TCB->ptask = task_body;
|
||||
|
||||
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
/* Set a magic word for checking of stack overflow.
|
||||
For the main thread (ID: MAIN_THREAD_ID) the stack is in a memory area shared with the
|
||||
heap, therefore the last word of the stack is a moving target.
|
||||
We want to do stack/heap collision detection instead.
|
||||
Similar applies to stack filling for the magic pattern.
|
||||
*/
|
||||
if (p_TCB->task_id != MAIN_THREAD_ID) {
|
||||
p_TCB->stack[0] = MAGIC_WORD;
|
||||
|
||||
/* Initialize stack with magic pattern. */
|
||||
if (os_stackinfo & 0x10000000U) {
|
||||
if (size > (16U+1U)) {
|
||||
for (i = ((size - 16U)/2U) - 1U; i; i--) {
|
||||
stk -= 2U;
|
||||
stk[1] = MAGIC_PATTERN;
|
||||
stk[0] = MAGIC_PATTERN;
|
||||
}
|
||||
if (--stk > p_TCB->stack) {
|
||||
*stk = MAGIC_PATTERN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Initialize stack with magic pattern. */
|
||||
if (os_stackinfo & 0x10000000U) {
|
||||
if (size > (16U+1U)) {
|
||||
|
@ -132,7 +106,6 @@ void rt_init_stack (P_TCB p_TCB, FUNCP task_body) {
|
|||
|
||||
/* Set a magic word for checking of stack overflow. */
|
||||
p_TCB->stack[0] = MAGIC_WORD;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,14 +80,6 @@
|
|||
#define OS_TIMERS 0
|
||||
#endif
|
||||
|
||||
/* If os timers macro is set to 0, there's no timer thread created, therefore
|
||||
* main thread has tid 0x01
|
||||
*/
|
||||
#if defined(OS_TIMERS) && (OS_TIMERS == 0)
|
||||
#define MAIN_THREAD_ID 0x01
|
||||
#else
|
||||
#define MAIN_THREAD_ID 0x02
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4)
|
||||
|
|
|
@ -313,22 +313,10 @@ void rt_systick (void) {
|
|||
/*--------------------------- rt_stk_check ----------------------------------*/
|
||||
|
||||
__weak void rt_stk_check (void) {
|
||||
#ifdef __MBED_CMSIS_RTOS_CM
|
||||
/* Check for stack overflow. */
|
||||
if (os_tsk.run->task_id == MAIN_THREAD_ID) {
|
||||
// TODO: For the main thread the check should be done against the main heap pointer
|
||||
} else {
|
||||
if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
|
||||
(os_tsk.run->stack[0] != MAGIC_WORD)) {
|
||||
os_error (OS_ERR_STK_OVF);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if ((os_tsk.run->tsk_stack < (U32)os_tsk.run->stack) ||
|
||||
(os_tsk.run->stack[0] != MAGIC_WORD)) {
|
||||
os_error (OS_ERR_STK_OVF);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue