mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-17 08:17:40 +00:00
Merge pull request #915 from SChernykh/dev
Make JIT memory read-only after patching is done
This commit is contained in:
commit
5f9ebdf149
4 changed files with 15 additions and 0 deletions
|
@ -61,6 +61,7 @@ public:
|
||||||
static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info);
|
static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info);
|
||||||
|
|
||||||
static void *allocateExecutableMemory(size_t size);
|
static void *allocateExecutableMemory(size_t size);
|
||||||
|
static void protectExecutableMemory(void *p, size_t size);
|
||||||
static void flushInstructionCache(void *p, size_t size);
|
static void flushInstructionCache(void *p, size_t size);
|
||||||
|
|
||||||
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }
|
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }
|
||||||
|
|
|
@ -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)
|
void Mem::flushInstructionCache(void *p, size_t size)
|
||||||
{
|
{
|
||||||
# ifndef __FreeBSD__
|
# ifndef __FreeBSD__
|
||||||
|
|
|
@ -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)
|
void Mem::flushInstructionCache(void *p, size_t size)
|
||||||
{
|
{
|
||||||
::FlushInstructionCache(GetCurrentProcess(), p, size);
|
::FlushInstructionCache(GetCurrentProcess(), p, size);
|
||||||
|
|
|
@ -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_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);
|
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);
|
Mem::flushInstructionCache(base, allocation_size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue