From 88a8745e45f525e5fb12b6b048df87afabebbfc9 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 3 Jun 2025 23:14:16 +0200 Subject: feat: TLS: Improved its implementation, and add a user field for additional checks. refactor: Reworked `open_msg`'s messaging system. refactor: Rename `Utils.cc` to `AsciiUtils.cc` Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/AsciiUtils.cc | 194 +++++++++++++++++++++++++++++++++++ dev/kernel/src/ThreadLocalStorage.cc | 21 +--- dev/kernel/src/Utils.cc | 194 ----------------------------------- 3 files changed, 199 insertions(+), 210 deletions(-) create mode 100644 dev/kernel/src/AsciiUtils.cc delete mode 100644 dev/kernel/src/Utils.cc (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc new file mode 100644 index 00000000..087b6d5f --- /dev/null +++ b/dev/kernel/src/AsciiUtils.cc @@ -0,0 +1,194 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include + +namespace Kernel { + +STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); +STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); + +Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { + for (Size i = 0; i < size; ++i) { + if (src[i] != cmp[i]) + return static_cast(src[i]) - static_cast(cmp[i]); + } + return 0; +} + +SizeT rt_string_len(const Char* str, SizeT max_len) { + SizeT len = 0; + while (len < max_len && str[len] != '\0') + ++len; + return len; +} + +Size rt_string_len(const Char* ptr) { + Size cnt = 0; + while (ptr[cnt] != '\0') + ++cnt; + return cnt; +} + +const Char* rt_alloc_string(const Char* src) { + SizeT slen = rt_string_len(src); + Char* buffer = new Char[slen + 1]; + if (!buffer) return nullptr; + + if (rt_copy_memory_safe(reinterpret_cast(const_cast(src)), + reinterpret_cast(buffer), + slen, + slen + 1) < 0) { + delete[] buffer; + return nullptr; + } + + buffer[slen] = '\0'; + return buffer; +} + +STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size) { + if (!src || !dst || len > dst_size) { + if (dst && dst_size) { + rt_set_memory_safe(dst, 0, dst_size, dst_size); + } + return -1; + } + auto s = reinterpret_cast(src); + auto d = reinterpret_cast(dst); + for (Size i = 0; i < len; ++i) + d[i] = s[i]; + return static_cast(len); +} + +STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { + if (!dst || len > dst_size) return nullptr; + auto p = reinterpret_cast(dst); + UInt8 v = static_cast(value & 0xFF); + for (Size i = 0; i < len; ++i) + p[i] = v; + return dst; +} + +Void rt_zero_memory(voidPtr pointer, Size len) { + rt_set_memory_safe(pointer, 0, len, len); +} + +#ifdef __NE_ENFORCE_DEPRECATED_WARNINGS +[[deprecated("Use rt_set_memory_safe instead")]] +#endif +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); + for (Size i = 0; i < len; ++i) + p[i] = v; + return src; +} + +#ifdef __NE_ENFORCE_DEPRECATED_WARNINGS +[[deprecated("Use rt_copy_memory_safe instead")]] +#endif +Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { + if (!src || !dst) return -1; + auto s = reinterpret_cast(src); + auto d = reinterpret_cast(dst); + + for (Size i = 0; i < len; ++i) + d[i] = s[i]; + + return static_cast(len); +} + + +Int32 rt_to_uppercase(Int32 ch) { + return (ch >= 'a' && ch <= 'z') ? ch - 0x20 : ch; +} + +Int32 rt_to_lower(Int32 ch) { + return (ch >= 'A' && ch <= 'Z') ? ch + 0x20 : ch; +} + +Int32 rt_is_alnum(Int32 ch) { + return (ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z') || + (ch >= '0' && ch <= '9'); +} + +Boolean rt_is_space(Char ch) { + return ch == ' '; +} + +Boolean rt_is_newln(Char ch) { + return ch == '\n'; +} + +Char rt_to_char(UInt64 value, Int32 base) { + static constexpr Char kDigits[] = "0123456789ABCDEF"; + return kDigits[value % base]; +} + +Bool rt_to_string(Char* str, UInt64 value, Int32 base) { +#ifdef __NE_AMD64__ + Int i = 0; + do { + str[i++] = rt_to_char(value, base); + value /= base; + } while (value); + str[i] = '\0'; + // in-place + for (Int j = 0; j < i / 2; ++j) { + Char tmp = str[j]; + str[j] = str[i - j - 1]; + str[i - j - 1] = tmp; + } +#endif + return true; +} + + +VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { + SizeT needle_len = rt_string_len(needle); + SizeT hay_len = rt_string_len(haystack); + + if (needle_len > hay_len) return nullptr; + for (SizeT i = 0; i <= hay_len - needle_len; ++i) { + if (rt_string_cmp(haystack + i, needle, needle_len) == 0) { + return reinterpret_cast(const_cast(haystack + i)); + } + } + return nullptr; +} + +Char* rt_string_has_char(Char* str, Char ch) { + while (*str && *str != ch) ++str; + return (*str == ch) ? str : nullptr; +} + +Int32 rt_strcmp(const Char* a, const Char* b) { + Size i = 0; + while (a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) { + ++i; + } + return static_cast(static_cast(a[i]) - + static_cast(b[i])); +} + + // @uses the deprecated version callers should ensure 'len' is valid. +extern "C" void* memset(void* dst, int c, long long unsigned int len) { + return Kernel::rt_set_memory(dst, c, static_cast(len)); +} + +extern "C" void* memcpy(void* dst, const void* src, long long unsigned int len) { + Kernel::rt_copy_memory(const_cast(src), dst, static_cast(len)); + return dst; +} + +extern "C" Kernel::Int32 strcmp(const char* a, const char* b) { + return Kernel::rt_strcmp(a, b); +} + +} diff --git a/dev/kernel/src/ThreadLocalStorage.cc b/dev/kernel/src/ThreadLocalStorage.cc index ec315ddf..88fefee4 100644 --- a/dev/kernel/src/ThreadLocalStorage.cc +++ b/dev/kernel/src/ThreadLocalStorage.cc @@ -15,7 +15,7 @@ /***********************************************************************************/ /// @bugs: 0 /// @file ThreadLocalStorage.cc -/// @brief Process Thread Local Storage. +/// @brief NeKernel Thread Local Storage. /***********************************************************************************/ using namespace Kernel; @@ -27,15 +27,10 @@ using namespace Kernel; */ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* tib_ptr) { - if (!tib_ptr || !tib_ptr->Record) return false; + if (!tib_ptr) return false; - ICodec encoder; - const Char* tib_as_bytes = encoder.AsBytes(tib_ptr); - - kout << "TLS: Validating the TIB...\r"; - - return tib_as_bytes[kCookieMag0Idx] == kCookieMag0 && - tib_as_bytes[kCookieMag1Idx] == kCookieMag1 && tib_as_bytes[kCookieMag2Idx] == kCookieMag2; + return tib_ptr->Cookie[kCookieMag0Idx] == kCookieMag0 && + tib_ptr->Cookie[kCookieMag1Idx] == kCookieMag1 && tib_ptr->Cookie[kCookieMag2Idx] == kCookieMag2; } /** @@ -51,11 +46,5 @@ EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { THREAD_INFORMATION_BLOCK* tib = reinterpret_cast(tib_ptr); - if (!tls_check_tib(tib)) { - kout << "TLS: Failed because of an invalid TIB...\r"; - return No; - } - - kout << "TLS Pass.\r"; - return Yes; + return tls_check_tib(tib); } diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc deleted file mode 100644 index 087b6d5f..00000000 --- a/dev/kernel/src/Utils.cc +++ /dev/null @@ -1,194 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include - -namespace Kernel { - -STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); -STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); - -Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { - for (Size i = 0; i < size; ++i) { - if (src[i] != cmp[i]) - return static_cast(src[i]) - static_cast(cmp[i]); - } - return 0; -} - -SizeT rt_string_len(const Char* str, SizeT max_len) { - SizeT len = 0; - while (len < max_len && str[len] != '\0') - ++len; - return len; -} - -Size rt_string_len(const Char* ptr) { - Size cnt = 0; - while (ptr[cnt] != '\0') - ++cnt; - return cnt; -} - -const Char* rt_alloc_string(const Char* src) { - SizeT slen = rt_string_len(src); - Char* buffer = new Char[slen + 1]; - if (!buffer) return nullptr; - - if (rt_copy_memory_safe(reinterpret_cast(const_cast(src)), - reinterpret_cast(buffer), - slen, - slen + 1) < 0) { - delete[] buffer; - return nullptr; - } - - buffer[slen] = '\0'; - return buffer; -} - -STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size) { - if (!src || !dst || len > dst_size) { - if (dst && dst_size) { - rt_set_memory_safe(dst, 0, dst_size, dst_size); - } - return -1; - } - auto s = reinterpret_cast(src); - auto d = reinterpret_cast(dst); - for (Size i = 0; i < len; ++i) - d[i] = s[i]; - return static_cast(len); -} - -STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { - if (!dst || len > dst_size) return nullptr; - auto p = reinterpret_cast(dst); - UInt8 v = static_cast(value & 0xFF); - for (Size i = 0; i < len; ++i) - p[i] = v; - return dst; -} - -Void rt_zero_memory(voidPtr pointer, Size len) { - rt_set_memory_safe(pointer, 0, len, len); -} - -#ifdef __NE_ENFORCE_DEPRECATED_WARNINGS -[[deprecated("Use rt_set_memory_safe instead")]] -#endif -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); - for (Size i = 0; i < len; ++i) - p[i] = v; - return src; -} - -#ifdef __NE_ENFORCE_DEPRECATED_WARNINGS -[[deprecated("Use rt_copy_memory_safe instead")]] -#endif -Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { - if (!src || !dst) return -1; - auto s = reinterpret_cast(src); - auto d = reinterpret_cast(dst); - - for (Size i = 0; i < len; ++i) - d[i] = s[i]; - - return static_cast(len); -} - - -Int32 rt_to_uppercase(Int32 ch) { - return (ch >= 'a' && ch <= 'z') ? ch - 0x20 : ch; -} - -Int32 rt_to_lower(Int32 ch) { - return (ch >= 'A' && ch <= 'Z') ? ch + 0x20 : ch; -} - -Int32 rt_is_alnum(Int32 ch) { - return (ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9'); -} - -Boolean rt_is_space(Char ch) { - return ch == ' '; -} - -Boolean rt_is_newln(Char ch) { - return ch == '\n'; -} - -Char rt_to_char(UInt64 value, Int32 base) { - static constexpr Char kDigits[] = "0123456789ABCDEF"; - return kDigits[value % base]; -} - -Bool rt_to_string(Char* str, UInt64 value, Int32 base) { -#ifdef __NE_AMD64__ - Int i = 0; - do { - str[i++] = rt_to_char(value, base); - value /= base; - } while (value); - str[i] = '\0'; - // in-place - for (Int j = 0; j < i / 2; ++j) { - Char tmp = str[j]; - str[j] = str[i - j - 1]; - str[i - j - 1] = tmp; - } -#endif - return true; -} - - -VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { - SizeT needle_len = rt_string_len(needle); - SizeT hay_len = rt_string_len(haystack); - - if (needle_len > hay_len) return nullptr; - for (SizeT i = 0; i <= hay_len - needle_len; ++i) { - if (rt_string_cmp(haystack + i, needle, needle_len) == 0) { - return reinterpret_cast(const_cast(haystack + i)); - } - } - return nullptr; -} - -Char* rt_string_has_char(Char* str, Char ch) { - while (*str && *str != ch) ++str; - return (*str == ch) ? str : nullptr; -} - -Int32 rt_strcmp(const Char* a, const Char* b) { - Size i = 0; - while (a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) { - ++i; - } - return static_cast(static_cast(a[i]) - - static_cast(b[i])); -} - - // @uses the deprecated version callers should ensure 'len' is valid. -extern "C" void* memset(void* dst, int c, long long unsigned int len) { - return Kernel::rt_set_memory(dst, c, static_cast(len)); -} - -extern "C" void* memcpy(void* dst, const void* src, long long unsigned int len) { - Kernel::rt_copy_memory(const_cast(src), dst, static_cast(len)); - return dst; -} - -extern "C" Kernel::Int32 strcmp(const char* a, const char* b) { - return Kernel::rt_strcmp(a, b); -} - -} -- cgit v1.2.3 From 8b86ba2a1c0b229df94322c5fc6ee723efc4d717 Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Wed, 4 Jun 2025 10:52:54 +0000 Subject: Fix mParser --- dev/kernel/src/FS/NeFS+FileMgr.cc | 256 ++++++++++++++++++++++++-------------- 1 file changed, 160 insertions(+), 96 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/FS/NeFS+FileMgr.cc b/dev/kernel/src/FS/NeFS+FileMgr.cc index 978a43a8..d02f93da 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -16,78 +16,94 @@ namespace Kernel { /// @brief C++ constructor NeFileSystemMgr::NeFileSystemMgr() { - NeFileSystemParser* mParser = new NeFileSystemParser(); - MUST_PASS(mParser); + mParser = new NeFileSystemParser(); + MUST_PASS(mParser); - kout << "We are done allocating NeFileSystemParser...\r"; + kout << "We are done allocating NeFileSystemParser...\n"; } NeFileSystemMgr::~NeFileSystemMgr() { - if (mParser) { - kout << "Destroying NeFileSystemParser...\r"; - mm_delete_class(&mParser); - } + if (mParser) { + kout << "Destroying NeFileSystemParser...\n"; + delete mParser; + mParser = nullptr; + } } /// @brief Removes a node from the filesystem. /// @param path The filename /// @return If it was deleted or not. bool NeFileSystemMgr::Remove(_Input const Char* path) { - if (path == nullptr || *path == 0) return false; - - return mParser->RemoveCatalog(path); + if (path == nullptr || *path == 0) { + kout << "NeFS: Remove called with null or empty path\n"; + return false; + } + return mParser->RemoveCatalog(path); } /// @brief Creates a node with the specified. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::Create(_Input const Char* path) { - return rtl_node_cast(mParser->CreateCatalog(path)); + if (!path || *path == 0) { + kout << "NeFS: Create called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path)); } -/// @brief Creates a node with is a directory. +/// @brief Creates a node which is a directory. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { - return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); + if (!path || *path == 0) { + kout << "NeFS: CreateDirectory called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } -/// @brief Creates a node with is a alias. +/// @brief Creates a node which is an alias. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { - return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); + if (!path || *path == 0) { + kout << "NeFS: CreateAlias called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } -/// @brief Creates a node with is a page file. -/// @param path The filename path. -/// @return The Node pointer. NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) { - return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); + if (!path || *path == 0) { + kout << "NeFS: CreateSwapFile called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. /// @return const Char* NeFileSystemHelper::Root() { - return kNeFSRoot; + return kNeFSRoot; } /// @brief Gets the up-dir directory. /// @return const Char* NeFileSystemHelper::UpDir() { - return kNeFSUpDir; + return kNeFSUpDir; } /// @brief Gets the separator character. /// @return Char NeFileSystemHelper::Separator() { - return kNeFSSeparator; + return kNeFSSeparator; } /// @brief Gets the metafile character. /// @return Char NeFileSystemHelper::MetaFile() { - return kNeFSMetaFilePrefix; + return kNeFSMetaFilePrefix; } /// @brief Opens a new file. @@ -95,109 +111,157 @@ Char NeFileSystemHelper::MetaFile() { /// @param r /// @return _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) { - if (!path || *path == 0) return nullptr; - - if (!r || *r == 0) return nullptr; - - auto catalog = mParser->GetCatalog(path); - - return rtl_node_cast(catalog); + if (!path || *path == 0) { + kout << "NeFS: Open called with null or empty path\n"; + return nullptr; + } + if (!r || *r == 0) { + kout << "NeFS: Open called with null or empty mode string\n"; + return nullptr; + } + auto catalog = mParser->GetCatalog(path); + if (!catalog) { + kout << "NeFS: Open could not find catalog for path\n"; + return nullptr; + } + return rtl_node_cast(catalog); } -/// @brief Writes to a catalog's fork. -/// @param node the node ptr. -/// @param data the data. -/// @param flags the size. -/// @return Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { - if (!node) return; - if (!size) return; - - constexpr auto kDataForkName = kNeFSDataFork; - this->Write(kDataForkName, node, data, flags, size); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Write called with invalid node pointer\n"; + return; + } + if (!data) { + kout << "NeFS: Write called with null data pointer\n"; + return; + } + if (!size || size > kNeFSForkSize) { + kout << "NeFS: Write called with invalid size: " << size << "\n"; + return; + } + constexpr auto kDataForkName = kNeFSDataFork; + this->Write(kDataForkName, node, data, flags, size); } -/// @brief Read from filesystem fork. -/// @param node the catalog node. -/// @param flags the flags with it. -/// @param sz the size to read. -/// @return _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { - if (!node) return nullptr; - if (!size) return nullptr; - - constexpr auto kDataForkName = kNeFSDataFork; - return this->Read(kDataForkName, node, flags, size); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Read called with invalid node pointer\n"; + return nullptr; + } + if (!size || size > kNeFSForkSize) { + kout << "NeFS: Read called with invalid size: " << size << "\n"; + return nullptr; + } + constexpr auto kDataForkName = kNeFSDataFork; + return this->Read(kDataForkName, node, flags, size); } Void NeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { - if (!size || size > kNeFSForkSize) return; - - if (!data) return; - - NE_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) - mParser->WriteCatalog(reinterpret_cast(node)->Name, - (flags & kFileFlagRsrc ? true : false), data, size, name); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Write(fork) called with invalid node pointer\n"; + return; + } + if (!name || *name == 0) { + kout << "NeFS: Write(fork) called with null or empty fork name\n"; + return; + } + if (!data) { + kout << "NeFS: Write(fork) called with null data pointer\n"; + return; + } + if (!size || size > kNeFSForkSize) { + kout << "NeFS: Write(fork) called with invalid size: " << size << "\n"; + return; + } + NE_UNUSED(flags); + auto cat = reinterpret_cast(node); + if (cat->Kind == kNeFSCatalogKindFile) { + mParser->WriteCatalog(cat->Name, + (flags & kFileFlagRsrc ? true : false), + data, + size, + name); + } } _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, _Input SizeT sz) { - if (sz > kNeFSForkSize) return nullptr; - - if (!sz) return nullptr; - - NE_UNUSED(flags); - - if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) - return mParser->ReadCatalog(reinterpret_cast(node), - (flags & kFileFlagRsrc ? true : false), sz, name); - - return nullptr; + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Read(fork) called with invalid node pointer\n"; + return nullptr; + } + if (!name || *name == 0) { + kout << "NeFS: Read(fork) called with null or empty fork name\n"; + return nullptr; + } + if (!sz || sz > kNeFSForkSize) { + kout << "NeFS: Read(fork) called with invalid size: " << sz << "\n"; + return nullptr; + } + NE_UNUSED(flags); + auto cat = reinterpret_cast(node); + if (cat->Kind == kNeFSCatalogKindFile) { + return mParser->ReadCatalog(cat, + (flags & kFileFlagRsrc ? true : false), + sz, + name); + } + return nullptr; } -/// @brief Seek from Catalog. -/// @param node -/// @param off -/// @retval true always returns false, this is unimplemented. -/// @retval false always returns this, it is unimplemented. - _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) { - if (!node || off == 0) return false; - - return mParser->Seek(reinterpret_cast(node), off); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Seek called with invalid node pointer\n"; + return false; + } + // Allow off == 0 + return mParser->Seek(reinterpret_cast(node), off); } -/// @brief Tell where the catalog is. +/// @brief Tell current offset within catalog. /// @param node -/// @retval true always returns false, this is unimplemented. -/// @retval false always returns this, it is unimplemented. - +/// @return kFileMgrNPos if invalid, else current offset. _Output SizeT NeFileSystemMgr::Tell(NodePtr node) { - if (!node) return kFileMgrNPos; - - return mParser->Tell(reinterpret_cast(node)); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Tell called with invalid node pointer\n"; + return kFileMgrNPos; + } + return mParser->Tell(reinterpret_cast(node)); } -/// @brief Rewinds the catalog. +/// @brief Rewinds the catalog /// @param node -/// @retval true always returns false, this is unimplemented. -/// @retval false always returns this, it is unimplemented. - +/// @return False if invalid, nah? calls Seek(node, 0). _Output Bool NeFileSystemMgr::Rewind(NodePtr node) { - if (!node) return false; - - return this->Seek(node, 0); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Rewind called with invalid node pointer\n"; + return false; + } + return this->Seek(node, 0); } -/// @brief Returns the filesystem parser. -/// @return the Filesystem parser class. _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept { - return mParser; + return mParser; } + +static inline bool is_valid_nefs_catalog(NodePtr node) { + if (!node) return false; + auto cat = reinterpret_cast(node); + if (cat->Kind < 0 || cat->Kind > 3) return false; + bool null_found = false; + for (int i = 0; i < kNeFSCatalogNameLen; ++i) { + if (cat->Name[i] == 0) { + null_found = true; + break; + } + } + if (!null_found) return false; + return true; +} + } // namespace Kernel #endif // ifdef __FSKIT_INCLUDES_NEFS__ -- cgit v1.2.3 From f64668b1cca66565df06f59e1e68381ecbfef217 Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Wed, 4 Jun 2025 12:25:03 +0000 Subject: F* Macros --- dev/kernel/src/FS/NeFS+FileMgr.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/FS/NeFS+FileMgr.cc b/dev/kernel/src/FS/NeFS+FileMgr.cc index d02f93da..fffb1e80 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -250,13 +250,18 @@ _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept { static inline bool is_valid_nefs_catalog(NodePtr node) { if (!node) return false; auto cat = reinterpret_cast(node); - if (cat->Kind < 0 || cat->Kind > 3) return false; + switch (cat->Kind) { + case kNeFSCatalogKindFile: + case kNeFSCatalogKindDir: + case kNeFSCatalogKindAlias: + case kNeFSCatalogKindPage: + break; + default: + return false; + } bool null_found = false; for (int i = 0; i < kNeFSCatalogNameLen; ++i) { - if (cat->Name[i] == 0) { - null_found = true; - break; - } + if (cat->Name[i] == 0) { null_found = true; break; } } if (!null_found) return false; return true; -- cgit v1.2.3 From b5add3bcf5580a2b2384f414b2df7350f4ded786 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Jun 2025 14:37:38 +0200 Subject: fix: Fix #37 compilation errors and warnings. Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/FS/NeFS+FileMgr.cc | 311 +++++++++++++++++++------------------- tooling/fsck.hefs.cc | 2 + 2 files changed, 159 insertions(+), 154 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/FS/NeFS+FileMgr.cc b/dev/kernel/src/FS/NeFS+FileMgr.cc index fffb1e80..2fcfa2bb 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -14,96 +14,98 @@ /// BUGS: 0 namespace Kernel { +static inline bool is_valid_nefs_catalog(NodePtr node); + /// @brief C++ constructor NeFileSystemMgr::NeFileSystemMgr() { - mParser = new NeFileSystemParser(); - MUST_PASS(mParser); + mParser = new NeFileSystemParser(); + MUST_PASS(mParser); - kout << "We are done allocating NeFileSystemParser...\n"; + kout << "We are done allocating NeFileSystemParser...\n"; } NeFileSystemMgr::~NeFileSystemMgr() { - if (mParser) { - kout << "Destroying NeFileSystemParser...\n"; - delete mParser; - mParser = nullptr; - } + if (mParser) { + kout << "Destroying NeFileSystemParser...\n"; + delete mParser; + mParser = nullptr; + } } /// @brief Removes a node from the filesystem. /// @param path The filename /// @return If it was deleted or not. bool NeFileSystemMgr::Remove(_Input const Char* path) { - if (path == nullptr || *path == 0) { - kout << "NeFS: Remove called with null or empty path\n"; - return false; - } - return mParser->RemoveCatalog(path); + if (path == nullptr || *path == 0) { + kout << "NeFS: Remove called with null or empty path\n"; + return false; + } + return mParser->RemoveCatalog(path); } /// @brief Creates a node with the specified. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::Create(_Input const Char* path) { - if (!path || *path == 0) { - kout << "NeFS: Create called with null or empty path\n"; - return nullptr; - } - return rtl_node_cast(mParser->CreateCatalog(path)); + if (!path || *path == 0) { + kout << "NeFS: Create called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path)); } /// @brief Creates a node which is a directory. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { - if (!path || *path == 0) { - kout << "NeFS: CreateDirectory called with null or empty path\n"; - return nullptr; - } - return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); + if (!path || *path == 0) { + kout << "NeFS: CreateDirectory called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } /// @brief Creates a node which is an alias. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { - if (!path || *path == 0) { - kout << "NeFS: CreateAlias called with null or empty path\n"; - return nullptr; - } - return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); + if (!path || *path == 0) { + kout << "NeFS: CreateAlias called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) { - if (!path || *path == 0) { - kout << "NeFS: CreateSwapFile called with null or empty path\n"; - return nullptr; - } - return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); + if (!path || *path == 0) { + kout << "NeFS: CreateSwapFile called with null or empty path\n"; + return nullptr; + } + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. /// @return const Char* NeFileSystemHelper::Root() { - return kNeFSRoot; + return kNeFSRoot; } /// @brief Gets the up-dir directory. /// @return const Char* NeFileSystemHelper::UpDir() { - return kNeFSUpDir; + return kNeFSUpDir; } /// @brief Gets the separator character. /// @return Char NeFileSystemHelper::Separator() { - return kNeFSSeparator; + return kNeFSSeparator; } /// @brief Gets the metafile character. /// @return Char NeFileSystemHelper::MetaFile() { - return kNeFSMetaFilePrefix; + return kNeFSMetaFilePrefix; } /// @brief Opens a new file. @@ -111,160 +113,161 @@ Char NeFileSystemHelper::MetaFile() { /// @param r /// @return _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) { - if (!path || *path == 0) { - kout << "NeFS: Open called with null or empty path\n"; - return nullptr; - } - if (!r || *r == 0) { - kout << "NeFS: Open called with null or empty mode string\n"; - return nullptr; - } - auto catalog = mParser->GetCatalog(path); - if (!catalog) { - kout << "NeFS: Open could not find catalog for path\n"; - return nullptr; - } - return rtl_node_cast(catalog); + if (!path || *path == 0) { + kout << "NeFS: Open called with null or empty path\n"; + return nullptr; + } + if (!r || *r == 0) { + kout << "NeFS: Open called with null or empty mode string\n"; + return nullptr; + } + auto catalog = mParser->GetCatalog(path); + if (!catalog) { + kout << "NeFS: Open could not find catalog for path\n"; + return nullptr; + } + return rtl_node_cast(catalog); } Void NeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Write called with invalid node pointer\n"; - return; - } - if (!data) { - kout << "NeFS: Write called with null data pointer\n"; - return; - } - if (!size || size > kNeFSForkSize) { - kout << "NeFS: Write called with invalid size: " << size << "\n"; - return; - } - constexpr auto kDataForkName = kNeFSDataFork; - this->Write(kDataForkName, node, data, flags, size); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Write called with invalid node pointer\n"; + return; + } + if (!data) { + kout << "NeFS: Write called with null data pointer\n"; + return; + } + if (!size || size > kNeFSForkSize) { + (Void)(kout << "NeFS: Write called with invalid size: " << hex_number(size)); + kout << "\n"; + return; + } + constexpr auto kDataForkName = kNeFSDataFork; + this->Write(kDataForkName, node, data, flags, size); } _Output VoidPtr NeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Read called with invalid node pointer\n"; - return nullptr; - } - if (!size || size > kNeFSForkSize) { - kout << "NeFS: Read called with invalid size: " << size << "\n"; - return nullptr; - } - constexpr auto kDataForkName = kNeFSDataFork; - return this->Read(kDataForkName, node, flags, size); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Read called with invalid node pointer\n"; + return nullptr; + } + if (!size || size > kNeFSForkSize) { + (Void)(kout << "NeFS: Write called with invalid size: " << hex_number(size)); + kout << "\n"; + return nullptr; + } + constexpr auto kDataForkName = kNeFSDataFork; + return this->Read(kDataForkName, node, flags, size); } Void NeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, _Input SizeT size) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Write(fork) called with invalid node pointer\n"; - return; - } - if (!name || *name == 0) { - kout << "NeFS: Write(fork) called with null or empty fork name\n"; - return; - } - if (!data) { - kout << "NeFS: Write(fork) called with null data pointer\n"; - return; - } - if (!size || size > kNeFSForkSize) { - kout << "NeFS: Write(fork) called with invalid size: " << size << "\n"; - return; - } - NE_UNUSED(flags); - auto cat = reinterpret_cast(node); - if (cat->Kind == kNeFSCatalogKindFile) { - mParser->WriteCatalog(cat->Name, - (flags & kFileFlagRsrc ? true : false), - data, - size, - name); - } + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Write(fork) called with invalid node pointer\n"; + return; + } + if (!name || *name == 0) { + kout << "NeFS: Write(fork) called with null or empty fork name\n"; + return; + } + if (!data) { + kout << "NeFS: Write(fork) called with null data pointer\n"; + return; + } + if (!size || size > kNeFSForkSize) { + (Void)(kout << "NeFS: Write called with invalid size: " << hex_number(size)); + kout << "\n"; + return; + } + NE_UNUSED(flags); + auto cat = reinterpret_cast(node); + if (cat->Kind == kNeFSCatalogKindFile) { + mParser->WriteCatalog(cat->Name, (flags & kFileFlagRsrc ? true : false), data, size, name); + } } _Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, _Input SizeT sz) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Read(fork) called with invalid node pointer\n"; - return nullptr; - } - if (!name || *name == 0) { - kout << "NeFS: Read(fork) called with null or empty fork name\n"; - return nullptr; - } - if (!sz || sz > kNeFSForkSize) { - kout << "NeFS: Read(fork) called with invalid size: " << sz << "\n"; - return nullptr; - } - NE_UNUSED(flags); - auto cat = reinterpret_cast(node); - if (cat->Kind == kNeFSCatalogKindFile) { - return mParser->ReadCatalog(cat, - (flags & kFileFlagRsrc ? true : false), - sz, - name); - } + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Read(fork) called with invalid node pointer\n"; + return nullptr; + } + if (!name || *name == 0) { + kout << "NeFS: Read(fork) called with null or empty fork name\n"; + return nullptr; + } + if (!sz || sz > kNeFSForkSize) { + (Void)(kout << "NeFS: Write called with invalid size: " << hex_number(sz)); + kout << "\n"; return nullptr; + } + NE_UNUSED(flags); + auto cat = reinterpret_cast(node); + if (cat->Kind == kNeFSCatalogKindFile) { + return mParser->ReadCatalog(cat, (flags & kFileFlagRsrc ? true : false), sz, name); + } + return nullptr; } _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Seek called with invalid node pointer\n"; - return false; - } - // Allow off == 0 - return mParser->Seek(reinterpret_cast(node), off); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Seek called with invalid node pointer\n"; + return false; + } + // Allow off == 0 + return mParser->Seek(reinterpret_cast(node), off); } /// @brief Tell current offset within catalog. /// @param node /// @return kFileMgrNPos if invalid, else current offset. _Output SizeT NeFileSystemMgr::Tell(NodePtr node) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Tell called with invalid node pointer\n"; - return kFileMgrNPos; - } - return mParser->Tell(reinterpret_cast(node)); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Tell called with invalid node pointer\n"; + return kFileMgrNPos; + } + return mParser->Tell(reinterpret_cast(node)); } -/// @brief Rewinds the catalog +/// @brief Rewinds the catalog /// @param node /// @return False if invalid, nah? calls Seek(node, 0). _Output Bool NeFileSystemMgr::Rewind(NodePtr node) { - if (!is_valid_nefs_catalog(node)) { - kout << "NeFS: Rewind called with invalid node pointer\n"; - return false; - } - return this->Seek(node, 0); + if (!is_valid_nefs_catalog(node)) { + kout << "NeFS: Rewind called with invalid node pointer\n"; + return false; + } + return this->Seek(node, 0); } +/// @brief Returns the parser of NeFS. _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept { - return mParser; + return mParser; } static inline bool is_valid_nefs_catalog(NodePtr node) { - if (!node) return false; - auto cat = reinterpret_cast(node); - switch (cat->Kind) { - case kNeFSCatalogKindFile: - case kNeFSCatalogKindDir: - case kNeFSCatalogKindAlias: - case kNeFSCatalogKindPage: - break; - default: - return false; - } - bool null_found = false; - for (int i = 0; i < kNeFSCatalogNameLen; ++i) { - if (cat->Name[i] == 0) { null_found = true; break; } + if (!node) return false; + auto cat = reinterpret_cast(node); + switch (cat->Kind) { + case kNeFSCatalogKindFile: + case kNeFSCatalogKindDir: + case kNeFSCatalogKindAlias: + case kNeFSCatalogKindPage: + break; + default: + return false; + } + bool null_found = false; + for (int i = 0; i < kNeFSCatalogNameLen; ++i) { + if (cat->Name[i] == 0) { + null_found = true; + break; } - if (!null_found) return false; - return true; + } + if (!null_found) return false; + return true; } } // namespace Kernel diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc index ce586b13..2898f09b 100644 --- a/tooling/fsck.hefs.cc +++ b/tooling/fsck.hefs.cc @@ -15,5 +15,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + (void)(argv); + return EXIT_SUCCESS; } \ No newline at end of file -- cgit v1.2.3 From e4c4041182480e96d52d289204d7f5363e6be3e4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Jun 2025 14:41:29 +0200 Subject: meta: Ran `./format.sh` Signed-off-by: Amlal El Mahrouss --- dev/boot/BootKit/HW/SATA.h | 2 +- dev/boot/src/HEL/AMD64/BootATA.cc | 13 +- dev/kernel/KernelKit/ThreadLocalStorage.h | 2 +- dev/kernel/src/AsciiUtils.cc | 55 ++--- dev/kernel/src/CxxAbi-ARM64.cc | 2 +- dev/kernel/src/ThreadLocalStorage.cc | 3 +- tooling/fsck.hefs.cc | 2 +- tooling/mkfs.hefs.cc | 383 ++++++++++++++---------------- 8 files changed, 219 insertions(+), 243 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/boot/BootKit/HW/SATA.h b/dev/boot/BootKit/HW/SATA.h index ebb1151e..d880c3af 100644 --- a/dev/boot/BootKit/HW/SATA.h +++ b/dev/boot/BootKit/HW/SATA.h @@ -19,7 +19,7 @@ class BootDeviceSATA final { NE_COPY_DEFAULT(BootDeviceSATA) - struct SATATrait final : public Device::Trait { + struct SATATrait final : public Device::Trait { Kernel::Boolean mErr{false}; Kernel::Boolean mDetected{false}; diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc index e5e0d8c2..25810222 100644 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -88,7 +88,8 @@ 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); @@ -114,14 +115,15 @@ 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); @@ -147,14 +149,15 @@ 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/kernel/KernelKit/ThreadLocalStorage.h b/dev/kernel/KernelKit/ThreadLocalStorage.h index 35c17db0..1b8e4821 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.h +++ b/dev/kernel/KernelKit/ThreadLocalStorage.h @@ -28,7 +28,7 @@ struct 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::VoidPtr UserData{nullptr}; //! Thread Information Record (User defined canary structure) + Kernel::VoidPtr UserData{nullptr}; //! Thread Information Record (User defined canary structure) }; ///! @brief Cookie Sanity check. diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 087b6d5f..bfc56aec 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -8,40 +8,35 @@ namespace Kernel { -STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); +STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { for (Size i = 0; i < size; ++i) { - if (src[i] != cmp[i]) - return static_cast(src[i]) - static_cast(cmp[i]); + if (src[i] != cmp[i]) return static_cast(src[i]) - static_cast(cmp[i]); } return 0; } SizeT rt_string_len(const Char* str, SizeT max_len) { SizeT len = 0; - while (len < max_len && str[len] != '\0') - ++len; + while (len < max_len && str[len] != '\0') ++len; return len; } Size rt_string_len(const Char* ptr) { Size cnt = 0; - while (ptr[cnt] != '\0') - ++cnt; + while (ptr[cnt] != '\0') ++cnt; return cnt; } const Char* rt_alloc_string(const Char* src) { - SizeT slen = rt_string_len(src); + SizeT slen = rt_string_len(src); Char* buffer = new Char[slen + 1]; if (!buffer) return nullptr; if (rt_copy_memory_safe(reinterpret_cast(const_cast(src)), - reinterpret_cast(buffer), - slen, - slen + 1) < 0) { + reinterpret_cast(buffer), slen, slen + 1) < 0) { delete[] buffer; return nullptr; } @@ -59,17 +54,15 @@ STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size ds } auto s = reinterpret_cast(src); auto d = reinterpret_cast(dst); - for (Size i = 0; i < len; ++i) - d[i] = s[i]; + for (Size i = 0; i < len; ++i) d[i] = s[i]; return static_cast(len); } STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { if (!dst || len > dst_size) return nullptr; - auto p = reinterpret_cast(dst); + auto p = reinterpret_cast(dst); UInt8 v = static_cast(value & 0xFF); - for (Size i = 0; i < len; ++i) - p[i] = v; + for (Size i = 0; i < len; ++i) p[i] = v; return dst; } @@ -80,12 +73,12 @@ 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); + auto p = reinterpret_cast(src); UInt8 v = static_cast(value & 0xFF); - for (Size i = 0; i < len; ++i) - p[i] = v; + for (Size i = 0; i < len; ++i) p[i] = v; return src; } @@ -97,13 +90,11 @@ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { auto s = reinterpret_cast(src); auto d = reinterpret_cast(dst); - for (Size i = 0; i < len; ++i) - d[i] = s[i]; + for (Size i = 0; i < len; ++i) d[i] = s[i]; return static_cast(len); } - Int32 rt_to_uppercase(Int32 ch) { return (ch >= 'a' && ch <= 'z') ? ch - 0x20 : ch; } @@ -113,9 +104,7 @@ Int32 rt_to_lower(Int32 ch) { } Int32 rt_is_alnum(Int32 ch) { - return (ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || - (ch >= '0' && ch <= '9'); + return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'); } Boolean rt_is_space(Char ch) { @@ -141,18 +130,17 @@ Bool rt_to_string(Char* str, UInt64 value, Int32 base) { str[i] = '\0'; // in-place for (Int j = 0; j < i / 2; ++j) { - Char tmp = str[j]; - str[j] = str[i - j - 1]; + Char tmp = str[j]; + str[j] = str[i - j - 1]; str[i - j - 1] = tmp; } #endif return true; } - VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { SizeT needle_len = rt_string_len(needle); - SizeT hay_len = rt_string_len(haystack); + SizeT hay_len = rt_string_len(haystack); if (needle_len > hay_len) return nullptr; for (SizeT i = 0; i <= hay_len - needle_len; ++i) { @@ -173,11 +161,10 @@ Int32 rt_strcmp(const Char* a, const Char* b) { while (a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) { ++i; } - return static_cast(static_cast(a[i]) - - static_cast(b[i])); + return static_cast(static_cast(a[i]) - static_cast(b[i])); } - // @uses the deprecated version callers should ensure 'len' is valid. +// @uses the deprecated version callers should ensure 'len' is valid. extern "C" void* memset(void* dst, int c, long long unsigned int len) { return Kernel::rt_set_memory(dst, c, static_cast(len)); } @@ -191,4 +178,4 @@ extern "C" Kernel::Int32 strcmp(const char* a, const char* b) { return Kernel::rt_strcmp(a, b); } -} +} // namespace Kernel diff --git a/dev/kernel/src/CxxAbi-ARM64.cc b/dev/kernel/src/CxxAbi-ARM64.cc index d351b024..e91eb958 100644 --- a/dev/kernel/src/CxxAbi-ARM64.cc +++ b/dev/kernel/src/CxxAbi-ARM64.cc @@ -37,7 +37,7 @@ EXTERN_C void __cxa_finalize(void* f) { while (i--) { if (__atexit_funcs[i].destructor_func) { (*__atexit_funcs[i].destructor_func)(); - __atexit_funcs[i].destructor_func = 0; + __atexit_funcs[i].destructor_func = 0; }; } diff --git a/dev/kernel/src/ThreadLocalStorage.cc b/dev/kernel/src/ThreadLocalStorage.cc index 88fefee4..03a71f1a 100644 --- a/dev/kernel/src/ThreadLocalStorage.cc +++ b/dev/kernel/src/ThreadLocalStorage.cc @@ -30,7 +30,8 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* tib_ptr) { if (!tib_ptr) return false; return tib_ptr->Cookie[kCookieMag0Idx] == kCookieMag0 && - tib_ptr->Cookie[kCookieMag1Idx] == kCookieMag1 && tib_ptr->Cookie[kCookieMag2Idx] == kCookieMag2; + tib_ptr->Cookie[kCookieMag1Idx] == kCookieMag1 && + tib_ptr->Cookie[kCookieMag2Idx] == kCookieMag2; } /** diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc index 2898f09b..37dfbdd7 100644 --- a/tooling/fsck.hefs.cc +++ b/tooling/fsck.hefs.cc @@ -15,7 +15,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - (void)(argv); + (void) (argv); return EXIT_SUCCESS; } \ No newline at end of file diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index ef6ceb32..3960fa5e 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -6,228 +6,213 @@ #include #include +#include #include #include #include #include -#include namespace detail { /// @internal /// @brief GB‐to‐byte conversion (use multiplication, not XOR). static constexpr size_t gib_cast(uint32_t gb) { - return static_cast(gb) * 1024ULL * 1024ULL * 1024ULL; + return static_cast(gb) * 1024ULL * 1024ULL * 1024ULL; } } // namespace detail -static size_t kDiskSize = detail::gib_cast(4UL); -static uint16_t kVersion = kHeFSVersion; -static std::u8string kLabel; +static size_t kDiskSize = detail::gib_cast(4UL); +static uint16_t kVersion = kHeFSVersion; +static std::u8string kLabel; static size_t kSectorSize = 512; static bool parse_decimal(const std::string& opt, unsigned long long& out) { - if (opt.empty()) return false; - char* endptr = nullptr; - unsigned long long val = std::strtoull(opt.c_str(), &endptr, 10); - if (endptr == opt.c_str() || *endptr != '\0') return false; - out = val; - return true; + if (opt.empty()) return false; + char* endptr = nullptr; + unsigned long long val = std::strtoull(opt.c_str(), &endptr, 10); + if (endptr == opt.c_str() || *endptr != '\0') return false; + out = val; + return true; } static bool parse_signed(const std::string& opt, long& out, int base = 10) { - if (opt.empty()) return false; - char* endptr = nullptr; - long val = std::strtol(opt.c_str(), &endptr, base); - if (endptr == opt.c_str() || *endptr != '\0' || val < 0) return false; - out = val; - return true; + if (opt.empty()) return false; + char* endptr = nullptr; + long val = std::strtol(opt.c_str(), &endptr, base); + if (endptr == opt.c_str() || *endptr != '\0' || val < 0) return false; + out = val; + return true; } static std::string build_args(int argc, char** argv) { - std::string combined; - for (int i = 1; i < argc; ++i) { - combined += argv[i]; - combined += ' '; - } - return combined; + std::string combined; + for (int i = 1; i < argc; ++i) { + combined += argv[i]; + combined += ' '; + } + return combined; } int main(int argc, char** argv) { - if (argc < 2) { - mkfs::console_out() - << "hefs: usage: mkfs.hefs -L=