From 2420b269817fb31d2f6dc25395f9e0f6dd0f4a6e Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 10 Dec 2019 18:10:47 -0800 Subject: [PATCH] sf: Allow for more than one process id holder (ugly) --- .../sf/impl/sf_impl_command_serialization.hpp | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp index ba1598a8f..50cc9d024 100644 --- a/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp +++ b/libraries/libstratosphere/include/stratosphere/sf/impl/sf_impl_command_serialization.hpp @@ -417,22 +417,9 @@ namespace ams::sf::impl { template static constexpr bool IsInProcessIdHolder = GetArgumentType == ArgumentType::InData && std::is_base_of::value; - template - static constexpr size_t GetInProcessIdHolderIndex(std::index_sequence) { - static_assert(sizeof...(Is) == std::tuple_size::value, "Invalid InProcessIdHolderIndexGetter invocation"); - constexpr std::array::value> is_in_process_id_holder = { IsInProcessIdHolder::type>... }; - for (size_t i = 0; i < std::tuple_size::value; i++) { - if (is_in_process_id_holder[i]) { - return i; - } - } - return std::numeric_limits::max(); - } + template + static constexpr bool IsInProcessIdHolderIndex = I < std::tuple_size::value && IsInProcessIdHolder::type>; - static constexpr size_t InProcessIdHolderIndex = GetInProcessIdHolderIndex(std::make_index_sequence::value>()); - - static_assert(NumInProcessIdHolders <= 1, "Methods must take in 0 or 1 ProcessIdHolders"); - static_assert(!HasInProcessIdHolder || InProcessIdHolderIndex != std::numeric_limits::max(), "Unable to identify InProcessIdHolder Index"); static_assert(NumBuffers <= 8, "Methods must take in <= 8 Buffers"); static_assert(NumInHandles <= 8, "Methods must take in <= 8 Handles"); static_assert(NumOutHandles + NumOutObjects <= 8, "Methods must output <= 8 Handles"); @@ -1105,7 +1092,26 @@ namespace ams::sf::impl { /* Handle in process ID holder if relevant. */ if constexpr (CommandMeta::HasInProcessIdHolder) { - R_TRY(MarshalProcessId(std::get(args_tuple), os::ProcessId{ctx.request.pid})); + /* TODO: More precise value than 32? */ + static_assert(std::tuple_size::value <= 32, "Commands must have <= 32 arguments"); + os::ProcessId process_id{ctx.request.pid}; + #define _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(n) do { \ + using ArgsType = typename CommandMeta::ArgsType; \ + if constexpr (n < std::tuple_size::value) { \ + if constexpr (CommandMeta::template IsInProcessIdHolderIndex) { \ + R_TRY(MarshalProcessId(std::get(args_tuple), process_id)); \ + } \ + } \ + } while (0) + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x00); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x01); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x02); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x03); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x04); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x05); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x06); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x07); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x08); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x09); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x0a); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x0b); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x0c); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x0d); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x0e); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x0f); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x10); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x11); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x12); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x13); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x14); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x15); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x16); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x17); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x18); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x19); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x1a); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x1b); + _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x1c); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x1d); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x1e); _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID(0x1f); + #undef _SF_IMPL_PROCESSOR_MARSHAL_PROCESS_ID } if constexpr (CommandMeta::ReturnsResult) {