From 7b52a414594730e51c18698fc41493258d396190 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 21 Sep 2022 15:18:06 +0200 Subject: [PATCH] Fix: protectRX flushed CPU cache only on MacOS/iOS --- src/crypto/common/VirtualMemory_unix.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/crypto/common/VirtualMemory_unix.cpp b/src/crypto/common/VirtualMemory_unix.cpp index edda231f..12f4f25f 100644 --- a/src/crypto/common/VirtualMemory_unix.cpp +++ b/src/crypto/common/VirtualMemory_unix.cpp @@ -112,13 +112,19 @@ bool xmrig::VirtualMemory::protectRWX(void *p, size_t size) bool xmrig::VirtualMemory::protectRX(void *p, size_t size) { + bool result = true; + # if defined(XMRIG_OS_APPLE) && defined(XMRIG_ARM) pthread_jit_write_protect_np(true); - flushInstructionCache(p, size); - return true; # else - return mprotect(p, size, PROT_READ | PROT_EXEC) == 0; + result = (mprotect(p, size, PROT_READ | PROT_EXEC) == 0); # endif + +# if defined(XMRIG_ARM) + flushInstructionCache(p, size); +# endif + + return result; }