Set initial task receiver to top_self for stability

The current implementation of `task_init_context` inheriting a receiver from the parent task is unstable and causes critical faults, especially on microcontrollers.

- It leads to a HardFault on devices like Raspberry Pi Pico 2 by accessing a potentially NULL `mrb->c->ci`.
- Even when `mrb->c->ci` is not NULL, this incomplete context copy causes other memory errors (SEGV).

This patch reverts to the safer, previous behavior, that I implemented in picoruby/picoruby, of always initializing a new task's receiver to `top_self`, ensuring predictable and
robust operation.
The issue was likely masked on POSIX systems due to the unpredictable nature of undefined behavior.
This commit is contained in:
HASUMI Hitoshi
2026-02-13 13:59:48 +09:00
parent cfcd86fd9b
commit ee610cdbb6
+2 -2
View File
@@ -278,8 +278,8 @@ task_init_context(mrb_state *mrb, mrb_task *t, const struct RProc *proc)
}
}
/* Copy receiver from current context */
c->stbase[0] = mrb->c->ci->stack[0];
/* Set receiver to top self */
c->stbase[0] = mrb_top_self(mrb);
/* Initialize callinfo stack */
static const mrb_callinfo ci_zero = { 0 };