diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 180f77bff3..7f6b68fcb4 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -194,7 +194,7 @@ void LogManager::log(LogMessage msg) } if (NamedThreadBase* thr = GetCurrentNamedThread()) { - prefix += thr->GetThreadName(); + prefix += "{" + thr->GetThreadName() + "} "; } msg.mText.insert(0, prefix); msg.mText.append(1,'\n'); diff --git a/rpcs3/Emu/Memory/DynamicMemoryBlockBase.h b/rpcs3/Emu/Memory/DynamicMemoryBlockBase.h index fb45886bbf..6bc225daca 100644 --- a/rpcs3/Emu/Memory/DynamicMemoryBlockBase.h +++ b/rpcs3/Emu/Memory/DynamicMemoryBlockBase.h @@ -161,6 +161,8 @@ u64 DynamicMemoryBlockBase::AllocAlign(u32 size, u32 align) addr = (addr + (align - 1)) & ~(align - 1); } + //LOG_NOTICE(MEMORY, "AllocAlign(size=0x%x) -> 0x%llx", size, addr); + AppendMem(addr, size); return addr; @@ -202,6 +204,8 @@ bool DynamicMemoryBlockBase::Free(u64 addr) m_pages[i] = nullptr; } + //LOG_NOTICE(MEMORY, "Free(0x%llx)", addr); + m_allocated.erase(m_allocated.begin() + num); return true; } diff --git a/rpcs3/Emu/Memory/Memory.h b/rpcs3/Emu/Memory/Memory.h index 4eea68c630..c363528f3f 100644 --- a/rpcs3/Emu/Memory/Memory.h +++ b/rpcs3/Emu/Memory/Memory.h @@ -78,18 +78,32 @@ public: void RegisterPages(u64 addr, u32 size) { + std::lock_guard lock(m_mutex); + + //LOG_NOTICE(MEMORY, "RegisterPages(addr=0x%llx, size=0x%x)", addr, size); for (u32 i = addr / 4096; i < (addr + size) / 4096; i++) { if (i >= sizeof(m_pages) / sizeof(m_pages[0])) break; + if (m_pages[i]) + { + LOG_ERROR(MEMORY, "Page already registered (page=0x%x)", i * 4096); + } m_pages[i] = 1; // TODO: define page parameters } } void UnregisterPages(u64 addr, u32 size) { + std::lock_guard lock(m_mutex); + + //LOG_NOTICE(MEMORY, "UnregisterPages(addr=0x%llx, size=0x%x)", addr, size); for (u32 i = addr / 4096; i < (addr + size) / 4096; i++) { if (i >= sizeof(m_pages) / sizeof(m_pages[0])) break; + if (!m_pages[i]) + { + LOG_ERROR(MEMORY, "Page not registered (page=0x%x)", i * 4096); + } m_pages[i] = 0; // TODO: define page parameters } } @@ -173,8 +187,6 @@ public: void Init(MemoryType type) { - std::lock_guard lock(m_mutex); - if(m_inited) return; m_inited = true; @@ -257,8 +269,6 @@ public: void Close() { - std::lock_guard lock(m_mutex); - if(!m_inited) return; m_inited = false; diff --git a/rpcs3/Emu/Memory/MemoryBlock.h b/rpcs3/Emu/Memory/MemoryBlock.h index d58f5d7f17..caac4efc56 100644 --- a/rpcs3/Emu/Memory/MemoryBlock.h +++ b/rpcs3/Emu/Memory/MemoryBlock.h @@ -27,15 +27,21 @@ struct MemBlockInfo : public MemInfo void Free(); MemBlockInfo(MemBlockInfo &other) = delete; - MemBlockInfo(MemBlockInfo &&other) : MemInfo(other.addr,other.size) ,mem(other.mem) + + MemBlockInfo(MemBlockInfo &&other) + : MemInfo(other.addr,other.size) + , mem(other.mem) { other.mem = nullptr; } + MemBlockInfo& operator =(MemBlockInfo &other) = delete; - MemBlockInfo& operator =(MemBlockInfo &&other){ + + MemBlockInfo& operator =(MemBlockInfo &&other) + { + this->Free(); this->addr = other.addr; this->size = other.size; - this->Free(); this->mem = other.mem; other.mem = nullptr; return *this; diff --git a/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp b/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp index 8546d26345..ed40ca711e 100644 --- a/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/lv2Fs.cpp @@ -144,7 +144,11 @@ s32 cellFsRead(u32 fd, u32 buf_addr, u64 nbytes, mem64_t nread) vfsStream* file; if(!sys_fs->CheckId(fd, file)) return CELL_ESRCH; - if (nread.GetAddr() && !nread.IsGood()) return CELL_EFAULT; + if (nread.GetAddr() && !nread.IsGood()) + { + sys_fs->Error("cellFsRead(): bad nread_addr(0x%x)", nread.GetAddr()); + return CELL_EFAULT; + } if (nbytes != (u32)nbytes) return CELL_ENOMEM; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 54254c4f62..b44a4000a4 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -201,6 +201,10 @@ void Emulator::Load() switch(l.GetMachine()) { case MACHINE_SPU: + Memory.Init(Memory_PS3); + Memory.MainMem.AllocFixed(Memory.MainMem.GetStartAddr(), 0x40000); + break; + case MACHINE_PPC64: Memory.Init(Memory_PS3); break; @@ -263,7 +267,6 @@ void Emulator::Load() LOG_NOTICE(LOADER, "offset = 0x%llx", Memory.MainMem.GetStartAddr()); LOG_NOTICE(LOADER, "max addr = 0x%x", l.GetMaxAddr()); thread.SetOffset(Memory.MainMem.GetStartAddr()); - Memory.MainMem.AllocFixed(Memory.MainMem.GetStartAddr() + l.GetMaxAddr(), 0xFFFFED - l.GetMaxAddr()); thread.SetEntry(l.GetEntry() - Memory.MainMem.GetStartAddr()); break; diff --git a/rpcs3/Loader/ELF32.cpp b/rpcs3/Loader/ELF32.cpp index 5765974566..4e736e34e2 100644 --- a/rpcs3/Loader/ELF32.cpp +++ b/rpcs3/Loader/ELF32.cpp @@ -236,7 +236,7 @@ bool ELF32Loader::LoadPhdrData(u64 _offset) switch(machine) { - case MACHINE_SPU: Memory.MainMem.AllocFixed(phdr_arr[i].p_vaddr + offset, phdr_arr[i].p_memsz); break; + case MACHINE_SPU: break; case MACHINE_MIPS: Memory.PSPMemory.RAM.AllocFixed(phdr_arr[i].p_vaddr + offset, phdr_arr[i].p_memsz); break; case MACHINE_ARM: Memory.PSVMemory.RAM.AllocFixed(phdr_arr[i].p_vaddr + offset, phdr_arr[i].p_memsz); break;