Merge pull request #3386 from lioncash/memory

Common: Namespace MemoryUtil
This commit is contained in:
JosJuice
2016-08-19 11:04:45 +02:00
committed by GitHub
15 changed files with 49 additions and 47 deletions

View File

@ -42,7 +42,7 @@ public:
void AllocCodeSpace(int size, bool need_low = true)
{
region_size = size;
region = (u8*)AllocateExecutableMemory(region_size, need_low);
region = static_cast<u8*>(Common::AllocateExecutableMemory(region_size, need_low));
T::SetCodePtr(region);
}
@ -57,7 +57,7 @@ public:
// Call this when shutting down. Don't rely on the destructor, even though it'll do the job.
void FreeCodeSpace()
{
FreeMemoryPages(region, region_size);
Common::FreeMemoryPages(region, region_size);
region = nullptr;
region_size = 0;
parent_region_size = 0;
@ -71,7 +71,7 @@ public:
bool IsInSpace(u8* ptr) const { return (ptr >= region) && (ptr < (region + region_size)); }
// Cannot currently be undone. Will write protect the entire code region.
// Start over if you need to change the code (call FreeCodeSpace(), AllocCodeSpace()).
void WriteProtect() { WriteProtectMemory(region, region_size, true); }
void WriteProtect() { Common::WriteProtectMemory(region, region_size, true); }
void ResetCodePtr() { T::SetCodePtr(region); }
size_t GetSpaceLeft() const
{

View File

@ -31,6 +31,9 @@
// Uncomment the following line to be able to run Dolphin in Valgrind.
//#undef MAP_32BIT
namespace Common
{
#if !defined(_WIN32)
#include <unistd.h>
static uintptr_t RoundPage(uintptr_t addr)
@ -273,3 +276,5 @@ size_t MemPhysical()
return (size_t)memInfo.totalram * memInfo.mem_unit;
#endif
}
} // namespace Common

View File

@ -7,6 +7,9 @@
#include <cstddef>
#include <string>
namespace Common
{
void* AllocateExecutableMemory(size_t size, bool low = true);
void* AllocateMemoryPages(size_t size);
void FreeMemoryPages(void* ptr, size_t size);
@ -18,10 +21,4 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute = false);
std::string MemUsage();
size_t MemPhysical();
void GuardMemoryMake(void* ptr, size_t size);
void GuardMemoryUnmake(void* ptr, size_t size);
inline int GetPageSize()
{
return 4096;
}
} // namespace Common