summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-31 00:55:34 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-31 00:55:34 +0100
commitbd4466fbe026ac25f84d88d0306b9745b9bbbe8b (patch)
treeda67bf337c9c1c3d519f142b96bead55b5cf2147 /dev
parentd546e35937521c868150a0807f30a2e2b1f69bb8 (diff)
feat: IPC: use C-lock pattern to retain IPC transfers.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev')
-rw-r--r--dev/kernel/NetworkKit/IPC.h8
-rw-r--r--dev/kernel/src/Network/IPCMsg.cc14
2 files changed, 21 insertions, 1 deletions
diff --git a/dev/kernel/NetworkKit/IPC.h b/dev/kernel/NetworkKit/IPC.h
index 0dd8a1f1..d14356c0 100644
--- a/dev/kernel/NetworkKit/IPC.h
+++ b/dev/kernel/NetworkKit/IPC.h
@@ -57,6 +57,12 @@ enum {
constexpr inline auto kIPCMsgSize = 6094U;
+enum {
+ kIPCLockInvalid,
+ kIPCLockFree = 1,
+ kIPCLockUsed = 2,
+};
+
/// @brief IPC connection header, message cannot be greater than 6K.
typedef struct IPC_MSG final {
UInt32 IpcHeaderMagic; // cRemoteHeaderMagic
@@ -68,7 +74,7 @@ typedef struct IPC_MSG final {
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 IPC_MSG;
diff --git a/dev/kernel/src/Network/IPCMsg.cc b/dev/kernel/src/Network/IPCMsg.cc
index 6f54e449..9abefcef 100644
--- a/dev/kernel/src/Network/IPCMsg.cc
+++ b/dev/kernel/src/Network/IPCMsg.cc
@@ -87,6 +87,8 @@ Bool ipc_construct_packet(_Output IPC_MSG** pckt_in) {
(*pckt_in)->IpcFrom.UserProcessID = 0;
(*pckt_in)->IpcFrom.UserProcessTeam = 0;
+ (*pckt_in)->IpcLock = kIPCLockFree;
+
return Yes;
}
@@ -103,8 +105,20 @@ Bool IPC_MSG::Pass(IPC_MSG* src, IPC_MSG* target) noexcept {
if (src->IpcMsgSz > target->IpcMsgSz) return No;
if (target->IpcMsgSz > src->IpcMsgSz) return No;
+ UInt32 timeout = 0U;
+
+ while ((target->IpcLock % kIPCLockUsed) != 0) {
+ if (timeout > 100000U) {
+ return No;
+ }
+ }
+
+ ++target->IpcLock;
+
rt_copy_memory_safe(src->IpcData, target->IpcData, src->IpcMsgSz, kIPCMsgSize);
+ --target->IpcLock;
+
return Yes;
}