コード例 #1
0
ファイル: lpage.c プロジェクト: ShaoyuC/OS161
/*
 * lpage_destroy: deallocates a logical page. Releases any RAM or swap
 * pages involved.
 *
 * Synchronization: Someone might be in the process of evicting the
 * page if it's resident, so it might be pinned. So lock and pin
 * together.
 *
 * We assume that lpages are not shared between address spaces and
 * address spaces are not shared between threads.
 */
void 					
lpage_destroy(struct lpage *lp)
{
	paddr_t pa;

	KASSERT(lp != NULL);

	lpage_lock_and_pin(lp);

	pa = lp->lp_paddr & PAGE_FRAME;
	if (pa != INVALID_PADDR) {
		DEBUG(DB_VM, "lpage_destroy: freeing paddr 0x%x\n", pa);
		lp->lp_paddr = INVALID_PADDR;
		lpage_unlock(lp);
		coremap_free(pa, false /* iskern */);
		coremap_unpin(pa);
	}
	else {
		lpage_unlock(lp);
	}

	if (lp->lp_swapaddr != INVALID_SWAPADDR) {
		DEBUG(DB_VM, "lpage_destroy: freeing swap addr 0x%llx\n", 
		      lp->lp_swapaddr);
		swap_free(lp->lp_swapaddr);
	}

	spinlock_cleanup(&lp->lp_spinlock);
	kfree(lp);
}
コード例 #2
0
ファイル: synch.c プロジェクト: sfurrow88/cs571_sfurrow
void
lock_destroy(struct lock *lock)
{
    kfree(lock->lk_name);
    wchan_destroy(lock->lk_wchan);
    spinlock_cleanup(&lock->spin_lock);
    kfree(lock);
}
コード例 #3
0
ファイル: synch.c プロジェクト: sfurrow88/cs571_sfurrow
void
cv_destroy(struct cv *cv)
{
    KASSERT(cv != NULL);
    kfree(cv->cv_name);
    wchan_destroy(cv->cv_wchan);
    spinlock_cleanup(&cv->spin_lock);
    kfree(cv);
}
コード例 #4
0
ファイル: synch.c プロジェクト: simnic31/OS
void
lock_destroy(struct lock *lock)
{
        KASSERT(lock != NULL);

        spinlock_cleanup(&lock->lk_spinlock);
		  wchan_destroy(lock->lk_wchan);
        kfree(lock->lk_name);
        kfree(lock);
}
コード例 #5
0
ファイル: synch.c プロジェクト: jamesidzik/Test
void
lock_destroy(struct lock *lock)
{
        KASSERT(lock != NULL);

        // add stuff here as needed
        spinlock_cleanup(&lock->lk_spinlock);
        wchan_destroy(lock->lk_wchan);
        kfree(lock->lk_name);
        kfree(lock);
}
コード例 #6
0
ファイル: synch.c プロジェクト: ChunHungLiu/pikachuos
void
cv_destroy(struct cv *cv)
{
    KASSERT(cv != NULL);

    // add stuff here as needed
    spinlock_cleanup(&cv->cv_lock);
    wchan_destroy(cv->cv_wchan);
    kfree(cv->cv_name);
    kfree(cv);
}
コード例 #7
0
ファイル: synch.c プロジェクト: y3046308/os-group-project
void
sem_destroy(struct semaphore *sem)
{
        KASSERT(sem != NULL);

	/* wchan_cleanup will assert if anyone's waiting on it */
	spinlock_cleanup(&sem->sem_lock);
	wchan_destroy(sem->sem_wchan);
        kfree(sem->sem_name);
        kfree(sem);
}
コード例 #8
0
ファイル: vnode.c プロジェクト: MartinoMensio/os161
/*
 * Destroy an abstract vnode.
 */
void
vnode_cleanup(struct vnode *vn)
{
	KASSERT(vn->vn_refcount == 1);

	spinlock_cleanup(&vn->vn_countlock);

	vn->vn_ops = NULL;
	vn->vn_refcount = 0;
	vn->vn_fs = NULL;
	vn->vn_data = NULL;
}
コード例 #9
0
void
lock_destroy(struct lock *lock)
{
	KASSERT(lock != NULL);
    KASSERT(lock_do_i_hold(lock) == false);
	// add stuff here as needed
    lock->lk_curthread = NULL;
	spinlock_cleanup(&lock->lk_spinlock);
	wchan_destroy(lock->lk_wchan);
	kfree(lock->lk_name);
	kfree(lock);
}
コード例 #10
0
ファイル: cv.c プロジェクト: plurmiscuous/JinxOS
void
cv_destroy(struct cv* cv) {
    assert(cv != NULL);

    // wchan_cleanup will assert if anyone's waiting on it
    spinlock_cleanup(&cv->cv_splock);
    wchan_destroy(cv->cv_wchan);

    // provided code
    kfree(cv->cv_name);
    kfree(cv);
}
コード例 #11
0
ファイル: synch.c プロジェクト: jmangue/os161
void
lock_destroy(struct lock *lk)
{
        KASSERT(lk != NULL);
		  KASSERT(lk->locked == false);

        // add stuff here as needed
        spinlock_cleanup(&lk->slock);
		  wchan_destroy(lk->lock_wchan);
		  
		  kfree(lk->lk_name);
        kfree(lk);
}
コード例 #12
0
ファイル: proc.c プロジェクト: BWK/os161
/*
 * Destroy a proc structure.
 *
 * Note: nothing currently calls this. Your wait/exit code will
 * probably want to do so.
 */
void
proc_destroy(struct proc *proc)
{
	/*
	 * You probably want to destroy and null out much of the
	 * process (particularly the address space) at exit time if
	 * your wait/exit design calls for the process structure to
	 * hang around beyond process exit. Some wait/exit designs
	 * do, some don't.
	 */

	KASSERT(proc != NULL);
	KASSERT(proc != kproc);

	/*
	 * We don't take p_lock in here because we must have the only
	 * reference to this structure. (Otherwise it would be
	 * incorrect to destroy it.)
	 */

	/* VFS fields */
	if (proc->p_cwd) {
		VOP_DECREF(proc->p_cwd);
		proc->p_cwd = NULL;
	}

	/* VM fields */
	if (proc->p_addrspace) {
		/*
		 * In case p is the currently running process (which
		 * it might be in some circumstances, or if this code
		 * gets moved into exit as suggested above), clear
		 * p_addrspace before calling as_destroy. Otherwise if
		 * as_destroy sleeps (which is quite possible) when we
		 * come back we'll be calling as_activate on a
		 * half-destroyed address space. This tends to be
		 * messily fatal.
		 */
		struct addrspace *as;

		as_deactivate();
		as = curproc_setas(NULL);
		as_destroy(as);
	}

	threadarray_cleanup(&proc->p_threads);
	spinlock_cleanup(&proc->p_lock);

	kfree(proc->p_name);
	kfree(proc);
}
コード例 #13
0
ファイル: synch.c プロジェクト: y3046308/os-group-project
void
lock_destroy(struct lock *lock)
{
        KASSERT(lock != NULL);

        // add stuff here as needed
		#if OPT_A1
		spinlock_cleanup(&lock->lock_lock);
		wchan_destroy(lock->lk_wchan);
		lock->lock_holder = NULL;
		#endif
        kfree(lock->lk_name);
        kfree(lock);
}
コード例 #14
0
ファイル: synch.c プロジェクト: HeliWang/cs350OS
void
cv_destroy(struct cv *cv)
{
        KASSERT(cv != NULL);
	
        #if OPT_A1

	spinlock_cleanup(&cv->cv_spinlock);
	wchan_destroy(cv->cv_wchan);
	
	#endif        
        kfree(cv->cv_name);
        kfree(cv);
}
コード例 #15
0
ファイル: file.c プロジェクト: gapry/os161
/*
 * filetable_destroy
 * closes the files in the file table, frees the table.
 * This should be called as part of cleaning up a process (after kill
 * or exit).
 */
void
filetable_destroy(struct filetable *ft)
{
    DEBUG(DB_VFS, "*** Destroying filetable\n");
    int fd;
    for (fd = 0; fd < __OPEN_MAX; fd++) {
        struct filetable_entry *ft_entry = ft->ft_entries[fd];
        if (ft_entry != NULL) {
            file_close(fd);
        }
    }
    
	spinlock_cleanup(&ft->ft_spinlock);
    kfree(ft);
}	
コード例 #16
0
void rwlock_destroy(struct rwlock *rwlock) {
	KASSERT(rwlock != NULL);
	//KASSERT(rwlock_do_i_hold(rwlock) == false);
    KASSERT(rwlock->rwlock_readers_count == 0);
    KASSERT(rwlock->is_held_by_writer == false);
	//kprintf("threadlist count: %d\n", rwlock->readers_list.tl_count);
	spinlock_cleanup(&rwlock->rwlock_spinlock);
	wchan_destroy(rwlock->rwlock_read_wchan);
	wchan_destroy(rwlock->rwlock_write_wchan);
	lock_destroy(rwlock->rwlock_write_lock);
	//cv_destroy(rwlock->rwlock_cv_lock);
	//threadlist_cleanup(&rwlock->readers_list);
	kfree(rwlock->rwlock_name);
	kfree(rwlock);
}
コード例 #17
0
ファイル: synch.c プロジェクト: shaon0000/massive-wookie
void
lock_destroy(struct lock *lock)
{
#if OPT_A1
    KASSERT(lock != NULL);
    spinlock_cleanup(&lock->lk_spinlock);
    wchan_destroy(lock->lock_wchan);
    lock->lock_wchan = NULL;
    lock->initial_thread = NULL;
    kfree(lock->lk_name);
    kfree(lock);
#else
    (void*)lock;
#endif
}
コード例 #18
0
void
lock_destroy(struct lock *mylock)
{
        KASSERT(mylock != NULL);

        // add stuff here as needed
        
        spinlock_cleanup(&mylock->lk_spinlock);
        wchan_destroy(mylock->lk_wchan);

        //end of added stuff

        kfree(mylock->lk_name);
        kfree(mylock);
}
コード例 #19
0
ファイル: synch.c プロジェクト: hccyang/OS-system
void
lock_destroy(struct lock *lock)
{
        KASSERT(lock != NULL);

        // add stuff here as needed
        spinlock_cleanup(&lock->splk);
        wchan_destroy(lock->lock_wchan);
        
        kfree(lock->lk_name);
        //kfree(lock->currentplace);
        kfree(lock);
        
        //lock = NULL;
       
        
}
コード例 #20
0
ファイル: synch.c プロジェクト: jcseto/os161-1.99
void
cv_destroy(struct cv *cv)
{
        KASSERT(cv != NULL);

        // add stuff here as needed
        #if OPT_A1
        spinlock_cleanup(&(cv->cv_spinlock));
        wchan_destroy(cv->cv_wchan);
        kfree(cv->cv_name);
        kfree(cv);
        #else

        kfree(cv->cv_name);
        kfree(cv);
        #endif
}
コード例 #21
0
ファイル: mngr.c プロジェクト: nguyenduchien1994/os161
void proc_mngr_destroy(proc_mngr *ptr)
{
  KASSERT(ptr != NULL);

  spinlock_cleanup(&ptr->run_lk);
  lock_destroy(ptr->write_lk);
  lock_destroy(ptr->read_lk);
  lock_destroy(ptr->proc_sys_lk);
  lock_destroy(ptr->file_sys_lk);
  Linked_List_Node *runner = ptr->free_ids->first;
  while(runner != NULL){
    kfree(runner->data);
    runner = runner->next;
  }
  linkedlist_destroy(ptr->free_ids);
  multi_queue_destroy(ptr->ready_queue);
  kfree(ptr->threads);
  kfree(ptr->procs);
  kfree(ptr);
}
コード例 #22
0
ファイル: unsafethreadcounter.c プロジェクト: noaner/OS161
int
spinlockthreadcounter(int nargs, char **args)
{
    unsigned long num_threads = DEFAULT_THREADS;
    unsigned long num_inc = DEFAULT_INC;

    if (nargs > 1)
        num_threads = atoi(args[1]);
    if (nargs > 2)
        num_inc = atoi(args[2]);

    init_sem();
    spinlock_init(&thread_spinlock);
    kprintf("Starting a thread counter using spinlocks with %lu threads...\n", num_threads);
    runspinlockthreadcounter(num_threads, num_inc);
    kprintf("\nThread test done.\n");
    kprintf("Counter: %lu (should be %lu)\n", counter, num_threads * num_inc);
    spinlock_cleanup(&thread_spinlock);
    destroy_sem();

    return 0;
}
コード例 #23
0
ファイル: smartvm.c プロジェクト: smflorentino/os161
/* Initialization function */
void vm_bootstrap() 
{
	
	/* Get the firstaddr and lastaddr of physical memory.
	It will most definitely be less than actual memory; becuase
	before the VM bootstraps we have to use getppages (which in turn
	calls stealmem).
	*/
	paddr_t firstaddr, lastaddr;
	ram_getsize(&firstaddr,&lastaddr);
	/* The number of pages (core map entries) will be the size of 
	physical memory (lastaddr *should* not change) divided by PAGE_SIZE
	*/
	page_count = lastaddr / PAGE_SIZE;
	/* Allocate space for the coremap *without* using kmalloc. This 
	solves the chicken-and-egg problem. Simply set the core_map pointer
	to point to the first available address of memory as of this point;
	then increment freeaddr by the size of the coremap (we're effectively 
	replicating stealmem here, but we're not grabbing a whole page) */
	core_map = (struct page*)PADDR_TO_KVADDR(firstaddr);
	paddr_t freeaddr = firstaddr + page_count * sizeof(struct page);
	// kprintf("FirstAddr: %p\n", (void*) firstaddr);
	// kprintf("Freeaddr: %p\n", (void*) freeaddr);
	// kprintf("Size of Core Map: %d\n", page_count * sizeof(struct page));
	// kprintf("Base Addr of core_map: %p\n", &core_map);
	// kprintf("Base Addr of core_map[0]: %p\n", &core_map[0]);
	// kprintf("Base Addr of core_map[127]: %p\n", &core_map[127]);
	
	/* Calculate the number of fixed pages. The number of fixed pages
	will be everything from 0x0 to freeaddr (essentially all the stolen
	memory will be FIXED). This might be a signficant amount; up until VM bootstrapping
	kmalloc will steal memory. This is the only way to solve the chicken-and-egg problem
	of the VM needing kmalloc and kmalloc needing VM.*/
	size_t num_of_fixed_pages = (freeaddr / PAGE_SIZE);
	if(freeaddr % PAGE_SIZE != 0)
	{
		/*If the stolen memory crosses a page boundry (probabably almost always will)
		mark that partially stolen page as FIXED*/
		num_of_fixed_pages++;
	}
	//Now, mark every (stolen) page from 0 to freeaddr as FIXED...
	for(size_t i = 0; i<num_of_fixed_pages; i++)
	{
		// kprintf("Address of Core Map %d: %p ",i,&core_map[i]);
		// kprintf("PA of Core Map %d:%p\n", i, (void*) (PAGE_SIZE * i));
		core_map[i].pa = i * PAGE_SIZE;
		// core_map[i].va = PADDR_TO_KVADDR(i * PAGE_SIZE);
		core_map[i].state = FIXED;
		core_map[i].as = 0x0;
	}
	/* Mark every available page (from freeaddr + offset into next page,
	if applicable) to lastaddr as FREE*/
	for(size_t i = num_of_fixed_pages; i<page_count; i++)
	{
		// kprintf("Address of Core Map %d: %p\n",i,&core_map[i]);
		// kprintf("PA of Core Map %d:%p\n", i, (void*) (PAGE_SIZE * i));
		// kprintf("KVA of Core Map %d:%p\n",i, (void*) PADDR_TO_KVADDR(PAGE_SIZE*i));
		core_map[i].state = FREE;
		core_map[i].as = 0x0;
		core_map[i].va = 0x0;
		free_pages++;
	}
	/* Set VM initialization flag. alloc_kpages and free_kpages
	should behave accordingly now*/
	vm_initialized = true;
	/* Now that the VM is initialized, create a lock */
	spinlock_cleanup(&stealmem_lock);
	spinlock_init(&stealmem_lock);
	core_map_lock = lock_create("coremap_lock");
}
コード例 #24
0
/*
 * Create a proc structure.
 */
static struct proc *
proc_create(const char *name) {
	struct proc *proc;

	proc = kmalloc(sizeof(*proc));
	if (proc == NULL) {
		return NULL;
	}
	proc->p_name = kstrdup(name);
	if (proc->p_name == NULL) {
		kfree(proc);
		return NULL;
	}

	proc->p_numthreads = 0;
	spinlock_init(&proc->p_lock);

	/* VM fields */
	proc->p_addrspace = NULL;

	/* VFS fields */
	proc->p_cwd = NULL;

	/** file table */

	proc->p_filetable = array_create();
	//kprintf("TEMPPP: Newly created filetable %p\n",proc->p_filetable);
	if (proc->p_filetable == NULL) {
		spinlock_cleanup(&proc->p_lock);
		kfree(proc->p_name);
		kfree(proc);
		return NULL;
	}
	if(array_preallocate(proc->p_filetable, 1024) == ENOMEM) {
		array_destroy(proc->p_filetable);
		spinlock_cleanup(&proc->p_lock);
		kfree(proc->p_name);
		kfree(proc);
		return NULL;
	}
	proc->p_waitcvlock = lock_create(name);
	if (proc->p_waitcvlock == NULL) {
		array_destroy(proc->p_filetable);
		spinlock_cleanup(&proc->p_lock);
		kfree(proc->p_name);
		kfree(proc);
		return NULL;
	}

	proc->p_waitcv = cv_create(name);
	if (proc->p_waitcv == NULL) {
		lock_destroy(proc->p_waitcvlock);
		array_destroy(proc->p_filetable);
		spinlock_cleanup(&proc->p_lock);
		kfree(proc->p_name);
		kfree(proc);
		return NULL;
	}

	proc->p_opslock = lock_create(name);
	if (proc->p_opslock == NULL) {
		cv_destroy(proc->p_waitcv);
		lock_destroy(proc->p_waitcvlock);
		array_destroy(proc->p_filetable);
		spinlock_cleanup(&proc->p_lock);
		kfree(proc->p_name);
		kfree(proc);
		return NULL;
	}
	proc->p_state = PS_RUNNING;

	proc->p_returnvalue = -1;

	proc->p_fdcounter = 0;

	// add the process to the process table

	return proc;
}
コード例 #25
0
ファイル: proc.c プロジェクト: sammmylin/os161
/*
 * Destroy a proc structure.
 *
 * Note: nothing currently calls this. Your wait/exit code will
 * probably want to do so.
 */
void
proc_destroy(struct proc *proc)
{
	/*
	 * You probably want to destroy and null out much of the
	 * process (particularly the address space) at exit time if
	 * your wait/exit design calls for the process structure to
	 * hang around beyond process exit. Some wait/exit designs
	 * do, some don't.
	 */

	KASSERT(proc != NULL);
	KASSERT(proc != kproc);

	/*
	 * We don't take p_lock in here because we must have the only
	 * reference to this structure. (Otherwise it would be
	 * incorrect to destroy it.)
	 */

	/* VFS fields */
	if (proc->p_cwd) {
		VOP_DECREF(proc->p_cwd);
		proc->p_cwd = NULL;
	}
	if (proc->p_filetable) {
		filetable_destroy(proc->p_filetable);
		proc->p_filetable = NULL;
	}

	/* VM fields */
	if (proc->p_addrspace) {
		/*
		 * If p is the current process, remove it safely from
		 * p_addrspace before destroying it. This makes sure
		 * we don't try to activate the address space while
		 * it's being destroyed.
		 *
		 * Also explicitly deactivate, because setting the
		 * address space to NULL won't necessarily do that.
		 *
		 * (When the address space is NULL, it means the
		 * process is kernel-only; in that case it is normally
		 * ok if the MMU and MMU- related data structures
		 * still refer to the address space of the last
		 * process that had one. Then you save work if that
		 * process is the next one to run, which isn't
		 * uncommon. However, here we're going to destroy the
		 * address space, so we need to make sure that nothing
		 * in the VM system still refers to it.)
		 *
		 * The call to as_deactivate() must come after we
		 * clear the address space, or a timer interrupt might
		 * reactivate the old address space again behind our
		 * back.
		 *
		 * If p is not the current process, still remove it
		 * from p_addrspace before destroying it as a
		 * precaution. Note that if p is not the current
		 * process, in order to be here p must either have
		 * never run (e.g. cleaning up after fork failed) or
		 * have finished running and exited. It is quite
		 * incorrect to destroy the proc structure of some
		 * random other process while it's still running...
		 */
		struct addrspace *as;

		if (proc == curproc) {
			as = proc_setas(NULL);
			as_deactivate();
		}
		else {
			as = proc->p_addrspace;
			proc->p_addrspace = NULL;
		}
		as_destroy(as);
	}

	threadarray_cleanup(&proc->p_threads);
	spinlock_cleanup(&proc->p_lock);

	kfree(proc->p_name);
	kfree(proc);
}
コード例 #26
0
ファイル: proc.c プロジェクト: jcseto/os161-1.99
/*
 * Destroy a proc structure.
 */
void
proc_destroy(struct proc *proc)
{
	/*
         * note: some parts of the process structure, such as the address space,
         *  are destroyed in sys_exit, before we get here
         *
         * note: depending on where this function is called from, curproc may not
         * be defined because the calling thread may have already detached itself
         * from the process.
	 */

	KASSERT(proc != NULL);
	KASSERT(proc != kproc);

	#if OPT_A2
	lock_destroy(proc->opencloselock);
	if(proc->filetable != NULL) {
	for(int i = 127; i >= 0; i--) {
		if(array_get(proc->filetable, i) != NULL) {
			//kprintf("%d \n", i);
			cleanupfile(array_get(proc->filetable, i));
		}
		array_remove(proc->filetable, i);
	}
	array_destroy(proc->filetable);
	}
#endif

	/*
	 * We don't take p_lock in here because we must have the only
	 * reference to this structure. (Otherwise it would be
	 * incorrect to destroy it.)
	 */

	/* VFS fields */
	if (proc->p_cwd) {
		VOP_DECREF(proc->p_cwd);
		proc->p_cwd = NULL;
	}


#ifndef UW  // in the UW version, space destruction occurs in sys_exit, not here
	if (proc->p_addrspace) {
		/*
		 * In case p is the currently running process (which
		 * it might be in some circumstances, or if this code
		 * gets moved into exit as suggested above), clear
		 * p_addrspace before calling as_destroy. Otherwise if
		 * as_destroy sleeps (which is quite possible) when we
		 * come back we'll be calling as_activate on a
		 * half-destroyed address space. This tends to be
		 * messily fatal.
		 */
		struct addrspace *as;

		as_deactivate();
		as = curproc_setas(NULL);
		as_destroy(as);
	}
#endif // UW

#ifdef UW
	if (proc->console) {
	  vfs_close(proc->console);
	}
#endif // UW

	threadarray_cleanup(&proc->p_threads);
	spinlock_cleanup(&proc->p_lock);

	kfree(proc->p_name);
	kfree(proc);


#ifdef UW
	/* decrement the process count */
        /* note: kproc is not included in the process count, but proc_destroy
	   is never called on kproc (see KASSERT above), so we're OK to decrement
	   the proc_count unconditionally here */
	P(proc_count_mutex); 
	KASSERT(proc_count > 0);
	proc_count--;
	/* signal the kernel menu thread if the process count has reached zero */
	if (proc_count == 0) {
	  V(no_proc_sem);
	}
	V(proc_count_mutex);
#endif // UW
	

}