From b8ac9a8fcf0bc7cfd9a3866944d4bac6b3ba40d8 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 16 Oct 2018 13:33:45 -0700 Subject: [PATCH] fs.mitm: Add domain support (closes #202) --- include/stratosphere/ipc_templating.hpp | 14 +++++++++++--- include/stratosphere/isession.hpp | 10 +++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/stratosphere/ipc_templating.hpp b/include/stratosphere/ipc_templating.hpp index 7f9c2c89..d37857ae 100644 --- a/include/stratosphere/ipc_templating.hpp +++ b/include/stratosphere/ipc_templating.hpp @@ -459,7 +459,9 @@ struct Encoder> { raw = (decltype(raw))ipcPrepareHeader(&out_command, sizeof(*raw) + size_in_raw_data_for_arguments::value - sizeof(Result)); } else { raw = (decltype(raw))ipcPrepareHeaderForDomain(&out_command, sizeof(*raw) + size_in_raw_data_for_arguments::value + (num_out_sessions_in_arguments::value * sizeof(u32)) - sizeof(Result), 0); - *((DomainMessageHeader *)((uintptr_t)raw - sizeof(DomainMessageHeader))) = {0}; + auto resp_header = (DomainResponseHeader *)((uintptr_t)raw - sizeof(DomainResponseHeader)); + *resp_header = {0}; + resp_header->NumObjectIds = num_out_sessions_in_arguments::value; } @@ -474,7 +476,13 @@ struct Encoder> { if (R_FAILED(rc)) { std::fill(tls, tls + 0x100, 0x00); ipcInitialize(&out_command); - raw = (decltype(raw))ipcPrepareHeader(&out_command, sizeof(raw)); + if (domain_owner != NULL) { + raw = (decltype(raw))ipcPrepareHeaderForDomain(&out_command, sizeof(raw), 0); + auto resp_header = (DomainResponseHeader *)((uintptr_t)raw - sizeof(DomainResponseHeader)); + *resp_header = {0}; + } else { + raw = (decltype(raw))ipcPrepareHeader(&out_command, sizeof(raw)); + } raw->magic = SFCO_MAGIC; raw->result = rc; } @@ -526,7 +534,7 @@ Result WrapIpcCommandImpl(Class *this_ptr, IpcParsedCommand& r, IpcCommand &out_ auto args = Decoder::Decode(r, out_command, pointer_buffer); auto result = std::apply( [=](auto&&... args) { return (this_ptr->*IpcCommandImpl)(args...); }, args); DomainOwner *down = NULL; - if (r.IsDomainMessage) { + if (r.IsDomainRequest) { down = this_ptr->get_owner(); } diff --git a/include/stratosphere/isession.hpp b/include/stratosphere/isession.hpp index 842dfd41..95156a2d 100644 --- a/include/stratosphere/isession.hpp +++ b/include/stratosphere/isession.hpp @@ -118,12 +118,12 @@ class ISession : public IWaitable { IpcCommand c; ipcInitialize(&c); - if (r.IsDomainMessage && this->active_object == NULL) { + if (r.IsDomainRequest && this->active_object == NULL) { return 0xF601; } - if (r.IsDomainMessage && r.MessageType == DomainMessageType_Close) { + if (r.IsDomainRequest && r.InMessageType == DomainMessageType_Close) { this->domain->delete_object(this->active_object); this->active_object = NULL; struct { @@ -198,11 +198,11 @@ class ISession : public IWaitable { Result retval = ipcParse(&r); if (R_SUCCEEDED(retval)) { if (this->is_domain && (r.CommandType == IpcCommandType_Request || r.CommandType == IpcCommandType_RequestWithContext)) { - retval = ipcParseForDomain(&r); - if (!r.IsDomainMessage || r.ThisObjectId >= DOMAIN_ID_MAX) { + retval = ipcParseDomainRequest(&r); + if (!r.IsDomainRequest || r.InThisObjectId >= DOMAIN_ID_MAX) { retval = 0xF601; } else { - this->active_object = this->domain->get_domain_object(r.ThisObjectId); + this->active_object = this->domain->get_domain_object(r.InThisObjectId); } } else { this->active_object = this->service_object;