summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Subv2016-12-05 12:05:00 -0500
committerGravatar Subv2016-12-05 12:05:00 -0500
commit00f0c775702af4145a4a81ec5d357c3586a5c6c3 (patch)
tree58f7dbfddba5de2c2f4a7fac420ab5ac8a8a3de1
parentKernel: Remove the Redirection handle type. (diff)
downloadyuzu-00f0c775702af4145a4a81ec5d357c3586a5c6c3.tar.gz
yuzu-00f0c775702af4145a4a81ec5d357c3586a5c6c3.tar.xz
yuzu-00f0c775702af4145a4a81ec5d357c3586a5c6c3.zip
Split SessionRequestHandler::HandleSyncRequest into HandleSyncRequest, TranslateRequest and HandleSyncRequestImpl.
HandleSyncRequest now takes care of calling the command buffer translate function before actually invoking the command handler for HLE services.
-rw-r--r--src/core/hle/kernel/client_port.cpp1
-rw-r--r--src/core/hle/kernel/server_port.h1
-rw-r--r--src/core/hle/service/fs/archive.cpp14
-rw-r--r--src/core/hle/service/fs/archive.h10
-rw-r--r--src/core/hle/service/service.cpp27
-rw-r--r--src/core/hle/service/service.h28
6 files changed, 59 insertions, 22 deletions
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp
index f25cb48dd..b6a4cab26 100644
--- a/src/core/hle/kernel/client_port.cpp
+++ b/src/core/hle/kernel/client_port.cpp
@@ -4,6 +4,7 @@
4 4
5#include "common/assert.h" 5#include "common/assert.h"
6#include "core/hle/kernel/client_port.h" 6#include "core/hle/kernel/client_port.h"
7#include "core/hle/kernel/client_session.h"
7#include "core/hle/kernel/kernel.h" 8#include "core/hle/kernel/kernel.h"
8#include "core/hle/kernel/server_port.h" 9#include "core/hle/kernel/server_port.h"
9#include "core/hle/kernel/server_session.h" 10#include "core/hle/kernel/server_session.h"
diff --git a/src/core/hle/kernel/server_port.h b/src/core/hle/kernel/server_port.h
index dee0b1a9a..b0f8df62c 100644
--- a/src/core/hle/kernel/server_port.h
+++ b/src/core/hle/kernel/server_port.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <memory>
7#include <string> 8#include <string>
8#include <tuple> 9#include <tuple>
9#include "common/common_types.h" 10#include "common/common_types.h"
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index a9f457726..c10d6a3a9 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -93,7 +93,7 @@ File::File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path&
93 93
94File::~File() {} 94File::~File() {}
95 95
96ResultCode File::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) { 96void File::HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
97 u32* cmd_buff = Kernel::GetCommandBuffer(); 97 u32* cmd_buff = Kernel::GetCommandBuffer();
98 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]); 98 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
99 switch (cmd) { 99 switch (cmd) {
@@ -116,7 +116,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> serv
116 ResultVal<size_t> read = backend->Read(offset, data.size(), data.data()); 116 ResultVal<size_t> read = backend->Read(offset, data.size(), data.data());
117 if (read.Failed()) { 117 if (read.Failed()) {
118 cmd_buff[1] = read.Code().raw; 118 cmd_buff[1] = read.Code().raw;
119 return read.Code(); 119 return;
120 } 120 }
121 Memory::WriteBlock(address, data.data(), *read); 121 Memory::WriteBlock(address, data.data(), *read);
122 cmd_buff[2] = static_cast<u32>(*read); 122 cmd_buff[2] = static_cast<u32>(*read);
@@ -137,7 +137,7 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> serv
137 ResultVal<size_t> written = backend->Write(offset, data.size(), flush != 0, data.data()); 137 ResultVal<size_t> written = backend->Write(offset, data.size(), flush != 0, data.data());
138 if (written.Failed()) { 138 if (written.Failed()) {
139 cmd_buff[1] = written.Code().raw; 139 cmd_buff[1] = written.Code().raw;
140 return written.Code(); 140 return;
141 } 141 }
142 cmd_buff[2] = static_cast<u32>(*written); 142 cmd_buff[2] = static_cast<u32>(*written);
143 break; 143 break;
@@ -195,10 +195,9 @@ ResultCode File::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> serv
195 LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); 195 LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
196 ResultCode error = UnimplementedFunction(ErrorModule::FS); 196 ResultCode error = UnimplementedFunction(ErrorModule::FS);
197 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. 197 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
198 return error; 198 return;
199 } 199 }
200 cmd_buff[1] = RESULT_SUCCESS.raw; // No error 200 cmd_buff[1] = RESULT_SUCCESS.raw; // No error
201 return RESULT_SUCCESS;
202} 201}
203 202
204Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, 203Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
@@ -207,7 +206,7 @@ Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
207 206
208Directory::~Directory() {} 207Directory::~Directory() {}
209 208
210ResultCode Directory::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) { 209void Directory::HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
211 u32* cmd_buff = Kernel::GetCommandBuffer(); 210 u32* cmd_buff = Kernel::GetCommandBuffer();
212 DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]); 211 DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
213 switch (cmd) { 212 switch (cmd) {
@@ -237,10 +236,9 @@ ResultCode Directory::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession>
237 LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd); 236 LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
238 ResultCode error = UnimplementedFunction(ErrorModule::FS); 237 ResultCode error = UnimplementedFunction(ErrorModule::FS);
239 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. 238 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
240 return RESULT_SUCCESS; 239 return;
241 } 240 }
242 cmd_buff[1] = RESULT_SUCCESS.raw; // No error 241 cmd_buff[1] = RESULT_SUCCESS.raw; // No error
243 return RESULT_SUCCESS;
244} 242}
245 243
246//////////////////////////////////////////////////////////////////////////////////////////////////// 244////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index 29527ef48..cb014b5d7 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -50,11 +50,12 @@ public:
50 return "Path: " + path.DebugStr(); 50 return "Path: " + path.DebugStr();
51 } 51 }
52 52
53 ResultCode HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
54
55 FileSys::Path path; ///< Path of the file 53 FileSys::Path path; ///< Path of the file
56 u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means 54 u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means
57 std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface 55 std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface
56
57protected:
58 void HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
58}; 59};
59 60
60class Directory : public SessionRequestHandler { 61class Directory : public SessionRequestHandler {
@@ -66,10 +67,11 @@ public:
66 return "Directory: " + path.DebugStr(); 67 return "Directory: " + path.DebugStr();
67 } 68 }
68 69
69 ResultCode HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
70
71 FileSys::Path path; ///< Path of the directory 70 FileSys::Path path; ///< Path of the directory
72 std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface 71 std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface
72
73protected:
74 void HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
73}; 75};
74 76
75/** 77/**
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 3462af8ce..3d5e3058c 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -64,7 +64,27 @@ static std::string MakeFunctionString(const char* name, const char* port_name,
64 return function_string; 64 return function_string;
65} 65}
66 66
67ResultCode Interface::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) { 67ResultCode SessionRequestHandler::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
68 // Attempt to translate the incoming request's command buffer.
69 ResultCode result = TranslateRequest(server_session);
70
71 if (result.IsError())
72 return result;
73
74 // Actually handle the request
75 HandleSyncRequestImpl(server_session);
76
77 // TODO(Subv): Translate the response command buffer.
78
79 return RESULT_SUCCESS;
80}
81
82ResultCode SessionRequestHandler::TranslateRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
83 // TODO(Subv): Implement this function once multiple concurrent processes are supported.
84 return RESULT_SUCCESS;
85}
86
87void Interface::HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
68 // TODO(Subv): Make use of the server_session in the HLE service handlers to distinguish which session triggered each command. 88 // TODO(Subv): Make use of the server_session in the HLE service handlers to distinguish which session triggered each command.
69 89
70 u32* cmd_buff = Kernel::GetCommandBuffer(); 90 u32* cmd_buff = Kernel::GetCommandBuffer();
@@ -80,14 +100,12 @@ ResultCode Interface::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession>
80 100
81 // TODO(bunnei): Hack - ignore error 101 // TODO(bunnei): Hack - ignore error
82 cmd_buff[1] = 0; 102 cmd_buff[1] = 0;
83 return RESULT_SUCCESS; 103 return;
84 } 104 }
85 LOG_TRACE(Service, "%s", 105 LOG_TRACE(Service, "%s",
86 MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str()); 106 MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str());
87 107
88 itr->second.func(this); 108 itr->second.func(this);
89
90 return RESULT_SUCCESS; // TODO: Implement return from actual function, it should fail if the parameter translation fails
91} 109}
92 110
93void Interface::Register(const FunctionInfo* functions, size_t n) { 111void Interface::Register(const FunctionInfo* functions, size_t n) {
@@ -179,4 +197,5 @@ void Shutdown() {
179 g_kernel_named_ports.clear(); 197 g_kernel_named_ports.clear();
180 LOG_DEBUG(Service, "shutdown OK"); 198 LOG_DEBUG(Service, "shutdown OK");
181} 199}
200
182} 201}
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index e85882713..7b7db8499 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -187,11 +187,27 @@ public:
187 * Dispatches and handles a sync request from the emulated application. 187 * Dispatches and handles a sync request from the emulated application.
188 * @param server_session The ServerSession that was triggered for this sync request, 188 * @param server_session The ServerSession that was triggered for this sync request,
189 * it should be used to differentiate which client (As in ClientSession) we're answering to. 189 * it should be used to differentiate which client (As in ClientSession) we're answering to.
190 * TODO(Subv): Make a HandleSyncRequestParent function that is called from the outside and does { ReturnIfError(Translate()); HandleSyncRequest(); } 190 * @returns ResultCode the result code of the translate operation.
191 * The Translate() function would copy the command buffer from the ServerSession thread's TLS into a temporary buffer, and pass it to HandleSyncRequest.
192 * TODO(Subv): HandleSyncRequest's return type should be void.
193 */ 191 */
194 virtual ResultCode HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) = 0; 192 ResultCode HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session);
193
194protected:
195 /**
196 * Handles a sync request from the emulated application and writes the response to the command buffer.
197 * TODO(Subv): Use a wrapper structure to hold all the information relevant to
198 * this request (ServerSession, Originator thread, Translated command buffer, etc).
199 */
200 virtual void HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) = 0;
201
202private:
203 /**
204 * Performs command buffer translation for this request.
205 * The command buffer from the ServerSession thread's TLS is copied into a
206 * buffer and all descriptors in the buffer are processed.
207 * TODO(Subv): Implement this function, currently we do not support multiple processes running at once,
208 * but once that is implemented we'll need to properly translate all descriptors in the command buffer.
209 */
210 ResultCode TranslateRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session);
195}; 211};
196 212
197/** 213/**
@@ -231,9 +247,9 @@ public:
231 return "[UNKNOWN SERVICE PORT]"; 247 return "[UNKNOWN SERVICE PORT]";
232 } 248 }
233 249
234 ResultCode HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
235
236protected: 250protected:
251 void HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server_session) override;
252
237 /** 253 /**
238 * Registers the functions in the service 254 * Registers the functions in the service
239 */ 255 */