sim: Fix sim stack smashing problem

The reason is that the new created task receives signal while
it has not entered its stack frame.

Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
This commit is contained in:
chenxiaoyi
2023-04-24 12:48:48 +08:00
committed by Xiang Xiao
parent b3678b1454
commit 6d6e1aea3b
+23 -1
View File
@@ -32,8 +32,26 @@
#include <nuttx/arch.h>
#include "sched/sched.h"
#include "sim_internal.h"
/****************************************************************************
* Private Functions
****************************************************************************/
static void pre_start(void)
{
struct tcb_s *tcb = this_task();
/* Enable signal delivery */
up_irq_restore(0);
/* Then call the real start function */
tcb->start();
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -93,7 +111,11 @@ void up_initial_state(struct tcb_s *tcb)
#endif
+ tcb->adj_stack_size;
tcb->xcp.regs[JB_PC] = (xcpt_reg_t)tcb->start;
/* Mask the interrupt until switching to the new task */
memset(&tcb->xcp.regs[JB_FLAG], 0xff, sizeof(xcpt_reg_t) * 2);
tcb->xcp.regs[JB_PC] = (xcpt_reg_t)pre_start;
#ifdef CONFIG_SIM_ASAN
__asan_unpoison_memory_region(tcb->stack_alloc_ptr, tcb->adj_stack_size);