diff --git a/arch/sim/src/sim/up_initialstate.c b/arch/sim/src/sim/up_initialstate.c index 03e5a35a036..f48f71f0937 100644 --- a/arch/sim/src/sim/up_initialstate.c +++ b/arch/sim/src/sim/up_initialstate.c @@ -41,6 +41,9 @@ #include #include +#ifdef CONFIG_SIM_SANITIZE +#include +#endif #include @@ -75,4 +78,7 @@ void up_initial_state(struct tcb_s *tcb) memset(&tcb->xcp, 0, sizeof(struct xcptcontext)); tcb->xcp.regs[JB_SP] = (xcpt_reg_t)tcb->adj_stack_ptr - sizeof(xcpt_reg_t); tcb->xcp.regs[JB_PC] = (xcpt_reg_t)tcb->start; +#ifdef CONFIG_SIM_SANITIZE + __asan_unpoison_memory_region(tcb->stack_alloc_ptr, tcb->adj_stack_size); +#endif } diff --git a/arch/sim/src/sim/up_vfork.c b/arch/sim/src/sim/up_vfork.c index 0675778c443..11ca1440712 100644 --- a/arch/sim/src/sim/up_vfork.c +++ b/arch/sim/src/sim/up_vfork.c @@ -83,11 +83,16 @@ * ****************************************************************************/ +#ifdef CONFIG_SIM_SANITIZE +__attribute__((no_sanitize_address)) +#endif pid_t up_vfork(const xcpt_reg_t *context) { struct tcb_s *parent = this_task(); struct task_tcb_s *child; size_t stacksize; + unsigned char *pout; + unsigned char *pin; unsigned long newsp; unsigned long newfp; unsigned long stackutil; @@ -151,7 +156,9 @@ pid_t up_vfork(const xcpt_reg_t *context) */ newsp = (unsigned long)child->cmn.adj_stack_ptr - stackutil; - memcpy((void *)newsp, (const void *)context[JB_SP], stackutil); + pout = (unsigned char *)newsp; + pin = (unsigned char *)context[JB_SP]; + while (stackutil-- > 0) *pout++ = *pin++; /* Was there a frame pointer in place before? */ @@ -180,7 +187,8 @@ pid_t up_vfork(const xcpt_reg_t *context) * child thread. */ - memcpy(child->cmn.xcp.regs, context, sizeof(xcpt_reg_t) * XCPTCONTEXT_REGS); + memcpy(child->cmn.xcp.regs, context, + sizeof(xcpt_reg_t) * XCPTCONTEXT_REGS); child->cmn.xcp.regs[JB_FP] = newfp; /* Frame pointer */ child->cmn.xcp.regs[JB_SP] = newsp; /* Stack pointer */