kernel: kill proc with bogus ipc address
[minix.git] / kernel / system / do_mcontext.c
blobc72ac6fd7cf34ffcdbdf28e9709ce3d4296abf11
1 /* The kernel calls that are implemented in this file:
2 * m_type: SYS_SETMCONTEXT
3 * m_type: SYS_GETMCONTEXT
5 * The parameters for these kernel calls are:
6 * m1_i1: PR_ENDPT # proc endpoint doing call
7 * m1_p1: PR_MEM_PTR # pointer to mcontext structure
9 */
11 #include "kernel/system.h"
12 #include <string.h>
13 #include <machine/mcontext.h>
15 #if USE_MCONTEXT
16 /*===========================================================================*
17 * do_getmcontext *
18 *===========================================================================*/
19 int do_getmcontext(struct proc * caller, message * m_ptr)
21 /* Retrieve machine context of a process */
23 register struct proc *rp;
24 int proc_nr, r;
25 mcontext_t mc;
27 if (! isokendpt(m_ptr->PR_ENDPT, &proc_nr)) return(EINVAL);
28 if (iskerneln(proc_nr)) return(EPERM);
29 rp = proc_addr(proc_nr);
31 #if defined(__i386__)
32 if (!proc_used_fpu(rp))
33 return(OK); /* No state to copy */
34 #endif
36 /* Get the mcontext structure into our address space. */
37 if ((r = data_copy(m_ptr->PR_ENDPT, (vir_bytes) m_ptr->PR_CTX_PTR, KERNEL,
38 (vir_bytes) &mc, (phys_bytes) sizeof(struct __mcontext))) != OK)
39 return(r);
41 #if defined(__i386__)
42 /* Copy FPU state */
43 mc.mc_fpu_flags = 0;
44 if (proc_used_fpu(rp)) {
45 /* make sure that the FPU context is saved into proc structure first */
46 save_fpu(rp);
47 mc.mc_fpu_flags = rp->p_misc_flags & MF_FPU_INITIALIZED;
48 memcpy(&(mc.mc_fpu_state), rp->p_seg.fpu_state, FPU_XFP_SIZE);
50 #endif
53 /* Copy the mcontext structure to the user's address space. */
54 if ((r = data_copy(KERNEL, (vir_bytes) &mc, m_ptr->PR_ENDPT,
55 (vir_bytes) m_ptr->PR_CTX_PTR,
56 (phys_bytes) sizeof(struct __mcontext))) != OK)
57 return(r);
59 return(OK);
63 /*===========================================================================*
64 * do_setmcontext *
65 *===========================================================================*/
66 int do_setmcontext(struct proc * caller, message * m_ptr)
68 /* Set machine context of a process */
70 register struct proc *rp;
71 int proc_nr, r;
72 mcontext_t mc;
74 if (!isokendpt(m_ptr->PR_ENDPT, &proc_nr)) return(EINVAL);
75 rp = proc_addr(proc_nr);
77 /* Get the mcontext structure into our address space. */
78 if ((r = data_copy(m_ptr->PR_ENDPT, (vir_bytes) m_ptr->PR_CTX_PTR, KERNEL,
79 (vir_bytes) &mc, (phys_bytes) sizeof(struct __mcontext))) != OK)
80 return(r);
82 #if defined(__i386__)
83 /* Copy FPU state */
84 if (mc.mc_fpu_flags & MF_FPU_INITIALIZED) {
85 rp->p_misc_flags |= MF_FPU_INITIALIZED;
86 memcpy(rp->p_seg.fpu_state, &(mc.mc_fpu_state), FPU_XFP_SIZE);
87 } else
88 rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
89 /* force reloading FPU in either case */
90 release_fpu(rp);
91 #endif
93 return(OK);
96 #endif