From 058229b626ebd97350d7ded5e507b4e2e459dff8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 16 Sep 2014 13:33:13 -0600 Subject: [PATCH] Correct stack handling is signal deliver to user processes --- arch/arm/src/armv7-a/arm_syscall.c | 36 +++++++++++------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_syscall.c b/arch/arm/src/armv7-a/arm_syscall.c index d70782f344..343226a86d 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -352,10 +352,6 @@ uint32_t *arm_syscall(uint32_t *regs) case SYS_signal_handler: { FAR struct tcb_s *rtcb = sched_self(); -#ifdef CONFIG_ARCH_KERNEL_STACK - int depth; -#endif - /* Remember the caller's return address */ DEBUGASSERT(rtcb->xcp.sigreturn == 0); @@ -384,20 +380,19 @@ uint32_t *arm_syscall(uint32_t *regs) regs[REG_R3] = *(uint32_t*)(regs[REG_SP]+4); #ifdef CONFIG_ARCH_KERNEL_STACK - /* If this is a nested SYSCALL and if there is an allocated kernel - * stack, then we must be operating on the kernal stack now. We - * need to switch back to the user stack before dispatching the - * signal handler to the user code. + /* If we are signalling a user process, then we must be operating + * on the kernel stack now. We need to switch back to the user + * stack before dispatching the signal handler to the user code. + * The existence of an allocated kernel stack is sufficient + * information to make this decision. */ - depth = rtcb->xcp.nsyscalls; - if (depth > 0 && rtcb->xcp.kstack != NULL) + if (rtcb->xcp.kstack != NULL) { - DEBUGASSERT(rtcb->xcp.kstkptr == NULL && - rtcb->xcp.ustkptr[depth - 1] != 0); + DEBUGASSERT(rtcb->xcp.kstkptr == NULL && rtcb->xcp.ustkptr != NULL); rtcb->xcp.kstkptr = (FAR uint32_t *)regs[REG_SP]; - regs[REG_SP] = (uint32_t)rtcb->xcp.ustkptr[depth - 1]; + regs[REG_SP] = (uint32_t)rtcb->xcp.ustkptr; } #endif } @@ -417,9 +412,6 @@ uint32_t *arm_syscall(uint32_t *regs) case SYS_signal_handler_return: { FAR struct tcb_s *rtcb = sched_self(); -#ifdef CONFIG_ARCH_KERNEL_STACK - int depth; -#endif /* Set up to return to the kernel-mode signal dispatching logic. */ @@ -431,17 +423,15 @@ uint32_t *arm_syscall(uint32_t *regs) rtcb->xcp.sigreturn = 0; #ifdef CONFIG_ARCH_KERNEL_STACK - /* If this is a nested SYSCALL and if there is an allocated kernel - * stack, we must be using the user stack to dispatch to the signal - * handler. We need to switch to back to the kernel user stack - * before returning to the kernel mode signal trampoline. + /* We must enter here be using the user stack. We need to switch + * to back to the kernel user stack before returning to the kernel + * mode signal trampoline. */ - depth = rtcb->xcp.nsyscalls; - if (depth > 0 && rtcb->xcp.kstack != NULL) + if (rtcb->xcp.kstack != NULL) { DEBUGASSERT(rtcb->xcp.kstkptr != NULL && - (uint32_t)rtcb->xcp.ustkptr[depth - 1] == regs[REG_SP]); + (uint32_t)rtcb->xcp.ustkptr == regs[REG_SP]); regs[REG_SP] = (uint32_t)rtcb->xcp.kstkptr; rtcb->xcp.kstkptr = NULL;