mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-22 20:51:42 +00:00
.github
.vscode
Architecture
Core
Crash
Driver
Interrupts
Memory
HeapAllocators
Memory.cpp
PageMapIndexer.cpp
PhysicalMemoryManager.cpp
StackGuard.cpp
Tracker.cpp
VirtualMemoryManager.cpp
Video
CPU.cpp
Debugger.cpp
Disk.cpp
Lock.cpp
PeripheralComponentInterconnect.cpp
Power.cpp
README.md
Random.cpp
StackGuard.c
Symbols.cpp
SystemManagementBIOS.cpp
Time.cpp
Timer.cpp
UndefinedBehaviorSanitization.c
UniversalAsynchronousReceiverTransmitter.cpp
crashhandler.hpp
smbios.hpp
ubsan.h
Execute
FileSystem
Library
Profiling
Recovery
SystemCalls
Tasking
include
.gitignore
DAPI.hpp
Doxyfile
Fex.hpp
KConfig.cpp
KThread.cpp
Kernel.cpp
LICENSE
Makefile
README.md
dump.sh
kernel.h
syscalls.h
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#include <memory.hpp>
|
|
#include <debug.h>
|
|
|
|
namespace Memory
|
|
{
|
|
uint64_t Tracker::GetAllocatedMemorySize()
|
|
{
|
|
uint64_t Size = 0;
|
|
foreach (auto var in AllocatedPagesList)
|
|
Size += var.PageCount;
|
|
return FROM_PAGES(Size);
|
|
}
|
|
|
|
void *Tracker::RequestPages(uint64_t Count)
|
|
{
|
|
void *Address = KernelAllocator.RequestPages(Count);
|
|
for (uint64_t i = 0; i < Count; i++)
|
|
Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW | Memory::PTFlag::US);
|
|
AllocatedPagesList.push_back({Address, Count});
|
|
return Address;
|
|
}
|
|
|
|
void Tracker::FreePages(void *Address, uint64_t Count)
|
|
{
|
|
KernelAllocator.FreePages(Address, Count);
|
|
for (uint64_t i = 0; i < Count; i++)
|
|
Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)Address + (i * PAGE_SIZE)), (void *)((uint64_t)Address + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
|
|
|
for (uint64_t i = 0; i < AllocatedPagesList.size(); i++)
|
|
if (AllocatedPagesList[i].Address == Address)
|
|
{
|
|
AllocatedPagesList.remove(i);
|
|
break;
|
|
}
|
|
}
|
|
|
|
Tracker::Tracker(PageTable4 *PageTable)
|
|
{
|
|
if (PageTable)
|
|
this->PageTable = PageTable;
|
|
else
|
|
this->PageTable = (PageTable4 *)CPU::x64::readcr3().raw;
|
|
debug("Tracker initialized.");
|
|
}
|
|
|
|
Tracker::~Tracker()
|
|
{
|
|
foreach (auto var in AllocatedPagesList)
|
|
{
|
|
KernelAllocator.FreePages(var.Address, var.PageCount);
|
|
for (uint64_t i = 0; i < var.PageCount; i++)
|
|
Memory::Virtual(this->PageTable).Remap((void *)((uint64_t)var.Address + (i * PAGE_SIZE)), (void *)((uint64_t)var.Address + (i * PAGE_SIZE)), Memory::PTFlag::RW);
|
|
}
|
|
debug("Tracker destroyed.");
|
|
}
|
|
}
|