diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-09 02:50:07 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-09 02:52:34 +0100 |
| commit | 4d192e629a07ae457134cb0063e0136e54b01008 (patch) | |
| tree | b933444d27c2b9ac22693e2e65bd294792c79d39 | |
| parent | f78c535aec66e02584e1b02995dc12c9e1bcb64c (diff) | |
chore: Codebase improvements and tweaks.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
30 files changed, 175 insertions, 253 deletions
diff --git a/docs/tex/binary_mutex.tex b/docs/tex/binary_mutex.tex index f5d54743..b326f4b4 100644 --- a/docs/tex/binary_mutex.tex +++ b/docs/tex/binary_mutex.tex @@ -50,14 +50,14 @@ class BinaryMutex final { BOOL WaitForProcess(const UInt32& sec); public: - bool Lock(USER_PROCESS* process); - bool LockAndWait(USER_PROCESS* process, TimerInterface* timer); + bool Lock(UserProcess* process); + bool LockAndWait(UserProcess* process, TimerInterface* timer); public: NE_COPY_DEFAULT(BinaryMutex) private: - USER_PROCESS* fLockingProcess; + UserProcess* fLockingProcess; }; \end{verbatim} diff --git a/docs/tex/core_process_scheduler.tex b/docs/tex/core_process_scheduler.tex index e48b5f5f..c8a8f97b 100644 --- a/docs/tex/core_process_scheduler.tex +++ b/docs/tex/core_process_scheduler.tex @@ -53,8 +53,8 @@ class UserProcessTeam final { NE_COPY_DEFAULT(UserProcessTeam) - Array<USER_PROCESS, kSchedProcessLimitPerTeam>& AsArray(); - Ref<USER_PROCESS>& AsRef(); + Array<UserProcess, kSchedProcessLimitPerTeam>& AsArray(); + Ref<UserProcess>& AsRef(); ProcessID& Id() noexcept; public: @@ -81,8 +81,8 @@ struct PROCESS_IMAGE final { explicit PROCESS_IMAGE() = default; private: - friend USER_PROCESS; - friend KERNEL_TASK; + friend UserProcess; + friend KernelTask; friend class UserProcessScheduler; diff --git a/public/frameworks/DiskImage.fwrk/xml/.keep b/public/frameworks/DiskImage.fwrk/xml/.keep deleted file mode 100644 index e69de29b..00000000 --- a/public/frameworks/DiskImage.fwrk/xml/.keep +++ /dev/null diff --git a/public/frameworks/KernelTest.fwrk/xml/.keep b/public/frameworks/KernelTest.fwrk/xml/.keep deleted file mode 100644 index e69de29b..00000000 --- a/public/frameworks/KernelTest.fwrk/xml/.keep +++ /dev/null diff --git a/src/boot/BootKit/BootKit.h b/src/boot/BootKit/BootKit.h index fb8941e0..b00fd112 100644 --- a/src/boot/BootKit/BootKit.h +++ b/src/boot/BootKit/BootKit.h @@ -9,7 +9,10 @@ /// @brief Bootloader Application Programming Interface. /***********************************************************************************/ -#pragma once +#ifndef __BOOTKIT_H__ +#define __BOOTKIT_H__ + +#include <BootKit/Config.h> #include <BootKit/HW/ATA.h> #include <CompilerKit/Version.h> @@ -333,3 +336,5 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) { return YES; } } // namespace Boot + +#endif // __BOOTKIT_H__
\ No newline at end of file diff --git a/src/boot/BootKit/Config.h b/src/boot/BootKit/Config.h new file mode 100644 index 00000000..b2641b24 --- /dev/null +++ b/src/boot/BootKit/Config.h @@ -0,0 +1,16 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#ifndef __BOOTKIT_CONFIG_H__ +#define __BOOTKIT_CONFIG_H__ + +#include <NeKit/Config.h> + +namespace Boot { + using namespace Kernel; +} + +#endif // ! __BOOTKIT_CONFIG_H__
\ No newline at end of file diff --git a/src/boot/BootKit/Device.h b/src/boot/BootKit/Device.h index 36e2b3d4..efe27659 100644 --- a/src/boot/BootKit/Device.h +++ b/src/boot/BootKit/Device.h @@ -4,13 +4,15 @@ ======================================== */ -#pragma once +#ifndef __BOOTKIT_DEVICE_H__ +#define __BOOTKIT_DEVICE_H__ +#include <BootKit/Config.h> #include <modules/AHCI/AHCI.h> #include <modules/ATA/ATA.h> -namespace Kernel { -/// @brief Device type. +namespace Boot { +/// @brief Physical/Virtual device type. class Device { public: explicit Device() = default; @@ -19,7 +21,7 @@ class Device { NE_MOVE_DEFAULT(Device) struct Trait { - SizeT mBase{0}; + Lba mBase{0}; SizeT mSize{0}; }; @@ -29,7 +31,9 @@ class Device { virtual Device& Write(Char* Buf, SizeT SecCount) = 0; }; -typedef Device BootDevice; -typedef Device NetworkDevice; -typedef Device DiskDevice; -} // namespace Kernel
\ No newline at end of file +using BootDevice = Device; +using NetworkDevice = Device; +using DiskDevice = Device; +} // namespace Boot + +#endif
\ No newline at end of file diff --git a/src/boot/BootKit/EPM.h b/src/boot/BootKit/EPM.h index cc82dd41..5657337a 100644 --- a/src/boot/BootKit/EPM.h +++ b/src/boot/BootKit/EPM.h @@ -4,6 +4,9 @@ ======================================== */ -#pragma once +#ifndef __BOOTKIT_EPM_H__ +#define __BOOTKIT_EPM_H__ #include <FirmwareKit/EPM.h> + +#endif
\ No newline at end of file diff --git a/src/boot/BootKit/HW/ATA.h b/src/boot/BootKit/HW/ATA.h index 7ebf296d..1842300b 100644 --- a/src/boot/BootKit/HW/ATA.h +++ b/src/boot/BootKit/HW/ATA.h @@ -9,8 +9,7 @@ #include <BootKit/Device.h> #include <modules/ATA/ATA.h> -using namespace Kernel; - +namespace Boot { class BootDeviceATA final : public Device { public: enum { @@ -45,3 +44,4 @@ class BootDeviceATA final : public Device { private: ATATrait mTrait; }; +} // namespace Boot
\ No newline at end of file diff --git a/src/boot/BootKit/HW/SATA.h b/src/boot/BootKit/HW/SATA.h index 68ed30c8..442ea399 100644 --- a/src/boot/BootKit/HW/SATA.h +++ b/src/boot/BootKit/HW/SATA.h @@ -12,6 +12,7 @@ #define kAHCISectorSz (512) +namespace Boot { class BootDeviceSATA final { public: explicit BootDeviceSATA(); @@ -23,7 +24,7 @@ class BootDeviceSATA final { Kernel::Boolean mErr{false}; Kernel::Boolean mDetected{false}; - operator bool() { return !this->mErr; } + explicit operator bool() { return !this->mErr; } }; operator bool() { return this->Leak().mDetected; } @@ -40,3 +41,4 @@ class BootDeviceSATA final { private: SATATrait mTrait; }; +} // namespace Boot
\ No newline at end of file diff --git a/src/boot/src/docs/KERN_VER.md b/src/boot/src/docs/KERN_VER.md deleted file mode 100644 index c47c3d5b..00000000 --- a/src/boot/src/docs/KERN_VER.md +++ /dev/null @@ -1,18 +0,0 @@ -# `/props/kern_ver` โ NVRAM EFI Variable - -The `/props/kern_ver` variable is used to track NeKernel's current version in a BCD format. - -## ๐ Reason - -- It is also used for: - - Bug tracking and system patching. - - Version and compatibility checking. - -## ๐งช Usage - -N/A - -## ยฉ License - - Copyright (C) 2025, - Amlal El Mahrouss โ Licensed under the Apache 2.0 license.
\ No newline at end of file diff --git a/src/boot/src/docs/MKFS_HEFS.md b/src/boot/src/docs/MKFS_HEFS.md deleted file mode 100644 index b42ad9c2..00000000 --- a/src/boot/src/docs/MKFS_HEFS.md +++ /dev/null @@ -1,106 +0,0 @@ -# `mkfs.hefs` โ OpenHeFS Filesystem Formatter - -`mkfs.hefs` is a command-line utility used to format a block device or disk image with the **High-throughput Extended File System (OpenHeFS)** used by NeKernel. This tool initializes a OpenHeFS volume by writing a boot node and configuring directory and inode index regions, block ranges, and volume metadata. - ---- - -## ๐ Features - -- Writes a valid `BootNode` to the specified output device or file. -- Sets disk size, sector size, and volume label. -- Supports user-defined ranges for: - - Index Node Directory (IND) - - Inodes (IN) - - Data blocks -- UTF-8 encoded volume label support. -- Fully compatible with NeKernel's VFS subsystem. - ---- - -## ๐งช Usage - - mkfs.hefs -L <label> -s <sector_size> \ - -b <ind_start> -e <ind_end> \ - -bs <block_start> -be <block_end> \ - -is <in_start> -ie <in_end> \ - -S <disk_size> -o <output_device> - ---- - -## ๐งพ Arguments - -| Option | Description | -|---------------|-------------------------------------------------------------------------| -| `-L` | Volume label (UTF-8, internally stored as UTF-16) | -| `-s` | Sector size (e.g., 512) | -| `-b` `-e` | Start and end addresses for the **Index Node Directory (IND)** region | -| `-bs` `-be` | Start and end addresses for the **Block** data region | -| `-is` `-ie` | Start and end addresses for the **Inode** region | -| `-S` | Disk size in **gigabytes** | -| `-o` | Path to the output device or image file | - -> All address-based inputs (`-b`, `-e`, etc.) must be specified in **hexadecimal** format. - ---- - -## ๐งท Notes - -- Default sector size is `512` bytes. -- Default volume name is `"HeFS_VOLUME"`, defined as `kOpenHeFSDefaultVolumeName`. -- The tool writes a `BootNode` at the beginning of the index node range. -- A CRC-safe magic signature is embedded for boot and integrity validation. -- After writing the metadata, the tool flushes and closes the file stream. - ---- - -## ๐ป Example - - mkfs.hefs -L "MyHeFS" -s 512 \ - -b 0x1000 -e 0x8000 \ - -bs 0x8000 -be 0x800000 \ - -is 0x800000 -ie 0xA00000 \ - -S 128 -o hefs.img - -This will create a 128 GiB formatted OpenHeFS image named `hefs.img` with specified region boundaries. - ---- - -## ๐ BootNode Structure - -The `BootNode` stores key filesystem metadata: - - struct BootNode { - char magic[8]; - char16_t volumeName[64]; - uint16_t version; - uint16_t diskKind; - uint16_t encoding; - uint64_t diskSize; - uint32_t sectorSize; - uint64_t startIND, endIND; - uint64_t startIN, endIN; - uint64_t startBlock, endBlock; - uint64_t indCount; - uint16_t diskStatus; - }; - ---- - -## โ ๏ธ Error Handling - -- Prints usage and exits on invalid/missing arguments. -- Exits with error if the output device cannot be opened or written to. -- Checks for zero sector size or disk size to prevent invalid formatting. - ---- - -## ๐ Source Location - -Part of the [OpenHeFS Tooling module](https://github.com/nekernel-org/nekernel) and used during system setup or disk preparation for NeKernel. - ---- - -## ยฉ License - - Copyright (C) 2025, - Amlal El Mahrouss โ Licensed under the Apache 2.0 license.
\ No newline at end of file diff --git a/src/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc b/src/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc index 44ec2a37..f120bd39 100644 --- a/src/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc +++ b/src/kernel/HALKit/AMD64/HalSchedulerCorePrimitives.cc @@ -13,7 +13,7 @@ namespace Kernel { /// @param /***********************************************************************************/ -EXTERN_C Void __ne_pure_call(USER_PROCESS* process) { +EXTERN_C Void __ne_pure_call(UserProcess* process) { if (process) process->Crash(); } diff --git a/src/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc b/src/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc index b1728bac..87fa1ab6 100644 --- a/src/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc +++ b/src/kernel/HALKit/ARM64/HalSchedulerCorePrimitives.cc @@ -13,7 +13,7 @@ namespace Kernel { /// @param process The process handle.
/***********************************************************************************/
-EXTERN_C Void __ne_pure_call(USER_PROCESS* process) {
+EXTERN_C Void __ne_pure_call(UserProcess* process) {
if (process) process->Crash();
}
diff --git a/src/kernel/KernelKit/BinaryMutex.h b/src/kernel/KernelKit/BinaryMutex.h index f8a2898b..12dc7d15 100644 --- a/src/kernel/KernelKit/BinaryMutex.h +++ b/src/kernel/KernelKit/BinaryMutex.h @@ -11,12 +11,12 @@ #include <NeKit/Config.h> namespace Kernel { -class USER_PROCESS; +class UserProcess; /// @brief Access control class, which locks a task until one is done. class BinaryMutex final { public: - using LockedPtr = USER_PROCESS*; + using LockedPtr = UserProcess*; explicit BinaryMutex() = default; ~BinaryMutex() = default; diff --git a/src/kernel/KernelKit/Config.h b/src/kernel/KernelKit/Config.h index 6db4bdf7..f0d1e106 100644 --- a/src/kernel/KernelKit/Config.h +++ b/src/kernel/KernelKit/Config.h @@ -14,6 +14,6 @@ namespace Kernel { class UserProcessScheduler; class IDylibObject; -class USER_PROCESS; -class KERNEL_TASK; +class UserProcess; +class KernelTask; } // namespace Kernel
\ No newline at end of file diff --git a/src/kernel/KernelKit/CoreProcessScheduler.h b/src/kernel/KernelKit/CoreProcessScheduler.h index da89b112..5071f85d 100644 --- a/src/kernel/KernelKit/CoreProcessScheduler.h +++ b/src/kernel/KernelKit/CoreProcessScheduler.h @@ -26,22 +26,22 @@ EXTERN_C void sched_idle_task(void); namespace Kernel { -class USER_PROCESS; -class KERNEL_TASK; +class UserProcess; +class KernelTask; class KernelTaskScheduler; class UserProcessScheduler; class UserProcessTeam; template <typename T> -struct PROCESS_HEAP_TREE; +struct ProcessHeapTree; template <typename T> -struct PROCESS_SPECIAL_TREE; +struct ProcessSpecialTree; template <typename T> -struct PROCESS_FILE_TREE; +struct ProcessFileTree; -enum { +enum struct TreeKind : UInt32 { kInvalidTreeKind = 0U, kRedTreeKind = 100U, kBlackTreeKind = 101U, @@ -49,7 +49,7 @@ enum { }; template <typename T> -struct PROCESS_HEAP_TREE { +struct ProcessHeapTree { static constexpr auto kHeap = true; static constexpr auto kFile = false; static constexpr auto kSpecial = false; @@ -58,25 +58,25 @@ struct PROCESS_HEAP_TREE { SizeT EntrySize{0UL}; SizeT EntryPad{0UL}; - UInt32 Color{kBlackTreeKind}; + TreeKind Color{TreeKind::kBlackTreeKind}; - struct PROCESS_HEAP_TREE<T>* Parent { + struct ProcessHeapTree<T>* Parent { nullptr }; - struct PROCESS_HEAP_TREE<T>* Child { + struct ProcessHeapTree<T>* Child { nullptr }; - struct PROCESS_HEAP_TREE<T>* Prev { + struct ProcessHeapTree<T>* Prev { nullptr }; - struct PROCESS_HEAP_TREE<T>* Next { + struct ProcessHeapTree<T>* Next { nullptr }; }; template <typename T> -struct PROCESS_FILE_TREE { +struct ProcessFileTree { static constexpr auto kHeap = false; static constexpr auto kFile = true; static constexpr auto kSpecial = false; @@ -85,21 +85,21 @@ struct PROCESS_FILE_TREE { SizeT EntrySize{0UL}; SizeT EntryPad{0UL}; - UInt32 Color{kBlackTreeKind}; + TreeKind Color{TreeKind::kBlackTreeKind}; - struct PROCESS_FILE_TREE<T>* Parent { + struct ProcessFileTree<T>* Parent { nullptr }; - struct PROCESS_FILE_TREE<T>* Child { + struct ProcessFileTree<T>* Child { nullptr }; - struct PROCESS_FILE_TREE<T>* Prev { + struct ProcessFileTree<T>* Prev { nullptr }; - struct PROCESS_FILE_TREE<T>* Next { + struct ProcessFileTree<T>* Next { nullptr }; }; @@ -107,7 +107,7 @@ struct PROCESS_FILE_TREE { using ProcessCtx = UInt32; template <typename T> -struct PROCESS_SPECIAL_TREE { +struct ProcessSpecialTree { static constexpr auto kHeap = false; static constexpr auto kFile = false; static constexpr auto kSpecial = true; @@ -119,21 +119,21 @@ struct PROCESS_SPECIAL_TREE { /// @brief a context is where the resource comes from. ProcessCtx EntryContext{0UL}; // could be a socket, printer, device... - UInt32 Color{kBlackTreeKind}; + TreeKind Color{TreeKind::kBlackTreeKind}; - struct PROCESS_SPECIAL_TREE<T>* Parent { + struct ProcessSpecialTree<T>* Parent { nullptr }; - struct PROCESS_SPECIAL_TREE<T>* Child { + struct ProcessSpecialTree<T>* Child { nullptr }; - struct PROCESS_SPECIAL_TREE<T>* Prev { + struct ProcessSpecialTree<T>* Prev { nullptr }; - struct PROCESS_SPECIAL_TREE<T>* Next { + struct ProcessSpecialTree<T>* Next { nullptr }; }; @@ -240,8 +240,8 @@ struct ProcessImage final { explicit ProcessImage() = default; private: - friend USER_PROCESS; - friend KERNEL_TASK; + friend UserProcess; + friend KernelTask; friend UserProcessScheduler; friend KernelTaskScheduler; diff --git a/src/kernel/KernelKit/IPEFDylibObject.h b/src/kernel/KernelKit/IPEFDylibObject.h index fb386526..d8ed3fc5 100644 --- a/src/kernel/KernelKit/IPEFDylibObject.h +++ b/src/kernel/KernelKit/IPEFDylibObject.h @@ -79,8 +79,8 @@ class IPEFDylibObject final NE_DYLIB_OBJECT { typedef IPEFDylibObject* IDylibRef; -EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& header); -EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& header, IDylibRef lib, Bool* successful); +EXTERN_C IDylibRef rtl_init_dylib_pef(UserProcess& header); +EXTERN_C Void rtl_fini_dylib_pef(UserProcess& header, IDylibRef lib, Bool* successful); } // namespace Kernel #endif /* ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ */ diff --git a/src/kernel/KernelKit/KernelTaskScheduler.h b/src/kernel/KernelKit/KernelTaskScheduler.h index 9bfce1d6..714a4fa7 100644 --- a/src/kernel/KernelKit/KernelTaskScheduler.h +++ b/src/kernel/KernelKit/KernelTaskScheduler.h @@ -19,11 +19,11 @@ class KernelTaskHelper; typedef ProcessID KID; -/// @brief Equivalent of USER_PROCESS, but for kernel tasks. +/// @brief Equivalent of UserProcess, but for kernel tasks. /// @author Amlal -class KERNEL_TASK final { +class KernelTask final { public: - Char Name[kSchedNameLen] = {"KERNEL_TASK"}; + Char Name[kSchedNameLen] = {"KernelTask"}; ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemKernel}; HAL::StackFramePtr StackFrame{nullptr}; UInt8* StackReserve{nullptr}; @@ -40,7 +40,7 @@ class KernelTaskHelper final { public: STATIC Bool Add(HAL::StackFramePtr frame_ptr, ProcessID new_kid); STATIC Bool Remove(const KID kid); - STATIC Bool CanBeScheduled(const KERNEL_TASK& process); + STATIC Bool CanBeScheduled(const KernelTask& process); STATIC ErrorOr<KID> TheCurrentKID(); STATIC SizeT StartScheduling(); }; diff --git a/src/kernel/KernelKit/UserProcessScheduler.h b/src/kernel/KernelKit/UserProcessScheduler.h index 6a6cfd61..9d483ef4 100644 --- a/src/kernel/KernelKit/UserProcessScheduler.h +++ b/src/kernel/KernelKit/UserProcessScheduler.h @@ -29,21 +29,21 @@ class UserProcessScheduler; class UserProcessHelper; /***********************************************************************************/ -/// @name USER_PROCESS -/// @brief USER_PROCESS class, holds information about the running process/thread. +/// @name UserProcess +/// @brief UserProcess class, holds information about the running process/thread. /***********************************************************************************/ -class USER_PROCESS final NE_VETTABLE { +class UserProcess final NE_VETTABLE { public: - explicit USER_PROCESS(); - ~USER_PROCESS(); + explicit UserProcess(); + ~UserProcess(); auto DoVet() const { return *this; } public: - NE_COPY_DEFAULT(USER_PROCESS) + NE_COPY_DEFAULT(UserProcess) public: - Char Name[kSchedNameLen] = {"USER_PROCESS"}; + Char Name[kSchedNameLen] = {"UserProcess"}; ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemUser}; User* Owner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; @@ -64,8 +64,8 @@ class USER_PROCESS final NE_VETTABLE { }; USER_PROCESS_SIGNAL Signal; - PROCESS_FILE_TREE<VoidPtr>* FileTree{nullptr}; - PROCESS_HEAP_TREE<VoidPtr>* HeapTree{nullptr}; + ProcessFileTree<VoidPtr>* FileTree{nullptr}; + ProcessHeapTree<VoidPtr>* HeapTree{nullptr}; UserProcessTeam* ParentTeam; VoidPtr VMRegister{0UL}; @@ -158,8 +158,8 @@ class USER_PROCESS final NE_VETTABLE { friend UserProcessHelper; }; -typedef Array<USER_PROCESS, kSchedProcessLimitPerTeam> USER_PROCESS_ARRAY; -typedef Ref<USER_PROCESS> USER_PROCESS_REF; +typedef Array<UserProcess, kSchedProcessLimitPerTeam> USER_PROCESS_ARRAY; +typedef Ref<UserProcess> USER_PROCESS_REF; /// \brief Processs Team (contains multiple processes inside it.) /// Equivalent to a process batch @@ -170,8 +170,8 @@ class UserProcessTeam final { NE_COPY_DEFAULT(UserProcessTeam) - Array<USER_PROCESS, kSchedProcessLimitPerTeam>& AsArray(); - Ref<USER_PROCESS>& AsRef(); + Array<UserProcess, kSchedProcessLimitPerTeam>& AsArray(); + Ref<UserProcess>& AsRef(); ProcessID& Id(); public: @@ -182,7 +182,7 @@ class UserProcessTeam final { }; /***********************************************************************************/ -/// @brief USER_PROCESS scheduler class. +/// @brief UserProcess scheduler class. /// The main class which you call to schedule user processes. /***********************************************************************************/ class UserProcessScheduler final : public ISchedulable { @@ -224,14 +224,14 @@ class UserProcessScheduler final : public ISchedulable { /***********************************************************************************/ /** - * \brief USER_PROCESS helper class, which contains needed utilities for the scheduler. + * \brief UserProcess helper class, which contains needed utilities for the scheduler. */ /***********************************************************************************/ class UserProcessHelper final { public: STATIC Bool Switch(HAL::StackFramePtr frame_ptr, ProcessID new_pid); - STATIC Bool CanBeScheduled(const USER_PROCESS& process); + STATIC Bool CanBeScheduled(const UserProcess& process); STATIC ErrorOr<ProcessID> TheCurrentPID(); STATIC SizeT StartScheduling(); }; diff --git a/src/kernel/KernelKit/UserProcessScheduler.inl b/src/kernel/KernelKit/UserProcessScheduler.inl index e8a57212..2ed960d5 100644 --- a/src/kernel/KernelKit/UserProcessScheduler.inl +++ b/src/kernel/KernelKit/UserProcessScheduler.inl @@ -21,15 +21,15 @@ namespace Kernel { /***********************************************************************************/ template <typename T> -BOOL USER_PROCESS::Delete(ErrorOr<T*> ptr) { +BOOL UserProcess::Delete(ErrorOr<T*> ptr) { if (!ptr) return No; if (!this->HeapTree) { - kout << "USER_PROCESS: Heap is empty.\r"; + kout << "UserProcess: Heap is empty.\r"; return No; } - PROCESS_HEAP_TREE<VoidPtr>* entry = this->HeapTree; + ProcessHeapTree<VoidPtr>* entry = this->HeapTree; while (entry != nullptr) { if (entry->Entry == ptr.Leak().Leak()) { @@ -51,7 +51,7 @@ BOOL USER_PROCESS::Delete(ErrorOr<T*> ptr) { entry = entry->Next; } - kout << "USER_PROCESS: Trying to free a pointer which doesn't exist.\r"; + kout << "UserProcess: Trying to free a pointer which doesn't exist.\r"; this->Crash(); diff --git a/src/kernel/NeKit/Config.h b/src/kernel/NeKit/Config.h index f8414069..bb21ba5c 100644 --- a/src/kernel/NeKit/Config.h +++ b/src/kernel/NeKit/Config.h @@ -79,7 +79,13 @@ using Lba = UInt64; using Char16 = char16_t; -enum struct Endian : UInt8 { kEndianInvalid, kEndianBig, kEndianLittle, kEndianMixed, kEndianCount }; +enum struct Endian : UInt8 { + kEndianInvalid, + kEndianBig, + kEndianLittle, + kEndianMixed, + kEndianCount +}; /// @brief Forward object. /// @tparam Args the object type. diff --git a/src/kernel/src/BinaryMutex.cc b/src/kernel/src/BinaryMutex.cc index f3c580ec..bfecfb53 100644 --- a/src/kernel/src/BinaryMutex.cc +++ b/src/kernel/src/BinaryMutex.cc @@ -26,7 +26,7 @@ Bool BinaryMutex::Unlock() { /// @brief Locks process in the binary mutex. /***********************************************************************************/ -Bool BinaryMutex::Lock(USER_PROCESS* process) { +Bool BinaryMutex::Lock(UserProcess* process) { if (!process || this->IsLocked()) return No; this->fLockingProcess = process; @@ -46,7 +46,7 @@ Bool BinaryMutex::IsLocked() const { /// @brief Try lock or wait. /***********************************************************************************/ -Bool BinaryMutex::LockAndWait(USER_PROCESS* process, TimerInterface* timer) { +Bool BinaryMutex::LockAndWait(UserProcess* process, TimerInterface* timer) { if (timer == nullptr) return No; this->Lock(process); diff --git a/src/kernel/src/IPEFDylibObject.cc b/src/kernel/src/IPEFDylibObject.cc index 90c83484..2cc9b328 100644 --- a/src/kernel/src/IPEFDylibObject.cc +++ b/src/kernel/src/IPEFDylibObject.cc @@ -42,7 +42,7 @@ using namespace Kernel; /** @brief Library initializer. */ /***********************************************************************************/ -EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& process) { +EXTERN_C IDylibRef rtl_init_dylib_pef(UserProcess& process) { IDylibRef dll_obj = tls_new_class<IPEFDylibObject>(); if (!dll_obj) { @@ -87,7 +87,7 @@ EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& process) { /** @param successful Reports if successful or not. */ /***********************************************************************************/ -EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& process, IDylibRef dll_obj, BOOL* successful) { +EXTERN_C Void rtl_fini_dylib_pef(UserProcess& process, IDylibRef dll_obj, BOOL* successful) { MUST_PASS(successful); if (!successful) { diff --git a/src/kernel/src/KernelTaskScheduler.cc b/src/kernel/src/KernelTaskScheduler.cc index c3628765..37aab59d 100644 --- a/src/kernel/src/KernelTaskScheduler.cc +++ b/src/kernel/src/KernelTaskScheduler.cc @@ -31,7 +31,7 @@ Bool KernelTaskHelper::Remove(const KID kid) { return NO; } -Bool KernelTaskHelper::CanBeScheduled(const KERNEL_TASK& task) { +Bool KernelTaskHelper::CanBeScheduled(const KernelTask& task) { return task.Kid > 0 && task.Image.HasCode(); } } // namespace Kernel
\ No newline at end of file diff --git a/src/kernel/src/UserMgr.cc b/src/kernel/src/UserMgr.cc index 9759b6fd..52730201 100644 --- a/src/kernel/src/UserMgr.cc +++ b/src/kernel/src/UserMgr.cc @@ -39,13 +39,13 @@ namespace Detail { kout << "user_fnv_generator: Hashing user password...\r"; const UInt64 kFnvOffsetBasis = 0xcbf29ce484222325ULL; - const UInt64 fFnvPrime = 0x100000001b3ULL; + const UInt64 kFnvPrime = 0x100000001b3ULL; UInt64 hash = kFnvOffsetBasis; while (*password) { hash ^= (Char) (*password++); - hash *= fFnvPrime; + hash *= kFnvPrime; } kout << "user_fnv_generator: Hashed user password.\r"; diff --git a/src/kernel/src/UserProcessScheduler.cc b/src/kernel/src/UserProcessScheduler.cc index 7c2d6d6a..f29b75a2 100644 --- a/src/kernel/src/UserProcessScheduler.cc +++ b/src/kernel/src/UserProcessScheduler.cc @@ -26,8 +26,8 @@ ///! BUGS: 0 namespace Kernel { -USER_PROCESS::USER_PROCESS() = default; -USER_PROCESS::~USER_PROCESS() = default; +UserProcess::UserProcess() = default; +UserProcess::~UserProcess() = default; /// @brief Gets the last exit code. /// @note Not thread-safe. @@ -37,7 +37,7 @@ USER_PROCESS::~USER_PROCESS() = default; /// @brief Crashes the current process. /***********************************************************************************/ -Void USER_PROCESS::Crash() { +Void UserProcess::Crash() { if (this->Status != ProcessStatusKind::kRunning) return; this->Status = ProcessStatusKind::kKilled; @@ -49,7 +49,7 @@ Void USER_PROCESS::Crash() { /// @brief boolean operator, check status. /***********************************************************************************/ -USER_PROCESS::operator bool() { +UserProcess::operator bool() { return this->Status == ProcessStatusKind::kRunning; } @@ -59,7 +59,7 @@ USER_PROCESS::operator bool() { /// @return Int32 the last exit code. /***********************************************************************************/ -KPCError& USER_PROCESS::GetExitCode() { +KPCError& UserProcess::GetExitCode() { return this->LastExitCode; } @@ -67,7 +67,7 @@ KPCError& USER_PROCESS::GetExitCode() { /// @brief Error code variable getter. /***********************************************************************************/ -KPCError& USER_PROCESS::GetLocalCode() { +KPCError& UserProcess::GetLocalCode() { return this->LocalCode; } @@ -76,7 +76,7 @@ KPCError& USER_PROCESS::GetLocalCode() { /// @param should_wakeup if the program shall wakeup or not. /***********************************************************************************/ -Void USER_PROCESS::Wake(Bool should_wakeup) { +Void UserProcess::Wake(Bool should_wakeup) { this->Status = should_wakeup ? ProcessStatusKind::kRunning : ProcessStatusKind::kFrozen; } @@ -91,9 +91,9 @@ STATIC T* sched_try_go_upper_ptr_tree(T* tree) { return nullptr; } - tree = tree->Parent; - if (tree) { + if (tree->Parent) tree = tree->Parent; + auto tree_tmp = tree->Next; if (!tree_tmp) { @@ -110,7 +110,7 @@ STATIC T* sched_try_go_upper_ptr_tree(T* tree) { /** @brief Allocate pointer to heap/file tree. */ /***********************************************************************************/ -ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { +ErrorOr<VoidPtr> UserProcess::New(SizeT sz, SizeT pad_amount) { if (this->UsedMemory > kSchedMaxMemoryLimit) return ErrorOr<VoidPtr>(-kErrorHeapOutOfMemory); #ifdef __NE_VIRTUAL_MEMORY_SUPPORT__ @@ -126,7 +126,7 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { #endif if (!this->HeapTree) { - this->HeapTree = new PROCESS_HEAP_TREE<VoidPtr>(); + this->HeapTree = new ProcessHeapTree<VoidPtr>(); if (!this->HeapTree) { this->Crash(); @@ -138,15 +138,15 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { this->HeapTree->Entry = ptr; - this->HeapTree->Color = kBlackTreeKind; + this->HeapTree->Color = TreeKind::kBlackTreeKind; this->HeapTree->Prev = nullptr; this->HeapTree->Next = nullptr; this->HeapTree->Parent = nullptr; this->HeapTree->Child = nullptr; } else { - PROCESS_HEAP_TREE<VoidPtr>* entry = this->HeapTree; - PROCESS_HEAP_TREE<VoidPtr>* prev_entry = entry; + ProcessHeapTree<VoidPtr>* entry = this->HeapTree; + ProcessHeapTree<VoidPtr>* prev_entry = entry; BOOL is_parent = NO; @@ -163,11 +163,11 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { entry = entry->Next; } else { entry = sched_try_go_upper_ptr_tree(entry); - if (entry && entry->Color == kBlackTreeKind) break; + if (entry && entry->Color == TreeKind::kBlackTreeKind) break; } } - auto new_entry = new PROCESS_HEAP_TREE<VoidPtr>(); + auto new_entry = new ProcessHeapTree<VoidPtr>(); if (!new_entry) { this->Crash(); @@ -182,8 +182,8 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { new_entry->Next = nullptr; new_entry->Prev = nullptr; - new_entry->Color = kBlackTreeKind; - prev_entry->Color = kRedTreeKind; + new_entry->Color = TreeKind::kBlackTreeKind; + prev_entry->Color = TreeKind::kRedTreeKind; if (is_parent) { prev_entry->Child = new_entry; @@ -203,7 +203,7 @@ ErrorOr<VoidPtr> USER_PROCESS::New(SizeT sz, SizeT pad_amount) { /// @brief Gets the name of the current process. /***********************************************************************************/ -const Char* USER_PROCESS::GetName() { +const Char* UserProcess::GetName() { return this->Name; } @@ -211,12 +211,12 @@ const Char* USER_PROCESS::GetName() { /// @brief Gets the owner of the process. /***********************************************************************************/ -const User* USER_PROCESS::GetOwner() { +const User* UserProcess::GetOwner() { return this->Owner; } -/// @brief USER_PROCESS status getter. -const ProcessStatusKind& USER_PROCESS::GetStatus() { +/// @brief UserProcess status getter. +const ProcessStatusKind& UserProcess::GetStatus() { return this->Status; } @@ -226,7 +226,7 @@ const ProcessStatusKind& USER_PROCESS::GetStatus() { */ /***********************************************************************************/ -const AffinityKind& USER_PROCESS::GetAffinity() { +const AffinityKind& UserProcess::GetAffinity() { return this->Affinity; } @@ -262,7 +262,7 @@ STATIC Void sched_free_ptr_tree(T* tree) { */ /***********************************************************************************/ -Void USER_PROCESS::Exit(const Int32& exit_code) { +Void UserProcess::Exit(const Int32& exit_code) { this->Status = exit_code > 0 ? ProcessStatusKind::kKilled : ProcessStatusKind::kFrozen; this->LastExitCode = exit_code; @@ -323,10 +323,10 @@ Void USER_PROCESS::Exit(const Int32& exit_code) { /// @brief Add dylib to the process object. /***********************************************************************************/ -Bool USER_PROCESS::InitDylib() { +Bool UserProcess::InitDylib() { // React according to the process's kind. switch (this->Kind) { - case USER_PROCESS::kExecutableDylibKind: { + case UserProcess::kExecutableDylibKind: { this->DylibDelegate = rtl_init_dylib_pef(*this); if (!this->DylibDelegate) { @@ -336,7 +336,7 @@ Bool USER_PROCESS::InitDylib() { return YES; } - case USER_PROCESS::kExecutableKind: { + case UserProcess::kExecutableKind: { return NO; } default: { @@ -373,7 +373,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im ++this->mTeam.mProcessCur; - USER_PROCESS& process = this->mTeam.mProcessList[pid]; + UserProcess& process = this->mTeam.mProcessList[pid]; process.Image.fCode = code; process.Image.fBlob = image; @@ -427,7 +427,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im process.RTime = 0; if (!process.FileTree) { - process.FileTree = new PROCESS_FILE_TREE<VoidPtr>(); + process.FileTree = new ProcessFileTree<VoidPtr>(); if (!process.FileTree) { process.Crash(); @@ -489,7 +489,7 @@ Bool UserProcessScheduler::HasMP() { /***********************************************************************************/ /// @brief Run User scheduler object. -/// @return USER_PROCESS count executed within a team. +/// @return UserProcess count executed within a team. /***********************************************************************************/ SizeT UserProcessScheduler::Run() { @@ -562,12 +562,12 @@ BOOL UserProcessScheduler::SwitchTeam(UserProcessTeam& team) { /// @brief Gets current running process. /// @return -Ref<USER_PROCESS>& UserProcessScheduler::TheCurrentProcess() { +Ref<UserProcess>& UserProcessScheduler::TheCurrentProcess() { return mTeam.AsRef(); } /// @brief Current proccess id getter. -/// @return USER_PROCESS ID integer. +/// @return UserProcess ID integer. ErrorOr<ProcessID> UserProcessHelper::TheCurrentPID() { if (!UserProcessScheduler::The().TheCurrentProcess()) return ErrorOr<ProcessID>{-kErrorProcessFault}; @@ -580,7 +580,7 @@ ErrorOr<ProcessID> UserProcessHelper::TheCurrentPID() { /// @param process the process reference. /// @retval true can be schedulded. /// @retval false cannot be schedulded. -Bool UserProcessHelper::CanBeScheduled(const USER_PROCESS& process) { +Bool UserProcessHelper::CanBeScheduled(const UserProcess& process) { if (process.Affinity == AffinityKind::kRealTime) return Yes; if (process.Status != ProcessStatusKind::kRunning) return No; diff --git a/src/kernel/src/UserProcessTeam.cc b/src/kernel/src/UserProcessTeam.cc index 9b124d75..4413ad09 100644 --- a/src/kernel/src/UserProcessTeam.cc +++ b/src/kernel/src/UserProcessTeam.cc @@ -15,7 +15,7 @@ namespace Kernel { UserProcessTeam::UserProcessTeam() { for (SizeT i = 0U; i < this->mProcessList.Count(); ++i) { - this->mProcessList[i] = USER_PROCESS(); + this->mProcessList[i] = UserProcess(); this->mProcessList[i].PTime = 0; this->mProcessList[i].RTime = 0; this->mProcessList[i].UTime = 0; @@ -31,7 +31,7 @@ UserProcessTeam::UserProcessTeam() { /// @return The list of process to schedule. /***********************************************************************************/ -Array<USER_PROCESS, kSchedProcessLimitPerTeam>& UserProcessTeam::AsArray() { +Array<UserProcess, kSchedProcessLimitPerTeam>& UserProcessTeam::AsArray() { return this->mProcessList; } @@ -49,7 +49,7 @@ ProcessID& UserProcessTeam::Id() { /// @return The current process header. /***********************************************************************************/ -Ref<USER_PROCESS>& UserProcessTeam::AsRef() { +Ref<UserProcess>& UserProcessTeam::AsRef() { return this->mCurrentProcess; } } // namespace Kernel diff --git a/tools/chk.hefs.cc b/tools/chk.hefs.cc index c1c58c6e..a47e4fc6 100644 --- a/tools/chk.hefs.cc +++ b/tools/chk.hefs.cc @@ -59,7 +59,8 @@ int main(int argc, char** argv) { if (strncmp(boot_node.magic, kOpenHeFSMagic, kOpenHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || boot_node.sectorSize < kMkFsSectorSz) { - mkfs::console_out() << "hefs: error: Device does not contain an OpenHeFS disk: " << opt_disk << "\n"; + mkfs::console_out() << "hefs: error: Device does not contain an OpenHeFS disk: " << opt_disk + << "\n"; return EXIT_FAILURE; } diff --git a/tools/mkfs.hefs.cc b/tools/mkfs.hefs.cc index 7016bf18..4be6ed04 100644 --- a/tools/mkfs.hefs.cc +++ b/tools/mkfs.hefs.cc @@ -12,12 +12,12 @@ #include <fstream> #include <limits> -static uint16_t kVersion = kOpenHeFSVersion; -static uint16_t kNumericalBase = 10; +static std::uint16_t kVersion = kOpenHeFSVersion; +static std::uint16_t kNumericalBase = 10; -static size_t kDiskSize = mkfs::detail::gib_cast(4UL); +static std::size_t kDiskSize = mkfs::detail::gib_cast(4UL); static std::u8string kDiskLabel; -static size_t kDiskSectorSz = 512; +static std::size_t kDiskSectorSz = 512; int main(int argc, char** argv) { if (argc != 10) { @@ -32,6 +32,7 @@ int main(int argc, char** argv) { std::string args = mkfs::detail::build_args(argc, argv); auto output_path = mkfs::get_option<char>(args, "o"); + if (output_path.empty()) { mkfs::console_out() << "hefs: error: Missing -o <output_device> argument.\n"; return EXIT_FAILURE; @@ -39,6 +40,7 @@ int main(int argc, char** argv) { auto opt_s = mkfs::get_option<char>(args, "s"); long parsed_s = 0; + if (!mkfs::detail::parse_signed(opt_s, parsed_s, kNumericalBase) || parsed_s == 0) { mkfs::console_out() << "hefs: error: Invalid sector size \"" << opt_s << "\". Must be a positive integer.\n"; @@ -50,9 +52,11 @@ int main(int argc, char** argv) { << "\" is not a power of two.\n"; return EXIT_FAILURE; } + kDiskSectorSz = static_cast<size_t>(parsed_s); auto opt_L = mkfs::get_option<char>(args, "L"); + if (!opt_L.empty()) { kDiskLabel.clear(); for (char c : opt_L) kDiskLabel.push_back(static_cast<char8_t>(c)); @@ -65,16 +69,19 @@ int main(int argc, char** argv) { auto opt_S = mkfs::get_option<char>(args, "S"); unsigned long long gb = 0; + if (!mkfs::detail::parse_decimal(opt_S, gb) || gb == 0ULL) { mkfs::console_out() << "hefs: error: Invalid disk size \"" << opt_S << "\". Must be a positive integer.\n"; return EXIT_FAILURE; } unsigned long long max_gb = std::numeric_limits<uint64_t>::max() / (1024ULL * 1024ULL * 1024ULL); + if (gb > max_gb) { mkfs::console_out() << "hefs: error: Disk size \"" << gb << "GB\" is too large.\n"; return EXIT_FAILURE; } + kDiskSize = static_cast<size_t>(gb * 1024ULL * 1024ULL * 1024ULL); auto opt_b = mkfs::get_option<char>(args, "b"); @@ -178,19 +185,21 @@ int main(int argc, char** argv) { } output_device.write(reinterpret_cast<const char*>(&boot_node), sizeof(boot_node)); + if (!output_device.good()) { mkfs::console_out() << "hefs: error: Unable to write BootNode to output device: " << output_path << "\n"; return EXIT_FAILURE; } - output_device.seekp(static_cast<std::streamoff>(boot_node.startIND)); + output_device.seekp(static_cast<std::streamoff>(kDiskSize - 1)); + if (!output_device.good()) { mkfs::console_out() << "hefs: error: Failed seek to startIND.\n"; return EXIT_FAILURE; } - output_device.seekp(static_cast<std::streamoff>(kDiskSize - 1)); + output_device.put(0); output_device.flush(); |
