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.
This commit is contained in:
YoungJoon Chun 2022-02-16 18:47:05 +09:00 committed by Damien George
parent 795370ca23
commit 2d47020e15

View File

@ -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);
// Collect core1's stack if it is active.
gc_collect_root((void **)&core1_stack, 1);
gc_collect_root((void **)&core1_arg, 1);
}
} else {
if (get_core_num() == 1) {
// GC running on core1, trace core0's stack.
gc_collect_root((void **)&__StackBottom, (&__StackTop - &__StackBottom) / sizeof(uintptr_t));
}