diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-25 10:28:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-25 10:28:07 +0200 |
| commit | 1057fd299e17fcc04f6b3a1aa3ace1026f8652a0 (patch) | |
| tree | a663c7dcd26779295ce0d9681418964f802f2d14 /dev/kernel/src | |
| parent | 1a32b9307357ac0fc9095e853b2b6d94f9fe62bb (diff) | |
| parent | 328b34360ab8b2462ea5858441693277b3d23f08 (diff) | |
Merge pull request #56 from nekernel-org/dev
Errata: v0.0.4
Diffstat (limited to 'dev/kernel/src')
| -rw-r--r-- | dev/kernel/src/ACPIFactoryInterface.cc | 7 | ||||
| -rw-r--r-- | dev/kernel/src/AsciiUtils.cc | 3 | ||||
| -rw-r--r-- | dev/kernel/src/BinaryMutex.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS+FileSystemParser.cc | 8 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS+FileSystemParser.cc | 6 | ||||
| -rw-r--r-- | dev/kernel/src/IndexableProperty.cc | 16 | ||||
| -rw-r--r-- | dev/kernel/src/KString.cc | 180 | ||||
| -rw-r--r-- | dev/kernel/src/Network/IPAddress.cc (renamed from dev/kernel/src/Network/IPAddr.cc) | 5 | ||||
| -rw-r--r-- | dev/kernel/src/Network/IPCAddress.cc (renamed from dev/kernel/src/Network/IPCAddr.cc) | 0 | ||||
| -rw-r--r-- | dev/kernel/src/Network/IPCMessage.cc (renamed from dev/kernel/src/Network/IPCMsg.cc) | 6 | ||||
| -rw-r--r-- | dev/kernel/src/Property.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/src/UserProcessScheduler.cc | 16 | ||||
| -rw-r--r-- | dev/kernel/src/UtfUtils.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/src/ZXD.cc | 7 |
14 files changed, 44 insertions, 218 deletions
diff --git a/dev/kernel/src/ACPIFactoryInterface.cc b/dev/kernel/src/ACPIFactoryInterface.cc index 01f30500..b4ac03cc 100644 --- a/dev/kernel/src/ACPIFactoryInterface.cc +++ b/dev/kernel/src/ACPIFactoryInterface.cc @@ -70,11 +70,11 @@ ErrorOr<voidPtr> ACPIFactoryInterface::Find(const Char* signature) { @param len the length of it. */ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) { - if (len == 0) return 1; + if (len == 0 || !checksum) return false; - char chr = 0; + Char chr = 0; - for (int index = 0; index < len; ++index) { + for (SSizeT index = 0L; index < len; ++index) { chr += checksum[index]; } @@ -82,6 +82,7 @@ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) { } ErrorOr<voidPtr> ACPIFactoryInterface::operator[](const Char* signature) { + if (!signature) return ErrorOr<voidPtr>{-kErrorInvalidData}; return this->Find(signature); } } // namespace Kernel diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 66a4aaef..24e4e220 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -73,7 +73,8 @@ Void rt_zero_memory(voidPtr pointer, Size len) { #ifdef __NE_ENFORCE_DEPRECATED_WARNINGS [[deprecated("Use rt_set_memory_safe instead")]] #endif -voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len) { +voidPtr +rt_set_memory(voidPtr src, UInt32 value, Size len) { if (!src) return nullptr; auto p = reinterpret_cast<UInt8*>(src); UInt8 v = static_cast<UInt8>(value & 0xFF); diff --git a/dev/kernel/src/BinaryMutex.cc b/dev/kernel/src/BinaryMutex.cc index 9bfb89d9..3fef477c 100644 --- a/dev/kernel/src/BinaryMutex.cc +++ b/dev/kernel/src/BinaryMutex.cc @@ -46,7 +46,7 @@ Bool BinaryMutex::IsLocked() const { /// @brief Try lock or wait. /***********************************************************************************/ -Bool BinaryMutex::LockOrWait(USER_PROCESS* process, TimerInterface* timer) { +Bool BinaryMutex::LockAndWait(USER_PROCESS* process, TimerInterface* timer) { if (timer == nullptr) return No; this->Lock(process); diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 344369d5..f1531b4c 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -91,14 +91,14 @@ namespace Detail { STATIC UInt64 hefsi_hash_64(const Utf8Char* path) { if (!path || *path == 0) return 0; - const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; - const UInt64 FNV_PRIME = 0x100000001b3ULL; + const UInt64 kFnvBaseOffset = 0xcbf29ce484222325ULL; + const UInt64 kFnvPrimeNumber = 0x100000001b3ULL; - UInt64 hash = FNV_OFFSET_BASIS; + UInt64 hash = kFnvBaseOffset; while (*path) { hash ^= (Utf8Char) (*path++); - hash *= FNV_PRIME; + hash *= kFnvPrimeNumber; } return hefsi_to_big_endian_64(hash); diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 7b9ebcd6..14e0b974 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -154,8 +154,8 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) { /// @return the newly found fork. /***********************************************************************************/ _Output NEFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NEFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - _Input Boolean is_data) { + _Input const Char* name, + _Input Boolean is_data) { if (!catalog || !name) return nullptr; auto& drive = kMountpoint.A(); @@ -217,7 +217,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char /// @param kind the catalog kind. /// @return catalog pointer. /***********************************************************************************/ -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) { kout << "CreateCatalog(*...*)\r"; diff --git a/dev/kernel/src/IndexableProperty.cc b/dev/kernel/src/IndexableProperty.cc index 251d6645..c11e328d 100644 --- a/dev/kernel/src/IndexableProperty.cc +++ b/dev/kernel/src/IndexableProperty.cc @@ -18,21 +18,13 @@ namespace Kernel { namespace Indexer { - Index& IndexableProperty::Leak() noexcept { - return fIndex; - } + Index& IndexableProperty::Leak() noexcept { return fIndex; } - Void IndexableProperty::AddFlag(Int16 flag) { - fFlags |= flag; - } + Void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } - Void IndexableProperty::RemoveFlag(Int16 flag) { - fFlags &= flag; - } + Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } - Int16 IndexableProperty::HasFlag(Int16 flag) { - return fFlags & flag; - } + Int16 IndexableProperty::HasFlag(Int16 flag) { return fFlags & flag; } /// @brief Index a file into the indexer instance. /// @param filename filesystem path to access. diff --git a/dev/kernel/src/KString.cc b/dev/kernel/src/KString.cc deleted file mode 100644 index f5732280..00000000 --- a/dev/kernel/src/KString.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include <NeKit/KString.h> -#include <NeKit/Utils.h> - -/// @file KString.cc -/// @brief Kernel String manipulation file. - -namespace Kernel { -Char* KString::Data() { - return this->fData; -} - -const Char* KString::CData() const { - return const_cast<const Char*>(this->fData); -} - -Size KString::Length() const { - return this->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] != this->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] != this->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] == this->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] == this->fData[index]) return false; - } - - return true; -} - -ErrorOr<KString> KStringBuilder::Construct(const Char* data) { - if (!data || *data == 0) return ErrorOr<KString>(new KString(0)); - - KString* view = new KString(rt_string_len(data)); - (*view) += data; - - return ErrorOr<KString>(*view); -} - -const Char* KStringBuilder::FromBool(const Char* fmt, bool i) { - if (!fmt) return ("?"); - - const Char* boolean_expr = i ? "YES" : "NO"; - Char* ret = (Char*) RTL_ALLOCA(rt_string_len(boolean_expr) + 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 KStringBuilder::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; -} - -/// @note This is unsafe!!! -bool KStringBuilder::Equals(const Utf8Char* lhs, const Utf8Char* rhs) { - for (Size index = 0; index < urt_string_len(rhs); ++index) { - if (rhs[index] != lhs[index]) return false; - } - - return true; -} - -bool KStringBuilder::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* KStringBuilder::Format(const Char* fmt, const Char* fmt2) { - if (!fmt || !fmt2) return ("?"); - - Char* ret = (Char*) RTL_ALLOCA(sizeof(char) * (rt_string_len(fmt2) + rt_string_len(fmt))); - - if (!ret) return ("?"); - - const auto len = rt_string_len(fmt); - - for (Size idx = 0; idx < len; ++idx) { - if (fmt[idx] == '%' && idx < rt_string_len(fmt) && fmt[idx] == 's') { - 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; - } - } - - 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<Char*>(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast<Char*>(rhs.fData)); - - return *this; -} -} // namespace Kernel diff --git a/dev/kernel/src/Network/IPAddr.cc b/dev/kernel/src/Network/IPAddress.cc index ec7d8a35..b02eae08 100644 --- a/dev/kernel/src/Network/IPAddr.cc +++ b/dev/kernel/src/Network/IPAddress.cc @@ -91,11 +91,14 @@ bool IPFactory::IpCheckVersion4(const Char* ip) { Int32 cnter = 0; Int32 dot_cnter = 0; + constexpr const auto kIP4DotCharacter = '.'; + for (SizeT base = 0; base < rt_string_len(ip); ++base) { - if (ip[base] == '.') { + if (ip[base] == kIP4DotCharacter) { cnter = 0; ++dot_cnter; } else { + if (ip[base] > '5' || ip[base] < '0') return NO; if (!rt_is_alnum(ip[base])) return NO; if (cnter == 3) return NO; diff --git a/dev/kernel/src/Network/IPCAddr.cc b/dev/kernel/src/Network/IPCAddress.cc index 4c1dd500..4c1dd500 100644 --- a/dev/kernel/src/Network/IPCAddr.cc +++ b/dev/kernel/src/Network/IPCAddress.cc diff --git a/dev/kernel/src/Network/IPCMsg.cc b/dev/kernel/src/Network/IPCMessage.cc index 9abefcef..6f8223f7 100644 --- a/dev/kernel/src/Network/IPCMsg.cc +++ b/dev/kernel/src/Network/IPCMessage.cc @@ -105,10 +105,12 @@ Bool IPC_MSG::Pass(IPC_MSG* src, IPC_MSG* target) noexcept { if (src->IpcMsgSz > target->IpcMsgSz) return No; if (target->IpcMsgSz > src->IpcMsgSz) return No; - UInt32 timeout = 0U; + auto timeout = 0U; + + const auto kLimitTimeout = 1000000U; while ((target->IpcLock % kIPCLockUsed) != 0) { - if (timeout > 100000U) { + if (timeout > kLimitTimeout) { return No; } } diff --git a/dev/kernel/src/Property.cc b/dev/kernel/src/Property.cc index 62aa6ef2..581da501 100644 --- a/dev/kernel/src/Property.cc +++ b/dev/kernel/src/Property.cc @@ -21,14 +21,14 @@ Property::Property() = default; /// @brief Check if property's name equals to name. /// @param name string to check. /***********************************************************************************/ -Bool Property::StringEquals(KString& name) { +Bool Property::StringEquals(BasicKString<>& name) { return this->fName && this->fName == name; } /***********************************************************************************/ /// @brief Gets the key (name) of property. /***********************************************************************************/ -KString& Property::GetKey() { +BasicKString<>& Property::GetKey() { return this->fName; } diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 45957c7b..19e509ed 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -122,7 +122,7 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { hal_write_cr3(vm_register); #else - auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); + auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); #endif if (!this->HeapTree) { @@ -265,7 +265,6 @@ STATIC Void sched_free_ptr_tree(T* tree) { Void USER_PROCESS::Exit(const Int32& exit_code) { this->Status = exit_code > 0 ? ProcessStatusKind::kKilled : ProcessStatusKind::kFrozen; this->LastExitCode = exit_code; - this->UTime = 0; #ifdef __NE_VIRTUAL_MEMORY_SUPPORT__ auto pd = kKernelVM; @@ -424,6 +423,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im process.ProcessId = pid; process.Status = ProcessStatusKind::kRunning; process.PTime = 0; + process.UTime = 0; process.RTime = 0; if (!process.FileTree) { @@ -437,7 +437,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im /// @todo File Tree allocation and dispose methods (amlal) } - (Void)(kout << "PID: " << number(process.ProcessId) << kendl); + (Void)(kout << "ProcessID: " << number(process.ProcessId) << kendl); (Void)(kout << "Name: " << process.Name << kendl); return pid; @@ -573,11 +573,11 @@ Ref<USER_PROCESS>& UserProcessScheduler::TheCurrentProcess() { /// @brief Current proccess id getter. /// @return USER_PROCESS ID integer. -ErrorOr<PID> UserProcessHelper::TheCurrentPID() { - if (!UserProcessScheduler::The().TheCurrentProcess()) return ErrorOr<PID>{-kErrorProcessFault}; +ErrorOr<ProcessID> UserProcessHelper::TheCurrentPID() { + if (!UserProcessScheduler::The().TheCurrentProcess()) return ErrorOr<ProcessID>{-kErrorProcessFault}; kout << "UserProcessHelper::TheCurrentPID: Leaking ProcessId...\r"; - return ErrorOr<PID>{UserProcessScheduler::The().TheCurrentProcess().Leak().ProcessId}; + return ErrorOr<ProcessID>{UserProcessScheduler::The().TheCurrentProcess().Leak().ProcessId}; } /// @brief Check if process can be schedulded. @@ -613,11 +613,11 @@ SizeT UserProcessHelper::StartScheduling() { /** * \brief Does a context switch in a CPU. * \param the_stack the stackframe of the running app. - * \param new_pid the process's PID. + * \param new_pid the process's ProcessID. */ /***********************************************************************************/ -Bool UserProcessHelper::Switch(HAL::StackFramePtr frame_ptr, PID new_pid) { +Bool UserProcessHelper::Switch(HAL::StackFramePtr frame_ptr, ProcessID new_pid) { (Void)(kout << "IP: " << hex_number(frame_ptr->IP) << kendl); for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc index a5c03b85..907632ad 100644 --- a/dev/kernel/src/UtfUtils.cc +++ b/dev/kernel/src/UtfUtils.cc @@ -27,7 +27,7 @@ Void urt_set_memory(const voidPtr src, UInt32 dst, Size len) { } } -Int32 rt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { +Int32 urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { Int32 counter = 0; for (Size index = 0; index < size; ++index) { diff --git a/dev/kernel/src/ZXD.cc b/dev/kernel/src/ZXD.cc new file mode 100644 index 00000000..8ca6bbf7 --- /dev/null +++ b/dev/kernel/src/ZXD.cc @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include <KernelKit/ZXD.h> |
