diff --git a/src/Mem.cpp b/src/Mem.cpp index bb2da646..1e7e1e3c 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -6,7 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/Mem.h b/src/Mem.h index 0aa6eb4d..21616a40 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -6,7 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,8 +23,8 @@ * along with this program. If not, see . */ -#ifndef __MEM_H__ -#define __MEM_H__ +#ifndef XMRIG_MEM_H +#define XMRIG_MEM_H #include @@ -59,8 +60,8 @@ public: static void init(bool enabled); static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info); - static void* allocate_executable_memory(size_t size); - static void FlushInstructionCache(void* p, size_t size); + static void *allocateExecutableMemory(size_t size); + static void flushInstructionCache(void *p, size_t size); static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } @@ -73,4 +74,4 @@ private: }; -#endif /* __MEM_H__ */ +#endif /* XMRIG_MEM_H */ diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index af7791bd..7db761ae 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -6,7 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -89,7 +90,7 @@ void Mem::release(MemInfo &info) } -void* Mem::allocate_executable_memory(size_t size) +void *Mem::allocateExecutableMemory(size_t size) { # if defined(__APPLE__) return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); @@ -99,7 +100,7 @@ void* Mem::allocate_executable_memory(size_t size) } -void Mem::FlushInstructionCache(void* p, size_t size) +void Mem::flushInstructionCache(void *p, size_t size) { __builtin___clear_cache(reinterpret_cast(p), reinterpret_cast(p) + size); } diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index 2fad191d..c43b2ce4 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -6,7 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -184,13 +185,13 @@ void Mem::release(MemInfo &info) } -void* Mem::allocate_executable_memory(size_t size) +void *Mem::allocateExecutableMemory(size_t size) { return VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); } -void Mem::FlushInstructionCache(void* p, size_t size) +void Mem::flushInstructionCache(void *p, size_t size) { ::FlushInstructionCache(GetCurrentProcess(), p, size); } diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index 0c3fd52a..d3ff25bc 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -568,7 +568,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); +extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx *ctx0, cryptonight_ctx *ctx1); extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm; diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index cf366860..5b7016e4 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -5,7 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -29,9 +29,9 @@ #include "common/log/Log.h" #include "common/net/Pool.h" #include "crypto/Asm.h" +#include "Mem.h" #include "rapidjson/document.h" #include "workers/CpuThread.h" -#include "Mem.h" #if defined(XMRIG_ARM) @@ -61,10 +61,12 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma { const uint8_t* p = reinterpret_cast(src); - // Workaround for Visual Studio placing trampoline in debug builds + // Workaround for Visual Studio placing trampoline in debug builds. +# if defined(_MSC_VER) if (p[0] == 0xE9) { p += *(int32_t*)(p + 1) + 5; } +# endif size_t size = 0; while (*(uint32_t*)(p + size) != 0x90909090) { @@ -79,6 +81,7 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma case xmrig::CRYPTONIGHT_ITER: *(uint32_t*)(patched_data + i) = iterations; break; + case xmrig::CRYPTONIGHT_MASK: *(uint32_t*)(patched_data + i) = mask; break; @@ -86,20 +89,23 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma } } + extern "C" void cnv2_mainloop_ivybridge_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_ryzen_asm(cryptonight_ctx *ctx); extern "C" void cnv2_mainloop_bulldozer_asm(cryptonight_ctx *ctx); -extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx* ctx0, cryptonight_ctx* ctx1); +extern "C" void cnv2_double_mainloop_sandybridge_asm(cryptonight_ctx *ctx0, cryptonight_ctx *ctx1); + xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ivybridge_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_ryzen_asm = nullptr; xmrig::CpuThread::cn_mainloop_fun cn_half_mainloop_bulldozer_asm = nullptr; xmrig::CpuThread::cn_mainloop_double_fun cn_half_double_mainloop_sandybridge_asm = nullptr; + void xmrig::CpuThread::patchAsmVariants() { const int allocation_size = 65536; - uint8_t* base = reinterpret_cast(Mem::allocate_executable_memory(allocation_size)); + uint8_t *base = static_cast(Mem::allocateExecutableMemory(allocation_size)); cn_half_mainloop_ivybridge_asm = reinterpret_cast (base + 0x0000); cn_half_mainloop_ryzen_asm = reinterpret_cast (base + 0x1000); @@ -111,10 +117,11 @@ 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::FlushInstructionCache(base, allocation_size); + Mem::flushInstructionCache(base, allocation_size); } #endif + bool xmrig::CpuThread::isSoftAES(AlgoVariant av) { return av == AV_SINGLE_SOFT || av == AV_DOUBLE_SOFT || av > AV_PENTA; diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index e9d764da..a31be058 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index e285005e..d6201ebf 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 1d619cea..61868819 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __WORKERS_H__ -#define __WORKERS_H__ +#ifndef XMRIG_WORKERS_H +#define XMRIG_WORKERS_H #include @@ -118,4 +119,4 @@ private: }; -#endif /* __WORKERS_H__ */ +#endif /* XMRIG_WORKERS_H */