1*433d6423SLionel Sambuc /* The kernel call implemented in this file:
2*433d6423SLionel Sambuc * m_type: SYS_EXEC
3*433d6423SLionel Sambuc *
4*433d6423SLionel Sambuc * The parameters for this kernel call are:
5*433d6423SLionel Sambuc * m_lsys_krn_sys_exec.endpt (process that did exec call)
6*433d6423SLionel Sambuc * m_lsys_krn_sys_exec.stack (new stack pointer)
7*433d6423SLionel Sambuc * m_lsys_krn_sys_exec.name (pointer to program name)
8*433d6423SLionel Sambuc * m_lsys_krn_sys_exec.ip (new instruction pointer)
9*433d6423SLionel Sambuc * m_lsys_krn_sys_exec.ps_str (struct ps_strings *)
10*433d6423SLionel Sambuc */
11*433d6423SLionel Sambuc #include "kernel/system.h"
12*433d6423SLionel Sambuc #include <string.h>
13*433d6423SLionel Sambuc #include <minix/endpoint.h>
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc #if USE_EXEC
16*433d6423SLionel Sambuc
17*433d6423SLionel Sambuc /*===========================================================================*
18*433d6423SLionel Sambuc * do_exec *
19*433d6423SLionel Sambuc *===========================================================================*/
do_exec(struct proc * caller,message * m_ptr)20*433d6423SLionel Sambuc int do_exec(struct proc * caller, message * m_ptr)
21*433d6423SLionel Sambuc {
22*433d6423SLionel Sambuc /* Handle sys_exec(). A process has done a successful EXEC. Patch it up. */
23*433d6423SLionel Sambuc register struct proc *rp;
24*433d6423SLionel Sambuc int proc_nr;
25*433d6423SLionel Sambuc char name[PROC_NAME_LEN];
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc if(!isokendpt(m_ptr->m_lsys_krn_sys_exec.endpt, &proc_nr))
28*433d6423SLionel Sambuc return EINVAL;
29*433d6423SLionel Sambuc
30*433d6423SLionel Sambuc rp = proc_addr(proc_nr);
31*433d6423SLionel Sambuc
32*433d6423SLionel Sambuc if(rp->p_misc_flags & MF_DELIVERMSG) {
33*433d6423SLionel Sambuc rp->p_misc_flags &= ~MF_DELIVERMSG;
34*433d6423SLionel Sambuc }
35*433d6423SLionel Sambuc
36*433d6423SLionel Sambuc /* Save command name for debugging, ps(1) output, etc. */
37*433d6423SLionel Sambuc if(data_copy(caller->p_endpoint, m_ptr->m_lsys_krn_sys_exec.name,
38*433d6423SLionel Sambuc KERNEL, (vir_bytes) name,
39*433d6423SLionel Sambuc (phys_bytes) sizeof(name) - 1) != OK)
40*433d6423SLionel Sambuc strncpy(name, "<unset>", PROC_NAME_LEN);
41*433d6423SLionel Sambuc
42*433d6423SLionel Sambuc name[sizeof(name)-1] = '\0';
43*433d6423SLionel Sambuc
44*433d6423SLionel Sambuc /* Set process state. */
45*433d6423SLionel Sambuc arch_proc_init(rp,
46*433d6423SLionel Sambuc (u32_t) m_ptr->m_lsys_krn_sys_exec.ip,
47*433d6423SLionel Sambuc (u32_t) m_ptr->m_lsys_krn_sys_exec.stack,
48*433d6423SLionel Sambuc (u32_t) m_ptr->m_lsys_krn_sys_exec.ps_str, name);
49*433d6423SLionel Sambuc
50*433d6423SLionel Sambuc /* No reply to EXEC call */
51*433d6423SLionel Sambuc RTS_UNSET(rp, RTS_RECEIVING);
52*433d6423SLionel Sambuc
53*433d6423SLionel Sambuc /* Mark fpu_regs contents as not significant, so fpu
54*433d6423SLionel Sambuc * will be initialized, when it's used next time. */
55*433d6423SLionel Sambuc rp->p_misc_flags &= ~MF_FPU_INITIALIZED;
56*433d6423SLionel Sambuc /* force reloading FPU if the current process is the owner */
57*433d6423SLionel Sambuc release_fpu(rp);
58*433d6423SLionel Sambuc return(OK);
59*433d6423SLionel Sambuc }
60*433d6423SLionel Sambuc #endif /* USE_EXEC */
61