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