Merge pull request #4646 from leoetlino/minor-simplifications

IOS HLE: Minor simplifications
This commit is contained in:
Matthew Parlane 2017-01-12 12:32:05 +13:00 committed by GitHub
commit 04a86e1cee
5 changed files with 25 additions and 56 deletions

View File

@ -67,7 +67,7 @@ static std::mutex s_device_map_mutex;
constexpr u8 IPC_MAX_FDS = 0x18; constexpr u8 IPC_MAX_FDS = 0x18;
constexpr u8 ES_MAX_COUNT = 3; constexpr u8 ES_MAX_COUNT = 3;
static std::shared_ptr<IWII_IPC_HLE_Device> s_fdmap[IPC_MAX_FDS]; static std::shared_ptr<IWII_IPC_HLE_Device> s_fdmap[IPC_MAX_FDS];
static std::shared_ptr<IWII_IPC_HLE_Device> s_es_handles[ES_MAX_COUNT]; static std::shared_ptr<CWII_IPC_HLE_Device_es> s_es_handles[ES_MAX_COUNT];
using IPCMsgQueue = std::deque<u32>; using IPCMsgQueue = std::deque<u32>;
static IPCMsgQueue s_request_queue; // ppc -> arm static IPCMsgQueue s_request_queue; // ppc -> arm
@ -171,30 +171,19 @@ void Reset(bool hard)
{ {
CoreTiming::RemoveAllEvents(s_event_enqueue); CoreTiming::RemoveAllEvents(s_event_enqueue);
for (auto& dev : s_fdmap) // Close all devices that were opened and delete their resources
for (auto& device : s_fdmap)
{ {
if (dev && dev->GetDeviceType() != IWII_IPC_HLE_Device::DeviceType::Static) if (!device)
{ continue;
// close all files and delete their resources device->Close(0, true);
dev->Close(0, true); device.reset();
}
dev.reset();
} }
if (hard)
{ {
std::lock_guard<std::mutex> lock(s_device_map_mutex); std::lock_guard<std::mutex> lock(s_device_map_mutex);
for (const auto& entry : s_device_map) s_device_map.clear();
{
if (entry.second)
{
// Force close
entry.second->Close(0, true);
}
}
if (hard)
s_device_map.clear();
} }
s_request_queue.clear(); s_request_queue.clear();
@ -211,13 +200,8 @@ void Shutdown()
void SetDefaultContentFile(const std::string& file_name) void SetDefaultContentFile(const std::string& file_name)
{ {
std::lock_guard<std::mutex> lock(s_device_map_mutex); std::lock_guard<std::mutex> lock(s_device_map_mutex);
for (const auto& entry : s_device_map) for (const auto& es : s_es_handles)
{ es->LoadWAD(file_name);
if (entry.second && entry.second->GetDeviceName().find("/dev/es") == 0)
{
static_cast<CWII_IPC_HLE_Device_es*>(entry.second.get())->LoadWAD(file_name);
}
}
} }
void ES_DIVerify(const std::vector<u8>& tmd) void ES_DIVerify(const std::vector<u8>& tmd)
@ -319,7 +303,7 @@ void DoState(PointerWrap& p)
{ {
const u32 handle_id = es_device->GetDeviceID(); const u32 handle_id = es_device->GetDeviceID();
p.Do(handle_id); p.Do(handle_id);
es_device = AccessDeviceByID(handle_id); es_device = std::static_pointer_cast<CWII_IPC_HLE_Device_es>(AccessDeviceByID(handle_id));
} }
} }
else else

View File

@ -106,11 +106,8 @@ IPCCommandResult CWII_IPC_HLE_Device_di::IOCtlV(u32 _CommandAddress)
// Prepare the out buffer(s) with zeros as a safety precaution // Prepare the out buffer(s) with zeros as a safety precaution
// to avoid returning bad values // to avoid returning bad values
for (u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; i++) for (const auto& buffer : CommandBuffer.PayloadBuffer)
{ Memory::Memset(buffer.m_Address, 0, buffer.m_Size);
Memory::Memset(CommandBuffer.PayloadBuffer[i].m_Address, 0,
CommandBuffer.PayloadBuffer[i].m_Size);
}
u32 ReturnValue = 0; u32 ReturnValue = 0;
switch (CommandBuffer.Parameter) switch (CommandBuffer.Parameter)

View File

@ -31,6 +31,7 @@
*/ */
// ============= // =============
#include <algorithm>
#include <cinttypes> #include <cinttypes>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@ -241,22 +242,15 @@ IPCCommandResult CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress)
// Prepare the out buffer(s) with zeroes as a safety precaution // Prepare the out buffer(s) with zeroes as a safety precaution
// to avoid returning bad values // to avoid returning bad values
// XXX: is this still necessary? for (const auto& buffer : Buffer.PayloadBuffer)
for (u32 i = 0; i < Buffer.NumberPayloadBuffer; i++)
{ {
u32 j; // Don't zero an out buffer which is also one of the in buffers.
for (j = 0; j < Buffer.NumberInBuffer; j++) if (std::any_of(Buffer.InBuffer.begin(), Buffer.InBuffer.end(),
[&](const auto& in_buffer) { return in_buffer.m_Address == buffer.m_Address; }))
{ {
if (Buffer.InBuffer[j].m_Address == Buffer.PayloadBuffer[i].m_Address) continue;
{
// The out buffer is the same as one of the in buffers. Don't zero it.
break;
}
}
if (j == Buffer.NumberInBuffer)
{
Memory::Memset(Buffer.PayloadBuffer[i].m_Address, 0, Buffer.PayloadBuffer[i].m_Size);
} }
Memory::Memset(buffer.m_Address, 0, buffer.m_Size);
} }
switch (Buffer.Parameter) switch (Buffer.Parameter)

View File

@ -78,11 +78,8 @@ IPCCommandResult CWII_IPC_HLE_Device_fs::IOCtlV(u32 _CommandAddress)
// Prepare the out buffer(s) with zeros as a safety precaution // Prepare the out buffer(s) with zeros as a safety precaution
// to avoid returning bad values // to avoid returning bad values
for (u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; i++) for (const auto& buffer : CommandBuffer.PayloadBuffer)
{ Memory::Memset(buffer.m_Address, 0, buffer.m_Size);
Memory::Memset(CommandBuffer.PayloadBuffer[i].m_Address, 0,
CommandBuffer.PayloadBuffer[i].m_Size);
}
switch (CommandBuffer.Parameter) switch (CommandBuffer.Parameter)
{ {

View File

@ -245,11 +245,8 @@ IPCCommandResult CWII_IPC_HLE_Device_sdio_slot0::IOCtlV(u32 _CommandAddress)
// Prepare the out buffer(s) with zeros as a safety precaution // Prepare the out buffer(s) with zeros as a safety precaution
// to avoid returning bad values // to avoid returning bad values
for (u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; i++) for (const auto& buffer : CommandBuffer.PayloadBuffer)
{ Memory::Memset(buffer.m_Address, 0, buffer.m_Size);
Memory::Memset(CommandBuffer.PayloadBuffer[i].m_Address, 0,
CommandBuffer.PayloadBuffer[i].m_Size);
}
u32 ReturnValue = 0; u32 ReturnValue = 0;
switch (CommandBuffer.Parameter) switch (CommandBuffer.Parameter)