From 81027667166d9624ee12f45f011426678d1bbbf4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 29 May 2025 17:19:57 +0200 Subject: feat: Improve libSystem's architecture and implementation. fix: Fix NeKit's Ref, and ErrorOr classes. fix: Fix userland tools. next: - Finish the latest tickets and then release nekernel 0.0.3 Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/HardwareThreadScheduler.cc | 4 ++-- dev/kernel/src/KString.cc | 2 +- dev/kernel/src/Pmm.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/HardwareThreadScheduler.cc b/dev/kernel/src/HardwareThreadScheduler.cc index 78bad9d6..e3255326 100644 --- a/dev/kernel/src/HardwareThreadScheduler.cc +++ b/dev/kernel/src/HardwareThreadScheduler.cc @@ -20,7 +20,7 @@ namespace Kernel { /// @note Those symbols are needed in order to switch and validate the stack. /***********************************************************************************/ -EXTERN_C Bool hal_check_stack(HAL::StackFramePtr frame); +EXTERN_C Bool hal_check_task(HAL::StackFramePtr frame); EXTERN_C Bool mp_register_task(HAL::StackFramePtr frame, ProcessID pid); STATIC HardwareThreadScheduler kHardwareThreadScheduler; @@ -96,7 +96,7 @@ Bool HardwareThread::Switch(HAL::StackFramePtr frame) { return NO; } - if (!hal_check_stack(frame)) { + if (!hal_check_task(frame)) { return NO; } diff --git a/dev/kernel/src/KString.cc b/dev/kernel/src/KString.cc index 9f332cdf..f5732280 100644 --- a/dev/kernel/src/KString.cc +++ b/dev/kernel/src/KString.cc @@ -64,7 +64,7 @@ bool KString::operator!=(const Char* rhs) const { } ErrorOr KStringBuilder::Construct(const Char* data) { - if (!data || *data == 0) return {}; + if (!data || *data == 0) return ErrorOr(new KString(0)); KString* view = new KString(rt_string_len(data)); (*view) += data; diff --git a/dev/kernel/src/Pmm.cc b/dev/kernel/src/Pmm.cc index b9fba20e..7f5050f9 100644 --- a/dev/kernel/src/Pmm.cc +++ b/dev/kernel/src/Pmm.cc @@ -35,7 +35,7 @@ Ref Pmm::RequestPage(Boolean user, Boolean readWrite) { if (pt.fPresent) { kout << "[PMM]: Allocation failed.\r"; - return {}; + return {pt}; } return Ref(pt); -- cgit v1.2.3 From 267b82036b457242325d30893280fdd4e74cd27f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 29 May 2025 23:20:20 +0200 Subject: feat: UserProcessScheduler: reset UTime when exiting. feat: drawio: Rename OS_DESIGN to SYSTEM_DESIGN. Signed-off-by: Amlal El Mahrouss --- dev/kernel/KernelKit/CoreProcessScheduler.h | 4 +-- dev/kernel/KernelKit/UserProcessScheduler.h | 4 +-- dev/kernel/src/UserProcessScheduler.cc | 7 +++-- docs/drawio/OS_DESIGN.drawio | 46 ----------------------------- docs/drawio/SYSTEM_DESIGN.drawio | 46 +++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 53 deletions(-) delete mode 100644 docs/drawio/OS_DESIGN.drawio create mode 100644 docs/drawio/SYSTEM_DESIGN.drawio (limited to 'dev/kernel/src') diff --git a/dev/kernel/KernelKit/CoreProcessScheduler.h b/dev/kernel/KernelKit/CoreProcessScheduler.h index 5ba29d3a..c06ef92c 100644 --- a/dev/kernel/KernelKit/CoreProcessScheduler.h +++ b/dev/kernel/KernelKit/CoreProcessScheduler.h @@ -130,7 +130,7 @@ enum class ProcessStatusKind : Int32 { //! @brief Affinity is the amount of nano-seconds this process is going to run. /***********************************************************************************/ enum class AffinityKind : Int32 { - kRealTime = 50, + kRealTime = 100, kVeryHigh = 150, kHigh = 200, kStandard = 1000, @@ -208,7 +208,7 @@ struct PROCESS_IMAGE final { Bool HasImage() const { return this->fBlob != nullptr; } - ErrorOr Leak() { + ErrorOr LeakImage() { if (this->fCode) { return ErrorOr{this->fCode}; } diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 14986ab6..23636ffb 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -144,8 +144,8 @@ class USER_PROCESS final { const AffinityKind& GetAffinity() noexcept; private: - UInt32 fLastExitCode{0}; - Int32 fLocalCode{0}; + UInt32 LastExitCode{0}; + KPCError LocalCode{0}; friend UserProcessScheduler; friend UserProcessHelper; diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 4bbd085a..876cae03 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -72,7 +72,7 @@ USER_PROCESS::operator bool() { /***********************************************************************************/ const UInt32& USER_PROCESS::GetExitCode() noexcept { - return this->fLastExitCode; + return this->LastExitCode; } /***********************************************************************************/ @@ -80,7 +80,7 @@ const UInt32& USER_PROCESS::GetExitCode() noexcept { /***********************************************************************************/ Int32& USER_PROCESS::GetLocalCode() noexcept { - return this->fLocalCode; + return this->LocalCode; } /***********************************************************************************/ @@ -263,7 +263,8 @@ STATIC Void sched_free_ptr_tree(PROCESS_HEAP_TREE* memory_ptr_list) { Void USER_PROCESS::Exit(const Int32& exit_code) { this->Status = exit_code > 0 ? ProcessStatusKind::kKilled : ProcessStatusKind::kFrozen; - this->fLastExitCode = exit_code; + this->LastExitCode = exit_code; + this->UTime = 0; kLastExitCode = exit_code; diff --git a/docs/drawio/OS_DESIGN.drawio b/docs/drawio/OS_DESIGN.drawio deleted file mode 100644 index c428d137..00000000 --- a/docs/drawio/OS_DESIGN.drawio +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/drawio/SYSTEM_DESIGN.drawio b/docs/drawio/SYSTEM_DESIGN.drawio new file mode 100644 index 00000000..c428d137 --- /dev/null +++ b/docs/drawio/SYSTEM_DESIGN.drawio @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 0e92d4841f0d1b6a5f2e1b093d9d0b6864dfac93 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 30 May 2025 10:56:29 +0200 Subject: refactor: Refactor IDeviceObject to DeviceInterface and its usages. refactor: Cleanup UPS (UserProcessScheduler) implementation. Signed-off-by: Amlal El Mahrouss --- dev/kernel/GfxKit/FB.h | 6 +++--- dev/kernel/HALKit/AMD64/HalDebugOutput.cc | 8 ++++---- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 4 ++-- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 4 ++-- dev/kernel/HALKit/ARM64/HalDebugOutput.cc | 4 ++-- dev/kernel/KernelKit/DebugOutput.h | 12 ++++++------ dev/kernel/KernelKit/DeviceMgr.h | 24 ++++++++++++------------ dev/kernel/NetworkKit/NetworkDevice.h | 4 ++-- dev/kernel/NetworkKit/NetworkDevice.inl | 6 +++--- dev/kernel/StorageKit/AHCI.h | 6 +++--- dev/kernel/StorageKit/ATA.h | 6 +++--- dev/kernel/StorageKit/NVME.h | 4 ++-- dev/kernel/StorageKit/StorageKit.h | 2 +- dev/kernel/src/Gfx/FBDeviceInterface.cc | 6 +++--- dev/kernel/src/Storage/AHCIDeviceInterface.cc | 10 +++++----- dev/kernel/src/Storage/ATADeviceInterface.cc | 10 +++++----- dev/kernel/src/Storage/NVMEDeviceInterface.cc | 6 +++--- dev/kernel/src/UserProcessScheduler.cc | 4 ---- 18 files changed, 61 insertions(+), 65 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/GfxKit/FB.h b/dev/kernel/GfxKit/FB.h index e30f1800..14f0393c 100644 --- a/dev/kernel/GfxKit/FB.h +++ b/dev/kernel/GfxKit/FB.h @@ -32,11 +32,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 IDeviceObject class. +/// @note The class is derived from the DeviceInterface class. class FBDeviceInterface NE_DEVICE { public: - explicit FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* out), - void (*in)(IDeviceObject* self, FBDevicePacket* in)); + explicit FBDeviceInterface(void (*out)(DeviceInterface* self, FBDevicePacket* out), + void (*in)(DeviceInterface* self, FBDevicePacket* in)); virtual ~FBDeviceInterface() override; diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc index b0463eb5..1e9fbab3 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -59,7 +59,7 @@ TerminalDevice::~TerminalDevice() = default; STATIC SizeT kX = kFontSizeX, kY = kFontSizeY; -EXTERN_C void ke_utf_io_write(IDeviceObject* obj, const Utf8Char* bytes) { +EXTERN_C void ke_utf_io_write(DeviceInterface* obj, const Utf8Char* bytes) { NE_UNUSED(bytes); NE_UNUSED(obj); @@ -115,7 +115,7 @@ EXTERN_C void ke_utf_io_write(IDeviceObject* obj, const Utf8Cha #endif // __DEBUG__ } -EXTERN_C void ke_io_write(IDeviceObject* obj, const Char* bytes) { +EXTERN_C void ke_io_write(DeviceInterface* obj, const Char* bytes) { NE_UNUSED(bytes); NE_UNUSED(obj); @@ -171,7 +171,7 @@ EXTERN_C void ke_io_write(IDeviceObject* obj, const Char* bytes) { #endif // __DEBUG__ } -EXTERN_C void ke_io_read(IDeviceObject*, const Char* bytes) { +EXTERN_C void ke_io_read(DeviceInterface*, const Char* bytes) { NE_UNUSED(bytes); #ifdef __DEBUG__ @@ -218,7 +218,7 @@ Utf8TerminalDevice::~Utf8TerminalDevice() = default; Utf8TerminalDevice Utf8TerminalDevice::The() noexcept { Utf8TerminalDevice out(Kernel::ke_utf_io_write, - [](IDeviceObject*, const Utf8Char*) -> Void {}); + [](DeviceInterface*, const Utf8Char*) -> Void {}); return out; } diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index b30bfc32..a9bdc89b 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -546,7 +546,7 @@ namespace Detail { /// @brief Read AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_ahci(IDeviceObject* self, MountpointInterface* mnt) { + STATIC Void sk_io_read_ahci(DeviceInterface* self, MountpointInterface* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; err_global_get() = kErrorDisk; @@ -567,7 +567,7 @@ namespace Detail { /// @brief Write AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_ahci(IDeviceObject* self, + STATIC Void sk_io_write_ahci(DeviceInterface* self, MountpointInterface* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 99e1c619..7b121c64 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -200,7 +200,7 @@ namespace Detail { /// @brief Read PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_pio(IDeviceObject* self, MountpointInterface* mnt) { + STATIC Void sk_io_read_pio(DeviceInterface* self, MountpointInterface* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; @@ -221,7 +221,7 @@ namespace Detail { /// @brief Write PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_pio(IDeviceObject* self, MountpointInterface* mnt) { + STATIC Void sk_io_write_pio(DeviceInterface* self, MountpointInterface* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; diff --git a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc index 3c518e2f..64004ac3 100644 --- a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc @@ -10,7 +10,7 @@ #include namespace Kernel { -EXTERN_C void ke_io_write(IDeviceObject* self, const Char* bytes) { +EXTERN_C void ke_io_write(DeviceInterface* self, const Char* bytes) { #ifdef __DEBUG__ if (*bytes == 0) return; @@ -33,7 +33,7 @@ EXTERN_C void ke_io_write(IDeviceObject* self, const Char* bytes) { TerminalDevice::~TerminalDevice() = default; -EXTERN_C void ke_io_read(IDeviceObject* self, const Char* bytes) { +EXTERN_C void ke_io_read(DeviceInterface* self, const Char* bytes) { #ifdef __DEBUG__ SizeT index = 0; diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h index 9598f590..de3bc997 100644 --- a/dev/kernel/KernelKit/DebugOutput.h +++ b/dev/kernel/KernelKit/DebugOutput.h @@ -37,9 +37,9 @@ inline TerminalDevice hex_number(const Long& x); // @brief Emulates a VT100 terminal. class TerminalDevice final NE_DEVICE { public: - TerminalDevice(void (*print)(IDeviceObject*, const Char*), - void (*gets)(IDeviceObject*, const Char*)) - : IDeviceObject(print, gets) {} + TerminalDevice(void (*print)(DeviceInterface*, const Char*), + void (*gets)(DeviceInterface*, const Char*)) + : DeviceInterface(print, gets) {} ~TerminalDevice() override; @@ -54,9 +54,9 @@ class TerminalDevice final NE_DEVICE { class Utf8TerminalDevice final NE_DEVICE { public: - Utf8TerminalDevice(void (*print)(IDeviceObject*, const Utf8Char*), - void (*gets)(IDeviceObject*, const Utf8Char*)) - : IDeviceObject(print, gets) {} + Utf8TerminalDevice(void (*print)(DeviceInterface*, const Utf8Char*), + void (*gets)(DeviceInterface*, const Utf8Char*)) + : DeviceInterface(print, gets) {} ~Utf8TerminalDevice() override; diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index 0a21710d..d82b43dc 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -24,13 +24,13 @@ #define kDeviceMgrRootDirPath "/devices/" -#define NE_DEVICE : public ::Kernel::IDeviceObject +#define NE_DEVICE : public ::Kernel::DeviceInterface // Last Rev: Wed, May 27, 2025 6:22 PM namespace Kernel { template -class IDeviceObject; +class DeviceInterface; template class IOBuf; @@ -39,26 +39,26 @@ class IOBuf; /// @brief Device contract interface, represents an HW device. /***********************************************************************************/ template -class IDeviceObject { +class DeviceInterface { public: - IDeviceObject() = default; + DeviceInterface() = default; - explicit IDeviceObject(void (*Out)(IDeviceObject*, T), void (*In)(IDeviceObject*, T)) + explicit DeviceInterface(void (*Out)(DeviceInterface*, T), void (*In)(DeviceInterface*, T)) : fOut(Out), fIn(In) {} - virtual ~IDeviceObject() = default; + virtual ~DeviceInterface() = default; public: - IDeviceObject& operator=(const IDeviceObject&) = default; - IDeviceObject(const IDeviceObject&) = default; + DeviceInterface& operator=(const DeviceInterface&) = default; + DeviceInterface(const DeviceInterface&) = default; public: - virtual IDeviceObject& operator<<(T Data) { + virtual DeviceInterface& operator<<(T Data) { fOut(this, Data); return *this; } - virtual IDeviceObject& operator>>(T Data) { + virtual DeviceInterface& operator>>(T Data) { fIn(this, Data); return *this; } @@ -70,8 +70,8 @@ class IDeviceObject { Bool operator!() { return !fOut || !fIn; } protected: - Void (*fOut)(IDeviceObject*, T Data) = {nullptr}; - Void (*fIn)(IDeviceObject*, T Data) = {nullptr}; + Void (*fOut)(DeviceInterface*, T Data) = {nullptr}; + Void (*fIn)(DeviceInterface*, T Data) = {nullptr}; }; /// diff --git a/dev/kernel/NetworkKit/NetworkDevice.h b/dev/kernel/NetworkKit/NetworkDevice.h index c37d8504..04d208c5 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.h +++ b/dev/kernel/NetworkKit/NetworkDevice.h @@ -21,8 +21,8 @@ class NetworkDevice; */ class NetworkDevice final NE_DEVICE { public: - NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), - void (*in)(IDeviceObject*, NetworkDeviceCommand), + NetworkDevice(void (*out)(DeviceInterface*, NetworkDeviceCommand), + void (*in)(DeviceInterface*, NetworkDeviceCommand), void (*cleanup)(void) = nullptr); ~NetworkDevice() override; diff --git a/dev/kernel/NetworkKit/NetworkDevice.inl b/dev/kernel/NetworkKit/NetworkDevice.inl index 84ec9edc..6ef480a9 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.inl +++ b/dev/kernel/NetworkKit/NetworkDevice.inl @@ -13,12 +13,12 @@ #endif // __INC_NETWORK_DEVICE_H__ namespace Kernel { -inline NetworkDevice::NetworkDevice(void (*out)(IDeviceObject*, +inline NetworkDevice::NetworkDevice(void (*out)(DeviceInterface*, NetworkDeviceCommand), - void (*in)(IDeviceObject*, + void (*in)(DeviceInterface*, NetworkDeviceCommand), void (*on_cleanup)(void)) - : IDeviceObject(out, in), fCleanup(on_cleanup) { + : DeviceInterface(out, in), fCleanup(on_cleanup) { kout << "NetworkDevice initialized.\r"; MUST_PASS(out && in && on_cleanup); diff --git a/dev/kernel/StorageKit/AHCI.h b/dev/kernel/StorageKit/AHCI.h index e2220719..3b9dac67 100644 --- a/dev/kernel/StorageKit/AHCI.h +++ b/dev/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 IDeviceObject class. +/// @note The class is derived from the DeviceInterface class. class AHCIDeviceInterface NE_DEVICE { public: - explicit AHCIDeviceInterface(void (*out)(IDeviceObject* self, MountpointInterface* out), - void (*in)(IDeviceObject* self, MountpointInterface* in)); + explicit AHCIDeviceInterface(void (*out)(DeviceInterface* self, MountpointInterface* out), + void (*in)(DeviceInterface* self, MountpointInterface* in)); virtual ~AHCIDeviceInterface() override; diff --git a/dev/kernel/StorageKit/ATA.h b/dev/kernel/StorageKit/ATA.h index abf255a5..d4c894a3 100644 --- a/dev/kernel/StorageKit/ATA.h +++ b/dev/kernel/StorageKit/ATA.h @@ -13,10 +13,10 @@ namespace Kernel { /// @brief ATA device interface class. -class ATADeviceInterface : public IDeviceObject { +class ATADeviceInterface : public DeviceInterface { public: - explicit ATADeviceInterface(void (*Out)(IDeviceObject*, MountpointInterface* outpacket), - void (*In)(IDeviceObject*, MountpointInterface* inpacket)); + explicit ATADeviceInterface(void (*Out)(DeviceInterface*, MountpointInterface* outpacket), + void (*In)(DeviceInterface*, MountpointInterface* inpacket)); virtual ~ATADeviceInterface(); diff --git a/dev/kernel/StorageKit/NVME.h b/dev/kernel/StorageKit/NVME.h index aae36a94..1b2b6358 100644 --- a/dev/kernel/StorageKit/NVME.h +++ b/dev/kernel/StorageKit/NVME.h @@ -12,8 +12,8 @@ namespace Kernel { class NVMEDeviceInterface final NE_DEVICE { public: - explicit NVMEDeviceInterface(Void (*out)(IDeviceObject*, MountpointInterface* out_packet), - Void (*in)(IDeviceObject*, MountpointInterface* in_packet), + explicit NVMEDeviceInterface(Void (*out)(DeviceInterface*, MountpointInterface* out_packet), + Void (*in)(DeviceInterface*, MountpointInterface* in_packet), Void (*cleanup)(Void)); ~NVMEDeviceInterface() override; diff --git a/dev/kernel/StorageKit/StorageKit.h b/dev/kernel/StorageKit/StorageKit.h index adb9f5dc..411aa6ae 100644 --- a/dev/kernel/StorageKit/StorageKit.h +++ b/dev/kernel/StorageKit/StorageKit.h @@ -12,7 +12,7 @@ namespace Kernel { template -class IDeviceObject; +class DeviceInterface; class NVMEDeviceInterface; class AHCIDeviceInterface; diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index d588e8c8..f1867b45 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/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)(IDeviceObject* self, FBDevicePacket* outpacket), - void (*in)(IDeviceObject* self, FBDevicePacket* inpacket)) - : IDeviceObject(out, in) {} +FBDeviceInterface::FBDeviceInterface(void (*out)(DeviceInterface* self, FBDevicePacket* outpacket), + void (*in)(DeviceInterface* self, FBDevicePacket* inpacket)) + : DeviceInterface(out, in) {} /// @brief Class desctructor FBDeviceInterface::~FBDeviceInterface() = default; diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc index 2d97eee7..382ce37b 100644 --- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc @@ -12,11 +12,11 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(IDeviceObject* self, +AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(DeviceInterface* self, MountpointInterface* outpacket), - void (*in)(IDeviceObject* self, + void (*in)(DeviceInterface* self, MountpointInterface* inpacket)) - : IDeviceObject(out, in) {} + : DeviceInterface(out, in) {} /// @brief Class desctructor AHCIDeviceInterface::~AHCIDeviceInterface() = default; @@ -45,7 +45,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator<<(MountpointInterface* mnt) { } } - return (AHCIDeviceInterface&) IDeviceObject::operator<<(mnt); + return (AHCIDeviceInterface&) DeviceInterface::operator<<(mnt); } /// @brief Input operator. @@ -67,7 +67,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator>>(MountpointInterface* mnt) { } } - return (AHCIDeviceInterface&) IDeviceObject::operator>>(mnt); + return (AHCIDeviceInterface&) DeviceInterface::operator>>(mnt); } const UInt16& AHCIDeviceInterface::GetPortsImplemented() { diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc index a66d812b..697571a3 100644 --- a/dev/kernel/src/Storage/ATADeviceInterface.cc +++ b/dev/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)(IDeviceObject*, MountpointInterface* outpacket), - void (*In)(IDeviceObject*, MountpointInterface* inpacket)) - : IDeviceObject(Out, In) {} +ATADeviceInterface::ATADeviceInterface(void (*Out)(DeviceInterface*, MountpointInterface* outpacket), + void (*In)(DeviceInterface*, MountpointInterface* inpacket)) + : DeviceInterface(Out, In) {} /// @brief Class desctructor ATADeviceInterface::~ATADeviceInterface() = default; @@ -43,7 +43,7 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) { } } - return (ATADeviceInterface&) IDeviceObject::operator<<(Data); + return (ATADeviceInterface&) DeviceInterface::operator<<(Data); } /// @brief Input operator. @@ -65,7 +65,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) { } } - return (ATADeviceInterface&) IDeviceObject::operator>>(Data); + return (ATADeviceInterface&) DeviceInterface::operator>>(Data); } const UInt32& ATADeviceInterface::GetIndex() { diff --git a/dev/kernel/src/Storage/NVMEDeviceInterface.cc b/dev/kernel/src/Storage/NVMEDeviceInterface.cc index cff776c9..bc138710 100644 --- a/dev/kernel/src/Storage/NVMEDeviceInterface.cc +++ b/dev/kernel/src/Storage/NVMEDeviceInterface.cc @@ -7,11 +7,11 @@ #include namespace Kernel { -NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(IDeviceObject*, +NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(DeviceInterface*, MountpointInterface* outpacket), - void (*in)(IDeviceObject*, MountpointInterface* inpacket), + void (*in)(DeviceInterface*, MountpointInterface* inpacket), void (*cleanup)(void)) - : IDeviceObject(out, in), fCleanup(cleanup) {} + : DeviceInterface(out, in), fCleanup(cleanup) {} NVMEDeviceInterface::~NVMEDeviceInterface() { if (fCleanup) fCleanup(); diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 876cae03..1454585c 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -31,10 +31,6 @@ namespace Kernel { STATIC UInt32 kLastExitCode = 0U; -/***********************************************************************************/ -/// @brief Scheduler itself. -/***********************************************************************************/ - USER_PROCESS::USER_PROCESS() = default; USER_PROCESS::~USER_PROCESS() = default; -- cgit v1.2.3 From 86b89793dcaf290206faeb7fe3100dd0a5f71d1d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 30 May 2025 14:42:35 +0200 Subject: global: architectural changes, see commit details. refactor: Refactor libSystem, user frameworks, and preparing for OpenMSG. feat: Jail info client structure (libSystem) feat: Document what the RTime is doing starting from line 504. feat: use `int 50` instead of `syscall` for now. Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/UserProcessScheduler.cc | 1 + dev/libSystem/Err.h | 58 ---- dev/libSystem/Jail.h | 15 - dev/libSystem/Macros.h | 126 ------- dev/libSystem/Syscall.h | 19 - dev/libSystem/System.h | 385 --------------------- dev/libSystem/SystemKit/Err.h | 58 ++++ dev/libSystem/SystemKit/Jail.h | 23 ++ dev/libSystem/SystemKit/Macros.h | 126 +++++++ dev/libSystem/SystemKit/Syscall.h | 19 + dev/libSystem/SystemKit/System.h | 385 +++++++++++++++++++++ dev/libSystem/src/Makefile | 2 +- dev/libSystem/src/SystemAPI.cc | 91 ----- dev/libSystem/src/SystemImpl.cc | 91 +++++ dev/libSystem/src/SystemProc.asm | 13 +- dev/open_msg/.keep | 0 dev/open_msg/MsgKit/Server.h | 22 ++ dev/open_msg/obj/.keep | 0 dev/open_msg/script/window.msg | 6 + dev/open_msg/src/.keep | 0 dev/system_sdk/.keep | 0 .../CoreFoundation.fwrk/CoreFoundation.json | 2 +- .../frameworks/CoreFoundation.fwrk/headers/Array.h | 2 +- .../CoreFoundation.fwrk/headers/Foundation.h | 2 +- .../CoreFoundation.fwrk/headers/Property.h | 2 +- .../frameworks/CoreFoundation.fwrk/headers/Ref.h | 2 +- public/frameworks/DiskImage.fwrk/DiskImage.json | 2 +- .../frameworks/DiskImage.fwrk/headers/DiskImage.h | 2 +- public/frameworks/KernelTest.fwrk/KernelTest.json | 2 +- public/frameworks/OpenMSG.fwrk/.keep | 0 public/frameworks/OpenMSG.fwrk/OpenMSG.json | 19 + public/frameworks/OpenMSG.fwrk/headers/.keep | 0 public/frameworks/OpenMSG.fwrk/src/.keep | 0 public/frameworks/OpenMSG.fwrk/src/DylibMain.cc | 5 + public/frameworks/OpenMSG.fwrk/xml/.keep | 0 public/frameworks/OpenMSG.fwrk/xml/app.xml | 2 + public/tools/cc/src/CommandLine.cc | 2 +- public/tools/ld.dyn/src/CommandLine.cc | 2 +- public/tools/ld.fwrk/src/CommandLine.cc | 2 +- public/tools/manual/src/CommandLine.cc | 2 +- public/tools/mgmt/src/CommandLine.cc | 2 +- public/tools/mk.fwrk/Common.h | 2 +- public/tools/mk.fwrk/src/CommandLine.cc | 2 +- public/tools/mk.hefs/src/CommandLine.cc | 2 +- public/tools/mk.nefs/src/CommandLine.cc | 2 +- public/tools/open/src/CommandLine.cc | 2 +- public/tools/ping/src/CommandLine.cc | 2 +- tooling/mk_app.py | 2 +- tooling/mk_fwrk.py | 4 +- 49 files changed, 789 insertions(+), 721 deletions(-) delete mode 100644 dev/libSystem/Err.h delete mode 100644 dev/libSystem/Jail.h delete mode 100644 dev/libSystem/Macros.h delete mode 100644 dev/libSystem/Syscall.h delete mode 100644 dev/libSystem/System.h create mode 100644 dev/libSystem/SystemKit/Err.h create mode 100644 dev/libSystem/SystemKit/Jail.h create mode 100644 dev/libSystem/SystemKit/Macros.h create mode 100644 dev/libSystem/SystemKit/Syscall.h create mode 100644 dev/libSystem/SystemKit/System.h delete mode 100644 dev/libSystem/src/SystemAPI.cc create mode 100644 dev/libSystem/src/SystemImpl.cc create mode 100644 dev/open_msg/.keep create mode 100644 dev/open_msg/MsgKit/Server.h create mode 100644 dev/open_msg/obj/.keep create mode 100644 dev/open_msg/script/window.msg create mode 100644 dev/open_msg/src/.keep delete mode 100644 dev/system_sdk/.keep create mode 100644 public/frameworks/OpenMSG.fwrk/.keep create mode 100644 public/frameworks/OpenMSG.fwrk/OpenMSG.json create mode 100644 public/frameworks/OpenMSG.fwrk/headers/.keep create mode 100644 public/frameworks/OpenMSG.fwrk/src/.keep create mode 100644 public/frameworks/OpenMSG.fwrk/src/DylibMain.cc create mode 100644 public/frameworks/OpenMSG.fwrk/xml/.keep create mode 100644 public/frameworks/OpenMSG.fwrk/xml/app.xml (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 1454585c..e6309589 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -504,6 +504,7 @@ SizeT UserProcessScheduler::Run() noexcept { if (UserProcessHelper::Switch(process.StackFrame, process.ProcessId)) { process.PTime = static_cast(process.Affinity); + // We add a bigger cooldown according to the RTime and affinity here. if (process.PTime < process.RTime && AffinityKind::kRealTime != process.Affinity) { if (process.RTime < (Int32) AffinityKind::kVeryHigh) process.RTime = (Int32) AffinityKind::kLowUsage / 2; diff --git a/dev/libSystem/Err.h b/dev/libSystem/Err.h deleted file mode 100644 index e9fe013b..00000000 --- a/dev/libSystem/Err.h +++ /dev/null @@ -1,58 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file Err.h -/// @brief Process Codes type and values. -/// @author Amlal El Mahrouss (amlal@nekernel.org) - -#define err_local_ok() (kLastError == kErrorSuccess) -#define err_local_fail() (kLastError != kErrorSuccess) -#define err_local_get() (kLastError) - -typedef SInt32 ErrRef; - -inline constexpr ErrRef kErrorSuccess = 0; -inline constexpr ErrRef kErrorExecutable = 33; -inline constexpr ErrRef kErrorExecutableLib = 34; -inline constexpr ErrRef kErrorFileNotFound = 35; -inline constexpr ErrRef kErrorDirectoryNotFound = 36; -inline constexpr ErrRef kErrorDiskReadOnly = 37; -inline constexpr ErrRef kErrorDiskIsFull = 38; -inline constexpr ErrRef kErrorProcessFault = 39; -inline constexpr ErrRef kErrorSocketHangUp = 40; -inline constexpr ErrRef kErrorThreadLocalStorage = 41; -inline constexpr ErrRef kErrorMath = 42; -inline constexpr ErrRef kErrorNoNetwork = 43; -inline constexpr ErrRef kErrorHeapOutOfMemory = 44; -inline constexpr ErrRef kErrorNoSuchDisk = 45; -inline constexpr ErrRef kErrorFileExists = 46; -inline constexpr ErrRef kErrorFormatFailed = 47; -inline constexpr ErrRef kErrorNetworkTimeout = 48; -inline constexpr ErrRef kErrorInternal = 49; -inline constexpr ErrRef kErrorForkAlreadyExists = 50; -inline constexpr ErrRef kErrorOutOfTeamSlot = 51; -inline constexpr ErrRef kErrorHeapNotPresent = 52; -inline constexpr ErrRef kErrorNoEntrypoint = 53; -inline constexpr ErrRef kErrorDiskIsCorrupted = 54; -inline constexpr ErrRef kErrorDisk = 55; -inline constexpr ErrRef kErrorInvalidData = 56; -inline constexpr ErrRef kErrorAsync = 57; -inline constexpr ErrRef kErrorNonBlocking = 58; -inline constexpr ErrRef kErrorIPC = 59; -inline constexpr ErrRef kErrorSign = 60; -inline constexpr ErrRef kErrorInvalidCreds = 61; -inline constexpr ErrRef kErrorCDTrayBroken = 62; -inline constexpr ErrRef kErrorUnrecoverableDisk = 63; -inline constexpr ErrRef kErrorFileLocked = 64; -inline constexpr ErrRef kErrorDiskIsTooTiny = 65; -inline constexpr ErrRef kErrorUnimplemented = -1; - -/// @brief The last error reported by the system to the process. -IMPORT_C ErrRef kLastError; diff --git a/dev/libSystem/Jail.h b/dev/libSystem/Jail.h deleted file mode 100644 index 6a9259fc..00000000 --- a/dev/libSystem/Jail.h +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include - -/// @file Jail.h -/// @brief NeKernel Jail System - -struct JAIL_INFO; -struct JAIL; \ No newline at end of file diff --git a/dev/libSystem/Macros.h b/dev/libSystem/Macros.h deleted file mode 100644 index 5b3a5ce1..00000000 --- a/dev/libSystem/Macros.h +++ /dev/null @@ -1,126 +0,0 @@ -/* ------------------------------------------- - -Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -File: Macros.h -Purpose: libsci Macros header. - -------------------------------------------- */ - -#pragma once - -/***********************************************************************************/ -/// @file libSystem/Macros.h -/// @brief Macros and Core types of the SCI (System Call Interface). -/***********************************************************************************/ - -#include - -#define ATTRIBUTE(X) __attribute__((X)) - -#define IMPORT_CXX extern "C++" -#define IMPORT_C extern "C" - -#define DEPRECATED ATTRIBUTE(deprecated) - -#define EXIT_SUCCESS (0) -#define EXIT_FAILURE (1) - -#define FILE_MAX_LEN (256) - -#ifndef BOOL -#define BOOL bool -#endif - -typedef bool Bool; -typedef bool Boolean; -typedef void Void; - -#ifndef __cplusplus -#define true (1) -#define false (0) -#endif - -#define YES true -#define NO false - -typedef __UINT64_TYPE__ UInt64; -typedef __UINT32_TYPE__ UInt32; -typedef __UINT16_TYPE__ UInt16; -typedef __UINT8_TYPE__ UInt8; - -typedef __SIZE_TYPE__ SizeT; - -typedef __INT64_TYPE__ SInt64; -typedef __INT32_TYPE__ SInt32; -typedef __INT16_TYPE__ SInt16; -typedef __INT8_TYPE__ SInt8; - -typedef void* VoidPtr; -typedef __UINTPTR_TYPE__ UIntPtr; -typedef char Char; - -#ifdef __cplusplus -typedef decltype(nullptr) nullPtr; -typedef nullPtr NullPtr; - -#define LIBSYS_COPY_DELETE(KLASS) \ - KLASS& operator=(const KLASS&) = delete; \ - KLASS(const KLASS&) = delete; - -#define LIBSYS_COPY_DEFAULT(KLASS) \ - KLASS& operator=(const KLASS&) = default; \ - KLASS(const KLASS&) = default; - -#define LIBSYS_MOVE_DELETE(KLASS) \ - KLASS& operator=(KLASS&&) = delete; \ - KLASS(KLASS&&) = delete; - -#define LIBSYS_MOVE_DEFAULT(KLASS) \ - KLASS& operator=(KLASS&&) = default; \ - KLASS(KLASS&&) = default; - -#endif - -IMPORT_C void _rtl_assert(Bool expr, const Char* origin); - -#define MUST_PASS(X) _rtl_assert(X, __FILE__) - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(X) \ - (((sizeof(X) / sizeof(*(X))) / (static_cast(!(sizeof(X) % sizeof(*(X))))))) -#endif - -#ifndef KIB -#define KIB(X) (UInt64)((X) / 1024) -#endif - -#ifndef kib_cast -#define kib_cast(X) (UInt64)((X) *1024) -#endif - -#ifndef MIB -#define MIB(X) (UInt64)((UInt64) KIB(X) / 1024) -#endif - -#ifndef mib_cast -#define mib_cast(X) (UInt64)((UInt64) kib_cast(X) * 1024) -#endif - -#ifndef GIB -#define GIB(X) (UInt64)((UInt64) MIB(X) / 1024) -#endif - -#ifndef gib_cast -#define gib_cast(X) (UInt64)((UInt64) mib_cast(X) * 1024) -#endif - -#ifndef TIB -#define TIB(X) (UInt64)((UInt64) GIB(X) / 1024) -#endif - -#ifndef tib_cast -#define tib_cast(X) ((UInt64) gib_cast(X) * 1024) -#endif - -#define LIBSYS_UNUSED(X) ((void) X) diff --git a/dev/libSystem/Syscall.h b/dev/libSystem/Syscall.h deleted file mode 100644 index 21f8287c..00000000 --- a/dev/libSystem/Syscall.h +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -#ifndef SYSCALL_HASH -#define SYSCALL_HASH(str) (UInt64)str -#endif // !SYSCALL_HASH - -IMPORT_C VoidPtr libsys_syscall_arg_1(SizeT id); -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); diff --git a/dev/libSystem/System.h b/dev/libSystem/System.h deleted file mode 100644 index 88e1f173..00000000 --- a/dev/libSystem/System.h +++ /dev/null @@ -1,385 +0,0 @@ -/* ------------------------------------------- - -Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -File: System.h -Purpose: System Call Interface. - -------------------------------------------- */ - -#ifndef LIBSYS_SYSTEM_CALLS_H -#define LIBSYS_SYSTEM_CALLS_H - -#include - -// ------------------------------------------------------------------------------------------ // -/// @brief Types API. -// ------------------------------------------------------------------------------------------ // - -struct REF_TYPE { - UInt64 __hash; /// @brief Hash of the syscall - VoidPtr __self; /// @brief Syscall self value. -}; - -typedef REF_TYPE* Ref; - -typedef Ref IORef; -typedef Ref FSRef; -typedef Ref DylibRef; -typedef Ref ThreadRef; -typedef Ref SocketRef; -typedef Ref NetworkRef; -typedef Ref MutexRef; -typedef Ref EventRef; -typedef Ref SemaphoreRef; - -// ------------------------------------------------------------------------------------------ // -/// @brief Dynamic Loader API. -// ------------------------------------------------------------------------------------------ // - -/// @brief Get function which is part of the Dylib. -/// @param symbol the symbol to look for -/// @param dll_handle the Dylib handle. -/// @return the proc pointer. -IMPORT_C Ref LdrGetDylibSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle); - -/// @brief Open Dylib handle. -/// @param path dll path. -/// @param drv driver letter. -/// @return a dylib ref. -IMPORT_C Ref LdrOpenDylibHandle(_Input const Char* path, _Input const Char* drive_letter); - -/// @brief Close Dylib handle -/// @param dll_handle the dylib ref. -/// @return whether it closed or not. -IMPORT_C UInt32 LdrCloseDylibHandle(_Input Ref* dll_handle); - -// ------------------------------------------------------------------------------------------ // -// File API. -// ------------------------------------------------------------------------------------------ // - -/// @brief Opens a file from a drive. -/// @param fs_path the filesystem path. -/// @param drive_letter drive name, use NULL to use default drive location. -/// @return the file descriptor of the file. -IMPORT_C Ref IoOpenFile(const Char* fs_path, const Char* drive_letter); - -/// @brief Closes a file and flushes its content. -/// @param file_desc the file descriptor. -/// @return Function doesn't return a type. -IMPORT_C Void IoCloseFile(_Input Ref file_desc); - -/// @brief I/O control (ioctl) on a file. -/// @param file_desc the file descriptor. -/// @param ioctl_code the ioctl code. -/// @param in_data the input data. -/// @param out_data the output data. -/// @return the number of bytes written. -/// @note This function is used to control the file descriptor, introduced for HeFS. -IMPORT_C SInt32 IoCtrlFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data, - _Output VoidPtr out_data); - -/// @brief Gets the file mime (if any) -/// @param file_desc the file descriptor. -IMPORT_C const Char* IoMimeFile(_Input Ref file_desc); - -/// @brief Gets the dir DIM. -/// @param dir_desc directory descriptor. -/// @note only works in HeFS, will return nil-x/nil if used on any other filesystem. -IMPORT_C const Char* IoDimFile(_Input Ref dir_desc); - -/// @brief Write data to a file ref -/// @param file_desc the file descriptor. -/// @param out_data the data to write. -/// @param sz_data the size of the data to write. -/// @return the number of bytes written. -IMPORT_C UInt32 IoWriteFile(_Input Ref file_desc, _Output VoidPtr out_data, SizeT sz_data); - -/// @brief Read data from a file. -/// @param file_desc the file descriptor. -/// @param out_data the data to read. -/// @param sz_data the size of the data to read. -IMPORT_C UInt32 IoReadFile(_Input Ref file_desc, _Output VoidPtr* out_data, SizeT sz_data); - -/// @brief Rewind the file pointer to the beginning of the file. -/// @param file_desc the file descriptor. -/// @return the number of bytes read. -IMPORT_C UInt64 IoRewindFile(_Input Ref file_desc); - -/// @brief Tell the current position of the file pointer. -/// @param file_desc the file descriptor. -/// @return the current position of the file pointer. -IMPORT_C UInt64 IoTellFile(_Input Ref file_desc); - -/// @brief Seek file offset from file descriptor. -IMPORT_C UInt64 IoSeekFile(_Input Ref file_desc, UInt64 file_offset); - -// ------------------------------------------------------------------------ -// Process API. -// ------------------------------------------------------------------------ - -/// @brief Spawns a Thread Information Block and Global Information Block inside the current -/// process. -/// @param process_id Target Process ID, must be valid. -/// @return > 0 error occurred or already present, = 0 success. -IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id); - -/// @brief Spawns a process with a unique pid (stored as UIntPtr). -/// @param process_path process filesystem path. -/// @return > 0 process was created. -IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** argv, Char** envp, - SizeT envp_len); - -/// @brief Exits a process with an exit_code. -/// @return if it has succeeded true, otherwise false. -IMPORT_C Bool RtlExitProcess(UIntPtr handle, UIntPtr exit_code); - -// ------------------------------------------------------------------------ -// Memory Manager API. -// ------------------------------------------------------------------------ - -/// @brief Creates a new heap from the process's address space. -/// @param len the length of it. -/// @param flags the flags of it. -/// @return heap pointer. -IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); - -/// @brief Destroys the pointer -/// @param heap the heap itself. -/// @return void. -IMPORT_C SInt32 MmDestroyHeap(_Input VoidPtr heap); - -/// @brief Change protection flags of a memory region. -IMPORT_C SInt32 MmSetHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); - -/// @brief Change protection flags of a memory region. -IMPORT_C UInt32 MmGetHeapFlags(_Input VoidPtr heap); - -/// @brief Fill memory region with CRC32. -IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); - -/// @brief Copy memory region. -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); - -/// @brief Compare memory regions. -IMPORT_C SInt64 MmCmpMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); - -/// @brief Fill memory region. -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value); - -/// @brief Compare string regions. -IMPORT_C SInt64 MmStrCmp(_Input const Char* dest, _Input const Char* src); - -/// @brief Get length of string. -IMPORT_C SInt64 MmStrLen(const Char* str); - -// ------------------------------------------------------------------------ -// @brief Error API. -// ------------------------------------------------------------------------ - -IMPORT_C SInt32 ErrGetLastError(Void); - -// ------------------------------------------------------------------------ -// @brief Threading API. -// ------------------------------------------------------------------------ - -/// @brief Exit the current thread. -/// @param exit_code the exit code. -IMPORT_C SInt32 ThrExitCurrentThread(_Input SInt32 exit_code); - -/// @brief Exit the main thread. -/// @param exit_code the exit code. -IMPORT_C SInt32 ThrExitMainThread(_Input SInt32 exit_code); - -/// @brief Exit a thread. -/// @param thread the thread to exit. -/// @param exit_code the exit code. -IMPORT_C SInt32 ThrExitThread(_Input ThreadRef thread, _Input SInt32 exit_code); - -/// @brief Thread procedure function type. -typedef SInt32 (*ThrProcKind)(SInt32 argc, Char** argv); - -/// @brief Creates a thread. -/// @param procedure the thread procedure. -/// @param argument_count number of arguments inside that thread. -/// @param flags Thread flags. -/// @return the thread object. -IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, - SInt32 argument_count, SInt32 flags); - -/// @brief Yields the current thread. -/// @param thread the thread to yield. -IMPORT_C SInt32 ThrYieldThread(ThreadRef thrd); - -/// @brief Joins a thread. -/// @param thread the thread to join. -IMPORT_C SInt32 ThrJoinThread(ThreadRef thrd); - -/// @brief Detach a thread. -/// @param thread the thread to detach. -IMPORT_C SInt32 ThrDetachThread(ThreadRef thrd); - -// ------------------------------------------------------------------------ -// @brief Drive Management API. -// ------------------------------------------------------------------------ - -// ------------------------------------------------------------------------------------------ // -/// @brief Get the default drive letter. -/// @param void. -/// @return the drive letter. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Char* DrvGetDefaultDriveLetter(Void); - -// ------------------------------------------------------------------------------------------ // -/// @brief Get the drive letter from a path. -/// @param path the path. -/// @return the drive letter. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path); - -// ------------------------------------------------------------------------------------------ // -/// @brief Get a mounted drive from a letter. -/// @param letter the letter (A..Z). -/// @return the drive object. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Ref DrvGetMountedDrive(_Input Char letter); - -// ------------------------------------------------------------------------------------------ // -/// @brief Mount a drive. -/// @param path the path to mount. -/// @param letter the letter to mount. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter); - -// ------------------------------------------------------------------------------------------ // -/// @brief Unmount a drive. -/// @param letter the letter to unmount. -// ------------------------------------------------------------------------------------------ // -IMPORT_C Void DrvUnmountDrive(_Input Char letter); - -// ------------------------------------------------------------------------ -// Event handling API, use to listen to OS specific events. -// ------------------------------------------------------------------------ - -// ------------------------------------------------------------------------------------------ // -/// @brief Add an event listener. -/// @param event_name the event name. -/// @param listener the listener to add. -/// @return the event listener. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input Ref listener); - -// ------------------------------------------------------------------------------------------ // -/// @brief Remove an event listener. -/// @param event_name the event name. -/// @param listener the listener to remove. -/// @return the event listener. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input Ref listener); - -// ------------------------------------------------------------------------------------------ // -/// @brief Dispatch an event. -/// @param event_name the event name. -/// @param event_data the event data. -/// @return the event data. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data); - -// ------------------------------------------------------------------------------------------ // -// Power API. -// ------------------------------------------------------------------------------------------ // - -enum { - kPowerCodeInvalid = 0, - kPowerCodeShutdown = 12, - kPowerCodeReboot, - kPowerCodeSleep, - kPowerCodeWake, - kPowerCodeCount, -}; - -IMPORT_C SInt32 PwrReadCode(_Output SInt32& code); - -IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); - -// ------------------------------------------------------------------------------------------ // -// CD-ROM API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C SInt32 CdEjectDrive(_Input Char drv_letter); - -IMPORT_C SInt32 CdOpenTray(Void); - -IMPORT_C SInt32 CdCloseTray(Void); - -// ------------------------------------------------------------------------------------------ // -// Printer API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C SInt32 PrintOut(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); - -IMPORT_C SInt32 PrintIn(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); - -IMPORT_C IORef PrintCreate(Void); - -IMPORT_C SInt32 PrintRelease(IORef); - -IMPORT_C IORef PrintGet(const Char* path); - -// ------------------------------------------------------------------------------------------ // -// @brief Scheduler/Debug API. -// ------------------------------------------------------------------------------------------ // - -typedef SInt32 AffinityRef; -typedef UInt64 ProcessRef; - -IMPORT_C SInt32 SchedSetAffinity(_Input ProcessRef, SInt32 req, _Input AffinityRef*); - -IMPORT_C SInt32 SchedGetAffinity(_Input ProcessRef, _InOut AffinityRef*); - -IMPORT_C SInt32 SchedFireSignal(_Input ProcessRef, SInt32); - -IMPORT_C SInt32 SchedReadMemory(_Input ProcessRef, SInt32, SInt32); - -IMPORT_C SInt32 SchedWriteMemory(_Input ProcessRef, SInt32, SInt32); - -IMPORT_C UIntPtr SchedGetCurrentProcessID(Void); - -// ------------------------------------------------------------------------------------------ // -// @brief Filesystem API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C BOOL FsCopy(const Char* path, const Char* dst); - -IMPORT_C BOOL FsMove(const Char* path, const Char* dst); - -IMPORT_C BOOL FsExists(const Char* path); - -IMPORT_C BOOL FsCreateDir(const Char* path); - -IMPORT_C BOOL FsCreateFile(const Char* path); - -IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); - -// ------------------------------------------------------------------------------------------ // -// @brief Installable Filesystem API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C BOOL IfsMount(const Char* path, const Char* drive_letter); - -IMPORT_C BOOL IfsUnmount(const Char* drive_letter); - -IMPORT_C BOOL IfsIsMounted(const Char* drive_letter); - -// ------------------------------------------------------------------------------------------ // -// @brief String Manip API. -// ------------------------------------------------------------------------------------------ // - -IMPORT_C Char* StrFmt(const Char* fmt, ...); - -IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); - -#endif // ifndef LIBSYS_SYSTEM_CALLS_H diff --git a/dev/libSystem/SystemKit/Err.h b/dev/libSystem/SystemKit/Err.h new file mode 100644 index 00000000..c0a2282b --- /dev/null +++ b/dev/libSystem/SystemKit/Err.h @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Err.h +/// @brief Process Codes type and values. +/// @author Amlal El Mahrouss (amlal@nekernel.org) + +#define err_local_ok() (kLastError == kErrorSuccess) +#define err_local_fail() (kLastError != kErrorSuccess) +#define err_local_get() (kLastError) + +typedef SInt32 ErrRef; + +inline constexpr ErrRef kErrorSuccess = 0; +inline constexpr ErrRef kErrorExecutable = 33; +inline constexpr ErrRef kErrorExecutableLib = 34; +inline constexpr ErrRef kErrorFileNotFound = 35; +inline constexpr ErrRef kErrorDirectoryNotFound = 36; +inline constexpr ErrRef kErrorDiskReadOnly = 37; +inline constexpr ErrRef kErrorDiskIsFull = 38; +inline constexpr ErrRef kErrorProcessFault = 39; +inline constexpr ErrRef kErrorSocketHangUp = 40; +inline constexpr ErrRef kErrorThreadLocalStorage = 41; +inline constexpr ErrRef kErrorMath = 42; +inline constexpr ErrRef kErrorNoNetwork = 43; +inline constexpr ErrRef kErrorHeapOutOfMemory = 44; +inline constexpr ErrRef kErrorNoSuchDisk = 45; +inline constexpr ErrRef kErrorFileExists = 46; +inline constexpr ErrRef kErrorFormatFailed = 47; +inline constexpr ErrRef kErrorNetworkTimeout = 48; +inline constexpr ErrRef kErrorInternal = 49; +inline constexpr ErrRef kErrorForkAlreadyExists = 50; +inline constexpr ErrRef kErrorOutOfTeamSlot = 51; +inline constexpr ErrRef kErrorHeapNotPresent = 52; +inline constexpr ErrRef kErrorNoEntrypoint = 53; +inline constexpr ErrRef kErrorDiskIsCorrupted = 54; +inline constexpr ErrRef kErrorDisk = 55; +inline constexpr ErrRef kErrorInvalidData = 56; +inline constexpr ErrRef kErrorAsync = 57; +inline constexpr ErrRef kErrorNonBlocking = 58; +inline constexpr ErrRef kErrorIPC = 59; +inline constexpr ErrRef kErrorSign = 60; +inline constexpr ErrRef kErrorInvalidCreds = 61; +inline constexpr ErrRef kErrorCDTrayBroken = 62; +inline constexpr ErrRef kErrorUnrecoverableDisk = 63; +inline constexpr ErrRef kErrorFileLocked = 64; +inline constexpr ErrRef kErrorDiskIsTooTiny = 65; +inline constexpr ErrRef kErrorUnimplemented = -1; + +/// @brief The last error reported by the system to the process. +IMPORT_C ErrRef kLastError; diff --git a/dev/libSystem/SystemKit/Jail.h b/dev/libSystem/SystemKit/Jail.h new file mode 100644 index 00000000..93734dcf --- /dev/null +++ b/dev/libSystem/SystemKit/Jail.h @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Jail.h +/// @brief NeKernel Jail System + +struct JAIL_INFO; +struct JAIL; + +/// @brief Jail information (client side struct) +struct JAIL_INFO +{ + SInt32 fParentID; + SInt32 fJailHash; + SInt64 fACL; +}; \ No newline at end of file diff --git a/dev/libSystem/SystemKit/Macros.h b/dev/libSystem/SystemKit/Macros.h new file mode 100644 index 00000000..48c586cc --- /dev/null +++ b/dev/libSystem/SystemKit/Macros.h @@ -0,0 +1,126 @@ +/* ------------------------------------------- + +Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +File: Macros.h +Purpose: libsci Macros header. + +------------------------------------------- */ + +#pragma once + +/***********************************************************************************/ +/// @file libSystem/Macros.h +/// @brief Macros and Core types of the SCI (System Call Interface). +/***********************************************************************************/ + +#include + +#define ATTRIBUTE(X) __attribute__((X)) + +#define IMPORT_CXX extern "C++" +#define IMPORT_C extern "C" + +#define DEPRECATED ATTRIBUTE(deprecated) + +#define EXIT_SUCCESS (0) +#define EXIT_FAILURE (1) + +#define FILE_MAX_LEN (256) + +#ifndef BOOL +#define BOOL bool +#endif + +typedef bool Bool; +typedef bool Boolean; +typedef void Void; + +#ifndef __cplusplus +#define true (1) +#define false (0) +#endif + +#define YES true +#define NO false + +typedef __UINT64_TYPE__ UInt64; +typedef __UINT32_TYPE__ UInt32; +typedef __UINT16_TYPE__ UInt16; +typedef __UINT8_TYPE__ UInt8; + +typedef __SIZE_TYPE__ SizeT; + +typedef __INT64_TYPE__ SInt64; +typedef __INT32_TYPE__ SInt32; +typedef __INT16_TYPE__ SInt16; +typedef __INT8_TYPE__ SInt8; + +typedef void* VoidPtr; +typedef __UINTPTR_TYPE__ UIntPtr; +typedef char Char; + +#ifdef __cplusplus +typedef decltype(nullptr) nullPtr; +typedef nullPtr NullPtr; + +#define LIBSYS_COPY_DELETE(KLASS) \ + KLASS& operator=(const KLASS&) = delete; \ + KLASS(const KLASS&) = delete; + +#define LIBSYS_COPY_DEFAULT(KLASS) \ + KLASS& operator=(const KLASS&) = default; \ + KLASS(const KLASS&) = default; + +#define LIBSYS_MOVE_DELETE(KLASS) \ + KLASS& operator=(KLASS&&) = delete; \ + KLASS(KLASS&&) = delete; + +#define LIBSYS_MOVE_DEFAULT(KLASS) \ + KLASS& operator=(KLASS&&) = default; \ + KLASS(KLASS&&) = default; + +#endif + +#define MUST_PASS(X) _rtl_assert(X, __FILE__) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(X) \ + (((sizeof(X) / sizeof(*(X))) / (static_cast(!(sizeof(X) % sizeof(*(X))))))) +#endif + +#ifndef KIB +#define KIB(X) (UInt64)((X) / 1024) +#endif + +#ifndef kib_cast +#define kib_cast(X) (UInt64)((X) *1024) +#endif + +#ifndef MIB +#define MIB(X) (UInt64)((UInt64) KIB(X) / 1024) +#endif + +#ifndef mib_cast +#define mib_cast(X) (UInt64)((UInt64) kib_cast(X) * 1024) +#endif + +#ifndef GIB +#define GIB(X) (UInt64)((UInt64) MIB(X) / 1024) +#endif + +#ifndef gib_cast +#define gib_cast(X) (UInt64)((UInt64) mib_cast(X) * 1024) +#endif + +#ifndef TIB +#define TIB(X) (UInt64)((UInt64) GIB(X) / 1024) +#endif + +#ifndef tib_cast +#define tib_cast(X) ((UInt64) gib_cast(X) * 1024) +#endif + +#define LIBSYS_UNUSED(X) ((void) X) + +IMPORT_C void _rtl_assert(Bool expr, const Char* origin); diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h new file mode 100644 index 00000000..1a334ead --- /dev/null +++ b/dev/libSystem/SystemKit/Syscall.h @@ -0,0 +1,19 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +#ifndef SYSCALL_HASH +#define SYSCALL_HASH(str) (UInt64)str +#endif // !SYSCALL_HASH + +IMPORT_C VoidPtr libsys_syscall_arg_1(SizeT id); +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); diff --git a/dev/libSystem/SystemKit/System.h b/dev/libSystem/SystemKit/System.h new file mode 100644 index 00000000..b3d10e32 --- /dev/null +++ b/dev/libSystem/SystemKit/System.h @@ -0,0 +1,385 @@ +/* ------------------------------------------- + +Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +File: System.h +Purpose: System Call Interface. + +------------------------------------------- */ + +#ifndef LIBSYS_SYSTEM_CALLS_H +#define LIBSYS_SYSTEM_CALLS_H + +#include + +// ------------------------------------------------------------------------------------------ // +/// @brief Types API. +// ------------------------------------------------------------------------------------------ // + +struct REF_TYPE { + UInt64 __hash; /// @brief Hash of the syscall + VoidPtr __self; /// @brief Syscall self value. +}; + +typedef REF_TYPE* Ref; + +typedef Ref IORef; +typedef Ref FSRef; +typedef Ref DylibRef; +typedef Ref ThreadRef; +typedef Ref SocketRef; +typedef Ref NetworkRef; +typedef Ref MutexRef; +typedef Ref EventRef; +typedef Ref SemaphoreRef; + +// ------------------------------------------------------------------------------------------ // +/// @brief Dynamic Loader API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Get function which is part of the Dylib. +/// @param symbol the symbol to look for +/// @param dll_handle the Dylib handle. +/// @return the proc pointer. +IMPORT_C Ref LdrGetDylibSymbolFromHandle(_Input const Char* symbol, _Input Ref dll_handle); + +/// @brief Open Dylib handle. +/// @param path dll path. +/// @param drv driver letter. +/// @return a dylib ref. +IMPORT_C Ref LdrOpenDylibHandle(_Input const Char* path, _Input const Char* drive_letter); + +/// @brief Close Dylib handle +/// @param dll_handle the dylib ref. +/// @return whether it closed or not. +IMPORT_C UInt32 LdrCloseDylibHandle(_Input Ref* dll_handle); + +// ------------------------------------------------------------------------------------------ // +// File API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Opens a file from a drive. +/// @param fs_path the filesystem path. +/// @param drive_letter drive name, use NULL to use default drive location. +/// @return the file descriptor of the file. +IMPORT_C Ref IoOpenFile(const Char* fs_path, const Char* drive_letter); + +/// @brief Closes a file and flushes its content. +/// @param file_desc the file descriptor. +/// @return Function doesn't return a type. +IMPORT_C Void IoCloseFile(_Input Ref file_desc); + +/// @brief I/O control (ioctl) on a file. +/// @param file_desc the file descriptor. +/// @param ioctl_code the ioctl code. +/// @param in_data the input data. +/// @param out_data the output data. +/// @return the number of bytes written. +/// @note This function is used to control the file descriptor, introduced for HeFS. +IMPORT_C SInt32 IoCtrlFile(_Input Ref file_desc, _Input UInt32 ioctl_code, _Input VoidPtr in_data, + _Output VoidPtr out_data); + +/// @brief Gets the file mime (if any) +/// @param file_desc the file descriptor. +IMPORT_C const Char* IoMimeFile(_Input Ref file_desc); + +/// @brief Gets the dir DIM. +/// @param dir_desc directory descriptor. +/// @note only works in HeFS, will return nil-x/nil if used on any other filesystem. +IMPORT_C const Char* IoDimFile(_Input Ref dir_desc); + +/// @brief Write data to a file ref +/// @param file_desc the file descriptor. +/// @param out_data the data to write. +/// @param sz_data the size of the data to write. +/// @return the number of bytes written. +IMPORT_C UInt32 IoWriteFile(_Input Ref file_desc, _Output VoidPtr out_data, SizeT sz_data); + +/// @brief Read data from a file. +/// @param file_desc the file descriptor. +/// @param out_data the data to read. +/// @param sz_data the size of the data to read. +IMPORT_C UInt32 IoReadFile(_Input Ref file_desc, _Output VoidPtr* out_data, SizeT sz_data); + +/// @brief Rewind the file pointer to the beginning of the file. +/// @param file_desc the file descriptor. +/// @return the number of bytes read. +IMPORT_C UInt64 IoRewindFile(_Input Ref file_desc); + +/// @brief Tell the current position of the file pointer. +/// @param file_desc the file descriptor. +/// @return the current position of the file pointer. +IMPORT_C UInt64 IoTellFile(_Input Ref file_desc); + +/// @brief Seek file offset from file descriptor. +IMPORT_C UInt64 IoSeekFile(_Input Ref file_desc, UInt64 file_offset); + +// ------------------------------------------------------------------------ +// Process API. +// ------------------------------------------------------------------------ + +/// @brief Spawns a Thread Information Block and Global Information Block inside the current +/// process. +/// @param process_id Target Process ID, must be valid. +/// @return > 0 error occurred or already present, = 0 success. +IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id); + +/// @brief Spawns a process with a unique pid (stored as UIntPtr). +/// @param process_path process filesystem path. +/// @return > 0 process was created. +IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** argv, Char** envp, + SizeT envp_len); + +/// @brief Exits a process with an exit_code. +/// @return if it has succeeded true, otherwise false. +IMPORT_C Bool RtlExitProcess(UIntPtr handle, UIntPtr exit_code); + +// ------------------------------------------------------------------------ +// Memory Manager API. +// ------------------------------------------------------------------------ + +/// @brief Creates a new heap from the process's address space. +/// @param len the length of it. +/// @param flags the flags of it. +/// @return heap pointer. +IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); + +/// @brief Destroys the pointer +/// @param heap the heap itself. +/// @return void. +IMPORT_C SInt32 MmDestroyHeap(_Input VoidPtr heap); + +/// @brief Change protection flags of a memory region. +IMPORT_C SInt32 MmSetHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); + +/// @brief Change protection flags of a memory region. +IMPORT_C UInt32 MmGetHeapFlags(_Input VoidPtr heap); + +/// @brief Fill memory region with CRC32. +IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); + +/// @brief Copy memory region. +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); + +/// @brief Compare memory regions. +IMPORT_C SInt64 MmCmpMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len); + +/// @brief Fill memory region. +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value); + +/// @brief Compare string regions. +IMPORT_C SInt64 MmStrCmp(_Input const Char* dest, _Input const Char* src); + +/// @brief Get length of string. +IMPORT_C SInt64 MmStrLen(const Char* str); + +// ------------------------------------------------------------------------ +// @brief Error API. +// ------------------------------------------------------------------------ + +IMPORT_C SInt32 ErrGetLastError(Void); + +// ------------------------------------------------------------------------ +// @brief Threading API. +// ------------------------------------------------------------------------ + +/// @brief Exit the current thread. +/// @param exit_code the exit code. +IMPORT_C SInt32 ThrExitCurrentThread(_Input SInt32 exit_code); + +/// @brief Exit the main thread. +/// @param exit_code the exit code. +IMPORT_C SInt32 ThrExitMainThread(_Input SInt32 exit_code); + +/// @brief Exit a thread. +/// @param thread the thread to exit. +/// @param exit_code the exit code. +IMPORT_C SInt32 ThrExitThread(_Input ThreadRef thread, _Input SInt32 exit_code); + +/// @brief Thread procedure function type. +typedef SInt32 (*ThrProcKind)(SInt32 argc, Char** argv); + +/// @brief Creates a thread. +/// @param procedure the thread procedure. +/// @param argument_count number of arguments inside that thread. +/// @param flags Thread flags. +/// @return the thread object. +IMPORT_C ThreadRef ThrCreateThread(const Char* thread_name, ThrProcKind procedure, + SInt32 argument_count, SInt32 flags); + +/// @brief Yields the current thread. +/// @param thread the thread to yield. +IMPORT_C SInt32 ThrYieldThread(ThreadRef thrd); + +/// @brief Joins a thread. +/// @param thread the thread to join. +IMPORT_C SInt32 ThrJoinThread(ThreadRef thrd); + +/// @brief Detach a thread. +/// @param thread the thread to detach. +IMPORT_C SInt32 ThrDetachThread(ThreadRef thrd); + +// ------------------------------------------------------------------------ +// @brief Drive Management API. +// ------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------ // +/// @brief Get the default drive letter. +/// @param void. +/// @return the drive letter. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Char* DrvGetDefaultDriveLetter(Void); + +// ------------------------------------------------------------------------------------------ // +/// @brief Get the drive letter from a path. +/// @param path the path. +/// @return the drive letter. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path); + +// ------------------------------------------------------------------------------------------ // +/// @brief Get a mounted drive from a letter. +/// @param letter the letter (A..Z). +/// @return the drive object. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Ref DrvGetMountedDrive(_Input Char letter); + +// ------------------------------------------------------------------------------------------ // +/// @brief Mount a drive. +/// @param path the path to mount. +/// @param letter the letter to mount. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter); + +// ------------------------------------------------------------------------------------------ // +/// @brief Unmount a drive. +/// @param letter the letter to unmount. +// ------------------------------------------------------------------------------------------ // +IMPORT_C Void DrvUnmountDrive(_Input Char letter); + +// ------------------------------------------------------------------------ +// Event handling API, use to listen to OS specific events. +// ------------------------------------------------------------------------ + +// ------------------------------------------------------------------------------------------ // +/// @brief Add an event listener. +/// @param event_name the event name. +/// @param listener the listener to add. +/// @return the event listener. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input Ref listener); + +// ------------------------------------------------------------------------------------------ // +/// @brief Remove an event listener. +/// @param event_name the event name. +/// @param listener the listener to remove. +/// @return the event listener. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input Ref listener); + +// ------------------------------------------------------------------------------------------ // +/// @brief Dispatch an event. +/// @param event_name the event name. +/// @param event_data the event data. +/// @return the event data. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data); + +// ------------------------------------------------------------------------------------------ // +// Power API. +// ------------------------------------------------------------------------------------------ // + +enum { + kPowerCodeInvalid = 0, + kPowerCodeShutdown = 12, + kPowerCodeReboot, + kPowerCodeSleep, + kPowerCodeWake, + kPowerCodeCount, +}; + +IMPORT_C SInt32 PwrReadCode(_Output SInt32& code); + +IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); + +// ------------------------------------------------------------------------------------------ // +// CD-ROM API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C SInt32 CdEjectDrive(_Input Char drv_letter); + +IMPORT_C SInt32 CdOpenTray(Void); + +IMPORT_C SInt32 CdCloseTray(Void); + +// ------------------------------------------------------------------------------------------ // +// Printer API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C SInt32 PrintOut(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); + +IMPORT_C SInt32 PrintIn(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); + +IMPORT_C IORef PrintCreate(Void); + +IMPORT_C SInt32 PrintRelease(IORef); + +IMPORT_C IORef PrintGet(const Char* path); + +// ------------------------------------------------------------------------------------------ // +// @brief Scheduler/Debug API. +// ------------------------------------------------------------------------------------------ // + +typedef SInt32 AffinityRef; +typedef UInt64 ProcessRef; + +IMPORT_C SInt32 SchedSetAffinity(_Input ProcessRef, SInt32 req, _Input AffinityRef*); + +IMPORT_C SInt32 SchedGetAffinity(_Input ProcessRef, _InOut AffinityRef*); + +IMPORT_C SInt32 SchedFireSignal(_Input ProcessRef, SInt32); + +IMPORT_C SInt32 SchedReadMemory(_Input ProcessRef, SInt32, SInt32); + +IMPORT_C SInt32 SchedWriteMemory(_Input ProcessRef, SInt32, SInt32); + +IMPORT_C UIntPtr SchedGetCurrentProcessID(Void); + +// ------------------------------------------------------------------------------------------ // +// @brief Filesystem API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C BOOL FsCopy(const Char* path, const Char* dst); + +IMPORT_C BOOL FsMove(const Char* path, const Char* dst); + +IMPORT_C BOOL FsExists(const Char* path); + +IMPORT_C BOOL FsCreateDir(const Char* path); + +IMPORT_C BOOL FsCreateFile(const Char* path); + +IMPORT_C BOOL FsCreateAlias(const Char* path, const Char* from); + +// ------------------------------------------------------------------------------------------ // +// @brief Installable Filesystem API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C BOOL IfsMount(const Char* path, const Char* drive_letter); + +IMPORT_C BOOL IfsUnmount(const Char* drive_letter); + +IMPORT_C BOOL IfsIsMounted(const Char* drive_letter); + +// ------------------------------------------------------------------------------------------ // +// @brief String Manip API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C Char* StrFmt(const Char* fmt, ...); + +IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base); + +#endif // ifndef LIBSYS_SYSTEM_CALLS_H diff --git a/dev/libSystem/src/Makefile b/dev/libSystem/src/Makefile index 41c99c4d..39af446b 100644 --- a/dev/libSystem/src/Makefile +++ b/dev/libSystem/src/Makefile @@ -13,4 +13,4 @@ error: .PHONY: libsys_asm_io_x64 libsys_asm_io_x64: - $(ASM) $(FLAGS) SystemProc.asm -o SystemProc.asm.obj + $(ASM) $(FLAGS) SystemProc.asm -o SystemProc.stub.obj diff --git a/dev/libSystem/src/SystemAPI.cc b/dev/libSystem/src/SystemAPI.cc deleted file mode 100644 index 37e835c1..00000000 --- a/dev/libSystem/src/SystemAPI.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/// @file SystemAPI.cc -/// @brief System wide API for NeKernel. - -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { - if (!len || !dest || !src) { - return nullptr; - } - - for (SizeT i = 0; i < len; i++) { - ((Char*) dest)[i] = ((Char*) src)[i]; - } - - return dest; -} - -IMPORT_C SInt64 MmStrLen(const Char* in) { - if (!in) return 0; - - SizeT len{0}; - - do { - ++len; - } while (in[len] != '\0'); - - return len; -} - -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { - if (!len || !dest) { - return nullptr; - } - - for (SizeT i = 0; i < len; i++) { - ((Char*) dest)[i] = value; - } - - return dest; -} - -IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return (Ref)libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), reinterpret_cast(const_cast(path)), - reinterpret_cast(const_cast(drv_letter))); -} - -IMPORT_C Void IoCloseFile(_Input Ref desc) { - libsys_syscall_arg_2(2, desc); -} - -IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret = (volatile UInt64*) libsys_syscall_arg_3(SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), - reinterpret_cast(&off)); - - MUST_PASS((*ret) != ~0UL); - return *ret; -} - -IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), reinterpret_cast(desc)); - return *ret; -} - -IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { - va_list args; - - va_start(args, fmt); - - auto ret = (volatile UInt64*) libsys_syscall_arg_4( - SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), reinterpret_cast(const_cast(fmt)), args); - - va_end(args); - - return *ret; -} - -IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { - if (!expr) { - PrintOut(nullptr, "Assertion failed: %s\r", origin); - PrintOut(nullptr, "Origin: %s\r", origin); - - libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break')); - } -} diff --git a/dev/libSystem/src/SystemImpl.cc b/dev/libSystem/src/SystemImpl.cc new file mode 100644 index 00000000..6c2201fe --- /dev/null +++ b/dev/libSystem/src/SystemImpl.cc @@ -0,0 +1,91 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include + +/// @file SystemAPI.cc +/// @brief System wide API for NeKernel. + +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { + if (!len || !dest || !src) { + return nullptr; + } + + for (SizeT i = 0; i < len; i++) { + ((Char*) dest)[i] = ((Char*) src)[i]; + } + + return dest; +} + +IMPORT_C SInt64 MmStrLen(const Char* in) { + if (!in) return 0; + + SizeT len{0}; + + do { + ++len; + } while (in[len] != '\0'); + + return len; +} + +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) { + if (!len || !dest) { + return nullptr; + } + + for (SizeT i = 0; i < len; i++) { + ((Char*) dest)[i] = value; + } + + return dest; +} + +IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { + return (Ref)libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), reinterpret_cast(const_cast(path)), + reinterpret_cast(const_cast(drv_letter))); +} + +IMPORT_C Void IoCloseFile(_Input Ref desc) { + libsys_syscall_arg_2(2, desc); +} + +IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { + auto ret = (volatile UInt64*) libsys_syscall_arg_3(SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), + reinterpret_cast(&off)); + + MUST_PASS((*ret) != ~0UL); + return *ret; +} + +IMPORT_C UInt64 IoTellFile(_Input Ref desc) { + auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), reinterpret_cast(desc)); + return *ret; +} + +IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { + va_list args; + + va_start(args, fmt); + + auto ret = (volatile UInt64*) libsys_syscall_arg_4( + SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), reinterpret_cast(const_cast(fmt)), args); + + va_end(args); + + return *ret; +} + +IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { + if (!expr) { + PrintOut(nullptr, "Assertion failed: %s\r", origin); + PrintOut(nullptr, "Origin: %s\r", origin); + + libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break')); + } +} diff --git a/dev/libSystem/src/SystemProc.asm b/dev/libSystem/src/SystemProc.asm index bc41059a..299b59f9 100644 --- a/dev/libSystem/src/SystemProc.asm +++ b/dev/libSystem/src/SystemProc.asm @@ -21,7 +21,8 @@ libsys_syscall_arg_1: mov rbp, rsp mov r8, rcx - syscall + + int 50 pop rbp @@ -33,7 +34,9 @@ libsys_syscall_arg_2: mov r8, rcx mov r9, rdx - syscall + + int 50 + pop rbp ret @@ -46,7 +49,8 @@ libsys_syscall_arg_3: mov r9, rdx mov r10, rbx - syscall + int 50 + pop rbp ret @@ -60,7 +64,8 @@ libsys_syscall_arg_4: mov r10, rbx mov r11, rax - syscall + int 50 + pop rbp ret diff --git a/dev/open_msg/.keep b/dev/open_msg/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/open_msg/MsgKit/Server.h b/dev/open_msg/MsgKit/Server.h new file mode 100644 index 00000000..867d3b54 --- /dev/null +++ b/dev/open_msg/MsgKit/Server.h @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +struct OPENMSG_EXPR; + +struct OPENMSG_EXPR { + Kernel::KString* l_head; + Kernel::MutableArray l_args; +}; + +typedef Kernel::Void(*openmsg_func_t)(OPENMSG_EXPR* arg); + +EXTERN_C Kernel::Void openmsg_init_library(openmsg_func_t* funcs, Kernel::SizeT cnt); +EXTERN_C Kernel::UInt32 openmsg_close_library(Kernel::Void); diff --git a/dev/open_msg/obj/.keep b/dev/open_msg/obj/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/open_msg/script/window.msg b/dev/open_msg/script/window.msg new file mode 100644 index 00000000..77d6ef69 --- /dev/null +++ b/dev/open_msg/script/window.msg @@ -0,0 +1,6 @@ +(window + :id 1 + :pos (x 100 y 100) + :size (w 300 h 200) + :title "My App" + :on-click (lambda () (log "Clicked!"))) \ No newline at end of file diff --git a/dev/open_msg/src/.keep b/dev/open_msg/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/dev/system_sdk/.keep b/dev/system_sdk/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json b/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json index a208f57a..076b35ae 100644 --- a/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json +++ b/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./", "../../../dev", "../../../dev/kernel"], "sources_path": ["src/*.cc"], - "output_name": "./dist/libCoreFoundation.dylib", + "output_name": "./dist/libCoreFoundation.fwrk.dylib", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Array.h b/public/frameworks/CoreFoundation.fwrk/headers/Array.h index 55e75e5e..d9c528d9 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Array.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Array.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace CF { template diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h index 1f295ea5..500ad544 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h @@ -10,7 +10,7 @@ #pragma once -#include +#include namespace CF { class CFString; diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Property.h b/public/frameworks/CoreFoundation.fwrk/headers/Property.h index 4da173c7..5210bd95 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Property.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Property.h @@ -8,7 +8,7 @@ #define _PROPS_H #include -#include +#include #define kMaxPropLen (256U) diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h index cb72a034..87005db1 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h @@ -9,7 +9,7 @@ #define _REF_H_ #include -#include +#include namespace CF { template diff --git a/public/frameworks/DiskImage.fwrk/DiskImage.json b/public/frameworks/DiskImage.fwrk/DiskImage.json index aaff409c..16c538e5 100644 --- a/public/frameworks/DiskImage.fwrk/DiskImage.json +++ b/public/frameworks/DiskImage.fwrk/DiskImage.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./", "../../../dev", "../../../dev/kernel"], "sources_path": ["src/*.cc"], - "output_name": "./dist/libDiskImage.dylib", + "output_name": "./dist/libDiskImage.fwrk.dylib", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h index efc21253..53348f3e 100644 --- a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h +++ b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h @@ -9,7 +9,7 @@ #pragma once -#include +#include #ifndef __DISK_IMAGE_CDROM__ #define kDISectorSz (512) diff --git a/public/frameworks/KernelTest.fwrk/KernelTest.json b/public/frameworks/KernelTest.fwrk/KernelTest.json index aa70db30..b8c322b6 100644 --- a/public/frameworks/KernelTest.fwrk/KernelTest.json +++ b/public/frameworks/KernelTest.fwrk/KernelTest.json @@ -3,7 +3,7 @@ "compiler_std": "c++20", "headers_path": ["../", "./", "../../../dev", "../../../dev/kernel"], "sources_path": ["src/*.cc"], - "output_name": "./dist/libKernelTest.dylib", + "output_name": "./dist/libKernelTest.fwrk.dylib", "compiler_flags": [ "-ffreestanding", "-shared", diff --git a/public/frameworks/OpenMSG.fwrk/.keep b/public/frameworks/OpenMSG.fwrk/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/OpenMSG.fwrk/OpenMSG.json b/public/frameworks/OpenMSG.fwrk/OpenMSG.json new file mode 100644 index 00000000..4bda8798 --- /dev/null +++ b/public/frameworks/OpenMSG.fwrk/OpenMSG.json @@ -0,0 +1,19 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "./", + "../../../dev/kernel", + "../../../public/frameworks/", + "../../../dev/", + "./" + ], + "sources_path": [], + "output_name": "./dist/libOpenMSG.fwrk.dylib", + "cpp_macros": [ + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", + "__NE_SDK__" + ] +} \ No newline at end of file diff --git a/public/frameworks/OpenMSG.fwrk/headers/.keep b/public/frameworks/OpenMSG.fwrk/headers/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/OpenMSG.fwrk/src/.keep b/public/frameworks/OpenMSG.fwrk/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/OpenMSG.fwrk/src/DylibMain.cc b/public/frameworks/OpenMSG.fwrk/src/DylibMain.cc new file mode 100644 index 00000000..814132e3 --- /dev/null +++ b/public/frameworks/OpenMSG.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/OpenMSG.fwrk/xml/.keep b/public/frameworks/OpenMSG.fwrk/xml/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/frameworks/OpenMSG.fwrk/xml/app.xml b/public/frameworks/OpenMSG.fwrk/xml/app.xml new file mode 100644 index 00000000..6a46e598 --- /dev/null +++ b/public/frameworks/OpenMSG.fwrk/xml/app.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/public/tools/cc/src/CommandLine.cc b/public/tools/cc/src/CommandLine.cc index f1c72b64..62757c43 100644 --- a/public/tools/cc/src/CommandLine.cc +++ b/public/tools/cc/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief Placeholder program. diff --git a/public/tools/ld.dyn/src/CommandLine.cc b/public/tools/ld.dyn/src/CommandLine.cc index 70a0dbd9..e64e7837 100644 --- a/public/tools/ld.dyn/src/CommandLine.cc +++ b/public/tools/ld.dyn/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief Library loader. diff --git a/public/tools/ld.fwrk/src/CommandLine.cc b/public/tools/ld.fwrk/src/CommandLine.cc index 853a4ef7..323e58c7 100644 --- a/public/tools/ld.fwrk/src/CommandLine.cc +++ b/public/tools/ld.fwrk/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief This program loads a code framework into Kernel's memory. diff --git a/public/tools/manual/src/CommandLine.cc b/public/tools/manual/src/CommandLine.cc index 68594c09..8c75d565 100644 --- a/public/tools/manual/src/CommandLine.cc +++ b/public/tools/manual/src/CommandLine.cc @@ -1,4 +1,4 @@ -#include +#include SInt32 _NeMain(SInt32 argc, Char* argv[]) { LIBSYS_UNUSED(argc); diff --git a/public/tools/mgmt/src/CommandLine.cc b/public/tools/mgmt/src/CommandLine.cc index f3840d01..6015988e 100644 --- a/public/tools/mgmt/src/CommandLine.cc +++ b/public/tools/mgmt/src/CommandLine.cc @@ -1,4 +1,4 @@ -#include +#include SInt32 _NeMain(SInt32 argc, Char* argv[]) { return EXIT_FAILURE; diff --git a/public/tools/mk.fwrk/Common.h b/public/tools/mk.fwrk/Common.h index 89e52471..8e434043 100644 --- a/public/tools/mk.fwrk/Common.h +++ b/public/tools/mk.fwrk/Common.h @@ -7,6 +7,6 @@ #define APPS_COMMON_H #include -#include +#include #endif // APPS_COMMON_H diff --git a/public/tools/mk.fwrk/src/CommandLine.cc b/public/tools/mk.fwrk/src/CommandLine.cc index 423dc12f..87945ddc 100644 --- a/public/tools/mk.fwrk/src/CommandLine.cc +++ b/public/tools/mk.fwrk/src/CommandLine.cc @@ -7,7 +7,7 @@ #include #include -#include +#include #include diff --git a/public/tools/mk.hefs/src/CommandLine.cc b/public/tools/mk.hefs/src/CommandLine.cc index 0b38386a..91a3527d 100644 --- a/public/tools/mk.hefs/src/CommandLine.cc +++ b/public/tools/mk.hefs/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2025 Amlal El Mahrouss */ -#include +#include /// @brief Placeholder program. diff --git a/public/tools/mk.nefs/src/CommandLine.cc b/public/tools/mk.nefs/src/CommandLine.cc index 0b38386a..91a3527d 100644 --- a/public/tools/mk.nefs/src/CommandLine.cc +++ b/public/tools/mk.nefs/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2025 Amlal El Mahrouss */ -#include +#include /// @brief Placeholder program. diff --git a/public/tools/open/src/CommandLine.cc b/public/tools/open/src/CommandLine.cc index 6fa4e2f2..e02fcebc 100644 --- a/public/tools/open/src/CommandLine.cc +++ b/public/tools/open/src/CommandLine.cc @@ -4,7 +4,7 @@ * Copyright (c) 2024-2025 Amlal El Mahrouss */ -#include +#include /// @brief This program opens an application from **OPEN_APP_BASE_PATH** /// @file CommandLine.cc diff --git a/public/tools/ping/src/CommandLine.cc b/public/tools/ping/src/CommandLine.cc index 580d7973..a9ba177a 100644 --- a/public/tools/ping/src/CommandLine.cc +++ b/public/tools/ping/src/CommandLine.cc @@ -1,4 +1,4 @@ -#include +#include SInt32 _NeMain(SInt32 argc, Char* argv[]) { LIBSYS_UNUSED(argc); diff --git a/tooling/mk_app.py b/tooling/mk_app.py index 5ee6d5b7..7f7cef17 100755 --- a/tooling/mk_app.py +++ b/tooling/mk_app.py @@ -64,7 +64,7 @@ def create_directory_structure(base_path, project_name): proj_cpp_path = os.path.join(base_path, project_name, f"src/CommandLine.cc") - cpp_file = "#include \n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include \n\nSInt32 _NeMain(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" with open(proj_cpp_path, 'w') as cpp_file_io: cpp_file_io.write(cpp_file) diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py index e4e5d7de..b2ef99ff 100755 --- a/tooling/mk_fwrk.py +++ b/tooling/mk_fwrk.py @@ -56,7 +56,7 @@ def create_directory_structure(base_path_fwrk, project_file_name, project_name): "sources_path": [ ], - "output_name": f"./dist/{project_name}", + "output_name": f"./dist/lib{project_name}.dylib", "cpp_macros": [ "kSampleFWVersion=0x0100", "kSampleFWVersionHighest=0x0100", @@ -70,7 +70,7 @@ def create_directory_structure(base_path_fwrk, project_file_name, project_name): proj_cpp_path = os.path.join(base_path_fwrk, project_name, f"src/DylibMain.cc") - cpp_file = "#include \n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" + cpp_file = "#include \n\nSInt32 _DylibAttach(SInt32 argc, Char* argv[]) {\n\treturn EXIT_FAILURE;\n}" with open(proj_cpp_path, 'w') as cpp_file_io: cpp_file_io.write(cpp_file) -- cgit v1.2.3 From baaa09cefe3ed0f2bbf9d93e07d55e60a04ca17f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 30 May 2025 16:48:00 +0200 Subject: refactor: Format codebase and fix warning in UserProcessScheduler. Signed-off-by: Amlal El Mahrouss --- dev/boot/modules/BootNet/BootNet.cc | 2 +- dev/boot/src/BootFileReader.cc | 2 +- dev/boot/src/HEL/AMD64/BootEFI.cc | 4 +-- dev/boot/src/HEL/ARM64/BootEFI.cc | 4 +-- dev/generic_kits/BenchKit/X64Chrono.h | 2 +- dev/kernel/DmaKit/DmaPool.h | 2 +- dev/kernel/FirmwareKit/EFI/EFI.h | 2 +- dev/kernel/FirmwareKit/GPT.h | 36 +++++++++++----------- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 4 +-- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 5 +-- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 6 ++-- dev/kernel/KernelKit/DeviceMgr.h | 2 +- dev/kernel/KernelKit/UserMgr.h | 8 ++--- dev/kernel/KernelKit/UserProcessScheduler.h | 17 +++++----- dev/kernel/NeKit/ErrorOr.h | 8 ++--- dev/kernel/NeKit/Ref.h | 4 +-- dev/kernel/src/Storage/AHCIDeviceInterface.cc | 4 +-- dev/kernel/src/Storage/ATADeviceInterface.cc | 3 +- dev/kernel/src/Storage/NVMEDeviceInterface.cc | 7 ++--- dev/kernel/src/UserProcessScheduler.cc | 18 +++++------ dev/kernel/src/UserProcessTeam.cc | 2 +- dev/libSystem/SystemKit/Jail.h | 3 +- dev/libSystem/SystemKit/Macros.h | 8 ++--- dev/libSystem/SystemKit/Syscall.h | 4 +-- dev/libSystem/SystemKit/System.h | 4 +-- dev/libSystem/src/SystemImpl.cc | 15 +++++---- dev/open_msg/MsgKit/Server.h | 6 ++-- public/frameworks/OpenMSG.fwrk/src/DylibMain.cc | 2 +- 28 files changed, 95 insertions(+), 89 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 2fbd7edc..ba9beef4 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -12,7 +12,7 @@ #include #include -STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, diff --git a/dev/boot/src/BootFileReader.cc b/dev/boot/src/BootFileReader.cc index 2f409848..5aadd608 100644 --- a/dev/boot/src/BootFileReader.cc +++ b/dev/boot/src/BootFileReader.cc @@ -48,7 +48,7 @@ Boot::BootFileReader::BootFileReader(const CharacterTypeUTF16* path, EfiHandlePt EfiSimpleFilesystemProtocol* efp = nullptr; EfiLoadImageProtocol* img = nullptr; - EFI_GUID guidImg = EFI_GUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); + EFI_GUID guidImg = EFI_GUID(EFI_LOADED_IMAGE_PROTOCOL_GUID); if (BS->HandleProtocol(ImageHandle, &guidImg, (void**) &img) != kEfiOk) { mWriter.Write(L"BootZ: Handle-Protocol: No-Such-Protocol").Write(L"\r"); diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 3685add5..166e0169 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -21,7 +21,7 @@ STATIC EfiGraphicsOutputProtocol* kGop = nullptr; STATIC UInt16 kGopStride = 0U; -STATIC EFI_GUID kGopGuid; +STATIC EFI_GUID kGopGuid; /** Related to jumping to the reset vector. */ @@ -102,7 +102,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // Grab MP services, extended to runtime. // // ------------------------------------------- // - EFI_GUID guid_mp = EFI_GUID(EFI_MP_SERVICES_PROTOCOL_GUID); + EFI_GUID guid_mp = EFI_GUID(EFI_MP_SERVICES_PROTOCOL_GUID); EfiMpServicesProtocol* mp = nullptr; BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast(&mp)); diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 1633cb39..66f91352 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -29,7 +29,7 @@ STATIC EfiGraphicsOutputProtocol* kGop = nullptr; STATIC UInt16 kGopStride = 0U; -STATIC EFI_GUID kGopGuid; +STATIC EFI_GUID kGopGuid; EXTERN_C Void rt_reset_hardware(); @@ -107,7 +107,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // Grab MP services, extended to runtime. // // ------------------------------------------- // - EFI_GUID guid_mp = EFI_GUID(EFI_MP_SERVICES_PROTOCOL_GUID); + EFI_GUID guid_mp = EFI_GUID(EFI_MP_SERVICES_PROTOCOL_GUID); EfiMpServicesProtocol* mp = nullptr; BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast(&mp)); diff --git a/dev/generic_kits/BenchKit/X64Chrono.h b/dev/generic_kits/BenchKit/X64Chrono.h index 1578814f..229146cb 100644 --- a/dev/generic_kits/BenchKit/X64Chrono.h +++ b/dev/generic_kits/BenchKit/X64Chrono.h @@ -15,7 +15,7 @@ class X64Chrono; struct X64ChronoTraits; struct X64ChronoTraits { -private: + private: STATIC UInt64 TickImpl_(void) { UInt64 a = 0, d = 0; __asm__ volatile("rdtsc" : "=a"(a), "=d"(d)); diff --git a/dev/kernel/DmaKit/DmaPool.h b/dev/kernel/DmaKit/DmaPool.h index ec98745d..9decb3f1 100644 --- a/dev/kernel/DmaKit/DmaPool.h +++ b/dev/kernel/DmaKit/DmaPool.h @@ -44,7 +44,7 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { kDmaPoolPtr = (UInt8*) (addr + size); - HAL::mm_memory_fence((VoidPtr)addr); + HAL::mm_memory_fence((VoidPtr) addr); return (VoidPtr) addr; } diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index ed22f1e9..97e3ad01 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -664,7 +664,7 @@ typedef struct EfiSystemTable { /// The configuration table (contains the RSD PTR entry.) struct { EFI_GUID VendorGUID; - VoidPtr VendorTable; + VoidPtr VendorTable; } * ConfigurationTable; } EfiSystemTable; diff --git a/dev/kernel/FirmwareKit/GPT.h b/dev/kernel/FirmwareKit/GPT.h index df0ed286..f361c4a2 100644 --- a/dev/kernel/FirmwareKit/GPT.h +++ b/dev/kernel/FirmwareKit/GPT.h @@ -20,29 +20,29 @@ struct GPT_PARTITION_TABLE; struct GPT_PARTITION_ENTRY; struct PACKED GPT_PARTITION_TABLE final { - Char Signature[kMagicLenGPT]; - UInt32 Revision; - UInt32 HeaderSize; - UInt32 CRC32; - UInt32 Reserved1; - UInt64 LBAHeader; - UInt64 LBAAltHeader; - UInt64 FirstGPTEntry; - UInt64 LastGPTEntry; + Char Signature[kMagicLenGPT]; + UInt32 Revision; + UInt32 HeaderSize; + UInt32 CRC32; + UInt32 Reserved1; + UInt64 LBAHeader; + UInt64 LBAAltHeader; + UInt64 FirstGPTEntry; + UInt64 LastGPTEntry; EFI_GUID Guid; - UInt64 StartingLBA; - UInt32 NumPartitionEntries; - UInt32 SizeOfEntries; - UInt32 CRC32PartEntry; - UInt8 Reserved2[kSectorAlignGPT_PartTbl]; + UInt64 StartingLBA; + UInt32 NumPartitionEntries; + UInt32 SizeOfEntries; + UInt32 CRC32PartEntry; + UInt8 Reserved2[kSectorAlignGPT_PartTbl]; }; struct PACKED GPT_PARTITION_ENTRY { EFI_GUID PartitionTypeGUID; EFI_GUID UniquePartitionGUID; - UInt64 StartLBA; - UInt64 EndLBA; - UInt64 Attributes; - UInt8 Name[kSectorAlignGPT_PartEntry]; + UInt64 StartLBA; + UInt64 EndLBA; + UInt64 Attributes; + UInt8 Name[kSectorAlignGPT_PartEntry]; }; } // namespace Kernel diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 3e10d577..5bdfd863 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -201,9 +201,9 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { volatile LAPIC* entry_struct = (volatile LAPIC*) entry_ptr; if (entry_struct->Flags & 0x1) { - kAPICLocales[kSMPCount] = entry_struct->ProcessorID; + kAPICLocales[kSMPCount] = entry_struct->ProcessorID; kHWThread[kSMPCount].mThreadID = kAPICLocales[kSMPCount]; - + ++kSMPCount; kout << "Kind: LAPIC: ON\r"; diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index a9bdc89b..cd41480a 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -546,7 +546,8 @@ namespace Detail { /// @brief Read AHCI device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_ahci(DeviceInterface* self, MountpointInterface* mnt) { + STATIC Void sk_io_read_ahci(DeviceInterface* self, + MountpointInterface* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; err_global_get() = kErrorDisk; @@ -568,7 +569,7 @@ namespace Detail { /// @param self device /// @param mnt mounted disk. STATIC Void sk_io_write_ahci(DeviceInterface* self, - MountpointInterface* mnt) { + MountpointInterface* mnt) { AHCIDeviceInterface* dev = (AHCIDeviceInterface*) self; err_global_get() = kErrorDisk; diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index 7b121c64..6fccbdfa 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -200,7 +200,8 @@ namespace Detail { /// @brief Read PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_read_pio(DeviceInterface* self, MountpointInterface* mnt) { + STATIC Void sk_io_read_pio(DeviceInterface* self, + MountpointInterface* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; @@ -221,7 +222,8 @@ namespace Detail { /// @brief Write PIO device. /// @param self device /// @param mnt mounted disk. - STATIC Void sk_io_write_pio(DeviceInterface* self, MountpointInterface* mnt) { + STATIC Void sk_io_write_pio(DeviceInterface* self, + MountpointInterface* mnt) { ATADeviceInterface* dev = (ATADeviceInterface*) self; err_global_get() = kErrorDisk; diff --git a/dev/kernel/KernelKit/DeviceMgr.h b/dev/kernel/KernelKit/DeviceMgr.h index d82b43dc..c6467190 100644 --- a/dev/kernel/KernelKit/DeviceMgr.h +++ b/dev/kernel/KernelKit/DeviceMgr.h @@ -42,7 +42,7 @@ template class DeviceInterface { public: DeviceInterface() = default; - + explicit DeviceInterface(void (*Out)(DeviceInterface*, T), void (*In)(DeviceInterface*, T)) : fOut(Out), fIn(In) {} diff --git a/dev/kernel/KernelKit/UserMgr.h b/dev/kernel/KernelKit/UserMgr.h index 82f8ca66..89436025 100644 --- a/dev/kernel/KernelKit/UserMgr.h +++ b/dev/kernel/KernelKit/UserMgr.h @@ -34,11 +34,11 @@ namespace Kernel { class User; -enum class UserRingKind { +enum class UserRingKind : Int32 { kRingInvalid = 0, - kRingStdUser = 1, - kRingSuperUser = 2, - kRingGuestUser = 5, + kRingStdUser = 444, + kRingSuperUser = 666, + kRingGuestUser = 777, kRingCount = 3, }; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 23636ffb..7c994726 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -125,7 +125,7 @@ class USER_PROCESS final { /***********************************************************************************/ //! @brief Gets the local exit code. /***********************************************************************************/ - const UInt32& GetExitCode() noexcept; + KPCError& GetExitCode() noexcept; /***********************************************************************************/ ///! @brief Get the process's name @@ -137,21 +137,22 @@ class USER_PROCESS final { //! @brief return local error code of process. //! @return Int32 local error code. /***********************************************************************************/ - Int32& GetLocalCode() noexcept; + KPCError& GetLocalCode() noexcept; const User* GetOwner() noexcept; const ProcessStatusKind& GetStatus() noexcept; const AffinityKind& GetAffinity() noexcept; private: - UInt32 LastExitCode{0}; - KPCError LocalCode{0}; + KPCError LastExitCode{0}; + KPCError LocalCode{0}; friend UserProcessScheduler; friend UserProcessHelper; }; typedef Array USER_PROCESS_ARRAY; +typedef Ref USER_PROCESS_REF; /// \brief Processs Team (contains multiple processes inside it.) /// Equivalent to a process batch @@ -168,9 +169,9 @@ class UserProcessTeam final { public: USER_PROCESS_ARRAY mProcessList; - Ref mCurrentProcess; + USER_PROCESS_REF mCurrentProcess; ProcessID mTeamId{0}; - ProcessID mProcessCount{0}; + ProcessID mProcessCur{0}; }; /***********************************************************************************/ @@ -204,8 +205,8 @@ class UserProcessScheduler final : public ISchedulable { Bool HasMP() override; public: - Ref& TheCurrentProcess(); - SizeT Run() noexcept; + USER_PROCESS_REF& TheCurrentProcess(); + SizeT Run() noexcept; public: STATIC UserProcessScheduler& The(); diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h index 5e983d09..b653e0ee 100644 --- a/dev/kernel/NeKit/ErrorOr.h +++ b/dev/kernel/NeKit/ErrorOr.h @@ -18,11 +18,11 @@ using ErrorT = UInt; template class ErrorOr final { public: - explicit ErrorOr() = default; - ~ErrorOr() = default; + explicit ErrorOr() = default; + ~ErrorOr() = default; public: - explicit ErrorOr(Int32 err) : mRef((T*)RTL_ALLOCA(sizeof(T))), mId(err) {} + explicit ErrorOr(Int32 err) : mRef((T*) RTL_ALLOCA(sizeof(T))), mId(err) {} explicit ErrorOr(nullPtr) {} @@ -48,7 +48,7 @@ class ErrorOr final { private: Ref mRef; - Int32 mId{0}; + Int32 mId{0}; }; using ErrorOrAny = ErrorOr; diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 9380bab4..4d343bc5 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -8,17 +8,17 @@ #ifndef _NEWKIT_REF_H_ #define _NEWKIT_REF_H_ +#include #include #include #include -#include namespace Kernel { template class Ref final { public: explicit Ref() = default; - ~Ref() = default; + ~Ref() = default; public: Ref(T* cls) : fClass(*cls) {} diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc index 382ce37b..39570665 100644 --- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/dev/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, +AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(DeviceInterface* self, MountpointInterface* outpacket), - void (*in)(DeviceInterface* self, + void (*in)(DeviceInterface* self, MountpointInterface* inpacket)) : DeviceInterface(out, in) {} diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc index 697571a3..609837af 100644 --- a/dev/kernel/src/Storage/ATADeviceInterface.cc +++ b/dev/kernel/src/Storage/ATADeviceInterface.cc @@ -12,7 +12,8 @@ using namespace Kernel; /// @param Out Drive output /// @param In Drive input /// @param Cleanup Drive cleanup. -ATADeviceInterface::ATADeviceInterface(void (*Out)(DeviceInterface*, MountpointInterface* outpacket), +ATADeviceInterface::ATADeviceInterface(void (*Out)(DeviceInterface*, + MountpointInterface* outpacket), void (*In)(DeviceInterface*, MountpointInterface* inpacket)) : DeviceInterface(Out, In) {} diff --git a/dev/kernel/src/Storage/NVMEDeviceInterface.cc b/dev/kernel/src/Storage/NVMEDeviceInterface.cc index bc138710..077595cf 100644 --- a/dev/kernel/src/Storage/NVMEDeviceInterface.cc +++ b/dev/kernel/src/Storage/NVMEDeviceInterface.cc @@ -7,10 +7,9 @@ #include namespace Kernel { -NVMEDeviceInterface::NVMEDeviceInterface(void (*out)(DeviceInterface*, - MountpointInterface* outpacket), - void (*in)(DeviceInterface*, MountpointInterface* inpacket), - void (*cleanup)(void)) +NVMEDeviceInterface::NVMEDeviceInterface( + void (*out)(DeviceInterface*, MountpointInterface* outpacket), + void (*in)(DeviceInterface*, MountpointInterface* inpacket), void (*cleanup)(void)) : DeviceInterface(out, in), fCleanup(cleanup) {} NVMEDeviceInterface::~NVMEDeviceInterface() { diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index e6309589..f76d4821 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -67,7 +67,7 @@ USER_PROCESS::operator bool() { /// @return Int32 the last exit code. /***********************************************************************************/ -const UInt32& USER_PROCESS::GetExitCode() noexcept { +KPCError& USER_PROCESS::GetExitCode() noexcept { return this->LastExitCode; } @@ -75,7 +75,7 @@ const UInt32& USER_PROCESS::GetExitCode() noexcept { /// @brief Error code variable getter. /***********************************************************************************/ -Int32& USER_PROCESS::GetLocalCode() noexcept { +KPCError& USER_PROCESS::GetLocalCode() noexcept { return this->LocalCode; } @@ -258,13 +258,13 @@ STATIC Void sched_free_ptr_tree(PROCESS_HEAP_TREE* memory_ptr_list) { /***********************************************************************************/ Void USER_PROCESS::Exit(const Int32& exit_code) { - this->Status = exit_code > 0 ? ProcessStatusKind::kKilled : ProcessStatusKind::kFrozen; + this->Status = exit_code > 0 ? ProcessStatusKind::kKilled : ProcessStatusKind::kFrozen; this->LastExitCode = exit_code; - this->UTime = 0; + this->UTime = 0; kLastExitCode = exit_code; - --this->ParentTeam->mProcessCount; + --this->ParentTeam->mProcessCur; auto memory_ptr_list = this->HeapTree; @@ -314,7 +314,7 @@ Void USER_PROCESS::Exit(const Int32& exit_code) { this->ProcessId = 0UL; this->Status = ProcessStatusKind::kFinished; - --this->ParentTeam->mProcessCount; + --this->ParentTeam->mProcessCur; } /***********************************************************************************/ @@ -360,13 +360,13 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im return -kErrorProcessFault; } - ProcessID pid = this->mTeam.mProcessCount; + ProcessID pid = this->mTeam.mProcessCur; if (pid > kSchedProcessLimitPerTeam) { return -kErrorProcessFault; } - ++this->mTeam.mProcessCount; + ++this->mTeam.mProcessCur; USER_PROCESS& process = this->mTeam.mProcessList[pid]; @@ -480,7 +480,7 @@ Bool UserProcessScheduler::HasMP() { /***********************************************************************************/ SizeT UserProcessScheduler::Run() noexcept { - if (mTeam.mProcessCount < 1) { + if (mTeam.mProcessCur < 1) { return 0UL; } diff --git a/dev/kernel/src/UserProcessTeam.cc b/dev/kernel/src/UserProcessTeam.cc index 8ef9a013..dd21ac49 100644 --- a/dev/kernel/src/UserProcessTeam.cc +++ b/dev/kernel/src/UserProcessTeam.cc @@ -21,7 +21,7 @@ UserProcessTeam::UserProcessTeam() { this->mProcessList[i].ParentTeam = this; } - this->mProcessCount = 0UL; + this->mProcessCur = 0UL; } /***********************************************************************************/ diff --git a/dev/libSystem/SystemKit/Jail.h b/dev/libSystem/SystemKit/Jail.h index 93734dcf..998173f9 100644 --- a/dev/libSystem/SystemKit/Jail.h +++ b/dev/libSystem/SystemKit/Jail.h @@ -15,8 +15,7 @@ struct JAIL_INFO; struct JAIL; /// @brief Jail information (client side struct) -struct JAIL_INFO -{ +struct JAIL_INFO { SInt32 fParentID; SInt32 fJailHash; SInt64 fACL; diff --git a/dev/libSystem/SystemKit/Macros.h b/dev/libSystem/SystemKit/Macros.h index 48c586cc..2bdeff9d 100644 --- a/dev/libSystem/SystemKit/Macros.h +++ b/dev/libSystem/SystemKit/Macros.h @@ -64,19 +64,19 @@ typedef char Char; typedef decltype(nullptr) nullPtr; typedef nullPtr NullPtr; -#define LIBSYS_COPY_DELETE(KLASS) \ +#define LIBSYS_COPY_DELETE(KLASS) \ KLASS& operator=(const KLASS&) = delete; \ KLASS(const KLASS&) = delete; -#define LIBSYS_COPY_DEFAULT(KLASS) \ +#define LIBSYS_COPY_DEFAULT(KLASS) \ KLASS& operator=(const KLASS&) = default; \ KLASS(const KLASS&) = default; -#define LIBSYS_MOVE_DELETE(KLASS) \ +#define LIBSYS_MOVE_DELETE(KLASS) \ KLASS& operator=(KLASS&&) = delete; \ KLASS(KLASS&&) = delete; -#define LIBSYS_MOVE_DEFAULT(KLASS) \ +#define LIBSYS_MOVE_DEFAULT(KLASS) \ KLASS& operator=(KLASS&&) = default; \ KLASS(KLASS&&) = default; diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index 1a334ead..436665ae 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -10,8 +10,8 @@ #include #ifndef SYSCALL_HASH -#define SYSCALL_HASH(str) (UInt64)str -#endif // !SYSCALL_HASH +#define SYSCALL_HASH(str) (UInt64) str +#endif // !SYSCALL_HASH IMPORT_C VoidPtr libsys_syscall_arg_1(SizeT id); IMPORT_C VoidPtr libsys_syscall_arg_2(SizeT id, VoidPtr arg1); diff --git a/dev/libSystem/SystemKit/System.h b/dev/libSystem/SystemKit/System.h index b3d10e32..91899efe 100644 --- a/dev/libSystem/SystemKit/System.h +++ b/dev/libSystem/SystemKit/System.h @@ -17,8 +17,8 @@ Purpose: System Call Interface. // ------------------------------------------------------------------------------------------ // struct REF_TYPE { - UInt64 __hash; /// @brief Hash of the syscall - VoidPtr __self; /// @brief Syscall self value. + UInt64 __hash; /// @brief Hash of the syscall + VoidPtr __self; /// @brief Syscall self value. }; typedef REF_TYPE* Ref; diff --git a/dev/libSystem/src/SystemImpl.cc b/dev/libSystem/src/SystemImpl.cc index 6c2201fe..d0682830 100644 --- a/dev/libSystem/src/SystemImpl.cc +++ b/dev/libSystem/src/SystemImpl.cc @@ -47,8 +47,9 @@ 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 (Ref)libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), reinterpret_cast(const_cast(path)), - reinterpret_cast(const_cast(drv_letter))); + return (Ref) libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'), + reinterpret_cast(const_cast(path)), + reinterpret_cast(const_cast(drv_letter))); } IMPORT_C Void IoCloseFile(_Input Ref desc) { @@ -56,15 +57,16 @@ IMPORT_C Void IoCloseFile(_Input Ref desc) { } IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret = (volatile UInt64*) libsys_syscall_arg_3(SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), - reinterpret_cast(&off)); + auto ret = (volatile UInt64*) libsys_syscall_arg_3( + SYSCALL_HASH('IoSeekFile'), reinterpret_cast(desc), reinterpret_cast(&off)); MUST_PASS((*ret) != ~0UL); return *ret; } IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), reinterpret_cast(desc)); + auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'), + reinterpret_cast(desc)); return *ret; } @@ -74,7 +76,8 @@ IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { va_start(args, fmt); auto ret = (volatile UInt64*) libsys_syscall_arg_4( - SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), reinterpret_cast(const_cast(fmt)), args); + SYSCALL_HASH('PrintOut'), reinterpret_cast(desc), + reinterpret_cast(const_cast(fmt)), args); va_end(args); diff --git a/dev/open_msg/MsgKit/Server.h b/dev/open_msg/MsgKit/Server.h index 867d3b54..54183472 100644 --- a/dev/open_msg/MsgKit/Server.h +++ b/dev/open_msg/MsgKit/Server.h @@ -12,11 +12,11 @@ struct OPENMSG_EXPR; struct OPENMSG_EXPR { - Kernel::KString* l_head; - Kernel::MutableArray l_args; + Kernel::KString* l_head; + Kernel::MutableArray l_args; }; -typedef Kernel::Void(*openmsg_func_t)(OPENMSG_EXPR* arg); +typedef Kernel::Void (*openmsg_func_t)(OPENMSG_EXPR* arg); EXTERN_C Kernel::Void openmsg_init_library(openmsg_func_t* funcs, Kernel::SizeT cnt); EXTERN_C Kernel::UInt32 openmsg_close_library(Kernel::Void); diff --git a/public/frameworks/OpenMSG.fwrk/src/DylibMain.cc b/public/frameworks/OpenMSG.fwrk/src/DylibMain.cc index 814132e3..99eebd26 100644 --- a/public/frameworks/OpenMSG.fwrk/src/DylibMain.cc +++ b/public/frameworks/OpenMSG.fwrk/src/DylibMain.cc @@ -1,5 +1,5 @@ #include SInt32 _DylibAttach(SInt32 argc, Char* argv[]) { - return EXIT_FAILURE; + return EXIT_FAILURE; } \ No newline at end of file -- cgit v1.2.3 From fc0e8401c905171cbc5659065052c3ca9db89cc2 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 1 Jun 2025 11:00:57 +0200 Subject: feat: Be more flexible when the OS is not SMP-aware. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 4 +++- dev/kernel/src/HardwareThreadScheduler.cc | 2 +- dev/kernel/src/UserProcessScheduler.cc | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 5bdfd863..24a81af9 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -120,7 +120,9 @@ EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ThreadID thrdid) HardwareThreadScheduler::The()[thrdid].Leak()->Busy(NO); - sched_jump_to_task(kHWThread[thrdid].mFramePtr); + if (!kSMPAware) { + sched_jump_to_task(kHWThread[thrdid].mFramePtr); + } return YES; } diff --git a/dev/kernel/src/HardwareThreadScheduler.cc b/dev/kernel/src/HardwareThreadScheduler.cc index e3255326..86f46718 100644 --- a/dev/kernel/src/HardwareThreadScheduler.cc +++ b/dev/kernel/src/HardwareThreadScheduler.cc @@ -145,7 +145,7 @@ HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept { */ /***********************************************************************************/ Ref HardwareThreadScheduler::operator[](SizeT idx) { - if (idx >= kMaxAPInsideSched) { + if (idx > kMaxAPInsideSched) { HardwareThread* kFakeThread = nullptr; return {kFakeThread}; } diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index f76d4821..e417cc8d 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -444,7 +444,7 @@ UserProcessScheduler& UserProcessScheduler::The() { /***********************************************************************************/ Void UserProcessScheduler::Remove(ProcessID process_id) { - if (process_id < 0 || process_id >= kSchedProcessLimitPerTeam) { + if (process_id < 0 || process_id > kSchedProcessLimitPerTeam) { return; } -- cgit v1.2.3 From fb7b7f658327f659c6a6da1af151cb389c2ca4ee Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Sun, 1 Jun 2025 13:13:52 +0000 Subject: Heap Overflow in `rt_copy_memory` To avoid directly affecting the API that relies on null-termination, this patch applies a minimal fix by removing the overflow without adding bounds checks or changing the function signature. --- dev/kernel/src/Utils.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc index d7cc08af..484bcfaa 100644 --- a/dev/kernel/src/Utils.cc +++ b/dev/kernel/src/Utils.cc @@ -80,8 +80,6 @@ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { ++index; } - dstChar[index] = 0; - return index; } -- cgit v1.2.3 From cad3c2b62b0d3c050578234514f357d5c2bd6ffc Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Sun, 1 Jun 2025 22:53:17 +0300 Subject: Revise rt_* mem APIs --- dev/kernel/src/Utils.cc | 249 +++++++++++++++++++++++------------------------- 1 file changed, 121 insertions(+), 128 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc index 484bcfaa..e55058d6 100644 --- a/dev/kernel/src/Utils.cc +++ b/dev/kernel/src/Utils.cc @@ -7,187 +7,180 @@ #include namespace Kernel { -Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { - Int32 counter = 0; - for (Size index = 0; index < size; ++index) { - if (src[index] != cmp[index]) ++counter; +Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { + for (Size i = 0; i < size; ++i) { + if (src[i] != cmp[i]) + return static_cast(src[i]) - static_cast(cmp[i]); } - - return counter; -} - -Void rt_zero_memory(voidPtr pointer, Size len) { - rt_set_memory(pointer, 0, len); + return 0; } -SizeT rt_string_len(const Char* str, SizeT _len) { - SizeT len{0}; - - do { - if (len > _len) { - return _len; - } - +SizeT rt_string_len(const Char* str, SizeT max_len) { + SizeT len = 0; + while (len < max_len && str[len] != '\0') ++len; - } while (str[len] != '\0'); - return len; } Size rt_string_len(const Char* ptr) { - SizeT cnt{0}; - - while (ptr[cnt] != 0) ++cnt; - + Size cnt = 0; + while (ptr[cnt] != '\0') + ++cnt; return cnt; } -voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len) { - UInt32* start = reinterpret_cast(src); - - while (len) { - *start = value; - ++start; - --len; - } - - return (voidPtr) start; -} - -Int rt_move_memory(const voidPtr src, voidPtr dst, Size len) { - Char* srcChr = reinterpret_cast(src); - Char* dstChar = reinterpret_cast(dst); - SizeT index = 0; - - while (index < len) { - dstChar[index] = srcChr[index]; - srcChr[index] = 0; - - ++index; +const Char* rt_alloc_string(const Char* src) { + SizeT slen = rt_string_len(src); + Char* buffer = new Char[slen + 1]; + if (!buffer) return nullptr; + + if (rt_copy_memory_safe(reinterpret_cast(const_cast(src)), + reinterpret_cast(buffer), + slen, + slen + 1) < 0) { + delete[] buffer; + return nullptr; } - return 0; + buffer[slen] = '\0'; + return buffer; } -Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { - char* srcChr = reinterpret_cast(src); - char* dstChar = reinterpret_cast(dst); - Size index = 0; - - while (index < len) { - dstChar[index] = srcChr[index]; - ++index; +Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size) { + if (!src || !dst || len > dst_size) { + if (dst && dst_size) { + rt_set_memory_safe(dst, 0, dst_size, dst_size); + } + return -1; } - - return index; + auto s = reinterpret_cast(src); + auto d = reinterpret_cast(dst); + for (Size i = 0; i < len; ++i) + d[i] = s[i]; + return static_cast(len); +} + +voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { + if (!dst || len > dst_size) return nullptr; + auto p = reinterpret_cast(dst); + unsigned char v = static_cast(value & 0xFF); + for (Size i = 0; i < len; ++i) + p[i] = v; + return dst; } -const Char* rt_alloc_string(const Char* src) { - const Char* string = new Char[rt_string_len(src) + 1]; - - if (!string) return nullptr; - - voidPtr v_src = reinterpret_cast(const_cast(src)); - voidPtr v_dst = reinterpret_cast(const_cast(string)); - - rt_copy_memory(v_src, v_dst, rt_string_len(src) + 1); - - return string; +Void rt_zero_memory(voidPtr pointer, Size len) { + rt_set_memory_safe(pointer, 0, len, len); } -Int32 rt_to_uppercase(Int32 character) { - if (character >= 'a' && character <= 'z') return character - 0x20; - return character; +[[deprecated("Use rt_set_memory_safe instead")]] +voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len) { + if (!src) return nullptr; + auto p = reinterpret_cast(src); + unsigned char v = static_cast(value & 0xFF); + for (Size i = 0; i < len; ++i) + p[i] = v; + return src; } -Int32 rt_is_alnum(Int32 character) { - return (character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') || - (character >= '0' && character <= '9'); +[[deprecated("Use rt_copy_memory_safe instead")]] +Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { + if (!src || !dst) return -1; + auto s = reinterpret_cast(src); + auto d = reinterpret_cast(dst); + for (Size i = 0; i < len; ++i) + d[i] = s[i]; + return static_cast(len); } -Int32 rt_to_lower(Int32 character) { - if (character >= 'A' && character <= 'Z') return character + 0x20; - return character; +Int32 rt_to_uppercase(Int32 ch) { + return (ch >= 'a' && ch <= 'z') ? ch - 0x20 : ch; } -Boolean rt_is_space(Char chr) { - return chr == ' '; +Int32 rt_to_lower(Int32 ch) { + return (ch >= 'A' && ch <= 'Z') ? ch + 0x20 : ch; } -Boolean rt_is_newln(Char chr) { - return chr == '\n'; +Int32 rt_is_alnum(Int32 ch) { + return (ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z') || + (ch >= '0' && ch <= '9'); } -VoidPtr rt_string_in_string(const Char* in, const Char* needle) { - for (SizeT i = 0; i < rt_string_len(in); ++i) { - if (rt_string_cmp(in + i, needle, rt_string_len(needle)) == 0) - return reinterpret_cast(const_cast(in + i)); - } +Boolean rt_is_space(Char ch) { + return ch == ' '; +} - return nullptr; +Boolean rt_is_newln(Char ch) { + return ch == '\n'; } -Char rt_to_char(UInt64 base, Int32 limit) { - Char kNumbers[17] = "0123456789ABCDEF"; - return kNumbers[base % limit]; +Char rt_to_char(UInt64 value, Int32 base) { + static constexpr Char kDigits[] = "0123456789ABCDEF"; + return kDigits[value % base]; } -Bool rt_to_string(Char* str, UInt64 base, Int32 limit) { +Bool rt_to_string(Char* str, UInt64 value, Int32 base) { #ifdef __NE_AMD64__ - auto i = 0; - - auto final_number = base; - - auto mult = 1; - auto elems = 0L; - - base /= 10; - - while (base > 0) { - elems++; - mult *= 10; - base /= 10; - } - - while (elems > -1) { - final_number = (final_number % mult) * 10 + final_number / mult; - str[i] = rt_to_char(final_number, limit); - - --elems; - ++i; + Int i = 0; + do { + str[i++] = rt_to_char(value, base); + value /= base; + } while (value); + str[i] = '\0'; + // in-place + for (Int j = 0; j < i / 2; ++j) { + Char tmp = str[j]; + str[j] = str[i - j - 1]; + str[i - j - 1] = tmp; } #endif - - return YES; + return true; } -/// @brief Checks for a string start at the character. -Char* rt_string_has_char(Char* str, Char chr) { - while (*str != chr) { - ++str; +VoidPtr rt_string_in_string(const Char* haystack, const Char* needle) { + SizeT needle_len = rt_string_len(needle); + SizeT hay_len = rt_string_len(haystack); - if (*str == 0) return nullptr; + if (needle_len > hay_len) return nullptr; + for (SizeT i = 0; i <= hay_len - needle_len; ++i) { + if (rt_string_cmp(haystack + i, needle, needle_len) == 0) { + return reinterpret_cast(const_cast(haystack + i)); + } } + return nullptr; +} - return str; +Char* rt_string_has_char(Char* str, Char ch) { + while (*str && *str != ch) ++str; + return (*str == ch) ? str : nullptr; } -} // namespace Kernel -////// @note These symbols were written to satisfy gcc, clang and other compiler complaints. +Int32 rt_strcmp(const Char* a, const Char* b) { + Size i = 0; + while (a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) { + ++i; + } + return static_cast(static_cast(a[i]) - + static_cast(b[i])); +} -EXTERN_C void* memset(void* dst, int c, long long unsigned int len) { - return Kernel::rt_set_memory(dst, c, len); + // @uses the deprecated version callers should ensure 'len' is valid. +extern "C" void* memset(void* dst, int c, long long unsigned int len) { + return Kernel::rt_set_memory(dst, c, static_cast(len)); } -EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len) { - Kernel::rt_copy_memory(const_cast(src), dst, len); +extern "C" void* memcpy(void* dst, const void* src, long long unsigned int len) { + Kernel::rt_copy_memory(const_cast(src), dst, static_cast(len)); return dst; } -EXTERN_C Kernel::Int32 strcmp(const char* dst, const char* src) { - return Kernel::rt_string_cmp(dst, src, Kernel::rt_string_len(dst)); +extern "C" Kernel::Int32 strcmp(const char* a, const char* b) { + return Kernel::rt_strcmp(a, b); } + +} -- cgit v1.2.3 From 561d7b7a5e8dcf3944a2e73b1c1dd7bf5b9affb5 Mon Sep 17 00:00:00 2001 From: 0xf00sec <159052166+0xf00sec@users.noreply.github.com> Date: Mon, 2 Jun 2025 04:04:45 +0300 Subject: Revise rt_* mem APIs --- dev/kernel/src/Utils.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc index e55058d6..6c770798 100644 --- a/dev/kernel/src/Utils.cc +++ b/dev/kernel/src/Utils.cc @@ -8,6 +8,9 @@ namespace Kernel { +STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size); +STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); + Int32 rt_string_cmp(const Char* src, const Char* cmp, Size size) { for (Size i = 0; i < size; ++i) { if (src[i] != cmp[i]) @@ -47,7 +50,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) { +STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size) { if (!src || !dst || len > dst_size) { if (dst && dst_size) { rt_set_memory_safe(dst, 0, dst_size, dst_size); @@ -61,7 +64,7 @@ Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_size) return static_cast(len); } -voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { +STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { if (!dst || len > dst_size) return nullptr; auto p = reinterpret_cast(dst); unsigned char v = static_cast(value & 0xFF); -- cgit v1.2.3 From 2445945e41b09c900b2f6a26365f38c9741b143c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 2 Jun 2025 12:40:14 +0200 Subject: fix: hal/aarch64: aarch64 patches for ne_kernel. --- dev/kernel/HALKit/ARM64/HalCommonAPI.s | 2 +- dev/kernel/HALKit/ARM64/HalKernelPanic.cc | 1 - dev/kernel/src/CxxAbi-ARM64.cc | 7 ++++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'dev/kernel/src') diff --git a/dev/kernel/HALKit/ARM64/HalCommonAPI.s b/dev/kernel/HALKit/ARM64/HalCommonAPI.s index e76b6e3f..f0c69368 100644 --- a/dev/kernel/HALKit/ARM64/HalCommonAPI.s +++ b/dev/kernel/HALKit/ARM64/HalCommonAPI.s @@ -5,5 +5,5 @@ .global hal_flush_tlb hal_flush_tlb: - tlbi + tlbi vmalle1 ret diff --git a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc index 5feb6c75..d70fef00 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc @@ -33,7 +33,6 @@ Void ke_panic(const Kernel::Int32& id, const Char* message) { (Void)(kout << "*** STOP ***\r"); (Void)(kout << "Kernel_Panic_MSG: " << message << kendl); (Void)(kout << "Kernel_Panic_ID: " << hex_number(id) << kendl); - (Void)(kout << "Kernel_Panic_CR2: " << hex_number((UIntPtr) hal_read_cr2()) << kendl); RecoveryFactory::Recover(); } diff --git a/dev/kernel/src/CxxAbi-ARM64.cc b/dev/kernel/src/CxxAbi-ARM64.cc index 02f3dbcf..d351b024 100644 --- a/dev/kernel/src/CxxAbi-ARM64.cc +++ b/dev/kernel/src/CxxAbi-ARM64.cc @@ -19,7 +19,7 @@ Kernel::UIntPtr __dso_handle; EXTERN_C void __chkstk(void) {} -EXTERN_C int atexit(void (*f)(void*), void* arg, void* dso) { +EXTERN_C int atexit(void (*f)(), void* arg, void* dso) { if (__atexit_func_count >= kAtExitMacDestructors) return 1; __atexit_funcs[__atexit_func_count].destructor_func = f; @@ -36,7 +36,8 @@ EXTERN_C void __cxa_finalize(void* f) { if (!f) { while (i--) { if (__atexit_funcs[i].destructor_func) { - (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + (*__atexit_funcs[i].destructor_func)(); + __atexit_funcs[i].destructor_func = 0; }; } @@ -45,7 +46,7 @@ EXTERN_C void __cxa_finalize(void* f) { while (i--) { if (__atexit_funcs[i].destructor_func) { - (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr); + (*__atexit_funcs[i].destructor_func)(); __atexit_funcs[i].destructor_func = 0; }; } -- cgit v1.2.3 From 71dddecbce68f803820b780ccb8c744935256b49 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 3 Jun 2025 09:18:18 +0200 Subject: feat: Last changes before `0.0.3` Signed-off-by: Amlal El Mahrouss --- .github/workflows/boot-pio.yml | 3 +- .github/workflows/kernel-ahci.yml | 4 +- .github/workflows/kernel-pio.yml | 4 +- dev/boot/amd64-desktop.make | 2 +- dev/boot/src/HEL/AMD64/BootATA.cc | 266 ++++++++++++++++++++++++++++++++++++++ dev/boot/src/HEL/AMD64/BootATAcc | 266 -------------------------------------- dev/kernel/KernelKit/UserMgr.h | 4 +- dev/kernel/src/UserMgr.cc | 4 +- dev/kernel/src/Utils.cc | 27 ++-- 9 files changed, 290 insertions(+), 290 deletions(-) create mode 100644 dev/boot/src/HEL/AMD64/BootATA.cc delete mode 100644 dev/boot/src/HEL/AMD64/BootATAcc (limited to 'dev/kernel/src') diff --git a/.github/workflows/boot-pio.yml b/.github/workflows/boot-pio.yml index 80c5b932..3a8c087b 100644 --- a/.github/workflows/boot-pio.yml +++ b/.github/workflows/boot-pio.yml @@ -15,6 +15,5 @@ jobs: - uses: actions/checkout@v4 - name: Install Packages run: sudo apt update && sudo apt install mingw-w64 qemu-utils nasm - - name: Build BootZ (ATA PIO) - run: cd dev/boot && export ATA_PIO_SUPPORT=1 && make -f amd64-ci.make all + diff --git a/.github/workflows/kernel-ahci.yml b/.github/workflows/kernel-ahci.yml index a328a0f7..17a68a30 100644 --- a/.github/workflows/kernel-ahci.yml +++ b/.github/workflows/kernel-ahci.yml @@ -15,6 +15,4 @@ jobs: - uses: actions/checkout@v4 - name: Install Packages run: sudo apt update && sudo apt install mingw-w64 qemu-utils nasm - - name: Build NeKernel (AHCI) - run: ./setup_x64_project.sh && cd dev/kernel && export AHCI_SUPPORT=1 && make -f amd64-ci.make all - + diff --git a/.github/workflows/kernel-pio.yml b/.github/workflows/kernel-pio.yml index 69f14a83..6c4fbb6a 100644 --- a/.github/workflows/kernel-pio.yml +++ b/.github/workflows/kernel-pio.yml @@ -15,6 +15,4 @@ jobs: - uses: actions/checkout@v4 - name: Install Packages run: sudo apt update && sudo apt install mingw-w64 qemu-utils nasm - - name: Build NeKernel (ATA PIO) - run: ./setup_x64_project.sh && cd dev/kernel && export ATA_PIO_SUPPORT=1 && make -f amd64-ci.make all - + \ No newline at end of file diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index d39c3bcd..d7515367 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -128,7 +128,7 @@ 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 .PHONY: run-efi-amd64-ata -run-efi-amd64-ata: run-efi-amd64-ata-dma +run-efi-amd64-ata: run-efi-amd64-ata-pio # img_2 is the rescue disk. img is the bootable disk, as provided by the NeKernel specs. .PHONY: epm-img diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc new file mode 100644 index 00000000..e5e0d8c2 --- /dev/null +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -0,0 +1,266 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss/Symphony Corp, all rights reserved. + +------------------------------------------- */ + +/** + * @file BootATA.cc + * @author Amlal El Mahrouss (amlal@nekernel.org) + * @brief ATA driver. + * @version 0.1 + * @date 2024-02-02 + * + * @copyright Copyright (c) Amlal El Mahrouss + * + */ + +#include +#include +#include + +#define kATADataLen (256) + +/// bugs: 0 + +using namespace Boot; + +static Boolean kATADetected = false; +static UInt16 kATAData[kATADataLen] = {0}; + +Boolean boot_ata_detected(Void); + +STATIC Boolean boot_ata_wait_io(UInt16 IO) { + for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS); + +ATAWaitForIO_Retry: + auto status_rdy = rt_in8(IO + ATA_REG_STATUS); + + if ((status_rdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; + +ATAWaitForIO_Retry2: + status_rdy = rt_in8(IO + ATA_REG_STATUS); + + if (status_rdy & ATA_SR_ERR) return false; + + if (!(status_rdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; + + return true; +} + +Void boot_ata_select(UInt16 Bus) { + if (Bus == ATA_PRIMARY_IO) + rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); + else + rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); +} + +Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { + NE_UNUSED(Drive); + + if (boot_ata_detected()) return true; + + BootTextWriter writer; + + UInt16 IO = Bus; + + boot_ata_select(IO); + + // Bus init, NEIN bit. + rt_out8(IO + ATA_REG_NEIN, 1); + + // identify until it's good. +ATAInit_Retry: + auto status_rdy = rt_in8(IO + ATA_REG_STATUS); + + if (status_rdy & ATA_SR_ERR) { + writer.Write(L"VMBoot: ATA: Not an IDE based drive.\r"); + + return false; + } + + if ((status_rdy & ATA_SR_BSY)) goto ATAInit_Retry; + + boot_ata_select(IO); + + rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); + + /// fetch serial info + /// model, speed, number of sectors... + + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + + for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { + kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); + } + + OutBus = (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary; + + OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; + + return true; +} + +Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, SizeT SectorSz, + SizeT Size) { + Lba /= SectorSz; + + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); + + boot_ata_wait_io(IO); + boot_ata_select(IO); + + rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); + + rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); + + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); + rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); + rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); + rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); + + rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); + + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + + for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { + boot_ata_wait_io(IO); + + auto in = rt_in16(IO + ATA_REG_DATA); + + Buf[IndexOff] = in & 0xFF; + Buf[IndexOff + 1] = (in >> 8) & 0xFF; + boot_ata_wait_io(IO); + } +} + +Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, SizeT SectorSz, + SizeT Size) { + Lba /= SectorSz; + + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); + + boot_ata_wait_io(IO); + boot_ata_select(IO); + + rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); + + rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); + + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); + rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); + rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); + rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); + + rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); + + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + + for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { + boot_ata_wait_io(IO); + + UInt8 low = (UInt8) Buf[IndexOff]; + UInt8 high = (IndexOff + 1 < Size) ? (UInt8) Buf[IndexOff + 1] : 0; + UInt16 packed = (high << 8) | low; + + rt_out16(IO + ATA_REG_DATA, packed); + + boot_ata_wait_io(IO); + } + + boot_ata_wait_io(IO); +} + +/// @check is ATA detected? +Boolean boot_ata_detected(Void) { + return kATADetected; +} + +/*** + * + * + * @brief ATA Device class. + * + * + */ + +/** + * @brief ATA Device constructor. + * @param void none. + */ +BootDeviceATA::BootDeviceATA() noexcept { + if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, this->Leak().mMaster) || + boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, this->Leak().mMaster)) { + kATADetected = true; + } +} +/** + * @brief Is ATA detected? + */ +BootDeviceATA::operator bool() { + return boot_ata_detected(); +} + +/** + @brief Read Buf from disk + @param Sz Sector size + @param Buf buffer +*/ +BootDeviceATA& BootDeviceATA::Read(CharacterTypeASCII* Buf, SizeT SectorSz) { + if (!boot_ata_detected()) { + Leak().mErr = true; + return *this; + } + + this->Leak().mErr = false; + + if (!Buf || SectorSz < 1) return *this; + + boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, + this->Leak().mSize); + + return *this; +} + +/** + @brief Write Buf into disk + @param Sz Sector size + @param Buf buffer +*/ +BootDeviceATA& BootDeviceATA::Write(CharacterTypeASCII* Buf, SizeT SectorSz) { + if (!boot_ata_detected()) { + Leak().mErr = true; + return *this; + } + + Leak().mErr = false; + + if (!Buf || SectorSz < 1 || this->Leak().mSize < 1) { + Leak().mErr = true; + return *this; + } + + boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, + this->Leak().mSize); + + return *this; +} + +/** + * @brief ATA trait getter. + * @return BootDeviceATA::ATATrait& the drive config. + */ +BootDeviceATA::ATATrait& BootDeviceATA::Leak() { + return mTrait; +} + +/*** + @brief Getter, gets the number of sectors inside the drive. +*/ +SizeT BootDeviceATA::GetSectorsCount() noexcept { + return (kATAData[61] << 16) | kATAData[60]; +} + +SizeT BootDeviceATA::GetDiskSize() noexcept { + return this->GetSectorsCount() * BootDeviceATA::kSectorSize; +} diff --git a/dev/boot/src/HEL/AMD64/BootATAcc b/dev/boot/src/HEL/AMD64/BootATAcc deleted file mode 100644 index 4fd6dc16..00000000 --- a/dev/boot/src/HEL/AMD64/BootATAcc +++ /dev/null @@ -1,266 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -/** - * @file BootATA.cc - * @author Amlal El Mahrouss (amlal@nekernel.org) - * @brief ATA driver. - * @version 0.1 - * @date 2024-02-02 - * - * @copyright Copyright (c) Amlal El Mahrouss - * - */ - -#include -#include -#include - -#define kATADataLen (256) - -/// bugs: 0 - -using namespace Boot; - -static Boolean kATADetected = false; -static UInt16 kATAData[kATADataLen] = {0}; - -Boolean boot_ata_detected(Void); - -STATIC Boolean boot_ata_wait_io(UInt16 IO) { - for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS); - -ATAWaitForIO_Retry: - auto status_rdy = rt_in8(IO + ATA_REG_STATUS); - - if ((status_rdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; - -ATAWaitForIO_Retry2: - status_rdy = rt_in8(IO + ATA_REG_STATUS); - - if (status_rdy & ATA_SR_ERR) return false; - - if (!(status_rdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; - - return true; -} - -Void boot_ata_select(UInt16 Bus) { - if (Bus == ATA_PRIMARY_IO) - rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); - else - rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); -} - -Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - NE_UNUSED(Drive); - - if (boot_ata_detected()) return true; - - BootTextWriter writer; - - UInt16 IO = Bus; - - boot_ata_select(IO); - - // Bus init, NEIN bit. - rt_out8(IO + ATA_REG_NEIN, 1); - - // identify until it's good. -ATAInit_Retry: - auto status_rdy = rt_in8(IO + ATA_REG_STATUS); - - if (status_rdy & ATA_SR_ERR) { - writer.Write(L"BootZ: ATA: Not an IDE based drive.\r"); - - return false; - } - - if ((status_rdy & ATA_SR_BSY)) goto ATAInit_Retry; - - boot_ata_select(IO); - - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - - /// fetch serial info - /// model, speed, number of sectors... - - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - - for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); - } - - OutBus = (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary; - - OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - - return true; -} - -Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, SizeT SectorSz, - SizeT Size) { - Lba /= SectorSz; - - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - - boot_ata_wait_io(IO); - boot_ata_select(IO); - - rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - - rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - - rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); - rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); - rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); - rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); - - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - - for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { - boot_ata_wait_io(IO); - - auto in = rt_in16(IO + ATA_REG_DATA); - - Buf[IndexOff] = in & 0xFF; - Buf[IndexOff + 1] = (in >> 8) & 0xFF; - boot_ata_wait_io(IO); - } -} - -Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, SizeT SectorSz, - SizeT Size) { - Lba /= SectorSz; - - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - - boot_ata_wait_io(IO); - boot_ata_select(IO); - - rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - - rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - - rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); - rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); - rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); - rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); - - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - - for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { - boot_ata_wait_io(IO); - - UInt8 low = (UInt8) Buf[IndexOff]; - UInt8 high = (IndexOff + 1 < Size) ? (UInt8) Buf[IndexOff + 1] : 0; - UInt16 packed = (high << 8) | low; - - rt_out16(IO + ATA_REG_DATA, packed); - - boot_ata_wait_io(IO); - } - - boot_ata_wait_io(IO); -} - -/// @check is ATA detected? -Boolean boot_ata_detected(Void) { - return kATADetected; -} - -/*** - * - * - * @brief ATA Device class. - * - * - */ - -/** - * @brief ATA Device constructor. - * @param void none. - */ -BootDeviceATA::BootDeviceATA() noexcept { - if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, this->Leak().mMaster) || - boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, this->Leak().mMaster)) { - kATADetected = true; - } -} -/** - * @brief Is ATA detected? - */ -BootDeviceATA::operator bool() { - return boot_ata_detected(); -} - -/** - @brief Read Buf from disk - @param Sz Sector size - @param Buf buffer -*/ -BootDeviceATA& BootDeviceATA::Read(CharacterTypeASCII* Buf, SizeT SectorSz) { - if (!boot_ata_detected()) { - Leak().mErr = true; - return *this; - } - - this->Leak().mErr = false; - - if (!Buf || SectorSz < 1) return *this; - - boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, - this->Leak().mSize); - - return *this; -} - -/** - @brief Write Buf into disk - @param Sz Sector size - @param Buf buffer -*/ -BootDeviceATA& BootDeviceATA::Write(CharacterTypeASCII* Buf, SizeT SectorSz) { - if (!boot_ata_detected()) { - Leak().mErr = true; - return *this; - } - - Leak().mErr = false; - - if (!Buf || SectorSz < 1 || this->Leak().mSize < 1) { - Leak().mErr = true; - return *this; - } - - boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, - this->Leak().mSize); - - return *this; -} - -/** - * @brief ATA trait getter. - * @return BootDeviceATA::ATATrait& the drive config. - */ -BootDeviceATA::ATATrait& BootDeviceATA::Leak() { - return mTrait; -} - -/*** - @brief Getter, gets the number of sectors inside the drive. -*/ -SizeT BootDeviceATA::GetSectorsCount() noexcept { - return (kATAData[61] << 16) | kATAData[60]; -} - -SizeT BootDeviceATA::GetDiskSize() noexcept { - return this->GetSectorsCount() * BootDeviceATA::kSectorSize; -} diff --git a/dev/kernel/KernelKit/UserMgr.h b/dev/kernel/KernelKit/UserMgr.h index 89436025..ef1cc659 100644 --- a/dev/kernel/KernelKit/UserMgr.h +++ b/dev/kernel/KernelKit/UserMgr.h @@ -20,8 +20,8 @@ #include #include -///! We got the Super, Standard (%s format) and Guest user, -///! all are used to make authorization operations on the OS. +///! We got the MGMT, STD (%s format) and GUEST users, +///! all are used to make authorized operations. #define kSuperUser "OS AUTHORITY/MGMT/%s" #define kGuestUser "OS AUTHORITY/GUEST/%s" #define kStdUser "OS AUTHORITY/STD/%s" diff --git a/dev/kernel/src/UserMgr.cc b/dev/kernel/src/UserMgr.cc index c41b445b..8eade85e 100644 --- a/dev/kernel/src/UserMgr.cc +++ b/dev/kernel/src/UserMgr.cc @@ -4,8 +4,8 @@ * NeKernel * Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. * - * File: User.cc - * Purpose: User class, used to provide authentication and security. + * File: UserMgr.cc + * Purpose: User Manager, used to provide authentication and security. * * ======================================================== */ diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc index 6c770798..087b6d5f 100644 --- a/dev/kernel/src/Utils.cc +++ b/dev/kernel/src/Utils.cc @@ -57,8 +57,8 @@ STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size ds } return -1; } - auto s = reinterpret_cast(src); - auto d = reinterpret_cast(dst); + auto s = reinterpret_cast(src); + auto d = reinterpret_cast(dst); for (Size i = 0; i < len; ++i) d[i] = s[i]; return static_cast(len); @@ -66,8 +66,8 @@ STATIC Int rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size ds STATIC voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size) { if (!dst || len > dst_size) return nullptr; - auto p = reinterpret_cast(dst); - unsigned char v = static_cast(value & 0xFF); + auto p = reinterpret_cast(dst); + UInt8 v = static_cast(value & 0xFF); for (Size i = 0; i < len; ++i) p[i] = v; return dst; @@ -77,24 +77,29 @@ Void rt_zero_memory(voidPtr pointer, Size len) { rt_set_memory_safe(pointer, 0, len, len); } - +#ifdef __NE_ENFORCE_DEPRECATED_WARNINGS [[deprecated("Use rt_set_memory_safe instead")]] +#endif voidPtr rt_set_memory(voidPtr src, UInt32 value, Size len) { if (!src) return nullptr; - auto p = reinterpret_cast(src); - unsigned char v = static_cast(value & 0xFF); + auto p = reinterpret_cast(src); + UInt8 v = static_cast(value & 0xFF); for (Size i = 0; i < len; ++i) p[i] = v; return src; } +#ifdef __NE_ENFORCE_DEPRECATED_WARNINGS [[deprecated("Use rt_copy_memory_safe instead")]] +#endif Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) { if (!src || !dst) return -1; - auto s = reinterpret_cast(src); - auto d = reinterpret_cast(dst); + auto s = reinterpret_cast(src); + auto d = reinterpret_cast(dst); + for (Size i = 0; i < len; ++i) d[i] = s[i]; + return static_cast(len); } @@ -168,8 +173,8 @@ Int32 rt_strcmp(const Char* a, const Char* b) { while (a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) { ++i; } - return static_cast(static_cast(a[i]) - - static_cast(b[i])); + return static_cast(static_cast(a[i]) - + static_cast(b[i])); } // @uses the deprecated version callers should ensure 'len' is valid. -- cgit v1.2.3