mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-24 20:35:01 +00:00
Add initial Linux support.
This commit is contained in:
parent
8acfc3d557
commit
1e57195ded
7 changed files with 130 additions and 48 deletions
|
@ -1,5 +1,11 @@
|
|||
#include "../Core/PS4/Loader/Elf.h"
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#include "../Util/Log.h"
|
||||
|
||||
namespace Memory
|
||||
|
@ -9,18 +15,31 @@ namespace Memory
|
|||
u64 memory_alloc(u64 address, u64 size)
|
||||
{
|
||||
//TODO it supports only execute_read_write mode
|
||||
auto ptr = reinterpret_cast<uintptr_t>(VirtualAlloc(reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)),
|
||||
size,
|
||||
static_cast<DWORD>(MEM_COMMIT) | static_cast<DWORD>(MEM_RESERVE),
|
||||
PAGE_EXECUTE_READWRITE));
|
||||
#ifdef _WIN64
|
||||
auto ptr = reinterpret_cast<uintptr_t>(VirtualAlloc(reinterpret_cast<LPVOID>(static_cast<uintptr_t>(address)),
|
||||
size,
|
||||
static_cast<DWORD>(MEM_COMMIT) | static_cast<DWORD>(MEM_RESERVE),
|
||||
PAGE_EXECUTE_READWRITE));
|
||||
|
||||
if (ptr == 0)
|
||||
{
|
||||
auto err = static_cast<u32>(GetLastError());
|
||||
LOG_ERROR_IF(true,"VirtualAlloc() failed: 0x{:X}\n", err);
|
||||
}
|
||||
if (ptr == 0)
|
||||
{
|
||||
auto err = static_cast<u32>(GetLastError());
|
||||
LOG_ERROR_IF(true, "VirtualAlloc() failed: 0x{:X}\n", err);
|
||||
}
|
||||
#else
|
||||
auto ptr = reinterpret_cast<uintptr_t>(mmap(reinterpret_cast<void *>(static_cast<uintptr_t>(address)),
|
||||
size,
|
||||
PROT_EXEC | PROT_READ | PROT_WRITE,
|
||||
MAP_ANONYMOUS | MAP_PRIVATE,
|
||||
-1,
|
||||
0));
|
||||
|
||||
if (ptr == reinterpret_cast<uintptr_t>MAP_FAILED)
|
||||
{
|
||||
LOG_ERROR_IF(true, "mmap() failed: {}\n", std::strerror(errno));
|
||||
}
|
||||
#endif
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue