ramdisk Makefile: CLEANFILES fix
[minix.git] / kernel / system / do_clear.c
blobf2f8fd8c9acc9551d53b2632e4472fb993f95bff
1 /* The kernel call implemented in this file:
2 * m_type: SYS_CLEAR
4 * The parameters for this kernel call are:
5 * m1_i1: PR_ENDPT (endpoint of process to clean up)
6 */
8 #include "kernel/system.h"
10 #include <minix/endpoint.h>
12 #if USE_CLEAR
14 /*===========================================================================*
15 * do_clear *
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.
25 struct proc *rc;
26 int exit_p;
27 int i;
29 if(!isokendpt(m_ptr->PR_ENDPT, &exit_p)) { /* get exiting process */
30 return EINVAL;
32 rc = proc_addr(exit_p); /* clean up */
34 release_address_space(rc);
36 /* Don't clear if already cleared. */
37 if(isemptyp(rc)) return OK;
39 /* Check the table with IRQ hooks to see if hooks should be released. */
40 for (i=0; i < NR_IRQ_HOOKS; i++) {
41 if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
42 rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
43 irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
47 /* Remove the process' ability to send and receive messages */
48 clear_endpoint(rc);
50 /* Turn off any alarm timers at the clock. */
51 reset_timer(&priv(rc)->s_alarm_timer);
53 /* Make sure that the exiting process is no longer scheduled,
54 * and mark slot as FREE. Also mark saved fpu contents as not significant.
56 RTS_SETFLAGS(rc, RTS_SLOT_FREE);
58 /* release FPU */
59 release_fpu(rc);
60 rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
62 /* Release the process table slot. If this is a system process, also
63 * release its privilege structure. Further cleanup is not needed at
64 * this point. All important fields are reinitialized when the
65 * slots are assigned to another, new process.
67 if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
69 #if 0
70 /* Clean up virtual memory */
71 if (rc->p_misc_flags & MF_VM) {
72 vm_map_default(rc);
74 #endif
76 return OK;
79 #endif /* USE_CLEAR */