PMM -- finishing up and changing names, types
This commit is contained in:
parent
28916257f1
commit
1a7852de4d
@ -30,4 +30,7 @@ void *memset(void *s, int c, size_t n);
|
|||||||
void *memmove(void *dest, const void *src, size_t n);
|
void *memmove(void *dest, const void *src, size_t n);
|
||||||
int memcmp(const void *s1, const void *s2, size_t n);
|
int memcmp(const void *s1, const void *s2, size_t n);
|
||||||
size_t strlen(const char *s);
|
size_t strlen(const char *s);
|
||||||
|
|
||||||
|
void pmm_free(uintptr_t page);
|
||||||
|
uintptr_t pmm_alloc();
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
uintptr_t *first = 0;
|
uintptr_t first = 0;
|
||||||
|
|
||||||
void pmm_free(void *c)
|
void pmm_free(uintptr_t page)
|
||||||
{
|
{
|
||||||
c = (void *)P2V(c);
|
page = (uintptr_t)P2V(page);
|
||||||
*(uintptr_t **)c = first;
|
*(uintptr_t *)page = first;
|
||||||
first = c;
|
first = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pmm_alloc()
|
uintptr_t pmm_alloc()
|
||||||
{
|
{
|
||||||
void *c = first;
|
uintptr_t page = first;
|
||||||
first = c?*(uintptr_t **)c:0;
|
first = page?*(uintptr_t *)page:0;
|
||||||
c = (void *)V2P(c);
|
page = (uintptr_t)V2P(page);
|
||||||
return c;
|
return page;
|
||||||
}
|
}
|
||||||
|
@ -14,44 +14,44 @@ struct {
|
|||||||
|
|
||||||
TEST(alloc_returns_freed_page)
|
TEST(alloc_returns_freed_page)
|
||||||
{
|
{
|
||||||
pmm_free(&mem[0]);
|
pmm_free((uintptr_t)&mem[0]);
|
||||||
void *a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
ASSERT_EQ_PTR(a, &mem[0]);
|
ASSERT_EQ_PTR(a, &mem[0]);
|
||||||
}
|
}
|
||||||
TEST(alloc_returns_0_if_no_free_pages)
|
TEST(alloc_returns_0_if_no_free_pages)
|
||||||
{
|
{
|
||||||
void *a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
ASSERT_EQ_PTR(a, 0);
|
ASSERT_EQ_PTR(a, 0);
|
||||||
}
|
}
|
||||||
TEST(alloc_zero_after_all_free_pages)
|
TEST(alloc_zero_after_all_free_pages)
|
||||||
{
|
{
|
||||||
pmm_free(&mem[0]);
|
pmm_free((uintptr_t)&mem[0]);
|
||||||
pmm_alloc();
|
pmm_alloc();
|
||||||
void *a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
ASSERT_EQ_PTR(a, 0);
|
ASSERT_EQ_PTR(a, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(alloc_two_pages___first_page_is_not_zero)
|
TEST(alloc_two_pages___first_page_is_not_zero)
|
||||||
{
|
{
|
||||||
pmm_free(&mem[0]);
|
pmm_free((uintptr_t)&mem[0]);
|
||||||
pmm_free(&mem[1]);
|
pmm_free((uintptr_t)&mem[1]);
|
||||||
void *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(&mem[0]);
|
pmm_free((uintptr_t)&mem[0]);
|
||||||
pmm_free(&mem[1]);
|
pmm_free((uintptr_t)&mem[1]);
|
||||||
pmm_alloc();
|
pmm_alloc();
|
||||||
void *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(&mem[0]);
|
pmm_free((uintptr_t)&mem[0]);
|
||||||
pmm_free(&mem[1]);
|
pmm_free((uintptr_t)&mem[1]);
|
||||||
void *a = pmm_alloc();
|
uintptr_t a = pmm_alloc();
|
||||||
void *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