mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-26 04:32:35 +01:00
Linux fix
This commit is contained in:
parent
6aef58318c
commit
e70875ad5c
@ -102,20 +102,17 @@ void MemoryBase::Init(MemoryType type)
|
||||
memset(m_pages, 0, sizeof(m_pages));
|
||||
memset(RawSPUMem, 0, sizeof(RawSPUMem));
|
||||
|
||||
LOG_NOTICE(MEMORY, "Initializing memory: base_addr = 0x%llx, priv_addr = 0x%llx", (u64)vm::g_base_addr, (u64)vm::g_priv_addr);
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!vm::g_base_addr)
|
||||
if (!vm::g_base_addr || !vm::g_priv_addr)
|
||||
#else
|
||||
if ((s64)vm::g_base_addr == (s64)-1)
|
||||
if ((s64)vm::g_base_addr == (s64)-1 || (s64)vm::g_priv_addr == (s64)-1)
|
||||
#endif
|
||||
{
|
||||
LOG_ERROR(MEMORY, "Initializing memory failed");
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_NOTICE(MEMORY, "Initializing memory: base_addr = 0x%llx", (u64)vm::g_base_addr);
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@ -207,7 +204,7 @@ bool MemoryBase::Map(const u64 addr, const u32 size)
|
||||
}
|
||||
|
||||
MemoryBlocks.push_back((new MemoryBlock())->SetRange(addr, size));
|
||||
|
||||
|
||||
LOG_WARNING(MEMORY, "Memory mapped at 0x%llx: size=0x%x", addr, size);
|
||||
return true;
|
||||
}
|
||||
@ -237,7 +234,7 @@ MemBlockInfo::MemBlockInfo(u64 _addr, u32 _size)
|
||||
#ifdef _WIN32
|
||||
if (!VirtualAlloc(priv_addr, size, MEM_COMMIT, PAGE_READWRITE) || !VirtualAlloc(real_addr, size, MEM_COMMIT, PAGE_READWRITE))
|
||||
#else
|
||||
if (!::mprotect(real_addr, size, PROT_READ | PROT_WRITE) || !::mprotect(priv_addr, size, PROT_READ | PROT_WRITE))
|
||||
if (mprotect(real_addr, size, PROT_READ | PROT_WRITE) || mprotect(priv_addr, size, PROT_READ | PROT_WRITE))
|
||||
#endif
|
||||
{
|
||||
LOG_ERROR(MEMORY, "Memory allocation failed (addr=0x%llx, size=0x%x)", addr, size);
|
||||
@ -261,9 +258,8 @@ void MemBlockInfo::Free()
|
||||
DWORD old;
|
||||
|
||||
if (!VirtualProtect(mem, size, PAGE_NOACCESS, &old) || !VirtualProtect(vm::get_priv_ptr(vm::cast(addr)), size, PAGE_NOACCESS, &old))
|
||||
//if (!VirtualFree(mem, size, MEM_DECOMMIT))
|
||||
#else
|
||||
if (::mprotect(mem, size, PROT_NONE) || !::mprotect(vm::get_priv_ptr(vm::cast(addr)), size, PROT_NONE))
|
||||
if (mprotect(mem, size, PROT_NONE) || mprotect(vm::get_priv_ptr(vm::cast(addr)), size, PROT_NONE))
|
||||
#endif
|
||||
{
|
||||
LOG_ERROR(MEMORY, "Memory deallocation failed (addr=0x%llx, size=0x%x)", addr, size);
|
||||
@ -436,7 +432,7 @@ u64 DynamicMemoryBlockBase::AllocAlign(u32 size, u32 align)
|
||||
LOG_ERROR(MEMORY, "DynamicMemoryBlockBase::AllocAlign(size=0x%x, align=0x%x): memory block not initialized", size, align);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size = PAGE_4K(size);
|
||||
u32 exsize;
|
||||
|
||||
|
@ -14,6 +14,8 @@
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* OS X uses MAP_ANON instead of MAP_ANONYMOUS */
|
||||
#ifndef MAP_ANONYMOUS
|
||||
@ -25,8 +27,6 @@ namespace vm
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HANDLE g_memory_handle;
|
||||
#else
|
||||
int g_memory_handle;
|
||||
#endif
|
||||
|
||||
void* g_priv_addr;
|
||||
@ -43,10 +43,22 @@ namespace vm
|
||||
|
||||
//return VirtualAlloc(nullptr, 0x100000000, MEM_RESERVE, PAGE_NOACCESS);
|
||||
#else
|
||||
g_memory_handle = shm_open("/rpcs3_vm", O_RDWR | O_CREAT | O_EXCL, 0);
|
||||
//shm_unlink("/rpcs3_vm");
|
||||
|
||||
void* base_addr = mmap(nullptr, 0x100000000, PROT_NONE, MAP_PRIVATE, g_memory_handle, 0);
|
||||
g_priv_addr = mmap(nullptr, 0x100000000, PROT_NONE, MAP_PRIVATE, g_memory_handle, 0);
|
||||
int memory_handle = shm_open("/rpcs3_vm", O_RDWR | O_CREAT | O_EXCL, 0);
|
||||
|
||||
if (memory_handle == -1)
|
||||
{
|
||||
printf("shm_open() failed\n");
|
||||
return (void*)-1;
|
||||
}
|
||||
|
||||
ftruncate(memory_handle, 0x100000000);
|
||||
|
||||
void* base_addr = mmap(nullptr, 0x100000000, PROT_NONE, MAP_SHARED, memory_handle, 0);
|
||||
g_priv_addr = mmap(nullptr, 0x100000000, PROT_NONE, MAP_SHARED, memory_handle, 0);
|
||||
|
||||
shm_unlink("/rpcs3_vm");
|
||||
|
||||
return base_addr;
|
||||
|
||||
@ -63,8 +75,6 @@ namespace vm
|
||||
#else
|
||||
munmap(g_base_addr, 0x100000000);
|
||||
munmap(g_priv_addr, 0x100000000);
|
||||
|
||||
shm_unlink("/rpcs3_vm");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -94,7 +104,7 @@ namespace vm
|
||||
while (!m_owner.compare_exchange_strong(old, owner))
|
||||
{
|
||||
std::unique_lock<std::mutex> cv_lock(m_cv_mutex);
|
||||
|
||||
|
||||
m_cv.wait_for(cv_lock, std::chrono::milliseconds(1));
|
||||
|
||||
if (old == owner)
|
||||
@ -146,7 +156,7 @@ namespace vm
|
||||
DWORD old;
|
||||
if (!VirtualProtect(vm::get_ptr(addr & ~0xfff), 4096, PAGE_READONLY, &old))
|
||||
#else
|
||||
if (!::mprotect(vm::get_ptr(addr & ~0xfff), 4096, PROT_READ))
|
||||
if (mprotect(vm::get_ptr(addr & ~0xfff), 4096, PROT_READ))
|
||||
#endif
|
||||
{
|
||||
throw fmt::format("vm::_reservation_set() failed (addr=0x%x)", addr);
|
||||
@ -164,7 +174,7 @@ namespace vm
|
||||
#ifdef _WIN32
|
||||
if (!VirtualAlloc(vm::get_ptr(addr & ~0xfff), 4096, MEM_COMMIT, PAGE_READWRITE))
|
||||
#else
|
||||
if (!::mprotect(vm::get_ptr(addr & ~0xfff), 4096, PROT_READ | PROT_WRITE))
|
||||
if (mprotect(vm::get_ptr(addr & ~0xfff), 4096, PROT_READ | PROT_WRITE))
|
||||
#endif
|
||||
{
|
||||
throw fmt::format("vm::_reservation_break() failed (addr=0x%x)", addr);
|
||||
@ -297,7 +307,7 @@ namespace vm
|
||||
|
||||
// change memory protection to read-only
|
||||
_reservation_set(addr);
|
||||
|
||||
|
||||
// set additional information
|
||||
g_reservation_addr = addr;
|
||||
g_reservation_owner = GetCurrentNamedThread();
|
||||
@ -352,7 +362,7 @@ namespace vm
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
if (real_pointer)
|
||||
{
|
||||
throw fmt::format("vm::get_addr(0x%016llx) failed: not a part of virtual memory", (u64)real_pointer);
|
||||
@ -557,4 +567,4 @@ namespace vm
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user