diff --git a/rpcs3/Emu/Memory/Memory.cpp b/rpcs3/Emu/Memory/Memory.cpp index 4188cb3170..44b5fa408f 100644 --- a/rpcs3/Emu/Memory/Memory.cpp +++ b/rpcs3/Emu/Memory/Memory.cpp @@ -516,7 +516,7 @@ VirtualMemoryBlock::VirtualMemoryBlock() : MemoryBlock() bool VirtualMemoryBlock::IsInMyRange(const u64 addr) { - return addr >= GetStartAddr() && addr < GetStartAddr() + GetSize(); + return addr >= GetStartAddr() && addr < GetStartAddr() + GetSize() - GetResevedAmount(); } bool VirtualMemoryBlock::IsInMyRange(const u64 addr, const u32 size) @@ -549,10 +549,11 @@ u64 VirtualMemoryBlock::Map(u64 realaddr, u32 size, u64 addr) } else { - for(u64 addr = GetStartAddr(); addr <= GetEndAddr() - size;) + for(u64 addr = GetStartAddr(); addr <= GetEndAddr() - GetResevedAmount() - size;) { bool is_good_addr = true; + // check if address is already mapped for(u32 i=0; i= m_mapped_memory[i].addr && addr < m_mapped_memory[i].addr + m_mapped_memory[i].size) || @@ -579,7 +580,7 @@ bool VirtualMemoryBlock::UnmapRealAddress(u64 realaddr) { for(u32 i=0; i GetEndAddr() - GetStartAddr()) + return false; + + m_reserve_size += size; + return true; +} + +bool VirtualMemoryBlock::Unreserve(u32 size) +{ + if(size > GetResevedAmount()) + return false; + + m_reserve_size -= size; + return true; +} + +u32 VirtualMemoryBlock::GetResevedAmount() +{ + return m_reserve_size; } \ No newline at end of file diff --git a/rpcs3/Emu/Memory/MemoryBlock.h b/rpcs3/Emu/Memory/MemoryBlock.h index 793af5ca4d..f9d7c6fefd 100644 --- a/rpcs3/Emu/Memory/MemoryBlock.h +++ b/rpcs3/Emu/Memory/MemoryBlock.h @@ -226,6 +226,7 @@ private: class VirtualMemoryBlock : public MemoryBlock { Array m_mapped_memory; + u32 m_reserve_size; public: VirtualMemoryBlock(); @@ -245,6 +246,15 @@ public: // Unmap address (please specify only starting point, no midway memory will be unmapped) virtual bool UnmapAddress(u64 addr); + // Reserve a certain amount so no one can use it, returns true on succces, false on failure + virtual bool Reserve(u32 size); + + // Unreserve a certain amount of bytes, returns true on succcess, false if size is bigger than the reserved amount + virtual bool Unreserve(u32 size); + + // Return the total amount of reserved memory + virtual u32 GetResevedAmount(); + virtual bool Read8(const u64 addr, u8* value); virtual bool Read16(const u64 addr, u16* value); virtual bool Read32(const u64 addr, u32* value);