source: branches/minix3-book/kernel/system/do_exec.c

Last change on this file was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 1.7 KB
Line 
1/* The kernel call implemented in this file:
2 * m_type: SYS_EXEC
3 *
4 * The parameters for this kernel call are:
5 * m1_i1: PR_PROC_NR (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 "../system.h"
11#include <string.h>
12#include <signal.h>
13
14#if USE_EXEC
15
16/*===========================================================================*
17 * do_exec *
18 *===========================================================================*/
19PUBLIC int do_exec(m_ptr)
20register message *m_ptr; /* pointer to request message */
21{
22/* Handle sys_exec(). A process has done a successful EXEC. Patch it up. */
23 register struct proc *rp;
24 reg_t sp; /* new sp */
25 phys_bytes phys_name;
26 char *np;
27
28 rp = proc_addr(m_ptr->PR_PROC_NR);
29 sp = (reg_t) m_ptr->PR_STACK_PTR;
30 rp->p_reg.sp = sp; /* set the stack pointer */
31 phys_memset(vir2phys(&rp->p_ldt[EXTRA_LDT_INDEX]), 0,
32 (LDT_SIZE - EXTRA_LDT_INDEX) * sizeof(rp->p_ldt[0]));
33 rp->p_reg.pc = (reg_t) m_ptr->PR_IP_PTR; /* set pc */
34 rp->p_rts_flags &= ~RECEIVING; /* PM does not reply to EXEC call */
35 if (rp->p_rts_flags == 0) lock_enqueue(rp);
36
37 /* Save command name for debugging, ps(1) output, etc. */
38 phys_name = numap_local(m_ptr->m_source, (vir_bytes) m_ptr->PR_NAME_PTR,
39 (vir_bytes) P_NAME_LEN - 1);
40 if (phys_name != 0) {
41 phys_copy(phys_name, vir2phys(rp->p_name), (phys_bytes) P_NAME_LEN - 1);
42 for (np = rp->p_name; (*np & BYTE) >= ' '; np++) {}
43 *np = 0; /* mark end */
44 } else {
45 strncpy(rp->p_name, "<unset>", P_NAME_LEN);
46 }
47 return(OK);
48}
49#endif /* USE_EXEC */
Note: See TracBrowser for help on using the repository browser.