summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--defs.h6
-rw-r--r--kalloc.c2
-rw-r--r--vm.c21
3 files changed, 13 insertions, 16 deletions
diff --git a/defs.h b/defs.h
index 43f35d2..8ea46d6 100644
--- a/defs.h
+++ b/defs.h
@@ -161,11 +161,11 @@ int allocuvm(pde_t*, uint, uint);
int deallocuvm(pde_t*, uint, uint);
void freevm(pde_t*);
void inituvm(pde_t*, char*, uint);
-int loaduvm(pde_t*, char*, struct inode *, uint, uint);
-pde_t* copyuvm(pde_t*,uint);
+int loaduvm(pde_t*, char*, struct inode*, uint, uint);
+pde_t* copyuvm(pde_t*, uint);
void switchuvm(struct proc*);
void switchkvm(void);
-int copyout(pde_t *pgdir, uint va, void *buf, uint len);
+int copyout(pde_t*, uint, void*, uint);
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
diff --git a/kalloc.c b/kalloc.c
index e31d71d..bf1616a 100644
--- a/kalloc.c
+++ b/kalloc.c
@@ -27,7 +27,7 @@ kinit(void)
initlock(&kmem.lock, "kmem");
p = (char*)PGROUNDUP((uint)end);
- for(; p + PGSIZE - 1 < (char*)PHYSTOP; p += PGSIZE)
+ for(; p + PGSIZE <= (char*)PHYSTOP; p += PGSIZE)
kfree(p);
}
diff --git a/vm.c b/vm.c
index 940cc2f..bfc0845 100644
--- a/vm.c
+++ b/vm.c
@@ -250,16 +250,16 @@ loaduvm(pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
int
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
- char *a, *last, *mem;
+ char *mem;
+ uint a;
if(newsz > USERTOP)
return 0;
if(newsz < oldsz)
return oldsz;
- a = (char*)PGROUNDUP(oldsz);
- last = PGROUNDDOWN(newsz - 1);
- for(; a <= last; a += PGSIZE){
+ a = PGROUNDUP(oldsz);
+ for(; a < newsz; a += PGSIZE){
mem = kalloc();
if(mem == 0){
cprintf("allocuvm out of memory\n");
@@ -267,7 +267,7 @@ allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
return 0;
}
memset(mem, 0, PGSIZE);
- mappages(pgdir, a, PGSIZE, PADDR(mem), PTE_W|PTE_U);
+ mappages(pgdir, (char*)a, PGSIZE, PADDR(mem), PTE_W|PTE_U);
}
return newsz;
}
@@ -279,17 +279,15 @@ allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
int
deallocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
- char *a, *last;
pte_t *pte;
- uint pa;
+ uint a, pa;
if(newsz >= oldsz)
return oldsz;
- a = (char*)PGROUNDUP(newsz);
- last = PGROUNDDOWN(oldsz - 1);
- for(; a <= last; a += PGSIZE){
- pte = walkpgdir(pgdir, a, 0);
+ a = PGROUNDUP(newsz);
+ for(; a < oldsz; a += PGSIZE){
+ pte = walkpgdir(pgdir, (char*)a, 0);
if(pte && (*pte & PTE_P) != 0){
pa = PTE_ADDR(*pte);
if(pa == 0)
@@ -351,7 +349,6 @@ bad:
// copy some data to user address va in page table pgdir.
// most useful when pgdir is not the current page table.
-// returns 1 if everthing OK, 0 on error.
// uva2ka ensures this only works for PTE_U pages.
int
copyout(pde_t *pgdir, uint va, void *xbuf, uint len)