summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources/SMPManager.cxx
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-06-18 10:39:00 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-06-18 10:43:43 +0200
commit596268586bb4c8248a8ec106b8cdea12b9ab926a (patch)
tree5fdad88c44af284271ffac1ad3fefcbfe0dac4a6 /Kernel/Sources/SMPManager.cxx
parent8051ad2bd4af1f226a9751288957ee6af7e787d7 (diff)
IMP: TLS syscall, serial write syscall.
FIX: SMP manager writes to stack frame directly, check if we also want to free the stack. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources/SMPManager.cxx')
-rw-r--r--Kernel/Sources/SMPManager.cxx44
1 files changed, 17 insertions, 27 deletions
diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx
index 5002e880..149b1334 100644
--- a/Kernel/Sources/SMPManager.cxx
+++ b/Kernel/Sources/SMPManager.cxx
@@ -85,36 +85,26 @@ namespace NewOS
bool HardwareThread::Switch(HAL::StackFramePtr stack)
{
if (!rt_check_stack(stack))
- return false;
-
- if (!fStack)
- {
- fStack = stack;
- }
- else
{
- /// Keep the arguments, switch the base pointer, stack pointer
- /// fs and gs registers.
- fStack->Rbp = stack->Rbp;
- fStack->Rsp = stack->Rsp;
- fStack->Fs = stack->Fs;
- fStack->Gs = stack->Gs;
-
- // save global registers.
-
- fStack->R15 = stack->R15;
- fStack->R14 = stack->R14;
+ /// provide 'nullptr' to free the stack frame.
+ if (stack == nullptr)
+ {
+ delete fStack;
+ fStack = nullptr;
- fStack->R13 = stack->R13;
- fStack->R12 = stack->R12;
- fStack->R11 = stack->R11;
+ return true;
+ }
- fStack->R10 = stack->R10;
- fStack->R9 = stack->R9;
- fStack->R8 = stack->R8;
+ return false;
+ }
- fStack->Rcx = this->fID;
+ if (fStack)
+ {
+ delete fStack;
+ fStack = nullptr;
}
+
+ fStack = stack;
rt_do_context_switch(fStack);
@@ -146,7 +136,7 @@ namespace NewOS
HAL::StackFramePtr SMPManager::Leak() noexcept
{
if (fThreadList[fCurrentThread].Leak() &&
- ProcessHelper::GetCurrentPID() ==
+ ProcessHelper::TheCurrentPID() ==
fThreadList[fCurrentThread].Leak().Leak()->fPID)
return fThreadList[fCurrentThread].Leak().Leak()->fStack;
@@ -189,7 +179,7 @@ namespace NewOS
fThreadList[idx].Leak().Leak()->Switch(fThreadList[idx].Leak().Leak()->fStack);
- fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::GetCurrentPID();
+ fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::TheCurrentPID();
fThreadList[idx].Leak().Leak()->Busy(false);