From 3c233e380524d6842d396fd0a1fb9aeacf34d35f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 28 Aug 2024 08:00:52 +0200 Subject: [IMP] Add ipc_construct_packet function to IPC protocol implementation. [IMP] Update Endian enum to match the one from the IPC protocol. [IMP] MUST_PASS works in debug only now. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/Sources/Network/IPC.cxx | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'dev/ZKA/Sources') diff --git a/dev/ZKA/Sources/Network/IPC.cxx b/dev/ZKA/Sources/Network/IPC.cxx index 926224d9..2ec50892 100644 --- a/dev/ZKA/Sources/Network/IPC.cxx +++ b/dev/ZKA/Sources/Network/IPC.cxx @@ -30,8 +30,12 @@ Bool ipc_int_sanitize_packet(IPC_MESSAGE_STRUCT* pckt) break; } - case Endian::kEndianMixed: + case Endian::kEndianMixed: { + if (pckt->IpcEndianess == eIPCEPMixedEndian) + goto ipc_check_failed; + break; + } default: goto ipc_check_failed; } @@ -42,7 +46,7 @@ Bool ipc_int_sanitize_packet(IPC_MESSAGE_STRUCT* pckt) goto ipc_check_failed; } - return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cRemoteHeaderMagic; + return pckt->IpcPacketSize > 1 && pckt->IpcHeaderMagic == cIPCEPHeaderMagic; ipc_check_failed: ErrLocal() = kErrorIPC; @@ -65,4 +69,41 @@ namespace Kernel return true; } + + /// @brief Construct packet function + /// @retval true packet is correct. + /// @retval false packet is incorrect and process has crashed. + Bool ipc_construct_packet(_Output IPC_MESSAGE_STRUCT** pckt_in) + { + // don't do anything if it's valid already. + if (*pckt_in) + return true; + + // crash process if the packet pointer of pointer is NULL. + if (!pckt_in) + { + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + return false; + } + + *pckt_in = new IPC_MESSAGE_STRUCT(); + + MUST_PASS((*pckt_in)); + + if (*pckt_in) + { + (*pckt_in)->IpcHeaderMagic = cIPCEPHeaderMagic; + + auto endian = DEDUCE_ENDIAN((*pckt_in), ((Char*)(*pckt_in))[0]); + + (*pckt_in)->IpcEndianess = static_cast(endian); + (*pckt_in)->IpcPacketSize = sizeof(IPC_MESSAGE_STRUCT); + (*pckt_in)->IpcFrom.ProcessID = Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().ProcessId; + (*pckt_in)->IpcFrom.ProcessTeam = Kernel::ProcessScheduler::The().Leak().CurrentTeam().mTeamId; + return true; + } + + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + return false; + } } // namespace Kernel -- cgit v1.2.3