summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MemArenaWin.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2023-09-02 12:37:13 -0400
committerGitHub <noreply@github.com>2023-09-02 12:37:13 -0400
commit6beaee078baeaa80f9f1c21ce372ce28fd8273b6 (patch)
treea0a45e35d77c1c14f0f52721e05cd6175d271a47 /Source/Core/Common/MemArenaWin.cpp
parent5e5887a378db28324a8fc8825f21539525412e12 (diff)
parentf1c1c6ded690b34c8e5add75fecc96fff00848e5 (diff)
Merge pull request #12150 from AdmiralCurtiss/fast-block-cache-fix
JitCache: Fix potentially dangling pointer to fast block map.
Diffstat (limited to 'Source/Core/Common/MemArenaWin.cpp')
-rw-r--r--Source/Core/Common/MemArenaWin.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/Source/Core/Common/MemArenaWin.cpp b/Source/Core/Common/MemArenaWin.cpp
index 9d4a88d54a..ebf078f45b 100644
--- a/Source/Core/Common/MemArenaWin.cpp
+++ b/Source/Core/Common/MemArenaWin.cpp
@@ -433,4 +433,47 @@ void MemArena::UnmapFromMemoryRegion(void* view, size_t size)
UnmapViewOfFile(view);
}
+
+LazyMemoryRegion::LazyMemoryRegion() = default;
+
+LazyMemoryRegion::~LazyMemoryRegion()
+{
+ Release();
+}
+
+void* LazyMemoryRegion::Create(size_t size)
+{
+ ASSERT(!m_memory);
+
+ void* memory = VirtualAlloc(nullptr, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+ if (!memory)
+ {
+ NOTICE_LOG_FMT(MEMMAP, "Memory allocation of {} bytes failed.", size);
+ return nullptr;
+ }
+
+ m_memory = memory;
+ m_size = size;
+
+ return memory;
+}
+
+void LazyMemoryRegion::Clear()
+{
+ ASSERT(m_memory);
+
+ VirtualFree(m_memory, m_size, MEM_DECOMMIT);
+ VirtualAlloc(m_memory, m_size, MEM_COMMIT, PAGE_READWRITE);
+}
+
+void LazyMemoryRegion::Release()
+{
+ if (m_memory)
+ {
+ VirtualFree(m_memory, 0, MEM_RELEASE);
+ m_memory = nullptr;
+ m_size = 0;
+ }
+}
+
} // namespace Common