1
0
mirror of https://github.com/xmrig/xmrig.git synced 2025-12-06 23:52:38 -05:00

Merge pull request #915 from SChernykh/dev

Make JIT memory read-only after patching is done
This commit is contained in:
xmrig
2019-01-19 17:55:54 +07:00
committed by GitHub
4 changed files with 15 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ public:
static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info);
static void *allocateExecutableMemory(size_t size);
static void protectExecutableMemory(void *p, size_t size);
static void flushInstructionCache(void *p, size_t size);
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }

View File

@@ -100,6 +100,12 @@ void *Mem::allocateExecutableMemory(size_t size)
}
void Mem::protectExecutableMemory(void *p, size_t size)
{
mprotect(p, size, PROT_READ | PROT_EXEC);
}
void Mem::flushInstructionCache(void *p, size_t size)
{
# ifndef __FreeBSD__

View File

@@ -191,6 +191,13 @@ void *Mem::allocateExecutableMemory(size_t size)
}
void Mem::protectExecutableMemory(void *p, size_t size)
{
DWORD oldProtect;
VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect);
}
void Mem::flushInstructionCache(void *p, size_t size)
{
::FlushInstructionCache(GetCurrentProcess(), p, size);

View File

@@ -118,6 +118,7 @@ void xmrig::CpuThread::patchAsmVariants()
patchCode(cn_half_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK);
patchCode(cn_half_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_HALF_ITER, xmrig::CRYPTONIGHT_MASK);
Mem::protectExecutableMemory(base, allocation_size);
Mem::flushInstructionCache(base, allocation_size);
}
#endif