diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-29 10:51:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-29 10:51:53 +0200 |
| commit | 5c0bb7ee7b1b0fee02cc179fb21f4c57a61d6c2d (patch) | |
| tree | cb17577bcdc9714c97a84ce417a075117097f146 /dev/kernel/KernelKit | |
| parent | d608230b1350b064ceb01e6572519b108f6139b0 (diff) | |
| parent | 3167f59dbb401d6a79b1524537e04218baf49ee3 (diff) | |
Merge pull request #32 from nekernel-org/dev
0.0.2e3
Diffstat (limited to 'dev/kernel/KernelKit')
39 files changed, 428 insertions, 230 deletions
diff --git a/dev/kernel/KernelKit/BinaryMutex.h b/dev/kernel/KernelKit/BinaryMutex.h index a1cd5b7c..45d4bd8d 100644 --- a/dev/kernel/KernelKit/BinaryMutex.h +++ b/dev/kernel/KernelKit/BinaryMutex.h @@ -8,7 +8,7 @@ #include <CompilerKit/CompilerKit.h> #include <KernelKit/Timer.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> namespace Kernel { class USER_PROCESS; diff --git a/dev/kernel/KernelKit/CodeMgr.h b/dev/kernel/KernelKit/CodeMgr.h index bb287b24..072ba4d5 100644 --- a/dev/kernel/KernelKit/CodeMgr.h +++ b/dev/kernel/KernelKit/CodeMgr.h @@ -20,20 +20,20 @@ namespace Kernel { /// @brief Main process entrypoint. -typedef void (*rtl_main_kind)(SizeT argc, Char** argv, Char** envp, SizeT envp_len); +typedef void (*rtl_main_kind)(void); /// @brief C++ Constructor entrypoint. -typedef void (*rtl_ctor_kind)(void); +typedef void (*rtl_cxx_ctor_kind)(void); /// @brief C++ Destructor entrypoint. -typedef void (*rtl_dtor_kind)(void); +typedef void (*rtl_cxx_dtor_kind)(void); /// @brief Executes a new process from a function. Kernel code only. /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be /// accessible. /// @param main the start of the process. /// @return The team's process id. -ProcessID rtl_create_kernel_process(rtl_main_kind main, const Char* process_name) noexcept; +ProcessID rtl_create_kernel_process(rtl_main_kind main, const Char* task_name) noexcept; /// @brief Executes a new process from a function. User code only. /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index b3bc3e65..5ba29d3a 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -6,21 +6,100 @@ #pragma once -#include <NewKit/Defines.h> -#include <NewKit/ErrorOr.h> +#include <NeKit/Defines.h> +#include <NeKit/ErrorOr.h> + +#define kSchedMinMicroTime (AffinityKind::kStandard) +#define kSchedInvalidPID (-1) +#define kSchedProcessLimitPerTeam (32U) +#define kSchedTeamCount (256U) + +#define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ +#define kSchedMaxStackSz (kib_cast(8)) /* maximum stack size */ + +#define kSchedNameLen (128U) + +EXTERN_C void sched_idle_task(void); namespace Kernel { class USER_PROCESS; -class KERNEL_PROCESS; +class KERNEL_TASK; +class KernelTaskScheduler; +class UserProcessScheduler; class UserProcessTeam; +template <typename T> +struct PROCESS_HEAP_TREE; + +template <typename T> +struct PROCESS_FILE_TREE; + +enum { + kInvalidTreeKind = 0U, + kRedTreeKind = 100U, + kBlackTreeKind = 101U, + kTreeKindCount = 2U, +}; + +template <typename T> +struct PROCESS_HEAP_TREE { + static constexpr auto kPtr = true; + static constexpr auto kFD = false; + + T Entry{nullptr}; + SizeT EntrySize{0UL}; + SizeT EntryPad{0UL}; + + UInt32 Color{kBlackTreeKind}; + + struct PROCESS_HEAP_TREE<T>* Parent { + nullptr + }; + struct PROCESS_HEAP_TREE<T>* Child { + nullptr + }; + + struct PROCESS_HEAP_TREE<T>* Prev { + nullptr + }; + struct PROCESS_HEAP_TREE<T>* Next { + nullptr + }; +}; + +template <typename T> +struct PROCESS_FILE_TREE { + static constexpr auto kPtr = false; + static constexpr auto kFD = true; + + T Entry{nullptr}; + SizeT EntrySize{0UL}; + SizeT EntryPad{0UL}; + + UInt32 Color{kBlackTreeKind}; + + struct PROCESS_FILE_TREE<T>* Parent { + nullptr + }; + struct PROCESS_FILE_TREE<T>* Child { + nullptr + }; + + struct PROCESS_FILE_TREE<T>* Prev { + nullptr + }; + struct PROCESS_FILE_TREE<T>* Next { + nullptr + }; +}; + /***********************************************************************************/ /// @brief Subsystem enum type. /***********************************************************************************/ enum class ProcessSubsystem : Int32 { kProcessSubsystemSecurity = 100, - kProcessSubsystemApplication, + kProcessSubsystemUser, kProcessSubsystemService, kProcessSubsystemDriver, kProcessSubsystemInvalid = 0xFFFFFFF, @@ -51,8 +130,8 @@ enum class ProcessStatusKind : Int32 { //! @brief Affinity is the amount of nano-seconds this process is going to run. /***********************************************************************************/ enum class AffinityKind : Int32 { - kRealTime = 500, - kVeryHigh = 250, + kRealTime = 50, + kVeryHigh = 150, kHigh = 200, kStandard = 1000, kLowUsage = 1500, @@ -117,7 +196,8 @@ struct PROCESS_IMAGE final { private: friend USER_PROCESS; - friend KERNEL_PROCESS; + friend KERNEL_TASK; + friend class UserProcessScheduler; ImagePtr fCode; diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index f6cfa027..9598f590 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -8,9 +8,9 @@ #include <CompilerKit/CompilerKit.h> #include <KernelKit/DeviceMgr.h> -#include <NewKit/OwnPtr.h> -#include <NewKit/Stream.h> -#include <NewKit/Utils.h> +#include <NeKit/OwnPtr.h> +#include <NeKit/Stream.h> +#include <NeKit/Utils.h> #define kDebugUnboundPort 0x0FEED @@ -158,8 +158,8 @@ namespace Detail { inline TerminalDevice hex_number(const Long& x) { TerminalDevice self = TerminalDevice::The(); + self << "0x"; Detail::_write_number_hex(x, self); - self.operator<<("h"); return self; } @@ -184,10 +184,12 @@ inline constexpr SizeT kDebugTypeLen = 256U; typedef Char rt_debug_type[kDebugTypeLen]; -class DebuggerPortHeader final { +/// @brief KDBG's packet header. +class KernelDebugHeader final { public: - Int16 fPort; - Int16 fPortBsy; + Int16 fPort; + Int16 fPortKind; + rt_debug_type fPortBlob; }; inline TerminalDevice& operator<<(TerminalDevice& src, const Long& num) { diff --git a/dev/kernel/KernelKit/Defines.h b/dev/kernel/KernelKit/Defines.h index 2c170940..975520b6 100644 --- a/dev/kernel/KernelKit/Defines.h +++ b/dev/kernel/KernelKit/Defines.h @@ -6,11 +6,14 @@ #pragma once -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> -#define KERNELKIT_VERSION "0.0.1" +#define KERNELKIT_VERSION "0.0.1-kernelkit" #define KERNELKIT_VERSION_BCD 0x0001 +namespace Kernel { class UserProcessScheduler; class IDylibObject; -class Process; +class USER_PROCESS; +class KERNEL_TASK; +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index 210cef2a..7c7b9da3 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -8,8 +8,8 @@ Revision History: - 31/01/24: Add kDeviceCnt (amlel) - 15/11/24: Add NE_DEVICE macro, to inherit from device object. + 31/01/24: Add kDeviceCnt (amlel) + 15/11/24: Add NE_DEVICE macro, to inherit from device object. ------------------------------------------- */ @@ -19,19 +19,22 @@ /* @file KernelKit/DeviceMgr.h */ /* @brief Device abstraction and I/O buffer. */ -#include <NewKit/ErrorOr.h> -#include <NewKit/Ref.h> +#include <NeKit/ErrorOr.h> +#include <NeKit/Ref.h> #define kDeviceMgrRootDirPath "/devices/" #define NE_DEVICE : public ::Kernel::IDeviceObject -// Last Rev: Wed, Apr 3, 2024 9:09:41 AM +// Last Rev: Wed, May 27, 2025 6:22 PM namespace Kernel { template <typename T> class IDeviceObject; +template <typename T> +class IOBuf; + /***********************************************************************************/ /// @brief Device contract interface, represents an HW device. /***********************************************************************************/ @@ -103,7 +106,8 @@ class IOBuf final { ///! @brief Device enum types. enum { - kDeviceTypeIDE, + kDeviceTypeInvalid = 0, + kDeviceTypeIDE = 100, kDeviceTypeEthernet, kDeviceTypeWiFi, kDeviceTypeFW, @@ -114,7 +118,10 @@ enum { kDeviceTypeMBCI, kDeviceTypeATA, kDeviceTypeUSB, - kDeviceTypeMediaCtrl, // MM controller + kDeviceTypeAPM, // Adv. Pwr. Mgmt. + kDeviceTypePCI, + kDeviceTypeVGA, + kDeviceTypeGPU, kDeviceTypeCount, }; } // namespace Kernel diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h index 7972ac74..4a530deb 100644 --- a/dev/kernel/KernelKit/DriveMgr.h +++ b/dev/kernel/KernelKit/DriveMgr.h @@ -12,9 +12,9 @@ #include <KernelKit/DeviceMgr.h> #include <KernelKit/KPC.h> #include <KernelKit/ProcessScheduler.h> -#include <NewKit/Defines.h> -#include <NewKit/KString.h> -#include <NewKit/Ref.h> +#include <NeKit/Defines.h> +#include <NeKit/KString.h> +#include <NeKit/Ref.h> #define kDriveMaxCount (4U) #define kDriveSectorSz (512U) @@ -23,6 +23,8 @@ #define drv_sector_cnt(SIZE, SECTOR_SZ) (((SIZE) + (SECTOR_SZ)) / (SECTOR_SZ)) +#define kDriveHiddenPrefix '~' + namespace Kernel { enum { kInvalidDrive = -1, @@ -159,20 +161,6 @@ namespace Detect { Void io_drv_input(DriveTrait::DrivePacket pckt); Void io_drv_output(DriveTrait::DrivePacket pckt); - -/// @brief Read from IFS disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); - -/// @brief Write to IFS disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); } // namespace Kernel #endif /* ifndef INC_DRIVE_MANAGER_H */ diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 2c4b2055..13eeabdf 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss Labs, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss , all rights reserved. File: FileMgr.h Purpose: Kernel file manager. @@ -28,15 +28,15 @@ #include <CompilerKit/CompilerKit.h> #include <KernelKit/DebugOutput.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/KPC.h> -#include <KernelKit/MemoryMgr.h> -#include <NewKit/ErrorOr.h> -#include <NewKit/Ref.h> -#include <NewKit/Stream.h> +#include <NeKit/ErrorOr.h> +#include <NeKit/Ref.h> +#include <NeKit/Stream.h> #include <hint/CompilerHint.h> /// @brief Filesystem manager, abstraction over mounted filesystem. -/// Works like the VFS or IFS subsystem. +/// Works like an VFS (Virtual File System) or IFS subsystem on NT/OS 2. #define kRestrictR "r" #define kRestrictRB "rb" @@ -52,6 +52,7 @@ @note Refer to first enum. */ #define kFileOpsCount (4U) + #define kFileMimeGeneric "ne-application-kind/all" /** @brief invalid position. (n-pos) */ @@ -176,6 +177,52 @@ class NeFileSystemMgr final : public IFilesystemMgr { #endif // ifdef __FSKIT_INCLUDES_NEFS__ +#ifdef __FSKIT_INCLUDES_HEFS__ +/** + * @brief Based of IFilesystemMgr, takes care of managing NeFS + * disks. + */ +class HeFileSystemMgr final : public IFilesystemMgr { + public: + explicit HeFileSystemMgr(); + ~HeFileSystemMgr() override; + + public: + NE_COPY_DEFAULT(HeFileSystemMgr) + + public: + NodePtr Create(const Char* path) override; + NodePtr CreateAlias(const Char* path) override; + NodePtr CreateDirectory(const Char* path) override; + NodePtr CreateSwapFile(const Char* path) override; + + public: + bool Remove(_Input const Char* path) override; + NodePtr Open(_Input const Char* path, _Input const Char* r) override; + Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, + _Input SizeT sz) override; + VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) override; + bool Seek(_Input NodePtr node, _Input SizeT off) override; + SizeT Tell(_Input NodePtr node) override; + bool Rewind(_Input NodePtr node) override; + + Void Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, + _Input SizeT size) override; + + _Output VoidPtr Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, + _Input SizeT sz) override; + + public: + /// @brief Get NeFS parser class. + /// @return The filesystem parser class. + HeFileSystemParser* GetParser() noexcept; + + private: + HeFileSystemParser* mParser{nullptr}; +}; + +#endif // ifdef __FSKIT_INCLUDES_HEFS__ + /** * FileStream class. * @tparam Encoding file encoding (char, wchar_t...) @@ -278,7 +325,7 @@ class FileStream final { Char* MIME() noexcept { return const_cast<Char*>(fMime); } enum { - kFileMgrRestrictRead, + kFileMgrRestrictRead = 100, kFileMgrRestrictReadBinary, kFileMgrRestrictWrite, kFileMgrRestrictWriteBinary, @@ -292,15 +339,16 @@ class FileStream final { const Char* fMime{kFileMimeGeneric}; }; -using FileStreamUTF8 = FileStream<Char>; +using FileStreamASCII = FileStream<Char>; +using FileStreamUTF8 = FileStream<Utf8Char>; using FileStreamUTF16 = FileStream<WideChar>; typedef UInt64 CursorType; -inline static const auto kRestrictStrLen = 8U; +inline STATIC const auto kRestrictStrLen = 8U; /// @brief restrict information about the file descriptor. -struct FileRestrictKind final { +struct FILEMGR_RESTRICT final { Char fRestrict[kRestrictStrLen]; Int32 fMappedTo; }; @@ -310,7 +358,7 @@ template <typename Encoding, typename Class> inline FileStream<Encoding, Class>::FileStream(const Encoding* path, const Encoding* restrict_type) : fFile(Class::GetMounted()->Open(path, restrict_type)) { SizeT kRestrictCount = kRestrictMax; - const FileRestrictKind kRestrictList[] = {{ + const FILEMGR_RESTRICT kRestrictList[] = {{ .fRestrict = kRestrictR, .fMappedTo = kFileMgrRestrictRead, }, @@ -339,13 +387,13 @@ inline FileStream<Encoding, Class>::FileStream(const Encoding* path, const Encod } } - kout << "new file: " << path << ".\r"; + kout << "FileMgr: Open file at: " << path << ".\r"; } /// @brief destructor of the file stream. template <typename Encoding, typename Class> inline FileStream<Encoding, Class>::~FileStream() { - mm_delete_heap(fFile); + mm_free_ptr(fFile); } } // namespace Kernel diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index d47b2994..76327a93 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -9,12 +9,12 @@ #include <ArchKit/ArchKit.h> #include <CompilerKit/CompilerKit.h> -#include <NewKit/Ref.h> +#include <NeKit/Ref.h> /// @note Last Rev Sun 28 Jul CET 2024 /// @note Last Rev Thu, Aug 1, 2024 9:07:38 AM -#define kMaxAPInsideSched (8U) +#define kMaxAPInsideSched (4U) namespace Kernel { class HardwareThread; @@ -23,12 +23,12 @@ class HardwareThreadScheduler; using ThreadID = UInt32; enum ThreadKind { - kAPInvalid, - kAPSystemReserved, // System reserved thread, well user can't use it - kAPStandard, // user thread, cannot be used by Kernel - kAPRealTime, // fallback thread, cannot be used by user if not clear or - // used by Kernel. - kAPBoot, // The core we booted from, the mama. + kAPInvalid = 0, + kAPSystemReserved = 100, // System reserved thread, well user can't use it + kAPStandard, // user thread, cannot be used by Kernel + kAPRealTime, // fallback thread, cannot be used by user if not clear or + // used by Kernel. + kAPBoot, // The core we booted from, the mama. kAPCount, }; @@ -58,20 +58,19 @@ class HardwareThread final { void Busy(const BOOL busy = false) noexcept; public: - BOOL Switch(VoidPtr image, Ptr8 stack_ptr, HAL::StackFramePtr frame, const ThreadID& pid); + BOOL Switch(HAL::StackFramePtr frame); BOOL IsWakeup() noexcept; public: HAL::StackFramePtr StackFrame() noexcept; - const ThreadKind& Kind() noexcept; - bool IsBusy() noexcept; - const ThreadID& ID() noexcept; + ThreadKind& Kind() noexcept; + BOOL IsBusy() noexcept; + ThreadID& ID() noexcept; private: HAL::StackFramePtr fStack{nullptr}; ThreadKind fKind{ThreadKind::kAPStandard}; ThreadID fID{0}; - ThreadID fPID{0}; Bool fWakeup{NO}; Bool fBusy{NO}; UInt64 fPTime{0}; diff --git a/dev/kernel/KernelKit/MemoryMgr.h b/dev/kernel/KernelKit/HeapMgr.h index 2274e24e..dacdfa5d 100644 --- a/dev/kernel/KernelKit/MemoryMgr.h +++ b/dev/kernel/KernelKit/HeapMgr.h @@ -8,40 +8,35 @@ #define INC_KERNEL_HEAP_H /// @date 30/01/24 -/// @file: MemoryMgr.h +/// @file: HeapMgr.h /// @brief: Memory allocation support for the NeKernel. #include <KernelKit/KPC.h> -#include <NewKit/KernelPanic.h> +#include <NeKit/KernelPanic.h> #include <hint/CompilerHint.h> namespace Kernel { /// @brief Declare pointer as free. /// @param heap_ptr the pointer. /// @return a status code regarding the deallocation. -Int32 mm_delete_heap(VoidPtr heap_ptr); - -/// @brief Declare a new size for heap_ptr. -/// @param heap_ptr the pointer. -/// @return unsupported always returns nullptr. -VoidPtr mm_realloc_heap(VoidPtr heap_ptr, SizeT new_sz); +Int32 mm_free_ptr(VoidPtr heap_ptr); /// @brief Check if pointer is a valid Kernel pointer. /// @param heap_ptr the pointer /// @return if it exists it returns true. -Boolean mm_is_valid_heap(VoidPtr heap_ptr); +Boolean mm_is_valid_ptr(VoidPtr heap_ptr); /// @brief Allocate chunk of memory. /// @param sz Size of pointer /// @param wr Read Write bit. /// @param user User enable bit. /// @return The newly allocated pointer, or nullptr. -VoidPtr mm_new_heap(SizeT sz, Bool wr, Bool user, SizeT pad_amount = 0); +VoidPtr mm_alloc_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount = 0); /// @brief Protect the heap with a CRC value. /// @param heap_ptr pointer. /// @return if it valid: point has crc now., otherwise fail. -Boolean mm_protect_heap(VoidPtr heap_ptr); +Boolean mm_protect_ptr(VoidPtr heap_ptr); /// @brief Makes a Kernel page. /// @param heap_ptr the page pointer. @@ -51,33 +46,13 @@ Int32 mm_make_page(VoidPtr heap_ptr); /// @brief Overwrites and set the flags of a heap header. /// @param heap_ptr the pointer to update. /// @param flags the flags to set. -Int32 mm_make_flags(VoidPtr heap_ptr, UInt64 flags); +Int32 mm_set_ptr_flags(VoidPtr heap_ptr, UInt64 flags); /// @brief Gets the flags of a heap header. /// @param heap_ptr the pointer to get. -UInt64 mm_get_flags(VoidPtr heap_ptr); - -/// @brief Allocate C++ class. -/// @param cls The class to allocate. -/// @param args The args to pass. -template <typename T, typename... Args> -inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) { - if (*cls) { - err_global_get() = Kernel::kErrorInvalidData; - return NO; - } - - *cls = new T(move(args)...); - return *cls; -} - -/// @brief Delete and nullify C++ class. -/// @param cls The class to delete. -template <typename T> -inline Void mm_delete_class(_Input _Output T** cls) { - delete *cls; - *cls = nullptr; -} +UInt64 mm_get_ptr_flags(VoidPtr heap_ptr); } // namespace Kernel +#include <KernelKit/HeapMgr.inl> + #endif // !INC_KERNEL_HEAP_H diff --git a/dev/kernel/KernelKit/HeapMgr.inl b/dev/kernel/KernelKit/HeapMgr.inl new file mode 100644 index 00000000..6371012e --- /dev/null +++ b/dev/kernel/KernelKit/HeapMgr.inl @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#ifndef INC_KERNEL_HEAP_H +#include <KernelKit/HeapMgr.h> +#endif // !INC_KERNEL_HEAP_H + +namespace Kernel { +/// @brief Allocate C++ class. +/// @param cls The class to allocate. +/// @param args The args to pass. +template <typename T, typename... Args> +inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) { + if (*cls) { + err_global_get() = Kernel::kErrorInvalidData; + return NO; + } + + *cls = new T(move(args)...); + return *cls; +} + +/// @brief Delete and nullify C++ class. +/// @param cls The class to delete. +template <typename T> +inline Void mm_delete_class(_Input _Output T** cls) { + delete *cls; + *cls = nullptr; +} +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/KernelKit/IDylibObject.h b/dev/kernel/KernelKit/IDylibObject.h index 7a7cd913..b673766c 100644 --- a/dev/kernel/KernelKit/IDylibObject.h +++ b/dev/kernel/KernelKit/IDylibObject.h @@ -10,31 +10,34 @@ #pragma once #include <CompilerKit/CompilerKit.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> #define NE_DYLIB_OBJECT : public IDylibObject namespace Kernel { +class IDylibObject; + /// @brief Dylib class object. A handle to a shared library. class IDylibObject { public: explicit IDylibObject() = default; virtual ~IDylibObject() = default; - struct DLL_TRAITS final { + struct DylibTraits final { VoidPtr ImageObject{nullptr}; VoidPtr ImageEntrypointOffset{nullptr}; - Bool IsValid() { return ImageObject && ImageEntrypointOffset; } + VoidPtr Image() const { return ImageObject; } + Bool IsValid() const { return ImageObject && ImageEntrypointOffset; } }; NE_COPY_DEFAULT(IDylibObject) - virtual DLL_TRAITS** GetAddressOf() = 0; - virtual DLL_TRAITS* Get() = 0; + virtual DylibTraits** GetAddressOf() = 0; + virtual DylibTraits* Get() = 0; - virtual Void Mount(DLL_TRAITS* to_mount) = 0; - virtual Void Unmount() = 0; + virtual Void Mount(DylibTraits* to_mount) = 0; + virtual Void Unmount() = 0; }; /// @brief Pure implementation, missing method/function handler. diff --git a/dev/kernel/KernelKit/IFS.h b/dev/kernel/KernelKit/IFS.h new file mode 100644 index 00000000..5555764f --- /dev/null +++ b/dev/kernel/KernelKit/IFS.h @@ -0,0 +1,25 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <KernelKit/DriveMgr.h> + +namespace Kernel { +/// @brief Read from IFS disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); + +/// @brief Write to IFS disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex); +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/KernelKit/IPEFDylibObject.h b/dev/kernel/KernelKit/IPEFDylibObject.h index 42ed1830..66b4895d 100644 --- a/dev/kernel/KernelKit/IPEFDylibObject.h +++ b/dev/kernel/KernelKit/IPEFDylibObject.h @@ -14,7 +14,7 @@ #include <KernelKit/PEF.h> #include <KernelKit/PEFCodeMgr.h> #include <KernelKit/ProcessScheduler.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> namespace Kernel { /** @@ -30,15 +30,15 @@ class IPEFDylibObject final NE_DYLIB_OBJECT { NE_COPY_DEFAULT(IPEFDylibObject) private: - DLL_TRAITS* fMounted{nullptr}; + DylibTraits* fMounted{nullptr}; public: - DLL_TRAITS** GetAddressOf() { return &fMounted; } + DylibTraits** GetAddressOf() { return &fMounted; } - DLL_TRAITS* Get() { return fMounted; } + DylibTraits* Get() { return fMounted; } public: - void Mount(DLL_TRAITS* to_mount) { + void Mount(DylibTraits* to_mount) { if (!to_mount || !to_mount->ImageObject) return; fMounted = to_mount; diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index 9de1f70f..a3b13de6 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -6,18 +6,19 @@ #pragma once -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> /// @file KPC.h /// @brief Kernel Procedure Code. -#define err_local_ok() \ - (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() == \ +#define err_local_ok() \ + (Kernel::UserProcessScheduler::The().TheCurrentProcess().Leak().GetLocalCode() == \ Kernel::kErrorSuccess) -#define err_local_fail() \ - (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode() != \ +#define err_local_fail() \ + (Kernel::UserProcessScheduler::The().TheCurrentProcess().Leak().GetLocalCode() != \ Kernel::kErrorSuccess) -#define err_local_get() (Kernel::UserProcessScheduler::The().CurrentProcess().Leak().GetLocalCode()) +#define err_local_get() \ + (Kernel::UserProcessScheduler::The().TheCurrentProcess().Leak().GetLocalCode()) #define err_global_ok() (Kernel::kErrorLocalNumber == Kernel::kErrorSuccess) #define err_global_fail() (Kernel::kErrorLocalNumber != Kernel::kErrorSuccess) @@ -62,8 +63,8 @@ inline constexpr KPCError kErrorCDTrayBroken = 62; inline constexpr KPCError kErrorUnrecoverableDisk = 63; inline constexpr KPCError kErrorFileLocked = 64; inline constexpr KPCError kErrorDiskIsTooTiny = 65; -/// Kernel errors. -inline constexpr KPCError kErrorDmaExhausted = 101; +inline constexpr KPCError kErrorDmaExhausted = 66; +inline constexpr KPCError kErrorOutOfBitMapMemory = 67; /// Generic errors. inline constexpr KPCError kErrorUnimplemented = -1; diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index ca10003f..57b83ccb 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -12,4 +12,16 @@ #include <ArchKit/ArchKit.h> #include <KernelKit/CoreProcessScheduler.h> -#include <KernelKit/LockDelegate.h>
\ No newline at end of file +#include <KernelKit/LockDelegate.h> + +namespace Kernel { +class KERNEL_TASK final { + public: + Char Name[kSchedNameLen] = {"KERNEL_TASK"}; + ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemDriver}; + HAL::StackFramePtr StackFrame{nullptr}; + UInt8* StackReserve{nullptr}; + SizeT StackSize{kSchedMaxStackSz}; + PROCESS_IMAGE Image{}; +}; +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/KernelKit/LoaderInterface.h b/dev/kernel/KernelKit/LoaderInterface.h index 2b38ddbf..1f9b1e56 100644 --- a/dev/kernel/KernelKit/LoaderInterface.h +++ b/dev/kernel/KernelKit/LoaderInterface.h @@ -7,8 +7,8 @@ #pragma once #include <CompilerKit/CompilerKit.h> -#include <NewKit/Defines.h> -#include <NewKit/ErrorOr.h> +#include <NeKit/Defines.h> +#include <NeKit/ErrorOr.h> #include <hint/CompilerHint.h> namespace Kernel { diff --git a/dev/kernel/KernelKit/LockDelegate.h b/dev/kernel/KernelKit/LockDelegate.h index 18ab0cf5..b5977c92 100644 --- a/dev/kernel/KernelKit/LockDelegate.h +++ b/dev/kernel/KernelKit/LockDelegate.h @@ -6,13 +6,13 @@ #pragma once -#include <NewKit/Atom.h> -#include <NewKit/Defines.h> +#include <NeKit/Atom.h> +#include <NeKit/Defines.h> namespace Kernel { enum { - kLockInvalid, - kLockDone = 200, + kLockInvalid = 0, + kLockDone = 200, kLockTimedOut, kLockCount = 3, }; diff --git a/dev/kernel/KernelKit/MSDOS.h b/dev/kernel/KernelKit/MSDOS.h index a0751a6f..b4ffeff2 100644 --- a/dev/kernel/KernelKit/MSDOS.h +++ b/dev/kernel/KernelKit/MSDOS.h @@ -15,7 +15,7 @@ #define __MSDOS_EXEC__ #include <KernelKit/PE.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> // Last Rev // Sat Feb 24 CET 2024 diff --git a/dev/kernel/KernelKit/PCI/DMA.h b/dev/kernel/KernelKit/PCI/DMA.h index 66d64f61..7e7d3f0c 100644 --- a/dev/kernel/KernelKit/PCI/DMA.h +++ b/dev/kernel/KernelKit/PCI/DMA.h @@ -8,17 +8,18 @@ #include <KernelKit/DeviceMgr.h> #include <KernelKit/PCI/Device.h> -#include <NewKit/Array.h> -#include <NewKit/OwnPtr.h> -#include <NewKit/Ref.h> +#include <NeKit/Array.h> +#include <NeKit/OwnPtr.h> +#include <NeKit/Ref.h> namespace Kernel { enum class DmaKind { - PCI, // Bus mastering is required to be turned on. Basiaclly a request + PCI = 10, // Bus mastering is required to be turned on. Basiaclly a request // control system. 64-Bit access depends on the PAE bit and the device // (if Double Address Cycle is available) ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. - Invalid, + Count = 2, + Invalid = 0, }; class DMAWrapper final { diff --git a/dev/kernel/KernelKit/PCI/Database.h b/dev/kernel/KernelKit/PCI/Database.h index 6da653dd..093338da 100644 --- a/dev/kernel/KernelKit/PCI/Database.h +++ b/dev/kernel/KernelKit/PCI/Database.h @@ -6,7 +6,7 @@ #pragma once #include <KernelKit/PCI/Device.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> namespace Kernel { namespace Types { diff --git a/dev/kernel/KernelKit/PCI/Device.h b/dev/kernel/KernelKit/PCI/Device.h index d9bb4e70..f41e0575 100644 --- a/dev/kernel/KernelKit/PCI/Device.h +++ b/dev/kernel/KernelKit/PCI/Device.h @@ -5,7 +5,7 @@ ------------------------------------------- */ #pragma once -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> namespace Kernel::PCI { enum class PciConfigKind : UShort { diff --git a/dev/kernel/KernelKit/PCI/Express.h b/dev/kernel/KernelKit/PCI/Express.h index 4d94830c..c9d65da7 100644 --- a/dev/kernel/KernelKit/PCI/Express.h +++ b/dev/kernel/KernelKit/PCI/Express.h @@ -7,6 +7,6 @@ #pragma once #include <KernelKit/PCI/PCI.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> #define PCI_EXPRESS_BUS_COUNT (4096) diff --git a/dev/kernel/KernelKit/PCI/IO.h b/dev/kernel/KernelKit/PCI/IO.h index bd5751ec..a7abc163 100644 --- a/dev/kernel/KernelKit/PCI/IO.h +++ b/dev/kernel/KernelKit/PCI/IO.h @@ -7,9 +7,9 @@ #pragma once #include <ArchKit/ArchKit.h> -#include <NewKit/Array.h> -#include <NewKit/Defines.h> -#include <NewKit/Ref.h> +#include <NeKit/Array.h> +#include <NeKit/Defines.h> +#include <NeKit/Ref.h> namespace Kernel { template <SizeT Sz> diff --git a/dev/kernel/KernelKit/PCI/Iterator.h b/dev/kernel/KernelKit/PCI/Iterator.h index 10924bc8..d4c89404 100644 --- a/dev/kernel/KernelKit/PCI/Iterator.h +++ b/dev/kernel/KernelKit/PCI/Iterator.h @@ -9,9 +9,9 @@ #include <KernelKit/PCI/Database.h> #include <KernelKit/PCI/Device.h> -#include <NewKit/Array.h> -#include <NewKit/Defines.h> -#include <NewKit/Ref.h> +#include <NeKit/Array.h> +#include <NeKit/Defines.h> +#include <NeKit/Ref.h> #define NE_BUS_COUNT (256) #define NE_DEVICE_COUNT (33) diff --git a/dev/kernel/KernelKit/PCI/PCI.h b/dev/kernel/KernelKit/PCI/PCI.h index 7b30d455..d8805a0c 100644 --- a/dev/kernel/KernelKit/PCI/PCI.h +++ b/dev/kernel/KernelKit/PCI/PCI.h @@ -6,7 +6,7 @@ #pragma once -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> #define kPCIConfigAddressPort (0xCF8) #define kPCIConfigDataPort (0xCFC) diff --git a/dev/kernel/KernelKit/PE.h b/dev/kernel/KernelKit/PE.h index b961e901..df5047a3 100644 --- a/dev/kernel/KernelKit/PE.h +++ b/dev/kernel/KernelKit/PE.h @@ -14,7 +14,7 @@ #ifndef __KERNELKIT_INC_PE_H__ #define __KERNELKIT_INC_PE_H__ -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> #define kPeSignature (0x00004550) diff --git a/dev/kernel/KernelKit/PECodeMgr.h b/dev/kernel/KernelKit/PECodeMgr.h index 05a2674c..15c2b7ee 100644 --- a/dev/kernel/KernelKit/PECodeMgr.h +++ b/dev/kernel/KernelKit/PECodeMgr.h @@ -22,8 +22,8 @@ #include <KernelKit/FileMgr.h> #include <KernelKit/LoaderInterface.h> #include <KernelKit/PE.h> -#include <NewKit/ErrorOr.h> -#include <NewKit/KString.h> +#include <NeKit/ErrorOr.h> +#include <NeKit/KString.h> #ifndef INC_PROCESS_SCHEDULER_H #include <KernelKit/ProcessScheduler.h> diff --git a/dev/kernel/KernelKit/PEF.h b/dev/kernel/KernelKit/PEF.h index 9381e491..c28c8f8c 100644 --- a/dev/kernel/KernelKit/PEF.h +++ b/dev/kernel/KernelKit/PEF.h @@ -16,7 +16,7 @@ #include <CompilerKit/CompilerKit.h> #include <KernelKit/LoaderInterface.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> #define kPefMagic "Joy!" #define kPefMagicFat "yoJ!" diff --git a/dev/kernel/KernelKit/PEFCodeMgr.h b/dev/kernel/KernelKit/PEFCodeMgr.h index a637892f..18041f8f 100644 --- a/dev/kernel/KernelKit/PEFCodeMgr.h +++ b/dev/kernel/KernelKit/PEFCodeMgr.h @@ -9,8 +9,8 @@ #include <KernelKit/FileMgr.h> #include <KernelKit/PEF.h> -#include <NewKit/ErrorOr.h> -#include <NewKit/KString.h> +#include <NeKit/ErrorOr.h> +#include <NeKit/KString.h> #ifndef INC_PROCESS_SCHEDULER_H #include <KernelKit/ProcessScheduler.h> diff --git a/dev/kernel/KernelKit/Semaphore.h b/dev/kernel/KernelKit/Semaphore.h index 9a66b9fe..a1b5ecad 100644 --- a/dev/kernel/KernelKit/Semaphore.h +++ b/dev/kernel/KernelKit/Semaphore.h @@ -8,7 +8,7 @@ #include <CompilerKit/CompilerKit.h> #include <KernelKit/Timer.h> -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> namespace Kernel { typedef Int64 Semaphore; diff --git a/dev/kernel/KernelKit/ThreadLocalStorage.h b/dev/kernel/KernelKit/ThreadLocalStorage.h index bf34f39a..6c764221 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.h +++ b/dev/kernel/KernelKit/ThreadLocalStorage.h @@ -7,8 +7,8 @@ #ifndef KERNELKIT_TLS_H #define KERNELKIT_TLS_H -#include <NewKit/Defines.h> -#include <NewKit/ErrorOr.h> +#include <NeKit/Defines.h> +#include <NeKit/ErrorOr.h> ///! @brief Thread Local Storage for neoskrnl. diff --git a/dev/kernel/KernelKit/ThreadLocalStorage.inl b/dev/kernel/KernelKit/ThreadLocalStorage.inl index 553f8d42..7c7a0b7f 100644 --- a/dev/kernel/KernelKit/ThreadLocalStorage.inl +++ b/dev/kernel/KernelKit/ThreadLocalStorage.inl @@ -15,7 +15,7 @@ template <typename T> inline T* tls_new_ptr(void) noexcept { using namespace Kernel; - auto ref_process = UserProcessScheduler::The().CurrentProcess(); + auto ref_process = UserProcessScheduler::The().TheCurrentProcess(); MUST_PASS(ref_process); auto pointer = ref_process.Leak().New(sizeof(T)); @@ -33,7 +33,7 @@ inline Kernel::Bool tls_delete_ptr(T* obj) noexcept { if (!obj) return No; - auto ref_process = UserProcessScheduler::The().CurrentProcess(); + auto ref_process = UserProcessScheduler::The().TheCurrentProcess(); MUST_PASS(ref_process); ErrorOr<T*> obj_wrapped{obj}; diff --git a/dev/kernel/KernelKit/Timer.h b/dev/kernel/KernelKit/Timer.h index d6cfee39..2d040535 100644 --- a/dev/kernel/KernelKit/Timer.h +++ b/dev/kernel/KernelKit/Timer.h @@ -60,16 +60,16 @@ class HardwareTimer final : public TimerInterface { Int64 fWaitFor{0}; }; -inline Int64 rtl_microseconds(Int64 time) { - if (time < 0) return 0; +inline UInt64 rtl_microseconds(UInt64 time) { + if (time < 1) return 0; // TODO: nanoseconds maybe? - return kTimeUnit * time; + return time / kTimeUnit; } -inline Int64 rtl_milliseconds(Int64 time) { - if (time < 0) return 0; +inline UInt64 rtl_milliseconds(UInt64 time) { + if (time < 1) return 0; - return kTimeUnit * kTimeUnit * time; + return time; } } // namespace Kernel diff --git a/dev/kernel/KernelKit/User.h b/dev/kernel/KernelKit/UserMgr.h index 250b1dfc..82f8ca66 100644 --- a/dev/kernel/KernelKit/User.h +++ b/dev/kernel/KernelKit/UserMgr.h @@ -11,22 +11,22 @@ Revision History: - 04/03/25: Set users directory as /user/ instead of /usr/ + 04/03/25: Set users directory as /libSystem/ instead of /usr/ ------------------------------------------- */ #include <CompilerKit/CompilerKit.h> #include <KernelKit/KPC.h> -#include <NewKit/Defines.h> -#include <NewKit/KString.h> +#include <NeKit/Defines.h> +#include <NeKit/KString.h> ///! We got the Super, Standard (%s format) and Guest user, ///! all are used to make authorization operations on the OS. -#define kSuperUser "OS AUTHORITY/SUPER/%s" +#define kSuperUser "OS AUTHORITY/MGMT/%s" #define kGuestUser "OS AUTHORITY/GUEST/%s" #define kStdUser "OS AUTHORITY/STD/%s" -#define kUsersDir "/user/" +#define kUsersDir "/users/" #define kMaxUserNameLen (256U) #define kMaxUserTokenLen (256U) @@ -45,7 +45,7 @@ enum class UserRingKind { typedef Char* UserPublicKey; typedef Char UserPublicKeyType; -/// @brief User class. +/// @brief System User class. class User final { public: User() = delete; @@ -80,12 +80,12 @@ class User final { /// @brief Checks if a password matches the **password**. /// @param password the password to check. - Bool Matches(const UserPublicKey password) noexcept; + Bool Login(const UserPublicKey password) noexcept; private: UserRingKind mUserRing{UserRingKind::kRingStdUser}; Char mUserName[kMaxUserNameLen] = {0}; - Char mUserKey[kMaxUserTokenLen] = {0}; + UInt64 mUserFNV{0UL}; }; } // namespace Kernel diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 3ed3cbfe..14986ab6 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -14,18 +14,8 @@ #include <ArchKit/ArchKit.h> #include <KernelKit/CoreProcessScheduler.h> #include <KernelKit/LockDelegate.h> -#include <KernelKit/User.h> -#include <NewKit/MutableArray.h> - -#define kSchedMinMicroTime (AffinityKind::kStandard) -#define kSchedInvalidPID (-1) -#define kSchedProcessLimitPerTeam (32U) -#define kSchedTeamCount (256U) - -#define kSchedMaxMemoryLimit gib_cast(128) /* max physical memory limit */ -#define kSchedMaxStackSz mib_cast(8) /* maximum stack size */ - -#define kSchedNameLen (128U) +#include <KernelKit/UserMgr.h> +#include <NeKit/MutableArray.h> //////////////////////////////////////////////////// // Last revision date is: Fri Mar 28 2025 // @@ -52,12 +42,12 @@ class USER_PROCESS final { public: Char Name[kSchedNameLen] = {"USER_PROCESS"}; - ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemInvalid}; + ProcessSubsystem SubSystem{ProcessSubsystem::kProcessSubsystemUser}; User* Owner{nullptr}; HAL::StackFramePtr StackFrame{nullptr}; AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatusKind Status{ProcessStatusKind::kKilled}; - UInt8* StackReserve{nullptr}; + UInt8 StackReserve[kSchedMaxStackSz]; PROCESS_IMAGE Image{}; SizeT StackSize{kSchedMaxStackSz}; IDylibObject* DylibDelegate{nullptr}; @@ -65,37 +55,16 @@ class USER_PROCESS final { SizeT MemoryLimit{kSchedMaxMemoryLimit}; SizeT UsedMemory{0UL}; - /// @brief Allocation tracker structure. - struct USER_HEAP_TREE final { - VoidPtr MemoryEntry{nullptr}; - SizeT MemoryEntrySize{0UL}; - SizeT MemoryEntryPad{0UL}; - - enum { - kInvalidMemory = 0, - kRedMemory = 100, - kBlackMemory = 101, - kCountMemory = 2, - }; - - Int32 MemoryColor{kBlackMemory}; - - struct USER_HEAP_TREE* MemoryParent{nullptr}; - struct USER_HEAP_TREE* MemoryChild{nullptr}; - - struct USER_HEAP_TREE* MemoryPrev{nullptr}; - struct USER_HEAP_TREE* MemoryNext{nullptr}; - }; - struct USER_PROCESS_SIGNAL final { - UIntPtr SignalArg; - ProcessStatusKind Status; - UIntPtr SignalID; + UIntPtr SignalArg{0}; + ProcessStatusKind Status{ProcessStatusKind::kKilled}; + UIntPtr SignalID{0}; }; - USER_PROCESS_SIGNAL Signal; - USER_HEAP_TREE* HeapTree{nullptr}; - UserProcessTeam* ParentTeam; + USER_PROCESS_SIGNAL Signal; + PROCESS_FILE_TREE<UInt32*>* FileTree{nullptr}; + PROCESS_HEAP_TREE<VoidPtr>* HeapTree{nullptr}; + UserProcessTeam* ParentTeam; VoidPtr VMRegister{0UL}; @@ -107,7 +76,8 @@ class USER_PROCESS final { }; ProcessTime PTime{0}; //! @brief Process allocated tine. - ProcessTime RTime{0}; //! @brief Process Run time + ProcessTime RTime{0}; //! @brief Process run time. + ProcessTime UTime{0}; //! #brief Process used time. PID ProcessId{kSchedInvalidPID}; Int32 Kind{kExecutableKind}; @@ -123,6 +93,8 @@ class USER_PROCESS final { /***********************************************************************************/ Void Crash(); + Bool SpawnDylib(); + /***********************************************************************************/ ///! @brief Exits the app. /***********************************************************************************/ @@ -215,11 +187,12 @@ class UserProcessScheduler final : public ISchedulable { NE_COPY_DELETE(UserProcessScheduler) NE_MOVE_DELETE(UserProcessScheduler) + public: operator bool(); bool operator!(); public: - UserProcessTeam& CurrentTeam(); + UserProcessTeam& TheCurrentTeam(); BOOL SwitchTeam(UserProcessTeam& team); public: @@ -231,7 +204,7 @@ class UserProcessScheduler final : public ISchedulable { Bool HasMP() override; public: - Ref<USER_PROCESS>& CurrentProcess(); + Ref<USER_PROCESS>& TheCurrentProcess(); SizeT Run() noexcept; public: @@ -249,8 +222,7 @@ class UserProcessScheduler final : public ISchedulable { class UserProcessHelper final { public: - STATIC Bool Switch(VoidPtr image_ptr, UInt8* stack_ptr, HAL::StackFramePtr frame_ptr, - PID new_pid); + STATIC Bool Switch(HAL::StackFramePtr frame_ptr, PID new_pid); STATIC Bool CanBeScheduled(const USER_PROCESS& process); STATIC ErrorOr<PID> TheCurrentPID(); STATIC SizeT StartScheduling(); diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index 2333b898..df35e037 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -11,13 +11,17 @@ /// @author Amlal El Mahrouss (amlal@nekernel.org) /// @date Tue Apr 22 22:01:07 CEST 2025 +#ifndef INC_PROCESS_SCHEDULER_H +#include <KernelKit/UserProcessScheduler.h> +#endif // INC_PROCESS_SCHEDULER_H + namespace Kernel { /***********************************************************************************/ /** @brief Free pointer from usage. */ /***********************************************************************************/ template <typename T> -Boolean USER_PROCESS::Delete(ErrorOr<T*> ptr) { +BOOL USER_PROCESS::Delete(ErrorOr<T*> ptr) { if (!ptr) return No; if (!this->HeapTree) { @@ -25,30 +29,30 @@ Boolean USER_PROCESS::Delete(ErrorOr<T*> ptr) { return No; } - USER_HEAP_TREE* entry = this->HeapTree; + PROCESS_HEAP_TREE<VoidPtr>* entry = this->HeapTree; while (entry != nullptr) { - if (entry->MemoryEntry == ptr.Leak().Leak()) { - this->UsedMemory -= entry->MemoryEntrySize; + if (entry->Entry == ptr.Leak().Leak()) { + this->UsedMemory -= entry->EntrySize; #ifdef __NE_AMD64__ auto pd = hal_read_cr3(); hal_write_cr3(this->VMRegister); - auto ret = mm_delete_heap(entry->MemoryEntry); + auto ret = mm_free_ptr(entry->Entry); hal_write_cr3(pd); return ret == kErrorSuccess; #else - Bool ret = mm_delete_heap(ptr.Leak().Leak()); + Bool ret = mm_free_ptr(ptr.Leak().Leak()); return ret == kErrorSuccess; #endif } - entry = entry->MemoryNext; + entry = entry->Next; } kout << "USER_PROCESS: Trying to free a pointer which doesn't exist.\r"; diff --git a/dev/kernel/KernelKit/XCOFF.h b/dev/kernel/KernelKit/XCOFF.h index 7b15782b..9cfe8ded 100644 --- a/dev/kernel/KernelKit/XCOFF.h +++ b/dev/kernel/KernelKit/XCOFF.h @@ -14,7 +14,7 @@ #ifndef INC_XOCFF_H #define INC_XOCFF_H -#include <NewKit/Defines.h> +#include <NeKit/Defines.h> #define kXCOFF64Magic (0x01F7) #define kXCOFF64ForkNameLen (256U) diff --git a/dev/kernel/KernelKit/ZXD.h b/dev/kernel/KernelKit/ZXD.h new file mode 100644 index 00000000..10af568b --- /dev/null +++ b/dev/kernel/KernelKit/ZXD.h @@ -0,0 +1,43 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <NeKit/Defines.h> + +namespace ZXD { +using namespace Kernel; + +struct ZXD_EXEC_HEADER; +struct ZXD_STUB_HEADER; + +/// @brief ZXD executable header +/// @details This header is used to identify ZXD executable files. +struct ZXD_EXEC_HEADER { + UInt32 fMagic; + UInt32 fVersion; + UInt32 fFlags; + UInt32 fHdrSize; + UInt32 fCRC32; + UInt32 fAssigneeSignature; + UInt32 fIssuerSingature; + UIntPtr fExecOffset; + SizeT fExecSize; + UIntPtr fStubOffset; + SizeT fStubSize; + SizeT fStubAlign; + SizeT fStubCount; +}; + +/// @brief ZXD stub header +/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the +/// offset of the stub, and the CRC32 checksum of the stub. +struct ZXD_STUB_HEADER { + UInt32 fStubSize; + UInt32 fStubOffset; + UInt32 fStubCRC32; +}; +} // namespace ZXD
\ No newline at end of file |
