This commit is contained in:
Alex 2022-10-26 21:50:29 +03:00
parent e489d49917
commit 50037c4a81
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,63 @@
#include <ipc.hpp>
#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()
{
}
}

75
include/ipc.hpp Normal file
View File

@ -0,0 +1,75 @@
#ifndef __FENNIX_KERNEL_IPC_H__
#define __FENNIX_KERNEL_IPC_H__
#include <types.h>
#include <lock.hpp>
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__