fix: fix heap regression

This commit is contained in:
2026-02-27 23:51:46 +01:00
parent bd16b9afd1
commit ca85553eec
3 changed files with 34 additions and 2 deletions
+19
View File
@@ -61,6 +61,25 @@ namespace Zenith {
return userVa;
}
// Free all heap allocations for a process slot (called on process exit)
static void CleanupHeapForSlot(int slot, uint64_t pml4Phys) {
if (slot < 0 || slot >= Sched::MaxProcesses) return;
for (int i = 0; i < g_heapAllocCount[slot]; i++) {
uint64_t va = g_heapAllocs[slot][i].va;
uint64_t numPages = g_heapAllocs[slot][i].numPages;
for (uint64_t p = 0; p < numPages; p++) {
uint64_t pageVa = va + p * 0x1000;
uint64_t physAddr = Memory::VMM::Paging::GetPhysAddr(pml4Phys, pageVa);
if (physAddr != 0) {
Memory::g_pfa->Free((void*)Memory::HHDM(physAddr));
}
Memory::VMM::Paging::UnmapUserIn(pml4Phys, pageVa);
}
}
g_heapAllocCount[slot] = 0;
}
static void Sys_Free(uint64_t addr) {
auto* proc = Sched::GetCurrentProcessPtr();
if (proc == nullptr) return;