From f00769f758c11031aa4fbd558e36bf0288a9a2ff Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 28 Dec 2019 01:45:54 +0700 Subject: [PATCH] Code style cleanup. --- CMakeLists.txt | 2 +- cmake/randomx.cmake | 2 ++ src/crypto/rx/Rx.cpp | 8 ++++++-- src/crypto/rx/Rx.h | 18 +++++++++--------- src/crypto/rx/Rx_linux.cpp | 13 ++++--------- src/crypto/rx/Rx_win.cpp | 10 +++++----- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d7084e7..d792ef38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ option(WITH_HTTP "Enable HTTP protocol support (client/server)" ON) option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_TLS "Enable OpenSSL support" ON) option(WITH_ASM "Enable ASM PoW implementations" ON) -option(WITH_MSR "Enable MSR support" ON) +option(WITH_MSR "Enable MSR mod & 1st-gen Ryzen fix" ON) option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF) option(WITH_OPENCL "Enable OpenCL backend" ON) option(WITH_CUDA "Enable CUDA backend" ON) diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index c7b64aab..83180710 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -81,6 +81,7 @@ if (WITH_RANDOMX) if (WITH_MSR AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND (XMRIG_OS_WIN OR XMRIG_OS_LINUX)) add_definitions(/DXMRIG_FEATURE_MSR) + add_definitions(/DXMRIG_FIX_RYZEN) message("-- WITH_MSR=ON") if (XMRIG_OS_WIN) @@ -93,6 +94,7 @@ if (WITH_RANDOMX) list(APPEND SOURCES_CRYPTO src/crypto/rx/msr/MsrItem.cpp) else() remove_definitions(/DXMRIG_FEATURE_MSR) + remove_definitions(/DXMRIG_FIX_RYZEN) message("-- WITH_MSR=OFF") endif() else() diff --git a/src/crypto/rx/Rx.cpp b/src/crypto/rx/Rx.cpp index 2887ab15..c0425409 100644 --- a/src/crypto/rx/Rx.cpp +++ b/src/crypto/rx/Rx.cpp @@ -74,7 +74,7 @@ bool xmrig::Rx::init(const Job &job, const RxConfig &config, const CpuConfig &cp if (!osInitialized) { msrInit(config); - SetupMainLoopExceptionFrame(); + setupMainLoopExceptionFrame(); osInitialized = true; } @@ -132,4 +132,8 @@ void xmrig::Rx::msrDestroy() #endif - +#ifndef XMRIG_FIX_RYZEN +void xmrig::Rx::setupMainLoopExceptionFrame() +{ +} +#endif diff --git a/src/crypto/rx/Rx.h b/src/crypto/rx/Rx.h index bcbaa857..5b88dd4d 100644 --- a/src/crypto/rx/Rx.h +++ b/src/crypto/rx/Rx.h @@ -57,20 +57,20 @@ public: static void destroy(); static void init(IRxListener *listener); - static void setMainLoopBounds(const void* loopBegin, const void* loopEnd) - { - mainLoopBounds.first = loopBegin; - mainLoopBounds.second = loopEnd; - } - - static const std::pair& getMainLoopBounds() { return mainLoopBounds; } +# ifdef XMRIG_FIX_RYZEN + static inline const std::pair &mainLoopBounds() { return m_mainLoopBounds; } + static inline void setMainLoopBounds(const void* loopBegin, const void* loopEnd) { m_mainLoopBounds.first = loopBegin; m_mainLoopBounds.second = loopEnd; } +# endif private: static void msrInit(const RxConfig &config); static void msrDestroy(); - static void SetupMainLoopExceptionFrame(); - static thread_local std::pair mainLoopBounds; +# ifdef XMRIG_FIX_RYZEN + static void setupMainLoopExceptionFrame(); + + static thread_local std::pair m_mainLoopBounds; +# endif }; diff --git a/src/crypto/rx/Rx_linux.cpp b/src/crypto/rx/Rx_linux.cpp index f16ac7e7..c482ace5 100644 --- a/src/crypto/rx/Rx_linux.cpp +++ b/src/crypto/rx/Rx_linux.cpp @@ -182,13 +182,12 @@ static bool wrmsr(const MsrItems &preset, bool save) static void MainLoopHandler(int sig, siginfo_t *info, void *ucontext) { -# if defined(__x86_64__) || defined(__amd64__) ucontext_t *ucp = (ucontext_t*) ucontext; - LOG_INFO(YELLOW_BOLD("%s at %p"), (sig == SIGSEGV) ? "SIGSEGV" : "SIGILL", ucp->uc_mcontext.gregs[REG_RIP]); + LOG_VERBOSE(YELLOW_BOLD("%s at %p"), (sig == SIGSEGV) ? "SIGSEGV" : "SIGILL", ucp->uc_mcontext.gregs[REG_RIP]); void* p = reinterpret_cast(ucp->uc_mcontext.gregs[REG_RIP]); - const std::pair& loopBounds = xmrig::Rx::getMainLoopBounds(); + const std::pair& loopBounds = Rx::mainLoopBounds(); if ((loopBounds.first <= p) && (p < loopBounds.second)) { ucp->uc_mcontext.gregs[REG_RIP] = reinterpret_cast(loopBounds.second); @@ -196,11 +195,10 @@ static void MainLoopHandler(int sig, siginfo_t *info, void *ucontext) else { abort(); } -# endif } -thread_local std::pair Rx::mainLoopBounds = { nullptr, nullptr }; +thread_local std::pair Rx::m_mainLoopBounds = { nullptr, nullptr }; } // namespace xmrig @@ -235,14 +233,11 @@ void xmrig::Rx::msrDestroy() } -void xmrig::Rx::SetupMainLoopExceptionFrame() +void xmrig::Rx::setupMainLoopExceptionFrame() { -# if defined(__x86_64__) || defined(__amd64__) struct sigaction act = {}; act.sa_sigaction = MainLoopHandler; act.sa_flags = SA_RESTART | SA_SIGINFO; sigaction(SIGSEGV, &act, nullptr); sigaction(SIGILL, &act, nullptr); -# endif } - diff --git a/src/crypto/rx/Rx_win.cpp b/src/crypto/rx/Rx_win.cpp index 483ebe56..d685592d 100644 --- a/src/crypto/rx/Rx_win.cpp +++ b/src/crypto/rx/Rx_win.cpp @@ -313,14 +313,14 @@ static LONG WINAPI MainLoopHandler(_EXCEPTION_POINTERS *ExceptionInfo) case 8: accessType = "DEP violation"; break; default: accessType = "unknown"; break; } - LOG_INFO(YELLOW_BOLD("[THREAD %u] Access violation at 0x%p: %s at address 0x%p"), GetCurrentThreadId(), ExceptionInfo->ExceptionRecord->ExceptionAddress, accessType, ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); + LOG_VERBOSE(YELLOW_BOLD("[THREAD %u] Access violation at 0x%p: %s at address 0x%p"), GetCurrentThreadId(), ExceptionInfo->ExceptionRecord->ExceptionAddress, accessType, ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); } else { - LOG_INFO(YELLOW_BOLD("[THREAD %u] Exception 0x%08X at 0x%p"), GetCurrentThreadId(), ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress); + LOG_VERBOSE(YELLOW_BOLD("[THREAD %u] Exception 0x%08X at 0x%p"), GetCurrentThreadId(), ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress); } void* p = reinterpret_cast(ExceptionInfo->ContextRecord->Rip); - const std::pair& loopBounds = xmrig::Rx::getMainLoopBounds(); + const std::pair& loopBounds = Rx::mainLoopBounds(); if ((loopBounds.first <= p) && (p < loopBounds.second)) { ExceptionInfo->ContextRecord->Rip = reinterpret_cast(loopBounds.second); @@ -331,7 +331,7 @@ static LONG WINAPI MainLoopHandler(_EXCEPTION_POINTERS *ExceptionInfo) } -thread_local std::pair Rx::mainLoopBounds = { nullptr, nullptr }; +thread_local std::pair Rx::m_mainLoopBounds = { nullptr, nullptr }; } // namespace xmrig @@ -366,7 +366,7 @@ void xmrig::Rx::msrDestroy() } -void xmrig::Rx::SetupMainLoopExceptionFrame() +void xmrig::Rx::setupMainLoopExceptionFrame() { AddVectoredExceptionHandler(1, MainLoopHandler); }