From b5412df53bbf52f1cb9de3b0053a7812b81651d2 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 3 May 2018 03:14:48 -0600 Subject: [PATCH] Stratosphere: Add IPC templating for non-member functions. --- .gitignore | 2 ++ .../include/stratosphere/ipc_templating.hpp | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/.gitignore b/.gitignore index 132a020c9..445b799b9 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,8 @@ stratosphere/loader/out/** stratosphere/loader/build/** stratosphere/sm/out/** stratosphere/sm/build/** +stratosphere/pm/out/** +stratosphere/pm/build/** stratosphere/boot/out/** stratosphere/boot/build/** stratosphere/boot2/out/** diff --git a/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp b/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp index 7150fa38d..98c0490b1 100644 --- a/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/ipc_templating.hpp @@ -428,5 +428,27 @@ 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); + return std::apply(Encoder{out_command}, result); +} + +template +Result WrapStaticIpcCommandImpl(IpcParsedCommand& r, IpcCommand &out_command, u8 *pointer_buffer, size_t pointer_buffer_size) { + using InArgs = typename boost::callable_traits::args_t; + using OutArgs = typename boost::callable_traits::return_type_t; + + static_assert(is_specialization_of::value, "IpcCommandImpls must return std::tuple"); + static_assert(std::is_same_v, Result>, "IpcCommandImpls must return std::tuple"); + + ipcInitialize(&out_command); + + Result rc = Validator{r, pointer_buffer_size}(); + + if (R_FAILED(rc)) { + return 0xF601; + } + + auto args = Decoder::Decode(r, out_command, pointer_buffer); + auto result = std::apply(IpcCommandImpl, args); + return std::apply(Encoder{out_command}, result); } \ No newline at end of file