From f2b53fc242000c0f65aa09db3250ecf97dce6035 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 18 Jun 2025 10:16:05 +0200 Subject: feat: Fix `ProcessLevelRing` enum value `kRingCount` Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index c06ef92c..f64cbf22 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -180,7 +180,7 @@ enum class ProcessLevelRing : Int32 { kRingStdUser = 1, kRingSuperUser = 2, kRingGuestUser = 5, - kRingCount = 5, + kRingCount = 3, }; /***********************************************************************************/ -- cgit v1.2.3 From 42301b6977bf11f8d5b55c6ca8c08b97a2b4cc3c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 18 Jun 2025 10:26:27 +0200 Subject: PEF format update `5.0` and codebase refactors. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/PEF.h | 14 ++++++++------ dev/kernel/src/PEFCodeMgr.cc | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index c28c8f8c..a357e827 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -18,12 +18,12 @@ #include #include -#define kPefMagic "Joy!" -#define kPefMagicFat "yoJ!" +#define kPefMagic "Open" +#define kPefMagicFat "nepO" #define kPefMagicLen (5) -#define kPefVersion (4) +#define kPefVersion (0x0500) #define kPefNameLen (256U) /* not mandatory, only for non fork based filesystems. */ @@ -59,10 +59,10 @@ enum { }; enum { + kPefSubArchGeneric, kPefSubArchAMD = 200, kPefSubArchIntel, kPefSubArchARM, - kPefSubArchGeneric, kPefSubArchIBM, }; @@ -98,15 +98,17 @@ typedef struct PEFCommandHeader final { UInt32 Flags; /* container flags */ UInt16 Kind; /* container kind */ UIntPtr Offset; /* content offset */ - UIntPtr VMAddress; /* VM offset */ - SizeT Size; /* content Size */ + UIntPtr VMAddress; /* Virtual Address */ + SizeT VMSize; /* Virtual Size */ } PACKED PEFCommandHeader; enum { + kPefInvalid = 0x0, kPefCode = 0xC, kPefData = 0xD, kPefZero = 0xE, kPefLinkerID = 0x1, + kPefCount = 4, }; } // namespace Kernel diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index ed72473f..f572fe99 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -152,10 +152,10 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { } } - Char* container_blob_value = new Char[container_header->Size]; + Char* container_blob_value = new Char[container_header->VMSize]; rt_copy_memory((VoidPtr) ((Char*) blob + sizeof(PEFCommandHeader)), container_blob_value, - container_header->Size); + container_header->VMSize); mm_free_ptr(blob); kout << "PEFLoader: Information: Loaded stub: " << container_header->Name << "!\r"; -- cgit v1.2.3 From d432898acdc4cebae81bff06f2c954f7165ebeb5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 25 Jun 2025 10:03:49 +0200 Subject: fix: PEF format fixes. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/PEF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index a357e827..ed6fc423 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -54,7 +54,7 @@ enum { kPefArch32x0, /* 32x0. ISA */ kPefArchPowerPC, kPefArchARM64, - kPefArchCount = (kPefArchPowerPC - kPefArchIntel86S) + 1, + kPefArchCount = (kPefArchARM64 - kPefArchIntel86S) + 1, kPefArchInvalid = 0xFF, }; -- cgit v1.2.3 From b3c3b0f62331a695fb7c90c386c15396b6607575 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 30 Jun 2025 10:36:15 +0200 Subject: feat: Introducing `FileTree` allocation and WiP DebugSrv integration. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/DebugOutput.h | 12 ++---------- dev/kernel/KernelKit/UserProcessScheduler.h | 2 +- dev/kernel/src/UserProcessScheduler.cc | 11 +++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index de3bc997..87649406 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -12,7 +12,7 @@ #include #include -#define kDebugUnboundPort 0x0FEED +#define kDebugPort (51820U) #define kDebugMag0 'K' #define kDebugMag1 'D' @@ -27,7 +27,7 @@ namespace Kernel { class TerminalDevice; class DTraceDevice; -class DebugDevice; +class NeDebugDevice; class Utf8TerminalDevice; inline TerminalDevice end_line(); @@ -184,14 +184,6 @@ inline constexpr SizeT kDebugTypeLen = 256U; typedef Char rt_debug_type[kDebugTypeLen]; -/// @brief KDBG's packet header. -class KernelDebugHeader final { - public: - Int16 fPort; - Int16 fPortKind; - rt_debug_type fPortBlob; -}; - inline TerminalDevice& operator<<(TerminalDevice& src, const Long& num) { src = number(num); return src; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 5bc5b8d2..ebe8d1cd 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -62,7 +62,7 @@ class USER_PROCESS final { }; USER_PROCESS_SIGNAL Signal; - PROCESS_FILE_TREE* FileTree{nullptr}; + PROCESS_FILE_TREE* FileTree{nullptr}; PROCESS_HEAP_TREE* HeapTree{nullptr}; UserProcessTeam* ParentTeam; diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 94099c0a..621c848b 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -124,6 +124,17 @@ ErrorOr USER_PROCESS::New(SizeT sz, SizeT pad_amount) { auto ptr = mm_alloc_ptr(sz, Yes, Yes, pad_amount); #endif + if (!this->FileTree) { + this->FileTree = new PROCESS_FILE_TREE(); + + if (!this->FileTree) { + this->Crash(); + return ErrorOr(-kErrorHeapOutOfMemory); + } + + /// @todo File Tree allocation and dispose methods (amlal) + } + if (!this->HeapTree) { this->HeapTree = new PROCESS_HEAP_TREE(); -- cgit v1.2.3 From 65350ab87ab7d577cd6d85bc6e9727beef5ee737 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 5 Jul 2025 10:19:51 +0200 Subject: feat: Document `SpawnDylib` Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/UserProcessScheduler.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index ebe8d1cd..8a730233 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -93,6 +93,9 @@ class USER_PROCESS final { /***********************************************************************************/ Void Crash(); + /***********************************************************************************/ + ///! @brief Spawns a dynamic library handle if dylib. + /***********************************************************************************/ Bool SpawnDylib(); /***********************************************************************************/ -- cgit v1.2.3 From f4370b44bacfa3035496aa6f5aca24469326ebff Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 5 Jul 2025 10:32:16 +0200 Subject: feat: add magic check in `fsck.hefs` Signed-off-by: Amlal El Mahrouss --- dev/kernel/FirmwareKit/EPM.h | 12 +++++++----- dev/kernel/KernelKit/CodeMgr.h | 4 ++++ dev/kernel/KernelKit/CoreProcessScheduler.h | 4 ++++ dev/kernel/KernelKit/FileMgr.h | 3 ++- dev/libMsg/MsgKit/Network.h | 2 +- tooling/fsck.hefs.cc | 8 ++++++-- 6 files changed, 24 insertions(+), 9 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/FirmwareKit/EPM.h b/dev/kernel/FirmwareKit/EPM.h index 05291929..dcab3607 100644 --- a/dev/kernel/FirmwareKit/EPM.h +++ b/dev/kernel/FirmwareKit/EPM.h @@ -97,11 +97,13 @@ struct PACKED EPM_PART_BLOCK { ///! @brief Use in boot block version field. enum { - kEPMInvalid = 0x00, - kEPMGeneric = 0xcf, /// @brief Generic OS - kEPMLinux = 0x8f, /// @brief Linux on EPM - kEPMBSD = 0x9f, /// @brief Berkeley Soft. Distribution - kEPMNeKernel = 0x1f, /// @brief NeKernel. + kEPMInvalid = 0x00, + kEPMGeneric = 0xcf, /// @brief Generic OS + kEPMLinux = 0x8f, /// @brief Linux on EPM. + kEPMBSD = 0x9f, /// @brief BSD on EPM. + kEPMNeKernel = 0x1f, /// @brief NeKernel. + kEPMVMKernel = 0x2f, /// @brief VMKernel. + /// @note ... the rest is reserved for future OSes. kEPMInvalidOS = 0xff, }; diff --git a/dev/kernel/KernelKit/CodeMgr.h b/dev/kernel/KernelKit/CodeMgr.h index 072ba4d5..c733bc47 100644 --- a/dev/kernel/KernelKit/CodeMgr.h +++ b/dev/kernel/KernelKit/CodeMgr.h @@ -18,6 +18,10 @@ #include #include +/// @file CodeMgr.h +/// @brief Code Manager header file. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + namespace Kernel { /// @brief Main process entrypoint. typedef void (*rtl_main_kind)(void); diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index f64cbf22..e5606987 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -9,6 +9,10 @@ #include #include +/// @file CoreProcessScheduler.h +/// @brief Core Process Scheduler header file. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + #define kSchedMinMicroTime (AffinityKind::kStandard) #define kSchedInvalidPID (-1) #define kSchedProcessLimitPerTeam (32U) diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 13eeabdf..adcb1d6e 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -4,6 +4,7 @@ File: FileMgr.h Purpose: Kernel file manager. + Author: Amlal El Mahrouss (amlal@nekernel.org) ------------------------------------------- */ @@ -65,10 +66,10 @@ enum { kFileReadAll = 101, kFileReadChunk = 102, kFileWriteChunk = 103, - kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1, // File flags (HFS+, NeFS specific) kFileFlagRsrc = 104, kFileFlagData = 105, + kFileIOCnt = (kFileFlagData - kFileWriteAll) + 1, }; typedef VoidPtr NodePtr; diff --git a/dev/libMsg/MsgKit/Network.h b/dev/libMsg/MsgKit/Network.h index c7b562a2..7dd56877 100644 --- a/dev/libMsg/MsgKit/Network.h +++ b/dev/libMsg/MsgKit/Network.h @@ -6,4 +6,4 @@ #pragma once -#include \ No newline at end of file +#include \ No newline at end of file diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc index ce386152..0fa697be 100644 --- a/tooling/fsck.hefs.cc +++ b/tooling/fsck.hefs.cc @@ -18,7 +18,7 @@ int main(int argc, char** argv) { auto args = mkfs::detail::build_args(argc, argv); - auto opt_disk = mkfs::get_option(args, "-i"); + auto opt_disk = mkfs::get_option(args, "-i"); if (opt_disk.empty()) { mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." @@ -26,7 +26,6 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - std::ifstream output_device(opt_disk, std::ios::binary); if (!output_device.good()) { @@ -37,6 +36,11 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); + if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0) { + mkfs::console_out() << "hefs: error: Device is not an HeFS disk: " << opt_disk << "\n"; + return EXIT_FAILURE; + } + mkfs::console_out() << "hefs: HeFS partition is is healthy, exiting...\r"; return EXIT_SUCCESS; -- cgit v1.2.3 From 739d4dd79a459aa0aecf4195c6e940e09fce9bce Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 6 Jul 2025 18:18:46 +0200 Subject: fix: CoreProcessScheduler.h: Correct `kTreeKindCount` enum value to three. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index e5606987..e9dea5b3 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -42,7 +42,7 @@ enum { kInvalidTreeKind = 0U, kRedTreeKind = 100U, kBlackTreeKind = 101U, - kTreeKindCount = 2U, + kTreeKindCount = 3U, }; template -- cgit v1.2.3 From 6e0a8d09c3cfa1ddc15c12ad966a660d21731709 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 6 Jul 2025 18:27:34 +0200 Subject: feat: set `fFile` to nullptr when freeing it. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/FileMgr.h | 1 + 1 file changed, 1 insertion(+) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index adcb1d6e..18593f5c 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -395,6 +395,7 @@ inline FileStream::FileStream(const Encoding* path, const Encod template inline FileStream::~FileStream() { mm_free_ptr(fFile); + fFile = nullptr; } } // namespace Kernel -- cgit v1.2.3 From a09ca66b2e7d8a05b0da4218b82d1897bce721ba Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 7 Jul 2025 01:10:22 +0200 Subject: fix: FileMgr: use `sz` when `Reading` blob inside file. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/FileMgr.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 18593f5c..641dd448 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -285,12 +285,10 @@ class FileStream final { this->fFileRestrict != kFileMgrRestrictReadBinary) return nullptr; - NE_UNUSED(sz); - auto man = FSClass::GetMounted(); if (man) { - VoidPtr ret = man->Read(name, fFile, kFileReadAll, 0); + VoidPtr ret = man->Read(name, fFile, kFileReadAll, sz); return ret; } -- cgit v1.2.3 From f6a7873714c73b8f3d3190669f8a3181d6679b9d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 7 Jul 2025 08:11:41 +0200 Subject: refactor: FileMgr: remove useless macros. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/FileMgr.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 641dd448..40db0e14 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -49,11 +49,6 @@ #define rtl_node_cast(PTR) reinterpret_cast(PTR) -/** - @note Refer to first enum. -*/ -#define kFileOpsCount (4U) - #define kFileMimeGeneric "ne-application-kind/all" /** @brief invalid position. (n-pos) */ -- cgit v1.2.3 From b8ecc3fc6fced20f61095caf3eb6ec7eac4d818d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 8 Jul 2025 16:35:47 +0200 Subject: refactor: Refactor NeKernel's TLS API. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/ThreadLocalStorage.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/ThreadLocalStorage.h b/dev/kernel/KernelKit/ThreadLocalStorage.h index 1b8e4821..7474289e 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.h +++ b/dev/kernel/KernelKit/ThreadLocalStorage.h @@ -12,22 +12,22 @@ ///! @brief Thread Local Storage for neoskrnl. -#define kCookieMag0Idx 0 -#define kCookieMag1Idx 1 -#define kCookieMag2Idx 2 +#define kCookieMag0Idx (0U) +#define kCookieMag1Idx (1U) +#define kCookieMag2Idx (2U) #define kCookieMag0 'Z' #define kCookieMag1 'K' #define kCookieMag2 'A' -#define kTLSCookieLen (3U) +#define kCookieMagLen (3U) struct THREAD_INFORMATION_BLOCK; /// @brief Thread Information Block. /// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) struct PACKED THREAD_INFORMATION_BLOCK final { - Kernel::Char Cookie[kTLSCookieLen]{0}; //! Thread Magic Number. + Kernel::Char Cookie[kCookieMagLen]{0}; //! Thread Magic Number. Kernel::VoidPtr UserData{nullptr}; //! Thread Information Record (User defined canary structure) }; -- cgit v1.2.3 From a8130b763b7b7b184671f86be4462e7b1c6f7e90 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 8 Jul 2025 16:58:59 +0200 Subject: refactor: comments cleanup, breaking change! updated TLS magic from ZKA to NKO. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/FileMgr.h | 2 +- dev/kernel/KernelKit/ThreadLocalStorage.h | 6 +++--- dev/kernel/amd64-ci.make | 2 +- dev/kernel/amd64-desktop.make | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 40db0e14..e00e036f 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -22,7 +22,7 @@ #ifndef INC_FILEMGR_H #define INC_FILEMGR_H -//! Include filesystems that neoskrnl supports. +//! Include filesystems that NeKernel supports. #include #include #include diff --git a/dev/kernel/KernelKit/ThreadLocalStorage.h b/dev/kernel/KernelKit/ThreadLocalStorage.h index 7474289e..47ff526c 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.h +++ b/dev/kernel/KernelKit/ThreadLocalStorage.h @@ -10,15 +10,15 @@ #include #include -///! @brief Thread Local Storage for neoskrnl. +///! @brief Thread Local Storage for NeKernel. #define kCookieMag0Idx (0U) #define kCookieMag1Idx (1U) #define kCookieMag2Idx (2U) -#define kCookieMag0 'Z' +#define kCookieMag0 'N' #define kCookieMag1 'K' -#define kCookieMag2 'A' +#define kCookieMag2 'O' #define kCookieMagLen (3U) diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make index c728b29c..81b72b93 100644 --- a/dev/kernel/amd64-ci.make +++ b/dev/kernel/amd64-ci.make @@ -1,6 +1,6 @@ ################################################## # (c) Amlal El Mahrouss, all rights reserved. -# This is the neoskrnl's makefile. +# This is the NeKernel's makefile. ################################################## CXX = x86_64-w64-mingw32-g++ diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index 21488782..2874d31c 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -1,6 +1,6 @@ ################################################## # (c) Amlal El Mahrouss, all rights reserved. -# This is the neoskrnl's makefile. +# This is the NeKernel's makefile. ################################################## CXX = x86_64-w64-mingw32-g++ -- cgit v1.2.3 From 002de3d50a300e49c0c2b9f21c6b7efce218ca15 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 9 Jul 2025 08:14:41 +0200 Subject: refactor! `CoreProcessScheduler` now uses `kFile` instead of `kFD` Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 6 +++--- dev/kernel/KernelKit/DriveMgr.h | 4 ++++ dev/kernel/KernelKit/FileMgr.h | 5 +++++ dev/kernel/KernelKit/PEFCodeMgr.h | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index e9dea5b3..01219214 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -18,7 +18,7 @@ #define kSchedProcessLimitPerTeam (32U) #define kSchedTeamCount (256U) -#define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ +#define kSchedMaxMemoryLimit (gib_cast(128)) /* max physical memory limit */ #define kSchedMaxStackSz (kib_cast(8)) /* maximum stack size */ #define kSchedNameLen (128U) @@ -48,7 +48,7 @@ enum { template struct PROCESS_HEAP_TREE { static constexpr auto kPtr = true; - static constexpr auto kFD = false; + static constexpr auto kFile = false; T Entry{nullptr}; SizeT EntrySize{0UL}; @@ -74,7 +74,7 @@ struct PROCESS_HEAP_TREE { template struct PROCESS_FILE_TREE { static constexpr auto kPtr = false; - static constexpr auto kFD = true; + static constexpr auto kFile = true; T Entry{nullptr}; SizeT EntrySize{0UL}; diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h index 4a530deb..69df1cec 100644 --- a/dev/kernel/KernelKit/DriveMgr.h +++ b/dev/kernel/KernelKit/DriveMgr.h @@ -7,6 +7,10 @@ #ifndef INC_DRIVE_MANAGER_H #define INC_DRIVE_MANAGER_H +/// @file DriveMgr.h +/// @brief Drive Manager. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + #include #include #include diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index e00e036f..d1334277 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -22,6 +22,11 @@ #ifndef INC_FILEMGR_H #define INC_FILEMGR_H + +/// @file FileMgr.h +/// @brief File Manager. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + //! Include filesystems that NeKernel supports. #include #include diff --git a/dev/kernel/KernelKit/PEFCodeMgr.h b/dev/kernel/KernelKit/PEFCodeMgr.h index 18041f8f..899a1869 100644 --- a/dev/kernel/KernelKit/PEFCodeMgr.h +++ b/dev/kernel/KernelKit/PEFCodeMgr.h @@ -7,6 +7,10 @@ #ifndef _INC_CODE_MANAGER_PEF_H_ #define _INC_CODE_MANAGER_PEF_H_ +/// @file PEFCodeMgr.h +/// @brief PEF Code Manager header file. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + #include #include #include -- cgit v1.2.3 From 44b09ad2f4b701414379e3a4567e5c7dd1d77413 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 9 Jul 2025 11:47:51 +0200 Subject: feat: KID, UPS improvements, and future refactors regarding the FileTree system inside the UPS. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/KernelTaskScheduler.h | 18 ++++++++++++++++++ dev/kernel/KernelKit/UserProcessScheduler.inl | 2 +- dev/kernel/src/UserProcessScheduler.cc | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index 57b83ccb..222041e8 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -15,6 +15,12 @@ #include namespace Kernel { +class KernelTaskHelper; + +typedef PID KID; + +/// @brief Equivalent of USER_PROCESS, but for kernel tasks. +/// @author Amlal class KERNEL_TASK final { public: Char Name[kSchedNameLen] = {"KERNEL_TASK"}; @@ -23,5 +29,17 @@ class KERNEL_TASK final { UInt8* StackReserve{nullptr}; SizeT StackSize{kSchedMaxStackSz}; PROCESS_IMAGE Image{}; + /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within the kernel. + KID Kid{0}; +}; + +/// @brief Equivalent of UserProcessHelper, but for kernel tasks. +/// @author Amlal +class KernelTaskHelper final { + public: + STATIC Bool Switch(HAL::StackFramePtr frame_ptr, PID new_kid); + STATIC Bool CanBeScheduled(const KERNEL_TASK& process); + STATIC ErrorOr TheCurrentKID(); + STATIC SizeT StartScheduling(); }; } // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index df35e037..0605a5e0 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -17,7 +17,7 @@ namespace Kernel { /***********************************************************************************/ -/** @brief Free pointer from usage. */ +/** @brief Free pointer/file from usage. */ /***********************************************************************************/ template diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index ba6e1857..7e14fa62 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -107,7 +107,7 @@ STATIC T* sched_try_go_upper_ptr_tree(T* tree) { } /***********************************************************************************/ -/** @brief Allocate pointer to heap tree. */ +/** @brief Allocate pointer to heap/file tree. */ /***********************************************************************************/ ErrorOr USER_PROCESS::New(SizeT sz, SizeT pad_amount) { -- cgit v1.2.3 From 5e0d656c5762e8123dde32d959255bd71d9e2184 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 10 Jul 2025 10:27:27 +0200 Subject: refactor: use `rt_debug_cmd` instead of `rt_debug_type` Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/DebugOutput.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index 87649406..992d1ca7 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -180,9 +180,9 @@ inline TerminalDevice get_console_in(Char* buf) { return self; } -inline constexpr SizeT kDebugTypeLen = 256U; +inline constexpr SizeT kDebugCmdLen = 256U; -typedef Char rt_debug_type[kDebugTypeLen]; +typedef Char rt_debug_cmd[kDebugCmdLen]; inline TerminalDevice& operator<<(TerminalDevice& src, const Long& num) { src = number(num); -- cgit v1.2.3 From 3d1932fb68aa20b87429b55355bb051f817070ce Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Jul 2025 11:48:34 +0100 Subject: feat: CoreProcessScheduler has now a 'kSpecial' type for trees. (Because of SwapKit, or devices) reworked LibMSG lisp function pointer type. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 6 ++++-- dev/libMsg/MsgKit/Server.h | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index 01219214..e8ac158e 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -47,8 +47,9 @@ enum { template struct PROCESS_HEAP_TREE { - static constexpr auto kPtr = true; + static constexpr auto kHeap = true; static constexpr auto kFile = false; + static constexpr auto kSpecial = false; T Entry{nullptr}; SizeT EntrySize{0UL}; @@ -73,8 +74,9 @@ struct PROCESS_HEAP_TREE { template struct PROCESS_FILE_TREE { - static constexpr auto kPtr = false; + static constexpr auto kHeap = false; static constexpr auto kFile = true; + static constexpr auto kSpecial = false; T Entry{nullptr}; SizeT EntrySize{0UL}; diff --git a/dev/libMsg/MsgKit/Server.h b/dev/libMsg/MsgKit/Server.h index 33d10407..aee0dbdd 100644 --- a/dev/libMsg/MsgKit/Server.h +++ b/dev/libMsg/MsgKit/Server.h @@ -29,8 +29,10 @@ struct LIBMSG_EXPR final { LIBMSG_EXPR* l_child{nullptr}; }; -typedef Void (*libmsg_func_t)(LIBMSG_EXPR* arg); +/// @brief Function type for LibMSG lisp. +typedef Void (*libmsg_func_t)(LIBMSG_EXPR* self, VoidPtr arg, SizeT arg_size); IMPORT_C Void libmsg_init_library(libmsg_func_t* funcs, SizeT cnt); -IMPORT_C UInt32 libmsg_eval_library(struct LIBMSG_EXPR* head); IMPORT_C UInt32 libmsg_close_library(Void); + +IMPORT_C UInt32 libmsg_eval_expr(struct LIBMSG_EXPR* head); -- cgit v1.2.3 From 1e12163836e649da0d67fc8f17bc9a415554efe4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Jul 2025 16:11:51 +0100 Subject: feat: wip: new tree kind 'kSpecial' and refactor user scheduler code temporary regarding FileTree allocation. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 24 ++++++++++---------- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 23 ++++++++++--------- dev/kernel/KernelKit/CoreProcessScheduler.h | 17 ++++++++------ dev/kernel/KernelKit/UserProcessScheduler.h | 4 ++-- dev/kernel/src/UserProcessScheduler.cc | 26 +++++++++++----------- 5 files changed, 49 insertions(+), 45 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 8b4c0d1a..79f25920 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -45,15 +45,15 @@ struct HAL_APIC_MADT; struct HAL_HARDWARE_THREAD; struct HAL_HARDWARE_THREAD final { - HAL::StackFramePtr mFramePtr; - ProcessID mThreadID{0}; + StackFramePtr mFramePtr; + ProcessID mThreadID{0}; }; -EXTERN_C Void sched_jump_to_task(HAL::StackFramePtr stack_frame); +EXTERN_C Void sched_jump_to_task(StackFramePtr stack_frame); -STATIC HAL_APIC_MADT* kMADTBlock = nullptr; -STATIC Bool kSMPAware = false; -STATIC Int64 kSMPCount = 0; +STATIC HAL_APIC_MADT* kSMPBlock = nullptr; +STATIC Bool kSMPAware = false; +STATIC Int64 kSMPCount = 0; EXTERN_C UIntPtr kApicBaseAddress; @@ -160,11 +160,11 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { return; } - kRawMADT = pwr.Leak().Leak(); - kMADTBlock = reinterpret_cast(kRawMADT); - kSMPAware = NO; + kRawMADT = pwr.Leak().Leak(); + kSMPBlock = reinterpret_cast(kRawMADT); + kSMPAware = NO; - if (kMADTBlock) { + if (kSMPBlock) { kSMPInterrupt = 0; kSMPCount = 0; @@ -191,8 +191,8 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { controller.Write(LAPIC_REG_TIMER_LVT, 0x20 | (1 << 17)); controller.Write(LAPIC_REG_TIMER_INITCNT, 1000000); - volatile UInt8* entry_ptr = reinterpret_cast(kMADTBlock->List); - volatile UInt8* end_ptr = ((UInt8*) kMADTBlock) + kMADTBlock->Length; + volatile UInt8* entry_ptr = reinterpret_cast(kSMPBlock->List); + volatile UInt8* end_ptr = ((UInt8*) kSMPBlock) + kSMPBlock->Length; while (entry_ptr < end_ptr) { UInt8 type = *entry_ptr; diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index cd41480a..3363e809 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -136,7 +136,7 @@ template STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz, SizeT size_buffer) noexcept { if (sector_sz == 0) { - kout << "Invalid sector size.\r"; + kout << "ahci: Invalid sector size.\r"; err_global_get() = kErrorDisk; return; } @@ -144,7 +144,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz lba /= sector_sz; if (!buffer || size_buffer == 0) { - kout << "Invalid buffer for AHCI I/O.\r"; + kout << "ahci: Invalid buffer for AHCI I/O.\r"; err_global_get() = kErrorDisk; return; } @@ -157,7 +157,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz while (slot == ~0UL) { if (timeout > kTimeout) { - kout << "No free command slot found, AHCI disk is busy!\r"; + kout << "ahci: No free command slot found, AHCI disk is busy!\r"; err_global_get() = kErrorDisk; return; @@ -217,7 +217,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz command_table->Prdt[prdt_index - 1].Ie = YES; if (bytes_remaining > 0) { - kout << "Warning: AHCI PRDT overflow, cannot map full buffer.\r"; + kout << "ahci: AHCI PRDT overflow, cannot map full buffer.\r"; err_global_get() = kErrorDisk; rtl_dma_free(size_buffer); @@ -262,7 +262,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz while (YES) { if (timeout > kTimeout) { - kout << "Disk hangup!\r"; + kout << "ahci: disk-hangup, corrupted-disk.\r"; err_global_get() = kErrorDiskIsCorrupted; rtl_dma_free(size_buffer); @@ -277,7 +277,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz rtl_dma_flush(ptr, size_buffer); if (kSATAHba->Is & kSATAErrTaskFile) { - kout << "AHCI Task File Error during I/O.\r"; + kout << "ahci: Task File Error during I/O.\r"; rtl_dma_free(size_buffer); err_global_get() = kErrorDiskIsCorrupted; @@ -293,9 +293,8 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz if ((kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)) == 0) { goto ahci_io_end; } else { - kout << "Warning: Disk still busy after command completion!\r"; - while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)) - ; + kout << "ahci: Disk still busy after command completion!\r"; + while (kSATAHba->Ports[kSATAIndex].Tfd & (kSATASRBsy | kSATASRDrq)); } ahci_io_end: @@ -308,13 +307,15 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz @brief Gets the number of sectors inside the drive. @return Sector size in bytes. */ -STATIC ATTRIBUTE(unused) SizeT drv_get_sector_count_ahci() { +STATIC ATTRIBUTE(unused) +SizeT drv_get_sector_count_ahci() { return kSATASectorCount; } /// @brief Get the drive size. /// @return Disk size in bytes. -STATIC ATTRIBUTE(unused) SizeT drv_get_size_ahci() { +STATIC ATTRIBUTE(unused) +SizeT drv_get_size_ahci() { return drv_std_get_sector_count() * kAHCISectorSize; } diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index e8ac158e..170244eb 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -19,7 +19,7 @@ #define kSchedTeamCount (256U) #define kSchedMaxMemoryLimit (gib_cast(128)) /* max physical memory limit */ -#define kSchedMaxStackSz (kib_cast(8)) /* maximum stack size */ +#define kSchedMaxStackSz (kib_cast(8)) /* maximum stack size */ #define kSchedNameLen (128U) @@ -35,6 +35,9 @@ class UserProcessTeam; template struct PROCESS_HEAP_TREE; +template +struct PROCESS_SPECIAL_TREE; + template struct PROCESS_FILE_TREE; @@ -47,9 +50,9 @@ enum { template struct PROCESS_HEAP_TREE { - static constexpr auto kHeap = true; - static constexpr auto kFile = false; - static constexpr auto kSpecial = false; + static constexpr auto kHeap = true; + static constexpr auto kFile = false; + static constexpr auto kSpecial = false; T Entry{nullptr}; SizeT EntrySize{0UL}; @@ -74,9 +77,9 @@ struct PROCESS_HEAP_TREE { template struct PROCESS_FILE_TREE { - static constexpr auto kHeap = false; - static constexpr auto kFile = true; - static constexpr auto kSpecial = false; + static constexpr auto kHeap = false; + static constexpr auto kFile = true; + static constexpr auto kSpecial = false; T Entry{nullptr}; SizeT EntrySize{0UL}; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 8a730233..3dae178a 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -96,7 +96,7 @@ class USER_PROCESS final { /***********************************************************************************/ ///! @brief Spawns a dynamic library handle if dylib. /***********************************************************************************/ - Bool SpawnDylib(); + Bool InitDylib(); /***********************************************************************************/ ///! @brief Exits the app. @@ -192,7 +192,7 @@ class UserProcessScheduler final : public ISchedulable { NE_MOVE_DELETE(UserProcessScheduler) public: - operator bool(); + operator bool(); bool operator!(); public: diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 7e14fa62..45957c7b 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -122,20 +122,9 @@ ErrorOr 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->FileTree) { - this->FileTree = new PROCESS_FILE_TREE(); - - if (!this->FileTree) { - this->Crash(); - return ErrorOr(-kErrorHeapOutOfMemory); - } - - /// @todo File Tree allocation and dispose methods (amlal) - } - if (!this->HeapTree) { this->HeapTree = new PROCESS_HEAP_TREE(); @@ -335,7 +324,7 @@ Void USER_PROCESS::Exit(const Int32& exit_code) { /// @brief Add dylib to the process object. /***********************************************************************************/ -Bool USER_PROCESS::SpawnDylib() { +Bool USER_PROCESS::InitDylib() { // React according to the process's kind. switch (this->Kind) { case USER_PROCESS::kExecutableDylibKind: { @@ -437,6 +426,17 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im process.PTime = 0; process.RTime = 0; + if (!process.FileTree) { + process.FileTree = new PROCESS_FILE_TREE(); + + if (!process.FileTree) { + process.Crash(); + return ErrorOr(-kErrorHeapOutOfMemory); + } + + /// @todo File Tree allocation and dispose methods (amlal) + } + (Void)(kout << "PID: " << number(process.ProcessId) << kendl); (Void)(kout << "Name: " << process.Name << kendl); -- cgit v1.2.3 From 4e61e22c3da59b259741e57298725330791aed3e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Jul 2025 08:51:41 +0100 Subject: feat: NeKernel Semaphore API. includes: - New semaphore API for the kernel, we also make use of the HardwareTimer class here. - Defined header only for now. - New HAL HW Timer API in AMD64. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalTimer.cc | 18 ++++----- dev/kernel/KernelKit/KPC.h | 1 + dev/kernel/KernelKit/Semaphore.h | 79 ++++++++++++++++++++++++++++++++++++- tooling/mk_htman.py | 2 +- 4 files changed, 89 insertions(+), 11 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/HALKit/AMD64/HalTimer.cc b/dev/kernel/HALKit/AMD64/HalTimer.cc index 13573880..ae3271f6 100644 --- a/dev/kernel/HALKit/AMD64/HalTimer.cc +++ b/dev/kernel/HALKit/AMD64/HalTimer.cc @@ -61,11 +61,8 @@ HardwareTimer::HardwareTimer(UInt64 ms) : fWaitFor(ms) { // if not enabled yet. if (!(*((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) & (1 << 0))) { *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) = - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | - (1 << 0); // enable timer - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) = - *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | - (1 << 3); // one shot conf + *((volatile UInt64*) ((UInt8*) fDigitalTimer + kHPETConfigRegValue)) | (1 << 0) | + (1 << 3); // enable timer } } @@ -80,18 +77,21 @@ HardwareTimer::~HardwareTimer() { BOOL HardwareTimer::Wait() noexcept { if (fWaitFor < 1) return NO; + if (fWaitFor > 1'000'000) return NO; // max 1000s = 16 minutes - UInt64 hpet_cap = *((volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue)); + UInt64 hpet_cap = *((volatile UInt64*) (fDigitalTimer)); UInt64 femtoseconds_per_tick = (hpet_cap >> 32); if (femtoseconds_per_tick == 0) return NO; volatile UInt64* timer = (volatile UInt64*) (fDigitalTimer + kHPETCounterRegValue); - UInt64 now = *timer; - UInt64 prev = now + (fWaitFor / femtoseconds_per_tick); + UInt64 now = *timer; + + UInt64 fs_wait = fWaitFor * 1'000'000'000'000ULL; + UInt64 stop_at = now + (fs_wait / femtoseconds_per_tick); - while (*timer < (prev)) asm volatile("pause"); + while (*timer < (stop_at)) asm volatile("pause"); return YES; } diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index a3b13de6..26d1b113 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -65,6 +65,7 @@ inline constexpr KPCError kErrorFileLocked = 64; inline constexpr KPCError kErrorDiskIsTooTiny = 65; inline constexpr KPCError kErrorDmaExhausted = 66; inline constexpr KPCError kErrorOutOfBitMapMemory = 67; +inline constexpr KPCError kErrorNetworkTimeout = 68; /// Generic errors. inline constexpr KPCError kErrorUnimplemented = -1; diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index a1b5ecad..7fa05008 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -6,10 +6,87 @@ #pragma once +/// @author Amlal El Mahrouss +/// @file Semaphore.h +/// @brief Semaphore structure and functions for synchronization in the kernel. + #include #include #include +#define kSemaphoreOwnerIndex (0) +#define kSemaphoreCountIndex (1) + +#define kSemaphoreCount (2) + namespace Kernel { -typedef Int64 Semaphore; +/// @brief Semaphore structure used for synchronization. +typedef UInt64 Semaphore[kSemaphoreCount]; + +/// @brief Checks if the semaphore is valid. +inline BOOL rtl_sem_is_valid(const Semaphore& sem) { + return sem[kSemaphoreOwnerIndex] != 0 || sem[kSemaphoreCountIndex] > 0; +} + +/// @brief Releases the semaphore, resetting its owner and count. +/// @param sem +/// @return +inline BOOL rtl_sem_release(Semaphore& sem) { + sem[kSemaphoreOwnerIndex] = 0; + sem[kSemaphoreCountIndex] = 0; + + return TRUE; +} + +/// @brief Initializes the semaphore with an owner and a count of zero. +/// @param sem +/// @param owner +/// @return +inline BOOL rtl_sem_init(Semaphore& sem, Int64 owner) { + if (!owner || sem[kSemaphoreOwnerIndex] > 0) { + return FALSE; + } + + sem[kSemaphoreOwnerIndex] = owner; + sem[kSemaphoreCountIndex] = 0; + + return TRUE; +} + +/// @brief Waits for the semaphore to be available, blocking until it is. +/// @param sem +/// @param timeout +/// @return +inline BOOL rtl_sem_wait(Semaphore& sem, Int64 timeout) { + if (!rtl_sem_is_valid(sem)) { + return FALSE; + } + + if (timeout <= 0) { + err_global_get() = kErrorNetworkTimeout; + + return FALSE; + } + + if (sem[kSemaphoreCountIndex] > 0) { + err_global_get() = kErrorSuccess; + sem[kSemaphoreCountIndex]--; + + return TRUE; + } + + HardwareTimer timer(timeout); + timer.Wait(); + + if (sem[kSemaphoreCountIndex] > 0) { + err_global_get() = kErrorSuccess; + sem[kSemaphoreCountIndex]--; + + return TRUE; + } + + err_global_get() = kErrorNetworkTimeout; + + return FALSE; // Failed to acquire semaphore +} // namespace Kernel } // namespace Kernel \ No newline at end of file diff --git a/tooling/mk_htman.py b/tooling/mk_htman.py index 8298559b..5488d478 100755 --- a/tooling/mk_htman.py +++ b/tooling/mk_htman.py @@ -5,5 +5,5 @@ import sys, os if __name__ == "__main__": if len(sys.argv) != 2: - print("Usage: manual.py ") + print("INFO: manual.py ") sys.exit(os.EX_CONFIG) -- cgit v1.2.3 From c7e9d01d331d966a92efdc7ad6fb76ac96d0943e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Jul 2025 21:19:33 +0100 Subject: fix: KPC: Fix duplicate of kErrorNetworkTimeout. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/KPC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index 26d1b113..836be458 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -65,7 +65,7 @@ inline constexpr KPCError kErrorFileLocked = 64; inline constexpr KPCError kErrorDiskIsTooTiny = 65; inline constexpr KPCError kErrorDmaExhausted = 66; inline constexpr KPCError kErrorOutOfBitMapMemory = 67; -inline constexpr KPCError kErrorNetworkTimeout = 68; +inline constexpr KPCError kErrorTimeout = 68; /// Generic errors. inline constexpr KPCError kErrorUnimplemented = -1; -- cgit v1.2.3 From 5516544f97026460ede96f894c806dd8925885ae Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:05:37 +0100 Subject: feat: dev/kernel: Finish kernel semaphore API. note: - The API is very new, except breaking changces. - It may be buggy in some areas, except some changes soon. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 7fa05008..a00273e8 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -19,13 +19,21 @@ #define kSemaphoreCount (2) +#define kSemaphoreIncremenntOwner(sem) \ + (sem[kSemaphoreOwnerIndex]++) + + +#define kSemaphoreDecrementOwner(sem) \ + (sem[kSemaphoreOwnerIndex]--) + + namespace Kernel { /// @brief Semaphore structure used for synchronization. typedef UInt64 Semaphore[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. -inline BOOL rtl_sem_is_valid(const Semaphore& sem) { - return sem[kSemaphoreOwnerIndex] != 0 || sem[kSemaphoreCountIndex] > 0; +inline BOOL rtl_sem_is_valid(const Semaphore& sem, UInt64 owner = 0) { + return sem[kSemaphoreOwnerIndex] != owner || sem[kSemaphoreCountIndex] > 0; } /// @brief Releases the semaphore, resetting its owner and count. @@ -42,9 +50,10 @@ inline BOOL rtl_sem_release(Semaphore& sem) { /// @param sem /// @param owner /// @return -inline BOOL rtl_sem_init(Semaphore& sem, Int64 owner) { - if (!owner || sem[kSemaphoreOwnerIndex] > 0) { - return FALSE; +inline BOOL rtl_sem_acquire(Semaphore& sem, UInt64 owner) { + if (!owner) { + err_global_get() = kErrorInvalidData; + return FALSE; // Invalid owner } sem[kSemaphoreOwnerIndex] = owner; @@ -57,8 +66,8 @@ inline BOOL rtl_sem_init(Semaphore& sem, Int64 owner) { /// @param sem /// @param timeout /// @return -inline BOOL rtl_sem_wait(Semaphore& sem, Int64 timeout) { - if (!rtl_sem_is_valid(sem)) { +inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* condition = nullptr) { + if (!rtl_sem_is_valid(sem, owner)) { return FALSE; } @@ -68,7 +77,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, Int64 timeout) { return FALSE; } - if (sem[kSemaphoreCountIndex] > 0) { + if (!condition || *condition) { err_global_get() = kErrorSuccess; sem[kSemaphoreCountIndex]--; @@ -76,13 +85,15 @@ inline BOOL rtl_sem_wait(Semaphore& sem, Int64 timeout) { } HardwareTimer timer(timeout); - timer.Wait(); - - if (sem[kSemaphoreCountIndex] > 0) { - err_global_get() = kErrorSuccess; - sem[kSemaphoreCountIndex]--; + BOOL ret = timer.Wait(); - return TRUE; + if (ret) { + if (!condition || *condition) { + err_global_get() = kErrorSuccess; + sem[kSemaphoreCountIndex]--; + + return TRUE; + } } err_global_get() = kErrorNetworkTimeout; -- cgit v1.2.3 From ec995b2501d337eca9aedfeb5eebbc0a4bc930ba Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:14:01 +0100 Subject: fix: sem: remove useless 'namespace Kernel' comment on function. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index a00273e8..f98110b0 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -99,5 +99,5 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con err_global_get() = kErrorNetworkTimeout; return FALSE; // Failed to acquire semaphore -} // namespace Kernel +} } // namespace Kernel \ No newline at end of file -- cgit v1.2.3 From c81208be24a34bd36fc9e01fdbdc146440d7c9e7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:21:30 +0100 Subject: fix: sem: fix Semaphore API of kernel, validation and typo fixes. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index f98110b0..ee29eeae 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -19,7 +19,7 @@ #define kSemaphoreCount (2) -#define kSemaphoreIncremenntOwner(sem) \ +#define kSemaphoreIncrementOwner(sem) \ (sem[kSemaphoreOwnerIndex]++) @@ -33,7 +33,7 @@ typedef UInt64 Semaphore[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. inline BOOL rtl_sem_is_valid(const Semaphore& sem, UInt64 owner = 0) { - return sem[kSemaphoreOwnerIndex] != owner || sem[kSemaphoreCountIndex] > 0; + return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0; } /// @brief Releases the semaphore, resetting its owner and count. -- cgit v1.2.3 From 4ece9e7d55734ca14c87f7fb6b708aa086b4d3c0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:22:38 +0100 Subject: fix: sem: fix condition in 'rtl_sem_is_valid' as it was to strict. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index ee29eeae..0d2b84da 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -33,7 +33,7 @@ typedef UInt64 Semaphore[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. inline BOOL rtl_sem_is_valid(const Semaphore& sem, UInt64 owner = 0) { - return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0; + return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] >= 0; } /// @brief Releases the semaphore, resetting its owner and count. -- cgit v1.2.3 From 3978ac0540a7e430a4a2a157d2e53653b5c37bd0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:25:39 +0100 Subject: feat: rtl_sem_wait: check semaphore for underflows. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 0d2b84da..686ce1c9 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -19,13 +19,9 @@ #define kSemaphoreCount (2) -#define kSemaphoreIncrementOwner(sem) \ - (sem[kSemaphoreOwnerIndex]++) - - -#define kSemaphoreDecrementOwner(sem) \ - (sem[kSemaphoreOwnerIndex]--) +#define kSemaphoreIncrementOwner(sem) (sem[kSemaphoreOwnerIndex]++) +#define kSemaphoreDecrementOwner(sem) (sem[kSemaphoreOwnerIndex]--) namespace Kernel { /// @brief Semaphore structure used for synchronization. @@ -71,6 +67,11 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con return FALSE; } + if (sem[kSemaphoreCountIndex] <= 0) { + err_global_get() = kErrorNetworkTimeout; + return FALSE; + } + if (timeout <= 0) { err_global_get() = kErrorNetworkTimeout; -- cgit v1.2.3 From 8cda61ab7fe436075a7d93306819a609de80c4a0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:28:51 +0100 Subject: fix: sem: fix decrement logic of the semaphore api's 'rtl_sem_wait' Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 686ce1c9..618a3268 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -67,11 +67,6 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con return FALSE; } - if (sem[kSemaphoreCountIndex] <= 0) { - err_global_get() = kErrorNetworkTimeout; - return FALSE; - } - if (timeout <= 0) { err_global_get() = kErrorNetworkTimeout; @@ -79,6 +74,11 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con } if (!condition || *condition) { + if (sem[kSemaphoreCountIndex] == 0) { + err_global_get() = kErrorNetworkTimeout; + return FALSE; + } + err_global_get() = kErrorSuccess; sem[kSemaphoreCountIndex]--; @@ -90,6 +90,11 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con if (ret) { if (!condition || *condition) { + if (sem[kSemaphoreCountIndex] == 0) { + err_global_get() = kErrorNetworkTimeout; + return FALSE; + } + err_global_get() = kErrorSuccess; sem[kSemaphoreCountIndex]--; -- cgit v1.2.3 From b17e50f399180aa1fed136a0917625bb0d9ebf81 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:29:52 +0100 Subject: fix: sem: use 'kErrorTimeout' instead of 'kErrorNetworkTimeout' Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 618a3268..8bb8c1fe 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -102,7 +102,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con } } - err_global_get() = kErrorNetworkTimeout; + err_global_get() = kErrorTimeout; return FALSE; // Failed to acquire semaphore } -- cgit v1.2.3 From cab7131a9eab7f06ba39260be477a1b4532705d8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:30:44 +0100 Subject: feat: sem: fix usage of 'kErrorNetworkTimeout' to 'kErrorTimeout' Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 8bb8c1fe..7957ce31 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -68,14 +68,14 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con } if (timeout <= 0) { - err_global_get() = kErrorNetworkTimeout; + err_global_get() = kErrorTimeout; return FALSE; } if (!condition || *condition) { if (sem[kSemaphoreCountIndex] == 0) { - err_global_get() = kErrorNetworkTimeout; + err_global_get() = kErrorTimeout; return FALSE; } @@ -91,7 +91,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con if (ret) { if (!condition || *condition) { if (sem[kSemaphoreCountIndex] == 0) { - err_global_get() = kErrorNetworkTimeout; + err_global_get() = kErrorTimeout; return FALSE; } -- cgit v1.2.3 From ca7b843f1c15dd479d287f93221cd23e74d94385 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:32:09 +0100 Subject: feat: new 'kErrorAccessDenied' type for semaphore api. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/KPC.h | 3 ++- dev/kernel/KernelKit/Semaphore.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index 836be458..b55d98fc 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -65,7 +65,8 @@ inline constexpr KPCError kErrorFileLocked = 64; inline constexpr KPCError kErrorDiskIsTooTiny = 65; inline constexpr KPCError kErrorDmaExhausted = 66; inline constexpr KPCError kErrorOutOfBitMapMemory = 67; -inline constexpr KPCError kErrorTimeout = 68; +inline constexpr KPCError kErrorTimeout = 68; +inline constexpr KPCError kErrorAccessDenied = 69; /// Generic errors. inline constexpr KPCError kErrorUnimplemented = -1; diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 7957ce31..6905c8cc 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -75,7 +75,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con if (!condition || *condition) { if (sem[kSemaphoreCountIndex] == 0) { - err_global_get() = kErrorTimeout; + err_global_get() = kErrorAccessDenied; return FALSE; } @@ -91,7 +91,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con if (ret) { if (!condition || *condition) { if (sem[kSemaphoreCountIndex] == 0) { - err_global_get() = kErrorTimeout; + err_global_get() = kErrorAccessDenied; return FALSE; } -- cgit v1.2.3 From 6d16db11d91c5fdf302af54e8e797dcbed8c9c71 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 23 Jul 2025 08:33:49 +0100 Subject: feat: new 'kErrorUnavailable' type and semaphore API breaking changes. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/KPC.h | 1 + dev/kernel/KernelKit/Semaphore.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index b55d98fc..794197e2 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -67,6 +67,7 @@ inline constexpr KPCError kErrorDmaExhausted = 66; inline constexpr KPCError kErrorOutOfBitMapMemory = 67; inline constexpr KPCError kErrorTimeout = 68; inline constexpr KPCError kErrorAccessDenied = 69; +inline constexpr KPCError kErrorUnavailable = 70; /// Generic errors. inline constexpr KPCError kErrorUnimplemented = -1; diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 6905c8cc..df410208 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -75,7 +75,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con if (!condition || *condition) { if (sem[kSemaphoreCountIndex] == 0) { - err_global_get() = kErrorAccessDenied; + err_global_get() = kErrorUnavailable; return FALSE; } @@ -91,7 +91,7 @@ inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* con if (ret) { if (!condition || *condition) { if (sem[kSemaphoreCountIndex] == 0) { - err_global_get() = kErrorAccessDenied; + err_global_get() = kErrorUnavailable; return FALSE; } -- cgit v1.2.3 From 5dcf3ce391288e9d4f5f25120cf722f962e30881 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 24 Jul 2025 09:57:46 +0100 Subject: refactor: FB.h, Semaphore.h: minor style changes. Signed-off-by: Amlal El Mahrouss --- dev/kernel/GfxKit/FB.h | 4 ++-- dev/kernel/KernelKit/Semaphore.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/GfxKit/FB.h b/dev/kernel/GfxKit/FB.h index d7523064..28f3a20c 100644 --- a/dev/kernel/GfxKit/FB.h +++ b/dev/kernel/GfxKit/FB.h @@ -46,7 +46,7 @@ class FBDeviceInterface NE_DEVICE { const Char* Name() const override; public: - FBDeviceInterface& operator<<(FBDevicePacket* Data) override; - FBDeviceInterface& operator>>(FBDevicePacket* Data) override; + FBDeviceInterface& operator<<(FBDevicePacket* dat) override; + FBDeviceInterface& operator>>(FBDevicePacket* dat) override; }; } // namespace Kernel diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index df410208..1bc61ed1 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -20,7 +20,6 @@ #define kSemaphoreCount (2) #define kSemaphoreIncrementOwner(sem) (sem[kSemaphoreOwnerIndex]++) - #define kSemaphoreDecrementOwner(sem) (sem[kSemaphoreOwnerIndex]--) namespace Kernel { -- cgit v1.2.3 From 40498554aa642ac0dbf4ce021df5bbceda5b61e4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 24 Jul 2025 10:35:32 +0100 Subject: feat: __CF_64BIT__ macro for CoreFoundation.fwrk. refactor! Semaphore API breaking changes in the new 'SemaphoreArr' type. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/Semaphore.h | 16 ++++++++-------- .../frameworks/CoreFoundation.fwrk/CoreFoundation.json | 3 ++- .../frameworks/CoreFoundation.fwrk/headers/Foundation.h | 2 +- public/frameworks/CoreFoundation.fwrk/headers/String.h | 5 +++++ 4 files changed, 16 insertions(+), 10 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 1bc61ed1..930b245d 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -14,27 +14,27 @@ #include #include -#define kSemaphoreOwnerIndex (0) -#define kSemaphoreCountIndex (1) +#define kSemaphoreOwnerIndex (0U) +#define kSemaphoreCountIndex (1U) -#define kSemaphoreCount (2) +#define kSemaphoreCount (2U) #define kSemaphoreIncrementOwner(sem) (sem[kSemaphoreOwnerIndex]++) #define kSemaphoreDecrementOwner(sem) (sem[kSemaphoreOwnerIndex]--) namespace Kernel { /// @brief Semaphore structure used for synchronization. -typedef UInt64 Semaphore[kSemaphoreCount]; +typedef UInt64 SemaphoreArr[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. -inline BOOL rtl_sem_is_valid(const Semaphore& sem, UInt64 owner = 0) { +inline BOOL rtl_sem_is_valid(const SemaphoreArr& sem, UInt64 owner = 0) { return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] >= 0; } /// @brief Releases the semaphore, resetting its owner and count. /// @param sem /// @return -inline BOOL rtl_sem_release(Semaphore& sem) { +inline BOOL rtl_sem_release(SemaphoreArr& sem) { sem[kSemaphoreOwnerIndex] = 0; sem[kSemaphoreCountIndex] = 0; @@ -45,7 +45,7 @@ inline BOOL rtl_sem_release(Semaphore& sem) { /// @param sem /// @param owner /// @return -inline BOOL rtl_sem_acquire(Semaphore& sem, UInt64 owner) { +inline BOOL rtl_sem_acquire(SemaphoreArr& sem, UInt64 owner) { if (!owner) { err_global_get() = kErrorInvalidData; return FALSE; // Invalid owner @@ -61,7 +61,7 @@ inline BOOL rtl_sem_acquire(Semaphore& sem, UInt64 owner) { /// @param sem /// @param timeout /// @return -inline BOOL rtl_sem_wait(Semaphore& sem, UInt64 owner, UInt64 timeout, BOOL* condition = nullptr) { +inline BOOL rtl_sem_wait(SemaphoreArr& sem, UInt64 owner, UInt64 timeout, BOOL* condition = nullptr) { if (!rtl_sem_is_valid(sem, owner)) { return FALSE; } diff --git a/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json b/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json index 076b35ae..39e6b480 100644 --- a/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json +++ b/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json @@ -15,7 +15,8 @@ "kCFVersion=0x0100", "kCFVersionHighest=0x0100", "kCFVersionLowest=0x0100", - "__NE_AMD64__" + "__NE_AMD64__", + "__CF_64BIT__" ] } \ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h index 500ad544..8396a3e8 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h @@ -25,7 +25,7 @@ struct CFPoint; struct CFRect; struct CFColor; -#ifndef __LP64__ +#ifndef __CF_64BIT__ typedef SInt32 CFInteger; typedef float CFReal; #else diff --git a/public/frameworks/CoreFoundation.fwrk/headers/String.h b/public/frameworks/CoreFoundation.fwrk/headers/String.h index c28c05cd..ea32038d 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/String.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/String.h @@ -14,5 +14,10 @@ class CFString; class CFString final CF_OBJECT { public: + CFString() = default; + ~CFString() = default; + + CFString(const CFString&) = delete; + CFString& operator=(const CFString&) = delete; }; } // namespace CF \ No newline at end of file -- cgit v1.2.3 From 11ad9b56ccc1ed50c9293ee4771cf135f6b03c99 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 1 Aug 2025 09:16:50 +0100 Subject: fix: KernelKit: fix BinaryMutex object, it used to took USER_PROCESS as reference with a explicit default constructor. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/BinaryMutex.h | 8 ++++---- dev/kernel/src/BinaryMutex.cc | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index 45d4bd8d..4a192bdd 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -24,16 +24,16 @@ class BinaryMutex final { bool Unlock() noexcept; public: - BOOL WaitForProcess(const Int16& sec) noexcept; + BOOL WaitForProcess(const UInt32& sec) noexcept; public: - bool Lock(USER_PROCESS& process); - bool LockOrWait(USER_PROCESS& process, TimerInterface* timer); + bool Lock(USER_PROCESS* process); + bool LockOrWait(USER_PROCESS* process, TimerInterface* timer); public: NE_COPY_DEFAULT(BinaryMutex) private: - USER_PROCESS& fLockingProcess; + USER_PROCESS* fLockingProcess; }; } // namespace Kernel diff --git a/dev/kernel/src/BinaryMutex.cc b/dev/kernel/src/BinaryMutex.cc index 8c8cdc0f..f669d7fa 100644 --- a/dev/kernel/src/BinaryMutex.cc +++ b/dev/kernel/src/BinaryMutex.cc @@ -13,9 +13,8 @@ namespace Kernel { /***********************************************************************************/ Bool BinaryMutex::Unlock() noexcept { - if (fLockingProcess.Status == ProcessStatusKind::kRunning) { - fLockingProcess = USER_PROCESS(); - fLockingProcess.Status = ProcessStatusKind::kFrozen; + if (fLockingProcess->Status == ProcessStatusKind::kRunning) { + fLockingProcess = nullptr; return Yes; } @@ -27,7 +26,7 @@ Bool BinaryMutex::Unlock() noexcept { /// @brief Locks process in the binary mutex. /***********************************************************************************/ -Bool BinaryMutex::Lock(USER_PROCESS& process) { +Bool BinaryMutex::Lock(USER_PROCESS* process) { if (!process || this->IsLocked()) return No; this->fLockingProcess = process; @@ -40,14 +39,14 @@ Bool BinaryMutex::Lock(USER_PROCESS& process) { /***********************************************************************************/ Bool BinaryMutex::IsLocked() const { - return this->fLockingProcess.Status == ProcessStatusKind::kRunning; + return this->fLockingProcess->Status == ProcessStatusKind::kRunning; } /***********************************************************************************/ /// @brief Try lock or wait. /***********************************************************************************/ -Bool BinaryMutex::LockOrWait(USER_PROCESS& process, TimerInterface* timer) { +Bool BinaryMutex::LockOrWait(USER_PROCESS* process, TimerInterface* timer) { if (timer == nullptr) return No; this->Lock(process); @@ -62,7 +61,7 @@ Bool BinaryMutex::LockOrWait(USER_PROCESS& process, TimerInterface* timer) { /// @param sec seconds. /***********************************************************************************/ -BOOL BinaryMutex::WaitForProcess(const Int16& sec) noexcept { +BOOL BinaryMutex::WaitForProcess(const UInt32& sec) noexcept { HardwareTimer hw_timer(rtl_milliseconds(sec)); hw_timer.Wait(); -- cgit v1.2.3 From 23774eda327ec2dffbda34d907a3b70b7772c7b5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 1 Aug 2025 10:33:29 +0100 Subject: fix: BinaryMutex: Assign `fLockingProcess` to nullptr. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/BinaryMutex.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index 4a192bdd..f2c15af0 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -34,6 +34,6 @@ class BinaryMutex final { NE_COPY_DEFAULT(BinaryMutex) private: - USER_PROCESS* fLockingProcess; + USER_PROCESS* fLockingProcess{nullptr}; }; } // namespace Kernel -- cgit v1.2.3 From 34758487e7630244dcec71ebf3995675ac2d1c27 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 3 Aug 2025 13:27:49 +0100 Subject: feat: LaTeX: update technical papers. feat: CPS: Assign image to nullptr in PROCESS_IMAGE container. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 11 ++++++----- docs/tex/NOTICE.md | 5 +++++ docs/tex/binary_mutex.tex | 2 +- docs/tex/coreprocessscheduler.tex | 13 +++---------- 4 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 docs/tex/NOTICE.md (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index 170244eb..b92d7393 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -90,6 +90,7 @@ struct PROCESS_FILE_TREE { struct PROCESS_FILE_TREE* Parent { nullptr }; + struct PROCESS_FILE_TREE* Child { nullptr }; @@ -97,6 +98,7 @@ struct PROCESS_FILE_TREE { struct PROCESS_FILE_TREE* Prev { nullptr }; + struct PROCESS_FILE_TREE* Next { nullptr }; @@ -115,8 +117,6 @@ enum class ProcessSubsystem : Int32 { kProcessSubsystemCount = 4, }; -typedef UInt64 PTime; - /***********************************************************************************/ //! @brief Local Process identifier. /***********************************************************************************/ @@ -179,7 +179,8 @@ inline bool operator>=(AffinityKind lhs, AffinityKind rhs) { return lhs_int >= rhs_int; } -using ProcessTime = UInt64; +using PTime = UInt64; +using ProcessTime = PTime; using PID = Int64; /***********************************************************************************/ @@ -209,8 +210,8 @@ struct PROCESS_IMAGE final { friend class UserProcessScheduler; - ImagePtr fCode; - ImagePtr fBlob; + ImagePtr fCode{}; + ImagePtr fBlob{}; public: Bool HasCode() const { return this->fCode != nullptr; } diff --git a/docs/tex/NOTICE.md b/docs/tex/NOTICE.md new file mode 100644 index 00000000..5d6eb03f --- /dev/null +++ b/docs/tex/NOTICE.md @@ -0,0 +1,5 @@ +# Notice for LaTeX documents. + +## Recommended Tool + +`pdflatex` is recommended for this matter, although you are free to use other tools. diff --git a/docs/tex/binary_mutex.tex b/docs/tex/binary_mutex.tex index 4e61eb65..cc5a7d3c 100644 --- a/docs/tex/binary_mutex.tex +++ b/docs/tex/binary_mutex.tex @@ -1,7 +1,7 @@ \documentclass{article} \usepackage{graphicx} % Required for inserting images -\title{BinaryMutex} +\title{BinaryMutex: Technical Documentation} \author{Amlal El Mahrouss} \date{\today} diff --git a/docs/tex/coreprocessscheduler.tex b/docs/tex/coreprocessscheduler.tex index 60f2b8cd..dd3594b1 100644 --- a/docs/tex/coreprocessscheduler.tex +++ b/docs/tex/coreprocessscheduler.tex @@ -2,7 +2,7 @@ \usepackage{graphicx} % Required for inserting images \usepackage{hyperref} -\title{CoreProcessScheduler} +\title{CoreProcessScheduler: Technical Documentation} \author{Amlal El Mahrouss} \date{\today} @@ -70,7 +70,7 @@ class UserProcessTeam final { {The process image container is a design pattern made to contain process data and metadata, its purpose comes from the lack of mainstream operating systems of such ability to hold metadata.} -\newline{} +\newline {This approach helps separate concerns and give modularity to the system, as the image and process structure are not mixed together.} @@ -123,17 +123,10 @@ struct PROCESS_IMAGE final { \section{References} -{Here are the reference material on this paper:} +{Here are the reference mentioned on this paper:} {NeKernel}: \href{https://github.com/nekernel-org/nekernel}{NeKernel} {CoreProcessScheduler}: \href{https://github.com/nekernel-org/nekernel/blob/dev/dev/kernel/KernelKit/CoreProcessScheduler.h}{CoreProcessScheduler} -\section{Hyperlinks} - -{NeKernel.org}: \href{https://nekernel.org}{NeKernel.org} -\newline -\newline -{SNU Systems}: \href{https://snu.systems}{SNU.Systems} - \end{document} -- cgit v1.2.3 From d728ff289123fff3443a897cca3fc6424634f536 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 4 Aug 2025 14:35:52 +0100 Subject: fix! PEFCodeMgr: critical fixes applied to PEF loader. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/PEFCodeMgr.h | 4 +-- dev/kernel/src/PEFCodeMgr.cc | 61 +++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 36 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/PEFCodeMgr.h b/dev/kernel/KernelKit/PEFCodeMgr.h index 899a1869..d61aa863 100644 --- a/dev/kernel/KernelKit/PEFCodeMgr.h +++ b/dev/kernel/KernelKit/PEFCodeMgr.h @@ -63,8 +63,8 @@ class PEFLoader : public LoaderInterface { Ref fPath; VoidPtr fCachedBlob; - bool fFatBinary; - bool fBad; + BOOL fFatBinary{}; + BOOL fBad{}; }; namespace Utils { diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index 71e4e232..d61a3cab 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -78,10 +78,9 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) container->Magic[3] == kPefMagic[3] && container->Magic[4] == kPefMagic[4] && container->Abi == kPefAbi) { return; - } else if (container->Magic[0] == kPefMagicFat[0] && - container->Magic[1] == kPefMagicFat[1] && container->Magic[2] == kPefMagicFat[2] && - container->Magic[3] == kPefMagicFat[3] && container->Magic[4] == kPefMagicFat[4] && - container->Abi == kPefAbi) { + } else if (container->Magic[0] == kPefMagicFat[0] && container->Magic[1] == kPefMagicFat[1] && + container->Magic[2] == kPefMagicFat[2] && container->Magic[3] == kPefMagicFat[3] && + container->Magic[4] == kPefMagicFat[4] && container->Abi == kPefAbi) { /// This is a fat binary, treat it as such. this->fFatBinary = true; return; @@ -111,9 +110,7 @@ PEFLoader::~PEFLoader() { /// @param kind kind of symbol we want. /***********************************************************************************/ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { - if (!fCachedBlob || fBad || !name) return ErrorOr{kErrorInvalidData}; - - PEFContainer* container = reinterpret_cast(fCachedBlob); + if (fBad || !name) return ErrorOr{kErrorInvalidData}; auto blob = fFile->Read(name, sizeof(PEFCommandHeader)); @@ -152,44 +149,40 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { } error_or_symbol.Leak().Leak() += name; - - for (SizeT index = 0; index < container->Count; ++index) { - if (KStringBuilder::Equals(container_header[index].Name, error_or_symbol.Leak().Leak().CData())) { - if (container_header[index].Kind == kind) { - if (container_header[index].Cpu != Detail::ldr_get_platform()) { - if (!this->fFatBinary) { - mm_free_ptr(blob); - return ErrorOr{kErrorInvalidData}; - } + if (KStringBuilder::Equals(container_header->Name, error_or_symbol.Leak().Leak().CData())) { + if (container_header->Kind == kind) { + if (container_header->Cpu != Detail::ldr_get_platform()) { + if (!this->fFatBinary) { + mm_free_ptr(blob); + return ErrorOr{kErrorInvalidData}; } + } - Char* container_blob_value = new Char[container_header[index].VMSize]; + Char* container_blob_value = new Char[container_header->VMSize]; - rt_copy_memory_safe((VoidPtr) ((Char*) blob + sizeof(PEFCommandHeader)), - container_blob_value, container_header[index].VMSize, - container_header[index].VMSize); + rt_copy_memory_safe((VoidPtr) ((Char*) blob + sizeof(PEFCommandHeader)), container_blob_value, + container_header->VMSize, container_header->VMSize); - mm_free_ptr(blob); + mm_free_ptr(blob); - kout << "PEFLoader: info: Loaded stub: " << container_header[index].Name << "!\r"; + kout << "PEFLoader: info: Loaded stub: " << container_header->Name << "!\r"; - auto ret = 0; + auto ret = 0; - auto pages_count = (container_header[index].VMSize + kPageSize - 1) / kPageSize; + auto pages_count = (container_header->VMSize + kPageSize - 1) / kPageSize; - for (SizeT i_vm{}; i_vm < pages_count; ++i_vm) { - ret = HAL::mm_map_page((VoidPtr) (container_header[index].VMAddress + (i_vm * kPageSize)), - (VoidPtr) HAL::mm_get_page_addr(container_blob_value), - HAL::kMMFlagsPresent | HAL::kMMFlagsUser); + for (SizeT i_vm{}; i_vm < pages_count; ++i_vm) { + ret = HAL::mm_map_page((VoidPtr) (container_header->VMAddress + (i_vm * kPageSize)), + (VoidPtr) HAL::mm_get_page_addr(container_blob_value), + HAL::kMMFlagsPresent | HAL::kMMFlagsUser); - if (ret != kErrorSuccess) { - delete[] container_blob_value; - return ErrorOr{kErrorInvalidData}; - } + if (ret != kErrorSuccess) { + delete[] container_blob_value; + return ErrorOr{kErrorInvalidData}; } - - return ErrorOr{container_blob_value}; } + + return ErrorOr{container_blob_value}; } } -- cgit v1.2.3 From 1bde51e7123ebe7660edecabd3d9dca355d1751f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 5 Aug 2025 05:29:06 +0100 Subject: feat: PEFCodeMgr: Improved FAT binary support, made code more readable. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/LockDelegate.h | 8 ++--- dev/kernel/src/PEFCodeMgr.cc | 59 ++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 28 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/LockDelegate.h b/dev/kernel/KernelKit/LockDelegate.h index b5977c92..a8c36de7 100644 --- a/dev/kernel/KernelKit/LockDelegate.h +++ b/dev/kernel/KernelKit/LockDelegate.h @@ -11,10 +11,10 @@ namespace Kernel { enum { - kLockInvalid = 0, - kLockDone = 200, - kLockTimedOut, - kLockCount = 3, + kLockInvalid = 0, + kLockDone = 200, + kLockTimedOut = 300, + kLockCount = 3, }; /// @brief Lock condition pointer. diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index 98830fdd..5611bafe 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -72,24 +72,25 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) PEFContainer* container = reinterpret_cast(fCachedBlob); - if (container->Cpu == Detail::ldr_get_platform() && container->Magic[0] == kPefMagic[0] && - container->Magic[1] == kPefMagic[1] && container->Magic[2] == kPefMagic[2] && - container->Magic[3] == kPefMagic[3] && container->Magic[4] == kPefMagic[4] && - container->Abi == kPefAbi) { - return; - } else if (container->Magic[0] == kPefMagicFat[0] && container->Magic[1] == kPefMagicFat[1] && - container->Magic[2] == kPefMagicFat[2] && container->Magic[3] == kPefMagicFat[3] && - container->Magic[4] == kPefMagicFat[4] && container->Abi == kPefAbi) { - /// This is a fat binary, treat it as such. - this->fFatBinary = true; - return; + if (container->Abi == kPefAbi) { + if (container->Cpu == Detail::ldr_get_platform() && container->Magic[0] == kPefMagic[0] && + container->Magic[1] == kPefMagic[1] && container->Magic[2] == kPefMagic[2] && + container->Magic[3] == kPefMagic[3] && container->Magic[4] == kPefMagic[4]) { + return; + } else if (container->Magic[0] == kPefMagicFat[0] && container->Magic[1] == kPefMagicFat[1] && + container->Magic[2] == kPefMagicFat[2] && container->Magic[3] == kPefMagicFat[3] && + container->Magic[4] == kPefMagicFat[4]) { + /// This is a fat binary, treat it as such. + this->fFatBinary = true; + return; + } } fBad = true; if (fCachedBlob) mm_free_ptr(fCachedBlob); - kout << "PEFLoader: warning: Executable format error!\r"; + kout << "PEFLoader: warning: exec format error!\r"; fCachedBlob = nullptr; } @@ -113,17 +114,19 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { auto blob = fFile->Read(name, sizeof(PEFCommandHeader)); + if (!blob) return ErrorOr{kErrorInvalidData}; + PEFContainer* container = reinterpret_cast(fCachedBlob); if (!container) return ErrorOr{kErrorInvalidData}; - if (container->Cpu != Detail::ldr_get_platform()) return ErrorOr{kErrorInvalidData}; - PEFCommandHeader* container_header = reinterpret_cast(blob); + PEFCommandHeader* command_header = reinterpret_cast(blob); - if (!container_header || container_header->VMSize < 1 || container_header->VMAddress == 0) + if (command_header->VMSize < 1 || command_header->VMAddress == 0) return ErrorOr{kErrorInvalidData}; - if (container_header->Cpu != container->Cpu) { + /// fat binary check. + if (command_header->Cpu != container->Cpu && !this->fFatBinary) { return ErrorOr{kErrorInvalidData}; } @@ -161,9 +164,9 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { error_or_symbol.Leak().Leak() += name; - if (KStringBuilder::Equals(container_header->Name, error_or_symbol.Leak().Leak().CData())) { - if (container_header->Kind == kind) { - if (container_header->Cpu != Detail::ldr_get_platform()) { + if (KStringBuilder::Equals(command_header->Name, error_or_symbol.Leak().Leak().CData())) { + if (command_header->Kind == kind) { + if (command_header->Cpu != Detail::ldr_get_platform()) { if (!this->fFatBinary) { mm_free_ptr(blob); blob = nullptr; @@ -172,26 +175,34 @@ ErrorOr PEFLoader::FindSymbol(const Char* name, Int32 kind) { } } - Char* container_blob_value = new Char[container_header->VMSize]; + Char* container_blob_value = new Char[command_header->VMSize]; rt_copy_memory_safe((VoidPtr) ((Char*) blob + sizeof(PEFCommandHeader)), container_blob_value, - container_header->VMSize, container_header->VMSize); + command_header->VMSize, command_header->VMSize); mm_free_ptr(blob); - kout << "PEFLoader: info: Loaded stub: " << container_header->Name << "!\r"; + kout << "PEFLoader: info: Loaded stub: " << command_header->Name << "!\r"; Int32 ret = 0; - SizeT pages_count = (container_header->VMSize + kPageSize - 1) / kPageSize; + SizeT pages_count = (command_header->VMSize + kPageSize - 1) / kPageSize; for (SizeT i_vm{}; i_vm < pages_count; ++i_vm) { ret = HAL::mm_map_page( - (VoidPtr) (container_header->VMAddress + (i_vm * kPageSize)), + (VoidPtr) (command_header->VMAddress + (i_vm * kPageSize)), (VoidPtr) (HAL::mm_get_page_addr(container_blob_value) + (i_vm * kPageSize)), HAL::kMMFlagsPresent | HAL::kMMFlagsUser); if (ret != kErrorSuccess) { + /// We set the VMAddress to nullptr, if the mapping fail here. + for (SizeT i_vm_unmap{}; i_vm_unmap < i_vm; ++i_vm_unmap) { + ret = HAL::mm_map_page((VoidPtr) (command_header->VMAddress + (i_vm * kPageSize)), + nullptr, HAL::kMMFlagsPresent | HAL::kMMFlagsUser); + } + delete[] container_blob_value; + container_blob_value = nullptr; + return ErrorOr{kErrorInvalidData}; } } -- cgit v1.2.3 From 7ada9006860084ba5d72b517649d1b2d51e4484a Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 9 Aug 2025 20:01:15 +0200 Subject: feat: warning fixes and Semaphore API patches. what: - The Semaphore API is being preppared for v0.0.4 Signed-off-by: Amlal --- dev/boot/BootKit/BootKit.h | 16 +-- dev/boot/modules/BootNet/BootNet.cc | 4 +- dev/boot/src/HEL/AMD64/BootATA.cc | 13 +- dev/boot/src/HEL/ARM64/BootPlatform.cc | 3 +- dev/boot/src/New+Delete.cc | 3 +- dev/kernel/FSKit/HeFS.h | 6 +- dev/kernel/FirmwareKit/EFI/EFI.h | 134 +++++++++++++-------- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 2 +- dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc | 3 +- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 5 +- dev/kernel/HALKit/AMD64/Paging.h | 4 +- dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc | 10 +- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 13 +- dev/kernel/HALKit/ARM64/CxxAbi.cc | 1 - dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc | 3 +- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 3 +- dev/kernel/HALKit/ARM64/Paging.h | 4 +- dev/kernel/HALKit/POWER/HalApplicationProcessor.cc | 3 +- dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc | 3 +- dev/kernel/KernelKit/CoreProcessScheduler.h | 2 +- dev/kernel/KernelKit/FileMgr.h | 1 - dev/kernel/KernelKit/HardwareThreadScheduler.h | 2 +- dev/kernel/KernelKit/KernelTaskScheduler.h | 5 +- dev/kernel/KernelKit/LoaderInterface.h | 6 +- dev/kernel/KernelKit/PCI/DMA.h | 2 +- dev/kernel/KernelKit/Semaphore.h | 5 +- dev/kernel/NeKit/Macros.h | 2 +- dev/kernel/NeKit/OwnPtr.h | 2 +- dev/kernel/NeKit/Ref.h | 2 +- dev/kernel/src/AsciiUtils.cc | 3 +- dev/kernel/src/BinaryMutex.cc | 2 +- dev/kernel/src/FS/NeFS+FileSystemParser.cc | 6 +- dev/kernel/src/IndexableProperty.cc | 16 ++- dev/libSystem/SystemKit/Macros.h | 2 +- dev/misc/BenchKit/Chrono.h | 12 +- dev/misc/BenchKit/X64Chrono.h | 2 +- dev/modules/Power/PowerFactory.h | 2 +- .../CoreFoundation.fwrk/headers/String.h | 6 +- .../frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc | 2 +- .../KernelTest.fwrk/headers/KernelTest.h | 20 +-- public/frameworks/KernelTest.fwrk/src/UnitTests.cc | 14 +-- public/tools/diutil/vendor/Dialogs.h | 41 +++---- public/tools/mgmt.oe/src/CommandLine.cc | 3 +- tools/fsck.hefs.cc | 10 +- tools/libmkfs/mkfs.h | 8 +- tools/mkfs.hefs.cc | 44 +++---- 46 files changed, 241 insertions(+), 214 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 68e4b484..12a5861f 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -293,16 +293,16 @@ inline Boolean BDiskFormatFactory::Format(const Char* part_name) { CopyMem(gpt_part->Signature, reinterpret_cast(const_cast(kMagicGPT)), StrLen(kMagicGPT)); - gpt_part->Revision = 0x00010000; + gpt_part->Revision = 0x00010000; gpt_part->HeaderSize = sizeof(GPT_PARTITION_TABLE); gpt_part->CRC32 = 0x00000000; - gpt_part->Reserved1 = 0x00000000; - gpt_part->LBAHeader = 0x00000000; - gpt_part->LBAAltHeader = 0x00000000; + gpt_part->Reserved1 = 0x00000000; + gpt_part->LBAHeader = 0x00000000; + gpt_part->LBAAltHeader = 0x00000000; gpt_part->FirstGPTEntry = 0x00000000; - gpt_part->LastGPTEntry = 0x00000000; + gpt_part->LastGPTEntry = 0x00000000; gpt_part->Guid.Data1 = 0x00000000; gpt_part->Guid.Data2 = 0x0000; @@ -312,10 +312,10 @@ inline Boolean BDiskFormatFactory::Format(const Char* part_name) { gpt_part->Revision = 0x00010000; - gpt_part->StartingLBA = 0x00000000; + gpt_part->StartingLBA = 0x00000000; gpt_part->NumPartitionEntries = 0x00000000; - gpt_part->SizeOfEntries = 0x00000000; - gpt_part->CRC32PartEntry = 0x00000000; + gpt_part->SizeOfEntries = 0x00000000; + gpt_part->CRC32PartEntry = 0x00000000; SetMem(gpt_part->Reserved2, 0, kSectorAlignGPT_PartTbl); diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 8236dd0d..d8ea5799 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -12,8 +12,8 @@ #include #include -STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; -STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; +STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, BOOTNET_INTERNET_HEADER** inet_out); diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc index 25810222..e5e0d8c2 100644 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -88,8 +88,7 @@ ATAInit_Retry: /// fetch serial info /// model, speed, number of sectors... - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); @@ -115,15 +114,14 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); @@ -149,15 +147,14 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); diff --git a/dev/boot/src/HEL/ARM64/BootPlatform.cc b/dev/boot/src/HEL/ARM64/BootPlatform.cc index 9dd03afe..683245fb 100644 --- a/dev/boot/src/HEL/ARM64/BootPlatform.cc +++ b/dev/boot/src/HEL/ARM64/BootPlatform.cc @@ -13,8 +13,7 @@ using namespace Boot; EXTERN_C void rt_halt() { - while (Yes) - ; + while (Yes); } EXTERN_C void rt_cli() {} diff --git a/dev/boot/src/New+Delete.cc b/dev/boot/src/New+Delete.cc index d4d5dfed..f7ad2898 100644 --- a/dev/boot/src/New+Delete.cc +++ b/dev/boot/src/New+Delete.cc @@ -17,8 +17,7 @@ void* operator new(size_t sz) { void* buf = nullptr; - while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk) - ; + while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) != kEfiOk); return buf; } diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 845ef467..bb4e3dc0 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -259,7 +259,7 @@ inline UInt32 hefs_hour_get(ATime raw_atime) noexcept { /// @return the minute value. /// @note The minute is stored in the lower 8 bits of the ATime value. inline UInt32 hefs_minute_get(ATime raw_atime) noexcept { - return (raw_atime) &0xFF; + return (raw_atime) & 0xFF; } inline constexpr UInt32 kHeFSBaseYear = 1970; @@ -379,10 +379,10 @@ class HeFileSystemParser final { ~HeFileSystemParser() = default; public: - HeFileSystemParser(const HeFileSystemParser&) = delete; + HeFileSystemParser(const HeFileSystemParser&) = delete; HeFileSystemParser& operator=(const HeFileSystemParser&) = delete; - HeFileSystemParser(HeFileSystemParser&&) = delete; + HeFileSystemParser(HeFileSystemParser&&) = delete; HeFileSystemParser& operator=(HeFileSystemParser&&) = delete; public: diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index 97e3ad01..9b22f5b6 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -57,7 +57,7 @@ typedef Char16 EfiChar16Type; /// @brief Core Handle Kind /// Self is like NT's Win32 HANDLE type. typedef struct EfiHandle { -} * EfiHandlePtr; +}* EfiHandlePtr; /* UEFI uses wide characters by default. */ typedef WideChar EfiCharType; @@ -239,63 +239,85 @@ typedef struct EfiTableHeader { UInt32 Reserved; } EfiTableHeader; -#define EFI_ACPI_TABLE_PROTOCOL_GUID \ - { \ - 0xffe06bdd, 0x6107, 0x46a6, { 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c } \ +#define EFI_ACPI_TABLE_PROTOCOL_GUID \ + { \ + 0xffe06bdd, 0x6107, 0x46a6, { \ + 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c \ + } \ } -#define EFI_LOAD_FILE_PROTOCOL_GUID \ - { \ - 0x56EC3091, 0x954C, 0x11d2, { 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_LOAD_FILE_PROTOCOL_GUID \ + { \ + 0x56EC3091, 0x954C, 0x11d2, { \ + 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } -#define EFI_LOAD_FILE2_PROTOCOL_GUID \ - { \ - 0x4006c0c1, 0xfcb3, 0x403e, { 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d } \ +#define EFI_LOAD_FILE2_PROTOCOL_GUID \ + { \ + 0x4006c0c1, 0xfcb3, 0x403e, { \ + 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d \ + } \ } -#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ - { \ - 0x5B1B31A1, 0x9562, 0x11d2, { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \ +#define EFI_LOADED_IMAGE_PROTOCOL_GUID \ + { \ + 0x5B1B31A1, 0x9562, 0x11d2, { \ + 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \ + } \ } -#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ - { \ - 0x9042a9de, 0x23dc, 0x4a38, { 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } \ +#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ + { \ + 0x9042a9de, 0x23dc, 0x4a38, { \ + 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a \ + } \ } -#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \ - { \ - 0xA19832B9, 0xAC25, 0x11D3, { 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ +#define EFI_SIMPLE_NETWORK_PROTOCOL_GUID \ + { \ + 0xA19832B9, 0xAC25, 0x11D3, { \ + 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d \ + } \ } #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000 -#define EFI_IP4_PROTOCOL_GUID \ - { \ - 0x41d94cd2, 0x35b6, 0x455a, { 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd } \ +#define EFI_IP4_PROTOCOL_GUID \ + { \ + 0x41d94cd2, 0x35b6, 0x455a, { \ + 0x82, 0x58, 0xd4, 0xe5, 0x13, 0x34, 0xaa, 0xdd \ + } \ } #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000 -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } -#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0xbc62157e, 0x3e33, 0x4fec, { 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf } \ +#define EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0xbc62157e, 0x3e33, 0x4fec, { \ + 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf \ + } \ } -#define EFI_DEVICE_PATH_PROTOCOL_GUID \ - { \ - 0x9576e91, 0x6d3f, 0x11d2, { 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_DEVICE_PATH_PROTOCOL_GUID \ + { \ + 0x9576e91, 0x6d3f, 0x11d2, { \ + 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } -#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ - { \ - 0x0964e5b22, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ + { \ + 0x0964e5b22, 0x6459, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } typedef UInt64(EfiImageUnload)(EfiHandlePtr ImageHandle); @@ -351,17 +373,17 @@ typedef struct { typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_TRANSMIT)(IN EFI_SIMPLE_NETWORK_PROTOCOL* This, IN UInt32 HeaderSize, IN UInt32 BufferSize, - IN Void* Buffer, - IN EfiMacAddress* SrcAddr OPTIONAL, + IN Void* Buffer, + IN EfiMacAddress* SrcAddr OPTIONAL, IN EfiMacAddress* DestAddr OPTIONAL, - IN UInt16* Protocol OPTIONAL); + IN UInt16* Protocol OPTIONAL); typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_RECEIVE)(IN EFI_SIMPLE_NETWORK_PROTOCOL* This, - OUT UInt32* HeaderSize OPTIONAL, + OUT UInt32* HeaderSize OPTIONAL, IN OUT UInt32* BufferSize, OUT Void* Buffer, - OUT EfiMacAddress* SrcAddr OPTIONAL, + OUT EfiMacAddress* SrcAddr OPTIONAL, OUT EfiMacAddress* DestAddr OPTIONAL, - OUT UInt16* Protocol OPTIONAL); + OUT UInt16* Protocol OPTIONAL); typedef struct EFI_SIMPLE_NETWORK_PROTOCOL { UInt64 Revision; @@ -506,9 +528,11 @@ typedef struct EFI_GUID EFI_FINAL { * Protocol stuff... */ -#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ - { \ - 0x387477c1, 0x69c7, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \ + { \ + 0x387477c1, 0x69c7, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } /** some helpers */ @@ -607,7 +631,7 @@ typedef struct { } EfiInputKey; typedef EfiStatusType(EFI_API* EfiInputReadKey)(IN EfiSimpleTextInputProtocol* This, - OUT EfiInputKey* Key); + OUT EfiInputKey* Key); typedef EfiStatusType(EFI_API* EfiInputReset)(IN EfiSimpleTextInputProtocol* This, IN Boolean ExtendedChk); @@ -665,7 +689,7 @@ typedef struct EfiSystemTable { struct { EFI_GUID VendorGUID; VoidPtr VendorTable; - } * ConfigurationTable; + }* ConfigurationTable; } EfiSystemTable; #define kEfiOk 0 @@ -726,9 +750,11 @@ enum { #define EFI_EXTRA_DESCRIPTOR_SIZE 8 -#define EFI_MP_SERVICES_PROTOCOL_GUID \ - { \ - 0x3fdda605, 0xa76e, 0x4f46, { 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 } \ +#define EFI_MP_SERVICES_PROTOCOL_GUID \ + { \ + 0x3fdda605, 0xa76e, 0x4f46, { \ + 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 \ + } \ } #define PROCESSOR_AS_BSP_BIT 0x00000001 @@ -825,9 +851,11 @@ typedef struct EfiTime { UInt8 Pad2; } EfiTime; -#define EFI_FILE_INFO_GUID \ - { \ - 0x09576e92, 0x6d3f, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ +#define EFI_FILE_INFO_GUID \ + { \ + 0x09576e92, 0x6d3f, 0x11d2, { \ + 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b \ + } \ } struct EfiFileInfo EFI_FINAL { @@ -896,8 +924,8 @@ typedef EfiStatusType EFI_API (*EfiMpServicesStartupThisAP)( IN Void* ProcedureArgument OPTIONAL, OUT Boolean* Finished OPTIONAL); typedef EfiStatusType EFI_API (*EfiMpServicesDisableThisAP)(IN struct _EfiMpServicesProtocol* Self, - IN UInt32 ProcessorNumber, - IN Boolean EnableAP, + IN UInt32 ProcessorNumber, + IN Boolean EnableAP, IN UInt32* HealthFlag OPTIONAL); typedef EfiStatusType EFI_API (*EfiMpServicesWhoAmI)(IN struct _EfiMpServicesProtocol* Self, diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 0dbd6815..4a667549 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -116,7 +116,7 @@ EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ThreadID thrdid) if (!stack_frame) return NO; if (thrdid > kSMPCount) return NO; - + if (!kSMPAware) { sched_jump_to_task(kHWThread[thrdid].mFramePtr); diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc index b837497e..0c2d0960 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc @@ -61,8 +61,7 @@ EXTERN_C void idt_handle_scheduler(Kernel::UIntPtr rsp) { hal_idt_send_eoi(32); - while (kIsRunning) - ; + while (kIsRunning); kIsRunning = YES; diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 39f7de1d..c7a87b13 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -42,7 +42,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { handover_hdr->f_HardwareTables.f_ImageHandle); kKernelVM = kHandoverHeader->f_PageStart; - + if (!kKernelVM) { MUST_PASS(kKernelVM); return kEfiFail; @@ -168,7 +168,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { idt_loader.Load(idt_reg); - while (YES) - ; + while (YES); } #endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ diff --git a/dev/kernel/HALKit/AMD64/Paging.h b/dev/kernel/HALKit/AMD64/Paging.h index 079acde4..cf297632 100644 --- a/dev/kernel/HALKit/AMD64/Paging.h +++ b/dev/kernel/HALKit/AMD64/Paging.h @@ -57,7 +57,9 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast(reg); } + inline UInt8 control_register_cast(ControlRegisterBits reg) { + return static_cast(reg); + } } // namespace Detail auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad = 0) -> VoidPtr; diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc index 39efb7d3..4688203f 100644 --- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc @@ -105,7 +105,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz - 1) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); @@ -123,8 +123,7 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz rt_out8(kATADevice.Bar(0x20) + 0x00, 0x09); // Start DMA engine - while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01) - ; + while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01); rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine @@ -147,7 +146,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz - 1)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); @@ -163,8 +162,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + 0x00, 0x09); // Start DMA engine - while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01) - ; + while (rt_in8(kATADevice.Bar(0x20) + ATA_REG_STATUS) & 0x01); rt_out8(kATADevice.Bar(0x20) + 0x00, 0x00); // Stop DMA engine diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 6fccbdfa..9c5b3931 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -83,8 +83,7 @@ ATAInit_Retry: rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); /// fetch serial info /// model, speed, number of sectors... @@ -117,15 +116,14 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { drv_pio_std_wait_io(IO); @@ -149,15 +147,14 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) - ; + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { drv_pio_std_wait_io(IO); diff --git a/dev/kernel/HALKit/ARM64/CxxAbi.cc b/dev/kernel/HALKit/ARM64/CxxAbi.cc index 09898b08..964fc2f4 100644 --- a/dev/kernel/HALKit/ARM64/CxxAbi.cc +++ b/dev/kernel/HALKit/ARM64/CxxAbi.cc @@ -85,4 +85,3 @@ EXTERN_C Kernel::Void _Init_thread_header(Kernel::Int* thread_obj) { } EXTERN_C Kernel::Int _tls_index = 0UL; - diff --git a/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc index 0c26f4cb..63a42de8 100644 --- a/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/ARM64/HalCoreInterruptHandler.cc @@ -56,8 +56,7 @@ EXTERN_C void int_handle_scheduler(Kernel::UIntPtr rsp) { hal_int_send_eoi(32); - while (kIsRunning) - ; + while (kIsRunning); kIsRunning = YES; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 20bd3d8a..d8e6843b 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -71,7 +71,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { Kernel::mp_init_cores(); - while (YES) - ; + while (YES); } #endif \ No newline at end of file diff --git a/dev/kernel/HALKit/ARM64/Paging.h b/dev/kernel/HALKit/ARM64/Paging.h index 7a022141..be9fb116 100644 --- a/dev/kernel/HALKit/ARM64/Paging.h +++ b/dev/kernel/HALKit/ARM64/Paging.h @@ -86,7 +86,9 @@ namespace Detail { PageEnable = 31, }; - inline UInt8 control_register_cast(ControlRegisterBits reg) { return static_cast(reg); } + inline UInt8 control_register_cast(ControlRegisterBits reg) { + return static_cast(reg); + } } // namespace Detail struct PDE_4KB final { diff --git a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc index daa26e53..6059e3be 100644 --- a/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/POWER/HalApplicationProcessor.cc @@ -10,8 +10,7 @@ namespace Kernel::Detail { STATIC void mp_hang_fn(void) { - while (YES) - ; + while (YES); } } // namespace Kernel::Detail diff --git a/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc b/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc index 31d4a62e..e6fdddfb 100644 --- a/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/RISCV/HalApplicationProcessor.cc @@ -13,8 +13,7 @@ using namespace Kernel; namespace Kernel { namespace Detail { STATIC void mp_hang_fn(void) { - while (YES) - ; + while (YES); } } // namespace Detail diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index b92d7393..a7908b7d 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -98,7 +98,7 @@ struct PROCESS_FILE_TREE { struct PROCESS_FILE_TREE* Prev { nullptr }; - + struct PROCESS_FILE_TREE* Next { nullptr }; diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index d1334277..f925a96c 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -22,7 +22,6 @@ #ifndef INC_FILEMGR_H #define INC_FILEMGR_H - /// @file FileMgr.h /// @brief File Manager. /// @author Amlal El Mahrouss (amlal@nekernel.org) diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index 76327a93..168a0cc1 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -100,7 +100,7 @@ class HardwareThreadScheduler final : public ISchedulable { public: Ref operator[](SizeT idx); bool operator!() noexcept; - operator bool() noexcept; + operator bool() noexcept; Bool IsUser() override { return Yes; } diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index 222041e8..c0879769 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -29,8 +29,9 @@ class KERNEL_TASK final { UInt8* StackReserve{nullptr}; SizeT StackSize{kSchedMaxStackSz}; PROCESS_IMAGE Image{}; - /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within the kernel. - KID Kid{0}; + /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within + /// the kernel. + KID Kid{0}; }; /// @brief Equivalent of UserProcessHelper, but for kernel tasks. diff --git a/dev/kernel/KernelKit/LoaderInterface.h b/dev/kernel/KernelKit/LoaderInterface.h index 1f9b1e56..ed7d8364 100644 --- a/dev/kernel/KernelKit/LoaderInterface.h +++ b/dev/kernel/KernelKit/LoaderInterface.h @@ -23,9 +23,9 @@ class LoaderInterface { public: virtual _Output ErrorOr GetBlob() = 0; - virtual _Output const Char* AsString() = 0; - virtual _Output const Char* MIME() = 0; - virtual _Output const Char* Path() = 0; + virtual _Output const Char* AsString() = 0; + virtual _Output const Char* MIME() = 0; + virtual _Output const Char* Path() = 0; virtual _Output ErrorOr FindStart() = 0; virtual _Output ErrorOr FindSymbol(_Input const Char* name, _Input Int32 kind) = 0; }; diff --git a/dev/kernel/KernelKit/PCI/DMA.h b/dev/kernel/KernelKit/PCI/DMA.h index 7e7d3f0c..c4e3b61a 100644 --- a/dev/kernel/KernelKit/PCI/DMA.h +++ b/dev/kernel/KernelKit/PCI/DMA.h @@ -47,7 +47,7 @@ class DMAWrapper final { T* Get(UIntPtr off = 0); public: - operator bool(); + operator bool(); bool operator!(); public: diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 930b245d..705d9f18 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -28,7 +28,7 @@ typedef UInt64 SemaphoreArr[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. inline BOOL rtl_sem_is_valid(const SemaphoreArr& sem, UInt64 owner = 0) { - return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] >= 0; + return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0; } /// @brief Releases the semaphore, resetting its owner and count. @@ -61,7 +61,8 @@ inline BOOL rtl_sem_acquire(SemaphoreArr& sem, UInt64 owner) { /// @param sem /// @param timeout /// @return -inline BOOL rtl_sem_wait(SemaphoreArr& sem, UInt64 owner, UInt64 timeout, BOOL* condition = nullptr) { +inline BOOL rtl_sem_wait(SemaphoreArr& sem, UInt64 owner, UInt64 timeout, + BOOL* condition = nullptr) { if (!rtl_sem_is_valid(sem, owner)) { return FALSE; } diff --git a/dev/kernel/NeKit/Macros.h b/dev/kernel/NeKit/Macros.h index b46ffaa8..e80e2e47 100644 --- a/dev/kernel/NeKit/Macros.h +++ b/dev/kernel/NeKit/Macros.h @@ -16,7 +16,7 @@ #endif #ifndef kib_cast -#define kib_cast(X) (Kernel::UInt64)((X) *1024) +#define kib_cast(X) (Kernel::UInt64)((X) * 1024) #endif #ifndef MIB diff --git a/dev/kernel/NeKit/OwnPtr.h b/dev/kernel/NeKit/OwnPtr.h index 674f9ff3..f5ff4b54 100644 --- a/dev/kernel/NeKit/OwnPtr.h +++ b/dev/kernel/NeKit/OwnPtr.h @@ -50,7 +50,7 @@ class OwnPtr final { Ref AsRef() { return Ref(fCls); } - operator bool() { return fCls; } + operator bool() { return fCls; } bool operator!() { return !fCls; } private: diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 4d343bc5..46e94f88 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -29,7 +29,7 @@ class Ref final { return *this; } - NE_COPY_DEFAULT(Ref); + NE_COPY_DEFAULT(Ref) public: T operator->() const { return fClass; } diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 24e4e220..66a4aaef 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -73,8 +73,7 @@ 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(src); UInt8 v = static_cast(value & 0xFF); diff --git a/dev/kernel/src/BinaryMutex.cc b/dev/kernel/src/BinaryMutex.cc index f669d7fa..9bfb89d9 100644 --- a/dev/kernel/src/BinaryMutex.cc +++ b/dev/kernel/src/BinaryMutex.cc @@ -14,7 +14,7 @@ namespace Kernel { Bool BinaryMutex::Unlock() noexcept { if (fLockingProcess->Status == ProcessStatusKind::kRunning) { - fLockingProcess = nullptr; + fLockingProcess = nullptr; return Yes; } diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 14e0b974..7b9ebcd6 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 c11e328d..251d6645 100644 --- a/dev/kernel/src/IndexableProperty.cc +++ b/dev/kernel/src/IndexableProperty.cc @@ -18,13 +18,21 @@ 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/libSystem/SystemKit/Macros.h b/dev/libSystem/SystemKit/Macros.h index 2bdeff9d..25bc77ba 100644 --- a/dev/libSystem/SystemKit/Macros.h +++ b/dev/libSystem/SystemKit/Macros.h @@ -94,7 +94,7 @@ typedef nullPtr NullPtr; #endif #ifndef kib_cast -#define kib_cast(X) (UInt64)((X) *1024) +#define kib_cast(X) (UInt64)((X) * 1024) #endif #ifndef MIB diff --git a/dev/misc/BenchKit/Chrono.h b/dev/misc/BenchKit/Chrono.h index c6801de5..3a82a94e 100644 --- a/dev/misc/BenchKit/Chrono.h +++ b/dev/misc/BenchKit/Chrono.h @@ -24,13 +24,17 @@ class ChronoInterface { ChronoInterface() = default; virtual ~ChronoInterface() = default; - NE_COPY_DEFAULT(ChronoInterface); + NE_COPY_DEFAULT(ChronoInterface) - virtual void Start() = 0; - virtual void Stop() = 0; - virtual void Reset() = 0; + virtual Void Start() = 0; + virtual Void Stop() = 0; + virtual Void Reset() = 0; virtual UInt64 GetElapsedTime() const = 0; }; } // namespace Kernel +namespace BenchKit { +using namespace Kernel; +} + #endif // BENCHKIT_CHRONO_H diff --git a/dev/misc/BenchKit/X64Chrono.h b/dev/misc/BenchKit/X64Chrono.h index 358c74d4..ac92ebb1 100644 --- a/dev/misc/BenchKit/X64Chrono.h +++ b/dev/misc/BenchKit/X64Chrono.h @@ -19,7 +19,7 @@ struct X64ChronoTraits { private: STATIC UInt64 TickImpl_(void) { UInt64 a = 0, d = 0; - + asm volatile("rdtsc" : "=a"(a), "=d"(d)); return (d << 32) | a; } diff --git a/dev/modules/Power/PowerFactory.h b/dev/modules/Power/PowerFactory.h index b7c13280..ba3a8da6 100644 --- a/dev/modules/Power/PowerFactory.h +++ b/dev/modules/Power/PowerFactory.h @@ -27,6 +27,6 @@ class PowerFactory { public: Bool Shutdown() { return NO; }; // shutdown - Void Reboot(){}; // soft-reboot + Void Reboot() {}; // soft-reboot }; } // namespace Kernel \ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/headers/String.h b/public/frameworks/CoreFoundation.fwrk/headers/String.h index ea32038d..80b68536 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/String.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/String.h @@ -14,10 +14,10 @@ class CFString; class CFString final CF_OBJECT { public: - CFString() = default; + CFString() = default; ~CFString() = default; - - CFString(const CFString&) = delete; + + CFString(const CFString&) = delete; CFString& operator=(const CFString&) = delete; }; } // namespace CF \ No newline at end of file diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc index 1291a3e1..83b52905 100644 --- a/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc +++ b/public/frameworks/DiskImage.fwrk/src/DiskImage+EPM.cc @@ -38,7 +38,7 @@ SInt32 DI::DIFormatPartitionEPM(struct DI_DISK_IMAGE& img) noexcept { if (!handle) return kDIFailureStatus; ::IoWriteFile(handle, (Char*) &block, sizeof(struct ::EPM_PART_BLOCK)); - + ::IoCloseFile(handle); handle = nullptr; diff --git a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h index 9d4fd351..70b1b9b3 100644 --- a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h +++ b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h @@ -18,14 +18,18 @@ #define KT_TEST_SUCCESS (0) -#define KT_DECL_TEST(NAME, FN) \ - class KT_##NAME final { \ - public: \ - Kernel::Void Run(); \ - const Kernel::Char* ToString(); \ - }; \ - inline Kernel::Void KT_##NAME::Run() { MUST_PASS(FN() == true); } \ - inline const Kernel::Char* KT_##NAME::ToString() { return #FN; } +#define KT_DECL_TEST(NAME, FN) \ + class KT_##NAME final { \ + public: \ + Kernel::Void Run(); \ + const Kernel::Char* ToString(); \ + }; \ + inline Kernel::Void KT_##NAME::Run() { \ + MUST_PASS(FN() == true); \ + } \ + inline const Kernel::Char* KT_##NAME::ToString() { \ + return #FN; \ + } KT_DECL_TEST(ALWAYS_BREAK, []() -> bool { return false; }); KT_DECL_TEST(ALWAYS_GOOD, []() -> bool { return true; }); \ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc b/public/frameworks/KernelTest.fwrk/src/UnitTests.cc index a02d1499..07e7b129 100644 --- a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc +++ b/public/frameworks/KernelTest.fwrk/src/UnitTests.cc @@ -6,14 +6,12 @@ #include -EXTERN_C Kernel::Void KT_TestBreak() -{ - KT_ALWAYS_BREAK brk; - brk.Run(); +EXTERN_C Kernel::Void KT_TestBreak() { + KT_ALWAYS_BREAK brk; + brk.Run(); } -EXTERN_C Kernel::Void KT_TestGood() -{ - KT_ALWAYS_GOOD good; - good.Run(); +EXTERN_C Kernel::Void KT_TestGood() { + KT_ALWAYS_GOOD good; + good.Run(); } \ No newline at end of file diff --git a/public/tools/diutil/vendor/Dialogs.h b/public/tools/diutil/vendor/Dialogs.h index 84e239f5..ce50b811 100644 --- a/public/tools/diutil/vendor/Dialogs.h +++ b/public/tools/diutil/vendor/Dialogs.h @@ -175,7 +175,7 @@ namespace internal { #elif __EMSCRIPTEN__ void start(int exit_code); #else - void start_process(std::vector const& command); + void start_process(std::vector const& command); #endif ~executor(); @@ -490,10 +490,10 @@ inline settings::settings(bool resync) { #if _WIN32 flags(flag::is_vista) = internal::is_vista(); #elif !__APPLE__ - flags(flag::has_zenity) = check_program("zenity"); + flags(flag::has_zenity) = check_program("zenity"); flags(flag::has_matedialog) = check_program("matedialog"); - flags(flag::has_qarma) = check_program("qarma"); - flags(flag::has_kdialog) = check_program("kdialog"); + flags(flag::has_qarma) = check_program("qarma"); + flags(flag::has_kdialog) = check_program("kdialog"); // If multiple helpers are available, try to default to the best one if (flags(flag::has_zenity) && flags(flag::has_kdialog)) { @@ -540,7 +540,7 @@ inline bool settings::check_program(std::string const& program) { (void) program; return false; #else - int exit_code = -1; + int exit_code = -1; internal::executor async; async.start_process({"/bin/sh", "-c", "which " + program}); async.result(&exit_code); @@ -604,7 +604,7 @@ inline std::string path::home() { if (size_max != -1) len = size_t(size_max); #endif std::vector buf(len); - struct passwd pwd, *result; + struct passwd pwd, *result; if (getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result) == 0) return result->pw_dir; #endif return "/"; @@ -717,7 +717,7 @@ inline void internal::executor::start_process(std::vector const& co } close(in[1]); - m_fd = out[0]; + m_fd = out[0]; auto flags = fcntl(m_fd, F_GETFL); fcntl(m_fd, F_SETFL, flags | O_NONBLOCK); @@ -753,7 +753,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // FIXME: do something (void) timeout; #else - char buf[BUFSIZ]; + char buf[BUFSIZ]; ssize_t received = read(m_fd, buf, BUFSIZ); // Flawfinder: ignore if (received > 0) { m_stdout += std::string(buf, received); @@ -764,7 +764,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) // (this happens when the calling application handles or ignores SIG_CHLD) and results in // waitpid() failing with ECHILD. Otherwise we assume the child is running and we sleep for // a little while. - int status; + int status; pid_t child = waitpid(m_pid, &status, WNOHANG); if (child != m_pid && (child >= 0 || errno != ECHILD)) { // FIXME: this happens almost always at first iteration @@ -782,8 +782,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */) inline void internal::executor::stop() { // Loop until the user closes the dialog - while (!ready()) - ; + while (!ready()); } // dll implementation @@ -879,11 +878,11 @@ inline std::vector internal::dialog::desktop_helper() const { #if __APPLE__ return {"osascript"}; #else - return {flags(flag::has_zenity) ? "zenity" + return {flags(flag::has_zenity) ? "zenity" : flags(flag::has_matedialog) ? "matedialog" - : flags(flag::has_qarma) ? "qarma" - : flags(flag::has_kdialog) ? "kdialog" - : "echo"}; + : flags(flag::has_qarma) ? "qarma" + : flags(flag::has_kdialog) ? "kdialog" + : "echo"}; #endif } @@ -1125,9 +1124,9 @@ inline internal::file_dialog::file_dialog(type in_type, std::string const& title // Split the pattern list to check whether "*" is in there; if it // is, we have to disable filters because there is no mechanism in // OS X for the user to override the filter. - std::regex sep("\\s+"); - std::string filter_list; - bool has_filter = true; + std::regex sep("\\s+"); + std::string filter_list; + bool has_filter = true; std::sregex_token_iterator iter(patterns.begin(), patterns.end(), sep, -1); std::sregex_token_iterator end; for (; iter != end; ++iter) { @@ -1236,7 +1235,7 @@ inline std::vector internal::file_dialog::vector_result() { return m_vector_result; #else std::vector ret; - auto result = m_async->result(); + auto result = m_async->result(); for (;;) { // Split result along newline characters auto i = result.find('\n'); @@ -1569,7 +1568,7 @@ inline message::message(std::string const& title, std::string const& text, if_cancel = button::ok; break; } - m_mappings[1] = if_cancel; + m_mappings[1] = if_cancel; m_mappings[256] = if_cancel; // XXX: I think this was never correct script += " with icon "; switch (_icon) { @@ -1656,7 +1655,7 @@ inline message::message(std::string const& title, std::string const& text, if (_choice == choice::yes_no_cancel) flag += "cancel"; command.push_back(flag); if (_choice == choice::yes_no || _choice == choice::yes_no_cancel) { - m_mappings[0] = button::yes; + m_mappings[0] = button::yes; m_mappings[256] = button::no; } } diff --git a/public/tools/mgmt.oe/src/CommandLine.cc b/public/tools/mgmt.oe/src/CommandLine.cc index 3888476c..3a0c192d 100644 --- a/public/tools/mgmt.oe/src/CommandLine.cc +++ b/public/tools/mgmt.oe/src/CommandLine.cc @@ -22,7 +22,8 @@ SInt32 _NeMain(SInt32 argc, Char* argv[]) { ::PrintOut(nullptr, "%s", "mgmt.oe: OpenEnclave Management Tool."); - /// @note JailGetCurrent returns client as nullptr if we're not that client (we'll not be able to access the jail then) + /// @note JailGetCurrent returns client as nullptr if we're not that client (we'll not be able to + /// access the jail then) if (kJailSrv->fClient == nullptr) return EXIT_FAILURE; return EXIT_FAILURE; diff --git a/tools/fsck.hefs.cc b/tools/fsck.hefs.cc index e3837b8a..5a41cec2 100644 --- a/tools/fsck.hefs.cc +++ b/tools/fsck.hefs.cc @@ -9,12 +9,11 @@ #include #include -static uint16_t kNumericalBase = 10; +static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { if (argc < 2) { - mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" - << "\n"; + mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" << "\n"; return EXIT_FAILURE; } @@ -25,8 +24,7 @@ int main(int argc, char** argv) { auto origin = mkfs::get_option(args, "-o"); if (opt_disk.empty()) { - mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." - << "\n"; + mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." << "\n"; return EXIT_FAILURE; } @@ -54,7 +52,7 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); - + output_device.read(reinterpret_cast(&boot_node), sizeof(boot_node)); if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || diff --git a/tools/libmkfs/mkfs.h b/tools/libmkfs/mkfs.h index e729c29b..6e242293 100644 --- a/tools/libmkfs/mkfs.h +++ b/tools/libmkfs/mkfs.h @@ -7,8 +7,8 @@ #pragma once #include -#include #include +#include #include #define kMkFsSectorSz (512U) @@ -35,13 +35,13 @@ namespace detail { inline bool parse_signed(const std::string& opt, long& out, int base = 10) { out = 0L; - + if (opt.empty()) return true; char* endptr = nullptr; long val = std::strtol(opt.c_str(), &endptr, base); - auto err = errno; - + auto err = errno; + if (err == ERANGE || err == EINVAL) return false; if (endptr == opt.c_str() || *endptr != '\0') return false; diff --git a/tools/mkfs.hefs.cc b/tools/mkfs.hefs.cc index bf790598..9f70b78f 100644 --- a/tools/mkfs.hefs.cc +++ b/tools/mkfs.hefs.cc @@ -15,7 +15,7 @@ static size_t kDiskSize = mkfs::detail::gib_cast(4UL); static uint16_t kVersion = kHeFSVersion; static std::u8string kLabel; -static size_t kSectorSize = 512; +static size_t kSectorSize = 512; static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { @@ -91,22 +91,22 @@ int main(int argc, char** argv) { mkfs::console_out() << "hefs: error: Invalid -b argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_e, end_ind, kNumericalBase) || end_ind <= start_ind) { mkfs::console_out() << "hefs: error: Invalid or out-of-range -e argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_bs, start_block, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -bs argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_be, end_block, kNumericalBase) || end_block <= start_block) { mkfs::console_out() << "hefs: error: Invalid or out-of-range -be argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_is, start_in, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -is argument.\n"; return EXIT_FAILURE; @@ -133,24 +133,24 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); - boot_node.version = kVersion; - boot_node.diskKind = mkfs::hefs::kHeFSHardDrive; - boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8; - boot_node.diskSize = kDiskSize; - boot_node.sectorSize = kSectorSize; + boot_node.version = kVersion; + boot_node.diskKind = mkfs::hefs::kHeFSHardDrive; + boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8; + boot_node.diskSize = kDiskSize; + boot_node.sectorSize = kSectorSize; boot_node.sectorCount = kDiskSize / kSectorSize; - boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); - boot_node.endIND = static_cast(end_ind); - boot_node.startIN = static_cast(start_in); - boot_node.endIN = static_cast(end_in); - boot_node.startBlock = static_cast(start_block); - boot_node.endBlock = static_cast(end_block); - boot_node.indCount = 0UL; - boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; + boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); + boot_node.endIND = static_cast(end_ind); + boot_node.startIN = static_cast(start_in); + boot_node.endIN = static_cast(end_in); + boot_node.startBlock = static_cast(start_block); + boot_node.endBlock = static_cast(end_block); + boot_node.indCount = 0UL; + boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; static_assert(sizeof(boot_node.magic) >= kHeFSMagicLen, "BootNode::magic too small to hold kHeFSMagicLen"); - + std::memset(boot_node.magic, 0, sizeof(boot_node.magic)); size_t magic_copy = (sizeof(boot_node.magic) < kHeFSMagicLen - 1) ? sizeof(boot_node.magic) : (kHeFSMagicLen - 1); @@ -158,15 +158,15 @@ int main(int argc, char** argv) { boot_node.magic[magic_copy] = 0; constexpr size_t vol_slots = kHeFSPartNameLen; - + std::memset(boot_node.volumeName, 0, sizeof(boot_node.volumeName)); - + size_t label_units = std::min(kLabel.size(), vol_slots - 1); for (size_t i = 0; i < label_units; ++i) { boot_node.volumeName[i] = static_cast(kLabel[i]); } - + boot_node.volumeName[label_units] = 0U; output_device.seekp(static_cast(start_ind)); -- cgit v1.2.3 From f3c12b72db9e6983741c0d79fd7f8903c23d93d4 Mon Sep 17 00:00:00 2001 From: Amlal Date: Mon, 11 Aug 2025 09:38:55 +0200 Subject: feat: Semaphore API has been documented, RTL driver improvements, and better help for fsck.hefs. Signed-off-by: Amlal --- .../HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 30 +++++++++++++++------- dev/kernel/KernelKit/Semaphore.h | 5 ++-- tools/fsck.hefs.cc | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc index 3ccbfa24..bf0731c6 100644 --- a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc +++ b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc @@ -13,10 +13,9 @@ using namespace Kernel::HAL; STATIC UInt16 kRTLIOBase = 0xFFFF; -STATIC BOOL kTXEnabled = NO; - -STATIC UInt32 kRXOffset = 0UL; +STATIC BOOL kTXRXEnabled = NO; +STATIC UInt32 kRXOffset = 0UL; STATIC constexpr CONST UInt32 kRXBufferSize = 8192 + 16 + 1500; STATIC UInt8* kRXUpperLayer = nullptr; @@ -26,8 +25,8 @@ STATIC UInt8* kRXBuffer = nullptr; ///@brief RTL8139 Init routine. /***********************************************************************************/ -EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { - if (kTXEnabled) return; +EXTERN_C BOOL rtl_init_nic_rtl8139(UInt16 io_base) noexcept { + if (kTXRXEnabled) return NO; kRTLIOBase = io_base; @@ -49,8 +48,7 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { } if (timeout <= 0x1000) { - ke_panic(RUNTIME_CHECK_BAD_BEHAVIOR, "RTL8139: Reset failed"); - return; + return NO; } rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRXBuffer); @@ -61,7 +59,9 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { rt_out16(io_base + 0x3C, 0x0005); - kTXEnabled = YES; + kTXRXEnabled = YES; + + return YES; } /***********************************************************************************/ @@ -69,7 +69,7 @@ EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { /// @note This function is called when the device interrupts to retrieve network data. /***********************************************************************************/ -EXTERN_C void rtl_rtl8139_interrupt_handler() { +EXTERN_C Void rtl_rtl8139_interrupt_handler(UIntPtr rsp) { if (kRTLIOBase == 0xFFFF) return; UInt16 status = rt_in16(kRTLIOBase + 0x3E); @@ -111,4 +111,16 @@ EXTERN_C void rtl_rtl8139_interrupt_handler() { EXTERN_C UInt8* rtl_rtl8139_get_upper_layer() { return kRXUpperLayer; +} + +/***********************************************************************************/ +/// @brief RTL8139 set upper layer function +/// @param layer the upper layer. +/***********************************************************************************/ + +EXTERN_C BOOL rtl_rtl8139_set_upper_layer(UInt8* layer) { + if (!layer) return NO; + kRXUpperLayer = layer; + + return YES; } \ No newline at end of file diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 705d9f18..f73f36ed 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -42,8 +42,8 @@ inline BOOL rtl_sem_release(SemaphoreArr& sem) { } /// @brief Initializes the semaphore with an owner and a count of zero. -/// @param sem -/// @param owner +/// @param sem the semaphore array to use. +/// @param owner the owner to set, could be anything identifitable. /// @return inline BOOL rtl_sem_acquire(SemaphoreArr& sem, UInt64 owner) { if (!owner) { @@ -60,6 +60,7 @@ inline BOOL rtl_sem_acquire(SemaphoreArr& sem, UInt64 owner) { /// @brief Waits for the semaphore to be available, blocking until it is. /// @param sem /// @param timeout +/// @param condition condition pointer. /// @return inline BOOL rtl_sem_wait(SemaphoreArr& sem, UInt64 owner, UInt64 timeout, BOOL* condition = nullptr) { diff --git a/tools/fsck.hefs.cc b/tools/fsck.hefs.cc index 5a41cec2..eb6a66d8 100644 --- a/tools/fsck.hefs.cc +++ b/tools/fsck.hefs.cc @@ -13,7 +13,7 @@ static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { if (argc < 2) { - mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" << "\n"; + mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i= -o=" << "\n"; return EXIT_FAILURE; } -- cgit v1.2.3 From 621310537c26e8ac0fb3c0d2e38aaa12e3945eec Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 12 Aug 2025 19:35:27 +0200 Subject: feat! abi! Breaking ABI changes in the PEF format! Signed-off-by: Amlal --- dev/kernel/KernelKit/PEF.h | 1 + dev/kernel/src/PEFCodeMgr.cc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index ed6fc423..f306c52e 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -98,6 +98,7 @@ typedef struct PEFCommandHeader final { UInt32 Flags; /* container flags */ UInt16 Kind; /* container kind */ UIntPtr Offset; /* content offset */ + SizeT OffsetSize; /* offset size (physical size inside the file) */ UIntPtr VMAddress; /* Virtual Address */ SizeT VMSize; /* Virtual Size */ } PACKED PEFCommandHeader; diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index 3cbc4faa..c0caeb5b 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -71,7 +71,9 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false) PEFContainer* container = reinterpret_cast(fCachedBlob); - if (container->Abi == kPefAbi) { + if (container->Abi == kPefAbi && + container->Count >= + 3) { /* if same ABI, AND: .text, .bss, .data (or at least similar) exists */ if (container->Cpu == Detail::ldr_get_platform() && container->Magic[0] == kPefMagic[0] && container->Magic[1] == kPefMagic[1] && container->Magic[2] == kPefMagic[2] && container->Magic[3] == kPefMagic[3] && container->Magic[4] == kPefMagic[4]) { -- cgit v1.2.3 From b301047903b79560dce69085fc271a653a1eb4b6 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 16 Aug 2025 00:03:56 +0200 Subject: feat: ACPI: Better error handling. Signed-off-by: Amlal --- dev/kernel/KernelKit/PEF.h | 6 +++--- dev/kernel/src/ACPIFactoryInterface.cc | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'dev/kernel/KernelKit') diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index f306c52e..fd39392e 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -11,8 +11,8 @@ ------------------------------------------- */ -#ifndef KERNELKIT_PEF_H -#define KERNELKIT_PEF_H +#ifndef __KERNELKIT_PEF_H__ +#define __KERNELKIT_PEF_H__ #include #include @@ -113,4 +113,4 @@ enum { }; } // namespace Kernel -#endif /* ifndef KERNELKIT_PEF_H */ +#endif /* ifndef __KERNELKIT_PEF_H__ */ diff --git a/dev/kernel/src/ACPIFactoryInterface.cc b/dev/kernel/src/ACPIFactoryInterface.cc index 8cc11cad..01f30500 100644 --- a/dev/kernel/src/ACPIFactoryInterface.cc +++ b/dev/kernel/src/ACPIFactoryInterface.cc @@ -10,12 +10,11 @@ #include namespace Kernel { -constexpr STATIC const auto kMinACPIVer = 1; +constexpr STATIC const auto kMinACPIVer = 1U; /// @brief Finds a descriptor table inside ACPI XSDT. ErrorOr ACPIFactoryInterface::Find(const Char* signature) { - MUST_PASS(this->fRsdp); - + if (this->fRsdp) return ErrorOr{kErrorInvalidData}; if (!signature) return ErrorOr{-kErrorInvalidData}; if (*signature == 0) return ErrorOr{-kErrorInvalidData}; @@ -33,7 +32,7 @@ ErrorOr ACPIFactoryInterface::Find(const Char* signature) { if (num < 1) { /// stop here, we should have entries... ke_panic(RUNTIME_CHECK_ACPI); - return ErrorOr{-1}; + return ErrorOr{-kErrorInvalidData}; } this->fEntries = num; @@ -62,7 +61,7 @@ ErrorOr ACPIFactoryInterface::Find(const Char* signature) { } } - return ErrorOr{-1}; + return ErrorOr{-kErrorInvalidData}; } /*** -- cgit v1.2.3