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
commit 5f9ebdf149
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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