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


C++ PGROUNDUP函数代码示例

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


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

示例1: growproc

// Grow current process's memory by n bytes.
// Return 0 on success, -1 on failure.
int
growproc(int n)
{
    uint sz;

    sz = proc->sz;
    if(n > 0) {
        //prevent heap from overwriting our stack
        int se=proc->se;
        int page_n = PGROUNDUP(n);
        int heap_size = PGROUNDUP(proc->sz);
        if((heap_size + page_n) > (se - PGSIZE)) {
            //panic("Heap is overwriting stack!"); //just return -1 is sufficient. No need to panic!
            return -1;
        }
        if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0)
            return -1;
    } else if(n < 0) {
        if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0)
            return -1;
    }
    proc->sz = sz;
    switchuvm(proc);
    return 0;
}
开发者ID:tmfahey,项目名称:cs537,代码行数:27,代码来源:proc.c

示例2: map_section

int
map_section(int k, int fd, SCNHDR *shdr, int envid) {
  u_int page_count;
  Pte *ptes;
  int i, retval = 0, type;
  off_t curloc = lseek(fd, 0, SEEK_CUR);
  u32 start, zero_start, len;

  if (!strcmp(shdr->s_name, ".text"))
    type = MS_TEXT;
  else if (!strcmp(shdr->s_name, ".data"))
    type = MS_DATA;
  else if (!strcmp(shdr->s_name, ".bss"))
    type = MS_BSS;
  else
    {
      type = MS_UNKNOWN;
      return 0;
    }

  page_count = PGNO(PGROUNDUP(shdr->s_size));
  if (type == MS_BSS) {
    start = PGROUNDUP(shdr->s_vaddr);
    if (start != shdr->s_vaddr) page_count--;
  }
  else
    start = shdr->s_vaddr;
  if ((ptes = malloc(sizeof(Pte) * page_count)) == 0) {
    return -1;
  }
  for (i=0; i < page_count; i++)
    ptes[i] = PG_U|PG_W|PG_P;
  
  if (sys_self_insert_pte_range(k, ptes, page_count, TEMP_REGION) < 0 ||
      sys_insert_pte_range(k, &vpt[PGNO(TEMP_REGION)], page_count, 
			   start, k, envid) < 0 ||
      (type != MS_BSS &&
       (lseek(fd, shdr->s_scnptr, SEEK_SET) != shdr->s_scnptr ||
	read(fd, (void*)TEMP_REGION, shdr->s_size) != shdr->s_size ||
	lseek(fd, curloc, SEEK_SET) != curloc))) {
    retval = -1;
  }
  if (type == MS_BSS) {
    zero_start = TEMP_REGION;
    len = page_count * NBPG;
  } else {
    zero_start = TEMP_REGION + shdr->s_size;
    len = NBPG - (zero_start & PGMASK);
  }
  bzero((void*)zero_start, len);
  if (type == MS_TEXT)
    mprotect((void*)TEMP_REGION, page_count*NBPG, PROT_READ);
  for (i=0; i < page_count; i++)
    ptes[i] = 0;
  sys_self_insert_pte_range(k, ptes, page_count, TEMP_REGION);
  if (retval == -1)
    sys_insert_pte_range(k, ptes, page_count, start, k, envid);
  return retval;
}
开发者ID:aunali1,项目名称:exopc,代码行数:59,代码来源:exec.c

示例3: init_range

void kmem_t::init_range(void* vstart, void* vend) {
  vstart = (char*)PGROUNDUP((uint)vstart);
  vend = (char*)PGROUNDUP((uint)vend);
  int startpfn = MAP_NR(vstart);
  int endpfn = MAP_NR(vend);
  int j=0;
  for(int i = startpfn; vstart < vend; i++, j++) {
    page_t* page = pages + i;
    page->vaddr = (void*)vstart;
    free_page(page);
    vstart += PGSIZE;
  }
}
开发者ID:qhjindev,项目名称:jinos,代码行数:13,代码来源:kmem.cpp

示例4: maybe_commission_sector

/* Find an empty sector and bring it into use.  If there isn't one,
   try and allocate one.  If that fails, return -1. */
static
Int maybe_commission_sector ( void )
{
   Char msg[100];
   Int  s;
   for (s = 0; s < VG_TC_N_SECTORS; s++) {
      if (vg_tc[s] != NULL && vg_tc_used[s] == 0) {
         vg_tc_age[s] = overall_in_count;
         VG_(sprintf)(msg, "after  commission of sector %d "
                           "at time %d", 
                           s, vg_tc_age[s]);
         pp_tt_tc_status ( msg );
#        ifdef DEBUG_TRANSTAB
         VG_(sanity_check_tt_tc)();
#        endif
         return s;
      }
   }
   for (s = 0; s < VG_TC_N_SECTORS; s++) {
      if (vg_tc[s] == NULL) {
#if 1
         vg_tc[s] = VG_(get_memory_from_mmap) 
                       ( vg_tc_sector_szB, "trans-cache(sector)" );
#else
         // Alternative: put translations in an mmap'd file.  The main
         // reason is to help OProfile -- OProfile can assign time spent in
         // translations to a particular file.  The file format doesn't
         // really matter, which is good because it's not really readable,
         // being generated code but not a proper ELF file.
	 Char buf[20];
	 static Int count = 0;
	 Int fd;
	 
	 VG_(sprintf)(buf, ".transtab.%d", count++);

	 fd = VG_(open)(buf, VKI_O_RDWR|VKI_O_CREAT|VKI_O_TRUNC, 0700);
	 //VG_(unlink)(buf);
	 VG_(do_syscall)(__NR_ftruncate, fd, PGROUNDUP(vg_tc_sector_szB));
	 vg_tc[s] = VG_(mmap)(0, PGROUNDUP(vg_tc_sector_szB), VKI_PROT_READ|VKI_PROT_WRITE|VKI_PROT_EXEC, VKI_MAP_SHARED, 0, fd, 0);
	 VG_(close)(fd);
#endif
         vg_tc_used[s] = 0;
         VG_(sprintf)(msg, "after  allocation of sector %d (size %d)", 
                           s, vg_tc_sector_szB );
         pp_tt_tc_status ( msg );
         return maybe_commission_sector();
      }
   }
   return -1;
}
开发者ID:svn2github,项目名称:valgrind-3,代码行数:52,代码来源:vg_transtab.c

示例5: __zero_segment

static int
__zero_segment (int envid, u_int start, u_int sz)
{
  u_int temp_pages;

  assert (!(start & PGMASK)); 

  temp_pages = (u_int)__malloc(PGROUNDUP(sz));
  if (temp_pages == 0) return -1;

  /* alloc pages for this segment and map into our address space writeable */
  if (__vm_alloc_region (temp_pages, sz, 0, PG_P|PG_U|PG_W) < 0) {
    __free((void*)temp_pages);
    return -1;
  }
  /* and map them into the other address space */
  if (__vm_share_region (temp_pages, sz, 0, 0, envid, start) < 0) {
    __free((void*)temp_pages);
    return -1;
  }
  /* zero the pages */
  bzero ((void *)temp_pages, sz);
  /* and remove our mapping of the pages */
  if (__vm_free_region (temp_pages, sz, 0) < 0) {
    __free((void*)temp_pages);
    return -1;
  }

  __free((void*)temp_pages);
  return 0;
}  
开发者ID:aunali1,项目名称:exopc,代码行数:31,代码来源:shexec.c

示例6: 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);
  int isShmem; //added by Ying
  for(; a  < oldsz; a += PGSIZE){
    isShmem = 0; //added by Ying
    pte = walkpgdir(pgdir, (char*)a, 0);
    if(pte && (*pte & PTE_P) != 0){
      pa = PTE_ADDR(*pte);

      //added by Ying
      int i;
      for (i = 0; i < 4; i++) {
          if (pa == (unsigned int)shmem_addr[i])
            isShmem = 1;
      }
      if (isShmem) continue;

      if(pa == 0)
        panic("kfree");
      kfree((char*)pa);
      *pte = 0;
    }
  }
  return newsz;
}
开发者ID:daisyfy1991,项目名称:cs537,代码行数:37,代码来源:vm.c

示例7: 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:arielqw,项目名称:ariel-ami,代码行数:29,代码来源:vm.c

示例8: 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");
      acquire(&r_c.lock);
      r_c.ref_count[pa / 4096] --;
      if(r_c.ref_count[pa / 4096] == 0) {
        char *v = p2v(pa);
        kfree(v);
      }
      release(&r_c.lock);
      *pte = 0;
    }
  }
  return newsz;
}
开发者ID:TBReinhart,项目名称:os_4,代码行数:34,代码来源:vm.c

示例9: allocuvm

// Allocate page tables and physical memory to grow process from oldsz to
// newsz, which need not be page aligned.  Returns new size or 0 on error.
int
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
  char *mem;
  uint a;

  if(newsz >= KERNBASE)
    return 0;
  if(newsz < oldsz)
    return oldsz;

  cprintf("%d \n", oldsz);
  cprintf("%d \n", newsz);

  a = PGROUNDUP(oldsz);
  for(; a < newsz; a += PGSIZE){
    mem = kalloc();
    if(mem == 0){
      cprintf("allocuvm out of memory\n");
      deallocuvm(pgdir, newsz, oldsz);
      return 0;
    }
    memset(mem, 0, PGSIZE);
    mappages(pgdir, (char*)a, PGSIZE, v2p(mem), PTE_W|PTE_U);
  }
  return newsz;
}
开发者ID:satote2,项目名称:xv6,代码行数:29,代码来源:vm.c

示例10: register_pagefault_handler

int register_pagefault_handler (uint vastart, int len,
				int (*handler)(uint,int))
{
   handler_t *tmp = handlers;
   uint vaend = PGROUNDUP (vastart+len);

   vastart = PGROUNDDOWN (vastart);

   while (tmp) {
      if ((vastart >= tmp->vastart) && (vastart < tmp->vaend)) {
         return (-1);
      }
      if ((vaend >= tmp->vastart) && (vaend < tmp->vaend)) {
         return (-1);
      }
      if ((vastart < tmp->vastart) && (vaend >= tmp->vaend)) {
         return (-1);
      }
      tmp = tmp->next;
   }

   tmp = (handler_t *) __malloc (sizeof(handler_t));
   assert(tmp);
   tmp->vastart = vastart;
   tmp->vaend = vaend;
   tmp->handler = handler;
   tmp->next = handlers;
   handlers = tmp;

   /* kprintf ("(%d) pagefault_handler registered for %x -- %x\n", geteid(),
      tmp->vastart, tmp->vaend); */

   return (0);
}
开发者ID:aunali1,项目名称:exopc,代码行数:34,代码来源:fault.c

示例11: allocuvm

// Allocate page tables and physical memory to grow process from oldsz to
// newsz, which need not be page aligned.  Returns new size or 0 on error.
int
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
  char *mem;
  uint a;

  if(newsz > USERTOP)
    return 0;
  if(newsz < oldsz)
    return oldsz;

  a = PGROUNDUP(oldsz);
  for(; a < newsz; a += PGSIZE){
    mem = kalloc();
    if(mem == 0){
      cprintf("proc %d: allocuvm out of memory\n", proc->pid);
      cprintf("proc %d: newsz: %d\n", proc->pid, newsz);
      cprintf("proc %d: oldsz: %d\n", proc->pid, oldsz);
      deallocuvm(pgdir, newsz, oldsz);
      return 0;
    }
    memset(mem, 0, PGSIZE);
    mappages(pgdir, (char*)a, PGSIZE, PADDR(mem), PTE_W|PTE_U);
  }
  return newsz;
}
开发者ID:zambur,项目名称:Course-Work,代码行数:28,代码来源:vm.c

示例12: freerange

void freerange(void *vstart, void *vend)
{
  char *p;
  p = (char*)PGROUNDUP((uint)vstart);
  for(; p + PGSIZE <= (char*)vend; p += PGSIZE)
    kfree(p);
}
开发者ID:kalfazed,项目名称:Operating-System,代码行数:7,代码来源:kalloc.c

示例13: allocuvm

// Allocate page tables and physical memory to grow process from oldsz to
// newsz, which need not be page aligned.  Returns new size or 0 on error.
int
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
  char *mem;
  uint a;

  if(newsz >= KERNBASE)
    return 0;
  if(newsz < oldsz)
    return oldsz;

  a = PGROUNDUP(oldsz);
  for(; a < newsz; a += PGSIZE){
    mem = kalloc();
    if(mem == 0){
      cprintf("allocuvm out of memory\n");
      deallocuvm(pgdir, newsz, oldsz);
      return 0;
    }
    memset(mem, 0, PGSIZE);
    if (mappages(pgdir, (char*)a, PGSIZE, V2P(mem), PTE_W|PTE_U) < 0)
      panic("allocuvm: cannot create pagetable");
  }
  return newsz;
}
开发者ID:baileyparker,项目名称:xv6-public,代码行数:27,代码来源:vm.c

示例14: allocuvm

// Allocate page tables and physical memory to grow process from oldsz to
// newsz, which need not be page aligned.  Returns new size or 0 on error.
int
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
  char *mem;
  uint a;

  if(newsz > USERTOP)
    return 0;
  if(newsz < oldsz)
    return oldsz;

  a = PGROUNDUP(oldsz);
  for(; a < newsz; a += PGSIZE){
    mem = kalloc();
    if(mem == 0){
      cprintf("allocuvm out of memory\n");
      deallocuvm(pgdir, newsz, oldsz);
      return 0;
    }
    //cprintf("alloc a new page starting at: %x\n", mem);
    memset(mem, 0, PGSIZE);
    mappages(pgdir, (char*)a, PGSIZE, PADDR(mem), PTE_W|PTE_U);
  }
  return newsz;
}
开发者ID:byan23,项目名称:OS_P3,代码行数:27,代码来源:vm.c

示例15: VG_

/* set new protection flags on an address range */
void VG_(mprotect_range)(Addr a, UInt len, UInt prot)
{
   Segment *s, *next;
   static const Bool debug = False || mem_debug;

   if (debug)
      VG_(printf)("mprotect_range(%p, %d, %x)\n", a, len, prot);

   /* Everything must be page-aligned */
   vg_assert((a & (VKI_BYTES_PER_PAGE-1)) == 0);
   len = PGROUNDUP(len);

   VG_(split_segment)(a);
   VG_(split_segment)(a+len);

   for(s = VG_(SkipList_Find)(&sk_segments, &a);
       s != NULL && s->addr < a+len;
       s = next)
   {
      next = VG_(SkipNode_Next)(&sk_segments, s);
      if (s->addr < a)
	 continue;

      s->prot = prot;
   }

   merge_segments(a, len);
}
开发者ID:svn2github,项目名称:valgrind-3,代码行数:29,代码来源:vg_memory.c


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