From 8cb65fe65a48988d40dd3ca2c4f673629a275b4b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 9 Jun 2017 05:23:13 -0700 Subject: Kernel: Basic support for IPC translation for HLE services --- src/core/hle/kernel/hle_ipc.h | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/core/hle/kernel/hle_ipc.h') diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index f23daa7ea..d6ebf113c 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -8,6 +8,7 @@ #include #include #include "common/common_types.h" +#include "common/swap.h" #include "core/hle/ipc.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/server_session.h" @@ -18,6 +19,9 @@ class ServiceFrameworkBase; namespace Kernel { +class HandleTable; +class Process; + /** * Interface implemented by HLE Session handlers. * This can be provided to a ServerSession in order to hook into several relevant events @@ -62,6 +66,20 @@ protected: * Class containing information about an in-flight IPC request being handled by an HLE service * implementation. Services should avoid using old global APIs (e.g. Kernel::GetCommandBuffer()) and * when possible use the APIs in this class to service the request. + * + * HLE handle protocol + * =================== + * + * To avoid needing HLE services to keep a separate handle table, or having to directly modify the + * requester's table, a tweaked protocol is used to receive and send handles in requests. The kernel + * will decode the incoming handles into object pointers and insert a id in the buffer where the + * handle would normally be. The service then calls GetIncomingHandle() with that id to get the + * pointer to the object. Similarly, instead of inserting a handle into the command buffer, the + * service calls AddOutgoingHandle() and stores the returned id where the handle would normally go. + * + * The end result is similar to just giving services their own real handle tables, but since these + * ids are local to a specific context, it avoids requiring services to manage handles for objects + * across multiple calls and ensuring that unneeded handles are cleaned up. */ class HLERequestContext { public: @@ -80,14 +98,29 @@ public: return session; } - SharedPtr GetIncomingHandle(Handle id_from_cmdbuf) const; - Handle AddOutgoingHandle(SharedPtr object); + /** + * Resolves a object id from the request command buffer into a pointer to an object. See the + * "HLE handle protocol" section in the class documentation for more details. + */ + SharedPtr GetIncomingHandle(u32 id_from_cmdbuf) const; + + /** + * Adds an outgoing object to the response, returning the id which should be used to reference + * it. See the "HLE handle protocol" section in the class documentation for more details. + */ + u32 AddOutgoingHandle(SharedPtr object); private: friend class Service::ServiceFrameworkBase; + ResultCode PopulateFromIncomingCommandBuffer(const u32_le* src_cmdbuf, Process& src_process, + HandleTable& src_table); + ResultCode WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, Process& dst_process, + HandleTable& dst_table) const; + std::array cmd_buf; SharedPtr session; + std::vector> request_handles; }; } // namespace Kernel -- cgit v1.2.3