diff --git a/Utilities/IdManager.h b/rpcs3/Emu/IdManager.h similarity index 57% rename from Utilities/IdManager.h rename to rpcs3/Emu/IdManager.h index 9d72c65476..b1170cce04 100644 --- a/Utilities/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -3,7 +3,32 @@ #define rID_ANY -1 // was wxID_ANY -typedef u32 ID_TYPE; +enum IDType +{ + // Special objects + TYPE_MEM, + TYPE_MUTEX, + TYPE_COND, + TYPE_RWLOCK, + TYPE_INTR_TAG, + TYPE_INTR_SERVICE_HANDLE, + TYPE_EVENT_QUEUE, + TYPE_EVENT_PORT, + TYPE_TRACE, + TYPE_SPUIMAGE, + TYPE_PRX, + TYPE_SPUPORT, + TYPE_LWMUTEX, + TYPE_TIMER, + TYPE_SEMAPHORE, + TYPE_FS_FILE, + TYPE_FS_DIR, + TYPE_LWCOND, + TYPE_EVENT_FLAG, + + // Any other objects + TYPE_OTHER, +}; class IDData { @@ -37,13 +62,13 @@ public: struct ID { std::string m_name; - u32 m_attr; IDData* m_data; + IDType m_type; template - ID(const std::string& name, T* data, const u32 attr) + ID(const std::string& name, T* data, const IDType type) : m_name(name) - , m_attr(attr) + , m_type(type) { m_data = new IDData(data, [](void *ptr) -> void { delete (T*)ptr; }); } @@ -55,14 +80,14 @@ struct ID ID(ID&& other) { m_name = other.m_name; - m_attr = other.m_attr; + m_type = other.m_type; m_data = other.m_data; other.m_data = nullptr; } ID& operator=(ID&& other) { std::swap(m_name,other.m_name); - std::swap(m_attr,other.m_attr); + std::swap(m_type,other.m_type); std::swap(m_data,other.m_data); return *this; } @@ -75,13 +100,14 @@ struct ID class IdManager { - static const ID_TYPE s_first_id = 1; - static const ID_TYPE s_max_id = -1; + static const u32 s_first_id = 1; + static const u32 s_max_id = -1; - std::unordered_map m_id_map; + std::unordered_map m_id_map; + std::set m_types[TYPE_OTHER]; std::mutex m_mtx_main; - ID_TYPE m_cur_id; + u32 m_cur_id; public: IdManager() : m_cur_id(s_first_id) @@ -93,7 +119,7 @@ public: Clear(); } - bool CheckID(const ID_TYPE id) + bool CheckID(const u32 id) { std::lock_guard lock(m_mtx_main); @@ -104,8 +130,7 @@ public: { std::lock_guard lock(m_mtx_main); - for(auto& i : m_id_map) - { + for(auto& i : m_id_map) { i.second.Kill(); } @@ -118,16 +143,19 @@ public: = char #endif > - ID_TYPE GetNewID(const std::string& name = "", T* data = nullptr, const u32 attr = 0) + u32 GetNewID(const std::string& name = "", T* data = nullptr, const IDType type = TYPE_OTHER) { std::lock_guard lock(m_mtx_main); - m_id_map[m_cur_id] = ID(name, data, attr); + m_id_map[m_cur_id] = ID(name, data, type); + if (type < TYPE_OTHER) { + m_types[type].insert(m_cur_id); + } return m_cur_id++; } - ID& GetID(const ID_TYPE id) + ID& GetID(const u32 id) { std::lock_guard lock(m_mtx_main); @@ -135,14 +163,12 @@ public: } template - bool GetIDData(const ID_TYPE id, T*& result) + bool GetIDData(const u32 id, T*& result) { std::lock_guard lock(m_mtx_main); auto f = m_id_map.find(id); - - if(f == m_id_map.end()) - { + if (f == m_id_map.end()) { return false; } @@ -156,24 +182,43 @@ public: { std::lock_guard lock(m_mtx_main); - if(id == rID_ANY) + if(id == rID_ANY) { return m_id_map.begin() != m_id_map.end(); + } } - return CheckID(id); } - bool RemoveID(const ID_TYPE id) + bool RemoveID(const u32 id) { std::lock_guard lock(m_mtx_main); auto item = m_id_map.find(id); - if(item == m_id_map.end()) return false; + if (item == m_id_map.end()) { + return false; + } + if (item->second.m_type < TYPE_OTHER) { + m_types[item->second.m_type].erase(id); + } item->second.Kill(); m_id_map.erase(item); return true; } + + u32 GetTypeCount(IDType type) + { + if (type < TYPE_OTHER) { + return m_types[type].size(); + } + return 1; + } + + const std::set& GetTypeIDs(IDType type) + { + assert(type < TYPE_OTHER); + return m_types[type]; + } }; diff --git a/rpcs3/Emu/SysCalls/Modules.h b/rpcs3/Emu/SysCalls/Modules.h index a7835db354..14f0bb3522 100644 --- a/rpcs3/Emu/SysCalls/Modules.h +++ b/rpcs3/Emu/SysCalls/Modules.h @@ -90,23 +90,23 @@ public: return true; } - template bool CheckId(u32 id, T*& data, u32& attr) + template bool CheckId(u32 id, T*& data, IDType& type) { ID* id_data; if(!CheckID(id, id_data)) return false; data = id_data->m_data->get(); - attr = id_data->m_attr; + type = id_data->m_type; return true; } bool CheckID(u32 id, ID*& _id) const; template - u32 GetNewId(T* data, u8 flags = 0) + u32 GetNewId(T* data, IDType type = TYPE_OTHER) { - return Emu.GetIdManager().GetNewID(GetName(), data, flags); + return Emu.GetIdManager().GetNewID(GetName(), data, type); } template __forceinline void AddFunc(u32 id, T func); diff --git a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp index eb97c00e58..032da5f98f 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp @@ -128,7 +128,7 @@ int cellFsSdataOpen(u32 path_addr, int flags, mem32_t fd, mem32_t arg, u64 size) int ret = sdata_unpack(path, unpacked_path); if (ret) return ret; - fd = sys_fs->GetNewId(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), flags); + fd = sys_fs->GetNewId(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), TYPE_FS_FILE); return CELL_OK;*/ diff --git a/rpcs3/Emu/SysCalls/SysCalls.h b/rpcs3/Emu/SysCalls/SysCalls.h index ae82066d4e..e7b20635b4 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.h +++ b/rpcs3/Emu/SysCalls/SysCalls.h @@ -78,9 +78,9 @@ public: } template - u32 GetNewId(T* data, u8 flags = 0) + u32 GetNewId(T* data, IDType type = TYPE_OTHER) { - return Emu.GetIdManager().GetNewID(GetName(), data, flags); + return Emu.GetIdManager().GetNewID(GetName(), data, type); } }; diff --git a/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp b/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp index 8446a195f3..76ab51955f 100644 --- a/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp @@ -13,12 +13,6 @@ extern Module *sys_fs; -enum -{ - IDFlag_File = 1, - IDFlag_Dir = 2, -}; - struct FsRingBufferConfig { CellFsRingBuffer m_ring_buffer; // Currently unused after assignment @@ -117,7 +111,7 @@ s32 cellFsOpen(u32 path_addr, s32 flags, mem32_t fd, mem32_t arg, u64 size) return CELL_ENOENT; } - fd = sys_fs->GetNewId(stream, IDFlag_File); + fd = sys_fs->GetNewId(stream, TYPE_FS_FILE); LOG_NOTICE(HLE, "\"%s\" opened: fd = %d", path.c_str(), fd.GetValue()); return CELL_OK; @@ -181,7 +175,7 @@ s32 cellFsOpendir(u32 path_addr, mem32_t fd) return CELL_ENOENT; } - fd = sys_fs->GetNewId(dir, IDFlag_Dir); + fd = sys_fs->GetNewId(dir, TYPE_FS_DIR); return CELL_OK; } @@ -263,9 +257,11 @@ s32 cellFsFstat(u32 fd, mem_ptr_t sb) { sys_fs->Log("cellFsFstat(fd=%d, sb_addr: 0x%x)", fd, sb.GetAddr()); - u32 attr; + IDType type; vfsStream* file; - if(!sys_fs->CheckId(fd, file, attr) || attr != IDFlag_File) return CELL_ESRCH; + if(!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) { + return CELL_ESRCH; + } sb->st_mode = CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | @@ -398,9 +394,11 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, mem64_t pos) return CELL_EINVAL; } - u32 attr; + IDType type; vfsStream* file; - if(!sys_fs->CheckId(fd, file, attr) || attr != IDFlag_File) return CELL_ESRCH; + if (!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) { + return CELL_ESRCH; + } pos = file->Seek(offset, seek_mode); return CELL_OK; } @@ -408,9 +406,12 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, mem64_t pos) s32 cellFsFtruncate(u32 fd, u64 size) { sys_fs->Log("cellFsFtruncate(fd=%d, size=%lld)", fd, size); - u32 attr; + + IDType type; vfsStream* file; - if(!sys_fs->CheckId(fd, file, attr) || attr != IDFlag_File) return CELL_ESRCH; + if (!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) { + return CELL_ESRCH; + } u64 initialSize = file->GetSize(); if (initialSize < size) diff --git a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp index b90ac46e18..e169fcc740 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp @@ -32,7 +32,7 @@ s32 sys_cond_create(mem32_t cond_id, u32 mutex_id, mem_ptr_t } Cond* cond = new Cond(mutex, attr->name_u64); - u32 id = sys_cond.GetNewId(cond); + u32 id = sys_cond.GetNewId(cond, TYPE_COND); 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, cond_id.GetValue()); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp index 52c4703e6c..bf4b722388 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp @@ -50,7 +50,7 @@ s32 sys_event_queue_create(mem32_t equeue_id, mem_ptr_t at return CELL_EAGAIN; } - equeue_id = sys_event.GetNewId(eq); + equeue_id = sys_event.GetNewId(eq, TYPE_EVENT_QUEUE); sys_event.Warning("*** event_queue created [%s] (protocol=0x%x, type=0x%x): id = %d", std::string(attr->name, 8).c_str(), (u32)attr->protocol, (int)attr->type, equeue_id.GetValue()); @@ -237,7 +237,7 @@ s32 sys_event_port_create(mem32_t eport_id, int port_type, u64 name) } EventPort* eport = new EventPort(); - u32 id = sys_event.GetNewId(eport); + u32 id = sys_event.GetNewId(eport, TYPE_EVENT_PORT); eport->name = name ? name : ((u64)sys_process_getpid() << 32) | (u64)id; eport_id = id; sys_event.Warning("*** sys_event_port created: id = %d", id); @@ -360,4 +360,4 @@ s32 sys_event_port_send(u32 eport_id, u64 data1, u64 data2, u64 data3) } return CELL_OK; -} \ No newline at end of file +} diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp index e7bdb22458..57943453bb 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp @@ -14,7 +14,7 @@ s32 sys_lwcond_create(mem_ptr_t lwcond, mem_ptr_t l sys_lwcond.Log("sys_lwcond_create(lwcond_addr=0x%x, lwmutex_addr=0x%x, attr_addr=0x%x)", lwcond.GetAddr(), lwmutex.GetAddr(), attr.GetAddr()); - u32 id = sys_lwcond.GetNewId(new Lwcond(attr->name_u64)); + u32 id = sys_lwcond.GetNewId(new Lwcond(attr->name_u64), TYPE_LWCOND); lwcond->lwmutex = lwmutex.GetAddr(); lwcond->lwcond_queue = id; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp index 958142a75a..267b68a0d0 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp @@ -36,7 +36,7 @@ s32 sys_lwmutex_create(mem_ptr_t lwmutex, mem_ptr_tpad = 0; lwmutex->recursive_count = 0; - u32 sq_id = sc_lwmutex.GetNewId(new SleepQueue(attr->name_u64)); + u32 sq_id = sc_lwmutex.GetNewId(new SleepQueue(attr->name_u64), TYPE_LWMUTEX); lwmutex->sleep_queue = sq_id; sc_lwmutex.Warning("*** lwmutex created [%s] (attribute=0x%x): sq_id = %d", diff --git a/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp b/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp index dd16cae520..936b5ff0ac 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp @@ -122,7 +122,7 @@ s32 sys_memory_container_create(mem32_t cid, u32 yield_size) // Wrap the allocated memory in a memory container. MemoryContainerInfo *ct = new MemoryContainerInfo(addr, yield_size); - cid = sc_mem.GetNewId(ct); + cid = sc_mem.GetNewId(ct, TYPE_MEM); sc_mem.Warning("*** memory_container created(addr=0x%llx): id = %d", addr, cid.GetValue()); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp index 3a041eb0a7..7555a5da0e 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp @@ -121,7 +121,7 @@ s32 sys_mmapper_allocate_memory_from_container(u32 size, u32 cid, u64 flags, mem ct->size = size; // Generate a new mem ID. - mem_id = sys_mmapper.GetNewId(new mmapper_info(ct->addr, ct->size, flags)); + mem_id = sys_mmapper.GetNewId(new mmapper_info(ct->addr, ct->size, flags), TYPE_MEM); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp index fed9b6d3cd..e9817bd0dd 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp @@ -38,7 +38,7 @@ s32 sys_mutex_create(mem32_t mutex_id, mem_ptr_t attr) u32 tid = GetCurrentPPUThread().GetId(); Mutex* mutex = new Mutex((u32)attr->protocol, is_recursive, attr->name_u64); - u32 id = sys_mtx.GetNewId(mutex); + u32 id = sys_mtx.GetNewId(mutex, TYPE_MUTEX); mutex->m_mutex.lock(tid); mutex->id = id; mutex_id = id; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp index f36e417ec2..02ff2174b6 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp @@ -8,8 +8,6 @@ SysCallBase sc_p("Process"); -sysProcessObjects_t procObjects; - s32 process_getpid() { // TODO: get current process id @@ -147,23 +145,26 @@ s32 sys_process_get_number_of_object(u32 object, mem32_t nump) switch(object) { - case SYS_MEM_OBJECT: nump = procObjects.mem_objects.size(); break; - case SYS_MUTEX_OBJECT: nump = procObjects.mutex_objects.size(); break; - case SYS_COND_OBJECT: nump = procObjects.cond_objects.size(); break; - case SYS_RWLOCK_OBJECT: nump = procObjects.rwlock_objects.size(); break; - case SYS_INTR_TAG_OBJECT: nump = procObjects.intr_tag_objects.size(); break; - case SYS_INTR_SERVICE_HANDLE_OBJECT: nump = procObjects.intr_service_handle_objects.size(); break; - case SYS_EVENT_QUEUE_OBJECT: nump = procObjects.event_queue_objects.size(); break; - case SYS_EVENT_PORT_OBJECT: nump = procObjects.event_port_objects.size(); break; - case SYS_TRACE_OBJECT: nump = procObjects.trace_objects.size(); break; - case SYS_SPUIMAGE_OBJECT: nump = procObjects.spuimage_objects.size(); break; - case SYS_PRX_OBJECT: nump = procObjects.prx_objects.size(); break; - case SYS_SPUPORT_OBJECT: nump = procObjects.spuport_objects.size(); break; - case SYS_LWMUTEX_OBJECT: nump = procObjects.lwmutex_objects.size(); break; - case SYS_TIMER_OBJECT: nump = procObjects.timer_objects.size(); break; - case SYS_SEMAPHORE_OBJECT: nump = procObjects.semaphore_objects.size(); break; - case SYS_FS_FD_OBJECT: nump = procObjects.fs_fd_objects.size(); break; - case SYS_LWCOND_OBJECT: nump = procObjects.lwcond_objects.size(); break; + case SYS_MEM_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_MEM); break; + case SYS_MUTEX_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_MUTEX); break; + case SYS_COND_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_COND); break; + case SYS_RWLOCK_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_RWLOCK); break; + case SYS_INTR_TAG_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_INTR_TAG); break; + case SYS_INTR_SERVICE_HANDLE_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_INTR_SERVICE_HANDLE); break; + case SYS_EVENT_QUEUE_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_QUEUE); break; + case SYS_EVENT_PORT_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_PORT); break; + case SYS_TRACE_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_TRACE); break; + case SYS_SPUIMAGE_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_SPUIMAGE); break; + case SYS_PRX_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_PRX); break; + case SYS_SPUPORT_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_SPUPORT); break; + case SYS_LWMUTEX_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_LWMUTEX); break; + case SYS_TIMER_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_TIMER); break; + case SYS_SEMAPHORE_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_SEMAPHORE); break; + case SYS_LWCOND_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_LWCOND); break; + case SYS_EVENT_FLAG_OBJECT: nump = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_FLAG); break; + case SYS_FS_FD_OBJECT: + nump = Emu.GetIdManager().GetTypeCount(TYPE_FS_FILE) + Emu.GetIdManager().GetTypeCount(TYPE_FS_DIR); + break; default: return CELL_EINVAL; @@ -180,31 +181,32 @@ s32 sys_process_get_id(u32 object, mem32_ptr_t buffer, u32 size, mem32_t set_siz switch(object) { -#define ADD_OBJECTS(objects) { \ +#define ADD_OBJECTS(type) { \ u32 i=0; \ + const auto& objects = Emu.GetIdManager().GetTypeIDs(type); \ for(auto id=objects.begin(); i mem_objects; - std::set mutex_objects; - std::set cond_objects; - std::set rwlock_objects; - std::set intr_tag_objects; - std::set intr_service_handle_objects; - std::set event_queue_objects; - std::set event_port_objects; - std::set trace_objects; - std::set spuimage_objects; - std::set prx_objects; - std::set spuport_objects; - std::set lwmutex_objects; - std::set timer_objects; - std::set semaphore_objects; - std::set fs_fd_objects; - std::set lwcond_objects; - std::set event_flag_objects; -}; - -// Extern -extern sysProcessObjects_t procObjects; - // Auxiliary functions s32 process_getpid(); s32 process_get_sdk_version(u32 pid, s32& ver); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp b/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp index 2abbc26226..5e8370b730 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp @@ -4,6 +4,7 @@ #include "Emu/System.h" #include "Emu/SysCalls/SysCalls.h" #include "Emu/FS/vfsFile.h" +#include "Crypto/unself.h" #include "sys_prx.h" SysCallBase sys_prx("sys_prx"); @@ -13,19 +14,31 @@ s32 sys_prx_load_module(u32 path_addr, u64 flags, mem_ptr_tsize = f.GetSize(); + prx->address = Memory.Alloc(prx->size, 4); + prx->path = path; + + // Load the PRX into memory + f.Read(Memory.VirtualToRealAddr(prx->address), prx->size); + + u32 id = sys_prx.GetNewId(prx, TYPE_PRX); return id; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_prx.h b/rpcs3/Emu/SysCalls/lv2/sys_prx.h index 523ccc82cc..5c09a7c475 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_prx.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_prx.h @@ -51,15 +51,15 @@ struct sys_prx_unload_module_option_t }; // Auxiliary data types -struct sys_prx_t { +struct sys_prx_t +{ u32 size; u32 address; + std::string path; bool isStarted; - sys_prx_t(u32 prx_size, u32 prx_address) - : size(prx_size) - , address(prx_address) - , isStarted(false) + sys_prx_t() + : isStarted(false) { } }; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp index 74987422fd..28a7d61d21 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp @@ -28,7 +28,7 @@ s32 sys_rwlock_create(mem32_t rw_lock_id, mem_ptr_t attr return CELL_EINVAL; } - rw_lock_id = sys_rwlock.GetNewId(new RWLock((u32)attr->attr_protocol, attr->name_u64)); + rw_lock_id = sys_rwlock.GetNewId(new RWLock((u32)attr->attr_protocol, attr->name_u64), TYPE_RWLOCK); sys_rwlock.Warning("*** rwlock created [%s] (protocol=0x%x): id = %d", std::string(attr->name, 8).c_str(), (u32)attr->attr_protocol, rw_lock_id.GetValue()); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp index 243f578076..d402105eee 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp @@ -35,7 +35,7 @@ s32 sys_semaphore_create(mem32_t sem, mem_ptr_t attr, i default: sys_sem.Error("Unknown protocol attribute(0x%x)", (u32)attr->protocol); return CELL_EINVAL; } - sem = sys_sem.GetNewId(new Semaphore(initial_count, max_count, attr->protocol, attr->name_u64)); + sem = sys_sem.GetNewId(new Semaphore(initial_count, max_count, attr->protocol, attr->name_u64), TYPE_SEMAPHORE); LOG_NOTICE(HLE, "*** semaphore created [%s] (protocol=0x%x): id = %d", std::string(attr->name, 8).c_str(), (u32)attr->protocol, sem.GetValue()); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp b/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp index b479783bfa..01f8ec7526 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp @@ -11,7 +11,11 @@ s32 sys_timer_create(mem32_t timer_id) { sys_timer.Warning("sys_timer_create(timer_id_addr=0x%x)", timer_id.GetAddr()); - timer_id = sys_timer.GetNewId(new timer); + if (!timer_id.IsGood()) { + return CELL_EFAULT; + } + + timer_id = sys_timer.GetNewId(new timer, TYPE_TIMER); return CELL_OK; } diff --git a/rpcs3/Gui/KernelExplorer.cpp b/rpcs3/Gui/KernelExplorer.cpp new file mode 100644 index 0000000000..d54a33fcc5 --- /dev/null +++ b/rpcs3/Gui/KernelExplorer.cpp @@ -0,0 +1,167 @@ +#include "stdafx.h" +#include "Utilities/Log.h" +#include "Emu/Memory/Memory.h" +#include "Emu/System.h" + +#include "KernelExplorer.h" + +KernelExplorer::KernelExplorer(wxWindow* parent) + : wxFrame(parent, wxID_ANY, "Kernel Explorer", wxDefaultPosition, wxSize(700, 450)) +{ + this->SetBackgroundColour(wxColour(240,240,240)); //This fix the ugly background color under Windows + wxBoxSizer* s_panel = new wxBoxSizer(wxVERTICAL); + + // Buttons + wxBoxSizer* box_buttons = new wxBoxSizer(wxHORIZONTAL); + wxButton* b_refresh = new wxButton(this, wxID_ANY, "Refresh"); + box_buttons->AddSpacer(10); + box_buttons->Add(b_refresh); + box_buttons->AddSpacer(10); + + wxStaticBoxSizer* box_tree = new wxStaticBoxSizer(wxHORIZONTAL, this, "Kernel"); + m_tree = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(600,300)); + box_tree->Add(m_tree); + + // Merge and display everything + s_panel->AddSpacer(10); + s_panel->Add(box_buttons); + s_panel->AddSpacer(10); + s_panel->Add(box_tree, 0, 0, 100); + s_panel->AddSpacer(10); + SetSizerAndFit(s_panel); + + // Events + b_refresh->Bind(wxEVT_BUTTON, &KernelExplorer::OnRefresh, this); + + // Fill the wxTreeCtrl + Update(); +}; + +void KernelExplorer::Update() +{ + int count; + char name[4096]; + + m_tree->DeleteAllItems(); + const auto& root = m_tree->AddRoot("Process, ID = 0x00000001, Total Memory Usage = 0x???????? (???.? MB)"); + + // TODO: PPU Threads + // TODO: SPU/RawSPU Threads + // TODO: FileSystem + + // Semaphores + count = Emu.GetIdManager().GetTypeCount(TYPE_SEMAPHORE); + if (count) { + sprintf(name, "Semaphores (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_SEMAPHORE); + for (const auto& id : objects) { + sprintf(name, "Semaphore: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Mutexes + count = Emu.GetIdManager().GetTypeCount(TYPE_MUTEX); + if (count) { + sprintf(name, "Mutexes (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_MUTEX); + for (const auto& id : objects) { + sprintf(name, "Mutex: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Light Weight Mutexes + count = Emu.GetIdManager().GetTypeCount(TYPE_LWMUTEX); + if (count) { + sprintf(name, "Light Weight Mutexes (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWMUTEX); + for (const auto& id : objects) { + sprintf(name, "LW Mutex: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Condition Variables + count = Emu.GetIdManager().GetTypeCount(TYPE_COND); + if (count) { + sprintf(name, "Condition Variables (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_COND); + for (const auto& id : objects) { + sprintf(name, "Condition Variable: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Light Weight Condition Variables + count = Emu.GetIdManager().GetTypeCount(TYPE_LWCOND); + if (count) { + sprintf(name, "Light Weight Condition Variables (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWCOND); + for (const auto& id : objects) { + sprintf(name, "LW Condition Variable: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Event Queues + count = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_QUEUE); + if (count) { + sprintf(name, "Event Queues (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_EVENT_QUEUE); + for (const auto& id : objects) { + sprintf(name, "Event Queue: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Modules + count = Emu.GetIdManager().GetTypeCount(TYPE_PRX); + if (count) { + sprintf(name, "Modules (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_PRX); + sprintf(name, "Segment List (%d)", 2 * objects.size()); // TODO: Assuming 2 segments per PRX file is not good + m_tree->AppendItem(node, name); + for (const auto& id : objects) { + sprintf(name, "PRX: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Memory Containers + count = Emu.GetIdManager().GetTypeCount(TYPE_MEM); + if (count) { + sprintf(name, "Memory Containers (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_MEM); + for (const auto& id : objects) { + sprintf(name, "Memory Container: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + // Event Flags + count = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_FLAG); + if (count) { + sprintf(name, "Event Flags (%d)", count); + const auto& node = m_tree->AppendItem(root, name); + const auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_EVENT_FLAG); + for (const auto& id : objects) { + sprintf(name, "Event Flag: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + m_tree->Expand(root); +} + +void KernelExplorer::OnRefresh(wxCommandEvent& WXUNUSED(event)) +{ + Update(); +} diff --git a/rpcs3/Gui/KernelExplorer.h b/rpcs3/Gui/KernelExplorer.h new file mode 100644 index 0000000000..85316badf4 --- /dev/null +++ b/rpcs3/Gui/KernelExplorer.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +class KernelExplorer : public wxFrame +{ + wxTreeCtrl* m_tree; + +public: + KernelExplorer(wxWindow* parent); + void Update(); + + void OnRefresh(wxCommandEvent& WXUNUSED(event)); +}; diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 69249a2fd8..fc79993072 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -4,20 +4,22 @@ #include "Emu/System.h" #include "rpcs3.h" #include "MainFrame.h" -#include "CompilerELF.h" -#include "MemoryViewer.h" -#include "RSXDebugger.h" -#include "PADManager.h" #include "git-version.h" #include "Ini.h" #include "Emu/RSX/sysutil_video.h" +#include "Gui/PADManager.h" #include "Gui/VHDDManager.h" #include "Gui/VFSManager.h" #include "Gui/AboutDialog.h" #include "Gui/GameViewer.h" +#include "Gui/CompilerELF.h" #include "Gui/AutoPauseManager.h" #include "Gui/SaveDataUtility.h" +#include "Gui/KernelExplorer.h" +#include "Gui/MemoryViewer.h" +#include "Gui/RSXDebugger.h" + #include #include "Loader/PKG.h" @@ -42,6 +44,7 @@ enum IDs id_config_autopause_manager, id_config_savedata_manager, id_tools_compiler, + id_tools_kernel_explorer, id_tools_memory_viewer, id_tools_rsx_debugger, id_help_about, @@ -98,6 +101,7 @@ MainFrame::MainFrame() wxMenu* menu_tools = new wxMenu(); menubar->Append(menu_tools, "Tools"); menu_tools->Append(id_tools_compiler, "ELF Compiler"); + menu_tools->Append(id_tools_kernel_explorer, "Kernel Explorer")->Enable(false); menu_tools->Append(id_tools_memory_viewer, "Memory Viewer")->Enable(false); menu_tools->Append(id_tools_rsx_debugger, "RSX Debugger")->Enable(false); @@ -134,6 +138,7 @@ MainFrame::MainFrame() Bind(wxEVT_MENU, &MainFrame::ConfigSaveData, this, id_config_savedata_manager); Bind(wxEVT_MENU, &MainFrame::OpenELFCompiler, this, id_tools_compiler); + Bind(wxEVT_MENU, &MainFrame::OpenKernelExplorer, this, id_tools_kernel_explorer); Bind(wxEVT_MENU, &MainFrame::OpenMemoryViewer, this, id_tools_memory_viewer); Bind(wxEVT_MENU, &MainFrame::OpenRSXDebugger, this, id_tools_rsx_debugger); @@ -635,6 +640,11 @@ void MainFrame::OpenELFCompiler(wxCommandEvent& WXUNUSED(event)) (new CompilerELF(this)) -> Show(); } +void MainFrame::OpenKernelExplorer(wxCommandEvent& WXUNUSED(event)) +{ + (new KernelExplorer(this)) -> Show(); +} + void MainFrame::OpenMemoryViewer(wxCommandEvent& WXUNUSED(event)) { (new MemoryViewerPanel(this)) -> Show(); @@ -732,8 +742,10 @@ void MainFrame::UpdateUI(wxCommandEvent& event) send_exit.Enable(enable_commands); // Tools - wxMenuItem& memory_viewer = *menubar.FindItem( id_tools_memory_viewer ); - wxMenuItem& rsx_debugger = *menubar.FindItem( id_tools_rsx_debugger); + wxMenuItem& kernel_explorer = *menubar.FindItem(id_tools_kernel_explorer); + wxMenuItem& memory_viewer = *menubar.FindItem(id_tools_memory_viewer); + wxMenuItem& rsx_debugger = *menubar.FindItem(id_tools_rsx_debugger); + kernel_explorer.Enable(!is_stopped); memory_viewer.Enable(!is_stopped); rsx_debugger.Enable(!is_stopped); diff --git a/rpcs3/Gui/MainFrame.h b/rpcs3/Gui/MainFrame.h index 604e68e97c..3e1b625048 100644 --- a/rpcs3/Gui/MainFrame.h +++ b/rpcs3/Gui/MainFrame.h @@ -41,6 +41,7 @@ private: void ConfigAutoPause(wxCommandEvent& event); void ConfigSaveData(wxCommandEvent& event); void OpenELFCompiler(wxCommandEvent& evt); + void OpenKernelExplorer(wxCommandEvent& evt); void OpenMemoryViewer(wxCommandEvent& evt); void OpenRSXDebugger(wxCommandEvent& evt); void OpenFnIdGenerator(wxCommandEvent& evt); diff --git a/rpcs3/Loader/ELF64.cpp b/rpcs3/Loader/ELF64.cpp index e949ae56d3..f32697a716 100644 --- a/rpcs3/Loader/ELF64.cpp +++ b/rpcs3/Loader/ELF64.cpp @@ -5,10 +5,9 @@ #include "Emu/Cell/PPUThread.h" #include "Emu/SysCalls/SC_FUNC.h" #include "Emu/SysCalls/Modules.h" -#include "ELF64.h" #include "Emu/Cell/PPUInstrTable.h" -#include "Emu/System.h" #include "Emu/SysCalls/ModuleManager.h" +#include "ELF64.h" using namespace PPU_instr; diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 8c74b31988..7ce030b02a 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -218,7 +218,6 @@ - @@ -291,6 +290,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index db572c65f9..271fa80725 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -937,9 +937,6 @@ Utilities - - Utilities - Utilities @@ -1158,6 +1155,9 @@ Emu\SysCalls\Modules + + + Emu \ No newline at end of file diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 9b4424a1db..bdd38e73eb 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -173,6 +173,7 @@ + @@ -218,6 +219,7 @@ + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index 7043c6c0f1..d01670ad84 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -101,6 +101,9 @@ Gui + + + Gui @@ -214,6 +217,9 @@ Gui + + + Gui \ No newline at end of file diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 0b5741fae2..ff93662fa2 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -63,7 +63,7 @@ typedef int64_t s64; #include "Utilities/rMsgBox.h" #include "Utilities/Thread.h" #include "Utilities/Timer.h" -#include "Utilities/IdManager.h" +#include "Emu/IdManager.h" #define _PRGNAME_ "RPCS3" #define _PRGVER_ "0.0.0.5"