|
|
|
@ -8,6 +8,7 @@
|
|
|
|
|
#include "core/hle/kernel/handle_table.h"
|
|
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
|
|
|
|
#include "core/hle/kernel/kernel.h"
|
|
|
|
|
#include "core/hle/kernel/process.h"
|
|
|
|
|
#include "core/hle/kernel/server_session.h"
|
|
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
@ -24,12 +25,97 @@ void SessionRequestHandler::ClientDisconnected(SharedPtr<ServerSession> server_s
|
|
|
|
|
|
|
|
|
|
HLERequestContext::~HLERequestContext() = default;
|
|
|
|
|
|
|
|
|
|
SharedPtr<Object> HLERequestContext::GetIncomingHandle(Handle id_from_cmdbuf) const {
|
|
|
|
|
return Kernel::g_handle_table.GetGeneric(id_from_cmdbuf);
|
|
|
|
|
SharedPtr<Object> HLERequestContext::GetIncomingHandle(u32 id_from_cmdbuf) const {
|
|
|
|
|
ASSERT(id_from_cmdbuf < request_handles.size());
|
|
|
|
|
return request_handles[id_from_cmdbuf];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Handle HLERequestContext::AddOutgoingHandle(SharedPtr<Object> object) {
|
|
|
|
|
return Kernel::g_handle_table.Create(object).Unwrap();
|
|
|
|
|
u32 HLERequestContext::AddOutgoingHandle(SharedPtr<Object> object) {
|
|
|
|
|
request_handles.push_back(std::move(object));
|
|
|
|
|
return request_handles.size() - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const u32_le* src_cmdbuf,
|
|
|
|
|
Process& src_process,
|
|
|
|
|
HandleTable& src_table) {
|
|
|
|
|
IPC::Header header{src_cmdbuf[0]};
|
|
|
|
|
|
|
|
|
|
size_t untranslated_size = 1u + header.normal_params_size;
|
|
|
|
|
size_t command_size = untranslated_size + header.translate_params_size;
|
|
|
|
|
ASSERT(command_size <= IPC::COMMAND_BUFFER_LENGTH); // TODO(yuriks): Return error
|
|
|
|
|
|
|
|
|
|
std::copy_n(src_cmdbuf, untranslated_size, cmd_buf.begin());
|
|
|
|
|
|
|
|
|
|
size_t i = untranslated_size;
|
|
|
|
|
while (i < command_size) {
|
|
|
|
|
u32 descriptor = cmd_buf[i] = src_cmdbuf[i];
|
|
|
|
|
i += 1;
|
|
|
|
|
|
|
|
|
|
switch (IPC::GetDescriptorType(descriptor)) {
|
|
|
|
|
case IPC::DescriptorType::CopyHandle:
|
|
|
|
|
case IPC::DescriptorType::MoveHandle: {
|
|
|
|
|
u32 num_handles = IPC::HandleNumberFromDesc(descriptor);
|
|
|
|
|
ASSERT(i + num_handles <= command_size); // TODO(yuriks): Return error
|
|
|
|
|
for (u32 j = 0; j < num_handles; ++j) {
|
|
|
|
|
Handle handle = src_cmdbuf[i];
|
|
|
|
|
SharedPtr<Object> object = src_table.GetGeneric(handle);
|
|
|
|
|
ASSERT(object != nullptr); // TODO(yuriks): Return error
|
|
|
|
|
if (descriptor == IPC::DescriptorType::MoveHandle) {
|
|
|
|
|
src_table.Close(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd_buf[i++] = AddOutgoingHandle(std::move(object));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case IPC::DescriptorType::CallingPid: {
|
|
|
|
|
cmd_buf[i++] = src_process.process_id;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
UNIMPLEMENTED_MSG("Unsupported handle translation: 0x%08X", descriptor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(u32_le* dst_cmdbuf, Process& dst_process,
|
|
|
|
|
HandleTable& dst_table) const {
|
|
|
|
|
IPC::Header header{cmd_buf[0]};
|
|
|
|
|
|
|
|
|
|
size_t untranslated_size = 1u + header.normal_params_size;
|
|
|
|
|
size_t command_size = untranslated_size + header.translate_params_size;
|
|
|
|
|
ASSERT(command_size <= IPC::COMMAND_BUFFER_LENGTH);
|
|
|
|
|
|
|
|
|
|
std::copy_n(cmd_buf.begin(), untranslated_size, dst_cmdbuf);
|
|
|
|
|
|
|
|
|
|
size_t i = untranslated_size;
|
|
|
|
|
while (i < command_size) {
|
|
|
|
|
u32 descriptor = dst_cmdbuf[i] = cmd_buf[i];
|
|
|
|
|
i += 1;
|
|
|
|
|
|
|
|
|
|
switch (IPC::GetDescriptorType(descriptor)) {
|
|
|
|
|
case IPC::DescriptorType::CopyHandle:
|
|
|
|
|
case IPC::DescriptorType::MoveHandle: {
|
|
|
|
|
// HLE services don't use handles, so we treat both CopyHandle and MoveHandle equally
|
|
|
|
|
u32 num_handles = IPC::HandleNumberFromDesc(descriptor);
|
|
|
|
|
ASSERT(i + num_handles <= command_size);
|
|
|
|
|
for (u32 j = 0; j < num_handles; ++j) {
|
|
|
|
|
SharedPtr<Object> object = GetIncomingHandle(cmd_buf[i]);
|
|
|
|
|
|
|
|
|
|
// TODO(yuriks): Figure out the proper error handling for if this fails
|
|
|
|
|
Handle handle = dst_table.Create(object).Unwrap();
|
|
|
|
|
dst_cmdbuf[i++] = handle;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
UNIMPLEMENTED_MSG("Unsupported handle translation: 0x%08X", descriptor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Kernel
|
|
|
|
|