PMM -- calloc function for getting cleared pages

This commit is contained in:
Thomas Lovén 2018-01-04 00:36:59 +01:00
parent 5dc4e27392
commit 3a4136c225
4 changed files with 13 additions and 5 deletions

View File

@ -33,6 +33,7 @@ size_t strlen(const char *s);
void pmm_free(uintptr_t page);
uintptr_t pmm_alloc();
uintptr_t pmm_calloc();
uintptr_t vmm_get_page(void *P4, uintptr_t addr);
int vmm_set_page(void *P4, uintptr_t addr, uintptr_t page, uint16_t flags);

View File

@ -16,3 +16,10 @@ uintptr_t pmm_alloc()
page = (uintptr_t)(page?V2P(page):0);
return page;
}
uintptr_t pmm_calloc()
{
uintptr_t page = pmm_alloc();
memset(P2V(page), 0, 0x1000);
return page;
}

View File

@ -77,19 +77,19 @@ int touch_page(void *P4, uintptr_t addr, uint16_t flags)
flags ^= PAGE_HUGE*huge;
if((!P4e(P4, addr).present)
&& (!(P4e(P4, addr).value = pmm_alloc())))
&& (!(P4e(P4, addr).value = pmm_calloc())))
return -1;
P4e(P4, addr).value |= flags | PAGE_PRESENT;
if((!P3e(P4, addr).present)
&& (!(P3e(P4, addr).value = pmm_alloc())))
&& (!(P3e(P4, addr).value = pmm_calloc())))
return -1;
P3e(P4, addr).value |= flags | PAGE_PRESENT;
if(huge) return 0;
if((!P2e(P4, addr).present)
&& (!(P2e(P4, addr).value = pmm_alloc())))
&& (!(P2e(P4, addr).value = pmm_calloc())))
return -1;
P2e(P4, addr).value |= flags | PAGE_PRESENT;

View File

@ -119,7 +119,7 @@ TEST(set_page_does_not_overwrite_4kb_pages_with_2mb)
ASSERT_NEQ_INT(retval, 0);
}
uintptr_t pmm_alloc()
uintptr_t pmm_calloc()
{
uintptr_t *pages[] = {p3, p2, p1};
static int counter=0;
@ -153,7 +153,7 @@ TEST(touch_page_sets_flags)
}
TEST(touch_page_fails_if_out_of_pages)
{
pmm_alloc();
pmm_calloc();
int retval = touch_page(p4, 0, 0);
ASSERT_NEQ_INT(retval, 0);
}