mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
Removed the frame allocation logic from page_manager and replaced it
with using an instance of frame_allocator instead. This had several
major ripple effects:
- memory_initalize() had to change to support this new world
- Where to map used blocks is now passed as a flag, since blocks don't
track their virtual address anymore
- Instead of the complicated "find N contiguous pages that can be
mapped in with one page table", we now just have the bootloader give
us some (currently 64) pages to use both for tables and scratch
space.
- frame_allocator initialization was split into two steps to allow
mapping used blocks before std::move()ing them over
52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#include "kutil/frame_allocator.h"
|
|
#include "kutil/heap_manager.h"
|
|
#include "kutil/memory.h"
|
|
#include "catch.hpp"
|
|
|
|
using namespace kutil;
|
|
|
|
extern void * grow_callback(void*, size_t);
|
|
extern void free_memory();
|
|
|
|
const size_t max_block = 1ull << 36;
|
|
const size_t start = max_block;
|
|
const size_t GB = 1ull << 30;
|
|
|
|
TEST_CASE( "Frame allocator tests", "[memory frame]" )
|
|
{
|
|
heap_manager mm(nullptr, grow_callback);
|
|
kutil::setup::set_heap(&mm);
|
|
|
|
frame_block_list free;
|
|
frame_block_list used;
|
|
frame_block_list cache;
|
|
|
|
auto *f = new frame_block_list::item_type;
|
|
f->address = 0x1000;
|
|
f->count = 1;
|
|
free.sorted_insert(f);
|
|
|
|
f = new frame_block_list::item_type;
|
|
f->address = 0x2000;
|
|
f->count = 1;
|
|
free.sorted_insert(f);
|
|
|
|
frame_allocator fa(std::move(cache));
|
|
fa.init(std::move(free), std::move(used));
|
|
|
|
uintptr_t a = 0;
|
|
size_t c = fa.allocate(2, &a);
|
|
CHECK( a == 0x1000 );
|
|
CHECK( c == 2 );
|
|
|
|
fa.free(a, 2);
|
|
a = 0;
|
|
|
|
c = fa.allocate(2, &a);
|
|
CHECK( a == 0x1000 );
|
|
CHECK( c == 2 );
|
|
|
|
kutil::setup::set_heap(nullptr);
|
|
free_memory();
|
|
}
|