Clear U bit for second stack page so that it functions as a guard page
This commit is contained in:
parent
38b430687c
commit
b2e9c8eea5
3 changed files with 13 additions and 1 deletions
|
@ -192,9 +192,10 @@ void unmappages(pagetable_t, uint64, uint64, int);
|
||||||
uint64 walkaddr(pagetable_t, uint64);
|
uint64 walkaddr(pagetable_t, uint64);
|
||||||
int copyout(pagetable_t, uint64, char *, uint64);
|
int copyout(pagetable_t, uint64, char *, uint64);
|
||||||
int copyin(pagetable_t, char *, uint64, uint64);
|
int copyin(pagetable_t, char *, uint64, uint64);
|
||||||
int copyinstr(pagetable_t pagetable, char *dst, uint64 srcva, uint64 max);
|
int copyinstr(pagetable_t, char *, uint64, uint64);
|
||||||
char* map_kstack();
|
char* map_kstack();
|
||||||
uint64 kernelpa(uint64);
|
uint64 kernelpa(uint64);
|
||||||
|
void clearpteu(pagetable_t, uint64);
|
||||||
|
|
||||||
// plic.c
|
// plic.c
|
||||||
void plicinit(void);
|
void plicinit(void);
|
||||||
|
|
|
@ -68,6 +68,7 @@ exec(char *path, char **argv)
|
||||||
sz = PGROUNDUP(sz);
|
sz = PGROUNDUP(sz);
|
||||||
if((sz = uvmalloc(pagetable, sz, sz + 2*PGSIZE)) == 0)
|
if((sz = uvmalloc(pagetable, sz, sz + 2*PGSIZE)) == 0)
|
||||||
goto bad;
|
goto bad;
|
||||||
|
clearpteu(pagetable, sz-2*PGSIZE);
|
||||||
sp = sz;
|
sp = sz;
|
||||||
stackbase = sp - PGSIZE;
|
stackbase = sp - PGSIZE;
|
||||||
|
|
||||||
|
|
10
kernel/vm.c
10
kernel/vm.c
|
@ -436,3 +436,13 @@ kernelpa(uint64 va) {
|
||||||
pa = PTE2PA(*pte);
|
pa = PTE2PA(*pte);
|
||||||
return pa+off;
|
return pa+off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
clearpteu(pagetable_t pagetable, uint64 va) {
|
||||||
|
pte_t *pte;
|
||||||
|
|
||||||
|
pte = walk(pagetable, va, 0);
|
||||||
|
if(pte == 0)
|
||||||
|
panic("clearpteu");
|
||||||
|
*pte &= ~PTE_U;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue