1 /* The kernel call implemented in this file:
4 * The parameters for this kernel call are:
5 * m1_i1: PR_ENDPT (slot number of exiting process)
10 #include <minix/endpoint.h>
14 FORWARD
_PROTOTYPE( void clear_proc
, (register struct proc
*rc
));
16 /*===========================================================================*
18 *===========================================================================*/
19 PUBLIC
int do_exit(m_ptr
)
20 message
*m_ptr
; /* pointer to request message */
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.
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 */
35 clear_proc(proc_addr(exit_e
)); /* exit a user process */
36 return(OK
); /* report back to PM */
40 /* The PM or some other system process requested to be exited. */
41 clear_proc(proc_addr(who_p
));
45 /*===========================================================================*
47 *===========================================================================*/
48 PRIVATE
void clear_proc(rc
)
49 register struct proc
*rc
; /* slot of process to clean up */
51 register struct proc
*rp
; /* iterate over process table */
52 register struct proc
**xpp
; /* iterate over caller queue */
56 /* Don't clear if already cleared. */
57 if(isemptyp(rc
)) return;
59 /* Remove the process' ability to send and receive messages */
62 /* Turn off any alarm timers at the clock. */
63 reset_timer(&priv(rc
)->s_alarm_timer
);
65 /* Make sure that the exiting process is no longer scheduled,
66 * and mark slot as FREE.
68 RTS_LOCK_SETFLAGS(rc
, SLOT_FREE
);
70 /* Check the table with IRQ hooks to see if hooks should be released. */
71 for (i
=0; i
< NR_IRQ_HOOKS
; i
++) {
73 if (rc
->p_endpoint
== irq_hooks
[i
].proc_nr_e
) {
74 rm_irq_handler(&irq_hooks
[i
]); /* remove interrupt handler */
75 irq_hooks
[i
].proc_nr_e
= NONE
; /* mark hook as free */
79 /* Release the process table slot. If this is a system process, also
80 * release its privilege structure. Further cleanup is not needed at
81 * this point. All important fields are reinitialized when the
82 * slots are assigned to another, new process.
84 if (priv(rc
)->s_flags
& SYS_PROC
) priv(rc
)->s_proc_nr
= NONE
;
86 /* Clean up virtual memory */
87 if (rc
->p_misc_flags
& MF_VM
)