Some semantic cleanup

This commit is contained in:
Henrik Rydgård 2023-04-24 11:42:27 +02:00
parent 7a75119ed0
commit f45a7cf06b
4 changed files with 9 additions and 7 deletions

View file

@ -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;

View file

@ -30,15 +30,11 @@ template <class T, int N>
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_;
}

View file

@ -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;

View file

@ -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);