diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-22 07:38:52 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-22 07:42:26 +0100 |
| commit | 36dee4f0d8ea806b2f061ed66a89e812ab007ed2 (patch) | |
| tree | 8fe0f6895abb96eb40ee390d6411099b4decf489 /src/kernel | |
| parent | f7023f6a08e117d483b5928fd4301062a3384abf (diff) | |
feat: test: Add `kout` test and rename DeviceInterface to IDevice in KernelKit.
introduce UserPtr and unburden vettable by removing the IVettable helper.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel')
33 files changed, 151 insertions, 137 deletions
diff --git a/src/kernel/ArchKit/ArchKit.h b/src/kernel/ArchKit/ArchKit.h index 9d35c445..375c5b44 100644 --- a/src/kernel/ArchKit/ArchKit.h +++ b/src/kernel/ArchKit/ArchKit.h @@ -67,7 +67,7 @@ namespace HAL { } // namespace HAL } // namespace Kernel -typedef Kernel::Void (*rt_syscall_proc)(Kernel::VoidPtr); +using rt_syscall_proc = Kernel::Void (*)(Kernel::VoidPtr); /// @brief System Call Dispatch. struct HAL_DISPATCH_ENTRY final { @@ -81,7 +81,7 @@ struct HAL_DISPATCH_ENTRY final { operator bool() { return fHooked; } }; -typedef Kernel::Void (*rt_kerncall_proc)(Kernel::SizeT, Kernel::VoidPtr, Kernel::SizeT); +using rt_kerncall_proc = Kernel::Void (*)(Kernel::SizeT, Kernel::VoidPtr, Kernel::SizeT); /// @brief Kernel Call Dispatch. struct HAL_KERNEL_DISPATCH_ENTRY final { diff --git a/src/kernel/GfxKit/FB.h b/src/kernel/GfxKit/FB.h index c8a2dc4b..a55a3a5a 100644 --- a/src/kernel/GfxKit/FB.h +++ b/src/kernel/GfxKit/FB.h @@ -31,11 +31,11 @@ struct PACKED FBDevicePacket final { /// @brief Framebuffer device interface. /// @details This class is used to send and receive data from the framebuffer device. -/// @note The class is derived from the DeviceInterface class. +/// @note The class is derived from the IDevice class. class FBDeviceInterface NE_DEVICE<FBDevicePacket*> { public: - explicit FBDeviceInterface(void (*out)(DeviceInterface* self, FBDevicePacket* out), - void (*in)(DeviceInterface* self, FBDevicePacket* in)); + explicit FBDeviceInterface(void (*out)(IDevice* self, FBDevicePacket* out), + void (*in)(IDevice* self, FBDevicePacket* in)); virtual ~FBDeviceInterface() override; diff --git a/src/kernel/HALKit/AMD64/HalDebugOutput.cc b/src/kernel/HALKit/AMD64/HalDebugOutput.cc index f35e7a57..71e20ce6 100644 --- a/src/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/src/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -61,7 +61,7 @@ TerminalDevice::~TerminalDevice() = default; STATIC SizeT kX = kFontSizeX, kY = kFontSizeY; #endif // __DEBUG__ -EXTERN_C void ke_utf_io_write(DeviceInterface<const Utf8Char*>* obj, const Utf8Char* bytes) { +EXTERN_C void ke_utf_io_write(IDevice<const Utf8Char*>* obj, const Utf8Char* bytes) { NE_UNUSED(bytes); NE_UNUSED(obj); @@ -117,7 +117,7 @@ EXTERN_C void ke_utf_io_write(DeviceInterface<const Utf8Char*>* obj, const Utf8C #endif // __DEBUG__ } -EXTERN_C void ke_io_write(DeviceInterface<const Char*>* obj, const Char* bytes) { +EXTERN_C void ke_io_write(IDevice<const Char*>* obj, const Char* bytes) { NE_UNUSED(bytes); NE_UNUSED(obj); @@ -173,7 +173,7 @@ EXTERN_C void ke_io_write(DeviceInterface<const Char*>* obj, const Char* bytes) #endif // __DEBUG__ } -EXTERN_C void ke_io_read(DeviceInterface<const Char*>*, const Char* bytes) { +EXTERN_C void ke_io_read(IDevice<const Char*>*, const Char* bytes) { NE_UNUSED(bytes); #ifdef __DEBUG__ @@ -220,7 +220,7 @@ Utf8TerminalDevice::~Utf8TerminalDevice() = default; Utf8TerminalDevice Utf8TerminalDevice::The() { Utf8TerminalDevice out(Kernel::ke_utf_io_write, - [](DeviceInterface<const Utf8Char*>*, const Utf8Char*) -> Void {}); + [](IDevice<const Utf8Char*>*, const Utf8Char*) -> Void {}); return out; } diff --git a/src/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/src/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index d97884ff..561b03cb 100644 --- a/src/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/src/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -545,7 +545,7 @@ namespace Detail { /// @brief Read AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_ahci(DeviceInterface<IMountpoint*>* self, IMountpoint* mnt) { + STATIC Void sk_io_read_ahci(IDevice<IMountpoint*>* self, IMountpoint* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; err_global_get() = kErrorDisk; @@ -566,7 +566,7 @@ namespace Detail { /// @brief Write AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_ahci(DeviceInterface<IMountpoint*>* self, IMountpoint* mnt) { + STATIC Void sk_io_write_ahci(IDevice<IMountpoint*>* self, IMountpoint* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; err_global_get() = kErrorDisk; diff --git a/src/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/src/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 81a79c6f..a62884f9 100644 --- a/src/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/src/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -197,7 +197,7 @@ namespace Detail { /// @brief Read PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_pio(DeviceInterface<IMountpoint*>* self, IMountpoint* mnt) { + STATIC Void sk_io_read_pio(IDevice<IMountpoint*>* self, IMountpoint* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; @@ -218,7 +218,7 @@ namespace Detail { /// @brief Write PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_pio(DeviceInterface<IMountpoint*>* self, IMountpoint* mnt) { + STATIC Void sk_io_write_pio(IDevice<IMountpoint*>* self, IMountpoint* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; diff --git a/src/kernel/HALKit/ARM64/HalDebugOutput.cc b/src/kernel/HALKit/ARM64/HalDebugOutput.cc index 22a41dbf..2a49bb56 100644 --- a/src/kernel/HALKit/ARM64/HalDebugOutput.cc +++ b/src/kernel/HALKit/ARM64/HalDebugOutput.cc @@ -10,7 +10,7 @@ #include <NeKit/Utils.h> namespace Kernel { -EXTERN_C void ke_io_write(DeviceInterface<const Char*>* self, const Char* bytes) { +EXTERN_C void ke_io_write(IDevice<const Char*>* self, const Char* bytes) { #ifdef __DEBUG__ if (*bytes == 0) return; @@ -33,7 +33,7 @@ EXTERN_C void ke_io_write(DeviceInterface<const Char*>* self, const Char* bytes) TerminalDevice::~TerminalDevice() = default; -EXTERN_C void ke_io_read(DeviceInterface<const Char*>* self, const Char* bytes) { +EXTERN_C void ke_io_read(IDevice<const Char*>* self, const Char* bytes) { #ifdef __DEBUG__ SizeT index = 0; diff --git a/src/kernel/KernelKit/DebugOutput.h b/src/kernel/KernelKit/DebugOutput.h index 301a3a9e..0818a712 100644 --- a/src/kernel/KernelKit/DebugOutput.h +++ b/src/kernel/KernelKit/DebugOutput.h @@ -25,9 +25,8 @@ inline TerminalDevice hex_number(const Long& x); // @brief Emulates a VT100 terminal. class TerminalDevice final NE_DEVICE<const Char*> { public: - TerminalDevice(void (*print)(DeviceInterface*, const Char*), - void (*gets)(DeviceInterface*, const Char*)) - : DeviceInterface<const Char*>(print, gets) {} + TerminalDevice(void (*print)(IDevice*, const Char*), void (*gets)(IDevice*, const Char*)) + : IDevice<const Char*>(print, gets) {} ~TerminalDevice() override; @@ -42,9 +41,9 @@ class TerminalDevice final NE_DEVICE<const Char*> { class Utf8TerminalDevice final NE_DEVICE<const Utf8Char*> { public: - Utf8TerminalDevice(void (*print)(DeviceInterface*, const Utf8Char*), - void (*gets)(DeviceInterface*, const Utf8Char*)) - : DeviceInterface<const Utf8Char*>(print, gets) {} + Utf8TerminalDevice(void (*print)(IDevice*, const Utf8Char*), + void (*gets)(IDevice*, const Utf8Char*)) + : IDevice<const Utf8Char*>(print, gets) {} ~Utf8TerminalDevice() override; diff --git a/src/kernel/KernelKit/DeviceMgr.h b/src/kernel/KernelKit/DeviceMgr.h index 1dbad161..56208140 100644 --- a/src/kernel/KernelKit/DeviceMgr.h +++ b/src/kernel/KernelKit/DeviceMgr.h @@ -24,13 +24,13 @@ #define kDeviceMgrRootDirPath "/devices/" -#define NE_DEVICE : public ::Kernel::DeviceInterface +#define NE_DEVICE : public ::Kernel::IDevice // Last Rev: Wed, May 27, 2025 6:22 PM namespace Kernel { template <typename T> -class DeviceInterface; +class IDevice; template <typename T> class IOBuf; @@ -39,26 +39,30 @@ class IOBuf; /// @brief Device contract interface, represents an HW device. /***********************************************************************************/ template <typename T> -class DeviceInterface { +class IDevice { public: - DeviceInterface() = default; + IDevice() = default; - explicit DeviceInterface(void (*Out)(DeviceInterface<T>*, T), void (*In)(DeviceInterface<T>*, T)) - : fOut(Out), fIn(In) {} + explicit IDevice(void (*Out)(IDevice<T>*, T), void (*In)(IDevice<T>*, T)) : fOut(Out), fIn(In) {} - virtual ~DeviceInterface() = default; + virtual ~IDevice() = default; public: - DeviceInterface& operator=(const DeviceInterface<T>&) = default; - DeviceInterface(const DeviceInterface<T>&) = default; + using Type = T; + using TypeRef = T&; + using ConstType = const T&; + using TypePtr = T*; + + IDevice& operator=(const IDevice<T>&) = default; + IDevice(const IDevice<T>&) = default; public: - virtual DeviceInterface<T>& operator<<(T Data) { + virtual IDevice<T>& operator<<(T Data) { fOut(this, Data); return *this; } - virtual DeviceInterface<T>& operator>>(T Data) { + virtual IDevice<T>& operator>>(T Data) { fIn(this, Data); return *this; } @@ -70,8 +74,8 @@ class DeviceInterface { Bool operator!() { return !fOut || !fIn; } protected: - Void (*fOut)(DeviceInterface<T>*, T Data) = {nullptr}; - Void (*fIn)(DeviceInterface<T>*, T Data) = {nullptr}; + Void (*fOut)(IDevice<T>*, T Data) = {nullptr}; + Void (*fIn)(IDevice<T>*, T Data) = {nullptr}; }; /// diff --git a/src/kernel/KernelKit/PE32CodeMgr.h b/src/kernel/KernelKit/PE32CodeMgr.h index 03a68363..c62cd518 100644 --- a/src/kernel/KernelKit/PE32CodeMgr.h +++ b/src/kernel/KernelKit/PE32CodeMgr.h @@ -66,7 +66,7 @@ class PE32Loader : public ILoader { ErrorOr<VoidPtr> GetBlob() override; public: - bool IsLoaded(); + BOOL IsLoaded(); private: #ifdef __FSKIT_INCLUDES_NEFS__ @@ -78,14 +78,15 @@ class PE32Loader : public ILoader { #endif // __FSKIT_INCLUDES_NEFS__ Ref<KString> fPath; - VoidPtr fCachedBlob; - BOOL fBad; + RefAny fCachedBlob{}; + BOOL fBad{}; }; enum { kPEPlatformInvalid, kPEPlatformAMD64 = 100, kPEPlatformARM64 }; enum { kPETypeInvalid, kPETypeText = 100, kPETypeData, kPETypeBSS }; -typedef LDR_SECTION_HEADER PE_SECTION_INFO; +using PE_SECTION_INFO = LDR_SECTION_HEADER; -ProcessID rtl_create_user_process(PE32Loader& exec, const Int32& process_kind); +ProcessID rtl_create_user_process(PE32Loader& exec, + const UserProcess::ExecutableKind& process_kind); } // namespace Kernel
\ No newline at end of file diff --git a/src/kernel/KernelKit/PEFCodeMgr.h b/src/kernel/KernelKit/PEFCodeMgr.h index f7b6672a..db19eb0d 100644 --- a/src/kernel/KernelKit/PEFCodeMgr.h +++ b/src/kernel/KernelKit/PEFCodeMgr.h @@ -68,7 +68,7 @@ class PEFLoader : public ILoader { }; namespace Utils { - ProcessID rtl_create_user_process(PEFLoader& exec, const Int32& procKind); + ProcessID rtl_create_user_process(PEFLoader& exec, const UserProcess::ExecutableKind& procKind); } // namespace Utils } // namespace Kernel diff --git a/src/kernel/KernelKit/TraceSrv.h b/src/kernel/KernelKit/TraceSrv.h index 389357ec..2dced719 100644 --- a/src/kernel/KernelKit/TraceSrv.h +++ b/src/kernel/KernelKit/TraceSrv.h @@ -12,9 +12,9 @@ namespace Kernel { namespace Detail { - inline constexpr auto kDebugCmdLen = 256U; - inline constexpr auto kDebugPort = 51820; - /// \brief Debug Magic Value + inline constexpr auto kDebugCmdLen = 256U; + inline constexpr auto kDebugPort = 51820; + /// \brief Debug Magic Value inline constexpr auto kDebugMagic = "NE1.0.0;"; inline constexpr auto kDebugVersion = 0x0100; inline constexpr auto kDebugDelim = ';'; diff --git a/src/kernel/KernelKit/UserMgr.h b/src/kernel/KernelKit/UserMgr.h index 77356aae..8f14fe9d 100644 --- a/src/kernel/KernelKit/UserMgr.h +++ b/src/kernel/KernelKit/UserMgr.h @@ -88,8 +88,14 @@ class User final { UInt64 mUserFNV{0UL}; }; +/// \brief Alias for user ptr. +using UserPtr = User*; + +/// \brief Current running user. inline User* kCurrentUser = nullptr; -inline User* kRootUser = nullptr; + +/// \brief Super user. +inline User* kRootUser = nullptr; } // namespace Kernel #endif /* ifndef __KERNEL_KIT_USER_MGR_H__ */ diff --git a/src/kernel/KernelKit/UserProcessScheduler.h b/src/kernel/KernelKit/UserProcessScheduler.h index c8790352..9a679c87 100644 --- a/src/kernel/KernelKit/UserProcessScheduler.h +++ b/src/kernel/KernelKit/UserProcessScheduler.h @@ -32,7 +32,7 @@ class UserProcessHelper; /// @name UserProcess /// @brief UserProcess class, holds information about the running process/thread. /***********************************************************************************/ -class UserProcess NE_VETTABLE { +class UserProcess { public: UserProcess(); ~UserProcess(); @@ -55,20 +55,23 @@ class UserProcess NE_VETTABLE { SizeT MemoryLimit{kSchedMaxMemoryLimit}; SizeT UsedMemory{0UL}; - struct USER_PROCESS_SIGNAL final { + struct UserProcessSignal { UIntPtr SignalArg{0}; ProcessStatusKind Status{ProcessStatusKind::kKilled}; UIntPtr SignalID{0}; }; - USER_PROCESS_SIGNAL Signal; + UserProcessSignal Signal; ProcessFileTree<VoidPtr>* FileTree{nullptr}; ProcessHeapTree<VoidPtr>* HeapTree{nullptr}; UserProcessTeam* ParentTeam; + public: + using VMReg = VoidPtr; + VoidPtr VMRegister{0UL}; - enum { + enum struct ExecutableKind { kInvalidExecutableKind, kExecutableKind, kExecutableDylibKind, @@ -79,8 +82,8 @@ class UserProcess NE_VETTABLE { ProcessTime RTime{0}; //! @brief Process run time. ProcessTime UTime{0}; //! #brief Process used time. - ProcessID ProcessId{kSchedInvalidPID}; - Int32 Kind{kExecutableKind}; + ProcessID ProcessId{kSchedInvalidPID}; + ExecutableKind Kind{ExecutableKind::kExecutableKind}; public: /***********************************************************************************/ diff --git a/src/kernel/NeKit/Config.h b/src/kernel/NeKit/Config.h index 79dbf411..e4e34e2c 100644 --- a/src/kernel/NeKit/Config.h +++ b/src/kernel/NeKit/Config.h @@ -191,6 +191,9 @@ template <class Type> struct FalseResult final { using ResultType = Type; using ResultTypeRef = ResultType&; + using TypeRef = ResultTypeRef; + using ConstType = const Type&; + using TypePtr = Type*; static constexpr bool kValue = false; }; @@ -199,6 +202,9 @@ template <class Type> struct TrueResult final { using ResultType = Type; using ResultTypeRef = ResultType&; + using TypeRef = ResultTypeRef; + using ConstType = const Type&; + using TypePtr = Type*; static constexpr bool kValue = true; }; @@ -207,6 +213,9 @@ template <class Type> struct PropertyResult final { using ResultType = Type; using ResultTypeRef = ResultType&; + using TypeRef = ResultTypeRef; + using ConstType = const Type&; + using TypePtr = Type*; static constexpr bool kValue = Type::kValue; }; diff --git a/src/kernel/NeKit/Ref.h b/src/kernel/NeKit/Ref.h index b4d6cb5e..2010f3e9 100644 --- a/src/kernel/NeKit/Ref.h +++ b/src/kernel/NeKit/Ref.h @@ -26,7 +26,9 @@ class Ref final { ~Ref() = default; public: - using Type = T; + using Type = T; + using ConstType = const T&; + using RefType = T&; Ref(Type* cls) : fClass(*cls) {} Ref(Type cls) : fClass(cls) {} @@ -50,7 +52,10 @@ class Ref final { Type& Leak() { return fClass; } - Type& TryLeak() { return fClass; } + Type& TryLeak() { + MUST_PASS(fClass); + return fClass; + } Type operator*() { return fClass; } diff --git a/src/kernel/NeKit/Variant.h b/src/kernel/NeKit/Variant.h index 5747e9ca..c7aa509c 100644 --- a/src/kernel/NeKit/Variant.h +++ b/src/kernel/NeKit/Variant.h @@ -50,9 +50,9 @@ class Variant final { /// ======================================================================== /// @brief Returns the underlying pointer. - /// @return the underlying pointer. + /// @return the underlying pointer as a reference. /// ======================================================================== - VoidPtr Leak(); + RefAny Leak(); template <typename T> T* As() { diff --git a/src/kernel/NeKit/Vettable.h b/src/kernel/NeKit/Vettable.h index 8290b318..e4c09624 100644 --- a/src/kernel/NeKit/Vettable.h +++ b/src/kernel/NeKit/Vettable.h @@ -11,29 +11,16 @@ #include <CompilerKit/CompilerKit.h> #include <NeKit/Config.h> -#define NE_VETTABLE \ - final: \ - public \ - ::Kernel::IVettable - namespace Kernel { -struct IVettable { - explicit IVettable() = default; - virtual ~IVettable() = default; - - NE_COPY_DEFAULT(IVettable) -}; - template <class Type> struct Vettable final { using ResultType = Type; + using TypeRef = Type&; + using ConstType = const Type&; + using TypePtr = Type*; - static constexpr BOOL kValue = NO; -}; -template <> -struct Vettable<IVettable> final { - static constexpr BOOL kValue = YES; + static constexpr BOOL kValue = NO; }; template <class Type> diff --git a/src/kernel/NetworkKit/NetworkDevice.h b/src/kernel/NetworkKit/NetworkDevice.h index 3afa8484..62d3229b 100644 --- a/src/kernel/NetworkKit/NetworkDevice.h +++ b/src/kernel/NetworkKit/NetworkDevice.h @@ -21,8 +21,8 @@ class NetworkDevice; */ class NetworkDevice final NE_DEVICE<NetworkDeviceCommand> { public: - NetworkDevice(void (*out)(DeviceInterface<NetworkDeviceCommand>*, NetworkDeviceCommand), - void (*in)(DeviceInterface<NetworkDeviceCommand>*, NetworkDeviceCommand), + NetworkDevice(void (*out)(IDevice<NetworkDeviceCommand>*, NetworkDeviceCommand), + void (*in)(IDevice<NetworkDeviceCommand>*, NetworkDeviceCommand), void (*cleanup)(void) = nullptr); ~NetworkDevice() override; diff --git a/src/kernel/NetworkKit/NetworkDevice.inl b/src/kernel/NetworkKit/NetworkDevice.inl index a86d7e56..b57012c9 100644 --- a/src/kernel/NetworkKit/NetworkDevice.inl +++ b/src/kernel/NetworkKit/NetworkDevice.inl @@ -13,12 +13,10 @@ #endif // __INC_NETWORK_DEVICE_H__ namespace Kernel { -inline NetworkDevice::NetworkDevice(void (*out)(DeviceInterface<NetworkDeviceCommand>*, - NetworkDeviceCommand), - void (*in)(DeviceInterface<NetworkDeviceCommand>*, - NetworkDeviceCommand), - void (*on_cleanup)(void)) - : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) { +inline NetworkDevice::NetworkDevice( + void (*out)(IDevice<NetworkDeviceCommand>*, NetworkDeviceCommand), + void (*in)(IDevice<NetworkDeviceCommand>*, NetworkDeviceCommand), void (*on_cleanup)(void)) + : IDevice<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) { kout << "NetworkDevice initialized.\r"; MUST_PASS(out && in && on_cleanup); diff --git a/src/kernel/StorageKit/AHCI.h b/src/kernel/StorageKit/AHCI.h index 82bd9747..d29cb0fc 100644 --- a/src/kernel/StorageKit/AHCI.h +++ b/src/kernel/StorageKit/AHCI.h @@ -13,11 +13,11 @@ namespace Kernel { /// @brief AHCIDeviceInterface class /// @details This class is used to send and receive data from the AHCI device. -/// @note The class is derived from the DeviceInterface class. +/// @note The class is derived from the IDevice class. class AHCIDeviceInterface NE_DEVICE<IMountpoint*> { public: - explicit AHCIDeviceInterface(void (*out)(DeviceInterface* self, IMountpoint* out), - void (*in)(DeviceInterface* self, IMountpoint* in)); + explicit AHCIDeviceInterface(void (*out)(IDevice* self, IMountpoint* out), + void (*in)(IDevice* self, IMountpoint* in)); virtual ~AHCIDeviceInterface() override; @@ -28,12 +28,10 @@ class AHCIDeviceInterface NE_DEVICE<IMountpoint*> { const Char* Name() const override; const UInt16& GetPortsImplemented(); - - Void SetPortsImplemented(const UInt16& pi); + Void SetPortsImplemented(const UInt16& pi); const UInt32& GetIndex(); - - Void SetIndex(const UInt32& drv); + Void SetIndex(const UInt32& drv); public: AHCIDeviceInterface& operator<<(IMountpoint* Data) override; diff --git a/src/kernel/StorageKit/ATA.h b/src/kernel/StorageKit/ATA.h index f92e09d3..729cf4f7 100644 --- a/src/kernel/StorageKit/ATA.h +++ b/src/kernel/StorageKit/ATA.h @@ -13,10 +13,10 @@ namespace Kernel { /// @brief ATA device interface class. -class ATADeviceInterface : public DeviceInterface<IMountpoint*> { +class ATADeviceInterface : public IDevice<IMountpoint*> { public: - explicit ATADeviceInterface(void (*Out)(DeviceInterface*, IMountpoint* outpacket), - void (*In)(DeviceInterface*, IMountpoint* inpacket)); + explicit ATADeviceInterface(void (*Out)(IDevice*, IMountpoint* outpacket), + void (*In)(IDevice*, IMountpoint* inpacket)); virtual ~ATADeviceInterface(); diff --git a/src/kernel/StorageKit/NVME.h b/src/kernel/StorageKit/NVME.h index d1c036ab..3a4ced1e 100644 --- a/src/kernel/StorageKit/NVME.h +++ b/src/kernel/StorageKit/NVME.h @@ -12,9 +12,8 @@ namespace Kernel { class NVMEDeviceInterface final NE_DEVICE<IMountpoint*> { public: - explicit NVMEDeviceInterface(Void (*out)(DeviceInterface*, IMountpoint* out_packet), - Void (*in)(DeviceInterface*, IMountpoint* in_packet), - Void (*cleanup)(Void)); + explicit NVMEDeviceInterface(Void (*out)(IDevice*, IMountpoint* out_packet), + Void (*in)(IDevice*, IMountpoint* in_packet), Void (*cleanup)(Void)); ~NVMEDeviceInterface() override; diff --git a/src/kernel/StorageKit/SCSI.h b/src/kernel/StorageKit/SCSI.h index f31d36f0..3354a678 100644 --- a/src/kernel/StorageKit/SCSI.h +++ b/src/kernel/StorageKit/SCSI.h @@ -13,9 +13,8 @@ namespace Kernel { class SCSIDeviceInterface final NE_DEVICE<IMountpoint*> { public: - explicit SCSIDeviceInterface(Void (*out)(DeviceInterface*, IMountpoint* out_packet), - Void (*in)(DeviceInterface*, IMountpoint* in_packet), - Void (*cleanup)(Void)); + explicit SCSIDeviceInterface(Void (*out)(IDevice*, IMountpoint* out_packet), + Void (*in)(IDevice*, IMountpoint* in_packet), Void (*cleanup)(Void)); ~SCSIDeviceInterface() override; diff --git a/src/kernel/StorageKit/StorageKit.h b/src/kernel/StorageKit/StorageKit.h index c9633392..d7a1b6e9 100644 --- a/src/kernel/StorageKit/StorageKit.h +++ b/src/kernel/StorageKit/StorageKit.h @@ -12,7 +12,7 @@ namespace Kernel { template <typename T> -class DeviceInterface; +class IDevice; class NVMEDeviceInterface; class AHCIDeviceInterface; diff --git a/src/kernel/src/Gfx/FBDeviceInterface.cc b/src/kernel/src/Gfx/FBDeviceInterface.cc index c5fac330..a43d08f0 100644 --- a/src/kernel/src/Gfx/FBDeviceInterface.cc +++ b/src/kernel/src/Gfx/FBDeviceInterface.cc @@ -12,9 +12,9 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -FBDeviceInterface::FBDeviceInterface(void (*out)(DeviceInterface* self, FBDevicePacket* outpacket), - void (*in)(DeviceInterface* self, FBDevicePacket* inpacket)) - : DeviceInterface(out, in) {} +FBDeviceInterface::FBDeviceInterface(void (*out)(IDevice* self, FBDevicePacket* outpacket), + void (*in)(IDevice* self, FBDevicePacket* inpacket)) + : IDevice(out, in) {} /// @brief Class desctructor FBDeviceInterface::~FBDeviceInterface() = default; diff --git a/src/kernel/src/PE32CodeMgr.cc b/src/kernel/src/PE32CodeMgr.cc index 1aef8b0d..3cf43270 100644 --- a/src/kernel/src/PE32CodeMgr.cc +++ b/src/kernel/src/PE32CodeMgr.cc @@ -37,7 +37,7 @@ namespace Detail { /***********************************************************************************/ PE32Loader::PE32Loader(const VoidPtr blob) : fCachedBlob(blob) { - MUST_PASS(fCachedBlob); + (Void) fCachedBlob.TryLeak(); fBad = false; } @@ -46,7 +46,7 @@ PE32Loader::PE32Loader(const VoidPtr blob) : fCachedBlob(blob) { /// @param path the filesystem path. /***********************************************************************************/ -PE32Loader::PE32Loader(const Char* path) : fCachedBlob(nullptr), fBad(false) { +PE32Loader::PE32Loader(const Char* path) : fCachedBlob(static_cast<VoidPtr>(nullptr)), fBad(false) { fFile.New(const_cast<Char*>(path), kRestrictRB); fPath = KStringBuilder::Construct(path).Leak(); @@ -61,7 +61,7 @@ PE32Loader::PE32Loader(const Char* path) : fCachedBlob(nullptr), fBad(false) { /***********************************************************************************/ PE32Loader::~PE32Loader() { - if (fCachedBlob) mm_free_ptr(fCachedBlob); + if (fCachedBlob) mm_free_ptr(fCachedBlob.Leak()); fFile.Reset(); } @@ -74,8 +74,9 @@ PE32Loader::~PE32Loader() { ErrorOr<VoidPtr> PE32Loader::FindSectionByName(const Char* name) { if (!fCachedBlob || fBad || !name) return ErrorOr<VoidPtr>{kErrorInvalidData}; - LDR_EXEC_HEADER_PTR header_ptr = CF::ldr_find_exec_header((const Char*) fCachedBlob); - LDR_OPTIONAL_HEADER_PTR opt_header_ptr = CF::ldr_find_opt_exec_header((const Char*) fCachedBlob); + LDR_EXEC_HEADER_PTR header_ptr = CF::ldr_find_exec_header((const Char*) fCachedBlob.Leak()); + LDR_OPTIONAL_HEADER_PTR opt_header_ptr = + CF::ldr_find_opt_exec_header((const Char*) fCachedBlob.Leak()); if (!header_ptr || !opt_header_ptr) return ErrorOr<VoidPtr>{kErrorInvalidData}; @@ -138,7 +139,8 @@ ErrorOr<VoidPtr> PE32Loader::FindSymbol(const Char* name, Int32 kind) { if (!sec_ptr || !*sec_ptr) return ErrorOr<VoidPtr>{kErrorInvalidData}; - LDR_OPTIONAL_HEADER_PTR opt_header_ptr = CF::ldr_find_opt_exec_header((const Char*) fCachedBlob); + LDR_OPTIONAL_HEADER_PTR opt_header_ptr = + CF::ldr_find_opt_exec_header((const Char*) fCachedBlob.Leak()); if (opt_header_ptr) { LDR_DATA_DIRECTORY_PTR data_dirs = @@ -150,20 +152,22 @@ ErrorOr<VoidPtr> PE32Loader::FindSymbol(const Char* name, Int32 kind) { return ErrorOr<VoidPtr>{kErrorInvalidData}; LDR_EXPORT_DIRECTORY* export_dir = - (LDR_EXPORT_DIRECTORY*) ((UIntPtr) fCachedBlob + export_dir_entry->VirtualAddress); + (LDR_EXPORT_DIRECTORY*) ((UIntPtr) fCachedBlob.Leak() + export_dir_entry->VirtualAddress); - UInt32* name_table = (UInt32*) ((UIntPtr) fCachedBlob + export_dir->AddressOfNames); - UInt16* ordinal_table = (UInt16*) ((UIntPtr) fCachedBlob + export_dir->AddressOfNameOrdinal); - UInt32* function_table = (UInt32*) ((UIntPtr) fCachedBlob + export_dir->AddressOfFunctions); + UInt32* name_table = (UInt32*) ((UIntPtr) fCachedBlob.Leak() + export_dir->AddressOfNames); + UInt16* ordinal_table = + (UInt16*) ((UIntPtr) fCachedBlob.Leak() + export_dir->AddressOfNameOrdinal); + UInt32* function_table = + (UInt32*) ((UIntPtr) fCachedBlob.Leak() + export_dir->AddressOfFunctions); for (UInt32 i = 0; i < export_dir->NumberOfNames; ++i) { - const char* exported_name = (const char*) ((UIntPtr) fCachedBlob + name_table[i]); + const char* exported_name = (const char*) ((UIntPtr) fCachedBlob.Leak() + name_table[i]); if (KStringBuilder::Equals(exported_name, name)) { UInt16 ordinal = ordinal_table[i]; UInt32 rva = function_table[ordinal]; - VoidPtr symbol_addr = (VoidPtr) ((UIntPtr) fCachedBlob + rva); + VoidPtr symbol_addr = (VoidPtr) ((UIntPtr) fCachedBlob.Leak() + rva); return ErrorOr<VoidPtr>{symbol_addr}; } @@ -212,11 +216,12 @@ const Char* PE32Loader::MIME() { } ErrorOr<VoidPtr> PE32Loader::GetBlob() { - return ErrorOr<VoidPtr>{this->fCachedBlob}; + return ErrorOr<VoidPtr>{this->fCachedBlob.TryLeak()}; } namespace Utils { - ProcessID rtl_create_user_process(PE32Loader& exec, const Int32& process_kind) { + ProcessID rtl_create_user_process(PE32Loader& exec, + const UserProcess::ExecutableKind& process_kind) { auto errOrStart = exec.FindStart(); if (errOrStart.Error() != kErrorSuccess) return kSchedInvalidPID; diff --git a/src/kernel/src/PEFCodeMgr.cc b/src/kernel/src/PEFCodeMgr.cc index 7f87b58a..a373441b 100644 --- a/src/kernel/src/PEFCodeMgr.cc +++ b/src/kernel/src/PEFCodeMgr.cc @@ -294,7 +294,8 @@ ErrorOr<VoidPtr> PEFLoader::GetBlob() { } namespace Utils { - ProcessID rtl_create_user_process(PEFLoader& exec, const Int32& process_kind) { + ProcessID rtl_create_user_process(PEFLoader& exec, + const UserProcess::ExecutableKind& process_kind) { auto errOrStart = exec.FindStart(); if (errOrStart.Error() != kErrorSuccess) return kSchedInvalidPID; diff --git a/src/kernel/src/Storage/AHCIDeviceInterface.cc b/src/kernel/src/Storage/AHCIDeviceInterface.cc index 4faad175..2ec993aa 100644 --- a/src/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/src/kernel/src/Storage/AHCIDeviceInterface.cc @@ -12,9 +12,9 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(DeviceInterface* self, IMountpoint* outpacket), - void (*in)(DeviceInterface* self, IMountpoint* inpacket)) - : DeviceInterface(out, in) {} +AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(IDevice* self, IMountpoint* outpacket), + void (*in)(IDevice* self, IMountpoint* inpacket)) + : IDevice(out, in) {} /// @brief Class desctructor AHCIDeviceInterface::~AHCIDeviceInterface() = default; @@ -43,7 +43,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator<<(IMountpoint* mnt) { } } - return (AHCIDeviceInterface&) DeviceInterface<IMountpoint*>::operator<<(mnt); + return (AHCIDeviceInterface&) IDevice<IMountpoint*>::operator<<(mnt); } /// @brief Input operator. @@ -65,7 +65,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator>>(IMountpoint* mnt) { } } - return (AHCIDeviceInterface&) DeviceInterface<IMountpoint*>::operator>>(mnt); + return (AHCIDeviceInterface&) IDevice<IMountpoint*>::operator>>(mnt); } const UInt16& AHCIDeviceInterface::GetPortsImplemented() { diff --git a/src/kernel/src/Storage/ATADeviceInterface.cc b/src/kernel/src/Storage/ATADeviceInterface.cc index 8e15fdea..16e0afda 100644 --- a/src/kernel/src/Storage/ATADeviceInterface.cc +++ b/src/kernel/src/Storage/ATADeviceInterface.cc @@ -12,9 +12,9 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -ATADeviceInterface::ATADeviceInterface(void (*Out)(DeviceInterface*, IMountpoint* outpacket), - void (*In)(DeviceInterface*, IMountpoint* inpacket)) - : DeviceInterface(Out, In) {} +ATADeviceInterface::ATADeviceInterface(void (*Out)(IDevice*, IMountpoint* outpacket), + void (*In)(IDevice*, IMountpoint* inpacket)) + : IDevice(Out, In) {} /// @brief Class desctructor ATADeviceInterface::~ATADeviceInterface() = default; @@ -43,7 +43,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(IMountpoint* Data) { } } - return (ATADeviceInterface&) DeviceInterface<IMountpoint*>::operator<<(Data); + return (ATADeviceInterface&) IDevice<IMountpoint*>::operator<<(Data); } /// @brief Input operator. @@ -65,7 +65,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(IMountpoint* Data) { } } - return (ATADeviceInterface&) DeviceInterface<IMountpoint*>::operator>>(Data); + return (ATADeviceInterface&) IDevice<IMountpoint*>::operator>>(Data); } const UInt32& ATADeviceInterface::GetIndex() { diff --git a/src/kernel/src/Storage/NVMEDeviceInterface.cc b/src/kernel/src/Storage/NVMEDeviceInterface.cc index 12d9e363..6258ca7e 100644 --- a/src/kernel/src/Storage/NVMEDeviceInterface.cc +++ b/src/kernel/src/Storage/NVMEDeviceInterface.cc @@ -7,10 +7,10 @@ #include <StorageKit/NVME.h> namespace Kernel { -NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(DeviceInterface*, IMountpoint* outpacket), - void (*in)(DeviceInterface*, IMountpoint* inpacket), +NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(IDevice*, IMountpoint* outpacket), + void (*in)(IDevice*, IMountpoint* inpacket), void (*cleanup)(void)) - : DeviceInterface(out, in), fCleanup(cleanup) {} + : IDevice(out, in), fCleanup(cleanup) {} NVMEDeviceInterface::~NVMEDeviceInterface() { if (fCleanup) fCleanup(); diff --git a/src/kernel/src/Storage/SCSIDeviceInterface.cc b/src/kernel/src/Storage/SCSIDeviceInterface.cc index 921e660a..e74d429b 100644 --- a/src/kernel/src/Storage/SCSIDeviceInterface.cc +++ b/src/kernel/src/Storage/SCSIDeviceInterface.cc @@ -7,10 +7,10 @@ #include <StorageKit/SCSI.h> namespace Kernel { -SCSIDeviceInterface::SCSIDeviceInterface(void (*out)(DeviceInterface*, IMountpoint* outpacket), - void (*in)(DeviceInterface*, IMountpoint* inpacket), +SCSIDeviceInterface::SCSIDeviceInterface(void (*out)(IDevice*, IMountpoint* outpacket), + void (*in)(IDevice*, IMountpoint* inpacket), void (*cleanup)(void)) - : DeviceInterface(out, in), fCleanup(cleanup) {} + : IDevice(out, in), fCleanup(cleanup) {} SCSIDeviceInterface::~SCSIDeviceInterface() { if (fCleanup) fCleanup(); diff --git a/src/kernel/src/UserProcessScheduler.cc b/src/kernel/src/UserProcessScheduler.cc index 97445251..cf3c27e9 100644 --- a/src/kernel/src/UserProcessScheduler.cc +++ b/src/kernel/src/UserProcessScheduler.cc @@ -301,7 +301,7 @@ Void UserProcess::Exit(const Int32& exit_code) { this->Image.fCode = nullptr; this->StackFrame = nullptr; - if (this->Kind == kExecutableDylibKind) { + if (this->Kind == ExecutableKind::kExecutableDylibKind) { Bool success = false; rtl_fini_dylib_pef(*this, reinterpret_cast<IPEFDylibObject*>(this->DylibDelegate), &success); @@ -320,13 +320,13 @@ Void UserProcess::Exit(const Int32& exit_code) { } /***********************************************************************************/ -/// @brief Add dylib to the process object. +/// @brief Initializer dylib of User Process. /***********************************************************************************/ Bool UserProcess::InitDylib() { // React according to the process's kind. switch (this->Kind) { - case UserProcess::kExecutableDylibKind: { + case ExecutableKind::kExecutableDylibKind: { this->DylibDelegate = rtl_init_dylib_pef(*this); if (!this->DylibDelegate) { @@ -336,7 +336,7 @@ Bool UserProcess::InitDylib() { return YES; } - case UserProcess::kExecutableKind: { + case ExecutableKind::kExecutableKind: { return NO; } default: { @@ -344,7 +344,7 @@ Bool UserProcess::InitDylib() { } } - (Void)(kout << "Unknown process kind: " << hex_number(this->Kind) << kendl); + (Void)(kout << "Unknown process kind: " << hex_number(static_cast<Int32>(this->Kind)) << kendl); this->Crash(); return NO; diff --git a/src/kernel/src/Variant.cc b/src/kernel/src/Variant.cc index fcf2f443..05bacf8c 100644 --- a/src/kernel/src/Variant.cc +++ b/src/kernel/src/Variant.cc @@ -32,7 +32,7 @@ Variant::VariantKind& Variant::Kind() { } /// @brief Leak variant's instance. -VoidPtr Variant::Leak() { - return this->fPtr; +RefAny Variant::Leak() { + return {this->fPtr}; } } // namespace Kernel |
