diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index 0c06303b14..6bb8bce4de 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -116,7 +116,7 @@ static long _list_thread(struct rt_list_node *list) else if (stat == RT_THREAD_CLOSE) rt_kprintf(" close "); #if defined(ARCH_CPU_STACK_GROWS_UPWARD) - ptr = (rt_uint8_t *)thread->stack_addr + thread->stack_size; + ptr = (rt_uint8_t *)thread->stack_addr + thread->stack_size - 1; while (*ptr == '#')ptr --; rt_kprintf(" 0x%08x 0x%08x %02d%% 0x%08x %03d\n", diff --git a/src/scheduler.c b/src/scheduler.c index 14f7510e66..503639fa81 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -82,7 +82,11 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread) { RT_ASSERT(thread != RT_NULL); +#if defined(ARCH_CPU_STACK_GROWS_UPWARD) + if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' || +#else if (*((rt_uint8_t *)thread->stack_addr) != '#' || +#endif (rt_ubase_t)thread->sp <= (rt_ubase_t)thread->stack_addr || (rt_ubase_t)thread->sp > (rt_ubase_t)thread->stack_addr + (rt_ubase_t)thread->stack_size)