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


C++ pa2page函数代码示例

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


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

示例1: env_free

//
// Frees env e and all memory it uses.
// 
void
env_free(struct Env *e)
{
	pte_t *pt;
	uint32_t pdeno, pteno;
	physaddr_t pa;
	
	// If freeing the current environment, switch to boot_pgdir
	// before freeing the page directory, just in case the page
	// gets reused.
	if (e == curenv)
		lcr3(boot_cr3);

	// Note the environment's demise.
	// cprintf("[%08x] free env %08x\n", curenv ? curenv->env_id : 0, e->env_id);

	// Flush all mapped pages in the user portion of the address space
	static_assert(UTOP % PTSIZE == 0);
	for (pdeno = 0; pdeno < PDX(UTOP); pdeno++) {

		// only look at mapped page tables
		if (!(e->env_pgdir[pdeno] & PTE_P))
			continue;

		// find the pa and va of the page table
		pa = PTE_ADDR(e->env_pgdir[pdeno]);
		pt = (pte_t*) KADDR(pa);

		// unmap all PTEs in this page table
		for (pteno = 0; pteno <= PTX(~0); pteno++) {
			if (pt[pteno] & PTE_P)
				page_remove(e->env_pgdir, PGADDR(pdeno, pteno, 0));
		}

		// free the page table itself
		e->env_pgdir[pdeno] = 0;
		page_decref(pa2page(pa));

	}

	// free the page directory
	pa = e->env_cr3;
	e->env_pgdir = 0;
	e->env_cr3 = 0;
	

	page_decref(pa2page(pa));
	

	// return the environment to the free list
	e->env_status = ENV_FREE;
	LIST_INSERT_HEAD(&env_free_list, e, env_link);
}
开发者ID:gzs715,项目名称:JOS,代码行数:56,代码来源:env.c

示例2: check_pgfault

// check_pgfault - check correctness of pgfault handler
static void check_pgfault(void)
{
#ifdef UCONFIG_CHECK_PGFAULT
	kprintf("starting check_pgfault()\n");
	size_t nr_used_pages_store = nr_used_pages();
	size_t slab_allocated_store = slab_allocated();

	check_mm_struct = mm_create();
	assert(check_mm_struct != NULL);

	struct mm_struct *mm = check_mm_struct;
	pgd_t *pgdir = mm->pgdir = init_pgdir_get();
	assert(pgdir[PGX(TEST_PAGE)] == 0);

	struct vma_struct *vma =
	    vma_create(TEST_PAGE, TEST_PAGE + PTSIZE, VM_WRITE);
	assert(vma != NULL);

	insert_vma_struct(mm, vma);
	uintptr_t addr = TEST_PAGE + 0x100;
	assert(find_vma(mm, addr) == vma);

	int i, sum = 0;
	for (i = 0; i < 100; i++) {
		*(char *)(addr + i) = i;
		sum += i;
	}
	for (i = 0; i < 100; i++) {
		sum -= *(char *)(addr + i);
	}
	assert(sum == 0);

	page_remove(pgdir, ROUNDDOWN(addr, PGSIZE));
#if PMXSHIFT != PUXSHIFT
	free_page(pa2page(PMD_ADDR(*get_pmd(pgdir, addr, 0))));
#endif
#if PUXSHIFT != PGXSHIFT
	free_page(pa2page(PUD_ADDR(*get_pud(pgdir, addr, 0))));
#endif
	free_page(pa2page(PGD_ADDR(*get_pgd(pgdir, addr, 0))));
	pgdir[PGX(TEST_PAGE)] = 0;

	mm->pgdir = NULL;
	mm_destroy(mm);
	check_mm_struct = NULL;

	assert(nr_used_pages_store == nr_used_pages());
	assert(slab_allocated_store == slab_allocated());

	kprintf("check_pgfault() succeeded!\n");
#endif
}
开发者ID:piyifan,项目名称:ucore_plus-next,代码行数:53,代码来源:vmm.c

示例3: check_pgdir

/**
 * Check page table
 */
void check_pgdir(void)
{
	assert(npage <= KMEMSIZE / PGSIZE);
	assert(boot_pgdir != NULL && (uint32_t) PGOFF(boot_pgdir) == 0);
	assert(get_page(boot_pgdir, TEST_PAGE, NULL) == NULL);

	struct Page *p1, *p2;
	p1 = alloc_page();
	assert(page_insert(boot_pgdir, p1, TEST_PAGE, 0) == 0);

	pte_t *ptep, perm;
	assert((ptep = get_pte(boot_pgdir, TEST_PAGE, 0)) != NULL);
	assert(pa2page(*ptep) == p1);
	assert(page_ref(p1) == 1);

	ptep = &((pte_t *) KADDR(PTE_ADDR(boot_pgdir[PDX(TEST_PAGE)])))[1];
	assert(get_pte(boot_pgdir, TEST_PAGE + PGSIZE, 0) == ptep);

	p2 = alloc_page();
	ptep_unmap(&perm);
	ptep_set_u_read(&perm);
	ptep_set_u_write(&perm);
	assert(page_insert(boot_pgdir, p2, TEST_PAGE + PGSIZE, perm) == 0);
	assert((ptep = get_pte(boot_pgdir, TEST_PAGE + PGSIZE, 0)) != NULL);
	assert(ptep_u_read(ptep));
	assert(ptep_u_write(ptep));
	assert(ptep_u_read(&(boot_pgdir[PDX(TEST_PAGE)])));
	assert(page_ref(p2) == 1);

	assert(page_insert(boot_pgdir, p1, TEST_PAGE + PGSIZE, 0) == 0);
	assert(page_ref(p1) == 2);
	assert(page_ref(p2) == 0);
	assert((ptep = get_pte(boot_pgdir, TEST_PAGE + PGSIZE, 0)) != NULL);
	assert(pa2page(*ptep) == p1);
	assert(!ptep_u_read(ptep));

	page_remove(boot_pgdir, TEST_PAGE);
	assert(page_ref(p1) == 1);
	assert(page_ref(p2) == 0);

	page_remove(boot_pgdir, TEST_PAGE + PGSIZE);
	assert(page_ref(p1) == 0);
	assert(page_ref(p2) == 0);

	assert(page_ref(pa2page(boot_pgdir[PDX(TEST_PAGE)])) == 1);
	free_page(pa2page(boot_pgdir[PDX(TEST_PAGE)]));
	boot_pgdir[PDX(TEST_PAGE)] = 0;
	exit_range(boot_pgdir, TEST_PAGE, TEST_PAGE + PGSIZE);

	kprintf("check_pgdir() succeeded.\n");
}
开发者ID:Aresthu,项目名称:ucore_plus,代码行数:54,代码来源:pmm.c

示例4: page_insert

//
// Map the physical page 'pp' at virtual address 'va'.
// The permissions (the low 12 bits) of the page table entry
// should be set to 'perm|PTE_P'.
//
// Requirements
//   - If there is already a page mapped at 'va', it should be page_remove()d.
//   - If necessary, on demand, a page table should be allocated and inserted
//     into 'pgdir'.
//   - pp->pp_ref should be incremented if the insertion succeeds.
//   - The TLB must be invalidated if a page was formerly present at 'va'.
//
// Corner-case hint: Make sure to consider what happens when the same
// pp is re-inserted at the same virtual address in the same pgdir.
// However, try not to distinguish this case in your code, as this
// frequently leads to subtle bugs; there's an elegant way to handle
// everything in one code path.
//
// RETURNS:
//   0 on success
//   -E_NO_MEM, if page table couldn't be allocated
//
// Hint: The TA solution is implemented using pgdir_walk, page_remove,
// and page2pa.
//
int
page_insert(pde_t *pgdir, struct PageInfo *pp, void *va, int perm)
{
	// Fill this function in
	
	pte_t* ptep = pgdir_walk(pgdir, va, true);
	
	if(!ptep) {
		return -E_NO_MEM;
	}

	
	if( pa2page(*ptep) != pp ){
		page_remove(pgdir, va);
		assert( *ptep == 0 );
		assert(pp->pp_ref >= 0);
		pp->pp_ref++;
	}
	else {
		tlb_invalidate(pgdir, va);
	}

	
	*ptep = page2pa(pp) | perm | PTE_P;
	/* we should also change pde's perm*/
	pde_t *pde = pgdir + PDX(va); 
	*pde = *pde | perm;
	
	
	return 0;
}
开发者ID:DeepinDream,项目名称:6.828-MIT-OS,代码行数:56,代码来源:pmap.c

示例5: page_init

/**
 * Examine address space, create virtual physical memory and map it.
 */
static void
page_init (void)
{
    int i;
    int freemem_size = 0;

    /* Construct page descriptor table.
     * mem => memory not reserved or occupied by kernel code
     * freemem => memory available after page descriptor table is built
     */

    /* all pages from 0x100000 to the top should have an entry in page descriptor table */
    for (i = 0; i < e820map.nr_map; i++) {
        mem_size += (uint32_t)(e820map.map[i].size);
        if (e820map.map[i].type == E820_ARM)
            freemem_size += e820map.map[i].size;
    }

    pages = (struct Page *)(uint32_t)(e820map.map[e820map.nr_map-1].addr);
    npage = (mem_size) / PGSIZE;
    for (i = 0; i < npage; i++) {
        SetPageReserved (pages + i);
    }

    uintptr_t freemem = PADDR(ROUNDUP((uintptr_t)pages + sizeof(struct Page) * npage, PGSIZE));
    uint32_t freemem_npage = freemem_size / PGSIZE - npage * sizeof (struct Page) / PGSIZE;
    init_memmap(pa2page(freemem), freemem_npage);
}
开发者ID:haozhun,项目名称:ucore_plus,代码行数:31,代码来源:pmm.c

示例6: page_lookup

struct Page *
page_lookup(Pde *pgdir, u_long va, Pte **ppte)
{
	struct Page *ppage;
	Pte *pte;

	pgdir_walk(pgdir, va, 0, &pte);

	//printf("page_lookup:come 1\n");
	if (pte == 0) {
		return 0;
	}

	if ((*pte & PTE_V) == 0) {
		return 0;    //the page is not in memory.
	}

	//printf("page_lookup:come 2\n");
	ppage = pa2page(*pte);

	if (ppte) {
		*ppte = pte;
	}

	return ppage;
}
开发者ID:SivilTaram,项目名称:Jos-mips,代码行数:26,代码来源:pmap.c

示例7: page_insert

//
// Map the physical page 'pp' at virtual address 'va'.
// The permissions (the low 12 bits) of the page table entry
// should be set to 'perm|PTE_P'.
//
// Requirements
//   - If there is already a page mapped at 'va', it should be page_remove()d.
//   - If necessary, on demand, a page table should be allocated and inserted
//     into 'pgdir'.
//   - pp->pp_ref should be incremented if the insertion succeeds.
//   - The TLB must be invalidated if a page was formerly present at 'va'.
//
// Corner-case hint: Make sure to consider what happens when the same
// pp is re-inserted at the same virtual address in the same pgdir.
// However, try not to distinguish this case in your code, as this
// frequently leads to subtle bugs; there's an elegant way to handle
// everything in one code path.
//
// RETURNS:
//   0 on success
//   -E_NO_MEM, if page table couldn't be allocated
//
// Hint: The TA solution is implemented using pgdir_walk, page_remove,
// and page2pa.
//
int
page_insert(pde_t *pgdir, struct PageInfo *pp, void *va, int perm)
{
	// Fill this function in
	pte_t *entry=NULL;
	struct PageInfo *page=NULL;
	physaddr_t page_paddr;
	entry = pgdir_walk(pgdir, va, 1);
	if(entry)
	{
		page_paddr = (physaddr_t)*entry;
		if(page_paddr & PTE_P)
		{
			page = pa2page(page_paddr);	
			if(page!=pp)
				page_remove(pgdir, va);	
			else
			{
				*entry = page2pa(pp) | perm | PTE_P;
				// cprintf("\npage_insert: perm:%d addr:%p",*entry);
				return 0;
			}
		}
		*entry = page2pa(pp) | perm | PTE_P;	
		pp->pp_ref++;
		return 0;
	}
	return -E_NO_MEM;
}
开发者ID:saurabhgadia4,项目名称:jos-kernel,代码行数:54,代码来源:pmap.c

示例8: check_boot_pgdir

void check_boot_pgdir(void)
{
	pte_t *ptep;
	int i;
	for (i = 0; i < npage; i += PGSIZE) {
		assert((ptep =
			get_pte(boot_pgdir, (uintptr_t) KADDR(i), 0)) != NULL);
		assert(PTE_ADDR(*ptep) == i);
	}

	assert(PDE_ADDR(boot_pgdir[PDX(VPT)]) == PADDR(boot_pgdir));

	assert(boot_pgdir[0] == 0);

	struct Page *p;
	p = alloc_page();
	assert(page_insert(boot_pgdir, p, 0x100, PTE_W) == 0);
	assert(page_ref(p) == 1);
	assert(page_insert(boot_pgdir, p, 0x100 + PGSIZE, PTE_W) == 0);
	assert(page_ref(p) == 2);

	const char *str = "ucore: Hello world!!";
	strcpy((void *)0x100, str);
	assert(strcmp((void *)0x100, (void *)(0x100 + PGSIZE)) == 0);

	*(char *)(page2kva(p) + 0x100) = '\0';
	assert(strlen((const char *)0x100) == 0);

	free_page(p);
	free_page(pa2page(PDE_ADDR(boot_pgdir[0])));
	boot_pgdir[0] = 0;

	kprintf("check_boot_pgdir() succeeded!\n");
}
开发者ID:TySag,项目名称:project,代码行数:34,代码来源:pmm.c

示例9: map_upage_at_addr

/*
 * Our version knocked off from kern/src/mm.c version + uncaching logic from
 * vmap_pmem_nocache(). This routine is expected to be invoked as part of mmap()
 * handler.
 */
int map_upage_at_addr(struct proc *p, physaddr_t paddr, uintptr_t addr, int pteprot, int dolock)
{
	pte_t		pte;
	int		rv = -1;
	struct page	*pp;

	/* __vmr_free_pgs() assumes mapped pte is backed by "struct page" */
	if (paddr > max_paddr) {
		printk("[akaros]: map_upage_at_addr(): paddr=0x%llx "
		    "max_paddr=0x%llx\n", paddr, max_paddr);
		return -1;
	}

	pp = pa2page(paddr);

	/* __vmr_free_pgs() refcnt's pagemap pages differently */
	if (atomic_read(&pp->pg_flags) & PG_PAGEMAP) {
		printk("[akaros]: map_upage_at_addr(): mapPA=0x%llx\n",
		    paddr);
		return -1;
	}

	spin_lock(&p->pte_lock);

	/*
	 * Free any existing page backing uva, drop in this page, and
	 * acquire refcnt on page on behalf of user. Note though that we
	 * do not expect an existing page, since we are invoked in mmap
	 * path (page_insert() does not handle PG_PAGEMAP refcnt's).
	 */
	rv = page_insert(p->env_pgdir, pp, (void *)addr, pteprot);
	spin_unlock(&p->pte_lock);
	return rv;
}
开发者ID:GanShun,项目名称:akaros,代码行数:39,代码来源:compat.c

示例10: ept_lookup_gpa

// Find the final ept entry for a given guest physical address,
// creating any missing intermediate extended page tables if create is non-zero.
//
// If epte_out is non-NULL, store the found epte_t* at this address.
//
// Return 0 on success.  
// 
// Error values:
//    -E_INVAL if eptrt is NULL
//    -E_NO_ENT if create == 0 and the intermediate page table entries are missing.
//    -E_NO_MEM if allocation of intermediate page table entries fails.
//
// Hint: Set the permissions of intermediate ept entries to __EPTE_FULL.
//       The hardware ANDs the permissions at each level, so removing a permission
//       bit at the last level entry is sufficient (and the bookkeeping is much simpler).
static int ept_lookup_gpa(epte_t* eptrt, void *gpa, 
			  int create, epte_t **epte_out) {
	epte_t * pgTblIndexPtr = NULL;
	struct PageInfo * page = NULL;

    /* Your code here */

	if(eptrt == NULL){
			cprintf("ept_lookup_gpa : 1\n");
			return -E_INVAL;
	}
	pgTblIndexPtr =  pml4e_walk(eptrt, gpa, create);
	if(pgTblIndexPtr == NULL){
		cprintf("ept_lookup_gpa : 2\n");
		if(create  == 0)
			return -E_NO_ENT;			
		else
			return  -E_NO_MEM;
	}
	
	page = pa2page(*pgTblIndexPtr);				
	if(epte_out)
	{
		*epte_out = pgTblIndexPtr;
	}
	return 0;
	
    //panic("ept_lookup_gpa not implemented\n");
    //return 0;

}
开发者ID:rishabhagrawal1,项目名称:JOS-on-JOS-hypervisor,代码行数:46,代码来源:ept.c

示例11: page_lookup

//
// Return the page mapped at virtual address 'va'.
// If pte_store is not zero, then we store in it the address
// of the pte for this page.  This is used by page_remove and
// can be used to verify page permissions for syscall arguments,
// but should not be used by most callers.
//
// Return NULL if there is no page mapped at va.
//
// Hint: the TA solution uses pgdir_walk and pa2page.
//
struct PageInfo *
page_lookup(pde_t *pgdir, void *va, pte_t **pte_store)
{      // Fill this function in
	pte_t *pte_entry;

	pte_entry = pgdir_walk(pgdir, va, 0);
	if (pte_entry == NULL)
		return NULL;
	if (*pte_entry == 0)
		return NULL;

	if (pte_store != NULL)
		*pte_store = pte_entry;

	return pa2page(PTE_ADDR(*pte_entry));	


/*	pte_t *pgtab=pgdir_walk(pgdir,va,0);
	if( !(pgtab) );
		return NULL;
	if(pte_store)
		*pte_store=pgtab;	

	return pa2page(PTE_ADDR(*pgtab));
*/
}
开发者ID:prasadv90,项目名称:AdvOS,代码行数:37,代码来源:pmap.c

示例12: page_insert

int
page_insert(Pde *pgdir, struct Page *pp, u_long va, u_int perm)
{
	// Fill this function in
	u_int PERM;
	Pte *pgtable_entry;
	PERM = perm | PTE_V;

	pgdir_walk(pgdir, va, 0, &pgtable_entry);

	if (pgtable_entry != 0 && (*pgtable_entry & PTE_V) != 0) {
		if (pa2page(*pgtable_entry) != pp) {
			page_remove(pgdir, va);
		} else	{
			tlb_invalidate(pgdir, va);
			*pgtable_entry = (page2pa(pp) | PERM);

			return 0;
		}
	}

	tlb_invalidate(pgdir, va);

	if (pgdir_walk(pgdir, va, 1, &pgtable_entry) != 0) {
		return -E_NO_MEM;    // panic("page insert wrong.\n");
	}

	*pgtable_entry = (page2pa(pp) | PERM);
	//printf("page_insert:PTE:\tcon:%x\[email protected]:%x\n",(int)*pgtable_entry,(int)pgtable_entry);
	pp->pp_ref++;
	return 0;
}
开发者ID:SivilTaram,项目名称:Jos-mips,代码行数:32,代码来源:pmap.c

示例13: check_pgfault

// check_pgfault - check correctness of pgfault handler
static void
check_pgfault(void) {
    size_t nr_free_pages_store = nr_free_pages();
    size_t slab_allocated_store = slab_allocated();

    check_mm_struct = mm_create();
    assert(check_mm_struct != NULL);

    struct mm_struct *mm = check_mm_struct;
    pgd_t *pgdir = mm->pgdir = boot_pgdir;
    assert(pgdir[0] == 0);

    struct vma_struct *vma = vma_create(0, PTSIZE, VM_WRITE);
    assert(vma != NULL);

    insert_vma_struct(mm, vma);

    uintptr_t addr = 0x100;
    assert(find_vma(mm, addr) == vma);

    int i, sum = 0;
    for (i = 0; i < 100; i ++) {
        *(char *)(addr + i) = i;
        sum += i;
    }
    for (i = 0; i < 100; i ++) {
        sum -= *(char *)(addr + i);
    }
    assert(sum == 0);

    page_remove(pgdir, ROUNDDOWN(addr, PGSIZE));
    free_page(pa2page(PMD_ADDR(*get_pmd(pgdir, addr, 0))));
    free_page(pa2page(PUD_ADDR(*get_pud(pgdir, addr, 0))));
    free_page(pa2page(PGD_ADDR(*get_pgd(pgdir, addr, 0))));
    pgdir[0] = 0;

    mm->pgdir = NULL;
    mm_destroy(mm);
    check_mm_struct = NULL;

    assert(nr_free_pages_store == nr_free_pages());
    assert(slab_allocated_store == slab_allocated());

    cprintf("check_pgfault() succeeded!\n");
}
开发者ID:spinlock,项目名称:ucore,代码行数:46,代码来源:vmm.c

示例14: pgdir_walk

/**
 * @brief Return the page mapped at virtual address 'va' in 
 * page directory 'pgdir'.
 *
 * If pte_store is not NULL, then we store in it the address
 * of the pte for this page.  This is used by page_remove
 * but should not be used by other callers.
 *
 * For jumbos, right now this returns the first Page* in the 4MB range
 *
 * @param[in]  pgdir     the page directory from which we should do the lookup
 * @param[in]  va        the virtual address of the page we are looking up
 * @param[out] pte_store the address of the page table entry for the returned page
 *
 * @return PAGE the page mapped at virtual address 'va'
 * @return NULL No mapping exists at virtual address 'va', or it's paged out
 */
page_t *page_lookup(pde_t *pgdir, void *va, pte_t **pte_store)
{
	pte_t* pte = pgdir_walk(pgdir, va, 0);
	if (!pte || !PAGE_PRESENT(*pte))
		return 0;
	if (pte_store)
		*pte_store = pte;
	return pa2page(PTE_ADDR(*pte));
}
开发者ID:kstraube,项目名称:hysim,代码行数:26,代码来源:pmap.c

示例15: page_lookup

//
// Return the page mapped at virtual address 'va'.
// If pte_store is not zero, then we store in it the address
// of the pte for this page.  This is used by page_remove and
// can be used to verify page permissions for syscall arguments,
// but should not be used by most callers.
//
// Return NULL if there is no page mapped at va.
//
// Hint: the TA solution uses pgdir_walk and pa2page.
//
struct PageInfo *
page_lookup(pde_t *pgdir, void *va, pte_t **pte_store)
{
	// Fill this function in
	    pte_t* pte = pgdir_walk(pgdir, va, 0);
        if (pte_store != NULL) *pte_store = pte;
        if (pte == NULL || !(*pte & PTE_P) ) return NULL;
        return pa2page(PTE_ADDR(*pte));
}
开发者ID:DoraXingyu,项目名称:JosLab_2015,代码行数:20,代码来源:pmap.c


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