1 | /* The kernel call implemented in this file:
|
---|
2 | * m_type: SYS_EXIT
|
---|
3 | *
|
---|
4 | * The parameters for this kernel call are:
|
---|
5 | * m1_i1: PR_ENDPT (slot number of exiting process)
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "../system.h"
|
---|
9 |
|
---|
10 | #include <minix/endpoint.h>
|
---|
11 |
|
---|
12 | #if USE_EXIT
|
---|
13 |
|
---|
14 | FORWARD _PROTOTYPE( void clear_proc, (register struct proc *rc));
|
---|
15 |
|
---|
16 | /*===========================================================================*
|
---|
17 | * do_exit *
|
---|
18 | *===========================================================================*/
|
---|
19 | PUBLIC int do_exit(m_ptr)
|
---|
20 | message *m_ptr; /* pointer to request message */
|
---|
21 | {
|
---|
22 | /* Handle sys_exit. A user process has exited or a system process requests
|
---|
23 | * to exit. Only the PM can request other process slots to be cleared.
|
---|
24 | * The routine to clean up a process table slot cancels outstanding timers,
|
---|
25 | * possibly removes the process from the message queues, and resets certain
|
---|
26 | * process table fields to the default values.
|
---|
27 | */
|
---|
28 | int exit_e;
|
---|
29 |
|
---|
30 | /* Determine what process exited. User processes are handled here. */
|
---|
31 | if (PM_PROC_NR == who_p) {
|
---|
32 | if (m_ptr->PR_ENDPT != SELF) { /* PM tries to exit self */
|
---|
33 | if(!isokendpt(m_ptr->PR_ENDPT, &exit_e)) /* get exiting process */
|
---|
34 | return EINVAL;
|
---|
35 | clear_proc(proc_addr(exit_e)); /* exit a user process */
|
---|
36 | return(OK); /* report back to PM */
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | /* The PM or some other system process requested to be exited. */
|
---|
41 | clear_proc(proc_addr(who_p));
|
---|
42 | return(EDONTREPLY);
|
---|
43 | }
|
---|
44 |
|
---|
45 | /*===========================================================================*
|
---|
46 | * clear_proc *
|
---|
47 | *===========================================================================*/
|
---|
48 | PRIVATE void clear_proc(rc)
|
---|
49 | register struct proc *rc; /* slot of process to clean up */
|
---|
50 | {
|
---|
51 | register struct proc *rp; /* iterate over process table */
|
---|
52 | register struct proc **xpp; /* iterate over caller queue */
|
---|
53 | int i;
|
---|
54 | int sys_id;
|
---|
55 | char saved_rts_flags;
|
---|
56 |
|
---|
57 | /* Don't clear if already cleared. */
|
---|
58 | if(isemptyp(rc)) return;
|
---|
59 |
|
---|
60 | /* Remove the process' ability to send and receive messages */
|
---|
61 | clear_endpoint(rc);
|
---|
62 |
|
---|
63 | /* Turn off any alarm timers at the clock. */
|
---|
64 | reset_timer(&priv(rc)->s_alarm_timer);
|
---|
65 |
|
---|
66 | /* Make sure that the exiting process is no longer scheduled. */
|
---|
67 | if (rc->p_rts_flags == 0) lock_dequeue(rc);
|
---|
68 |
|
---|
69 | /* Check the table with IRQ hooks to see if hooks should be released. */
|
---|
70 | for (i=0; i < NR_IRQ_HOOKS; i++) {
|
---|
71 | int proc;
|
---|
72 | if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
|
---|
73 | rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
|
---|
74 | irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* Release the process table slot. If this is a system process, also
|
---|
79 | * release its privilege structure. Further cleanup is not needed at
|
---|
80 | * this point. All important fields are reinitialized when the
|
---|
81 | * slots are assigned to another, new process.
|
---|
82 | */
|
---|
83 | saved_rts_flags = rc->p_rts_flags;
|
---|
84 | rc->p_rts_flags = SLOT_FREE;
|
---|
85 | if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
|
---|
86 |
|
---|
87 | /* Clean up virtual memory */
|
---|
88 | if (rc->p_misc_flags & MF_VM)
|
---|
89 | vm_map_default(rc);
|
---|
90 | }
|
---|
91 |
|
---|
92 | #endif /* USE_EXIT */
|
---|
93 |
|
---|