vir_bytes offset;
int p, wr = PFERR_WRITE(err);
-#if 0
- printf("VM: pagefault: ep %d 0x%lx %s\n",
- ep, arch_map2vir(vmp, addr), pf_errstr(err));
-#endif
-
if(vm_isokendpt(ep, &p) != OK)
vm_panic("do_pagefaults: endpoint wrong", ep);
vmp = &vmproc[p];
vm_assert(vmp->vm_flags & VMF_INUSE);
-#if 0
- map_printmap(vmp);
-#endif
-
/* See if address is valid at all. */
if(!(region = map_lookup(vmp, addr))) {
vm_assert(PFERR_NOPAGE(err));
vm_panic("do_pagefaults: sys_vmctl failed", ep);
continue;
}
-#if 0
- printf("VM: map_pf done; ep %d 0x%lx %s\n",
- ep, arch_map2vir(vmp, addr), pf_errstr(err));
-
-
- printf("VM: handling pagefault OK: %d addr 0x%lx %s\n",
- ep, arch_map2vir(vmp, addr), pf_errstr(err));
-#endif
/* Pagefault is handled, so now reactivate the process. */
if((s=sys_vmctl(ep, VMCTL_CLEAR_PAGEFAULT, r)) != OK)
if(sys_vmctl(requestor, VMCTL_MEMREQ_REPLY, r) != OK)
vm_panic("do_memory: sys_vmctl failed", r);
-
-#if 0
- printf("VM: handling memory request %d done OK\n",
- who);
-#endif
}
}
{
struct vir_region *region;
vir_bytes o;
- int r;
-
-#if 0
- printf("VM: handling memory request: %d, 0x%lx-0x%lx, wr %d\n",
- vmp->vm_endpoint, mem, mem+len, wrflag);
-#endif
+ vir_bytes v;
/* Page-align memory and length. */
o = mem % VM_PAGE_SIZE;
o = len % VM_PAGE_SIZE;
if(o > 0) len += VM_PAGE_SIZE - o;
- if(!(region = map_lookup(vmp, mem))) {
- map_printmap(vmp);
- printf("VM: do_memory: memory doesn't exist\n");
- r = EFAULT;
- } else if(mem + len > region->vaddr + region->length) {
- vm_assert(region->vaddr <= mem);
- vm_panic("do_memory: not contained", NO_NUM);
- } else if(!(region->flags & VR_WRITABLE) && wrflag) {
- printf("VM: do_memory: write to unwritable map\n");
- r = EFAULT;
- } else {
- vir_bytes offset;
- vm_assert(region->vaddr <= mem);
- vm_assert(!(region->flags & VR_NOPF));
- vm_assert(!(region->vaddr % VM_PAGE_SIZE));
- offset = mem - region->vaddr;
-
- r = map_handle_memory(vmp, region, offset, len, wrflag);
- }
-
- if(r != OK) {
- printf("VM: memory range 0x%lx-0x%lx not available in %d\n",
- arch_map2vir(vmp, mem), arch_map2vir(vmp, mem+len),
- vmp->vm_endpoint);
+ while(len > 0) {
+ int r;
+ if(!(region = map_lookup(vmp, mem))) {
+ map_printmap(vmp);
+ printf("VM: do_memory: memory doesn't exist\n");
+ r = EFAULT;
+ } else if(!(region->flags & VR_WRITABLE) && wrflag) {
+ printf("VM: do_memory: write to unwritable map\n");
+ r = EFAULT;
+ } else {
+ vir_bytes offset, sublen;
+ vm_assert(region->vaddr <= mem);
+ vm_assert(!(region->flags & VR_NOPF));
+ vm_assert(!(region->vaddr % VM_PAGE_SIZE));
+ offset = mem - region->vaddr;
+ sublen = len;
+ if(offset + sublen > region->length)
+ sublen = region->length - offset;
+
+ r = map_handle_memory(vmp, region, offset,
+ sublen, wrflag);
+
+ len -= sublen;
+ mem += sublen;
+ }
+
+ if(r != OK) {
+ printf("VM: memory range 0x%lx-0x%lx not available in %d\n",
+ arch_map2vir(vmp, mem), arch_map2vir(vmp, mem+len),
+ vmp->vm_endpoint);
+ return r;
+ }
}
- return r;
+ return OK;
}
physr_start_iter(region->phys, &it, where, AVL_EQUAL); \
what = physr_get_iter(&it); \
if(!what) vm_panic("thing missing", NO_NUM); \
+ if(what->offset != where) vm_panic("thing wrong", NO_NUM); \
}
FREE_RANGE_HERE(NULL, physr);
physr_incr_iter(&iter);
physr = physr_get_iter(&iter);
+ FREE_RANGE_HERE(NULL, physr);
if(physr) {
- FREE_RANGE_HERE(NULL, physr);
RESET_ITER(iter, physr->offset, physr);
}
}
SANITYCHECK(SCL_FUNCTIONS);
- vm_assert(changes > 0);
+ if(changes < 1) {
+ printf("region start at 0x%lx offset 0x%lx len 0x%lx write %d\n",
+ region->vaddr, offset, length, write);
+ vm_panic("no changes in map_handle_memory", NO_NUM);
+ }
#if SANITYCHECKS
if(OK != pt_checkrange(&vmp->vm_pt, region->vaddr+offset, length, write)) {