mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-01-29 00:33:01 +00:00
Merge pull request #807 from O1L/master
More information in KernelExplorer.
This commit is contained in:
commit
8f1a8450be
114
rpcs3/Emu/SysCalls/SyncPrimitivesManager.h
Normal file
114
rpcs3/Emu/SysCalls/SyncPrimitivesManager.h
Normal file
@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "Emu/System.h"
|
||||
#include "Emu/IdManager.h"
|
||||
#include "Utilities/Log.h"
|
||||
|
||||
struct SemaphoreAttributes
|
||||
{
|
||||
std::string name;
|
||||
u32 count;
|
||||
u32 max_count;
|
||||
|
||||
SemaphoreAttributes() {}
|
||||
SemaphoreAttributes(const std::string& _name, u32 _count, u32 _max_count) : name(_name), count(_count), max_count(_max_count) {}
|
||||
};
|
||||
|
||||
struct LwMutexAttributes
|
||||
{
|
||||
std::string name;
|
||||
u32 owner_id;
|
||||
std::string status; // TODO: check status?
|
||||
|
||||
LwMutexAttributes() {}
|
||||
LwMutexAttributes(const std::string& _name, u32 _owner_id, std::string _status = "INITIALIZED")
|
||||
: name(_name), owner_id(_owner_id), status(_status) {}
|
||||
};
|
||||
|
||||
class SyncPrimManager
|
||||
{
|
||||
private:
|
||||
std::map<u32, std::string> m_cond_name;
|
||||
std::map<u32, std::string> m_mutex_name;
|
||||
std::map<u32, std::string> m_lw_cond_name;
|
||||
std::map<u32, LwMutexAttributes> m_lw_mutex_attr;
|
||||
std::map<u32, SemaphoreAttributes> m_semaph_attr;
|
||||
|
||||
public:
|
||||
|
||||
// semaphores
|
||||
void AddSemaphoreData(const u32 id, const std::string& name, const u32 count, const u32 max_count)
|
||||
{
|
||||
m_semaph_attr[id] = *(new SemaphoreAttributes(name, count, max_count));
|
||||
}
|
||||
|
||||
void EraseSemaphoreData(const u32 id)
|
||||
{
|
||||
m_semaph_attr.erase(id);
|
||||
}
|
||||
|
||||
SemaphoreAttributes& GetSemaphoreData(const u32 id)
|
||||
{
|
||||
return m_semaph_attr[id];
|
||||
}
|
||||
|
||||
// lw_mutexes
|
||||
void AddLwMutexData(const u32 id, const std::string& name, const u32 owner_id)
|
||||
{
|
||||
m_lw_mutex_attr[id] = *(new LwMutexAttributes(name, owner_id));
|
||||
}
|
||||
|
||||
void EraseLwMutexData(const u32 id)
|
||||
{
|
||||
m_lw_mutex_attr.erase(id);
|
||||
}
|
||||
|
||||
LwMutexAttributes& GetLwMutexData(const u32 id)
|
||||
{
|
||||
return m_lw_mutex_attr[id];
|
||||
}
|
||||
|
||||
// lw_conditions, mutexes, conditions
|
||||
void AddSyncPrimData(const IDType type, const u32 id, const std::string& name)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TYPE_LWCOND: m_lw_cond_name[id] = name; break;
|
||||
case TYPE_MUTEX: m_mutex_name[id] = name; break;
|
||||
case TYPE_COND: m_cond_name[id] = name; break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void EraseSyncPrimData(const IDType type, const u32 id)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TYPE_LWCOND: m_lw_cond_name.erase(id); break;
|
||||
case TYPE_MUTEX: m_mutex_name.erase(id); break;
|
||||
case TYPE_COND: m_cond_name.erase(id); break;
|
||||
|
||||
default: LOG_ERROR(GENERAL, "Unknown IDType = %d", type);
|
||||
}
|
||||
}
|
||||
|
||||
std::string& GetSyncPrimName(const IDType type, const u32 id)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TYPE_LWCOND: return m_lw_cond_name[id];
|
||||
case TYPE_MUTEX: return m_mutex_name[id];
|
||||
case TYPE_COND: return m_cond_name[id];
|
||||
}
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
m_cond_name.clear();
|
||||
m_mutex_name.clear();
|
||||
m_lw_cond_name.clear();
|
||||
m_lw_mutex_attr.clear();
|
||||
m_semaph_attr.clear();
|
||||
}
|
||||
};
|
@ -36,6 +36,7 @@ s32 sys_cond_create(vm::ptr<be_t<u32>> cond_id, u32 mutex_id, vm::ptr<sys_cond_a
|
||||
*cond_id = id;
|
||||
mutex->cond_count++;
|
||||
sys_cond.Warning("*** condition created [%s] (mutex_id=%d): id = %d", std::string(attr->name, 8).c_str(), mutex_id, id);
|
||||
Emu.GetSyncPrimManager().AddSyncPrimData(TYPE_COND, id, std::string(attr->name, 8));
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
@ -57,6 +58,7 @@ s32 sys_cond_destroy(u32 cond_id)
|
||||
|
||||
cond->mutex->cond_count--;
|
||||
Emu.GetIdManager().RemoveID(cond_id);
|
||||
Emu.GetSyncPrimManager().EraseSyncPrimData(TYPE_COND, cond_id);
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ s32 sys_lwcond_create(vm::ptr<sys_lwcond_t> lwcond, vm::ptr<sys_lwmutex_t> lwmut
|
||||
sys_lwcond.Warning("*** lwcond created [%s] (lwmutex_addr=0x%x): id = %d",
|
||||
std::string(attr->name, 8).c_str(), lwmutex.addr(), (u32) lwcond->lwcond_queue);
|
||||
|
||||
Emu.GetSyncPrimManager().AddSyncPrimData(TYPE_LWCOND, id, std::string(attr->name, 8));
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
@ -42,6 +44,7 @@ s32 sys_lwcond_destroy(vm::ptr<sys_lwcond_t> lwcond)
|
||||
}
|
||||
|
||||
Emu.GetIdManager().RemoveID(id);
|
||||
Emu.GetSyncPrimManager().EraseSyncPrimData(TYPE_LWCOND, id);
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,8 @@ s32 sys_lwmutex_create(vm::ptr<sys_lwmutex_t> lwmutex, vm::ptr<sys_lwmutex_attri
|
||||
sys_lwmutex.Warning("*** lwmutex created [%s] (attribute=0x%x): sq_id = %d",
|
||||
std::string(attr->name, 8).c_str(), (u32) lwmutex->attribute, sq_id);
|
||||
|
||||
Emu.GetSyncPrimManager().AddLwMutexData(sq_id, std::string(attr->name, 8), GetCurrentPPUThread().GetId());
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
@ -63,6 +65,7 @@ s32 sys_lwmutex_destroy(vm::ptr<sys_lwmutex_t> lwmutex)
|
||||
lwmutex->attribute = 0xDEADBEEF;
|
||||
lwmutex->sleep_queue = 0;
|
||||
Emu.GetIdManager().RemoveID(sq_id);
|
||||
Emu.GetSyncPrimManager().EraseLwMutexData(sq_id);
|
||||
default: return res;
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ s32 sys_mutex_create(vm::ptr<be_t<u32>> mutex_id, vm::ptr<sys_mutex_attribute> a
|
||||
sys_mutex.Warning("*** mutex created [%s] (protocol=0x%x, recursive=%s): id = %d",
|
||||
std::string(attr->name, 8).c_str(), (u32) attr->protocol, (is_recursive ? "true" : "false"), id);
|
||||
|
||||
Emu.GetSyncPrimManager().AddSyncPrimData(TYPE_MUTEX, id, std::string(attr->name, 8));
|
||||
// TODO: unlock mutex when owner thread does exit
|
||||
|
||||
return CELL_OK;
|
||||
@ -98,6 +99,7 @@ s32 sys_mutex_destroy(u32 mutex_id)
|
||||
|
||||
mutex->m_mutex.unlock(tid, ~0);
|
||||
Emu.GetIdManager().RemoveID(mutex_id);
|
||||
Emu.GetSyncPrimManager().EraseSyncPrimData(TYPE_MUTEX, mutex_id);
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ s32 sys_semaphore_create(vm::ptr<be_t<u32>> sem, vm::ptr<sys_semaphore_attribute
|
||||
sys_semaphore.Notice("*** semaphore created [%s] (protocol=0x%x): id = %d",
|
||||
std::string(attr->name, 8).c_str(), (u32)attr->protocol, id);
|
||||
|
||||
Emu.GetSyncPrimManager().AddSemaphoreData(id, std::string(attr->name, 8), initial_count, max_count);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
@ -61,6 +63,7 @@ s32 sys_semaphore_destroy(u32 sem_id)
|
||||
}
|
||||
|
||||
Emu.GetIdManager().RemoveID(sem_id);
|
||||
Emu.GetSyncPrimManager().EraseSemaphoreData(sem_id);
|
||||
return CELL_OK;
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ Emulator::Emulator()
|
||||
, m_event_manager(new EventManager())
|
||||
, m_sfunc_manager(new StaticFuncManager())
|
||||
, m_module_manager(new ModuleManager())
|
||||
, m_sync_prim_manager(new SyncPrimManager())
|
||||
, m_vfs(new VFS())
|
||||
{
|
||||
}
|
||||
@ -71,6 +72,7 @@ Emulator::~Emulator()
|
||||
delete m_event_manager;
|
||||
delete m_sfunc_manager;
|
||||
delete m_module_manager;
|
||||
delete m_sync_prim_manager;
|
||||
delete m_vfs;
|
||||
}
|
||||
|
||||
@ -480,6 +482,7 @@ void Emulator::Stop()
|
||||
GetCallbackManager().Clear();
|
||||
GetModuleManager().UnloadModules();
|
||||
GetSFuncManager().StaticFinalize();
|
||||
GetSyncPrimManager().Close();
|
||||
|
||||
CurGameInfo.Reset();
|
||||
Memory.Close();
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loader/Loader.h"
|
||||
#include "Emu/SysCalls/SyncPrimitivesManager.h"
|
||||
|
||||
enum Status
|
||||
{
|
||||
@ -21,6 +23,7 @@ class CPUThread;
|
||||
class EventManager;
|
||||
class ModuleManager;
|
||||
class StaticFuncManager;
|
||||
class SyncPrimManager;
|
||||
struct VFS;
|
||||
|
||||
struct EmuInfo
|
||||
@ -99,6 +102,7 @@ class Emulator
|
||||
EventManager* m_event_manager;
|
||||
StaticFuncManager* m_sfunc_manager;
|
||||
ModuleManager* m_module_manager;
|
||||
SyncPrimManager* m_sync_prim_manager;
|
||||
VFS* m_vfs;
|
||||
|
||||
EmuInfo m_info;
|
||||
@ -133,6 +137,7 @@ public:
|
||||
EventManager& GetEventManager() { return *m_event_manager; }
|
||||
StaticFuncManager& GetSFuncManager() { return *m_sfunc_manager; }
|
||||
ModuleManager& GetModuleManager() { return *m_module_manager; }
|
||||
SyncPrimManager& GetSyncPrimManager() { return *m_sync_prim_manager; }
|
||||
|
||||
void AddModuleInit(std::unique_ptr<ModuleInitializer> m)
|
||||
{
|
||||
|
@ -46,7 +46,9 @@ void KernelExplorer::Update()
|
||||
char name[4096];
|
||||
|
||||
m_tree->DeleteAllItems();
|
||||
const auto& root = m_tree->AddRoot("Process, ID = 0x00000001, Total Memory Usage = 0x???????? (???.? MB)");
|
||||
const u32 total_memory_usage = Memory.GetUserMemTotalSize() - Memory.GetUserMemAvailSize();
|
||||
|
||||
const auto& root = m_tree->AddRoot(fmt::Format("Process, ID = 0x00000001, Total Memory Usage = 0x%x (%0.2f MB)", total_memory_usage, (float)total_memory_usage / (1024 * 1024)));
|
||||
|
||||
// TODO: FileSystem
|
||||
|
||||
@ -59,7 +61,8 @@ void KernelExplorer::Update()
|
||||
const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_SEMAPHORE);
|
||||
for (const auto& id : objects)
|
||||
{
|
||||
sprintf(name, "Semaphore: ID = 0x%08x", id);
|
||||
sprintf(name, "Semaphore: ID = 0x%08x '%s', Count = %d, Max Count = %d", id, Emu.GetSyncPrimManager().GetSemaphoreData(id).name.c_str(),
|
||||
Emu.GetSyncPrimManager().GetSemaphoreData(id).count, Emu.GetSyncPrimManager().GetSemaphoreData(id).max_count);
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -73,7 +76,7 @@ void KernelExplorer::Update()
|
||||
const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_MUTEX);
|
||||
for (const auto& id : objects)
|
||||
{
|
||||
sprintf(name, "Mutex: ID = 0x%08x", id);
|
||||
sprintf(name, "Mutex: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_MUTEX, id).c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -87,7 +90,8 @@ void KernelExplorer::Update()
|
||||
const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWMUTEX);
|
||||
for (const auto& id : objects)
|
||||
{
|
||||
sprintf(name, "LW Mutex: ID = 0x%08x", id);
|
||||
sprintf(name, "LW Mutex: ID = 0x%08x '%s', Owner Thread ID = 0x%08x - %s", id, Emu.GetSyncPrimManager().GetLwMutexData(id).name.c_str(),
|
||||
Emu.GetSyncPrimManager().GetLwMutexData(id).owner_id, Emu.GetSyncPrimManager().GetLwMutexData(id).status.c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -101,7 +105,7 @@ void KernelExplorer::Update()
|
||||
const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_COND);
|
||||
for (const auto& id : objects)
|
||||
{
|
||||
sprintf(name, "Condition Variable: ID = 0x%08x", id);
|
||||
sprintf(name, "Condition Variable: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_COND, id).c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -113,9 +117,11 @@ void KernelExplorer::Update()
|
||||
sprintf(name, "Light Weight Condition Variables (%d)", count);
|
||||
const auto& node = m_tree->AppendItem(root, name);
|
||||
const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWCOND);
|
||||
|
||||
u32 index = 0;
|
||||
for (const auto& id : objects)
|
||||
{
|
||||
sprintf(name, "LW Condition Variable: ID = 0x%08x", id);
|
||||
sprintf(name, "LW Condition Variable: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_LWCOND, id).c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -163,6 +169,7 @@ void KernelExplorer::Update()
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
|
||||
// Event Flags
|
||||
count = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_FLAG);
|
||||
if (count)
|
||||
@ -180,7 +187,7 @@ void KernelExplorer::Update()
|
||||
// PPU / SPU / RawSPU threads
|
||||
{
|
||||
// TODO: add mutexes owners
|
||||
|
||||
|
||||
const auto& objects = Emu.GetCPU().GetThreads();
|
||||
u32 ppu_threads_count = 0;
|
||||
u32 spu_threads_count = 0;
|
||||
@ -206,7 +213,7 @@ void KernelExplorer::Update()
|
||||
{
|
||||
if (thread->GetType() == CPU_THREAD_PPU)
|
||||
{
|
||||
sprintf(name, "Thread: ID = 0x%08x ''%s'', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str());
|
||||
sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -221,7 +228,7 @@ void KernelExplorer::Update()
|
||||
{
|
||||
if (thread->GetType() == CPU_THREAD_SPU)
|
||||
{
|
||||
sprintf(name, "Thread: ID = 0x%08x ''%s'', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str());
|
||||
sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
@ -236,7 +243,7 @@ void KernelExplorer::Update()
|
||||
{
|
||||
if (thread->GetType() == CPU_THREAD_RAW_SPU)
|
||||
{
|
||||
sprintf(name, "Thread: ID = 0x%08x ''%s'', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str());
|
||||
sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str());
|
||||
m_tree->AppendItem(node, name);
|
||||
}
|
||||
}
|
||||
|
@ -408,6 +408,7 @@
|
||||
<ClInclude Include="Emu\SysCalls\Modules\sys_net.h" />
|
||||
<ClInclude Include="Emu\SysCalls\SC_FUNC.h" />
|
||||
<ClInclude Include="Emu\SysCalls\Static.h" />
|
||||
<ClInclude Include="Emu\SysCalls\SyncPrimitivesManager.h" />
|
||||
<ClInclude Include="Emu\SysCalls\SysCalls.h" />
|
||||
<ClInclude Include="Emu\System.h" />
|
||||
<ClInclude Include="Ini.h" />
|
||||
|
@ -1216,5 +1216,8 @@
|
||||
<ClInclude Include="Emu\SysCalls\CB_FUNC.h">
|
||||
<Filter>Emu\SysCalls</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Emu\SysCalls\SyncPrimitivesManager.h">
|
||||
<Filter>Emu\SysCalls</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user