1 | /* The kernel call implemented in this file:
|
---|
2 | * m_type: SYS_FORK
|
---|
3 | *
|
---|
4 | * The parameters for this kernel call are:
|
---|
5 | * m1_i1: PR_PROC_NR (child's process table slot)
|
---|
6 | * m1_i2: PR_PPROC_NR (parent, process that forked)
|
---|
7 | */
|
---|
8 |
|
---|
9 | #include "../system.h"
|
---|
10 | #include <signal.h>
|
---|
11 | #if (CHIP == INTEL)
|
---|
12 | #include "../protect.h"
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | #if USE_FORK
|
---|
16 |
|
---|
17 | /*===========================================================================*
|
---|
18 | * do_fork *
|
---|
19 | *===========================================================================*/
|
---|
20 | PUBLIC int do_fork(m_ptr)
|
---|
21 | register message *m_ptr; /* pointer to request message */
|
---|
22 | {
|
---|
23 | /* Handle sys_fork(). PR_PPROC_NR has forked. The child is PR_PROC_NR. */
|
---|
24 | #if (CHIP == INTEL)
|
---|
25 | reg_t old_ldt_sel;
|
---|
26 | #endif
|
---|
27 | register struct proc *rpc; /* child process pointer */
|
---|
28 | struct proc *rpp; /* parent process pointer */
|
---|
29 | int i;
|
---|
30 |
|
---|
31 | rpp = proc_addr(m_ptr->PR_PPROC_NR);
|
---|
32 | rpc = proc_addr(m_ptr->PR_PROC_NR);
|
---|
33 | if (isemptyp(rpp) || ! isemptyp(rpc)) return(EINVAL);
|
---|
34 |
|
---|
35 | /* Copy parent 'proc' struct to child. And reinitialize some fields. */
|
---|
36 | #if (CHIP == INTEL)
|
---|
37 | old_ldt_sel = rpc->p_ldt_sel; /* backup local descriptors */
|
---|
38 | *rpc = *rpp; /* copy 'proc' struct */
|
---|
39 | rpc->p_ldt_sel = old_ldt_sel; /* restore descriptors */
|
---|
40 | #else
|
---|
41 | *rpc = *rpp; /* copy 'proc' struct */
|
---|
42 | #endif
|
---|
43 | rpc->p_nr = m_ptr->PR_PROC_NR; /* this was obliterated by copy */
|
---|
44 |
|
---|
45 | /* Only one in group should have SIGNALED, child doesn't inherit tracing. */
|
---|
46 | rpc->p_rts_flags |= NO_MAP; /* inhibit process from running */
|
---|
47 | rpc->p_rts_flags &= ~(SIGNALED | SIG_PENDING | P_STOP);
|
---|
48 | sigemptyset(&rpc->p_pending);
|
---|
49 |
|
---|
50 | rpc->p_reg.retreg = 0; /* child sees pid = 0 to know it is child */
|
---|
51 | rpc->p_user_time = 0; /* set all the accounting times to 0 */
|
---|
52 | rpc->p_sys_time = 0;
|
---|
53 |
|
---|
54 | /* Parent and child have to share the quantum that the forked process had,
|
---|
55 | * so that queued processes do not have to wait longer because of the fork.
|
---|
56 | * If the time left is odd, the child gets an extra tick.
|
---|
57 | */
|
---|
58 | rpc->p_ticks_left = (rpc->p_ticks_left + 1) / 2;
|
---|
59 | rpp->p_ticks_left = rpp->p_ticks_left / 2;
|
---|
60 |
|
---|
61 | /* If the parent is a privileged process, take away the privileges from the
|
---|
62 | * child process and inhibit it from running by setting the NO_PRIV flag.
|
---|
63 | * The caller should explicitely set the new privileges before executing.
|
---|
64 | */
|
---|
65 | if (priv(rpp)->s_flags & SYS_PROC) {
|
---|
66 | rpc->p_priv = priv_addr(USER_PRIV_ID);
|
---|
67 | rpc->p_rts_flags |= NO_PRIV;
|
---|
68 | }
|
---|
69 | return(OK);
|
---|
70 | }
|
---|
71 |
|
---|
72 | #endif /* USE_FORK */
|
---|
73 |
|
---|