From ac43cd4f9cfb4f1c50d696f31979e6444140bb7d Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 4 Jun 2019 15:48:32 +0700 Subject: [PATCH] Added unprotectExecutableMemory for future use. --- src/crypto/common/VirtualMemory.h | 1 + src/crypto/common/VirtualMemory_unix.cpp | 6 ++++++ src/crypto/common/VirtualMemory_win.cpp | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/src/crypto/common/VirtualMemory.h b/src/crypto/common/VirtualMemory.h index 262b732a6..e8acb017e 100644 --- a/src/crypto/common/VirtualMemory.h +++ b/src/crypto/common/VirtualMemory.h @@ -43,6 +43,7 @@ public: static void flushInstructionCache(void *p, size_t size); static void freeLargePagesMemory(void *p, size_t size); static void protectExecutableMemory(void *p, size_t size); + static void unprotectExecutableMemory(void *p, size_t size); }; diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp index 0297520a1..beac976d0 100644 --- a/src/crypto/common/VirtualMemory_unix.cpp +++ b/src/crypto/common/VirtualMemory_unix.cpp @@ -82,3 +82,9 @@ void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size) { mprotect(p, size, PROT_READ | PROT_EXEC); } + + +void xmrig::VirtualMemory::unprotectExecutableMemory(void *p, size_t size) +{ + mprotect(p, size, PROT_WRITE | PROT_EXEC); +} diff --git a/src/crypto/common/VirtualMemory_win.cpp b/src/crypto/common/VirtualMemory_win.cpp index 43b02f38c..dd6be14f4 100644 --- a/src/crypto/common/VirtualMemory_win.cpp +++ b/src/crypto/common/VirtualMemory_win.cpp @@ -77,3 +77,10 @@ void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size) DWORD oldProtect; VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect); } + + +void xmrig::VirtualMemory::unprotectExecutableMemory(void *p, size_t size) +{ + DWORD oldProtect; + VirtualProtect(p, size, PAGE_EXECUTE_READWRITE, &oldProtect); +}