Skip to content

Commit f00769f

Browse files
committed
Code style cleanup.
1 parent 6ceb4df commit f00769f

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ option(WITH_HTTP "Enable HTTP protocol support (client/server)" ON)
1313
option(WITH_DEBUG_LOG "Enable debug log output" OFF)
1414
option(WITH_TLS "Enable OpenSSL support" ON)
1515
option(WITH_ASM "Enable ASM PoW implementations" ON)
16-
option(WITH_MSR "Enable MSR support" ON)
16+
option(WITH_MSR "Enable MSR mod & 1st-gen Ryzen fix" ON)
1717
option(WITH_EMBEDDED_CONFIG "Enable internal embedded JSON config" OFF)
1818
option(WITH_OPENCL "Enable OpenCL backend" ON)
1919
option(WITH_CUDA "Enable CUDA backend" ON)

cmake/randomx.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ if (WITH_RANDOMX)
8181

8282
if (WITH_MSR AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND (XMRIG_OS_WIN OR XMRIG_OS_LINUX))
8383
add_definitions(/DXMRIG_FEATURE_MSR)
84+
add_definitions(/DXMRIG_FIX_RYZEN)
8485
message("-- WITH_MSR=ON")
8586

8687
if (XMRIG_OS_WIN)
@@ -93,6 +94,7 @@ if (WITH_RANDOMX)
9394
list(APPEND SOURCES_CRYPTO src/crypto/rx/msr/MsrItem.cpp)
9495
else()
9596
remove_definitions(/DXMRIG_FEATURE_MSR)
97+
remove_definitions(/DXMRIG_FIX_RYZEN)
9698
message("-- WITH_MSR=OFF")
9799
endif()
98100
else()

src/crypto/rx/Rx.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool xmrig::Rx::init(const Job &job, const RxConfig &config, const CpuConfig &cp
7474

7575
if (!osInitialized) {
7676
msrInit(config);
77-
SetupMainLoopExceptionFrame();
77+
setupMainLoopExceptionFrame();
7878
osInitialized = true;
7979
}
8080

@@ -132,4 +132,8 @@ void xmrig::Rx::msrDestroy()
132132
#endif
133133

134134

135-
135+
#ifndef XMRIG_FIX_RYZEN
136+
void xmrig::Rx::setupMainLoopExceptionFrame()
137+
{
138+
}
139+
#endif

src/crypto/rx/Rx.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ class Rx
5757
static void destroy();
5858
static void init(IRxListener *listener);
5959

60-
static void setMainLoopBounds(const void* loopBegin, const void* loopEnd)
61-
{
62-
mainLoopBounds.first = loopBegin;
63-
mainLoopBounds.second = loopEnd;
64-
}
65-
66-
static const std::pair<const void*, const void*>& getMainLoopBounds() { return mainLoopBounds; }
60+
# ifdef XMRIG_FIX_RYZEN
61+
static inline const std::pair<const void*, const void*> &mainLoopBounds() { return m_mainLoopBounds; }
62+
static inline void setMainLoopBounds(const void* loopBegin, const void* loopEnd) { m_mainLoopBounds.first = loopBegin; m_mainLoopBounds.second = loopEnd; }
63+
# endif
6764

6865
private:
6966
static void msrInit(const RxConfig &config);
7067
static void msrDestroy();
71-
static void SetupMainLoopExceptionFrame();
7268

73-
static thread_local std::pair<const void*, const void*> mainLoopBounds;
69+
# ifdef XMRIG_FIX_RYZEN
70+
static void setupMainLoopExceptionFrame();
71+
72+
static thread_local std::pair<const void*, const void*> m_mainLoopBounds;
73+
# endif
7474
};
7575

7676

src/crypto/rx/Rx_linux.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,23 @@ static bool wrmsr(const MsrItems &preset, bool save)
182182

183183
static void MainLoopHandler(int sig, siginfo_t *info, void *ucontext)
184184
{
185-
# if defined(__x86_64__) || defined(__amd64__)
186185
ucontext_t *ucp = (ucontext_t*) ucontext;
187186

188-
LOG_INFO(YELLOW_BOLD("%s at %p"), (sig == SIGSEGV) ? "SIGSEGV" : "SIGILL", ucp->uc_mcontext.gregs[REG_RIP]);
187+
LOG_VERBOSE(YELLOW_BOLD("%s at %p"), (sig == SIGSEGV) ? "SIGSEGV" : "SIGILL", ucp->uc_mcontext.gregs[REG_RIP]);
189188

190189
void* p = reinterpret_cast<void*>(ucp->uc_mcontext.gregs[REG_RIP]);
191-
const std::pair<const void*, const void*>& loopBounds = xmrig::Rx::getMainLoopBounds();
190+
const std::pair<const void*, const void*>& loopBounds = Rx::mainLoopBounds();
192191

193192
if ((loopBounds.first <= p) && (p < loopBounds.second)) {
194193
ucp->uc_mcontext.gregs[REG_RIP] = reinterpret_cast<size_t>(loopBounds.second);
195194
}
196195
else {
197196
abort();
198197
}
199-
# endif
200198
}
201199

202200

203-
thread_local std::pair<const void*, const void*> Rx::mainLoopBounds = { nullptr, nullptr };
201+
thread_local std::pair<const void*, const void*> Rx::m_mainLoopBounds = { nullptr, nullptr };
204202

205203

206204
} // namespace xmrig
@@ -235,14 +233,11 @@ void xmrig::Rx::msrDestroy()
235233
}
236234

237235

238-
void xmrig::Rx::SetupMainLoopExceptionFrame()
236+
void xmrig::Rx::setupMainLoopExceptionFrame()
239237
{
240-
# if defined(__x86_64__) || defined(__amd64__)
241238
struct sigaction act = {};
242239
act.sa_sigaction = MainLoopHandler;
243240
act.sa_flags = SA_RESTART | SA_SIGINFO;
244241
sigaction(SIGSEGV, &act, nullptr);
245242
sigaction(SIGILL, &act, nullptr);
246-
# endif
247243
}
248-

src/crypto/rx/Rx_win.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ static LONG WINAPI MainLoopHandler(_EXCEPTION_POINTERS *ExceptionInfo)
313313
case 8: accessType = "DEP violation"; break;
314314
default: accessType = "unknown"; break;
315315
}
316-
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]);
316+
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]);
317317
}
318318
else {
319-
LOG_INFO(YELLOW_BOLD("[THREAD %u] Exception 0x%08X at 0x%p"), GetCurrentThreadId(), ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);
319+
LOG_VERBOSE(YELLOW_BOLD("[THREAD %u] Exception 0x%08X at 0x%p"), GetCurrentThreadId(), ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);
320320
}
321321

322322
void* p = reinterpret_cast<void*>(ExceptionInfo->ContextRecord->Rip);
323-
const std::pair<const void*, const void*>& loopBounds = xmrig::Rx::getMainLoopBounds();
323+
const std::pair<const void*, const void*>& loopBounds = Rx::mainLoopBounds();
324324

325325
if ((loopBounds.first <= p) && (p < loopBounds.second)) {
326326
ExceptionInfo->ContextRecord->Rip = reinterpret_cast<DWORD64>(loopBounds.second);
@@ -331,7 +331,7 @@ static LONG WINAPI MainLoopHandler(_EXCEPTION_POINTERS *ExceptionInfo)
331331
}
332332

333333

334-
thread_local std::pair<const void*, const void*> Rx::mainLoopBounds = { nullptr, nullptr };
334+
thread_local std::pair<const void*, const void*> Rx::m_mainLoopBounds = { nullptr, nullptr };
335335

336336

337337
} // namespace xmrig
@@ -366,7 +366,7 @@ void xmrig::Rx::msrDestroy()
366366
}
367367

368368

369-
void xmrig::Rx::SetupMainLoopExceptionFrame()
369+
void xmrig::Rx::setupMainLoopExceptionFrame()
370370
{
371371
AddVectoredExceptionHandler(1, MainLoopHandler);
372372
}

0 commit comments

Comments
 (0)