mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-04 03:04:48 +12:00
Initial implementation of ports and sessions
This commit is contained in:
parent
aa643c44bb
commit
0e66af8dae
7 changed files with 100 additions and 17 deletions
src/core
|
@ -39,18 +39,32 @@ KernelObject* Kernel::getProcessFromPID(Handle handle) {
|
|||
}
|
||||
}
|
||||
|
||||
void Kernel::deleteObjectData(KernelObject& object) {
|
||||
// Resource limit and dummy objects do not allocate heap data, so we don't delete anything
|
||||
if (object.type == KernelObjectType::ResourceLimit || object.type == KernelObjectType::Dummy) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (object.data != nullptr) {
|
||||
delete object.data;
|
||||
}
|
||||
}
|
||||
|
||||
void Kernel::reset() {
|
||||
handleCounter = 0;
|
||||
|
||||
for (auto& object : objects) {
|
||||
if (object.data != nullptr) {
|
||||
delete object.data;
|
||||
}
|
||||
deleteObjectData(object);
|
||||
}
|
||||
objects.clear();
|
||||
portHandles.clear();
|
||||
|
||||
// Make a main process object
|
||||
// Allocate handle #0 to a dummy object and make a main process object
|
||||
makeObject(KernelObjectType::Dummy);
|
||||
currentProcess = makeProcess();
|
||||
|
||||
// Create global service manager port
|
||||
makePort("srv:");
|
||||
}
|
||||
|
||||
// Result CreateAddressArbiter(Handle* arbiter)
|
||||
|
@ -65,14 +79,6 @@ void Kernel::svcCloseHandle() {
|
|||
regs[0] = SVCResult::Success;
|
||||
}
|
||||
|
||||
void Kernel::connectToPort() {
|
||||
const u32 handlePointer = regs[0];
|
||||
const char* port = static_cast<const char*>(mem.getReadPointer(regs[1]));
|
||||
|
||||
printf("ConnectToPort(handle pointer = %08X, port = \"%s\")\n", handlePointer, port);
|
||||
Helpers::panic("Unimplemented IPC");
|
||||
}
|
||||
|
||||
std::string Kernel::getProcessName(u32 pid) {
|
||||
if (pid == KernelHandles::CurrentProcess) {
|
||||
return "current";
|
||||
|
|
57
src/core/kernel/ports.cpp
Normal file
57
src/core/kernel/ports.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "kernel.hpp"
|
||||
#include <cstring>
|
||||
|
||||
Handle Kernel::makePort(const char* name) {
|
||||
Handle ret = makeObject(KernelObjectType::Port);
|
||||
portHandles.push_back(ret); // Push the port handle to our cache of port handles
|
||||
|
||||
objects[ret].data = new PortData();
|
||||
const auto data = static_cast<PortData*>(objects[ret].data);
|
||||
|
||||
// If the name is empty (ie the first char is the null terminator) then the port is private
|
||||
data->isPublic = name[0] != '\0';
|
||||
std::strncpy(data->name, name, PortData::maxNameLen);
|
||||
|
||||
// printf("Created %s port \"%s\" with handle %d\n", data->isPublic ? "public" : "private", data->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get the handle of a port based on its name
|
||||
// If there's no such port, return nullopt
|
||||
std::optional<Handle> Kernel::getPortHandle(const char* name) {
|
||||
for (auto handle : portHandles) {
|
||||
const auto data = static_cast<PortData*>(objects[handle].data);
|
||||
if (std::strncmp(name, data->name, PortData::maxNameLen) == 0) {
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Result ConnectToPort(Handle* out, const char* portName)
|
||||
void Kernel::connectToPort() {
|
||||
const u32 handlePointer = regs[0];
|
||||
const char* port = static_cast<const char*>(mem.getReadPointer(regs[1]));
|
||||
printf("ConnectToPort(handle pointer = %08X, port = \"%s\")\n", handlePointer, port);
|
||||
|
||||
// TODO: This is unsafe
|
||||
if (std::strlen(port) > PortData::maxNameLen) {
|
||||
Helpers::panic("ConnectToPort: Port name too long\n");
|
||||
regs[0] = SVCResult::PortNameTooLong;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto portHandle = getPortHandle(port);
|
||||
if (!portHandle.has_value()) {
|
||||
Helpers::panic("ConnectToPort: Port doesn't exist\n");
|
||||
regs[0] = SVCResult::ObjectNotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Actually create session
|
||||
Handle sessionHandle = makeObject(KernelObjectType::Session);
|
||||
|
||||
regs[0] = SVCResult::Success;
|
||||
regs[1] = sessionHandle;
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
#include "config_mem.hpp"
|
||||
#include <cassert>
|
||||
|
||||
|
||||
Memory::Memory() {
|
||||
fcram = new uint8_t[FCRAM_SIZE]();
|
||||
readTable.resize(totalPageCount, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue