mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
Memory: Factorize virtual memory reservation/allocation code in function
This commit is contained in:
parent
241dedef4e
commit
942f26509b
5 changed files with 75 additions and 15 deletions
41
Utilities/VirtualMemory.cpp
Normal file
41
Utilities/VirtualMemory.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "stdafx.h"
|
||||
#include "VirtualMemory.h"
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
namespace memory_helper
|
||||
{
|
||||
void* reserve_memory(size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS);
|
||||
#else
|
||||
return mmap(nullptr, size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void commit_page_memory(void* pointer, size_t page_size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
VirtualAlloc((u8*)pointer, page_size, MEM_COMMIT, PAGE_READWRITE);
|
||||
#else
|
||||
mprotect((u8*)pointer, page_size, PROT_READ | PROT_WRITE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void free_reserved_memory(void* pointer, size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
VirtualFree(pointer, 0, MEM_RELEASE);
|
||||
#else
|
||||
munmap(pointer, size);
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue