2005-10-14 10:58:59 +02:00
|
|
|
/* The kernel call that is implemented in this file:
|
2013-11-28 19:22:37 +01:00
|
|
|
* m_type: SYS_SIGRETURN
|
2005-07-14 17:12:12 +02:00
|
|
|
*
|
2005-10-14 10:58:59 +02:00
|
|
|
* The parameters for this kernel call are:
|
2013-11-28 19:22:37 +01:00
|
|
|
* m_sigcalls.endp # process returning from handler
|
|
|
|
* m_sigcalls.sigctx # pointer to sigcontext structure
|
2005-07-14 17:12:12 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/system.h"
|
2005-07-19 17:01:47 +02:00
|
|
|
#include <string.h>
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/cpu.h>
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
#if USE_SIGRETURN
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_sigreturn *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_sigreturn(struct proc * caller, message * m_ptr)
|
2005-07-14 17:12:12 +02:00
|
|
|
{
|
|
|
|
/* POSIX style signals require sys_sigreturn to put things in order before
|
|
|
|
* the signalled process can resume execution
|
|
|
|
*/
|
|
|
|
struct sigcontext sc;
|
|
|
|
register struct proc *rp;
|
2009-09-15 11:57:22 +02:00
|
|
|
int proc_nr, r;
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2013-11-28 19:22:37 +01:00
|
|
|
if (!isokendpt(m_ptr->m_sigcalls.endpt, &proc_nr)) return EINVAL;
|
|
|
|
if (iskerneln(proc_nr)) return EPERM;
|
2009-09-15 11:57:22 +02:00
|
|
|
rp = proc_addr(proc_nr);
|
2005-07-14 17:12:12 +02:00
|
|
|
|
|
|
|
/* Copy in the sigcontext structure. */
|
2013-11-28 19:22:37 +01:00
|
|
|
if ((r = data_copy(m_ptr->m_sigcalls.endpt,
|
|
|
|
(vir_bytes)m_ptr->m_sigcalls.sigctx, KERNEL,
|
|
|
|
(vir_bytes)&sc, sizeof(struct sigcontext))) != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
return r;
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2012-10-08 03:38:03 +02:00
|
|
|
#if defined(__i386__)
|
2007-05-08 17:43:00 +02:00
|
|
|
/* Restore user bits of psw from sc, maintain system bits from proc. */
|
2013-12-11 00:47:22 +01:00
|
|
|
sc.sc_eflags = (sc.sc_eflags & X86_FLAGS_USER) |
|
2007-05-08 17:43:00 +02:00
|
|
|
(rp->p_reg.psw & ~X86_FLAGS_USER);
|
2012-10-08 03:38:03 +02:00
|
|
|
#endif
|
2005-07-14 17:12:12 +02:00
|
|
|
|
2012-08-06 12:55:50 +02:00
|
|
|
#if defined(__i386__)
|
2013-12-11 00:47:22 +01:00
|
|
|
/* Write back registers we allow to be restored, i.e.
|
|
|
|
* not the segment ones.
|
|
|
|
*/
|
|
|
|
rp->p_reg.di = sc.sc_edi;
|
|
|
|
rp->p_reg.si = sc.sc_esi;
|
|
|
|
rp->p_reg.fp = sc.sc_ebp;
|
|
|
|
rp->p_reg.bx = sc.sc_ebx;
|
|
|
|
rp->p_reg.dx = sc.sc_edx;
|
|
|
|
rp->p_reg.cx = sc.sc_ecx;
|
|
|
|
rp->p_reg.retreg = sc.sc_eax;
|
|
|
|
rp->p_reg.pc = sc.sc_eip;
|
|
|
|
rp->p_reg.psw = sc.sc_eflags;
|
|
|
|
rp->p_reg.sp = sc.sc_esp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__arm__)
|
|
|
|
rp->p_reg.psr = sc.sc_spsr;
|
|
|
|
rp->p_reg.retreg = sc.sc_r0;
|
|
|
|
rp->p_reg.r1 = sc.sc_r1;
|
|
|
|
rp->p_reg.r2 = sc.sc_r2;
|
|
|
|
rp->p_reg.r3 = sc.sc_r3;
|
|
|
|
rp->p_reg.r4 = sc.sc_r4;
|
|
|
|
rp->p_reg.r5 = sc.sc_r5;
|
|
|
|
rp->p_reg.r6 = sc.sc_r6;
|
|
|
|
rp->p_reg.r7 = sc.sc_r7;
|
|
|
|
rp->p_reg.r8 = sc.sc_r8;
|
|
|
|
rp->p_reg.r9 = sc.sc_r9;
|
|
|
|
rp->p_reg.r10 = sc.sc_r10;
|
|
|
|
rp->p_reg.fp = sc.sc_r11;
|
|
|
|
rp->p_reg.r12 = sc.sc_r12;
|
|
|
|
rp->p_reg.sp = sc.sc_usr_sp;
|
|
|
|
rp->p_reg.lr = sc.sc_usr_lr;
|
|
|
|
rp->p_reg.pc = sc.sc_pc;
|
2005-07-14 17:12:12 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore the registers. */
|
2013-12-11 00:47:22 +01:00
|
|
|
arch_proc_setcontext(rp, &rp->p_reg, 1, sc.trap_style);
|
|
|
|
|
|
|
|
if(sc.sc_magic != SC_MAGIC) { printf("kernel sigreturn: corrupt signal context\n"); }
|
|
|
|
|
2012-08-06 12:55:50 +02:00
|
|
|
#if defined(__i386__)
|
2013-11-28 19:22:37 +01:00
|
|
|
if (sc.sc_flags & MF_FPU_INITIALIZED)
|
2009-12-02 14:01:48 +01:00
|
|
|
{
|
2012-04-19 15:06:47 +02:00
|
|
|
memcpy(rp->p_seg.fpu_state, &sc.sc_fpu_state, FPU_XFP_SIZE);
|
2009-12-02 14:01:48 +01:00
|
|
|
rp->p_misc_flags |= MF_FPU_INITIALIZED; /* Restore math usage flag. */
|
2010-06-07 09:43:17 +02:00
|
|
|
/* force reloading FPU */
|
2010-09-15 16:11:25 +02:00
|
|
|
release_fpu(rp);
|
2009-12-02 14:01:48 +01:00
|
|
|
}
|
|
|
|
#endif
|
2009-07-07 20:55:11 +02:00
|
|
|
|
2013-11-28 19:22:37 +01:00
|
|
|
return OK;
|
2005-07-14 17:12:12 +02:00
|
|
|
}
|
|
|
|
#endif /* USE_SIGRETURN */
|
|
|
|
|