diff options
| author | 2016-06-14 18:03:30 -0500 | |
|---|---|---|
| committer | 2016-11-30 23:02:05 -0500 | |
| commit | 073653e858abf377fd1ebbdb071809c8830ce99d (patch) | |
| tree | a29e1c1e50d53162ed89cd90e8c069525150392f /src/core/hle/kernel/session.h | |
| parent | Merge pull request #2228 from freiro/winver_fix (diff) | |
| download | yuzu-073653e858abf377fd1ebbdb071809c8830ce99d.tar.gz yuzu-073653e858abf377fd1ebbdb071809c8830ce99d.tar.xz yuzu-073653e858abf377fd1ebbdb071809c8830ce99d.zip | |
Kernel/IPC: Use Ports and Sessions as the fundamental building block of Inter Process Communication.
All handles obtained via srv::GetServiceHandle or svcConnectToPort are references to ClientSessions.
Service modules will wait on the counterpart of those ClientSessions (Called ServerSessions) using svcReplyAndReceive or svcWaitSynchronization[1|N], and will be awoken when a SyncRequest is performed.
HLE Interfaces are now ClientPorts which override the HandleSyncRequest virtual member function to perform command handling immediately.
Diffstat (limited to 'src/core/hle/kernel/session.h')
| -rw-r--r-- | src/core/hle/kernel/session.h | 218 |
1 files changed, 0 insertions, 218 deletions
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h deleted file mode 100644 index ec025f732..000000000 --- a/src/core/hle/kernel/session.h +++ /dev/null | |||
| @@ -1,218 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | #include "common/assert.h" | ||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "core/hle/kernel/kernel.h" | ||
| 11 | #include "core/hle/kernel/thread.h" | ||
| 12 | #include "core/hle/result.h" | ||
| 13 | #include "core/memory.h" | ||
| 14 | |||
| 15 | namespace IPC { | ||
| 16 | |||
| 17 | enum DescriptorType : u32 { | ||
| 18 | // Buffer related desciptors types (mask : 0x0F) | ||
| 19 | StaticBuffer = 0x02, | ||
| 20 | PXIBuffer = 0x04, | ||
| 21 | MappedBuffer = 0x08, | ||
| 22 | // Handle related descriptors types (mask : 0x30, but need to check for buffer related | ||
| 23 | // descriptors first ) | ||
| 24 | CopyHandle = 0x00, | ||
| 25 | MoveHandle = 0x10, | ||
| 26 | CallingPid = 0x20, | ||
| 27 | }; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @brief Creates a command header to be used for IPC | ||
| 31 | * @param command_id ID of the command to create a header for. | ||
| 32 | * @param normal_params Size of the normal parameters in words. Up to 63. | ||
| 33 | * @param translate_params_size Size of the translate parameters in words. Up to 63. | ||
| 34 | * @return The created IPC header. | ||
| 35 | * | ||
| 36 | * Normal parameters are sent directly to the process while the translate parameters might go | ||
| 37 | * through modifications and checks by the kernel. | ||
| 38 | * The translate parameters are described by headers generated with the IPC::*Desc functions. | ||
| 39 | * | ||
| 40 | * @note While #normal_params is equivalent to the number of normal parameters, | ||
| 41 | * #translate_params_size includes the size occupied by the translate parameters headers. | ||
| 42 | */ | ||
| 43 | constexpr u32 MakeHeader(u16 command_id, unsigned int normal_params, | ||
| 44 | unsigned int translate_params_size) { | ||
| 45 | return (u32(command_id) << 16) | ((u32(normal_params) & 0x3F) << 6) | | ||
| 46 | (u32(translate_params_size) & 0x3F); | ||
| 47 | } | ||
| 48 | |||
| 49 | union Header { | ||
| 50 | u32 raw; | ||
| 51 | BitField<0, 6, u32> translate_params_size; | ||
| 52 | BitField<6, 6, u32> normal_params; | ||
| 53 | BitField<16, 16, u32> command_id; | ||
| 54 | }; | ||
| 55 | |||
| 56 | inline Header ParseHeader(u32 header) { | ||
| 57 | return {header}; | ||
| 58 | } | ||
| 59 | |||
| 60 | constexpr u32 MoveHandleDesc(u32 num_handles = 1) { | ||
| 61 | return MoveHandle | ((num_handles - 1) << 26); | ||
| 62 | } | ||
| 63 | |||
| 64 | constexpr u32 CopyHandleDesc(u32 num_handles = 1) { | ||
| 65 | return CopyHandle | ((num_handles - 1) << 26); | ||
| 66 | } | ||
| 67 | |||
| 68 | constexpr u32 CallingPidDesc() { | ||
| 69 | return CallingPid; | ||
| 70 | } | ||
| 71 | |||
| 72 | constexpr bool isHandleDescriptor(u32 descriptor) { | ||
| 73 | return (descriptor & 0xF) == 0x0; | ||
| 74 | } | ||
| 75 | |||
| 76 | constexpr u32 HandleNumberFromDesc(u32 handle_descriptor) { | ||
| 77 | return (handle_descriptor >> 26) + 1; | ||
| 78 | } | ||
| 79 | |||
| 80 | constexpr u32 StaticBufferDesc(u32 size, u8 buffer_id) { | ||
| 81 | return StaticBuffer | (size << 14) | ((buffer_id & 0xF) << 10); | ||
| 82 | } | ||
| 83 | |||
| 84 | union StaticBufferDescInfo { | ||
| 85 | u32 raw; | ||
| 86 | BitField<10, 4, u32> buffer_id; | ||
| 87 | BitField<14, 18, u32> size; | ||
| 88 | }; | ||
| 89 | |||
| 90 | inline StaticBufferDescInfo ParseStaticBufferDesc(const u32 desc) { | ||
| 91 | return {desc}; | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * @brief Creates a header describing a buffer to be sent over PXI. | ||
| 96 | * @param size Size of the buffer. Max 0x00FFFFFF. | ||
| 97 | * @param buffer_id The Id of the buffer. Max 0xF. | ||
| 98 | * @param is_read_only true if the buffer is read-only. If false, the buffer is considered to have | ||
| 99 | * read-write access. | ||
| 100 | * @return The created PXI buffer header. | ||
| 101 | * | ||
| 102 | * The next value is a phys-address of a table located in the BASE memregion. | ||
| 103 | */ | ||
| 104 | inline u32 PXIBufferDesc(u32 size, unsigned buffer_id, bool is_read_only) { | ||
| 105 | u32 type = PXIBuffer; | ||
| 106 | if (is_read_only) | ||
| 107 | type |= 0x2; | ||
| 108 | return type | (size << 8) | ((buffer_id & 0xF) << 4); | ||
| 109 | } | ||
| 110 | |||
| 111 | enum MappedBufferPermissions { | ||
| 112 | R = 1, | ||
| 113 | W = 2, | ||
| 114 | RW = R | W, | ||
| 115 | }; | ||
| 116 | |||
| 117 | constexpr u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { | ||
| 118 | return MappedBuffer | (size << 4) | (u32(perms) << 1); | ||
| 119 | } | ||
| 120 | |||
| 121 | union MappedBufferDescInfo { | ||
| 122 | u32 raw; | ||
| 123 | BitField<4, 28, u32> size; | ||
| 124 | BitField<1, 2, MappedBufferPermissions> perms; | ||
| 125 | }; | ||
| 126 | |||
| 127 | inline MappedBufferDescInfo ParseMappedBufferDesc(const u32 desc) { | ||
| 128 | return {desc}; | ||
| 129 | } | ||
| 130 | |||
| 131 | inline DescriptorType GetDescriptorType(u32 descriptor) { | ||
| 132 | // Note: Those checks must be done in this order | ||
| 133 | if (isHandleDescriptor(descriptor)) | ||
| 134 | return (DescriptorType)(descriptor & 0x30); | ||
| 135 | |||
| 136 | // handle the fact that the following descriptors can have rights | ||
| 137 | if (descriptor & MappedBuffer) | ||
| 138 | return MappedBuffer; | ||
| 139 | |||
| 140 | if (descriptor & PXIBuffer) | ||
| 141 | return PXIBuffer; | ||
| 142 | |||
| 143 | return StaticBuffer; | ||
| 144 | } | ||
| 145 | |||
| 146 | } // namespace IPC | ||
| 147 | |||
| 148 | namespace Kernel { | ||
| 149 | |||
| 150 | static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header | ||
| 151 | |||
| 152 | /** | ||
| 153 | * Returns a pointer to the command buffer in the current thread's TLS | ||
| 154 | * TODO(Subv): This is not entirely correct, the command buffer should be copied from | ||
| 155 | * the thread's TLS to an intermediate buffer in kernel memory, and then copied again to | ||
| 156 | * the service handler process' memory. | ||
| 157 | * @param offset Optional offset into command buffer | ||
| 158 | * @return Pointer to command buffer | ||
| 159 | */ | ||
| 160 | inline u32* GetCommandBuffer(const int offset = 0) { | ||
| 161 | return (u32*)Memory::GetPointer(GetCurrentThread()->GetTLSAddress() + kCommandHeaderOffset + | ||
| 162 | offset); | ||
| 163 | } | ||
| 164 | |||
| 165 | /** | ||
| 166 | * Kernel object representing the client endpoint of an IPC session. Sessions are the basic CTR-OS | ||
| 167 | * primitive for communication between different processes, and are used to implement service calls | ||
| 168 | * to the various system services. | ||
| 169 | * | ||
| 170 | * To make a service call, the client must write the command header and parameters to the buffer | ||
| 171 | * located at offset 0x80 of the TLS (Thread-Local Storage) area, then execute a SendSyncRequest | ||
| 172 | * SVC call with its Session handle. The kernel will read the command header, using it to marshall | ||
| 173 | * the parameters to the process at the server endpoint of the session. After the server replies to | ||
| 174 | * the request, the response is marshalled back to the caller's TLS buffer and control is | ||
| 175 | * transferred back to it. | ||
| 176 | * | ||
| 177 | * In Citra, only the client endpoint is currently implemented and only HLE calls, where the IPC | ||
| 178 | * request is answered by C++ code in the emulator, are supported. When SendSyncRequest is called | ||
| 179 | * with the session handle, this class's SyncRequest method is called, which should read the TLS | ||
| 180 | * buffer and emulate the call accordingly. Since the code can directly read the emulated memory, | ||
| 181 | * no parameter marshalling is done. | ||
| 182 | * | ||
| 183 | * In the long term, this should be turned into the full-fledged IPC mechanism implemented by | ||
| 184 | * CTR-OS so that IPC calls can be optionally handled by the real implementations of processes, as | ||
| 185 | * opposed to HLE simulations. | ||
| 186 | */ | ||
| 187 | class Session : public WaitObject { | ||
| 188 | public: | ||
| 189 | Session(); | ||
| 190 | ~Session() override; | ||
| 191 | |||
| 192 | std::string GetTypeName() const override { | ||
| 193 | return "Session"; | ||
| 194 | } | ||
| 195 | |||
| 196 | static const HandleType HANDLE_TYPE = HandleType::Session; | ||
| 197 | HandleType GetHandleType() const override { | ||
| 198 | return HANDLE_TYPE; | ||
| 199 | } | ||
| 200 | |||
| 201 | /** | ||
| 202 | * Handles a synchronous call to this session using HLE emulation. Emulated <-> emulated calls | ||
| 203 | * aren't supported yet. | ||
| 204 | */ | ||
| 205 | virtual ResultVal<bool> SyncRequest() = 0; | ||
| 206 | |||
| 207 | // TODO(bunnei): These functions exist to satisfy a hardware test with a Session object | ||
| 208 | // passed into WaitSynchronization. Figure out the meaning of them. | ||
| 209 | |||
| 210 | bool ShouldWait() override { | ||
| 211 | return true; | ||
| 212 | } | ||
| 213 | |||
| 214 | void Acquire() override { | ||
| 215 | ASSERT_MSG(!ShouldWait(), "object unavailable!"); | ||
| 216 | } | ||
| 217 | }; | ||
| 218 | } | ||