diff --git a/Common/CodeBlock.h b/Common/CodeBlock.h index 0307cf9df6..e2f269ed29 100644 --- a/Common/CodeBlock.h +++ b/Common/CodeBlock.h @@ -136,7 +136,7 @@ public: // Call this when shutting down. Don't rely on the destructor, even though it'll do the job. void FreeCodeSpace() { ProtectMemoryPages(region, region_size, MEM_PROT_READ | MEM_PROT_WRITE); - FreeMemoryPages(region, region_size); + FreeExecutableMemory(region, region_size); region = nullptr; writableRegion = nullptr; region_size = 0; diff --git a/Common/Data/Collections/FixedSizeQueue.h b/Common/Data/Collections/FixedSizeQueue.h index ed7eb14a75..e8578c6bd8 100644 --- a/Common/Data/Collections/FixedSizeQueue.h +++ b/Common/Data/Collections/FixedSizeQueue.h @@ -30,15 +30,11 @@ template class FixedSizeQueue { public: FixedSizeQueue() { - // Allocate aligned memory, just because. - //int sizeInBytes = N * sizeof(T); - //storage_ = (T *)AllocateMemoryPages(sizeInBytes); storage_ = new T[N]; clear(); } ~FixedSizeQueue() { - // FreeMemoryPages((void *)storage_, N * sizeof(T)); delete [] storage_; } diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index 762b63bb15..cee1e33eca 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -275,6 +275,10 @@ void FreeMemoryPages(void *ptr, size_t size) { #endif } +void FreeExecutableMemory(void *ptr, size_t size) { + FreeMemoryPages(ptr, size); +} + void FreeAlignedMemory(void* ptr) { if (!ptr) return; diff --git a/Common/MemoryUtil.h b/Common/MemoryUtil.h index 2807d12957..865209f7ca 100644 --- a/Common/MemoryUtil.h +++ b/Common/MemoryUtil.h @@ -31,9 +31,11 @@ bool PlatformIsWXExclusive(); // Note that some platforms go through special contortions to allocate executable memory. So for memory // that's intended for execution, allocate it first using AllocateExecutableMemory, then modify protection as desired. -// AllocateMemoryPages is simpler and more generic. Note that on W^X platforms, this will return executable but not writable -// memory! +// AllocateMemoryPages is simpler and more generic. +// Note that on W^X platforms, this will return writable memory that can later be changed to executable! void* AllocateExecutableMemory(size_t size); +void FreeExecutableMemory(void *ptr, size_t size); + void* AllocateMemoryPages(size_t size, uint32_t memProtFlags); // Note that on platforms returning PlatformIsWXExclusive, you cannot set a page to be both readable and writable at the same time. bool ProtectMemoryPages(const void* ptr, size_t size, uint32_t memProtFlags);