summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NetworkKit/IPC.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/NetworkKit/IPC.h')
-rw-r--r--src/kernel/NetworkKit/IPC.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/kernel/NetworkKit/IPC.h b/src/kernel/NetworkKit/IPC.h
new file mode 100644
index 00000000..c08a9457
--- /dev/null
+++ b/src/kernel/NetworkKit/IPC.h
@@ -0,0 +1,90 @@
+/* ========================================
+
+ Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license..
+
+ File: IPC.h.
+ Purpose: IPC protocol.
+
+======================================== */
+
+#ifndef INC_IPC_H
+#define INC_IPC_H
+
+#include <NeKit/Defines.h>
+#include <NeKit/KString.h>
+#include <hint/CompilerHint.h>
+
+/// @file IPC.h
+/// @brief IPC comm. protocol.
+
+/// IA separator.
+#define kIPCRemoteSeparator ":"
+
+/// Interchange address, consists of ProcessID:TEAM.
+#define kIPCRemoteInvalid "00:00"
+
+#define kIPCHeaderMagic (0x4950434)
+
+namespace Kernel {
+struct IPC_ADDR;
+struct IPC_MSG;
+
+/// @brief 128-bit IPC address.
+struct PACKED IPC_ADDR final {
+ UInt64 UserProcessID;
+ UInt64 UserProcessTeam;
+
+ ////////////////////////////////////
+ // some operators.
+ ////////////////////////////////////
+
+ BOOL operator==(const IPC_ADDR& addr) noexcept;
+ BOOL operator==(IPC_ADDR& addr) noexcept;
+ BOOL operator!=(const IPC_ADDR& addr) noexcept;
+ BOOL operator!=(IPC_ADDR& addr) noexcept;
+};
+
+typedef struct IPC_ADDR IPC_ADDR;
+
+enum {
+ kIPCLittleEndian = 0,
+ kIPCBigEndian = 1,
+ kIPCMixedEndian = 2,
+};
+
+constexpr inline auto kIPCMsgSize = 6094U;
+
+enum {
+ kIPCLockInvalid = 0,
+ kIPCLockFree = 1,
+ kIPCLockUsed = 2,
+};
+
+/// @brief IPC connection header, message cannot be greater than 6K.
+typedef struct IPC_MSG final {
+ UInt32 IpcHeaderMagic; // cRemoteHeaderMagic
+ UInt8 IpcEndianess; // 0 : LE, 1 : BE
+ SizeT IpcPacketSize;
+ IPC_ADDR IpcFrom;
+ IPC_ADDR IpcTo;
+ UInt32 IpcCRC32;
+ UInt32 IpcMsg;
+ UInt32 IpcMsgSz;
+ UInt8 IpcData[kIPCMsgSize];
+ UInt32 IpcLock;
+ /// @brief Passes the message to target, could be anything, HTTP packet, JSON or whatever.
+ static Bool Pass(IPC_MSG* self, IPC_MSG* target) noexcept;
+} PACKED ALIGN(8) IPC_MSG;
+
+/// @brief Sanitize packet function
+/// @retval true packet is correct.
+/// @retval false packet is incorrect and process has crashed.
+BOOL ipc_sanitize_packet(_Input IPC_MSG* pckt_in);
+
+/// @brief Construct packet function
+/// @retval true packet is correct.
+/// @retval false packet is incorrect and process has crashed.
+BOOL ipc_construct_packet(_Output _Input IPC_MSG** pckt_in);
+} // namespace Kernel
+
+#endif // INC_IPC_H