fix: memory and other improvements
This commit is contained in:
@@ -18,7 +18,7 @@ namespace Montauk {
|
||||
uint64_t numPages;
|
||||
};
|
||||
|
||||
static constexpr int MaxHeapAllocs = 128;
|
||||
static constexpr int MaxHeapAllocs = 512;
|
||||
|
||||
static HeapAlloc g_heapAllocs[Sched::MaxProcesses][MaxHeapAllocs];
|
||||
static int g_heapAllocCount[Sched::MaxProcesses];
|
||||
@@ -43,6 +43,7 @@ namespace Montauk {
|
||||
uint64_t userVa = proc->heapNext;
|
||||
uint64_t numPages = size / 0x1000;
|
||||
|
||||
// Allocate physical pages and map them into the process
|
||||
for (uint64_t i = 0; i < numPages; i++) {
|
||||
void* page = Memory::g_pfa->AllocateZeroed();
|
||||
if (page == nullptr) return 0;
|
||||
@@ -90,7 +91,7 @@ namespace Montauk {
|
||||
uint64_t va = g_heapAllocs[slot][idx].va;
|
||||
uint64_t numPages = g_heapAllocs[slot][idx].numPages;
|
||||
|
||||
// Free each physical page and unmap the virtual address
|
||||
// Free physical pages in bulk and unmap virtual addresses
|
||||
for (uint64_t i = 0; i < numPages; i++) {
|
||||
uint64_t pageVa = va + i * 0x1000;
|
||||
uint64_t physAddr = Memory::VMM::Paging::GetPhysAddr(proc->pml4Phys, pageVa);
|
||||
@@ -100,7 +101,7 @@ namespace Montauk {
|
||||
Memory::VMM::Paging::UnmapUserIn(proc->pml4Phys, pageVa);
|
||||
}
|
||||
|
||||
if (slot >= 0) Sched::g_allocatedPages[slot] -= numPages;
|
||||
Sched::g_allocatedPages[slot] -= numPages;
|
||||
|
||||
// Remove tracking entry by swapping with the last element
|
||||
g_heapAllocs[slot][idx] = g_heapAllocs[slot][g_heapAllocCount[slot] - 1];
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Sched {
|
||||
static constexpr int MaxProcesses = 256;
|
||||
static constexpr uint64_t StackPages = 4; // 16 KiB kernel stack per process
|
||||
static constexpr uint64_t StackSize = StackPages * 0x1000;
|
||||
static constexpr uint64_t UserStackPages = 4; // 16 KiB user stack
|
||||
static constexpr uint64_t UserStackPages = 8; // 32 KiB user stack
|
||||
static constexpr uint64_t UserStackSize = UserStackPages * 0x1000;
|
||||
static constexpr uint64_t UserStackTop = 0x7FFFFFF000ULL; // User stack top VA
|
||||
static constexpr uint64_t UserHeapBase = 0x40000000ULL; // User heap start VA
|
||||
|
||||
Reference in New Issue
Block a user