diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 19:29:04 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 19:29:04 +0100 |
| commit | 0511c53e648e5f253cd9e83c9e211aa6600db377 (patch) | |
| tree | 84cabfcb7c3b77d554c6c217ff32c1c5c39d74d5 /dev/ZKAKit/src | |
| parent | d5c125378d54ceaad7e34e8bac337d9b4665573e (diff) | |
META: Bumping source code.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/src')
| -rw-r--r-- | dev/ZKAKit/src/ACPIFactoryInterface.cc | 2 | ||||
| -rw-r--r-- | dev/ZKAKit/src/FS/NeFS.cc | 2 | ||||
| -rw-r--r-- | dev/ZKAKit/src/GUIDWizard.cc | 6 | ||||
| -rw-r--r-- | dev/ZKAKit/src/KString.cc (renamed from dev/ZKAKit/src/String.cc) | 30 | ||||
| -rw-r--r-- | dev/ZKAKit/src/Network/IP.cc | 4 | ||||
| -rw-r--r-- | dev/ZKAKit/src/Network/IPC.cc | 8 | ||||
| -rw-r--r-- | dev/ZKAKit/src/PEFCodeMgr.cc | 4 | ||||
| -rw-r--r-- | dev/ZKAKit/src/PRDT.cc | 2 | ||||
| -rw-r--r-- | dev/ZKAKit/src/Property.cc | 4 | ||||
| -rw-r--r-- | dev/ZKAKit/src/Stop.cc | 2 | ||||
| -rw-r--r-- | dev/ZKAKit/src/ThreadLocalStorage.cc | 2 | ||||
| -rw-r--r-- | dev/ZKAKit/src/UserProcessScheduler.cc | 86 |
12 files changed, 84 insertions, 68 deletions
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. |
