From 6ea68d219dc3a1bcc0deef1683e8442082025940 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Tue, 30 Jul 2024 10:01:42 +0200 Subject: [IMP] SCIKit: SharedInterface1 and UnknownInterface, both are defined in foreign SOs. [REFACTOR] IPCEP is just now IPC. Signed-off-by: Amlal EL Mahrouss --- Kernel/HALKit/AMD64/HalKernelMain.cxx | 4 +- Kernel/HALKit/ARM64/HalKernelMain.cxx | 4 +- Kernel/KernelKit/User.hxx | 1 + Kernel/NetworkKit/IPC.hxx | 80 +++++++++++++++++++++++++++++++++++ Kernel/NetworkKit/IPCEP.hxx | 79 ---------------------------------- Kernel/NetworkKit/NetworkDevice.hpp | 2 +- Kernel/Sources/Network/IPC.cxx | 68 +++++++++++++++++++++++++++++ Kernel/Sources/Network/IPCEP.cxx | 68 ----------------------------- 8 files changed, 154 insertions(+), 152 deletions(-) create mode 100644 Kernel/NetworkKit/IPC.hxx delete mode 100644 Kernel/NetworkKit/IPCEP.hxx create mode 100644 Kernel/Sources/Network/IPC.cxx delete mode 100644 Kernel/Sources/Network/IPCEP.cxx (limited to 'Kernel') diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index 1628e5e9..a4067c84 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #define mInitKernel(X) \ @@ -141,7 +141,7 @@ EXTERN_C void hal_init_platform( }; kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { - Kernel::ipc_sanitize_packet(reinterpret_cast(rdx)); + Kernel::ipc_sanitize_packet(reinterpret_cast(rdx)); }; kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { diff --git a/Kernel/HALKit/ARM64/HalKernelMain.cxx b/Kernel/HALKit/ARM64/HalKernelMain.cxx index a2d215f6..a5285f0f 100644 --- a/Kernel/HALKit/ARM64/HalKernelMain.cxx +++ b/Kernel/HALKit/ARM64/HalKernelMain.cxx @@ -17,7 +17,7 @@ #include #include #include -#include +#include #define KERNEL_INIT(X) \ X; \ @@ -99,7 +99,7 @@ EXTERN_C void hal_init_platform( }; kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { - Kernel::ipc_sanitize_packet(reinterpret_cast(rdx)); + Kernel::ipc_sanitize_packet(reinterpret_cast(rdx)); }; kSyscalls[cNewInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { diff --git a/Kernel/KernelKit/User.hxx b/Kernel/KernelKit/User.hxx index 861fd17a..c84910c5 100644 --- a/Kernel/KernelKit/User.hxx +++ b/Kernel/KernelKit/User.hxx @@ -57,6 +57,7 @@ namespace Kernel public: /// @brief Get software ring const RingKind& Ring() noexcept; + /// @brief Get user name StringView& Name() noexcept; diff --git a/Kernel/NetworkKit/IPC.hxx b/Kernel/NetworkKit/IPC.hxx new file mode 100644 index 00000000..e53d8f1c --- /dev/null +++ b/Kernel/NetworkKit/IPC.hxx @@ -0,0 +1,80 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: IPC.hxx. + Purpose: IPC protocol. + +------------------------------------------- */ + +#ifndef _INC_IPC_ENDPOINT_HXX_ +#define _INC_IPC_ENDPOINT_HXX_ + +#include +#include + +/// @file IPC.hxx +/// @brief IPC protocol. + +/// IA separator. +#define cRemoteSeparator "." + +/// Interchange address, consists of PID:TEAM. +#define cRemoteInvalid "00:00" + +#define cRemoteHeaderMagic (0x4950434) + +namespace Kernel +{ + /// @brief 128-bit IPC address. + struct PACKED IPC_ADDRESS_STRUCT final + { + UInt64 ProcessID; + UInt64 ProcessTeam; + + //////////////////////////////////// + // some operators. + //////////////////////////////////// + + bool operator==(const IPC_ADDRESS_STRUCT& addr) noexcept + { + return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; + } + + bool operator==(IPC_ADDRESS_STRUCT& addr) noexcept + { + return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; + } + }; + + typedef struct IPC_ADDRESS_STRUCT IPCEPAddressKind; + + enum + { + eIPCEPLittleEndian = 0, + eIPCEPBigEndian = 1 + }; + + constexpr auto cIPCEPMsgSize = 6094U; + + /// @brief IPC connection header, message cannot be greater than 6K. + typedef struct IPC_MESSAGE_STRUCT final + { + UInt32 IpcHeaderMagic; // cRemoteHeaderMagic + UInt8 IpcEndianess; // 0 : LE, 1 : BE + SizeT IpcPacketSize; + IPCEPAddressKind IpcFrom; + IPCEPAddressKind IpcTo; + UInt32 IpcCRC32; + UInt32 IpcMsg; + UInt32 IpcMsgSz; + UInt8 IpcData[cIPCEPMsgSize]; + } PACKED IPC_MESSAGE_STRUCT; + + /// @brief Sanitize packet function + /// @retval true packet is correct. + /// @retval false packet is incorrect and process has crashed. + Bool ipc_sanitize_packet(IPC_MESSAGE_STRUCT* pckt); +} // namespace Kernel + +#endif // _INC_IPC_ENDPOINT_HXX_ diff --git a/Kernel/NetworkKit/IPCEP.hxx b/Kernel/NetworkKit/IPCEP.hxx deleted file mode 100644 index 7a7d8fc9..00000000 --- a/Kernel/NetworkKit/IPCEP.hxx +++ /dev/null @@ -1,79 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: IPCEP.hxx. - Purpose: IPC protocol. - -------------------------------------------- */ - -#ifndef _INC_IPC_ENDPOINT_HXX_ -#define _INC_IPC_ENDPOINT_HXX_ - -#include -#include - -/// @brief IPC Endpoint Protocol (IPCEP for short). - -/// IA separator. -#define cRemoteSeparator "." - -/// Interchange address, consists of PID:TEAM. -#define cRemoteInvalid "00:00" - -#define cRemoteHeaderMagic (0x4950434) - -namespace Kernel -{ - /// @brief 128-bit IPC address. - struct PACKED IPCEPAddress final - { - UInt64 ProcessID; - UInt64 ProcessTeam; - - //////////////////////////////////// - // some operators. - //////////////////////////////////// - - bool operator==(const IPCEPAddress& addr) noexcept - { - return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; - } - - bool operator==(IPCEPAddress& addr) noexcept - { - return addr.ProcessID == this->ProcessID && addr.ProcessTeam == this->ProcessTeam; - } - }; - - typedef struct IPCEPAddress IPCEPAddressType; - - enum - { - eIPCEPLittleEndian = 0, - eIPCEPBigEndian = 1 - }; - - constexpr auto cIPCEPMsgSize = 6094U; - - /// @brief IPCEP connection header, message cannot be greater than 6K. - typedef struct IPCEPMessageHeader final - { - UInt32 IpcHeaderMagic; // cRemoteHeaderMagic - UInt8 IpcEndianess; // 0 : LE, 1 : BE - SizeT IpcPacketSize; - IPCEPAddressType IpcFrom; - IPCEPAddressType IpcTo; - UInt32 IpcCRC32; - UInt32 IpcMsg; - UInt32 IpcMsgSz; - UInt8 IpcData[cIPCEPMsgSize]; - } PACKED IPCEPMessageHeader; - - /// @brief Sanitize packet function - /// @retval true packet is correct. - /// @retval false packet is incorrect and process has crashed. - Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt); -} // namespace Kernel - -#endif // _INC_IPC_ENDPOINT_HXX_ diff --git a/Kernel/NetworkKit/NetworkDevice.hpp b/Kernel/NetworkKit/NetworkDevice.hpp index 956475aa..eed5f071 100644 --- a/Kernel/NetworkKit/NetworkDevice.hpp +++ b/Kernel/NetworkKit/NetworkDevice.hpp @@ -62,7 +62,7 @@ namespace Kernel /// @brief PPP device. using PPPNetworkDevice = NetworkDevice; - /// @brief IPCEP device. + /// @brief IPC device. using IPCEPNetworkDevice = NetworkDevice; /// @brief GRPS device. diff --git a/Kernel/Sources/Network/IPC.cxx b/Kernel/Sources/Network/IPC.cxx new file mode 100644 index 00000000..12ec6c1a --- /dev/null +++ b/Kernel/Sources/Network/IPC.cxx @@ -0,0 +1,68 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies + +------------------------------------------- */ + +#include +#include +#include + +using namespace Kernel; + +/// @internal +/// @brief The internal sanitize function. +Bool ipc_int_sanitize_packet(IPC_MESSAGE_STRUCT* pckt) +{ + auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]); + + switch (endian) + { + case Endian::kEndianBig: { + if (pckt->IpcEndianess == eIPCEPLittleEndian) + goto ipc_check_failed; + + break; + } + case Endian::kEndianLittle: { + if (pckt->IpcEndianess == eIPCEPBigEndian) + goto ipc_check_failed; + + break; + } + case Endian::kEndianMixed: + break; + default: + goto ipc_check_failed; + } + + if (pckt->IpcFrom == pckt->IpcTo || + pckt->IpcPacketSize > cIPCEPMsgSize) + { + goto ipc_check_failed; + } + + return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; + +ipc_check_failed: + ErrLocal() = kErrorIPC; + return false; +} + +namespace Kernel +{ + /// @brief Sanitize packet function + /// @retval true packet is correct. + /// @retval false packet is incorrect and process has crashed. + Bool ipc_sanitize_packet(IPC_MESSAGE_STRUCT* pckt) + { + if (!pckt || + !ipc_int_sanitize_packet(pckt)) + { + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + return false; + } + + return true; + } +} // namespace Kernel diff --git a/Kernel/Sources/Network/IPCEP.cxx b/Kernel/Sources/Network/IPCEP.cxx deleted file mode 100644 index 5271be05..00000000 --- a/Kernel/Sources/Network/IPCEP.cxx +++ /dev/null @@ -1,68 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#include -#include -#include - -using namespace Kernel; - -/// @internal -/// @brief The internal sanitize function. -Bool ipc_int_sanitize_packet(IPCEPMessageHeader* pckt) -{ - auto endian = DEDUCE_ENDIAN(pckt, ((char*)pckt)[0]); - - switch (endian) - { - case Endian::kEndianBig: { - if (pckt->IpcEndianess == eIPCEPLittleEndian) - goto ipc_check_failed; - - break; - } - case Endian::kEndianLittle: { - if (pckt->IpcEndianess == eIPCEPBigEndian) - goto ipc_check_failed; - - break; - } - case Endian::kEndianMixed: - break; - default: - goto ipc_check_failed; - } - - if (pckt->IpcFrom == pckt->IpcTo || - pckt->IpcPacketSize > cIPCEPMsgSize) - { - goto ipc_check_failed; - } - - return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; - -ipc_check_failed: - ErrLocal() = kErrorIPC; - return false; -} - -namespace Kernel -{ - /// @brief Sanitize packet function - /// @retval true packet is correct. - /// @retval false packet is incorrect and process has crashed. - Bool ipc_sanitize_packet(IPCEPMessageHeader* pckt) - { - if (!pckt || - !ipc_int_sanitize_packet(pckt)) - { - ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); - return false; - } - - return true; - } -} // namespace Kernel -- cgit v1.2.3