summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/KernelKit
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-30 20:46:01 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-30 20:46:01 +0200
commit43bac17a2986ac2ea86e9d70c61268fa7e90ca4e (patch)
treed259814b8c388e87bb02860405ff668a92434c44 /dev/ZKA/KernelKit
parent8a4f0e988a901e4fce5d32e3d5f9dbdc5f309863 (diff)
Fixed many issues with the kernel, and refactored it.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/KernelKit')
-rw-r--r--dev/ZKA/KernelKit/LPC.hxx6
-rw-r--r--dev/ZKA/KernelKit/ProcessHeap.hxx44
-rw-r--r--dev/ZKA/KernelKit/ProcessScheduler.hxx45
-rw-r--r--dev/ZKA/KernelKit/Semaphore.hxx4
-rw-r--r--dev/ZKA/KernelKit/ThreadLocalStorage.inl9
5 files changed, 31 insertions, 77 deletions
diff --git a/dev/ZKA/KernelKit/LPC.hxx b/dev/ZKA/KernelKit/LPC.hxx
index 6553f45c..152e7295 100644
--- a/dev/ZKA/KernelKit/LPC.hxx
+++ b/dev/ZKA/KernelKit/LPC.hxx
@@ -11,9 +11,9 @@
/// @file LPC.hxx
/// @brief Local Process Codes.
-#define ErrLocalIsOk() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() == Kernel::kErrorSuccess)
-#define ErrLocalFailed() (Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode() != Kernel::kErrorSuccess)
-#define ErrLocal() Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().GetLocalCode()
+#define ErrLocalIsOk() (Kernel::ProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() == Kernel::kErrorSuccess)
+#define ErrLocalFailed() (Kernel::ProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() != Kernel::kErrorSuccess)
+#define ErrLocal() Kernel::ProcessScheduler::The().CurrentProcess().Leak().GetLocalCode()
namespace Kernel
{
diff --git a/dev/ZKA/KernelKit/ProcessHeap.hxx b/dev/ZKA/KernelKit/ProcessHeap.hxx
deleted file mode 100644
index 820daa76..00000000
--- a/dev/ZKA/KernelKit/ProcessHeap.hxx
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
-------------------------------------------- */
-
-#pragma once
-
-#include <NewKit/Array.hxx>
-#include <NewKit/ArrayList.hxx>
-#include <NewKit/ErrorOr.hxx>
-#include <NewKit/PageManager.hxx>
-#include <NewKit/Ref.hxx>
-#include <NewKit/Pmm.hxx>
-
-/// @version 5/11/23
-/// @file ProcessHeap.hxx
-/// @brief Process heap allocator.
-
-#define kProcessHeapMag (0xFAF0FEF0)
-
-namespace Kernel
-{
- typedef enum
- {
- /// @brief Shared heap.
- kProcessHeapShared = 0x4,
- /// @brief User and private heap.
- kProcessHeapUser = 0x6,
- /// @brief Read and Write heap.
- kProcessHeapRw = 0x8,
- } UserHeapFlags;
-
- /// @brief Allocate a process heap, no zero out is done here.
- /// @param flags the heap's flags.
- /// @param initial_len_in_gib the initial heap's length in GB.
- /// @return The process's heap.
- VoidPtr sched_new_heap(Int32 flags, SizeT initial_len_in_gib);
-
- /// @brief Frees the process heap.
- /// @param pointer The process heap pointer.
- /// @return status code of the freeing.
- Int32 sched_free_heap(voidPtr pointer);
-} // namespace Kernel
diff --git a/dev/ZKA/KernelKit/ProcessScheduler.hxx b/dev/ZKA/KernelKit/ProcessScheduler.hxx
index b0756522..5534c591 100644
--- a/dev/ZKA/KernelKit/ProcessScheduler.hxx
+++ b/dev/ZKA/KernelKit/ProcessScheduler.hxx
@@ -10,7 +10,6 @@
#include <ArchKit/ArchKit.hxx>
#include <KernelKit/LockDelegate.hxx>
#include <KernelKit/User.hxx>
-#include <KernelKit/ProcessHeap.hxx>
#include <NewKit/MutableArray.hxx>
#define kSchedMinMicroTime (AffinityKind::kStandard)
@@ -40,7 +39,6 @@ namespace Kernel
//! @brief Process name length.
inline constexpr SizeT kProcessLen = 256U;
-
//! @brief Process status enum.
enum class ProcessStatus : Int32
{
@@ -58,7 +56,7 @@ namespace Kernel
kInvalid = 300,
kVeryHigh = 250,
kHigh = 200,
- kStandard = 150,
+ kStandard = 150,
kLowUsage = 100,
kVeryLowUsage = 50,
};
@@ -126,7 +124,7 @@ namespace Kernel
/// @name PROCESS_HEADER_BLOCK
/// @brief Process Header Block (PHB).
- /// Holds information about the running process/thread.
+ /// Holds information about the running process/thread.
struct PROCESS_HEADER_BLOCK final
{
public:
@@ -140,13 +138,13 @@ namespace Kernel
ZKA_COPY_DEFAULT(PROCESS_HEADER_BLOCK)
public:
- void SetEntrypoint(UIntPtr& imageStart) noexcept;
+ void SetEntrypoint(UIntPtr& imageStart) noexcept;
const UInt32& GetExitCode() noexcept;
public:
Char Name[kProcessLen] = {"PROCESS #0 (TEAM 0)"};
ProcessSubsystem SubSystem{ProcessSubsystem::eProcessSubsystemInvalid};
- User* AssignedOwner{nullptr};
+ User* AssignedOwner{nullptr};
HAL::StackFramePtr StackFrame{nullptr};
AffinityKind Affinity{AffinityKind::kStandard};
ProcessStatus Status{ProcessStatus::kDead};
@@ -157,7 +155,7 @@ namespace Kernel
HeapPtrKind HeapPtr{nullptr};
// shared library handle, reserved for kSharedObjectKind types of executables only.
- PEFDLLInterface* DLLPtr{nullptr};
+ PEFDLLInterface* DLLPtr{nullptr};
PROCESS_HEADER_BLOCK* Parent{nullptr};
// Memory usage.
@@ -167,7 +165,7 @@ namespace Kernel
enum
{
- kExeKind = 1,
+ kExeKind = 1,
kSharedObjectKind = 2,
kKindCount,
};
@@ -211,13 +209,13 @@ namespace Kernel
//! @return Int32 local error code.
Int32& GetLocalCode() noexcept;
- const User* GetOwner() noexcept;
- const ProcessStatus& GetStatus() noexcept;
- const AffinityKind& GetAffinity() noexcept;
+ const User* GetOwner() noexcept;
+ const ProcessStatus& GetStatus() noexcept;
+ const AffinityKind& GetAffinity() noexcept;
private:
UInt32 fLastExitCode{0};
- Int32 fLocalCode{0};
+ Int32 fLocalCode{0};
friend ProcessScheduler;
friend ProcessHelper;
@@ -234,23 +232,24 @@ namespace Kernel
ZKA_COPY_DEFAULT(ProcessTeam);
Array<PROCESS_HEADER_BLOCK, kSchedProcessLimitPerTeam>& AsArray();
- Ref<PROCESS_HEADER_BLOCK>& AsRef();
- UInt64& Id() noexcept;
+ Ref<PROCESS_HEADER_BLOCK>& AsRef();
+ ProcessID& Id() noexcept;
public:
Array<PROCESS_HEADER_BLOCK, kSchedProcessLimitPerTeam> mProcessList;
- Ref<PROCESS_HEADER_BLOCK> mCurrentProcess;
- UInt64 mTeamId{0};
+ Ref<PROCESS_HEADER_BLOCK> mCurrentProcess;
+ SizeT mProcessAmount{0};
+ ProcessID mTeamId{0};
};
- using ProcessHeaderRef = PROCESS_HEADER_BLOCK*;
+ using PROCESS_HEADER_BLOCK_PTR = PROCESS_HEADER_BLOCK*;
/// @brief PROCESS_HEADER_BLOCK manager class.
/// The main class which you call to schedule an app.
class ProcessScheduler final
{
public:
- explicit ProcessScheduler() = default;
+ explicit ProcessScheduler() = default;
~ProcessScheduler() = default;
@@ -263,15 +262,15 @@ namespace Kernel
ProcessTeam& CurrentTeam();
public:
- SizeT Add(Ref<PROCESS_HEADER_BLOCK> processRef);
- Bool Remove(SizeT processSlot);
+ SizeT Add(PROCESS_HEADER_BLOCK& processRef);
+ Bool Remove(ProcessID processSlot);
public:
- Ref<PROCESS_HEADER_BLOCK>& TheCurrent();
- SizeT Run() noexcept;
+ Ref<PROCESS_HEADER_BLOCK>& CurrentProcess();
+ SizeT Run() noexcept;
public:
- STATIC Ref<ProcessScheduler> The();
+ STATIC ProcessScheduler& The();
private:
ProcessTeam mTeam;
diff --git a/dev/ZKA/KernelKit/Semaphore.hxx b/dev/ZKA/KernelKit/Semaphore.hxx
index 7f6b2001..685b00a3 100644
--- a/dev/ZKA/KernelKit/Semaphore.hxx
+++ b/dev/ZKA/KernelKit/Semaphore.hxx
@@ -14,7 +14,7 @@ namespace Kernel
{
class PROCESS_HEADER_BLOCK;
- typedef PROCESS_HEADER_BLOCK* ProcessHeaderRef;
+ typedef PROCESS_HEADER_BLOCK* PROCESS_HEADER_BLOCK_PTR;
/// @brief Access control class, which locks a task until one is done.
class Semaphore final
@@ -38,6 +38,6 @@ namespace Kernel
ZKA_COPY_DEFAULT(Semaphore);
private:
- ProcessHeaderRef fLockingProcess{nullptr};
+ PROCESS_HEADER_BLOCK_PTR fLockingProcess{nullptr};
};
} // namespace Kernel
diff --git a/dev/ZKA/KernelKit/ThreadLocalStorage.inl b/dev/ZKA/KernelKit/ThreadLocalStorage.inl
index 56244537..97480bdd 100644
--- a/dev/ZKA/KernelKit/ThreadLocalStorage.inl
+++ b/dev/ZKA/KernelKit/ThreadLocalStorage.inl
@@ -16,9 +16,8 @@ inline T* tls_new_ptr(void) noexcept
{
using namespace Kernel;
- MUST_PASS(ProcessScheduler::The().Leak().TheCurrent());
-
- auto ref_process = ProcessScheduler::The().Leak().TheCurrent();
+ auto ref_process = ProcessScheduler::The().CurrentProcess();
+ MUST_PASS(ref_process);
T* pointer = (T*)ref_process.Leak().New(sizeof(T));
return pointer;
@@ -33,9 +32,9 @@ inline Kernel::Bool tls_delete_ptr(T* ptr) noexcept
using namespace Kernel;
- MUST_PASS(ProcessScheduler::The().Leak().TheCurrent());
+ auto ref_process = ProcessScheduler::The().CurrentProcess();
+ MUST_PASS(ref_process);
- auto ref_process = ProcessScheduler::The().Leak().TheCurrent();
return ref_process.Leak().Delete(ptr, sizeof(T));
}