VMM - touch_page fails if out of pages

This commit is contained in:
Thomas Lovén 2017-12-27 23:30:14 +01:00
parent 59ffd9d5f5
commit acf9a43980
2 changed files with 22 additions and 7 deletions

View File

@ -52,14 +52,22 @@ int vmm_set_page(void *P4, uintptr_t addr, uintptr_t page, uint16_t flags)
int touch_page(void *P4, uintptr_t addr, uint16_t flags) int touch_page(void *P4, uintptr_t addr, uint16_t flags)
{ {
(void)flags;
if(!P4) return -1; if(!P4) return -1;
if(!P4e(P4, addr).present)
P4e(P4, addr).value = pmm_alloc() | flags | PAGE_PRESENT; if((!P4e(P4, addr).present)
if(!P3e(P4, addr).present) && (!(P4e(P4, addr).value = pmm_alloc())))
P3e(P4, addr).value = pmm_alloc() | flags | PAGE_PRESENT; return -1;
if(!P2e(P4, addr).present) P4e(P4, addr).value |= flags | PAGE_PRESENT;
P2e(P4, addr).value = pmm_alloc() | flags | PAGE_PRESENT;
if((!P3e(P4, addr).present)
&& (!(P3e(P4, addr).value = pmm_alloc())))
return -1;
P3e(P4, addr).value |= flags | PAGE_PRESENT;
if((!P2e(P4, addr).present)
&& (!(P2e(P4, addr).value = pmm_alloc())))
return -1;
P2e(P4, addr).value |= flags | PAGE_PRESENT;
return 0; return 0;
} }

View File

@ -119,6 +119,7 @@ uintptr_t pmm_alloc()
{ {
uintptr_t *pages[] = {p3, p2, p1}; uintptr_t *pages[] = {p3, p2, p1};
static int counter=0; static int counter=0;
if(counter >= 3) return 0;
return (uintptr_t)pages[counter++]; return (uintptr_t)pages[counter++];
} }
@ -146,3 +147,9 @@ TEST(touch_page_sets_flags)
ASSERT_EQ_PTR(p2[0], (uintptr_t)p1 | 0x123 | PAGE_PRESENT); ASSERT_EQ_PTR(p2[0], (uintptr_t)p1 | 0x123 | PAGE_PRESENT);
} }
TEST(touch_page_fails_if_out_of_pages)
{
pmm_alloc();
int retval = touch_page(p4, 0, 0);
ASSERT_NEQ_INT(retval, 0);
}