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. */
|
|
|
|
sc.sc_psw = (sc.sc_psw & X86_FLAGS_USER) |
|
|
|
|
(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__)
|
2005-07-14 17:12:12 +02:00
|
|
|
/* Don't panic kernel if user gave bad selectors. */
|
|
|
|
sc.sc_cs = rp->p_reg.cs;
|
|
|
|
sc.sc_ds = rp->p_reg.ds;
|
|
|
|
sc.sc_es = rp->p_reg.es;
|
2009-09-25 19:44:26 +02:00
|
|
|
sc.sc_ss = rp->p_reg.ss;
|
2005-07-14 17:12:12 +02:00
|
|
|
sc.sc_fs = rp->p_reg.fs;
|
|
|
|
sc.sc_gs = rp->p_reg.gs;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Restore the registers. */
|
2013-01-06 19:18:41 +01:00
|
|
|
arch_proc_setcontext(rp, &sc.sc_regs, 1, sc.trap_style);
|
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 */
|
|
|
|
|