PMM -- Make sure stuff works even with V2P and P2V
This commit is contained in:
parent
acf9a43980
commit
f78500d603
@ -13,6 +13,6 @@ uintptr_t pmm_alloc()
|
|||||||
{
|
{
|
||||||
uintptr_t page = first;
|
uintptr_t page = first;
|
||||||
first = page?*(uintptr_t *)page:0;
|
first = page?*(uintptr_t *)page:0;
|
||||||
page = (uintptr_t)V2P(page);
|
page = (uintptr_t)(page?V2P(page):0);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#undef P2V
|
#undef P2V
|
||||||
#define P2V(addr) (void *)((uintptr_t)(addr))
|
#define P2V(addr) ((void *)((uintptr_t)(addr)+1))
|
||||||
#undef V2P
|
#undef V2P
|
||||||
#define V2P(addr) (void *)((uintptr_t)(addr))
|
#define V2P(addr) ((uintptr_t)(addr)-1)
|
||||||
#include "pmm.c"
|
#include "pmm.c"
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -14,9 +14,9 @@ struct {
|
|||||||
|
|
||||||
TEST(alloc_returns_freed_page)
|
TEST(alloc_returns_freed_page)
|
||||||
{
|
{
|
||||||
pmm_free((uintptr_t)&mem[0]);
|
pmm_free(V2P(&mem[0]));
|
||||||
uintptr_t a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
ASSERT_EQ_PTR(a, &mem[0]);
|
ASSERT_EQ_PTR(a, V2P(&mem[0]));
|
||||||
}
|
}
|
||||||
TEST(alloc_returns_0_if_no_free_pages)
|
TEST(alloc_returns_0_if_no_free_pages)
|
||||||
{
|
{
|
||||||
@ -25,7 +25,7 @@ TEST(alloc_returns_0_if_no_free_pages)
|
|||||||
}
|
}
|
||||||
TEST(alloc_zero_after_all_free_pages)
|
TEST(alloc_zero_after_all_free_pages)
|
||||||
{
|
{
|
||||||
pmm_free((uintptr_t)&mem[0]);
|
pmm_free(V2P(&mem[0]));
|
||||||
pmm_alloc();
|
pmm_alloc();
|
||||||
uintptr_t a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
ASSERT_EQ_PTR(a, 0);
|
ASSERT_EQ_PTR(a, 0);
|
||||||
@ -33,24 +33,24 @@ TEST(alloc_zero_after_all_free_pages)
|
|||||||
|
|
||||||
TEST(alloc_two_pages___first_page_is_not_zero)
|
TEST(alloc_two_pages___first_page_is_not_zero)
|
||||||
{
|
{
|
||||||
pmm_free((uintptr_t)&mem[0]);
|
pmm_free(V2P(&mem[0]));
|
||||||
pmm_free((uintptr_t)&mem[1]);
|
pmm_free(V2P(&mem[1]));
|
||||||
uintptr_t a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
pmm_alloc();
|
pmm_alloc();
|
||||||
ASSERT_NEQ_PTR(a, 0);
|
ASSERT_NEQ_PTR(a, 0);
|
||||||
}
|
}
|
||||||
TEST(alloc_two_pages___second_page_is_not_zero)
|
TEST(alloc_two_pages___second_page_is_not_zero)
|
||||||
{
|
{
|
||||||
pmm_free((uintptr_t)&mem[0]);
|
pmm_free(V2P(&mem[0]));
|
||||||
pmm_free((uintptr_t)&mem[1]);
|
pmm_free(V2P(&mem[1]));
|
||||||
pmm_alloc();
|
pmm_alloc();
|
||||||
uintptr_t a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
ASSERT_NEQ_PTR(a, 0);
|
ASSERT_NEQ_PTR(a, 0);
|
||||||
}
|
}
|
||||||
TEST(alloc_two_pages___doesnt_return_same_page_twice)
|
TEST(alloc_two_pages___doesnt_return_same_page_twice)
|
||||||
{
|
{
|
||||||
pmm_free((uintptr_t)&mem[0]);
|
pmm_free(V2P(&mem[0]));
|
||||||
pmm_free((uintptr_t)&mem[1]);
|
pmm_free(V2P(&mem[1]));
|
||||||
uintptr_t a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
uintptr_t b = pmm_alloc();
|
uintptr_t b = pmm_alloc();
|
||||||
ASSERT_NEQ_PTR(a, b);
|
ASSERT_NEQ_PTR(a, b);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user