xiaoxiang781216 commented on pull request #5731: URL: https://github.com/apache/incubator-nuttx/pull/5731#issuecomment-1080996343
> Oops, you are also right, the original code is suspicious too, as the first thing exception_common does is this: > > ``` > exception_common: > addi sp, sp, -XCPTCONTEXT_SIZE > ``` > > I assume the same issue is in the ARM implementation too. In this case the new task's address environment is already in use, but sp still points to the old task. Yes, ARM has the similar issue, @anchao hit the problem before like this: 1. The first task wait on a named semaphore 2. The second task post this semaphore to wake up the first 3. And the system panic suddenly he made a temp fix like this: 1. Move group_addrenv to arm_syscall::SYS_switch_context 2. Disable FPU since the lazy fpu save may corrupt the next task memory space The above problem is fixed. So, to fix this issue: 1. We need review all place which call group_addrenv and move to the right location 2. Save and restore FPU in exception_common @no1wudi please prepare two patches for RISCV tomorrow, so @pussuw can verify with his S-mode change. @anchao will fix the similar issue on ARM in the next couple days. > > This is not an issue with the new S-mode function however: > > ``` > riscv_switchcontext: > > /* Save old context to arg[0] */ > > save_ctx a0 /* save context */ > ``` > > Saving the context does not use stack, and this is why the old code works on my table. > Yes, but it isn't reliable since we can't control how C compiler generate the machine code which may insert push/pop operation between group_addrenv and riscv_switchcontext in the new version or different option. > But indeed, the location for calling group_addrenv() is suspicious, as the context switch is done by using the new tasks environment, even though the old task's registers are still in use. Yes, we move need do the address space change with the interrupt or kernel stack, otherwise we have to write the whole process in assemble code, so we can control the stack usage manually. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org