From b38046db46ced8a42b8ff91616de7857f948c8fa Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 23 Apr 2020 14:32:13 +0700 Subject: [PATCH 01/24] v5.11.2-dev --- src/version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/version.h b/src/version.h index 34c4cdacc..4c7327454 100644 --- a/src/version.h +++ b/src/version.h @@ -28,7 +28,7 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "5.11.1" +#define APP_VERSION "5.11.2-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2020 xmrig.com" @@ -36,7 +36,7 @@ #define APP_VER_MAJOR 5 #define APP_VER_MINOR 11 -#define APP_VER_PATCH 1 +#define APP_VER_PATCH 2 #ifdef _MSC_VER # if (_MSC_VER >= 1920) From 46e49cde0bb1cf65c3215a21de74ec86c65802ef Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 29 Apr 2020 14:17:33 +0700 Subject: [PATCH 02/24] Update base. --- src/App.cpp | 2 +- src/backend/cuda/wrappers/CudaLib.cpp | 2 +- src/backend/opencl/wrappers/OclLib.cpp | 6 +-- src/backend/opencl/wrappers/OclLib.h | 4 +- src/base/api/Api.cpp | 2 +- src/base/base.cmake | 8 ++-- src/base/{kernel => io}/Env.cpp | 4 +- src/base/{kernel => io}/Env.h | 0 src/base/{kernel => io}/Signals.cpp | 2 +- src/base/{kernel => io}/Signals.h | 0 src/base/io/log/FileLogWriter.cpp | 2 +- src/base/io/log/Log.h | 4 +- src/base/kernel/Platform.h | 2 - src/base/kernel/Platform_mac.cpp | 20 --------- src/base/kernel/Platform_unix.cpp | 20 --------- src/base/kernel/Platform_win.cpp | 50 +--------------------- src/base/kernel/Process.cpp | 22 +++++++++- src/base/kernel/Process.h | 2 + src/base/kernel/interfaces/IDnsListener.h | 4 +- src/base/kernel/interfaces/ILineListener.h | 8 +++- src/base/net/dns/Dns.cpp | 16 +++---- src/base/net/dns/Dns.h | 13 +++--- src/base/net/http/Fetch.cpp | 47 +++----------------- src/base/net/http/Fetch.h | 9 ++-- src/base/net/http/HttpData.cpp | 13 ++++++ src/base/net/http/HttpData.h | 5 ++- src/base/net/http/HttpListener.cpp | 8 ++-- src/base/net/http/HttpListener.h | 3 +- src/base/net/stratum/BaseClient.cpp | 8 ++-- src/base/net/stratum/DaemonClient.cpp | 4 +- src/base/net/tls/TlsConfig.cpp | 4 +- src/base/net/tls/TlsConfig.h | 2 +- src/base/net/tls/TlsContext.cpp | 2 +- src/base/net/tools/Storage.h | 25 ++++------- src/base/tools/Arguments.cpp | 4 +- src/base/tools/Arguments.h | 2 +- src/base/tools/String.cpp | 8 ++-- src/base/tools/String.h | 14 +++--- src/base/tools/Timer.cpp | 30 +++++++------ src/base/tools/Timer.h | 25 ++++++----- 40 files changed, 162 insertions(+), 244 deletions(-) rename src/base/{kernel => io}/Env.cpp (96%) rename src/base/{kernel => io}/Env.h (100%) rename src/base/{kernel => io}/Signals.cpp (98%) rename src/base/{kernel => io}/Signals.h (100%) diff --git a/src/App.cpp b/src/App.cpp index 106238c80..f57e658f7 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -32,7 +32,7 @@ #include "backend/cpu/Cpu.h" #include "base/io/Console.h" #include "base/io/log/Log.h" -#include "base/kernel/Signals.h" +#include "base/io/Signals.h" #include "base/kernel/Platform.h" #include "core/config/Config.h" #include "core/Controller.h" diff --git a/src/backend/cuda/wrappers/CudaLib.cpp b/src/backend/cuda/wrappers/CudaLib.cpp index db1ff9047..9436f760b 100644 --- a/src/backend/cuda/wrappers/CudaLib.cpp +++ b/src/backend/cuda/wrappers/CudaLib.cpp @@ -28,7 +28,7 @@ #include "backend/cuda/wrappers/CudaLib.h" -#include "base/kernel/Env.h" +#include "base/io/Env.h" #include "crypto/rx/RxAlgo.h" diff --git a/src/backend/opencl/wrappers/OclLib.cpp b/src/backend/opencl/wrappers/OclLib.cpp index d3329e730..b5b12c62f 100644 --- a/src/backend/opencl/wrappers/OclLib.cpp +++ b/src/backend/opencl/wrappers/OclLib.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -31,8 +31,8 @@ #include "backend/opencl/wrappers/OclLib.h" #include "backend/common/Tags.h" #include "backend/opencl/wrappers/OclError.h" +#include "base/io/Env.h" #include "base/io/log/Log.h" -#include "base/kernel/Env.h" #if defined(OCL_DEBUG_REFERENCE_COUNT) diff --git a/src/backend/opencl/wrappers/OclLib.h b/src/backend/opencl/wrappers/OclLib.h index 9b9e19a8b..b4db1d8d8 100644 --- a/src/backend/opencl/wrappers/OclLib.h +++ b/src/backend/opencl/wrappers/OclLib.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/base/api/Api.cpp b/src/base/api/Api.cpp index 535875fb2..85c9dd609 100644 --- a/src/base/api/Api.cpp +++ b/src/base/api/Api.cpp @@ -31,9 +31,9 @@ #include "base/api/interfaces/IApiListener.h" #include "base/api/requests/HttpApiRequest.h" #include "base/crypto/keccak.h" +#include "base/io/Env.h" #include "base/io/json/Json.h" #include "base/kernel/Base.h" -#include "base/kernel/Env.h" #include "base/tools/Buffer.h" #include "base/tools/Chrono.h" #include "core/config/Config.h" diff --git a/src/base/base.cmake b/src/base/base.cmake index d32f723ea..2957a5652 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -4,6 +4,7 @@ set(HEADERS_BASE src/base/crypto/Coin.h src/base/crypto/keccak.h src/base/io/Console.h + src/base/io/Env.h src/base/io/json/Json.h src/base/io/json/JsonChain.h src/base/io/json/JsonRequest.h @@ -11,12 +12,12 @@ set(HEADERS_BASE src/base/io/log/backends/FileLog.h src/base/io/log/FileLogWriter.h src/base/io/log/Log.h + src/base/io/Signals.h src/base/io/Watcher.h src/base/kernel/Base.h src/base/kernel/config/BaseConfig.h src/base/kernel/config/BaseTransform.h src/base/kernel/Entry.h - src/base/kernel/Env.h src/base/kernel/interfaces/IBaseListener.h src/base/kernel/interfaces/IClient.h src/base/kernel/interfaces/IClientListener.h @@ -34,7 +35,6 @@ set(HEADERS_BASE src/base/kernel/interfaces/IWatcherListener.h src/base/kernel/Platform.h src/base/kernel/Process.h - src/base/kernel/Signals.h src/base/net/dns/Dns.h src/base/net/dns/DnsRecord.h src/base/net/http/Http.h @@ -70,6 +70,7 @@ set(SOURCES_BASE src/base/crypto/Coin.cpp src/base/crypto/keccak.cpp src/base/io/Console.cpp + src/base/io/Env.cpp src/base/io/json/Json.cpp src/base/io/json/JsonChain.cpp src/base/io/json/JsonRequest.cpp @@ -77,15 +78,14 @@ set(SOURCES_BASE src/base/io/log/backends/FileLog.cpp src/base/io/log/FileLogWriter.cpp src/base/io/log/Log.cpp + src/base/io/Signals.cpp src/base/io/Watcher.cpp src/base/kernel/Base.cpp src/base/kernel/config/BaseConfig.cpp src/base/kernel/config/BaseTransform.cpp src/base/kernel/Entry.cpp - src/base/kernel/Env.cpp src/base/kernel/Platform.cpp src/base/kernel/Process.cpp - src/base/kernel/Signals.cpp src/base/net/dns/Dns.cpp src/base/net/dns/DnsRecord.cpp src/base/net/http/Http.cpp diff --git a/src/base/kernel/Env.cpp b/src/base/io/Env.cpp similarity index 96% rename from src/base/kernel/Env.cpp rename to src/base/io/Env.cpp index 9b018e6ed..ae1c27b52 100644 --- a/src/base/kernel/Env.cpp +++ b/src/base/io/Env.cpp @@ -23,7 +23,7 @@ */ -#include "base/kernel/Env.h" +#include "base/io/Env.h" #include "base/kernel/Process.h" #include "version.h" @@ -57,6 +57,8 @@ static std::map variables; static void createVariables() { variables.insert({ "XMRIG_VERSION", APP_VERSION }); + variables.insert({ "XMRIG_KIND", APP_KIND }); + variables.insert({ "XMRIG_HOSTNAME", Env::hostname() }); variables.insert({ "XMRIG_EXE", Process::exepath() }); variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) }); variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) }); diff --git a/src/base/kernel/Env.h b/src/base/io/Env.h similarity index 100% rename from src/base/kernel/Env.h rename to src/base/io/Env.h diff --git a/src/base/kernel/Signals.cpp b/src/base/io/Signals.cpp similarity index 98% rename from src/base/kernel/Signals.cpp rename to src/base/io/Signals.cpp index 87825b832..00ec8c174 100644 --- a/src/base/kernel/Signals.cpp +++ b/src/base/io/Signals.cpp @@ -26,8 +26,8 @@ #include +#include "base/io/Signals.h" #include "base/kernel/interfaces/ISignalListener.h" -#include "base/kernel/Signals.h" #include "base/tools/Handle.h" diff --git a/src/base/kernel/Signals.h b/src/base/io/Signals.h similarity index 100% rename from src/base/kernel/Signals.h rename to src/base/io/Signals.h diff --git a/src/base/io/log/FileLogWriter.cpp b/src/base/io/log/FileLogWriter.cpp index 8ae31273c..921d93370 100644 --- a/src/base/io/log/FileLogWriter.cpp +++ b/src/base/io/log/FileLogWriter.cpp @@ -18,7 +18,7 @@ #include "base/io/log/FileLogWriter.h" -#include "base/kernel/Env.h" +#include "base/io/Env.h" #include diff --git a/src/base/io/log/Log.h b/src/base/io/log/Log.h index 45183d1ce..b4675757f 100644 --- a/src/base/io/log/Log.h +++ b/src/base/io/log/Log.h @@ -141,7 +141,9 @@ private: #define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__) #define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__) #define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__) -#define LOG_VERBOSE(x, ...) if (xmrig::Log::isVerbose()) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } +#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } +#define LOG_V(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } +#define LOG_VV(x, ...) if (xmrig::Log::verbose() > 1) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); } #ifdef APP_DEBUG # define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__) diff --git a/src/base/kernel/Platform.h b/src/base/kernel/Platform.h index 341b4dfd2..3fcf666be 100644 --- a/src/base/kernel/Platform.h +++ b/src/base/kernel/Platform.h @@ -48,9 +48,7 @@ public: } static bool setThreadAffinity(uint64_t cpu_id); - static uint32_t setTimerResolution(uint32_t resolution); static void init(const char *userAgent); - static void restoreTimerResolution(); static void setProcessPriority(int priority); static void setThreadPriority(int priority); diff --git a/src/base/kernel/Platform_mac.cpp b/src/base/kernel/Platform_mac.cpp index aab006759..5a5520eb2 100644 --- a/src/base/kernel/Platform_mac.cpp +++ b/src/base/kernel/Platform_mac.cpp @@ -34,10 +34,6 @@ #include "base/kernel/Platform.h" #include "version.h" -#ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" -#endif - char *xmrig::Platform::createUserAgent() { @@ -46,11 +42,6 @@ char *xmrig::Platform::createUserAgent() char *buf = new char[max](); int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s", APP_NAME, APP_VERSION, uv_version_string()); -# ifdef XMRIG_NVIDIA_PROJECT - const int cudaVersion = cuda_get_runtime_version(); - length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); -# endif - # ifdef __clang__ length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); # elif defined(__GNUC__) @@ -75,17 +66,6 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) #endif -uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution) -{ - return resolution; -} - - -void xmrig::Platform::restoreTimerResolution() -{ -} - - void xmrig::Platform::setProcessPriority(int) { } diff --git a/src/base/kernel/Platform_unix.cpp b/src/base/kernel/Platform_unix.cpp index ba55ed77c..6d9576363 100644 --- a/src/base/kernel/Platform_unix.cpp +++ b/src/base/kernel/Platform_unix.cpp @@ -43,10 +43,6 @@ #include "base/kernel/Platform.h" #include "version.h" -#ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" -#endif - #ifdef __FreeBSD__ typedef cpuset_t cpu_set_t; @@ -70,11 +66,6 @@ char *xmrig::Platform::createUserAgent() length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); # endif -# ifdef XMRIG_NVIDIA_PROJECT - const int cudaVersion = cuda_get_runtime_version(); - length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); -# endif - # ifdef __clang__ length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); # elif defined(__GNUC__) @@ -104,17 +95,6 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) #endif -uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution) -{ - return resolution; -} - - -void xmrig::Platform::restoreTimerResolution() -{ -} - - void xmrig::Platform::setProcessPriority(int) { } diff --git a/src/base/kernel/Platform_win.cpp b/src/base/kernel/Platform_win.cpp index ce7e60e21..018dba31f 100644 --- a/src/base/kernel/Platform_win.cpp +++ b/src/base/kernel/Platform_win.cpp @@ -29,23 +29,12 @@ #include "base/kernel/Platform.h" -#include "base/io/log/Log.h" #include "version.h" -#ifdef XMRIG_NVIDIA_PROJECT -# include "nvidia/cryptonight.h" -#endif - - -#ifdef XMRIG_AMD_PROJECT -static uint32_t timerResolution = 0; -#endif - - static inline OSVERSIONINFOEX winOsVersion() { - typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); + using RtlGetVersionFunction = NTSTATUS (*)(LPOSVERSIONINFO); OSVERSIONINFOEX result = { sizeof(OSVERSIONINFOEX), 0, 0, 0, 0, {'\0'}, 0, 0, 0, 0, 0}; HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); @@ -75,11 +64,6 @@ char *xmrig::Platform::createUserAgent() length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string()); # endif -# ifdef XMRIG_NVIDIA_PROJECT - const int cudaVersion = cuda_get_runtime_version(); - length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); -# endif - # ifdef __GNUC__ length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # elif _MSC_VER @@ -93,10 +77,6 @@ char *xmrig::Platform::createUserAgent() #ifndef XMRIG_FEATURE_HWLOC bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) { - if (cpu_id >= 64) { - LOG_ERR("Unable to set affinity. Windows supports only affinity up to 63."); - } - const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0); Sleep(1); return result; @@ -104,34 +84,6 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) #endif -uint32_t xmrig::Platform::setTimerResolution(uint32_t resolution) -{ -# ifdef XMRIG_AMD_PROJECT - TIMECAPS tc; - - if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) { - return 0; - } - - timerResolution = std::min(std::max(tc.wPeriodMin, resolution), tc.wPeriodMax); - - return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0; -# else - return resolution; -# endif -} - - -void xmrig::Platform::restoreTimerResolution() -{ -# ifdef XMRIG_AMD_PROJECT - if (timerResolution) { - timeEndPeriod(timerResolution); - } -# endif -} - - void xmrig::Platform::setProcessPriority(int priority) { if (priority == -1) { diff --git a/src/base/kernel/Process.cpp b/src/base/kernel/Process.cpp index 34f5d02b1..36dcae78b 100644 --- a/src/base/kernel/Process.cpp +++ b/src/base/kernel/Process.cpp @@ -115,7 +115,27 @@ xmrig::Process::Process(int argc, char **argv) : { srand(static_cast(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast(this))); - setDataDir(m_arguments.value("--data-dir")); + setDataDir(m_arguments.value("--data-dir", "-d")); +} + + +int xmrig::Process::pid() +{ +# if UV_VERSION_HEX >= 0x011200 + return uv_os_getpid(); +# else + return 0; +# endif +} + + +int xmrig::Process::ppid() +{ +# if UV_VERSION_HEX >= 0x011000 + return uv_os_getppid(); +# else + return 0; +# endif } diff --git a/src/base/kernel/Process.h b/src/base/kernel/Process.h index 29f247f2b..a97a3dccb 100644 --- a/src/base/kernel/Process.h +++ b/src/base/kernel/Process.h @@ -51,6 +51,8 @@ public: Process(int argc, char **argv); + static int pid(); + static int ppid(); static String exepath(); static String location(Location location, const char *fileName = nullptr); diff --git a/src/base/kernel/interfaces/IDnsListener.h b/src/base/kernel/interfaces/IDnsListener.h index 3683ea51d..4cbb3f7e4 100644 --- a/src/base/kernel/interfaces/IDnsListener.h +++ b/src/base/kernel/interfaces/IDnsListener.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/base/kernel/interfaces/ILineListener.h b/src/base/kernel/interfaces/ILineListener.h index 2759dcecb..a7d349012 100644 --- a/src/base/kernel/interfaces/ILineListener.h +++ b/src/base/kernel/interfaces/ILineListener.h @@ -26,6 +26,9 @@ #define XMRIG_ILINELISTENER_H +#include "base/tools/Object.h" + + #include @@ -35,7 +38,10 @@ namespace xmrig { class ILineListener { public: - virtual ~ILineListener() = default; + XMRIG_DISABLE_COPY_MOVE(ILineListener) + + ILineListener() = default; + virtual ~ILineListener() = default; virtual void onLine(char *line, size_t size) = 0; }; diff --git a/src/base/net/dns/Dns.cpp b/src/base/net/dns/Dns.cpp index 40d2a6e33..6246421c0 100644 --- a/src/base/net/dns/Dns.cpp +++ b/src/base/net/dns/Dns.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -23,9 +23,8 @@ */ -#include "base/kernel/interfaces/IDnsListener.h" #include "base/net/dns/Dns.h" -#include "base/tools/Handle.h" +#include "base/kernel/interfaces/IDnsListener.h" namespace xmrig { @@ -35,10 +34,7 @@ namespace xmrig { xmrig::Dns::Dns(IDnsListener *listener) : - m_hints(), - m_listener(listener), - m_status(0), - m_resolver(nullptr) + m_listener(listener) { m_key = m_storage.add(this); @@ -134,11 +130,11 @@ void xmrig::Dns::onResolved(int status, addrinfo *res) addrinfo *ptr = res; while (ptr != nullptr) { if (ptr->ai_family == AF_INET) { - m_ipv4.push_back(ptr); + m_ipv4.emplace_back(ptr); } if (ptr->ai_family == AF_INET6) { - m_ipv6.push_back(ptr); + m_ipv6.emplace_back(ptr); } ptr = ptr->ai_next; diff --git a/src/base/net/dns/Dns.h b/src/base/net/dns/Dns.h index 11f5bf80a..068ab80f3 100644 --- a/src/base/net/dns/Dns.h +++ b/src/base/net/dns/Dns.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -32,6 +32,7 @@ #include "base/net/dns/DnsRecord.h" #include "base/net/tools/Storage.h" +#include "base/tools/Object.h" #include "base/tools/String.h" @@ -44,6 +45,8 @@ class IDnsListener; class Dns { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(Dns) + Dns(IDnsListener *listener); ~Dns(); @@ -62,14 +65,14 @@ private: static void onResolved(uv_getaddrinfo_t *req, int status, addrinfo *res); - addrinfo m_hints; + addrinfo m_hints{}; IDnsListener *m_listener; - int m_status; + int m_status = 0; std::vector m_ipv4; std::vector m_ipv6; String m_host; uintptr_t m_key; - uv_getaddrinfo_t *m_resolver; + uv_getaddrinfo_t *m_resolver = nullptr; static Storage m_storage; }; diff --git a/src/base/net/http/Fetch.cpp b/src/base/net/http/Fetch.cpp index a0eb2b555..4d18b71d0 100644 --- a/src/base/net/http/Fetch.cpp +++ b/src/base/net/http/Fetch.cpp @@ -18,12 +18,11 @@ #include "base/net/http/Fetch.h" +#include "3rdparty/rapidjson/document.h" +#include "3rdparty/rapidjson/stringbuffer.h" +#include "3rdparty/rapidjson/writer.h" #include "base/io/log/Log.h" #include "base/net/http/HttpClient.h" -#include "base/net/stratum/Pool.h" -#include "rapidjson/document.h" -#include "rapidjson/stringbuffer.h" -#include "rapidjson/writer.h" #ifdef XMRIG_FEATURE_TLS @@ -45,7 +44,7 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16 } -xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls, bool quiet) : +xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls, bool quiet) : quiet(quiet), tls(tls), method(method), @@ -55,42 +54,10 @@ xmrig::FetchRequest::FetchRequest(http_method method, const String &host, uint16 { assert(port > 0); - setBody(doc); + setBody(value); } -xmrig::FetchRequest::FetchRequest(int method, const Pool &pool, const String &path, bool quiet, const char *data, size_t size, const char *contentType) : - quiet(quiet), - tls(pool.isTLS()), - method(static_cast(method)), - fingerprint(pool.fingerprint()), - host(pool.host()), - path(path), - port(pool.port()) -{ - assert(pool.isValid()); - - setBody(data, size, contentType); -} - - - -xmrig::FetchRequest::FetchRequest(int method, const Pool &pool, const String &path, const rapidjson::Document &doc, bool quiet) : - quiet(quiet), - tls(pool.isTLS()), - method(static_cast(method)), - fingerprint(pool.fingerprint()), - host(pool.host()), - path(path), - port(pool.port()) -{ - assert(pool.isValid()); - - setBody(doc); -} - - - void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *contentType) { if (!data) { @@ -110,7 +77,7 @@ void xmrig::FetchRequest::setBody(const char *data, size_t size, const char *con } -void xmrig::FetchRequest::setBody(const rapidjson::Document &doc) +void xmrig::FetchRequest::setBody(const rapidjson::Value &value) { assert(method != HTTP_GET && method != HTTP_HEAD); @@ -122,7 +89,7 @@ void xmrig::FetchRequest::setBody(const rapidjson::Document &doc) StringBuffer buffer(nullptr, 512); Writer writer(buffer); - doc.Accept(writer); + value.Accept(writer); setBody(buffer.GetString(), buffer.GetSize(), HttpData::kApplicationJson.c_str()); } diff --git a/src/base/net/http/Fetch.h b/src/base/net/http/Fetch.h index db1e899b6..b6fbf487d 100644 --- a/src/base/net/http/Fetch.h +++ b/src/base/net/http/Fetch.h @@ -22,8 +22,8 @@ #include "3rdparty/http-parser/http_parser.h" +#include "3rdparty/rapidjson/fwd.h" #include "base/tools/String.h" -#include "rapidjson/fwd.h" #include @@ -35,7 +35,6 @@ namespace xmrig { class IHttpListener; -class Pool; class FetchRequest @@ -43,12 +42,10 @@ class FetchRequest public: FetchRequest() = default; FetchRequest(http_method method, const String &host, uint16_t port, const String &path, bool tls = false, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr); - FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Document &doc, bool tls = false, bool quiet = false); - FetchRequest(int method, const Pool &pool, const String &path, bool quiet = false, const char *data = nullptr, size_t size = 0, const char *contentType = nullptr); - FetchRequest(int method, const Pool &pool, const String &path, const rapidjson::Document &doc, bool quiet = false); + FetchRequest(http_method method, const String &host, uint16_t port, const String &path, const rapidjson::Value &value, bool tls = false, bool quiet = false); void setBody(const char *data, size_t size, const char *contentType = nullptr); - void setBody(const rapidjson::Document &doc); + void setBody(const rapidjson::Value &value); inline bool hasBody() const { return method != HTTP_GET && method != HTTP_HEAD && !body.empty(); } diff --git a/src/base/net/http/HttpData.cpp b/src/base/net/http/HttpData.cpp index 5aa575a80..6e75e2ac6 100644 --- a/src/base/net/http/HttpData.cpp +++ b/src/base/net/http/HttpData.cpp @@ -26,6 +26,19 @@ namespace xmrig { const std::string HttpData::kApplicationJson = "application/json"; const std::string HttpData::kContentType = "Content-Type"; const std::string HttpData::kContentTypeL = "content-type"; +const std::string HttpData::kTextPlain = "text/plain"; } // namespace xmrig + + +bool xmrig::HttpData::isJSON() const +{ + if (!headers.count(kContentTypeL)) { + return false; + } + + auto &type = headers.at(kContentTypeL); + + return type == kApplicationJson || type == kTextPlain; +} diff --git a/src/base/net/http/HttpData.h b/src/base/net/http/HttpData.h index 82a8ee8f8..2e8b78f8f 100644 --- a/src/base/net/http/HttpData.h +++ b/src/base/net/http/HttpData.h @@ -46,12 +46,13 @@ public: static const std::string kApplicationJson; static const std::string kContentType; static const std::string kContentTypeL; + static const std::string kTextPlain; inline HttpData(uint64_t id) : m_id(id) {} virtual ~HttpData() = default; - inline uint64_t id() const { return m_id; } + inline uint64_t id() const { return m_id; } virtual bool isRequest() const = 0; virtual const char *host() const = 0; @@ -61,6 +62,8 @@ public: virtual uint16_t port() const = 0; virtual void write(std::string &&data, bool close) = 0; + bool isJSON() const; + int method = 0; int status = 0; int userType = 0; diff --git a/src/base/net/http/HttpListener.cpp b/src/base/net/http/HttpListener.cpp index e58d5e55e..077184fcb 100644 --- a/src/base/net/http/HttpListener.cpp +++ b/src/base/net/http/HttpListener.cpp @@ -27,11 +27,11 @@ void xmrig::HttpListener::onHttpData(const HttpData &data) { # ifdef APP_DEBUG if (!data.isRequest()) { - LOG_DEBUG(CYAN("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"), - data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast(data.method)), data.url.data(), - data.status >= 400 ? 31 : 32, data.status, data.body.size()); + LOG_DEBUG("%s " CYAN_BOLD("http%s://%s:%u ") MAGENTA_BOLD("\"%s %s\" ") CSI "1;%dm%d" CLEAR BLACK_BOLD(" received: ") CYAN_BOLD("%zu") BLACK_BOLD(" bytes"), + m_tag, data.tlsVersion() ? "s" : "", data.host(), data.port(), http_method_str(static_cast(data.method)), data.url.data(), + (data.status >= 400 || data.status < 0) ? 31 : 32, data.status, data.body.size()); - if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.headers.count(HttpData::kContentTypeL) && data.headers.at(HttpData::kContentTypeL) == HttpData::kApplicationJson) { + if (data.body.size() < (Log::kMaxBufferSize - 1024) && data.isJSON()) { Log::print(BLUE_BG_BOLD("%s:") BLACK_BOLD_S " %.*s", data.headers.at(HttpData::kContentTypeL).c_str(), static_cast(data.body.size()), data.body.c_str()); } } diff --git a/src/base/net/http/HttpListener.h b/src/base/net/http/HttpListener.h index 36975db48..ac302dab9 100644 --- a/src/base/net/http/HttpListener.h +++ b/src/base/net/http/HttpListener.h @@ -29,12 +29,13 @@ namespace xmrig { class HttpListener : public IHttpListener { public: - inline HttpListener(IHttpListener *listener) : m_listener(listener) {} + inline HttpListener(IHttpListener *listener, const char *tag = nullptr) : m_tag(tag), m_listener(listener) {} protected: void onHttpData(const HttpData &data) override; private: + const char *m_tag; IHttpListener *m_listener; }; diff --git a/src/base/net/stratum/BaseClient.cpp b/src/base/net/stratum/BaseClient.cpp index 677b0e376..6072a666a 100644 --- a/src/base/net/stratum/BaseClient.cpp +++ b/src/base/net/stratum/BaseClient.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -24,10 +24,10 @@ #include "base/net/stratum/BaseClient.h" -#include "base/kernel/Env.h" +#include "3rdparty/rapidjson/document.h" +#include "base/io/Env.h" #include "base/kernel/interfaces/IClientListener.h" #include "base/net/stratum/SubmitResult.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index bdf6d5ca1..89a8e67eb 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -328,7 +328,7 @@ int64_t xmrig::DaemonClient::getBlockTemplate() int64_t xmrig::DaemonClient::rpcSend(const rapidjson::Document &doc) { - FetchRequest req(HTTP_POST, m_pool, kJsonRPC, doc, isQuiet()); + FetchRequest req(HTTP_POST, m_pool.host(), m_pool.port(), kJsonRPC, doc, m_pool.isTLS(), isQuiet()); fetch(std::move(req), m_httpListener); return m_sequence++; @@ -355,7 +355,7 @@ void xmrig::DaemonClient::retry() void xmrig::DaemonClient::send(const char *path) { - FetchRequest req(HTTP_GET, m_pool, path, isQuiet()); + FetchRequest req(HTTP_GET, m_pool.host(), m_pool.port(), path, m_pool.isTLS(), isQuiet()); fetch(std::move(req), m_httpListener); } diff --git a/src/base/net/tls/TlsConfig.cpp b/src/base/net/tls/TlsConfig.cpp index 49b1970d0..2e3dc903b 100644 --- a/src/base/net/tls/TlsConfig.cpp +++ b/src/base/net/tls/TlsConfig.cpp @@ -25,10 +25,10 @@ #include "base/net/tls/TlsConfig.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" #include "base/net/tls/TlsGen.h" -#include "rapidjson/document.h" namespace xmrig { @@ -86,7 +86,7 @@ xmrig::TlsConfig::TlsConfig(const rapidjson::Value &value) generate(); } } -# ifdef XMRIG_PROXY_PROJECT +# ifdef XMRIG_FORCE_TLS else if (value.IsNull()) { generate(); } diff --git a/src/base/net/tls/TlsConfig.h b/src/base/net/tls/TlsConfig.h index 4e0fe7879..c5407f321 100644 --- a/src/base/net/tls/TlsConfig.h +++ b/src/base/net/tls/TlsConfig.h @@ -27,8 +27,8 @@ #define XMRIG_TLSCONFIG_H +#include "3rdparty/rapidjson/fwd.h" #include "base/tools/String.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/net/tls/TlsContext.cpp b/src/base/net/tls/TlsContext.cpp index d2ab71c5a..03c79e654 100644 --- a/src/base/net/tls/TlsContext.cpp +++ b/src/base/net/tls/TlsContext.cpp @@ -25,8 +25,8 @@ #include "base/net/tls/TlsContext.h" +#include "base/io/Env.h" #include "base/io/log/Log.h" -#include "base/kernel/Env.h" #include "base/net/tls/TlsConfig.h" diff --git a/src/base/net/tools/Storage.h b/src/base/net/tools/Storage.h index 0af4db263..e23e86665 100644 --- a/src/base/net/tools/Storage.h +++ b/src/base/net/tools/Storage.h @@ -1,10 +1,4 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , * Copyright 2018-2020 SChernykh * Copyright 2016-2020 XMRig , * @@ -48,10 +42,10 @@ public: } - inline static void *ptr(uintptr_t id) { return reinterpret_cast(id); } + inline void *ptr(uintptr_t id) { return reinterpret_cast(id); } - inline TYPE *get(const void *id) const { return get(reinterpret_cast(id)); } + inline TYPE *get(const void *id) const { return get(reinterpret_cast(id)); } inline TYPE *get(uintptr_t id) const { assert(m_data.count(id) > 0); @@ -63,19 +57,16 @@ public: } - inline void remove(const void *id) { delete release(reinterpret_cast(id)); } - inline void remove(uintptr_t id) { delete release(id); } + inline void remove(const void *id) { delete release(reinterpret_cast(id)); } + inline void remove(uintptr_t id) { delete release(id); } - inline TYPE *release(const void *id) { release(reinterpret_cast(id)); } + inline TYPE *release(const void *id) { return release(reinterpret_cast(id)); } inline TYPE *release(uintptr_t id) { - TYPE *obj = get(id); + auto obj = get(id); if (obj != nullptr) { - auto it = m_data.find(id); - if (it != m_data.end()) { - m_data.erase(it); - } + m_data.erase(id); } return obj; @@ -84,7 +75,7 @@ public: private: std::map m_data; - uint64_t m_counter = 0; + uintptr_t m_counter = 0; }; diff --git a/src/base/tools/Arguments.cpp b/src/base/tools/Arguments.cpp index d0352939b..eebe0e736 100644 --- a/src/base/tools/Arguments.cpp +++ b/src/base/tools/Arguments.cpp @@ -52,7 +52,7 @@ bool xmrig::Arguments::hasArg(const char *name) const } -const char *xmrig::Arguments::value(const char *key) const +const char *xmrig::Arguments::value(const char *key1, const char *key2) const { const size_t size = m_data.size(); if (size < 3) { @@ -60,7 +60,7 @@ const char *xmrig::Arguments::value(const char *key) const } for (size_t i = 1; i < size - 1; ++i) { - if (m_data[i] == key) { + if (m_data[i] == key1 || (key2 && m_data[i] == key2)) { return m_data[i + 1]; } } diff --git a/src/base/tools/Arguments.h b/src/base/tools/Arguments.h index 0016c519f..e7a105363 100644 --- a/src/base/tools/Arguments.h +++ b/src/base/tools/Arguments.h @@ -41,7 +41,7 @@ public: Arguments(int argc, char **argv); bool hasArg(const char *name) const; - const char *value(const char *key) const; + const char *value(const char *key1, const char *key2 = nullptr) const; inline char **argv() const { return m_argv; } inline const std::vector &data() const { return m_data; } diff --git a/src/base/tools/String.cpp b/src/base/tools/String.cpp index b11d67745..f93222746 100644 --- a/src/base/tools/String.cpp +++ b/src/base/tools/String.cpp @@ -23,11 +23,11 @@ */ -#include - - #include "base/tools/String.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" + + +#include xmrig::String::String(const char *str) : diff --git a/src/base/tools/String.h b/src/base/tools/String.h index 0f3656410..df6495768 100644 --- a/src/base/tools/String.h +++ b/src/base/tools/String.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,13 +26,13 @@ #define XMRIG_STRING_H +#include "3rdparty/rapidjson/fwd.h" + + #include #include -#include "rapidjson/fwd.h" - - namespace xmrig { @@ -85,11 +85,11 @@ public: rapidjson::Value toJSON() const; rapidjson::Value toJSON(rapidjson::Document &doc) const; - std::vector split(char sep) const; + std::vector split(char sep) const; String &toLower(); String &toUpper(); - static String join(const std::vector &vec, char sep); + static String join(const std::vector &vec, char sep); private: void copy(const char *str); diff --git a/src/base/tools/Timer.cpp b/src/base/tools/Timer.cpp index d06df1636..858d1219e 100644 --- a/src/base/tools/Timer.cpp +++ b/src/base/tools/Timer.cpp @@ -1,12 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -23,22 +17,20 @@ */ +#include "base/tools/Timer.h" #include "base/kernel/interfaces/ITimerListener.h" #include "base/tools/Handle.h" -#include "base/tools/Timer.h" xmrig::Timer::Timer(ITimerListener *listener) : - m_listener(listener), - m_timer(nullptr) + m_listener(listener) { init(); } xmrig::Timer::Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat) : - m_listener(listener), - m_timer(nullptr) + m_listener(listener) { init(); start(timeout, repeat); @@ -63,6 +55,15 @@ void xmrig::Timer::setRepeat(uint64_t repeat) } +void xmrig::Timer::singleShot(uint64_t timeout, int id) +{ + m_id = id; + + stop(); + start(timeout, 0); +} + + void xmrig::Timer::start(uint64_t timeout, uint64_t repeat) { uv_timer_start(m_timer, onTimer, timeout, repeat); @@ -71,6 +72,7 @@ void xmrig::Timer::start(uint64_t timeout, uint64_t repeat) void xmrig::Timer::stop() { + setRepeat(0); uv_timer_stop(m_timer); } @@ -85,7 +87,7 @@ void xmrig::Timer::init() void xmrig::Timer::onTimer(uv_timer_t *handle) { - const Timer *timer = static_cast(handle->data); + const auto timer = static_cast(handle->data); timer->m_listener->onTimer(timer); } diff --git a/src/base/tools/Timer.h b/src/base/tools/Timer.h index e0e210f52..8fd040f83 100644 --- a/src/base/tools/Timer.h +++ b/src/base/tools/Timer.h @@ -1,12 +1,6 @@ /* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,10 +20,13 @@ #define XMRIG_TIMER_H -#include +using uv_timer_t = struct uv_timer_s; -typedef struct uv_timer_s uv_timer_t; +#include "base/tools/Object.h" + + +#include namespace xmrig { @@ -41,12 +38,17 @@ class ITimerListener; class Timer { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(Timer); + Timer(ITimerListener *listener); Timer(ITimerListener *listener, uint64_t timeout, uint64_t repeat); ~Timer(); + inline int id() const { return m_id; } + uint64_t repeat() const; void setRepeat(uint64_t repeat); + void singleShot(uint64_t timeout, int id = 0); void start(uint64_t timeout, uint64_t repeat); void stop(); @@ -55,8 +57,9 @@ private: static void onTimer(uv_timer_t *handle); + int m_id = 0; ITimerListener *m_listener; - uv_timer_t *m_timer; + uv_timer_t *m_timer = nullptr; }; From 8aeba617066168e9132649c2f4008a0859f70910 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 29 Apr 2020 14:55:04 +0700 Subject: [PATCH 03/24] Add 3rdparty prefix to all rapidjson includes. --- src/backend/common/Hashrate.cpp | 6 +- src/backend/common/Hashrate.h | 6 +- src/backend/common/Threads.cpp | 2 +- src/backend/common/Threads.h | 2 +- src/backend/common/common.cmake | 1 - src/backend/common/interfaces/IBackend.h | 2 +- src/backend/common/interfaces/IThread.h | 77 ------------------- src/backend/cpu/Cpu.cpp | 2 +- src/backend/cpu/CpuBackend.cpp | 4 +- src/backend/cpu/CpuConfig.cpp | 2 +- src/backend/cpu/CpuThread.cpp | 6 +- src/backend/cpu/CpuThread.h | 6 +- src/backend/cpu/CpuThreads.cpp | 6 +- src/backend/cpu/CpuThreads.h | 4 +- src/backend/cuda/CudaBackend.cpp | 2 +- src/backend/cuda/CudaConfig.cpp | 2 +- src/backend/cuda/CudaThread.cpp | 2 +- src/backend/cuda/CudaThread.h | 2 +- src/backend/cuda/CudaThreads.cpp | 6 +- src/backend/cuda/CudaThreads.h | 4 +- src/backend/cuda/wrappers/CudaDevice.cpp | 3 +- src/backend/opencl/OclBackend.cpp | 2 +- src/backend/opencl/OclConfig.cpp | 2 +- src/backend/opencl/OclThread.cpp | 2 +- src/backend/opencl/OclThread.h | 2 +- src/backend/opencl/OclThreads.cpp | 6 +- src/backend/opencl/OclThreads.h | 4 +- src/backend/opencl/wrappers/OclDevice.cpp | 3 +- src/backend/opencl/wrappers/OclPlatform.cpp | 8 +- src/backend/opencl/wrappers/OclPlatform.h | 4 +- src/base/api/interfaces/IApiRequest.h | 2 +- src/base/api/requests/HttpApiRequest.cpp | 4 +- src/base/crypto/Algorithm.cpp | 2 +- src/base/crypto/Algorithm.h | 2 +- src/base/crypto/Coin.cpp | 2 +- src/base/crypto/Coin.h | 2 +- src/base/io/json/Json.cpp | 2 +- src/base/io/json/Json.h | 2 +- src/base/io/json/JsonChain.cpp | 8 +- src/base/io/json/JsonChain.h | 6 +- src/base/io/json/JsonRequest.cpp | 2 +- src/base/io/json/JsonRequest.h | 2 +- src/base/io/json/Json_unix.cpp | 12 +-- src/base/io/json/Json_win.cpp | 12 +-- src/base/kernel/Base.h | 2 +- src/base/kernel/config/BaseConfig.cpp | 2 +- src/base/kernel/config/BaseTransform.h | 2 +- src/base/kernel/interfaces/IClient.h | 2 +- src/base/kernel/interfaces/IClientListener.h | 6 +- src/base/kernel/interfaces/IConfig.h | 2 +- src/base/kernel/interfaces/IConfigTransform.h | 2 +- src/base/kernel/interfaces/IJsonReader.h | 6 +- .../kernel/interfaces/IStrategyListener.h | 6 +- src/base/net/http/HttpApiResponse.cpp | 4 +- src/base/net/http/HttpApiResponse.h | 2 +- src/base/net/stratum/Client.cpp | 8 +- src/base/net/stratum/DaemonClient.cpp | 4 +- src/base/net/stratum/NetworkState.cpp | 2 +- src/base/net/stratum/Pool.cpp | 2 +- src/base/net/stratum/Pool.h | 2 +- src/base/net/stratum/Pools.cpp | 2 +- src/base/net/stratum/ProxyUrl.cpp | 2 +- src/base/net/stratum/SelfSelectClient.cpp | 4 +- src/core/Miner.cpp | 6 +- src/core/config/Config.cpp | 6 +- src/core/config/Config.h | 2 +- src/crypto/common/Assembly.cpp | 6 +- src/crypto/common/Assembly.h | 6 +- src/crypto/rx/RxConfig.cpp | 2 +- src/crypto/rx/RxConfig.h | 2 +- src/crypto/rx/msr/MsrItem.cpp | 6 +- src/crypto/rx/msr/MsrItem.h | 4 +- src/donate.h | 9 ++- src/net/Network.cpp | 2 +- src/net/Network.h | 2 +- src/net/strategies/DonateStrategy.cpp | 2 +- 76 files changed, 140 insertions(+), 217 deletions(-) delete mode 100644 src/backend/common/interfaces/IThread.h diff --git a/src/backend/common/Hashrate.cpp b/src/backend/common/Hashrate.cpp index eb01a5fb0..c7ef90fbf 100644 --- a/src/backend/common/Hashrate.cpp +++ b/src/backend/common/Hashrate.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -30,10 +30,10 @@ #include "backend/common/Hashrate.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" #include "base/tools/Chrono.h" #include "base/tools/Handle.h" -#include "rapidjson/document.h" inline static const char *format(double h, char *buf, size_t size) diff --git a/src/backend/common/Hashrate.h b/src/backend/common/Hashrate.h index ba60d2adf..59e1afe1f 100644 --- a/src/backend/common/Hashrate.h +++ b/src/backend/common/Hashrate.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -30,8 +30,8 @@ #include +#include "3rdparty/rapidjson/fwd.h" #include "base/tools/Object.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/backend/common/Threads.cpp b/src/backend/common/Threads.cpp index 4b23e85d2..920e7deff 100644 --- a/src/backend/common/Threads.cpp +++ b/src/backend/common/Threads.cpp @@ -24,9 +24,9 @@ #include "backend/common/Threads.h" +#include "3rdparty/rapidjson/document.h" #include "backend/cpu/CpuThreads.h" #include "crypto/cn/CnAlgo.h" -#include "rapidjson/document.h" #ifdef XMRIG_FEATURE_OPENCL diff --git a/src/backend/common/Threads.h b/src/backend/common/Threads.h index a21fe13b5..1682efbad 100644 --- a/src/backend/common/Threads.h +++ b/src/backend/common/Threads.h @@ -30,9 +30,9 @@ #include +#include "3rdparty/rapidjson/fwd.h" #include "base/crypto/Algorithm.h" #include "base/tools/String.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/backend/common/common.cmake b/src/backend/common/common.cmake index 9dd0fb3c1..03c37c8f7 100644 --- a/src/backend/common/common.cmake +++ b/src/backend/common/common.cmake @@ -4,7 +4,6 @@ set(HEADERS_BACKEND_COMMON src/backend/common/interfaces/IBackend.h src/backend/common/interfaces/IRxListener.h src/backend/common/interfaces/IRxStorage.h - src/backend/common/interfaces/IThread.h src/backend/common/interfaces/IWorker.h src/backend/common/misc/PciTopology.h src/backend/common/Thread.h diff --git a/src/backend/common/interfaces/IBackend.h b/src/backend/common/interfaces/IBackend.h index bdaf54635..405d876a7 100644 --- a/src/backend/common/interfaces/IBackend.h +++ b/src/backend/common/interfaces/IBackend.h @@ -29,7 +29,7 @@ #include -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/backend/common/interfaces/IThread.h b/src/backend/common/interfaces/IThread.h deleted file mode 100644 index 3c0a7287a..000000000 --- a/src/backend/common/interfaces/IThread.h +++ /dev/null @@ -1,77 +0,0 @@ -/* XMRig - * Copyright 2010 Jeff Garzik - * Copyright 2012-2014 pooler - * Copyright 2014 Lucas Jones - * Copyright 2014-2016 Wolf9466 - * Copyright 2016 Jay D Dee - * Copyright 2016-2018 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_ITHREAD_H -#define XMRIG_ITHREAD_H - - -#include - - -#include "crypto/common/Algorithm.h" -#include "rapidjson/fwd.h" - - -namespace xmrig { - - -class IThread -{ -public: - enum Type { - CPU, - OpenCL, - CUDA - }; - - enum Multiway { - SingleWay = 1, - DoubleWay, - TripleWay, - QuadWay, - PentaWay - }; - - virtual ~IThread() = default; - - virtual Algorithm algorithm() const = 0; - virtual int priority() const = 0; - virtual int64_t affinity() const = 0; - virtual Multiway multiway() const = 0; - virtual rapidjson::Value toConfig(rapidjson::Document &doc) const = 0; - virtual size_t index() const = 0; - virtual Type type() const = 0; - -# ifdef XMRIG_FEATURE_API - virtual rapidjson::Value toAPI(rapidjson::Document &doc) const = 0; -# endif - -# ifdef APP_DEBUG - virtual void print() const = 0; -# endif -}; - - -} /* namespace xmrig */ - - -#endif // XMRIG_ITHREAD_H diff --git a/src/backend/cpu/Cpu.cpp b/src/backend/cpu/Cpu.cpp index 1e3157773..a11c4c567 100644 --- a/src/backend/cpu/Cpu.cpp +++ b/src/backend/cpu/Cpu.cpp @@ -27,7 +27,7 @@ #include "backend/cpu/Cpu.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" #if defined(XMRIG_FEATURE_HWLOC) diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 1efc1eafe..40b774d25 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -26,12 +26,13 @@ #include +#include "backend/cpu/CpuBackend.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Hashrate.h" #include "backend/common/interfaces/IWorker.h" #include "backend/common/Tags.h" #include "backend/common/Workers.h" #include "backend/cpu/Cpu.h" -#include "backend/cpu/CpuBackend.h" #include "base/io/log/Log.h" #include "base/net/stratum/Job.h" #include "base/tools/Chrono.h" @@ -41,7 +42,6 @@ #include "crypto/common/VirtualMemory.h" #include "crypto/rx/Rx.h" #include "crypto/rx/RxDataset.h" -#include "rapidjson/document.h" #ifdef XMRIG_FEATURE_API diff --git a/src/backend/cpu/CpuConfig.cpp b/src/backend/cpu/CpuConfig.cpp index 4c7a630f6..ab966e701 100644 --- a/src/backend/cpu/CpuConfig.cpp +++ b/src/backend/cpu/CpuConfig.cpp @@ -24,10 +24,10 @@ #include "backend/cpu/CpuConfig.h" +#include "3rdparty/rapidjson/document.h" #include "backend/cpu/CpuConfig_gen.h" #include "backend/cpu/Cpu.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" #include diff --git a/src/backend/cpu/CpuThread.cpp b/src/backend/cpu/CpuThread.cpp index 660107fa6..4da1baf7f 100644 --- a/src/backend/cpu/CpuThread.cpp +++ b/src/backend/cpu/CpuThread.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -24,8 +24,8 @@ #include "backend/cpu/CpuThread.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" xmrig::CpuThread::CpuThread(const rapidjson::Value &value) diff --git a/src/backend/cpu/CpuThread.h b/src/backend/cpu/CpuThread.h index 91d63a1c9..b198c8001 100644 --- a/src/backend/cpu/CpuThread.h +++ b/src/backend/cpu/CpuThread.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,7 +26,7 @@ #define XMRIG_CPUTHREAD_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/backend/cpu/CpuThreads.cpp b/src/backend/cpu/CpuThreads.cpp index 416b4ecbc..d9ae61b15 100644 --- a/src/backend/cpu/CpuThreads.cpp +++ b/src/backend/cpu/CpuThreads.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -27,8 +27,8 @@ #include "backend/cpu/CpuThreads.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/backend/cpu/CpuThreads.h b/src/backend/cpu/CpuThreads.h index 076670cdd..e87f52306 100644 --- a/src/backend/cpu/CpuThreads.h +++ b/src/backend/cpu/CpuThreads.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/backend/cuda/CudaBackend.cpp b/src/backend/cuda/CudaBackend.cpp index 25a773364..6004a83d2 100644 --- a/src/backend/cuda/CudaBackend.cpp +++ b/src/backend/cuda/CudaBackend.cpp @@ -28,6 +28,7 @@ #include "backend/cuda/CudaBackend.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Hashrate.h" #include "backend/common/interfaces/IWorker.h" #include "backend/common/Tags.h" @@ -43,7 +44,6 @@ #include "base/tools/String.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "rapidjson/document.h" #ifdef XMRIG_ALGO_ASTROBWT diff --git a/src/backend/cuda/CudaConfig.cpp b/src/backend/cuda/CudaConfig.cpp index 618aefa90..89e5237eb 100644 --- a/src/backend/cuda/CudaConfig.cpp +++ b/src/backend/cuda/CudaConfig.cpp @@ -24,12 +24,12 @@ #include "backend/cuda/CudaConfig.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Tags.h" #include "backend/cuda/CudaConfig_gen.h" #include "backend/cuda/wrappers/CudaLib.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/backend/cuda/CudaThread.cpp b/src/backend/cuda/CudaThread.cpp index eb65dc2c4..fff58eaa9 100644 --- a/src/backend/cuda/CudaThread.cpp +++ b/src/backend/cuda/CudaThread.cpp @@ -24,9 +24,9 @@ #include "backend/cuda/CudaThread.h" +#include "3rdparty/rapidjson/document.h" #include "backend/cuda/wrappers/CudaLib.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" #include diff --git a/src/backend/cuda/CudaThread.h b/src/backend/cuda/CudaThread.h index 3588e846d..75110bfdc 100644 --- a/src/backend/cuda/CudaThread.h +++ b/src/backend/cuda/CudaThread.h @@ -29,7 +29,7 @@ using nvid_ctx = struct nvid_ctx; -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/backend/cuda/CudaThreads.cpp b/src/backend/cuda/CudaThreads.cpp index 5ff4cb24b..b5696350e 100644 --- a/src/backend/cuda/CudaThreads.cpp +++ b/src/backend/cuda/CudaThreads.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -24,8 +24,8 @@ #include "backend/cuda/CudaThreads.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" #include diff --git a/src/backend/cuda/CudaThreads.h b/src/backend/cuda/CudaThreads.h index 5f174d8eb..eb6d54ee2 100644 --- a/src/backend/cuda/CudaThreads.h +++ b/src/backend/cuda/CudaThreads.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/backend/cuda/wrappers/CudaDevice.cpp b/src/backend/cuda/wrappers/CudaDevice.cpp index daa160745..f06fe9401 100644 --- a/src/backend/cuda/wrappers/CudaDevice.cpp +++ b/src/backend/cuda/wrappers/CudaDevice.cpp @@ -24,11 +24,12 @@ #include "backend/cuda/wrappers/CudaDevice.h" +#include "3rdparty/rapidjson/document.h" #include "backend/cuda/CudaThreads.h" #include "backend/cuda/wrappers/CudaLib.h" #include "base/crypto/Algorithm.h" #include "base/io/log/Log.h" -#include "rapidjson/document.h" + #ifdef XMRIG_FEATURE_NVML # include "backend/cuda/wrappers/NvmlLib.h" diff --git a/src/backend/opencl/OclBackend.cpp b/src/backend/opencl/OclBackend.cpp index 4b1a14bcf..2d431c323 100644 --- a/src/backend/opencl/OclBackend.cpp +++ b/src/backend/opencl/OclBackend.cpp @@ -28,6 +28,7 @@ #include "backend/opencl/OclBackend.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Hashrate.h" #include "backend/common/interfaces/IWorker.h" #include "backend/common/Tags.h" @@ -45,7 +46,6 @@ #include "base/tools/String.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "rapidjson/document.h" #ifdef XMRIG_FEATURE_API diff --git a/src/backend/opencl/OclConfig.cpp b/src/backend/opencl/OclConfig.cpp index b06746f3c..c05f36d45 100644 --- a/src/backend/opencl/OclConfig.cpp +++ b/src/backend/opencl/OclConfig.cpp @@ -24,12 +24,12 @@ #include "backend/opencl/OclConfig.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Tags.h" #include "backend/opencl/OclConfig_gen.h" #include "backend/opencl/wrappers/OclLib.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/backend/opencl/OclThread.cpp b/src/backend/opencl/OclThread.cpp index b542b443f..087b2cf7e 100644 --- a/src/backend/opencl/OclThread.cpp +++ b/src/backend/opencl/OclThread.cpp @@ -24,8 +24,8 @@ #include "backend/opencl/OclThread.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" #include diff --git a/src/backend/opencl/OclThread.h b/src/backend/opencl/OclThread.h index dac57a4f1..fbdfe1779 100644 --- a/src/backend/opencl/OclThread.h +++ b/src/backend/opencl/OclThread.h @@ -26,7 +26,7 @@ #define XMRIG_OCLTHREAD_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" #include diff --git a/src/backend/opencl/OclThreads.cpp b/src/backend/opencl/OclThreads.cpp index 3e53a5f5d..5b6995132 100644 --- a/src/backend/opencl/OclThreads.cpp +++ b/src/backend/opencl/OclThreads.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -27,8 +27,8 @@ #include "backend/opencl/OclThreads.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" xmrig::OclThreads::OclThreads(const rapidjson::Value &value) diff --git a/src/backend/opencl/OclThreads.h b/src/backend/opencl/OclThreads.h index ed3ad18db..8d9c101e3 100644 --- a/src/backend/opencl/OclThreads.h +++ b/src/backend/opencl/OclThreads.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/backend/opencl/wrappers/OclDevice.cpp b/src/backend/opencl/wrappers/OclDevice.cpp index cd90e95b7..68ab60722 100644 --- a/src/backend/opencl/wrappers/OclDevice.cpp +++ b/src/backend/opencl/wrappers/OclDevice.cpp @@ -24,11 +24,12 @@ #include "backend/opencl/wrappers/OclDevice.h" +#include "3rdparty/rapidjson/document.h" #include "backend/opencl/OclGenerator.h" #include "backend/opencl/OclThreads.h" #include "backend/opencl/wrappers/OclLib.h" #include "base/io/log/Log.h" -#include "rapidjson/document.h" + #ifdef XMRIG_FEATURE_ADL # include "backend/opencl/wrappers/AdlLib.h" diff --git a/src/backend/opencl/wrappers/OclPlatform.cpp b/src/backend/opencl/wrappers/OclPlatform.cpp index 601ee6fae..6c3509f08 100644 --- a/src/backend/opencl/wrappers/OclPlatform.cpp +++ b/src/backend/opencl/wrappers/OclPlatform.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -23,9 +23,9 @@ */ -#include "backend/opencl/wrappers/OclLib.h" #include "backend/opencl/wrappers/OclPlatform.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" +#include "backend/opencl/wrappers/OclLib.h" std::vector xmrig::OclPlatform::get() diff --git a/src/backend/opencl/wrappers/OclPlatform.h b/src/backend/opencl/wrappers/OclPlatform.h index 133e84755..dc9bd24ee 100644 --- a/src/backend/opencl/wrappers/OclPlatform.h +++ b/src/backend/opencl/wrappers/OclPlatform.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/base/api/interfaces/IApiRequest.h b/src/base/api/interfaces/IApiRequest.h index c23c16523..c05e513ec 100644 --- a/src/base/api/interfaces/IApiRequest.h +++ b/src/base/api/interfaces/IApiRequest.h @@ -26,7 +26,7 @@ #define XMRIG_IAPIREQUEST_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/api/requests/HttpApiRequest.cpp b/src/base/api/requests/HttpApiRequest.cpp index 6be25e968..70fa2523b 100644 --- a/src/base/api/requests/HttpApiRequest.cpp +++ b/src/base/api/requests/HttpApiRequest.cpp @@ -23,11 +23,11 @@ */ -#include "3rdparty/http-parser/http_parser.h" #include "base/api/requests/HttpApiRequest.h" +#include "3rdparty/http-parser/http_parser.h" +#include "3rdparty/rapidjson/error/en.h" #include "base/io/json/Json.h" #include "base/net/http/HttpData.h" -#include "rapidjson/error/en.h" namespace xmrig { diff --git a/src/base/crypto/Algorithm.cpp b/src/base/crypto/Algorithm.cpp index 5ed372199..7d7db9b4f 100644 --- a/src/base/crypto/Algorithm.cpp +++ b/src/base/crypto/Algorithm.cpp @@ -25,7 +25,7 @@ #include "base/crypto/Algorithm.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" #include diff --git a/src/base/crypto/Algorithm.h b/src/base/crypto/Algorithm.h index 198ca4f21..1fb9e2acc 100644 --- a/src/base/crypto/Algorithm.h +++ b/src/base/crypto/Algorithm.h @@ -30,7 +30,7 @@ #include -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/crypto/Coin.cpp b/src/base/crypto/Coin.cpp index 8b32e4fc2..57b5fcf0a 100644 --- a/src/base/crypto/Coin.cpp +++ b/src/base/crypto/Coin.cpp @@ -25,7 +25,7 @@ #include "base/crypto/Coin.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" #include diff --git a/src/base/crypto/Coin.h b/src/base/crypto/Coin.h index 3197c46dc..73eb8d24c 100644 --- a/src/base/crypto/Coin.h +++ b/src/base/crypto/Coin.h @@ -27,8 +27,8 @@ #define XMRIG_COIN_H +#include "3rdparty/rapidjson/fwd.h" #include "base/crypto/Algorithm.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/io/json/Json.cpp b/src/base/io/json/Json.cpp index cd7213d22..b9918d02f 100644 --- a/src/base/io/json/Json.cpp +++ b/src/base/io/json/Json.cpp @@ -24,7 +24,7 @@ #include "base/io/json/Json.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" #include diff --git a/src/base/io/json/Json.h b/src/base/io/json/Json.h index 15f340a76..c711d6ef2 100644 --- a/src/base/io/json/Json.h +++ b/src/base/io/json/Json.h @@ -26,8 +26,8 @@ #define XMRIG_JSON_H +#include "3rdparty/rapidjson/fwd.h" #include "base/kernel/interfaces/IJsonReader.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/io/json/JsonChain.cpp b/src/base/io/json/JsonChain.cpp index bbaabbde9..972167f1b 100644 --- a/src/base/io/json/JsonChain.cpp +++ b/src/base/io/json/JsonChain.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -23,10 +23,10 @@ */ -#include "base/io/json/Json.h" #include "base/io/json/JsonChain.h" +#include "3rdparty/rapidjson/error/en.h" +#include "base/io/json/Json.h" #include "base/io/log/Log.h" -#include "rapidjson/error/en.h" namespace xmrig { diff --git a/src/base/io/json/JsonChain.h b/src/base/io/json/JsonChain.h index 275f789ea..90f307422 100644 --- a/src/base/io/json/JsonChain.h +++ b/src/base/io/json/JsonChain.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -29,9 +29,9 @@ #include +#include "3rdparty/rapidjson/document.h" #include "base/kernel/interfaces/IJsonReader.h" #include "base/tools/String.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/base/io/json/JsonRequest.cpp b/src/base/io/json/JsonRequest.cpp index d66040a7b..cacbdc809 100644 --- a/src/base/io/json/JsonRequest.cpp +++ b/src/base/io/json/JsonRequest.cpp @@ -24,7 +24,7 @@ #include "base/io/json/JsonRequest.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" namespace xmrig { diff --git a/src/base/io/json/JsonRequest.h b/src/base/io/json/JsonRequest.h index b2e0b156e..88dbbad65 100644 --- a/src/base/io/json/JsonRequest.h +++ b/src/base/io/json/JsonRequest.h @@ -26,7 +26,7 @@ #define XMRIG_JSONREQUEST_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/io/json/Json_unix.cpp b/src/base/io/json/Json_unix.cpp index dedea947d..ebb45a3ba 100644 --- a/src/base/io/json/Json_unix.cpp +++ b/src/base/io/json/Json_unix.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -27,10 +27,10 @@ #include "base/io/json/Json.h" -#include "rapidjson/document.h" -#include "rapidjson/istreamwrapper.h" -#include "rapidjson/ostreamwrapper.h" -#include "rapidjson/prettywriter.h" +#include "3rdparty/rapidjson/document.h" +#include "3rdparty/rapidjson/istreamwrapper.h" +#include "3rdparty/rapidjson/ostreamwrapper.h" +#include "3rdparty/rapidjson/prettywriter.h" bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc) diff --git a/src/base/io/json/Json_win.cpp b/src/base/io/json/Json_win.cpp index cb6f02f64..093cd3dab 100644 --- a/src/base/io/json/Json_win.cpp +++ b/src/base/io/json/Json_win.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -37,10 +37,10 @@ #include "base/io/json/Json.h" -#include "rapidjson/document.h" -#include "rapidjson/istreamwrapper.h" -#include "rapidjson/ostreamwrapper.h" -#include "rapidjson/prettywriter.h" +#include "3rdparty/rapidjson/document.h" +#include "3rdparty/rapidjson/istreamwrapper.h" +#include "3rdparty/rapidjson/ostreamwrapper.h" +#include "3rdparty/rapidjson/prettywriter.h" #if defined(_MSC_VER) || defined (__GNUC__) diff --git a/src/base/kernel/Base.h b/src/base/kernel/Base.h index 756b6cafc..f113c0f70 100644 --- a/src/base/kernel/Base.h +++ b/src/base/kernel/Base.h @@ -26,11 +26,11 @@ #define XMRIG_BASE_H +#include "3rdparty/rapidjson/fwd.h" #include "base/api/interfaces/IApiListener.h" #include "base/kernel/interfaces/IConfigListener.h" #include "base/kernel/interfaces/IWatcherListener.h" #include "base/tools/Object.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 12f5db742..1fe2d1edc 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -24,10 +24,10 @@ #include "base/kernel/config/BaseConfig.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" #include "base/kernel/interfaces/IJsonReader.h" -#include "rapidjson/document.h" #include "version.h" diff --git a/src/base/kernel/config/BaseTransform.h b/src/base/kernel/config/BaseTransform.h index 9550328ae..d6c08821b 100644 --- a/src/base/kernel/config/BaseTransform.h +++ b/src/base/kernel/config/BaseTransform.h @@ -26,9 +26,9 @@ #define XMRIG_BASETRANSFORM_H +#include "3rdparty/rapidjson/document.h" #include "base/crypto/Coin.h" #include "base/kernel/interfaces/IConfigTransform.h" -#include "rapidjson/document.h" struct option; diff --git a/src/base/kernel/interfaces/IClient.h b/src/base/kernel/interfaces/IClient.h index 9349aa6af..8a8776ba9 100644 --- a/src/base/kernel/interfaces/IClient.h +++ b/src/base/kernel/interfaces/IClient.h @@ -26,7 +26,7 @@ #define XMRIG_ICLIENT_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" #include diff --git a/src/base/kernel/interfaces/IClientListener.h b/src/base/kernel/interfaces/IClientListener.h index 45b0bcfd2..4f2be302c 100644 --- a/src/base/kernel/interfaces/IClientListener.h +++ b/src/base/kernel/interfaces/IClientListener.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -29,7 +29,7 @@ #include -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/kernel/interfaces/IConfig.h b/src/base/kernel/interfaces/IConfig.h index 32f4b29b4..7e5c255d5 100644 --- a/src/base/kernel/interfaces/IConfig.h +++ b/src/base/kernel/interfaces/IConfig.h @@ -26,7 +26,7 @@ #define XMRIG_ICONFIG_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/kernel/interfaces/IConfigTransform.h b/src/base/kernel/interfaces/IConfigTransform.h index 571d3e5a7..c8ada0b8b 100644 --- a/src/base/kernel/interfaces/IConfigTransform.h +++ b/src/base/kernel/interfaces/IConfigTransform.h @@ -26,7 +26,7 @@ #define XMRIG_ICONFIGTRANSFORM_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/kernel/interfaces/IJsonReader.h b/src/base/kernel/interfaces/IJsonReader.h index c0fe09cb5..b545514db 100644 --- a/src/base/kernel/interfaces/IJsonReader.h +++ b/src/base/kernel/interfaces/IJsonReader.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,7 +26,7 @@ #define XMRIG_IJSONREADER_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/kernel/interfaces/IStrategyListener.h b/src/base/kernel/interfaces/IStrategyListener.h index 8b88b5068..4d99ce7f2 100644 --- a/src/base/kernel/interfaces/IStrategyListener.h +++ b/src/base/kernel/interfaces/IStrategyListener.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,7 +26,7 @@ #define XMRIG_ISTRATEGYLISTENER_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/net/http/HttpApiResponse.cpp b/src/base/net/http/HttpApiResponse.cpp index 6bf23c45b..fed3df53a 100644 --- a/src/base/net/http/HttpApiResponse.cpp +++ b/src/base/net/http/HttpApiResponse.cpp @@ -26,9 +26,9 @@ #include "base/net/http/HttpApiResponse.h" #include "3rdparty/http-parser/http_parser.h" +#include "3rdparty/rapidjson/prettywriter.h" +#include "3rdparty/rapidjson/stringbuffer.h" #include "base/net/http/HttpData.h" -#include "rapidjson/prettywriter.h" -#include "rapidjson/stringbuffer.h" namespace xmrig { diff --git a/src/base/net/http/HttpApiResponse.h b/src/base/net/http/HttpApiResponse.h index a50707354..8a7825108 100644 --- a/src/base/net/http/HttpApiResponse.h +++ b/src/base/net/http/HttpApiResponse.h @@ -28,8 +28,8 @@ #define XMRIG_HTTPAPIRESPONSE_H +#include "3rdparty/rapidjson/document.h" #include "base/net/http/HttpResponse.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 95de98c7d..815740162 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -39,6 +39,10 @@ #include "base/net/stratum/Client.h" +#include "3rdparty/rapidjson/document.h" +#include "3rdparty/rapidjson/error/en.h" +#include "3rdparty/rapidjson/stringbuffer.h" +#include "3rdparty/rapidjson/writer.h" #include "base/io/json/Json.h" #include "base/io/json/JsonRequest.h" #include "base/io/log/Log.h" @@ -49,10 +53,6 @@ #include "base/tools/Buffer.h" #include "base/tools/Chrono.h" #include "net/JobResult.h" -#include "rapidjson/document.h" -#include "rapidjson/error/en.h" -#include "rapidjson/stringbuffer.h" -#include "rapidjson/writer.h" #ifdef _MSC_VER diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 89a8e67eb..59e2a6ff8 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -26,6 +26,8 @@ #include "base/net/stratum/DaemonClient.h" #include "3rdparty/http-parser/http_parser.h" +#include "3rdparty/rapidjson/document.h" +#include "3rdparty/rapidjson/error/en.h" #include "base/io/json/Json.h" #include "base/io/json/JsonRequest.h" #include "base/io/log/Log.h" @@ -36,8 +38,6 @@ #include "base/tools/Buffer.h" #include "base/tools/Timer.h" #include "net/JobResult.h" -#include "rapidjson/document.h" -#include "rapidjson/error/en.h" #include diff --git a/src/base/net/stratum/NetworkState.cpp b/src/base/net/stratum/NetworkState.cpp index 29d911e1f..16f76336d 100644 --- a/src/base/net/stratum/NetworkState.cpp +++ b/src/base/net/stratum/NetworkState.cpp @@ -24,13 +24,13 @@ #include "base/net/stratum/NetworkState.h" +#include "3rdparty/rapidjson/document.h" #include "base/kernel/interfaces/IClient.h" #include "base/kernel/interfaces/IStrategy.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/Pool.h" #include "base/net/stratum/SubmitResult.h" #include "base/tools/Chrono.h" -#include "rapidjson/document.h" #include diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index e112feca3..afd7433f9 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -32,11 +32,11 @@ #include "base/net/stratum/Pool.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" #include "base/kernel/Platform.h" #include "base/net/stratum/Client.h" -#include "rapidjson/document.h" #ifdef XMRIG_FEATURE_HTTP diff --git a/src/base/net/stratum/Pool.h b/src/base/net/stratum/Pool.h index 02855200c..95703eca8 100644 --- a/src/base/net/stratum/Pool.h +++ b/src/base/net/stratum/Pool.h @@ -31,9 +31,9 @@ #include +#include "3rdparty/rapidjson/fwd.h" #include "base/crypto/Coin.h" #include "base/net/stratum/ProxyUrl.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/base/net/stratum/Pools.cpp b/src/base/net/stratum/Pools.cpp index a65e26b1d..90655547a 100644 --- a/src/base/net/stratum/Pools.cpp +++ b/src/base/net/stratum/Pools.cpp @@ -24,12 +24,12 @@ #include "base/net/stratum/Pools.h" +#include "3rdparty/rapidjson/document.h" #include "base/io/log/Log.h" #include "base/kernel/interfaces/IJsonReader.h" #include "base/net/stratum/strategies/FailoverStrategy.h" #include "base/net/stratum/strategies/SinglePoolStrategy.h" #include "donate.h" -#include "rapidjson/document.h" namespace xmrig { diff --git a/src/base/net/stratum/ProxyUrl.cpp b/src/base/net/stratum/ProxyUrl.cpp index 5b0ff281b..ad4542bc6 100644 --- a/src/base/net/stratum/ProxyUrl.cpp +++ b/src/base/net/stratum/ProxyUrl.cpp @@ -18,7 +18,7 @@ #include "base/net/stratum/ProxyUrl.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" namespace xmrig { diff --git a/src/base/net/stratum/SelfSelectClient.cpp b/src/base/net/stratum/SelfSelectClient.cpp index 6fdcf14d6..8ad48b65c 100644 --- a/src/base/net/stratum/SelfSelectClient.cpp +++ b/src/base/net/stratum/SelfSelectClient.cpp @@ -26,14 +26,14 @@ #include "base/net/stratum/SelfSelectClient.h" #include "3rdparty/http-parser/http_parser.h" +#include "3rdparty/rapidjson/document.h" +#include "3rdparty/rapidjson/error/en.h" #include "base/io/json/Json.h" #include "base/io/json/JsonRequest.h" #include "base/io/log/Log.h" #include "base/net/http/Fetch.h" #include "base/net/http/HttpData.h" #include "base/net/stratum/Client.h" -#include "rapidjson/document.h" -#include "rapidjson/error/en.h" namespace xmrig { diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 254428fbe..78beeb8ed 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -28,6 +28,8 @@ #include +#include "core/Miner.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Hashrate.h" #include "backend/cpu/Cpu.h" #include "backend/cpu/CpuBackend.h" @@ -38,11 +40,9 @@ #include "base/tools/Timer.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "core/Miner.h" +#include "crypto/astrobwt/AstroBWT.h" #include "crypto/common/Nonce.h" #include "crypto/rx/Rx.h" -#include "crypto/astrobwt/AstroBWT.h" -#include "rapidjson/document.h" #include "version.h" diff --git a/src/core/config/Config.cpp b/src/core/config/Config.cpp index fe3c8c33a..9fc6a830c 100644 --- a/src/core/config/Config.cpp +++ b/src/core/config/Config.cpp @@ -28,14 +28,12 @@ #include +#include "core/config/Config.h" +#include "3rdparty/rapidjson/document.h" #include "backend/cpu/Cpu.h" #include "base/io/log/Log.h" #include "base/kernel/interfaces/IJsonReader.h" -#include "core/config/Config.h" #include "crypto/common/Assembly.h" -#include "rapidjson/document.h" -#include "rapidjson/filewritestream.h" -#include "rapidjson/prettywriter.h" #ifdef XMRIG_ALGO_RANDOMX diff --git a/src/core/config/Config.h b/src/core/config/Config.h index 997fa505c..501b8c592 100644 --- a/src/core/config/Config.h +++ b/src/core/config/Config.h @@ -29,10 +29,10 @@ #include +#include "3rdparty/rapidjson/fwd.h" #include "backend/cpu/CpuConfig.h" #include "base/kernel/config/BaseConfig.h" #include "base/tools/Object.h" -#include "rapidjson/fwd.h" namespace xmrig { diff --git a/src/crypto/common/Assembly.cpp b/src/crypto/common/Assembly.cpp index 44bf0a949..5b7f8959b 100644 --- a/src/crypto/common/Assembly.cpp +++ b/src/crypto/common/Assembly.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 SChernykh - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -34,7 +34,7 @@ #include "crypto/common/Assembly.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" namespace xmrig { diff --git a/src/crypto/common/Assembly.h b/src/crypto/common/Assembly.h index 5ea29e11e..803ea7168 100644 --- a/src/crypto/common/Assembly.h +++ b/src/crypto/common/Assembly.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,7 +26,7 @@ #define XMRIG_ASSEMBLY_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" namespace xmrig { diff --git a/src/crypto/rx/RxConfig.cpp b/src/crypto/rx/RxConfig.cpp index 01d0616e9..82336708b 100644 --- a/src/crypto/rx/RxConfig.cpp +++ b/src/crypto/rx/RxConfig.cpp @@ -24,9 +24,9 @@ #include "crypto/rx/RxConfig.h" +#include "3rdparty/rapidjson/document.h" #include "backend/cpu/Cpu.h" #include "base/io/json/Json.h" -#include "rapidjson/document.h" #ifdef XMRIG_FEATURE_HWLOC diff --git a/src/crypto/rx/RxConfig.h b/src/crypto/rx/RxConfig.h index e42b3a711..af2ac9df8 100644 --- a/src/crypto/rx/RxConfig.h +++ b/src/crypto/rx/RxConfig.h @@ -26,7 +26,7 @@ #define XMRIG_RXCONFIG_H -#include "rapidjson/fwd.h" +#include "3rdparty/rapidjson/fwd.h" #ifdef XMRIG_FEATURE_MSR diff --git a/src/crypto/rx/msr/MsrItem.cpp b/src/crypto/rx/msr/MsrItem.cpp index 23cf5dc03..4c8e7f2af 100644 --- a/src/crypto/rx/msr/MsrItem.cpp +++ b/src/crypto/rx/msr/MsrItem.cpp @@ -7,8 +7,8 @@ * Copyright 2017-2019 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2018-2019 tevador - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -26,7 +26,7 @@ #include "crypto/rx/msr/MsrItem.h" -#include "rapidjson/document.h" +#include "3rdparty/rapidjson/document.h" #include diff --git a/src/crypto/rx/msr/MsrItem.h b/src/crypto/rx/msr/MsrItem.h index 5b84f432d..b14fda3b6 100644 --- a/src/crypto/rx/msr/MsrItem.h +++ b/src/crypto/rx/msr/MsrItem.h @@ -7,8 +7,8 @@ * Copyright 2017-2019 XMR-Stak , * Copyright 2018 Lee Clagett * Copyright 2018-2019 tevador - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 diff --git a/src/donate.h b/src/donate.h index 46f26b73e..a316389e7 100644 --- a/src/donate.h +++ b/src/donate.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __DONATE_H__ -#define __DONATE_H__ +#ifndef XMRIG_DONATE_H +#define XMRIG_DONATE_H /* @@ -47,4 +48,4 @@ constexpr const int kDefaultDonateLevel = 5; constexpr const int kMinimumDonateLevel = 1; -#endif /* __DONATE_H__ */ +#endif /* XMRIG_DONATE_H */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index b2b32e016..976ea8c44 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -28,6 +28,7 @@ #endif #include "net/Network.h" +#include "3rdparty/rapidjson/document.h" #include "backend/common/Tags.h" #include "base/io/log/Log.h" #include "base/net/stratum/Client.h" @@ -41,7 +42,6 @@ #include "net/JobResult.h" #include "net/JobResults.h" #include "net/strategies/DonateStrategy.h" -#include "rapidjson/document.h" #ifdef XMRIG_FEATURE_API diff --git a/src/net/Network.h b/src/net/Network.h index 826c64d0d..17490fca2 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -27,13 +27,13 @@ #define XMRIG_NETWORK_H +#include "3rdparty/rapidjson/fwd.h" #include "base/api/interfaces/IApiListener.h" #include "base/kernel/interfaces/IBaseListener.h" #include "base/kernel/interfaces/IStrategyListener.h" #include "base/kernel/interfaces/ITimerListener.h" #include "base/tools/Object.h" #include "interfaces/IJobResultListener.h" -#include "rapidjson/fwd.h" #include diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index ace9cfa3f..b1a9b6cae 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -29,6 +29,7 @@ #include "net/strategies/DonateStrategy.h" +#include "3rdparty/rapidjson/document.h" #include "base/crypto/keccak.h" #include "base/kernel/Platform.h" #include "base/net/stratum/Client.h" @@ -41,7 +42,6 @@ #include "core/Controller.h" #include "core/Miner.h" #include "net/Network.h" -#include "rapidjson/document.h" namespace xmrig { From 05d3f17f15cbc35005e17e40cc54361fd9f0588a Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 29 Apr 2020 11:08:45 +0200 Subject: [PATCH 04/24] Improved JSON config error reporting Show incorrect lines in config.json together with line number and position. --- src/base/io/json/Json.cpp | 31 +++++++++++++++++++++++++++++++ src/base/io/json/Json.h | 8 ++++++++ src/base/io/json/JsonChain.cpp | 22 +++++++++++++++++++++- src/base/io/json/Json_unix.cpp | 11 +++++++++++ src/base/io/json/Json_win.cpp | 28 ++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/base/io/json/Json.cpp b/src/base/io/json/Json.cpp index cd7213d22..48016665a 100644 --- a/src/base/io/json/Json.cpp +++ b/src/base/io/json/Json.cpp @@ -191,6 +191,37 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero) } +bool xmrig::Json::convertOffset(std::ifstream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s) +{ + std::string prev_t; + std::string t; + line = 0; + pos = 0; + size_t k = 0; + + while (!ifs.eof()) { + prev_t = t; + std::getline(ifs, t); + k += t.length() + 1; + ++line; + + if (k > offset) { + pos = offset + t.length() + 1 - k + 1; + + s.clear(); + if (!prev_t.empty()) { + s.emplace_back(prev_t); + } + s.emplace_back(t); + + return true; + } + } + + return false; +} + + bool xmrig::JsonReader::isEmpty() const { return Json::isEmpty(m_obj); diff --git a/src/base/io/json/Json.h b/src/base/io/json/Json.h index 15f340a76..7ceae5dd3 100644 --- a/src/base/io/json/Json.h +++ b/src/base/io/json/Json.h @@ -28,6 +28,9 @@ #include "base/kernel/interfaces/IJsonReader.h" #include "rapidjson/fwd.h" +#include +#include +#include namespace xmrig { @@ -50,7 +53,12 @@ public: static bool get(const char *fileName, rapidjson::Document &doc); static bool save(const char *fileName, const rapidjson::Document &doc); + static bool convertOffset(const char *fileName, size_t offset, size_t &line, size_t &pos, std::vector& s); + static rapidjson::Value normalize(double value, bool zero); + +private: + static bool convertOffset(std::ifstream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s); }; diff --git a/src/base/io/json/JsonChain.cpp b/src/base/io/json/JsonChain.cpp index bbaabbde9..48f04be7d 100644 --- a/src/base/io/json/JsonChain.cpp +++ b/src/base/io/json/JsonChain.cpp @@ -64,7 +64,27 @@ bool xmrig::JsonChain::addFile(const char *fileName) } if (doc.HasParseError()) { - LOG_ERR("%s: \"%s\"", fileName, doc.GetErrorOffset(), GetParseError_En(doc.GetParseError())); + const size_t offset = doc.GetErrorOffset(); + + size_t line, pos; + std::vector s; + if (Json::convertOffset(fileName, offset, line, pos, s)) { + for (const auto& t : s) { + LOG_ERR("%s", t.c_str()); + } + + std::string t; + if (pos > 0) { + t.assign(pos - 1, ' '); + } + t += '^'; + LOG_ERR("%s", t.c_str()); + + LOG_ERR("%s: \"%s\"", fileName, line, pos, GetParseError_En(doc.GetParseError())); + } + else { + LOG_ERR("%s: \"%s\"", fileName, offset, GetParseError_En(doc.GetParseError())); + } } else { LOG_ERR("unable to open \"%s\".", fileName); diff --git a/src/base/io/json/Json_unix.cpp b/src/base/io/json/Json_unix.cpp index dedea947d..f31e1bd0c 100644 --- a/src/base/io/json/Json_unix.cpp +++ b/src/base/io/json/Json_unix.cpp @@ -62,3 +62,14 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc) return true; } + + +bool xmrig::Json::convertOffset(const char* fileName, size_t offset, size_t& line, size_t& pos, std::vector& s) +{ + std::ifstream ifs(fileName, std::ios_base::in | std::ios_base::binary); + if (!ifs.is_open()) { + return false; + } + + return convertOffset(ifs, offset, line, pos, s); +} diff --git a/src/base/io/json/Json_win.cpp b/src/base/io/json/Json_win.cpp index cb6f02f64..693594832 100644 --- a/src/base/io/json/Json_win.cpp +++ b/src/base/io/json/Json_win.cpp @@ -125,3 +125,31 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc) return true; } + + +bool xmrig::Json::convertOffset(const char* fileName, size_t offset, size_t& line, size_t& pos, std::vector& s) +{ + constexpr const std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary; + +# if defined(_MSC_VER) + std::ifstream ifs(toUtf16(fileName), mode); + if (!ifs.is_open()) { + return false; + } +# elif defined(__GNUC__) + const int fd = _wopen(toUtf16(fileName).c_str(), _O_RDONLY | _O_BINARY); + if (fd == -1) { + return false; + } + + __gnu_cxx::stdio_filebuf buf(fd, mode); + std::istream ifs(&buf); +# else + std::ifstream ifs(fileName, mode); + if (!ifs.is_open()) { + return false; + } +# endif + + return convertOffset(ifs, offset, line, pos, s); +} From d33c91684d3646f1fbae584f7f78d91f80a5b594 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 29 Apr 2020 16:29:30 +0700 Subject: [PATCH 05/24] Fixed MSYS build. --- src/base/io/json/Json.cpp | 2 +- src/base/io/json/Json.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/io/json/Json.cpp b/src/base/io/json/Json.cpp index 48016665a..fb4c0e470 100644 --- a/src/base/io/json/Json.cpp +++ b/src/base/io/json/Json.cpp @@ -191,7 +191,7 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero) } -bool xmrig::Json::convertOffset(std::ifstream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s) +bool xmrig::Json::convertOffset(std::istream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s) { std::string prev_t; std::string t; diff --git a/src/base/io/json/Json.h b/src/base/io/json/Json.h index 7ceae5dd3..e6b772a17 100644 --- a/src/base/io/json/Json.h +++ b/src/base/io/json/Json.h @@ -58,7 +58,7 @@ public: static rapidjson::Value normalize(double value, bool zero); private: - static bool convertOffset(std::ifstream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s); + static bool convertOffset(std::istream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s); }; From 781f08a034d05096982919c9f3bb2f2ec36fcd60 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 29 Apr 2020 17:40:51 +0700 Subject: [PATCH 06/24] Remove code duplication. --- src/base/io/json/Json.cpp | 2 +- src/base/io/json/Json.h | 5 +-- src/base/io/json/Json_win.cpp | 76 +++++++++++++++-------------------- 3 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/base/io/json/Json.cpp b/src/base/io/json/Json.cpp index fb4c0e470..b239777b3 100644 --- a/src/base/io/json/Json.cpp +++ b/src/base/io/json/Json.cpp @@ -191,7 +191,7 @@ rapidjson::Value xmrig::Json::normalize(double value, bool zero) } -bool xmrig::Json::convertOffset(std::istream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s) +bool xmrig::Json::convertOffset(std::istream &ifs, size_t offset, size_t &line, size_t &pos, std::vector &s) { std::string prev_t; std::string t; diff --git a/src/base/io/json/Json.h b/src/base/io/json/Json.h index e6b772a17..10e6e696f 100644 --- a/src/base/io/json/Json.h +++ b/src/base/io/json/Json.h @@ -53,12 +53,11 @@ public: static bool get(const char *fileName, rapidjson::Document &doc); static bool save(const char *fileName, const rapidjson::Document &doc); - static bool convertOffset(const char *fileName, size_t offset, size_t &line, size_t &pos, std::vector& s); - + static bool convertOffset(const char *fileName, size_t offset, size_t &line, size_t &pos, std::vector &s); static rapidjson::Value normalize(double value, bool zero); private: - static bool convertOffset(std::istream& ifs, size_t offset, size_t& line, size_t& pos, std::vector& s); + static bool convertOffset(std::istream &ifs, size_t offset, size_t &line, size_t &pos, std::vector &s); }; diff --git a/src/base/io/json/Json_win.cpp b/src/base/io/json/Json_win.cpp index 693594832..a9c4065a3 100644 --- a/src/base/io/json/Json_win.cpp +++ b/src/base/io/json/Json_win.cpp @@ -43,6 +43,9 @@ #include "rapidjson/prettywriter.h" +namespace xmrig { + + #if defined(_MSC_VER) || defined (__GNUC__) static std::wstring toUtf16(const char *str) { @@ -60,31 +63,36 @@ static std::wstring toUtf16(const char *str) #endif +#if defined(_MSC_VER) +# define OPEN_IFS(name) \ + std::ifstream ifs(toUtf16(name), std::ios_base::in | std::ios_base::binary); \ + if (!ifs.is_open()) { \ + return false; \ + } +#elif defined(__GNUC__) +# define OPEN_IFS(name) \ + const int fd = _wopen(toUtf16(name).c_str(), _O_RDONLY | _O_BINARY); \ + if (fd == -1) { \ + return false; \ + } \ + __gnu_cxx::stdio_filebuf buf(fd, std::ios_base::in | std::ios_base::binary); \ + std::istream ifs(&buf); +#else +# define OPEN_IFS(name) \ + std::ifstream ifs(name, std::ios_base::in | std::ios_base::binary); \ + if (!ifs.is_open()) { \ + return false; \ + } +#endif + +} // namespace xmrig + + bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc) { + OPEN_IFS(fileName) + using namespace rapidjson; - constexpr const std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary; - -# if defined(_MSC_VER) - std::ifstream ifs(toUtf16(fileName), mode); - if (!ifs.is_open()) { - return false; - } -# elif defined(__GNUC__) - const int fd = _wopen(toUtf16(fileName).c_str(), _O_RDONLY | _O_BINARY); - if (fd == -1) { - return false; - } - - __gnu_cxx::stdio_filebuf buf(fd, mode); - std::istream ifs(&buf); -# else - std::ifstream ifs(fileName, mode); - if (!ifs.is_open()) { - return false; - } -# endif - IStreamWrapper isw(ifs); doc.ParseStream(isw); @@ -127,29 +135,9 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc) } -bool xmrig::Json::convertOffset(const char* fileName, size_t offset, size_t& line, size_t& pos, std::vector& s) +bool xmrig::Json::convertOffset(const char *fileName, size_t offset, size_t &line, size_t &pos, std::vector &s) { - constexpr const std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary; - -# if defined(_MSC_VER) - std::ifstream ifs(toUtf16(fileName), mode); - if (!ifs.is_open()) { - return false; - } -# elif defined(__GNUC__) - const int fd = _wopen(toUtf16(fileName).c_str(), _O_RDONLY | _O_BINARY); - if (fd == -1) { - return false; - } - - __gnu_cxx::stdio_filebuf buf(fd, mode); - std::istream ifs(&buf); -# else - std::ifstream ifs(fileName, mode); - if (!ifs.is_open()) { - return false; - } -# endif + OPEN_IFS(fileName) return convertOffset(ifs, offset, line, pos, s); } From c18478a6b4ab7ea2d2365830b5dde7aa427b934c Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 3 May 2020 13:38:34 +0700 Subject: [PATCH 07/24] Small cleanups. --- src/crypto/randomx/blake2/blake2b.c | 6 +++--- src/crypto/randomx/jit_compiler_x86.cpp | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/crypto/randomx/blake2/blake2b.c b/src/crypto/randomx/blake2/blake2b.c index 24305c3c0..29a402d8a 100644 --- a/src/crypto/randomx/blake2/blake2b.c +++ b/src/crypto/randomx/blake2/blake2b.c @@ -87,7 +87,7 @@ static FORCE_INLINE void blake2b_init0(blake2b_state *S) { memcpy(S->h, blake2b_IV, sizeof(S->h)); } -int blake2b_init_param(blake2b_state *S, const blake2b_param *P) { +int rx_blake2b_init_param(blake2b_state *S, const blake2b_param *P) { const unsigned char *p = (const unsigned char *)P; unsigned int i; @@ -130,7 +130,7 @@ int rx_blake2b_init(blake2b_state *S, size_t outlen) { memset(P.salt, 0, sizeof(P.salt)); memset(P.personal, 0, sizeof(P.personal)); - return blake2b_init_param(S, &P); + return rx_blake2b_init_param(S, &P); } int rx_blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, size_t keylen) { @@ -163,7 +163,7 @@ int rx_blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, size_t memset(P.salt, 0, sizeof(P.salt)); memset(P.personal, 0, sizeof(P.personal)); - if (blake2b_init_param(S, &P) < 0) { + if (rx_blake2b_init_param(S, &P) < 0) { blake2b_invalidate_state(S); return -1; } diff --git a/src/crypto/randomx/jit_compiler_x86.cpp b/src/crypto/randomx/jit_compiler_x86.cpp index 095f4d3c9..178d35a5c 100644 --- a/src/crypto/randomx/jit_compiler_x86.cpp +++ b/src/crypto/randomx/jit_compiler_x86.cpp @@ -36,7 +36,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "crypto/randomx/program.hpp" #include "crypto/randomx/reciprocal.h" #include "crypto/randomx/virtual_memory.hpp" -#include "crypto/rx/Rx.h" + +#ifdef XMRIG_FIX_RYZEN +# include "crypto/rx/Rx.h" +#endif #ifdef _MSC_VER # include From 80d944bf82ce0398a441d7e0f06a0ed023e1393a Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 3 May 2020 20:44:59 +0200 Subject: [PATCH 08/24] Optimized RandomX dataset initialization - Use single Argon2 implemenation - Auto-select the fastest Argon2 implementation for RandomX --- cmake/randomx.cmake | 2 - src/3rdparty/argon2/lib/core.c | 14 +- src/backend/cpu/CpuBackend.cpp | 27 +- src/crypto/randomx/argon2.h | 229 -------------- src/crypto/randomx/argon2_core.c | 502 ------------------------------- src/crypto/randomx/argon2_core.h | 254 ---------------- src/crypto/randomx/argon2_ref.c | 214 ------------- src/crypto/randomx/dataset.cpp | 35 +-- 8 files changed, 33 insertions(+), 1244 deletions(-) delete mode 100644 src/crypto/randomx/argon2.h delete mode 100644 src/crypto/randomx/argon2_core.c delete mode 100644 src/crypto/randomx/argon2_core.h delete mode 100644 src/crypto/randomx/argon2_ref.c diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 831807101..85e18fe39 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -16,8 +16,6 @@ if (WITH_RANDOMX) list(APPEND SOURCES_CRYPTO src/crypto/randomx/aes_hash.cpp src/crypto/randomx/allocator.cpp - src/crypto/randomx/argon2_core.c - src/crypto/randomx/argon2_ref.c src/crypto/randomx/blake2_generator.cpp src/crypto/randomx/blake2/blake2b.c src/crypto/randomx/bytecode_machine.cpp diff --git a/src/3rdparty/argon2/lib/core.c b/src/3rdparty/argon2/lib/core.c index 5d130c04a..e3ec883b9 100644 --- a/src/3rdparty/argon2/lib/core.c +++ b/src/3rdparty/argon2/lib/core.c @@ -147,7 +147,7 @@ void clear_internal_memory(void *v, size_t n) { } void finalize(const argon2_context *context, argon2_instance_t *instance) { - if (context != NULL && instance != NULL) { + if (context != NULL && instance != NULL && context->out != NULL) { block blockhash; uint32_t l; @@ -281,14 +281,14 @@ int validate_inputs(const argon2_context *context) { return ARGON2_INCORRECT_PARAMETER; } - if (NULL == context->out) { - return ARGON2_OUTPUT_PTR_NULL; - } + //if (NULL == context->out) { + // return ARGON2_OUTPUT_PTR_NULL; + //} /* Validate output length */ - if (ARGON2_MIN_OUTLEN > context->outlen) { - return ARGON2_OUTPUT_TOO_SHORT; - } + //if (ARGON2_MIN_OUTLEN > context->outlen) { + // return ARGON2_OUTPUT_TOO_SHORT; + //} if (ARGON2_MAX_OUTLEN < context->outlen) { return ARGON2_OUTPUT_TOO_LONG; diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 40b774d25..bd8e0ad11 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -275,12 +275,27 @@ const xmrig::String &xmrig::CpuBackend::type() const void xmrig::CpuBackend::prepare(const Job &nextJob) { # ifdef XMRIG_ALGO_ARGON2 - if (nextJob.algorithm().family() == Algorithm::ARGON2 && argon2::Impl::select(d_ptr->controller->config()->cpu().argon2Impl())) { - LOG_INFO("%s use " WHITE_BOLD("argon2") " implementation " CSI "1;%dm" "%s", - tag, - argon2::Impl::name() == "default" ? 33 : 32, - argon2::Impl::name().data() - ); + const xmrig::Algorithm::Family f = nextJob.algorithm().family(); + if ((f == Algorithm::ARGON2) || (f == Algorithm::RANDOM_X)) { + + xmrig::String impl = d_ptr->controller->config()->cpu().argon2Impl(); + + if (impl.isEmpty()) { + if (xmrig::Cpu::info()->hasAVX2()) { + impl = "AVX2"; + } + else if (xmrig::Cpu::info()->isX64()) { + impl = "SSE2"; + } + } + + if (argon2::Impl::select(impl)) { + LOG_INFO("%s use " WHITE_BOLD("argon2") " implementation " CSI "1;%dm" "%s", + tag, + argon2::Impl::name() == "default" ? 33 : 32, + argon2::Impl::name().data() + ); + } } # endif } diff --git a/src/crypto/randomx/argon2.h b/src/crypto/randomx/argon2.h deleted file mode 100644 index 9d4271595..000000000 --- a/src/crypto/randomx/argon2.h +++ /dev/null @@ -1,229 +0,0 @@ -/* -Copyright (c) 2018-2019, tevador - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/* Original code from Argon2 reference source code package used under CC0 Licence - * https://github.com/P-H-C/phc-winner-argon2 - * Copyright 2015 - * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves -*/ - -#pragma once - -#include -#include -#include - -/* - * Argon2 input parameter restrictions - */ - - /* Minimum and maximum number of lanes (degree of parallelism) */ -#define ARGON2_MIN_LANES UINT32_C(1) -#define ARGON2_MAX_LANES UINT32_C(0xFFFFFF) - -/* Minimum and maximum number of threads */ -#define ARGON2_MIN_THREADS UINT32_C(1) -#define ARGON2_MAX_THREADS UINT32_C(0xFFFFFF) - -/* Number of synchronization points between lanes per pass */ -#define ARGON2_SYNC_POINTS UINT32_C(4) - -/* Minimum and maximum digest size in bytes */ -#define ARGON2_MIN_OUTLEN UINT32_C(4) -#define ARGON2_MAX_OUTLEN UINT32_C(0xFFFFFFFF) - -/* Minimum and maximum number of memory blocks (each of BLOCK_SIZE bytes) */ -#define ARGON2_MIN_MEMORY (2 * ARGON2_SYNC_POINTS) /* 2 blocks per slice */ - -#define ARGON2_MIN(a, b) ((a) < (b) ? (a) : (b)) -/* Max memory size is addressing-space/2, topping at 2^32 blocks (4 TB) */ -#define ARGON2_MAX_MEMORY_BITS \ - ARGON2_MIN(UINT32_C(32), (sizeof(void *) * CHAR_BIT - 10 - 1)) -#define ARGON2_MAX_MEMORY \ - ARGON2_MIN(UINT32_C(0xFFFFFFFF), UINT64_C(1) << ARGON2_MAX_MEMORY_BITS) - -/* Minimum and maximum number of passes */ -#define ARGON2_MIN_TIME UINT32_C(1) -#define ARGON2_MAX_TIME UINT32_C(0xFFFFFFFF) - -/* Minimum and maximum password length in bytes */ -#define ARGON2_MIN_PWD_LENGTH UINT32_C(0) -#define ARGON2_MAX_PWD_LENGTH UINT32_C(0xFFFFFFFF) - -/* Minimum and maximum associated data length in bytes */ -#define ARGON2_MIN_AD_LENGTH UINT32_C(0) -#define ARGON2_MAX_AD_LENGTH UINT32_C(0xFFFFFFFF) - -/* Minimum and maximum salt length in bytes */ -#define ARGON2_MIN_SALT_LENGTH UINT32_C(8) -#define ARGON2_MAX_SALT_LENGTH UINT32_C(0xFFFFFFFF) - -/* Minimum and maximum key length in bytes */ -#define ARGON2_MIN_SECRET UINT32_C(0) -#define ARGON2_MAX_SECRET UINT32_C(0xFFFFFFFF) - -/* Flags to determine which fields are securely wiped (default = no wipe). */ -#define ARGON2_DEFAULT_FLAGS UINT32_C(0) -#define ARGON2_FLAG_CLEAR_PASSWORD (UINT32_C(1) << 0) -#define ARGON2_FLAG_CLEAR_SECRET (UINT32_C(1) << 1) - - -/* Error codes */ -typedef enum Argon2_ErrorCodes { - ARGON2_OK = 0, - - ARGON2_OUTPUT_PTR_NULL = -1, - - ARGON2_OUTPUT_TOO_SHORT = -2, - ARGON2_OUTPUT_TOO_LONG = -3, - - ARGON2_PWD_TOO_SHORT = -4, - ARGON2_PWD_TOO_LONG = -5, - - ARGON2_SALT_TOO_SHORT = -6, - ARGON2_SALT_TOO_LONG = -7, - - ARGON2_AD_TOO_SHORT = -8, - ARGON2_AD_TOO_LONG = -9, - - ARGON2_SECRET_TOO_SHORT = -10, - ARGON2_SECRET_TOO_LONG = -11, - - ARGON2_TIME_TOO_SMALL = -12, - ARGON2_TIME_TOO_LARGE = -13, - - ARGON2_MEMORY_TOO_LITTLE = -14, - ARGON2_MEMORY_TOO_MUCH = -15, - - ARGON2_LANES_TOO_FEW = -16, - ARGON2_LANES_TOO_MANY = -17, - - ARGON2_PWD_PTR_MISMATCH = -18, /* NULL ptr with non-zero length */ - ARGON2_SALT_PTR_MISMATCH = -19, /* NULL ptr with non-zero length */ - ARGON2_SECRET_PTR_MISMATCH = -20, /* NULL ptr with non-zero length */ - ARGON2_AD_PTR_MISMATCH = -21, /* NULL ptr with non-zero length */ - - ARGON2_MEMORY_ALLOCATION_ERROR = -22, - - ARGON2_FREE_MEMORY_CBK_NULL = -23, - ARGON2_ALLOCATE_MEMORY_CBK_NULL = -24, - - ARGON2_INCORRECT_PARAMETER = -25, - ARGON2_INCORRECT_TYPE = -26, - - ARGON2_OUT_PTR_MISMATCH = -27, - - ARGON2_THREADS_TOO_FEW = -28, - ARGON2_THREADS_TOO_MANY = -29, - - ARGON2_MISSING_ARGS = -30, - - ARGON2_ENCODING_FAIL = -31, - - ARGON2_DECODING_FAIL = -32, - - ARGON2_THREAD_FAIL = -33, - - ARGON2_DECODING_LENGTH_FAIL = -34, - - ARGON2_VERIFY_MISMATCH = -35 -} argon2_error_codes; - -/* Memory allocator types --- for external allocation */ -typedef int(*allocate_fptr)(uint8_t **memory, size_t bytes_to_allocate); -typedef void(*deallocate_fptr)(uint8_t *memory, size_t bytes_to_allocate); - -/* Argon2 external data structures */ - -/* - ***** - * Context: structure to hold Argon2 inputs: - * output array and its length, - * password and its length, - * salt and its length, - * secret and its length, - * associated data and its length, - * number of passes, amount of used memory (in KBytes, can be rounded up a bit) - * number of parallel threads that will be run. - * All the parameters above affect the output hash value. - * Additionally, two function pointers can be provided to allocate and - * deallocate the memory (if NULL, memory will be allocated internally). - * Also, three flags indicate whether to erase password, secret as soon as they - * are pre-hashed (and thus not needed anymore), and the entire memory - ***** - * Simplest situation: you have output array out[8], password is stored in - * pwd[32], salt is stored in salt[16], you do not have keys nor associated - * data. You need to spend 1 GB of RAM and you run 5 passes of Argon2d with - * 4 parallel lanes. - * You want to erase the password, but you're OK with last pass not being - * erased. You want to use the default memory allocator. - * Then you initialize: - Argon2_Context(out,8,pwd,32,salt,16,NULL,0,NULL,0,5,1<<20,4,4,NULL,NULL,true,false,false,false) - */ -typedef struct Argon2_Context { - uint8_t *out; /* output array */ - uint32_t outlen; /* digest length */ - - uint8_t *pwd; /* password array */ - uint32_t pwdlen; /* password length */ - - uint8_t *salt; /* salt array */ - uint32_t saltlen; /* salt length */ - - uint8_t *secret; /* key array */ - uint32_t secretlen; /* key length */ - - uint8_t *ad; /* associated data array */ - uint32_t adlen; /* associated data length */ - - uint32_t t_cost; /* number of passes */ - uint32_t m_cost; /* amount of memory requested (KB) */ - uint32_t lanes; /* number of lanes */ - uint32_t threads; /* maximum number of threads */ - - uint32_t version; /* version number */ - - allocate_fptr allocate_cbk; /* pointer to memory allocator */ - deallocate_fptr free_cbk; /* pointer to memory deallocator */ - - uint32_t flags; /* array of bool options */ -} argon2_context; - -/* Argon2 primitive type */ -typedef enum Argon2_type { - Argon2_d = 0, - Argon2_i = 1, - Argon2_id = 2 -} argon2_type; - -/* Version of the algorithm */ -typedef enum Argon2_version { - ARGON2_VERSION_10 = 0x10, - ARGON2_VERSION_13 = 0x13, - ARGON2_VERSION_NUMBER = ARGON2_VERSION_13 -} argon2_version; diff --git a/src/crypto/randomx/argon2_core.c b/src/crypto/randomx/argon2_core.c deleted file mode 100644 index 971766082..000000000 --- a/src/crypto/randomx/argon2_core.c +++ /dev/null @@ -1,502 +0,0 @@ -/* -Copyright (c) 2018-2019, tevador - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/* Original code from Argon2 reference source code package used under CC0 Licence - * https://github.com/P-H-C/phc-winner-argon2 - * Copyright 2015 - * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves -*/ - - /*For memory wiping*/ -#ifdef _MSC_VER -#include -#include /* For SecureZeroMemory */ -#endif -#if defined __STDC_LIB_EXT1__ -#define __STDC_WANT_LIB_EXT1__ 1 -#endif -#define VC_GE_2005(version) (version >= 1400) - -#include -#include -#include - -#include "crypto/randomx/argon2_core.h" -#include "crypto/randomx/blake2/blake2.h" -#include "crypto/randomx/blake2/blake2-impl.h" - -#ifdef GENKAT -#include "genkat.h" -#endif - -#if defined(__clang__) -#if __has_attribute(optnone) -#define NOT_OPTIMIZED __attribute__((optnone)) -#endif -#elif defined(__GNUC__) -#define GCC_VERSION \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#if GCC_VERSION >= 40400 -#define NOT_OPTIMIZED __attribute__((optimize("O0"))) -#endif -#endif -#ifndef NOT_OPTIMIZED -#define NOT_OPTIMIZED -#endif - -/***************Instance and Position constructors**********/ -void rxa2_init_block_value(block *b, uint8_t in) { memset(b->v, in, sizeof(b->v)); } - -void rxa2_copy_block(block *dst, const block *src) { - memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK); -} - -void rxa2_xor_block(block *dst, const block *src) { - int i; - for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) { - dst->v[i] ^= src->v[i]; - } -} - -static void load_block(block *dst, const void *input) { - unsigned i; - for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) { - dst->v[i] = load64((const uint8_t *)input + i * sizeof(dst->v[i])); - } -} - -//static void store_block(void *output, const block *src) { -// unsigned i; -// for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) { -// store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]); -// } -//} - -/***************Memory functions*****************/ - -int rxa2_allocate_memory(const argon2_context *context, uint8_t **memory, - size_t num, size_t size) { - size_t memory_size = num * size; - if (memory == NULL) { - return ARGON2_MEMORY_ALLOCATION_ERROR; - } - - /* 1. Check for multiplication overflow */ - if (size != 0 && memory_size / size != num) { - return ARGON2_MEMORY_ALLOCATION_ERROR; - } - - /* 2. Try to allocate with appropriate allocator */ - if (context->allocate_cbk) { - (context->allocate_cbk)(memory, memory_size); - } - else { - *memory = (uint8_t*)malloc(memory_size); - } - - if (*memory == NULL) { - return ARGON2_MEMORY_ALLOCATION_ERROR; - } - - return ARGON2_OK; -} - -void rxa2_free_memory(const argon2_context *context, uint8_t *memory, - size_t num, size_t size) { - size_t memory_size = num * size; - rxa2_clear_internal_memory(memory, memory_size); - if (context->free_cbk) { - (context->free_cbk)(memory, memory_size); - } - else { - free(memory); - } -} - -void NOT_OPTIMIZED rxa2_secure_wipe_memory(void *v, size_t n) { -#if defined(_MSC_VER) && VC_GE_2005(_MSC_VER) - SecureZeroMemory(v, n); -#elif defined memset_s - memset_s(v, n, 0, n); -#elif defined(__OpenBSD__) - explicit_bzero(v, n); -#else - static void *(*const volatile memset_sec)(void *, int, size_t) = &memset; - memset_sec(v, 0, n); -#endif -} - -/* Memory clear flag defaults to true. */ -#define FLAG_clear_internal_memory 0 -void rxa2_clear_internal_memory(void *v, size_t n) { - if (FLAG_clear_internal_memory && v) { - rxa2_secure_wipe_memory(v, n); - } -} - -uint32_t rxa2_index_alpha(const argon2_instance_t *instance, - const argon2_position_t *position, uint32_t pseudo_rand, - int same_lane) { - /* - * Pass 0: - * This lane : all already finished segments plus already constructed - * blocks in this segment - * Other lanes : all already finished segments - * Pass 1+: - * This lane : (SYNC_POINTS - 1) last segments plus already constructed - * blocks in this segment - * Other lanes : (SYNC_POINTS - 1) last segments - */ - uint32_t reference_area_size; - uint64_t relative_position; - uint32_t start_position, absolute_position; - - if (0 == position->pass) { - /* First pass */ - if (0 == position->slice) { - /* First slice */ - reference_area_size = - position->index - 1; /* all but the previous */ - } - else { - if (same_lane) { - /* The same lane => add current segment */ - reference_area_size = - position->slice * instance->segment_length + - position->index - 1; - } - else { - reference_area_size = - position->slice * instance->segment_length + - ((position->index == 0) ? (-1) : 0); - } - } - } - else { - /* Second pass */ - if (same_lane) { - reference_area_size = instance->lane_length - - instance->segment_length + position->index - - 1; - } - else { - reference_area_size = instance->lane_length - - instance->segment_length + - ((position->index == 0) ? (-1) : 0); - } - } - - /* 1.2.4. Mapping pseudo_rand to 0.. and produce - * relative position */ - relative_position = pseudo_rand; - relative_position = relative_position * relative_position >> 32; - relative_position = reference_area_size - 1 - - (reference_area_size * relative_position >> 32); - - /* 1.2.5 Computing starting position */ - start_position = 0; - - if (0 != position->pass) { - start_position = (position->slice == ARGON2_SYNC_POINTS - 1) - ? 0 - : (position->slice + 1) * instance->segment_length; - } - - /* 1.2.6. Computing absolute position */ - absolute_position = (start_position + relative_position) % - instance->lane_length; /* absolute position */ - return absolute_position; -} - -/* Single-threaded version for p=1 case */ -static int fill_memory_blocks_st(argon2_instance_t *instance) { - uint32_t r, s, l; - - for (r = 0; r < instance->passes; ++r) { - for (s = 0; s < ARGON2_SYNC_POINTS; ++s) { - for (l = 0; l < instance->lanes; ++l) { - argon2_position_t position = { r, l, (uint8_t)s, 0 }; - rxa2_fill_segment(instance, position); - } - } -#ifdef GENKAT - internal_kat(instance, r); /* Print all memory blocks */ -#endif - } - return ARGON2_OK; -} - -int rxa2_fill_memory_blocks(argon2_instance_t *instance) { - if (instance == NULL || instance->lanes == 0) { - return ARGON2_INCORRECT_PARAMETER; - } - return fill_memory_blocks_st(instance); -} - -int rxa2_validate_inputs(const argon2_context *context) { - if (NULL == context) { - return ARGON2_INCORRECT_PARAMETER; - } - - /* Validate password (required param) */ - if (NULL == context->pwd) { - if (0 != context->pwdlen) { - return ARGON2_PWD_PTR_MISMATCH; - } - } - - if (ARGON2_MIN_PWD_LENGTH > context->pwdlen) { - return ARGON2_PWD_TOO_SHORT; - } - - if (ARGON2_MAX_PWD_LENGTH < context->pwdlen) { - return ARGON2_PWD_TOO_LONG; - } - - /* Validate salt (required param) */ - if (NULL == context->salt) { - if (0 != context->saltlen) { - return ARGON2_SALT_PTR_MISMATCH; - } - } - - if (ARGON2_MIN_SALT_LENGTH > context->saltlen) { - return ARGON2_SALT_TOO_SHORT; - } - - if (ARGON2_MAX_SALT_LENGTH < context->saltlen) { - return ARGON2_SALT_TOO_LONG; - } - - /* Validate secret (optional param) */ - if (NULL == context->secret) { - if (0 != context->secretlen) { - return ARGON2_SECRET_PTR_MISMATCH; - } - } - else { - if (ARGON2_MIN_SECRET > context->secretlen) { - return ARGON2_SECRET_TOO_SHORT; - } - if (ARGON2_MAX_SECRET < context->secretlen) { - return ARGON2_SECRET_TOO_LONG; - } - } - - /* Validate associated data (optional param) */ - if (NULL == context->ad) { - if (0 != context->adlen) { - return ARGON2_AD_PTR_MISMATCH; - } - } - else { - if (ARGON2_MIN_AD_LENGTH > context->adlen) { - return ARGON2_AD_TOO_SHORT; - } - if (ARGON2_MAX_AD_LENGTH < context->adlen) { - return ARGON2_AD_TOO_LONG; - } - } - - /* Validate memory cost */ - if (ARGON2_MIN_MEMORY > context->m_cost) { - return ARGON2_MEMORY_TOO_LITTLE; - } - - if (ARGON2_MAX_MEMORY < context->m_cost) { - return ARGON2_MEMORY_TOO_MUCH; - } - - if (context->m_cost < 8 * context->lanes) { - return ARGON2_MEMORY_TOO_LITTLE; - } - - /* Validate time cost */ - if (ARGON2_MIN_TIME > context->t_cost) { - return ARGON2_TIME_TOO_SMALL; - } - - if (ARGON2_MAX_TIME < context->t_cost) { - return ARGON2_TIME_TOO_LARGE; - } - - /* Validate lanes */ - if (ARGON2_MIN_LANES > context->lanes) { - return ARGON2_LANES_TOO_FEW; - } - - if (ARGON2_MAX_LANES < context->lanes) { - return ARGON2_LANES_TOO_MANY; - } - - /* Validate threads */ - if (ARGON2_MIN_THREADS > context->threads) { - return ARGON2_THREADS_TOO_FEW; - } - - if (ARGON2_MAX_THREADS < context->threads) { - return ARGON2_THREADS_TOO_MANY; - } - - if (NULL != context->allocate_cbk && NULL == context->free_cbk) { - return ARGON2_FREE_MEMORY_CBK_NULL; - } - - if (NULL == context->allocate_cbk && NULL != context->free_cbk) { - return ARGON2_ALLOCATE_MEMORY_CBK_NULL; - } - - return ARGON2_OK; -} - -void rxa2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { - uint32_t l; - /* Make the first and second block in each lane as G(H0||0||i) or - G(H0||1||i) */ - uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE]; - for (l = 0; l < instance->lanes; ++l) { - - store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0); - store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l); - rxa2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, - ARGON2_PREHASH_SEED_LENGTH); - load_block(&instance->memory[l * instance->lane_length + 0], - blockhash_bytes); - - store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1); - rxa2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, - ARGON2_PREHASH_SEED_LENGTH); - load_block(&instance->memory[l * instance->lane_length + 1], - blockhash_bytes); - } - rxa2_clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); -} - -void rxa2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) { - blake2b_state BlakeHash; - uint8_t value[sizeof(uint32_t)]; - - if (NULL == context || NULL == blockhash) { - return; - } - - rx_blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); - - store32(&value, context->lanes); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - store32(&value, context->outlen); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - store32(&value, context->m_cost); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - store32(&value, context->t_cost); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - store32(&value, context->version); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - store32(&value, (uint32_t)type); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - store32(&value, context->pwdlen); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - if (context->pwd != NULL) { - rx_blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, - context->pwdlen); - - if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) { - rxa2_secure_wipe_memory(context->pwd, context->pwdlen); - context->pwdlen = 0; - } - } - - store32(&value, context->saltlen); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - if (context->salt != NULL) { - rx_blake2b_update(&BlakeHash, (const uint8_t *)context->salt, context->saltlen); - } - - store32(&value, context->secretlen); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - if (context->secret != NULL) { - rx_blake2b_update(&BlakeHash, (const uint8_t *)context->secret, - context->secretlen); - - if (context->flags & ARGON2_FLAG_CLEAR_SECRET) { - rxa2_secure_wipe_memory(context->secret, context->secretlen); - context->secretlen = 0; - } - } - - store32(&value, context->adlen); - rx_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); - - if (context->ad != NULL) { - rx_blake2b_update(&BlakeHash, (const uint8_t *)context->ad, - context->adlen); - } - - rx_blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); -} - -int rxa2_argon_initialize(argon2_instance_t *instance, argon2_context *context) { - uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; - - if (instance == NULL || context == NULL) - return ARGON2_INCORRECT_PARAMETER; - instance->context_ptr = context; - - /* 1. Memory allocation */ - /*result = allocate_memory(context, (uint8_t **)&(instance->memory), instance->memory_blocks, sizeof(block)); - if (result != ARGON2_OK) { - return result; - }*/ - - /* 2. Initial hashing */ - /* H_0 + 8 extra bytes to produce the first blocks */ - /* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */ - /* Hashing all inputs */ - rxa2_initial_hash(blockhash, context, instance->type); - /* Zeroing 8 extra bytes */ - rxa2_clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, - ARGON2_PREHASH_SEED_LENGTH - - ARGON2_PREHASH_DIGEST_LENGTH); - - /* 3. Creating first blocks, we always have at least two blocks in a slice - */ - rxa2_fill_first_blocks(blockhash, instance); - /* Clearing the hash */ - rxa2_clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH); - - return ARGON2_OK; -} diff --git a/src/crypto/randomx/argon2_core.h b/src/crypto/randomx/argon2_core.h deleted file mode 100644 index 274a01c74..000000000 --- a/src/crypto/randomx/argon2_core.h +++ /dev/null @@ -1,254 +0,0 @@ -/* -Copyright (c) 2018-2019, tevador - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/* Original code from Argon2 reference source code package used under CC0 Licence - * https://github.com/P-H-C/phc-winner-argon2 - * Copyright 2015 - * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves -*/ - -#ifndef ARGON2_CORE_H -#define ARGON2_CORE_H - -#include -#include "crypto/randomx/argon2.h" - -#if defined(__cplusplus) -extern "C" { -#endif - -#define CONST_CAST(x) (x)(uintptr_t) - - /**********************Argon2 internal constants*******************************/ - -enum argon2_core_constants { - /* Memory block size in bytes */ - ARGON2_BLOCK_SIZE = 1024, - ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 8, - ARGON2_OWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 16, - ARGON2_HWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 32, - ARGON2_512BIT_WORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 64, - - /* Number of pseudo-random values generated by one call to Blake in Argon2i - to - generate reference block positions */ - ARGON2_ADDRESSES_IN_BLOCK = 128, - - /* Pre-hashing digest length and its extension*/ - ARGON2_PREHASH_DIGEST_LENGTH = 64, - ARGON2_PREHASH_SEED_LENGTH = 72 -}; - -/*************************Argon2 internal data types***********************/ - -/* - * Structure for the (1KB) memory block implemented as 128 64-bit words. - * Memory blocks can be copied, XORed. Internal words can be accessed by [] (no - * bounds checking). - */ -typedef struct block_ { uint64_t v[ARGON2_QWORDS_IN_BLOCK]; } block; - -/*****************Functions that work with the block******************/ - -/* Initialize each byte of the block with @in */ -void rxa2_init_block_value(block *b, uint8_t in); - -/* Copy block @src to block @dst */ -void rxa2_copy_block(block *dst, const block *src); - -/* XOR @src onto @dst bytewise */ -void rxa2_xor_block(block *dst, const block *src); - -/* - * Argon2 instance: memory pointer, number of passes, amount of memory, type, - * and derived values. - * Used to evaluate the number and location of blocks to construct in each - * thread - */ -typedef struct Argon2_instance_t { - block *memory; /* Memory pointer */ - uint32_t version; - uint32_t passes; /* Number of passes */ - uint32_t memory_blocks; /* Number of blocks in memory */ - uint32_t segment_length; - uint32_t lane_length; - uint32_t lanes; - uint32_t threads; - argon2_type type; - int print_internals; /* whether to print the memory blocks */ - argon2_context *context_ptr; /* points back to original context */ -} argon2_instance_t; - -/* - * Argon2 position: where we construct the block right now. Used to distribute - * work between threads. - */ -typedef struct Argon2_position_t { - uint32_t pass; - uint32_t lane; - uint8_t slice; - uint32_t index; -} argon2_position_t; - -/*Struct that holds the inputs for thread handling FillSegment*/ -typedef struct Argon2_thread_data { - argon2_instance_t *instance_ptr; - argon2_position_t pos; -} argon2_thread_data; - -/*************************Argon2 core functions********************************/ - -/* Allocates memory to the given pointer, uses the appropriate allocator as - * specified in the context. Total allocated memory is num*size. - * @param context argon2_context which specifies the allocator - * @param memory pointer to the pointer to the memory - * @param size the size in bytes for each element to be allocated - * @param num the number of elements to be allocated - * @return ARGON2_OK if @memory is a valid pointer and memory is allocated - */ -int rxa2_allocate_memory(const argon2_context *context, uint8_t **memory, - size_t num, size_t size); - -/* - * Frees memory at the given pointer, uses the appropriate deallocator as - * specified in the context. Also cleans the memory using clear_internal_memory. - * @param context argon2_context which specifies the deallocator - * @param memory pointer to buffer to be freed - * @param size the size in bytes for each element to be deallocated - * @param num the number of elements to be deallocated - */ -void rxa2_free_memory(const argon2_context *context, uint8_t *memory, - size_t num, size_t size); - -/* Function that securely cleans the memory. This ignores any flags set - * regarding clearing memory. Usually one just calls clear_internal_memory. - * @param mem Pointer to the memory - * @param s Memory size in bytes - */ -void rxa2_secure_wipe_memory(void *v, size_t n); - -/* Function that securely clears the memory if FLAG_clear_internal_memory is - * set. If the flag isn't set, this function does nothing. - * @param mem Pointer to the memory - * @param s Memory size in bytes - */ -void rxa2_clear_internal_memory(void *v, size_t n); - -/* - * Computes absolute position of reference block in the lane following a skewed - * distribution and using a pseudo-random value as input - * @param instance Pointer to the current instance - * @param position Pointer to the current position - * @param pseudo_rand 32-bit pseudo-random value used to determine the position - * @param same_lane Indicates if the block will be taken from the current lane. - * If so we can reference the current segment - * @pre All pointers must be valid - */ -uint32_t rxa2_index_alpha(const argon2_instance_t *instance, - const argon2_position_t *position, uint32_t pseudo_rand, - int same_lane); - -/* - * Function that validates all inputs against predefined restrictions and return - * an error code - * @param context Pointer to current Argon2 context - * @return ARGON2_OK if everything is all right, otherwise one of error codes - * (all defined in - */ -int rxa2_validate_inputs(const argon2_context *context); - -/* - * Hashes all the inputs into @a blockhash[PREHASH_DIGEST_LENGTH], clears - * password and secret if needed - * @param context Pointer to the Argon2 internal structure containing memory - * pointer, and parameters for time and space requirements. - * @param blockhash Buffer for pre-hashing digest - * @param type Argon2 type - * @pre @a blockhash must have at least @a PREHASH_DIGEST_LENGTH bytes - * allocated - */ -void rxa2_initial_hash(uint8_t *blockhash, argon2_context *context, - argon2_type type); - -/* - * Function creates first 2 blocks per lane - * @param instance Pointer to the current instance - * @param blockhash Pointer to the pre-hashing digest - * @pre blockhash must point to @a PREHASH_SEED_LENGTH allocated values - */ -void rxa2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); - -/* - * Function allocates memory, hashes the inputs with Blake, and creates first - * two blocks. Returns the pointer to the main memory with 2 blocks per lane - * initialized - * @param context Pointer to the Argon2 internal structure containing memory - * pointer, and parameters for time and space requirements. - * @param instance Current Argon2 instance - * @return Zero if successful, -1 if memory failed to allocate. @context->state - * will be modified if successful. - */ -int rxa2_argon_initialize(argon2_instance_t *instance, argon2_context *context); - -/* - * XORing the last block of each lane, hashing it, making the tag. Deallocates - * the memory. - * @param context Pointer to current Argon2 context (use only the out parameters - * from it) - * @param instance Pointer to current instance of Argon2 - * @pre instance->state must point to necessary amount of memory - * @pre context->out must point to outlen bytes of memory - * @pre if context->free_cbk is not NULL, it should point to a function that - * deallocates memory - */ -void rxa2_finalize(const argon2_context *context, argon2_instance_t *instance); - -/* - * Function that fills the segment using previous segments also from other - * threads - * @param context current context - * @param instance Pointer to the current instance - * @param position Current position - * @pre all block pointers must be valid - */ -void rxa2_fill_segment(const argon2_instance_t *instance, - argon2_position_t position); - -/* - * Function that fills the entire memory t_cost times based on the first two - * blocks in each lane - * @param instance Pointer to the current instance - * @return ARGON2_OK if successful, @context->state - */ -int rxa2_fill_memory_blocks(argon2_instance_t *instance); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/src/crypto/randomx/argon2_ref.c b/src/crypto/randomx/argon2_ref.c deleted file mode 100644 index 157eda862..000000000 --- a/src/crypto/randomx/argon2_ref.c +++ /dev/null @@ -1,214 +0,0 @@ -/* -Copyright (c) 2018-2019, tevador - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of the copyright holder nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/* Original code from Argon2 reference source code package used under CC0 Licence - * https://github.com/P-H-C/phc-winner-argon2 - * Copyright 2015 - * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves -*/ - -#include -#include -#include - -#include "crypto/randomx/argon2.h" -#include "crypto/randomx/argon2_core.h" - -#include "crypto/randomx/blake2/blamka-round-ref.h" -#include "crypto/randomx/blake2/blake2-impl.h" -#include "crypto/randomx/blake2/blake2.h" - - /* - * Function fills a new memory block and optionally XORs the old block over the new one. - * @next_block must be initialized. - * @param prev_block Pointer to the previous block - * @param ref_block Pointer to the reference block - * @param next_block Pointer to the block to be constructed - * @param with_xor Whether to XOR into the new block (1) or just overwrite (0) - * @pre all block pointers must be valid - */ -static void fill_block(const block *prev_block, const block *ref_block, - block *next_block, int with_xor) { - block blockR, block_tmp; - unsigned i; - - rxa2_copy_block(&blockR, ref_block); - rxa2_xor_block(&blockR, prev_block); - rxa2_copy_block(&block_tmp, &blockR); - /* Now blockR = ref_block + prev_block and block_tmp = ref_block + prev_block */ - if (with_xor) { - /* Saving the next block contents for XOR over: */ - rxa2_xor_block(&block_tmp, next_block); - /* Now blockR = ref_block + prev_block and - block_tmp = ref_block + prev_block + next_block */ - } - - /* Apply Blake2 on columns of 64-bit words: (0,1,...,15) , then - (16,17,..31)... finally (112,113,...127) */ - for (i = 0; i < 8; ++i) { - BLAKE2_ROUND_NOMSG( - blockR.v[16 * i], blockR.v[16 * i + 1], blockR.v[16 * i + 2], - blockR.v[16 * i + 3], blockR.v[16 * i + 4], blockR.v[16 * i + 5], - blockR.v[16 * i + 6], blockR.v[16 * i + 7], blockR.v[16 * i + 8], - blockR.v[16 * i + 9], blockR.v[16 * i + 10], blockR.v[16 * i + 11], - blockR.v[16 * i + 12], blockR.v[16 * i + 13], blockR.v[16 * i + 14], - blockR.v[16 * i + 15]); - } - - /* Apply Blake2 on rows of 64-bit words: (0,1,16,17,...112,113), then - (2,3,18,19,...,114,115).. finally (14,15,30,31,...,126,127) */ - for (i = 0; i < 8; i++) { - BLAKE2_ROUND_NOMSG( - blockR.v[2 * i], blockR.v[2 * i + 1], blockR.v[2 * i + 16], - blockR.v[2 * i + 17], blockR.v[2 * i + 32], blockR.v[2 * i + 33], - blockR.v[2 * i + 48], blockR.v[2 * i + 49], blockR.v[2 * i + 64], - blockR.v[2 * i + 65], blockR.v[2 * i + 80], blockR.v[2 * i + 81], - blockR.v[2 * i + 96], blockR.v[2 * i + 97], blockR.v[2 * i + 112], - blockR.v[2 * i + 113]); - } - - rxa2_copy_block(next_block, &block_tmp); - rxa2_xor_block(next_block, &blockR); -} - -static void next_addresses(block *address_block, block *input_block, - const block *zero_block) { - input_block->v[6]++; - fill_block(zero_block, input_block, address_block, 0); - fill_block(zero_block, address_block, address_block, 0); -} - -void rxa2_fill_segment(const argon2_instance_t *instance, - argon2_position_t position) { - block *ref_block = NULL, *curr_block = NULL; - block address_block, input_block, zero_block; - uint64_t pseudo_rand, ref_index, ref_lane; - uint32_t prev_offset, curr_offset; - uint32_t starting_index; - uint32_t i; - int data_independent_addressing; - - if (instance == NULL) { - return; - } - - data_independent_addressing = - (instance->type == Argon2_i) || - (instance->type == Argon2_id && (position.pass == 0) && - (position.slice < ARGON2_SYNC_POINTS / 2)); - - if (data_independent_addressing) { - rxa2_init_block_value(&zero_block, 0); - rxa2_init_block_value(&input_block, 0); - - input_block.v[0] = position.pass; - input_block.v[1] = position.lane; - input_block.v[2] = position.slice; - input_block.v[3] = instance->memory_blocks; - input_block.v[4] = instance->passes; - input_block.v[5] = instance->type; - } - - starting_index = 0; - - if ((0 == position.pass) && (0 == position.slice)) { - starting_index = 2; /* we have already generated the first two blocks */ - - /* Don't forget to generate the first block of addresses: */ - if (data_independent_addressing) { - next_addresses(&address_block, &input_block, &zero_block); - } - } - - /* Offset of the current block */ - curr_offset = position.lane * instance->lane_length + - position.slice * instance->segment_length + starting_index; - - if (0 == curr_offset % instance->lane_length) { - /* Last block in this lane */ - prev_offset = curr_offset + instance->lane_length - 1; - } - else { - /* Previous block */ - prev_offset = curr_offset - 1; - } - - for (i = starting_index; i < instance->segment_length; - ++i, ++curr_offset, ++prev_offset) { - /*1.1 Rotating prev_offset if needed */ - if (curr_offset % instance->lane_length == 1) { - prev_offset = curr_offset - 1; - } - - /* 1.2 Computing the index of the reference block */ - /* 1.2.1 Taking pseudo-random value from the previous block */ - if (data_independent_addressing) { - if (i % ARGON2_ADDRESSES_IN_BLOCK == 0) { - next_addresses(&address_block, &input_block, &zero_block); - } - pseudo_rand = address_block.v[i % ARGON2_ADDRESSES_IN_BLOCK]; - } - else { - pseudo_rand = instance->memory[prev_offset].v[0]; - } - - /* 1.2.2 Computing the lane of the reference block */ - ref_lane = ((pseudo_rand >> 32)) % instance->lanes; - - if ((position.pass == 0) && (position.slice == 0)) { - /* Can not reference other lanes yet */ - ref_lane = position.lane; - } - - /* 1.2.3 Computing the number of possible reference block within the - * lane. - */ - position.index = i; - ref_index = rxa2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); - - /* 2 Creating a new block */ - ref_block = - instance->memory + instance->lane_length * ref_lane + ref_index; - curr_block = instance->memory + curr_offset; - if (ARGON2_VERSION_10 == instance->version) { - /* version 1.2.1 and earlier: overwrite, not XOR */ - fill_block(instance->memory + prev_offset, ref_block, curr_block, 0); - } - else { - if (0 == position.pass) { - fill_block(instance->memory + prev_offset, ref_block, - curr_block, 0); - } - else { - fill_block(instance->memory + prev_offset, ref_block, - curr_block, 1); - } - } - } -} diff --git a/src/crypto/randomx/dataset.cpp b/src/crypto/randomx/dataset.cpp index 8aeafffd8..e80086a5f 100644 --- a/src/crypto/randomx/dataset.cpp +++ b/src/crypto/randomx/dataset.cpp @@ -46,13 +46,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "crypto/randomx/blake2_generator.hpp" #include "crypto/randomx/reciprocal.h" #include "crypto/randomx/blake2/endian.h" -#include "crypto/randomx/argon2.h" -#include "crypto/randomx/argon2_core.h" #include "crypto/randomx/jit_compiler.hpp" #include "crypto/randomx/intrin_portable.h" +#include "3rdparty/argon2/include/argon2.h" +#include "3rdparty/argon2/lib/core.h" + //static_assert(RANDOMX_ARGON_MEMORY % (RANDOMX_ARGON_LANES * ARGON2_SYNC_POINTS) == 0, "RANDOMX_ARGON_MEMORY - invalid value"); -static_assert(ARGON2_BLOCK_SIZE == randomx::ArgonBlockSize, "Unpexpected value of ARGON2_BLOCK_SIZE"); +static_assert(ARGON2_BLOCK_SIZE == randomx::ArgonBlockSize, "Unexpected value of ARGON2_BLOCK_SIZE"); namespace randomx { @@ -91,33 +92,7 @@ namespace randomx { context.flags = ARGON2_DEFAULT_FLAGS; context.version = ARGON2_VERSION_NUMBER; - /* 2. Align memory size */ - /* Minimum memory_blocks = 8L blocks, where L is the number of lanes */ - memory_blocks = context.m_cost; - - segment_length = memory_blocks / (context.lanes * ARGON2_SYNC_POINTS); - - instance.version = context.version; - instance.memory = NULL; - instance.passes = context.t_cost; - instance.memory_blocks = memory_blocks; - instance.segment_length = segment_length; - instance.lane_length = segment_length * ARGON2_SYNC_POINTS; - instance.lanes = context.lanes; - instance.threads = context.threads; - instance.type = Argon2_d; - instance.memory = (block*)cache->memory; - - if (instance.threads > instance.lanes) { - instance.threads = instance.lanes; - } - - /* 3. Initialization: Hashing inputs, allocating memory, filling first - * blocks - */ - rxa2_argon_initialize(&instance, &context); - - rxa2_fill_memory_blocks(&instance); + argon2_ctx_mem(&context, Argon2_d, cache->memory, RandomX_CurrentConfig.ArgonMemory * 1024); cache->reciprocalCache.clear(); randomx::Blake2Generator gen(key, keySize); From b34e3e1a7b4a4010be45ae4d937ed0d4547b481c Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 May 2020 02:07:38 +0700 Subject: [PATCH 09/24] Remove unused code. --- src/crypto/randomx/dataset.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/crypto/randomx/dataset.cpp b/src/crypto/randomx/dataset.cpp index e80086a5f..38dc9f4ef 100644 --- a/src/crypto/randomx/dataset.cpp +++ b/src/crypto/randomx/dataset.cpp @@ -69,8 +69,6 @@ namespace randomx { template void deallocCache(randomx_cache* cache); void initCache(randomx_cache* cache, const void* key, size_t keySize) { - uint32_t memory_blocks, segment_length; - argon2_instance_t instance; argon2_context context; context.out = nullptr; From 4326ba3c386db0efea19fbe441953b897865a86a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 May 2020 18:09:34 +0700 Subject: [PATCH 10/24] Add prefixes to argon2 to avoid potential conflicts with other implementations. --- .../argon2/arch/x86_64/lib/argon2-arch.c | 10 +- .../argon2/arch/x86_64/lib/argon2-avx2.c | 19 +--- .../argon2/arch/x86_64/lib/argon2-avx2.h | 6 +- .../argon2/arch/x86_64/lib/argon2-avx512f.c | 19 +--- .../argon2/arch/x86_64/lib/argon2-avx512f.h | 6 +- .../argon2/arch/x86_64/lib/argon2-sse2.c | 16 +-- .../argon2/arch/x86_64/lib/argon2-sse2.h | 6 +- .../argon2/arch/x86_64/lib/argon2-ssse3.c | 16 +-- .../argon2/arch/x86_64/lib/argon2-ssse3.h | 6 +- .../arch/x86_64/lib/argon2-template-128.h | 3 +- .../argon2/arch/x86_64/lib/argon2-xop.c | 16 +-- .../argon2/arch/x86_64/lib/argon2-xop.h | 6 +- src/3rdparty/argon2/lib/argon2-template-64.h | 3 +- src/3rdparty/argon2/lib/argon2.c | 16 +-- src/3rdparty/argon2/lib/blake2/blake2.c | 44 ++++---- src/3rdparty/argon2/lib/blake2/blake2.h | 8 +- src/3rdparty/argon2/lib/core.c | 105 ++++++++---------- src/3rdparty/argon2/lib/core.h | 30 ++--- src/3rdparty/argon2/lib/encoding.c | 4 +- src/3rdparty/argon2/lib/impl-select.c | 2 +- 20 files changed, 134 insertions(+), 207 deletions(-) diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c index 4486e3951..48d2a77e1 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c @@ -27,11 +27,11 @@ void argon2_get_impl_list(argon2_impl_list *list) { static const argon2_impl IMPLS[] = { { "x86_64", NULL, fill_segment_default }, - { "SSE2", check_sse2, fill_segment_sse2 }, - { "SSSE3", check_ssse3, fill_segment_ssse3 }, - { "XOP", check_xop, fill_segment_xop }, - { "AVX2", check_avx2, fill_segment_avx2 }, - { "AVX-512F", check_avx512f, fill_segment_avx512f }, + { "SSE2", xmrig_ar2_check_sse2, xmrig_ar2_fill_segment_sse2 }, + { "SSSE3", xmrig_ar2_check_ssse3, xmrig_ar2_fill_segment_ssse3 }, + { "XOP", xmrig_ar2_check_xop, xmrig_ar2_fill_segment_xop }, + { "AVX2", xmrig_ar2_check_avx2, xmrig_ar2_fill_segment_avx2 }, + { "AVX-512F", xmrig_ar2_check_avx512f, xmrig_ar2_fill_segment_avx512f }, }; cpu_flags_get(); diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c index 09ef421a6..976fd4711 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c @@ -225,8 +225,7 @@ static void next_addresses(block *address_block, block *input_block) fill_block(zero2_block, address_block, address_block, 0); } -void fill_segment_avx2(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_position_t position) { block *ref_block = NULL, *curr_block = NULL; block address_block, input_block; @@ -310,8 +309,7 @@ void fill_segment_avx2(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = @@ -327,21 +325,14 @@ void fill_segment_avx2(const argon2_instance_t *instance, } } -int check_avx2(void) +int xmrig_ar2_check_avx2(void) { return cpu_flags_have_avx2(); } #else -void fill_segment_avx2(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_avx2(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_avx2(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h index 8abdb8a53..2c34269af 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_avx2(const argon2_instance_t *instance, - argon2_position_t position); - -int check_avx2(void); +void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_avx2(void); #endif // ARGON2_AVX2_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c index 79fd2ddaf..994f35022 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c @@ -210,8 +210,7 @@ static void next_addresses(block *address_block, block *input_block) fill_block(zero2_block, address_block, address_block, 0); } -void fill_segment_avx512f(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_position_t position) { block *ref_block = NULL, *curr_block = NULL; block address_block, input_block; @@ -295,8 +294,7 @@ void fill_segment_avx512f(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = @@ -312,21 +310,14 @@ void fill_segment_avx512f(const argon2_instance_t *instance, } } -int check_avx512f(void) +int xmrig_ar2_check_avx512f(void) { return cpu_flags_have_avx512f(); } #else -void fill_segment_avx512f(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_avx512f(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_avx512f(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h index ba4311142..882bb7fd4 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_avx512f(const argon2_instance_t *instance, - argon2_position_t position); - -int check_avx512f(void); +void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_avx512f(void); #endif // ARGON2_AVX512F_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c index 5eccdf07e..1e992b54e 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c @@ -102,27 +102,19 @@ static __m128i f(__m128i x, __m128i y) #include "argon2-template-128.h" -void fill_segment_sse2(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_position_t position) { fill_segment_128(instance, position); } -int check_sse2(void) +int xmrig_ar2_check_sse2(void) { return cpu_flags_have_sse2(); } #else -void fill_segment_sse2(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_sse2(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_sse2(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h index 024d503d3..9f92fbc6a 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_sse2(const argon2_instance_t *instance, - argon2_position_t position); - -int check_sse2(void); +void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_sse2(void); #endif // ARGON2_SSE2_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c index 86e9b3c90..b848e3ebe 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c @@ -114,27 +114,19 @@ static __m128i f(__m128i x, __m128i y) #include "argon2-template-128.h" -void fill_segment_ssse3(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_position_t position) { fill_segment_128(instance, position); } -int check_ssse3(void) +int xmrig_ar2_check_ssse3(void) { return cpu_flags_have_ssse3(); } #else -void fill_segment_ssse3(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_ssse3(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_ssse3(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h index 139fdacca..7d0346c7e 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_ssse3(const argon2_instance_t *instance, - argon2_position_t position); - -int check_ssse3(void); +void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_ssse3(void); #endif // ARGON2_SSSE3_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h index 4fb04c1fe..e55bbb92e 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h @@ -150,8 +150,7 @@ static void fill_segment_128(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c index 0e877bce0..2e8b965b5 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c @@ -102,27 +102,19 @@ static __m128i f(__m128i x, __m128i y) #include "argon2-template-128.h" -void fill_segment_xop(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_position_t position) { fill_segment_128(instance, position); } -int check_xop(void) +int xmrig_ar2_check_xop(void) { return cpu_flags_have_xop(); } #else -void fill_segment_xop(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_xop(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_xop(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h index 1474a11c0..631f239c4 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_xop(const argon2_instance_t *instance, - argon2_position_t position); - -int check_xop(void); +void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_xop(void); #endif // ARGON2_XOP_H diff --git a/src/3rdparty/argon2/lib/argon2-template-64.h b/src/3rdparty/argon2/lib/argon2-template-64.h index 16ddbd35e..c7541c075 100644 --- a/src/3rdparty/argon2/lib/argon2-template-64.h +++ b/src/3rdparty/argon2/lib/argon2-template-64.h @@ -174,8 +174,7 @@ static void fill_segment_64(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = diff --git a/src/3rdparty/argon2/lib/argon2.c b/src/3rdparty/argon2/lib/argon2.c index b2eafd2fd..ab45229c6 100644 --- a/src/3rdparty/argon2/lib/argon2.c +++ b/src/3rdparty/argon2/lib/argon2.c @@ -57,7 +57,7 @@ size_t argon2_memory_size(uint32_t m_cost, uint32_t parallelism) { int argon2_ctx_mem(argon2_context *context, argon2_type type, void *memory, size_t memory_size) { /* 1. Validate all inputs */ - int result = validate_inputs(context); + int result = xmrig_ar2_validate_inputs(context); uint32_t memory_blocks, segment_length; argon2_instance_t instance; @@ -98,20 +98,20 @@ int argon2_ctx_mem(argon2_context *context, argon2_type type, void *memory, /* 3. Initialization: Hashing inputs, allocating memory, filling first * blocks */ - result = initialize(&instance, context); + result = xmrig_ar2_initialize(&instance, context); if (ARGON2_OK != result) { return result; } /* 4. Filling memory */ - result = fill_memory_blocks(&instance); + result = xmrig_ar2_fill_memory_blocks(&instance); if (ARGON2_OK != result) { return result; } /* 5. Finalization */ - finalize(context, &instance); + xmrig_ar2_finalize(context, &instance); return ARGON2_OK; } @@ -174,7 +174,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, result = argon2_ctx(&context, type); if (result != ARGON2_OK) { - clear_internal_memory(out, hashlen); + xmrig_ar2_clear_internal_memory(out, hashlen); free(out); return result; } @@ -187,13 +187,13 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, /* if encoding requested, write it */ if (encoded && encodedlen) { if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) { - clear_internal_memory(out, hashlen); /* wipe buffers if error */ - clear_internal_memory(encoded, encodedlen); + xmrig_ar2_clear_internal_memory(out, hashlen); /* wipe buffers if error */ + xmrig_ar2_clear_internal_memory(encoded, encodedlen); free(out); return ARGON2_ENCODING_FAIL; } } - clear_internal_memory(out, hashlen); + xmrig_ar2_clear_internal_memory(out, hashlen); free(out); return ARGON2_OK; diff --git a/src/3rdparty/argon2/lib/blake2/blake2.c b/src/3rdparty/argon2/lib/blake2/blake2.c index d32028ed5..76de85a54 100644 --- a/src/3rdparty/argon2/lib/blake2/blake2.c +++ b/src/3rdparty/argon2/lib/blake2/blake2.c @@ -128,14 +128,14 @@ static void blake2b_init_state(blake2b_state *S) S->buflen = 0; } -void blake2b_init(blake2b_state *S, size_t outlen) +void xmrig_ar2_blake2b_init(blake2b_state *S, size_t outlen) { blake2b_init_state(S); /* XOR initial state with param block: */ S->h[0] ^= (uint64_t)outlen | (UINT64_C(1) << 16) | (UINT64_C(1) << 24); } -void blake2b_update(blake2b_state *S, const void *in, size_t inlen) +void xmrig_ar2_blake2b_update(blake2b_state *S, const void *in, size_t inlen) { const uint8_t *pin = (const uint8_t *)in; @@ -160,7 +160,7 @@ void blake2b_update(blake2b_state *S, const void *in, size_t inlen) S->buflen += inlen; } -void blake2b_final(blake2b_state *S, void *out, size_t outlen) +void xmrig_ar2_blake2b_final(blake2b_state *S, void *out, size_t outlen) { uint8_t buffer[BLAKE2B_OUTBYTES] = {0}; unsigned int i; @@ -174,12 +174,12 @@ void blake2b_final(blake2b_state *S, void *out, size_t outlen) } memcpy(out, buffer, outlen); - clear_internal_memory(buffer, sizeof(buffer)); - clear_internal_memory(S->buf, sizeof(S->buf)); - clear_internal_memory(S->h, sizeof(S->h)); + xmrig_ar2_clear_internal_memory(buffer, sizeof(buffer)); + xmrig_ar2_clear_internal_memory(S->buf, sizeof(S->buf)); + xmrig_ar2_clear_internal_memory(S->h, sizeof(S->h)); } -void blake2b_long(void *out, size_t outlen, const void *in, size_t inlen) +void xmrig_ar2_blake2b_long(void *out, size_t outlen, const void *in, size_t inlen) { uint8_t *pout = (uint8_t *)out; blake2b_state blake_state; @@ -187,39 +187,39 @@ void blake2b_long(void *out, size_t outlen, const void *in, size_t inlen) store32(outlen_bytes, (uint32_t)outlen); if (outlen <= BLAKE2B_OUTBYTES) { - blake2b_init(&blake_state, outlen); - blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); - blake2b_update(&blake_state, in, inlen); - blake2b_final(&blake_state, pout, outlen); + xmrig_ar2_blake2b_init(&blake_state, outlen); + xmrig_ar2_blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); + xmrig_ar2_blake2b_update(&blake_state, in, inlen); + xmrig_ar2_blake2b_final(&blake_state, pout, outlen); } else { uint32_t toproduce; uint8_t out_buffer[BLAKE2B_OUTBYTES]; - blake2b_init(&blake_state, BLAKE2B_OUTBYTES); - blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); - blake2b_update(&blake_state, in, inlen); - blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_init(&blake_state, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); + xmrig_ar2_blake2b_update(&blake_state, in, inlen); + xmrig_ar2_blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); memcpy(pout, out_buffer, BLAKE2B_OUTBYTES / 2); pout += BLAKE2B_OUTBYTES / 2; toproduce = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2; while (toproduce > BLAKE2B_OUTBYTES) { - blake2b_init(&blake_state, BLAKE2B_OUTBYTES); - blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); - blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_init(&blake_state, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); memcpy(pout, out_buffer, BLAKE2B_OUTBYTES / 2); pout += BLAKE2B_OUTBYTES / 2; toproduce -= BLAKE2B_OUTBYTES / 2; } - blake2b_init(&blake_state, toproduce); - blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); - blake2b_final(&blake_state, out_buffer, toproduce); + xmrig_ar2_blake2b_init(&blake_state, toproduce); + xmrig_ar2_blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_final(&blake_state, out_buffer, toproduce); memcpy(pout, out_buffer, toproduce); - clear_internal_memory(out_buffer, sizeof(out_buffer)); + xmrig_ar2_clear_internal_memory(out_buffer, sizeof(out_buffer)); } } diff --git a/src/3rdparty/argon2/lib/blake2/blake2.h b/src/3rdparty/argon2/lib/blake2/blake2.h index 7deeaa1fa..33f19eec8 100644 --- a/src/3rdparty/argon2/lib/blake2/blake2.h +++ b/src/3rdparty/argon2/lib/blake2/blake2.h @@ -20,11 +20,11 @@ typedef struct __blake2b_state { } blake2b_state; /* Streaming API */ -void blake2b_init(blake2b_state *S, size_t outlen); -void blake2b_update(blake2b_state *S, const void *in, size_t inlen); -void blake2b_final(blake2b_state *S, void *out, size_t outlen); +void xmrig_ar2_blake2b_init(blake2b_state *S, size_t outlen); +void xmrig_ar2_blake2b_update(blake2b_state *S, const void *in, size_t inlen); +void xmrig_ar2_blake2b_final(blake2b_state *S, void *out, size_t outlen); -void blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); +void xmrig_ar2_blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); #endif // ARGON2_BLAKE2_H diff --git a/src/3rdparty/argon2/lib/core.c b/src/3rdparty/argon2/lib/core.c index e3ec883b9..8c5d1c0ec 100644 --- a/src/3rdparty/argon2/lib/core.c +++ b/src/3rdparty/argon2/lib/core.c @@ -77,8 +77,7 @@ static void store_block(void *output, const block *src) { /***************Memory functions*****************/ -int allocate_memory(const argon2_context *context, - argon2_instance_t *instance) { +int xmrig_ar2_allocate_memory(const argon2_context *context, argon2_instance_t *instance) { size_t blocks = instance->memory_blocks; size_t memory_size = blocks * ARGON2_BLOCK_SIZE; @@ -107,11 +106,10 @@ int allocate_memory(const argon2_context *context, return ARGON2_OK; } -void free_memory(const argon2_context *context, - const argon2_instance_t *instance) { +void xmrig_ar2_free_memory(const argon2_context *context, const argon2_instance_t *instance) { size_t memory_size = instance->memory_blocks * ARGON2_BLOCK_SIZE; - clear_internal_memory(instance->memory, memory_size); + xmrig_ar2_clear_internal_memory(instance->memory, memory_size); if (instance->keep_memory) { /* user-supplied memory -- do not free */ @@ -125,7 +123,7 @@ void free_memory(const argon2_context *context, } } -void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) { +void NOT_OPTIMIZED xmrig_ar2_secure_wipe_memory(void *v, size_t n) { #if defined(_MSC_VER) && VC_GE_2005(_MSC_VER) SecureZeroMemory(v, n); #elif defined memset_s @@ -140,13 +138,13 @@ void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) { /* Memory clear flag defaults to true. */ int FLAG_clear_internal_memory = 0; -void clear_internal_memory(void *v, size_t n) { +void xmrig_ar2_clear_internal_memory(void *v, size_t n) { if (FLAG_clear_internal_memory && v) { - secure_wipe_memory(v, n); + xmrig_ar2_secure_wipe_memory(v, n); } } -void finalize(const argon2_context *context, argon2_instance_t *instance) { +void xmrig_ar2_finalize(const argon2_context *context, argon2_instance_t *instance) { if (context != NULL && instance != NULL && context->out != NULL) { block blockhash; uint32_t l; @@ -164,24 +162,21 @@ void finalize(const argon2_context *context, argon2_instance_t *instance) { { uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE]; store_block(blockhash_bytes, &blockhash); - blake2b_long(context->out, context->outlen, blockhash_bytes, - ARGON2_BLOCK_SIZE); + xmrig_ar2_blake2b_long(context->out, context->outlen, blockhash_bytes, ARGON2_BLOCK_SIZE); /* clear blockhash and blockhash_bytes */ - clear_internal_memory(blockhash.v, ARGON2_BLOCK_SIZE); - clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); + xmrig_ar2_clear_internal_memory(blockhash.v, ARGON2_BLOCK_SIZE); + xmrig_ar2_clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); } if (instance->print_internals) { print_tag(context->out, context->outlen); } - free_memory(context, instance); + xmrig_ar2_free_memory(context, instance); } } -uint32_t index_alpha(const argon2_instance_t *instance, - const argon2_position_t *position, uint32_t pseudo_rand, - int same_lane) { +uint32_t xmrig_ar2_index_alpha(const argon2_instance_t *instance, const argon2_position_t *position, uint32_t pseudo_rand, int same_lane) { /* * Pass 0: * This lane : all already finished segments plus already constructed @@ -257,7 +252,7 @@ static int fill_memory_blocks_st(argon2_instance_t *instance) { for (s = 0; s < ARGON2_SYNC_POINTS; ++s) { for (l = 0; l < instance->lanes; ++l) { argon2_position_t position = { r, l, (uint8_t)s, 0 }; - fill_segment(instance, position); + xmrig_ar2_fill_segment(instance, position); } } @@ -268,7 +263,7 @@ static int fill_memory_blocks_st(argon2_instance_t *instance) { return ARGON2_OK; } -int fill_memory_blocks(argon2_instance_t *instance) { +int xmrig_ar2_fill_memory_blocks(argon2_instance_t *instance) { if (instance == NULL || instance->lanes == 0) { return ARGON2_INCORRECT_PARAMETER; } @@ -276,7 +271,7 @@ int fill_memory_blocks(argon2_instance_t *instance) { return fill_memory_blocks_st(instance); } -int validate_inputs(const argon2_context *context) { +int xmrig_ar2_validate_inputs(const argon2_context *context) { if (NULL == context) { return ARGON2_INCORRECT_PARAMETER; } @@ -403,7 +398,7 @@ int validate_inputs(const argon2_context *context) { return ARGON2_OK; } -void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { +void xmrig_ar2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { uint32_t l; /* Make the first and second block in each lane as G(H0||0||i) or G(H0||1||i) */ @@ -412,21 +407,17 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0); store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l); - blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, - ARGON2_PREHASH_SEED_LENGTH); - load_block(&instance->memory[l * instance->lane_length + 0], - blockhash_bytes); + xmrig_ar2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, ARGON2_PREHASH_SEED_LENGTH); + load_block(&instance->memory[l * instance->lane_length + 0], blockhash_bytes); store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1); - blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, - ARGON2_PREHASH_SEED_LENGTH); - load_block(&instance->memory[l * instance->lane_length + 1], - blockhash_bytes); + xmrig_ar2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, ARGON2_PREHASH_SEED_LENGTH); + load_block(&instance->memory[l * instance->lane_length + 1], blockhash_bytes); } - clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); + xmrig_ar2_clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); } -void initial_hash(uint8_t *blockhash, argon2_context *context, +void xmrig_ar2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) { blake2b_state BlakeHash; uint8_t value[sizeof(uint32_t)]; @@ -435,72 +426,70 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, return; } - blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); + xmrig_ar2_blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); store32(&value, context->lanes); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->outlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->m_cost); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->t_cost); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->version); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, (uint32_t)type); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->pwdlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->pwd != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, context->pwdlen); if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) { - secure_wipe_memory(context->pwd, context->pwdlen); + xmrig_ar2_secure_wipe_memory(context->pwd, context->pwdlen); context->pwdlen = 0; } } store32(&value, context->saltlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->salt != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->salt, + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->salt, context->saltlen); } store32(&value, context->secretlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->secret != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->secret, - context->secretlen); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->secret, context->secretlen); if (context->flags & ARGON2_FLAG_CLEAR_SECRET) { - secure_wipe_memory(context->secret, context->secretlen); + xmrig_ar2_secure_wipe_memory(context->secret, context->secretlen); context->secretlen = 0; } } store32(&value, context->adlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->ad != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->ad, - context->adlen); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->ad, context->adlen); } - blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); + xmrig_ar2_blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); } -int initialize(argon2_instance_t *instance, argon2_context *context) { +int xmrig_ar2_initialize(argon2_instance_t *instance, argon2_context *context) { uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; int result = ARGON2_OK; @@ -510,7 +499,7 @@ int initialize(argon2_instance_t *instance, argon2_context *context) { /* 1. Memory allocation */ - result = allocate_memory(context, instance); + result = xmrig_ar2_allocate_memory(context, instance); if (result != ARGON2_OK) { return result; } @@ -519,11 +508,9 @@ int initialize(argon2_instance_t *instance, argon2_context *context) { /* H_0 + 8 extra bytes to produce the first blocks */ /* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */ /* Hashing all inputs */ - initial_hash(blockhash, context, instance->type); + xmrig_ar2_initial_hash(blockhash, context, instance->type); /* Zeroing 8 extra bytes */ - clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, - ARGON2_PREHASH_SEED_LENGTH - - ARGON2_PREHASH_DIGEST_LENGTH); + xmrig_ar2_clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH); if (instance->print_internals) { initial_kat(blockhash, context, instance->type); @@ -531,9 +518,9 @@ int initialize(argon2_instance_t *instance, argon2_context *context) { /* 3. Creating first blocks, we always have at least two blocks in a slice */ - fill_first_blocks(blockhash, instance); + xmrig_ar2_fill_first_blocks(blockhash, instance); /* Clearing the hash */ - clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH); + xmrig_ar2_clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH); return ARGON2_OK; } diff --git a/src/3rdparty/argon2/lib/core.h b/src/3rdparty/argon2/lib/core.h index 8a3227a98..1fc75bcca 100644 --- a/src/3rdparty/argon2/lib/core.h +++ b/src/3rdparty/argon2/lib/core.h @@ -110,8 +110,7 @@ typedef struct Argon2_thread_data { * @param instance the Argon2 instance * @return ARGON2_OK if memory is allocated successfully */ -int allocate_memory(const argon2_context *context, - argon2_instance_t *instance); +int xmrig_ar2_allocate_memory(const argon2_context *context, argon2_instance_t *instance); /* * Frees memory at the given pointer, uses the appropriate deallocator as @@ -119,22 +118,21 @@ int allocate_memory(const argon2_context *context, * @param context argon2_context which specifies the deallocator * @param instance the Argon2 instance */ -void free_memory(const argon2_context *context, - const argon2_instance_t *instance); +void xmrig_ar2_free_memory(const argon2_context *context, const argon2_instance_t *instance); /* Function that securely cleans the memory. This ignores any flags set * regarding clearing memory. Usually one just calls clear_internal_memory. * @param mem Pointer to the memory * @param s Memory size in bytes */ -void secure_wipe_memory(void *v, size_t n); +void xmrig_ar2_secure_wipe_memory(void *v, size_t n); /* Function that securely clears the memory if FLAG_clear_internal_memory is * set. If the flag isn't set, this function does nothing. * @param mem Pointer to the memory * @param s Memory size in bytes */ -ARGON2_PUBLIC void clear_internal_memory(void *v, size_t n); +ARGON2_PUBLIC void xmrig_ar2_clear_internal_memory(void *v, size_t n); /* * Computes absolute position of reference block in the lane following a skewed @@ -146,9 +144,7 @@ ARGON2_PUBLIC void clear_internal_memory(void *v, size_t n); * If so we can reference the current segment * @pre All pointers must be valid */ -uint32_t index_alpha(const argon2_instance_t *instance, - const argon2_position_t *position, uint32_t pseudo_rand, - int same_lane); +uint32_t xmrig_ar2_index_alpha(const argon2_instance_t *instance, const argon2_position_t *position, uint32_t pseudo_rand, int same_lane); /* * Function that validates all inputs against predefined restrictions and return @@ -157,7 +153,7 @@ uint32_t index_alpha(const argon2_instance_t *instance, * @return ARGON2_OK if everything is all right, otherwise one of error codes * (all defined in */ -int validate_inputs(const argon2_context *context); +int xmrig_ar2_validate_inputs(const argon2_context *context); /* * Hashes all the inputs into @a blockhash[PREHASH_DIGEST_LENGTH], clears @@ -169,8 +165,7 @@ int validate_inputs(const argon2_context *context); * @pre @a blockhash must have at least @a PREHASH_DIGEST_LENGTH bytes * allocated */ -void initial_hash(uint8_t *blockhash, argon2_context *context, - argon2_type type); +void xmrig_ar2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type); /* * Function creates first 2 blocks per lane @@ -178,7 +173,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, * @param blockhash Pointer to the pre-hashing digest * @pre blockhash must point to @a PREHASH_SEED_LENGTH allocated values */ -void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); +void xmrig_ar2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); /* * Function allocates memory, hashes the inputs with Blake, and creates first @@ -190,7 +185,7 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); * @return Zero if successful, -1 if memory failed to allocate. @context->state * will be modified if successful. */ -int initialize(argon2_instance_t *instance, argon2_context *context); +int xmrig_ar2_initialize(argon2_instance_t *instance, argon2_context *context); /* * XORing the last block of each lane, hashing it, making the tag. Deallocates @@ -203,7 +198,7 @@ int initialize(argon2_instance_t *instance, argon2_context *context); * @pre if context->free_cbk is not NULL, it should point to a function that * deallocates memory */ -void finalize(const argon2_context *context, argon2_instance_t *instance); +void xmrig_ar2_finalize(const argon2_context *context, argon2_instance_t *instance); /* * Function that fills the segment using previous segments also from other @@ -212,8 +207,7 @@ void finalize(const argon2_context *context, argon2_instance_t *instance); * @param position Current position * @pre all block pointers must be valid */ -void fill_segment(const argon2_instance_t *instance, - argon2_position_t position); +void xmrig_ar2_fill_segment(const argon2_instance_t *instance, argon2_position_t position); /* * Function that fills the entire memory t_cost times based on the first two @@ -221,6 +215,6 @@ void fill_segment(const argon2_instance_t *instance, * @param instance Pointer to the current instance * @return ARGON2_OK if successful, @context->state */ -int fill_memory_blocks(argon2_instance_t *instance); +int xmrig_ar2_fill_memory_blocks(argon2_instance_t *instance); #endif diff --git a/src/3rdparty/argon2/lib/encoding.c b/src/3rdparty/argon2/lib/encoding.c index af56e4477..6190ae8f5 100644 --- a/src/3rdparty/argon2/lib/encoding.c +++ b/src/3rdparty/argon2/lib/encoding.c @@ -323,7 +323,7 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) { ctx->flags = ARGON2_DEFAULT_FLAGS; /* On return, must have valid context */ - validation_result = validate_inputs(ctx); + validation_result = xmrig_ar2_validate_inputs(ctx); if (validation_result != ARGON2_OK) { return validation_result; } @@ -371,7 +371,7 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx, } while ((void)0, 0) const char* type_string = argon2_type2string(type, 0); - int validation_result = validate_inputs(ctx); + int validation_result = xmrig_ar2_validate_inputs(ctx); if (!type_string) { return ARGON2_ENCODING_FAIL; diff --git a/src/3rdparty/argon2/lib/impl-select.c b/src/3rdparty/argon2/lib/impl-select.c index 965b639e8..aa5d9911e 100644 --- a/src/3rdparty/argon2/lib/impl-select.c +++ b/src/3rdparty/argon2/lib/impl-select.c @@ -83,7 +83,7 @@ void argon2_select_impl() } } -void fill_segment(const argon2_instance_t *instance, argon2_position_t position) +void xmrig_ar2_fill_segment(const argon2_instance_t *instance, argon2_position_t position) { selected_argon_impl.fill_segment(instance, position); } From c828e6b79330783094df785846fa07bab04e3d53 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 May 2020 01:55:00 +0700 Subject: [PATCH 11/24] Code cleanup. --- cmake/randomx.cmake | 1 + src/base/kernel/config/BaseConfig.cpp | 2 +- src/base/kernel/config/BaseConfig.h | 2 - src/core/Miner.cpp | 78 +++++++++++++-------------- src/core/Miner.h | 1 - src/crypto/astrobwt/AstroBWT.cpp | 43 +++++++-------- src/crypto/astrobwt/AstroBWT.h | 3 +- 7 files changed, 61 insertions(+), 69 deletions(-) diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 85e18fe39..0d3f7bab8 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -1,5 +1,6 @@ if (WITH_RANDOMX) add_definitions(/DXMRIG_ALGO_RANDOMX) + set(WITH_ARGON2 ON) list(APPEND HEADERS_CRYPTO src/crypto/rx/Rx.h diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index 1fe2d1edc..e2023d76f 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -89,13 +89,13 @@ bool xmrig::BaseConfig::read(const IJsonReader &reader, const char *fileName) m_watch = reader.getBool(kWatch, m_watch); m_logFile = reader.getString(kLogFile); m_userAgent = reader.getString(kUserAgent); + m_printTime = std::min(reader.getUint(kPrintTime, m_printTime), 3600U); # ifdef XMRIG_FEATURE_TLS m_tls = reader.getValue(kTls); # endif Log::setColors(reader.getBool(kColors, Log::isColors())); - setPrintTime(reader.getUint(kPrintTime, 60)); setVerbose(reader.getValue(kVerbose)); const auto &api = reader.getObject(kApi); diff --git a/src/base/kernel/config/BaseConfig.h b/src/base/kernel/config/BaseConfig.h index c7e693084..5335dd6c6 100644 --- a/src/base/kernel/config/BaseConfig.h +++ b/src/base/kernel/config/BaseConfig.h @@ -112,8 +112,6 @@ protected: # endif private: - inline void setPrintTime(uint32_t printTime) { if (printTime <= 3600) { m_printTime = printTime; } } - void setVerbose(const rapidjson::Value &value); }; diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 78beeb8ed..a56eafce0 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -40,7 +40,6 @@ #include "base/tools/Timer.h" #include "core/config/Config.h" #include "core/Controller.h" -#include "crypto/astrobwt/AstroBWT.h" #include "crypto/common/Nonce.h" #include "crypto/rx/Rx.h" #include "version.h" @@ -67,6 +66,11 @@ #endif +#ifdef XMRIG_ALGO_ASTROBWT +# include "crypto/astrobwt/AstroBWT.h" +#endif + + namespace xmrig { @@ -238,15 +242,36 @@ public: # endif + void printHashrate(bool details) + { + char num[8 * 4] = { 0 }; + double speed[3] = { 0.0 }; + + for (auto backend : backends) { + const auto hashrate = backend->hashrate(); + if (hashrate) { + speed[0] += hashrate->calc(Hashrate::ShortInterval); + speed[1] += hashrate->calc(Hashrate::MediumInterval); + speed[2] += hashrate->calc(Hashrate::LargeInterval); + } + + backend->printHashrate(details); + } + + LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"), + Hashrate::format(speed[0], num, sizeof(num) / 4), + Hashrate::format(speed[1], num + 8, sizeof(num) / 4), + Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ), + Hashrate::format(maxHashrate[algorithm], num + 8 * 3, sizeof(num) / 4) + ); + } + + # ifdef XMRIG_ALGO_RANDOMX inline bool initRX() { return Rx::init(job, controller->config()->rx(), controller->config()->cpu()); } # endif -# ifdef XMRIG_ALGO_ASTROBWT - inline bool initAstroBWT() { return astrobwt::init(job); } -# endif - Algorithm algorithm; Algorithms algorithms; bool active = false; @@ -279,6 +304,10 @@ xmrig::Miner::Miner(Controller *controller) Rx::init(this); # endif +# ifdef XMRIG_ALGO_ASTROBWT + astrobwt::init(); +# endif + controller->addListener(this); # ifdef XMRIG_FEATURE_API @@ -345,7 +374,7 @@ void xmrig::Miner::execCommand(char command) switch (command) { case 'h': case 'H': - printHashrate(true); + d_ptr->printHashrate(true); break; case 'p': @@ -384,31 +413,6 @@ void xmrig::Miner::pause() } -void xmrig::Miner::printHashrate(bool details) -{ - char num[8 * 4] = { 0 }; - double speed[3] = { 0.0 }; - - for (IBackend *backend : d_ptr->backends) { - const Hashrate *hashrate = backend->hashrate(); - if (hashrate) { - speed[0] += hashrate->calc(Hashrate::ShortInterval); - speed[1] += hashrate->calc(Hashrate::MediumInterval); - speed[2] += hashrate->calc(Hashrate::LargeInterval); - } - - backend->printHashrate(details); - } - - LOG_INFO(WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("H/s") " max " CYAN_BOLD("%s H/s"), - Hashrate::format(speed[0], num, sizeof(num) / 4), - Hashrate::format(speed[1], num + 8, sizeof(num) / 4), - Hashrate::format(speed[2], num + 8 * 2, sizeof(num) / 4 ), - Hashrate::format(d_ptr->maxHashrate[d_ptr->algorithm], num + 8 * 3, sizeof(num) / 4) - ); -} - - void xmrig::Miner::setEnabled(bool enabled) { if (d_ptr->enabled == enabled) { @@ -459,14 +463,10 @@ void xmrig::Miner::setJob(const Job &job, bool donate) d_ptr->userJobId = job.id(); } - bool ready = true; - # ifdef XMRIG_ALGO_RANDOMX - ready &= d_ptr->initRX(); -# endif - -# ifdef XMRIG_ALGO_ASTROBWT - ready &= d_ptr->initAstroBWT(); + const bool ready = d_ptr->initRX(); +# else + constexpr const bool ready = true; # endif mutex.unlock(); @@ -524,7 +524,7 @@ void xmrig::Miner::onTimer(const Timer *) const auto printTime = d_ptr->controller->config()->printTime(); if (printTime && d_ptr->ticks && (d_ptr->ticks % (printTime * 2)) == 0) { - printHashrate(false); + d_ptr->printHashrate(false); } d_ptr->ticks++; diff --git a/src/core/Miner.h b/src/core/Miner.h index b529d969c..1de19c4ab 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -61,7 +61,6 @@ public: Job job() const; void execCommand(char command); void pause(); - void printHashrate(bool details); void setEnabled(bool enabled); void setJob(const Job &job, bool donate); void stop(); diff --git a/src/crypto/astrobwt/AstroBWT.cpp b/src/crypto/astrobwt/AstroBWT.cpp index 47949e4c6..c692bdddf 100644 --- a/src/crypto/astrobwt/AstroBWT.cpp +++ b/src/crypto/astrobwt/AstroBWT.cpp @@ -27,15 +27,15 @@ */ -#include "AstroBWT.h" -#include "sha3.h" -#include "crypto/cn/CryptoNight.h" -#include "base/net/stratum/Job.h" -#include "base/crypto/Algorithm.h" -#include "base/io/log/Log.h" +#include "crypto/astrobwt/AstroBWT.h" #include "backend/cpu/Cpu.h" +#include "crypto/astrobwt/sha3.h" +#include "crypto/cn/CryptoNight.h" + + #include + constexpr int STAGE1_SIZE = 147253; constexpr int ALLOCATION_SIZE = (STAGE1_SIZE + 1048576) + (128 - (STAGE1_SIZE & 63)); @@ -171,24 +171,6 @@ void sort_indices(int N, const uint8_t* v, uint64_t* indices, uint64_t* tmp_indi } } -bool xmrig::astrobwt::init(const xmrig::Job& job) -{ - if (job.algorithm().family() != xmrig::Algorithm::ASTROBWT) - return true; - - if (astrobwtInitialized) - return true; - -#ifdef ASTROBWT_AVX2 - if (xmrig::Cpu::info()->hasAVX2()) { - hasAVX2 = true; - } -#endif - - astrobwtInitialized = true; - return true; -} - bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2) { uint8_t key[32]; @@ -257,6 +239,19 @@ bool xmrig::astrobwt::astrobwt_dero(const void* input_data, uint32_t input_size, return true; } + +void xmrig::astrobwt::init() +{ + if (!astrobwtInitialized) { +# ifdef ASTROBWT_AVX2 + hasAVX2 = Cpu::info()->hasAVX2(); +# endif + + astrobwtInitialized = true; + } +} + + template<> void xmrig::astrobwt::single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t) { diff --git a/src/crypto/astrobwt/AstroBWT.h b/src/crypto/astrobwt/AstroBWT.h index e10dc8a55..4e526060d 100644 --- a/src/crypto/astrobwt/AstroBWT.h +++ b/src/crypto/astrobwt/AstroBWT.h @@ -35,12 +35,11 @@ struct cryptonight_ctx; namespace xmrig { -class Job; namespace astrobwt { -bool init(const Job&); bool astrobwt_dero(const void* input_data, uint32_t input_size, void* scratchpad, uint8_t* output_hash, int stage2_max_size, bool avx2); +void init(); template void single_hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx** ctx, uint64_t); From dd7789763f57ddc4910061cbca0f68536c26d641 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 May 2020 02:06:49 +0700 Subject: [PATCH 12/24] Fix MSVC build. --- src/base/kernel/config/BaseConfig.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base/kernel/config/BaseConfig.cpp b/src/base/kernel/config/BaseConfig.cpp index e2023d76f..99381f025 100644 --- a/src/base/kernel/config/BaseConfig.cpp +++ b/src/base/kernel/config/BaseConfig.cpp @@ -31,6 +31,7 @@ #include "version.h" +#include #include #include #include From 39ae24b138ef069ab9230bc325e33c7c135a239b Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 May 2020 16:05:50 +0700 Subject: [PATCH 13/24] Fix memory leak. --- src/base/net/http/HttpClient.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/base/net/http/HttpClient.cpp b/src/base/net/http/HttpClient.cpp index 82f62c84a..ff82eab04 100644 --- a/src/base/net/http/HttpClient.cpp +++ b/src/base/net/http/HttpClient.cpp @@ -128,8 +128,9 @@ void xmrig::HttpClient::read(const char *data, size_t size) void xmrig::HttpClient::onConnect(uv_connect_t *req, int status) { auto client = static_cast(req->data); + delete req; + if (!client) { - delete req; return; } @@ -138,9 +139,7 @@ void xmrig::HttpClient::onConnect(uv_connect_t *req, int status) LOG_ERR("[%s:%d] connect error: \"%s\"", client->m_dns->host().data(), client->port(), uv_strerror(status)); } - delete req; - client->close(status); - return; + return client->close(status); } uv_read_start(client->stream(), NetBuffer::onAlloc, From 628506e2665bc4869774556eb16f18bd01beed48 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 8 May 2020 22:25:13 +0700 Subject: [PATCH 14/24] ICpuInfo refactoring. --- src/backend/cpu/Cpu.cpp | 27 +--- src/backend/cpu/cpu.cmake | 11 +- src/backend/cpu/interfaces/ICpuInfo.h | 15 +++ src/backend/cpu/platform/AdvancedCpuInfo.cpp | 91 +------------- src/backend/cpu/platform/AdvancedCpuInfo.h | 22 +--- src/backend/cpu/platform/BasicCpuInfo.cpp | 115 ++++++++++-------- src/backend/cpu/platform/BasicCpuInfo.h | 21 ++-- src/backend/cpu/platform/BasicCpuInfo_arm.cpp | 4 +- src/backend/cpu/platform/HwlocCpuInfo.cpp | 6 +- src/backend/cpu/platform/HwlocCpuInfo.h | 4 +- 10 files changed, 110 insertions(+), 206 deletions(-) diff --git a/src/backend/cpu/Cpu.cpp b/src/backend/cpu/Cpu.cpp index a11c4c567..a6c629729 100644 --- a/src/backend/cpu/Cpu.cpp +++ b/src/backend/cpu/Cpu.cpp @@ -60,32 +60,7 @@ xmrig::ICpuInfo *xmrig::Cpu::info() rapidjson::Value xmrig::Cpu::toJSON(rapidjson::Document &doc) { - using namespace rapidjson; - auto &allocator = doc.GetAllocator(); - - ICpuInfo *i = info(); - Value cpu(kObjectType); - Assembly assembly(i->assembly()); - - cpu.AddMember("brand", StringRef(i->brand()), allocator); - cpu.AddMember("aes", i->hasAES(), allocator); - cpu.AddMember("avx2", i->hasAVX2(), allocator); - cpu.AddMember("x64", ICpuInfo::isX64(), allocator); - cpu.AddMember("l2", static_cast(i->L2()), allocator); - cpu.AddMember("l3", static_cast(i->L3()), allocator); - cpu.AddMember("cores", static_cast(i->cores()), allocator); - cpu.AddMember("threads", static_cast(i->threads()), allocator); - cpu.AddMember("packages", static_cast(i->packages()), allocator); - cpu.AddMember("nodes", static_cast(i->nodes()), allocator); - cpu.AddMember("backend", StringRef(i->backend()), allocator); - -# ifdef XMRIG_FEATURE_ASM - cpu.AddMember("assembly", StringRef(assembly.toString()), allocator); -# else - cpu.AddMember("assembly", "none", allocator); -# endif - - return cpu; + return info()->toJSON(doc); } diff --git a/src/backend/cpu/cpu.cmake b/src/backend/cpu/cpu.cmake index cb5431745..75ec1ad77 100644 --- a/src/backend/cpu/cpu.cmake +++ b/src/backend/cpu/cpu.cmake @@ -70,11 +70,8 @@ else() ) endif() - -if (NOT WITH_LIBCPUID) - if (XMRIG_ARM) - set(SOURCES_CPUID ${SOURCES_CPUID} src/backend/cpu/platform/BasicCpuInfo_arm.cpp) - else() - set(SOURCES_CPUID ${SOURCES_CPUID} src/backend/cpu/platform/BasicCpuInfo.cpp) - endif() +if (XMRIG_ARM) + list(APPEND SOURCES_CPUID src/backend/cpu/platform/BasicCpuInfo_arm.cpp) +else() + list(APPEND SOURCES_CPUID src/backend/cpu/platform/BasicCpuInfo.cpp) endif() diff --git a/src/backend/cpu/interfaces/ICpuInfo.h b/src/backend/cpu/interfaces/ICpuInfo.h index f5a35b2d0..badb44c0d 100644 --- a/src/backend/cpu/interfaces/ICpuInfo.h +++ b/src/backend/cpu/interfaces/ICpuInfo.h @@ -51,6 +51,19 @@ public: MSR_MOD_MAX }; + enum Flag : uint32_t { + FLAG_AES, + FLAG_AVX2, + FLAG_AVX512F, + FLAG_BMI2, + FLAG_OSXSAVE, + FLAG_PDPE1GB, + FLAG_SSE2, + FLAG_SSSE3, + FLAG_XOP, + FLAG_MAX + }; + virtual ~ICpuInfo() = default; # if defined(__x86_64__) || defined(_M_AMD64) || defined (__arm64__) || defined (__aarch64__) @@ -60,6 +73,7 @@ public: # endif virtual Assembly::Id assembly() const = 0; + virtual bool has(Flag feature) const = 0; virtual bool hasAES() const = 0; virtual bool hasAVX2() const = 0; virtual bool hasBMI2() const = 0; @@ -68,6 +82,7 @@ public: virtual const char *brand() const = 0; virtual CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const = 0; virtual MsrMod msrMod() const = 0; + virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0; virtual size_t cores() const = 0; virtual size_t L2() const = 0; virtual size_t L3() const = 0; diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.cpp b/src/backend/cpu/platform/AdvancedCpuInfo.cpp index 0632c1d19..941f60aa2 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.cpp +++ b/src/backend/cpu/platform/AdvancedCpuInfo.cpp @@ -26,13 +26,6 @@ #include "3rdparty/libcpuid/libcpuid.h" -#ifdef _MSC_VER -# include -#else -# include -#endif - - #include #include #include @@ -40,59 +33,7 @@ #include -namespace xmrig { - - -static inline void cpu_brand_string(char out[64], const char *in) { - size_t pos = 0; - const size_t size = strlen(in); - - for (size_t i = 0; i < size; ++i) { - if (in[i] == ' ' && ((pos > 0 && out[pos - 1] == ' ') || pos == 0)) { - continue; - } - - out[pos++] = in[i]; - } - - if (pos > 0 && out[pos - 1] == ' ') { - out[pos - 1] = '\0'; - } -} - - -static inline void cpuid(uint32_t level, int32_t output[4]) -{ - memset(output, 0, sizeof(int32_t) * 4); - -# ifdef _MSC_VER - __cpuid(output, static_cast(level)); -# else - __cpuid_count(level, 0, output[0], output[1], output[2], output[3]); -# endif -} - - -static inline bool has_feature(uint32_t level, uint32_t reg, int32_t bit) -{ - int32_t cpu_info[4] = { 0 }; - cpuid(level, cpu_info); - - return (cpu_info[reg] & bit) != 0; -} - - -static inline bool has_pdpe1gb() -{ - return has_feature(0x80000001, 3, 1 << 26); -} - - -} // namespace xmrig - - -xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : - m_pdpe1gb(has_pdpe1gb()) +xmrig::AdvancedCpuInfo::AdvancedCpuInfo() { struct cpu_raw_data_t raw = {}; struct cpu_id_t data = {}; @@ -100,18 +41,10 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : cpuid_get_raw_data(&raw); cpu_identify(&raw, &data); - cpu_brand_string(m_brand, data.brand_str); snprintf(m_backend, sizeof m_backend, "libcpuid/%s", cpuid_lib_version()); - if (data.vendor == ::VENDOR_INTEL) { - m_vendor = VENDOR_INTEL; - } - else if (data.vendor == ::VENDOR_AMD) { - m_vendor = VENDOR_AMD; - } - m_threads = static_cast(data.total_logical_cpus); - m_packages = std::max(threads() / static_cast(data.num_logical_cpus), 1); + m_packages = std::max(m_threads / static_cast(data.num_logical_cpus), 1); m_cores = static_cast(data.num_cores) * m_packages; m_L3 = data.l3_cache > 0 ? static_cast(data.l3_cache) * m_packages : 0; @@ -134,26 +67,6 @@ xmrig::AdvancedCpuInfo::AdvancedCpuInfo() : m_L2 *= 1024; m_L3 *= 1024; - - if (data.flags[CPU_FEATURE_AES]) { - m_aes = true; - - if (m_vendor == VENDOR_AMD) { - if (data.ext_family >= 23) { - m_assembly = Assembly::RYZEN; - m_msrMod = MSR_MOD_RYZEN; - } - else { - m_assembly = Assembly::BULLDOZER; - } - } - else if (m_vendor == VENDOR_INTEL) { - m_assembly = Assembly::INTEL; - } - } - - m_avx2 = data.flags[CPU_FEATURE_AVX2] && data.flags[CPU_FEATURE_OSXSAVE]; - m_bmi2 = data.flags[CPU_FEATURE_BMI2]; } diff --git a/src/backend/cpu/platform/AdvancedCpuInfo.h b/src/backend/cpu/platform/AdvancedCpuInfo.h index 30ad3c584..9be075efe 100644 --- a/src/backend/cpu/platform/AdvancedCpuInfo.h +++ b/src/backend/cpu/platform/AdvancedCpuInfo.h @@ -26,13 +26,13 @@ #define XMRIG_ADVANCEDCPUINFO_H -#include "backend/cpu/interfaces/ICpuInfo.h" +#include "backend/cpu/platform/BasicCpuInfo.h" namespace xmrig { -class AdvancedCpuInfo : public ICpuInfo +class AdvancedCpuInfo : public BasicCpuInfo { public: AdvancedCpuInfo(); @@ -40,38 +40,20 @@ public: protected: CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const override; - inline Assembly::Id assembly() const override { return m_assembly; } - inline bool hasAES() const override { return m_aes; } - inline bool hasAVX2() const override { return m_avx2; } - inline bool hasBMI2() const override { return m_bmi2; } - inline bool hasOneGbPages() const override { return m_pdpe1gb; } inline const char *backend() const override { return m_backend; } - inline const char *brand() const override { return m_brand; } - inline MsrMod msrMod() const override { return m_msrMod; } inline size_t cores() const override { return m_cores; } inline size_t L2() const override { return m_L2; } inline size_t L3() const override { return m_L3; } - inline size_t nodes() const override { return 0; } inline size_t packages() const override { return m_packages; } inline size_t threads() const override { return m_threads; } - inline Vendor vendor() const override { return m_vendor; } private: - Assembly m_assembly; - bool m_aes = false; - bool m_avx2 = false; - bool m_bmi2 = false; bool m_L2_exclusive = false; char m_backend[32]{}; - char m_brand[64 + 5]{}; - const bool m_pdpe1gb = false; - MsrMod m_msrMod = MSR_MOD_NONE; size_t m_cores = 0; size_t m_L2 = 0; size_t m_L3 = 0; size_t m_packages = 1; - size_t m_threads = 0; - Vendor m_vendor = VENDOR_UNKNOWN; }; diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index d288ee28e..e1cda353f 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -33,28 +33,9 @@ # include #endif -#ifndef bit_AES -# define bit_AES (1 << 25) -#endif - -#ifndef bit_OSXSAVE -# define bit_OSXSAVE (1 << 27) -#endif - -#ifndef bit_AVX2 -# define bit_AVX2 (1 << 5) -#endif - -#ifndef bit_BMI2 -# define bit_BMI2 (1 << 8) -#endif - -#ifndef bit_PDPE1GB -# define bit_PDPE1GB (1 << 26) -#endif - #include "backend/cpu/platform/BasicCpuInfo.h" +#include "3rdparty/rapidjson/document.h" #include "crypto/common/Assembly.h" @@ -75,6 +56,11 @@ namespace xmrig { +static const std::array flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "xop" }; +static const std::array msrNames = { "none", "ryzen", "intel", "custom" }; +std::bitset BasicCpuInfo::m_flags; + + static inline void cpuid(uint32_t level, int32_t output[4]) { memset(output, 0, sizeof(int32_t) * 4); @@ -133,42 +119,35 @@ static inline int32_t get_masked(int32_t val, int32_t h, int32_t l) } -static inline bool has_aes_ni() -{ - return has_feature(PROCESSOR_INFO, ECX_Reg, bit_AES); -} - - -static inline bool has_avx2() -{ - return has_feature(EXTENDED_FEATURES, EBX_Reg, bit_AVX2) && has_feature(PROCESSOR_INFO, ECX_Reg, bit_OSXSAVE); -} - - -static inline bool has_bmi2() -{ - return has_feature(EXTENDED_FEATURES, EBX_Reg, bit_BMI2); -} - - -static inline bool has_pdpe1gb() -{ - return has_feature(PROCESSOR_EXT_INFO, EDX_Reg, bit_PDPE1GB); -} +static inline bool has_osxsave() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 27); } +static inline bool has_aes_ni() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 25); } +static inline bool has_avx2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 5) && has_osxsave(); } +static inline bool has_avx512f() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 16) && has_osxsave(); } +static inline bool has_bmi2() { return has_feature(EXTENDED_FEATURES, EBX_Reg, 1 << 8); } +static inline bool has_pdpe1gb() { return has_feature(PROCESSOR_EXT_INFO, EDX_Reg, 1 << 26); } +static inline bool has_sse2() { return has_feature(PROCESSOR_INFO, EDX_Reg, 1 << 26); } +static inline bool has_ssse3() { return has_feature(PROCESSOR_INFO, ECX_Reg, 1 << 9); } +static inline bool has_xop() { return has_feature(0x80000001, ECX_Reg, 1 << 11); } } // namespace xmrig xmrig::BasicCpuInfo::BasicCpuInfo() : - m_threads(std::thread::hardware_concurrency()), - m_aes(has_aes_ni()), - m_avx2(has_avx2()), - m_bmi2(has_bmi2()), - m_pdpe1gb(has_pdpe1gb()) + m_threads(std::thread::hardware_concurrency()) { cpu_brand_string(m_brand); + m_flags.set(FLAG_AES, has_aes_ni()); + m_flags.set(FLAG_AVX2, has_avx2()); + m_flags.set(FLAG_AVX512F, has_avx512f()); + m_flags.set(FLAG_BMI2, has_bmi2()); + m_flags.set(FLAG_OSXSAVE, has_osxsave()); + m_flags.set(FLAG_PDPE1GB, has_pdpe1gb()); + m_flags.set(FLAG_SSE2, has_sse2()); + m_flags.set(FLAG_SSSE3, has_ssse3()); + m_flags.set(FLAG_XOP, has_xop()); + # ifdef XMRIG_FEATURE_ASM if (hasAES()) { char vendor[13] = { 0 }; @@ -206,7 +185,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : const char *xmrig::BasicCpuInfo::backend() const { - return "basic"; + return "basic/1"; } @@ -270,3 +249,43 @@ xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm, uint3 return CpuThreads(std::max(count / 2, 1), 1); } + + +rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const +{ + using namespace rapidjson; + auto &allocator = doc.GetAllocator(); + + Value out(kObjectType); + + out.AddMember("brand", StringRef(brand()), allocator); + out.AddMember("aes", hasAES(), allocator); + out.AddMember("avx2", hasAVX2(), allocator); + out.AddMember("x64", ICpuInfo::isX64(), allocator); + out.AddMember("l2", static_cast(L2()), allocator); + out.AddMember("l3", static_cast(L3()), allocator); + out.AddMember("cores", static_cast(cores()), allocator); + out.AddMember("threads", static_cast(threads()), allocator); + out.AddMember("packages", static_cast(packages()), allocator); + out.AddMember("nodes", static_cast(nodes()), allocator); + out.AddMember("backend", StringRef(backend()), allocator); + out.AddMember("msr", StringRef(msrNames[msrMod()]), allocator); + +# ifdef XMRIG_FEATURE_ASM + out.AddMember("assembly", StringRef(Assembly(assembly()).toString()), allocator); +# else + cpu.AddMember("assembly", "none", allocator); +# endif + + Value flags(kArrayType); + + for (size_t i = 0; i < flagNames.size(); ++i) { + if (m_flags.test(i)) { + flags.PushBack(StringRef(flagNames[i]), allocator); + } + } + + out.AddMember("flags", flags, allocator); + + return out; +} diff --git a/src/backend/cpu/platform/BasicCpuInfo.h b/src/backend/cpu/platform/BasicCpuInfo.h index b553e575e..4d0fa745d 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.h +++ b/src/backend/cpu/platform/BasicCpuInfo.h @@ -29,6 +29,9 @@ #include "backend/cpu/interfaces/ICpuInfo.h" +#include + + namespace xmrig { @@ -40,12 +43,14 @@ public: protected: const char *backend() const override; CpuThreads threads(const Algorithm &algorithm, uint32_t limit) const override; + rapidjson::Value toJSON(rapidjson::Document &doc) const override; inline Assembly::Id assembly() const override { return m_assembly; } - inline bool hasAES() const override { return m_aes; } - inline bool hasAVX2() const override { return m_avx2; } - inline bool hasBMI2() const override { return m_bmi2; } - inline bool hasOneGbPages() const override { return m_pdpe1gb; } + inline bool has(Flag flag) const override { return m_flags.test(flag); } + inline bool hasAES() const override { return has(FLAG_AES); } + inline bool hasAVX2() const override { return has(FLAG_AVX2); } + inline bool hasBMI2() const override { return has(FLAG_BMI2); } + inline bool hasOneGbPages() const override { return has(FLAG_PDPE1GB); } inline const char *brand() const override { return m_brand; } inline MsrMod msrMod() const override { return m_msrMod; } inline size_t cores() const override { return 0; } @@ -59,15 +64,13 @@ protected: protected: char m_brand[64 + 6]{}; size_t m_threads; + Vendor m_vendor = VENDOR_UNKNOWN; private: + static std::bitset m_flags; + Assembly m_assembly = Assembly::NONE; - bool m_aes = false; - const bool m_avx2 = false; - const bool m_bmi2 = false; - const bool m_pdpe1gb = false; MsrMod m_msrMod = MSR_MOD_NONE; - Vendor m_vendor = VENDOR_UNKNOWN; }; diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp index 00f5f01f3..8c4bb63a4 100644 --- a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp @@ -46,9 +46,9 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : # if __ARM_FEATURE_CRYPTO # if !defined(__APPLE__) - m_aes = getauxval(AT_HWCAP) & HWCAP_AES; + m_flags.set(FLAG_AES, getauxval(AT_HWCAP) & HWCAP_AES); # else - m_aes = true; + m_flags.set(FLAG_AES, true); # endif # endif } diff --git a/src/backend/cpu/platform/HwlocCpuInfo.cpp b/src/backend/cpu/platform/HwlocCpuInfo.cpp index 527284505..378d6858a 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.cpp +++ b/src/backend/cpu/platform/HwlocCpuInfo.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2019 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -313,7 +313,7 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith size_t cacheHashes = ((L3 + extra) + (scratchpad / 2)) / scratchpad; # ifdef XMRIG_ALGO_CN_PICO - if (algorithm == Algorithm::CN_PICO_0 && (cacheHashes / PUs) >= 2) { + if (intensity && algorithm == Algorithm::CN_PICO_0 && (cacheHashes / PUs) >= 2) { intensity = 2; } # endif diff --git a/src/backend/cpu/platform/HwlocCpuInfo.h b/src/backend/cpu/platform/HwlocCpuInfo.h index c22291e85..3746f151e 100644 --- a/src/backend/cpu/platform/HwlocCpuInfo.h +++ b/src/backend/cpu/platform/HwlocCpuInfo.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2019 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 From a7caf4cc66ef9f523cc313ffa5efec939f28b030 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 8 May 2020 23:05:44 +0700 Subject: [PATCH 15/24] Fix build. --- src/backend/cpu/platform/BasicCpuInfo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index e1cda353f..b7a428c0f 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -23,6 +23,7 @@ */ #include +#include #include #include @@ -274,7 +275,7 @@ rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const # ifdef XMRIG_FEATURE_ASM out.AddMember("assembly", StringRef(Assembly(assembly()).toString()), allocator); # else - cpu.AddMember("assembly", "none", allocator); + out.AddMember("assembly", "none", allocator); # endif Value flags(kArrayType); From 85af4e27ecf51674ab9facc0692a9604c2392cd6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 8 May 2020 23:42:53 +0700 Subject: [PATCH 16/24] Fix ARM build. --- src/backend/cpu/platform/BasicCpuInfo.cpp | 2 +- src/backend/cpu/platform/BasicCpuInfo_arm.cpp | 44 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index b7a428c0f..2d2367fbb 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -262,7 +262,7 @@ rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const out.AddMember("brand", StringRef(brand()), allocator); out.AddMember("aes", hasAES(), allocator); out.AddMember("avx2", hasAVX2(), allocator); - out.AddMember("x64", ICpuInfo::isX64(), allocator); + out.AddMember("x64", isX64(), allocator); out.AddMember("l2", static_cast(L2()), allocator); out.AddMember("l3", static_cast(L3()), allocator); out.AddMember("cores", static_cast(cores()), allocator); diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp index 8c4bb63a4..9191a2b72 100644 --- a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2019 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -22,6 +22,7 @@ * along with this program. If not, see . */ +#include #include #include @@ -33,6 +34,10 @@ #include "backend/cpu/platform/BasicCpuInfo.h" +#include "3rdparty/rapidjson/document.h" + + +std::bitset xmrig::BasicCpuInfo::m_flags; xmrig::BasicCpuInfo::BasicCpuInfo() : @@ -56,7 +61,7 @@ xmrig::BasicCpuInfo::BasicCpuInfo() : const char *xmrig::BasicCpuInfo::backend() const { - return "basic_arm"; + return "basic/1"; } @@ -64,3 +69,36 @@ xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &, uint32_t) cons { return CpuThreads(threads()); } + + +rapidjson::Value xmrig::BasicCpuInfo::toJSON(rapidjson::Document &doc) const +{ + using namespace rapidjson; + auto &allocator = doc.GetAllocator(); + + Value out(kObjectType); + + out.AddMember("brand", StringRef(brand()), allocator); + out.AddMember("aes", hasAES(), allocator); + out.AddMember("avx2", false, allocator); + out.AddMember("x64", isX64(), allocator); + out.AddMember("l2", static_cast(L2()), allocator); + out.AddMember("l3", static_cast(L3()), allocator); + out.AddMember("cores", static_cast(cores()), allocator); + out.AddMember("threads", static_cast(threads()), allocator); + out.AddMember("packages", static_cast(packages()), allocator); + out.AddMember("nodes", static_cast(nodes()), allocator); + out.AddMember("backend", StringRef(backend()), allocator); + out.AddMember("msr", "none", allocator); + out.AddMember("assembly", "none", allocator); + + Value flags(kArrayType); + + if (hasAES()) { + flags.PushBack("aes", allocator); + } + + out.AddMember("flags", flags, allocator); + + return out; +} From 3cbf0dc0ee6a97cc92d173f6c57d21987506b202 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 9 May 2020 01:13:46 +0700 Subject: [PATCH 17/24] Removed code duplicate. --- src/3rdparty/argon2/CMakeLists.txt | 2 +- .../argon2/arch/x86_64/lib/argon2-arch.c | 5 +- .../argon2/arch/x86_64/lib/argon2-avx2.c | 9 +- .../argon2/arch/x86_64/lib/argon2-avx512f.c | 8 +- .../argon2/arch/x86_64/lib/argon2-sse2.c | 8 +- .../argon2/arch/x86_64/lib/argon2-ssse3.c | 8 +- .../argon2/arch/x86_64/lib/argon2-xop.c | 8 +- .../argon2/arch/x86_64/lib/cpu-flags.c | 129 ------------------ .../argon2/arch/x86_64/lib/cpu-flags.h | 12 -- src/3rdparty/argon2/lib/impl-select.c | 80 +++++------ src/backend/cpu/CpuBackend.cpp | 14 +- src/backend/cpu/platform/BasicCpuInfo.cpp | 16 ++- src/backend/cpu/platform/BasicCpuInfo.h | 3 +- src/backend/cpu/platform/BasicCpuInfo_arm.cpp | 3 - src/crypto/argon2/Impl.cpp | 37 ++++- src/crypto/argon2/Impl.h | 6 +- 16 files changed, 107 insertions(+), 241 deletions(-) delete mode 100644 src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.c delete mode 100644 src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.h diff --git a/src/3rdparty/argon2/CMakeLists.txt b/src/3rdparty/argon2/CMakeLists.txt index 0217382af..2f1fc0a90 100644 --- a/src/3rdparty/argon2/CMakeLists.txt +++ b/src/3rdparty/argon2/CMakeLists.txt @@ -17,7 +17,7 @@ set(ARGON2_SOURCES set(ARGON2_X86_64_ENABLED ON) set(ARGON2_X86_64_LIBS argon2-sse2 argon2-ssse3 argon2-xop argon2-avx2 argon2-avx512f) -set(ARGON2_X86_64_SOURCES arch/x86_64/lib/argon2-arch.c arch/x86_64/lib/cpu-flags.c) +set(ARGON2_X86_64_SOURCES arch/x86_64/lib/argon2-arch.c) if (CMAKE_C_COMPILER_ID MATCHES MSVC) function(add_feature_impl FEATURE MSVC_FLAG DEF) diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c index 48d2a77e1..b5f0b5e2c 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c @@ -4,7 +4,6 @@ #include "impl-select.h" -#include "cpu-flags.h" #include "argon2-sse2.h" #include "argon2-ssse3.h" #include "argon2-xop.h" @@ -26,7 +25,7 @@ void fill_segment_default(const argon2_instance_t *instance, void argon2_get_impl_list(argon2_impl_list *list) { static const argon2_impl IMPLS[] = { - { "x86_64", NULL, fill_segment_default }, + { "x86_64", NULL, fill_segment_default }, { "SSE2", xmrig_ar2_check_sse2, xmrig_ar2_fill_segment_sse2 }, { "SSSE3", xmrig_ar2_check_ssse3, xmrig_ar2_fill_segment_ssse3 }, { "XOP", xmrig_ar2_check_xop, xmrig_ar2_fill_segment_xop }, @@ -34,8 +33,6 @@ void argon2_get_impl_list(argon2_impl_list *list) { "AVX-512F", xmrig_ar2_check_avx512f, xmrig_ar2_fill_segment_avx512f }, }; - cpu_flags_get(); - list->count = sizeof(IMPLS) / sizeof(IMPLS[0]); list->entries = IMPLS; } diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c index 976fd4711..c8bf56f52 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c @@ -9,8 +9,6 @@ # include #endif -#include "cpu-flags.h" - #define r16 (_mm256_setr_epi8( \ 2, 3, 4, 5, 6, 7, 0, 1, \ 10, 11, 12, 13, 14, 15, 8, 9, \ @@ -325,10 +323,9 @@ void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_posit } } -int xmrig_ar2_check_avx2(void) -{ - return cpu_flags_have_avx2(); -} + +extern int cpu_flags_has_avx2(void); +int xmrig_ar2_check_avx2(void) { return cpu_flags_has_avx2(); } #else diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c index 994f35022..f9df1b875 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c @@ -10,8 +10,6 @@ # include #endif -#include "cpu-flags.h" - #define ror64(x, n) _mm512_ror_epi64((x), (n)) static __m512i f(__m512i x, __m512i y) @@ -310,10 +308,8 @@ void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_po } } -int xmrig_ar2_check_avx512f(void) -{ - return cpu_flags_have_avx512f(); -} +extern int cpu_flags_has_avx512f(void); +int xmrig_ar2_check_avx512f(void) { return cpu_flags_has_avx512f(); } #else diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c index 1e992b54e..099f851f8 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c @@ -7,8 +7,6 @@ # include #endif -#include "cpu-flags.h" - #define ror64_16(x) \ _mm_shufflehi_epi16( \ _mm_shufflelo_epi16((x), _MM_SHUFFLE(0, 3, 2, 1)), \ @@ -107,10 +105,8 @@ void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_posit fill_segment_128(instance, position); } -int xmrig_ar2_check_sse2(void) -{ - return cpu_flags_have_sse2(); -} +extern int cpu_flags_has_sse2(void); +int xmrig_ar2_check_sse2(void) { return cpu_flags_has_sse2(); } #else diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c index b848e3ebe..58a022ca6 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c @@ -9,8 +9,6 @@ # include #endif -#include "cpu-flags.h" - #define r16 (_mm_setr_epi8( \ 2, 3, 4, 5, 6, 7, 0, 1, \ 10, 11, 12, 13, 14, 15, 8, 9)) @@ -119,10 +117,8 @@ void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_posi fill_segment_128(instance, position); } -int xmrig_ar2_check_ssse3(void) -{ - return cpu_flags_have_ssse3(); -} +extern int cpu_flags_has_ssse3(void); +int xmrig_ar2_check_ssse3(void) { return cpu_flags_has_ssse3(); } #else diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c index 2e8b965b5..6fc6aa4b2 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c @@ -9,8 +9,6 @@ # include #endif -#include "cpu-flags.h" - #define ror64(x, c) _mm_roti_epi64((x), -(c)) static __m128i f(__m128i x, __m128i y) @@ -107,10 +105,8 @@ void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_positi fill_segment_128(instance, position); } -int xmrig_ar2_check_xop(void) -{ - return cpu_flags_have_xop(); -} +extern int cpu_flags_has_xop(void); +int xmrig_ar2_check_xop(void) { return cpu_flags_has_xop(); } #else diff --git a/src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.c b/src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.c deleted file mode 100644 index cd13cb015..000000000 --- a/src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.c +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include - - -#include "cpu-flags.h" - -#include - -#ifdef _MSC_VER -# include -#else -# include -#endif - -#ifndef bit_OSXSAVE -# define bit_OSXSAVE (1 << 27) -#endif - -#ifndef bit_SSE2 -# define bit_SSE2 (1 << 26) -#endif - -#ifndef bit_SSSE3 -# define bit_SSSE3 (1 << 9) -#endif - -#ifndef bit_AVX2 -# define bit_AVX2 (1 << 5) -#endif - -#ifndef bit_AVX512F -# define bit_AVX512F (1 << 16) -#endif - -#ifndef bit_XOP -# define bit_XOP (1 << 11) -#endif - -#define PROCESSOR_INFO (1) -#define EXTENDED_FEATURES (7) - -#define EAX_Reg (0) -#define EBX_Reg (1) -#define ECX_Reg (2) -#define EDX_Reg (3) - - -enum { - X86_64_FEATURE_SSE2 = (1 << 0), - X86_64_FEATURE_SSSE3 = (1 << 1), - X86_64_FEATURE_XOP = (1 << 2), - X86_64_FEATURE_AVX2 = (1 << 3), - X86_64_FEATURE_AVX512F = (1 << 4), -}; - -static unsigned int cpu_flags; - - -static inline void cpuid(uint32_t level, int32_t output[4]) -{ -# ifdef _MSC_VER - __cpuid(output, (int) level); -# else - __cpuid_count(level, 0, output[0], output[1], output[2], output[3]); -# endif -} - - -static bool has_feature(uint32_t level, uint32_t reg, int32_t bit) -{ - int32_t cpu_info[4] = { 0 }; - cpuid(level, cpu_info); - - return (cpu_info[reg] & bit) != 0; -} - - -void cpu_flags_get(void) -{ - if (has_feature(PROCESSOR_INFO, EDX_Reg, bit_SSE2)) { - cpu_flags |= X86_64_FEATURE_SSE2; - } - - if (has_feature(PROCESSOR_INFO, ECX_Reg, bit_SSSE3)) { - cpu_flags |= X86_64_FEATURE_SSSE3; - } - - if (!has_feature(PROCESSOR_INFO, ECX_Reg, bit_OSXSAVE)) { - return; - } - - if (has_feature(EXTENDED_FEATURES, EBX_Reg, bit_AVX2)) { - cpu_flags |= X86_64_FEATURE_AVX2; - } - - if (has_feature(EXTENDED_FEATURES, EBX_Reg, bit_AVX512F)) { - cpu_flags |= X86_64_FEATURE_AVX512F; - } - - if (has_feature(0x80000001, ECX_Reg, bit_XOP)) { - cpu_flags |= X86_64_FEATURE_XOP; - } -} - -int cpu_flags_have_sse2(void) -{ - return cpu_flags & X86_64_FEATURE_SSE2; -} - -int cpu_flags_have_ssse3(void) -{ - return cpu_flags & X86_64_FEATURE_SSSE3; -} - -int cpu_flags_have_xop(void) -{ - return cpu_flags & X86_64_FEATURE_XOP; -} - -int cpu_flags_have_avx2(void) -{ - return cpu_flags & X86_64_FEATURE_AVX2; -} - -int cpu_flags_have_avx512f(void) -{ - return cpu_flags & X86_64_FEATURE_AVX512F; -} - diff --git a/src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.h b/src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.h deleted file mode 100644 index b546a8ba1..000000000 --- a/src/3rdparty/argon2/arch/x86_64/lib/cpu-flags.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ARGON2_CPU_FLAGS_H -#define ARGON2_CPU_FLAGS_H - -void cpu_flags_get(void); - -int cpu_flags_have_sse2(void); -int cpu_flags_have_ssse3(void); -int cpu_flags_have_xop(void); -int cpu_flags_have_avx2(void); -int cpu_flags_have_avx512f(void); - -#endif // ARGON2_CPU_FLAGS_H diff --git a/src/3rdparty/argon2/lib/impl-select.c b/src/3rdparty/argon2/lib/impl-select.c index aa5d9911e..bc7d14383 100644 --- a/src/3rdparty/argon2/lib/impl-select.c +++ b/src/3rdparty/argon2/lib/impl-select.c @@ -2,79 +2,81 @@ #include #include "impl-select.h" - #include "3rdparty/argon2.h" -#define BENCH_SAMPLES 1024 + +extern uint64_t uv_hrtime(void); + + +#define BENCH_SAMPLES 1024U #define BENCH_MEM_BLOCKS 512 -static argon2_impl selected_argon_impl = { - "default", NULL, fill_segment_default -}; + +#ifdef _MSC_VER +# define strcasecmp _stricmp +#endif + + +static argon2_impl selected_argon_impl = { "default", NULL, fill_segment_default }; + /* the benchmark routine is not thread-safe, so we can use a global var here: */ static block memory[BENCH_MEM_BLOCKS]; -static uint64_t benchmark_impl(const argon2_impl *impl) { - clock_t time; - unsigned int i; - uint64_t bench; - argon2_instance_t instance; - argon2_position_t pos; +static uint64_t benchmark_impl(const argon2_impl *impl) { memset(memory, 0, sizeof(memory)); - instance.version = ARGON2_VERSION_NUMBER; - instance.memory = memory; - instance.passes = 1; - instance.memory_blocks = BENCH_MEM_BLOCKS; + argon2_instance_t instance; + instance.version = ARGON2_VERSION_NUMBER; + instance.memory = memory; + instance.passes = 1; + instance.memory_blocks = BENCH_MEM_BLOCKS; instance.segment_length = BENCH_MEM_BLOCKS / ARGON2_SYNC_POINTS; - instance.lane_length = instance.segment_length * ARGON2_SYNC_POINTS; - instance.lanes = 1; - instance.threads = 1; - instance.type = Argon2_i; + instance.lane_length = instance.segment_length * ARGON2_SYNC_POINTS; + instance.lanes = 1; + instance.threads = 1; + instance.type = Argon2_id; - pos.lane = 0; - pos.pass = 0; - pos.slice = 0; - pos.index = 0; + argon2_position_t pos; + pos.lane = 0; + pos.pass = 0; + pos.slice = 0; + pos.index = 0; /* warm-up cache: */ impl->fill_segment(&instance, pos); /* OK, now measure: */ - bench = 0; - time = clock(); - for (i = 0; i < BENCH_SAMPLES; i++) { + const uint64_t time = uv_hrtime(); + + for (uint32_t i = 0; i < BENCH_SAMPLES; i++) { impl->fill_segment(&instance, pos); } - time = clock() - time; - bench = (uint64_t)time; - return bench; + + return uv_hrtime() - time; } + void argon2_select_impl() { argon2_impl_list impls; - unsigned int i; const argon2_impl *best_impl = NULL; uint64_t best_bench = UINT_MAX; argon2_get_impl_list(&impls); - for (i = 0; i < impls.count; i++) { + for (uint32_t i = 0; i < impls.count; i++) { const argon2_impl *impl = &impls.entries[i]; - uint64_t bench; if (impl->check != NULL && !impl->check()) { continue; } - bench = benchmark_impl(impl); - + const uint64_t bench = benchmark_impl(impl); if (bench < best_bench) { best_bench = bench; - best_impl = impl; + best_impl = impl; } } @@ -83,11 +85,13 @@ void argon2_select_impl() } } + void xmrig_ar2_fill_segment(const argon2_instance_t *instance, argon2_position_t position) { selected_argon_impl.fill_segment(instance, position); } + const char *argon2_get_impl_name() { return selected_argon_impl.name; @@ -97,14 +101,12 @@ const char *argon2_get_impl_name() int argon2_select_impl_by_name(const char *name) { argon2_impl_list impls; - unsigned int i; - argon2_get_impl_list(&impls); - for (i = 0; i < impls.count; i++) { + for (uint32_t i = 0; i < impls.count; i++) { const argon2_impl *impl = &impls.entries[i]; - if (strcmp(impl->name, name) == 0) { + if (strcasecmp(impl->name, name) == 0) { selected_argon_impl = *impl; return 1; diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index bd8e0ad11..45a968a64 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -277,19 +277,7 @@ void xmrig::CpuBackend::prepare(const Job &nextJob) # ifdef XMRIG_ALGO_ARGON2 const xmrig::Algorithm::Family f = nextJob.algorithm().family(); if ((f == Algorithm::ARGON2) || (f == Algorithm::RANDOM_X)) { - - xmrig::String impl = d_ptr->controller->config()->cpu().argon2Impl(); - - if (impl.isEmpty()) { - if (xmrig::Cpu::info()->hasAVX2()) { - impl = "AVX2"; - } - else if (xmrig::Cpu::info()->isX64()) { - impl = "SSE2"; - } - } - - if (argon2::Impl::select(impl)) { + if (argon2::Impl::select(d_ptr->controller->config()->cpu().argon2Impl())) { LOG_INFO("%s use " WHITE_BOLD("argon2") " implementation " CSI "1;%dm" "%s", tag, argon2::Impl::name() == "default" ? 33 : 32, diff --git a/src/backend/cpu/platform/BasicCpuInfo.cpp b/src/backend/cpu/platform/BasicCpuInfo.cpp index 2d2367fbb..eb0429805 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo.cpp @@ -59,7 +59,6 @@ namespace xmrig { static const std::array flagNames = { "aes", "avx2", "avx512f", "bmi2", "osxsave", "pdpe1gb", "sse2", "ssse3", "xop" }; static const std::array msrNames = { "none", "ryzen", "intel", "custom" }; -std::bitset BasicCpuInfo::m_flags; static inline void cpuid(uint32_t level, int32_t output[4]) @@ -134,6 +133,21 @@ static inline bool has_xop() { return has_feature(0x80000001, } // namespace xmrig +#ifdef XMRIG_ALGO_ARGON2 +extern "C" { + + +int cpu_flags_has_avx2() { return xmrig::has_avx2(); } +int cpu_flags_has_avx512f() { return xmrig::has_avx512f(); } +int cpu_flags_has_sse2() { return xmrig::has_sse2(); } +int cpu_flags_has_ssse3() { return xmrig::has_ssse3(); } +int cpu_flags_has_xop() { return xmrig::has_xop(); } + + +} +#endif + + xmrig::BasicCpuInfo::BasicCpuInfo() : m_threads(std::thread::hardware_concurrency()) { diff --git a/src/backend/cpu/platform/BasicCpuInfo.h b/src/backend/cpu/platform/BasicCpuInfo.h index 4d0fa745d..ea478dbf1 100644 --- a/src/backend/cpu/platform/BasicCpuInfo.h +++ b/src/backend/cpu/platform/BasicCpuInfo.h @@ -67,10 +67,9 @@ protected: Vendor m_vendor = VENDOR_UNKNOWN; private: - static std::bitset m_flags; - Assembly m_assembly = Assembly::NONE; MsrMod m_msrMod = MSR_MOD_NONE; + std::bitset m_flags; }; diff --git a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp index 9191a2b72..653304c8f 100644 --- a/src/backend/cpu/platform/BasicCpuInfo_arm.cpp +++ b/src/backend/cpu/platform/BasicCpuInfo_arm.cpp @@ -37,9 +37,6 @@ #include "3rdparty/rapidjson/document.h" -std::bitset xmrig::BasicCpuInfo::m_flags; - - xmrig::BasicCpuInfo::BasicCpuInfo() : m_threads(std::thread::hardware_concurrency()) { diff --git a/src/crypto/argon2/Impl.cpp b/src/crypto/argon2/Impl.cpp index d0f267f95..02084a57d 100644 --- a/src/crypto/argon2/Impl.cpp +++ b/src/crypto/argon2/Impl.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -39,10 +39,39 @@ static String implName; } // namespace xmrig -bool xmrig::argon2::Impl::select(const String &nameHint) +extern "C" { + + +extern int xmrig_ar2_check_avx512f(); +extern int xmrig_ar2_check_avx2(); +extern int xmrig_ar2_check_ssse3(); +extern int xmrig_ar2_check_sse2(); + + +} + + +bool xmrig::argon2::Impl::select(const String &nameHint, bool benchmark) { if (!selected) { - if (nameHint.isEmpty() || argon2_select_impl_by_name(nameHint) == 0) { + auto hint = nameHint; + + if (hint.isEmpty() && !benchmark) { + if (xmrig_ar2_check_avx512f()) { + hint = "AVX-512F"; + } + else if (xmrig_ar2_check_avx2()) { + hint = "AVX2"; + } + else if (xmrig_ar2_check_ssse3()) { + hint = "SSSE3"; + } + else if (xmrig_ar2_check_sse2()) { + hint = "SSE2"; + } + } + + if (hint.isEmpty() || argon2_select_impl_by_name(hint) == 0) { argon2_select_impl(); } diff --git a/src/crypto/argon2/Impl.h b/src/crypto/argon2/Impl.h index 006dbd35f..aaedec028 100644 --- a/src/crypto/argon2/Impl.h +++ b/src/crypto/argon2/Impl.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018-2019 SChernykh - * Copyright 2016-2019 XMRig , + * Copyright 2018-2020 SChernykh + * Copyright 2016-2020 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 @@ -38,7 +38,7 @@ namespace argon2 { class Impl { public: - static bool select(const String &nameHint); + static bool select(const String &nameHint, bool benchmark = false); static const String &name(); }; From 7f31f45b6daddeb53b7788032d2e30cd1a5837b8 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 9 May 2020 01:26:05 +0700 Subject: [PATCH 18/24] Fix build. --- src/crypto/argon2/Impl.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/crypto/argon2/Impl.cpp b/src/crypto/argon2/Impl.cpp index 02084a57d..435f8b6d8 100644 --- a/src/crypto/argon2/Impl.cpp +++ b/src/crypto/argon2/Impl.cpp @@ -54,6 +54,7 @@ extern int xmrig_ar2_check_sse2(); bool xmrig::argon2::Impl::select(const String &nameHint, bool benchmark) { if (!selected) { +# if !defined(XMRIG_ARM) || defined(__x86_64__) || defined(_M_AMD64) auto hint = nameHint; if (hint.isEmpty() && !benchmark) { @@ -74,6 +75,7 @@ bool xmrig::argon2::Impl::select(const String &nameHint, bool benchmark) if (hint.isEmpty() || argon2_select_impl_by_name(hint) == 0) { argon2_select_impl(); } +# endif selected = true; implName = argon2_get_impl_name(); From 2e34bf7a1b47336914d8f48b3cd7dfddcd565a06 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 9 May 2020 01:36:57 +0700 Subject: [PATCH 19/24] Removed unnecessary check. --- src/crypto/argon2/Impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/argon2/Impl.cpp b/src/crypto/argon2/Impl.cpp index 435f8b6d8..f032cb277 100644 --- a/src/crypto/argon2/Impl.cpp +++ b/src/crypto/argon2/Impl.cpp @@ -54,7 +54,7 @@ extern int xmrig_ar2_check_sse2(); bool xmrig::argon2::Impl::select(const String &nameHint, bool benchmark) { if (!selected) { -# if !defined(XMRIG_ARM) || defined(__x86_64__) || defined(_M_AMD64) +# if defined(__x86_64__) || defined(_M_AMD64) auto hint = nameHint; if (hint.isEmpty() && !benchmark) { From 65dc8f3d8565e3f818b6837ad28d19c0101481e9 Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 22 May 2020 12:00:18 +0700 Subject: [PATCH 20/24] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc4d96a72..5419edcf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v5.11.2 +- [#1664](https://github.com/xmrig/xmrig/pull/1664) Improved JSON config error reporting. +- [#1668](https://github.com/xmrig/xmrig/pull/1668) Optimized RandomX dataset initialization. +- Fixed memory leak in HTTP client. + # v5.11.1 - [#1652](https://github.com/xmrig/xmrig/pull/1652) Up to 1% RandomX perfomance improvement on recent AMD CPUs. - [#1306](https://github.com/xmrig/xmrig/issues/1306) Fixed possible double connection to a pool. From 0d7820f61aa8097de30b5fa3c35d02a1b43a21fe Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 22 May 2020 19:14:38 +0700 Subject: [PATCH 21/24] Update build scripts. --- scripts/build.hwloc.sh | 19 +++++++++++++++++ scripts/build.libressl.sh | 20 ++++++++++++++++++ scripts/build.openssl.sh | 20 ++++++++++++++++++ scripts/build.uv.sh | 20 ++++++++++++++++++ scripts/build_deps.sh | 44 +++------------------------------------ 5 files changed, 82 insertions(+), 41 deletions(-) create mode 100755 scripts/build.hwloc.sh create mode 100755 scripts/build.libressl.sh create mode 100755 scripts/build.openssl.sh create mode 100755 scripts/build.uv.sh diff --git a/scripts/build.hwloc.sh b/scripts/build.hwloc.sh new file mode 100755 index 000000000..326b66409 --- /dev/null +++ b/scripts/build.hwloc.sh @@ -0,0 +1,19 @@ +#!/bin/bash -e + +HWLOC_VERSION="2.2.0" + +mkdir -p deps +mkdir -p deps/include +mkdir -p deps/lib + +mkdir -p build && cd build + +wget https://download.open-mpi.org/release/hwloc/v2.2/hwloc-${HWLOC_VERSION}.tar.bz2 -O hwloc-${HWLOC_VERSION}.tar.bz2 +tar -xjf hwloc-${HWLOC_VERSION}.tar.bz2 + +cd hwloc-${HWLOC_VERSION} +./configure --disable-shared --enable-static --disable-io --disable-libudev --disable-libxml2 +make -j$(nproc) +cp -fr include/ ../../deps +cp hwloc/.libs/libhwloc.a ../../deps/lib +cd .. \ No newline at end of file diff --git a/scripts/build.libressl.sh b/scripts/build.libressl.sh new file mode 100755 index 000000000..af7fe8227 --- /dev/null +++ b/scripts/build.libressl.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +LIBRESSL_VERSION="3.0.2" + +mkdir -p deps +mkdir -p deps/include +mkdir -p deps/lib + +mkdir -p build && cd build + +wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRESSL_VERSION}.tar.gz -O libressl-${LIBRESSL_VERSION}.tar.gz +tar -xzf libressl-${LIBRESSL_VERSION}.tar.gz + +cd libressl-${LIBRESSL_VERSION} +./configure --disable-shared +make -j$(nproc) +cp -fr include/ ../../deps +cp crypto/.libs/libcrypto.a ../../deps/lib +cp ssl/.libs/libssl.a ../../deps/lib +cd .. \ No newline at end of file diff --git a/scripts/build.openssl.sh b/scripts/build.openssl.sh new file mode 100755 index 000000000..5939eb57f --- /dev/null +++ b/scripts/build.openssl.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +OPENSSL_VERSION="1.1.1g" + +mkdir -p deps +mkdir -p deps/include +mkdir -p deps/lib + +mkdir -p build && cd build + +wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz -O openssl-${OPENSSL_VERSION}.tar.gz +tar -xzf openssl-${OPENSSL_VERSION}.tar.gz + +cd openssl-${OPENSSL_VERSION} +./config -no-shared -no-asm -no-zlib -no-comp -no-dgram -no-filenames -no-cms +make -j$(nproc) +cp -fr include/ ../../deps +cp libcrypto.a ../../deps/lib +cp libssl.a ../../deps/lib +cd .. \ No newline at end of file diff --git a/scripts/build.uv.sh b/scripts/build.uv.sh new file mode 100755 index 000000000..425904979 --- /dev/null +++ b/scripts/build.uv.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +UV_VERSION="1.38.0" + +mkdir -p deps +mkdir -p deps/include +mkdir -p deps/lib + +mkdir -p build && cd build + +wget https://github.com/libuv/libuv/archive/v${UV_VERSION}.tar.gz -O v${UV_VERSION}.tar.gz +tar -xzf v${UV_VERSION}.tar.gz + +cd libuv-${UV_VERSION} +sh autogen.sh +./configure --disable-shared +make -j$(nproc) +cp -fr include/ ../../deps +cp .libs/libuv.a ../../deps/lib +cd .. \ No newline at end of file diff --git a/scripts/build_deps.sh b/scripts/build_deps.sh index 7c4fc3dad..e3efbf23d 100755 --- a/scripts/build_deps.sh +++ b/scripts/build_deps.sh @@ -1,43 +1,5 @@ #!/bin/bash -e -UV_VERSION="1.34.0" -OPENSSL_VERSION="1.1.1d" -HWLOC_VERSION="2.1.0" - -mkdir deps -mkdir deps/include -mkdir deps/lib - -mkdir build && cd build - -wget https://github.com/libuv/libuv/archive/v${UV_VERSION}.tar.gz -tar -xzf v${UV_VERSION}.tar.gz - -wget https://download.open-mpi.org/release/hwloc/v2.1/hwloc-${HWLOC_VERSION}.tar.bz2 -tar -xjf hwloc-${HWLOC_VERSION}.tar.bz2 - -wget https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz -tar -xzf openssl-${OPENSSL_VERSION}.tar.gz - -cd libuv-${UV_VERSION} -sh autogen.sh -./configure --disable-shared -make -j$(nproc) -cp -fr include/ ../../deps -cp .libs/libuv.a ../../deps/lib -cd .. - -cd hwloc-${HWLOC_VERSION} -./configure --disable-shared --enable-static --disable-io --disable-libudev --disable-libxml2 -make -j$(nproc) -cp -fr include/ ../../deps -cp hwloc/.libs/libhwloc.a ../../deps/lib -cd .. - -cd openssl-${OPENSSL_VERSION} -./config -no-shared -no-asm -no-zlib -no-comp -no-dgram -no-filenames -no-cms -make -j$(nproc) -cp -fr include/ ../../deps -cp libcrypto.a ../../deps/lib -cp libssl.a ../../deps/lib -cd ../.. \ No newline at end of file +./build.uv.sh +./build.hwloc.sh +./build.openssl.sh \ No newline at end of file From 52e2890824bad1bf69b1a3fae22c855640ee801e Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 22 May 2020 20:47:12 +0700 Subject: [PATCH 22/24] Update hwloc for MSVC builds. --- src/3rdparty/hwloc/NEWS | 23 ++- src/3rdparty/hwloc/VERSION | 6 +- src/3rdparty/hwloc/include/hwloc.h | 35 ++-- .../hwloc/include/hwloc/autogen/config.h | 6 +- src/3rdparty/hwloc/include/hwloc/helper.h | 46 ++++-- src/3rdparty/hwloc/include/hwloc/opencl.h | 13 +- src/3rdparty/hwloc/include/hwloc/plugins.h | 18 ++- src/3rdparty/hwloc/include/hwloc/rename.h | 11 +- src/3rdparty/hwloc/include/private/private.h | 6 +- src/3rdparty/hwloc/src/bitmap.c | 6 +- src/3rdparty/hwloc/src/components.c | 153 ++++++++++++++++-- src/3rdparty/hwloc/src/distances.c | 2 + src/3rdparty/hwloc/src/pci-common.c | 4 +- src/3rdparty/hwloc/src/topology-noos.c | 29 ++-- src/3rdparty/hwloc/src/topology-synthetic.c | 1 + src/3rdparty/hwloc/src/topology-windows.c | 18 ++- .../hwloc/src/topology-xml-nolibxml.c | 8 +- src/3rdparty/hwloc/src/topology-xml.c | 68 ++++++-- src/3rdparty/hwloc/src/topology.c | 97 +++++++++-- 19 files changed, 435 insertions(+), 115 deletions(-) diff --git a/src/3rdparty/hwloc/NEWS b/src/3rdparty/hwloc/NEWS index 99809e6a3..0dfe28dfe 100644 --- a/src/3rdparty/hwloc/NEWS +++ b/src/3rdparty/hwloc/NEWS @@ -1,5 +1,5 @@ Copyright © 2009 CNRS -Copyright © 2009-2019 Inria. All rights reserved. +Copyright © 2009-2020 Inria. All rights reserved. Copyright © 2009-2013 Université Bordeaux Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. @@ -16,6 +16,27 @@ bug fixes (and other actions) for each version of hwloc since version 0.9. +Version 2.2.0 +------------- +* API + + Add hwloc_bitmap_singlify_by_core() to remove SMT from a given cpuset, + thanks to Florian Reynier for the suggestion. + + Add --enable-32bits-pci-domain to stop ignoring PCI devices with domain + >16bits (e.g. 10000:02:03.4). Enabling this option breaks the library ABI. + Thanks to Dylan Simon for the help. +* Backends + + Add support for Linux cgroups v2. + + Add NUMA support for FreeBSD. + + Add get_last_cpu_location support for FreeBSD. + + Remove support for Intel Xeon Phi (MIC, Knights Corner) co-processors. +* Tools + + Add --uid to filter the hwloc-ps output by uid on Linux. + + Add a GRAPHICAL OUTPUT section in the manpage of lstopo. +* Misc + + Use the native dlopen instead of libltdl, + unless --disable-plugin-dlopen is passed at configure time. + + Version 2.1.0 ------------- * API diff --git a/src/3rdparty/hwloc/VERSION b/src/3rdparty/hwloc/VERSION index 9035ed9cc..e182793d9 100644 --- a/src/3rdparty/hwloc/VERSION +++ b/src/3rdparty/hwloc/VERSION @@ -8,7 +8,7 @@ # Please update HWLOC_VERSION* in contrib/windows/hwloc_config.h too. major=2 -minor=1 +minor=2 release=0 # greek is used for alpha or beta release tags. If it is non-empty, @@ -22,7 +22,7 @@ greek= # The date when this release was created -date="Sep 30, 2019" +date="Mar 30, 2020" # If snapshot=1, then use the value from snapshot_version as the # entire hwloc version (i.e., ignore major, minor, release, and @@ -41,7 +41,7 @@ snapshot_version=${major}.${minor}.${release}${greek}-git # 2. Version numbers are described in the Libtool current:revision:age # format. -libhwloc_so_version=16:0:1 +libhwloc_so_version=17:0:2 libnetloc_so_version=0:0:0 # Please also update the lines in contrib/windows/libhwloc.vcxproj diff --git a/src/3rdparty/hwloc/include/hwloc.h b/src/3rdparty/hwloc/include/hwloc.h index e106e9cc0..01b42fdc0 100644 --- a/src/3rdparty/hwloc/include/hwloc.h +++ b/src/3rdparty/hwloc/include/hwloc.h @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2019 Inria. All rights reserved. + * Copyright © 2009-2020 Inria. All rights reserved. * Copyright © 2009-2012 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -173,8 +173,12 @@ typedef hwloc_const_bitmap_t hwloc_const_nodeset_t; * may be defined in the future! If you need to compare types, use * hwloc_compare_types() instead. */ -#define HWLOC_OBJ_TYPE_MIN HWLOC_OBJ_MACHINE /**< \private Sentinel value */ typedef enum { + +/** \cond */ +#define HWLOC_OBJ_TYPE_MIN HWLOC_OBJ_MACHINE /* Sentinel value */ +/** \endcond */ + HWLOC_OBJ_MACHINE, /**< \brief Machine. * A set of processors and memory with cache * coherency. @@ -251,7 +255,7 @@ typedef enum { */ HWLOC_OBJ_BRIDGE, /**< \brief Bridge (filtered out by default). - * Any bridge that connects the host or an I/O bus, + * Any bridge (or PCI switch) that connects the host or an I/O bus, * to another I/O bus. * They are not added to the topology unless I/O discovery * is enabled with hwloc_topology_set_flags(). @@ -360,9 +364,8 @@ typedef enum hwloc_obj_osdev_type_e { */ HWLOC_DECLSPEC int hwloc_compare_types (hwloc_obj_type_t type1, hwloc_obj_type_t type2) __hwloc_attribute_const; -enum hwloc_compare_types_e { - HWLOC_TYPE_UNORDERED = INT_MAX /**< \brief Value returned by hwloc_compare_types() when types can not be compared. \hideinitializer */ -}; +/** \brief Value returned by hwloc_compare_types() when types can not be compared. \hideinitializer */ +#define HWLOC_TYPE_UNORDERED INT_MAX /** @} */ @@ -614,7 +617,11 @@ union hwloc_obj_attr_u { } group; /** \brief PCI Device specific Object Attributes */ struct hwloc_pcidev_attr_s { - unsigned short domain; +#ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN + unsigned short domain; /* Only 16bits PCI domains are supported by default */ +#else + unsigned int domain; /* 32bits PCI domain support break the library ABI, hence it's disabled by default */ +#endif unsigned char bus, dev, func; unsigned short class_id; unsigned short vendor_id, device_id, subvendor_id, subdevice_id; @@ -629,7 +636,11 @@ union hwloc_obj_attr_u { hwloc_obj_bridge_type_t upstream_type; union { struct { - unsigned short domain; +#ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN + unsigned short domain; /* Only 16bits PCI domains are supported by default */ +#else + unsigned int domain; /* 32bits PCI domain support break the library ABI, hence it's disabled by default */ +#endif unsigned char secondary_bus, subordinate_bus; } pci; } downstream; @@ -859,7 +870,8 @@ hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type) /** \brief Returns the type of objects at depth \p depth. * - * \p depth should between 0 and hwloc_topology_get_depth()-1. + * \p depth should between 0 and hwloc_topology_get_depth()-1, + * or a virtual depth such as ::HWLOC_TYPE_DEPTH_NUMANODE. * * \return (hwloc_obj_type_t)-1 if depth \p depth does not exist. */ @@ -1355,7 +1367,7 @@ HWLOC_DECLSPEC int hwloc_get_proc_last_cpu_location(hwloc_topology_t topology, h typedef enum { /** \brief Reset the memory allocation policy to the system default. * Depending on the operating system, this may correspond to - * ::HWLOC_MEMBIND_FIRSTTOUCH (Linux), + * ::HWLOC_MEMBIND_FIRSTTOUCH (Linux, FreeBSD), * or ::HWLOC_MEMBIND_BIND (AIX, HP-UX, Solaris, Windows). * This policy is never returned by get membind functions. * The nodeset argument is ignored. @@ -2169,13 +2181,14 @@ HWLOC_DECLSPEC void * hwloc_topology_get_userdata(hwloc_topology_t topology); enum hwloc_restrict_flags_e { /** \brief Remove all objects that became CPU-less. * By default, only objects that contain no PU and no memory are removed. + * This flag may not be used with ::HWLOC_RESTRICT_FLAG_BYNODESET. * \hideinitializer */ HWLOC_RESTRICT_FLAG_REMOVE_CPULESS = (1UL<<0), /** \brief Restrict by nodeset instead of CPU set. * Only keep objects whose nodeset is included or partially included in the given set. - * This flag may not be used with ::HWLOC_RESTRICT_FLAG_BYNODESET. + * This flag may not be used with ::HWLOC_RESTRICT_FLAG_REMOVE_CPULESS. */ HWLOC_RESTRICT_FLAG_BYNODESET = (1UL<<3), diff --git a/src/3rdparty/hwloc/include/hwloc/autogen/config.h b/src/3rdparty/hwloc/include/hwloc/autogen/config.h index 36669de55..06963b364 100644 --- a/src/3rdparty/hwloc/include/hwloc/autogen/config.h +++ b/src/3rdparty/hwloc/include/hwloc/autogen/config.h @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2018 Inria. All rights reserved. + * Copyright © 2009-2019 Inria. All rights reserved. * Copyright © 2009-2012 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -11,9 +11,9 @@ #ifndef HWLOC_CONFIG_H #define HWLOC_CONFIG_H -#define HWLOC_VERSION "2.1.0" +#define HWLOC_VERSION "2.2.0" #define HWLOC_VERSION_MAJOR 2 -#define HWLOC_VERSION_MINOR 1 +#define HWLOC_VERSION_MINOR 2 #define HWLOC_VERSION_RELEASE 0 #define HWLOC_VERSION_GREEK "" diff --git a/src/3rdparty/hwloc/include/hwloc/helper.h b/src/3rdparty/hwloc/include/hwloc/helper.h index bc27be591..3df648433 100644 --- a/src/3rdparty/hwloc/include/hwloc/helper.h +++ b/src/3rdparty/hwloc/include/hwloc/helper.h @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2019 Inria. All rights reserved. + * Copyright © 2009-2020 Inria. All rights reserved. * Copyright © 2009-2012 Université Bordeaux * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -672,6 +672,24 @@ hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute * package has fewer caches than its peers. */ +/** \brief Remove simultaneous multithreading PUs from a CPU set. + * + * For each core in \p topology, if \p cpuset contains some PUs of that core, + * modify \p cpuset to only keep a single PU for that core. + * + * \p which specifies which PU will be kept. + * PU are considered in physical index order. + * If 0, for each core, the function keeps the first PU that was originally set in \p cpuset. + * + * If \p which is larger than the number of PUs in a core there were originally set in \p cpuset, + * no PU is kept for that core. + * + * \note PUs that are not below a Core object are ignored + * (for instance if the topology does not contain any Core object). + * None of them is removed from \p cpuset. + */ +HWLOC_DECLSPEC int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which); + /** \brief Returns the object of type ::HWLOC_OBJ_PU with \p os_index. * * This function is useful for converting a CPU set into the PU @@ -998,15 +1016,16 @@ hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_ * @{ */ -/** \brief Convert a CPU set into a NUMA node set and handle non-NUMA cases +/** \brief Convert a CPU set into a NUMA node set + * + * For each PU included in the input \p _cpuset, set the corresponding + * local NUMA node(s) in the output \p nodeset. * * If some NUMA nodes have no CPUs at all, this function never sets their * indexes in the output node set, even if a full CPU set is given in input. * - * If the topology contains no NUMA nodes, the machine is considered - * as a single memory node, and the following behavior is used: - * If \p cpuset is empty, \p nodeset will be emptied as well. - * Otherwise \p nodeset will be entirely filled. + * Hence the entire topology CPU set is converted into the set of all nodes + * that have some local CPUs. */ static __hwloc_inline int hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset) @@ -1021,13 +1040,16 @@ hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, return 0; } -/** \brief Convert a NUMA node set into a CPU set and handle non-NUMA cases +/** \brief Convert a NUMA node set into a CPU set * - * If the topology contains no NUMA nodes, the machine is considered - * as a single memory node, and the following behavior is used: - * If \p nodeset is empty, \p cpuset will be emptied as well. - * Otherwise \p cpuset will be entirely filled. - * This is useful for manipulating memory binding sets. + * For each NUMA node included in the input \p nodeset, set the corresponding + * local PUs in the output \p _cpuset. + * + * If some CPUs have no local NUMA nodes, this function never sets their + * indexes in the output CPU set, even if a full node set is given in input. + * + * Hence the entire topology node set is converted into the set of all CPUs + * that have some local NUMA nodes. */ static __hwloc_inline int hwloc_cpuset_from_nodeset(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset) diff --git a/src/3rdparty/hwloc/include/hwloc/opencl.h b/src/3rdparty/hwloc/include/hwloc/opencl.h index ebf09848f..99dfb0c8e 100644 --- a/src/3rdparty/hwloc/include/hwloc/opencl.h +++ b/src/3rdparty/hwloc/include/hwloc/opencl.h @@ -1,5 +1,5 @@ /* - * Copyright © 2012-2018 Inria. All rights reserved. + * Copyright © 2012-2019 Inria. All rights reserved. * Copyright © 2013, 2018 Université Bordeaux. All right reserved. * See COPYING in top-level directory. */ @@ -52,6 +52,7 @@ typedef union { /* needs "cl_nv_device_attribute_query" device extension, but not strictly required for clGetDeviceInfo() */ #define HWLOC_CL_DEVICE_PCI_BUS_ID_NV 0x4008 #define HWLOC_CL_DEVICE_PCI_SLOT_ID_NV 0x4009 +#define HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV 0x400A /** \defgroup hwlocality_opencl Interoperability with OpenCL @@ -74,7 +75,7 @@ hwloc_opencl_get_device_pci_busid(cl_device_id device, unsigned *domain, unsigned *bus, unsigned *dev, unsigned *func) { hwloc_cl_device_topology_amd amdtopo; - cl_uint nvbus, nvslot; + cl_uint nvbus, nvslot, nvdomain; cl_int clret; clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_TOPOLOGY_AMD, sizeof(amdtopo), &amdtopo, NULL); @@ -91,8 +92,12 @@ hwloc_opencl_get_device_pci_busid(cl_device_id device, if (CL_SUCCESS == clret) { clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_SLOT_ID_NV, sizeof(nvslot), &nvslot, NULL); if (CL_SUCCESS == clret) { - /* FIXME: PCI bus only uses 8bit, assume nvidia hardcodes the domain in higher bits */ - *domain = nvbus >> 8; + clret = clGetDeviceInfo(device, HWLOC_CL_DEVICE_PCI_DOMAIN_ID_NV, sizeof(nvdomain), &nvdomain, NULL); + if (CL_SUCCESS == clret) { /* available since CUDA 10.2 */ + *domain = nvdomain; + } else { + *domain = 0; + } *bus = nvbus & 0xff; /* non-documented but used in many other projects */ *dev = nvslot >> 3; diff --git a/src/3rdparty/hwloc/include/hwloc/plugins.h b/src/3rdparty/hwloc/include/hwloc/plugins.h index 0f53ac4d4..88faf538b 100644 --- a/src/3rdparty/hwloc/include/hwloc/plugins.h +++ b/src/3rdparty/hwloc/include/hwloc/plugins.h @@ -1,5 +1,5 @@ /* - * Copyright © 2013-2019 Inria. All rights reserved. + * Copyright © 2013-2020 Inria. All rights reserved. * Copyright © 2016 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. */ @@ -17,7 +17,11 @@ struct hwloc_backend; #ifdef HWLOC_INSIDE_PLUGIN /* needed for hwloc_plugin_check_namespace() */ +#ifdef HWLOC_HAVE_LTDL #include +#else +#include +#endif #endif @@ -418,14 +422,22 @@ static __hwloc_inline int hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused) { #ifdef HWLOC_INSIDE_PLUGIN - lt_dlhandle handle; void *sym; - handle = lt_dlopen(NULL); +#ifdef HWLOC_HAVE_LTDL + lt_dlhandle handle = lt_dlopen(NULL); +#else + void *handle = dlopen(NULL, RTLD_NOW|RTLD_LOCAL); +#endif if (!handle) /* cannot check, assume things will work */ return 0; +#ifdef HWLOC_HAVE_LTDL sym = lt_dlsym(handle, symbol); lt_dlclose(handle); +#else + sym = dlsym(handle, symbol); + dlclose(handle); +#endif if (!sym) { static int verboseenv_checked = 0; static int verboseenv_value = 0; diff --git a/src/3rdparty/hwloc/include/hwloc/rename.h b/src/3rdparty/hwloc/include/hwloc/rename.h index a23738d0d..224e25779 100644 --- a/src/3rdparty/hwloc/include/hwloc/rename.h +++ b/src/3rdparty/hwloc/include/hwloc/rename.h @@ -28,6 +28,7 @@ extern "C" { #define HWLOC_MUNGE_NAME(a, b) HWLOC_MUNGE_NAME2(a, b) #define HWLOC_MUNGE_NAME2(a, b) a ## b #define HWLOC_NAME(name) HWLOC_MUNGE_NAME(HWLOC_SYM_PREFIX, hwloc_ ## name) +/* FIXME: should be "HWLOC_ ## name" below, unchanged because it doesn't matter much and could break some embedders hacks */ #define HWLOC_NAME_CAPS(name) HWLOC_MUNGE_NAME(HWLOC_SYM_PREFIX_CAPS, hwloc_ ## name) /* Now define all the "real" names to be the prefixed names. This @@ -92,9 +93,6 @@ extern "C" { #define hwloc_compare_types HWLOC_NAME(compare_types) -#define hwloc_compare_types_e HWLOC_NAME(compare_types_e) -#define HWLOC_TYPE_UNORDERED HWLOC_NAME_CAPS(TYPE_UNORDERED) - #define hwloc_obj HWLOC_NAME(obj) #define hwloc_obj_t HWLOC_NAME(obj_t) @@ -324,6 +322,7 @@ extern "C" { #define hwloc_get_ancestor_obj_by_type HWLOC_NAME(get_ancestor_obj_by_type) #define hwloc_get_next_obj_by_depth HWLOC_NAME(get_next_obj_by_depth) #define hwloc_get_next_obj_by_type HWLOC_NAME(get_next_obj_by_type) +#define hwloc_bitmap_singlify_per_core HWLOC_NAME(bitmap_singlify_by_core) #define hwloc_get_pu_obj_by_os_index HWLOC_NAME(get_pu_obj_by_os_index) #define hwloc_get_numanode_obj_by_os_index HWLOC_NAME(get_numanode_obj_by_os_index) #define hwloc_get_next_child HWLOC_NAME(get_next_child) @@ -482,11 +481,6 @@ extern "C" { #define hwloc_ibv_get_device_osdev HWLOC_NAME(ibv_get_device_osdev) #define hwloc_ibv_get_device_osdev_by_name HWLOC_NAME(ibv_get_device_osdev_by_name) -/* intel-mic.h */ - -#define hwloc_intel_mic_get_device_cpuset HWLOC_NAME(intel_mic_get_device_cpuset) -#define hwloc_intel_mic_get_device_osdev_by_index HWLOC_NAME(intel_mic_get_device_osdev_by_index) - /* opencl.h */ #define hwloc_cl_device_topology_amd HWLOC_NAME(cl_device_topology_amd) @@ -709,6 +703,7 @@ extern "C" { #define hwloc_get_sysctlbyname HWLOC_NAME(get_sysctlbyname) #define hwloc_get_sysctl HWLOC_NAME(get_sysctl) #define hwloc_fallback_nbprocessors HWLOC_NAME(fallback_nbprocessors) +#define hwloc_fallback_memsize HWLOC_NAME(fallback_memsize) #define hwloc__object_cpusets_compare_first HWLOC_NAME(_object_cpusets_compare_first) #define hwloc__reorder_children HWLOC_NAME(_reorder_children) diff --git a/src/3rdparty/hwloc/include/private/private.h b/src/3rdparty/hwloc/include/private/private.h index 5f8789376..84d95bb30 100644 --- a/src/3rdparty/hwloc/include/private/private.h +++ b/src/3rdparty/hwloc/include/private/private.h @@ -1,7 +1,7 @@ /* * Copyright © 2009 CNRS * Copyright © 2009-2019 Inria. All rights reserved. - * Copyright © 2009-2012 Université Bordeaux + * Copyright © 2009-2012, 2020 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * * See COPYING in top-level directory. @@ -224,11 +224,13 @@ struct hwloc_topology { extern void hwloc_alloc_root_sets(hwloc_obj_t root); extern void hwloc_setup_pu_level(struct hwloc_topology *topology, unsigned nb_pus); extern int hwloc_get_sysctlbyname(const char *name, int64_t *n); -extern int hwloc_get_sysctl(int name[], unsigned namelen, int *n); +extern int hwloc_get_sysctl(int name[], unsigned namelen, int64_t *n); /* returns the number of CPU from the OS (only valid if thissystem) */ #define HWLOC_FALLBACK_NBPROCESSORS_INCLUDE_OFFLINE 1 /* by default we try to get only the online CPUs */ extern int hwloc_fallback_nbprocessors(unsigned flags); +/* returns the memory size from the OS (only valid if thissystem) */ +extern int64_t hwloc_fallback_memsize(void); extern int hwloc__object_cpusets_compare_first(hwloc_obj_t obj1, hwloc_obj_t obj2); extern void hwloc__reorder_children(hwloc_obj_t parent); diff --git a/src/3rdparty/hwloc/src/bitmap.c b/src/3rdparty/hwloc/src/bitmap.c index 5fb9cd356..4791a6942 100644 --- a/src/3rdparty/hwloc/src/bitmap.c +++ b/src/3rdparty/hwloc/src/bitmap.c @@ -505,14 +505,16 @@ int hwloc_bitmap_list_sscanf(struct hwloc_bitmap_s *set, const char * __hwloc_re if (begin != -1) { /* finishing a range */ - hwloc_bitmap_set_range(set, begin, val); + if (hwloc_bitmap_set_range(set, begin, val) < 0) + goto failed; begin = -1; } else if (*next == '-') { /* starting a new range */ if (*(next+1) == '\0') { /* infinite range */ - hwloc_bitmap_set_range(set, val, -1); + if (hwloc_bitmap_set_range(set, val, -1) < 0) + goto failed; break; } else { /* normal range */ diff --git a/src/3rdparty/hwloc/src/components.c b/src/3rdparty/hwloc/src/components.c index 5c2879b64..496ed2322 100644 --- a/src/3rdparty/hwloc/src/components.c +++ b/src/3rdparty/hwloc/src/components.c @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2019 Inria. All rights reserved. + * Copyright © 2009-2020 Inria. All rights reserved. * Copyright © 2012 Université Bordeaux * See COPYING in top-level directory. */ @@ -63,14 +63,128 @@ static pthread_mutex_t hwloc_components_mutex = PTHREAD_MUTEX_INITIALIZER; #ifdef HWLOC_HAVE_PLUGINS +#ifdef HWLOC_HAVE_LTDL +/* ltdl-based plugin load */ #include +typedef lt_dlhandle hwloc_dlhandle; +#define hwloc_dlinit lt_dlinit +#define hwloc_dlexit lt_dlexit +#define hwloc_dlopenext lt_dlopenext +#define hwloc_dlclose lt_dlclose +#define hwloc_dlerror lt_dlerror +#define hwloc_dlsym lt_dlsym +#define hwloc_dlforeachfile lt_dlforeachfile + +#else /* !HWLOC_HAVE_LTDL */ +/* no-ltdl plugin load relies on less portable libdl */ +#include +typedef void * hwloc_dlhandle; +static __hwloc_inline int hwloc_dlinit(void) { return 0; } +static __hwloc_inline int hwloc_dlexit(void) { return 0; } +#define hwloc_dlclose dlclose +#define hwloc_dlerror dlerror +#define hwloc_dlsym dlsym + +#include +#include +#include +#include + +static hwloc_dlhandle hwloc_dlopenext(const char *_filename) +{ + hwloc_dlhandle handle; + char *filename = NULL; + (void) asprintf(&filename, "%s.so", _filename); + if (!filename) + return NULL; + handle = dlopen(filename, RTLD_NOW|RTLD_LOCAL); + free(filename); + return handle; +} + +static int +hwloc_dlforeachfile(const char *_paths, + int (*func)(const char *filename, void *data), + void *data) +{ + char *paths = NULL, *path; + + paths = strdup(_paths); + if (!paths) + return -1; + + path = paths; + while (*path) { + char *colon; + DIR *dir; + struct dirent *dirent; + + colon = strchr(path, ':'); + if (colon) + *colon = '\0'; + + if (hwloc_plugins_verbose) + fprintf(stderr, " Looking under %s\n", path); + + dir = opendir(path); + if (!dir) + goto next; + + while ((dirent = readdir(dir)) != NULL) { + char *abs_name, *suffix; + struct stat stbuf; + int err; + + err = asprintf(&abs_name, "%s/%s", path, dirent->d_name); + if (err < 0) + continue; + + err = stat(abs_name, &stbuf); + if (err < 0) { + free(abs_name); + continue; + } + if (!S_ISREG(stbuf.st_mode)) { + free(abs_name); + continue; + } + + /* Only keep .so files, and remove that suffix to get the component basename */ + suffix = strrchr(abs_name, '.'); + if (!suffix || strcmp(suffix, ".so")) { + free(abs_name); + continue; + } + *suffix = '\0'; + + err = func(abs_name, data); + if (err) { + free(abs_name); + continue; + } + + free(abs_name); + } + + closedir(dir); + + next: + if (!colon) + break; + path = colon+1; + } + + free(paths); + return 0; +} +#endif /* !HWLOC_HAVE_LTDL */ /* array of pointers to dynamically loaded plugins */ static struct hwloc__plugin_desc { char *name; struct hwloc_component *component; char *filename; - lt_dlhandle handle; + hwloc_dlhandle handle; struct hwloc__plugin_desc *next; } *hwloc_plugins = NULL; @@ -78,9 +192,10 @@ static int hwloc__dlforeach_cb(const char *filename, void *_data __hwloc_attribute_unused) { const char *basename; - lt_dlhandle handle; + hwloc_dlhandle handle; struct hwloc_component *component; struct hwloc__plugin_desc *desc, **prevdesc; + char *componentsymbolname; if (hwloc_plugins_verbose) fprintf(stderr, "Plugin dlforeach found `%s'\n", filename); @@ -98,33 +213,40 @@ hwloc__dlforeach_cb(const char *filename, void *_data __hwloc_attribute_unused) } /* dlopen and get the component structure */ - handle = lt_dlopenext(filename); + handle = hwloc_dlopenext(filename); if (!handle) { if (hwloc_plugins_verbose) - fprintf(stderr, "Failed to load plugin: %s\n", lt_dlerror()); + fprintf(stderr, "Failed to load plugin: %s\n", hwloc_dlerror()); goto out; } -{ - char componentsymbolname[strlen(basename)+10+1]; + componentsymbolname = malloc(strlen(basename)+10+1); + if (!componentsymbolname) { + if (hwloc_plugins_verbose) + fprintf(stderr, "Failed to allocation component `%s' symbol\n", + basename); + goto out_with_handle; + } sprintf(componentsymbolname, "%s_component", basename); - component = lt_dlsym(handle, componentsymbolname); + component = hwloc_dlsym(handle, componentsymbolname); if (!component) { if (hwloc_plugins_verbose) fprintf(stderr, "Failed to find component symbol `%s'\n", componentsymbolname); + free(componentsymbolname); goto out_with_handle; } if (component->abi != HWLOC_COMPONENT_ABI) { if (hwloc_plugins_verbose) fprintf(stderr, "Plugin symbol ABI %u instead of %d\n", component->abi, HWLOC_COMPONENT_ABI); + free(componentsymbolname); goto out_with_handle; } if (hwloc_plugins_verbose) fprintf(stderr, "Plugin contains expected symbol `%s'\n", componentsymbolname); -} + free(componentsymbolname); if (HWLOC_COMPONENT_TYPE_DISC == component->type) { if (strncmp(basename, "hwloc_", 6)) { @@ -167,7 +289,7 @@ hwloc__dlforeach_cb(const char *filename, void *_data __hwloc_attribute_unused) return 0; out_with_handle: - lt_dlclose(handle); + hwloc_dlclose(handle); out: return 0; } @@ -183,7 +305,7 @@ hwloc_plugins_exit(void) desc = hwloc_plugins; while (desc) { next = desc->next; - lt_dlclose(desc->handle); + hwloc_dlclose(desc->handle); free(desc->name); free(desc->filename); free(desc); @@ -191,7 +313,7 @@ hwloc_plugins_exit(void) } hwloc_plugins = NULL; - lt_dlexit(); + hwloc_dlexit(); } static int @@ -207,7 +329,7 @@ hwloc_plugins_init(void) hwloc_plugins_blacklist = getenv("HWLOC_PLUGINS_BLACKLIST"); - err = lt_dlinit(); + err = hwloc_dlinit(); if (err) goto out; @@ -219,7 +341,7 @@ hwloc_plugins_init(void) if (hwloc_plugins_verbose) fprintf(stderr, "Starting plugin dlforeach in %s\n", path); - err = lt_dlforeachfile(path, hwloc__dlforeach_cb, NULL); + err = hwloc_dlforeachfile(path, hwloc__dlforeach_cb, NULL); if (err) goto out_with_init; @@ -680,7 +802,8 @@ hwloc_disc_components_enable_others(struct hwloc_topology *topology) while (*curenv) { s = strcspn(curenv, HWLOC_COMPONENT_SEPS); if (s) { - char c, *name; + char c; + const char *name; if (!strncmp(curenv, HWLOC_COMPONENT_STOP_NAME, s)) { tryall = 0; diff --git a/src/3rdparty/hwloc/src/distances.c b/src/3rdparty/hwloc/src/distances.c index 9e56a9696..4f2897a01 100644 --- a/src/3rdparty/hwloc/src/distances.c +++ b/src/3rdparty/hwloc/src/distances.c @@ -323,6 +323,8 @@ hwloc_internal_distances__add(hwloc_topology_t topology, const char *name, return 0; err_with_dist: + if (name) + free(dist->name); free(dist); err: free(different_types); diff --git a/src/3rdparty/hwloc/src/pci-common.c b/src/3rdparty/hwloc/src/pci-common.c index deca5cce5..a817c8da2 100644 --- a/src/3rdparty/hwloc/src/pci-common.c +++ b/src/3rdparty/hwloc/src/pci-common.c @@ -1,5 +1,5 @@ /* - * Copyright © 2009-2019 Inria. All rights reserved. + * Copyright © 2009-2020 Inria. All rights reserved. * See COPYING in top-level directory. */ @@ -366,7 +366,7 @@ hwloc_pcidisc_add_hostbridges(struct hwloc_topology *topology, struct hwloc_obj **dstnextp; struct hwloc_obj **srcnextp; struct hwloc_obj *child; - unsigned short current_domain; + unsigned current_domain; unsigned char current_bus; unsigned char current_subordinate; diff --git a/src/3rdparty/hwloc/src/topology-noos.c b/src/3rdparty/hwloc/src/topology-noos.c index 174b6fd8c..2658750aa 100644 --- a/src/3rdparty/hwloc/src/topology-noos.c +++ b/src/3rdparty/hwloc/src/topology-noos.c @@ -1,7 +1,7 @@ /* * Copyright © 2009 CNRS * Copyright © 2009-2019 Inria. All rights reserved. - * Copyright © 2009-2012 Université Bordeaux + * Copyright © 2009-2012, 2020 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. */ @@ -20,22 +20,27 @@ hwloc_look_noos(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus */ struct hwloc_topology *topology = backend->topology; - int nbprocs; + int64_t memsize; assert(dstatus->phase == HWLOC_DISC_PHASE_CPU); - if (topology->levels[0][0]->cpuset) - /* somebody discovered things */ - return -1; + if (!topology->levels[0][0]->cpuset) { + int nbprocs; + /* Nobody (even the x86 backend) created objects yet, setup basic objects */ - nbprocs = hwloc_fallback_nbprocessors(0); - if (nbprocs >= 1) - topology->support.discovery->pu = 1; - else - nbprocs = 1; + nbprocs = hwloc_fallback_nbprocessors(0); + if (nbprocs >= 1) + topology->support.discovery->pu = 1; + else + nbprocs = 1; + hwloc_alloc_root_sets(topology->levels[0][0]); + hwloc_setup_pu_level(topology, nbprocs); + } + + memsize = hwloc_fallback_memsize(); + if (memsize > 0) + topology->machine_memory.local_memory = memsize;; - hwloc_alloc_root_sets(topology->levels[0][0]); - hwloc_setup_pu_level(topology, nbprocs); hwloc_add_uname_info(topology, NULL); return 0; } diff --git a/src/3rdparty/hwloc/src/topology-synthetic.c b/src/3rdparty/hwloc/src/topology-synthetic.c index 686efce1f..50092e476 100644 --- a/src/3rdparty/hwloc/src/topology-synthetic.c +++ b/src/3rdparty/hwloc/src/topology-synthetic.c @@ -1503,6 +1503,7 @@ hwloc_topology_export_synthetic(struct hwloc_topology * topology, signed pdepth; node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0); + assert(node); assert(hwloc__obj_type_is_normal(node->parent->type)); /* only depth-1 memory children for now */ pdepth = node->parent->depth; diff --git a/src/3rdparty/hwloc/src/topology-windows.c b/src/3rdparty/hwloc/src/topology-windows.c index 22521aa31..195e5e222 100644 --- a/src/3rdparty/hwloc/src/topology-windows.c +++ b/src/3rdparty/hwloc/src/topology-windows.c @@ -1,7 +1,7 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2019 Inria. All rights reserved. - * Copyright © 2009-2012 Université Bordeaux + * Copyright © 2009-2020 Inria. All rights reserved. + * Copyright © 2009-2012, 2020 Université Bordeaux * Copyright © 2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. */ @@ -232,6 +232,10 @@ static void hwloc_win_get_function_ptrs(void) { HMODULE kernel32; +#if HWLOC_HAVE_GCC_W_CAST_FUNCTION_TYPE +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif + kernel32 = LoadLibrary("kernel32.dll"); if (kernel32) { GetActiveProcessorGroupCountProc = @@ -270,6 +274,10 @@ static void hwloc_win_get_function_ptrs(void) if (psapi) QueryWorkingSetExProc = (PFN_QUERYWORKINGSETEX) GetProcAddress(psapi, "QueryWorkingSetEx"); } + +#if HWLOC_HAVE_GCC_W_CAST_FUNCTION_TYPE +#pragma GCC diagnostic warning "-Wcast-function-type" +#endif } /* @@ -1199,3 +1207,9 @@ hwloc_fallback_nbprocessors(unsigned flags __hwloc_attribute_unused) { return n; } + +int64_t +hwloc_fallback_memsize(void) { + /* Unused */ + return -1; +} diff --git a/src/3rdparty/hwloc/src/topology-xml-nolibxml.c b/src/3rdparty/hwloc/src/topology-xml-nolibxml.c index d0e9ec164..5a0006a01 100644 --- a/src/3rdparty/hwloc/src/topology-xml-nolibxml.c +++ b/src/3rdparty/hwloc/src/topology-xml-nolibxml.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2019 Inria. All rights reserved. + * Copyright © 2009-2020 Inria. All rights reserved. * Copyright © 2009-2011 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -34,7 +34,7 @@ struct hwloc__nolibxml_backend_data_s { typedef struct hwloc__nolibxml_import_state_data_s { char *tagbuffer; /* buffer containing the next tag */ char *attrbuffer; /* buffer containing the next attribute of the current node */ - char *tagname; /* tag name of the current node */ + const char *tagname; /* tag name of the current node */ int closed; /* set if the current node is auto-closing */ } __hwloc_attribute_may_alias * hwloc__nolibxml_import_state_data_t; @@ -137,7 +137,7 @@ hwloc__nolibxml_import_find_child(hwloc__xml_import_state_t state, return 0; /* normal tag */ - tag = nchildstate->tagname = buffer; + nchildstate->tagname = tag = buffer; /* find the end, mark it and return it */ end = strchr(buffer, '>'); @@ -260,7 +260,7 @@ hwloc_nolibxml_look_init(struct hwloc_xml_backend_data_s *bdata, unsigned major, minor; char *end; char *buffer = nbdata->buffer; - char *tagname; + const char *tagname; HWLOC_BUILD_ASSERT(sizeof(*nstate) <= sizeof(state->data)); diff --git a/src/3rdparty/hwloc/src/topology-xml.c b/src/3rdparty/hwloc/src/topology-xml.c index f6bb210c9..ba242853f 100644 --- a/src/3rdparty/hwloc/src/topology-xml.c +++ b/src/3rdparty/hwloc/src/topology-xml.c @@ -1,6 +1,6 @@ /* * Copyright © 2009 CNRS - * Copyright © 2009-2019 Inria. All rights reserved. + * Copyright © 2009-2020 Inria. All rights reserved. * Copyright © 2009-2011 Université Bordeaux * Copyright © 2009-2018 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. @@ -107,7 +107,8 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology, struct hwloc_xml_backend_data_s *data, struct hwloc_obj *obj, const char *name, const char *value, - hwloc__xml_import_state_t state) + hwloc__xml_import_state_t state, + int *ignore) { if (!strcmp(name, "type")) { /* already handled */ @@ -252,11 +253,20 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology, case HWLOC_OBJ_PCI_DEVICE: case HWLOC_OBJ_BRIDGE: { unsigned domain, bus, dev, func; - if (sscanf(value, "%04x:%02x:%02x.%01x", + if (sscanf(value, "%x:%02x:%02x.%01x", &domain, &bus, &dev, &func) != 4) { if (hwloc__xml_verbose()) fprintf(stderr, "%s: ignoring invalid pci_busid format string %s\n", state->global->msgprefix, value); + *ignore = 1; +#ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN + } else if (domain > 0xffff) { + static int warned = 0; + if (!warned && !hwloc_hide_errors()) + fprintf(stderr, "Ignoring PCI device with non-16bit domain.\nPass --enable-32bits-pci-domain to configure to support such devices\n(warning: it would break the library ABI, don't enable unless really needed).\n"); + warned = 1; + *ignore = 1; +#endif } else { obj->attr->pcidev.domain = domain; obj->attr->pcidev.bus = bus; @@ -278,7 +288,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology, case HWLOC_OBJ_PCI_DEVICE: case HWLOC_OBJ_BRIDGE: { unsigned classid, vendor, device, subvendor, subdevice, revision; - if (sscanf(value, "%04x [%04x:%04x] [%04x:%04x] %02x", + if (sscanf(value, "%x [%04x:%04x] [%04x:%04x] %02x", &classid, &vendor, &device, &subvendor, &subdevice, &revision) != 6) { if (hwloc__xml_verbose()) fprintf(stderr, "%s: ignoring invalid pci_type format string %s\n", @@ -342,11 +352,20 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology, switch (obj->type) { case HWLOC_OBJ_BRIDGE: { unsigned domain, secbus, subbus; - if (sscanf(value, "%04x:[%02x-%02x]", + if (sscanf(value, "%x:[%02x-%02x]", &domain, &secbus, &subbus) != 3) { if (hwloc__xml_verbose()) fprintf(stderr, "%s: ignoring invalid bridge_pci format string %s\n", state->global->msgprefix, value); + *ignore = 1; +#ifndef HWLOC_HAVE_32BITS_PCI_DOMAIN + } else if (domain > 0xffff) { + static int warned = 0; + if (!warned && !hwloc_hide_errors()) + fprintf(stderr, "Ignoring bridge to PCI with non-16bit domain.\nPass --enable-32bits-pci-domain to configure to support such devices\n(warning: it would break the library ABI, don't enable unless really needed).\n"); + warned = 1; + *ignore = 1; +#endif } else { obj->attr->bridge.downstream.pci.domain = domain; obj->attr->bridge.downstream.pci.secondary_bus = secbus; @@ -426,6 +445,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology, memory->page_types = malloc(sizeof(*memory->page_types)); memory->page_types_len = 1; } + assert(memory->page_types); memory->page_types[0].size = lvalue << 10; } else if (hwloc__xml_verbose()) { fprintf(stderr, "%s: ignoring huge_page_size_kB attribute for non-NUMAnode non-root object\n", @@ -440,6 +460,7 @@ hwloc__xml_import_object_attr(struct hwloc_topology *topology, memory->page_types = malloc(sizeof(*memory->page_types)); memory->page_types_len = 1; } + assert(memory->page_types); memory->page_types[0].count = lvalue; } else if (hwloc__xml_verbose()) { fprintf(stderr, "%s: ignoring huge_page_free attribute for non-NUMAnode non-root object\n", @@ -835,7 +856,7 @@ hwloc__xml_import_object(hwloc_topology_t topology, state->global->msgprefix, attrname); goto error_with_object; } - hwloc__xml_import_object_attr(topology, data, obj, attrname, attrvalue, state); + hwloc__xml_import_object_attr(topology, data, obj, attrname, attrvalue, state, &ignored); } } @@ -1140,15 +1161,23 @@ hwloc__xml_import_object(hwloc_topology_t topology, ret = -1; } - if (ret < 0) - goto error; + if (ret < 0) { + if (parent && !ignored) + goto error; + else + goto error_with_object; + } state->global->close_child(&childstate); tag = NULL; ret = state->global->find_child(state, &childstate, &tag); - if (ret < 0) - goto error; + if (ret < 0) { + if (parent && !ignored) + goto error; + else + goto error_with_object; + } if (!ret) break; } @@ -1548,7 +1577,7 @@ hwloc__xml_import_diff_one(hwloc__xml_import_state_t state, memset(&diff->obj_attr.diff, 0, sizeof(diff->obj_attr.diff)); diff->obj_attr.diff.generic.type = obj_attr_type; - switch (atoi(obj_attr_type_s)) { + switch (obj_attr_type) { case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_SIZE: diff->obj_attr.diff.uint64.oldvalue = strtoull(obj_attr_oldvalue_s, NULL, 0); diff->obj_attr.diff.uint64.newvalue = strtoull(obj_attr_newvalue_s, NULL, 0); @@ -1732,7 +1761,7 @@ hwloc_look_xml(struct hwloc_backend *backend, struct hwloc_disc_status *dstatus) goto failed; } else { if (hwloc__xml_verbose()) - fprintf(stderr, "%s: ignoring unknown tag `%s' after root object, expected `distances2'\n", + fprintf(stderr, "%s: ignoring unknown tag `%s' after root object.\n", data->msgprefix, tag); goto done; } @@ -1778,6 +1807,8 @@ done: if (nbobjs == data->nbnumanodes) { hwloc_obj_t *objs = malloc(nbobjs*sizeof(hwloc_obj_t)); uint64_t *values = malloc(nbobjs*nbobjs*sizeof(*values)); + assert(data->nbnumanodes > 0); /* v1dist->nbobjs is >0 after import */ + assert(data->first_numanode); if (objs && values) { hwloc_obj_t node; unsigned i; @@ -2051,13 +2082,17 @@ hwloc__xml_export_object_contents (hwloc__xml_export_state_t state, hwloc_topolo state->new_prop(state, "online_cpuset", setstring); free(setstring); - if (v1export || !obj->parent) { + if (v1export) { hwloc_bitmap_t allowed_cpuset = hwloc_bitmap_dup(obj->cpuset); hwloc_bitmap_and(allowed_cpuset, allowed_cpuset, topology->allowed_cpuset); hwloc_bitmap_asprintf(&setstring, allowed_cpuset); state->new_prop(state, "allowed_cpuset", setstring); free(setstring); hwloc_bitmap_free(allowed_cpuset); + } else if (!obj->parent) { + hwloc_bitmap_asprintf(&setstring, topology->allowed_cpuset); + state->new_prop(state, "allowed_cpuset", setstring); + free(setstring); } } @@ -2072,13 +2107,17 @@ hwloc__xml_export_object_contents (hwloc__xml_export_state_t state, hwloc_topolo state->new_prop(state, "complete_nodeset", setstring); free(setstring); - if (v1export || !obj->parent) { + if (v1export) { hwloc_bitmap_t allowed_nodeset = hwloc_bitmap_dup(obj->nodeset); hwloc_bitmap_and(allowed_nodeset, allowed_nodeset, topology->allowed_nodeset); hwloc_bitmap_asprintf(&setstring, allowed_nodeset); state->new_prop(state, "allowed_nodeset", setstring); free(setstring); hwloc_bitmap_free(allowed_nodeset); + } else if (!obj->parent) { + hwloc_bitmap_asprintf(&setstring, topology->allowed_nodeset); + state->new_prop(state, "allowed_nodeset", setstring); + free(setstring); } } @@ -2921,6 +2960,7 @@ hwloc_export_obj_userdata(void *reserved, int encoded; size_t encoded_length; const char *realname; + assert(name); if (!strncmp(name, "base64", 6)) { encoded = 1; encoded_length = BASE64_ENCODED_LENGTH(length); diff --git a/src/3rdparty/hwloc/src/topology.c b/src/3rdparty/hwloc/src/topology.c index 8d376193b..346925177 100644 --- a/src/3rdparty/hwloc/src/topology.c +++ b/src/3rdparty/hwloc/src/topology.c @@ -1,7 +1,7 @@ /* * Copyright © 2009 CNRS * Copyright © 2009-2019 Inria. All rights reserved. - * Copyright © 2009-2012 Université Bordeaux + * Copyright © 2009-2012, 2020 Université Bordeaux * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. */ @@ -33,6 +33,9 @@ #ifdef HAVE_MACH_MACH_INIT_H #include #endif +#ifdef HAVE_MACH_INIT_H +#include +#endif #ifdef HAVE_MACH_MACH_HOST_H #include #endif @@ -123,15 +126,25 @@ int hwloc_get_sysctlbyname(const char *name, int64_t *ret) #endif #if defined(HAVE_SYSCTL) -int hwloc_get_sysctl(int name[], unsigned namelen, int *ret) +int hwloc_get_sysctl(int name[], unsigned namelen, int64_t *ret) { - int n; + union { + int32_t i32; + int64_t i64; + } n; size_t size = sizeof(n); if (sysctl(name, namelen, &n, &size, NULL, 0)) return -1; - if (size != sizeof(n)) - return -1; - *ret = n; + switch (size) { + case sizeof(n.i32): + *ret = n.i32; + break; + case sizeof(n.i64): + *ret = n.i64; + break; + default: + return -1; + } return 0; } #endif @@ -178,8 +191,10 @@ hwloc_fallback_nbprocessors(unsigned flags) { n = nn; #elif defined(HAVE_SYSCTL) && HAVE_DECL_CTL_HW && HAVE_DECL_HW_NCPU static int name[2] = {CTL_HW, HW_NCPU}; - if (hwloc_get_sysctl(name, sizeof(name)/sizeof(*name), &n)) + int64_t nn; + if (hwloc_get_sysctl(name, sizeof(name)/sizeof(*name), &nn)) n = -1; + n = nn; #else #ifdef __GNUC__ #warning No known way to discover number of available processors on this system @@ -188,6 +203,46 @@ hwloc_fallback_nbprocessors(unsigned flags) { #endif return n; } + +int64_t +hwloc_fallback_memsize(void) { + int64_t size; +#if defined(HAVE_HOST_INFO) && HAVE_HOST_INFO + struct host_basic_info info; + mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; + host_info(mach_host_self(), HOST_BASIC_INFO, (integer_t*) &info, &count); + size = info.memory_size; +#elif defined(HAVE_SYSCTL) && HAVE_DECL_CTL_HW && (HAVE_DECL_HW_REALMEM64 || HAVE_DECL_HW_MEMSIZE64 || HAVE_DECL_HW_PHYSMEM64 || HAVE_DECL_HW_USERMEM64 || HAVE_DECL_HW_REALMEM || HAVE_DECL_HW_MEMSIZE || HAVE_DECL_HW_PHYSMEM || HAVE_DECL_HW_USERMEM) +#if HAVE_DECL_HW_MEMSIZE64 + static int name[2] = {CTL_HW, HW_MEMSIZE64}; +#elif HAVE_DECL_HW_REALMEM64 + static int name[2] = {CTL_HW, HW_REALMEM64}; +#elif HAVE_DECL_HW_PHYSMEM64 + static int name[2] = {CTL_HW, HW_PHYSMEM64}; +#elif HAVE_DECL_HW_USERMEM64 + static int name[2] = {CTL_HW, HW_USERMEM64}; +#elif HAVE_DECL_HW_MEMSIZE + static int name[2] = {CTL_HW, HW_MEMSIZE}; +#elif HAVE_DECL_HW_REALMEM + static int name[2] = {CTL_HW, HW_REALMEM}; +#elif HAVE_DECL_HW_PHYSMEM + static int name[2] = {CTL_HW, HW_PHYSMEM}; +#elif HAVE_DECL_HW_USERMEM + static int name[2] = {CTL_HW, HW_USERMEM}; +#endif + if (hwloc_get_sysctl(name, sizeof(name)/sizeof(*name), &size)) + size = -1; +#elif defined(HAVE_SYSCTLBYNAME) + if (hwloc_get_sysctlbyname("hw.memsize", &size) && + hwloc_get_sysctlbyname("hw.realmem", &size) && + hwloc_get_sysctlbyname("hw.physmem", &size) && + hwloc_get_sysctlbyname("hw.usermem", &size)) + size = -1; +#else + size = -1; +#endif + return size; +} #endif /* !HWLOC_WIN_SYS */ /* @@ -2043,15 +2098,17 @@ propagate_total_memory(hwloc_obj_t obj) if (obj->type == HWLOC_OBJ_NUMANODE) { obj->total_memory += obj->attr->numanode.local_memory; - /* By the way, sort the page_type array. - * Cannot do it on insert since some backends (e.g. XML) add page_types after inserting the object. - */ - qsort(obj->attr->numanode.page_types, obj->attr->numanode.page_types_len, sizeof(*obj->attr->numanode.page_types), hwloc_memory_page_type_compare); - /* Ignore 0-size page_types, they are at the end */ - for(i=obj->attr->numanode.page_types_len; i>=1; i--) - if (obj->attr->numanode.page_types[i-1].size) - break; - obj->attr->numanode.page_types_len = i; + if (obj->attr->numanode.page_types_len) { + /* By the way, sort the page_type array. + * Cannot do it on insert since some backends (e.g. XML) add page_types after inserting the object. + */ + qsort(obj->attr->numanode.page_types, obj->attr->numanode.page_types_len, sizeof(*obj->attr->numanode.page_types), hwloc_memory_page_type_compare); + /* Ignore 0-size page_types, they are at the end */ + for(i=obj->attr->numanode.page_types_len; i>=1; i--) + if (obj->attr->numanode.page_types[i-1].size) + break; + obj->attr->numanode.page_types_len = i; + } } } @@ -2966,7 +3023,8 @@ hwloc_connect_levels(hwloc_topology_t topology) if (hwloc_type_cmp(top_obj, objs[i]) == HWLOC_OBJ_EQUAL) { /* Take it, add main children. */ taken_objs[n_taken_objs++] = objs[i]; - memcpy(&new_objs[n_new_objs], objs[i]->children, objs[i]->arity * sizeof(new_objs[0])); + if (objs[i]->arity) + memcpy(&new_objs[n_new_objs], objs[i]->children, objs[i]->arity * sizeof(new_objs[0])); n_new_objs += objs[i]->arity; } else { /* Leave it. */ @@ -4113,6 +4171,7 @@ hwloc_topology_restrict(struct hwloc_topology *topology, hwloc_const_bitmap_t se /* cpuset to clear */ if (flags & HWLOC_RESTRICT_FLAG_REMOVE_MEMLESS) { hwloc_obj_t pu = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0); + assert(pu); do { /* PU will be removed if cpuset gets or was empty */ if (hwloc_bitmap_iszero(pu->cpuset) @@ -4148,6 +4207,7 @@ hwloc_topology_restrict(struct hwloc_topology *topology, hwloc_const_bitmap_t se /* nodeset to clear */ if (flags & HWLOC_RESTRICT_FLAG_REMOVE_CPULESS) { hwloc_obj_t node = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 0); + assert(node); do { /* node will be removed if nodeset gets or was empty */ if (hwloc_bitmap_iszero(node->cpuset) @@ -4242,6 +4302,9 @@ hwloc_topology_allow(struct hwloc_topology *topology, goto error; } topology->binding_hooks.get_allowed_resources(topology); + /* make sure the backend returned something sane (Linux cpusets may return offline PUs in some cases) */ + hwloc_bitmap_and(topology->allowed_cpuset, topology->allowed_cpuset, hwloc_get_root_obj(topology)->cpuset); + hwloc_bitmap_and(topology->allowed_nodeset, topology->allowed_nodeset, hwloc_get_root_obj(topology)->nodeset); break; } case HWLOC_ALLOW_FLAG_CUSTOM: { From 5905dd63ccf89dba819c7fa8f532eae774e566de Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 23 May 2020 10:58:53 +0700 Subject: [PATCH 23/24] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5419edcf3..4eea32ae6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - [#1664](https://github.com/xmrig/xmrig/pull/1664) Improved JSON config error reporting. - [#1668](https://github.com/xmrig/xmrig/pull/1668) Optimized RandomX dataset initialization. - Fixed memory leak in HTTP client. +- Build [dependencies](https://github.com/xmrig/xmrig-deps/releases/tag/v4.1) updated to recent versions. +- Compiler for Windows gcc builds updated to v10.1. # v5.11.1 - [#1652](https://github.com/xmrig/xmrig/pull/1652) Up to 1% RandomX perfomance improvement on recent AMD CPUs. From 532520f62676ea7e90838c684482a49890606e0e Mon Sep 17 00:00:00 2001 From: xmrig Date: Sat, 23 May 2020 11:06:35 +0700 Subject: [PATCH 24/24] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eea32ae6..67d7e6f6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v5.11.2 - [#1664](https://github.com/xmrig/xmrig/pull/1664) Improved JSON config error reporting. - [#1668](https://github.com/xmrig/xmrig/pull/1668) Optimized RandomX dataset initialization. +- [#1675](https://github.com/xmrig/xmrig/pull/1675) Fixed cross-compiling on Linux. - Fixed memory leak in HTTP client. - Build [dependencies](https://github.com/xmrig/xmrig-deps/releases/tag/v4.1) updated to recent versions. - Compiler for Windows gcc builds updated to v10.1.