mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-27 15:11:44 +00:00
Kernel/multiboot2_64
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
#include <ipc.hpp>
|
||||
|
||||
#include <lock.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../kernel.h"
|
||||
|
||||
NewLock(IPCLock);
|
||||
|
||||
InterProcessCommunication::IPC *ipc = nullptr;
|
||||
|
||||
namespace InterProcessCommunication
|
||||
{
|
||||
IPCHandle *IPC::RegisterHandle(IPCPort Port)
|
||||
{
|
||||
SmartLock(IPCLock);
|
||||
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->Operation = IPCOperationNone;
|
||||
handle->Listening = 0;
|
||||
handle->Error = IPCUnknown;
|
||||
pcb->IPCHandles->AddNode(Port, (uint64_t)handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
IPCError IPC::Listen(IPCPort Port)
|
||||
{
|
||||
SmartLock(IPCLock);
|
||||
if (Port == 0)
|
||||
return IPCError{IPCInvalidPort};
|
||||
|
||||
Tasking::PCB *pcb = TaskManager->GetCurrentProcess();
|
||||
|
||||
if (pcb->IPCHandles->Get((int)Port) == 0)
|
||||
return IPCError{IPCPortNotRegistered};
|
||||
|
||||
IPCHandle *handle = (IPCHandle *)pcb->IPCHandles->Get((int)Port);
|
||||
handle->Listening = 1;
|
||||
return IPCError{IPCSuccess};
|
||||
}
|
||||
|
||||
IPCHandle *IPC::Wait(IPCPort Port)
|
||||
{
|
||||
SmartLock(IPCLock);
|
||||
if (Port == 0)
|
||||
return nullptr;
|
||||
|
||||
Tasking::PCB *pcb = TaskManager->GetCurrentProcess();
|
||||
|
||||
if (pcb->IPCHandles->Get((int)Port) == 0)
|
||||
return nullptr;
|
||||
|
||||
IPCHandle *handle = (IPCHandle *)pcb->IPCHandles->Get((int)Port);
|
||||
|
||||
while (handle->Listening == 1)
|
||||
CPU::Pause();
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
IPCError IPC::Read(Tasking::UPID ID, IPCPort Port, uint8_t *&Buffer, long &Size)
|
||||
{
|
||||
SmartLock(IPCLock);
|
||||
if (Port == 0)
|
||||
return IPCError{IPCInvalidPort};
|
||||
|
||||
Tasking::PCB *pcb = TaskManager->GetCurrentProcess();
|
||||
|
||||
if (pcb->IPCHandles->Get((int)Port) == 0)
|
||||
return IPCError{IPCInvalidPort};
|
||||
|
||||
IPCHandle *handle = (IPCHandle *)pcb->IPCHandles->Get((int)Port);
|
||||
|
||||
if (handle->Listening == 0)
|
||||
return IPCError{IPCPortInUse};
|
||||
|
||||
Buffer = handle->Buffer;
|
||||
Size = handle->Length;
|
||||
handle->Operation = IPCOperationRead;
|
||||
handle->Listening = 1;
|
||||
handle->Error = IPCSuccess;
|
||||
|
||||
return IPCError{IPCSuccess};
|
||||
}
|
||||
|
||||
IPCError IPC::Write(Tasking::UPID ID, IPCPort Port, uint8_t *Buffer, long Size)
|
||||
{
|
||||
SmartLock(IPCLock);
|
||||
if (Port == 0)
|
||||
return IPCError{IPCInvalidPort};
|
||||
|
||||
Vector<Tasking::PCB *> Processes = TaskManager->GetProcessList();
|
||||
|
||||
for (uint64_t i = 0; i < Processes.size(); i++)
|
||||
{
|
||||
Tasking::PCB *pcb = Processes[i];
|
||||
|
||||
if (pcb->ID == ID)
|
||||
{
|
||||
if (pcb->IPCHandles->Get((int)Port) == 0)
|
||||
return IPCError{IPCInvalidPort};
|
||||
|
||||
IPCHandle *handle = (IPCHandle *)pcb->IPCHandles->Get((int)Port);
|
||||
|
||||
if (handle->Listening == 0)
|
||||
return IPCError{IPCNotListening};
|
||||
|
||||
handle->Buffer = Buffer;
|
||||
handle->Length = Size;
|
||||
handle->Operation = IPCOperationWrite;
|
||||
handle->Listening = 0;
|
||||
handle->Error = IPCSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
return IPCError{IPCIDNotFound};
|
||||
}
|
||||
|
||||
IPC::IPC()
|
||||
{
|
||||
SmartLock(IPCLock);
|
||||
trace("Starting IPC Service...");
|
||||
}
|
||||
|
||||
IPC::~IPC()
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
#include <task.hpp>
|
||||
|
||||
#include <vector.hpp>
|
||||
#include <rand.hpp>
|
||||
#include <debug.h>
|
||||
|
||||
namespace Tasking
|
||||
{
|
||||
struct TokenData
|
||||
{
|
||||
Token token;
|
||||
enum TokenTrustLevel TrustLevel;
|
||||
uint64_t OwnerID;
|
||||
bool Process;
|
||||
};
|
||||
|
||||
Vector<TokenData> Tokens;
|
||||
|
||||
Token Security::CreateToken()
|
||||
{
|
||||
uint64_t ret = Random::rand64();
|
||||
Tokens.push_back({ret, UnknownTrustLevel, 0, false});
|
||||
debug("Created token %#lx", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Security::TrustToken(Token token,
|
||||
TokenTrustLevel TrustLevel)
|
||||
{
|
||||
enum TokenTrustLevel Level = static_cast<enum TokenTrustLevel>(TrustLevel);
|
||||
|
||||
foreach (auto var in Tokens)
|
||||
{
|
||||
if (var.token == token)
|
||||
{
|
||||
var.TrustLevel = Level;
|
||||
debug("Trusted token %#lx", token);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
debug("Failed to trust token %#lx", token);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Security::UntrustToken(Token token)
|
||||
{
|
||||
fixme("UntrustToken->false");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Security::DestroyToken(Token token)
|
||||
{
|
||||
fixme("DestroyToken->false");
|
||||
return false;
|
||||
}
|
||||
|
||||
Security::Security()
|
||||
{
|
||||
trace("Initializing Tasking Security");
|
||||
}
|
||||
|
||||
Security::~Security()
|
||||
{
|
||||
trace("Destroying Tasking Security");
|
||||
for (uint64_t i = 0; i < Tokens.size(); i++)
|
||||
Tokens.remove(i);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user