Code style cleanup.

This commit is contained in:
XMRig 2019-12-28 01:45:54 +07:00
parent 6ceb4dfc4f
commit f00769f758
No known key found for this signature in database
GPG key ID: 446A53638BE94409
6 changed files with 27 additions and 26 deletions

View file

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

View file

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

View file

@ -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

View file

@ -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
};

View file

@ -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
}

View file

@ -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);
}