xref: /minix/minix/kernel/system/do_clear.c (revision 433d6423)
1 /* The kernel call implemented in this file:
2  *   m_type:	SYS_CLEAR
3  *
4  * The parameters for this kernel call are:
5  *   m_lsys_krn_sys_clear.endpt		(endpoint of process to clean up)
6  */
7 
8 #include "kernel/system.h"
9 
10 #include <minix/endpoint.h>
11 
12 #if USE_CLEAR
13 
14 /*===========================================================================*
15  *				do_clear				     *
16  *===========================================================================*/
do_clear(struct proc * caller,message * m_ptr)17 int do_clear(struct proc * caller, message * m_ptr)
18 {
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.
24  */
25   struct proc *rc;
26   int exit_p;
27   int i;
28 
29   if(!isokendpt(m_ptr->m_lsys_krn_sys_clear.endpt, &exit_p)) {
30       /* get exiting process */
31       return EINVAL;
32   }
33   rc = proc_addr(exit_p);	/* clean up */
34 
35   release_address_space(rc);
36 
37   /* Don't clear if already cleared. */
38   if(isemptyp(rc)) return OK;
39 
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 */
45       }
46   }
47 
48   /* Remove the process' ability to send and receive messages */
49   clear_endpoint(rc);
50 
51   /* Turn off any alarm timers at the clock. */
52   reset_kernel_timer(&priv(rc)->s_alarm_timer);
53 
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.
56    */
57   RTS_SETFLAGS(rc, RTS_SLOT_FREE);
58 
59   /* release FPU */
60   release_fpu(rc);
61   rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
62 
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.
67    */
68   if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
69 
70 #if 0
71   /* Clean up virtual memory */
72   if (rc->p_misc_flags & MF_VM) {
73   	vm_map_default(rc);
74   }
75 #endif
76 
77   return OK;
78 }
79 
80 #endif /* USE_CLEAR */
81