mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-05-28 23:44:31 +00:00
IPC stub
This commit is contained in:
parent
e489d49917
commit
50037c4a81
63
Tasking/InterProcessCommunication.cpp
Normal file
63
Tasking/InterProcessCommunication.cpp
Normal 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
75
include/ipc.hpp
Normal 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__
|
Loading…
x
Reference in New Issue
Block a user