diff options
author | Colin Schmidt <colins@berkeley.edu> | 2014-05-22 19:26:15 -0700 |
---|---|---|
committer | Colin Schmidt <colins@berkeley.edu> | 2014-05-22 19:26:15 -0700 |
commit | 7790a3cc371ed07b464e787c85ddd3e3f0b8169c (patch) | |
tree | cc3333e5c983c820004e1d15cd9e094b4cadbb7d /pk | |
parent | e50dc18f5df45ea358182ce7d986b77858219cd9 (diff) | |
download | pk-7790a3cc371ed07b464e787c85ddd3e3f0b8169c.zip pk-7790a3cc371ed07b464e787c85ddd3e3f0b8169c.tar.gz pk-7790a3cc371ed07b464e787c85ddd3e3f0b8169c.tar.bz2 |
determine the address for an mmap before setuping the vmr
Diffstat (limited to 'pk')
-rw-r--r-- | pk/vm.c | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -178,6 +178,8 @@ static int __handle_page_fault(uintptr_t vaddr, int prot) { size_t flen = MIN(RISCV_PGSIZE, v->length - (vaddr - v->addr)); ssize_t ret = file_pread(v->file, (void*)vaddr, flen, vaddr - v->addr + v->offset); + printk("VMR_%ld(ad:%ld,len:%ld,off:%ld,refcnt:%ld,prot:%ld\n",v - vmrs, v->addr, v->length, v->offset, v->refcnt, v->prot); + printk("vaddr:%ld,flen:%ld,ret:%ld\n",vaddr,flen,ret); kassert(ret > 0); if (ret < RISCV_PGSIZE) memset((void*)vaddr + ret, 0, RISCV_PGSIZE - ret); @@ -223,19 +225,21 @@ static void __do_munmap(uintptr_t addr, size_t len) uintptr_t __do_mmap(uintptr_t addr, size_t length, int prot, int flags, file_t* f, off_t offset) { size_t npage = (length-1)/RISCV_PGSIZE+1; - vmr_t* v = __vmr_alloc(addr, length, f, offset, npage, prot); - if (!v) - goto fail_vmr; - if (flags & MAP_FIXED) { if ((addr & (RISCV_PGSIZE-1)) || addr < current.user_min || addr + length > current.stack_top || addr + length < addr) - goto fail_vma; + return (uintptr_t)-1; } else if ((addr = __vm_alloc(npage)) == 0) - goto fail_vma; + return (uintptr_t)-1; + + vmr_t* v = __vmr_alloc(addr, length, f, offset, npage, prot); + if (!v) + return (uintptr_t)-1; + + printk("start:%ld, len:%ld\n",addr,length); for (uintptr_t a = addr; a < addr + length; a += RISCV_PGSIZE) { pte_t* pte = __walk_create(a); @@ -254,11 +258,6 @@ uintptr_t __do_mmap(uintptr_t addr, size_t length, int prot, int flags, file_t* if (f) file_incref(f); return addr; - -fail_vma: - __vmr_decref(v, npage); -fail_vmr: - return (uintptr_t)-1; } int do_munmap(uintptr_t addr, size_t length) |