diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-23 09:11:33 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-23 09:21:50 +0200 |
| commit | 8c500f29bd0ef17f5b59e5be49f4cae88d827d85 (patch) | |
| tree | adce743ad0a20fde024cf7024b1813357b69f5e5 /dev/kernel/KernelKit | |
| parent | bb1d9fa4b7b2c680ed3c0ca16c060dd991bda16f (diff) | |
dev, kernel: scheduler and disk swap refactors.
Details:
- Reworked SCSI groundwork to prepare for a Generic SCSI driver.
- Refatored scheduler's code with the new coding style for
structs.
- Add Leak and LeakBlob inside PROCESS_IMAGE struct.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/KernelKit')
| -rw-r--r-- | dev/kernel/KernelKit/BinaryMutex.h | 10 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/FileMgr.h | 8 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/IPEFDylibObject.h | 4 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/ProcessSchedulerCore.h | 29 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/UserProcessScheduler.h | 68 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/UserProcessScheduler.inl | 10 |
6 files changed, 73 insertions, 56 deletions
diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index ec1e355d..660d2e71 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -12,9 +12,7 @@ namespace Kernel { - class UserProcess; - - typedef UserProcess& UserProcessRef; + class USER_PROCESS; /// @brief Access control class, which locks a task until one is done. class BinaryMutex final @@ -31,13 +29,13 @@ namespace Kernel BOOL WaitForProcess(const Int16& sec) noexcept; public: - bool Lock(UserProcess& process); - bool LockOrWait(UserProcess& process, TimerInterface* timer); + bool Lock(USER_PROCESS& process); + bool LockOrWait(USER_PROCESS& process, TimerInterface* timer); public: NE_COPY_DEFAULT(BinaryMutex) private: - UserProcessRef fLockingProcess; + USER_PROCESS fLockingProcess; }; } // namespace Kernel diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index e5f67080..f4acdae9 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -40,8 +40,8 @@ #define kRestrictR "r" #define kRestrictRB "rb" #define kRestrictW "w" -#define kRestrictWB "rw" -#define kRestrictRWB "rwb" +#define kRestrictWR "rw" +#define kRestrictWRB "rwb" #define kRestrictMax (5U) @@ -354,7 +354,7 @@ namespace Kernel .fMappedTo = kFileMgrRestrictReadBinary, }, { - .fRestrict = kRestrictRWB, + .fRestrict = kRestrictWRB, .fMappedTo = kFileMgrRestrictReadWriteBinary, }, { @@ -362,7 +362,7 @@ namespace Kernel .fMappedTo = kFileMgrRestrictWrite, }, { - .fRestrict = kRestrictWB, + .fRestrict = kRestrictWR, .fMappedTo = kFileMgrRestrictReadWrite, }}; diff --git a/dev/kernel/KernelKit/IPEFDylibObject.h b/dev/kernel/KernelKit/IPEFDylibObject.h index 4769f0f9..82f08932 100644 --- a/dev/kernel/KernelKit/IPEFDylibObject.h +++ b/dev/kernel/KernelKit/IPEFDylibObject.h @@ -99,8 +99,8 @@ namespace Kernel typedef IPEFDylibObject* IDylibRef; - EXTERN_C IDylibRef rtl_init_dylib(UserProcess& header); - EXTERN_C Void rtl_fini_dylib(UserProcess& header, IDylibRef lib, Bool* successful); + EXTERN_C IDylibRef rtl_init_dylib(USER_PROCESS& header); + EXTERN_C Void rtl_fini_dylib(USER_PROCESS& header, IDylibRef lib, Bool* successful); } // namespace Kernel #endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */ diff --git a/dev/kernel/KernelKit/ProcessSchedulerCore.h b/dev/kernel/KernelKit/ProcessSchedulerCore.h index 002e685e..ee90ed8b 100644 --- a/dev/kernel/KernelKit/ProcessSchedulerCore.h +++ b/dev/kernel/KernelKit/ProcessSchedulerCore.h @@ -7,11 +7,12 @@ #pragma once #include <NewKit/Defines.h> +#include <NewKit/ErrorOr.h> namespace Kernel { - class UserProcess; - class KernelProcess; + class USER_PROCESS; + class KERNEL_PROCESS; class UserProcessTeam; /***********************************************************************************/ @@ -117,9 +118,9 @@ namespace Kernel /***********************************************************************************/ using ImagePtr = VoidPtr; - struct ProcessImage final + struct PROCESS_IMAGE final { - explicit ProcessImage() = default; + explicit PROCESS_IMAGE() = default; ImagePtr fCode; ImagePtr fBlob; @@ -133,5 +134,25 @@ namespace Kernel { return this->fBlob != nullptr; } + + ErrorOr<ImagePtr> Leak() + { + if (this->fCode) + { + return ErrorOr<ImagePtr>{this->fCode}; + } + + return ErrorOr<ImagePtr>{nullptr}; + } + + ErrorOr<ImagePtr> LeakBlob() + { + if (this->fBlob) + { + return ErrorOr<ImagePtr>{this->fBlob}; + } + + return ErrorOr<ImagePtr>{nullptr}; + } }; } // namespace Kernel diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 4ba4b779..6e1ca146 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -8,7 +8,7 @@ #define INC_PROCESS_SCHEDULER_H /// @file UserProcessScheduler.h -/// @brief User UserProcess scheduler code and definitions. +/// @brief User USER_PROCESS scheduler code and definitions. /// @author Amlal El Mahrouss (amlal@nekernel.org) #include <ArchKit/ArchKit.h> @@ -20,7 +20,7 @@ #define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) #define kSchedProcessLimitPerTeam (32U) -#define kSchedTeamCount (512U) +#define kSchedTeamCount (512U) #define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ #define kSchedMaxStackSz mib_cast(8) /* maximum stack size */ @@ -40,53 +40,53 @@ namespace Kernel class UserProcessHelper; /***********************************************************************************/ - /// @name UserProcess - /// @brief UserProcess class, holds information about the running process/thread. + /// @name USER_PROCESS + /// @brief USER_PROCESS class, holds information about the running process/thread. /***********************************************************************************/ - class UserProcess final + class USER_PROCESS final { public: - explicit UserProcess(); - ~UserProcess(); + explicit USER_PROCESS(); + ~USER_PROCESS(); public: - NE_COPY_DEFAULT(UserProcess) + NE_COPY_DEFAULT(USER_PROCESS) public: - Char Name[kSchedNameLen] = {"UserProcess"}; + Char Name[kSchedNameLen] = {"USER_PROCESS"}; ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemInvalid}; User* Owner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatusKind Status{ProcessStatusKind::kFinished}; UInt8* StackReserve{nullptr}; - ProcessImage Image{}; + PROCESS_IMAGE Image{}; SizeT StackSize{kSchedMaxStackSz}; IDylibObject* DylibDelegate{nullptr}; SizeT MemoryCursor{0UL}; SizeT MemoryLimit{kSchedMaxMemoryLimit}; SizeT UsedMemory{0UL}; - struct ProcessMemoryHeapList final + struct USER_HEAP_LIST final { VoidPtr MemoryEntry{nullptr}; SizeT MemoryEntrySize{0UL}; SizeT MemoryEntryPad{0UL}; - struct ProcessMemoryHeapList* MemoryPrev{nullptr}; - struct ProcessMemoryHeapList* MemoryNext{nullptr}; + struct USER_HEAP_LIST* MemoryPrev{nullptr}; + struct USER_HEAP_LIST* MemoryNext{nullptr}; }; - struct ProcessSignal final + struct USER_PROCESS_SIGNAL final { UIntPtr SignalArg; ProcessStatusKind PreviousStatus; UIntPtr SignalID; }; - ProcessSignal ProcessSignal; - ProcessMemoryHeapList* ProcessMemoryHeap{nullptr}; - UserProcessTeam* ProcessParentTeam; + USER_PROCESS_SIGNAL Signal; + USER_HEAP_LIST* ProcessMemoryHeap{nullptr}; + UserProcessTeam* ProcessParentTeam; VoidPtr VMRegister{0UL}; @@ -98,7 +98,7 @@ namespace Kernel kExecutableKindCount, }; - ProcessTime PTime{0}; //! @brief UserProcess allocated tine. + ProcessTime PTime{0}; //! @brief USER_PROCESS allocated tine. PID ProcessId{kSchedInvalidPID}; Int32 Kind{kExecutableKind}; @@ -170,6 +170,8 @@ namespace Kernel friend UserProcessHelper; }; + typedef Array<USER_PROCESS, kSchedProcessLimitPerTeam> USER_PROCESS_ARRAY; + /// \brief Processs Team (contains multiple processes inside it.) /// Equivalent to a process batch class UserProcessTeam final @@ -180,23 +182,19 @@ namespace Kernel NE_COPY_DEFAULT(UserProcessTeam) - Array<UserProcess, kSchedProcessLimitPerTeam>& AsArray(); - Ref<UserProcess>& AsRef(); - ProcessID& Id() noexcept; + Array<USER_PROCESS, kSchedProcessLimitPerTeam>& AsArray(); + Ref<USER_PROCESS>& AsRef(); + ProcessID& Id() noexcept; public: - Array<UserProcess, kSchedProcessLimitPerTeam> mProcessList; - Ref<UserProcess> mCurrentProcess; - ProcessID mTeamId{0}; - ProcessID mProcessCount{0}; + USER_PROCESS_ARRAY mProcessList; + Ref<USER_PROCESS> mCurrentProcess; + ProcessID mTeamId{0}; + ProcessID mProcessCount{0}; }; - typedef Array<UserProcess, kSchedProcessLimitPerTeam> UserThreadArray; - - using UserProcessRef = UserProcess&; - /***********************************************************************************/ - /// @brief UserProcess scheduler class. + /// @brief USER_PROCESS scheduler class. /// The main class which you call to schedule user processes. /***********************************************************************************/ class UserProcessScheduler final : public ISchedulable @@ -215,7 +213,7 @@ namespace Kernel public: UserProcessTeam& CurrentTeam(); - BOOL SwitchTeam(UserProcessTeam& team); + BOOL SwitchTeam(UserProcessTeam& team); public: ProcessID Spawn(const Char* name, VoidPtr code, VoidPtr image); @@ -226,8 +224,8 @@ namespace Kernel Bool HasMP() override; public: - Ref<UserProcess>& CurrentProcess(); - SizeT Run() noexcept; + Ref<USER_PROCESS>& CurrentProcess(); + SizeT Run() noexcept; public: STATIC UserProcessScheduler& The(); @@ -238,7 +236,7 @@ namespace Kernel /***********************************************************************************/ /** - * \brief UserProcess helper class, which contains needed utilities for the scheduler. + * \brief USER_PROCESS helper class, which contains needed utilities for the scheduler. */ /***********************************************************************************/ @@ -246,7 +244,7 @@ namespace Kernel { public: STATIC Bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, PID new_pid); - STATIC Bool CanBeScheduled(const UserProcess& process); + STATIC Bool CanBeScheduled(const USER_PROCESS& process); STATIC ErrorOr<PID> TheCurrentPID(); STATIC SizeT StartScheduling(); }; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index 4179545c..a18af9c1 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -3,11 +3,11 @@ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. FILE: UserProcessScheduler.inl - PURPOSE: Low level/Ring-3 UserProcess scheduler. + PURPOSE: Low level/Ring-3 USER_PROCESS scheduler. ------------------------------------------- */ -/// @brief UserProcess scheduler inline definitions. +/// @brief USER_PROCESS scheduler inline definitions. /// @author Amlal El Mahrouss (amlal@nekernel.org) /// @date Tue Apr 22 22:01:07 CEST 2025 @@ -18,18 +18,18 @@ namespace Kernel /***********************************************************************************/ template <typename T> - Boolean UserProcess::Delete(ErrorOr<T*> ptr) + Boolean USER_PROCESS::Delete(ErrorOr<T*> ptr) { if (!ptr) return No; if (!this->ProcessMemoryHeap) { - kout << "UserProcess's heap is empty.\r"; + kout << "USER_PROCESS's heap is empty.\r"; return No; } - ProcessMemoryHeapList* entry = this->ProcessMemoryHeap; + USER_HEAP_LIST* entry = this->ProcessMemoryHeap; while (entry != nullptr) { |
