fix: kernel and desktop bug fixes
This commit is contained in:
@@ -243,21 +243,14 @@ namespace Sched {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate kernel stack (used during syscalls and interrupts)
|
||||
void* firstPage = Memory::g_pfa->AllocateZeroed();
|
||||
if (firstPage == nullptr) {
|
||||
Kt::KernelLogStream(Kt::ERROR, "Sched") << "Out of memory for kernel stack";
|
||||
Memory::VMM::Paging::FreeUserHalf(pml4Phys);
|
||||
Memory::g_pfa->Free((void*)Memory::HHDM(pml4Phys));
|
||||
schedLock.Acquire();
|
||||
processTable[slot].state = ProcessState::Free;
|
||||
schedLock.Release();
|
||||
return -1;
|
||||
}
|
||||
void* stackMem = Memory::g_pfa->ReallocConsecutive(firstPage, StackPages);
|
||||
// Allocate kernel stack (used during syscalls and interrupts).
|
||||
// ReallocConsecutive(nullptr, n) returns an n-page contiguous span;
|
||||
// the previous code allocated a throwaway page first and asked
|
||||
// ReallocConsecutive to migrate from it, which copied + freed the
|
||||
// throwaway for no benefit and double-counted failure paths.
|
||||
void* stackMem = Memory::g_pfa->ReallocConsecutive(nullptr, StackPages);
|
||||
if (stackMem == nullptr) {
|
||||
Kt::KernelLogStream(Kt::ERROR, "Sched") << "Failed to allocate contiguous kernel stack";
|
||||
Memory::g_pfa->Free(firstPage);
|
||||
Memory::VMM::Paging::FreeUserHalf(pml4Phys);
|
||||
Memory::g_pfa->Free((void*)Memory::HHDM(pml4Phys));
|
||||
schedLock.Acquire();
|
||||
@@ -265,6 +258,7 @@ namespace Sched {
|
||||
schedLock.Release();
|
||||
return -1;
|
||||
}
|
||||
memset(stackMem, 0, StackPages * 0x1000);
|
||||
|
||||
uint8_t* kernelStackBase = (uint8_t*)stackMem;
|
||||
uint64_t kernelStackTop = (uint64_t)kernelStackBase + StackSize;
|
||||
|
||||
Reference in New Issue
Block a user