From fd49fcb229b6694d69d8f7646c7940e40b67a0cb Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 11 Jul 2019 17:32:01 +1000 Subject: [PATCH] stm32/gccollect: Always use MP_STATE_THREAD(stack_top) to get stack top. In a non-thread build, using &_ram_end as the top-of-stack is no longer correct because the stack is not always at the very top end of RAM. See eg 04c7cdb668cc7ee391ef5fe000f825389197f7e2 and 378659209778a1bde24e9b15793087023b02bbd9. The correct value to use is &_estack, which is the value stored in MP_STATE_THREAD(stack_top), and using the same code for both thread and non-thread builds makes the code cleaner. --- ports/stm32/gccollect.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ports/stm32/gccollect.c b/ports/stm32/gccollect.c index 5c1bf1e06d..f5a49b7d08 100644 --- a/ports/stm32/gccollect.c +++ b/ports/stm32/gccollect.c @@ -48,11 +48,7 @@ void gc_collect(void) { uintptr_t sp = gc_helper_get_regs_and_sp(regs); // trace the stack, including the registers (since they live on the stack in this function) - #if MICROPY_PY_THREAD gc_collect_root((void**)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t)); - #else - gc_collect_root((void**)sp, ((uint32_t)&_ram_end - sp) / sizeof(uint32_t)); - #endif // trace root pointers from any threads #if MICROPY_PY_THREAD