/*------------------------------------------------------------------------- * xmunmap - xmunmap *------------------------------------------------------------------------- */ SYSCALL xmunmap(int virtpage ) { STATWORD ps; int getStoreValue, getPageNo; bs_map_t* main_bs; int getReturnValue, bs_no, page_no; unsigned int temp; /* sanity check ! */ if ( (virtpage < 4096) ) { // kprintf("xmummap call error: virtpage (%d) invalid! \n", virtpage); return SYSERR; } disable(ps); //kprintf("\nInside xmunmap().. %d ", virtpage); //getStoreValue = 20; getReturnValue = bsm_lookup(currpid, (virtpage*4096), &getStoreValue, &getPageNo); if (getReturnValue == SYSERR) { // kprintf("xmunmap(): could not find mapping!\n"); restore(ps); return SYSERR; } // kprintf("\nxmunmap(): bs returned %d!\n", getStoreValue); bs_no = getStoreValue; page_no = getPageNo; // For all frames that are mapped decrease their refcnts bstore_dec_fr_refcnt(bs_no, virtpage); getReturnValue = bsm_unmap(currpid, virtpage, bs_no); if( getReturnValue == SYSERR ) { //kprintf("xmummap: bsm_unmap error"); restore(ps); return(SYSERR); } //kprintf("\nxmummap: all OK"); temp = ((proctab[currpid].pdbr)<<12); write_cr3(temp); restore(ps); return(OK); }
/*------------------------------------------------------------------------- * xmunmap - xmunmap *------------------------------------------------------------------------- */ SYSCALL xmunmap(int virtpage ) { STATWORD ps; int bsid, page; /* sanity check ! */ if ( (virtpage < 4096) ){ kprintf("xmummap call error: virtpage (%d) invalid! \n", virtpage); return SYSERR; } if(OK == bsm_lookup(currpid, VPN2VAD(virtpage), &bsid, &page)){ write_back_frames(currpid, bsid); } ERROR_CHECK2( bsm_unmap(currpid, virtpage), ps); return OK; }
/*------------------------------------------------------------------------ * kill -- kill a process and remove it from the system *------------------------------------------------------------------------ */ SYSCALL kill(int pid) { STATWORD ps; struct pentry *pptr; /* points to proc. table for pid*/ int dev, i; disable(ps); if (isbadpid(pid) || (pptr= &proctab[pid])->pstate==PRFREE) { restore(ps); return(SYSERR); } if (--numproc == 0) xdone(); dev = pptr->pdevs[0]; if (! isbaddev(dev) ) close(dev); dev = pptr->pdevs[1]; if (! isbaddev(dev) ) close(dev); dev = pptr->ppagedev; if (! isbaddev(dev) ) close(dev); for(i = 0; i < NBS; i++) { bs_map_t *bs_ptr = &pptr->loc_bsm[i]; if(bs_ptr->bs_status == BSM_MAPPED){ bsm_unmap(pid,bs_ptr->bs_vpno, bs_ptr->bs_private); } free_bsm(i); } int source = pptr->pdbr/NBPG - FRAME0; free_frm(source); for(i = 0; i < NFRAMES; i++) { if(frm_tab[i].fr_pid == pid && frm_tab[i].fr_status == FRM_MAPPED){ //kprintf("freeing the frame %d for pid %d\n",i,pid); frm_tab[i].fr_status = FRM_UNMAPPED; frm_tab[i].fr_pid = UNDEFINED; frm_tab[i].fr_type = UNDEFINED; frm_tab[i].fr_refcnt = 0; frm_tab[i].fr_loadtime = UNDEFINED; frm_tab[i].fr_vpno = UNDEFINED; fifo_t *tmp = &fifo_head,*curr; while(tmp){ curr = tmp; tmp = tmp->fr_next; /*if(tmp && tmp->fr_id == -1) curr->fr_next = tmp->fr_next;*/ if(tmp && tmp->fr_id == i){ curr->fr_next = tmp->fr_next; //tmp->fr_next = NULL; break; } } } } fifo_t *tmp = &fifo_head,*curr; while(tmp){ curr = tmp; tmp = tmp->fr_next; /*if(tmp && tmp->fr_id == -1) curr->fr_next = tmp->fr_next;*/ if(tmp && (pid == frm_tab[tmp->fr_id].fr_pid)){ curr->fr_next = tmp->fr_next; //tmp->fr_next = NULL; } } send(pptr->pnxtkin, pid); freestk(pptr->pbase, pptr->pstklen); switch (pptr->pstate) { case PRCURR: pptr->pstate = PRFREE; /* suicide */ resched(); case PRWAIT: semaph[pptr->psem].semcnt++; case PRREADY: dequeue(pid); pptr->pstate = PRFREE; break; case PRSLEEP: case PRTRECV: unsleep(pid); /* fall through */ default: pptr->pstate = PRFREE; } restore(ps); return(OK); }
/******************************************************************************* * Name: bsm_remove_proc_maps * * Desc: Remvoes all the BS mappings of a process. Usually called when a * process is killed. * * Params: * pid - pid whose mapping is to be removed * * Returns: SYSCALL * OK - on sucess * SYSERR - on failure ******************************************************************************/ SYSCALL bsm_remove_proc_maps(int pid) { int bs_id = 0; bs_map_t *bsptr = NULL; STATWORD ps; disable(ps); DTRACE_START; if (isbadpid(pid)) { DTRACE("DBG$ %d %s> bad pid %d\n", currpid, __func__, pid); goto RESTORE_AND_RETURN_ERROR; } /* Remove the vheap, if the pid happens to have one. First remove (and write * back if necessary) the associated frames, remove the BS mappings and * finally release the BS. */ bs_id = P_GET_BS_ID(pid); if (BS_IS_ID_VALID(bs_id)) { bsptr = BS_GET_PTR(bs_id); /* Cleanup the frames first. */ if (OK != bsm_remove_frm(pid, bsptr)) { DTRACE("DBG$ %d %s> vheap bsm_remove_frm() failed\n", \ currpid, __func__); goto RESTORE_AND_RETURN_ERROR; } DTRACE("DBG$ %d %s> vheap bsm_remove_frm success\n", \ currpid, __func__); /* And, now the BS mapping. */ if (OK != bsm_unmap(pid, P_GET_VPAGE(pid), TRUE)) { DTRACE("DBG$ %d %s> vheap bsm_unmap() failed for pid %d, " \ "bs_id %d, vpage %d\n", currpid, __func__, pid); goto RESTORE_AND_RETURN_ERROR; } DTRACE("DBG$ %d %s> vheap bsm_unmap success\n", \ currpid, __func__); bsm_tab[bs_id]->bsm_status = BS_FREE; DTRACE("DBG$ %d %s> pid %d vheap bs id %d is now free\n", \ currpid, __func__, pid, bs_id); } /* Go over every BS and see if it has any mappings with this pid. If so, * first remove the associated frames and then remove the mappings. */ for (bs_id = 0; bs_id < BS_NUM; ++bs_id) { if (BS_IS_FREE(bs_id)) { continue; } bsptr = BS_GET_PTR(bs_id); while (bsptr) { if (bsptr->bsm_pid == pid) { /* First cleanup the frames held by this map. */ if (OK != bsm_remove_frm(pid, bsptr)) { DTRACE("DBG$ %d %s> bsm_remove_frm() failed\n", \ currpid, __func__); goto RESTORE_AND_RETURN_ERROR; } DTRACE("DBG$ %d %s> frms cleaned for pid %d, bs id %d " \ "using bsm_remove_frm()\n", \ currpid, __func__, pid, bsptr->bsm_id); /* Now, delete all the mappings. */ if (OK != bsm_unmap(pid, bsptr->bsm_vpno, TRUE)) { DTRACE("DBG$ %d %s> map bsm_unmap() failed for pid %d, "\ "bs_id %d, vpage %d\n", \ currpid, __func__, pid, bs_id, BS_GET_VPAGE(bs_id)); goto RESTORE_AND_RETURN_ERROR; } DTRACE("DBG$ %d %s> pid %d map is unmapped\n", \ currpid, __func__, pid); } bsptr = bsptr->bsm_next; } } DTRACE_END; restore(ps); return OK; RESTORE_AND_RETURN_ERROR: DTRACE("DBG$ %d %s> returning SYSERR\n", currpid, __func__); DTRACE_END; restore(ps); return SYSERR; }