forked from Bananymous/banan-os
Kernel: General allocator takes first valid vaddr as parameter
This commit is contained in:
parent
f83ae1e9c6
commit
714305ef56
|
@ -14,7 +14,7 @@ namespace Kernel
|
||||||
BAN_NON_MOVABLE(GeneralAllocator);
|
BAN_NON_MOVABLE(GeneralAllocator);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> create(PageTable&);
|
static BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> create(PageTable&, vaddr_t first_vaddr);
|
||||||
~GeneralAllocator();
|
~GeneralAllocator();
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> clone(PageTable&);
|
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> clone(PageTable&);
|
||||||
|
@ -23,7 +23,7 @@ namespace Kernel
|
||||||
bool deallocate(vaddr_t);
|
bool deallocate(vaddr_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GeneralAllocator(PageTable&);
|
GeneralAllocator(PageTable&, vaddr_t first_vaddr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Allocation
|
struct Allocation
|
||||||
|
@ -33,6 +33,7 @@ namespace Kernel
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const vaddr_t m_first_vaddr;
|
||||||
PageTable& m_page_table;
|
PageTable& m_page_table;
|
||||||
BAN::LinkedList<Allocation> m_allocations;
|
BAN::LinkedList<Allocation> m_allocations;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,16 +3,17 @@
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
{
|
{
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> GeneralAllocator::create(PageTable& page_table)
|
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> GeneralAllocator::create(PageTable& page_table, vaddr_t first_vaddr)
|
||||||
{
|
{
|
||||||
auto* allocator = new GeneralAllocator(page_table);
|
auto* allocator = new GeneralAllocator(page_table, first_vaddr);
|
||||||
if (allocator == nullptr)
|
if (allocator == nullptr)
|
||||||
return BAN::Error::from_errno(ENOMEM);
|
return BAN::Error::from_errno(ENOMEM);
|
||||||
return BAN::UniqPtr<GeneralAllocator>::adopt(allocator);
|
return BAN::UniqPtr<GeneralAllocator>::adopt(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneralAllocator::GeneralAllocator(PageTable& page_table)
|
GeneralAllocator::GeneralAllocator(PageTable& page_table, vaddr_t first_vaddr)
|
||||||
: m_page_table(page_table)
|
: m_page_table(page_table)
|
||||||
|
, m_first_vaddr(first_vaddr)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
GeneralAllocator::~GeneralAllocator()
|
GeneralAllocator::~GeneralAllocator()
|
||||||
|
@ -41,7 +42,11 @@ namespace Kernel
|
||||||
allocation.pages[i] = paddr;
|
allocation.pages[i] = paddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocation.address = m_page_table.get_free_contiguous_pages(needed_pages);
|
m_page_table.lock();
|
||||||
|
|
||||||
|
allocation.address = m_page_table.get_free_contiguous_pages(needed_pages, m_first_vaddr);
|
||||||
|
ASSERT(allocation.address);
|
||||||
|
|
||||||
for (size_t i = 0; i < needed_pages; i++)
|
for (size_t i = 0; i < needed_pages; i++)
|
||||||
{
|
{
|
||||||
vaddr_t vaddr = allocation.address + i * PAGE_SIZE;
|
vaddr_t vaddr = allocation.address + i * PAGE_SIZE;
|
||||||
|
@ -49,6 +54,8 @@ namespace Kernel
|
||||||
m_page_table.invalidate(vaddr);
|
m_page_table.invalidate(vaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_page_table.unlock();
|
||||||
|
|
||||||
MUST(m_allocations.push_back(BAN::move(allocation)));
|
MUST(m_allocations.push_back(BAN::move(allocation)));
|
||||||
return allocation.address;
|
return allocation.address;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +81,7 @@ namespace Kernel
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> GeneralAllocator::clone(PageTable& new_page_table)
|
BAN::ErrorOr<BAN::UniqPtr<GeneralAllocator>> GeneralAllocator::clone(PageTable& new_page_table)
|
||||||
{
|
{
|
||||||
auto allocator = TRY(GeneralAllocator::create(new_page_table));
|
auto allocator = TRY(GeneralAllocator::create(new_page_table, m_first_vaddr));
|
||||||
|
|
||||||
m_page_table.lock();
|
m_page_table.lock();
|
||||||
|
|
||||||
|
|
|
@ -791,7 +791,7 @@ namespace Kernel
|
||||||
LockGuard _(m_lock);
|
LockGuard _(m_lock);
|
||||||
|
|
||||||
if (!m_general_allocator)
|
if (!m_general_allocator)
|
||||||
m_general_allocator = TRY(GeneralAllocator::create(page_table()));
|
m_general_allocator = TRY(GeneralAllocator::create(page_table(), 0x400000));
|
||||||
|
|
||||||
address = m_general_allocator->allocate(bytes);
|
address = m_general_allocator->allocate(bytes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue