mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user