diff options
Diffstat (limited to 'dev')
37 files changed, 183 insertions, 151 deletions
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 <NewKit/Defines.h>
-#include <NewKit/String.h>
+#include <NewKit/KString.h>
/// @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 <NewKit/ErrorOr.h> #include <NewKit/Ref.h> #include <NewKit/Stream.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> namespace CFKit::XRN::Version1 { using namespace Kernel; Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq); - ErrorOr<Ref<Kernel::StringView>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid); + ErrorOr<Ref<Kernel::KString>> cf_try_guid_to_string(Ref<GUIDSequence*>& 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 <NewKit/Array.h> #include <NewKit/Defines.h> #include <NewKit/Function.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #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 <Modules/ACPI/ACPIFactoryInterface.h> #include <HALKit/AMD64/Processor.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <ArchKit/ArchKit.h> #include <KernelKit/Heap.h> 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 <ArchKit/ArchKit.h> #include <KernelKit/UserProcessScheduler.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> 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 <Modules/ACPI/ACPIFactoryInterface.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <ArchKit/ArchKit.h> #include <KernelKit/Heap.h> #include <Modules/APM/APM.h> 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 <KernelKit/DeviceMgr.h> #include <KernelKit/LPC.h> #include <NewKit/Defines.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <NewKit/Ref.h> #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 <KernelKit/PE.h> #include <NewKit/ErrorOr.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> 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 <KernelKit/PEF.h> #include <NewKit/ErrorOr.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <KernelKit/FileMgr.h> #define kPefApplicationMime "application/vnd-zka-executable" @@ -52,7 +52,7 @@ namespace Kernel OwnPtr<FileStream<Char>> fFile; #endif // __FSKIT_INCLUDES_NEFS__ - Ref<StringView> fPath; + Ref<KString> 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<T*>(pointer.Leak().Leak()); } //! @brief TLS delete implementation. @@ -28,21 +32,21 @@ template <typename T> 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 <typename T, typename... Args> 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 <CompilerKit/CompilerKit.h> #include <KernelKit/LPC.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <NewKit/Defines.h> // 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<VoidPtr> 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<VoidPtr> 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<UserProcess>& CurrentProcess(); - SizeT Run() noexcept; + Ref<UserProcess>& GetCurrentProcess(); + const SizeT Run() noexcept; public: + STATIC ErrorOr<UserProcessScheduler> 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 <KernelKit/DebugOutput.h> #include <NewKit/Defines.h> #include <NewKit/Ref.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> namespace Kernel { @@ -76,8 +76,8 @@ namespace Kernel class IPFactory final { public: - static ErrorOr<StringView> ToStringView(Ref<RawIPAddress6>& ipv6); - static ErrorOr<StringView> ToStringView(Ref<RawIPAddress>& ipv4); + static ErrorOr<KString> ToKString(Ref<RawIPAddress6>& ipv6); + static ErrorOr<KString> ToKString(Ref<RawIPAddress>& 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 <NewKit/Defines.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <HintKit/CompilerHint.h> #include <CompressKit/RLE.h> 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 <NewKit/Array.h> #include <NewKit/Defines.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> namespace Kernel { @@ -22,7 +22,7 @@ namespace Kernel explicit MacAddressGetter() = default; public: - StringView& AsString(); + KString& AsString(); Array<WideChar, 12>& 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 <CompilerKit/CompilerKit.h> #include <NewKit/Defines.h> #include <NewKit/Stream.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <NewKit/Utils.h> #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/String.h b/dev/ZKAKit/NewKit/KString.h index 8e77b61b..65ab13e5 100644 --- a/dev/ZKAKit/NewKit/String.h +++ b/dev/ZKAKit/NewKit/KString.h @@ -16,11 +16,11 @@ namespace Kernel { - /// @brief StringView class, using dynamic or static memory. - class StringView final + /// @brief KString static string class. + class KString final { public: - explicit StringView() + explicit KString() { fDataSz = cMinimumStringSize; @@ -30,7 +30,7 @@ namespace Kernel rt_set_memory(fData, 0, fDataSz); } - explicit StringView(const SizeT& Sz) + explicit KString(const SizeT& Sz) : fDataSz(Sz) { MUST_PASS(Sz > 1); @@ -41,13 +41,16 @@ namespace Kernel rt_set_memory(fData, 0, Sz); } - ~StringView() + ~KString() { if (fData) + { delete[] fData; + fData = nullptr; + } } - ZKA_COPY_DEFAULT(StringView); + ZKA_COPY_DEFAULT(KString); Char* Data(); const Char* CData() const; @@ -56,11 +59,11 @@ namespace Kernel bool operator==(const Char* rhs) const; bool operator!=(const Char* rhs) const; - bool operator==(const StringView& rhs) const; - bool operator!=(const StringView& rhs) const; + bool operator==(const KString& rhs) const; + bool operator!=(const KString& rhs) const; - StringView& operator+=(const Char* rhs); - StringView& operator+=(const StringView& rhs); + KString& operator+=(const Char* rhs); + KString& operator+=(const KString& rhs); operator bool() { @@ -82,7 +85,7 @@ namespace Kernel struct StringBuilder final { - static ErrorOr<StringView> Construct(const Char* data); + static ErrorOr<KString> 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); 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/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 <NewKit/Defines.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <NewKit/Json.h> 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 <Modules/ACPI/ACPIFactoryInterface.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <ArchKit/ArchKit.h> #include <KernelKit/Heap.h> 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 <KernelKit/LPC.h> #include <NewKit/Crc32.h> #include <NewKit/Stop.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <NewKit/Utils.h> #include <FirmwareKit/EPM.h> #include <KernelKit/UserProcessScheduler.h> 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<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> + auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<KString>> { Char buf[kUUIDSize]; @@ -65,8 +65,8 @@ namespace CFKit::XRN::Version1 auto view = StringBuilder::Construct(buf); if (view) - return ErrorOr<Ref<StringView>>{view.Leak()}; + return ErrorOr<Ref<KString>>{view.Leak()}; - return ErrorOr<Ref<StringView>>{-1}; + return ErrorOr<Ref<KString>>{-1}; } } // namespace CFKit::XRN::Version1 diff --git a/dev/ZKAKit/src/String.cc b/dev/ZKAKit/src/KString.cc index 9ff7e9a0..4f1ab7ba 100644 --- a/dev/ZKAKit/src/String.cc +++ b/dev/ZKAKit/src/KString.cc @@ -4,30 +4,30 @@ ------------------------------------------- */ -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <NewKit/Utils.h> -/// @file String.cc -/// @brief String manipulation file. +/// @file KString.cc +/// @brief Kernel String manipulation file. namespace Kernel { - Char* StringView::Data() + Char* KString::Data() { return fData; } - const Char* StringView::CData() const + const Char* KString::CData() const { return fData; } - Size StringView::Length() const + Size KString::Length() const { return fDataSz; } - bool StringView::operator==(const StringView& rhs) const + bool KString::operator==(const KString& rhs) const { if (rhs.Length() != this->Length()) return false; @@ -41,7 +41,7 @@ namespace Kernel return true; } - bool StringView::operator==(const Char* rhs) const + bool KString::operator==(const Char* rhs) const { if (rt_string_len(rhs) != this->Length()) return false; @@ -55,7 +55,7 @@ namespace Kernel return true; } - bool StringView::operator!=(const StringView& rhs) const + bool KString::operator!=(const KString& rhs) const { if (rhs.Length() != this->Length()) return false; @@ -69,7 +69,7 @@ namespace Kernel return true; } - bool StringView::operator!=(const Char* rhs) const + bool KString::operator!=(const Char* rhs) const { if (rt_string_len(rhs) != this->Length()) return false; @@ -83,15 +83,15 @@ namespace Kernel return true; } - ErrorOr<StringView> StringBuilder::Construct(const Char* data) + ErrorOr<KString> StringBuilder::Construct(const Char* data) { if (!data || *data == 0) return {}; - StringView* view = new StringView(rt_string_len(data)); + KString* view = new KString(rt_string_len(data)); (*view) += data; - return ErrorOr<StringView>(*view); + return ErrorOr<KString>(*view); } const Char* StringBuilder::FromBool(const Char* fmt, bool i) @@ -196,7 +196,7 @@ namespace Kernel } } - StringView& StringView::operator+=(const Char* rhs) + KString& KString::operator+=(const Char* rhs) { rt_string_append(this->fData, rhs, this->fCur); this->fCur += rt_string_len(rhs); @@ -204,7 +204,7 @@ namespace Kernel return *this; } - StringView& StringView::operator+=(const StringView& rhs) + KString& KString::operator+=(const KString& rhs) { if (rt_string_len(rhs.fData) > this->Length()) return *this; 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<StringView> IPFactory::ToStringView(Ref<RawIPAddress6>& ipv6) + ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress6>& ipv6) { auto str = StringBuilder::Construct(ipv6.Leak().Address()); return str; } - ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress>& ipv4) + ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress>& 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 <NewKit/Defines.h> #include <NewKit/Stop.h> #include <NewKit/OwnPtr.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> /// @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<StringView> error_or_symbol; + ErrorOr<KString> 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 <KernelKit/DebugOutput.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <StorageKit/PRDT.h> 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 <ArchKit/ArchKit.h> #include <KernelKit/Timer.h> #include <KernelKit/DebugOutput.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <FirmwareKit/Handover.h> #include <KernelKit/FileMgr.h> #include <Modules/FB/FB.h> 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 <NewKit/String.h> +#include <NewKit/KString.h> #include <CFKit/Property.h> #include <KernelKit/UserProcessScheduler.h> #include <KernelKit/ThreadLocalStorage.h> 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 <KernelKit/IPEFDLLObject.h> #include <KernelKit/HardwareThreadScheduler.h> #include <KernelKit/Heap.h> -#include <NewKit/String.h> +#include <NewKit/KString.h> #include <KernelKit/LPC.h> ///! 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<VoidPtr> 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<VoidPtr>(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<VoidPtr>(pd)); + hal_write_cr3(reinterpret_cast<VoidPtr>(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<VoidPtr>(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<VoidPtr>(nullptr); } /***********************************************************************************/ /** @brief Free pointer from usage. */ /***********************************************************************************/ - Boolean UserProcess::Delete(VoidPtr ptr, const SizeT& sz) + Boolean UserProcess::Delete(ErrorOr<VoidPtr> 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<UIntPtr>(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<HAL::StackFramePtr>(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<UInt8*>(mm_new_heap(sizeof(UInt8) * cMaxStackSize, Yes, Yes)); if (!process.StackReserve) { @@ -369,6 +377,14 @@ namespace Kernel return *kProcessScheduler; } + ErrorOr<UserProcessScheduler> UserProcessScheduler::TheSafe() + { + if (!kProcessScheduler) + return ErrorOr<UserProcessScheduler>(nullptr); + + return ErrorOr<UserProcessScheduler>(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<Int32>(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<UserProcess>& UserProcessScheduler::CurrentProcess() + Ref<UserProcess>& 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. |
