2018-01-13 21:22:39 +00:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2017-06-05 04:52:19 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-31 12:06:09 +00:00
|
|
|
#include <algorithm>
|
2018-08-02 02:40:00 +00:00
|
|
|
#include <array>
|
|
|
|
#include <sstream>
|
2018-07-18 23:02:47 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2017-06-05 04:52:19 +00:00
|
|
|
#include <boost/range/algorithm_ext/erase.hpp>
|
2018-08-02 02:40:00 +00:00
|
|
|
|
2017-06-05 04:52:19 +00:00
|
|
|
#include "common/assert.h"
|
2017-10-15 05:24:22 +00:00
|
|
|
#include "common/common_funcs.h"
|
2017-06-05 04:52:19 +00:00
|
|
|
#include "common/common_types.h"
|
2018-08-02 02:40:00 +00:00
|
|
|
#include "common/logging/log.h"
|
2017-10-15 02:18:42 +00:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2017-06-05 04:52:19 +00:00
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
2021-04-24 09:40:31 +00:00
|
|
|
#include "core/hle/kernel/k_handle_table.h"
|
2021-04-24 05:04:28 +00:00
|
|
|
#include "core/hle/kernel/k_process.h"
|
2021-01-30 06:48:06 +00:00
|
|
|
#include "core/hle/kernel/k_readable_event.h"
|
2020-12-03 02:08:35 +00:00
|
|
|
#include "core/hle/kernel/k_scheduler.h"
|
2020-12-04 05:56:02 +00:00
|
|
|
#include "core/hle/kernel/k_scoped_scheduler_lock_and_sleep.h"
|
2021-04-14 00:48:37 +00:00
|
|
|
#include "core/hle/kernel/k_server_session.h"
|
2020-12-31 07:01:08 +00:00
|
|
|
#include "core/hle/kernel/k_thread.h"
|
2021-01-30 07:51:40 +00:00
|
|
|
#include "core/hle/kernel/k_writable_event.h"
|
2018-08-31 16:21:34 +00:00
|
|
|
#include "core/hle/kernel/kernel.h"
|
2021-02-12 23:43:01 +00:00
|
|
|
#include "core/hle/kernel/svc_results.h"
|
2020-02-25 23:43:28 +00:00
|
|
|
#include "core/hle/kernel/time_manager.h"
|
2018-02-14 02:41:20 +00:00
|
|
|
#include "core/memory.h"
|
2017-06-05 04:52:19 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2018-12-31 23:09:41 +00:00
|
|
|
SessionRequestHandler::SessionRequestHandler() = default;
|
|
|
|
|
|
|
|
SessionRequestHandler::~SessionRequestHandler() = default;
|
|
|
|
|
2021-04-24 00:00:15 +00:00
|
|
|
void SessionRequestHandler::ClientConnected(KServerSession* session) {
|
|
|
|
session->SetHleHandler(shared_from_this());
|
2017-06-05 04:52:19 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 00:00:15 +00:00
|
|
|
void SessionRequestHandler::ClientDisconnected(KServerSession* session) {
|
|
|
|
session->SetHleHandler(nullptr);
|
2017-06-05 04:52:19 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 01:02:10 +00:00
|
|
|
HLERequestContext::HLERequestContext(KernelCore& kernel_, Core::Memory::Memory& memory_,
|
2021-04-14 00:48:37 +00:00
|
|
|
KServerSession* server_session_, KThread* thread_)
|
|
|
|
: server_session(server_session_), thread(thread_), kernel{kernel_}, memory{memory_} {
|
2017-06-18 23:05:12 +00:00
|
|
|
cmd_buf[0] = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-07 04:20:52 +00:00
|
|
|
HLERequestContext::~HLERequestContext() = default;
|
|
|
|
|
2021-04-24 09:40:31 +00:00
|
|
|
void HLERequestContext::ParseCommandBuffer(const KHandleTable& handle_table, u32_le* src_cmdbuf,
|
2018-10-20 18:34:41 +00:00
|
|
|
bool incoming) {
|
2017-10-15 02:18:42 +00:00
|
|
|
IPC::RequestParser rp(src_cmdbuf);
|
2019-03-07 21:44:28 +00:00
|
|
|
command_header = rp.PopRaw<IPC::CommandHeader>();
|
2017-06-09 12:23:13 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
if (command_header->IsCloseCommand()) {
|
2017-10-15 05:24:22 +00:00
|
|
|
// Close does not populate the rest of the IPC header
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-15 02:18:42 +00:00
|
|
|
// If handle descriptor is present, add size of it
|
|
|
|
if (command_header->enable_handle_descriptor) {
|
2019-03-07 21:44:28 +00:00
|
|
|
handle_descriptor_header = rp.PopRaw<IPC::HandleDescriptorHeader>();
|
2017-10-15 02:18:42 +00:00
|
|
|
if (handle_descriptor_header->send_current_pid) {
|
2021-05-16 04:40:19 +00:00
|
|
|
pid = rp.Pop<u64>();
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
2018-01-07 14:22:20 +00:00
|
|
|
if (incoming) {
|
|
|
|
// Populate the object lists with the data in the IPC request.
|
|
|
|
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) {
|
2021-03-12 15:13:31 +00:00
|
|
|
const u32 copy_handle{rp.Pop<Handle>()};
|
|
|
|
copy_handles.push_back(copy_handle);
|
2021-04-21 05:18:56 +00:00
|
|
|
copy_objects.push_back(handle_table.GetObject(copy_handle).GetPointerUnsafe());
|
2018-01-07 14:22:20 +00:00
|
|
|
}
|
|
|
|
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_move; ++handle) {
|
2021-03-12 15:13:31 +00:00
|
|
|
const u32 move_handle{rp.Pop<Handle>()};
|
|
|
|
move_handles.push_back(move_handle);
|
2021-04-21 05:18:56 +00:00
|
|
|
move_objects.push_back(handle_table.GetObject(move_handle).GetPointerUnsafe());
|
2018-01-07 14:22:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For responses we just ignore the handles, they're empty and will be populated when
|
|
|
|
// translating the response.
|
|
|
|
rp.Skip(handle_descriptor_header->num_handles_to_copy, false);
|
|
|
|
rp.Skip(handle_descriptor_header->num_handles_to_move, false);
|
|
|
|
}
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
2017-06-09 12:23:13 +00:00
|
|
|
|
2021-05-16 04:42:10 +00:00
|
|
|
for (u32 i = 0; i < command_header->num_buf_x_descriptors; ++i) {
|
2017-10-19 01:38:01 +00:00
|
|
|
buffer_x_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorX>());
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
2021-05-16 04:42:10 +00:00
|
|
|
for (u32 i = 0; i < command_header->num_buf_a_descriptors; ++i) {
|
2017-10-19 01:38:01 +00:00
|
|
|
buffer_a_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>());
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
2021-05-16 04:42:10 +00:00
|
|
|
for (u32 i = 0; i < command_header->num_buf_b_descriptors; ++i) {
|
2017-10-19 01:38:01 +00:00
|
|
|
buffer_b_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>());
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
2021-05-16 04:42:10 +00:00
|
|
|
for (u32 i = 0; i < command_header->num_buf_w_descriptors; ++i) {
|
2017-10-19 01:38:01 +00:00
|
|
|
buffer_w_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorABW>());
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
2018-01-18 19:54:34 +00:00
|
|
|
|
2021-05-08 09:50:47 +00:00
|
|
|
const auto buffer_c_offset = rp.GetCurrentOffset() + command_header->data_size;
|
2017-06-09 12:23:13 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
if (!command_header->IsTipc()) {
|
|
|
|
// Padding to align to 16 bytes
|
|
|
|
rp.AlignWithPadding();
|
|
|
|
|
|
|
|
if (Session()->IsDomain() &&
|
|
|
|
((command_header->type == IPC::CommandType::Request ||
|
|
|
|
command_header->type == IPC::CommandType::RequestWithContext) ||
|
|
|
|
!incoming)) {
|
|
|
|
// If this is an incoming message, only CommandType "Request" has a domain header
|
|
|
|
// All outgoing domain messages have the domain header, if only incoming has it
|
|
|
|
if (incoming || domain_message_header) {
|
|
|
|
domain_message_header = rp.PopRaw<IPC::DomainMessageHeader>();
|
|
|
|
} else {
|
|
|
|
if (Session()->IsDomain()) {
|
|
|
|
LOG_WARNING(IPC, "Domain request has no DomainMessageHeader!");
|
|
|
|
}
|
2019-03-07 21:44:28 +00:00
|
|
|
}
|
2018-02-20 16:27:49 +00:00
|
|
|
}
|
2017-10-15 05:24:22 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
data_payload_header = rp.PopRaw<IPC::DataPayloadHeader>();
|
2017-10-15 05:24:22 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
data_payload_offset = rp.GetCurrentOffset();
|
2018-01-17 06:16:55 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
if (domain_message_header &&
|
|
|
|
domain_message_header->command ==
|
|
|
|
IPC::DomainMessageHeader::CommandType::CloseVirtualHandle) {
|
|
|
|
// CloseVirtualHandle command does not have SFC* or any data
|
|
|
|
return;
|
|
|
|
}
|
2018-01-17 06:16:55 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
if (incoming) {
|
|
|
|
ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'I'));
|
|
|
|
} else {
|
|
|
|
ASSERT(data_payload_header->magic == Common::MakeMagic('S', 'F', 'C', 'O'));
|
|
|
|
}
|
2017-10-15 05:24:22 +00:00
|
|
|
}
|
2017-10-15 02:18:42 +00:00
|
|
|
|
2018-01-18 19:54:34 +00:00
|
|
|
rp.SetCurrentOffset(buffer_c_offset);
|
|
|
|
|
|
|
|
// For Inline buffers, the response data is written directly to buffer_c_offset
|
|
|
|
// and in this case we don't have any BufferDescriptorC on the request.
|
|
|
|
if (command_header->buf_c_descriptor_flags >
|
|
|
|
IPC::CommandHeader::BufferDescriptorCFlag::InlineDescriptor) {
|
|
|
|
if (command_header->buf_c_descriptor_flags ==
|
|
|
|
IPC::CommandHeader::BufferDescriptorCFlag::OneDescriptor) {
|
|
|
|
buffer_c_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorC>());
|
|
|
|
} else {
|
2021-05-16 04:42:10 +00:00
|
|
|
u32 num_buf_c_descriptors =
|
|
|
|
static_cast<u32>(command_header->buf_c_descriptor_flags.Value()) - 2;
|
2018-01-18 19:54:34 +00:00
|
|
|
|
|
|
|
// This is used to detect possible underflows, in case something is broken
|
|
|
|
// with the two ifs above and the flags value is == 0 || == 1.
|
|
|
|
ASSERT(num_buf_c_descriptors < 14);
|
|
|
|
|
2021-05-16 04:42:10 +00:00
|
|
|
for (u32 i = 0; i < num_buf_c_descriptors; ++i) {
|
2018-01-18 19:54:34 +00:00
|
|
|
buffer_c_desciptors.push_back(rp.PopRaw<IPC::BufferDescriptorC>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rp.SetCurrentOffset(data_payload_offset);
|
|
|
|
|
2017-10-15 02:18:42 +00:00
|
|
|
command = rp.Pop<u32_le>();
|
2018-01-07 04:19:42 +00:00
|
|
|
rp.Skip(1, false); // The command is actually an u64, but we don't use the high part.
|
2017-10-15 02:18:42 +00:00
|
|
|
}
|
|
|
|
|
2021-04-24 09:40:31 +00:00
|
|
|
ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const KHandleTable& handle_table,
|
2018-10-20 18:34:41 +00:00
|
|
|
u32_le* src_cmdbuf) {
|
|
|
|
ParseCommandBuffer(handle_table, src_cmdbuf, true);
|
2021-05-10 23:16:36 +00:00
|
|
|
|
|
|
|
if (command_header->IsCloseCommand()) {
|
2018-01-07 06:59:31 +00:00
|
|
|
// Close does not populate the rest of the IPC header
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
std::copy_n(src_cmdbuf, IPC::COMMAND_BUFFER_LENGTH, cmd_buf.begin());
|
|
|
|
|
2017-06-09 12:23:13 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-08 16:11:36 +00:00
|
|
|
ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(KThread& requesting_thread) {
|
2021-05-10 23:16:36 +00:00
|
|
|
auto current_offset = handles_offset;
|
2021-05-08 16:11:36 +00:00
|
|
|
auto& owner_process = *requesting_thread.GetOwnerProcess();
|
2018-10-20 18:34:41 +00:00
|
|
|
auto& handle_table = owner_process.GetHandleTable();
|
|
|
|
|
2021-05-11 19:27:43 +00:00
|
|
|
// The data_size already includes the payload header, the padding and the domain header.
|
|
|
|
std::size_t size{};
|
|
|
|
|
|
|
|
if (IsTipc()) {
|
|
|
|
size = cmd_buf.size();
|
|
|
|
} else {
|
|
|
|
size = data_payload_offset + data_size - sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
|
|
|
|
if (Session()->IsDomain()) {
|
|
|
|
size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
for (auto& object : copy_objects) {
|
|
|
|
Handle handle{};
|
|
|
|
if (object) {
|
|
|
|
R_TRY(handle_table.Add(&handle, object));
|
2018-01-07 06:50:55 +00:00
|
|
|
}
|
2021-05-10 23:16:36 +00:00
|
|
|
cmd_buf[current_offset++] = handle;
|
|
|
|
}
|
|
|
|
for (auto& object : move_objects) {
|
|
|
|
Handle handle{};
|
|
|
|
if (object) {
|
|
|
|
R_TRY(handle_table.Add(&handle, object));
|
2018-01-07 06:50:55 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
// Close our reference to the object, as it is being moved to the caller.
|
|
|
|
object->Close();
|
2017-06-09 12:23:13 +00:00
|
|
|
}
|
2021-05-10 23:16:36 +00:00
|
|
|
cmd_buf[current_offset++] = handle;
|
2017-06-09 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
// Write the domain objects to the command buffer, these go after the raw untranslated data.
|
|
|
|
// TODO(Subv): This completely ignores C buffers.
|
2018-01-07 06:50:55 +00:00
|
|
|
|
2021-05-10 23:16:36 +00:00
|
|
|
if (Session()->IsDomain()) {
|
|
|
|
current_offset = domain_offset - static_cast<u32>(domain_objects.size());
|
2019-03-05 23:51:16 +00:00
|
|
|
for (const auto& object : domain_objects) {
|
|
|
|
server_session->AppendDomainRequestHandler(object);
|
2021-05-10 23:16:36 +00:00
|
|
|
cmd_buf[current_offset++] =
|
2019-03-05 23:51:16 +00:00
|
|
|
static_cast<u32_le>(server_session->NumDomainRequestHandlers());
|
2018-01-07 06:50:55 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-19 00:17:06 +00:00
|
|
|
|
|
|
|
// Copy the translated command buffer back into the thread's command buffer area.
|
2021-05-10 23:16:36 +00:00
|
|
|
memory.WriteBlock(owner_process, requesting_thread.GetTLSAddress(), cmd_buf.data(),
|
2021-05-11 19:27:43 +00:00
|
|
|
size * sizeof(u32));
|
2018-03-19 00:17:06 +00:00
|
|
|
|
2017-06-09 12:23:13 +00:00
|
|
|
return RESULT_SUCCESS;
|
2017-06-09 06:55:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 02:02:08 +00:00
|
|
|
std::vector<u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const {
|
2020-06-24 12:50:27 +00:00
|
|
|
std::vector<u8> buffer{};
|
2020-04-17 02:02:08 +00:00
|
|
|
const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
|
2020-02-06 03:09:16 +00:00
|
|
|
BufferDescriptorA()[buffer_index].Size()};
|
2018-02-14 02:41:20 +00:00
|
|
|
|
|
|
|
if (is_buffer_a) {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorA().size() > buffer_index, { return buffer; },
|
|
|
|
"BufferDescriptorA invalid buffer_index {}", buffer_index);
|
2018-05-01 20:28:36 +00:00
|
|
|
buffer.resize(BufferDescriptorA()[buffer_index].Size());
|
2019-11-26 21:29:34 +00:00
|
|
|
memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), buffer.size());
|
2018-02-14 02:41:20 +00:00
|
|
|
} else {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorX().size() > buffer_index, { return buffer; },
|
|
|
|
"BufferDescriptorX invalid buffer_index {}", buffer_index);
|
2018-05-01 20:28:36 +00:00
|
|
|
buffer.resize(BufferDescriptorX()[buffer_index].Size());
|
2019-11-26 21:29:34 +00:00
|
|
|
memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), buffer.size());
|
2018-02-14 02:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2018-09-15 13:21:06 +00:00
|
|
|
std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
|
2020-04-17 02:02:08 +00:00
|
|
|
std::size_t buffer_index) const {
|
2018-06-22 08:18:23 +00:00
|
|
|
if (size == 0) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_WARNING(Core, "skip empty buffer write");
|
2018-06-22 08:18:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-17 02:02:08 +00:00
|
|
|
const bool is_buffer_b{BufferDescriptorB().size() > buffer_index &&
|
2020-02-06 03:09:16 +00:00
|
|
|
BufferDescriptorB()[buffer_index].Size()};
|
2018-09-15 13:21:06 +00:00
|
|
|
const std::size_t buffer_size{GetWriteBufferSize(buffer_index)};
|
2018-03-31 20:05:19 +00:00
|
|
|
if (size > buffer_size) {
|
2018-07-02 16:13:26 +00:00
|
|
|
LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size,
|
2018-07-02 16:20:50 +00:00
|
|
|
buffer_size);
|
2018-03-31 20:05:19 +00:00
|
|
|
size = buffer_size; // TODO(bunnei): This needs to be HW tested
|
|
|
|
}
|
2018-02-14 05:14:17 +00:00
|
|
|
|
2018-02-14 02:41:20 +00:00
|
|
|
if (is_buffer_b) {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorB().size() > buffer_index &&
|
|
|
|
BufferDescriptorB()[buffer_index].Size() >= size,
|
|
|
|
{ return 0; }, "BufferDescriptorB is invalid, index={}, size={}", buffer_index, size);
|
2019-11-26 22:39:57 +00:00
|
|
|
memory.WriteBlock(BufferDescriptorB()[buffer_index].Address(), buffer, size);
|
2018-02-14 02:41:20 +00:00
|
|
|
} else {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorC().size() > buffer_index &&
|
|
|
|
BufferDescriptorC()[buffer_index].Size() >= size,
|
|
|
|
{ return 0; }, "BufferDescriptorC is invalid, index={}, size={}", buffer_index, size);
|
2019-11-26 22:39:57 +00:00
|
|
|
memory.WriteBlock(BufferDescriptorC()[buffer_index].Address(), buffer, size);
|
2018-02-14 02:41:20 +00:00
|
|
|
}
|
2018-02-14 04:53:18 +00:00
|
|
|
|
|
|
|
return size;
|
2018-02-14 02:41:20 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 02:02:08 +00:00
|
|
|
std::size_t HLERequestContext::GetReadBufferSize(std::size_t buffer_index) const {
|
|
|
|
const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
|
2020-02-06 03:09:16 +00:00
|
|
|
BufferDescriptorA()[buffer_index].Size()};
|
|
|
|
if (is_buffer_a) {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorA().size() > buffer_index, { return 0; },
|
|
|
|
"BufferDescriptorA invalid buffer_index {}", buffer_index);
|
2020-02-06 03:09:16 +00:00
|
|
|
return BufferDescriptorA()[buffer_index].Size();
|
|
|
|
} else {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorX().size() > buffer_index, { return 0; },
|
|
|
|
"BufferDescriptorX invalid buffer_index {}", buffer_index);
|
2020-02-06 03:09:16 +00:00
|
|
|
return BufferDescriptorX()[buffer_index].Size();
|
|
|
|
}
|
2018-02-14 05:14:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 02:02:08 +00:00
|
|
|
std::size_t HLERequestContext::GetWriteBufferSize(std::size_t buffer_index) const {
|
|
|
|
const bool is_buffer_b{BufferDescriptorB().size() > buffer_index &&
|
2020-02-06 03:09:16 +00:00
|
|
|
BufferDescriptorB()[buffer_index].Size()};
|
|
|
|
if (is_buffer_b) {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorB().size() > buffer_index, { return 0; },
|
|
|
|
"BufferDescriptorB invalid buffer_index {}", buffer_index);
|
2020-02-06 03:09:16 +00:00
|
|
|
return BufferDescriptorB()[buffer_index].Size();
|
|
|
|
} else {
|
2020-08-11 15:08:10 +00:00
|
|
|
ASSERT_OR_EXECUTE_MSG(
|
|
|
|
BufferDescriptorC().size() > buffer_index, { return 0; },
|
|
|
|
"BufferDescriptorC invalid buffer_index {}", buffer_index);
|
2020-02-06 03:09:16 +00:00
|
|
|
return BufferDescriptorC()[buffer_index].Size();
|
|
|
|
}
|
2020-06-24 12:50:27 +00:00
|
|
|
return 0;
|
2018-02-14 02:41:20 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 06:18:06 +00:00
|
|
|
bool HLERequestContext::CanReadBuffer(std::size_t buffer_index) const {
|
|
|
|
const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
|
|
|
|
BufferDescriptorA()[buffer_index].Size()};
|
|
|
|
|
|
|
|
if (is_buffer_a) {
|
|
|
|
return BufferDescriptorA().size() > buffer_index;
|
|
|
|
} else {
|
|
|
|
return BufferDescriptorX().size() > buffer_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HLERequestContext::CanWriteBuffer(std::size_t buffer_index) const {
|
|
|
|
const bool is_buffer_b{BufferDescriptorB().size() > buffer_index &&
|
|
|
|
BufferDescriptorB()[buffer_index].Size()};
|
|
|
|
|
|
|
|
if (is_buffer_b) {
|
|
|
|
return BufferDescriptorB().size() > buffer_index;
|
|
|
|
} else {
|
|
|
|
return BufferDescriptorC().size() > buffer_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 14:22:11 +00:00
|
|
|
std::string HLERequestContext::Description() const {
|
|
|
|
if (!command_header) {
|
|
|
|
return "No command header available";
|
|
|
|
}
|
|
|
|
std::ostringstream s;
|
|
|
|
s << "IPC::CommandHeader: Type:" << static_cast<u32>(command_header->type.Value());
|
|
|
|
s << ", X(Pointer):" << command_header->num_buf_x_descriptors;
|
|
|
|
if (command_header->num_buf_x_descriptors) {
|
|
|
|
s << '[';
|
|
|
|
for (u64 i = 0; i < command_header->num_buf_x_descriptors; ++i) {
|
|
|
|
s << "0x" << std::hex << BufferDescriptorX()[i].Size();
|
|
|
|
if (i < command_header->num_buf_x_descriptors - 1)
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
s << ']';
|
|
|
|
}
|
|
|
|
s << ", A(Send):" << command_header->num_buf_a_descriptors;
|
|
|
|
if (command_header->num_buf_a_descriptors) {
|
|
|
|
s << '[';
|
|
|
|
for (u64 i = 0; i < command_header->num_buf_a_descriptors; ++i) {
|
|
|
|
s << "0x" << std::hex << BufferDescriptorA()[i].Size();
|
|
|
|
if (i < command_header->num_buf_a_descriptors - 1)
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
s << ']';
|
|
|
|
}
|
|
|
|
s << ", B(Receive):" << command_header->num_buf_b_descriptors;
|
|
|
|
if (command_header->num_buf_b_descriptors) {
|
|
|
|
s << '[';
|
|
|
|
for (u64 i = 0; i < command_header->num_buf_b_descriptors; ++i) {
|
|
|
|
s << "0x" << std::hex << BufferDescriptorB()[i].Size();
|
|
|
|
if (i < command_header->num_buf_b_descriptors - 1)
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
s << ']';
|
|
|
|
}
|
|
|
|
s << ", C(ReceiveList):" << BufferDescriptorC().size();
|
|
|
|
if (!BufferDescriptorC().empty()) {
|
|
|
|
s << '[';
|
|
|
|
for (u64 i = 0; i < BufferDescriptorC().size(); ++i) {
|
|
|
|
s << "0x" << std::hex << BufferDescriptorC()[i].Size();
|
|
|
|
if (i < BufferDescriptorC().size() - 1)
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
s << ']';
|
|
|
|
}
|
|
|
|
s << ", data_size:" << command_header->data_size.Value();
|
|
|
|
|
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
2017-06-05 04:52:19 +00:00
|
|
|
} // namespace Kernel
|