diff --git a/Tasking/InterProcessCommunication.cpp b/Tasking/InterProcessCommunication.cpp new file mode 100644 index 0000000..a5dcc12 --- /dev/null +++ b/Tasking/InterProcessCommunication.cpp @@ -0,0 +1,63 @@ +#include + +#include "../kernel.h" + +InterProcessCommunication::IPC *ipc = nullptr; + +namespace InterProcessCommunication +{ + IPCHandle *IPC::RegisterHandle(IPCPort Port) + { + if (Port == 0) + return nullptr; + + Tasking::PCB *pcb = TaskManager->GetCurrentProcess(); + + if (pcb->IPCHandles->Get((int)Port) != 0) + return nullptr; + + IPCHandle *handle = new IPCHandle; + handle->ID = -1; + handle->Buffer = nullptr; + handle->Length = 0; + handle->Type = IPCOperationNone; + handle->Listening = 0; + handle->Error = IPCUnknown; + pcb->IPCHandles->AddNode(Port, (uint64_t)handle); + return handle; + } + + IPCHandle *IPC::Wait(IPCPort port) + { + return nullptr; + } + + IPCError IPC::Read(int PID, IPCPort port, void *buf, int size) + { + return IPCError{IPCUnknown}; + } + + IPCError IPC::Write(int PID, IPCPort port, void *buf, int size) + { + return IPCError{IPCUnknown}; + } + + void IPCServiceStub() + { + trace("IPC Service Started."); + TaskManager->GetCurrentThread()->SetPriority(1); + // TODO: do something useful here, like, IPC event viewer or smth... + while (1) + ; + } + + IPC::IPC() + { + TaskManager->CreateThread(TaskManager->GetCurrentProcess(), (Tasking::IP)IPCServiceStub); + TaskManager->GetCurrentThread()->Rename("IPC Service"); + } + + IPC::~IPC() + { + } +} diff --git a/include/ipc.hpp b/include/ipc.hpp new file mode 100644 index 0000000..9757319 --- /dev/null +++ b/include/ipc.hpp @@ -0,0 +1,75 @@ +#ifndef __FENNIX_KERNEL_IPC_H__ +#define __FENNIX_KERNEL_IPC_H__ + +#include + +#include + +namespace InterProcessCommunication +{ + typedef unsigned int IPCPort; + + enum IPCOperationType + { + IPCOperationNone, + IPCOperationWrite, + IPCOperationRead + }; + + enum IPCErrorCode + { + IPCUnknown, + IPCSuccess, + IPCNotListening, + IPCTimeout, + IPCInvalidPort, + IPCPortInUse, + IPCPortNotRegistered + }; + + typedef struct + { + int ID; + int Length; + void *Buffer; + bool Listening; + IPCOperationType Type; + IPCErrorCode Error; + LockClass Lock; + } IPCHandle; + + typedef struct + { + int ID; + int Length; + IPCOperationType Type; + IPCErrorCode Error; + void *Buffer; + + // Reserved + IPCHandle *HandleBuffer; + } __attribute__((packed)) IPCSyscallHandle; + + struct IPCError + { + uint64_t ErrorCode; + }; + + class IPC + { + private: + + public: + IPC(); + ~IPC(); + + IPCHandle *RegisterHandle(IPCPort Port); + IPCHandle *Wait(IPCPort port); + IPCError Read(int pid, IPCPort port, void *buf, int size); + IPCError Write(int pid, IPCPort port, void *buf, int size); + }; +} + +extern InterProcessCommunication::IPC *ipc; + +#endif // !__FENNIX_KERNEL_IPC_H__