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


C++ p2v函数代码示例

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


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

示例1: deallocuvm

// Deallocate user pages to bring the process size from oldsz to
// newsz.  oldsz and newsz need not be page-aligned, nor does newsz
// need to be less than oldsz.  oldsz can be larger than the actual
// process size.  Returns the new process size.
int
deallocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
  pte_t *pte;
  uint a, pa;

  if(newsz >= oldsz)
    return oldsz;

  a = PGROUNDUP(newsz);
  for(; a  < oldsz; a += PGSIZE){
    pte = walkpgdir(pgdir, (char*)a, 0);
    if(!pte)
      a += (NPTENTRIES - 1) * PGSIZE;
    else if((*pte & PTE_P) != 0){
      pa = PTE_ADDR(*pte);
      if(pa == 0)
        panic("kfree");
      char *v = p2v(pa);
      kfree(v);
      *pte = 0;
    }
  }
  return newsz;
}
开发者ID:hxp,项目名称:xv6,代码行数:29,代码来源:vm.c

示例2: save_decoded_frame

static void save_decoded_frame(decoder_context *decoder, frame_data *frame)
{
	FILE *fp = decoder->opaque;
	long foff = ftell(fp);

	fwrite(p2v(frame->Y_paddr), 1, frame_luma_size(decoder), fp);
	fwrite(p2v(frame->U_paddr), 1, frame_chroma_size(decoder), fp);
	fwrite(p2v(frame->V_paddr), 1, frame_chroma_size(decoder), fp);

	if (ferror(fp) != 0) {
		perror("Error writing to output file");
		abort();
	}

	printf("Saved frame %d file offset 0x%lX\n",
	       decoder->frames_decoded - 1, foff);
}
开发者ID:digetx,项目名称:VDE-Tegra2,代码行数:17,代码来源:main.c

示例3: procdump

//PAGEBREAK: 36
// Print a process listing to console.  For debugging.
// Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
void
procdump(void)
{
  static char *states[] = {
  [UNUSED]    "unused",
  [EMBRYO]    "embryo",
  [SLEEPING]  "sleep ",
  [RUNNABLE]  "runble",
  [RUNNING]   "run   ",
  [ZOMBIE]    "zombie"
  };
  int i;
  struct proc *p;
  pde_t *pde;
  pte_t *pgtab, *pte;
  uint *va;
  char *state;
  uint pc[10];
  
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    if(p->state == UNUSED)
      continue;
    if(p->state >= 0 && p->state < NELEM(states) && states[p->state])
      state = states[p->state];
    else
      state = "???";
    int j, k;
    cprintf("%d %s %s", p->pid, state, p->name);
    cprintf("Page tables: \n");
    cprintf("	Memory location of page directory = %p\n", p->pgdir); 
    for(j = 0 ; j < 1024 ; j++){
	pde = &(p->pgdir[j]);
        if((uint)*pde & PTE_P){//The page directory entry is present
	   cprintf("		pdir PTE %d, %d\n", j, (uint)(((uint)*pde >> 12 ) & 0xfffff));
	   pgtab = (pte_t*)p2v(PTE_ADDR(*pde));
	   cprintf("		memory location of page table = %p\n", pgtab);
	   for(k = 0 ; k < 1024 ; k++){
	        pte = &pgtab[k];
		if((uint)*pte & PTE_P && (uint)*pte & PTE_U) {
		    va = (uint*)p2v(PTE_ADDR(*pte));
		    cprintf("			ptbl PTE %d, %p, %p\n", k, (uint)(PTE_ADDR(*pte) >> 12), va);
		}
	   }
	}
    }
开发者ID:Studentblanchard,项目名称:OS2,代码行数:49,代码来源:proc.c

示例4: dot

Point Sphere::Hit(Ray ray) 
{

  Point start = ray.start;
  Vector direction = ray.direction;
  Point retval;
  retval.valid = false;

  double A,B,C;
  
  A = dot(ray.direction, ray.direction);
  B = dot (p2v(ray.start), ray.direction);
  C = dot(p2v(ray.start), p2v(ray.start)) - 1.0;
  double discrim = B*B - A*C;
  if (discrim < 0.0)
    {
      //      printf("ray misses\n");
      return retval;
    }

  double discRoot = sqrt(discrim);
  double t1 = (-B - discRoot)/A;
  double t2 = (-B + discRoot)/A;

  if (t1 > 0.000001 && t2 > 0.000001)
      {
	retval = ray.start + v2p(direction)*t1;
	retval.valid = true;
	normal = p2v(retval);
	return retval;
      }
  /* 
  double t2 = (-B + discRoot)/A;
  if (t2 > 0.00001)
    {
      //      printf("back hit\n");
      retval = ray.start + v2p(direction)*t2;
      retval.valid = true;
      normal = p2v(retval) ;
      return retval;
    }
  */
  return retval;
}
开发者ID:michaelbernstein,项目名称:OSU-CIS681-Raytracer-from-2004,代码行数:44,代码来源:sphere.cpp

示例5: kinit

// Initialize free list of physical pages.
void
kinit(void)
{
  char *p;

  initlock(&kmem.lock, "kmem");
  p = (char*)PGROUNDUP((uint)newend);
  for(; p + PGSIZE <= (char*)p2v(PHYSTOP); p += PGSIZE)
    kfree(p);
}
开发者ID:KWMalik,项目名称:Homework-3,代码行数:11,代码来源:kalloc.c

示例6: uva2ka

//PAGEBREAK!
// Map user virtual address to kernel address.
char*
uva2ka(pde_t *pgdir, char *uva) {
	pte_t *pte;

	pte = walkpgdir(pgdir, uva, 0);
	if ((*pte & PTE_P) == 0)
		return 0;
	if ((*pte & PTE_U) == 0)
		return 0;
	return (char*) p2v(PTE_ADDR(*pte));
}
开发者ID:salexa92,项目名称:os161ass3,代码行数:13,代码来源:vm.c

示例7: check_page_fault

//Wille return 0 if error, 1 if success
int check_page_fault(pde_t *pgdir, uint va) {
    pte_t *pte;
    uint pa;
    char *mem;

    //check if exists, and allowed by user
    if(va >= KERNBASE || va < 4096) {
        cprintf("Kernel or Null memory access\n");
        return 0;
    }
    if((pte = walkpgdir(pgdir, (void *)va, 0)) == 0) {
        cprintf("memory access not in page dir\n");
        return 0;
    }
    if( (!(*pte & PTE_P)) || (!(*pte & PTE_U)) ) {
        cprintf("memory access not for users\n");
        return 0;
    }
    if( !(*pte & PTE_COW)) {
        cprintf("No cow bit, writing to read only mem\n");
        return 0;
    }
    if( *pte & PTE_W) {
        cprintf("Writing other processes mem, error\n");
        return 0;
    }
    pa = PTE_ADDR(*pte);
    //CHANGE: update reference counts
    acquire(&r_c.lock);
    if(r_c.ref_count[pa / 4096] == 1) {
        *pte = *pte | PTE_W;
        *pte = *pte & (~PTE_COW);
        release(&r_c.lock);
        //flush translation lookaside buffer
        flushtlb();
        return 1;
    } 
    else {
        r_c.ref_count[pa / 4096]--;
        release(&r_c.lock);
        if((mem = kalloc()) == 0) {
            return 0;
        }
        memmove(mem, (char*)p2v(pa), PGSIZE);
        *pte = v2p(mem) | PTE_FLAGS(*pte) | PTE_W;
        *pte = *pte & (~PTE_COW);
        acquire(&r_c.lock);
        r_c.ref_count[v2p(mem) / 4096] = 1;
        release(&r_c.lock);
        //flush translation lookaside buffer
        flushtlb();
        return 1;
    }
}
开发者ID:TBReinhart,项目名称:os_4,代码行数:55,代码来源:vm.c

示例8: walkpgdir

// Return the address of the PTE in page directory that corresponds to
// virtual address va.  If alloc!=0, create any required page table pages.
static pte_t* walkpgdir (pgd_t *pgdbase, const void *va, int alloc)
{
    pgd_t *pgd;
    pmd_t *pmdbase;
    pmd_t *pmd;
    pte_t *ptebase;

    pgd = &pgdbase[PGD_IDX((uint64)va)];

    if(*pgd & (ENTRY_TABLE | ENTRY_VALID)) {
        pmdbase = (pmd_t*) p2v((*pgd) & PG_ADDR_MASK);
    } else {
        if (!alloc || (pmdbase = (pmd_t*) kpt_alloc()) == 0) {
            return 0;
        }

        memset(pmdbase, 0, PT_SZ);

        *pgd = v2p(pmdbase) | ENTRY_TABLE | ENTRY_VALID;
    }

    pmd = &pmdbase[PMD_IDX(va)];

    if (*pmd & (ENTRY_TABLE | ENTRY_VALID)) {
        ptebase = (pte_t*) p2v((*pmd) & PG_ADDR_MASK);
    } else {
        if (!alloc || (ptebase = (pte_t*) kpt_alloc()) == 0) {
           return 0;
        }

        // Make sure all those PTE_P bits are zero.
        memset(ptebase, 0, PT_SZ);

        // The permissions here are overly generous, but they can
        // be further restricted by the permissions in the page table
        // entries, if necessary.
        *pmd = v2p(ptebase) | ENTRY_TABLE | ENTRY_VALID;
    }

    return &ptebase[PTE_IDX(va)];
}
开发者ID:finallyjustice,项目名称:xv6-OS-for-arm-v8,代码行数:43,代码来源:vm.c

示例9: swapOut

void 
swapOut(struct proc* p)
{
  //write to file
  char filename[9];
    struct file* f;
    uint i;
    pte_t* pte=0;
    getSwapFileName(p, filename);

    //cprintf("swapout %s %d\n", p->name, p->pid);
    //release(&inswapper_lk);
    //acquire(&inswapper_lk);
    release(&ptable.lock);
    f = openKernelFile(filename, O_CREATE | O_WRONLY);
    acquire(&ptable.lock);
    //cprintf("sfff\n");
    //release(&inswapper_lk);
    if(f == 0)
      panic("swapout: file open error\n");

    //cprintf("swapout: before write\n");
    int freed = 0;
    for (i = 0; i < p->sz; i += PGSIZE) {
         if (!(pte = walkpgdir(p->pgdir, (void *) i, 0)))
             panic("swapout: pte should exist\n");
         //cprintf("walkpgdir: ok\n");
        if (!(*pte & PTE_P))
            panic("swapout: page not present\n");
        if((*pte & PTE_SHR) || !(*pte & PTE_U))
          continue;
        char *addr=(char*)p2v(PTE_ADDR(*pte));
        //acquire(&inswapper_lk);
        release(&ptable.lock);
        filewrite(f, addr, PGSIZE);
        acquire(&ptable.lock);
       // release(&inswapper_lk);
        //cprintf("(w=%s)", addr);
        kfree(addr);
        *pte = 0;
        freed++;
        //cprintf("swapout: wrote %d\n",i/PGSIZE);
    }
    //cprintf("swapout freed %d\n", freed);
    //kfree((char*) p->pgdir);
    //cprintf("swapout: after write\n");
    //freevm(p->pgdir);
   // acquire(&inswapper_lk);
    release(&ptable.lock);
    fileclose(f);
    acquire(&ptable.lock);
   // release(&inswapper_lk);
}
开发者ID:RonBarabash,项目名称:OS132-Ass3,代码行数:53,代码来源:proc.c

示例10: mpsearch1

// Look for an MP structure in the len bytes at addr.
static struct mp*
mpsearch1(uint a, int len)
{
  uchar *e, *p, *addr;

  addr = p2v(a);
  e = addr+len;
  for(p = addr; p < e; p += sizeof(struct mp))
    if(memcmp(p, "_MP_", 4) == 0 && sum(p, sizeof(struct mp)) == 0)
      return (struct mp*)p;
  return 0;
}
开发者ID:KWMalik,项目名称:Homework-3,代码行数:13,代码来源:mp.c

示例11: uva2ka

//PAGEBREAK!
// Map user virtual address to kernel address.
char*
uva2ka(pde_t *pgdir, char *uva)
{
  pte_t *pte;

  pte = walkpgdir(pgdir, uva, UVMPDXATTR, 0);
  if((uint)*pte == 0)
    return 0;
  if(((uint)*pte & PTX_AP(U_AP)) == 0)
    return 0;
  return (char*)p2v(PTE_ADDR(*pte));
}
开发者ID:VictorDu,项目名称:xv6_rpi_port,代码行数:14,代码来源:vm.c

示例12: freevm

// Free a page table and all the physical memory pages
// in the user part.
void freevm(pde_t *pgdir) {
	uint i;

	if (pgdir == 0)
		panic("freevm: no pgdir");
	deallocuvm(pgdir, KERNBASE, 0);
	for (i = 0; i < NPDENTRIES; i++) {
		if (pgdir[i] & PTE_P) {
			char * v = p2v(PTE_ADDR(pgdir[i]));
			kfree(v);
		}
	}
	kfree((char*) pgdir);
}
开发者ID:salexa92,项目名称:os161ass3,代码行数:16,代码来源:vm.c

示例13: walkpgdir

static pte_t *
walkpgdir(pde_t *pgdir, const void *va)
{
    pde_t *pde;
    pte_t *pgtab;

    pde = &pgdir[PDX(va)];
    if(*pde & PTE_P) {
        pgtab = (pte_t*)p2v(PTE_ADDR(*pde));
    } else {
        return 0;
    }
    return &pgtab[PTX(va)];
}
开发者ID:forwchen,项目名称:xv6-lab,代码行数:14,代码来源:proc.c

示例14: setupkvm

// Set up kernel part of a page table.
pde_t*
setupkvm(void) {
	pde_t *pgdir;
	struct kmap *k;

	if ((pgdir = (pde_t*) kalloc()) == 0)
		return 0;
	memset(pgdir, 0, PGSIZE);
	if (p2v(PHYSTOP) > (void*) DEVSPACE)
		panic("PHYSTOP too high");
	for (k = kmap; k < &kmap[NELEM(kmap)]; k++)
		if (mappages(pgdir, k->virt, k->phys_end - k->phys_start,
				(uint) k->phys_start, k->perm) < 0)
			return 0;
	return pgdir;
}
开发者ID:salexa92,项目名称:os161ass3,代码行数:17,代码来源:vm.c

示例15: freevm

// Free a page table and all the physical memory pages
// in the user part.
void
freevm(pde_t *pgdir)
{
  uint i;

  if(pgdir == 0)
    panic("freevm: no pgdir");
  deallocuvm(pgdir, USERBOUND, 0);
  for(i = 0; i < NPDENTRIES; i++){
    if((uint)pgdir[i] != 0){
      char * v = p2v(PTE_ADDR(pgdir[i]));
      kfree(v);
    }
  }
  kfree((char*)pgdir);
}
开发者ID:VictorDu,项目名称:xv6_rpi_port,代码行数:18,代码来源:vm.c


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