Browse Source

Code style cleanup.

pull/1473/head
XMRig 5 years ago
parent
commit
f00769f758
No known key found for this signature in database GPG Key ID: 446A53638BE94409
  1. 2
      CMakeLists.txt
  2. 2
      cmake/randomx.cmake
  3. 8
      src/crypto/rx/Rx.cpp
  4. 18
      src/crypto/rx/Rx.h
  5. 13
      src/crypto/rx/Rx_linux.cpp
  6. 10
      src/crypto/rx/Rx_win.cpp

2
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)

2
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()

8
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

18
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<const void*, const void*>& getMainLoopBounds() { return mainLoopBounds; }
# ifdef XMRIG_FIX_RYZEN
static inline const std::pair<const void*, const void*> &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<const void*, const void*> mainLoopBounds;
# ifdef XMRIG_FIX_RYZEN
static void setupMainLoopExceptionFrame();
static thread_local std::pair<const void*, const void*> m_mainLoopBounds;
# endif
};

13
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<void*>(ucp->uc_mcontext.gregs[REG_RIP]);
const std::pair<const void*, const void*>& loopBounds = xmrig::Rx::getMainLoopBounds();
const std::pair<const void*, const void*>& loopBounds = Rx::mainLoopBounds();
if ((loopBounds.first <= p) && (p < loopBounds.second)) {
ucp->uc_mcontext.gregs[REG_RIP] = reinterpret_cast<size_t>(loopBounds.second);
@ -196,11 +195,10 @@ static void MainLoopHandler(int sig, siginfo_t *info, void *ucontext)
else {
abort();
}
# endif
}
thread_local std::pair<const void*, const void*> Rx::mainLoopBounds = { nullptr, nullptr };
thread_local std::pair<const void*, const void*> 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
}

10
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<void*>(ExceptionInfo->ContextRecord->Rip);
const std::pair<const void*, const void*>& loopBounds = xmrig::Rx::getMainLoopBounds();
const std::pair<const void*, const void*>& loopBounds = Rx::mainLoopBounds();
if ((loopBounds.first <= p) && (p < loopBounds.second)) {
ExceptionInfo->ContextRecord->Rip = reinterpret_cast<DWORD64>(loopBounds.second);
@ -331,7 +331,7 @@ static LONG WINAPI MainLoopHandler(_EXCEPTION_POINTERS *ExceptionInfo)
}
thread_local std::pair<const void*, const void*> Rx::mainLoopBounds = { nullptr, nullptr };
thread_local std::pair<const void*, const void*> 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);
}

Loading…
Cancel
Save