diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-11-03 11:47:03 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-11-03 11:47:03 +0100 |
| commit | 140d983c55e0f9a2d1829c997d7751f234703fb6 (patch) | |
| tree | fdf017bbb0f497bd7c292af136cf6108c4e8e610 /dev/ZKAKit/src/UserProcessScheduler.cc | |
| parent | fc3abbd067a4cc0d3b502afc8af5bc1e77e2d2fc (diff) | |
FIX: User Scheduler, fix process creation.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/src/UserProcessScheduler.cc')
| -rw-r--r-- | dev/ZKAKit/src/UserProcessScheduler.cc | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc index b2fed635..67eac095 100644 --- a/dev/ZKAKit/src/UserProcessScheduler.cc +++ b/dev/ZKAKit/src/UserProcessScheduler.cc @@ -32,7 +32,7 @@ namespace Kernel /// @brief Exit Code global variable. /***********************************************************************************/ - STATIC UInt32 kLastExitCode = 0U; + UInt32 kLastExitCode = 0U; /***********************************************************************************/ /// @brief User Process scheduler global and external reference of thread scheduler. @@ -61,14 +61,7 @@ namespace Kernel Void UserProcess::Crash() { - if (this->Status != ProcessStatusKind::kRunning) - return; - - if (*this->Name != 0) - { - kcout << this->Name << ": crashed, error id: " << number(kErrorProcessFault) << endl; - } - + kcout << this->Name << ": crashed, error id: " << number(kErrorProcessFault) << endl; this->Exit(kErrorProcessFault); } @@ -78,7 +71,7 @@ namespace Kernel UserProcess::operator bool() { - return this->Status != ProcessStatusKind::kDead; + return this->Status == ProcessStatusKind::kRunning && this->Image != nullptr; } /***********************************************************************************/ @@ -319,13 +312,25 @@ namespace Kernel SizeT UserProcessScheduler::Add(UserProcess process) { - if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) + kcout << "Creating process: " << process.Name << ", prevous process count: " << number(mTeam.mProcessList.Count()) << endl; + + if (mTeam.mProcessList.Count() >= kSchedProcessLimitPerTeam) return kErrorInvalidData; + kcout << "Create vm_register of: " << process.Name << endl; + #ifdef __ZKA_AMD64__ process.VMRegister = reinterpret_cast<UIntPtr>(mm_new_heap(sizeof(PDE), No, Yes)); + + if (!process.VMRegister) + { + process.Crash(); + return kErrorProcessFault; + } #endif // __ZKA_AMD64__ + kcout << "Create stack_frame of: " << process.Name << endl; + process.StackFrame = reinterpret_cast<HAL::StackFramePtr>(mm_new_heap(sizeof(HAL::StackFrame), Yes, Yes)); if (!process.StackFrame) @@ -334,18 +339,24 @@ namespace Kernel return kErrorProcessFault; } + kcout << "Create delegate if DLL for: " << process.Name << endl; + // Create heap according to type of process. if (process.Kind == UserProcess::kExectuableDLLKind) { process.PefDLLDelegate = rtl_init_dll(&process); } + kcout << "Validate image of: " << process.Name << endl; + if (!process.Image) { process.Crash(); return kErrorProcessFault; } + kcout << "Validate stack reserve of: " << process.Name << endl; + // Get preferred stack size by app. const auto kMaxStackSize = process.StackSize; process.StackReserve = reinterpret_cast<UInt8*>(mm_new_heap(sizeof(UInt8) * kMaxStackSize, Yes, Yes)); @@ -356,13 +367,13 @@ namespace Kernel return kErrorProcessFault; } - ++mTeam.mProcessAmount; - - process.ProcessId = mTeam.mProcessAmount; - process.Status = ProcessStatusKind::kStarting; + process.ProcessId = 0UL; + process.Status = ProcessStatusKind::kRunning; mTeam.AsArray()[process.ProcessId] = process; + kcout << "Create process: " << process.Name << endl; + return process.ProcessId; } @@ -372,6 +383,7 @@ namespace Kernel UserProcessScheduler& UserProcessScheduler::The() { + kcout << "Return user scheduler object.\r"; return kProcessScheduler; } @@ -387,11 +399,10 @@ namespace Kernel const Bool UserProcessScheduler::Remove(ProcessID process_id) { // check if process is within range. - if (process_id > mTeam.mProcessAmount) + if (process_id > mTeam.mProcessList.Count()) return No; mTeam.AsArray()[process_id].Status = ProcessStatusKind::kDead; - --mTeam.mProcessAmount; return Yes; } @@ -424,13 +435,13 @@ namespace Kernel SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. - if (mTeam.mProcessAmount == 0) + if (mTeam.mProcessList.Empty()) { kcout << "UserProcessScheduler::Run(): This team doesn't have any process!\r"; return 0; } - kcout << "UserProcessScheduler::Run(): This team has process # " << number(mTeam.mProcessAmount) << endl; + kcout << "UserProcessScheduler::Run(): This team has a process capacity of: " << number(mTeam.mProcessList.Capacity()) << endl; for (; process_index < mTeam.AsArray().Capacity(); ++process_index) { @@ -441,9 +452,6 @@ namespace Kernel { process.PTime = static_cast<Int32>(process.Affinity); - UserProcessScheduler::The().GetCurrentProcess().Leak().Status = ProcessStatusKind::kFrozen; - UserProcessScheduler::The().GetCurrentProcess() = process; - kcout << "Switch to '" << process.Name << "'.\r"; // Set current process header. @@ -463,8 +471,6 @@ namespace Kernel } } - kcout << "Scheduled Process Count: " << number(process_index) << endl; - return process_index; } |
