mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-08 20:11:39 +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
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue