1 /* The kernel call implemented in this file:
4 * The parameters for this kernel call are:
5 * m_lsys_krn_sys_clear.endpt (endpoint of process to clean up)
8 #include "kernel/system.h"
10 #include <minix/endpoint.h>
14 /*===========================================================================*
16 *===========================================================================*/
17 int do_clear(struct proc
* caller
, message
* m_ptr
)
19 /* Handle sys_clear. Only the PM can request other process slots to be cleared
20 * when a process has exited.
21 * The routine to clean up a process table slot cancels outstanding timers,
22 * possibly removes the process from the message queues, and resets certain
23 * process table fields to the default values.
29 if(!isokendpt(m_ptr
->m_lsys_krn_sys_clear
.endpt
, &exit_p
)) {
30 /* get exiting process */
33 rc
= proc_addr(exit_p
); /* clean up */
35 release_address_space(rc
);
37 /* Don't clear if already cleared. */
38 if(isemptyp(rc
)) return OK
;
40 /* Check the table with IRQ hooks to see if hooks should be released. */
41 for (i
=0; i
< NR_IRQ_HOOKS
; i
++) {
42 if (rc
->p_endpoint
== irq_hooks
[i
].proc_nr_e
) {
43 rm_irq_handler(&irq_hooks
[i
]); /* remove interrupt handler */
44 irq_hooks
[i
].proc_nr_e
= NONE
; /* mark hook as free */
48 /* Remove the process' ability to send and receive messages */
51 /* Turn off any alarm timers at the clock. */
52 reset_kernel_timer(&priv(rc
)->s_alarm_timer
);
54 /* Make sure that the exiting process is no longer scheduled,
55 * and mark slot as FREE. Also mark saved fpu contents as not significant.
57 RTS_SETFLAGS(rc
, RTS_SLOT_FREE
);
61 rc
->p_misc_flags
&= ~MF_FPU_INITIALIZED
;
63 /* Release the process table slot. If this is a system process, also
64 * release its privilege structure. Further cleanup is not needed at
65 * this point. All important fields are reinitialized when the
66 * slots are assigned to another, new process.
68 if (priv(rc
)->s_flags
& SYS_PROC
) priv(rc
)->s_proc_nr
= NONE
;
71 /* Clean up virtual memory */
72 if (rc
->p_misc_flags
& MF_VM
) {
80 #endif /* USE_CLEAR */