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