use linker to align fpu state save area
[minix3.git] / kernel / system / do_sigreturn.c
blob6edc492fbe58ff82e4843ad220eb0c40221ffc5d
1 /* The kernel call that is implemented in this file:
2 * m_type: SYS_SIGRETURN
4 * The parameters for this kernel call are:
5 * m2_i1: SIG_ENDPT # process returning from handler
6 * m2_p1: SIG_CTXT_PTR # pointer to sigcontext structure
8 */
10 #include "kernel/system.h"
11 #include <string.h>
12 #include <machine/cpu.h>
14 #if USE_SIGRETURN
16 /*===========================================================================*
17 * do_sigreturn *
18 *===========================================================================*/
19 int do_sigreturn(struct proc * caller, message * m_ptr)
21 /* POSIX style signals require sys_sigreturn to put things in order before
22 * the signalled process can resume execution
24 struct sigcontext sc;
25 register struct proc *rp;
26 int proc_nr, r;
28 if (! isokendpt(m_ptr->SIG_ENDPT, &proc_nr)) return(EINVAL);
29 if (iskerneln(proc_nr)) return(EPERM);
30 rp = proc_addr(proc_nr);
32 /* Copy in the sigcontext structure. */
33 if((r=data_copy(m_ptr->SIG_ENDPT, (vir_bytes) m_ptr->SIG_CTXT_PTR,
34 KERNEL, (vir_bytes) &sc, sizeof(struct sigcontext))) != OK)
35 return r;
37 /* Restore user bits of psw from sc, maintain system bits from proc. */
38 sc.sc_psw = (sc.sc_psw & X86_FLAGS_USER) |
39 (rp->p_reg.psw & ~X86_FLAGS_USER);
41 #if (_MINIX_CHIP == _CHIP_INTEL)
42 /* Don't panic kernel if user gave bad selectors. */
43 sc.sc_cs = rp->p_reg.cs;
44 sc.sc_ds = rp->p_reg.ds;
45 sc.sc_es = rp->p_reg.es;
46 sc.sc_ss = rp->p_reg.ss;
47 #if _WORD_SIZE == 4
48 sc.sc_fs = rp->p_reg.fs;
49 sc.sc_gs = rp->p_reg.gs;
50 #endif
51 #endif
53 /* Restore the registers. */
54 memcpy(&rp->p_reg, &sc.sc_regs, sizeof(sigregs));
55 #if (_MINIX_CHIP == _CHIP_INTEL)
56 if(sc.sc_flags & MF_FPU_INITIALIZED)
58 memcpy(rp->p_seg.fpu_state, &sc.sc_fpu_state, FPU_XFP_SIZE);
59 rp->p_misc_flags |= MF_FPU_INITIALIZED; /* Restore math usage flag. */
60 /* force reloading FPU */
61 release_fpu(rp);
63 #endif
65 rp->p_misc_flags |= MF_CONTEXT_SET;
67 return(OK);
69 #endif /* USE_SIGRETURN */