summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/hle_ipc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/hle_ipc.h')
-rw-r--r--src/core/hle/kernel/hle_ipc.h37
1 files changed, 35 insertions, 2 deletions
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 <memory>
#include <vector>
#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<Object> GetIncomingHandle(Handle id_from_cmdbuf) const;
- Handle AddOutgoingHandle(SharedPtr<Object> 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<Object> 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> 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<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
SharedPtr<ServerSession> session;
+ std::vector<SharedPtr<Object>> request_handles;
};
} // namespace Kernel