mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 20:19:23 +00:00
Merge pull request #1977 from SChernykh/dev
Fix: secure JIT and huge pages are incompatible on Windows
This commit is contained in:
commit
4c7d20c8e6
1 changed files with 19 additions and 3 deletions
|
@ -170,16 +170,26 @@ namespace randomx {
|
||||||
{0x0F, 0x1F, 0x44, 0x00, 0x00, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
|
{0x0F, 0x1F, 0x44, 0x00, 0x00, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline uint8_t* alignToPage(uint8_t* p, size_t pageSize) {
|
||||||
|
size_t k = (size_t) p;
|
||||||
|
k -= k % pageSize;
|
||||||
|
return (uint8_t*) k;
|
||||||
|
}
|
||||||
|
|
||||||
size_t JitCompilerX86::getCodeSize() {
|
size_t JitCompilerX86::getCodeSize() {
|
||||||
return codePos < prologueSize ? 0 : codePos - prologueSize;
|
return codePos < prologueSize ? 0 : codePos - prologueSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JitCompilerX86::enableWriting() const {
|
void JitCompilerX86::enableWriting() const {
|
||||||
xmrig::VirtualMemory::protectRW(allocatedCode, allocatedSize);
|
uint8_t* p1 = alignToPage(code, 4096);
|
||||||
|
uint8_t* p2 = code + CodeSize;
|
||||||
|
xmrig::VirtualMemory::protectRW(p1, p2 - p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JitCompilerX86::enableExecution() const {
|
void JitCompilerX86::enableExecution() const {
|
||||||
xmrig::VirtualMemory::protectRX(allocatedCode, allocatedSize);
|
uint8_t* p1 = alignToPage(code, 4096);
|
||||||
|
uint8_t* p2 = code + CodeSize;
|
||||||
|
xmrig::VirtualMemory::protectRX(p1, p2 - p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void cpuid(uint32_t level, int32_t output[4])
|
static inline void cpuid(uint32_t level, int32_t output[4])
|
||||||
|
@ -213,7 +223,13 @@ namespace randomx {
|
||||||
hasXOP = ((info[2] & (1 << 11)) != 0);
|
hasXOP = ((info[2] & (1 << 11)) != 0);
|
||||||
|
|
||||||
allocatedSize = CodeSize * 2;
|
allocatedSize = CodeSize * 2;
|
||||||
allocatedCode = static_cast<uint8_t*>(allocExecutableMemory(allocatedSize, hugePagesJIT && hugePagesEnable));
|
allocatedCode = static_cast<uint8_t*>(allocExecutableMemory(allocatedSize,
|
||||||
|
# ifdef XMRIG_SECURE_JIT
|
||||||
|
false
|
||||||
|
# else
|
||||||
|
hugePagesJIT && hugePagesEnable
|
||||||
|
# endif
|
||||||
|
));
|
||||||
|
|
||||||
// Shift code base address to improve caching - all threads will use different L2/L3 cache sets
|
// Shift code base address to improve caching - all threads will use different L2/L3 cache sets
|
||||||
code = allocatedCode + (codeOffset.fetch_add(codeOffsetIncrement) % CodeSize);
|
code = allocatedCode + (codeOffset.fetch_add(codeOffsetIncrement) % CodeSize);
|
||||||
|
|
Loading…
Reference in a new issue