mirror of
https://github.com/Takiiiiiiii/strato.git
synced 2025-07-17 08:46:39 +00:00
Improve IPC interface
This commit changes how IPC is interacted with in two ways: * Simplify all buffers into just InputBuffer and OutputBuffer * Use pushing/popping for data payload
This commit is contained in:
@ -2,6 +2,16 @@
|
||||
#include "types/KProcess.h"
|
||||
|
||||
namespace skyline::kernel::ipc {
|
||||
IpcBuffer::IpcBuffer(u64 address, size_t size, IpcBufferType type) : address(address), size(size), type(type) {}
|
||||
|
||||
InputBuffer::InputBuffer(kernel::ipc::BufferDescriptorX *xBuf) : IpcBuffer(xBuf->Address(), xBuf->size, IpcBufferType::X) {}
|
||||
|
||||
InputBuffer::InputBuffer(kernel::ipc::BufferDescriptorABW *aBuf, IpcBufferType type) : IpcBuffer(aBuf->Address(), aBuf->Size(), type) {}
|
||||
|
||||
OutputBuffer::OutputBuffer(kernel::ipc::BufferDescriptorABW *bBuf, IpcBufferType type) : IpcBuffer(bBuf->Address(), bBuf->Size(), type) {}
|
||||
|
||||
OutputBuffer::OutputBuffer(kernel::ipc::BufferDescriptorC *cBuf) : IpcBuffer(cBuf->address, cBuf->size, IpcBufferType::C) {}
|
||||
|
||||
IpcRequest::IpcRequest(bool isDomain, const DeviceState &state) : isDomain(isDomain), state(state), tls() {
|
||||
u8 *currPtr = tls.data();
|
||||
state.thisProcess->ReadMemory(currPtr, state.thisThread->tls, constant::TlsIpcSize);
|
||||
@ -25,7 +35,7 @@ namespace skyline::kernel::ipc {
|
||||
for (uint index = 0; header->Xno > index; index++) {
|
||||
auto bufX = reinterpret_cast<BufferDescriptorX *>(currPtr);
|
||||
if (bufX->Address()) {
|
||||
vecBufX.push_back(bufX);
|
||||
inputBuf.emplace_back(bufX);
|
||||
state.logger->Debug("Buf X #{} AD: 0x{:X} SZ: 0x{:X} CTR: {}", index, u64(bufX->Address()), u16(bufX->size), u16(bufX->Counter()));
|
||||
}
|
||||
currPtr += sizeof(BufferDescriptorX);
|
||||
@ -34,7 +44,7 @@ namespace skyline::kernel::ipc {
|
||||
for (uint index = 0; header->Ano > index; index++) {
|
||||
auto bufA = reinterpret_cast<BufferDescriptorABW *>(currPtr);
|
||||
if (bufA->Address()) {
|
||||
vecBufA.push_back(bufA);
|
||||
inputBuf.emplace_back(bufA);
|
||||
state.logger->Debug("Buf A #{} AD: 0x{:X} SZ: 0x{:X}", index, u64(bufA->Address()), u64(bufA->Size()));
|
||||
}
|
||||
currPtr += sizeof(BufferDescriptorABW);
|
||||
@ -43,7 +53,7 @@ namespace skyline::kernel::ipc {
|
||||
for (uint index = 0; header->Bno > index; index++) {
|
||||
auto bufB = reinterpret_cast<BufferDescriptorABW *>(currPtr);
|
||||
if (bufB->Address()) {
|
||||
vecBufB.push_back(bufB);
|
||||
outputBuf.emplace_back(bufB);
|
||||
state.logger->Debug("Buf B #{} AD: 0x{:X} SZ: 0x{:X}", index, u64(bufB->Address()), u64(bufB->Size()));
|
||||
}
|
||||
currPtr += sizeof(BufferDescriptorABW);
|
||||
@ -52,7 +62,8 @@ namespace skyline::kernel::ipc {
|
||||
for (uint index = 0; header->Wno > index; index++) {
|
||||
auto bufW = reinterpret_cast<BufferDescriptorABW *>(currPtr);
|
||||
if (bufW->Address()) {
|
||||
vecBufW.push_back(bufW);
|
||||
inputBuf.emplace_back(bufW, IpcBufferType::W);
|
||||
outputBuf.emplace_back(bufW, IpcBufferType::W);
|
||||
state.logger->Debug("Buf W #{} AD: 0x{:X} SZ: 0x{:X}", index, u64(bufW->Address()), u16(bufW->Size()));
|
||||
}
|
||||
currPtr += sizeof(BufferDescriptorABW);
|
||||
@ -85,6 +96,8 @@ namespace skyline::kernel::ipc {
|
||||
currPtr += cmdArgSz;
|
||||
}
|
||||
|
||||
payloadOffset = cmdArg;
|
||||
|
||||
if (payload->magic != constant::SfciMagic && header->type != CommandType::Control)
|
||||
state.logger->Debug("Unexpected Magic in PayloadHeader: 0x{:X}", u32(payload->magic));
|
||||
|
||||
@ -92,13 +105,15 @@ namespace skyline::kernel::ipc {
|
||||
|
||||
if (header->cFlag == BufferCFlag::SingleDescriptor) {
|
||||
auto bufC = reinterpret_cast<BufferDescriptorC *>(currPtr);
|
||||
vecBufC.push_back(bufC);
|
||||
state.logger->Debug("Buf C: AD: 0x{:X} SZ: 0x{:X}", u64(bufC->address), u16(bufC->size));
|
||||
if (bufC->address) {
|
||||
outputBuf.emplace_back(bufC);
|
||||
state.logger->Debug("Buf C: AD: 0x{:X} SZ: 0x{:X}", u64(bufC->address), u16(bufC->size));
|
||||
}
|
||||
} else if (header->cFlag > BufferCFlag::SingleDescriptor) {
|
||||
for (uint index = 0; (static_cast<u8>(header->cFlag) - 2) > index; index++) { // (cFlag - 2) C descriptors are present
|
||||
auto bufC = reinterpret_cast<BufferDescriptorC *>(currPtr);
|
||||
if (bufC->address) {
|
||||
vecBufC.push_back(bufC);
|
||||
outputBuf.emplace_back(bufC);
|
||||
state.logger->Debug("Buf C #{} AD: 0x{:X} SZ: 0x{:X}", index, u64(bufC->address), u16(bufC->size));
|
||||
}
|
||||
currPtr += sizeof(BufferDescriptorC);
|
||||
@ -106,7 +121,7 @@ namespace skyline::kernel::ipc {
|
||||
}
|
||||
|
||||
if (header->type == CommandType::Request) {
|
||||
state.logger->Debug("Header: X No: {}, A No: {}, B No: {}, W No: {}, C No: {}, Raw Size: {}", u8(header->Xno), u8(header->Ano), u8(header->Bno), u8(header->Wno), u8(vecBufC.size()), u64(cmdArgSz));
|
||||
state.logger->Debug("Header: Input No: {}, Output No: {}, Raw Size: {}", inputBuf.size(), outputBuf.size(), u64(cmdArgSz));
|
||||
if (header->handleDesc)
|
||||
state.logger->Debug("Handle Descriptor: Send PID: {}, Copy Count: {}, Move Count: {}", bool(handleDesc->sendPid), u32(handleDesc->copyCount), u32(handleDesc->moveCount));
|
||||
if (isDomain)
|
||||
@ -117,7 +132,7 @@ namespace skyline::kernel::ipc {
|
||||
|
||||
IpcResponse::IpcResponse(bool isDomain, const DeviceState &state) : isDomain(isDomain), state(state) {}
|
||||
|
||||
void IpcResponse::WriteTls() {
|
||||
void IpcResponse::WriteResponse() {
|
||||
std::array<u8, constant::TlsIpcSize> tls{};
|
||||
u8 *currPtr = tls.data();
|
||||
auto header = reinterpret_cast<CommandHeader *>(currPtr);
|
||||
|
Reference in New Issue
Block a user