more trivial cleanup
This commit is contained in:
parent
89bfdd4db1
commit
417c37115e
3 changed files with 13 additions and 16 deletions
2
defs.h
2
defs.h
|
@ -165,7 +165,7 @@ int loaduvm(pde_t*, char*, struct inode *, uint, uint);
|
||||||
pde_t* copyuvm(pde_t*, uint);
|
pde_t* copyuvm(pde_t*, uint);
|
||||||
void switchuvm(struct proc*);
|
void switchuvm(struct proc*);
|
||||||
void switchkvm(void);
|
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
|
// number of elements in fixed-size array
|
||||||
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
|
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
|
|
2
kalloc.c
2
kalloc.c
|
@ -27,7 +27,7 @@ kinit(void)
|
||||||
|
|
||||||
initlock(&kmem.lock, "kmem");
|
initlock(&kmem.lock, "kmem");
|
||||||
p = (char*)PGROUNDUP((uint)end);
|
p = (char*)PGROUNDUP((uint)end);
|
||||||
for(; p + PGSIZE - 1 < (char*)PHYSTOP; p += PGSIZE)
|
for(; p + PGSIZE <= (char*)PHYSTOP; p += PGSIZE)
|
||||||
kfree(p);
|
kfree(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
vm.c
21
vm.c
|
@ -250,16 +250,16 @@ loaduvm(pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
|
||||||
int
|
int
|
||||||
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
|
allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
|
||||||
{
|
{
|
||||||
char *a, *last, *mem;
|
char *mem;
|
||||||
|
uint a;
|
||||||
|
|
||||||
if(newsz > USERTOP)
|
if(newsz > USERTOP)
|
||||||
return 0;
|
return 0;
|
||||||
if(newsz < oldsz)
|
if(newsz < oldsz)
|
||||||
return oldsz;
|
return oldsz;
|
||||||
|
|
||||||
a = (char*)PGROUNDUP(oldsz);
|
a = PGROUNDUP(oldsz);
|
||||||
last = PGROUNDDOWN(newsz - 1);
|
for(; a < newsz; a += PGSIZE){
|
||||||
for(; a <= last; a += PGSIZE){
|
|
||||||
mem = kalloc();
|
mem = kalloc();
|
||||||
if(mem == 0){
|
if(mem == 0){
|
||||||
cprintf("allocuvm out of memory\n");
|
cprintf("allocuvm out of memory\n");
|
||||||
|
@ -267,7 +267,7 @@ allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memset(mem, 0, PGSIZE);
|
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;
|
return newsz;
|
||||||
}
|
}
|
||||||
|
@ -279,17 +279,15 @@ allocuvm(pde_t *pgdir, uint oldsz, uint newsz)
|
||||||
int
|
int
|
||||||
deallocuvm(pde_t *pgdir, uint oldsz, uint newsz)
|
deallocuvm(pde_t *pgdir, uint oldsz, uint newsz)
|
||||||
{
|
{
|
||||||
char *a, *last;
|
|
||||||
pte_t *pte;
|
pte_t *pte;
|
||||||
uint pa;
|
uint a, pa;
|
||||||
|
|
||||||
if(newsz >= oldsz)
|
if(newsz >= oldsz)
|
||||||
return oldsz;
|
return oldsz;
|
||||||
|
|
||||||
a = (char*)PGROUNDUP(newsz);
|
a = PGROUNDUP(newsz);
|
||||||
last = PGROUNDDOWN(oldsz - 1);
|
for(; a < oldsz; a += PGSIZE){
|
||||||
for(; a <= last; a += PGSIZE){
|
pte = walkpgdir(pgdir, (char*)a, 0);
|
||||||
pte = walkpgdir(pgdir, a, 0);
|
|
||||||
if(pte && (*pte & PTE_P) != 0){
|
if(pte && (*pte & PTE_P) != 0){
|
||||||
pa = PTE_ADDR(*pte);
|
pa = PTE_ADDR(*pte);
|
||||||
if(pa == 0)
|
if(pa == 0)
|
||||||
|
@ -351,7 +349,6 @@ bad:
|
||||||
|
|
||||||
// copy some data to user address va in page table pgdir.
|
// copy some data to user address va in page table pgdir.
|
||||||
// most useful when pgdir is not the current page table.
|
// 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.
|
// uva2ka ensures this only works for PTE_U pages.
|
||||||
int
|
int
|
||||||
copyout(pde_t *pgdir, uint va, void *xbuf, uint len)
|
copyout(pde_t *pgdir, uint va, void *xbuf, uint len)
|
||||||
|
|
Loading…
Reference in a new issue