only check local benchmark dir if it exists
[minix.git] / kernel / system / do_exit.c
blob64f006287cc6aaaff29fd680407d21309abfcdd8
1 /* The kernel call implemented in this file:
2 * m_type: SYS_EXIT
4 * The parameters for this kernel call are:
5 * m1_i1: PR_ENDPT (slot number of exiting process)
6 */
8 #include "../system.h"
10 #include <minix/endpoint.h>
12 #if USE_EXIT
14 FORWARD _PROTOTYPE( void clear_proc, (register struct proc *rc));
16 /*===========================================================================*
17 * do_exit *
18 *===========================================================================*/
19 PUBLIC int do_exit(struct proc * caller, message * m_ptr)
21 /* Handle sys_exit. A user process has exited or a system process requests
22 * to exit. Only the PM can request other process slots to be cleared.
23 * The routine to clean up a process table slot cancels outstanding timers,
24 * possibly removes the process from the message queues, and resets certain
25 * process table fields to the default values.
27 int exit_e;
29 /* Determine what process exited. User processes are handled here. */
30 if (PM_PROC_NR == caller->p_endpoint) {
31 if (m_ptr->PR_ENDPT != SELF) { /* PM tries to exit self */
32 if(!isokendpt(m_ptr->PR_ENDPT, &exit_e)) /* get exiting process */
33 return EINVAL;
34 clear_proc(proc_addr(exit_e)); /* exit a user process */
35 return(OK); /* report back to PM */
39 /* The PM or some other system process requested to be exited. */
40 clear_proc(caller);
41 return(EDONTREPLY);
44 /*===========================================================================*
45 * clear_proc *
46 *===========================================================================*/
47 PRIVATE void clear_proc(rc)
48 register struct proc *rc; /* slot of process to clean up */
50 int i;
52 /* Don't clear if already cleared. */
53 if(isemptyp(rc)) return;
55 /* Check the table with IRQ hooks to see if hooks should be released. */
56 for (i=0; i < NR_IRQ_HOOKS; i++) {
57 if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
58 rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
59 irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
63 /* Remove the process' ability to send and receive messages */
64 clear_endpoint(rc);
67 /* Turn off any alarm timers at the clock. */
68 reset_timer(&priv(rc)->s_alarm_timer);
70 /* Make sure that the exiting process is no longer scheduled,
71 * and mark slot as FREE. Also mark saved fpu contents as not significant.
73 RTS_LOCK_SETFLAGS(rc, RTS_SLOT_FREE);
74 rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
76 /* Release the process table slot. If this is a system process, also
77 * release its privilege structure. Further cleanup is not needed at
78 * this point. All important fields are reinitialized when the
79 * slots are assigned to another, new process.
81 if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
83 #if 0
84 /* Clean up virtual memory */
85 if (rc->p_misc_flags & MF_VM) {
86 vm_map_default(rc);
88 #endif
91 #endif /* USE_EXIT */