From 113093f919a9be4196137912ba5747a3abc68b37 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 23 Apr 2019 20:37:41 -0700 Subject: [PATCH] Fix page table copying bug. --- kern/env.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kern/env.c b/kern/env.c index 51e1f36..1b53826 100644 --- a/kern/env.c +++ b/kern/env.c @@ -186,7 +186,7 @@ env_setup_vm(struct Env *e) // - The functions in kern/pmap.h are handy. p->pp_ref++; e->env_pgdir = page2kva(p); - memcpy(e->env_pgdir + PDX(UTOP), kern_pgdir + PDX(UTOP), NPDENTRIES - PDX(UTOP)); + memcpy(e->env_pgdir + PDX(UTOP), kern_pgdir + PDX(UTOP), sizeof(pde_t) * (NPDENTRIES - PDX(UTOP))); // UVPT maps the env's own page table read-only. // Permissions: kernel R, user R @@ -276,11 +276,10 @@ region_alloc(struct Env *e, void *va, size_t len) // You should round va down, and round (va + len) up. // (Watch out for corner-cases!) va = ROUNDDOWN(va, PGSIZE); - len = ROUNDUP(len, PGSIZE); - void* last_va = va + len; + size_t count = ROUNDUP(len, PGSIZE) / PGSIZE; struct PageInfo* p; - while(va < last_va) { + while(count--) { if(!(p = page_alloc(0))) panic("Failed to allocate memory"); if(page_insert(e->env_pgdir, p, va, PTE_U | PTE_W))