diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-28 08:00:52 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-28 08:00:52 +0200 |
| commit | 3c233e380524d6842d396fd0a1fb9aeacf34d35f (patch) | |
| tree | 30ea7f65f614c96e60cb514d8402c352cdc05879 /dev/ZKA/Sources/Network | |
| parent | cdaf8e9379f1756a9416f455ff5552fb8871c16d (diff) | |
[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 <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/Sources/Network')
| -rw-r--r-- | dev/ZKA/Sources/Network/IPC.cxx | 45 |
1 files changed, 43 insertions, 2 deletions
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<UInt8>(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 |
