Alternative secure JIT for macOS.
This commit is contained in:
parent
775867fc3e
commit
179f09081f
3 changed files with 30 additions and 9 deletions
|
@ -99,17 +99,18 @@ static size_t CalcDatasetItemSize()
|
|||
constexpr uint32_t IntRegMap[8] = { 4, 5, 6, 7, 12, 13, 14, 15 };
|
||||
|
||||
JitCompilerA64::JitCompilerA64(bool hugePagesEnable)
|
||||
: code((uint8_t*) allocExecutableMemory(CodeSize + CalcDatasetItemSize(), hugePagesJIT && hugePagesEnable))
|
||||
, literalPos(ImulRcpLiteralsEnd)
|
||||
, num32bitLiterals(0)
|
||||
: literalPos(ImulRcpLiteralsEnd)
|
||||
{
|
||||
allocatedSize = CodeSize + CalcDatasetItemSize();
|
||||
code = static_cast<uint8_t*>(allocExecutableMemory(allocatedSize, hugePagesJIT && hugePagesEnable));
|
||||
|
||||
memset(reg_changed_offset, 0, sizeof(reg_changed_offset));
|
||||
memcpy(code, (void*) randomx_program_aarch64, CodeSize);
|
||||
}
|
||||
|
||||
JitCompilerA64::~JitCompilerA64()
|
||||
{
|
||||
freePagedMemory(code, CodeSize + CalcDatasetItemSize());
|
||||
freePagedMemory(code, allocatedSize);
|
||||
}
|
||||
|
||||
void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& config, uint32_t)
|
||||
|
@ -162,7 +163,9 @@ void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& con
|
|||
codePos = ((uint8_t*)randomx_program_aarch64_update_spMix1) - ((uint8_t*)randomx_program_aarch64);
|
||||
emit32(ARMV8A::EOR | 10 | (IntRegMap[config.readReg0] << 5) | (IntRegMap[config.readReg1] << 16), code, codePos);
|
||||
|
||||
# ifndef XMRIG_OS_APPLE
|
||||
xmrig::VirtualMemory::flushInstructionCache(reinterpret_cast<char*>(code + MainLoopBegin), reinterpret_cast<char*>(code + codePos));
|
||||
# endif
|
||||
}
|
||||
|
||||
void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration& config, uint32_t datasetOffset)
|
||||
|
@ -217,7 +220,9 @@ void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration
|
|||
emit32(ARMV8A::ADD_IMM_LO | 2 | (2 << 5) | (imm_lo << 10), code, codePos);
|
||||
emit32(ARMV8A::ADD_IMM_HI | 2 | (2 << 5) | (imm_hi << 10), code, codePos);
|
||||
|
||||
# ifndef XMRIG_OS_APPLE
|
||||
xmrig::VirtualMemory::flushInstructionCache(reinterpret_cast<char*>(code + MainLoopBegin), reinterpret_cast<char*>(code + codePos));
|
||||
# endif
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
|
@ -333,7 +338,9 @@ void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[N])
|
|||
memcpy(code + codePos, p1, p2 - p1);
|
||||
codePos += p2 - p1;
|
||||
|
||||
# ifndef XMRIG_OS_APPLE
|
||||
xmrig::VirtualMemory::flushInstructionCache(reinterpret_cast<char*>(code + CodeSize), reinterpret_cast<char*>(code + codePos));
|
||||
# endif
|
||||
}
|
||||
|
||||
template void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[RANDOMX_CACHE_MAX_ACCESSES]);
|
||||
|
@ -354,12 +361,12 @@ size_t JitCompilerA64::getCodeSize()
|
|||
|
||||
void JitCompilerA64::enableWriting() const
|
||||
{
|
||||
xmrig::VirtualMemory::protectRW(code, CodeSize + CalcDatasetItemSize());
|
||||
xmrig::VirtualMemory::protectRW(code, allocatedSize);
|
||||
}
|
||||
|
||||
void JitCompilerA64::enableExecution() const
|
||||
{
|
||||
xmrig::VirtualMemory::protectRX(code, CodeSize + CalcDatasetItemSize());
|
||||
xmrig::VirtualMemory::protectRX(code, allocatedSize);
|
||||
}
|
||||
|
||||
void JitCompilerA64::emitMovImmediate(uint32_t dst, uint32_t imm, uint8_t* code, uint32_t& codePos)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue