3.1.7 branch.
[minix.git] / kernel / system / do_exec.c
blob0e9e473c9c73ac2006c8917967d4f72aae42203d
1 /* The kernel call implemented in this file:
2 * m_type: SYS_EXEC
4 * The parameters for this kernel call are:
5 * m1_i1: PR_ENDPT (process that did exec call)
6 * m1_p1: PR_STACK_PTR (new stack pointer)
7 * m1_p2: PR_NAME_PTR (pointer to program name)
8 * m1_p3: PR_IP_PTR (new instruction pointer)
9 */
10 #include "kernel/system.h"
11 #include <string.h>
12 #include <minix/endpoint.h>
14 #if USE_EXEC
16 /*===========================================================================*
17 * do_exec *
18 *===========================================================================*/
19 PUBLIC int do_exec(struct proc * caller, message * m_ptr)
21 /* Handle sys_exec(). A process has done a successful EXEC. Patch it up. */
22 register struct proc *rp;
23 int proc_nr;
25 if(!isokendpt(m_ptr->PR_ENDPT, &proc_nr))
26 return EINVAL;
28 rp = proc_addr(proc_nr);
30 if(rp->p_misc_flags & MF_DELIVERMSG) {
31 rp->p_misc_flags &= ~MF_DELIVERMSG;
32 rp->p_delivermsg_lin = 0;
35 /* Save command name for debugging, ps(1) output, etc. */
36 if(data_copy(caller->p_endpoint, (vir_bytes) m_ptr->PR_NAME_PTR,
37 KERNEL, (vir_bytes) rp->p_name, (phys_bytes) P_NAME_LEN - 1) != OK)
38 strncpy(rp->p_name, "<unset>", P_NAME_LEN);
40 /* Do architecture-specific exec() stuff. */
41 arch_pre_exec(rp, (u32_t) m_ptr->PR_IP_PTR, (u32_t) m_ptr->PR_STACK_PTR);
43 /* No reply to EXEC call */
44 RTS_UNSET(rp, RTS_RECEIVING);
46 /* Mark fpu_regs contents as not significant, so fpu
47 * will be initialized, when it's used next time. */
48 rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
49 return(OK);
51 #endif /* USE_EXEC */