Esempio n. 1
0
/*------------------------------------------------------------------------
 * 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;
	inversion(pid);
	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);
	
	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++;
			int i;
			for(i=0;i<NLOCKS;i++)
			{
				if(proctab[pid].holding_lock[i].type != -1)
				{
					lockarr[i].lockcnt--;
					lockarr[i].process_lock[pid]=-1;
					if(proctab[pid].holding_lock[i].type==READ)
						lockarr[i].read_count--;
				}
			}

	case PRREADY:	dequeue(pid);
			pptr->pstate = PRFREE;
			break;

	case PRSLEEP:
	case PRTRECV:	unsleep(pid);
						/* fall through	*/
	default:	pptr->pstate = PRFREE;
	}
	restore(ps);
	return(OK);
}
Esempio n. 2
0
/*------------------------------------------------------------------------
 * 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;
	int i;
	disable(ps);
	if (isbadpid(pid) || (pptr= &proctab[pid])->pstate==PRFREE) {
		restore(ps);
		return(SYSERR);
	}

#ifdef ENABLE_LOCKS
  for (i = 0; i < NLOCKS; i++){
    if (locktab[i].procs[pid].lstate == LOCKED)
      release_lock(CREATELDESC(i, locktab[i].procs[pid].lage), pid);
    locktab[i].procs[pid].lstate = UNLOCKED;
  }
#endif

  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);
	
	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 PRLOCK:
	case PRREADY:	dequeue(pid);
			pptr->pstate = PRFREE;
			break;

	case PRSLEEP:
	case PRTRECV:	unsleep(pid);
						/* fall through	*/
	default:	pptr->pstate = PRFREE;
	}
	restore(ps);
	return(OK);
}
Esempio n. 3
0
/*------------------------------------------------------------------------
 *  kill  -  Kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
syscall	kill(
	  pid32		pid		/* ID of process to kill	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	procent *prptr;		/* Ptr to process's table entry	*/
	int32	i;			/* Index into descriptors	*/

	mask = disable();
	if (isbadpid(pid) || (pid == NULLPROC)
	    || ((prptr = &proctab[pid])->prstate) == PR_FREE) {
		restore(mask);
		return SYSERR;
	}

	if (prptr->prcleanup != NULL){
		prptr->prcleanup();
	}

	if (--prcount <= 1) {		/* Last user process completes	*/
		xdone();
	}

	send(prptr->prparent, pid);
	for (i=0; i<3; i++) {
		close(prptr->prdesc[i]);
	}
	freestk(prptr->prstkbase, prptr->prstklen);

	switch (prptr->prstate) {
	case PR_CURR:
		prptr->prstate = PR_FREE;	/* Suicide */
		resched();

	case PR_SLEEP:
	case PR_RECTIM:
		unsleep(pid);
		prptr->prstate = PR_FREE;
		break;

	case PR_WAIT:
		semtab[prptr->prsem].scount++;
		/* Fall through */

	case PR_READY:
		getitem(pid);		/* Remove from queue */
		/* Fall through */

	default:
		prptr->prstate = PR_FREE;
	}

	restore(mask);
	return OK;
}
Esempio n. 4
0
/*------------------------------------------------------------------------
 * kill  --  kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
SYSCALL kill(int pid)
{
extern int flag;
if(flag==1){	
	extern int freq[6][NPROC];
        freq[2][currpid]++;
	kprintf("########################################\n");
        kprintf("System Call(2) 'kill' being called by \"%s\" (pid=%d)\n", proctab[currpid].pname, currpid);
        kprintf("########################################\n");
}

	STATWORD ps;    
	struct	pentry	*pptr;		/* points to proc. table for pid*/
	int	dev;

	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);
	
	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);
}
Esempio n. 5
0
/*------------------------------------------------------------------------
 * 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, pdbr;

	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);
	
	send(pptr->pnxtkin, pid);
	
	
	proc_dies_clean_bs(pid);
	pdbr = proctab[pid].pdbr;
	//kprintf("\nFreeing frame in kill %d", (pdbr-FRAME0));
	free_frm((pdbr-FRAME0));
	
	
	
	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);
}
Esempio n. 6
0
/*------------------------------------------------------------------------
 * 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);
}
Esempio n. 7
0
/*------------------------------------------------------------------------
 * 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 i, dev;

	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);

	send(pptr->pnxtkin, pid);

	freestk(pptr->pbase, pptr->pstklen);
	switch (pptr->pstate) {

	case PRCURR:
		for (i = 0; i < NLOCKS; i++) {
			if (proctab[pid].locktype[i] != LNONE)
				release(pid,i);
		}
		pptr->pstate = PRFREE; /* suicide */
		resched();

	case PRWAIT:
		semaph[pptr->psem].semcnt++;

	case PRREADY:
		for (i = 0; i < NLOCKS; i++) {
			if (proctab[pid].locktype[i] != LNONE)
				release(pid,i);
		}
		dequeue(pid);
		pptr->pstate = PRFREE;
		break;

	case PRSLEEP:
	case PRTRECV:
		unsleep(pid);
		/* fall through	*/
	default:
		pptr->pstate = PRFREE;
		for (i = 0; i < NLOCKS; i++) {
			if (proctab[pid].locktype[i] != LNONE)
				release(pid,i);
		}
	}
	restore(ps);
	return (OK);
}
Esempio n. 8
0
/*------------------------------------------------------------------------
 * 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;

	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);
	
	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;
	}

	release_bs(proctab[pid].store);
	
	int i = 0;
	for(i = 0; i < NFRAMES; i++)
		{
		if(frm_tab[i].fr_pid == pid)
			{
			  if(frm_tab[i].fr_type == FR_PAGE)
			  	update_frm_fifo(i);
			  frm_tab[i].cookie = 0;
  			  frm_tab[i].fr_dirty = 0;
  			  frm_tab[i].fr_loadtime = 0;
  			  frm_tab[i].fr_pid = -1;
 			  frm_tab[i].fr_refcnt = 0;
 			  frm_tab[i].fr_status = FRM_UNMAPPED;
 			  frm_tab[i].fr_type = FR_PAGE;
 			  frm_tab[i].fr_vpno = BASE_VIRTUAL_PAGE;
 			  frm_tab[i].next_frame = -1;
			}
		}
	restore(ps);
	return(OK);
}
SYSCALL kill(int pid)
{
	STATWORD ps;    
	struct	pentry	*pptr;		/* points to proc. table for pid*/
	int	dev, i, callResched, lockID;
	callResched = RESCHNO;
	
	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<NLOCKS; i++)
	{
		if( locktab[i].acquiredby[pid] == 1)		//this process has acquired some lock and holding it, so release it and resched
		{
			//kprintf("\n Kill is holding lock %s", proctab[pid].pname);
			callResched = RESCHYES;
			relLock(pid, i, 0);
		}
	}
	
	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++;
					//if this proc is in wait queue of any lock i, remove it ... a proc can be in waiting q of any one lock only
					/* for( i=0; i<NLOCKS; i++)
					{
						
						if( (proctab[pid].procLockType[i]!=DELETED) && (locktab[i].acquiredby[pid]!=1) )
						{
							kprintf("Killed Process %d waiting on lock %d", pid, i);
							locktab[j].effectOfPriorityInheritance = 1;
							rampUpPriority(j, proctab[i].pprio);
						}
					} */
					
					
					lockID = getLockID(pptr->lockID);
					if( !isbadlock(lockID) || locktab[lockID].lstate != LOCKFREE )
					{
						//dequeue(pid);
						//kprintf("\nKill proc getting called in PRWAIT, releasing wait lock %d..%d", lockID, pid);
						proctab[pid].pprio = -1;
						proctab[pid].mainPrio = -1;
						relLock(pid, lockID, 1);
						//dequeue(pid);
					}
					

	case PRREADY:	dequeue(pid);
			pptr->pstate = PRFREE;
			break;

	case PRSLEEP:
	case PRTRECV:	unsleep(pid);
						/* fall through	*/
	default:	pptr->pstate = PRFREE;
	}
	
	if(callResched)
	{
		//kprintf("\n About to call resched");
		//indicates that this proc was holding lock and is deleted
		//in between so now it should release lock and call resched
		resched();
	}
	
	restore(ps);
	return(OK);
}
Esempio n. 10
0
/*------------------------------------------------------------------------
 * 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);

    send(pptr->pnxtkin, pid);
    kill_frames(pid);
    for (i = 0; i < NBS; i++) {

        if (bsm_tab[i].bs_status == BSM_MAPPED) {

            struct bs_proc_map_t *head = bsm_tab[i].mapping;
            while (head != NULL) {
                if ((head->pid == pid) && (head == bsm_tab[i].mapping)) {
                    head = head->next;

                    bsm_tab[i].mapping = head;
                    break;
                } else if (head->next != NULL) {
                    if (head->next->pid == pid) {
                        head->next = head->next->next;
                        break;
                    }
                }
                head = head->next;
            }
            if (bsm_tab[i].mapping == NULL) {
                bsm_tab[i].bs_status = BSM_UNMAPPED;
                free_bsm(i);
            }


        }
    }

    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: //kprintf("killing pid %d in sleep\n",pid);
        case PRTRECV: unsleep(pid);
            /* fall through	*/
        default: pptr->pstate = PRFREE;
    }
    restore(ps);
    return (OK);
}
Esempio n. 11
0
/*------------------------------------------------------------------------
 *  kill  -  Kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
syscall	kill(
	  pid32		pid		/* ID of process to kill	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	struct	procent *prptr;		/* Ptr to process' table entry	*/
	int32	i;			/* Index into descriptors	*/

	mask = disable();
	if (isbadpid(pid) || (pid == NULLPROC)
	    || ((prptr = &proctab[pid])->prstate) == PR_FREE) {
		restore(mask);
		return SYSERR;
	}
    /*
     * Virtual memory-related cleanup section.
     */
    /* If backing store was allocated, close and deallocate it */
    int retries = 4;
    bsd_t bs = (bsd_t) -1;
    if(prptr->prbs == -1) {
        bs = 0;
    }
    while(bs == -1 && retries > 0) {
        bs = deallocate_bs(close_bs(prptr->prbs));
        retries --;
    }
    if(bs == -1) {
        kprintf("!!Warning: could not close and deallocate the backing store of pid %d. ",pid);
    }

    /* Deallocate all physical frames that the current process holds */
    free_proc_frames(pid);

    /* Free virtual memory free list */
    struct vmemblk *next, *cur = prptr->prvmemlist;
    while(cur!=NULL) {
        next = cur->mnext;
        freemem((char*)cur, sizeof(struct vmemblk));
        cur = next;
    }



	if (--prcount <= 1) {		/* Last user process completes	*/
		xdone();
	}

	send(prptr->prparent, pid);
	for (i=0; i<3; i++) {
		close(prptr->prdesc[i]);
	}
	freestk(prptr->prstkbase, prptr->prstklen);

	switch (prptr->prstate) {
	case PR_CURR:
		prptr->prstate = PR_FREE;	/* Suicide */
		resched();

	case PR_SLEEP:
	case PR_RECTIM:
		unsleep(pid);
		prptr->prstate = PR_FREE;
		break;

	case PR_WAIT:
		semtab[prptr->prsem].scount++;
		/* Fall through */

	case PR_READY:
		getitem(pid);		/* Remove from queue */
		/* Fall through */

	default:
		prptr->prstate = PR_FREE;
	}

	restore(mask);
	return OK;
}
Esempio n. 12
0
/*------------------------------------------------------------------------
 *  kill  -  Kill a process and remove it from the system
 *------------------------------------------------------------------------
 */
syscall	kill(
	  pid32		pid		/* ID of process to kill	*/
	)
{
	intmask	mask;			/* saved interrupt mask		*/
	struct	procent *prptr;		/* ptr to process' table entry	*/
	int32	i;			/* index into descriptors	*/
	struct	pipent	*pipptr;	/* ptr to pipe entry		*/

	mask = disable();
	if (isbadpid(pid) || (pid == NULLPROC)
	    || ((prptr = &proctab[pid])->prstate) == PR_FREE) {
		restore(mask);
		return SYSERR;
	}

	if (--prcount <= 1) {		/* last user process completes	*/
		xdone();
	}

	for(i = 0 ; i < NPIPE ; i++) {
		pipptr = &piptab[i];
		if(pipptr->owner == (pid32) getpid) {
			pipptr->pipstate = PIPE_FREE;
			memset(piptab[i].buff, '\0', PIPE_SIZE);
			pipptr->owner = -1;	
			pipptr->reader = -1;
			pipptr->writer = -1;
			pipcount--;
		}
	}

	send(prptr->prparent, pid);
	for (i=0; i<3; i++) {
		close(prptr->prdesc[i]);
	}
	freestk(prptr->prstkbase, prptr->prstklen);

	switch (prptr->prstate) {
	case PR_CURR:
		prptr->prstate = PR_FREE;	/* suicide */
		resched();

	case PR_SLEEP:
	case PR_RECTIM:
		unsleep(pid);
		prptr->prstate = PR_FREE;
		break;

	case PR_WAIT:
		semtab[prptr->prsem].scount++;
		/* fall through */

	case PR_READY:
		getitem(pid);		/* remove from queue */
		/* fall through */

	default:
		prptr->prstate = PR_FREE;
	}

	restore(mask);
	return OK;
}
Esempio n. 13
0
SYSCALL create(int (*procaddr)(), int ssize, int priority, char *name, int nargs, ...)
{
	STATWORD ps;    
	int pid;				/* stores new process id	*/
	struct pentry *pptr;	/* pointer to proc. table entry */
	int i;
	unsigned char *saddr;			/* stack address		*/
	int INITRET();
	va_list ap;

	disable(ps);
	ssize = (int) roundmb(ssize);
	if ( (saddr = (unsigned char *)getstk(ssize)) == (unsigned char *)SYSERR ) {
	    restore(ps);
	    return (SYSERR);
	}
	if ( ssize < MINSTK || (pid=newpid()) == SYSERR || priority < 1 ) {
	    freestk((unsigned)saddr, (unsigned)ssize);
	    restore(ps);
	    return(SYSERR);
	}
	numproc++;
	pptr = &proctab[pid];
	
	/* stderr set to &kprint_out (see kprintf.c and initialize.c) */
	pptr->fildes[0] = fdopen(CONSOLE, "r");	/* stdin set to console */
	pptr->fildes[1] = fdopen(CONSOLE, "w");	/* stdout set to console */
	pptr->fildes[2] = &kprint_out;			/* stderr set to &kprint_out */

	for (i=2; i < _NFILE; i++)			/* others set to unused */
		pptr->fildes[i] = (FILE *)FDFREE;

	pptr->pstate = PRSUSP;
	for (i=0 ; i<PNMLEN && (int)(pptr->pname[i]=name[i])!=0 ; i++)
		;
	pptr->pprio = priority;
	pptr->pbase = saddr;
	pptr->pstklen = ssize;
	pptr->psem = 0;
	pptr->phasmsg = FALSE;
	pptr->plimit = pptr->pbase - ssize + sizeof (WORD);	
	*saddr-- = (char)MAGIC;		/* Bottom of stack */
	pptr->pargs = nargs;
	for (i=0 ; i<PNREGS ; i++)
		pptr->pregs[i] = INITREG;	
	pptr->paddr = (int *)procaddr;
	pptr->pregs[SPC_L] = lobyte((unsigned) procaddr);
	pptr->pregs[SPC_H] = hibyte((unsigned) procaddr);
	pptr->pregs[SSREG] = INITPS;
	pptr->pnxtkin = BADPID;
	pptr->pdevs[0] = pptr->pdevs[1] = BADDEV;
	
	va_start(ap,nargs);
	for (i=0 ; i < nargs; i++)
		{
	    pptr->parg[i] = va_arg(ap, unsigned int);
		}
	va_end(ap);
	pptr->parg[nargs] = 0;
	
	/* machine/compiler dependent pass arguments to created process */
	pptr->pregs[24] = lobyte((unsigned)pptr->pargs);	/*r24*/
	pptr->pregs[25] = hibyte((unsigned)pptr->pargs);
	pptr->pregs[22] = lobyte((unsigned)&pptr->parg[0]);	/*r22*/
	pptr->pregs[23] = hibyte((unsigned)&pptr->parg[0]);

	*saddr-- = lobyte((unsigned)INITRET);	/* push on initial return address*/
	*saddr-- = hibyte((unsigned)INITRET);
//	*saddr-- = 0;	/* 256Kb memory device */ /*TODO make conditional*/
	*saddr-- = lobyte((unsigned)procaddr);	/* push on procedure address	*/
	*saddr-- = hibyte((unsigned)procaddr);
//	*saddr-- = 0;	/* 256Kb memory device */ /*TODO make conditional*/
	pptr->pregs[SSP_L] = lobyte((unsigned) saddr);
	pptr->pregs[SSP_H] = hibyte((unsigned) saddr);

	restore(ps);
	return(pid);
}
Esempio n. 14
0
/*------------------------------------------------------------------------
 * 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;

	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);
	
	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;
			bs_map_t *temp;
			int i;
                        for (i=0;i<16;i++)
			{
				temp = &bsm_tab[i];
				 while(temp !=NULL)
			        {
			                if(temp->bs_pid == currpid)
			                {
			                        xmunmap(temp->bs_vpno);
						if(temp->bs_private_heap == 1)
							release_bs(i);
			                        return OK;
				         }
			                temp=temp->next;
				}

	}			}
	restore(ps);
	return(OK);
}
Esempio n. 15
0
syscall	kill(
	  pid32		pid		/* ID of process to kill	*/
	)
{
	intmask	mask;			/* Saved interrupt mask		*/
	int32	i;			/* Index into descriptors	*/
	struct	procent *prptr = &proctab[currpid];		/* Ptr to process' table entry	*/\
	struct memblkentry *prevmemblkptr = prptr->prmemblklist;
	struct memblkentry *memblkptr =  prevmemblkptr->next;

	//kprintf("in here homie bad zone\n");

	mask = disable();
	if (isbadpid(pid) || (pid == NULLPROC)
	    || ((prptr = &proctab[pid])->prstate) == PR_FREE) {
		restore(mask);
		return SYSERR;
	}
	
	while(memblkptr != NULL){
		prevmemblkptr = memblkptr;
		memblkptr = memblkptr->next;
	}

	//kprintf("prptr->prmemblklist->size before :%d\n",prptr->prmemblklist->size);
	prevmemblkptr->size = 0;
	prptr->prmemblklist->size = prevmemblkptr->size;
	prevmemblkptr->next = NULL;
	//kprintf("prptr->prmemblklist->size after :%d\n",prptr->prmemblklist->size);
	

	if (--prcount <= 1) {		/* Last user process completes	*/
		xdone();
	}

	send(prptr->prparent, pid);
	for (i=0; i<3; i++) {
		close(prptr->prdesc[i]);
	}
	freestk(prptr->prstkbase, prptr->prstklen);

	switch (prptr->prstate) {
	case PR_CURR:
		prptr->prstate = PR_FREE;	/* Suicide */
		resched();

	case PR_SLEEP:
	case PR_RECTIM:
		unsleep(pid);
		prptr->prstate = PR_FREE;
		break;

	case PR_WAIT:
		semtab[prptr->prsem].scount++;
		/* Fall through */

	case PR_READY:
		getitem(pid);		/* Remove from queue */
		/* Fall through */

	default:
		prptr->prstate = PR_FREE;
	}

	kprintf("prptr->prmemblklist->size %d\n",prevmemblkptr->size);
	restore(mask);
	return OK;
}