Kernel: fix register corruption on signal delivery
This fixes problems with test79 and other programs. Change-Id: I14de097a3b01114ec5dbd687ab5be9290ad13fc7
This commit is contained in:
parent
7597f4a8fc
commit
4316052bbe
1 changed files with 33 additions and 18 deletions
|
@ -24,6 +24,9 @@ int do_sigsend(struct proc * caller, message * m_ptr)
|
||||||
register struct proc *rp;
|
register struct proc *rp;
|
||||||
struct sigframe_sigcontext fr, *frp;
|
struct sigframe_sigcontext fr, *frp;
|
||||||
int proc_nr, r;
|
int proc_nr, r;
|
||||||
|
#if defined(__i386__)
|
||||||
|
reg_t new_fp;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!isokendpt(m_ptr->m_sigcalls.endpt, &proc_nr)) return EINVAL;
|
if (!isokendpt(m_ptr->m_sigcalls.endpt, &proc_nr)) return EINVAL;
|
||||||
if (iskerneln(proc_nr)) return EPERM;
|
if (iskerneln(proc_nr)) return EPERM;
|
||||||
|
@ -35,6 +38,10 @@ int do_sigsend(struct proc * caller, message * m_ptr)
|
||||||
(vir_bytes)&smsg, (phys_bytes) sizeof(struct sigmsg))) != OK)
|
(vir_bytes)&smsg, (phys_bytes) sizeof(struct sigmsg))) != OK)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
/* WARNING: the following code may be run more than once even for a single
|
||||||
|
* signal delivery. Do not change registers here. See the comment below.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Compute the user stack pointer where sigframe will start. */
|
/* Compute the user stack pointer where sigframe will start. */
|
||||||
smsg.sm_stkptr = arch_get_sp(rp);
|
smsg.sm_stkptr = arch_get_sp(rp);
|
||||||
frp = (struct sigframe_sigcontext *) smsg.sm_stkptr - 1;
|
frp = (struct sigframe_sigcontext *) smsg.sm_stkptr - 1;
|
||||||
|
@ -62,7 +69,7 @@ int do_sigsend(struct proc * caller, message * m_ptr)
|
||||||
fr.sf_sc.sc_ss = rp->p_reg.ss;
|
fr.sf_sc.sc_ss = rp->p_reg.ss;
|
||||||
fr.sf_fp = rp->p_reg.fp;
|
fr.sf_fp = rp->p_reg.fp;
|
||||||
fr.sf_signum = smsg.sm_signo;
|
fr.sf_signum = smsg.sm_signo;
|
||||||
rp->p_reg.fp = (reg_t) &frp->sf_fp;
|
new_fp = (reg_t) &frp->sf_fp;
|
||||||
fr.sf_scpcopy = fr.sf_scp;
|
fr.sf_scpcopy = fr.sf_scp;
|
||||||
fr.sf_ra_sigreturn = smsg.sm_sigreturn;
|
fr.sf_ra_sigreturn = smsg.sm_sigreturn;
|
||||||
fr.sf_ra= rp->p_reg.pc;
|
fr.sf_ra= rp->p_reg.pc;
|
||||||
|
@ -108,10 +115,28 @@ int do_sigsend(struct proc * caller, message * m_ptr)
|
||||||
fr.sf_sc.sc_magic = SC_MAGIC;
|
fr.sf_sc.sc_magic = SC_MAGIC;
|
||||||
|
|
||||||
/* Initialize the sigframe structure. */
|
/* Initialize the sigframe structure. */
|
||||||
|
|
||||||
fpu_sigcontext(rp, &fr, &fr.sf_sc);
|
fpu_sigcontext(rp, &fr, &fr.sf_sc);
|
||||||
|
|
||||||
#if defined(__arm__)
|
/* Copy the sigframe structure to the user's stack. */
|
||||||
|
if ((r = data_copy_vmcheck(caller, KERNEL, (vir_bytes)&fr,
|
||||||
|
m_ptr->m_sigcalls.endpt, (vir_bytes)frp,
|
||||||
|
(vir_bytes)sizeof(struct sigframe_sigcontext))) != OK)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
/* WARNING: up to the statement above, the code may run multiple times, since
|
||||||
|
* copying out the frame/context may fail with VMSUSPEND the first time. For
|
||||||
|
* that reason, changes to process registers *MUST* be deferred until after
|
||||||
|
* this last copy -- otherwise, these changes will be made several times,
|
||||||
|
* possibly leading to corrupted process state.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Reset user registers to execute the signal handler. */
|
||||||
|
rp->p_reg.sp = (reg_t) frp;
|
||||||
|
rp->p_reg.pc = (reg_t) smsg.sm_sighandler;
|
||||||
|
|
||||||
|
#if defined(__i386__)
|
||||||
|
rp->p_reg.fp = new_fp;
|
||||||
|
#elif defined(__arm__)
|
||||||
/* use the ARM link register to set the return address from the signal
|
/* use the ARM link register to set the return address from the signal
|
||||||
* handler
|
* handler
|
||||||
*/
|
*/
|
||||||
|
@ -125,16 +150,6 @@ int do_sigsend(struct proc * caller, message * m_ptr)
|
||||||
rp->p_misc_flags |= MF_CONTEXT_SET;
|
rp->p_misc_flags |= MF_CONTEXT_SET;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Copy the sigframe structure to the user's stack. */
|
|
||||||
if ((r = data_copy_vmcheck(caller, KERNEL, (vir_bytes)&fr,
|
|
||||||
m_ptr->m_sigcalls.endpt, (vir_bytes)frp,
|
|
||||||
(vir_bytes)sizeof(struct sigframe_sigcontext))) != OK)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
/* Reset user registers to execute the signal handler. */
|
|
||||||
rp->p_reg.sp = (reg_t) frp;
|
|
||||||
rp->p_reg.pc = (reg_t) smsg.sm_sighandler;
|
|
||||||
|
|
||||||
/* Signal handler should get clean FPU. */
|
/* Signal handler should get clean FPU. */
|
||||||
rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
|
rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue