Clear U bit for second stack page so that it functions as a guard page

This commit is contained in:
Frans Kaashoek 2019-07-22 15:38:08 -04:00
parent 38b430687c
commit b2e9c8eea5
3 changed files with 13 additions and 1 deletions

View file

@ -192,9 +192,10 @@ void unmappages(pagetable_t, uint64, uint64, int);
uint64 walkaddr(pagetable_t, uint64);
int copyout(pagetable_t, uint64, char *, 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();
uint64 kernelpa(uint64);
void clearpteu(pagetable_t, uint64);
// plic.c
void plicinit(void);

View file

@ -68,6 +68,7 @@ exec(char *path, char **argv)
sz = PGROUNDUP(sz);
if((sz = uvmalloc(pagetable, sz, sz + 2*PGSIZE)) == 0)
goto bad;
clearpteu(pagetable, sz-2*PGSIZE);
sp = sz;
stackbase = sp - PGSIZE;

View file

@ -436,3 +436,13 @@ kernelpa(uint64 va) {
pa = PTE2PA(*pte);
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;
}