Updated memory manager

This commit is contained in:
Alex 2022-12-26 08:40:09 +02:00
parent 98d58cf655
commit 18f05c6d83
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 34 additions and 0 deletions

View File

@ -11,6 +11,38 @@ namespace Memory
return FROM_PAGES(Size);
}
bool MemMgr::Add(void *Address, size_t Count)
{
for (size_t i = 0; i < AllocatedPagesList.size(); i++)
{
if (AllocatedPagesList[i].Address == Address)
{
error("Address already exists!");
return false;
}
if ((uintptr_t)Address < (uintptr_t)AllocatedPagesList[i].Address)
{
if ((uintptr_t)Address + (Count * PAGE_SIZE) > (uintptr_t)AllocatedPagesList[i].Address)
{
error("Address intersects with an allocated page!");
return false;
}
}
else
{
if ((uintptr_t)AllocatedPagesList[i].Address + (AllocatedPagesList[i].PageCount * PAGE_SIZE) > (uintptr_t)Address)
{
error("Address intersects with an allocated page!");
return false;
}
}
}
AllocatedPagesList.push_back({Address, Count});
return true;
}
void *MemMgr::RequestPages(size_t Count)
{
void *Address = KernelAllocator.RequestPages(Count);

View File

@ -648,6 +648,8 @@ namespace Memory
public:
uint64_t GetAllocatedMemorySize();
bool Add(void *Address, size_t Count);
void *RequestPages(size_t Count);
void FreePages(void *Address, size_t Count);