From 0adf3b9b215ab90533b0a4b07d6bf4c12dad74bf Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 5 Sep 2025 13:28:23 +0200 Subject: feat: libSystem: `libsys_hash_64` is now defined in `src/System.cc` Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/Syscall.h | 18 ++---------------- dev/libSystem/src/System.cc | 17 +++++++++++++++++ dev/misc/BenchKit/HWChronometer.h | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index a1505b46..35bfc6f8 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -14,22 +14,8 @@ IMPORT_C VoidPtr libsys_syscall_arg_2(SizeT id, VoidPtr arg1); IMPORT_C VoidPtr libsys_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); IMPORT_C VoidPtr libsys_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); -inline UInt64 libsys_hash_64(const Char* path) { - if (!path || *path == 0) return 0; - - const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; - const UInt64 FNV_PRIME = 0x100000001b3ULL; - - UInt64 hash = FNV_OFFSET_BASIS; - - while (*path) { - hash ^= (Char) (*path++); - hash *= FNV_PRIME; - } - - return hash; -} +IMPORT_C UInt64 libsys_hash_64(const Char* path); #ifndef SYSCALL_HASH #define SYSCALL_HASH(str) libsys_hash_64(str) -#endif // !SYSCALL_HASH \ No newline at end of file +#endif // !SYSCALL_HASH diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc index 3870ff18..ba848a18 100644 --- a/dev/libSystem/src/System.cc +++ b/dev/libSystem/src/System.cc @@ -23,6 +23,23 @@ IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { } } +/// @note this uses the FNV 64-bit variant. +IMPORT_C UInt64 libsys_hash_64(const Char* path) { + if (!path || *path == 0) return 0; + + const UInt64 kFNVSeed = 0xcbf29ce484222325ULL; + const UInt64 kFNVPrime = 0x100000001b3ULL; + + UInt64 hash = kFNVSeed; + + while (*path) { + hash ^= (Char) (*path++); + hash *= kFNVPrime; + } + + return hash; +} + // memmove-style copy IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { // handles overlap, prefers 64-bit word copies when aligned diff --git a/dev/misc/BenchKit/HWChronometer.h b/dev/misc/BenchKit/HWChronometer.h index e232db7e..56e4f2af 100644 --- a/dev/misc/BenchKit/HWChronometer.h +++ b/dev/misc/BenchKit/HWChronometer.h @@ -14,7 +14,7 @@ struct HWChronoTraits; template class HWChrono; -/// @brief BenchKit chrono logic for x64. +/// @brief BenchKit chrono logic for x64/ARM64. struct HWChronoTraits final { private: STATIC UInt64 TickImpl_(void) { -- cgit v1.2.3 From d9e1479799ef2d7594c9c9f7dc2724353a01faff Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 7 Sep 2025 00:10:00 +0200 Subject: meta: FSKit: Ext2 module has been formatted according to codebase. Signed-off-by: Amlal El Mahrouss --- dev/kernel/FSKit/Ext2.h | 202 ++++++++++++++++++++++----------------------- dev/kernel/FSKit/Ext2IFS.h | 186 ++++++++++++++++++++--------------------- 2 files changed, 195 insertions(+), 193 deletions(-) diff --git a/dev/kernel/FSKit/Ext2.h b/dev/kernel/FSKit/Ext2.h index 42875c47..06370a8c 100644 --- a/dev/kernel/FSKit/Ext2.h +++ b/dev/kernel/FSKit/Ext2.h @@ -18,126 +18,126 @@ namespace Ext2 { /// EXT2 Constants -#define kExt2FSMagic (0xEF53) -#define kExt2FSMaxFileNameLen (255U) -#define kExt2FSSuperblockOffset (1024) -#define kExt2FSRootInodeNumber (2) -#define kExt2FSInodeSize (128U) -#define kExt2FSBlockSizeBase (1024U) +#define kExt2FSMagic (0xEF53) +#define kExt2FSMaxFileNameLen (255U) +#define kExt2FSSuperblockOffset (1024) +#define kExt2FSRootInodeNumber (2) +#define kExt2FSInodeSize (128U) +#define kExt2FSBlockSizeBase (1024U) -#define kExt2FSRev0 (0) -#define kExt2FSRev1 (1) +#define kExt2FSRev0 (0) +#define kExt2FSRev1 (1) /// EXT2 file types enum { - kExt2FileTypeUnknown = 0, - kExt2FileTypeRegular = 1, - kExt2FileTypeDirectory = 2, - kExt2FileTypeCharDevice = 3, - kExt2FileTypeBlockDevice = 4, - kExt2FileTypeFIFO = 5, - kExt2FileTypeSocket = 6, - kExt2FileTypeSymbolicLink = 7 + kExt2FileTypeUnknown = 0, + kExt2FileTypeRegular = 1, + kExt2FileTypeDirectory = 2, + kExt2FileTypeCharDevice = 3, + kExt2FileTypeBlockDevice = 4, + kExt2FileTypeFIFO = 5, + kExt2FileTypeSocket = 6, + kExt2FileTypeSymbolicLink = 7 }; struct PACKED EXT2_SUPER_BLOCK final { - Kernel::UInt32 fInodeCount; - Kernel::UInt32 fBlockCount; - Kernel::UInt32 fReservedBlockCount; - Kernel::UInt32 fFreeBlockCount; - Kernel::UInt32 fFreeInodeCount; - Kernel::UInt32 fFirstDataBlock; - Kernel::UInt32 fLogBlockSize; - Kernel::UInt32 fLogFragmentSize; - Kernel::UInt32 fBlocksPerGroup; - Kernel::UInt32 fFragmentsPerGroup; - Kernel::UInt32 fInodesPerGroup; - Kernel::UInt32 fMountTime; - Kernel::UInt32 fWriteTime; - Kernel::UInt16 fMountCount; - Kernel::UInt16 fMaxMountCount; - Kernel::UInt16 fMagic; - Kernel::UInt16 fState; - Kernel::UInt16 fErrors; - Kernel::UInt16 fMinorRevision; - Kernel::UInt32 fLastCheck; - Kernel::UInt32 fCheckInterval; - Kernel::UInt32 fCreatorOS; - Kernel::UInt32 fRevisionLevel; - Kernel::UInt16 fDefaultUID; - Kernel::UInt16 fDefaultGID; - - // EXT2_DYNAMIC_REV fields - Kernel::UInt32 fFirstInode; - Kernel::UInt16 fInodeSize; - Kernel::UInt16 fBlockGroupNumber; - Kernel::UInt32 fFeatureCompat; - Kernel::UInt32 fFeatureIncompat; - Kernel::UInt32 fFeatureROCompat; - Kernel::UInt8 fUUID[16]; - Kernel::Char fVolumeName[16]; - Kernel::Char fLastMounted[64]; - Kernel::UInt32 fAlgoBitmap; - - Kernel::UInt8 fPreallocBlocks; - Kernel::UInt8 fPreallocDirBlocks; - Kernel::UInt16 fReservedGDTBlocks; - - Kernel::UInt8 fJournalUUID[16]; - Kernel::UInt32 fJournalInode; - Kernel::UInt32 fJournalDevice; - Kernel::UInt32 fLastOrphan; - - Kernel::UInt32 fHashSeed[4]; - Kernel::UInt8 fDefHashVersion; - Kernel::UInt8 fReservedCharPad; - Kernel::UInt16 fReservedWordPad; - Kernel::UInt32 fDefaultMountOpts; - Kernel::UInt32 fFirstMetaBlockGroup; - - Kernel::UInt8 fReserved[760]; // Padding to make 1024 bytes + Kernel::UInt32 fInodeCount; + Kernel::UInt32 fBlockCount; + Kernel::UInt32 fReservedBlockCount; + Kernel::UInt32 fFreeBlockCount; + Kernel::UInt32 fFreeInodeCount; + Kernel::UInt32 fFirstDataBlock; + Kernel::UInt32 fLogBlockSize; + Kernel::UInt32 fLogFragmentSize; + Kernel::UInt32 fBlocksPerGroup; + Kernel::UInt32 fFragmentsPerGroup; + Kernel::UInt32 fInodesPerGroup; + Kernel::UInt32 fMountTime; + Kernel::UInt32 fWriteTime; + Kernel::UInt16 fMountCount; + Kernel::UInt16 fMaxMountCount; + Kernel::UInt16 fMagic; + Kernel::UInt16 fState; + Kernel::UInt16 fErrors; + Kernel::UInt16 fMinorRevision; + Kernel::UInt32 fLastCheck; + Kernel::UInt32 fCheckInterval; + Kernel::UInt32 fCreatorOS; + Kernel::UInt32 fRevisionLevel; + Kernel::UInt16 fDefaultUID; + Kernel::UInt16 fDefaultGID; + + // EXT2_DYNAMIC_REV fields + Kernel::UInt32 fFirstInode; + Kernel::UInt16 fInodeSize; + Kernel::UInt16 fBlockGroupNumber; + Kernel::UInt32 fFeatureCompat; + Kernel::UInt32 fFeatureIncompat; + Kernel::UInt32 fFeatureROCompat; + Kernel::UInt8 fUUID[16]; + Kernel::Char fVolumeName[16]; + Kernel::Char fLastMounted[64]; + Kernel::UInt32 fAlgoBitmap; + + Kernel::UInt8 fPreallocBlocks; + Kernel::UInt8 fPreallocDirBlocks; + Kernel::UInt16 fReservedGDTBlocks; + + Kernel::UInt8 fJournalUUID[16]; + Kernel::UInt32 fJournalInode; + Kernel::UInt32 fJournalDevice; + Kernel::UInt32 fLastOrphan; + + Kernel::UInt32 fHashSeed[4]; + Kernel::UInt8 fDefHashVersion; + Kernel::UInt8 fReservedCharPad; + Kernel::UInt16 fReservedWordPad; + Kernel::UInt32 fDefaultMountOpts; + Kernel::UInt32 fFirstMetaBlockGroup; + + Kernel::UInt8 fReserved[760]; // Padding to make 1024 bytes }; struct PACKED EXT2_INODE final { - Kernel::UInt16 fMode; - Kernel::UInt16 fUID; - Kernel::UInt32 fSize; - Kernel::UInt32 fAccessTime; - Kernel::UInt32 fCreateTime; - Kernel::UInt32 fModifyTime; - Kernel::UInt32 fDeleteTime; - Kernel::UInt16 fGID; - Kernel::UInt16 fLinksCount; - Kernel::UInt32 fBlocks; - Kernel::UInt32 fFlags; - Kernel::UInt32 fOSD1; - - Kernel::UInt32 fBlock[15]; // direct 0-11, indirect 12, double 13, triple 14 - - Kernel::UInt32 fGeneration; - Kernel::UInt32 fFileACL; - Kernel::UInt32 fDirACL; - Kernel::UInt32 fFragmentAddr; - - Kernel::UInt8 fOSD2[12]; + Kernel::UInt16 fMode; + Kernel::UInt16 fUID; + Kernel::UInt32 fSize; + Kernel::UInt32 fAccessTime; + Kernel::UInt32 fCreateTime; + Kernel::UInt32 fModifyTime; + Kernel::UInt32 fDeleteTime; + Kernel::UInt16 fGID; + Kernel::UInt16 fLinksCount; + Kernel::UInt32 fBlocks; + Kernel::UInt32 fFlags; + Kernel::UInt32 fOSD1; + + Kernel::UInt32 fBlock[15]; // direct 0-11, indirect 12, double 13, triple 14 + + Kernel::UInt32 fGeneration; + Kernel::UInt32 fFileACL; + Kernel::UInt32 fDirACL; + Kernel::UInt32 fFragmentAddr; + + Kernel::UInt8 fOSD2[12]; }; /// Directory entry struct PACKED EXT2_DIR_ENTRY final { - Kernel::UInt32 fInode; - Kernel::UInt16 fRecordLength; - Kernel::UInt8 fNameLength; - Kernel::UInt8 fFileType; - Kernel::Char fName[kExt2FSMaxFileNameLen]; + Kernel::UInt32 fInode; + Kernel::UInt16 fRecordLength; + Kernel::UInt8 fNameLength; + Kernel::UInt8 fFileType; + Kernel::Char fName[kExt2FSMaxFileNameLen]; }; /// VFS usage struct Ext2Node { - Kernel::UInt32 inodeNumber; - EXT2_INODE inode; - Kernel::UInt32 cursor{0}; + Kernel::UInt32 inodeNumber; + EXT2_INODE inode; + Kernel::UInt32 cursor{0}; }; class Ext2FileSystemMgr; -} // namespace Ext2 +} // namespace Ext2 diff --git a/dev/kernel/FSKit/Ext2IFS.h b/dev/kernel/FSKit/Ext2IFS.h index 87095bc6..2550cfea 100644 --- a/dev/kernel/FSKit/Ext2IFS.h +++ b/dev/kernel/FSKit/Ext2IFS.h @@ -3,131 +3,133 @@ #include #include #include -#include -#include +#include #include -#include +#include +#include namespace Ext2 { /// @brief Context for an EXT2 filesystem on a given drive -struct Context { - Kernel::DriveTrait* drive{nullptr}; - EXT2_SUPER_BLOCK* superblock{nullptr}; - - /// @brief context with a drive - explicit Context(Kernel::DriveTrait* drv) : drive(drv) {} - - /// @brief Clean up - ~Context() { - if (superblock) { - Kernel::mm_free_ptr(superblock); - superblock = nullptr; - } - } - - Context(const Context&) = delete; - Context& operator=(const Context&) = delete; - - Context(Context&& other) noexcept : drive(other.drive), superblock(other.superblock) { - other.drive = nullptr; - other.superblock = nullptr; +struct Context { + Kernel::DriveTrait* drive{nullptr}; + EXT2_SUPER_BLOCK* superblock{nullptr}; + + /// @brief context with a drive + explicit Context(Kernel::DriveTrait* drv) : drive(drv) {} + + /// @brief Clean up + ~Context() { + if (superblock) { + Kernel::mm_free_ptr(superblock); + superblock = nullptr; } - - Context& operator=(Context&& other) noexcept { - if (this != &other) { - if (superblock) { - Kernel::mm_free_ptr(superblock); - } - drive = other.drive; - superblock = other.superblock; - other.drive = nullptr; - other.superblock = nullptr; - } - return *this; + } + + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + + Context(Context&& other) noexcept : drive(other.drive), superblock(other.superblock) { + other.drive = nullptr; + other.superblock = nullptr; + } + + Context& operator=(Context&& other) noexcept { + if (this != &other) { + if (superblock) { + Kernel::mm_free_ptr(superblock); + } + drive = other.drive; + superblock = other.superblock; + other.drive = nullptr; + other.superblock = nullptr; } + return *this; + } - inline Kernel::UInt32 BlockSize() const { - if (!superblock) return kExt2FSBlockSizeBase; - return kExt2FSBlockSizeBase << superblock->fLogBlockSize; - } + inline Kernel::UInt32 BlockSize() const { + if (!superblock) return kExt2FSBlockSizeBase; + return kExt2FSBlockSizeBase << superblock->fLogBlockSize; + } }; -inline bool ext2_read_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, void* buffer, Kernel::UInt32 size) { - if (!drv || !buffer) return false; +inline bool ext2_read_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, void* buffer, + Kernel::UInt32 size) { + if (!drv || !buffer) return false; - Kernel::DriveTrait::DrivePacket pkt{}; - pkt.fPacketContent = buffer; - pkt.fPacketSize = size; - pkt.fPacketLba = lba; - drv->fInput(pkt); - return pkt.fPacketGood; + Kernel::DriveTrait::DrivePacket pkt{}; + pkt.fPacketContent = buffer; + pkt.fPacketSize = size; + pkt.fPacketLba = lba; + drv->fInput(pkt); + return pkt.fPacketGood; } -inline bool ext2_write_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, const void* buffer, Kernel::UInt32 size) { - if (!drv || !buffer) return false; +inline bool ext2_write_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, const void* buffer, + Kernel::UInt32 size) { + if (!drv || !buffer) return false; - Kernel::DriveTrait::DrivePacket pkt{}; - pkt.fPacketContent = const_cast(buffer); - pkt.fPacketSize = size; - pkt.fPacketLba = lba; - drv->fOutput(pkt); - return pkt.fPacketGood; + Kernel::DriveTrait::DrivePacket pkt{}; + pkt.fPacketContent = const_cast(buffer); + pkt.fPacketSize = size; + pkt.fPacketLba = lba; + drv->fOutput(pkt); + return pkt.fPacketGood; } // Load superblock inline Kernel::ErrorOr ext2_load_superblock(Context* ctx) { - if (!ctx || !ctx->drive) return Kernel::ErrorOr(Kernel::kErrorInvalidData); + if (!ctx || !ctx->drive) return Kernel::ErrorOr(Kernel::kErrorInvalidData); - auto buf = Kernel::mm_alloc_ptr(sizeof(EXT2_SUPER_BLOCK), true, false); - if (!buf) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); + auto buf = Kernel::mm_alloc_ptr(sizeof(EXT2_SUPER_BLOCK), true, false); + if (!buf) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); - Kernel::UInt32 blockLba = kExt2FSSuperblockOffset / ctx->drive->fSectorSz; - if (!ext2_read_block(ctx->drive, blockLba, buf, sizeof(EXT2_SUPER_BLOCK))) { - Kernel::mm_free_ptr(buf); - return Kernel::ErrorOr(Kernel::kErrorDisk); - } + Kernel::UInt32 blockLba = kExt2FSSuperblockOffset / ctx->drive->fSectorSz; + if (!ext2_read_block(ctx->drive, blockLba, buf, sizeof(EXT2_SUPER_BLOCK))) { + Kernel::mm_free_ptr(buf); + return Kernel::ErrorOr(Kernel::kErrorDisk); + } - auto sb = reinterpret_cast(buf); - if (sb->fMagic != kExt2FSMagic) { - Kernel::mm_free_ptr(buf); - return Kernel::ErrorOr(Kernel::kErrorInvalidData); - } + auto sb = reinterpret_cast(buf); + if (sb->fMagic != kExt2FSMagic) { + Kernel::mm_free_ptr(buf); + return Kernel::ErrorOr(Kernel::kErrorInvalidData); + } - ctx->superblock = sb; - return Kernel::ErrorOr(sb); + ctx->superblock = sb; + return Kernel::ErrorOr(sb); } // Load inode -inline Kernel::ErrorOr ext2_load_inode(Context* ctx, Kernel::UInt32 inodeNumber) { - if (!ctx || !ctx->superblock) return Kernel::ErrorOr(Kernel::kErrorInvalidData); +inline Kernel::ErrorOr ext2_load_inode(Context* ctx, Kernel::UInt32 inodeNumber) { + if (!ctx || !ctx->superblock) return Kernel::ErrorOr(Kernel::kErrorInvalidData); - auto nodePtr = Kernel::mm_alloc_ptr(sizeof(Ext2Node), true, false); - if (!nodePtr) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); + auto nodePtr = Kernel::mm_alloc_ptr(sizeof(Ext2Node), true, false); + if (!nodePtr) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); - auto ext2Node = reinterpret_cast(nodePtr); - ext2Node->inodeNumber = inodeNumber; + auto ext2Node = reinterpret_cast(nodePtr); + ext2Node->inodeNumber = inodeNumber; - // Compute block group and index within group - Kernel::UInt32 inodesPerGroup = ctx->superblock->fInodesPerGroup; - Kernel::UInt32 group = (inodeNumber - 1) / inodesPerGroup; - Kernel::UInt32 index = (inodeNumber - 1) % inodesPerGroup; + // Compute block group and index within group + Kernel::UInt32 inodesPerGroup = ctx->superblock->fInodesPerGroup; + Kernel::UInt32 group = (inodeNumber - 1) / inodesPerGroup; + Kernel::UInt32 index = (inodeNumber - 1) % inodesPerGroup; - // dummy: just offset first inode - Kernel::UInt32 inodeTableBlock = ctx->superblock->fFirstInode + group; + // dummy: just offset first inode + Kernel::UInt32 inodeTableBlock = ctx->superblock->fFirstInode + group; - if (!ext2_read_block(ctx->drive, inodeTableBlock, &ext2Node->inode, sizeof(EXT2_INODE))) { - Kernel::mm_free_ptr(nodePtr); - return Kernel::ErrorOr(Kernel::kErrorDisk); - } + if (!ext2_read_block(ctx->drive, inodeTableBlock, &ext2Node->inode, sizeof(EXT2_INODE))) { + Kernel::mm_free_ptr(nodePtr); + return Kernel::ErrorOr(Kernel::kErrorDisk); + } - ext2Node->cursor = 0; - return Kernel::ErrorOr(ext2Node); + ext2Node->cursor = 0; + return Kernel::ErrorOr(ext2Node); } inline Kernel::UInt32 inode_offset(const Context* ctx, Kernel::UInt32 inodeNumber) { - if (!ctx || !ctx->superblock) return 0; - return ((inodeNumber - 1) % ctx->superblock->fInodesPerGroup) * ctx->superblock->fInodeSize; + if (!ctx || !ctx->superblock) return 0; + return ((inodeNumber - 1) % ctx->superblock->fInodesPerGroup) * ctx->superblock->fInodeSize; } -} // namespace Ext2 +} // namespace Ext2 -- cgit v1.2.3 From 537cadbf78695a01ea1c00a0a5a4b6b70ddac8c3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 7 Sep 2025 18:12:25 +0200 Subject: feat: `ne_launch` and `LaunchHelpers.fwrk`: PID zero of NeKernel. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 4 ---- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 4 ---- dev/launch/.keep | 0 dev/launch/LaunchKit/.keep | 0 dev/launch/obj/.keep | 0 dev/launch/src/.keep | 0 dev/libDDK/DriverKit/cpp/object.hpp | 16 ++++++++++++++++ dev/libDDK/DriverKit/ddk.h | 4 +++- dev/libDDK/src/ddk_kernel_call.c | 2 +- dev/libDDK/src/ddk_kernel_call_dispatch.S | 3 ++- public/frameworks/LaunchHelpers.fwrk/.keep | 0 .../frameworks/LaunchHelpers.fwrk/LaunchHelpers.json | 19 +++++++++++++++++++ public/frameworks/LaunchHelpers.fwrk/dist/.keep | 0 public/frameworks/LaunchHelpers.fwrk/headers/.keep | 0 public/frameworks/LaunchHelpers.fwrk/src/.keep | 0 public/frameworks/LaunchHelpers.fwrk/src/DylibMain.cc | 5 +++++ public/frameworks/LaunchHelpers.fwrk/xml/.keep | 0 public/frameworks/LaunchHelpers.fwrk/xml/app.xml | 2 ++ 18 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 dev/launch/.keep create mode 100644 dev/launch/LaunchKit/.keep create mode 100644 dev/launch/obj/.keep create mode 100644 dev/launch/src/.keep create mode 100644 dev/libDDK/DriverKit/cpp/object.hpp create mode 100644 public/frameworks/LaunchHelpers.fwrk/.keep create mode 100644 public/frameworks/LaunchHelpers.fwrk/LaunchHelpers.json create mode 100644 public/frameworks/LaunchHelpers.fwrk/dist/.keep create mode 100644 public/frameworks/LaunchHelpers.fwrk/headers/.keep create mode 100644 public/frameworks/LaunchHelpers.fwrk/src/.keep create mode 100644 public/frameworks/LaunchHelpers.fwrk/src/DylibMain.cc create mode 100644 public/frameworks/LaunchHelpers.fwrk/xml/.keep create mode 100644 public/frameworks/LaunchHelpers.fwrk/xml/app.xml diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index f121fbb4..cb5d4af8 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -148,10 +148,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { ProcessStatusKind::kInvalid; } - rtl_create_user_process(sched_idle_task, "MgmtSrv"); //! Mgmt command server. - rtl_create_user_process(sched_idle_task, "LaunchSrv"); //! launchd - rtl_create_user_process(sched_idle_task, "SecSrv"); //! Login Server - HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); #ifdef __FSKIT_INCLUDES_HEFS__ diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index d7663f4e..096df49e 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -67,10 +67,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { ProcessStatusKind::kInvalid; } - rtl_create_user_process(sched_idle_task, "MgmtSrv"); //! Mgmt command server. - rtl_create_user_process(sched_idle_task, "LaunchSrv"); //! launchd - rtl_create_user_process(sched_idle_task, "SecSrv"); //! Login Server - Kernel::mp_init_cores(); while (YES) diff --git a/dev/launch/.keep b/dev/launch/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/launch/LaunchKit/.keep b/dev/launch/LaunchKit/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/launch/obj/.keep b/dev/launch/obj/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/launch/src/.keep b/dev/launch/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/libDDK/DriverKit/cpp/object.hpp b/dev/libDDK/DriverKit/cpp/object.hpp new file mode 100644 index 00000000..3bf52657 --- /dev/null +++ b/dev/libDDK/DriverKit/cpp/object.hpp @@ -0,0 +1,16 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss 2025, all rights reserved. + + FILE: ddk.h + PURPOSE: DDK Driver model base header. + + ------------------------------------------- */ + +#pragma once + +#include + +#define DK_INTERFACE_IMPL : public ::DKInterface + +class DKInterface; diff --git a/dev/libDDK/DriverKit/ddk.h b/dev/libDDK/DriverKit/ddk.h index 254137f9..2e2dddf0 100644 --- a/dev/libDDK/DriverKit/ddk.h +++ b/dev/libDDK/DriverKit/ddk.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright Amlal El Mahrouss. + Copyright Amlal El Mahrouss 2025, all rights reserved. FILE: ddk.h PURPOSE: DDK Driver model base header. @@ -29,6 +29,8 @@ struct DDK_STATUS_STRUCT DDK_FINAL { struct DDK_OBJECT_MANIFEST* s_object; }; +typedef void* ptr_t; + /// @brief Call Kernel procedure. /// @param name the procedure name. /// @param cnt number of elements in **dat** diff --git a/dev/libDDK/src/ddk_kernel_call.c b/dev/libDDK/src/ddk_kernel_call.c index 1ac0a0aa..61742b7b 100644 --- a/dev/libDDK/src/ddk_kernel_call.c +++ b/dev/libDDK/src/ddk_kernel_call.c @@ -12,7 +12,7 @@ #include /// @brief this is an internal call, do not use it. -DDK_EXTERN ATTRIBUTE(naked) void* __ke_call_dispatch(const int32_t name, int32_t cnt, void* data, +DDK_EXTERN ATTRIBUTE(naked) ptr_t __ke_call_dispatch(const int32_t name, int32_t cnt, void* data, size_t sz); /// @brief This function hashes the path into a FNV symbol. /// @param path the path to hash. diff --git a/dev/libDDK/src/ddk_kernel_call_dispatch.S b/dev/libDDK/src/ddk_kernel_call_dispatch.S index 7b7a26cb..a607fe40 100644 --- a/dev/libDDK/src/ddk_kernel_call_dispatch.S +++ b/dev/libDDK/src/ddk_kernel_call_dispatch.S @@ -21,10 +21,11 @@ __ke_call_dispatch: push rbp mov rbp, rsp + /* registers have already been pushed. */ + int kKernelCallTrapId pop rbp - ret #elif defined(__DDK_POWER64__) diff --git a/public/frameworks/LaunchHelpers.fwrk/.keep b/public/frameworks/LaunchHelpers.fwrk/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/LaunchHelpers.fwrk/LaunchHelpers.json b/public/frameworks/LaunchHelpers.fwrk/LaunchHelpers.json new file mode 100644 index 00000000..9ec17332 --- /dev/null +++ b/public/frameworks/LaunchHelpers.fwrk/LaunchHelpers.json @@ -0,0 +1,19 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "./", + "../../../dev/kernel", + "../../../public/frameworks/", + "../../../dev/", + "./" + ], + "sources_path": [], + "output_name": "./dist/libLaunchHelpers.fwrk.dylib", + "cpp_macros": [ + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", + "__NE_SDK__" + ] +} \ No newline at end of file diff --git a/public/frameworks/LaunchHelpers.fwrk/dist/.keep b/public/frameworks/LaunchHelpers.fwrk/dist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/LaunchHelpers.fwrk/headers/.keep b/public/frameworks/LaunchHelpers.fwrk/headers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/LaunchHelpers.fwrk/src/.keep b/public/frameworks/LaunchHelpers.fwrk/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/LaunchHelpers.fwrk/src/DylibMain.cc b/public/frameworks/LaunchHelpers.fwrk/src/DylibMain.cc new file mode 100644 index 00000000..99eebd26 --- /dev/null +++ b/public/frameworks/LaunchHelpers.fwrk/src/DylibMain.cc @@ -0,0 +1,5 @@ +#include + +SInt32 _DylibAttach(SInt32 argc, Char* argv[]) { + return EXIT_FAILURE; +} \ No newline at end of file diff --git a/public/frameworks/LaunchHelpers.fwrk/xml/.keep b/public/frameworks/LaunchHelpers.fwrk/xml/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/LaunchHelpers.fwrk/xml/app.xml b/public/frameworks/LaunchHelpers.fwrk/xml/app.xml new file mode 100644 index 00000000..6bc3a3f4 --- /dev/null +++ b/public/frameworks/LaunchHelpers.fwrk/xml/app.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file -- cgit v1.2.3 From 12d192e44e4269b8398021adbf524e0e7c8cf308 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 7 Sep 2025 18:15:07 +0200 Subject: feat: reference OpenKnowledge instead of the old hosted docs. Signed-off-by: Amlal El Mahrouss --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e23d92df..299a4656 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ cd nekernel ## Documentation -- [API Reference (Doxygen)](https://nekernel-org.github.io/doc/) +- [OpenKnowledge](https://docs.nekernel.org/) - [Filesystem Specifications](docs/tex/) --- -- cgit v1.2.3 From d3f87b1b84d355ad72366ced5d7e5a43207226c0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 7 Sep 2025 23:29:48 +0200 Subject: feat: kernel: startup sequence fix, and new mgmt.hefs manual. wip: LaunchKit for the `ne_launch` program. Signed-off-by: Amlal El Mahrouss --- .gitignore | 2 +- dev/boot/amd64-desktop.make | 6 ++-- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 13 ++++----- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 31 ++++++-------------- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 14 +-------- dev/kernel/src/UserProcessScheduler.cc | 2 +- dev/launch/LaunchKit/LaunchKit.h | 9 ++++++ dev/launch/src/LaunchSrv.cc | 15 ++++++++++ dev/libDDK/src/ddk_kernel_call.c | 4 +-- public/manuals/nekernel/mgmt.hefs.util.man | 34 ++++++++++++++++++++++ public/tools/mgmt.launch/.keep | 0 public/tools/mgmt.launch/dist/.keep | 0 public/tools/mgmt.launch/mgmt.launch.json | 19 ++++++++++++ public/tools/mgmt.launch/src/.keep | 0 public/tools/mgmt.launch/src/CommandLine.cc | 5 ++++ public/tools/mgmt.launch/vendor/.keep | 0 16 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 dev/launch/LaunchKit/LaunchKit.h create mode 100644 dev/launch/src/LaunchSrv.cc create mode 100644 public/manuals/nekernel/mgmt.hefs.util.man create mode 100644 public/tools/mgmt.launch/.keep create mode 100644 public/tools/mgmt.launch/dist/.keep create mode 100644 public/tools/mgmt.launch/mgmt.launch.json create mode 100644 public/tools/mgmt.launch/src/.keep create mode 100644 public/tools/mgmt.launch/src/CommandLine.cc create mode 100644 public/tools/mgmt.launch/vendor/.keep diff --git a/.gitignore b/.gitignore index 1058abb8..1144fd7a 100644 --- a/.gitignore +++ b/.gitignore @@ -135,7 +135,7 @@ local.properties .externalToolBuilders/ # Locally stored "Eclipse launch configurations" -*.launch +# *.launch # PyDev specific (Python IDE for Eclipse) *.pydevproject diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 443e5677..d8c3fd86 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -117,15 +117,15 @@ compile-amd64: .PHONY: run-efi-amd64-ahci run-efi-amd64-ahci: - $(EMU) $(EMU_FLAGS) -monitor stdio -hda $(IMG) -s -S -boot menu=on + $(EMU) $(EMU_FLAGS) -monitor stdio -hda $(IMG) -s -boot menu=on .PHONY: run-efi-amd64-ata-pio run-efi-amd64-ata-pio: - $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -d int -boot menu=on + $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -d int -boot menu=on .PHONY: run-efi-amd64-ata-dma run-efi-amd64-ata-dma: - $(EMU) $(EMU_FLAGS) -device piix4-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -boot menu=on + $(EMU) $(EMU_FLAGS) -device piix4-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -boot menu=on .PHONY: run-efi-amd64-ata run-efi-amd64-ata: run-efi-amd64-ata-pio diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index df5386e4..e3e08830 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -88,7 +88,7 @@ struct LAPIC final { /// @param target /// @return /***********************************************************************************/ -Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) { +EXTERN_C Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) { Kernel::ke_dma_write(target, APIC_ICR_HIGH, apic_id << 24); Kernel::ke_dma_write(target, APIC_ICR_LOW, 0x00000600 | 0x00004000 | 0x00000000 | vector); @@ -200,10 +200,7 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { UInt8 type = *entry_ptr; UInt8 length = *(entry_ptr + 1); - // Avoid infinite loop on bad APIC tables. - if (length < 2) break; - - if (type == 0) { + if (type == 0 && length == sizeof(struct LAPIC)) { volatile LAPIC* entry_struct = (volatile LAPIC*) entry_ptr; if (entry_struct->Flags & 0x1) { @@ -212,15 +209,15 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { ++kSMPCount; - kout << "Kind: LAPIC: ON\r"; + kout << "AP: kind: LAPIC: ON.\r"; // 0x7c00, as recommended by the Intel SDM. hal_send_ipi_msg(kApicBaseAddress, entry_struct->ProcessorID, 0x7c); } else { - kout << "Kind: LAPIC: OFF\r"; + kout << "AP: kind: LAPIC: OFF.\r"; } } else { - kout << "Kind: UNKNOWN: OFF\r"; + kout << "AP: kind: UNKNOWN: OFF.\r"; } entry_ptr += length; diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index cb5d4af8..95214353 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -32,8 +32,6 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { HAL::rt_sti(); - kHandoverHeader = handover_hdr; - FB::fb_clear_video(); fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); @@ -41,8 +39,9 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey, handover_hdr->f_HardwareTables.f_ImageHandle); - kBitMapCursor = 0UL; - kKernelVM = kHandoverHeader->f_PageStart; + kHandoverHeader = handover_hdr; + + kKernelVM = kHandoverHeader->f_PageStart; if (!kKernelVM) { MUST_PASS(kKernelVM); @@ -55,6 +54,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { /* INITIALIZE BIT MAP. */ /************************************** */ + kBitMapCursor = 0UL; kKernelBitMpSize = kHandoverHeader->f_BitMapSize; kKernelBitMpStart = reinterpret_cast(reinterpret_cast(kHandoverHeader->f_BitMapStart)); @@ -133,20 +133,14 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { return kEfiFail; } -EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { +EXTERN_C Kernel::Void hal_real_init(Kernel::Void) { using namespace Kernel; - for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { - HardwareThreadScheduler::The()[index].Leak()->Kind() = ThreadKind::kAPStandard; - HardwareThreadScheduler::The()[index].Leak()->ID() = index; - HardwareThreadScheduler::The()[index].Leak()->Busy(NO); - } + HAL::Register64 idt_reg; + idt_reg.Base = reinterpret_cast(kInterruptVectorTable); - for (SizeT index = 0UL; index < UserProcessScheduler::The().TheCurrentTeam().AsArray().Count(); - ++index) { - UserProcessScheduler::The().TheCurrentTeam().AsArray()[index].Status = - ProcessStatusKind::kInvalid; - } + HAL::IDTLoader idt_loader; + idt_loader.Load(idt_reg); HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); @@ -158,13 +152,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { NeFS::fs_init_nefs(); #endif - HAL::Register64 idt_reg; - idt_reg.Base = reinterpret_cast(kInterruptVectorTable); - - HAL::IDTLoader idt_loader; - - idt_loader.Load(idt_reg); - while (YES) ; } diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 096df49e..29541d48 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -37,8 +37,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { FB::fb_clear_video(); - kBitMapCursor = 0UL; - #ifdef __NE_ARM64_EFI__ fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); @@ -50,23 +48,13 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { /* INITIALIZE BIT MAP. */ /************************************** */ + kBitMapCursor = 0UL; kKernelBitMpSize = kHandoverHeader->f_BitMapSize; kKernelBitMpStart = reinterpret_cast( reinterpret_cast(kHandoverHeader->f_BitMapStart)); /// @note do initialize the interrupts after it. - for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { - HardwareThreadScheduler::The()[index].Leak()->Kind() = ThreadKind::kAPStandard; - HardwareThreadScheduler::The()[index].Leak()->Busy(NO); - } - - for (SizeT index = 0UL; index < UserProcessScheduler::The().TheCurrentTeam().AsArray().Count(); - ++index) { - UserProcessScheduler::The().TheCurrentTeam().AsArray()[index].Status = - ProcessStatusKind::kInvalid; - } - Kernel::mp_init_cores(); while (YES) diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 174862a4..07c4a572 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -438,7 +438,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im } (Void)(kout << "ProcessID: " << number(process.ProcessId) << kendl); - (Void)(kout << "Name: " << process.Name << kendl); + (Void)(kout << "ProcesName: " << process.Name << kendl); return pid; } diff --git a/dev/launch/LaunchKit/LaunchKit.h b/dev/launch/LaunchKit/LaunchKit.h new file mode 100644 index 00000000..95d91e09 --- /dev/null +++ b/dev/launch/LaunchKit/LaunchKit.h @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + ------------------------------------------- */ + +#pragma once + +#include diff --git a/dev/launch/src/LaunchSrv.cc b/dev/launch/src/LaunchSrv.cc new file mode 100644 index 00000000..8c302c6d --- /dev/null +++ b/dev/launch/src/LaunchSrv.cc @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + ------------------------------------------- */ + +#include + +SInt32 _NeMain(Void) { + PrintOut(nullptr, "%s", "NeKernel Launcher\n"); + + /// @todo Start LaunchServices.fwrk, make the launcher manageable too (via mgmt.launch) + + return kErrorSuccess; +} diff --git a/dev/libDDK/src/ddk_kernel_call.c b/dev/libDDK/src/ddk_kernel_call.c index 61742b7b..5976665b 100644 --- a/dev/libDDK/src/ddk_kernel_call.c +++ b/dev/libDDK/src/ddk_kernel_call.c @@ -12,8 +12,8 @@ #include /// @brief this is an internal call, do not use it. -DDK_EXTERN ATTRIBUTE(naked) ptr_t __ke_call_dispatch(const int32_t name, int32_t cnt, void* data, - size_t sz); +DDK_EXTERN ATTRIBUTE(naked) ptr_t + __ke_call_dispatch(const int32_t name, int32_t cnt, void* data, size_t sz); /// @brief This function hashes the path into a FNV symbol. /// @param path the path to hash. /// @retval 0 symbol wasn't hashed. diff --git a/public/manuals/nekernel/mgmt.hefs.util.man b/public/manuals/nekernel/mgmt.hefs.util.man new file mode 100644 index 00000000..3274f93a --- /dev/null +++ b/public/manuals/nekernel/mgmt.hefs.util.man @@ -0,0 +1,34 @@ +NAME + mgmt.hefs — HeFS Management utility command + +SYNOPSIS + mgmt.hefs [OPTIONS] + +DESCRIPTION + The `mgmt.hefs` command provides scheduling, execution, and remote orchestration + of a HeFS volume inside a System One environement. One might use this tool to + create, edit, and remove volumes from a disk. + + Usages include, but are not limited to: + - Schedule scripts or tasks for future execution. + - Verify device or filesystem integrity. + - Manage and automate remote NeKernel machines. + +OPTIONS + -v, --volume Device input + -c, --create Create HeFS volume + -x, --xml Pass PropertyList to volume creation tool. + -t, --time Time to run the script + -d, --day Day of the week (e.g., Mon, Tue, Wed) + -m, --month Month (e.g., Jan, Feb, Mar) + -y, --year Year to schedule task + -r, --remote
Remote machine to manage (optional) + -v, --verify Run integrity checks only + -h, --help Display this help message + +EXAMPLES + mgmt.hefs -v /devices/disks0p0 -t 2:30PM -d Wed -m Apr -y 2026 --xml /xml/hefs.pxml + Schedules `/xml/hefs.pxml` to run at 2:30PM on Wednesday, April 2026. + +RELEASE + v1.0.0 — NeKernel.org diff --git a/public/tools/mgmt.launch/.keep b/public/tools/mgmt.launch/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.launch/dist/.keep b/public/tools/mgmt.launch/dist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.launch/mgmt.launch.json b/public/tools/mgmt.launch/mgmt.launch.json new file mode 100644 index 00000000..a181d745 --- /dev/null +++ b/public/tools/mgmt.launch/mgmt.launch.json @@ -0,0 +1,19 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "./", + "../../../dev/kernel", + "../../../public/frameworks/", + "../../../dev/", + "./" + ], + "sources_path": [], + "output_name": "./dist/mgmt.launch", + "cpp_macros": [ + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", + "__NE_SDK__" + ] +} \ No newline at end of file diff --git a/public/tools/mgmt.launch/src/.keep b/public/tools/mgmt.launch/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.launch/src/CommandLine.cc b/public/tools/mgmt.launch/src/CommandLine.cc new file mode 100644 index 00000000..6015988e --- /dev/null +++ b/public/tools/mgmt.launch/src/CommandLine.cc @@ -0,0 +1,5 @@ +#include + +SInt32 _NeMain(SInt32 argc, Char* argv[]) { + return EXIT_FAILURE; +} \ No newline at end of file diff --git a/public/tools/mgmt.launch/vendor/.keep b/public/tools/mgmt.launch/vendor/.keep new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From e55f246042a12955200e20abe406b26ab02b94fa Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Sep 2025 11:38:39 +0200 Subject: feat: launch: Working on LaunchKit's implementation. Signed-off-by: Amlal El Mahrouss --- .gitignore | 3 +++ dev/launch/LaunchKit/LaunchKit.h | 9 +++++++++ dev/launch/ne_launch.json | 20 ++++++++++++++++++++ dev/launch/src/LaunchSrv.cc | 5 +++-- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 dev/launch/ne_launch.json diff --git a/.gitignore b/.gitignore index 1144fd7a..329688e2 100644 --- a/.gitignore +++ b/.gitignore @@ -137,6 +137,9 @@ local.properties # Locally stored "Eclipse launch configurations" # *.launch +# NeKernel Launch +ne_launch + # PyDev specific (Python IDE for Eclipse) *.pydevproject diff --git a/dev/launch/LaunchKit/LaunchKit.h b/dev/launch/LaunchKit/LaunchKit.h index 95d91e09..1a134e8f 100644 --- a/dev/launch/LaunchKit/LaunchKit.h +++ b/dev/launch/LaunchKit/LaunchKit.h @@ -7,3 +7,12 @@ #pragma once #include + +/// @author Amlal El Mahrouss +/// @brief NeKernel Launch Kit. + +#define NELAUNCH_INFO(MSG) PrintOut(nullptr, "INFO: [LAUNCH] %s\n", MSG) +#define NELAUNCH_WARN(MSG) PrintOut(nullptr, "WARN: [LAUNCH] %s\n", MSG) + +using LaunchHandle = VoidPtr; +using KernelStatus = SInt32; diff --git a/dev/launch/ne_launch.json b/dev/launch/ne_launch.json new file mode 100644 index 00000000..38379de9 --- /dev/null +++ b/dev/launch/ne_launch.json @@ -0,0 +1,20 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "./"], + "sources_path": ["src/*.cc"], + "output_name": "ne_launch", + "compiler_flags": [ + "-ffreestanding", + "-shared", + "-fPIC", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17" + ], + "cpp_macros": [ + "kNeLaunchVersion=0x0100", + "kNeLaunchVersionHighest=0x0100", + "kNeLaunchVersionLowest=0x0100" + ] +} diff --git a/dev/launch/src/LaunchSrv.cc b/dev/launch/src/LaunchSrv.cc index 8c302c6d..40027f65 100644 --- a/dev/launch/src/LaunchSrv.cc +++ b/dev/launch/src/LaunchSrv.cc @@ -5,11 +5,12 @@ ------------------------------------------- */ #include +#include SInt32 _NeMain(Void) { - PrintOut(nullptr, "%s", "NeKernel Launcher\n"); + /// @todo Start LaunchServices.fwrk services, make the launcher manageable too (via mgmt.launch) - /// @todo Start LaunchServices.fwrk, make the launcher manageable too (via mgmt.launch) + NELAUNCH_INFO("Starting services..."); return kErrorSuccess; } -- cgit v1.2.3 From 42832ec1b72baf244a1290ccf747b79db0caa69f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Sep 2025 13:44:33 +0200 Subject: fix: hal: clear video memory once handoff is done. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 4 ++-- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 95214353..16670f5c 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -32,8 +32,6 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { HAL::rt_sti(); - FB::fb_clear_video(); - fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey, @@ -120,6 +118,8 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { kGDTArray[4].fFlags = 0; kGDTArray[4].fBaseHigh = 0; + FB::fb_clear_video(); + // Load memory descriptors. HAL::Register64 gdt_reg; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 29541d48..240b3ac8 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -35,8 +35,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { return; } - FB::fb_clear_video(); - #ifdef __NE_ARM64_EFI__ fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); @@ -44,6 +42,8 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { handover_hdr->f_HardwareTables.f_ImageHandle); #endif + FB::fb_clear_video(); + /************************************** */ /* INITIALIZE BIT MAP. */ /************************************** */ -- cgit v1.2.3 From b1e3dac861c0d6c28bdb7768d7f96f19456e9ad0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Sep 2025 21:28:04 +0200 Subject: feat:! ddk/dki, ne_launch, ifs: Big architectural changes and improvements. Signed-off-by: Amlal El Mahrouss --- dev/kernel/FSKit/Ext2+IFS.h | 140 +++++++++++++++++++++++++++++ dev/kernel/FSKit/Ext2IFS.h | 135 ---------------------------- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 2 +- dev/kernel/src/FS/Ext2+FileSystemParser.cc | 2 +- dev/launch/LaunchKit/LaunchKit.h | 2 + dev/launch/ne_launch.json | 2 +- dev/launch/src/CRT0.S | 17 ++++ dev/launch/src/LaunchSrv.cc | 5 +- dev/libDDK/DriverKit/cpp/object.hpp | 16 ---- dev/libDDK/DriverKit/dki/contract.h | 32 +++++++ dev/libSystem/src/System.cc | 15 +++- 12 files changed, 210 insertions(+), 160 deletions(-) create mode 100644 dev/kernel/FSKit/Ext2+IFS.h delete mode 100644 dev/kernel/FSKit/Ext2IFS.h create mode 100644 dev/launch/src/CRT0.S delete mode 100644 dev/libDDK/DriverKit/cpp/object.hpp create mode 100644 dev/libDDK/DriverKit/dki/contract.h diff --git a/dev/kernel/FSKit/Ext2+IFS.h b/dev/kernel/FSKit/Ext2+IFS.h new file mode 100644 index 00000000..d73ae43c --- /dev/null +++ b/dev/kernel/FSKit/Ext2+IFS.h @@ -0,0 +1,140 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace Kernel::Ext2 { +/// @brief Context for an EXT2 filesystem on a given drive +struct Ext2Context { + Kernel::DriveTrait* drive{nullptr}; + EXT2_SUPER_BLOCK* superblock{nullptr}; + + /// @brief context with a drive + Ext2Context(Kernel::DriveTrait* drv) : drive(drv) {} + + /// @brief Clean up + ~Ext2Context() { + if (superblock) { + Kernel::mm_free_ptr(superblock); + superblock = nullptr; + } + } + + Ext2Context(const Ext2Context&) = delete; + Ext2Context& operator=(const Ext2Context&) = delete; + + Ext2Context(Ext2Context&& other) noexcept : drive(other.drive), superblock(other.superblock) { + other.drive = nullptr; + other.superblock = nullptr; + } + + Ext2Context& operator=(Ext2Context&& other) noexcept { + if (this != &other) { + if (superblock) { + Kernel::mm_free_ptr(superblock); + } + drive = other.drive; + superblock = other.superblock; + other.drive = nullptr; + other.superblock = nullptr; + } + return *this; + } + + Kernel::SizeT LeakBlockSize() const { + if (!superblock) return kExt2FSBlockSizeBase; + return kExt2FSBlockSizeBase << superblock->fLogBlockSize; + } + + BOOL operator bool() { return superblock != nullptr; } +}; + +/// ======================================================================= /// +/// IFS FUNCTIONS +/// ======================================================================= /// + +inline bool ext2_read_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, void* buffer, + Kernel::UInt32 size) { + if (!drv || !buffer) return false; + + Kernel::DriveTrait::DrivePacket pkt{}; + pkt.fPacketContent = buffer; + pkt.fPacketSize = size; + pkt.fPacketLba = lba; + drv->fInput(pkt); + + return pkt.fPacketGood; +} + +inline bool ext2_write_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, const void* buffer, + Kernel::UInt32 size) { + if (!drv || !buffer) return false; + + Kernel::DriveTrait::DrivePacket pkt{}; + pkt.fPacketContent = const_cast(buffer); + pkt.fPacketSize = size; + pkt.fPacketLba = lba; + drv->fOutput(pkt); + return pkt.fPacketGood; +} + +inline Kernel::ErrorOr ext2_load_superblock(Ext2Context* ctx) { + if (!ctx || !ctx->drive) return Kernel::ErrorOr(Kernel::kErrorInvalidData); + + auto buf = Kernel::mm_alloc_ptr(sizeof(EXT2_SUPER_BLOCK), true, false); + if (!buf) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); + + Kernel::UInt32 blockLba = kExt2FSSuperblockOffset / ctx->drive->fSectorSz; + + if (!ext2_read_block(ctx->drive, blockLba, buf, sizeof(EXT2_SUPER_BLOCK))) { + Kernel::mm_free_ptr(buf); + return Kernel::ErrorOr(Kernel::kErrorDisk); + } + + auto sb = reinterpret_cast(buf); + if (sb->fMagic != kExt2FSMagic) { + Kernel::mm_free_ptr(buf); + return Kernel::ErrorOr(Kernel::kErrorInvalidData); + } + + ctx->superblock = sb; + return Kernel::ErrorOr(sb); +} + +// Load inode +inline Kernel::ErrorOr ext2_load_inode(Ext2Context* ctx, Kernel::UInt32 inodeNumber) { + if (!ctx || !ctx->superblock) return Kernel::ErrorOr(Kernel::kErrorInvalidData); + + auto nodePtr = Kernel::mm_alloc_ptr(sizeof(Ext2Node), true, false); + if (!nodePtr) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); + + auto ext2Node = reinterpret_cast(nodePtr); + ext2Node->inodeNumber = inodeNumber; + + // Compute block group and index within group + Kernel::UInt32 inodesPerGroup = ctx->superblock->fInodesPerGroup; + Kernel::UInt32 group = (inodeNumber - 1) / inodesPerGroup; + Kernel::UInt32 index = (inodeNumber - 1) % inodesPerGroup; + + // dummy: just offset first inode + Kernel::UInt32 inodeTableBlock = ctx->superblock->fFirstInode + group; + + if (!ext2_read_block(ctx->drive, inodeTableBlock, &ext2Node->inode, sizeof(EXT2_INODE))) { + Kernel::mm_free_ptr(nodePtr); + return Kernel::ErrorOr(Kernel::kErrorDisk); + } + + ext2Node->cursor = 0; + return Kernel::ErrorOr(ext2Node); +} + +inline Kernel::UInt32 inode_offset(const Ext2Context* ctx, Kernel::UInt32 inodeNumber) { + if (!ctx || !ctx->superblock) return 0; + return ((inodeNumber - 1) % ctx->superblock->fInodesPerGroup) * ctx->superblock->fInodeSize; +} +} // namespace Kernel::Ext2 diff --git a/dev/kernel/FSKit/Ext2IFS.h b/dev/kernel/FSKit/Ext2IFS.h deleted file mode 100644 index 2550cfea..00000000 --- a/dev/kernel/FSKit/Ext2IFS.h +++ /dev/null @@ -1,135 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace Ext2 { - -/// @brief Context for an EXT2 filesystem on a given drive -struct Context { - Kernel::DriveTrait* drive{nullptr}; - EXT2_SUPER_BLOCK* superblock{nullptr}; - - /// @brief context with a drive - explicit Context(Kernel::DriveTrait* drv) : drive(drv) {} - - /// @brief Clean up - ~Context() { - if (superblock) { - Kernel::mm_free_ptr(superblock); - superblock = nullptr; - } - } - - Context(const Context&) = delete; - Context& operator=(const Context&) = delete; - - Context(Context&& other) noexcept : drive(other.drive), superblock(other.superblock) { - other.drive = nullptr; - other.superblock = nullptr; - } - - Context& operator=(Context&& other) noexcept { - if (this != &other) { - if (superblock) { - Kernel::mm_free_ptr(superblock); - } - drive = other.drive; - superblock = other.superblock; - other.drive = nullptr; - other.superblock = nullptr; - } - return *this; - } - - inline Kernel::UInt32 BlockSize() const { - if (!superblock) return kExt2FSBlockSizeBase; - return kExt2FSBlockSizeBase << superblock->fLogBlockSize; - } -}; - -inline bool ext2_read_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, void* buffer, - Kernel::UInt32 size) { - if (!drv || !buffer) return false; - - Kernel::DriveTrait::DrivePacket pkt{}; - pkt.fPacketContent = buffer; - pkt.fPacketSize = size; - pkt.fPacketLba = lba; - drv->fInput(pkt); - return pkt.fPacketGood; -} - -inline bool ext2_write_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, const void* buffer, - Kernel::UInt32 size) { - if (!drv || !buffer) return false; - - Kernel::DriveTrait::DrivePacket pkt{}; - pkt.fPacketContent = const_cast(buffer); - pkt.fPacketSize = size; - pkt.fPacketLba = lba; - drv->fOutput(pkt); - return pkt.fPacketGood; -} - -// Load superblock -inline Kernel::ErrorOr ext2_load_superblock(Context* ctx) { - if (!ctx || !ctx->drive) return Kernel::ErrorOr(Kernel::kErrorInvalidData); - - auto buf = Kernel::mm_alloc_ptr(sizeof(EXT2_SUPER_BLOCK), true, false); - if (!buf) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); - - Kernel::UInt32 blockLba = kExt2FSSuperblockOffset / ctx->drive->fSectorSz; - if (!ext2_read_block(ctx->drive, blockLba, buf, sizeof(EXT2_SUPER_BLOCK))) { - Kernel::mm_free_ptr(buf); - return Kernel::ErrorOr(Kernel::kErrorDisk); - } - - auto sb = reinterpret_cast(buf); - if (sb->fMagic != kExt2FSMagic) { - Kernel::mm_free_ptr(buf); - return Kernel::ErrorOr(Kernel::kErrorInvalidData); - } - - ctx->superblock = sb; - return Kernel::ErrorOr(sb); -} - -// Load inode -inline Kernel::ErrorOr ext2_load_inode(Context* ctx, Kernel::UInt32 inodeNumber) { - if (!ctx || !ctx->superblock) return Kernel::ErrorOr(Kernel::kErrorInvalidData); - - auto nodePtr = Kernel::mm_alloc_ptr(sizeof(Ext2Node), true, false); - if (!nodePtr) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); - - auto ext2Node = reinterpret_cast(nodePtr); - ext2Node->inodeNumber = inodeNumber; - - // Compute block group and index within group - Kernel::UInt32 inodesPerGroup = ctx->superblock->fInodesPerGroup; - Kernel::UInt32 group = (inodeNumber - 1) / inodesPerGroup; - Kernel::UInt32 index = (inodeNumber - 1) % inodesPerGroup; - - // dummy: just offset first inode - Kernel::UInt32 inodeTableBlock = ctx->superblock->fFirstInode + group; - - if (!ext2_read_block(ctx->drive, inodeTableBlock, &ext2Node->inode, sizeof(EXT2_INODE))) { - Kernel::mm_free_ptr(nodePtr); - return Kernel::ErrorOr(Kernel::kErrorDisk); - } - - ext2Node->cursor = 0; - return Kernel::ErrorOr(ext2Node); -} - -inline Kernel::UInt32 inode_offset(const Context* ctx, Kernel::UInt32 inodeNumber) { - if (!ctx || !ctx->superblock) return 0; - return ((inodeNumber - 1) % ctx->superblock->fInodesPerGroup) * ctx->superblock->fInodeSize; -} - -} // namespace Ext2 diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 16670f5c..6f4d7e0a 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -119,7 +119,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { kGDTArray[4].fBaseHigh = 0; FB::fb_clear_video(); - + // Load memory descriptors. HAL::Register64 gdt_reg; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 240b3ac8..b711b833 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -48,7 +48,7 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { /* INITIALIZE BIT MAP. */ /************************************** */ - kBitMapCursor = 0UL; + kBitMapCursor = 0UL; kKernelBitMpSize = kHandoverHeader->f_BitMapSize; kKernelBitMpStart = reinterpret_cast( reinterpret_cast(kHandoverHeader->f_BitMapStart)); diff --git a/dev/kernel/src/FS/Ext2+FileSystemParser.cc b/dev/kernel/src/FS/Ext2+FileSystemParser.cc index 80449ed9..318f83d6 100644 --- a/dev/kernel/src/FS/Ext2+FileSystemParser.cc +++ b/dev/kernel/src/FS/Ext2+FileSystemParser.cc @@ -6,7 +6,7 @@ #ifdef __FSKIT_INCLUDES_EXT2__ -#include +#include #include #include #include diff --git a/dev/launch/LaunchKit/LaunchKit.h b/dev/launch/LaunchKit/LaunchKit.h index 1a134e8f..2fa9607b 100644 --- a/dev/launch/LaunchKit/LaunchKit.h +++ b/dev/launch/LaunchKit/LaunchKit.h @@ -14,5 +14,7 @@ #define NELAUNCH_INFO(MSG) PrintOut(nullptr, "INFO: [LAUNCH] %s\n", MSG) #define NELAUNCH_WARN(MSG) PrintOut(nullptr, "WARN: [LAUNCH] %s\n", MSG) +namespace Launch { using LaunchHandle = VoidPtr; using KernelStatus = SInt32; +} // namespace Launch diff --git a/dev/launch/ne_launch.json b/dev/launch/ne_launch.json index 38379de9..e3d26a46 100644 --- a/dev/launch/ne_launch.json +++ b/dev/launch/ne_launch.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "./"], - "sources_path": ["src/*.cc"], + "sources_path": ["src/*.cc", "src/*.S"], "output_name": "ne_launch", "compiler_flags": [ "-ffreestanding", diff --git a/dev/launch/src/CRT0.S b/dev/launch/src/CRT0.S new file mode 100644 index 00000000..ffc7398a --- /dev/null +++ b/dev/launch/src/CRT0.S @@ -0,0 +1,17 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + ------------------------------------------- */ + + .text + +.extern nelaunch_startup_fn + +_NeMain: + push %rbp + movq %rsp, %rbp + callq nelaunch_startup_fn + popq %rbp + + retq diff --git a/dev/launch/src/LaunchSrv.cc b/dev/launch/src/LaunchSrv.cc index 40027f65..f5c9ee3c 100644 --- a/dev/launch/src/LaunchSrv.cc +++ b/dev/launch/src/LaunchSrv.cc @@ -7,10 +7,11 @@ #include #include -SInt32 _NeMain(Void) { +/// @note This called by _NeMain from its own runtime. +extern "C" SInt32 nelaunch_startup_fn(Void) { /// @todo Start LaunchServices.fwrk services, make the launcher manageable too (via mgmt.launch) - NELAUNCH_INFO("Starting services..."); + NELAUNCH_INFO("Starting NeKernel services..."); return kErrorSuccess; } diff --git a/dev/libDDK/DriverKit/cpp/object.hpp b/dev/libDDK/DriverKit/cpp/object.hpp deleted file mode 100644 index 3bf52657..00000000 --- a/dev/libDDK/DriverKit/cpp/object.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss 2025, all rights reserved. - - FILE: ddk.h - PURPOSE: DDK Driver model base header. - - ------------------------------------------- */ - -#pragma once - -#include - -#define DK_INTERFACE_IMPL : public ::DKInterface - -class DKInterface; diff --git a/dev/libDDK/DriverKit/dki/contract.h b/dev/libDDK/DriverKit/dki/contract.h new file mode 100644 index 00000000..23884e02 --- /dev/null +++ b/dev/libDDK/DriverKit/dki/contract.h @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss 2025, all rights reserved. + + FILE: ddk.h + PURPOSE: Driver Kernel Interface Model base header. + + ------------------------------------------- */ + +#pragma once + +#include +#include + +#define DKI_CONTRACT_IMPL : public ::Kernel::DKIContract + +/// @author Amlal El Mahrouss + +namespace Kernel::DKI { +class DKIContract { + public: + explicit DKIContract() = default; + virtual ~DKIContract() = default; + + NE_COPY_DEFAULT(DKIContract); + + virtual BOOL IsCastable() { return false; } + virtual BOOL IsActive() { return false; } + virtual VoidPtr Leak() { return nullptr; } + virtual Int32 Type() { return 0; } +}; +} // namespace Kernel::DKI diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc index ba848a18..2215c4d8 100644 --- a/dev/libSystem/src/System.cc +++ b/dev/libSystem/src/System.cc @@ -40,6 +40,12 @@ IMPORT_C UInt64 libsys_hash_64(const Char* path) { return hash; } +IMPORT_C Char* StrFmt(const Char* fmt, ...) { + if (!fmt || *fmt == 0) return const_cast("(null)"); + + return const_cast(""); +} + // memmove-style copy IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { // handles overlap, prefers 64-bit word copies when aligned @@ -58,8 +64,9 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si // try 64-bit aligned backward copy if (len >= sizeof(UInt64) && (reinterpret_cast(rs) % sizeof(UInt64) == 0) && (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { - auto rsw = reinterpret_cast(rs); - auto rdw = reinterpret_cast(rd); + auto rsw = reinterpret_cast(rs); + auto rdw = reinterpret_cast(rd); + SizeT words = len / sizeof(UInt64); for (SizeT i = 0; i < words; ++i) { @@ -105,9 +112,11 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si IMPORT_C SInt64 MmStrLen(const Char* in) { // strlen via pointer walk - if (!in) return 0; + if (!in) return -kErrorInvalidData; + const Char* p = in; while (*p) ++p; + return static_cast(p - in); } -- cgit v1.2.3 From 4c5a70e4790698efe57bfdf75866f0236102582d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Sep 2025 21:29:59 +0200 Subject: fix: launch/crt0: export _NeMain to avoid linking issues. Signed-off-by: Amlal El Mahrouss --- dev/launch/src/CRT0.S | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/launch/src/CRT0.S b/dev/launch/src/CRT0.S index ffc7398a..dffbf9c9 100644 --- a/dev/launch/src/CRT0.S +++ b/dev/launch/src/CRT0.S @@ -7,7 +7,8 @@ .text .extern nelaunch_startup_fn - +.globl _NeMain + _NeMain: push %rbp movq %rsp, %rbp -- cgit v1.2.3 From 495ad933c9d0beb8b02b2ad849d429f0d7583a77 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 10 Sep 2025 11:40:27 +0200 Subject: meta: ran format command. Signed-off-by: Amlal El Mahrouss --- dev/launch/src/CRT0.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/launch/src/CRT0.S b/dev/launch/src/CRT0.S index dffbf9c9..84a293e6 100644 --- a/dev/launch/src/CRT0.S +++ b/dev/launch/src/CRT0.S @@ -8,7 +8,7 @@ .extern nelaunch_startup_fn .globl _NeMain - + _NeMain: push %rbp movq %rsp, %rbp -- cgit v1.2.3 From 2315f84184a0bd03580ba25a59c3832e12bffbc8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 10 Sep 2025 18:25:14 +0200 Subject: feat: kernel: abi: __cxa_guard inside CxxABI (AMD64) Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/CxxAbi.cc | 15 ++++++++------- dev/kernel/NeKit/CxxAbi.h | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dev/kernel/HALKit/AMD64/CxxAbi.cc b/dev/kernel/HALKit/AMD64/CxxAbi.cc index cd135abc..9dc87545 100644 --- a/dev/kernel/HALKit/AMD64/CxxAbi.cc +++ b/dev/kernel/HALKit/AMD64/CxxAbi.cc @@ -62,17 +62,18 @@ EXTERN_C void __cxa_finalize(void* f) { } namespace cxxabiv1 { -EXTERN_C int __cxa_guard_acquire(__guard* g) { - (void) g; +EXTERN_C int __cxa_guard_acquire(__guard g) { + if ((*g & 1) || (*g && 2)) return 1; + *g |= 2; return 0; } -EXTERN_C int __cxa_guard_release(__guard* g) { - *(char*) g = 1; - return 0; +EXTERN_C void __cxa_guard_release(__guard g) { + *g |= 1; + *g &= 2; } -EXTERN_C void __cxa_guard_abort(__guard* g) { - (void) g; +EXTERN_C void __cxa_guard_abort(__guard g) { + *g &= ~2; } } // namespace cxxabiv1 diff --git a/dev/kernel/NeKit/CxxAbi.h b/dev/kernel/NeKit/CxxAbi.h index 164a257d..5abdf76a 100644 --- a/dev/kernel/NeKit/CxxAbi.h +++ b/dev/kernel/NeKit/CxxAbi.h @@ -17,10 +17,10 @@ struct atexit_func_entry_t { void* dso_handle; }; -typedef unsigned uarch_t; +typedef Kernel::UInt32 uarch_t; namespace cxxabiv1 { -typedef void* __guard; + typedef Kernel::SizeT* __guard; } #endif // __GNUC__ -- cgit v1.2.3 From 2b61ca81b887a9ecc5ec38cc1150854f897070df Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 10 Sep 2025 18:35:31 +0200 Subject: fix: __cxa_guard_acquire: fix to `&` not `&&` Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/CxxAbi.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/kernel/HALKit/AMD64/CxxAbi.cc b/dev/kernel/HALKit/AMD64/CxxAbi.cc index 9dc87545..84a00449 100644 --- a/dev/kernel/HALKit/AMD64/CxxAbi.cc +++ b/dev/kernel/HALKit/AMD64/CxxAbi.cc @@ -63,7 +63,7 @@ EXTERN_C void __cxa_finalize(void* f) { namespace cxxabiv1 { EXTERN_C int __cxa_guard_acquire(__guard g) { - if ((*g & 1) || (*g && 2)) return 1; + if ((*g & 1) || (*g & 2)) return 1; *g |= 2; return 0; } -- cgit v1.2.3 From c9f97e7ac1178bd7fba5b0ccd59aa1256900f4c2 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 11 Sep 2025 17:51:50 +0200 Subject: feat: libSystem: `Verify.h` include file, used to verify SCI's input and data. Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/CxxAbi.h | 2 +- dev/libSystem/SystemKit/Verify.h | 40 ++++++++++++++++++++++++++++++++++++++++ dev/libSystem/src/System.cc | 16 +++++----------- 3 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 dev/libSystem/SystemKit/Verify.h diff --git a/dev/kernel/NeKit/CxxAbi.h b/dev/kernel/NeKit/CxxAbi.h index 5abdf76a..839308cf 100644 --- a/dev/kernel/NeKit/CxxAbi.h +++ b/dev/kernel/NeKit/CxxAbi.h @@ -20,7 +20,7 @@ struct atexit_func_entry_t { typedef Kernel::UInt32 uarch_t; namespace cxxabiv1 { - typedef Kernel::SizeT* __guard; +typedef Kernel::SizeT* __guard; } #endif // __GNUC__ diff --git a/dev/libSystem/SystemKit/Verify.h b/dev/libSystem/SystemKit/Verify.h new file mode 100644 index 00000000..68e75d47 --- /dev/null +++ b/dev/libSystem/SystemKit/Verify.h @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + File: Verify.h + Purpose: System Call Interface Verification Layer. + + ------------------------------------------- */ + +#pragma once + +#include + +namespace LibSystem::Detail { +/// @author 0xf00sec, and Amlal El Mahrouss +/// @brief safe cast operator. +template +static R sys_safe_cast(const T* ptr) { + _rtl_assert(ptr, "safe cast failed!"); + return static_cast(const_cast(ptr)); +} + +template +struct must_cast_traits { + constexpr static BOOL value = false; +}; + +template +struct must_cast_traits { + constexpr static BOOL value = true; +}; + +/// @author Amlal El Mahrouss +/// @brief Safe constexpr cast. +template +constexpr R* sys_constexpr_cast(T* ptr) { + static_assert(must_cast_traits::value, "constexpr cast failed! types are a mismatch!"); + return static_cast(ptr); +} +} // namespace LibSystem::Detail diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc index 2215c4d8..da9931fe 100644 --- a/dev/libSystem/src/System.cc +++ b/dev/libSystem/src/System.cc @@ -7,14 +7,9 @@ #include #include #include +#include -namespace Detail { -template -static VoidPtr safe_void_cast(const T* ptr) { - _rtl_assert(ptr, "safe void cast failed!"); - return static_cast(const_cast(ptr)); -} -} // namespace Detail +using namespace LibSystem; IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { if (!expr) { @@ -151,9 +146,8 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt } IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return static_cast(libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"), - Detail::safe_void_cast(path), - Detail::safe_void_cast(drv_letter))); + return static_cast(libsys_syscall_arg_3( + SYSCALL_HASH("IoOpenFile"), Detail::sys_safe_cast(path), Detail::sys_safe_cast(drv_letter))); } IMPORT_C Void IoCloseFile(_Input Ref desc) { @@ -189,7 +183,7 @@ IMPORT_C SInt32 PrintOut(_Input IORef desc, const Char* fmt, ...) { // if truncated, `needed` >= kBufferSz; we still send truncated buffer auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintOut"), static_cast(desc), - Detail::safe_void_cast(buf)); + Detail::sys_safe_cast(buf)); if (!ret_ptr) return -kErrorInvalidData; -- cgit v1.2.3 From 51023240ae3d6093c8c8fbe1ca8228bbddb54e0a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 11 Sep 2025 17:53:39 +0200 Subject: fix: CxxAbi: Fix ifndef with updated NeCTI macro. Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/CxxAbi.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/kernel/NeKit/CxxAbi.h b/dev/kernel/NeKit/CxxAbi.h index 839308cf..4b7bf002 100644 --- a/dev/kernel/NeKit/CxxAbi.h +++ b/dev/kernel/NeKit/CxxAbi.h @@ -7,7 +7,7 @@ #include -#ifndef __TOOLCHAINKIT__ +#ifndef __NECTI__ #define kAtExitMacDestructors (128) @@ -23,4 +23,4 @@ namespace cxxabiv1 { typedef Kernel::SizeT* __guard; } -#endif // __GNUC__ +#endif // !__NECTI__ -- cgit v1.2.3 From ecff424e9c78418f6d2bd79b7d4f50f42c29860e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 11 Sep 2025 18:00:19 +0200 Subject: fix: SystemKit/Verify.h: fix future link issues with `inline` Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/Verify.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/libSystem/SystemKit/Verify.h b/dev/libSystem/SystemKit/Verify.h index 68e75d47..cbf85830 100644 --- a/dev/libSystem/SystemKit/Verify.h +++ b/dev/libSystem/SystemKit/Verify.h @@ -15,7 +15,7 @@ namespace LibSystem::Detail { /// @author 0xf00sec, and Amlal El Mahrouss /// @brief safe cast operator. template -static R sys_safe_cast(const T* ptr) { +inline R sys_safe_cast(const T* ptr) { _rtl_assert(ptr, "safe cast failed!"); return static_cast(const_cast(ptr)); } @@ -33,7 +33,7 @@ struct must_cast_traits { /// @author Amlal El Mahrouss /// @brief Safe constexpr cast. template -constexpr R* sys_constexpr_cast(T* ptr) { +inline constexpr R* sys_constexpr_cast(T* ptr) { static_assert(must_cast_traits::value, "constexpr cast failed! types are a mismatch!"); return static_cast(ptr); } -- cgit v1.2.3 From d7ede77b3e13bc985e1b320249948434040c73a8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 15 Sep 2025 16:37:13 +0200 Subject: feat: kernel: type fixes. Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/AsciiUtils.cc | 8 ++++---- dev/kernel/src/UtfUtils.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 24e4e220..30773d91 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -45,7 +45,7 @@ const Char* rt_alloc_string(const Char* src) { return buffer; } -Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size) { +Int32 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); @@ -85,7 +85,7 @@ rt_set_memory(voidPtr src, UInt32 value, Size len) { #ifdef __NE_ENFORCE_DEPRECATED_WARNINGS [[deprecated("Use rt_copy_memory_safe instead")]] #endif -Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { +Int32 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); @@ -135,7 +135,7 @@ Bool rt_to_string(Char* str, UInt64 value, Int32 base) { str[i - j - 1] = tmp; } #endif - return true; + return false; } VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { @@ -166,7 +166,7 @@ EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len) { return dst; } -EXTERN_C Kernel::Int32 strcmp(const char* a, const char* b) { +EXTERN_C Int32 strcmp(const char* a, const char* b) { return Kernel::rt_string_cmp(a, b, rt_string_len(a)); } diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc index 907632ad..e98b8306 100644 --- a/dev/kernel/src/UtfUtils.cc +++ b/dev/kernel/src/UtfUtils.cc @@ -37,7 +37,7 @@ Int32 urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { return counter; } -Int urt_copy_memory(const VoidPtr src, VoidPtr dst, Size len) { +Int32 urt_copy_memory(const VoidPtr src, VoidPtr dst, Size len) { Utf8Char* srcChr = reinterpret_cast(src); Utf8Char* dstChar = reinterpret_cast(dst); -- cgit v1.2.3 From dfd6aca50dd2349e828afadc0183419e8e4d0acd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 16 Sep 2025 10:07:23 +0200 Subject: feat: kernel/AsciiUtils: use correct type `Int32` instead of `Int` Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/AsciiUtils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 30773d91..920a5b75 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -8,7 +8,7 @@ namespace Kernel { -Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); +Int32 rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); 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) { -- cgit v1.2.3 From a461a1b5a568087ea4991cb3af2300dd6f8ef90e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 19 Sep 2025 10:22:54 +0200 Subject: feat: kernel && libDDK: `DDK` and `kernel` improvements. what: - Hardened `AsciiUtils` and `libDDK` Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/AsciiUtils.cc | 9 +++++++-- dev/libDDK/src/ddk_dev.c | 4 ++-- dev/libDDK/src/ddk_io.c | 8 ++++++-- dev/libDDK/src/ddk_str.c | 2 ++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc index 920a5b75..cca3a368 100644 --- a/dev/kernel/src/AsciiUtils.cc +++ b/dev/kernel/src/AsciiUtils.cc @@ -8,7 +8,7 @@ namespace Kernel { -Int32 rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); +Int32 rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); 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) { @@ -134,11 +134,15 @@ Bool rt_to_string(Char* str, UInt64 value, Int32 base) { str[j] = str[i - j - 1]; str[i - j - 1] = tmp; } + + return YES; #endif - return false; + return NO; } VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { + if (!haystack || !needle) return nullptr; + SizeT needle_len = rt_string_len(needle); SizeT hay_len = rt_string_len(haystack); @@ -152,6 +156,7 @@ VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { } Char* rt_string_has_char(Char* str, Char ch) { + if (!str) return nullptr; while (*str && *str != ch) ++str; return (*str == ch) ? str : nullptr; } diff --git a/dev/libDDK/src/ddk_dev.c b/dev/libDDK/src/ddk_dev.c index 32ec2442..d20684aa 100644 --- a/dev/libDDK/src/ddk_dev.c +++ b/dev/libDDK/src/ddk_dev.c @@ -11,7 +11,7 @@ /// @brief Open a new binary device from path. DDK_EXTERN DDK_DEVICE_PTR open(const char* devicePath) { - if (!devicePath) return nil; + if (nil == devicePath) return nil; return ke_call_dispatch("dk_open_dev", 1, (void*) devicePath, kstrlen(devicePath)); } @@ -19,7 +19,7 @@ DDK_EXTERN DDK_DEVICE_PTR open(const char* devicePath) { /// @brief Close any device. /// @param device valid device. DDK_EXTERN BOOL close(DDK_DEVICE_PTR device) { - if (!device) return NO; + if (nil == device) return NO; ke_call_dispatch("dk_close_dev", 1, device, sizeof(DDK_DEVICE)); return YES; diff --git a/dev/libDDK/src/ddk_io.c b/dev/libDDK/src/ddk_io.c index c6cdd457..825e82a7 100644 --- a/dev/libDDK/src/ddk_io.c +++ b/dev/libDDK/src/ddk_io.c @@ -1,7 +1,9 @@ /* ------------------------------------------- - Copyright Amlal El Mahrouss. + libDDK. + Copyright 2025 - Amlal El Mahrouss and NeKernel contributors. + File: ddk_io.c Purpose: DDK Text I/O. ------------------------------------------- */ @@ -9,6 +11,8 @@ #include DDK_EXTERN void kputc(const char ch) { + if (!ch) return; + char assembled[2] = {0}; assembled[0] = ch; assembled[1] = 0; @@ -19,7 +23,7 @@ DDK_EXTERN void kputc(const char ch) { /// @brief print string to UART. /// @param message UART to transmit. DDK_EXTERN void kprint(const char* message) { - if (!message) return; + if (nil == message) return; if (*message == 0) return; size_t index = 0; diff --git a/dev/libDDK/src/ddk_str.c b/dev/libDDK/src/ddk_str.c index 514cddc7..1e2fde19 100644 --- a/dev/libDDK/src/ddk_str.c +++ b/dev/libDDK/src/ddk_str.c @@ -23,6 +23,8 @@ DDK_EXTERN size_t kstrlen(const char* in) { } DDK_EXTERN int kstrncpy(char* dst, const char* src, size_t len) { + if (nil == dst || nil == src) return 0; + size_t index = 0; while (index != len) { -- cgit v1.2.3 From 78bd706f8703d0c5cce7c8a66e4668ed28532e07 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 19 Sep 2025 10:24:21 +0200 Subject: fix: acpi: return error code as negative value instead of positive one. Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/ACPIFactoryInterface.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/kernel/src/ACPIFactoryInterface.cc b/dev/kernel/src/ACPIFactoryInterface.cc index 711ea588..6cebf26c 100644 --- a/dev/kernel/src/ACPIFactoryInterface.cc +++ b/dev/kernel/src/ACPIFactoryInterface.cc @@ -70,7 +70,7 @@ ErrorOr ACPIFactoryInterface::Find(const Char* signature) { @param len the length of it. */ bool ACPIFactoryInterface::Checksum(const Char* checksum, SSizeT len) { - if (len == 0 || !checksum) return false; + if (len == 0 || !checksum) return NO; Char chr = 0; -- cgit v1.2.3 From 2d673e164b98db5eb08d4c41c6225fbe73ee82d7 Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Sun, 28 Sep 2025 15:10:46 +0300 Subject: ErrorOr.h: T.Value Introduced T& Value() to extract the underlying scalar value without implying ownership transfer. Kept Leak() to explicitly indicate heap ownership transfer. Signed-off-by: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> --- dev/kernel/NeKit/ErrorOr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h index b653e0ee..52f0d6a9 100644 --- a/dev/kernel/NeKit/ErrorOr.h +++ b/dev/kernel/NeKit/ErrorOr.h @@ -38,6 +38,8 @@ class ErrorOr final { return *this; } + T Value() const { return *mRef; } + Ref& Leak() { return mRef; } Int32 Error() { return mId; } -- cgit v1.2.3