From 3673137df6a93a54b84e336c6ea0e1e531c99c29 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Tue, 25 Jan 2022 11:11:26 +0100 Subject: [PATCH 1/6] Fixed armv7 compilation Fix for error `Unsupported target. Must be either ARMv7-A+NEON or ARMv8-A.` --- cmake/flags.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index ff5943a13..e9e0e3958 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -26,8 +26,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM8_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM8_CXX_FLAGS} -flax-vector-conversions") elseif (ARM_TARGET EQUAL 7) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -mfpu=neon") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -mfpu=neon -flax-vector-conversions") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes") From 41a3f9706019479bf66c8823079071af56f4b67d Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 25 Jan 2022 23:21:54 +0700 Subject: [PATCH 2/6] v6.16.4-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index edb2a486a..377a4053d 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "6.16.3" +#define APP_VERSION "6.16.4-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2021 xmrig.com" @@ -30,7 +30,7 @@ #define APP_VER_MAJOR 6 #define APP_VER_MINOR 16 -#define APP_VER_PATCH 3 +#define APP_VER_PATCH 4 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From 644f4cc0176a144b4b10f44eb736c9f316e4f496 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 26 Jan 2022 15:26:23 +0100 Subject: [PATCH 3/6] Fixed unaligned memory accesses --- src/backend/common/WorkerJob.h | 7 +++-- src/backend/cpu/CpuWorker.cpp | 3 +- src/backend/cuda/CudaWorker.cpp | 3 +- src/backend/opencl/OclWorker.cpp | 3 +- src/base/base.cmake | 1 + src/base/net/stratum/Job.cpp | 3 +- src/base/tools/Alignment.h | 53 ++++++++++++++++++++++++++++++++ src/crypto/common/Nonce.cpp | 5 +-- src/net/JobResult.h | 10 +++--- 9 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 src/base/tools/Alignment.h diff --git a/src/backend/common/WorkerJob.h b/src/backend/common/WorkerJob.h index 8ff3ccdc9..7057c3571 100644 --- a/src/backend/common/WorkerJob.h +++ b/src/backend/common/WorkerJob.h @@ -30,6 +30,7 @@ #include "base/net/stratum/Job.h" +#include "base/tools/Alignment.h" #include "crypto/common/Nonce.h" @@ -77,7 +78,7 @@ public: } else { for (size_t i = 0; i < N; ++i) { - *nonce(i) += roundSize; + writeUnaligned(nonce(i), readUnaligned(nonce(i)) + roundSize); } } @@ -136,11 +137,11 @@ inline bool xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize) return false; } if (nonceSize() == sizeof(uint64_t)) { - m_jobs[index()].nonce()[1] = n[1]; + writeUnaligned(m_jobs[index()].nonce() + 1, readUnaligned(n + 1)); } } else { - *n += roundSize; + writeUnaligned(n, readUnaligned(n) + roundSize); } return true; diff --git a/src/backend/cpu/CpuWorker.cpp b/src/backend/cpu/CpuWorker.cpp index c5037a0e1..86201e506 100644 --- a/src/backend/cpu/CpuWorker.cpp +++ b/src/backend/cpu/CpuWorker.cpp @@ -23,6 +23,7 @@ #include "backend/cpu/Cpu.h" #include "backend/cpu/CpuWorker.h" +#include "base/tools/Alignment.h" #include "base/tools/Chrono.h" #include "core/config/Config.h" #include "core/Miner.h" @@ -271,7 +272,7 @@ void xmrig::CpuWorker::start() uint32_t current_job_nonces[N]; for (size_t i = 0; i < N; ++i) { - current_job_nonces[i] = *m_job.nonce(i); + current_job_nonces[i] = readUnaligned(m_job.nonce(i)); } # ifdef XMRIG_FEATURE_BENCHMARK diff --git a/src/backend/cuda/CudaWorker.cpp b/src/backend/cuda/CudaWorker.cpp index 725d59c95..5c51b9a6c 100644 --- a/src/backend/cuda/CudaWorker.cpp +++ b/src/backend/cuda/CudaWorker.cpp @@ -22,6 +22,7 @@ #include "backend/cuda/runners/CudaCnRunner.h" #include "backend/cuda/wrappers/CudaDevice.h" #include "base/io/log/Log.h" +#include "base/tools/Alignment.h" #include "base/tools/Chrono.h" #include "core/Miner.h" #include "crypto/common/Nonce.h" @@ -152,7 +153,7 @@ void xmrig::CudaWorker::start() uint32_t foundNonce[16] = { 0 }; uint32_t foundCount = 0; - if (!m_runner->run(*m_job.nonce(), &foundCount, foundNonce)) { + if (!m_runner->run(readUnaligned(m_job.nonce()), &foundCount, foundNonce)) { return; } diff --git a/src/backend/opencl/OclWorker.cpp b/src/backend/opencl/OclWorker.cpp index d2563d8ff..d9977a403 100644 --- a/src/backend/opencl/OclWorker.cpp +++ b/src/backend/opencl/OclWorker.cpp @@ -23,6 +23,7 @@ #include "backend/opencl/runners/tools/OclSharedData.h" #include "backend/opencl/runners/tools/OclSharedState.h" #include "base/io/log/Log.h" +#include "base/tools/Alignment.h" #include "base/tools/Chrono.h" #include "core/Miner.h" #include "crypto/common/Nonce.h" @@ -179,7 +180,7 @@ void xmrig::OclWorker::start() const uint64_t t = Chrono::steadyMSecs(); try { - m_runner->run(*m_job.nonce(), results); + m_runner->run(readUnaligned(m_job.nonce()), results); } catch (std::exception &ex) { printError(id(), ex.what()); diff --git a/src/base/base.cmake b/src/base/base.cmake index db26e2e98..0f4f87255 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -68,6 +68,7 @@ set(HEADERS_BASE src/base/net/tools/MemPool.h src/base/net/tools/NetBuffer.h src/base/net/tools/Storage.h + src/base/tools/Alignment.h src/base/tools/Arguments.h src/base/tools/Baton.h src/base/tools/bswap_64.h diff --git a/src/base/net/stratum/Job.cpp b/src/base/net/stratum/Job.cpp index 17122eaab..8465ec0bc 100644 --- a/src/base/net/stratum/Job.cpp +++ b/src/base/net/stratum/Job.cpp @@ -30,6 +30,7 @@ #include "base/net/stratum/Job.h" +#include "base/tools/Alignment.h" #include "base/tools/Buffer.h" #include "base/tools/Cvt.h" #include "base/tools/cryptonote/BlockTemplate.h" @@ -73,7 +74,7 @@ bool xmrig::Job::setBlob(const char *blob) return false; } - if (*nonce() != 0 && !m_nicehash) { + if (readUnaligned(nonce()) != 0 && !m_nicehash) { m_nicehash = true; } diff --git a/src/base/tools/Alignment.h b/src/base/tools/Alignment.h new file mode 100644 index 000000000..00316af9d --- /dev/null +++ b/src/base/tools/Alignment.h @@ -0,0 +1,53 @@ +/* XMRig + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_ALIGNMENT_H +#define XMRIG_ALIGNMENT_H + + +#include +#include + + +namespace xmrig { + + +template +inline T readUnaligned(const T* ptr) +{ + static_assert(std::is_integral::value, "Integer type required"); + + T result; + memcpy(&result, ptr, sizeof(T)); + return result; +} + + +template +inline void writeUnaligned(T* ptr, T data) +{ + static_assert(std::is_integral::value, "Integer type required"); + + memcpy(ptr, &data, sizeof(T)); +} + + +} /* namespace xmrig */ + + +#endif /* XMRIG_ALIGNMENT_H */ diff --git a/src/crypto/common/Nonce.cpp b/src/crypto/common/Nonce.cpp index e2e51c2c2..feb487866 100644 --- a/src/crypto/common/Nonce.cpp +++ b/src/crypto/common/Nonce.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see . */ +#include "base/tools/Alignment.h" #include "crypto/common/Nonce.h" @@ -53,10 +54,10 @@ bool xmrig::Nonce::next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, u continue; } - *nonce = (nonce[0] & ~mask) | counter; + writeUnaligned(nonce, static_cast((readUnaligned(nonce) & ~mask) | counter)); if (mask > 0xFFFFFFFFULL) { - nonce[1] = (nonce[1] & (~mask >> 32)) | (counter >> 32); + writeUnaligned(nonce + 1, static_cast((readUnaligned(nonce + 1) & (~mask >> 32)) | (counter >> 32))); } return true; diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 614baf14a..c7dbf6c53 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -45,12 +45,12 @@ public: inline JobResult(const Job &job, uint64_t nonce, const uint8_t *result, const uint8_t* header_hash = nullptr, const uint8_t *mix_hash = nullptr, const uint8_t* miner_signature = nullptr) : algorithm(job.algorithm()), + index(job.index()), clientId(job.clientId()), jobId(job.id()), backend(job.backend()), nonce(nonce), - diff(job.diff()), - index(job.index()) + diff(job.diff()) { memcpy(m_result, result, sizeof(m_result)); @@ -70,12 +70,12 @@ public: inline JobResult(const Job &job) : algorithm(job.algorithm()), + index(job.index()), clientId(job.clientId()), jobId(job.id()), backend(job.backend()), nonce(0), - diff(0), - index(job.index()) + diff(0) { } @@ -88,12 +88,12 @@ public: inline const uint8_t *minerSignature() const { return m_hasMinerSignature ? m_minerSignature : nullptr; } const Algorithm algorithm; + const uint8_t index; const String clientId; const String jobId; const uint32_t backend; const uint64_t nonce; const uint64_t diff; - const uint8_t index; private: uint8_t m_result[32] = { 0 }; From 15de3cc16c137a3e51677e0dd7abf9ac17cbe2cf Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Fri, 28 Jan 2022 21:09:24 -0700 Subject: [PATCH 4/6] Add MSVC/2022 to version.h --- src/version.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/version.h b/src/version.h index 377a4053d..57180c2bd 100644 --- a/src/version.h +++ b/src/version.h @@ -33,7 +33,9 @@ #define APP_VER_PATCH 4 #ifdef _MSC_VER -# if (_MSC_VER >= 1920) +# if (_MSC_VER >= 1930) +# define MSVC_VERSION 2022 +# elif (_MSC_VER >= 1920 && _MSC_VER < 1930) # define MSVC_VERSION 2019 # elif (_MSC_VER >= 1910 && _MSC_VER < 1920) # define MSVC_VERSION 2017 From 14117e965840d6549fe31738c1fdedc5b898cdee Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 31 Jan 2022 14:29:41 +0700 Subject: [PATCH 5/6] #2910 Fixed donation for GhostRider/RTM. --- src/base/net/stratum/AutoClient.cpp | 6 ++++++ src/base/net/stratum/EthStratumClient.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/base/net/stratum/AutoClient.cpp b/src/base/net/stratum/AutoClient.cpp index 702c0fa04..675be865a 100644 --- a/src/base/net/stratum/AutoClient.cpp +++ b/src/base/net/stratum/AutoClient.cpp @@ -65,6 +65,12 @@ bool xmrig::AutoClient::parseLogin(const rapidjson::Value &result, int *code) m_mode = ETH_MODE; setAlgo(algo); +# ifdef XMRIG_ALGO_GHOSTRIDER + if (algo.family() == Algorithm::GHOSTRIDER) { + setExtraNonce2Size(Json::getUint64(result, "extra_nonce2_size")); + } +# endif + return true; } diff --git a/src/base/net/stratum/EthStratumClient.h b/src/base/net/stratum/EthStratumClient.h index c1fde9b62..ebfda6ac3 100644 --- a/src/base/net/stratum/EthStratumClient.h +++ b/src/base/net/stratum/EthStratumClient.h @@ -47,6 +47,10 @@ protected: void setExtraNonce(const rapidjson::Value &nonce); +# ifdef XMRIG_ALGO_GHOSTRIDER + inline void setExtraNonce2Size(uint64_t size) { m_extraNonce2Size = size; } +# endif + private: static const char *errorMessage(const rapidjson::Value &error); From 802029e5f56b891ae4b2e1c5714feb5997ce02d9 Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 4 Feb 2022 15:14:46 +0700 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e71916fe3..8834cd641 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v6.16.4 +- [#2904](https://github.com/xmrig/xmrig/pull/2904) Fixed unaligned memory accesses. +- [#2908](https://github.com/xmrig/xmrig/pull/2908) Added MSVC/2022 to `version.h`. +- [#2910](https://github.com/xmrig/xmrig/issues/2910) Fixed donation for GhostRider/RTM. + # v6.16.3 - [#2778](https://github.com/xmrig/xmrig/pull/2778) Fixed `READY threads X/X` display after algorithm switching. - [#2782](https://github.com/xmrig/xmrig/pull/2782) Updated GhostRider documentation.