update am with permissions
This commit is contained in:
parent
21fb1f029f
commit
87e12fb649
3
am/am.h
3
am/am.h
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue