diff --git a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp index 697a9d3ff..434a88f0c 100644 --- a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.cpp @@ -18,7 +18,6 @@ #include #include #include "set_mitm_service.hpp" -#include "set_shim.h" void SetMitmService::PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx) { /* No commands need postprocessing. */ @@ -104,7 +103,3 @@ Result SetMitmService::GetRegionCode(Out out_region_code) { out_region_code.SetValue(this->locale.region_code); return ResultSuccess; } - -Result SetMitmService::GetAvailableLanguageCodes(OutPointerWithClientSize out_language_codes, Out out_count) { - return setGetAvailableLanguageCodesFwd(this->forward_service.get(), out_count.GetPointer(), out_language_codes.pointer, out_language_codes.num_elements); -} diff --git a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp index 6f4b2a0e9..d40532cb9 100644 --- a/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/set_mitm_service.hpp @@ -25,10 +25,6 @@ class SetMitmService : public IMitmServiceObject { enum class CommandId { GetLanguageCode = 0, GetRegionCode = 4, - - /* Commands for which set:sys *must* act as a passthrough. */ - /* TODO: Solve the relevant IPC detection problem. */ - GetAvailableLanguageCodes = 1, }; private: sts::os::Mutex lock; @@ -55,14 +51,9 @@ class SetMitmService : public IMitmServiceObject { /* Overridden commands. */ Result GetLanguageCode(Out out_lang_code); Result GetRegionCode(Out out_region_code); - - /* Forced passthrough commands. */ - Result GetAvailableLanguageCodes(OutPointerWithClientSize out_language_codes, Out out_count); public: DEFINE_SERVICE_DISPATCH_TABLE { MAKE_SERVICE_COMMAND_META(SetMitmService, GetLanguageCode), MAKE_SERVICE_COMMAND_META(SetMitmService, GetRegionCode), - - MAKE_SERVICE_COMMAND_META(SetMitmService, GetAvailableLanguageCodes), }; }; diff --git a/stratosphere/ams_mitm/source/set_mitm/set_shim.c b/stratosphere/ams_mitm/source/set_mitm/set_shim.c deleted file mode 100644 index 61943496a..000000000 --- a/stratosphere/ams_mitm/source/set_mitm/set_shim.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018-2019 Atmosphère-NX - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include "setsys_shim.h" - -/* Command forwarders. */ -Result setGetAvailableLanguageCodesFwd(Service* s, s32 *total_entries, u64 *language_codes, size_t max_entries) { - IpcCommand c; - ipcInitialize(&c); - ipcAddRecvStatic(&c, language_codes, max_entries * sizeof(*language_codes), 0); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 1; - - Result rc = serviceIpcDispatch(s); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - - struct { - u64 magic; - u64 result; - s32 total_entries; - } *resp; - - serviceIpcParse(s, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - - if (R_SUCCEEDED(rc)) { - *total_entries = resp->total_entries; - } - } - - return rc; -} diff --git a/stratosphere/ams_mitm/source/set_mitm/set_shim.h b/stratosphere/ams_mitm/source/set_mitm/set_shim.h deleted file mode 100644 index bee7dcf42..000000000 --- a/stratosphere/ams_mitm/source/set_mitm/set_shim.h +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @file set_shim.h - * @brief Settings Services (set) IPC wrapper. To be merged into libnx, eventually. - * @author SciresM - * @copyright libnx Authors - */ -#pragma once -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Command forwarders. */ -Result setGetAvailableLanguageCodesFwd(Service* s, s32 *total_entries, u64 *language_codes, size_t max_entries); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp index a9d98c501..d0091f0a5 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp @@ -98,7 +98,3 @@ Result SetSysMitmService::GetSettingsItemValue(Out out_size, OutBuffer return ResultSuccess; } - -Result SetSysMitmService::GetEdid(OutPointerWithServerSize out) { - return setsysGetEdidFwd(this->forward_service.get(), out.pointer); -} diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp index 13d1554b6..5b4798a17 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.hpp @@ -27,10 +27,6 @@ class SetSysMitmService : public IMitmServiceObject { GetFirmwareVersion2 = 4, GetSettingsItemValueSize = 37, GetSettingsItemValue = 38, - - /* Commands for which set:sys *must* act as a passthrough. */ - /* TODO: Solve the relevant IPC detection problem. */ - GetEdid = 41, }; public: SetSysMitmService(std::shared_ptr s, u64 pid, sts::ncm::TitleId tid) : IMitmServiceObject(s, pid, tid) { @@ -50,16 +46,11 @@ class SetSysMitmService : public IMitmServiceObject { Result GetFirmwareVersion2(OutPointerWithServerSize out); Result GetSettingsItemValueSize(Out out_size, InPointer name, InPointer key); Result GetSettingsItemValue(Out out_size, OutBuffer out_value, InPointer name, InPointer key); - - /* Forced passthrough commands. */ - Result GetEdid(OutPointerWithServerSize out); public: DEFINE_SERVICE_DISPATCH_TABLE { MAKE_SERVICE_COMMAND_META(SetSysMitmService, GetFirmwareVersion), MAKE_SERVICE_COMMAND_META(SetSysMitmService, GetFirmwareVersion2), MAKE_SERVICE_COMMAND_META(SetSysMitmService, GetSettingsItemValueSize), MAKE_SERVICE_COMMAND_META(SetSysMitmService, GetSettingsItemValue), - - MAKE_SERVICE_COMMAND_META(SetSysMitmService, GetEdid), }; }; diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_shim.c b/stratosphere/ams_mitm/source/set_mitm/setsys_shim.c index d532adb9d..1f895e8f5 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_shim.c +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_shim.c @@ -19,39 +19,6 @@ #include "setsys_shim.h" /* Command forwarders. */ -Result setsysGetEdidFwd(Service* s, SetSysEdid* out) { - IpcCommand c; - ipcInitialize(&c); - ipcAddRecvStatic(&c, out, sizeof(*out), 0); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 41; - - Result rc = serviceIpcDispatch(s); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - struct { - u64 magic; - u64 result; - } *resp; - - serviceIpcParse(s, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - } - - return rc; -} - Result setsysGetSettingsItemValueFwd(Service *s, const char *name, const char *item_key, void *value_out, size_t value_out_size, u64 *size_out) { char send_name[SET_MAX_NAME_SIZE]; char send_item_key[SET_MAX_NAME_SIZE]; diff --git a/stratosphere/ams_mitm/source/set_mitm/setsys_shim.h b/stratosphere/ams_mitm/source/set_mitm/setsys_shim.h index c2b5f73da..ad983c552 100644 --- a/stratosphere/ams_mitm/source/set_mitm/setsys_shim.h +++ b/stratosphere/ams_mitm/source/set_mitm/setsys_shim.h @@ -11,12 +11,7 @@ extern "C" { #endif -typedef struct { - char edid[0x100]; -} SetSysEdid; - /* Command forwarders. */ -Result setsysGetEdidFwd(Service* s, SetSysEdid* out); Result setsysGetSettingsItemValueFwd(Service* s, const char *name, const char *item_key, void *value_out, size_t value_out_size, u64 *size_out); #ifdef __cplusplus diff --git a/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_session.hpp b/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_session.hpp index 71c45cbbe..13110ce8e 100644 --- a/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_session.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/mitm/mitm_session.hpp @@ -80,6 +80,23 @@ class MitmSession final : public ServiceSession { } Result ForwardRequest(IpcResponseContext *ctx) { + /* Mitm forward specific preprocessing. */ + if (ctx->request.NumStaticsOut) { + u32 *cmdbuf = (u32 *)armGetTls(); + /* Overwrite the number of C descriptors to only use a single buffer. */ + cmdbuf[1] = (cmdbuf[1] & (~u32(0xF << 10))) | (0x2 << 10); + + IpcStaticRecvDescriptor *c_desc = (IpcStaticRecvDescriptor *)(reinterpret_cast(ctx->request.RawWithoutPadding) + ctx->request.RawSize); + /* Don't write out of bounds, though this should never happen. */ + if (reinterpret_cast(c_desc) + sizeof(*c_desc) <= reinterpret_cast(cmdbuf) + 0x100) { + uintptr_t ptr = reinterpret_cast(this->pointer_buffer.data()); + c_desc->Addr = ptr; + c_desc->Packed = (ptr >> 32) | (this->pointer_buffer.size() << 16); + } else { + std::abort(); + } + } + /* Dispatch forwards. */ R_TRY(serviceIpcDispatch(this->forward_service.get()));