yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Merge pull request #3381 from bunnei/ipc-fix

hle: services: Fix prepo IPC, and add better error checking.
This commit is contained in:
bunnei 2020-02-07 16:25:42 -05:00 committed by GitHub
commit aa3f9b9606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 23 deletions

View File

@ -284,13 +284,18 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) {
std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const { std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const {
std::vector<u8> buffer; std::vector<u8> buffer;
const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
BufferDescriptorA()[buffer_index].Size()};
auto& memory = Core::System::GetInstance().Memory(); auto& memory = Core::System::GetInstance().Memory();
if (is_buffer_a) { if (is_buffer_a) {
ASSERT_MSG(BufferDescriptorA().size() > buffer_index,
"BufferDescriptorA invalid buffer_index {}", buffer_index);
buffer.resize(BufferDescriptorA()[buffer_index].Size()); buffer.resize(BufferDescriptorA()[buffer_index].Size());
memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), buffer.size()); memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), buffer.size());
} else { } else {
ASSERT_MSG(BufferDescriptorX().size() > buffer_index,
"BufferDescriptorX invalid buffer_index {}", buffer_index);
buffer.resize(BufferDescriptorX()[buffer_index].Size()); buffer.resize(BufferDescriptorX()[buffer_index].Size());
memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), buffer.size()); memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), buffer.size());
} }
@ -305,7 +310,8 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
return 0; return 0;
} }
const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()}; const bool is_buffer_b{BufferDescriptorB().size() > buffer_index &&
BufferDescriptorB()[buffer_index].Size()};
const std::size_t buffer_size{GetWriteBufferSize(buffer_index)}; const std::size_t buffer_size{GetWriteBufferSize(buffer_index)};
if (size > buffer_size) { if (size > buffer_size) {
LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size, LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size,
@ -315,8 +321,16 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
auto& memory = Core::System::GetInstance().Memory(); auto& memory = Core::System::GetInstance().Memory();
if (is_buffer_b) { if (is_buffer_b) {
ASSERT_MSG(BufferDescriptorB().size() > buffer_index,
"BufferDescriptorB invalid buffer_index {}", buffer_index);
ASSERT_MSG(BufferDescriptorB()[buffer_index].Size() >= size,
"BufferDescriptorB buffer_index {} is not large enough", buffer_index);
memory.WriteBlock(BufferDescriptorB()[buffer_index].Address(), buffer, size); memory.WriteBlock(BufferDescriptorB()[buffer_index].Address(), buffer, size);
} else { } else {
ASSERT_MSG(BufferDescriptorC().size() > buffer_index,
"BufferDescriptorC invalid buffer_index {}", buffer_index);
ASSERT_MSG(BufferDescriptorC()[buffer_index].Size() >= size,
"BufferDescriptorC buffer_index {} is not large enough", buffer_index);
memory.WriteBlock(BufferDescriptorC()[buffer_index].Address(), buffer, size); memory.WriteBlock(BufferDescriptorC()[buffer_index].Address(), buffer, size);
} }
@ -324,15 +338,35 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
} }
std::size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { std::size_t HLERequestContext::GetReadBufferSize(int buffer_index) const {
const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
return is_buffer_a ? BufferDescriptorA()[buffer_index].Size() BufferDescriptorA()[buffer_index].Size()};
: BufferDescriptorX()[buffer_index].Size(); if (is_buffer_a) {
ASSERT_MSG(BufferDescriptorA().size() > buffer_index,
"BufferDescriptorA invalid buffer_index {}", buffer_index);
ASSERT_MSG(BufferDescriptorA()[buffer_index].Size() > 0,
"BufferDescriptorA buffer_index {} is empty", buffer_index);
return BufferDescriptorA()[buffer_index].Size();
} else {
ASSERT_MSG(BufferDescriptorX().size() > buffer_index,
"BufferDescriptorX invalid buffer_index {}", buffer_index);
ASSERT_MSG(BufferDescriptorX()[buffer_index].Size() > 0,
"BufferDescriptorX buffer_index {} is empty", buffer_index);
return BufferDescriptorX()[buffer_index].Size();
}
} }
std::size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const { std::size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const {
const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()}; const bool is_buffer_b{BufferDescriptorB().size() > buffer_index &&
return is_buffer_b ? BufferDescriptorB()[buffer_index].Size() BufferDescriptorB()[buffer_index].Size()};
: BufferDescriptorC()[buffer_index].Size(); if (is_buffer_b) {
ASSERT_MSG(BufferDescriptorB().size() > buffer_index,
"BufferDescriptorB invalid buffer_index {}", buffer_index);
return BufferDescriptorB()[buffer_index].Size();
} else {
ASSERT_MSG(BufferDescriptorC().size() > buffer_index,
"BufferDescriptorC invalid buffer_index {}", buffer_index);
return BufferDescriptorC()[buffer_index].Size();
}
} }
std::string HLERequestContext::Description() const { std::string HLERequestContext::Description() const {

View File

@ -50,16 +50,16 @@ private:
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto process_id = rp.PopRaw<u64>(); const auto process_id = rp.PopRaw<u64>();
const auto data1 = ctx.ReadBuffer(0); std::vector<std::vector<u8>> data{ctx.ReadBuffer(0)};
const auto data2 = ctx.ReadBuffer(1); if (Type == Core::Reporter::PlayReportType::New) {
data.emplace_back(ctx.ReadBuffer(1));
}
LOG_DEBUG(Service_PREPO, LOG_DEBUG(Service_PREPO, "called, type={:02X}, process_id={:016X}, data1_size={:016X}",
"called, type={:02X}, process_id={:016X}, data1_size={:016X}, data2_size={:016X}", static_cast<u8>(Type), process_id, data[0].size());
static_cast<u8>(Type), process_id, data1.size(), data2.size());
const auto& reporter{system.GetReporter()}; const auto& reporter{system.GetReporter()};
reporter.SavePlayReport(Type, system.CurrentProcess()->GetTitleID(), {data1, data2}, reporter.SavePlayReport(Type, system.CurrentProcess()->GetTitleID(), data, process_id);
process_id);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
@ -70,19 +70,19 @@ private:
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto user_id = rp.PopRaw<u128>(); const auto user_id = rp.PopRaw<u128>();
const auto process_id = rp.PopRaw<u64>(); const auto process_id = rp.PopRaw<u64>();
std::vector<std::vector<u8>> data{ctx.ReadBuffer(0)};
const auto data1 = ctx.ReadBuffer(0); if (Type == Core::Reporter::PlayReportType::New) {
const auto data2 = ctx.ReadBuffer(1); data.emplace_back(ctx.ReadBuffer(1));
}
LOG_DEBUG( LOG_DEBUG(
Service_PREPO, Service_PREPO,
"called, type={:02X}, user_id={:016X}{:016X}, process_id={:016X}, data1_size={:016X}, " "called, type={:02X}, user_id={:016X}{:016X}, process_id={:016X}, data1_size={:016X}",
"data2_size={:016X}", static_cast<u8>(Type), user_id[1], user_id[0], process_id, data[0].size());
static_cast<u8>(Type), user_id[1], user_id[0], process_id, data1.size(), data2.size());
const auto& reporter{system.GetReporter()}; const auto& reporter{system.GetReporter()};
reporter.SavePlayReport(Type, system.CurrentProcess()->GetTitleID(), {data1, data2}, reporter.SavePlayReport(Type, system.CurrentProcess()->GetTitleID(), data, process_id,
process_id, user_id); user_id);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);