当前位置: 首页>>代码示例>>C++>>正文


C++ page_free函数代码示例

本文整理汇总了C++中page_free函数的典型用法代码示例。如果您正苦于以下问题:C++ page_free函数的具体用法?C++ page_free怎么用?C++ page_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了page_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_single_rw

void test_single_rw(){
    dbg(DBG_TEST | DBG_DISK, "testing reading and writing to disk\n");

    blockdev_t *bd = blockdev_lookup(MKDEVID(1, 0));

    KASSERT(bd != NULL);

    char *writebuf = (char *) page_alloc();
    char *readbuf = (char *) page_alloc();

    KASSERT(readbuf != NULL && writebuf != NULL && "not enough memory");

    unsigned int i;
    for (i = 0; i < BLOCK_SIZE; i++){
        writebuf[i] = 'o';
    }

    int block_to_write = 60;

    rw_args_t read_args = {bd, readbuf, block_to_write, 1};
    rw_args_t write_args = {bd, writebuf, block_to_write, 1};

    simple_write(write_args);
    simple_read(read_args);
 
    unsigned int j;
    for (j = 0; j < BLOCK_SIZE; j++){
        KASSERT(readbuf[j] == 'o');
    }

    page_free((void *) readbuf);
    page_free((void *) writebuf);

    dbg(DBG_TESTPASS, "all simple ata tests passed\n");
}
开发者ID:AnupreetKJohar,项目名称:weenix,代码行数:35,代码来源:atatest.c

示例2: sys_write

/*
 * This function is almost identical to sys_read.  See comments above.
 */
static int
sys_write(write_args_t *arg)
{
    /*            NOT_YET_IMPLEMENTED("VM: sys_read");*/

        dbg(DBG_PRINT,"go into sys_write\n");
    write_args_t k_args;
    void* writeBuf = NULL;

    int retVal = copy_from_user(&k_args, arg, sizeof(k_args));
	KASSERT(0 <= retVal);
    writeBuf = page_alloc();
	KASSERT(writeBuf);
    int retVal_new = copy_from_user(writeBuf, arg->buf, arg->nbytes);
	KASSERT(0 <= retVal_new);
    int writeNum = 0;
    writeNum = do_write(k_args.fd, writeBuf, k_args.nbytes);
    if(0 > writeNum)
    {
        dbg(DBG_PRINT, "(GRADING3C)\n");
        curthr->kt_errno = -writeNum;
        page_free(writeBuf);
        return -1;
    }
    page_free(writeBuf);
    return writeNum;
}
开发者ID:ohyeslk,项目名称:unix_os_final,代码行数:30,代码来源:syscall.c

示例3: sys_read

static int
sys_read(read_args_t *arg)
{
/*            NOT_YET_IMPLEMENTED("VM: sys_read");*/

        dbg(DBG_PRINT,"go into sys_read\n");
    read_args_t k_args;
    void* readBuf = NULL;
    int readNum = 0;
    
    int retVal = copy_from_user(&k_args, arg, sizeof(read_args_t));
	KASSERT(retVal>=0);
	readBuf = page_alloc();
	KASSERT(readBuf!=NULL);
    readNum = do_read(k_args.fd, readBuf, k_args.nbytes);
    if(0 > readNum)
    {
        dbg(DBG_PRINT, "(GRADING3C)\n");
        curthr->kt_errno = -readNum;
        page_free(readBuf);
        return -1;
    }
    int retVal_new = copy_to_user(arg->buf, readBuf, readNum);
	KASSERT(retVal_new>=0);
    page_free(readBuf);
    return readNum;
}
开发者ID:ohyeslk,项目名称:unix_os_final,代码行数:27,代码来源:syscall.c

示例4: is_psx

int is_psx(int check_ps2)
{
	uint8_t *buf;
	int result;
	int ret = 0;

	if (page_allocate_auto(NULL, 2048, 0x2F, (void **)&buf) == 0)
	{
		result = read_real_disc_sector(buf, 0x10, 1, 3);

		if (result == 0)
		{
			// Check if it is a burned PS3 disk (deank)
			if(check_ps2==3)
			{
				ret = (memcmp(buf+1, "CD001", 5) == 0 && memcmp(buf+0x28, "PS3VOLUME", 9) == 0);
				if(!ret)
				{
					result = read_real_disc_sector(buf, 0x01, 1, 3);
					ret = (memcmp(buf, "PlayStation3", 12) == 0);
				}
				page_free(NULL, buf, 0x2F);
				return ret;
			}
		}
		page_free(NULL, buf, 0x2F);
	}

	return ret;
}
开发者ID:Joonie86,项目名称:COBRA-7.3,代码行数:30,代码来源:storage_ext.c

示例5: sys_write

/*
 * This function is almost identical to sys_read.  See comments above.
 */
static int
sys_write(write_args_t *arg)
{
    write_args_t kern_args;
    int err;

    if ((err = copy_from_user(&kern_args, arg, sizeof(write_args_t))) < 0) {
        curthr->kt_errno = -err;
        return -1;
    }

    void *kaddr = page_alloc();
    size_t count = kern_args.nbytes;
    char *buff = (char *)kern_args.buf;
    int total_write = 0;

    while (count > 0) {
        size_t writelen = MIN(PAGE_SIZE, count);

        err = copy_from_user(kaddr, buff, writelen);
        if (err < 0) {
            page_free(kaddr);
            curthr->kt_errno = -err;
            return -1;
        }
        KASSERT(err == 0);

        int actual_write = do_write(kern_args.fd, kaddr, writelen);
        if (actual_write < 0) {
            page_free(kaddr);
            curthr->kt_errno = -actual_write;
            return -1;
        }
        KASSERT((unsigned)actual_write <= writelen);

        count -= actual_write;
        buff += actual_write;
        total_write += actual_write;
        if ((unsigned)actual_write != writelen) {
            break;
        }
    }

    /*
     *copy_from_user(kaddr, kern_args.buf, kern_args.nbytes);
     *err = do_write(kern_args.fd, kaddr, kern_args.nbytes);
     *if (err < 0) {
     *    curthr->kt_errno = -err;
     *    return -1;
     *}
     */

    page_free(kaddr);

    return total_write;
        /*NOT_YET_IMPLEMENTED("VM: sys_write");*/
        /*return -1;*/
}
开发者ID:Metalgear47,项目名称:Weenix,代码行数:61,代码来源:syscall.c

示例6: check_n_pages

static void
check_n_pages(void)
{
	struct Page* pp, *pp0;
	char* addr;
	int i;
	pp = pp0 = 0;
	// Allocate two single pages
	pp =  page_alloc(0);
	pp0 = page_alloc(0);
	assert(pp != 0);
	assert(pp0 != 0);
	assert(pp != pp0);
	//cprintf("1");
	
	// Free pp and assign four continuous pages
	page_free(pp);
	pp = page_alloc_npages(0, 4);
	//cprintf("1");
	assert(check_continuous(pp, 4));
	//
	//pps = page_realloc_npages(pps, 4, 6);
	//assert(check_continuous(pps, 6));
	//cprintf("s");
	// Free four continuous pages
	//
	assert(!page_free_npages(pp, 4));
	//cprintf("1");
	//
	//assert(!page_free_npages(pps, 6));
	//cprintf("s");
	// Free pp and assign eight continuous pages
	pp = page_alloc_npages(0, 8);
	//cprintf("1");
	assert(check_continuous(pp, 8));
	//cprintf("1");
	// Free four continuous pages
	assert(!page_free_npages(pp, 8));
	//cprintf("1");

	// Free pp0 and assign four continuous zero pages
	page_free(pp0);
	//cprintf("1");
	pp0 = page_alloc_npages(ALLOC_ZERO, 4);
	//cprintf("1");
	addr = (char*)page2kva(pp0);
	//cprintf("1");
	// Check Zero
	for( i = 0; i < 4 * PGSIZE; i++ ){
		assert(addr[i] == 0);
	}
	//cprintf("1");
	// Free pages
	assert(!page_free_npages(pp0, 4));
	cprintf("check_n_pages() succeeded!\n");
	/*stone: if you want to test page_realloc_pages() function, please use this*/
	//check_realloc();
}
开发者ID:stone-SJH,项目名称:joslabs-byStone,代码行数:58,代码来源:pmap.c

示例7: sys_read

/*
 * this is one of the few sys_* functions you have to write. be sure to
 * check out the sys_* functions we have provided before trying to write
 * this one.
 *  - copy_from_user() the read_args_t
 *  - page_alloc() a temporary buffer
 *  - call do_read(), and copy_to_user() the read bytes
 *  - page_free() your buffer
 *  - return the number of bytes actually read, or if anything goes wrong
 *    set curthr->kt_errno and return -1
 */
static int sys_read(read_args_t *arg) {
	/*   NOT_YET_IMPLEMENTED("VM: sys_read"); */
	dbg(DBG_PRINT, "(GRADING3F)\n");

	read_args_t kern_args;
	char *addr;
	char *currBuf;
	uint32_t totRead = -1, to_read = 0;
	int readChar = 0;
	int err = copy_from_user(&kern_args, arg, sizeof(read_args_t));

	/*if (err < 0) {
		dbg(DBG_ERROR, "(GRADING  test 19)\n");
		curthr->kt_errno = -err;
		return -1;
	}

	if ((addr = page_alloc()) == NULL) {
		dbg(DBG_ERROR, "(GRADING  test 20)\n");
		curthr->kt_errno = ENOMEM;
		return -1;

	}*/

	if ( !(err < 0) &&  !((addr = page_alloc()) == NULL)){
	totRead = 0;
	currBuf = (char*) addr;

	while (totRead < kern_args.nbytes) {
		dbg(DBG_PRINT, "(GRADING3F)\n");
		to_read =
				(kern_args.nbytes - totRead) < PAGE_SIZE ?
						(kern_args.nbytes - totRead) : PAGE_SIZE;
		if ((readChar = do_read(kern_args.fd, currBuf, to_read)) < 0) {
			dbg(DBG_PRINT, "(GRADING3D 2)\n");
			page_free(currBuf);
			curthr->kt_errno = -readChar;
			return -1;
		}

		err = copy_to_user((void*) ((size_t) kern_args.buf + totRead),
				currBuf, readChar) ;

		totRead += readChar;

		if (readChar < (int) to_read) {
			dbg(DBG_PRINT, "(GRADING3D 2)\n");
			page_free(currBuf);
			return totRead;

		}
	}
	dbg(DBG_PRINT, "(GRADING3D 2)\n");
	page_free(currBuf);
	}
	return totRead;
}
开发者ID:darshanramu,项目名称:LinuxLikeOS,代码行数:68,代码来源:syscall.c

示例8: sys_read

/*
 * this is one of the few sys_* functions you have to write. be sure to
 * check out the sys_* functions we have provided before trying to write
 * this one.
 *  - copy_from_user() the read_args_t
 *  - page_alloc() a temporary buffer
 *  - call do_read(), and copy_to_user() the read bytes
 *  - page_free() your buffer
 *  - return the number of bytes actually read, or if anything goes wrong
 *    set curthr->kt_errno and return -1
 */
static int
sys_read(read_args_t *arg)
{
    read_args_t kern_args;
    int err;

    if ((err = copy_from_user(&kern_args, arg, sizeof(read_args_t))) < 0) {
        curthr->kt_errno = -err;
        return -1;
    }

    void *kaddr = page_alloc();
    size_t count = kern_args.nbytes;
    char *buff = (char *)kern_args.buf;
    int total_read = 0;

    while (count > 0) {
        size_t readlen = MIN(PAGE_SIZE, count);

        int actual_read = do_read(kern_args.fd, kaddr, readlen);
        if (actual_read < 0) {
            page_free(kaddr);
            curthr->kt_errno = -actual_read;
            return -1;
        }
        KASSERT((unsigned)actual_read <= readlen);

        err = copy_to_user(buff, kaddr, actual_read);
        if (err < 0) {
            page_free(kaddr);
            curthr->kt_errno = -err;
            return -1;
        }
        KASSERT(err == 0);

        count -= actual_read;
        buff += actual_read;
        total_read += actual_read;
        if ((unsigned)actual_read != readlen) {
            break;
        }
    }
/*
 *    err = do_read(kern_args.fd, kaddr, kern_args.nbytes);
 *    if (err < 0) {
 *        curthr->kt_errno = -err;
 *        return -1;
 *    }
 *
 *    copy_to_user(kern_args.buf, kaddr, err);
 */
    page_free(kaddr);

    return total_read;
        /*NOT_YET_IMPLEMENTED("VM: sys_read");*/
        /*return -1;*/
}
开发者ID:Metalgear47,项目名称:Weenix,代码行数:68,代码来源:syscall.c

示例9: sys_write

/*
 * This function is almost identical to sys_read.  See comments above.
 */
static int sys_write(write_args_t *arg) {
	/* NOT_YET_IMPLEMENTED("VM: sys_write"); */
	dbg(DBG_PRINT, "(GRADING3F)\n");
	write_args_t kern_args;
	char *addr;
	char *currBuf;
	uint32_t totWrite = -1, to_write = 0;
	int readChar = 0;
	int err = copy_from_user(&kern_args, arg, sizeof(write_args_t));

	/*if (err < 0) {
		dbg(DBG_ERROR, "(GRADING  test 19)\n");
		curthr->kt_errno = -err;
		return -1;
	}

	if ((addr = page_alloc()) == NULL) {
		dbg(DBG_ERROR, "(GRADING  test 20)\n");
		curthr->kt_errno = ENOMEM;
		return -1;

	}*/
	if ( !(err < 0) &&  !((addr = page_alloc()) == NULL)){
	currBuf = (char*) addr;
	totWrite = 0;
	while (totWrite < kern_args.nbytes) {
		dbg(DBG_PRINT, "(GRADING3F)\n");
		to_write = kern_args.nbytes - totWrite;


		err = copy_from_user(currBuf,
				(void*) ((size_t) kern_args.buf + totWrite), to_write);

		if ((readChar = do_write(kern_args.fd, currBuf, to_write)) < 0) {
			dbg(DBG_PRINT, "(GRADING3D 2)\n");
			page_free(currBuf);
			curthr->kt_errno = -readChar;
			return -1;
		}

		totWrite += readChar;

		/*if (readChar < (int) to_write) {
			dbg(DBG_ERROR, "(GRADING  test 25)\n");
			page_free(currBuf);
			return totWrite;

		}*/
	}
	dbg(DBG_PRINT, "(GRADING3F)\n");
	page_free(currBuf);
	}
	return totWrite;
}
开发者ID:darshanramu,项目名称:LinuxLikeOS,代码行数:57,代码来源:syscall.c

示例10: rcu_register_thread

static void *regression1_fn(void *arg)
{
	rcu_register_thread();

	if (pthread_barrier_wait(&worker_barrier) ==
			PTHREAD_BARRIER_SERIAL_THREAD) {
		int j;

		for (j = 0; j < 1000000; j++) {
			struct page *p;

			p = page_alloc();
			pthread_mutex_lock(&mt_lock);
			radix_tree_insert(&mt_tree, 0, p);
			pthread_mutex_unlock(&mt_lock);

			p = page_alloc();
			pthread_mutex_lock(&mt_lock);
			radix_tree_insert(&mt_tree, 1, p);
			pthread_mutex_unlock(&mt_lock);

			pthread_mutex_lock(&mt_lock);
			p = radix_tree_delete(&mt_tree, 1);
			pthread_mutex_lock(&p->lock);
			p->count--;
			pthread_mutex_unlock(&p->lock);
			pthread_mutex_unlock(&mt_lock);
			page_free(p);

			pthread_mutex_lock(&mt_lock);
			p = radix_tree_delete(&mt_tree, 0);
			pthread_mutex_lock(&p->lock);
			p->count--;
			pthread_mutex_unlock(&p->lock);
			pthread_mutex_unlock(&mt_lock);
			page_free(p);
		}
	} else {
		int j;

		for (j = 0; j < 100000000; j++) {
			struct page *pages[10];

			find_get_pages(0, 10, pages);
		}
	}

	rcu_unregister_thread();

	return NULL;
}
开发者ID:AshishNamdev,项目名称:linux,代码行数:51,代码来源:regression1.c

示例11: malloc

char *svga_rcall(uint64_t source, struct vfs_obj *file, const char *args) {
	char *rets = NULL;
	int x, y, d, w, h;
	int mode;

	if (!strcmp(args, "getmode")) {
		rets = malloc(16);
		sprintf(rets, "%d %d %d", svga.w, svga.h, svga.d);
		return rets;
	}
	if (!strcmp(args, "listmodes")) {
		return strdup(modesstr);
	}
	if (!strcmp(args, "unshare")) {
		mutex_spin(&file->mutex);
		page_free(buffer, msize(buffer));
		free(buffer);
		buffer = valloc(svga.w * svga.h * 4);
		mutex_free(&file->mutex);
		return strdup("T");
	}

	if (!strncmp(args, "setmode ", 8)) {
		if (sscanf(args + 8, "%i %i %i", &x, &y, &d) != 3) {
			return strdup("");
		}
		mutex_spin(&file->mutex);
		mode = svga_find_mode(x, y, d);
		if (svga_set_mode(mode)) {
			return strdup("");
		}
		page_free(buffer, msize(buffer));
		free(buffer);
		buffer = valloc(svga.w * svga.h * 4);
		mutex_free(&file->mutex);
		return strdup("T");
	}

	if (!strncmp(args, "syncrect ", 9)) {
		if (sscanf(args + 9, "%i %i %i %i", &x, &y, &w, &h) != 4) {
			return strdup("");
		}
		mutex_spin(&file->mutex);
		svga_fliprect(buffer, x, y, w, h);
		mutex_free(&file->mutex);
		return strdup("T");
	}
	
	return NULL;
}
开发者ID:UIKit0,项目名称:flux,代码行数:50,代码来源:main.c

示例12: page_decref

void
page_decref(struct Page *pp)
{
	if (--pp->pp_ref == 0) {
		page_free(pp);
	}
}
开发者ID:SivilTaram,项目名称:Jos-mips,代码行数:7,代码来源:pmap.c

示例13: mmio_cell_exit

/**
 * Perform MMIO-specific cleanup for a cell under destruction.
 * @param cell		Cell to be destructed.
 *
 * @see mmio_cell_init
 */
void mmio_cell_exit(struct cell *cell)
{
	page_free(&mem_pool, cell->mmio_locations,
		  PAGES(cell->max_mmio_regions *
			(sizeof(struct mmio_region_location) +
			 sizeof(struct mmio_region_handler))));
}
开发者ID:AdamRLukaitis,项目名称:jailhouse,代码行数:13,代码来源:mmio.c

示例14: sys_page_alloc

// Allocate a page of memory and map it at 'va' with permission
// 'perm' in the address space of 'envid'.
// The page's contents are set to 0.
// If a page is already mapped at 'va', that page is unmapped as a
// side effect.
//
// perm -- PTE_U | PTE_P must be set, PTE_AVAIL | PTE_W may or may not be set,
//         but no other bits may be set.  See PTE_SYSCALL in inc/mmu.h.
//
// Return 0 on success, < 0 on error.  Errors are:
//	-E_BAD_ENV if environment envid doesn't currently exist,
//		or the caller doesn't have permission to change envid.
//	-E_INVAL if va >= UTOP, or va is not page-aligned.
//	-E_INVAL if perm is inappropriate (see above).
//	-E_NO_MEM if there's no memory to allocate the new page,
//		or to allocate any necessary page tables.
static int
sys_page_alloc(envid_t envid, void *va, int perm)
{
	// Hint: This function is a wrapper around page_alloc() and
	//   page_insert() from kern/pmap.c.
	//   Most of the new code you write should be to check the
	//   parameters for correctness.
	//   If page_insert() fails, remember to free the page you
	//   allocated!

	// LAB 4: Your code here.
        int rslt;
        struct Env *tmp;
        struct PageInfo *p = NULL;
        if((rslt = envid2env(envid, &tmp, 1)) != 0)
                return rslt;
        if(va >= (void *)UTOP || (((size_t)va % PGSIZE) != 0))
                return -E_INVAL;
        if((perm & (PTE_U | PTE_P)) != (PTE_U | PTE_P))
                return -E_INVAL;
        if((p = page_alloc(1)) == (void*)NULL)
                return -E_NO_MEM;
        if((rslt = page_insert(tmp->env_pgdir, p, va, perm)) != 0) {
                page_free(p);
                return rslt;
        }
        memset(page2kva(p), 0, PGSIZE);
        return rslt;

	//panic("sys_page_alloc not implemented");
}
开发者ID:liuxu1005,项目名称:Operating-System-Engineering,代码行数:47,代码来源:syscall.c

示例15: pgdir_walk

	pte_t *
pgdir_walk(pde_t *pgdir, const void *va, int create)
{
	pte_t *pte;
	struct Page *newPage = NULL;
	//if(!create)cprintf("va = %0x, pgdir[PDX(va)] = %0x\n", va, pgdir[PDX(va)]);
	if (!pgdir[PDX(va)]) {

		if (!create)
			return NULL;
		else {
			newPage = page_alloc(0);
			if (newPage == 0) {
				return NULL;
			} else {
				newPage->pp_ref++;
				pgdir[PDX(va)] = page2pa(newPage) | PTE_U | PTE_W | PTE_P;	
				memset(page2kva(newPage), 0x00, PGSIZE);
			}

		}
	}
	pte_t *result = (pte_t *)((KADDR(PTE_ADDR(pgdir[PDX(va)]))));

	if (!result && newPage) {
		pgdir[PDX(va)] = 0;
		newPage->pp_ref = 0;
		page_free(newPage);
	}

	return result;
}
开发者ID:ajsbu,项目名称:cse506,代码行数:32,代码来源:pmap.c


注:本文中的page_free函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。