update am with permissions

This commit is contained in:
Yanyan Jiang 2018-02-15 04:30:40 -05:00
parent 21fb1f029f
commit 87e12fb649
2 changed files with 7 additions and 3 deletions

View File

@ -78,6 +78,9 @@ int _istatus(int enable);
// [3] Protection Extension (PTE)
// =======================================================================
#define _PG_R 1
#define _PG_W 2
#define _PG_X 4
void _pte_init(void*(*palloc)(), void (*pfree)(void*));
void _protect(_Protect *p);
void _release(_Protect *p);

View File

@ -70,15 +70,16 @@ void _switch(_Protect *p) {
set_cr3(p->ptr);
}
void _map(_Protect *p, void *va, void *pa) {
void _map(_Protect *p, void *va, void *pa, uint8_t mode) {
PDE *pt = (PDE*)p->ptr;
PDE *pde = &pt[PDX(va)];
uint32_t wflag = (mode & _PG_W) ? PTE_W : 0;
if (!(*pde & PTE_P)) {
*pde = PTE_P | PTE_W | PTE_U | reinterpret_cast<uint32_t>(palloc_f());
*pde = PTE_P | wflag | PTE_U | reinterpret_cast<uint32_t>(palloc_f());
}
PTE *pte = &((PTE*)PTE_ADDR(*pde))[PTX(va)];
if (!(*pte & PTE_P)) {
*pte = PTE_P | PTE_W | PTE_U | reinterpret_cast<uint32_t>(pa);
*pte = PTE_P | wflag | PTE_U | reinterpret_cast<uint32_t>(pa);
}
}