Fix page table copying bug.

This commit is contained in:
Danila Fedorin 2019-04-23 20:37:41 -07:00
parent 94b52c5730
commit 113093f919

View File

@ -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))