minix/kernel/system/do_exit.c
Tomas Hruby cca24d06d8 This patch removes the global variables who_p and who_e from the
kernel (sys task).  The main reason is that these would have to become
cpu local variables on SMP.  Once the system task is not a task but a
genuine part of the kernel there is even less reason to have these
extra variables as proc_ptr will already contain all neccessary
information. In addition converting who_e to the process pointer and
back again all the time will be avoided.

Although proc_ptr will contain all important information, accessing it
as a cpu local variable will be fairly expensive, hence the value
would be assigned to some on stack local variable. Therefore it is
better to add the 'caller' argument to the syscall handlers to pass
the value on stack anyway. It also clearly denotes on who's behalf is
the syscall being executed.

This patch also ANSIfies the syscall function headers.

Last but not least, it also fixes a potential bug in virtual_copy_f()
in case the check is disabled. So far the function in case of a
failure could possible reuse an old who_p in case this function had
not been called from the system task.

virtual_copy_f() takes the caller as a parameter too. In case the
checking is disabled, the caller must be NULL and non NULL if it is
enabled as we must be able to suspend the caller.
2010-02-03 09:04:48 +00:00

92 lines
2.9 KiB
C

/* The kernel call implemented in this file:
* m_type: SYS_EXIT
*
* The parameters for this kernel call are:
* m1_i1: PR_ENDPT (slot number of exiting process)
*/
#include "../system.h"
#include <minix/endpoint.h>
#if USE_EXIT
FORWARD _PROTOTYPE( void clear_proc, (register struct proc *rc));
/*===========================================================================*
* do_exit *
*===========================================================================*/
PUBLIC int do_exit(struct proc * caller, message * m_ptr)
{
/* Handle sys_exit. A user process has exited or a system process requests
* to exit. Only the PM can request other process slots to be cleared.
* The routine to clean up a process table slot cancels outstanding timers,
* possibly removes the process from the message queues, and resets certain
* process table fields to the default values.
*/
int exit_e;
/* Determine what process exited. User processes are handled here. */
if (PM_PROC_NR == caller->p_endpoint) {
if (m_ptr->PR_ENDPT != SELF) { /* PM tries to exit self */
if(!isokendpt(m_ptr->PR_ENDPT, &exit_e)) /* get exiting process */
return EINVAL;
clear_proc(proc_addr(exit_e)); /* exit a user process */
return(OK); /* report back to PM */
}
}
/* The PM or some other system process requested to be exited. */
clear_proc(caller);
return(EDONTREPLY);
}
/*===========================================================================*
* clear_proc *
*===========================================================================*/
PRIVATE void clear_proc(rc)
register struct proc *rc; /* slot of process to clean up */
{
int i;
/* Don't clear if already cleared. */
if(isemptyp(rc)) return;
/* Check the table with IRQ hooks to see if hooks should be released. */
for (i=0; i < NR_IRQ_HOOKS; i++) {
if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
}
}
/* Remove the process' ability to send and receive messages */
clear_endpoint(rc);
/* Turn off any alarm timers at the clock. */
reset_timer(&priv(rc)->s_alarm_timer);
/* Make sure that the exiting process is no longer scheduled,
* and mark slot as FREE. Also mark saved fpu contents as not significant.
*/
RTS_LOCK_SETFLAGS(rc, RTS_SLOT_FREE);
rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
/* Release the process table slot. If this is a system process, also
* release its privilege structure. Further cleanup is not needed at
* this point. All important fields are reinitialized when the
* slots are assigned to another, new process.
*/
if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
#if 0
/* Clean up virtual memory */
if (rc->p_misc_flags & MF_VM) {
vm_map_default(rc);
}
#endif
}
#endif /* USE_EXIT */