From 0511c53e648e5f253cd9e83c9e211aa6600db377 Mon Sep 17 00:00:00 2001 From: Amlal Date: Mon, 28 Oct 2024 19:29:04 +0100 Subject: META: Bumping source code. Signed-off-by: Amlal --- dev/Modules/LTE/LTE.h | 2 +- dev/ZKAKit/CFKit/GUIDWizard.h | 4 +- dev/ZKAKit/CFKit/Property.h | 8 +- dev/ZKAKit/FSKit/IndexableProperty.h | 2 +- dev/ZKAKit/HALKit/AMD64/HalACPIFactoryInterface.cc | 2 +- .../HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc | 12 +- dev/ZKAKit/HALKit/AMD64/HalCoreMPScheduler.cc | 8 +- dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc | 2 +- dev/ZKAKit/HALKit/ARM64/HalACPIFactoryInterface.cc | 2 +- dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc | 2 +- dev/ZKAKit/KernelKit/DriveMgr.h | 2 +- dev/ZKAKit/KernelKit/LPC.h | 6 +- dev/ZKAKit/KernelKit/PECodeMgr.h | 2 +- dev/ZKAKit/KernelKit/PEFCodeMgr.h | 4 +- dev/ZKAKit/KernelKit/ThreadLocalStorage.inl | 22 ++- dev/ZKAKit/KernelKit/User.h | 2 +- dev/ZKAKit/KernelKit/UserProcessScheduler.h | 37 ++-- dev/ZKAKit/NetworkKit/IP.h | 6 +- dev/ZKAKit/NetworkKit/IPC.h | 2 +- dev/ZKAKit/NetworkKit/MAC.h | 4 +- dev/ZKAKit/NewKit/ErrorOr.h | 5 + dev/ZKAKit/NewKit/Json.h | 12 +- dev/ZKAKit/NewKit/KString.h | 94 +++++++++ dev/ZKAKit/NewKit/Ref.h | 5 + dev/ZKAKit/NewKit/String.h | 91 --------- dev/ZKAKit/NewKit/Variant.h | 4 +- dev/ZKAKit/src/ACPIFactoryInterface.cc | 2 +- dev/ZKAKit/src/FS/NeFS.cc | 2 +- dev/ZKAKit/src/GUIDWizard.cc | 6 +- dev/ZKAKit/src/KString.cc | 217 +++++++++++++++++++++ dev/ZKAKit/src/Network/IP.cc | 4 +- dev/ZKAKit/src/Network/IPC.cc | 8 +- dev/ZKAKit/src/PEFCodeMgr.cc | 4 +- dev/ZKAKit/src/PRDT.cc | 2 +- dev/ZKAKit/src/Property.cc | 4 +- dev/ZKAKit/src/Stop.cc | 2 +- dev/ZKAKit/src/String.cc | 217 --------------------- dev/ZKAKit/src/ThreadLocalStorage.cc | 2 +- dev/ZKAKit/src/UserProcessScheduler.cc | 86 ++++---- zka-dev.files | 4 +- 40 files changed, 467 insertions(+), 435 deletions(-) create mode 100644 dev/ZKAKit/NewKit/KString.h delete mode 100644 dev/ZKAKit/NewKit/String.h create mode 100644 dev/ZKAKit/src/KString.cc delete mode 100644 dev/ZKAKit/src/String.cc diff --git a/dev/Modules/LTE/LTE.h b/dev/Modules/LTE/LTE.h index daced535..c9ca889b 100644 --- a/dev/Modules/LTE/LTE.h +++ b/dev/Modules/LTE/LTE.h @@ -11,7 +11,7 @@ Purpose: LTE Standard Library. #define _INC_NETWORK_LTE_H_ #include -#include +#include /// @brief Long Term Evolution I/O routines. diff --git a/dev/ZKAKit/CFKit/GUIDWizard.h b/dev/ZKAKit/CFKit/GUIDWizard.h index b4a92249..25fd5a30 100644 --- a/dev/ZKAKit/CFKit/GUIDWizard.h +++ b/dev/ZKAKit/CFKit/GUIDWizard.h @@ -13,12 +13,12 @@ #include #include #include -#include +#include namespace CFKit::XRN::Version1 { using namespace Kernel; Ref cf_make_sequence(const ArrayList& seq); - ErrorOr> cf_try_guid_to_string(Ref& guid); + ErrorOr> cf_try_guid_to_string(Ref& guid); } // namespace CFKit::XRN::Version1 diff --git a/dev/ZKAKit/CFKit/Property.h b/dev/ZKAKit/CFKit/Property.h index efdb9879..1e8e026e 100644 --- a/dev/ZKAKit/CFKit/Property.h +++ b/dev/ZKAKit/CFKit/Property.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #define kMaxPropLen 255 @@ -33,12 +33,12 @@ namespace CFKit Property& operator=(const Property&) = default; Property(const Property&) = default; - bool StringEquals(StringView& name); + bool StringEquals(KString& name); PropertyId& GetValue(); - StringView& GetKey(); + KString& GetKey(); private: - StringView fName{kMaxPropLen}; + KString fName{kMaxPropLen}; PropertyId fAction{No}; }; diff --git a/dev/ZKAKit/FSKit/IndexableProperty.h b/dev/ZKAKit/FSKit/IndexableProperty.h index fe9dea26..9e6f3c1f 100644 --- a/dev/ZKAKit/FSKit/IndexableProperty.h +++ b/dev/ZKAKit/FSKit/IndexableProperty.h @@ -30,7 +30,7 @@ namespace Kernel explicit IndexableProperty() : Property() { - Kernel::StringView strProp(kMaxPropLen); + Kernel::KString strProp(kMaxPropLen); strProp += "\\Properties\\Indexable"; this->GetKey() = strProp; diff --git a/dev/ZKAKit/HALKit/AMD64/HalACPIFactoryInterface.cc b/dev/ZKAKit/HALKit/AMD64/HalACPIFactoryInterface.cc index 8f2ae1e7..14a16c9c 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalACPIFactoryInterface.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalACPIFactoryInterface.cc @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index b8a84075..41490b1b 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -6,7 +6,7 @@ #include #include -#include +#include namespace Kernel { @@ -17,14 +17,14 @@ namespace Kernel /// @param rsp EXTERN_C void idt_handle_gpf(Kernel::UIntPtr rsp) { - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } /// @brief Handle page fault. /// @param rsp EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } /// @brief Handle scheduler interrupt. @@ -37,21 +37,21 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) /// @param rsp EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } /// @brief Handle any generic fault. /// @param rsp EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } /// @brief Handle #UD fault. /// @param rsp EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { - Kernel::UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } /// @brief Enter syscall from assembly. diff --git a/dev/ZKAKit/HALKit/AMD64/HalCoreMPScheduler.cc b/dev/ZKAKit/HALKit/AMD64/HalCoreMPScheduler.cc index 89282ebe..3f4280ee 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalCoreMPScheduler.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalCoreMPScheduler.cc @@ -145,16 +145,16 @@ namespace Kernel::HAL EXTERN_C HAL::StackFramePtr mp_get_current_context(Void) { - return fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame; + return fBlocks[UserProcessScheduler::The().GetCurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame; } EXTERN_C Void mp_do_task_switch(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr stack_frame); EXTERN_C Bool mp_register_process(VoidPtr image, UInt8* stack_ptr, HAL::StackFramePtr stack_frame) { - fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame = stack_frame; - fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Stack = stack_ptr; - fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Image = image; + fBlocks[UserProcessScheduler::The().GetCurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame = stack_frame; + fBlocks[UserProcessScheduler::The().GetCurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Stack = stack_ptr; + fBlocks[UserProcessScheduler::The().GetCurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Image = image; mp_do_task_switch(image, stack_ptr, stack_frame); diff --git a/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc b/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc index d4ca494c..876d32cf 100644 --- a/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc +++ b/dev/ZKAKit/HALKit/AMD64/HalSchedulerCoreAMD64.cc @@ -16,7 +16,7 @@ namespace Kernel EXTERN_C Void __zka_pure_call(void) { - UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } Bool hal_check_stack(HAL::StackFramePtr stack_ptr) diff --git a/dev/ZKAKit/HALKit/ARM64/HalACPIFactoryInterface.cc b/dev/ZKAKit/HALKit/ARM64/HalACPIFactoryInterface.cc index db3b688b..85989eea 100644 --- a/dev/ZKAKit/HALKit/ARM64/HalACPIFactoryInterface.cc +++ b/dev/ZKAKit/HALKit/ARM64/HalACPIFactoryInterface.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include #include #include diff --git a/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc b/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc index 49927c84..917e5d8f 100644 --- a/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc +++ b/dev/ZKAKit/HALKit/ARM64/HalSchedulerCoreARM64.cc @@ -10,7 +10,7 @@ namespace Kernel { EXTERN_C Void __zka_pure_call(void) { - UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); } bool hal_check_stack(HAL::StackFramePtr stackPtr) diff --git a/dev/ZKAKit/KernelKit/DriveMgr.h b/dev/ZKAKit/KernelKit/DriveMgr.h index 95c0cda4..212d6b71 100644 --- a/dev/ZKAKit/KernelKit/DriveMgr.h +++ b/dev/ZKAKit/KernelKit/DriveMgr.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #define kMaxDriveCountPerMountpoint (4U) diff --git a/dev/ZKAKit/KernelKit/LPC.h b/dev/ZKAKit/KernelKit/LPC.h index 305b504d..c270a447 100644 --- a/dev/ZKAKit/KernelKit/LPC.h +++ b/dev/ZKAKit/KernelKit/LPC.h @@ -11,9 +11,9 @@ /// @file LPC.h /// @brief Local Process Codes. -#define ErrLocalIsOk() (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() == Kernel::kErrorSuccess) -#define ErrLocalFailed() (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() != Kernel::kErrorSuccess) -#define ErrLocal() Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() +#define ErrLocalIsOk() (Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().GetLocalCode() == Kernel::kErrorSuccess) +#define ErrLocalFailed() (Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().GetLocalCode() != Kernel::kErrorSuccess) +#define ErrLocal() Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().GetLocalCode() namespace Kernel { diff --git a/dev/ZKAKit/KernelKit/PECodeMgr.h b/dev/ZKAKit/KernelKit/PECodeMgr.h index 14dd8c1a..cadd2737 100644 --- a/dev/ZKAKit/KernelKit/PECodeMgr.h +++ b/dev/ZKAKit/KernelKit/PECodeMgr.h @@ -21,4 +21,4 @@ #include #include -#include +#include diff --git a/dev/ZKAKit/KernelKit/PEFCodeMgr.h b/dev/ZKAKit/KernelKit/PEFCodeMgr.h index f4e9e446..00afa2d8 100644 --- a/dev/ZKAKit/KernelKit/PEFCodeMgr.h +++ b/dev/ZKAKit/KernelKit/PEFCodeMgr.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #define kPefApplicationMime "application/vnd-zka-executable" @@ -52,7 +52,7 @@ namespace Kernel OwnPtr> fFile; #endif // __FSKIT_INCLUDES_NEFS__ - Ref fPath; + Ref fPath; VoidPtr fCachedBlob; bool fFatBinary; bool fBad; diff --git a/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl b/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl index 305d3966..9f64ae55 100644 --- a/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl +++ b/dev/ZKAKit/KernelKit/ThreadLocalStorage.inl @@ -16,11 +16,15 @@ inline T* tls_new_ptr(void) noexcept { using namespace Kernel; - auto ref_process = UserProcessScheduler::The().CurrentProcess(); + auto ref_process = UserProcessScheduler::The().GetCurrentProcess(); MUST_PASS(ref_process); - T* pointer = (T*)ref_process.Leak().New(sizeof(T)); - return pointer; + auto pointer = ref_process.Leak().New(sizeof(T)); + + if (pointer.Error()) + return nullptr; + + return reinterpret_cast(pointer.Leak().Leak()); } //! @brief TLS delete implementation. @@ -28,21 +32,21 @@ template inline Kernel::Bool tls_delete_ptr(T* ptr) noexcept { if (!ptr) - return false; + return No; using namespace Kernel; - auto ref_process = UserProcessScheduler::The().CurrentProcess(); + auto ref_process = UserProcessScheduler::The().GetCurrentProcess(); MUST_PASS(ref_process); return ref_process.Leak().Delete(ptr, sizeof(T)); } /// @brief Allocate a C++ class, and then call the constructor of it. -/// @tparam T -/// @tparam ...Args -/// @param ...args -/// @return +/// @tparam T class type. +/// @tparam ...Args varg class type. +/// @param ...args arguments list. +/// @return Class instance. template T* tls_new_class(Args&&... args) { diff --git a/dev/ZKAKit/KernelKit/User.h b/dev/ZKAKit/KernelKit/User.h index 914d7ed2..8e7ef5e9 100644 --- a/dev/ZKAKit/KernelKit/User.h +++ b/dev/ZKAKit/KernelKit/User.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include // user mode users. diff --git a/dev/ZKAKit/KernelKit/UserProcessScheduler.h b/dev/ZKAKit/KernelKit/UserProcessScheduler.h index 4be849e2..c093bfb1 100644 --- a/dev/ZKAKit/KernelKit/UserProcessScheduler.h +++ b/dev/ZKAKit/KernelKit/UserProcessScheduler.h @@ -39,7 +39,7 @@ namespace Kernel typedef Int64 ProcessID; //! @brief Local Process name length. - inline constexpr SizeT kProcessLen = 256U; + inline constexpr SizeT kProcessLen = 4096U; //! @brief Local Process status enum. enum class ProcessStatusKind : Int32 @@ -131,18 +131,14 @@ namespace Kernel class UserProcess final { public: - explicit UserProcess(VoidPtr startImage = nullptr) - : Image(startImage) - { - } - - ~UserProcess() = default; + explicit UserProcess(VoidPtr startImage = nullptr); + ~UserProcess(); public: ZKA_COPY_DEFAULT(UserProcess) public: - Char Name[kProcessLen] = {"Process"}; + Char Name[kProcessLen] = {"Application Process (Unnamed)"}; ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemInvalid}; User* Owner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; @@ -155,15 +151,17 @@ namespace Kernel SizeT MemoryCursor{0}; SizeT MemoryLimit{kSchedMaxMemoryLimit}; - struct PROCESS_MEMORY_ENTRY final + struct USER_PROCESS_HEAP final { - VoidPtr MemoryEntry; + VoidPtr MemoryEntry{nullptr}; + SizeT MemoryEntrySize{0UL}; + SizeT MemoryEntryPad{0UL}; - struct PROCESS_MEMORY_ENTRY* MemoryPrev; - struct PROCESS_MEMORY_ENTRY* MemoryNext; + struct USER_PROCESS_HEAP* MemoryPrev{nullptr}; + struct USER_PROCESS_HEAP* MemoryNext{nullptr}; }; - PROCESS_MEMORY_ENTRY* MemoryEntryList{nullptr}; + USER_PROCESS_HEAP* MemoryHeap{nullptr}; UIntPtr VMRegister{0UL}; @@ -192,15 +190,15 @@ namespace Kernel ///! @brief TLS allocate. ///! @param sz size of new ptr. - VoidPtr New(const SizeT& sz); + ErrorOr New(const SizeT& sz, const SizeT& pad_amount = 0); ///! @brief TLS free. ///! @param ptr the pointer to free. ///! @param sz the size of it. - Boolean Delete(VoidPtr ptr, const SizeT& sz); + Boolean Delete(ErrorOr ptr, const SizeT& sz); ///! @brief Wakes up threads. - Void Wake(const bool wakeup = false); + Void Wake(const Bool wakeup = false); public: //! @brief Gets the local exit code. @@ -208,7 +206,7 @@ namespace Kernel ///! @brief Get the process's name ///! @example 'C Runtime Library' - const Char* GetProcessName() noexcept; + const Char* GetName() noexcept; //! @brief return local error code of process. //! @return Int32 local error code. @@ -276,10 +274,11 @@ namespace Kernel const Bool HasMP() override; public: - Ref& CurrentProcess(); - SizeT Run() noexcept; + Ref& GetCurrentProcess(); + const SizeT Run() noexcept; public: + STATIC ErrorOr TheSafe(); STATIC UserProcessScheduler& The(); private: diff --git a/dev/ZKAKit/NetworkKit/IP.h b/dev/ZKAKit/NetworkKit/IP.h index 6853ad6a..4de0ae66 100644 --- a/dev/ZKAKit/NetworkKit/IP.h +++ b/dev/ZKAKit/NetworkKit/IP.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace Kernel { @@ -76,8 +76,8 @@ namespace Kernel class IPFactory final { public: - static ErrorOr ToStringView(Ref& ipv6); - static ErrorOr ToStringView(Ref& ipv4); + static ErrorOr ToKString(Ref& ipv6); + static ErrorOr ToKString(Ref& ipv4); static bool IpCheckVersion4(const Char* ip); }; } // namespace Kernel diff --git a/dev/ZKAKit/NetworkKit/IPC.h b/dev/ZKAKit/NetworkKit/IPC.h index a2fa2ead..d7e16521 100644 --- a/dev/ZKAKit/NetworkKit/IPC.h +++ b/dev/ZKAKit/NetworkKit/IPC.h @@ -11,7 +11,7 @@ #define _INC_IPC_ENDPOINT_H_ #include -#include +#include #include #include diff --git a/dev/ZKAKit/NetworkKit/MAC.h b/dev/ZKAKit/NetworkKit/MAC.h index 8794c068..7a08d769 100644 --- a/dev/ZKAKit/NetworkKit/MAC.h +++ b/dev/ZKAKit/NetworkKit/MAC.h @@ -8,7 +8,7 @@ #include #include -#include +#include namespace Kernel { @@ -22,7 +22,7 @@ namespace Kernel explicit MacAddressGetter() = default; public: - StringView& AsString(); + KString& AsString(); Array& AsBytes(); }; diff --git a/dev/ZKAKit/NewKit/ErrorOr.h b/dev/ZKAKit/NewKit/ErrorOr.h index eae5bcd1..addeb6e5 100644 --- a/dev/ZKAKit/NewKit/ErrorOr.h +++ b/dev/ZKAKit/NewKit/ErrorOr.h @@ -33,6 +33,11 @@ namespace Kernel { } + explicit ErrorOr(T* Class) + : mRef(Class) + { + } + explicit ErrorOr(T Class) : mRef(Class) { diff --git a/dev/ZKAKit/NewKit/Json.h b/dev/ZKAKit/NewKit/Json.h index 68210e00..66533885 100644 --- a/dev/ZKAKit/NewKit/Json.h +++ b/dev/ZKAKit/NewKit/Json.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #define cMaxJsonPath 4096 @@ -28,7 +28,7 @@ namespace Kernel explicit JSON() { auto len = cJSONLen; - StringView key = StringView(len); + KString key = KString(len); key += cJSONNull; this->AsKey() = key; @@ -51,20 +51,20 @@ namespace Kernel private: Bool fUndefined; // is this instance undefined? - StringView fKey; - StringView fValue; + KString fKey; + KString fValue; public: /// @brief returns the key of the json /// @return the key as string view. - StringView& AsKey() + KString& AsKey() { return fKey; } /// @brief returns the value of the json. /// @return the key as string view. - StringView& AsValue() + KString& AsValue() { return fValue; } diff --git a/dev/ZKAKit/NewKit/KString.h b/dev/ZKAKit/NewKit/KString.h new file mode 100644 index 00000000..65ab13e5 --- /dev/null +++ b/dev/ZKAKit/NewKit/KString.h @@ -0,0 +1,94 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include + +#define cMinimumStringSize 8196 + +namespace Kernel +{ + /// @brief KString static string class. + class KString final + { + public: + explicit KString() + { + fDataSz = cMinimumStringSize; + + fData = new Char[fDataSz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, fDataSz); + } + + explicit KString(const SizeT& Sz) + : fDataSz(Sz) + { + MUST_PASS(Sz > 1); + + fData = new Char[Sz]; + MUST_PASS(fData); + + rt_set_memory(fData, 0, Sz); + } + + ~KString() + { + if (fData) + { + delete[] fData; + fData = nullptr; + } + } + + ZKA_COPY_DEFAULT(KString); + + Char* Data(); + const Char* CData() const; + Size Length() const; + + bool operator==(const Char* rhs) const; + bool operator!=(const Char* rhs) const; + + bool operator==(const KString& rhs) const; + bool operator!=(const KString& rhs) const; + + KString& operator+=(const Char* rhs); + KString& operator+=(const KString& rhs); + + operator bool() + { + return fData; + } + + bool operator!() + { + return fData; + } + + private: + Char* fData{nullptr}; + Size fDataSz{0}; + Size fCur{0}; + + friend class StringBuilder; + }; + + struct StringBuilder final + { + static ErrorOr Construct(const Char* data); + static const Char* FromBool(const Char* fmt, bool n); + static const Char* Format(const Char* fmt, const Char* from); + static bool Equals(const Char* lhs, const Char* rhs); + static bool Equals(const WideChar* lhs, const WideChar* rhs); + }; +} // namespace Kernel diff --git a/dev/ZKAKit/NewKit/Ref.h b/dev/ZKAKit/NewKit/Ref.h index cc6821c0..0cd43f6e 100644 --- a/dev/ZKAKit/NewKit/Ref.h +++ b/dev/ZKAKit/NewKit/Ref.h @@ -27,6 +27,11 @@ namespace Kernel } public: + Ref(T* cls) + : fClass(cls) + { + } + Ref(T cls) : fClass(&cls) { diff --git a/dev/ZKAKit/NewKit/String.h b/dev/ZKAKit/NewKit/String.h deleted file mode 100644 index 8e77b61b..00000000 --- a/dev/ZKAKit/NewKit/String.h +++ /dev/null @@ -1,91 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include -#include - -#define cMinimumStringSize 8196 - -namespace Kernel -{ - /// @brief StringView class, using dynamic or static memory. - class StringView final - { - public: - explicit StringView() - { - fDataSz = cMinimumStringSize; - - fData = new Char[fDataSz]; - MUST_PASS(fData); - - rt_set_memory(fData, 0, fDataSz); - } - - explicit StringView(const SizeT& Sz) - : fDataSz(Sz) - { - MUST_PASS(Sz > 1); - - fData = new Char[Sz]; - MUST_PASS(fData); - - rt_set_memory(fData, 0, Sz); - } - - ~StringView() - { - if (fData) - delete[] fData; - } - - ZKA_COPY_DEFAULT(StringView); - - Char* Data(); - const Char* CData() const; - Size Length() const; - - bool operator==(const Char* rhs) const; - bool operator!=(const Char* rhs) const; - - bool operator==(const StringView& rhs) const; - bool operator!=(const StringView& rhs) const; - - StringView& operator+=(const Char* rhs); - StringView& operator+=(const StringView& rhs); - - operator bool() - { - return fData; - } - - bool operator!() - { - return fData; - } - - private: - Char* fData{nullptr}; - Size fDataSz{0}; - Size fCur{0}; - - friend class StringBuilder; - }; - - struct StringBuilder final - { - static ErrorOr Construct(const Char* data); - static const Char* FromBool(const Char* fmt, bool n); - static const Char* Format(const Char* fmt, const Char* from); - static bool Equals(const Char* lhs, const Char* rhs); - static bool Equals(const WideChar* lhs, const WideChar* rhs); - }; -} // namespace Kernel diff --git a/dev/ZKAKit/NewKit/Variant.h b/dev/ZKAKit/NewKit/Variant.h index 92eee500..8aec9bff 100644 --- a/dev/ZKAKit/NewKit/Variant.h +++ b/dev/ZKAKit/NewKit/Variant.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include namespace Kernel @@ -33,7 +33,7 @@ namespace Kernel ~Variant() = default; public: - explicit Variant(StringView* stringView) + explicit Variant(KString* stringView) : fPtr((VoidPtr)stringView), fKind(VariantKind::kString) { } diff --git a/dev/ZKAKit/src/ACPIFactoryInterface.cc b/dev/ZKAKit/src/ACPIFactoryInterface.cc index 5c57d119..f90859da 100644 --- a/dev/ZKAKit/src/ACPIFactoryInterface.cc +++ b/dev/ZKAKit/src/ACPIFactoryInterface.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include #include diff --git a/dev/ZKAKit/src/FS/NeFS.cc b/dev/ZKAKit/src/FS/NeFS.cc index 6f8ffa14..1bbafae7 100644 --- a/dev/ZKAKit/src/FS/NeFS.cc +++ b/dev/ZKAKit/src/FS/NeFS.cc @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/ZKAKit/src/GUIDWizard.cc b/dev/ZKAKit/src/GUIDWizard.cc index cb4fc50b..c05af119 100644 --- a/dev/ZKAKit/src/GUIDWizard.cc +++ b/dev/ZKAKit/src/GUIDWizard.cc @@ -43,7 +43,7 @@ namespace CFKit::XRN::Version1 // @brief Tries to make a guid out of a string. // This function is not complete for now - auto cf_try_guid_to_string(Ref& seq) -> ErrorOr> + auto cf_try_guid_to_string(Ref& seq) -> ErrorOr> { Char buf[kUUIDSize]; @@ -65,8 +65,8 @@ namespace CFKit::XRN::Version1 auto view = StringBuilder::Construct(buf); if (view) - return ErrorOr>{view.Leak()}; + return ErrorOr>{view.Leak()}; - return ErrorOr>{-1}; + return ErrorOr>{-1}; } } // namespace CFKit::XRN::Version1 diff --git a/dev/ZKAKit/src/KString.cc b/dev/ZKAKit/src/KString.cc new file mode 100644 index 00000000..4f1ab7ba --- /dev/null +++ b/dev/ZKAKit/src/KString.cc @@ -0,0 +1,217 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#include +#include + +/// @file KString.cc +/// @brief Kernel String manipulation file. + +namespace Kernel +{ + Char* KString::Data() + { + return fData; + } + + const Char* KString::CData() const + { + return fData; + } + + Size KString::Length() const + { + return fDataSz; + } + + bool KString::operator==(const KString& rhs) const + { + if (rhs.Length() != this->Length()) + return false; + + for (Size index = 0; index < this->Length(); ++index) + { + if (rhs.fData[index] != fData[index]) + return false; + } + + return true; + } + + bool KString::operator==(const Char* rhs) const + { + if (rt_string_len(rhs) != this->Length()) + return false; + + for (Size index = 0; index < rt_string_len(rhs); ++index) + { + if (rhs[index] != fData[index]) + return false; + } + + return true; + } + + bool KString::operator!=(const KString& rhs) const + { + if (rhs.Length() != this->Length()) + return false; + + for (Size index = 0; index < rhs.Length(); ++index) + { + if (rhs.fData[index] == fData[index]) + return false; + } + + return true; + } + + bool KString::operator!=(const Char* rhs) const + { + if (rt_string_len(rhs) != this->Length()) + return false; + + for (Size index = 0; index < rt_string_len(rhs); ++index) + { + if (rhs[index] == fData[index]) + return false; + } + + return true; + } + + ErrorOr StringBuilder::Construct(const Char* data) + { + if (!data || *data == 0) + return {}; + + KString* view = new KString(rt_string_len(data)); + (*view) += data; + + return ErrorOr(*view); + } + + const Char* StringBuilder::FromBool(const Char* fmt, bool i) + { + if (!fmt) + return ("?"); + + const Char* boolean_expr = i ? "YES" : "NO"; + char* ret = (char*)cAlloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); + + if (!ret) + return ("?"); + + const auto fmt_len = rt_string_len(fmt); + const auto res_len = rt_string_len(boolean_expr); + + for (Size idx = 0; idx < fmt_len; ++idx) + { + if (fmt[idx] == '%') + { + SizeT result_cnt = idx; + + for (auto y_idx = idx; y_idx < res_len; ++y_idx) + { + ret[result_cnt] = boolean_expr[y_idx]; + ++result_cnt; + } + + break; + } + + ret[idx] = fmt[idx]; + } + + return ret; + } + + bool StringBuilder::Equals(const Char* lhs, const Char* rhs) + { + if (rt_string_len(rhs) != rt_string_len(lhs)) + return false; + + for (Size index = 0; index < rt_string_len(rhs); ++index) + { + if (rhs[index] != lhs[index]) + return false; + } + + return true; + } + + bool StringBuilder::Equals(const WideChar* lhs, const WideChar* rhs) + { + for (Size index = 0; rhs[index] != 0; ++index) + { + if (rhs[index] != lhs[index]) + return false; + } + + return true; + } + + const Char* StringBuilder::Format(const Char* fmt, const Char* fmt2) + { + if (!fmt || !fmt2) + return ("?"); + + char* ret = + (char*)cAlloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt)); + + if (!ret) + return ("?"); + + for (Size idx = 0; idx < rt_string_len(fmt); ++idx) + { + if (fmt[idx] == '%') + { + Size result_cnt = idx; + for (Size y_idx = 0; y_idx < rt_string_len(fmt2); ++y_idx) + { + ret[result_cnt] = fmt2[y_idx]; + ++result_cnt; + } + + break; + } + + ret[idx] = fmt[idx]; + } + + return ret; + } + + STATIC void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) + { + SizeT sz_rhs = rt_string_len(rhs); + SizeT rhs_i = 0; + + for (; rhs_i < sz_rhs; ++rhs_i) + { + lhs[rhs_i + cur] = rhs[rhs_i]; + } + } + + KString& KString::operator+=(const Char* rhs) + { + rt_string_append(this->fData, rhs, this->fCur); + this->fCur += rt_string_len(rhs); + + return *this; + } + + KString& KString::operator+=(const KString& rhs) + { + if (rt_string_len(rhs.fData) > this->Length()) + return *this; + + rt_string_append(this->fData, const_cast(rhs.fData), this->fCur); + this->fCur += rt_string_len(const_cast(rhs.fData)); + + return *this; + } +} // namespace Kernel diff --git a/dev/ZKAKit/src/Network/IP.cc b/dev/ZKAKit/src/Network/IP.cc index b78009dc..0ebe19b6 100644 --- a/dev/ZKAKit/src/Network/IP.cc +++ b/dev/ZKAKit/src/Network/IP.cc @@ -90,13 +90,13 @@ namespace Kernel return true; } - ErrorOr IPFactory::ToStringView(Ref& ipv6) + ErrorOr IPFactory::ToKString(Ref& ipv6) { auto str = StringBuilder::Construct(ipv6.Leak().Address()); return str; } - ErrorOr IPFactory::ToStringView(Ref& ipv4) + ErrorOr IPFactory::ToKString(Ref& ipv4) { auto str = StringBuilder::Construct(ipv4.Leak().Address()); return str; diff --git a/dev/ZKAKit/src/Network/IPC.cc b/dev/ZKAKit/src/Network/IPC.cc index 3f69bc3c..5dd4da0b 100644 --- a/dev/ZKAKit/src/Network/IPC.cc +++ b/dev/ZKAKit/src/Network/IPC.cc @@ -63,7 +63,7 @@ namespace Kernel if (!pckt || !ipc_int_sanitize_packet(pckt)) { - UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); return false; } @@ -82,7 +82,7 @@ namespace Kernel // crash process if the packet pointer of pointer is NULL. if (!pckt_in) { - UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); return false; } @@ -102,13 +102,13 @@ namespace Kernel (*pckt_in)->IpcTo.UserProcessID = 0; (*pckt_in)->IpcTo.UserProcessTeam = 0; - (*pckt_in)->IpcFrom.UserProcessID = Kernel::UserProcessScheduler::The().CurrentProcess().Leak().ProcessId; + (*pckt_in)->IpcFrom.UserProcessID = Kernel::UserProcessScheduler::The().GetCurrentProcess().Leak().ProcessId; (*pckt_in)->IpcFrom.UserProcessTeam = Kernel::UserProcessScheduler::The().CurrentTeam().mTeamId; return true; } - UserProcessScheduler::The().CurrentProcess().Leak().Crash(); + UserProcessScheduler::The().GetCurrentProcess().Leak().Crash(); return false; } } // namespace Kernel diff --git a/dev/ZKAKit/src/PEFCodeMgr.cc b/dev/ZKAKit/src/PEFCodeMgr.cc index 21c9dc46..45a5e46c 100644 --- a/dev/ZKAKit/src/PEFCodeMgr.cc +++ b/dev/ZKAKit/src/PEFCodeMgr.cc @@ -11,7 +11,7 @@ #include #include #include -#include +#include /// @brief PEF stack size symbol. #define cPefStackSizeSymbol "SizeOfReserveStack" @@ -117,7 +117,7 @@ namespace Kernel constexpr auto cMangleCharacter = '$'; const Char* cContainerKinds[] = {".code64", ".data64", ".zero64", nullptr}; - ErrorOr error_or_symbol; + ErrorOr error_or_symbol; switch (kind) { diff --git a/dev/ZKAKit/src/PRDT.cc b/dev/ZKAKit/src/PRDT.cc index 741e932b..38077ea5 100644 --- a/dev/ZKAKit/src/PRDT.cc +++ b/dev/ZKAKit/src/PRDT.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include -#include +#include #include namespace Kernel diff --git a/dev/ZKAKit/src/Property.cc b/dev/ZKAKit/src/Property.cc index 9ee17b74..cf29b6d8 100644 --- a/dev/ZKAKit/src/Property.cc +++ b/dev/ZKAKit/src/Property.cc @@ -10,12 +10,12 @@ namespace CFKit { Property::~Property() = default; - Bool Property::StringEquals(StringView& name) + Bool Property::StringEquals(KString& name) { return this->fName && this->fName == name; } - StringView& Property::GetKey() + KString& Property::GetKey() { return this->fName; } diff --git a/dev/ZKAKit/src/Stop.cc b/dev/ZKAKit/src/Stop.cc index 51e71b72..21163278 100644 --- a/dev/ZKAKit/src/Stop.cc +++ b/dev/ZKAKit/src/Stop.cc @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/dev/ZKAKit/src/String.cc b/dev/ZKAKit/src/String.cc deleted file mode 100644 index 9ff7e9a0..00000000 --- a/dev/ZKAKit/src/String.cc +++ /dev/null @@ -1,217 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#include -#include - -/// @file String.cc -/// @brief String manipulation file. - -namespace Kernel -{ - Char* StringView::Data() - { - return fData; - } - - const Char* StringView::CData() const - { - return fData; - } - - Size StringView::Length() const - { - return fDataSz; - } - - bool StringView::operator==(const StringView& rhs) const - { - if (rhs.Length() != this->Length()) - return false; - - for (Size index = 0; index < this->Length(); ++index) - { - if (rhs.fData[index] != fData[index]) - return false; - } - - return true; - } - - bool StringView::operator==(const Char* rhs) const - { - if (rt_string_len(rhs) != this->Length()) - return false; - - for (Size index = 0; index < rt_string_len(rhs); ++index) - { - if (rhs[index] != fData[index]) - return false; - } - - return true; - } - - bool StringView::operator!=(const StringView& rhs) const - { - if (rhs.Length() != this->Length()) - return false; - - for (Size index = 0; index < rhs.Length(); ++index) - { - if (rhs.fData[index] == fData[index]) - return false; - } - - return true; - } - - bool StringView::operator!=(const Char* rhs) const - { - if (rt_string_len(rhs) != this->Length()) - return false; - - for (Size index = 0; index < rt_string_len(rhs); ++index) - { - if (rhs[index] == fData[index]) - return false; - } - - return true; - } - - ErrorOr StringBuilder::Construct(const Char* data) - { - if (!data || *data == 0) - return {}; - - StringView* view = new StringView(rt_string_len(data)); - (*view) += data; - - return ErrorOr(*view); - } - - const Char* StringBuilder::FromBool(const Char* fmt, bool i) - { - if (!fmt) - return ("?"); - - const Char* boolean_expr = i ? "YES" : "NO"; - char* ret = (char*)cAlloca((sizeof(char) * i) ? 4 : 5 + rt_string_len(fmt)); - - if (!ret) - return ("?"); - - const auto fmt_len = rt_string_len(fmt); - const auto res_len = rt_string_len(boolean_expr); - - for (Size idx = 0; idx < fmt_len; ++idx) - { - if (fmt[idx] == '%') - { - SizeT result_cnt = idx; - - for (auto y_idx = idx; y_idx < res_len; ++y_idx) - { - ret[result_cnt] = boolean_expr[y_idx]; - ++result_cnt; - } - - break; - } - - ret[idx] = fmt[idx]; - } - - return ret; - } - - bool StringBuilder::Equals(const Char* lhs, const Char* rhs) - { - if (rt_string_len(rhs) != rt_string_len(lhs)) - return false; - - for (Size index = 0; index < rt_string_len(rhs); ++index) - { - if (rhs[index] != lhs[index]) - return false; - } - - return true; - } - - bool StringBuilder::Equals(const WideChar* lhs, const WideChar* rhs) - { - for (Size index = 0; rhs[index] != 0; ++index) - { - if (rhs[index] != lhs[index]) - return false; - } - - return true; - } - - const Char* StringBuilder::Format(const Char* fmt, const Char* fmt2) - { - if (!fmt || !fmt2) - return ("?"); - - char* ret = - (char*)cAlloca(sizeof(char) * rt_string_len(fmt2) + rt_string_len(fmt)); - - if (!ret) - return ("?"); - - for (Size idx = 0; idx < rt_string_len(fmt); ++idx) - { - if (fmt[idx] == '%') - { - Size result_cnt = idx; - for (Size y_idx = 0; y_idx < rt_string_len(fmt2); ++y_idx) - { - ret[result_cnt] = fmt2[y_idx]; - ++result_cnt; - } - - break; - } - - ret[idx] = fmt[idx]; - } - - return ret; - } - - STATIC void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) - { - SizeT sz_rhs = rt_string_len(rhs); - SizeT rhs_i = 0; - - for (; rhs_i < sz_rhs; ++rhs_i) - { - lhs[rhs_i + cur] = rhs[rhs_i]; - } - } - - StringView& StringView::operator+=(const Char* rhs) - { - rt_string_append(this->fData, rhs, this->fCur); - this->fCur += rt_string_len(rhs); - - return *this; - } - - StringView& StringView::operator+=(const StringView& rhs) - { - if (rt_string_len(rhs.fData) > this->Length()) - return *this; - - rt_string_append(this->fData, const_cast(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast(rhs.fData)); - - return *this; - } -} // namespace Kernel diff --git a/dev/ZKAKit/src/ThreadLocalStorage.cc b/dev/ZKAKit/src/ThreadLocalStorage.cc index 8c75d522..83883a6c 100644 --- a/dev/ZKAKit/src/ThreadLocalStorage.cc +++ b/dev/ZKAKit/src/ThreadLocalStorage.cc @@ -7,7 +7,7 @@ * ======================================================== */ -#include +#include #include #include #include diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc index 090faf32..249033a2 100644 --- a/dev/ZKAKit/src/UserProcessScheduler.cc +++ b/dev/ZKAKit/src/UserProcessScheduler.cc @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include ///! BUGS: 0 @@ -32,7 +32,7 @@ namespace Kernel /// @brief Exit Code global variable. /***********************************************************************************/ - STATIC UInt32 cLastExitCode = 0U; + STATIC UInt32 kLastExitCode = 0U; /***********************************************************************************/ /// @brief User Process scheduler global and external reference of thread scheduler. @@ -41,12 +41,16 @@ namespace Kernel UserProcessScheduler* kProcessScheduler = nullptr; EXTERN HardwareThreadScheduler* kHardwareThreadScheduler; + UserProcess::UserProcess(VoidPtr start_image) : Image(start_image) {} + + UserProcess::~UserProcess() = default; + /// @brief Gets the last exit code. /// @note Not thread-safe. /// @return Int32 the last exit code. const UInt32& sched_get_exit_code(void) noexcept { - return cLastExitCode; + return kLastExitCode; } /***********************************************************************************/ @@ -99,7 +103,7 @@ namespace Kernel /// @brief Wake process. /***********************************************************************************/ - void UserProcess::Wake(const bool should_wakeup) + Void UserProcess::Wake(const bool should_wakeup) { this->Status = should_wakeup ? ProcessStatusKind::kRunning : ProcessStatusKind::kFrozen; @@ -109,33 +113,37 @@ namespace Kernel /** @brief Add pointer to entry. */ /***********************************************************************************/ - VoidPtr UserProcess::New(const SizeT& sz) + ErrorOr UserProcess::New(const SizeT& sz, const SizeT& pad_amount) { #ifdef __ZKA_AMD64__ - auto pd = hal_read_cr3(); + auto vm_register = hal_read_cr3(); hal_write_cr3(reinterpret_cast(this->VMRegister)); - auto ptr = mm_new_heap(sz, Yes, Yes); + auto ptr = mm_new_heap(sz + pad_amount, Yes, Yes); - hal_write_cr3(reinterpret_cast(pd)); + hal_write_cr3(reinterpret_cast(vm_register)); #else - auto ptr = mm_new_heap(sz, Yes, Yes); + auto ptr = mm_new_heap(sz + pad_amount, Yes, Yes); #endif - if (!this->MemoryEntryList) + if (!this->MemoryHeap) { - this->MemoryEntryList = new UserProcess::PROCESS_MEMORY_ENTRY(); - this->MemoryEntryList->MemoryEntry = ptr; + this->MemoryHeap = new UserProcess::USER_PROCESS_HEAP(); + + this->MemoryHeap->MemoryEntryPad = pad_amount; + this->MemoryHeap->MemoryEntrySize = sz; - this->MemoryEntryList->MemoryPrev = nullptr; - this->MemoryEntryList->MemoryNext = nullptr; + this->MemoryHeap->MemoryEntry = ptr; - return ptr; + this->MemoryHeap->MemoryPrev = nullptr; + this->MemoryHeap->MemoryNext = nullptr; + + return ErrorOr(ptr); } else { - PROCESS_MEMORY_ENTRY* entry = this->MemoryEntryList; - PROCESS_MEMORY_ENTRY* prev_entry = nullptr; + USER_PROCESS_HEAP* entry = this->MemoryHeap; + USER_PROCESS_HEAP* prev_entry = nullptr; while (!entry) { @@ -146,31 +154,31 @@ namespace Kernel entry = entry->MemoryNext; } - entry->MemoryNext = new PROCESS_MEMORY_ENTRY(); + entry->MemoryNext = new USER_PROCESS_HEAP(); entry->MemoryNext->MemoryEntry = ptr; entry->MemoryNext->MemoryPrev = entry; entry->MemoryNext->MemoryNext = nullptr; } - return nullptr; + return ErrorOr(nullptr); } /***********************************************************************************/ /** @brief Free pointer from usage. */ /***********************************************************************************/ - Boolean UserProcess::Delete(VoidPtr ptr, const SizeT& sz) + Boolean UserProcess::Delete(ErrorOr ptr, const SizeT& sz) { if (!ptr || sz == 0) return No; - PROCESS_MEMORY_ENTRY* entry = this->MemoryEntryList; + USER_PROCESS_HEAP* entry = this->MemoryHeap; while (entry != nullptr) { - if (entry->MemoryEntry == ptr) + if (entry->MemoryEntry == ptr.Leak().Leak()) { #ifdef __ZKA_AMD64__ auto pd = hal_read_cr3(); @@ -197,7 +205,7 @@ namespace Kernel /// @brief Gets the name of the current process. /***********************************************************************************/ - const Char* UserProcess::GetProcessName() noexcept + const Char* UserProcess::GetName() noexcept { return this->Name; } @@ -239,9 +247,9 @@ namespace Kernel this->Status = ProcessStatusKind::kDead; fLastExitCode = exit_code; - cLastExitCode = exit_code; + kLastExitCode = exit_code; - auto memory_list = this->MemoryEntryList; + auto memory_list = this->MemoryHeap; // Deleting memory lists. Make sure to free all of them. while (memory_list) @@ -302,7 +310,7 @@ namespace Kernel } /***********************************************************************************/ - /// @brief Add process to list. + /// @brief Add process to team. /// @param process the process *Ref* class. /// @return the process index inside the team. /***********************************************************************************/ @@ -316,7 +324,7 @@ namespace Kernel process.VMRegister = reinterpret_cast(HAL::mm_alloc_bitmap(Yes, Yes, sizeof(PDE), Yes)); #endif // __ZKA_AMD64__ - process.StackFrame = (HAL::StackFramePtr)mm_new_heap(sizeof(HAL::StackFrame), Yes, Yes); + process.StackFrame = reinterpret_cast(mm_new_heap(sizeof(HAL::StackFrame), Yes, Yes)); if (!process.StackFrame) { @@ -339,9 +347,9 @@ namespace Kernel } } - // get preferred stack size by app. + // Get preferred stack size by app. const auto cMaxStackSize = process.StackSize; - process.StackReserve = (UInt8*)mm_new_heap(sizeof(UInt8) * cMaxStackSize, Yes, Yes); + process.StackReserve = reinterpret_cast(mm_new_heap(sizeof(UInt8) * cMaxStackSize, Yes, Yes)); if (!process.StackReserve) { @@ -369,6 +377,14 @@ namespace Kernel return *kProcessScheduler; } + ErrorOr UserProcessScheduler::TheSafe() + { + if (!kProcessScheduler) + return ErrorOr(nullptr); + + return ErrorOr(kProcessScheduler); + } + /***********************************************************************************/ /// @brief Remove process from list. @@ -413,7 +429,7 @@ namespace Kernel /***********************************************************************************/ - SizeT UserProcessScheduler::Run() noexcept + const SizeT UserProcessScheduler::Run() noexcept { SizeT process_index = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. @@ -433,13 +449,13 @@ namespace Kernel { process.PTime = static_cast(process.Affinity); - UserProcessScheduler::The().CurrentProcess().Leak().Status = ProcessStatusKind::kFrozen; - UserProcessScheduler::The().CurrentProcess() = process; + UserProcessScheduler::The().GetCurrentProcess().Leak().Status = ProcessStatusKind::kFrozen; + UserProcessScheduler::The().GetCurrentProcess() = process; kcout << "Switch to '" << process.Name << "'.\r"; // Set current process header. - this->CurrentProcess() = process; + this->GetCurrentProcess() = process; // tell helper to find a core to schedule on. if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize], process.StackFrame, @@ -471,7 +487,7 @@ namespace Kernel /// @brief Gets current running process. /// @return - Ref& UserProcessScheduler::CurrentProcess() + Ref& UserProcessScheduler::GetCurrentProcess() { return mTeam.AsRef(); } @@ -481,7 +497,7 @@ namespace Kernel PID& UserProcessHelper::TheCurrentPID() { kcout << "UserProcessHelper::TheCurrentPID: Leaking ProcessId...\r"; - return kProcessScheduler->CurrentProcess().Leak().ProcessId; + return kProcessScheduler->GetCurrentProcess().Leak().ProcessId; } /// @brief Check if process can be schedulded. diff --git a/zka-dev.files b/zka-dev.files index fde0f1b2..88bf2e46 100644 --- a/zka-dev.files +++ b/zka-dev.files @@ -221,6 +221,7 @@ dev/ZKAKit/NewKit/Defines.h dev/ZKAKit/NewKit/ErrorOr.h dev/ZKAKit/NewKit/Function.h dev/ZKAKit/NewKit/Json.h +dev/ZKAKit/NewKit/KString.h dev/ZKAKit/NewKit/Macros.h dev/ZKAKit/NewKit/MutableArray.h dev/ZKAKit/NewKit/New.h @@ -232,7 +233,6 @@ dev/ZKAKit/NewKit/Pmm.h dev/ZKAKit/NewKit/Ref.h dev/ZKAKit/NewKit/Stop.h dev/ZKAKit/NewKit/Stream.h -dev/ZKAKit/NewKit/String.h dev/ZKAKit/NewKit/Utils.h dev/ZKAKit/NewKit/Variant.h dev/ZKAKit/StorageKit/AHCI.h @@ -266,6 +266,7 @@ dev/ZKAKit/src/IDLLObject.cc dev/ZKAKit/src/IPEFDLLObject.cc dev/ZKAKit/src/IndexableProperty.cc dev/ZKAKit/src/Json.cc +dev/ZKAKit/src/KString.cc dev/ZKAKit/src/LPC.cc dev/ZKAKit/src/LockDelegate.cc dev/ZKAKit/src/MutableArray.cc @@ -289,7 +290,6 @@ dev/ZKAKit/src/Storage/ATADeviceInterface.cc dev/ZKAKit/src/Storage/NVMEDeviceInterface.cc dev/ZKAKit/src/Storage/SCSIDeviceInterface.cc dev/ZKAKit/src/Stream.cc -dev/ZKAKit/src/String.cc dev/ZKAKit/src/ThreadLocalStorage.cc dev/ZKAKit/src/Timer.cc dev/ZKAKit/src/User.cc -- cgit v1.2.3