From e74573f81f1b38b4e606b52c39165737656c7f57 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 1 Feb 2021 22:36:11 +0100 Subject: [PATCH 1/3] Fixed code allocation for ARM --- src/crypto/randomx/jit_compiler_a64.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/crypto/randomx/jit_compiler_a64.cpp b/src/crypto/randomx/jit_compiler_a64.cpp index da1d2471..fda829be 100644 --- a/src/crypto/randomx/jit_compiler_a64.cpp +++ b/src/crypto/randomx/jit_compiler_a64.cpp @@ -108,6 +108,7 @@ JitCompilerA64::JitCompilerA64(bool hugePagesEnable, bool) : hugePages(hugePagesJIT && hugePagesEnable), literalPos(ImulRcpLiteralsEnd) { + allocate(CodeSize); } JitCompilerA64::~JitCompilerA64() @@ -117,13 +118,8 @@ JitCompilerA64::~JitCompilerA64() void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& config, uint32_t) { - if (!allocatedSize) { - allocate(CodeSize); - } #ifdef XMRIG_SECURE_JIT - else { - enableWriting(); - } + enableWriting(); #endif uint32_t codePos = MainLoopBegin + 4; @@ -177,13 +173,8 @@ void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& con void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration& config, uint32_t datasetOffset) { - if (!allocatedSize) { - allocate(CodeSize); - } #ifdef XMRIG_SECURE_JIT - else { - enableWriting(); - } + enableWriting(); #endif uint32_t codePos = MainLoopBegin + 4; @@ -244,8 +235,12 @@ void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration template void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[N]) { - if (!allocatedSize) { - allocate(CodeSize + CalcDatasetItemSize()); + const size_t requiredSize = CodeSize + CalcDatasetItemSize(); + if (allocatedSize < requiredSize) { + if (allocatedSize) { + freePagedMemory(code, allocatedSize); + } + allocate(requiredSize); } #ifdef XMRIG_SECURE_JIT else { From db035738046aab3f4edfbe2d17acf297b691b4ac Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 1 Feb 2021 22:42:35 +0100 Subject: [PATCH 2/3] ARM JIT: added missing cache flush --- src/crypto/randomx/jit_compiler_a64.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/crypto/randomx/jit_compiler_a64.cpp b/src/crypto/randomx/jit_compiler_a64.cpp index fda829be..5c8bbea2 100644 --- a/src/crypto/randomx/jit_compiler_a64.cpp +++ b/src/crypto/randomx/jit_compiler_a64.cpp @@ -396,6 +396,10 @@ void JitCompilerA64::allocate(size_t size) code = static_cast(allocExecutableMemory(allocatedSize, hugePages)); memcpy(code, reinterpret_cast(randomx_program_aarch64), CodeSize); + +# ifndef XMRIG_OS_APPLE + xmrig::VirtualMemory::flushInstructionCache(reinterpret_cast(code), CodeSize); +# endif } From 346892e17059888421ee782d3ecb6f263595b773 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 1 Feb 2021 22:52:02 +0100 Subject: [PATCH 3/3] Update jit_compiler_a64.cpp --- src/crypto/randomx/jit_compiler_a64.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/crypto/randomx/jit_compiler_a64.cpp b/src/crypto/randomx/jit_compiler_a64.cpp index 5c8bbea2..c4f0f002 100644 --- a/src/crypto/randomx/jit_compiler_a64.cpp +++ b/src/crypto/randomx/jit_compiler_a64.cpp @@ -108,7 +108,6 @@ JitCompilerA64::JitCompilerA64(bool hugePagesEnable, bool) : hugePages(hugePagesJIT && hugePagesEnable), literalPos(ImulRcpLiteralsEnd) { - allocate(CodeSize); } JitCompilerA64::~JitCompilerA64() @@ -118,8 +117,13 @@ JitCompilerA64::~JitCompilerA64() void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& config, uint32_t) { + if (!allocatedSize) { + allocate(CodeSize); + } #ifdef XMRIG_SECURE_JIT - enableWriting(); + else { + enableWriting(); + } #endif uint32_t codePos = MainLoopBegin + 4; @@ -173,8 +177,13 @@ void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& con void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration& config, uint32_t datasetOffset) { + if (!allocatedSize) { + allocate(CodeSize); + } #ifdef XMRIG_SECURE_JIT - enableWriting(); + else { + enableWriting(); + } #endif uint32_t codePos = MainLoopBegin + 4; @@ -235,12 +244,8 @@ void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration template void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[N]) { - const size_t requiredSize = CodeSize + CalcDatasetItemSize(); - if (allocatedSize < requiredSize) { - if (allocatedSize) { - freePagedMemory(code, allocatedSize); - } - allocate(requiredSize); + if (!allocatedSize) { + allocate(CodeSize + CalcDatasetItemSize()); } #ifdef XMRIG_SECURE_JIT else {