Merge pull request #2981 from Subv/replyreceive
Kernel/SVC: Implement LLE command buffer translation in ReplyAndReceive
This commit is contained in:
commit
d55a13c35d
10 changed files with 173 additions and 33 deletions
|
@ -7,7 +7,6 @@
|
|||
#include "core/hle/result.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
namespace ErrCodes {
|
||||
enum {
|
||||
OutOfHandles = 19,
|
||||
|
@ -18,6 +17,7 @@ enum {
|
|||
WrongPermission = 46,
|
||||
InvalidBufferDescriptor = 48,
|
||||
MaxConnectionsReached = 52,
|
||||
CommandTooLarge = 54,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
93
src/core/hle/kernel/ipc.cpp
Normal file
93
src/core/hle/kernel/ipc.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Copyright 2017 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/hle/ipc.h"
|
||||
#include "core/hle/kernel/handle_table.h"
|
||||
#include "core/hle/kernel/ipc.h"
|
||||
#include "core/hle/kernel/kernel.h"
|
||||
#include "core/hle/kernel/memory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/thread.h"
|
||||
#include "core/memory.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread> dst_thread,
|
||||
VAddr src_address, VAddr dst_address) {
|
||||
|
||||
auto& src_process = src_thread->owner_process;
|
||||
|
||||
IPC::Header header;
|
||||
// TODO(Subv): Replace by Memory::Read32 when possible.
|
||||
Memory::ReadBlock(*src_process, src_address, &header.raw, sizeof(header.raw));
|
||||
|
||||
size_t untranslated_size = 1u + header.normal_params_size;
|
||||
size_t command_size = untranslated_size + header.translate_params_size;
|
||||
|
||||
// Note: The real kernel does not check that the command length fits into the IPC buffer area.
|
||||
ASSERT(command_size <= IPC::COMMAND_BUFFER_LENGTH);
|
||||
|
||||
std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
|
||||
Memory::ReadBlock(*src_process, src_address, cmd_buf.data(), command_size * sizeof(u32));
|
||||
|
||||
size_t i = untranslated_size;
|
||||
while (i < command_size) {
|
||||
u32 descriptor = cmd_buf[i];
|
||||
i += 1;
|
||||
|
||||
switch (IPC::GetDescriptorType(descriptor)) {
|
||||
case IPC::DescriptorType::CopyHandle:
|
||||
case IPC::DescriptorType::MoveHandle: {
|
||||
u32 num_handles = IPC::HandleNumberFromDesc(descriptor);
|
||||
// Note: The real kernel does not check that the number of handles fits into the command
|
||||
// buffer before writing them, only after finishing.
|
||||
if (i + num_handles > command_size) {
|
||||
return ResultCode(ErrCodes::CommandTooLarge, ErrorModule::OS,
|
||||
ErrorSummary::InvalidState, ErrorLevel::Status);
|
||||
}
|
||||
|
||||
for (u32 j = 0; j < num_handles; ++j) {
|
||||
Handle handle = cmd_buf[i];
|
||||
SharedPtr<Object> object = nullptr;
|
||||
// Perform pseudo-handle detection here because by the time this function is called,
|
||||
// the current thread and process are no longer the ones which created this IPC
|
||||
// request, but the ones that are handling it.
|
||||
if (handle == CurrentThread) {
|
||||
object = src_thread;
|
||||
} else if (handle == CurrentProcess) {
|
||||
object = src_process;
|
||||
} else if (handle != 0) {
|
||||
object = g_handle_table.GetGeneric(handle);
|
||||
if (descriptor == IPC::DescriptorType::MoveHandle) {
|
||||
g_handle_table.Close(handle);
|
||||
}
|
||||
}
|
||||
|
||||
if (object == nullptr) {
|
||||
// Note: The real kernel sets invalid translated handles to 0 in the target
|
||||
// command buffer.
|
||||
cmd_buf[i++] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto result = g_handle_table.Create(std::move(object));
|
||||
cmd_buf[i++] = result.ValueOr(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPC::DescriptorType::CallingPid: {
|
||||
cmd_buf[i++] = src_process->process_id;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNIMPLEMENTED_MSG("Unsupported handle translation: 0x%08X", descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
Memory::WriteBlock(*dst_thread->owner_process, dst_address, cmd_buf.data(),
|
||||
command_size * sizeof(u32));
|
||||
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
} // namespace Kernel
|
14
src/core/hle/kernel/ipc.h
Normal file
14
src/core/hle/kernel/ipc.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2017 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/kernel/thread.h"
|
||||
|
||||
namespace Kernel {
|
||||
/// Performs IPC command buffer translation from one process to another.
|
||||
ResultCode TranslateCommandBuffer(SharedPtr<Thread> src_thread, SharedPtr<Thread> dst_thread,
|
||||
VAddr src_address, VAddr dst_address);
|
||||
} // namespace Kernel
|
|
@ -61,13 +61,11 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
|
|||
|
||||
// If this ServerSession has an associated HLE handler, forward the request to it.
|
||||
if (hle_handler != nullptr) {
|
||||
// Attempt to translate the incoming request's command buffer.
|
||||
ResultCode result = TranslateHLERequest(this);
|
||||
if (result.IsError())
|
||||
return result;
|
||||
hle_handler->HandleSyncRequest(SharedPtr<ServerSession>(this));
|
||||
// TODO(Subv): Translate the response command buffer.
|
||||
} else {
|
||||
// Put the thread to sleep until the server replies, it will be awoken in
|
||||
// svcReplyAndReceive.
|
||||
thread->status = THREADSTATUS_WAIT_IPC;
|
||||
// Add the thread to the list of threads that have issued a sync request with this
|
||||
// server.
|
||||
pending_requesting_threads.push_back(std::move(thread));
|
||||
|
@ -96,8 +94,4 @@ ServerSession::SessionPair ServerSession::CreateSessionPair(const std::string& n
|
|||
return std::make_tuple(std::move(server_session), std::move(client_session));
|
||||
}
|
||||
|
||||
ResultCode TranslateHLERequest(ServerSession* server_session) {
|
||||
// TODO(Subv): Implement this function once multiple concurrent processes are supported.
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -36,6 +36,9 @@ class Thread;
|
|||
*/
|
||||
class ServerSession final : public WaitObject {
|
||||
public:
|
||||
std::string GetName() const override {
|
||||
return name;
|
||||
}
|
||||
std::string GetTypeName() const override {
|
||||
return "ServerSession";
|
||||
}
|
||||
|
@ -104,13 +107,4 @@ private:
|
|||
static ResultVal<SharedPtr<ServerSession>> Create(std::string name = "Unknown");
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs command buffer translation for an HLE IPC request.
|
||||
* The command buffer from the ServerSession thread's TLS is copied into a
|
||||
* buffer and all descriptors in the buffer are processed.
|
||||
* TODO(Subv): Implement this function, currently we do not support multiple processes running at
|
||||
* once, but once that is implemented we'll need to properly translate all descriptors
|
||||
* in the command buffer.
|
||||
*/
|
||||
ResultCode TranslateHLERequest(ServerSession* server_session);
|
||||
}
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -278,6 +278,7 @@ void Thread::ResumeFromWait() {
|
|||
case THREADSTATUS_WAIT_SYNCH_ANY:
|
||||
case THREADSTATUS_WAIT_ARB:
|
||||
case THREADSTATUS_WAIT_SLEEP:
|
||||
case THREADSTATUS_WAIT_IPC:
|
||||
break;
|
||||
|
||||
case THREADSTATUS_READY:
|
||||
|
|
|
@ -35,6 +35,7 @@ enum ThreadStatus {
|
|||
THREADSTATUS_READY, ///< Ready to run
|
||||
THREADSTATUS_WAIT_ARB, ///< Waiting on an address arbiter
|
||||
THREADSTATUS_WAIT_SLEEP, ///< Waiting due to a SleepThread SVC
|
||||
THREADSTATUS_WAIT_IPC, ///< Waiting for the reply from an IPC request
|
||||
THREADSTATUS_WAIT_SYNCH_ANY, ///< Waiting due to WaitSynch1 or WaitSynchN with wait_all = false
|
||||
THREADSTATUS_WAIT_SYNCH_ALL, ///< Waiting due to WaitSynchronizationN with wait_all = true
|
||||
THREADSTATUS_DORMANT, ///< Created but not yet made ready
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue