diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-08 08:18:37 +0200 |
| commit | df8a42aa1266d953a9ee473afe9f6349bd1837c7 (patch) | |
| tree | cad53c222ca90ee98ac82ee2d630a4ff0b0c3ee3 /dev/ZKA/Sources | |
| parent | 884ea5c2d43b6c8d4c2bb4fc33c11dc2313eeca2 (diff) | |
[dev/FeatureAdd] Add mm_new_class, as C++ new doesn't initialize class directly.
[dev/FeatureFix] CR2 set to invalid address due to stack corruption, fixing that.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA/Sources')
| -rw-r--r-- | dev/ZKA/Sources/CodeMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/ExeMain.cxx | 17 | ||||
| -rw-r--r-- | dev/ZKA/Sources/FileMgr.cxx | 8 | ||||
| -rw-r--r-- | dev/ZKA/Sources/HardwareThreadScheduler.cxx | 5 | ||||
| -rw-r--r-- | dev/ZKA/Sources/NeFS+FileMgr.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/Sources/UserProcessScheduler.cxx | 60 |
6 files changed, 54 insertions, 40 deletions
diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx index 8e560408..13bcd640 100644 --- a/dev/ZKA/Sources/CodeMgr.cxx +++ b/dev/ZKA/Sources/CodeMgr.cxx @@ -23,7 +23,7 @@ namespace Kernel proc.SetImageStart(reinterpret_cast<VoidPtr>(main)); proc.Kind = UserProcess::kExeKind; - proc.StackSize = mib_cast(4); + proc.StackSize = kib_cast(32); rt_set_memory(proc.Name, 0, kProcessLen); rt_copy_memory((VoidPtr)process_name, proc.Name, rt_string_len(process_name)); diff --git a/dev/ZKA/Sources/ExeMain.cxx b/dev/ZKA/Sources/ExeMain.cxx index 53865db7..e1b6afc1 100644 --- a/dev/ZKA/Sources/ExeMain.cxx +++ b/dev/ZKA/Sources/ExeMain.cxx @@ -50,17 +50,17 @@ namespace Kernel::Detail /// @brief wizard constructor. explicit FilesystemInstaller() { - if (Kernel::FilesystemMgrInterface::GetMounted()) + if (Kernel::IFilesystemMgr::GetMounted()) { CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNeFS = reinterpret_cast<Kernel::NewFilesystemMgr*>(Kernel::FilesystemMgrInterface::GetMounted()); + fNeFS = reinterpret_cast<Kernel::NewFilesystemMgr*>(Kernel::IFilesystemMgr::GetMounted()); } else { // Mounts a NeFS from main drive. fNeFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemMgrInterface::Mount(fNeFS); + Kernel::IFilesystemMgr::Mount(fNeFS); CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } @@ -154,15 +154,12 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawWindowList(&cKernelWnd, 1); - CG::CGDrawStringToWnd(cKernelWnd, "Running System Component: ", 10, 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysDrv, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running System Component: ")), RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Running: ", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, kSysLdr, 10, 10 + (FONT_SIZE_X * Kernel::rt_string_len("Running: ")), RGB(0, 0, 0)); Kernel::UserProcessHelper::StartScheduling(); - Kernel::sched_execute_thread((Kernel::MainKind)HangCPU, "HANG TEST"); + Kernel::sched_execute_thread(HangCPU, kSysLdr); - while (Yes) - { - Kernel::UserProcessHelper::StartScheduling(); - } + Kernel::UserProcessHelper::StartScheduling(); } diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx index 3e3977ab..eff3c334 100644 --- a/dev/ZKA/Sources/FileMgr.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -12,18 +12,18 @@ namespace Kernel { - STATIC FilesystemMgrInterface* kMounted = nullptr; + STATIC IFilesystemMgr* kMounted = nullptr; /// @brief FilesystemMgr getter. /// @return The mounted filesystem. - _Output FilesystemMgrInterface* FilesystemMgrInterface::GetMounted() + _Output IFilesystemMgr* IFilesystemMgr::GetMounted() { return kMounted; } /// @brief Unmount filesystem. /// @return The unmounted filesystem. - _Output FilesystemMgrInterface* FilesystemMgrInterface::Unmount() + _Output IFilesystemMgr* IFilesystemMgr::Unmount() { if (kMounted) { @@ -39,7 +39,7 @@ namespace Kernel /// @brief Mount filesystem. /// @param mount_ptr The filesystem to mount. /// @return if it succeeded true, otherwise false. - bool FilesystemMgrInterface::Mount(_Input FilesystemMgrInterface* mount_ptr) + bool IFilesystemMgr::Mount(_Input IFilesystemMgr* mount_ptr) { if (mount_ptr != nullptr) { diff --git a/dev/ZKA/Sources/HardwareThreadScheduler.cxx b/dev/ZKA/Sources/HardwareThreadScheduler.cxx index 5b310fca..09eadefb 100644 --- a/dev/ZKA/Sources/HardwareThreadScheduler.cxx +++ b/dev/ZKA/Sources/HardwareThreadScheduler.cxx @@ -90,7 +90,10 @@ namespace Kernel if (!frame || !image || !stack_ptr) - return false; + return No; + + if (!this->IsWakeup()) + return No; fStack = frame; diff --git a/dev/ZKA/Sources/NeFS+FileMgr.cxx b/dev/ZKA/Sources/NeFS+FileMgr.cxx index b3ad381f..609f2ece 100644 --- a/dev/ZKA/Sources/NeFS+FileMgr.cxx +++ b/dev/ZKA/Sources/NeFS+FileMgr.cxx @@ -18,7 +18,7 @@ namespace Kernel NewFilesystemMgr::NewFilesystemMgr() { MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NeFSParser(); + fImpl = mm_new_class<NeFSParser>(); MUST_PASS(fImpl); kcout << "We are done here... (NewFilesystemMgr).\r"; diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx index eba81677..721bd02f 100644 --- a/dev/ZKA/Sources/UserProcessScheduler.cxx +++ b/dev/ZKA/Sources/UserProcessScheduler.cxx @@ -91,11 +91,11 @@ namespace Kernel { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); - hal_write_cr3(this->MemoryPD); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); auto ptr = mm_new_ke_heap(sz, Yes, Yes); - hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); #else auto ptr = mm_new_ke_heap(sz, Yes, Yes); #endif @@ -143,10 +143,10 @@ namespace Kernel { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); - hal_write_cr3(this->MemoryPD); + hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD)); bool ret = mm_delete_ke_heap(ptr); - hal_write_cr3(reinterpret_cast<UIntPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(pd)); return ret; #else @@ -233,12 +233,17 @@ namespace Kernel /// @brief Add process to list. /// @param process the process *Ref* class. /// @return the process index inside the team. - SizeT UserProcessScheduler::Add(UserProcess& process) + SizeT UserProcessScheduler::Add(UserProcess process) { + if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) + return 0; + #ifdef __ZKA_AMD64__ process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3()); #endif // __ZKA_AMD64__ + process.Status = ProcessStatusKind::kStarting; + process.StackFrame = (HAL::StackFramePtr)mm_new_ke_heap(sizeof(HAL::StackFrame), Yes, Yes); if (!process.StackFrame) @@ -268,21 +273,22 @@ namespace Kernel if (!process.StackReserve) { - process.Crash(); + mm_delete_ke_heap(process.StackFrame); + process.StackFrame = nullptr; return -kErrorProcessFault; } - if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam) - mTeam.mProcessAmount = 0UL; - ++mTeam.mProcessAmount; process.ProcessId = mTeam.mProcessAmount; - process.Status = ProcessStatusKind::kStarting; + process.Status = ProcessStatusKind::kRunning; + + // avoid the pitfalls of moving process. + auto ret_pid = process.ProcessId; - mTeam.AsArray()[process.ProcessId] = process; + mTeam.AsArray()[process.ProcessId] = move(process); - return process.ProcessId; + return ret_pid; } /***********************************************************************************/ @@ -318,21 +324,21 @@ namespace Kernel SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. - kcout << "Finding available process...\r"; - for (; process_index < mTeam.AsArray().Capacity(); ++process_index) { + kcout << "Grabbing available process...\r"; + auto& process = mTeam.AsArray()[process_index]; //! check if process needs to be scheduled. if (UserProcessHelper::CanBeScheduled(process)) { - // set the current process. - mTeam.AsRef() = process; + kcout << process.Name << ": will be runned.\r"; - process.PTime = static_cast<Int32>(process.Affinity); + // Set current process header. + this->CurrentProcess() = process; - kcout << process.Name << ": will be runned.\r"; + process.PTime = static_cast<Int32>(process.Affinity); // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame, @@ -349,6 +355,8 @@ namespace Kernel } } + kcout << "Scheduled Process Count: " << number(process_index) << endl; + return process_index; } @@ -380,13 +388,17 @@ namespace Kernel /// @param process the process reference. /// @retval true can be schedulded. /// @retval false cannot be schedulded. - bool UserProcessHelper::CanBeScheduled(const UserProcess process) + bool UserProcessHelper::CanBeScheduled(const UserProcess& process) { + kcout << "Checking Status...\r"; + if (process.Status == ProcessStatusKind::kFrozen || process.Status == ProcessStatusKind::kDead) - return false; + return No; + + kcout << "Checking PTime...\r"; - return process.PTime < 1; + return process.PTime <= 0; } /** @@ -400,12 +412,14 @@ namespace Kernel { if (!cHardwareThreadScheduler) { - cHardwareThreadScheduler = new HardwareThreadScheduler(); + cHardwareThreadScheduler = mm_new_class<HardwareThreadScheduler>(); + MUST_PASS(cHardwareThreadScheduler); } if (!cProcessScheduler) { - cProcessScheduler = new UserProcessScheduler(); + cProcessScheduler = mm_new_class<UserProcessScheduler>(); + MUST_PASS(cProcessScheduler); } SizeT ret = cProcessScheduler->Run(); |
