diff options
| author | YoungJoon Chun <yjchun@mac.com> | 2022-02-16 18:47:05 +0900 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-03-01 17:03:57 +1100 |
| commit | 2d47020e15b82b7f021e0b52dabe75baf5cb4c4d (patch) | |
| tree | 2eb887bf641882f4dfefb17371e5fffa7ec0b810 | |
| parent | 795370ca23ac8b0f3589ec1d4b34d3d7f3b175eb (diff) | |
rp2/mpthreadport: Fix memory corruption when thread is created in core1.
The stack (and arg) of core1 is itself a root pointer, not just the entries
in it. Without this fix the GC could reclaim the entire stack (and
argument object).
Fixes issues #7124 and #7981.
| -rw-r--r-- | ports/rp2/mpthreadport.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/ports/rp2/mpthreadport.c b/ports/rp2/mpthreadport.c index 8a36cfca7..cdb5945d2 100644 --- a/ports/rp2/mpthreadport.c +++ b/ports/rp2/mpthreadport.c @@ -52,12 +52,12 @@ void mp_thread_deinit(void) { } void mp_thread_gc_others(void) { - if (get_core_num() == 0) { - // GC running on core0, trace core1's stack, if it's running. - if (core1_entry != NULL) { - gc_collect_root((void **)core1_stack, core1_stack_num_words); - } - } else { + if (core1_entry != NULL) { + // Collect core1's stack if it is active. + gc_collect_root((void **)&core1_stack, 1); + gc_collect_root((void **)&core1_arg, 1); + } + if (get_core_num() == 1) { // GC running on core1, trace core0's stack. gc_collect_root((void **)&__StackBottom, (&__StackTop - &__StackBottom) / sizeof(uintptr_t)); } |
