From d8239a39c91a3f816ae1ff012cb55864fa4d4af5 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 24 Dec 2014 02:38:13 +0300 Subject: [PATCH] std::shared_ptr in IdManager --- rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp | 8 +- rpcs3/Emu/CPU/CPUThreadManager.cpp | 20 +- rpcs3/Emu/CPU/CPUThreadManager.h | 6 +- rpcs3/Emu/Cell/SPUThread.cpp | 48 +-- rpcs3/Emu/Cell/SPUThread.h | 4 +- rpcs3/Emu/Event.cpp | 9 +- rpcs3/Emu/Event.h | 6 +- rpcs3/Emu/IdManager.h | 41 +-- rpcs3/Emu/SysCalls/Modules.h | 8 +- rpcs3/Emu/SysCalls/Modules/cellAdec.cpp | 17 +- rpcs3/Emu/SysCalls/Modules/cellAudio.cpp | 3 +- rpcs3/Emu/SysCalls/Modules/cellDmux.cpp | 43 +-- rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp | 10 +- rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp | 10 +- rpcs3/Emu/SysCalls/Modules/cellVdec.cpp | 19 +- rpcs3/Emu/SysCalls/Modules/cellVpost.cpp | 7 +- rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp | 7 +- rpcs3/Emu/SysCalls/Modules/sys_fs.cpp | 6 +- rpcs3/Emu/SysCalls/SysCalls.cpp | 9 +- rpcs3/Emu/SysCalls/SysCalls.h | 17 +- rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp | 46 ++- rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp | 18 +- rpcs3/Emu/SysCalls/lv2/sys_cond.cpp | 28 +- rpcs3/Emu/SysCalls/lv2/sys_cond.h | 4 +- rpcs3/Emu/SysCalls/lv2/sys_event.cpp | 25 +- rpcs3/Emu/SysCalls/lv2/sys_event.h | 10 +- rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp | 17 +- rpcs3/Emu/SysCalls/lv2/sys_interrupt.cpp | 4 +- rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp | 23 +- rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp | 37 ++- rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h | 2 +- rpcs3/Emu/SysCalls/lv2/sys_memory.cpp | 8 +- rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp | 14 +- rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp | 32 +- rpcs3/Emu/SysCalls/lv2/sys_mutex.h | 4 +- rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp | 14 +- rpcs3/Emu/SysCalls/lv2/sys_process.cpp | 78 ++--- rpcs3/Emu/SysCalls/lv2/sys_prx.cpp | 8 +- rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp | 17 +- rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp | 22 +- rpcs3/Emu/SysCalls/lv2/sys_spu.cpp | 147 ++++----- rpcs3/Emu/SysCalls/lv2/sys_spu.h | 4 +- rpcs3/Emu/SysCalls/lv2/sys_timer.cpp | 15 +- rpcs3/Emu/SysCalls/lv2/sys_vm.cpp | 6 +- rpcs3/Emu/System.cpp | 62 ++-- rpcs3/Gui/InterpreterDisAsm.cpp | 11 +- rpcs3/Gui/KernelExplorer.cpp | 322 +++++++++---------- 47 files changed, 654 insertions(+), 622 deletions(-) diff --git a/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp b/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp index 151d12ae21..562193cb22 100644 --- a/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp +++ b/rpcs3/Emu/ARMv7/Modules/sceLibKernel.cpp @@ -121,7 +121,7 @@ s32 sceKernelStartThread(s32 threadId, u32 argSize, vm::psv::ptr pAr { sceLibKernel.Error("sceKernelStartThread(threadId=%d, argSize=%d, pArgBlock_addr=0x%x)", threadId, argSize, pArgBlock.addr()); - CPUThread* t = Emu.GetCPU().GetThread(threadId); + std::shared_ptr t = Emu.GetCPU().GetThread(threadId); if (!t || t->GetType() != CPU_THREAD_ARMv7) { @@ -129,12 +129,12 @@ s32 sceKernelStartThread(s32 threadId, u32 argSize, vm::psv::ptr pAr } // push arg block onto the stack - u32 pos = (static_cast(t)->SP -= argSize); + u32 pos = (static_cast(t.get())->SP -= argSize); memcpy(vm::get_ptr(pos), pArgBlock.get_ptr(), argSize); // set SceKernelThreadEntry function arguments - static_cast(t)->write_gpr(0, argSize); - static_cast(t)->write_gpr(1, pos); + static_cast(t.get())->write_gpr(0, argSize); + static_cast(t.get())->write_gpr(1, pos); t->Exec(); return SCE_OK; diff --git a/rpcs3/Emu/CPU/CPUThreadManager.cpp b/rpcs3/Emu/CPU/CPUThreadManager.cpp index 2ddeac6406..2ee3133bf0 100644 --- a/rpcs3/Emu/CPU/CPUThreadManager.cpp +++ b/rpcs3/Emu/CPU/CPUThreadManager.cpp @@ -28,28 +28,28 @@ CPUThread& CPUThreadManager::AddThread(CPUThreadType type) { std::lock_guard lock(m_mtx_thread); - CPUThread* new_thread; + std::shared_ptr new_thread; switch(type) { case CPU_THREAD_PPU: { - new_thread = new PPUThread(); + new_thread.reset(new PPUThread()); break; } case CPU_THREAD_SPU: { - new_thread = new SPUThread(); + new_thread.reset(new SPUThread()); break; } case CPU_THREAD_RAW_SPU: { - new_thread = new RawSPUThread(); + new_thread.reset(new RawSPUThread()); break; } case CPU_THREAD_ARMv7: { - new_thread = new ARMv7Thread(); + new_thread.reset(new ARMv7Thread()); break; } default: assert(0); @@ -58,7 +58,7 @@ CPUThread& CPUThreadManager::AddThread(CPUThreadType type) new_thread->SetId(Emu.GetIdManager().GetNewID(fmt::Format("%s Thread", new_thread->GetTypeString().c_str()), new_thread)); m_threads.push_back(new_thread); - SendDbgCommand(DID_CREATE_THREAD, new_thread); + SendDbgCommand(DID_CREATE_THREAD, new_thread.get()); return *new_thread; } @@ -67,7 +67,7 @@ void CPUThreadManager::RemoveThread(const u32 id) { std::lock_guard lock(m_mtx_thread); - CPUThread* thr = nullptr; + std::shared_ptr thr; u32 thread_index = 0; for (u32 i = 0; i < m_threads.size(); ++i) @@ -80,7 +80,7 @@ void CPUThreadManager::RemoveThread(const u32 id) if (thr) { - SendDbgCommand(DID_REMOVE_THREAD, thr); + SendDbgCommand(DID_REMOVE_THREAD, thr.get()); thr->Close(); m_threads.erase(m_threads.begin() + thread_index); @@ -106,9 +106,9 @@ s32 CPUThreadManager::GetThreadNumById(CPUThreadType type, u32 id) return -1; } -CPUThread* CPUThreadManager::GetThread(u32 id) +std::shared_ptr CPUThreadManager::GetThread(u32 id) { - CPUThread* res; + std::shared_ptr res; if (!id) return nullptr; diff --git a/rpcs3/Emu/CPU/CPUThreadManager.h b/rpcs3/Emu/CPU/CPUThreadManager.h index d43a7506c3..e3fc1df32b 100644 --- a/rpcs3/Emu/CPU/CPUThreadManager.h +++ b/rpcs3/Emu/CPU/CPUThreadManager.h @@ -6,7 +6,7 @@ enum CPUThreadType : unsigned char; class CPUThreadManager { - std::vector m_threads; + std::vector> m_threads; std::mutex m_mtx_thread; public: @@ -18,9 +18,9 @@ public: CPUThread& AddThread(CPUThreadType type); void RemoveThread(const u32 id); - std::vector& GetThreads() { return m_threads; } + //std::vector>& GetThreads() { return m_threads; } s32 GetThreadNumById(CPUThreadType type, u32 id); - CPUThread* GetThread(u32 id); + std::shared_ptr GetThread(u32 id); RawSPUThread* GetRawSPUThread(u32 num); void Exec(); diff --git a/rpcs3/Emu/Cell/SPUThread.cpp b/rpcs3/Emu/Cell/SPUThread.cpp index 778b42c621..a84523ee97 100644 --- a/rpcs3/Emu/Cell/SPUThread.cpp +++ b/rpcs3/Emu/Cell/SPUThread.cpp @@ -39,6 +39,10 @@ SPUThread::SPUThread(CPUThreadType type) : PPCThread(type) assert(type == CPU_THREAD_SPU || type == CPU_THREAD_RAW_SPU); group = nullptr; + for (auto& p : SPUPs) + { + p.reset(new EventPort()); + } Reset(); } @@ -138,12 +142,12 @@ void SPUThread::DoClose() } for (u32 i = 0; i < 64; i++) { - EventPort& port = SPUPs[i]; - std::lock_guard lock(port.m_mutex); - if (port.eq) + std::shared_ptr port = SPUPs[i]; + std::lock_guard lock(port->m_mutex); + if (port->eq) { - port.eq->ports.remove(&port); - port.eq = nullptr; + port->eq->ports.remove(port); + port->eq = nullptr; } } } @@ -210,17 +214,17 @@ void SPUThread::ProcessCmd(u32 cmd, u32 tag, u32 lsa, u64 ea, u32 size) return; } - SPUThread* spu = (SPUThread*)Emu.GetCPU().GetThread(group->list[num]); + std::shared_ptr spu = Emu.GetCPU().GetThread(group->list[num]); u32 addr = (ea & SYS_SPU_THREAD_BASE_MASK) % SYS_SPU_THREAD_OFFSET; if ((addr <= 0x3ffff) && (addr + size <= 0x40000)) { // LS access - ea = spu->ls_offset + addr; + ea = ((SPUThread*)spu.get())->ls_offset + addr; } else if ((cmd & MFC_PUT_CMD) && size == 4 && (addr == SYS_SPU_THREAD_SNR1 || addr == SYS_SPU_THREAD_SNR2)) { - spu->WriteSNR(SYS_SPU_THREAD_SNR2 == addr, vm::read32(ls_offset + lsa)); + ((SPUThread*)spu.get())->WriteSNR(SYS_SPU_THREAD_SNR2 == addr, vm::read32(ls_offset + lsa)); return; } else @@ -597,7 +601,7 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) } } m_intrtag[2].stat |= 1; - if (CPUThread* t = Emu.GetCPU().GetThread(m_intrtag[2].thread)) + if (std::shared_ptr t = Emu.GetCPU().GetThread(m_intrtag[2].thread)) { if (t->GetType() == CPU_THREAD_PPU) { @@ -607,7 +611,7 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) Emu.Pause(); return; } - PPUThread& ppu = *(PPUThread*)t; + PPUThread& ppu = *(PPUThread*)t.get(); ppu.GPR[3] = ppu.m_interrupt_arg; ppu.FastCall2(vm::read32(ppu.entry), vm::read32(ppu.entry + 4)); } @@ -634,18 +638,18 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) LOG_NOTICE(Log::SPU, "sys_spu_thread_send_event(spup=%d, data0=0x%x, data1=0x%x)", spup, v & 0x00ffffff, data); } - EventPort& port = SPUPs[spup]; + std::shared_ptr port = SPUPs[spup]; - std::lock_guard lock(port.m_mutex); + std::lock_guard lock(port->m_mutex); - if (!port.eq) + if (!port->eq) { LOG_WARNING(Log::SPU, "sys_spu_thread_send_event(spup=%d, data0=0x%x, data1=0x%x): event queue not connected", spup, (v & 0x00ffffff), data); SPU.In_MBox.PushUncond(CELL_ENOTCONN); // TODO: check error passing return; } - if (!port.eq->events.push(SYS_SPU_THREAD_EVENT_USER_KEY, GetId(), ((u64)spup << 32) | (v & 0x00ffffff), data)) + if (!port->eq->events.push(SYS_SPU_THREAD_EVENT_USER_KEY, GetId(), ((u64)spup << 32) | (v & 0x00ffffff), data)) { SPU.In_MBox.PushUncond(CELL_EBUSY); return; @@ -672,18 +676,18 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) LOG_WARNING(Log::SPU, "sys_spu_thread_throw_event(spup=%d, data0=0x%x, data1=0x%x)", spup, v & 0x00ffffff, data); } - EventPort& port = SPUPs[spup]; + std::shared_ptr port = SPUPs[spup]; - std::lock_guard lock(port.m_mutex); + std::lock_guard lock(port->m_mutex); - if (!port.eq) + if (!port->eq) { LOG_WARNING(Log::SPU, "sys_spu_thread_throw_event(spup=%d, data0=0x%x, data1=0x%x): event queue not connected", spup, (v & 0x00ffffff), data); return; } // TODO: check passing spup value - if (!port.eq->events.push(SYS_SPU_THREAD_EVENT_USER_KEY, GetId(), ((u64)spup << 32) | (v & 0x00ffffff), data)) + if (!port->eq->events.push(SYS_SPU_THREAD_EVENT_USER_KEY, GetId(), ((u64)spup << 32) | (v & 0x00ffffff), data)) { LOG_WARNING(Log::SPU, "sys_spu_thread_throw_event(spup=%d, data0=0x%x, data1=0x%x) failed (queue is full)", spup, (v & 0x00ffffff), data); return; @@ -714,7 +718,7 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) LOG_WARNING(Log::SPU, "sys_event_flag_set_bit(id=%d, v=0x%x (flag=%d))", data, v, flag); } - EventFlag* ef; + std::shared_ptr ef; if (!Emu.GetIdManager().GetIDData(data, ef)) { LOG_ERROR(Log::SPU, "sys_event_flag_set_bit(id=%d, v=0x%x (flag=%d)): EventFlag not found", data, v, flag); @@ -755,7 +759,7 @@ void SPUThread::WriteChannel(u32 ch, const u128& r) LOG_WARNING(Log::SPU, "sys_event_flag_set_bit_impatient(id=%d, v=0x%x (flag=%d))", data, v, flag); } - EventFlag* ef; + std::shared_ptr ef; if (!Emu.GetIdManager().GetIDData(data, ef)) { LOG_WARNING(Log::SPU, "sys_event_flag_set_bit_impatient(id=%d, v=0x%x (flag=%d)): EventFlag not found", data, v, flag); @@ -1073,7 +1077,7 @@ void SPUThread::StopAndSignal(u32 code) LOG_NOTICE(Log::SPU, "sys_spu_thread_receive_event(spuq=0x%x)", spuq); } - EventQueue* eq; + std::shared_ptr eq; if (!SPUQs.GetEventQueue(FIX_SPUQ(spuq), eq)) { SPU.In_MBox.PushUncond(CELL_EINVAL); // TODO: check error value @@ -1159,7 +1163,7 @@ void SPUThread::StopAndSignal(u32 code) group->m_exit_status = SPU.Out_MBox.GetValue(); for (auto& v : group->list) { - if (CPUThread* t = Emu.GetCPU().GetThread(v)) + if (std::shared_ptr t = Emu.GetCPU().GetThread(v)) { t->Stop(); } diff --git a/rpcs3/Emu/Cell/SPUThread.h b/rpcs3/Emu/Cell/SPUThread.h index ff37e9660c..0b685d40b4 100644 --- a/rpcs3/Emu/Cell/SPUThread.h +++ b/rpcs3/Emu/Cell/SPUThread.h @@ -283,9 +283,9 @@ public: u64 R_ADDR; // reservation address u64 R_DATA[16]; // lock line data (BE) - EventPort SPUPs[64]; // SPU Thread Event Ports + std::shared_ptr SPUPs[64]; // SPU Thread Event Ports EventManager SPUQs; // SPU Queue Mapping - SpuGroupInfo* group; // associated SPU Thread Group (null for raw spu) + std::shared_ptr group; // associated SPU Thread Group (null for raw spu) u64 m_dec_start; // timestamp of writing decrementer value u32 m_dec_value; // written decrementer value diff --git a/rpcs3/Emu/Event.cpp b/rpcs3/Emu/Event.cpp index b3cdb2931f..2f6be5f107 100644 --- a/rpcs3/Emu/Event.cpp +++ b/rpcs3/Emu/Event.cpp @@ -23,7 +23,7 @@ bool EventManager::CheckKey(u64 key) return key_map.find(key) != key_map.end(); } -bool EventManager::RegisterKey(EventQueue* data, u64 key) +bool EventManager::RegisterKey(std::shared_ptr& data, u64 key) { if (!key) return true; std::lock_guard lock(m_lock); @@ -40,7 +40,7 @@ bool EventManager::RegisterKey(EventQueue* data, u64 key) return true; } -bool EventManager::GetEventQueue(u64 key, EventQueue*& data) +bool EventManager::GetEventQueue(u64 key, std::shared_ptr& data) { data = nullptr; if (!key) return false; @@ -79,8 +79,7 @@ bool EventManager::SendEvent(u64 key, u64 source, u64 d1, u64 d2, u64 d3) { return false; } - EventQueue* eq = f->second; - - eq->events.push(source, d1, d2, d3); + + f->second->events.push(source, d1, d2, d3); return true; } diff --git a/rpcs3/Emu/Event.h b/rpcs3/Emu/Event.h index a1f27901c8..eadcb533f3 100644 --- a/rpcs3/Emu/Event.h +++ b/rpcs3/Emu/Event.h @@ -6,14 +6,14 @@ struct EventQueue; class EventManager { std::mutex m_lock; - std::unordered_map key_map; + std::unordered_map> key_map; public: void Init(); void Clear(); bool CheckKey(u64 key); - bool RegisterKey(EventQueue* data, u64 key); - bool GetEventQueue(u64 key, EventQueue*& data); + bool RegisterKey(std::shared_ptr& data, u64 key); + bool GetEventQueue(u64 key, std::shared_ptr& data); bool UnregisterKey(u64 key); bool SendEvent(u64 key, u64 source, u64 d1, u64 d2, u64 d3); }; diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index a5ba1b1447..f335e20631 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -48,14 +48,14 @@ public: m_destr(m_ptr); } - template T* get() + template std::shared_ptr get() { - return (T*)m_ptr; + return *(std::shared_ptr*)m_ptr; } - template const T* get() const + template std::shared_ptr get() const { - return (const T*)m_ptr; + return *(std::shared_ptr*)m_ptr; } }; @@ -67,11 +67,11 @@ class ID public: template - ID(const std::string& name, T* data, const IDType type) + ID(const std::string& name, std::shared_ptr& data, const IDType type) : m_name(name) , m_type(type) { - m_data = new IDData(data, [](void *ptr) -> void { delete (T*)ptr; }); + m_data = new IDData(new std::shared_ptr(data), [](void *ptr) -> void { delete (std::shared_ptr*)ptr; }); } ID() : m_data(nullptr) @@ -85,6 +85,7 @@ public: m_data = other.m_data; other.m_data = nullptr; } + ID& operator=(ID&& other) { std::swap(m_name,other.m_name); @@ -159,7 +160,7 @@ public: = char #endif > - u32 GetNewID(const std::string& name = "", T* data = nullptr, const IDType type = TYPE_OTHER) + u32 GetNewID(const std::string& name = "", std::shared_ptr& data = nullptr, const IDType type = TYPE_OTHER) { std::lock_guard lock(m_mtx_main); @@ -179,7 +180,7 @@ public: } template - bool GetIDData(const u32 id, T*& result) + bool GetIDData(const u32 id, std::shared_ptr& result) { std::lock_guard lock(m_mtx_main); @@ -224,17 +225,17 @@ public: return true; } - u32 GetTypeCount(IDType type) - { - if (type < TYPE_OTHER) { - return (u32)m_types[type].size(); - } - return 1; - } + //u32 GetTypeCount(IDType type) + //{ + // if (type < TYPE_OTHER) { + // return (u32)m_types[type].size(); + // } + // return 1; + //} - const std::set& GetTypeIDs(IDType type) - { - assert(type < TYPE_OTHER); - return m_types[type]; - } + //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 0ee2ddd9f4..5874dc6fc5 100644 --- a/rpcs3/Emu/SysCalls/Modules.h +++ b/rpcs3/Emu/SysCalls/Modules.h @@ -95,7 +95,8 @@ public: public: bool CheckID(u32 id) const; - template bool CheckId(u32 id, T*& data) + + template bool CheckId(u32 id, std::shared_ptr& data) { ID* id_data; @@ -106,7 +107,7 @@ public: return true; } - template bool CheckId(u32 id, T*& data, IDType& type) + template bool CheckId(u32 id, std::shared_ptr& data, IDType& type) { ID* id_data; @@ -117,10 +118,11 @@ public: return true; } + bool CheckID(u32 id, ID*& _id) const; template - u32 GetNewId(T* data, IDType type = TYPE_OTHER) + u32 GetNewId(std::shared_ptr& data, IDType type = TYPE_OTHER) { return GetIdManager().GetNewID(GetName(), data, type); } diff --git a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp index c6fecc11ba..1eda5de2f9 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAdec.cpp @@ -216,9 +216,10 @@ next: u32 adecOpen(AudioDecoder* data) { + std::shared_ptr data_ptr(data); AudioDecoder& adec = *data; - u32 adec_id = cellAdec->GetNewId(data); + u32 adec_id = cellAdec->GetNewId(data_ptr); adec.id = adec_id; @@ -231,7 +232,7 @@ u32 adecOpen(AudioDecoder* data) adec.adecCb->InitRegs(); adec.adecCb->DoRun(); - thread t("Audio Decoder[" + std::to_string(adec_id) + "] Thread", [&]() + thread t("Audio Decoder[" + std::to_string(adec_id) + "] Thread", [&, data_ptr]() { cellAdec->Notice("Audio Decoder thread started"); @@ -554,7 +555,7 @@ int cellAdecClose(u32 handle) { cellAdec->Warning("cellAdecClose(handle=%d)", handle); - AudioDecoder* adec; + std::shared_ptr adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; @@ -582,7 +583,7 @@ int cellAdecStartSeq(u32 handle, u32 param_addr) { cellAdec->Warning("cellAdecStartSeq(handle=%d, param_addr=0x%x)", handle, param_addr); - AudioDecoder* adec; + std::shared_ptr adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; @@ -634,7 +635,7 @@ int cellAdecEndSeq(u32 handle) { cellAdec->Warning("cellAdecEndSeq(handle=%d)", handle); - AudioDecoder* adec; + std::shared_ptr adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; @@ -648,7 +649,7 @@ int cellAdecDecodeAu(u32 handle, vm::ptr auInfo) { cellAdec->Log("cellAdecDecodeAu(handle=%d, auInfo_addr=0x%x)", handle, auInfo.addr()); - AudioDecoder* adec; + std::shared_ptr adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; @@ -670,7 +671,7 @@ int cellAdecGetPcm(u32 handle, vm::ptr outBuffer) { cellAdec->Log("cellAdecGetPcm(handle=%d, outBuffer_addr=0x%x)", handle, outBuffer.addr()); - AudioDecoder* adec; + std::shared_ptr adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; @@ -784,7 +785,7 @@ int cellAdecGetPcmItem(u32 handle, vm::ptr pcmItem_ptr) { cellAdec->Log("cellAdecGetPcmItem(handle=%d, pcmItem_ptr_addr=0x%x)", handle, pcmItem_ptr.addr()); - AudioDecoder* adec; + std::shared_ptr adec; if (!Emu.GetIdManager().GetIDData(handle, adec)) { return CELL_ADEC_ERROR_ARG; diff --git a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp index 0e5bdc7e27..5fab1bb816 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellAudio.cpp @@ -752,11 +752,10 @@ int cellAudioCreateNotifyEventQueue(vm::ptr id, vm::ptr key) } event_key = (event_key << 48) | 0x80004d494f323221; // left part: 0x8000, 0x8001, 0x8002 ... - EventQueue* eq = new EventQueue(SYS_SYNC_FIFO, SYS_PPU_QUEUE, event_key, event_key, 32); + std::shared_ptr eq(new EventQueue(SYS_SYNC_FIFO, SYS_PPU_QUEUE, event_key, event_key, 32)); if (!Emu.GetEventManager().RegisterKey(eq, event_key)) { - delete eq; return CELL_AUDIO_ERROR_EVENT_QUEUE; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index 7c340a8950..eb31b171c0 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -298,9 +298,10 @@ void dmuxQueryEsAttr(u32 info_addr /* may be 0 */, vm::ptr data_ptr(data); Demuxer& dmux = *data; - u32 dmux_id = cellDmux->GetNewId(data); + u32 dmux_id = cellDmux->GetNewId(data_ptr); dmux.id = dmux_id; @@ -313,7 +314,7 @@ u32 dmuxOpen(Demuxer* data) dmux.dmuxCb->InitRegs(); dmux.dmuxCb->DoRun(); - thread t("Demuxer[" + std::to_string(dmux_id) + "] Thread", [&]() + thread t("Demuxer[" + std::to_string(dmux_id) + "] Thread", [&, data_ptr]() { cellDmux->Notice("Demuxer thread started (mem=0x%x, size=0x%x, cb=0x%x, arg=0x%x)", dmux.memAddr, dmux.memSize, dmux.cbFunc, dmux.cbArg); @@ -851,7 +852,7 @@ int cellDmuxClose(u32 demuxerHandle) { cellDmux->Warning("cellDmuxClose(demuxerHandle=%d)", demuxerHandle); - Demuxer* dmux; + std::shared_ptr dmux; if (!Emu.GetIdManager().GetIDData(demuxerHandle, dmux)) { return CELL_DMUX_ERROR_ARG; @@ -881,7 +882,7 @@ int cellDmuxSetStream(u32 demuxerHandle, const u32 streamAddress, u32 streamSize cellDmux->Log("cellDmuxSetStream(demuxerHandle=%d, streamAddress=0x%x, streamSize=%d, discontinuity=%d, userData=0x%llx", demuxerHandle, streamAddress, streamSize, discontinuity, userData); - Demuxer* dmux; + std::shared_ptr dmux; if (!Emu.GetIdManager().GetIDData(demuxerHandle, dmux)) { return CELL_DMUX_ERROR_ARG; @@ -908,7 +909,7 @@ int cellDmuxResetStream(u32 demuxerHandle) { cellDmux->Warning("cellDmuxResetStream(demuxerHandle=%d)", demuxerHandle); - Demuxer* dmux; + std::shared_ptr dmux; if (!Emu.GetIdManager().GetIDData(demuxerHandle, dmux)) { return CELL_DMUX_ERROR_ARG; @@ -922,7 +923,7 @@ int cellDmuxResetStreamAndWaitDone(u32 demuxerHandle) { cellDmux->Warning("cellDmuxResetStreamAndWaitDone(demuxerHandle=%d)", demuxerHandle); - Demuxer* dmux; + std::shared_ptr dmux; if (!Emu.GetIdManager().GetIDData(demuxerHandle, dmux)) { return CELL_DMUX_ERROR_ARG; @@ -981,7 +982,7 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr esFil "esSpecificInfo_addr=0x%x, esHandle_addr=0x%x)", demuxerHandle, esFilterId.addr(), esResourceInfo.addr(), esCb.addr(), esSpecificInfo_addr, esHandle.addr()); - Demuxer* dmux; + std::shared_ptr dmux; if (!Emu.GetIdManager().GetIDData(demuxerHandle, dmux)) { return CELL_DMUX_ERROR_ARG; @@ -989,9 +990,9 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr esFil // TODO: check esFilterId, esResourceInfo, esCb and esSpecificInfo correctly - ElementaryStream* es = new ElementaryStream(dmux, esResourceInfo->memAddr, esResourceInfo->memSize, + std::shared_ptr es(new ElementaryStream(dmux.get(), esResourceInfo->memAddr, esResourceInfo->memSize, esFilterId->filterIdMajor, esFilterId->filterIdMinor, esFilterId->supplementalInfo1, esFilterId->supplementalInfo2, - vm::ptr::make(esCb->cbEsMsgFunc.addr()), esCb->cbArg, esSpecificInfo_addr); + vm::ptr::make(esCb->cbEsMsgFunc.addr()), esCb->cbArg, esSpecificInfo_addr)); u32 id = cellDmux->GetNewId(es); es->id = id; @@ -1002,7 +1003,7 @@ int cellDmuxEnableEs(u32 demuxerHandle, vm::ptr esFil DemuxerTask task(dmuxEnableEs); task.es.es = id; - task.es.es_ptr = es; + task.es.es_ptr = es.get(); dmux->job.Push(task, &dmux->is_closed); return CELL_OK; @@ -1012,7 +1013,7 @@ int cellDmuxDisableEs(u32 esHandle) { cellDmux->Warning("cellDmuxDisableEs(esHandle=0x%x)", esHandle); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1020,7 +1021,7 @@ int cellDmuxDisableEs(u32 esHandle) DemuxerTask task(dmuxDisableEs); task.es.es = esHandle; - task.es.es_ptr = es; + task.es.es_ptr = es.get(); es->dmux->job.Push(task, &es->dmux->is_closed); return CELL_OK; @@ -1030,7 +1031,7 @@ int cellDmuxResetEs(u32 esHandle) { cellDmux->Log("cellDmuxResetEs(esHandle=0x%x)", esHandle); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1038,7 +1039,7 @@ int cellDmuxResetEs(u32 esHandle) DemuxerTask task(dmuxResetEs); task.es.es = esHandle; - task.es.es_ptr = es; + task.es.es_ptr = es.get(); es->dmux->job.Push(task, &es->dmux->is_closed); return CELL_OK; @@ -1049,7 +1050,7 @@ int cellDmuxGetAu(u32 esHandle, vm::ptr auInfo_ptr, vm::ptr auSpecific cellDmux->Log("cellDmuxGetAu(esHandle=0x%x, auInfo_ptr_addr=0x%x, auSpecificInfo_ptr_addr=0x%x)", esHandle, auInfo_ptr.addr(), auSpecificInfo_ptr.addr()); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1072,7 +1073,7 @@ int cellDmuxPeekAu(u32 esHandle, vm::ptr auInfo_ptr, vm::ptr auSpecifi cellDmux->Log("cellDmuxPeekAu(esHandle=0x%x, auInfo_ptr_addr=0x%x, auSpecificInfo_ptr_addr=0x%x)", esHandle, auInfo_ptr.addr(), auSpecificInfo_ptr.addr()); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1095,7 +1096,7 @@ int cellDmuxGetAuEx(u32 esHandle, vm::ptr auInfoEx_ptr, vm::ptr auSpec cellDmux->Log("cellDmuxGetAuEx(esHandle=0x%x, auInfoEx_ptr_addr=0x%x, auSpecificInfo_ptr_addr=0x%x)", esHandle, auInfoEx_ptr.addr(), auSpecificInfo_ptr.addr()); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1118,7 +1119,7 @@ int cellDmuxPeekAuEx(u32 esHandle, vm::ptr auInfoEx_ptr, vm::ptr auSpe cellDmux->Log("cellDmuxPeekAuEx(esHandle=0x%x, auInfoEx_ptr_addr=0x%x, auSpecificInfo_ptr_addr=0x%x)", esHandle, auInfoEx_ptr.addr(), auSpecificInfo_ptr.addr()); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1140,7 +1141,7 @@ int cellDmuxReleaseAu(u32 esHandle) { cellDmux->Log("cellDmuxReleaseAu(esHandle=0x%x)", esHandle); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1157,7 +1158,7 @@ int cellDmuxFlushEs(u32 esHandle) { cellDmux->Warning("cellDmuxFlushEs(esHandle=0x%x)", esHandle); - ElementaryStream* es; + std::shared_ptr es; if (!Emu.GetIdManager().GetIDData(esHandle, es)) { return CELL_DMUX_ERROR_ARG; @@ -1165,7 +1166,7 @@ int cellDmuxFlushEs(u32 esHandle) DemuxerTask task(dmuxFlushEs); task.es.es = esHandle; - task.es.es_ptr = es; + task.es.es_ptr = es.get(); es->dmux->job.Push(task, &es->dmux->is_closed); return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp index db9da02789..8f214be1fc 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp @@ -26,7 +26,7 @@ int cellGifDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptrWarning("cellGifDecOpen(mainHandle=0x%x, subHandle_addr=0x%x, src_addr=0x%x, openInfo_addr=0x%x)", mainHandle, subHandle.addr(), src.addr(), openInfo.addr()); - CellGifDecSubHandle *current_subHandle = new CellGifDecSubHandle; + std::shared_ptr current_subHandle(new CellGifDecSubHandle); current_subHandle->fd = 0; current_subHandle->src = *src; @@ -62,7 +62,7 @@ int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr cellGifDec->Warning("cellGifDecReadHeader(mainHandle=0x%x, subHandle=0x%x, info_addr=0x%x)", mainHandle, subHandle, info.addr()); - CellGifDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellGifDec->CheckId(subHandle, subHandle_data)) return CELL_GIFDEC_ERROR_FATAL; @@ -112,7 +112,7 @@ int cellGifDecSetParameter(u32 mainHandle, u32 subHandle, vm::ptrWarning("cellGifDecSetParameter(mainHandle=0x%x, subHandle=0x%x, inParam_addr=0x%x, outParam_addr=0x%x)", mainHandle, subHandle, inParam.addr(), outParam.addr()); - CellGifDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellGifDec->CheckId(subHandle, subHandle_data)) return CELL_GIFDEC_ERROR_FATAL; @@ -144,7 +144,7 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt dataOutInfo->status = CELL_GIFDEC_DEC_STATUS_STOP; - CellGifDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellGifDec->CheckId(subHandle, subHandle_data)) return CELL_GIFDEC_ERROR_FATAL; @@ -259,7 +259,7 @@ int cellGifDecClose(u32 mainHandle, u32 subHandle) cellGifDec->Warning("cellGifDecClose(mainHandle=0x%x, subHandle=0x%x)", mainHandle, subHandle); - CellGifDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellGifDec->CheckId(subHandle, subHandle_data)) return CELL_GIFDEC_ERROR_FATAL; diff --git a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp index 9ac73c1584..d068d229bf 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp @@ -31,7 +31,7 @@ int cellJpgDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptrWarning("cellJpgDecOpen(mainHandle=0x%x, subHandle_addr=0x%x, src_addr=0x%x, openInfo_addr=0x%x)", mainHandle, subHandle.addr(), src.addr(), openInfo.addr()); - CellJpgDecSubHandle *current_subHandle = new CellJpgDecSubHandle; + std::shared_ptr current_subHandle(new CellJpgDecSubHandle); current_subHandle->fd = 0; current_subHandle->src = *src; @@ -68,7 +68,7 @@ int cellJpgDecClose(u32 mainHandle, u32 subHandle) cellJpgDec->Warning("cellJpgDecOpen(mainHandle=0x%x, subHandle=0x%x)", mainHandle, subHandle); - CellJpgDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellJpgDec->CheckId(subHandle, subHandle_data)) return CELL_JPGDEC_ERROR_FATAL; @@ -82,7 +82,7 @@ int cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr { cellJpgDec->Log("cellJpgDecReadHeader(mainHandle=0x%x, subHandle=0x%x, info_addr=0x%x)", mainHandle, subHandle, info.addr()); - CellJpgDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellJpgDec->CheckId(subHandle, subHandle_data)) return CELL_JPGDEC_ERROR_FATAL; @@ -151,7 +151,7 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt mainHandle, subHandle, data.addr(), dataCtrlParam.addr(), dataOutInfo.addr()); dataOutInfo->status = CELL_JPGDEC_DEC_STATUS_STOP; - CellJpgDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellJpgDec->CheckId(subHandle, subHandle_data)) return CELL_JPGDEC_ERROR_FATAL; @@ -281,7 +281,7 @@ int cellJpgDecSetParameter(u32 mainHandle, u32 subHandle, vm::ptrLog("cellJpgDecSetParameter(mainHandle=0x%x, subHandle=0x%x, inParam_addr=0x%x, outParam_addr=0x%x)", mainHandle, subHandle, inParam.addr(), outParam.addr()); - CellJpgDecSubHandle* subHandle_data; + std::shared_ptr subHandle_data; if(!cellJpgDec->CheckId(subHandle, subHandle_data)) return CELL_JPGDEC_ERROR_FATAL; diff --git a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp index 3474b9bde8..65c8d840aa 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVdec.cpp @@ -206,9 +206,10 @@ u32 vdecQueryAttr(CellVdecCodecType type, u32 profile, u32 spec_addr /* may be 0 u32 vdecOpen(VideoDecoder* data) { + std::shared_ptr data_ptr(data); VideoDecoder& vdec = *data; - u32 vdec_id = cellVdec->GetNewId(data); + u32 vdec_id = cellVdec->GetNewId(data_ptr); vdec.id = vdec_id; @@ -221,7 +222,7 @@ u32 vdecOpen(VideoDecoder* data) vdec.vdecCb->InitRegs(); vdec.vdecCb->DoRun(); - thread t("Video Decoder[" + std::to_string(vdec_id) + "] Thread", [&]() + thread t("Video Decoder[" + std::to_string(vdec_id) + "] Thread", [&, data_ptr]() { cellVdec->Notice("Video Decoder thread started"); @@ -590,7 +591,7 @@ int cellVdecClose(u32 handle) { cellVdec->Warning("cellVdecClose(handle=%d)", handle); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; @@ -618,7 +619,7 @@ int cellVdecStartSeq(u32 handle) { cellVdec->Log("cellVdecStartSeq(handle=%d)", handle); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; @@ -632,7 +633,7 @@ int cellVdecEndSeq(u32 handle) { cellVdec->Warning("cellVdecEndSeq(handle=%d)", handle); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; @@ -646,7 +647,7 @@ int cellVdecDecodeAu(u32 handle, CellVdecDecodeMode mode, vm::ptrLog("cellVdecDecodeAu(handle=%d, mode=0x%x, auInfo_addr=0x%x)", handle, mode, auInfo.addr()); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; @@ -670,7 +671,7 @@ int cellVdecGetPicture(u32 handle, vm::ptr format, vm:: { cellVdec->Log("cellVdecGetPicture(handle=%d, format_addr=0x%x, outBuff_addr=0x%x)", handle, format.addr(), outBuff.addr()); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; @@ -726,7 +727,7 @@ int cellVdecGetPicItem(u32 handle, vm::ptr picItem_ptr) { cellVdec->Log("cellVdecGetPicItem(handle=%d, picItem_ptr_addr=0x%x)", handle, picItem_ptr.addr()); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; @@ -871,7 +872,7 @@ int cellVdecSetFrameRate(u32 handle, CellVdecFrameRate frc) { cellVdec->Log("cellVdecSetFrameRate(handle=%d, frc=0x%x)", handle, frc); - VideoDecoder* vdec; + std::shared_ptr vdec; if (!Emu.GetIdManager().GetIDData(handle, vdec)) { return CELL_VDEC_ERROR_ARG; diff --git a/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp b/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp index d4790ca782..e393ba8d13 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellVpost.cpp @@ -28,7 +28,8 @@ int cellVpostQueryAttr(vm::ptr cfgParam, vm::ptrGetNewId(data); + std::shared_ptr data_ptr(data); + u32 id = cellVpost->GetNewId(data_ptr); cellVpost->Notice("*** Vpost instance created (to_rgba=%d): id = %d", data->to_rgba, id); @@ -59,7 +60,7 @@ int cellVpostClose(u32 handle) { cellVpost->Warning("cellVpostClose(handle=0x%x)", handle); - VpostInstance* vpost; + std::shared_ptr vpost; if (!Emu.GetIdManager().GetIDData(handle, vpost)) { return CELL_VPOST_ERROR_C_ARG_HDL_INVALID; @@ -75,7 +76,7 @@ int cellVpostExec(u32 handle, vm::ptr inPicBuff, vm::ptrLog("cellVpostExec(handle=0x%x, inPicBuff_addr=0x%x, ctrlParam_addr=0x%x, outPicBuff_addr=0x%x, picInfo_addr=0x%x)", handle, inPicBuff.addr(), ctrlParam.addr(), outPicBuff.addr(), picInfo.addr()); - VpostInstance* vpost; + std::shared_ptr vpost; if (!Emu.GetIdManager().GetIDData(handle, vpost)) { return CELL_VPOST_ERROR_E_ARG_HDL_INVALID; diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index a21eb18ab2..30f9225ecd 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -33,7 +33,8 @@ int _sys_heap_create_heap(const u32 heap_addr, const u32 align, const u32 size) { sysPrxForUser->Warning("_sys_heap_create_heap(heap_addr=0x%x, align=0x%x, size=0x%x)", heap_addr, align, size); - u32 heap_id = sysPrxForUser->GetNewId(new HeapInfo(heap_addr, align, size)); + std::shared_ptr heap(new HeapInfo(heap_addr, align, size)); + u32 heap_id = sysPrxForUser->GetNewId(heap); sysPrxForUser->Warning("*** sys_heap created: id = %d", heap_id); return heap_id; } @@ -42,7 +43,7 @@ u32 _sys_heap_malloc(const u32 heap_id, const u32 size) { sysPrxForUser->Warning("_sys_heap_malloc(heap_id=%d, size=0x%x)", heap_id, size); - HeapInfo* heap; + std::shared_ptr heap; if(!sysPrxForUser->CheckId(heap_id, heap)) return CELL_ESRCH; return (u32)Memory.Alloc(size, 1); @@ -52,7 +53,7 @@ u32 _sys_heap_memalign(u32 heap_id, u32 align, u32 size) { sysPrxForUser->Warning("_sys_heap_memalign(heap_id=%d, align=0x%x, size=0x%x)", heap_id, align, size); - HeapInfo* heap; + std::shared_ptr heap; if(!sysPrxForUser->CheckId(heap_id, heap)) return CELL_ESRCH; return (u32)Memory.Alloc(size, align); diff --git a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp index 82a019a886..b9b89b5db7 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_fs.cpp @@ -168,7 +168,7 @@ void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptr orig_file; if (!sys_fs->CheckId(fd, orig_file)) { sys_fs->Error("Wrong fd (%s)", fd); @@ -178,7 +178,7 @@ void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptrsize; - vfsStream& file = *(vfsStream*)orig_file; + vfsStream& file = *(vfsStream*)orig_file.get(); const u64 old_pos = file.Tell(); file.Seek((u64)aio->offset); @@ -220,7 +220,7 @@ int cellFsAioRead(vm::ptr aio, vm::ptr aio_id, vm::ptr orig_file; u32 fd = aio->fd; if (!sys_fs->CheckId(fd, orig_file)) diff --git a/rpcs3/Emu/SysCalls/SysCalls.cpp b/rpcs3/Emu/SysCalls/SysCalls.cpp index 1a97b2290e..7f81d0f1a7 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.cpp +++ b/rpcs3/Emu/SysCalls/SysCalls.cpp @@ -35,8 +35,9 @@ #include "SysCalls.h" -namespace detail{ - template<> bool CheckId(u32 id, ID*& _id,const std::string &name) +namespace detail +{ + bool CheckIdID(u32 id, ID*& _id, const std::string &name) { return Emu.GetIdManager().CheckID(id) && (_id = &Emu.GetIdManager().GetID(id))->GetName() == name; } @@ -143,8 +144,8 @@ static func_caller* sc_table[kSyscallTableLength] = null_func,//bind_func(_sys_lwmutex_create), //95 (0x05F) // internal, used by sys_lwmutex_create null_func,//bind_func(_sys_lwmutex_destroy), //96 (0x060) // internal, used by sys_lwmutex_destroy null_func,//bind_func(_sys_lwmutex_lock), //97 (0x061) // internal, used by sys_lwmutex_lock - null_func,//bind_func(_sys_lwmutex_trylock), //98 (0x062) // internal, used by sys_lwmutex_unlock - null_func,//bind_func(_sys_lwmutex_unlock), //99 (0x063) // internal, used by sys_lwmutex_trylock + null_func,//bind_func(_sys_lwmutex_???lock), //98 (0x062) // internal, used by sys_lwmutex_unlock + null_func,//bind_func(_sys_lwmutex_???lock), //99 (0x063) // internal, used by sys_lwmutex_trylock bind_func(sys_mutex_create), //100 (0x064) bind_func(sys_mutex_destroy), //101 (0x065) bind_func(sys_mutex_lock), //102 (0x066) diff --git a/rpcs3/Emu/SysCalls/SysCalls.h b/rpcs3/Emu/SysCalls/SysCalls.h index f01e33ed14..5cf99e50cd 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.h +++ b/rpcs3/Emu/SysCalls/SysCalls.h @@ -7,16 +7,17 @@ class SysCallBase; -namespace detail{ - template bool CheckId(u32 id, T*& data,const std::string &name) +namespace detail +{ + bool CheckIdID(u32 id, ID*& _id, const std::string& name); + + template bool CheckId(u32 id, std::shared_ptr& data, const std::string& name) { ID* id_data; - if(!CheckId(id, id_data,name)) return false; + if(!CheckIdID(id, id_data, name)) return false; data = id_data->GetData()->get(); return true; } - - template<> bool CheckId(u32 id, ID*& _id,const std::string &name); } class SysCallBase : public LogBase @@ -44,13 +45,13 @@ public: } template - bool CheckId(u32 id, T*& data) const + bool CheckId(u32 id, std::shared_ptr& data) const { - return detail::CheckId(id,data,GetName()); + return detail::CheckId(id, data, GetName()); } template - u32 GetNewId(T* data, IDType type = TYPE_OTHER) + u32 GetNewId(std::shared_ptr& data, IDType type = TYPE_OTHER) { return GetIdManager().GetNewID(GetName(), data, type); } diff --git a/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp b/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp index 6a67a2c334..adc59aa65b 100644 --- a/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp @@ -100,11 +100,10 @@ s32 cellFsOpen(vm::ptr path, s32 flags, vm::ptr> fd, vm::p return CELL_ENOENT; } - vfsFileBase* stream = Emu.GetVFS().OpenFile(_path, o_mode); + std::shared_ptr stream(Emu.GetVFS().OpenFile(_path, o_mode)); if (!stream || !stream->IsOpened()) { - delete stream; sys_fs->Error("\"%s\" not found! flags: 0x%08x", path.get_ptr(), flags); return CELL_ENOENT; } @@ -123,7 +122,7 @@ s32 cellFsRead(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr> nread) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -146,7 +145,7 @@ s32 cellFsWrite(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; if (nbytes != (u32)nbytes) return CELL_ENOMEM; @@ -178,10 +177,9 @@ s32 cellFsOpendir(vm::ptr path, vm::ptr fd) LV2_LOCK(0); - vfsDirBase* dir = Emu.GetVFS().OpenDir(path.get_ptr()); + std::shared_ptr dir(Emu.GetVFS().OpenDir(path.get_ptr())); if (!dir || !dir->IsOpened()) { - delete dir; return CELL_ENOENT; } @@ -195,7 +193,7 @@ s32 cellFsReaddir(u32 fd, vm::ptr dir, vm::ptr nread) LV2_LOCK(0); - vfsDirBase* directory; + std::shared_ptr directory; if (!sys_fs->CheckId(fd, directory)) return CELL_ESRCH; @@ -277,7 +275,7 @@ s32 cellFsFstat(u32 fd, vm::ptr sb) LV2_LOCK(0); IDType type; - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) return CELL_ESRCH; @@ -427,7 +425,7 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr> pos) } IDType type; - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) return CELL_ESRCH; @@ -442,7 +440,7 @@ s32 cellFsFtruncate(u32 fd, u64 size) LV2_LOCK(0); IDType type; - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file, type) || type != TYPE_FS_FILE) return CELL_ESRCH; @@ -505,7 +503,7 @@ s32 cellFsFGetBlockSize(u32 fd, vm::ptr sector_size, vm::ptr block_siz LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -549,7 +547,7 @@ s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr entries, u32 LV2_LOCK(0); - vfsDirBase* directory; + std::shared_ptr directory; if (!sys_fs->CheckId(fd, directory)) return CELL_ESRCH; @@ -587,7 +585,7 @@ s32 cellFsStReadInit(u32 fd, vm::ptr ringbuf) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -614,7 +612,7 @@ s32 cellFsStReadFinish(u32 fd) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -630,7 +628,7 @@ s32 cellFsStReadGetRingBuf(u32 fd, vm::ptr ringbuf) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -647,7 +645,7 @@ s32 cellFsStReadGetStatus(u32 fd, vm::ptr status) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -662,7 +660,7 @@ s32 cellFsStReadGetRegid(u32 fd, vm::ptr regid) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -677,7 +675,7 @@ s32 cellFsStReadStart(u32 fd, u64 offset, u64 size) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -693,7 +691,7 @@ s32 cellFsStReadStop(u32 fd) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -708,7 +706,7 @@ s32 cellFsStRead(u32 fd, u32 buf_addr, u64 size, vm::ptr rsize) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -729,7 +727,7 @@ s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr addr, vm::ptr size) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -742,7 +740,7 @@ s32 cellFsStReadPutCurrentAddr(u32 fd, u32 addr_addr, u64 size) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -755,7 +753,7 @@ s32 cellFsStReadWait(u32 fd, u64 size) LV2_LOCK(0); - vfsStream* file; + std::shared_ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; @@ -768,7 +766,7 @@ s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptr file; if (!sys_fs->CheckId(fd, file)) return CELL_ESRCH; diff --git a/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp b/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp index d4c820f68e..6aaef287dc 100644 --- a/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sleep_queue_type.cpp @@ -65,19 +65,21 @@ u32 sleep_queue_t::pop(u32 protocol) u32 sel = 0; for (u32 i = 0; i < list.size(); i++) { - CPUThread* t = Emu.GetCPU().GetThread(list[i]); - if (!t) + if (std::shared_ptr t = Emu.GetCPU().GetThread(list[i])) + { + u64 prio = t->GetPrio(); + if (prio < highest_prio) + { + highest_prio = prio; + sel = i; + } + } + else { list[i] = 0; sel = i; break; } - u64 prio = t->GetPrio(); - if (prio < highest_prio) - { - highest_prio = prio; - sel = i; - } } u32 res = list[sel]; list.erase(list.begin() + sel); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp index d1416c7b9c..7c28ea29a8 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_cond.cpp @@ -27,13 +27,13 @@ s32 sys_cond_create(vm::ptr cond_id, u32 mutex_id, vm::ptr mutex; if (!Emu.GetIdManager().GetIDData(mutex_id, mutex)) { return CELL_ESRCH; } - Cond* cond = new Cond(mutex, attr->name_u64); + std::shared_ptr cond(new Cond(mutex, attr->name_u64)); const u32 id = sys_cond.GetNewId(cond, TYPE_COND); *cond_id = id; mutex->cond_count++; @@ -49,7 +49,7 @@ s32 sys_cond_destroy(u32 cond_id) LV2_LOCK(0); - Cond* cond; + std::shared_ptr cond; if (!Emu.GetIdManager().GetIDData(cond_id, cond)) { return CELL_ESRCH; @@ -70,13 +70,13 @@ s32 sys_cond_signal(u32 cond_id) { sys_cond.Log("sys_cond_signal(cond_id=%d)", cond_id); - Cond* cond; + std::shared_ptr cond; if (!Emu.GetIdManager().GetIDData(cond_id, cond)) { return CELL_ESRCH; } - Mutex* mutex = cond->mutex; + std::shared_ptr mutex = cond->mutex; if (u32 target = cond->queue.pop(mutex->protocol)) { @@ -95,13 +95,13 @@ s32 sys_cond_signal_all(u32 cond_id) { sys_cond.Log("sys_cond_signal_all(cond_id=%d)", cond_id); - Cond* cond; + std::shared_ptr cond; if (!Emu.GetIdManager().GetIDData(cond_id, cond)) { return CELL_ESRCH; } - Mutex* mutex = cond->mutex; + std::shared_ptr mutex = cond->mutex; while (u32 target = cond->queue.pop(mutex->protocol)) { @@ -121,7 +121,7 @@ s32 sys_cond_signal_to(u32 cond_id, u32 thread_id) { sys_cond.Log("sys_cond_signal_to(cond_id=%d, thread_id=%d)", cond_id, thread_id); - Cond* cond; + std::shared_ptr cond; if (!Emu.GetIdManager().GetIDData(cond_id, cond)) { return CELL_ESRCH; @@ -137,7 +137,7 @@ s32 sys_cond_signal_to(u32 cond_id, u32 thread_id) return CELL_EPERM; } - Mutex* mutex = cond->mutex; + std::shared_ptr mutex = cond->mutex; u32 target = thread_id; { @@ -156,13 +156,13 @@ s32 sys_cond_wait(PPUThread& CPU, u32 cond_id, u64 timeout) { sys_cond.Log("sys_cond_wait(cond_id=%d, timeout=%lld)", cond_id, timeout); - Cond* cond; + std::shared_ptr cond; if (!Emu.GetIdManager().GetIDData(cond_id, cond)) { return CELL_ESRCH; } - Mutex* mutex = cond->mutex; + std::shared_ptr mutex = cond->mutex; const u32 tid = CPU.GetId(); if (mutex->owner.read_sync() != tid) @@ -172,8 +172,8 @@ s32 sys_cond_wait(PPUThread& CPU, u32 cond_id, u64 timeout) cond->queue.push(tid, mutex->protocol); - auto old_recursive = mutex->recursive; - mutex->recursive = 0; + auto old_recursive = mutex->recursive_count.load(); + mutex->recursive_count = 0; if (!mutex->owner.compare_and_swap_test(tid, mutex->queue.pop(mutex->protocol))) { assert(!"sys_cond_wait() failed"); @@ -225,7 +225,7 @@ s32 sys_cond_wait(PPUThread& CPU, u32 cond_id, u64 timeout) } } - mutex->recursive = old_recursive; + mutex->recursive_count = old_recursive; cond->signal.Pop(cond_id /* unused result */, nullptr); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_cond.h b/rpcs3/Emu/SysCalls/lv2/sys_cond.h index 69e2faf27f..96938c0c41 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_cond.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_cond.h @@ -14,11 +14,11 @@ struct sys_cond_attribute struct Cond { - Mutex* mutex; // associated with mutex + std::shared_ptr mutex; // associated with mutex SQueue signal; sleep_queue_t queue; - Cond(Mutex* mutex, u64 name) + Cond(std::shared_ptr& mutex, u64 name) : mutex(mutex) , queue(name) { diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp index ae05dd4de3..065e2f1da6 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_event.cpp @@ -14,11 +14,10 @@ SysCallBase sys_event("sys_event"); u32 event_queue_create(u32 protocol, s32 type, u64 name_u64, u64 event_queue_key, s32 size) { - EventQueue* eq = new EventQueue(protocol, type, name_u64, event_queue_key, size); + std::shared_ptr eq(new EventQueue(protocol, type, name_u64, event_queue_key, size)); if (event_queue_key && !Emu.GetEventManager().RegisterKey(eq, event_queue_key)) { - delete eq; return 0; } @@ -73,7 +72,7 @@ s32 sys_event_queue_destroy(u32 equeue_id, int mode) { sys_event.Todo("sys_event_queue_destroy(equeue_id=%d, mode=0x%x)", equeue_id, mode); - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(equeue_id, eq)) { return CELL_ESRCH; @@ -119,7 +118,7 @@ s32 sys_event_queue_tryreceive(u32 equeue_id, vm::ptr event_arra sys_event.Todo("sys_event_queue_tryreceive(equeue_id=%d, event_array_addr=0x%x, size=%d, number_addr=0x%x)", equeue_id, event_array.addr(), size, number.addr()); - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(equeue_id, eq)) { return CELL_ESRCH; @@ -159,7 +158,7 @@ s32 sys_event_queue_receive(u32 equeue_id, vm::ptr dummy_event, sys_event.Log("sys_event_queue_receive(equeue_id=%d, dummy_event_addr=0x%x, timeout=%lld)", equeue_id, dummy_event.addr(), timeout); - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(equeue_id, eq)) { return CELL_ESRCH; @@ -236,7 +235,7 @@ s32 sys_event_queue_drain(u32 equeue_id) { sys_event.Log("sys_event_queue_drain(equeue_id=%d)", equeue_id); - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(equeue_id, eq)) { return CELL_ESRCH; @@ -249,7 +248,7 @@ s32 sys_event_queue_drain(u32 equeue_id) u32 event_port_create(u64 name) { - EventPort* eport = new EventPort(); + std::shared_ptr eport(new EventPort()); u32 id = sys_event.GetNewId(eport, TYPE_EVENT_PORT); eport->name = name ? name : ((u64)process_getpid() << 32) | (u64)id; sys_event.Warning("*** sys_event_port created: id = %d", id); @@ -275,7 +274,7 @@ s32 sys_event_port_destroy(u32 eport_id) { sys_event.Warning("sys_event_port_destroy(eport_id=%d)", eport_id); - EventPort* eport; + std::shared_ptr eport; if (!Emu.GetIdManager().GetIDData(eport_id, eport)) { return CELL_ESRCH; @@ -301,7 +300,7 @@ s32 sys_event_port_connect_local(u32 eport_id, u32 equeue_id) { sys_event.Warning("sys_event_port_connect_local(eport_id=%d, equeue_id=%d)", eport_id, equeue_id); - EventPort* eport; + std::shared_ptr eport; if (!Emu.GetIdManager().GetIDData(eport_id, eport)) { return CELL_ESRCH; @@ -318,7 +317,7 @@ s32 sys_event_port_connect_local(u32 eport_id, u32 equeue_id) return CELL_EISCONN; } - EventQueue* equeue; + std::shared_ptr equeue; if (!Emu.GetIdManager().GetIDData(equeue_id, equeue)) { sys_event.Error("sys_event_port_connect_local: event_queue(%d) not found!", equeue_id); @@ -339,7 +338,7 @@ s32 sys_event_port_disconnect(u32 eport_id) { sys_event.Warning("sys_event_port_disconnect(eport_id=%d)", eport_id); - EventPort* eport; + std::shared_ptr eport; if (!Emu.GetIdManager().GetIDData(eport_id, eport)) { return CELL_ESRCH; @@ -366,7 +365,7 @@ s32 sys_event_port_send(u32 eport_id, u64 data1, u64 data2, u64 data3) sys_event.Log("sys_event_port_send(eport_id=%d, data1=0x%llx, data2=0x%llx, data3=0x%llx)", eport_id, data1, data2, data3); - EventPort* eport; + std::shared_ptr eport; if (!Emu.GetIdManager().GetIDData(eport_id, eport)) { return CELL_ESRCH; @@ -374,7 +373,7 @@ s32 sys_event_port_send(u32 eport_id, u64 data1, u64 data2, u64 data3) std::lock_guard lock(eport->m_mutex); - EventQueue* eq = eport->eq; + std::shared_ptr eq = eport->eq; if (!eq) { return CELL_ENOTCONN; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event.h b/rpcs3/Emu/SysCalls/lv2/sys_event.h index 0d96819520..0fdfae8f4a 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_event.h @@ -56,7 +56,7 @@ struct EventQueue; struct EventPort { u64 name; // generated or user-specified code that is passed to sys_event_data struct - EventQueue* eq; // event queue this port has been connected to + std::shared_ptr eq; // event queue this port has been connected to std::mutex m_mutex; // may be locked until the event sending is finished EventPort(u64 name = 0) @@ -150,7 +150,7 @@ public: class EventPortList { - std::vector data; + std::vector> data; std::mutex m_mutex; public: @@ -167,18 +167,18 @@ public: data.clear(); } - void add(EventPort* port) + void add(std::shared_ptr& port) { std::lock_guard lock(m_mutex); data.push_back(port); } - void remove(EventPort* port) + void remove(std::shared_ptr& port) { std::lock_guard lock(m_mutex); for (u32 i = 0; i < data.size(); i++) { - if (data[i] == port) + if (data[i].get() == port.get()) { data.erase(data.begin() + i); return; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp b/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp index 909e31aa7b..66f74ff492 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_event_flag.cpp @@ -74,7 +74,8 @@ s32 sys_event_flag_create(vm::ptr eflag_id, vm::ptr at default: return CELL_EINVAL; } - u32 id = sys_event_flag.GetNewId(new EventFlag(init, (u32)attr->protocol, (int)attr->type), TYPE_EVENT_FLAG); + std::shared_ptr ef(new EventFlag(init, (u32)attr->protocol, (int)attr->type)); + u32 id = sys_event_flag.GetNewId(ef, TYPE_EVENT_FLAG); *eflag_id = id; sys_event_flag.Warning("*** event_flag created [%s] (protocol=0x%x, type=0x%x): id = %d", std::string(attr->name, 8).c_str(), (u32)attr->protocol, (int)attr->type, id); @@ -86,7 +87,7 @@ s32 sys_event_flag_destroy(u32 eflag_id) { sys_event_flag.Warning("sys_event_flag_destroy(eflag_id=%d)", eflag_id); - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; if (ef->waiters.size()) // ??? @@ -121,7 +122,7 @@ s32 sys_event_flag_wait(u32 eflag_id, u64 bitptn, u32 mode, vm::ptr result, default: return CELL_EINVAL; } - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); @@ -255,7 +256,7 @@ s32 sys_event_flag_trywait(u32 eflag_id, u64 bitptn, u32 mode, vm::ptr resu default: return CELL_EINVAL; } - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; std::lock_guard lock(ef->mutex); @@ -289,7 +290,7 @@ s32 sys_event_flag_set(u32 eflag_id, u64 bitptn) { sys_event_flag.Log("sys_event_flag_set(eflag_id=%d, bitptn=0x%llx)", eflag_id, bitptn); - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; std::lock_guard lock(ef->mutex); @@ -306,7 +307,7 @@ s32 sys_event_flag_clear(u32 eflag_id, u64 bitptn) { sys_event_flag.Log("sys_event_flag_clear(eflag_id=%d, bitptn=0x%llx)", eflag_id, bitptn); - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; std::lock_guard lock(ef->mutex); @@ -318,7 +319,7 @@ s32 sys_event_flag_cancel(u32 eflag_id, vm::ptr num) { sys_event_flag.Log("sys_event_flag_cancel(eflag_id=%d, num_addr=0x%x)", eflag_id, num.addr()); - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; std::vector tids; @@ -362,7 +363,7 @@ s32 sys_event_flag_get(u32 eflag_id, vm::ptr flags) return CELL_EFAULT; } - EventFlag* ef; + std::shared_ptr ef; if (!sys_event_flag.CheckId(eflag_id, ef)) return CELL_ESRCH; *flags = ef->flags.read_sync(); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_interrupt.cpp b/rpcs3/Emu/SysCalls/lv2/sys_interrupt.cpp index cd7f229b71..8ef3829ff5 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_interrupt.cpp @@ -60,7 +60,7 @@ s32 sys_interrupt_thread_establish(vm::ptr ih, u32 intrtag, u64 intrthread, return CELL_ESTAT; } - CPUThread* it = Emu.GetCPU().GetThread(intrthread); + std::shared_ptr it = Emu.GetCPU().GetThread(intrthread); if (!it) { return CELL_ESRCH; @@ -80,7 +80,7 @@ s32 sys_interrupt_thread_disestablish(u32 ih) { sys_interrupt.Todo("sys_interrupt_thread_disestablish(ih=%d)", ih); - CPUThread* it = Emu.GetCPU().GetThread(ih); + std::shared_ptr it = Emu.GetCPU().GetThread(ih); if (!it) { return CELL_ESRCH; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp index ff6e7ebf5a..60de22fef4 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwcond.cpp @@ -17,7 +17,8 @@ s32 lwcond_create(sys_lwcond_t& lwcond, sys_lwmutex_t& lwmutex, u64 name_u64) { LV2_LOCK(0); - u32 id = sys_lwcond.GetNewId(new Lwcond(name_u64), TYPE_LWCOND); + std::shared_ptr lw(new Lwcond(name_u64)); + u32 id = sys_lwcond.GetNewId(lw, TYPE_LWCOND); u32 addr = Memory.RealToVirtualAddr(&lwmutex); lwcond.lwmutex.set(addr); lwcond.lwcond_queue = id; @@ -48,7 +49,7 @@ s32 sys_lwcond_destroy(vm::ptr lwcond) u32 id = lwcond->lwcond_queue; - Lwcond* lw; + std::shared_ptr lw; if (!Emu.GetIdManager().GetIDData(id, lw)) { return CELL_ESRCH; @@ -68,7 +69,7 @@ s32 sys_lwcond_signal(vm::ptr lwcond) { sys_lwcond.Log("sys_lwcond_signal(lwcond_addr=0x%x)", lwcond.addr()); - Lwcond* lw; + std::shared_ptr lw; if (!Emu.GetIdManager().GetIDData((u32)lwcond->lwcond_queue, lw)) { return CELL_ESRCH; @@ -94,7 +95,7 @@ s32 sys_lwcond_signal_all(vm::ptr lwcond) { sys_lwcond.Log("sys_lwcond_signal_all(lwcond_addr=0x%x)", lwcond.addr()); - Lwcond* lw; + std::shared_ptr lw; if (!Emu.GetIdManager().GetIDData((u32)lwcond->lwcond_queue, lw)) { return CELL_ESRCH; @@ -120,7 +121,7 @@ s32 sys_lwcond_signal_to(vm::ptr lwcond, u32 ppu_thread_id) { sys_lwcond.Log("sys_lwcond_signal_to(lwcond_addr=0x%x, ppu_thread_id=%d)", lwcond.addr(), ppu_thread_id); - Lwcond* lw; + std::shared_ptr lw; if (!Emu.GetIdManager().GetIDData((u32)lwcond->lwcond_queue, lw)) { return CELL_ESRCH; @@ -154,7 +155,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) { sys_lwcond.Log("sys_lwcond_wait(lwcond_addr=0x%x, timeout=%lld)", lwcond.addr(), timeout); - Lwcond* lw; + std::shared_ptr lw; if (!Emu.GetIdManager().GetIDData((u32)lwcond->lwcond_queue, lw)) { return CELL_ESRCH; @@ -164,8 +165,8 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) u32 tid_le = CPU.GetId(); be_t tid = be_t::make(tid_le); - sleep_queue_t* sq = nullptr; - if (!Emu.GetIdManager().GetIDData((u32)mutex->sleep_queue, sq) && mutex->attribute.ToBE() != se32(SYS_SYNC_RETRY)) + std::shared_ptr sq; + if (!Emu.GetIdManager().GetIDData((u32)mutex->sleep_queue, sq)) { sys_lwcond.Warning("sys_lwcond_wait(id=%d): associated mutex had invalid sleep queue (%d)", (u32)lwcond->lwcond_queue, (u32)mutex->sleep_queue); @@ -179,8 +180,8 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) lw->queue.push(tid_le, mutex->attribute); - auto old_recursive = mutex->recursive_count; - mutex->recursive_count = 0; + auto old_recursive = mutex->recursive_count.read_relaxed(); + mutex->recursive_count.exchange(be_t::make(0)); be_t target = be_t::make(sq->pop(mutex->attribute)); if (!mutex->owner.compare_and_swap_test(tid, target)) @@ -254,7 +255,7 @@ s32 sys_lwcond_wait(PPUThread& CPU, vm::ptr lwcond, u64 timeout) } } - mutex->recursive_count = old_recursive; + mutex->recursive_count.exchange(old_recursive); lw->signal.Pop(tid_le /* unused result */, nullptr); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp index b27b3927c5..fe74347d36 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.cpp @@ -16,11 +16,13 @@ s32 lwmutex_create(sys_lwmutex_t& lwmutex, u32 protocol, u32 recursive, u64 name { LV2_LOCK(0); + std::shared_ptr sq(new sleep_queue_t(name_u64)); + lwmutex.owner.write_relaxed(be_t::make(0)); lwmutex.waiter.write_relaxed(be_t::make(~0)); lwmutex.attribute = protocol | recursive; - lwmutex.recursive_count = 0; - u32 sq_id = sys_lwmutex.GetNewId(new sleep_queue_t(name_u64), TYPE_LWMUTEX); + lwmutex.recursive_count.write_relaxed(be_t::make(0)); + u32 sq_id = sys_lwmutex.GetNewId(sq, TYPE_LWMUTEX); lwmutex.sleep_queue = sq_id; std::string name((const char*)&name_u64, 8); @@ -101,17 +103,24 @@ s32 sys_lwmutex_t::trylock(be_t tid) { if (attribute.ToBE() == se32(0xDEADBEEF)) return CELL_EINVAL; + if (!Emu.GetIdManager().CheckID(sleep_queue)) + { + return CELL_ESRCH; + } + const be_t old_owner = owner.read_sync(); if (old_owner == tid) { if (attribute.ToBE() & se32(SYS_SYNC_RECURSIVE)) { - recursive_count += 1; - if (!recursive_count.ToBE()) + auto rv = recursive_count.read_relaxed(); + if (!~(rv++).ToBE()) { return CELL_EKRESOURCE; } + + recursive_count.exchange(rv); return CELL_OK; } else @@ -125,7 +134,7 @@ s32 sys_lwmutex_t::trylock(be_t tid) return CELL_EBUSY; } - recursive_count = 1; + recursive_count.exchange(be_t::make(1)); return CELL_OK; } @@ -136,16 +145,18 @@ s32 sys_lwmutex_t::unlock(be_t tid) return CELL_EPERM; } - if (!recursive_count || (recursive_count.ToBE() != se32(1) && (attribute.ToBE() & se32(SYS_SYNC_NOT_RECURSIVE)))) + auto rv = recursive_count.read_relaxed(); + if (!rv.ToBE() || (rv.ToBE() != se32(1) && (attribute.ToBE() & se32(SYS_SYNC_NOT_RECURSIVE)))) { - sys_lwmutex.Error("sys_lwmutex_t::unlock(%d): wrong recursive value fixed (%d)", (u32)sleep_queue, (u32)recursive_count); - recursive_count = 1; + sys_lwmutex.Error("sys_lwmutex_t::unlock(%d): wrong recursive value fixed (%d)", (u32)sleep_queue, (u32)rv); + rv = 1; } - recursive_count -= 1; - if (!recursive_count.ToBE()) + rv--; + recursive_count.exchange(rv); + if (!rv.ToBE()) { - sleep_queue_t* sq; + std::shared_ptr sq; if (!Emu.GetIdManager().GetIDData(sleep_queue, sq)) { return CELL_ESRCH; @@ -168,7 +179,7 @@ s32 sys_lwmutex_t::lock(be_t tid, u64 timeout) default: return res; } - sleep_queue_t* sq; + std::shared_ptr sq; if (!Emu.GetIdManager().GetIDData(sleep_queue, sq)) { return CELL_ESRCH; @@ -205,6 +216,6 @@ s32 sys_lwmutex_t::lock(be_t tid, u64 timeout) } } - recursive_count = 1; + recursive_count.exchange(be_t::make(1)); return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h index 8a9e1b3212..ce29524d48 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_lwmutex.h @@ -16,7 +16,7 @@ struct sys_lwmutex_t atomic_t owner; atomic_t waiter; // currently not used be_t attribute; - be_t recursive_count; + atomic_t recursive_count; be_t sleep_queue; be_t pad; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp b/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp index ed68723e9d..b6b5e9ea57 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_memory.cpp @@ -43,7 +43,7 @@ s32 sys_memory_allocate_from_container(u32 size, u32 cid, u32 flags, u32 alloc_a sys_memory.Log("sys_memory_allocate_from_container(size=0x%x, cid=0x%x, flags=0x%x)", size, cid, flags); // Check if this container ID is valid. - MemoryContainerInfo* ct; + std::shared_ptr ct; if (!sys_memory.CheckId(cid, ct)) return CELL_ESRCH; @@ -119,7 +119,7 @@ s32 sys_memory_container_create(vm::ptr cid, u32 yield_size) return CELL_ENOMEM; // Wrap the allocated memory in a memory container. - MemoryContainerInfo *ct = new MemoryContainerInfo(addr, yield_size); + std::shared_ptr ct(new MemoryContainerInfo(addr, yield_size)); u32 id = sys_memory.GetNewId(ct, TYPE_MEM); *cid = id; @@ -133,7 +133,7 @@ s32 sys_memory_container_destroy(u32 cid) sys_memory.Warning("sys_memory_container_destroy(cid=%d)", cid); // Check if this container ID is valid. - MemoryContainerInfo* ct; + std::shared_ptr ct; if (!sys_memory.CheckId(cid, ct)) return CELL_ESRCH; @@ -149,7 +149,7 @@ s32 sys_memory_container_get_size(vm::ptr mem_info, u32 cid) sys_memory.Warning("sys_memory_container_get_size(mem_info_addr=0x%x, cid=%d)", mem_info.addr(), cid); // Check if this container ID is valid. - MemoryContainerInfo* ct; + std::shared_ptr ct; if (!sys_memory.CheckId(cid, ct)) return CELL_ESRCH; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp index 8dc1c35709..8c7f221160 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mmapper.cpp @@ -75,7 +75,8 @@ s32 sys_mmapper_allocate_memory(u32 size, u64 flags, vm::ptr mem_id) } // Generate a new mem ID. - *mem_id = sys_mmapper.GetNewId(new mmapper_info(size, flags)); + std::shared_ptr info(new mmapper_info(size, flags)); + *mem_id = sys_mmapper.GetNewId(info); return CELL_OK; } @@ -86,7 +87,7 @@ s32 sys_mmapper_allocate_memory_from_container(u32 size, u32 cid, u64 flags, vm: size, cid, flags, mem_id.addr()); // Check if this container ID is valid. - MemoryContainerInfo* ct; + std::shared_ptr ct; if(!sys_mmapper.CheckId(cid, ct)) return CELL_ESRCH; @@ -110,7 +111,8 @@ s32 sys_mmapper_allocate_memory_from_container(u32 size, u32 cid, u64 flags, vm: ct->size = size; // Generate a new mem ID. - *mem_id = sys_mmapper.GetNewId(new mmapper_info(ct->size, flags), TYPE_MEM); + std::shared_ptr info(new mmapper_info(ct->size, flags)); + *mem_id = sys_mmapper.GetNewId(info, TYPE_MEM); return CELL_OK; } @@ -138,7 +140,7 @@ s32 sys_mmapper_free_memory(u32 mem_id) sys_mmapper.Warning("sys_mmapper_free_memory(mem_id=0x%x)", mem_id); // Check if this mem ID is valid. - mmapper_info* info; + std::shared_ptr info; if(!sys_mmapper.CheckId(mem_id, info)) return CELL_ESRCH; @@ -153,7 +155,7 @@ s32 sys_mmapper_map_memory(u32 start_addr, u32 mem_id, u64 flags) sys_mmapper.Warning("sys_mmapper_map_memory(start_addr=0x%x, mem_id=0x%x, flags=0x%llx)", start_addr, mem_id, flags); // Check if this mem ID is valid. - mmapper_info* info; + std::shared_ptr info; if(!sys_mmapper.CheckId(mem_id, info)) return CELL_ESRCH; @@ -173,7 +175,7 @@ s32 sys_mmapper_search_and_map(u32 start_addr, u32 mem_id, u64 flags, u32 alloc_ start_addr, mem_id, flags, alloc_addr); // Check if this mem ID is valid. - mmapper_info* info; + std::shared_ptr info; if(!sys_mmapper.CheckId(mem_id, info)) return CELL_ESRCH; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp index 8ba4f2777f..ff907699fb 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.cpp @@ -16,7 +16,7 @@ Mutex::~Mutex() { if (u32 tid = owner.read_sync()) { - sys_mutex.Notice("Mutex(%d) was owned by thread %d (recursive=%d)", id, tid, recursive); + sys_mutex.Notice("Mutex(%d) was owned by thread %d (recursive=%d)", id, tid, recursive_count.load()); } if (!queue.m_mutex.try_lock()) return; @@ -61,7 +61,7 @@ s32 sys_mutex_create(PPUThread& CPU, vm::ptr mutex_id, vm::ptrprotocol, is_recursive, attr->name_u64); + std::shared_ptr mutex(new Mutex((u32)attr->protocol, is_recursive, attr->name_u64)); const u32 id = sys_mutex.GetNewId(mutex, TYPE_MUTEX); mutex->id.exchange(id); *mutex_id = id; @@ -80,7 +80,7 @@ s32 sys_mutex_destroy(PPUThread& CPU, u32 mutex_id) LV2_LOCK(0); - Mutex* mutex; + std::shared_ptr mutex; if (!Emu.GetIdManager().GetIDData(mutex_id, mutex)) { return CELL_ESRCH; @@ -120,7 +120,7 @@ s32 sys_mutex_lock(PPUThread& CPU, u32 mutex_id, u64 timeout) { sys_mutex.Log("sys_mutex_lock(mutex_id=%d, timeout=%lld)", mutex_id, timeout); - Mutex* mutex; + std::shared_ptr mutex; if (!Emu.GetIdManager().GetIDData(mutex_id, mutex)) { return CELL_ESRCH; @@ -132,10 +132,11 @@ s32 sys_mutex_lock(PPUThread& CPU, u32 mutex_id, u64 timeout) { if (mutex->is_recursive) { - if (!++mutex->recursive) + if (!~mutex->recursive_count) { return CELL_EKRESOURCE; } + mutex->recursive_count++; return CELL_OK; } else @@ -146,7 +147,7 @@ s32 sys_mutex_lock(PPUThread& CPU, u32 mutex_id, u64 timeout) if (mutex->owner.compare_and_swap_test(0, tid)) { - mutex->recursive = 1; + mutex->recursive_count = 1; CPU.owned_mutexes++; return CELL_OK; } @@ -182,7 +183,7 @@ s32 sys_mutex_lock(PPUThread& CPU, u32 mutex_id, u64 timeout) } } - mutex->recursive = 1; + mutex->recursive_count = 1; CPU.owned_mutexes++; return CELL_OK; } @@ -191,7 +192,7 @@ s32 sys_mutex_trylock(PPUThread& CPU, u32 mutex_id) { sys_mutex.Log("sys_mutex_trylock(mutex_id=%d)", mutex_id); - Mutex* mutex; + std::shared_ptr mutex; if (!Emu.GetIdManager().GetIDData(mutex_id, mutex)) { return CELL_ESRCH; @@ -203,10 +204,11 @@ s32 sys_mutex_trylock(PPUThread& CPU, u32 mutex_id) { if (mutex->is_recursive) { - if (!++mutex->recursive) + if (!~mutex->recursive_count) { return CELL_EKRESOURCE; } + mutex->recursive_count++; return CELL_OK; } else @@ -220,7 +222,7 @@ s32 sys_mutex_trylock(PPUThread& CPU, u32 mutex_id) return CELL_EBUSY; } - mutex->recursive = 1; + mutex->recursive_count = 1; CPU.owned_mutexes++; return CELL_OK; } @@ -229,7 +231,7 @@ s32 sys_mutex_unlock(PPUThread& CPU, u32 mutex_id) { sys_mutex.Log("sys_mutex_unlock(mutex_id=%d)", mutex_id); - Mutex* mutex; + std::shared_ptr mutex; if (!Emu.GetIdManager().GetIDData(mutex_id, mutex)) { return CELL_ESRCH; @@ -242,13 +244,13 @@ s32 sys_mutex_unlock(PPUThread& CPU, u32 mutex_id) return CELL_EPERM; } - if (!mutex->recursive || (mutex->recursive != 1 && !mutex->is_recursive)) + if (!mutex->recursive_count || (mutex->recursive_count != 1 && !mutex->is_recursive)) { - sys_mutex.Error("sys_mutex_unlock(%d): wrong recursive value fixed (%d)", mutex_id, mutex->recursive); - mutex->recursive = 1; + sys_mutex.Error("sys_mutex_unlock(%d): wrong recursive value fixed (%d)", mutex_id, mutex->recursive_count.load()); + mutex->recursive_count = 1; } - if (!--mutex->recursive) + if (!--mutex->recursive_count) { if (!mutex->owner.compare_and_swap_test(tid, mutex->queue.pop(mutex->protocol))) { diff --git a/rpcs3/Emu/SysCalls/lv2/sys_mutex.h b/rpcs3/Emu/SysCalls/lv2/sys_mutex.h index 14b4548ab7..0eee5a6650 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_mutex.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_mutex.h @@ -20,9 +20,9 @@ struct Mutex { atomic_le_t id; atomic_le_t owner; - sleep_queue_t queue; - u32 recursive; // recursive locks count + std::atomic recursive_count; // recursive locks count std::atomic cond_count; // count of condition variables associated + sleep_queue_t queue; const u32 protocol; const bool is_recursive; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp b/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp index 0a759cdc2f..bb1b49eead 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_ppu_thread.cpp @@ -51,7 +51,7 @@ s32 sys_ppu_thread_join(u64 thread_id, vm::ptr vptr) { sys_ppu_thread.Warning("sys_ppu_thread_join(thread_id=%lld, vptr_addr=0x%x)", thread_id, vptr.addr()); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if(!thr) return CELL_ESRCH; while (thr->IsAlive()) @@ -72,7 +72,7 @@ s32 sys_ppu_thread_detach(u64 thread_id) { sys_ppu_thread.Todo("sys_ppu_thread_detach(thread_id=%lld)", thread_id); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if(!thr) return CELL_ESRCH; if(!thr->IsJoinable()) @@ -93,7 +93,7 @@ s32 sys_ppu_thread_set_priority(u64 thread_id, s32 prio) { sys_ppu_thread.Log("sys_ppu_thread_set_priority(thread_id=%lld, prio=%d)", thread_id, prio); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if(!thr) return CELL_ESRCH; thr->SetPrio(prio); @@ -105,7 +105,7 @@ s32 sys_ppu_thread_get_priority(u64 thread_id, u32 prio_addr) { sys_ppu_thread.Log("sys_ppu_thread_get_priority(thread_id=%lld, prio_addr=0x%x)", thread_id, prio_addr); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if(!thr) return CELL_ESRCH; vm::write32(prio_addr, (s32)thr->GetPrio()); @@ -127,7 +127,7 @@ s32 sys_ppu_thread_stop(u64 thread_id) { sys_ppu_thread.Warning("sys_ppu_thread_stop(thread_id=%lld)", thread_id); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if(!thr) return CELL_ESRCH; thr->Stop(); @@ -139,7 +139,7 @@ s32 sys_ppu_thread_restart(u64 thread_id) { sys_ppu_thread.Warning("sys_ppu_thread_restart(thread_id=%lld)", thread_id); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if(!thr) return CELL_ESRCH; thr->Stop(); @@ -233,7 +233,7 @@ s32 sys_ppu_thread_rename(u64 thread_id, vm::ptr name) { sys_ppu_thread.Log("sys_ppu_thread_rename(thread_id=%d, name_addr=0x%x('%s'))", thread_id, name.addr(), name.get_ptr()); - CPUThread* thr = Emu.GetCPU().GetThread(thread_id); + std::shared_ptr thr = Emu.GetCPU().GetThread(thread_id); if (!thr) { return CELL_ESRCH; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp index b041044f95..749647be31 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_process.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_process.cpp @@ -196,31 +196,31 @@ void sys_game_process_exitspawn2(vm::ptr path, u32 argv_addr, u32 en s32 sys_process_get_number_of_object(u32 object, vm::ptr nump) { - sys_process.Warning("sys_process_get_number_of_object(object=%d, nump_addr=0x%x)", + sys_process.Todo("sys_process_get_number_of_object(object=%d, nump_addr=0x%x)", object, nump.addr()); switch(object) { - 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; + //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; @@ -245,24 +245,24 @@ s32 sys_process_get_id(u32 object, vm::ptr buffer, u32 size, vm::ptr s *set_size = i; \ } - case SYS_MEM_OBJECT: ADD_OBJECTS(TYPE_MEM); break; - case SYS_MUTEX_OBJECT: ADD_OBJECTS(TYPE_MUTEX); break; - case SYS_COND_OBJECT: ADD_OBJECTS(TYPE_COND); break; - case SYS_RWLOCK_OBJECT: ADD_OBJECTS(TYPE_RWLOCK); break; - case SYS_INTR_TAG_OBJECT: ADD_OBJECTS(TYPE_INTR_TAG); break; - case SYS_INTR_SERVICE_HANDLE_OBJECT: ADD_OBJECTS(TYPE_INTR_SERVICE_HANDLE); break; - case SYS_EVENT_QUEUE_OBJECT: ADD_OBJECTS(TYPE_EVENT_QUEUE); break; - case SYS_EVENT_PORT_OBJECT: ADD_OBJECTS(TYPE_EVENT_PORT); break; - case SYS_TRACE_OBJECT: ADD_OBJECTS(TYPE_TRACE); break; - case SYS_SPUIMAGE_OBJECT: ADD_OBJECTS(TYPE_SPUIMAGE); break; - case SYS_PRX_OBJECT: ADD_OBJECTS(TYPE_PRX); break; - case SYS_SPUPORT_OBJECT: ADD_OBJECTS(TYPE_SPUPORT); break; - case SYS_LWMUTEX_OBJECT: ADD_OBJECTS(TYPE_LWMUTEX); break; - case SYS_TIMER_OBJECT: ADD_OBJECTS(TYPE_TIMER); break; - case SYS_SEMAPHORE_OBJECT: ADD_OBJECTS(TYPE_SEMAPHORE); break; - case SYS_FS_FD_OBJECT: ADD_OBJECTS(TYPE_FS_FILE);/*TODO:DIR*/ break; - case SYS_LWCOND_OBJECT: ADD_OBJECTS(TYPE_LWCOND); break; - case SYS_EVENT_FLAG_OBJECT: ADD_OBJECTS(TYPE_EVENT_FLAG); break; + //case SYS_MEM_OBJECT: ADD_OBJECTS(TYPE_MEM); break; + //case SYS_MUTEX_OBJECT: ADD_OBJECTS(TYPE_MUTEX); break; + //case SYS_COND_OBJECT: ADD_OBJECTS(TYPE_COND); break; + //case SYS_RWLOCK_OBJECT: ADD_OBJECTS(TYPE_RWLOCK); break; + //case SYS_INTR_TAG_OBJECT: ADD_OBJECTS(TYPE_INTR_TAG); break; + //case SYS_INTR_SERVICE_HANDLE_OBJECT: ADD_OBJECTS(TYPE_INTR_SERVICE_HANDLE); break; + //case SYS_EVENT_QUEUE_OBJECT: ADD_OBJECTS(TYPE_EVENT_QUEUE); break; + //case SYS_EVENT_PORT_OBJECT: ADD_OBJECTS(TYPE_EVENT_PORT); break; + //case SYS_TRACE_OBJECT: ADD_OBJECTS(TYPE_TRACE); break; + //case SYS_SPUIMAGE_OBJECT: ADD_OBJECTS(TYPE_SPUIMAGE); break; + //case SYS_PRX_OBJECT: ADD_OBJECTS(TYPE_PRX); break; + //case SYS_SPUPORT_OBJECT: ADD_OBJECTS(TYPE_SPUPORT); break; + //case SYS_LWMUTEX_OBJECT: ADD_OBJECTS(TYPE_LWMUTEX); break; + //case SYS_TIMER_OBJECT: ADD_OBJECTS(TYPE_TIMER); break; + //case SYS_SEMAPHORE_OBJECT: ADD_OBJECTS(TYPE_SEMAPHORE); break; + //case SYS_FS_FD_OBJECT: ADD_OBJECTS(TYPE_FS_FILE);/*TODO:DIR*/ break; + //case SYS_LWCOND_OBJECT: ADD_OBJECTS(TYPE_LWCOND); break; + //case SYS_EVENT_FLAG_OBJECT: ADD_OBJECTS(TYPE_EVENT_FLAG); break; #undef ADD_OBJECTS diff --git a/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp b/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp index efdb47f96c..cf3cc9f17e 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_prx.cpp @@ -31,7 +31,7 @@ s32 sys_prx_load_module(vm::ptr path, u64 flags, vm::ptr prx(new sys_prx_t()); prx->size = (u32)f.GetSize(); prx->address = (u32)Memory.Alloc(prx->size, 4); prx->path = (const char*)path; @@ -66,7 +66,7 @@ s32 sys_prx_start_module(s32 id, u32 args, u32 argp_addr, vm::ptr modres, u sys_prx.Todo("sys_prx_start_module(id=%d, args=%d, argp_addr=0x%x, modres_addr=0x%x, flags=0x%llx, pOpt=0x%x)", id, args, argp_addr, modres.addr(), flags, pOpt.addr()); - sys_prx_t* prx; + std::shared_ptr prx; if (!Emu.GetIdManager().GetIDData(id, prx)) return CELL_ESRCH; @@ -81,7 +81,7 @@ s32 sys_prx_stop_module(s32 id, u32 args, u32 argp_addr, vm::ptr modres, u6 sys_prx.Todo("sys_prx_stop_module(id=%d, args=%d, argp_addr=0x%x, modres_addr=0x%x, flags=0x%llx, pOpt=0x%x)", id, args, argp_addr, modres.addr(), flags, pOpt.addr()); - sys_prx_t* prx; + std::shared_ptr prx; if (!Emu.GetIdManager().GetIDData(id, prx)) return CELL_ESRCH; @@ -96,7 +96,7 @@ s32 sys_prx_unload_module(s32 id, u64 flags, vm::ptr prx; if (!Emu.GetIdManager().GetIDData(id, prx)) return CELL_ESRCH; Memory.Free(prx->address); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp index 678f46bfe7..2428a89eae 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_rwlock.cpp @@ -32,7 +32,8 @@ s32 sys_rwlock_create(vm::ptr rw_lock_id, vm::ptr a return CELL_EINVAL; } - u32 id = sys_rwlock.GetNewId(new RWLock((u32)attr->attr_protocol, attr->name_u64), TYPE_RWLOCK); + std::shared_ptr rw(new RWLock((u32)attr->attr_protocol, attr->name_u64)); + u32 id = sys_rwlock.GetNewId(rw, TYPE_RWLOCK); *rw_lock_id = id; sys_rwlock.Warning("*** rwlock created [%s] (protocol=0x%x): id = %d", @@ -45,7 +46,7 @@ s32 sys_rwlock_destroy(u32 rw_lock_id) { sys_rwlock.Warning("sys_rwlock_destroy(rw_lock_id=%d)", rw_lock_id); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; std::lock_guard lock(rw->m_lock); @@ -61,7 +62,7 @@ s32 sys_rwlock_rlock(u32 rw_lock_id, u64 timeout) { sys_rwlock.Log("sys_rwlock_rlock(rw_lock_id=%d, timeout=%lld)", rw_lock_id, timeout); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); @@ -98,7 +99,7 @@ s32 sys_rwlock_tryrlock(u32 rw_lock_id) { sys_rwlock.Log("sys_rwlock_tryrlock(rw_lock_id=%d)", rw_lock_id); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; if (!rw->rlock_trylock(GetCurrentPPUThread().GetId())) return CELL_EBUSY; @@ -110,7 +111,7 @@ s32 sys_rwlock_runlock(u32 rw_lock_id) { sys_rwlock.Log("sys_rwlock_runlock(rw_lock_id=%d)", rw_lock_id); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; if (!rw->rlock_unlock(GetCurrentPPUThread().GetId())) return CELL_EPERM; @@ -122,7 +123,7 @@ s32 sys_rwlock_wlock(u32 rw_lock_id, u64 timeout) { sys_rwlock.Log("sys_rwlock_wlock(rw_lock_id=%d, timeout=%lld)", rw_lock_id, timeout); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); @@ -161,7 +162,7 @@ s32 sys_rwlock_trywlock(u32 rw_lock_id) { sys_rwlock.Log("sys_rwlock_trywlock(rw_lock_id=%d)", rw_lock_id); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; const u32 tid = GetCurrentPPUThread().GetId(); @@ -176,7 +177,7 @@ s32 sys_rwlock_wunlock(u32 rw_lock_id) { sys_rwlock.Log("sys_rwlock_wunlock(rw_lock_id=%d)", rw_lock_id); - RWLock* rw; + std::shared_ptr rw; if (!sys_rwlock.CheckId(rw_lock_id, rw)) return CELL_ESRCH; if (!rw->wlock_unlock(GetCurrentPPUThread().GetId())) return CELL_EPERM; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp index e68bf58c6c..7dc608a5c6 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_semaphore.cpp @@ -16,8 +16,9 @@ u32 semaphore_create(s32 initial_count, s32 max_count, u32 protocol, u64 name_u6 { LV2_LOCK(0); + std::shared_ptr sem(new Semaphore(initial_count, max_count, protocol, name_u64)); const std::string name((const char*)&name_u64, 8); - const u32 id = sys_semaphore.GetNewId(new Semaphore(initial_count, max_count, protocol, name_u64), TYPE_SEMAPHORE); + const u32 id = sys_semaphore.GetNewId(sem, TYPE_SEMAPHORE); sys_semaphore.Notice("*** semaphore created [%s] (protocol=0x%x): id = %d", name.c_str(), protocol, id); Emu.GetSyncPrimManager().AddSemaphoreData(id, name, initial_count, max_count); return id; @@ -69,7 +70,7 @@ s32 sys_semaphore_destroy(u32 sem_id) LV2_LOCK(0); - Semaphore* sem; + std::shared_ptr sem; if (!Emu.GetIdManager().GetIDData(sem_id, sem)) { return CELL_ESRCH; @@ -89,7 +90,7 @@ s32 sys_semaphore_wait(u32 sem_id, u64 timeout) { sys_semaphore.Log("sys_semaphore_wait(sem_id=%d, timeout=%lld)", sem_id, timeout); - Semaphore* sem; + std::shared_ptr sem; if (!Emu.GetIdManager().GetIDData(sem_id, sem)) { return CELL_ESRCH; @@ -142,7 +143,7 @@ s32 sys_semaphore_trywait(u32 sem_id) { sys_semaphore.Log("sys_semaphore_trywait(sem_id=%d)", sem_id); - Semaphore* sem; + std::shared_ptr sem; if (!Emu.GetIdManager().GetIDData(sem_id, sem)) { return CELL_ESRCH; @@ -165,7 +166,7 @@ s32 sys_semaphore_post(u32 sem_id, s32 count) { sys_semaphore.Log("sys_semaphore_post(sem_id=%d, count=%d)", sem_id, count); - Semaphore* sem; + std::shared_ptr sem; if (!Emu.GetIdManager().GetIDData(sem_id, sem)) { return CELL_ESRCH; @@ -216,12 +217,13 @@ s32 sys_semaphore_get_value(u32 sem_id, vm::ptr count) { sys_semaphore.Log("sys_semaphore_get_value(sem_id=%d, count_addr=0x%x)", sem_id, count.addr()); - if (count.addr() == NULL) { - sys_semaphore.Error("sys_semaphore_get_value(): invalid memory access (count=0x%x)", count.addr()); - return CELL_EFAULT; - } + if (!count) + { + sys_semaphore.Error("sys_semaphore_get_value(): invalid memory access (count=0x%x)", count.addr()); + return CELL_EFAULT; + } - Semaphore* sem; + std::shared_ptr sem; if (!Emu.GetIdManager().GetIDData(sem_id, sem)) { return CELL_ESRCH; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp b/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp index b033473a7c..885f0686bd 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_spu.cpp @@ -78,7 +78,7 @@ s32 sys_spu_image_open(vm::ptr img, vm::ptr path) return CELL_OK; } -SPUThread* spu_thread_initialize(SpuGroupInfo* group, u32 spu_num, sys_spu_image& img, const std::string& name, u32 option, u64 a1, u64 a2, u64 a3, u64 a4, std::function task) +SPUThread* spu_thread_initialize(std::shared_ptr& group, u32 spu_num, sys_spu_image& img, const std::string& name, u32 option, u64 a1, u64 a2, u64 a3, u64 a4, std::function task) { if (option) { @@ -117,7 +117,7 @@ s32 sys_spu_thread_initialize(vm::ptr thread, u32 group, u32 spu_num, vm::p sys_spu.Warning("sys_spu_thread_initialize(thread_addr=0x%x, group=0x%x, spu_num=%d, img_addr=0x%x, attr_addr=0x%x, arg_addr=0x%x)", thread.addr(), group, spu_num, img.addr(), attr.addr(), arg.addr()); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if(!Emu.GetIdManager().GetIDData(group, group_info)) { return CELL_ESRCH; @@ -150,14 +150,14 @@ s32 sys_spu_thread_set_argument(u32 id, vm::ptr arg) { sys_spu.Warning("sys_spu_thread_set_argument(id=%d, arg_addr=0x%x)", id, arg.addr()); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { return CELL_ESRCH; } - SPUThread& spu = *(SPUThread*)thr; + SPUThread& spu = *(SPUThread*)thr.get(); spu.GPR[3] = u128::from64(0, arg->arg1); spu.GPR[4] = u128::from64(0, arg->arg2); @@ -171,7 +171,7 @@ s32 sys_spu_thread_get_exit_status(u32 id, vm::ptr status) { sys_spu.Warning("sys_spu_thread_get_exit_status(id=%d, status_addr=0x%x)", id, status.addr()); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { @@ -179,7 +179,7 @@ s32 sys_spu_thread_get_exit_status(u32 id, vm::ptr status) } u32 res; - if (!(*(SPUThread*)thr).SPU.Out_MBox.Pop(res) || !thr->IsStopped()) + if (!(*(SPUThread*)thr.get()).SPU.Out_MBox.Pop(res) || !thr->IsStopped()) { return CELL_ESTAT; } @@ -192,7 +192,7 @@ s32 sys_spu_thread_group_destroy(u32 id) { sys_spu.Warning("sys_spu_thread_group_destroy(id=%d)", id); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if(!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -215,10 +215,10 @@ s32 sys_spu_thread_group_destroy(u32 id) for (u32 i = 0; i < group_info->list.size(); i++) { // TODO: disconnect all event ports - CPUThread* t = Emu.GetCPU().GetThread(group_info->list[i]); + std::shared_ptr t = Emu.GetCPU().GetThread(group_info->list[i]); if (t) { - Memory.Free(((SPUThread*)t)->GetOffset()); + Memory.Free(((SPUThread*)t.get())->GetOffset()); Emu.GetCPU().RemoveThread(group_info->list[i]); } } @@ -234,7 +234,7 @@ s32 sys_spu_thread_group_start(u32 id) { sys_spu.Warning("sys_spu_thread_group_start(id=%d)", id); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if(!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -252,10 +252,10 @@ s32 sys_spu_thread_group_start(u32 id) for (u32 i = 0; i < group_info->list.size(); i++) { - CPUThread* t = Emu.GetCPU().GetThread(group_info->list[i]); + std::shared_ptr t = Emu.GetCPU().GetThread(group_info->list[i]); if (t) { - ((SPUThread*)t)->SPU.Status.SetValue(SPU_STATUS_RUNNING); + ((SPUThread*)t.get())->SPU.Status.SetValue(SPU_STATUS_RUNNING); t->Exec(); } } @@ -270,7 +270,7 @@ s32 sys_spu_thread_group_suspend(u32 id) { sys_spu.Log("sys_spu_thread_group_suspend(id=%d)", id); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if(!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -291,7 +291,7 @@ s32 sys_spu_thread_group_suspend(u32 id) for (u32 i = 0; i < group_info->list.size(); i++) { - if (CPUThread* t = Emu.GetCPU().GetThread(group_info->list[i])) + if (std::shared_ptr t = Emu.GetCPU().GetThread(group_info->list[i])) { t->Pause(); } @@ -316,7 +316,7 @@ s32 sys_spu_thread_group_resume(u32 id) { sys_spu.Log("sys_spu_thread_group_resume(id=%d)", id); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if(!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -344,7 +344,7 @@ s32 sys_spu_thread_group_resume(u32 id) for (u32 i = 0; i < group_info->list.size(); i++) { - if (CPUThread* t = Emu.GetCPU().GetThread(group_info->list[i])) + if (std::shared_ptr t = Emu.GetCPU().GetThread(group_info->list[i])) { t->Resume(); } @@ -363,7 +363,7 @@ s32 sys_spu_thread_group_yield(u32 id) { sys_spu.Error("sys_spu_thread_group_yield(id=%d)", id); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if (!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -405,7 +405,7 @@ s32 sys_spu_thread_group_terminate(u32 id, int value) { sys_spu.Error("sys_spu_thread_group_terminate(id=%d, value=%d)", id, value); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if (!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -425,9 +425,9 @@ s32 sys_spu_thread_group_terminate(u32 id, int value) //SET BUSY for (u32 i = 0; i < group_info->list.size(); i++) { - if (CPUThread* t = Emu.GetCPU().GetThread(group_info->list[i])) + if (std::shared_ptr t = Emu.GetCPU().GetThread(group_info->list[i])) { - ((SPUThread*)t)->SPU.Status.SetValue(SPU_STATUS_STOPPED); + ((SPUThread*)t.get())->SPU.Status.SetValue(SPU_STATUS_STOPPED); t->Stop(); } } @@ -440,7 +440,7 @@ s32 sys_spu_thread_group_terminate(u32 id, int value) return CELL_OK; } -SpuGroupInfo* spu_thread_group_create(const std::string& name, u32 num, s32 prio, s32 type, u32 container) +std::shared_ptr spu_thread_group_create(const std::string& name, u32 num, s32 prio, s32 type, u32 container) { LV2_LOCK(0); @@ -449,7 +449,7 @@ SpuGroupInfo* spu_thread_group_create(const std::string& name, u32 num, s32 prio sys_spu.Todo("Unsupported SPU Thread Group type (0x%x)", type); } - auto group = new SpuGroupInfo(name, num, prio, type, container); + std::shared_ptr group(new SpuGroupInfo(name, num, prio, type, container)); const u32 _id = sys_spu.GetNewId(group); group->m_id = _id; sys_spu.Notice("*** SPU Thread Group created [%s] (num=%d, prio=%d, type=0x%x, container=%d): id=%d", @@ -475,7 +475,7 @@ s32 sys_spu_thread_group_join(u32 id, vm::ptr cause, vm::ptr status) { sys_spu.Warning("sys_spu_thread_group_join(id=%d, cause_addr=0x%x, status_addr=0x%x)", id, cause.addr(), status.addr()); - SpuGroupInfo* group_info; + std::shared_ptr group_info; if(!Emu.GetIdManager().GetIDData(id, group_info)) { return CELL_ESRCH; @@ -489,11 +489,11 @@ s32 sys_spu_thread_group_join(u32 id, vm::ptr cause, vm::ptr status) bool all_threads_exit = true; for (u32 i = 0; i < group_info->list.size(); i++) { - while (CPUThread* t = Emu.GetCPU().GetThread(group_info->list[i])) + while (std::shared_ptr t = Emu.GetCPU().GetThread(group_info->list[i])) { if (!t->IsAlive()) { - if (((SPUThread*)t)->SPU.Status.GetValue() != SPU_STATUS_STOPPED_BY_STOP) + if (((SPUThread*)t.get())->SPU.Status.GetValue() != SPU_STATUS_STOPPED_BY_STOP) { all_threads_exit = false; } @@ -548,7 +548,7 @@ s32 sys_spu_thread_write_ls(u32 id, u32 address, u64 value, u32 type) sys_spu.Log("sys_spu_thread_write_ls(id=%d, address=0x%x, value=0x%llx, type=0x%x)", id, address, value, type); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { @@ -567,10 +567,10 @@ s32 sys_spu_thread_write_ls(u32 id, u32 address, u64 value, u32 type) switch (type) { - case 1: (*(SPUThread*)thr).WriteLS8(address, (u8)value); return CELL_OK; - case 2: (*(SPUThread*)thr).WriteLS16(address, (u16)value); return CELL_OK; - case 4: (*(SPUThread*)thr).WriteLS32(address, (u32)value); return CELL_OK; - case 8: (*(SPUThread*)thr).WriteLS64(address, value); return CELL_OK; + case 1: (*(SPUThread*)thr.get()).WriteLS8(address, (u8)value); return CELL_OK; + case 2: (*(SPUThread*)thr.get()).WriteLS16(address, (u16)value); return CELL_OK; + case 4: (*(SPUThread*)thr.get()).WriteLS32(address, (u32)value); return CELL_OK; + case 8: (*(SPUThread*)thr.get()).WriteLS64(address, value); return CELL_OK; default: return CELL_EINVAL; } } @@ -580,7 +580,7 @@ s32 sys_spu_thread_read_ls(u32 id, u32 address, vm::ptr value, u32 type) sys_spu.Log("sys_spu_thread_read_ls(id=%d, address=0x%x, value_addr=0x%x, type=0x%x)", id, address, value.addr(), type); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { @@ -599,10 +599,10 @@ s32 sys_spu_thread_read_ls(u32 id, u32 address, vm::ptr value, u32 type) switch (type) { - case 1: *value = (*(SPUThread*)thr).ReadLS8(address); return CELL_OK; - case 2: *value = (*(SPUThread*)thr).ReadLS16(address); return CELL_OK; - case 4: *value = (*(SPUThread*)thr).ReadLS32(address); return CELL_OK; - case 8: *value = (*(SPUThread*)thr).ReadLS64(address); return CELL_OK; + case 1: *value = (*(SPUThread*)thr.get()).ReadLS8(address); return CELL_OK; + case 2: *value = (*(SPUThread*)thr.get()).ReadLS16(address); return CELL_OK; + case 4: *value = (*(SPUThread*)thr.get()).ReadLS32(address); return CELL_OK; + case 8: *value = (*(SPUThread*)thr.get()).ReadLS64(address); return CELL_OK; default: return CELL_EINVAL; } } @@ -611,14 +611,14 @@ s32 sys_spu_thread_write_spu_mb(u32 id, u32 value) { sys_spu.Warning("sys_spu_thread_write_spu_mb(id=%d, value=0x%x)", id, value); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { return CELL_ESRCH; } - (*(SPUThread*)thr).SPU.In_MBox.PushUncond(value); + (*(SPUThread*)thr.get()).SPU.In_MBox.PushUncond(value); return CELL_OK; } @@ -627,7 +627,7 @@ s32 sys_spu_thread_set_spu_cfg(u32 id, u64 value) { sys_spu.Warning("sys_spu_thread_set_spu_cfg(id=%d, value=0x%x)", id, value); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { @@ -639,7 +639,7 @@ s32 sys_spu_thread_set_spu_cfg(u32 id, u64 value) return CELL_EINVAL; } - (*(SPUThread*)thr).cfg.value = value; + (*(SPUThread*)thr.get()).cfg.value = value; return CELL_OK; } @@ -648,14 +648,14 @@ s32 sys_spu_thread_get_spu_cfg(u32 id, vm::ptr value) { sys_spu.Warning("sys_spu_thread_get_spu_cfg(id=%d, value_addr=0x%x)", id, value.addr()); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { return CELL_ESRCH; } - *value = (*(SPUThread*)thr).cfg.value; + *value = (*(SPUThread*)thr.get()).cfg.value; return CELL_OK; } @@ -663,7 +663,8 @@ s32 sys_spu_thread_get_spu_cfg(u32 id, vm::ptr value) s32 sys_spu_thread_write_snr(u32 id, u32 number, u32 value) { sys_spu.Log("sys_spu_thread_write_snr(id=%d, number=%d, value=0x%x)", id, number, value); - CPUThread* thr = Emu.GetCPU().GetThread(id); + + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { @@ -675,7 +676,7 @@ s32 sys_spu_thread_write_snr(u32 id, u32 number, u32 value) return CELL_EINVAL; } - (*(SPUThread*)thr).WriteSNR(number ? true : false, value); + (*(SPUThread*)thr.get()).WriteSNR(number ? true : false, value); return CELL_OK; } @@ -706,14 +707,14 @@ s32 sys_spu_thread_connect_event(u32 id, u32 eq_id, u32 et, u8 spup) { sys_spu.Warning("sys_spu_thread_connect_event(id=%d, eq_id=%d, event_type=0x%x, spup=%d)", id, eq_id, et, spup); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { return CELL_ESRCH; } - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(eq_id, eq)) { return CELL_ESRCH; @@ -733,19 +734,19 @@ s32 sys_spu_thread_connect_event(u32 id, u32 eq_id, u32 et, u8 spup) // TODO: check if can receive these events - SPUThread& spu = *(SPUThread*)thr; + SPUThread& spu = *(SPUThread*)thr.get(); - EventPort& port = spu.SPUPs[spup]; + std::shared_ptr port = spu.SPUPs[spup]; - std::lock_guard lock(port.m_mutex); + std::lock_guard lock(port->m_mutex); - if (port.eq) + if (port->eq) { return CELL_EISCONN; } - eq->ports.add(&port); - port.eq = eq; + eq->ports.add(port); + port->eq = eq; return CELL_OK; } @@ -754,7 +755,7 @@ s32 sys_spu_thread_disconnect_event(u32 id, u32 et, u8 spup) { sys_spu.Warning("sys_spu_thread_disconnect_event(id=%d, event_type=0x%x, spup=%d)", id, et, spup); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { @@ -773,19 +774,19 @@ s32 sys_spu_thread_disconnect_event(u32 id, u32 et, u8 spup) return CELL_EINVAL; } - SPUThread& spu = *(SPUThread*)thr; + SPUThread& spu = *(SPUThread*)thr.get(); - EventPort& port = spu.SPUPs[spup]; + std::shared_ptr port = spu.SPUPs[spup]; - std::lock_guard lock(port.m_mutex); + std::lock_guard lock(port->m_mutex); - if (!port.eq) + if (!port->eq) { return CELL_ENOTCONN; } - port.eq->ports.remove(&port); - port.eq = nullptr; + port->eq->ports.remove(port); + port->eq = nullptr; return CELL_OK; } @@ -794,7 +795,7 @@ s32 sys_spu_thread_bind_queue(u32 id, u32 eq_id, u32 spuq_num) { sys_spu.Warning("sys_spu_thread_bind_queue(id=%d, equeue_id=%d, spuq_num=0x%x)", id, eq_id, spuq_num); - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(eq_id, eq)) { return CELL_ESRCH; @@ -805,14 +806,14 @@ s32 sys_spu_thread_bind_queue(u32 id, u32 eq_id, u32 spuq_num) return CELL_EINVAL; } - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { return CELL_ESRCH; } - if (!(*(SPUThread*)thr).SPUQs.RegisterKey(eq, FIX_SPUQ(spuq_num))) + if (!(*(SPUThread*)thr.get()).SPUQs.RegisterKey(eq, FIX_SPUQ(spuq_num))) { return CELL_EBUSY; } @@ -824,14 +825,14 @@ s32 sys_spu_thread_unbind_queue(u32 id, u32 spuq_num) { sys_spu.Warning("sys_spu_thread_unbind_queue(id=0x%x, spuq_num=0x%x)", id, spuq_num); - CPUThread* thr = Emu.GetCPU().GetThread(id); + std::shared_ptr thr = Emu.GetCPU().GetThread(id); if(!thr || thr->GetType() != CPU_THREAD_SPU) { return CELL_ESRCH; } - if (!(*(SPUThread*)thr).SPUQs.UnregisterKey(FIX_SPUQ(spuq_num))) + if (!(*(SPUThread*)thr.get()).SPUQs.UnregisterKey(FIX_SPUQ(spuq_num))) { return CELL_ESRCH; // may be CELL_EINVAL } @@ -844,7 +845,7 @@ s32 sys_spu_thread_group_connect_event_all_threads(u32 id, u32 eq_id, u64 req, v sys_spu.Warning("sys_spu_thread_group_connect_event_all_threads(id=%d, eq_id=%d, req=0x%llx, spup_addr=0x%x)", id, eq_id, req, spup.addr()); - EventQueue* eq; + std::shared_ptr eq; if (!Emu.GetIdManager().GetIDData(eq_id, eq)) { return CELL_ESRCH; @@ -855,23 +856,23 @@ s32 sys_spu_thread_group_connect_event_all_threads(u32 id, u32 eq_id, u64 req, v return CELL_EINVAL; } - SpuGroupInfo* group; + std::shared_ptr group; if (!Emu.GetIdManager().GetIDData(id, group)) { return CELL_ESRCH; } - std::vector threads; + std::vector> threads; for (auto& v : group->list) { if (!v) continue; - CPUThread* thr = Emu.GetCPU().GetThread(v); + std::shared_ptr thr = Emu.GetCPU().GetThread(v); if (thr->GetType() != CPU_THREAD_SPU) { sys_spu.Error("sys_spu_thread_group_connect_event_all_threads(): CELL_ESTAT (wrong thread type)"); return CELL_ESTAT; } - threads.push_back((SPUThread*)thr); + threads.push_back(thr); } if (threads.size() != group->m_count) @@ -885,22 +886,22 @@ s32 sys_spu_thread_group_connect_event_all_threads(u32 id, u32 eq_id, u64 req, v bool found = true; if (req & (1ull << i)) { - for (auto& t : threads) t->SPUPs[i].m_mutex.lock(); + for (auto& t : threads) ((SPUThread*)t.get())->SPUPs[i]->m_mutex.lock(); - for (auto& t : threads) if (t->SPUPs[i].eq) found = false; + for (auto& t : threads) if (((SPUThread*)t.get())->SPUPs[i]->eq) found = false; if (found) { for (auto& t : threads) { - eq->ports.add(&(t->SPUPs[i])); - t->SPUPs[i].eq = eq; + eq->ports.add(((SPUThread*)t.get())->SPUPs[i]); + ((SPUThread*)t.get())->SPUPs[i]->eq = eq; } sys_spu.Warning("*** spup -> %d", i); *spup = (u8)i; } - for (auto& t : threads) t->SPUPs[i].m_mutex.unlock(); + for (auto& t : threads) ((SPUThread*)t.get())->SPUPs[i]->m_mutex.unlock(); } else { diff --git a/rpcs3/Emu/SysCalls/lv2/sys_spu.h b/rpcs3/Emu/SysCalls/lv2/sys_spu.h index 6cf66a7bcb..e71c606bf7 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_spu.h +++ b/rpcs3/Emu/SysCalls/lv2/sys_spu.h @@ -161,8 +161,8 @@ u32 LoadSpuImage(vfsStream& stream, u32& spu_ep); // Aux s32 spu_image_import(sys_spu_image& img, u32 src, u32 type); -SpuGroupInfo* spu_thread_group_create(const std::string& name, u32 num, s32 prio, s32 type, u32 container); -SPUThread* spu_thread_initialize(SpuGroupInfo* group, u32 spu_num, sys_spu_image& img, const std::string& name, u32 option, u64 a1, u64 a2, u64 a3, u64 a4, std::function task = nullptr); +std::shared_ptr spu_thread_group_create(const std::string& name, u32 num, s32 prio, s32 type, u32 container); +SPUThread* spu_thread_initialize(std::shared_ptr& group, u32 spu_num, sys_spu_image& img, const std::string& name, u32 option, u64 a1, u64 a2, u64 a3, u64 a4, std::function task = nullptr); // SysCalls s32 sys_spu_initialize(u32 max_usable_spu, u32 max_raw_spu); diff --git a/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp b/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp index 76cce5c01f..81af2d8d13 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_timer.cpp @@ -13,7 +13,8 @@ s32 sys_timer_create(vm::ptr timer_id) { sys_timer.Warning("sys_timer_create(timer_id_addr=0x%x)", timer_id.addr()); - *timer_id = sys_timer.GetNewId(new timer, TYPE_TIMER); + std::shared_ptr timer_data(new timer); + *timer_id = sys_timer.GetNewId(timer_data, TYPE_TIMER); return CELL_OK; } @@ -31,7 +32,7 @@ s32 sys_timer_get_information(u32 timer_id, vm::ptr inf { sys_timer.Warning("sys_timer_get_information(timer_id=%d, info_addr=0x%x)", timer_id, info.addr()); - timer* timer_data = nullptr; + std::shared_ptr timer_data = nullptr; if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH; *info = timer_data->timer_information_t; @@ -42,7 +43,7 @@ s32 sys_timer_start(u32 timer_id, s64 base_time, u64 period) { sys_timer.Warning("sys_timer_start_periodic_absolute(timer_id=%d, basetime=%lld, period=%llu)", timer_id, base_time, period); - timer* timer_data = nullptr; + std::shared_ptr timer_data = nullptr; if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH; if(timer_data->timer_information_t.timer_state != SYS_TIMER_STATE_STOP) return CELL_EBUSY; @@ -66,7 +67,7 @@ s32 sys_timer_stop(u32 timer_id) { sys_timer.Todo("sys_timer_stop()"); - timer* timer_data = nullptr; + std::shared_ptr timer_data = nullptr; if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH; timer_data->timer_information_t.timer_state = SYS_TIMER_STATE_STOP; @@ -78,8 +79,8 @@ s32 sys_timer_connect_event_queue(u32 timer_id, u32 queue_id, u64 name, u64 data sys_timer.Warning("sys_timer_connect_event_queue(timer_id=%d, queue_id=%d, name=%llu, data1=%llu, data2=%llu)", timer_id, queue_id, name, data1, data2); - timer* timer_data = nullptr; - EventQueue* equeue = nullptr; + std::shared_ptr timer_data = nullptr; + std::shared_ptr equeue = nullptr; if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH; if(!sys_timer.CheckId(queue_id, equeue)) return CELL_ESRCH; @@ -92,7 +93,7 @@ s32 sys_timer_disconnect_event_queue(u32 timer_id) { sys_timer.Todo("sys_timer_disconnect_event_queue(timer_id=%d)", timer_id); - timer* timer_data = nullptr; + std::shared_ptr timer_data = nullptr; if(!sys_timer.CheckId(timer_id, timer_data)) return CELL_ESRCH; //TODO: ? diff --git a/rpcs3/Emu/SysCalls/lv2/sys_vm.cpp b/rpcs3/Emu/SysCalls/lv2/sys_vm.cpp index d2557be42d..ed0615c13b 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_vm.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_vm.cpp @@ -7,7 +7,7 @@ #include "sys_vm.h" SysCallBase sys_vm("sys_vm"); -MemoryContainerInfo* current_ct; +std::shared_ptr current_ct; s32 sys_vm_memory_map(u32 vsize, u32 psize, u32 cid, u64 flag, u64 policy, u32 addr) { @@ -33,12 +33,12 @@ s32 sys_vm_memory_map(u32 vsize, u32 psize, u32 cid, u64 flag, u64 policy, u32 a if(cid == SYS_MEMORY_CONTAINER_ID_INVALID) { // Create a new MemoryContainerInfo to act as default container with vsize. - current_ct = new MemoryContainerInfo(new_addr, vsize); + current_ct.reset(new MemoryContainerInfo(new_addr, vsize)); } else { // Check memory container. - MemoryContainerInfo* ct; + std::shared_ptr ct; if(!sys_vm.CheckId(cid, ct)) return CELL_ESRCH; current_ct = ct; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index dc661ddf68..ab9cd94ec0 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -103,41 +103,41 @@ void Emulator::SetTitleID(const std::string& id) void Emulator::CheckStatus() { - std::vector& threads = GetCPU().GetThreads(); - if (!threads.size()) - { - Stop(); - return; - } + //auto& threads = GetCPU().GetThreads(); + //if (!threads.size()) + //{ + // Stop(); + // return; + //} - bool IsAllPaused = true; - for (u32 i = 0; i < threads.size(); ++i) - { - if (threads[i]->IsPaused()) continue; - IsAllPaused = false; - break; - } + //bool IsAllPaused = true; + //for (u32 i = 0; i < threads.size(); ++i) + //{ + // if (threads[i]->IsPaused()) continue; + // IsAllPaused = false; + // break; + //} - if(IsAllPaused) - { - //ConLog.Warning("all paused!"); - Pause(); - return; - } + //if(IsAllPaused) + //{ + // //ConLog.Warning("all paused!"); + // Pause(); + // return; + //} - bool IsAllStoped = true; - for (u32 i = 0; i < threads.size(); ++i) - { - if (threads[i]->IsStopped()) continue; - IsAllStoped = false; - break; - } + //bool IsAllStoped = true; + //for (u32 i = 0; i < threads.size(); ++i) + //{ + // if (threads[i]->IsStopped()) continue; + // IsAllStoped = false; + // break; + //} - if (IsAllStoped) - { - //ConLog.Warning("all stoped!"); - Pause(); //Stop(); - } + //if (IsAllStoped) + //{ + // //ConLog.Warning("all stoped!"); + // Pause(); //Stop(); + //} } bool Emulator::BootGame(const std::string& path, bool direct, int device) diff --git a/rpcs3/Gui/InterpreterDisAsm.cpp b/rpcs3/Gui/InterpreterDisAsm.cpp index 7750fc5c9d..1a62a4224c 100644 --- a/rpcs3/Gui/InterpreterDisAsm.cpp +++ b/rpcs3/Gui/InterpreterDisAsm.cpp @@ -108,13 +108,12 @@ void InterpreterDisAsmFrame::UpdateUnitList() { m_choice_units->Freeze(); m_choice_units->Clear(); - auto& thrs = Emu.GetCPU().GetThreads(); + //auto& thrs = Emu.GetCPU().GetThreads(); - for(uint i=0; iGetType() != CPU_THREAD_ARMv7) - m_choice_units->Append(thrs[i]->GetFName(), thrs[i]); - } + //for (auto& t : thrs) + //{ + // m_choice_units->Append(t->GetFName(), t.get()); + //} m_choice_units->Thaw(); } diff --git a/rpcs3/Gui/KernelExplorer.cpp b/rpcs3/Gui/KernelExplorer.cpp index ad6eedc461..c110fa66ff 100644 --- a/rpcs3/Gui/KernelExplorer.cpp +++ b/rpcs3/Gui/KernelExplorer.cpp @@ -53,200 +53,200 @@ void KernelExplorer::Update() // 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 '%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); - } - } + //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 '%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); + // } + //} // 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 '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_MUTEX, id).c_str()); - m_tree->AppendItem(node, name); - } - } + //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 '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_MUTEX, id).c_str()); + // 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 '%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); - } - } + //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 '%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); + // } + //} // 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 '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_COND, id).c_str()); - m_tree->AppendItem(node, name); - } - } + //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 '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_COND, id).c_str()); + // 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); + //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 '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_LWCOND, id).c_str()); - m_tree->AppendItem(node, name); - } - } + // for (const auto& id : objects) + // { + // sprintf(name, "LW Condition Variable: ID = 0x%08x '%s'", id, Emu.GetSyncPrimManager().GetSyncPrimName(TYPE_LWCOND, id).c_str()); + // 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); - } - } + //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 (%l)", 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); - } - } + //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 (%l)", 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); - } - } + //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); - } - } + //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); + // } + //} // PPU / SPU / RawSPU threads { // TODO: add mutexes owners - const auto& objects = Emu.GetCPU().GetThreads(); + //const auto& objects = Emu.GetCPU().GetThreads(); u32 ppu_threads_count = 0; u32 spu_threads_count = 0; u32 raw_spu_threads_count = 0; - for (const auto& thread : objects) - { - if (thread->GetType() == CPU_THREAD_PPU) - ppu_threads_count++; + //for (const auto& thread : objects) + //{ + // if (thread->GetType() == CPU_THREAD_PPU) + // ppu_threads_count++; - if (thread->GetType() == CPU_THREAD_SPU) - spu_threads_count++; + // if (thread->GetType() == CPU_THREAD_SPU) + // spu_threads_count++; - if (thread->GetType() == CPU_THREAD_RAW_SPU) - raw_spu_threads_count++; - } + // if (thread->GetType() == CPU_THREAD_RAW_SPU) + // raw_spu_threads_count++; + //} - if (ppu_threads_count) - { - sprintf(name, "PPU Threads (%d)", ppu_threads_count); - const auto& node = m_tree->AppendItem(root, name); + //if (ppu_threads_count) + //{ + // sprintf(name, "PPU Threads (%d)", ppu_threads_count); + // const auto& node = m_tree->AppendItem(root, name); - for (const auto& thread : objects) - { - if (thread->GetType() == CPU_THREAD_PPU) - { - sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); - m_tree->AppendItem(node, name); - } - } - } + // for (const auto& thread : objects) + // { + // if (thread->GetType() == CPU_THREAD_PPU) + // { + // sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); + // m_tree->AppendItem(node, name); + // } + // } + //} - if (spu_threads_count) - { - sprintf(name, "SPU Threads (%d)", spu_threads_count); - const auto& node = m_tree->AppendItem(root, name); + //if (spu_threads_count) + //{ + // sprintf(name, "SPU Threads (%d)", spu_threads_count); + // const auto& node = m_tree->AppendItem(root, name); - for (const auto& thread : objects) - { - if (thread->GetType() == CPU_THREAD_SPU) - { - sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); - m_tree->AppendItem(node, name); - } - } - } + // for (const auto& thread : objects) + // { + // if (thread->GetType() == CPU_THREAD_SPU) + // { + // sprintf(name, "Thread: ID = 0x%08x '%s', - %s", thread->GetId(), thread->GetName().c_str(), thread->ThreadStatusToString().c_str()); + // m_tree->AppendItem(node, name); + // } + // } + //} - if (raw_spu_threads_count) - { - sprintf(name, "RawSPU Threads (%d)", raw_spu_threads_count); - const auto& node = m_tree->AppendItem(root, name); + //if (raw_spu_threads_count) + //{ + // sprintf(name, "RawSPU Threads (%d)", raw_spu_threads_count); + // const auto& node = m_tree->AppendItem(root, name); - for (const auto& thread : objects) - { - 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()); - m_tree->AppendItem(node, name); - } - } - } + // for (const auto& thread : objects) + // { + // 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()); + // m_tree->AppendItem(node, name); + // } + // } + //} }