From 8a167cb2a739eff2a2190363a9018537a2f2b3eb Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Apr 2022 06:03:39 +0700 Subject: [PATCH] Sync with base. --- CMakeLists.txt | 2 +- res/app.rc | 2 +- src/App.cpp | 1 - src/backend/common/Worker.cpp | 10 +- src/base/api/Api.cpp | 7 +- src/base/base.cmake | 16 +- src/base/crypto/Algorithm.h | 8 +- src/base/crypto/Coin.cpp | 4 +- src/base/crypto/Coin.h | 8 +- src/base/io/Env.cpp | 44 +-- src/base/io/Env.h | 5 +- src/base/kernel/Base.cpp | 11 +- src/base/kernel/Entry.cpp | 14 +- src/base/kernel/Entry.h | 10 +- src/base/kernel/Lib.cpp | 78 +++++ src/base/kernel/{Platform.cpp => Lib.h} | 57 ++-- src/base/kernel/OS.cpp | 99 +++++++ src/base/kernel/{Platform.h => OS.h} | 47 ++- .../{Platform_hwloc.cpp => OS_hwloc.cpp} | 9 +- .../kernel/{Platform_mac.cpp => OS_mac.cpp} | 84 +++--- .../kernel/{Platform_unix.cpp => OS_unix.cpp} | 92 +++--- .../kernel/{Platform_win.cpp => OS_win.cpp} | 147 ++++++---- src/base/kernel/Process.cpp | 271 +++++++++++++----- src/base/kernel/Process.h | 41 ++- src/base/kernel/Versions.cpp | 203 +++++++++++++ src/base/kernel/Versions.h | 83 ++++++ src/base/kernel/base-version.h | 49 ++++ src/base/kernel/config/BaseTransform.cpp | 1 + src/base/net/http/HttpClient.cpp | 5 +- src/base/net/stratum/Pool.cpp | 10 +- src/base/net/tls/TlsGen.cpp | 3 +- src/base/tools/cryptonote/Signatures.cpp | 101 +++---- src/base/tools/cryptonote/Signatures.h | 28 +- src/base/tools/cryptonote/umul128.h | 39 ++- src/core/Miner.cpp | 19 +- src/core/Miner.h | 4 +- src/crypto/ghostrider/ghostrider.cpp | 13 +- src/crypto/ghostrider/ghostrider.h | 6 +- src/crypto/rx/RxDataset.cpp | 8 +- src/crypto/rx/RxDataset.h | 4 +- src/crypto/rx/RxNUMAStorage.cpp | 8 +- src/crypto/rx/RxNUMAStorage.h | 4 +- src/hw/msr/Msr_win.cpp | 9 +- src/net/strategies/DonateStrategy.cpp | 4 +- src/version.h | 35 +-- 45 files changed, 1159 insertions(+), 544 deletions(-) create mode 100644 src/base/kernel/Lib.cpp rename src/base/kernel/{Platform.cpp => Lib.h} (56%) create mode 100644 src/base/kernel/OS.cpp rename src/base/kernel/{Platform.h => OS.h} (66%) rename src/base/kernel/{Platform_hwloc.cpp => OS_hwloc.cpp} (86%) rename src/base/kernel/{Platform_mac.cpp => OS_mac.cpp} (64%) rename src/base/kernel/{Platform_unix.cpp => OS_unix.cpp} (68%) rename src/base/kernel/{Platform_win.cpp => OS_win.cpp} (69%) create mode 100644 src/base/kernel/Versions.cpp create mode 100644 src/base/kernel/Versions.h create mode 100644 src/base/kernel/base-version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bb35bfee6..6f7d034ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,7 +191,7 @@ else() endif() endif() -add_definitions(-DXMRIG_MINER_PROJECT -DXMRIG_JSON_SINGLE_LINE_ARRAY) +add_definitions(-DXMRIG_MINER_PROJECT -DXMRIG_LEGACY -DXMRIG_JSON_SINGLE_LINE_ARRAY) add_definitions(-D__STDC_FORMAT_MACROS -DUNICODE -D_FILE_OFFSET_BITS=64) find_package(UV REQUIRED) diff --git a/res/app.rc b/res/app.rc index fb41b8b1d..0330b39d8 100644 --- a/res/app.rc +++ b/res/app.rc @@ -20,7 +20,7 @@ VS_VERSION_INFO VERSIONINFO BEGIN BLOCK "000004b0" BEGIN - VALUE "CompanyName", APP_SITE + VALUE "CompanyName", APP_DOMAIN VALUE "FileDescription", APP_DESC VALUE "FileVersion", APP_VERSION VALUE "LegalCopyright", APP_COPYRIGHT diff --git a/src/App.cpp b/src/App.cpp index 39ec0d62e..f21d0276f 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -34,7 +34,6 @@ #include "base/io/log/Log.h" #include "base/io/log/Tags.h" #include "base/io/Signals.h" -#include "base/kernel/Platform.h" #include "core/config/Config.h" #include "core/Controller.h" #include "Summary.h" diff --git a/src/backend/common/Worker.cpp b/src/backend/common/Worker.cpp index b24ac2806..63c52a327 100644 --- a/src/backend/common/Worker.cpp +++ b/src/backend/common/Worker.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2020 SChernykh - * Copyright (c) 2016-2020 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ #include "backend/common/Worker.h" -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include "crypto/common/VirtualMemory.h" @@ -28,6 +28,6 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) : { m_node = VirtualMemory::bindToNUMANode(affinity); - Platform::trySetThreadAffinity(affinity); - Platform::setThreadPriority(priority); + OS::trySetThreadAffinity(affinity); + OS::setThreadPriority(priority); } diff --git a/src/base/api/Api.cpp b/src/base/api/Api.cpp index 54666efda..fc207c31a 100644 --- a/src/base/api/Api.cpp +++ b/src/base/api/Api.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,7 @@ #include "base/io/Env.h" #include "base/io/json/Json.h" #include "base/kernel/Base.h" +#include "base/kernel/OS.h" #include "base/tools/Chrono.h" #include "base/tools/Cvt.h" #include "core/config/Config.h" @@ -232,6 +233,6 @@ void xmrig::Api::genWorkerId(const String &id) { m_workerId = Env::expand(id); if (m_workerId.isEmpty()) { - m_workerId = Env::hostname(); + m_workerId = OS::hostname(); } } diff --git a/src/base/base.cmake b/src/base/base.cmake index 0f4f87255..29d03d019 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -41,8 +41,10 @@ set(HEADERS_BASE src/base/kernel/interfaces/IStrategyListener.h src/base/kernel/interfaces/ITimerListener.h src/base/kernel/interfaces/IWatcherListener.h - src/base/kernel/Platform.h + src/base/kernel/Lib.h + src/base/kernel/OS.h src/base/kernel/Process.h + src/base/kernel/Versions.h src/base/net/dns/Dns.h src/base/net/dns/DnsConfig.h src/base/net/dns/DnsRecord.h @@ -111,8 +113,10 @@ set(SOURCES_BASE src/base/kernel/config/BaseTransform.cpp src/base/kernel/config/Title.cpp src/base/kernel/Entry.cpp - src/base/kernel/Platform.cpp + src/base/kernel/Lib.cpp + src/base/kernel/OS.cpp src/base/kernel/Process.cpp + src/base/kernel/Versions.cpp src/base/net/dns/Dns.cpp src/base/net/dns/DnsConfig.cpp src/base/net/dns/DnsRecord.cpp @@ -148,19 +152,19 @@ set(SOURCES_BASE if (WIN32) set(SOURCES_OS src/base/io/json/Json_win.cpp - src/base/kernel/Platform_win.cpp + src/base/kernel/OS_win.cpp src/base/kernel/Process_win.cpp ) elseif (APPLE) set(SOURCES_OS src/base/io/json/Json_unix.cpp - src/base/kernel/Platform_mac.cpp + src/base/kernel/OS_mac.cpp src/base/kernel/Process_unix.cpp ) else() set(SOURCES_OS src/base/io/json/Json_unix.cpp - src/base/kernel/Platform_unix.cpp + src/base/kernel/OS_unix.cpp src/base/kernel/Process_unix.cpp ) endif() @@ -168,7 +172,7 @@ endif() if (WITH_HWLOC) list(APPEND SOURCES_OS - src/base/kernel/Platform_hwloc.cpp + src/base/kernel/OS_hwloc.cpp ) endif() diff --git a/src/base/crypto/Algorithm.h b/src/base/crypto/Algorithm.h index 5c223b362..71b75369d 100644 --- a/src/base/crypto/Algorithm.h +++ b/src/base/crypto/Algorithm.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018 Lee Clagett - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -217,7 +217,7 @@ private: using Algorithms = std::vector; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_ALGORITHM_H */ +#endif // XMRIG_ALGORITHM_H diff --git a/src/base/crypto/Coin.cpp b/src/base/crypto/Coin.cpp index 7b2e8e8bb..0ac2ffef2 100644 --- a/src/base/crypto/Coin.cpp +++ b/src/base/crypto/Coin.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/base/crypto/Coin.h b/src/base/crypto/Coin.h index a1ddf5d8b..8f3172170 100644 --- a/src/base/crypto/Coin.h +++ b/src/base/crypto/Coin.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,7 +84,7 @@ private: }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_COIN_H */ +#endif // XMRIG_COIN_H diff --git a/src/base/io/Env.cpp b/src/base/io/Env.cpp index 6fef90732..19263ecbd 100644 --- a/src/base/io/Env.cpp +++ b/src/base/io/Env.cpp @@ -17,29 +17,15 @@ */ #include "base/io/Env.h" +#include "base/kernel/OS.h" #include "base/kernel/Process.h" #include "version.h" #include -#include #include -#ifndef _WIN32 -# include -#endif - - -#ifndef UV_MAXHOSTNAMESIZE -# ifdef MAXHOSTNAMELEN -# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1) -# else -# define UV_MAXHOSTNAMESIZE 256 -# endif -#endif - - namespace xmrig { @@ -51,17 +37,17 @@ 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) }); - variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) }); - variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) }); - variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) }); + variables.insert({ "XMRIG_HOSTNAME", OS::hostname() }); + variables.insert({ "XMRIG_EXE", Process::locate(Process::ExePathLocation) }); + variables.insert({ "XMRIG_EXE_DIR", Process::locate(Process::ExeLocation) }); + variables.insert({ "XMRIG_CWD", Process::locate(Process::CwdLocation) }); + variables.insert({ "XMRIG_HOME_DIR", Process::locate(Process::HomeLocation) }); + variables.insert({ "XMRIG_TEMP_DIR", Process::locate(Process::TempLocation) }); + variables.insert({ "XMRIG_DATA_DIR", Process::locate(Process::DataLocation) }); String hostname = "HOSTNAME"; if (!getenv(hostname)) { // NOLINT(concurrency-mt-unsafe) - variables.insert({ std::move(hostname), Env::hostname() }); + variables.insert({ std::move(hostname), OS::hostname() }); } } #endif @@ -138,15 +124,3 @@ xmrig::String xmrig::Env::get(const String &name, const std::map return static_cast(getenv(name)); // NOLINT(concurrency-mt-unsafe) } - - -xmrig::String xmrig::Env::hostname() -{ - char buf[UV_MAXHOSTNAMESIZE]{}; - - if (gethostname(buf, sizeof(buf)) == 0) { - return static_cast(buf); - } - - return {}; -} diff --git a/src/base/io/Env.h b/src/base/io/Env.h index ba7017da0..f1d52b6f8 100644 --- a/src/base/io/Env.h +++ b/src/base/io/Env.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2020 SChernykh - * Copyright (c) 2016-2020 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 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,6 @@ class Env public: static String expand(const char *in, const std::map &extra = {}); static String get(const String &name, const std::map &extra = {}); - static String hostname(); }; diff --git a/src/base/kernel/Base.cpp b/src/base/kernel/Base.cpp index 4aa2e466e..e9e97b671 100644 --- a/src/base/kernel/Base.cpp +++ b/src/base/kernel/Base.cpp @@ -29,7 +29,7 @@ #include "base/io/log/Tags.h" #include "base/io/Watcher.h" #include "base/kernel/interfaces/IBaseListener.h" -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include "base/kernel/Process.h" #include "base/net/tools/NetBuffer.h" #include "core/config/Config.h" @@ -130,17 +130,17 @@ private: return config.release(); } - chain.addFile(Process::location(Process::DataLocation, "config.json")); + chain.addFile(Process::locate(Process::DataLocation, "config.json")); if (read(chain, config)) { return config.release(); } - chain.addFile(Process::location(Process::HomeLocation, "." APP_ID ".json")); + chain.addFile(Process::locate(Process::HomeLocation, "." APP_ID ".json")); if (read(chain, config)) { return config.release(); } - chain.addFile(Process::location(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json")); + chain.addFile(Process::locate(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json")); if (read(chain, config)) { return config.release(); } @@ -187,7 +187,8 @@ int xmrig::Base::init() d_ptr->api->addListener(this); # endif - Platform::init(config()->userAgent()); + OS::init(); + Process::setUserAgent(config()->userAgent()); if (isBackground()) { Log::setBackground(true); diff --git a/src/base/kernel/Entry.cpp b/src/base/kernel/Entry.cpp index 5ad75fd23..d435e28c6 100644 --- a/src/base/kernel/Entry.cpp +++ b/src/base/kernel/Entry.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 (c) 2016-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +16,6 @@ * along with this program. If not, see . */ - #include #include @@ -42,6 +35,7 @@ #include "base/kernel/Entry.h" #include "base/kernel/Process.h" +#include "base/tools/Arguments.h" #include "core/config/usage.h" #include "version.h" @@ -107,7 +101,7 @@ static int showVersion() #ifdef XMRIG_FEATURE_HWLOC static int exportTopology(const Process &) { - const String path = Process::location(Process::ExeLocation, "topology.xml"); + const String path = Process::locate(Process::ExeLocation, "topology.xml"); hwloc_topology_t topology = nullptr; hwloc_topology_init(&topology); diff --git a/src/base/kernel/Entry.h b/src/base/kernel/Entry.h index a459410fd..63b86cf50 100644 --- a/src/base/kernel/Entry.h +++ b/src/base/kernel/Entry.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 (c) 2016-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/base/kernel/Lib.cpp b/src/base/kernel/Lib.cpp new file mode 100644 index 000000000..5cd5721ad --- /dev/null +++ b/src/base/kernel/Lib.cpp @@ -0,0 +1,78 @@ +/* XMRig + * Copyright (c) 2016-2021 SChernykh + * Copyright (c) 2016-2021 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 . + */ + +#include "base/kernel/Lib.h" + + +#include +#include + + +namespace xmrig { + + +class Lib::Private +{ +public: + bool open = false; + uv_lib_t lib{}; +}; + + +} // namespace xmrig + + +xmrig::Lib::Lib() : + d(std::make_shared()) +{ +} + + +bool xmrig::Lib::isOpen() const +{ + return d->open; +} + + +bool xmrig::Lib::open(const char *filename) +{ + assert(!isOpen()); + + return (d->open = uv_dlopen(filename, &d->lib) == 0); +} + + +bool xmrig::Lib::sym(const char *name, void **ptr) +{ + return isOpen() && uv_dlsym(&d->lib, name, ptr); +} + + +const char *xmrig::Lib::lastError() const +{ + return uv_dlerror(&d->lib); +} + + +void xmrig::Lib::close() +{ + if (isOpen()) { + uv_dlclose(&d->lib); + d->open = false; + } +} diff --git a/src/base/kernel/Platform.cpp b/src/base/kernel/Lib.h similarity index 56% rename from src/base/kernel/Platform.cpp rename to src/base/kernel/Lib.h index ef2b67eb9..420d17b2a 100644 --- a/src/base/kernel/Platform.cpp +++ b/src/base/kernel/Lib.h @@ -1,5 +1,5 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 SChernykh * Copyright (c) 2016-2021 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -16,42 +16,39 @@ * along with this program. If not, see . */ - -#include "base/kernel/Platform.h" +#ifndef XMRIG_LIB_H +#define XMRIG_LIB_H -#include -#include - - -#ifdef XMRIG_FEATURE_TLS -# include -# include -#endif +#include "base/tools/Object.h" namespace xmrig { -String Platform::m_userAgent; + +class Lib +{ +public: + XMRIG_DISABLE_COPY_MOVE(Lib) + + Lib(); + inline ~Lib() { close(); } + + bool isOpen() const; + bool open(const char *filename); + bool sym(const char *name, void **ptr); + const char *lastError() const; + void close(); + + template + inline bool sym(const char *name, T t) { return sym(name, reinterpret_cast(t)); } + +private: + XMRIG_DECL_PRIVATE() +}; + } // namespace xmrig -void xmrig::Platform::init(const char *userAgent) -{ -# ifdef XMRIG_FEATURE_TLS - SSL_library_init(); - SSL_load_error_strings(); - ERR_load_BIO_strings(); - ERR_load_crypto_strings(); - SSL_load_error_strings(); - OpenSSL_add_all_digests(); -# endif - - if (userAgent) { - m_userAgent = userAgent; - } - else { - m_userAgent = createUserAgent(); - } -} +#endif // XMRIG_LIB_H diff --git a/src/base/kernel/OS.cpp b/src/base/kernel/OS.cpp new file mode 100644 index 000000000..9462a9ec1 --- /dev/null +++ b/src/base/kernel/OS.cpp @@ -0,0 +1,99 @@ +/* XMRig + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 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 . + */ + +#include + + +#include "base/kernel/OS.h" +#include "3rdparty/fmt/core.h" +#include "base/kernel/Process.h" +#include "base/kernel/Versions.h" +#include "version.h" + + +#ifndef XMRIG_OS_WIN +# include +#endif + + +#ifndef UV_MAXHOSTNAMESIZE +# ifdef MAXHOSTNAMELEN +# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1) +# else +# define UV_MAXHOSTNAMESIZE 256 +# endif +#endif + + +namespace xmrig { + + +#if (XMRIG_ARM == 8 || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)) +const char *OS::arch = "arm64"; +#elif (XMRIG_ARM == 7 || defined(__arm__) || defined(_M_ARM)) +const char *OS::arch = "arm"; +#elif (defined(__x86_64__) || defined(_M_AMD64)) +const char *OS::arch = "x86_64"; +#elif (defined(_X86_) || defined(_M_IX86)) +const char *OS::arch = "x86"; +#else +static_assert (false, "Unsupported CPU or compiler"); +#endif + + +} // namespace xmrig + + +std::string xmrig::OS::userAgent() +{ + return fmt::format("{}/{} ({}; {}) uv/{} {}/{}", + APP_NAME, + APP_VERSION, + name(), + arch, + Process::versions()[Versions::kUv], + Versions::kCompiler, + Process::versions()[Versions::kCompiler] + ); +} + + +#ifndef XMRIG_OS_WIN +xmrig::String xmrig::OS::hostname() +{ + char buf[UV_MAXHOSTNAMESIZE]{}; + + if (gethostname(buf, sizeof(buf)) == 0) { + return static_cast(buf); + } + + return {}; +} +#endif + + +uint64_t xmrig::OS::freemem() +{ + return uv_get_free_memory(); +} + + +uint64_t xmrig::OS::totalmem() +{ + return uv_get_total_memory(); +} diff --git a/src/base/kernel/Platform.h b/src/base/kernel/OS.h similarity index 66% rename from src/base/kernel/Platform.h rename to src/base/kernel/OS.h index 04c212e64..f4bf08e87 100644 --- a/src/base/kernel/Platform.h +++ b/src/base/kernel/OS.h @@ -16,50 +16,43 @@ * along with this program. If not, see . */ -#ifndef XMRIG_PLATFORM_H -#define XMRIG_PLATFORM_H - - -#include +#ifndef XMRIG_OS_H +#define XMRIG_OS_H #include "base/tools/String.h" +#include + + namespace xmrig { -class Platform +class OS { public: - static inline bool trySetThreadAffinity(int64_t cpu_id) - { - if (cpu_id < 0) { - return false; - } + static const char *arch; - return setThreadAffinity(static_cast(cpu_id)); - } - - static bool setThreadAffinity(uint64_t cpu_id); - static void init(const char *userAgent); - static void setProcessPriority(int priority); - static void setThreadPriority(int priority); - - static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; } - static inline const String &userAgent() { return m_userAgent; } + static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; } + static inline bool trySetThreadAffinity(int64_t cpu_id) { return cpu_id >= 0 && setThreadAffinity(static_cast(cpu_id)); } static bool isOnBatteryPower(); + static bool setThreadAffinity(uint64_t cpu_id); + static std::string name(); + static std::string userAgent(); + static String hostname(); + static uint64_t freemem(); static uint64_t idleTime(); - -private: - static char *createUserAgent(); - - static String m_userAgent; + static uint64_t totalmem(); + static void destroy(); + static void init(); + static void setProcessPriority(int priority); + static void setThreadPriority(int priority); }; } // namespace xmrig -#endif /* XMRIG_PLATFORM_H */ +#endif // XMRIG_OS_H diff --git a/src/base/kernel/Platform_hwloc.cpp b/src/base/kernel/OS_hwloc.cpp similarity index 86% rename from src/base/kernel/Platform_hwloc.cpp rename to src/base/kernel/OS_hwloc.cpp index 8d9d9f593..d0f919e64 100644 --- a/src/base/kernel/Platform_hwloc.cpp +++ b/src/base/kernel/OS_hwloc.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2020 SChernykh - * Copyright (c) 2016-2020 XMRig , + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 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 @@ -16,8 +16,7 @@ * along with this program. If not, see . */ - -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include "backend/cpu/platform/HwlocCpuInfo.h" #include "backend/cpu/Cpu.h" @@ -27,7 +26,7 @@ #ifndef XMRIG_OS_APPLE -bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) +bool xmrig::OS::setThreadAffinity(uint64_t cpu_id) { auto cpu = static_cast(Cpu::info()); hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast(cpu_id)); diff --git a/src/base/kernel/Platform_mac.cpp b/src/base/kernel/OS_mac.cpp similarity index 64% rename from src/base/kernel/Platform_mac.cpp rename to src/base/kernel/OS_mac.cpp index d07e925d4..3f2849ad6 100644 --- a/src/base/kernel/Platform_mac.cpp +++ b/src/base/kernel/OS_mac.cpp @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - #include #include #include @@ -27,46 +26,58 @@ #include -#include "base/kernel/Platform.h" -#include "version.h" +#include "base/kernel/OS.h" -char *xmrig::Platform::createUserAgent() +bool xmrig::OS::isOnBatteryPower() { - constexpr const size_t max = 256; - - char *buf = new char[max](); - int length = snprintf(buf, max, - "%s/%s (Macintosh; macOS" -# ifdef XMRIG_ARM - "; arm64" -# else - "; x86_64" -# endif - ") libuv/%s", APP_NAME, APP_VERSION, uv_version_string()); - -# ifdef __clang__ - length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); -# elif defined(__GNUC__) - length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# endif - - return buf; + return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited; } -bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) +bool xmrig::OS::setThreadAffinity(uint64_t /*cpu_id*/) { return true; } -void xmrig::Platform::setProcessPriority(int) +std::string xmrig::OS::name() +{ + return "macOS"; +} + + +uint64_t xmrig::OS::idleTime() +{ + uint64_t idle_time = 0; + const auto service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem")); + const auto property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0); + + CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle_time); + + CFRelease(property); + IOObjectRelease(service); + + return idle_time / 1000000U; +} + + +void xmrig::OS::destroy() { } -void xmrig::Platform::setThreadPriority(int priority) +void xmrig::OS::init() +{ +} + + +void xmrig::OS::setProcessPriority(int) +{ +} + + +void xmrig::OS::setThreadPriority(int priority) { if (priority == -1) { return; @@ -101,24 +112,3 @@ void xmrig::Platform::setThreadPriority(int priority) setpriority(PRIO_PROCESS, 0, prio); } - - -bool xmrig::Platform::isOnBatteryPower() -{ - return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited; -} - - -uint64_t xmrig::Platform::idleTime() -{ - uint64_t idle_time = 0; - const auto service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem")); - const auto property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0); - - CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle_time); - - CFRelease(property); - IOObjectRelease(service); - - return idle_time / 1000000U; -} diff --git a/src/base/kernel/Platform_unix.cpp b/src/base/kernel/OS_unix.cpp similarity index 68% rename from src/base/kernel/Platform_unix.cpp rename to src/base/kernel/OS_unix.cpp index f5bbc1931..2d6b0bad4 100644 --- a/src/base/kernel/Platform_unix.cpp +++ b/src/base/kernel/OS_unix.cpp @@ -37,8 +37,7 @@ #include -#include "base/kernel/Platform.h" -#include "version.h" +#include "base/kernel/OS.h" #ifdef __FreeBSD__ @@ -46,35 +45,24 @@ typedef cpuset_t cpu_set_t; #endif -char *xmrig::Platform::createUserAgent() +bool xmrig::OS::isOnBatteryPower() { - constexpr const size_t max = 256; - - char *buf = new char[max](); - int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); - -# if defined(__x86_64__) - length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string()); -# elif defined(__aarch64__) - length += snprintf(buf + length, max - length, "aarch64) libuv/%s", uv_version_string()); -# elif defined(__arm__) - length += snprintf(buf + length, max - length, "arm) libuv/%s", uv_version_string()); -# else - length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); -# endif - -# ifdef __clang__ - length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__); -# elif defined(__GNUC__) - length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# endif - - return buf; + for (int i = 0; i <= 1; ++i) { + char buf[64]; + snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i); + std::ifstream f(buf); + if (f.is_open()) { + std::string status; + f >> status; + return (status == "Discharging"); + } + } + return false; } #ifndef XMRIG_FEATURE_HWLOC -bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) +bool xmrig::OS::setThreadAffinity(uint64_t cpu_id) { cpu_set_t mn; CPU_ZERO(&mn); @@ -92,12 +80,38 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) #endif -void xmrig::Platform::setProcessPriority(int) +std::string xmrig::OS::name() +{ +# ifdef __FreeBSD__ + return "FreeBSD"; +# else + return "Linux"; +# endif +} + + +uint64_t xmrig::OS::idleTime() +{ + return std::numeric_limits::max(); +} + + +void xmrig::OS::destroy() { } -void xmrig::Platform::setThreadPriority(int priority) +void xmrig::OS::init() +{ +} + + +void xmrig::OS::setProcessPriority(int) +{ +} + + +void xmrig::OS::setThreadPriority(int priority) { if (priority == -1) { return; @@ -143,25 +157,3 @@ void xmrig::Platform::setThreadPriority(int priority) } # endif } - - -bool xmrig::Platform::isOnBatteryPower() -{ - for (int i = 0; i <= 1; ++i) { - char buf[64]; - snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i); - std::ifstream f(buf); - if (f.is_open()) { - std::string status; - f >> status; - return (status == "Discharging"); - } - } - return false; -} - - -uint64_t xmrig::Platform::idleTime() -{ - return std::numeric_limits::max(); -} diff --git a/src/base/kernel/Platform_win.cpp b/src/base/kernel/OS_win.cpp similarity index 69% rename from src/base/kernel/Platform_win.cpp rename to src/base/kernel/OS_win.cpp index 76d81ae56..32f42f5cc 100644 --- a/src/base/kernel/Platform_win.cpp +++ b/src/base/kernel/OS_win.cpp @@ -16,16 +16,28 @@ * along with this program. If not, see . */ - -#include -#include -#include #include -#include -#include "base/kernel/Platform.h" -#include "version.h" +#include "base/kernel/OS.h" +#include "3rdparty/fmt/core.h" +#include "base/kernel/Lib.h" +#include "base/tools/Cvt.h" + + +#ifndef UV_MAXHOSTNAMESIZE +# define UV_MAXHOSTNAMESIZE 256 +#endif + + +namespace xmrig { + + +typedef int (WSAAPI *GetHostNameW_t)(PWSTR, int); // NOLINT(modernize-use-using) + + +static Lib ws2_32; +static GetHostNameW_t pGetHostNameW = nullptr; static inline OSVERSIONINFOEX winOsVersion() @@ -46,32 +58,21 @@ static inline OSVERSIONINFOEX winOsVersion() } -char *xmrig::Platform::createUserAgent() +} // namespace xmrig + + +bool xmrig::OS::isOnBatteryPower() { - const auto osver = winOsVersion(); - constexpr const size_t max = 256; - - char *buf = new char[max](); - int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion); - -# if defined(__x86_64__) || defined(_M_AMD64) - length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string()); -# else - length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string()); -# endif - -# ifdef __GNUC__ - snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# elif _MSC_VER - snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION); -# endif - - return buf; + SYSTEM_POWER_STATUS st; + if (GetSystemPowerStatus(&st)) { + return (st.ACLineStatus == 0); + } + return false; } #ifndef XMRIG_FEATURE_HWLOC -bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) +bool xmrig::OS::setThreadAffinity(uint64_t cpu_id) { const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0); Sleep(1); @@ -80,7 +81,70 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) #endif -void xmrig::Platform::setProcessPriority(int priority) +std::string xmrig::OS::name() +{ + const auto osver = winOsVersion(); + + return fmt::format("Windows {}.{}", osver.dwMajorVersion, osver.dwMinorVersion); +} + + +xmrig::String xmrig::OS::hostname() +{ + if (pGetHostNameW) { + WCHAR buf[UV_MAXHOSTNAMESIZE]{}; + + if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) == 0) { + return Cvt::toUtf8(buf).c_str(); + } + } + + char buf[UV_MAXHOSTNAMESIZE]{}; + + if (gethostname(buf, sizeof(buf)) == 0) { + return static_cast(buf); + } + + return {}; +} + + +uint64_t xmrig::OS::idleTime() +{ + LASTINPUTINFO info{}; + info.cbSize = sizeof(LASTINPUTINFO); + + if (!GetLastInputInfo(&info)) { + return std::numeric_limits::max(); + } + + return static_cast(GetTickCount() - info.dwTime); +} + + +void xmrig::OS::destroy() +{ +# ifdef XMRIG_FEATURE_COM + CoUninitialize(); +# endif + + ws2_32.close(); +} + + +void xmrig::OS::init() +{ +# ifdef XMRIG_FEATURE_COM + CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); +# endif + + if (ws2_32.open("Ws2_32.dll")) { + ws2_32.sym("GetHostNameW", &pGetHostNameW); + } +} + + +void xmrig::OS::setProcessPriority(int priority) { if (priority == -1) { return; @@ -117,7 +181,7 @@ void xmrig::Platform::setProcessPriority(int priority) } -void xmrig::Platform::setThreadPriority(int priority) +void xmrig::OS::setThreadPriority(int priority) { if (priority == -1) { return; @@ -152,26 +216,3 @@ void xmrig::Platform::setThreadPriority(int priority) SetThreadPriority(GetCurrentThread(), prio); } - - -bool xmrig::Platform::isOnBatteryPower() -{ - SYSTEM_POWER_STATUS st; - if (GetSystemPowerStatus(&st)) { - return (st.ACLineStatus == 0); - } - return false; -} - - -uint64_t xmrig::Platform::idleTime() -{ - LASTINPUTINFO info{}; - info.cbSize = sizeof(LASTINPUTINFO); - - if (!GetLastInputInfo(&info)) { - return std::numeric_limits::max(); - } - - return static_cast(GetTickCount() - info.dwTime); -} diff --git a/src/base/kernel/Process.cpp b/src/base/kernel/Process.cpp index 5e95e3c34..3961cf8e5 100644 --- a/src/base/kernel/Process.cpp +++ b/src/base/kernel/Process.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,10 +23,25 @@ #include "base/kernel/Process.h" #include "3rdparty/fmt/core.h" +#include "base/kernel/OS.h" +#include "base/kernel/Versions.h" +#include "base/tools/Arguments.h" #include "base/tools/Chrono.h" #include "version.h" +#ifndef XMRIG_LEGACY +# include "base/kernel/Events.h" +# include "base/kernel/events/ExitEvent.h" +#endif + + +#ifdef XMRIG_FEATURE_TLS +# include +# include +#endif + + #ifdef XMRIG_OS_WIN # ifdef _MSC_VER # include @@ -42,99 +57,127 @@ namespace xmrig { -static char pathBuf[520]; -static std::string dataDir; - - -static std::string getPath(Process::Location location) +class Process::Private { - size_t size = sizeof(pathBuf); - - if (location == Process::DataLocation) { - if (!dataDir.empty()) { - return dataDir; - } - - location = Process::ExeLocation; - } - - if (location == Process::HomeLocation) { -# if UV_VERSION_HEX >= 0x010600 - return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size); -# else - location = Process::ExeLocation; +public: + Private(int argc, char **argv) : arguments(argc, argv) + { +# ifdef XMRIG_FEATURE_TLS + SSL_library_init(); + SSL_load_error_strings(); + ERR_load_BIO_strings(); + ERR_load_crypto_strings(); + SSL_load_error_strings(); + OpenSSL_add_all_digests(); # endif } - if (location == Process::TempLocation) { -# if UV_VERSION_HEX >= 0x010900 - return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size); -# else - location = Process::ExeLocation; -# endif - } - - if (location == Process::ExeLocation) { - if (uv_exepath(pathBuf, &size) < 0) { - return {}; + void setDataDir(const char *path) + { + if (path == nullptr) { + return; } - auto path = std::string(pathBuf, size); - const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR); - - if (pos != std::string::npos) { - return path.substr(0, pos); + std::string dir = path; + if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) { + dir.pop_back(); } - return path; + if (!dir.empty() && uv_chdir(dir.c_str()) == 0) { + dataDir = { dir.data(), dir.size() }; + } } - if (location == Process::CwdLocation) { - return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size); - } + Arguments arguments; + const char *version = APP_VERSION; - return {}; -} + int exitCode = 0; + String dataDir; + String userAgent; + Versions versions; + +# ifndef XMRIG_LEGACY + Events events; +# endif +}; -static void setDataDir(const char *path) -{ - if (path == nullptr) { - return; - } - - std::string dir = path; - if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) { - dir.pop_back(); - } - - if (!dir.empty() && uv_chdir(dir.c_str()) == 0) { - dataDir = dir; - } -} +Process::Private *Process::d = nullptr; } // namespace xmrig -xmrig::Process::Process(int argc, char **argv) : - m_arguments(argc, argv) +xmrig::Process::Process(int argc, char **argv) { + d = new Private(argc, argv); + + OS::init(); srand(static_cast(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast(this))); - setDataDir(m_arguments.value("--data-dir", "-d")); + d_fn()->setDataDir(arguments().value("--data-dir", "-d")); # ifdef XMRIG_SHARED_DATADIR - if (dataDir.empty()) { - dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, location(HomeLocation)); + if (d_fn()->dataDir.isEmpty()) { + auto dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, locate(HomeLocation)); MKDIR(dataDir); dataDir += APP_KIND; MKDIR(dataDir); - uv_chdir(dataDir.c_str()); + if (uv_chdir(dataDir.c_str()) == 0) { + d_fn()->dataDir = { dataDir.c_str(), dataDir.size() }; + } } # endif + + if (d_fn()->dataDir.isEmpty()) { + d_fn()->dataDir = locate(ExeLocation); + } +} + + +xmrig::Process::~Process() +{ + OS::destroy(); + + delete d; + + d = nullptr; +} + + +const xmrig::Arguments &xmrig::Process::arguments() +{ + return d_fn()->arguments; +} + + +const char *xmrig::Process::version() +{ + return d_fn()->version; +} + + +const xmrig::String &xmrig::Process::userAgent() +{ + if (d_fn()->userAgent.isEmpty()) { + d_fn()->userAgent = OS::userAgent().c_str(); + } + + return d_fn()->userAgent; +} + + +const xmrig::Versions &xmrig::Process::versions() +{ + return d_fn()->versions; +} + + +int xmrig::Process::exitCode() +{ + return d_fn()->exitCode; } @@ -148,20 +191,94 @@ int xmrig::Process::ppid() } -xmrig::String xmrig::Process::exepath() +xmrig::String xmrig::Process::locate(Location location, const char *fileName) { - size_t size = sizeof(pathBuf); - - return uv_exepath(pathBuf, &size) < 0 ? String("") : String(pathBuf, size); -} - - -xmrig::String xmrig::Process::location(Location location, const char *fileName) -{ - auto path = getPath(location); - if (path.empty() || fileName == nullptr) { - return path.c_str(); + auto path = locate(location); + if (path.isNull() || fileName == nullptr) { + return path; } return fmt::format("{}" XMRIG_DIR_SEPARATOR "{}", path, fileName).c_str(); } + + +xmrig::String xmrig::Process::locate(Location location) +{ + char buf[520]{}; + size_t size = sizeof(buf); + + if (location == ExePathLocation && uv_exepath(buf, &size) >= 0) { + return { buf, size }; + } + + if (location == Process::DataLocation && !d_fn()->dataDir.isEmpty()) { + return d_fn()->dataDir; + } + +# if UV_VERSION_HEX >= 0x010600 + if (location == Process::HomeLocation && uv_os_homedir(buf, &size) >= 0) { + return { buf, size }; + } +# endif + +# if UV_VERSION_HEX >= 0x010900 + if (location == Process::TempLocation && uv_os_tmpdir(buf, &size) >= 0) { + return { buf, size }; + } +# endif + + if (location == Process::CwdLocation && uv_cwd(buf, &size) >= 0) { + return { buf, size }; + } + + if (location == Process::ExeLocation) { + if (uv_exepath(buf, &size) < 0) { + return {}; + } + + auto path = std::string(buf, size); + const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR); + + if (pos != std::string::npos) { + return path.substr(0, pos).c_str(); + } + + return { buf, size }; + } + + return location != ExeLocation ? locate(ExeLocation) : String(); +} + + +void xmrig::Process::exit(int code) +{ + if (code != -1) { + d_fn()->exitCode = code; + } + +# ifndef XMRIG_LEGACY + events().post(exitCode()); +# endif +} + + +void xmrig::Process::setUserAgent(const String &userAgent) +{ + d_fn()->userAgent = userAgent; +} + + +#ifndef XMRIG_LEGACY +xmrig::Events &xmrig::Process::events() +{ + return d_fn()->events; +} +#endif + + +xmrig::Process::Private *xmrig::Process::d_fn() +{ + assert(d); + + return d; +} diff --git a/src/base/kernel/Process.h b/src/base/kernel/Process.h index 9af498f59..0f45f294c 100644 --- a/src/base/kernel/Process.h +++ b/src/base/kernel/Process.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,8 @@ #define XMRIG_PROCESS_H -#include "base/tools/Arguments.h" +#include "base/tools/Object.h" +#include "base/tools/String.h" #ifdef WIN32 @@ -33,10 +34,18 @@ namespace xmrig { +class Arguments; +class Events; +class Versions; + + class Process { public: + XMRIG_DISABLE_COPY_MOVE_DEFAULT(Process) + enum Location { + ExePathLocation, ExeLocation, CwdLocation, DataLocation, @@ -45,20 +54,34 @@ public: }; Process(int argc, char **argv); + ~Process(); + static const Arguments &arguments(); + static const char *version(); + static const String &userAgent(); + static const Versions &versions(); + static int exitCode(); static int pid(); static int ppid(); - static String exepath(); - static String location(Location location, const char *fileName = nullptr); + static String locate(Location location, const char *fileName); + static String locate(Location location); + static void exit(int code = -1); + static void setUserAgent(const String &userAgent); - inline const Arguments &arguments() const { return m_arguments; } +# ifndef XMRIG_LEGACY + static Events &events(); +# endif private: - Arguments m_arguments; + class Private; + + static Private *d_fn(); + + static Private *d; }; -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_PROCESS_H */ +#endif // XMRIG_PROCESS_H diff --git a/src/base/kernel/Versions.cpp b/src/base/kernel/Versions.cpp new file mode 100644 index 000000000..f08a53df9 --- /dev/null +++ b/src/base/kernel/Versions.cpp @@ -0,0 +1,203 @@ +/* XMRig + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "base/kernel/Versions.h" +#include "3rdparty/fmt/core.h" +#include "3rdparty/rapidjson/document.h" +#include "version.h" + + +#include + + +#ifdef XMRIG_FEATURE_HTTP +# include "3rdparty/llhttp/llhttp.h" +#endif + +#ifdef XMRIG_FEATURE_TLS +# include +#endif + +#ifdef XMRIG_FEATURE_SODIUM +# include +#endif + +#ifdef XMRIG_FEATURE_SQLITE +# include "3rdparty/sqlite/sqlite3.h" +#endif + +#ifdef XMRIG_FEATURE_HWLOC +# include "backend/cpu/Cpu.h" +#endif + +#ifdef XMRIG_FEATURE_POSTGRESQL +# include +#endif + + +namespace xmrig { + + +const char *Versions::kApp = "app"; +const char *Versions::kBase = "base"; +const char *Versions::kFmt = "fmt"; +const char *Versions::kRapidjson = "rapidjson"; +const char *Versions::kUv = "uv"; + +#if defined (__INTEL_LLVM_COMPILER) + const char *Versions::kCompiler = "icx"; +#elif defined(__INTEL_COMPILER) + const char *Versions::kCompiler = "icc"; +#elif defined(__clang__) + const char *Versions::kCompiler = "clang"; +#elif defined(__GNUC__) + const char *Versions::kCompiler = "gcc"; +#elif defined(_MSC_VER) +# if (_MSC_VER >= 1930) +# define MSVC_VERSION 2022 +# elif (_MSC_VER >= 1920 && _MSC_VER < 1930) +# define MSVC_VERSION 2019 +# elif (_MSC_VER >= 1910 && _MSC_VER < 1920) +# define MSVC_VERSION 2017 +# elif _MSC_VER == 1900 +# define MSVC_VERSION 2015 +# else +# define MSVC_VERSION 0 +# endif + const char *Versions::kCompiler = "MSVC"; +#else + const char *Versions::kCompiler = "unknown"; +#endif + + +#ifdef XMRIG_FEATURE_HTTP +const char *Versions::kLlhttp = "llhttp"; +#endif + +#ifdef XMRIG_FEATURE_TLS +# if defined(LIBRESSL_VERSION_TEXT) + const char *Versions::kTls = "libressl"; +# else + const char *Versions::kTls = "openssl"; +# endif +#endif + +#ifdef XMRIG_FEATURE_SODIUM +const char *Versions::kSodium = "sodium"; +#endif + +#ifdef XMRIG_FEATURE_SQLITE +const char *Versions::kSqlite = "sqlite"; +#endif + +#ifdef XMRIG_FEATURE_HWLOC +const char *Versions::kHwloc = "hwloc"; +#endif + +#ifdef XMRIG_FEATURE_POSTGRESQL +const char *kPq = "pq"; +#endif + + +} // namespace xmrig + + +xmrig::Versions::Versions() +{ + m_data.insert({ kApp, APP_VERSION }); + m_data.insert({ kBase, fmt::format("{}.{}.{}", XMRIG_BASE_VERSION / 10000, XMRIG_BASE_VERSION / 100 % 100, XMRIG_BASE_VERSION % 100).c_str() }); + m_data.insert({ kUv, uv_version_string() }); + m_data.insert({ kRapidjson, RAPIDJSON_VERSION_STRING }); + m_data.insert({ kFmt, fmt::format("{}.{}.{}", FMT_VERSION / 10000, FMT_VERSION / 100 % 100, FMT_VERSION % 100).c_str() }); + +# if defined (__INTEL_LLVM_COMPILER) + m_data.insert({ kCompiler, fmt::format("{}.{}.{}", __INTEL_LLVM_COMPILER / 10000, __INTEL_LLVM_COMPILER / 100 % 100, __INTEL_LLVM_COMPILER % 100).c_str() }); +# elif defined (__INTEL_COMPILER) +# if (__INTEL_COMPILER >= 2020) + m_data.insert({ kCompiler, XMRIG_TOSTRING(__INTEL_COMPILER) }); +# else + m_data.insert({ kCompiler, fmt::format("{}.{}.{}", __INTEL_COMPILER / 100, __INTEL_COMPILER / 10 % 10, __INTEL_COMPILER % 10).c_str() }); +# endif +# elif defined(__clang__) + m_data.insert({ kCompiler, XMRIG_TOSTRING(__clang_major__.__clang_minor__.__clang_patchlevel__) }); +# elif defined(__GNUC__) + m_data.insert({ kCompiler, XMRIG_TOSTRING(__GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__) }); +# elif defined(_MSC_VER) + m_data.insert({ kCompiler, XMRIG_TOSTRING(MSVC_VERSION) }); +# endif + +# ifdef XMRIG_FEATURE_HTTP + m_data.insert({ kLlhttp, XMRIG_TOSTRING(LLHTTP_VERSION_MAJOR.LLHTTP_VERSION_MINOR.LLHTTP_VERSION_PATCH) }); +# endif + +# ifdef XMRIG_FEATURE_TLS +# if defined(LIBRESSL_VERSION_TEXT) + m_data.insert({ kTls, String(LIBRESSL_VERSION_TEXT).split(' ')[1] }); +# elif defined(OPENSSL_VERSION_TEXT) + m_data.insert({ kTls, String(OPENSSL_VERSION_TEXT).split(' ')[1] }); +# endif +# endif + +# ifdef XMRIG_FEATURE_SODIUM + m_data.insert({ kSodium, sodium_version_string() }); +# endif + +# ifdef XMRIG_FEATURE_SQLITE + m_data.insert({ kSqlite, sqlite3_libversion() }); +# endif + +# if defined(XMRIG_FEATURE_HWLOC) && defined(XMRIG_LEGACY) + m_data.insert({ kHwloc, String(Cpu::info()->backend()).split('/')[1] }); +# endif + +# ifdef XMRIG_FEATURE_POSTGRESQL + m_data.insert({ kPq, fmt::format("{}.{}", PQlibVersion() / 10000, PQlibVersion() % 100).c_str() }); +# endif +} + + +const xmrig::String &xmrig::Versions::get(const char *key) const +{ + static const String empty; + + const auto it = m_data.find(key); + + return it != m_data.end() ? it->second : empty; +} + + +rapidjson::Value xmrig::Versions::toJSON(rapidjson::Document &doc) const +{ + using namespace rapidjson; + + Value out(kObjectType); + toJSON(out, doc); + + return out; +} + + +void xmrig::Versions::toJSON(rapidjson::Value &out, rapidjson::Document &doc) const +{ + auto &allocator = doc.GetAllocator(); + const auto &data = get(); + + for (const auto &kv : data) { + out.AddMember(kv.first.toJSON(), kv.second.toJSON(), allocator); + } +} diff --git a/src/base/kernel/Versions.h b/src/base/kernel/Versions.h new file mode 100644 index 000000000..b63ef16e2 --- /dev/null +++ b/src/base/kernel/Versions.h @@ -0,0 +1,83 @@ +/* XMRig + * Copyright (c) 2018-2021 SChernykh + * Copyright (c) 2016-2021 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_VERSIONS_H +#define XMRIG_VERSIONS_H + + +#include "base/tools/String.h" + + +#include + + +namespace xmrig { + + +class Versions +{ +public: + static const char *kApp; + static const char *kBase; + static const char *kCompiler; + static const char *kFmt; + static const char *kRapidjson; + static const char *kUv; + +# ifdef XMRIG_FEATURE_HTTP + static const char *kLlhttp; +# endif + +# ifdef XMRIG_FEATURE_TLS + static const char *kTls; +# endif + +# ifdef XMRIG_FEATURE_SODIUM + static const char *kSodium; +# endif + +# ifdef XMRIG_FEATURE_SQLITE + static const char *kSqlite; +# endif + +# ifdef XMRIG_FEATURE_HWLOC + static const char *kHwloc; +# endif + +# ifdef XMRIG_FEATURE_POSTGRESQL + static const char *kPq; +# endif + + Versions(); + + inline const std::map &get() const { return m_data; } + inline const String &operator[](const char *key) const { return get(key); } + + const String &get(const char *key) const; + rapidjson::Value toJSON(rapidjson::Document &doc) const; + void toJSON(rapidjson::Value &out, rapidjson::Document &doc) const; + +private: + std::map m_data; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_VERSIONS_H */ diff --git a/src/base/kernel/base-version.h b/src/base/kernel/base-version.h new file mode 100644 index 000000000..0824c1d7a --- /dev/null +++ b/src/base/kernel/base-version.h @@ -0,0 +1,49 @@ +/* XMRig + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef XMRIG_BASE_VERSION_H +#define XMRIG_BASE_VERSION_H + +// The base version in the form major * 10000 + minor * 100 + patch. +#define XMRIG_BASE_VERSION 70000 + +#ifndef APP_DOMAIN +# define APP_DOMAIN "xmrig.com" +#endif + +#ifndef APP_COPYRIGHT +# define APP_COPYRIGHT "Copyright (C) 2016-2022 xmrig.com" +#endif + +#define XMRIG_STRINGIFY(x) #x +#define XMRIG_TOSTRING(x) XMRIG_STRINGIFY(x) + +#ifdef GIT_COMMIT_HASH +# define XMRIG_GIT_COMMIT_HASH XMRIG_TOSTRING(GIT_COMMIT_HASH) +#else +# define XMRIG_GIT_COMMIT_HASH "0000000" +#endif + +#ifdef GIT_BRANCH +# define XMRIG_GIT_BRANCH XMRIG_TOSTRING(GIT_BRANCH) +# define APP_VERSION XMRIG_TOSTRING(APP_VER_MAJOR.APP_VER_MINOR.APP_VER_PATCH) "-" XMRIG_GIT_BRANCH +#else +# define APP_VERSION XMRIG_TOSTRING(APP_VER_MAJOR.APP_VER_MINOR.APP_VER_PATCH) +#endif + +#endif // XMRIG_BASE_VERSION_H diff --git a/src/base/kernel/config/BaseTransform.cpp b/src/base/kernel/config/BaseTransform.cpp index c924dd59a..b1d8201d5 100644 --- a/src/base/kernel/config/BaseTransform.cpp +++ b/src/base/kernel/config/BaseTransform.cpp @@ -35,6 +35,7 @@ #include "base/net/dns/DnsConfig.h" #include "base/net/stratum/Pool.h" #include "base/net/stratum/Pools.h" +#include "base/tools/Arguments.h" #include "core/config/Config_platform.h" diff --git a/src/base/net/http/HttpClient.cpp b/src/base/net/http/HttpClient.cpp index 3b1e5ad3b..e93d74e8a 100644 --- a/src/base/net/http/HttpClient.cpp +++ b/src/base/net/http/HttpClient.cpp @@ -17,11 +17,10 @@ * along with this program. If not, see . */ - #include "base/net/http/HttpClient.h" #include "3rdparty/llhttp/llhttp.h" #include "base/io/log/Log.h" -#include "base/kernel/Platform.h" +#include "base/kernel/Process.h" #include "base/net/dns/Dns.h" #include "base/net/dns/DnsRecords.h" #include "base/net/tools/NetBuffer.h" @@ -95,7 +94,7 @@ void xmrig::HttpClient::handshake() { headers.insert({ "Host", host() }); headers.insert({ "Connection", "close" }); - headers.insert({ "User-Agent", Platform::userAgent().data() }); + headers.insert({ "User-Agent", Process::userAgent().data() }); if (!body.empty()) { headers.insert({ "Content-Length", std::to_string(body.size()) }); diff --git a/src/base/net/stratum/Pool.cpp b/src/base/net/stratum/Pool.cpp index e11e8717f..8a77517e6 100644 --- a/src/base/net/stratum/Pool.cpp +++ b/src/base/net/stratum/Pool.cpp @@ -28,7 +28,7 @@ #include "3rdparty/rapidjson/document.h" #include "base/io/json/Json.h" #include "base/io/log/Log.h" -#include "base/kernel/Platform.h" +#include "base/kernel/Process.h" #include "base/net/stratum/Client.h" #if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER @@ -224,12 +224,12 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con # if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER const uint32_t f = m_algorithm.family(); if ((f == Algorithm::KAWPOW) || (f == Algorithm::GHOSTRIDER) || (m_coin == Coin::RAVEN)) { - client = new EthStratumClient(id, Platform::userAgent(), listener); + client = new EthStratumClient(id, Process::userAgent(), listener); } else # endif { - client = new Client(id, Platform::userAgent(), listener); + client = new Client(id, Process::userAgent(), listener); } } # ifdef XMRIG_FEATURE_HTTP @@ -237,12 +237,12 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con client = new DaemonClient(id, listener); } else if (m_mode == MODE_SELF_SELECT) { - client = new SelfSelectClient(id, Platform::userAgent(), listener, m_submitToOrigin); + client = new SelfSelectClient(id, Process::userAgent(), listener, m_submitToOrigin); } # endif # if defined XMRIG_ALGO_KAWPOW || defined XMRIG_ALGO_GHOSTRIDER else if (m_mode == MODE_AUTO_ETH) { - client = new AutoClient(id, Platform::userAgent(), listener); + client = new AutoClient(id, Process::userAgent(), listener); } # endif # ifdef XMRIG_FEATURE_BENCHMARK diff --git a/src/base/net/tls/TlsGen.cpp b/src/base/net/tls/TlsGen.cpp index 5d02cae26..6990ceb80 100644 --- a/src/base/net/tls/TlsGen.cpp +++ b/src/base/net/tls/TlsGen.cpp @@ -18,7 +18,6 @@ #include "base/net/tls/TlsGen.h" #include "base/io/log/Log.h" -#include "version.h" #include @@ -106,7 +105,7 @@ void xmrig::TlsGen::generate(const char *commonName) throw std::runtime_error("unable to write certificate to disk."); } -# if defined(XMRIG_BASE_VERSION) +# if !defined(XMRIG_LEGACY) LOG_NOTICE("%s " MAGENTA_BOLD("generated") WHITE_BOLD(" \"%s/%s\" ") "CN=" WHITE_BOLD("\"%s\""), tls_tag(), m_cert.data(), m_certKey.data(), cn()); # endif } diff --git a/src/base/tools/cryptonote/Signatures.cpp b/src/base/tools/cryptonote/Signatures.cpp index 935712585..6cd4b36d8 100644 --- a/src/base/tools/cryptonote/Signatures.cpp +++ b/src/base/tools/cryptonote/Signatures.cpp @@ -1,8 +1,8 @@ /* XMRig - * Copyright 2012-2013 The Cryptonote developers - * Copyright 2014-2021 The Monero Project - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright (c) 2012-2013 The Cryptonote developers + * Copyright (c) 2014-2021 The Monero Project + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,49 +18,54 @@ * along with this program. If not, see . */ - #include "base/crypto/keccak.h" #include "base/tools/cryptonote/Signatures.h" +#include "base/tools/Cvt.h" extern "C" { -#include "base/tools/cryptonote/crypto-ops.h" +#ifdef XMRIG_LEGACY +# include "base/tools/cryptonote/crypto-ops.h" +#else +# include "3rdparty/cryptonote/crypto-ops.h" +#endif } -#include "base/tools/Cvt.h" - -#ifdef XMRIG_PROXY_PROJECT -#define PROFILE_SCOPE(x) +#if defined(XMRIG_PROXY_PROJECT) || !defined(XMRIG_PROFILER_H) +# define PROFILE_SCOPE(x) #else -#include "crypto/rx/Profiler.h" +# include "crypto/rx/Profiler.h" #endif -struct ec_scalar { char data[32]; }; -struct hash { char data[32]; }; -struct ec_point { char data[32]; }; -struct signature { ec_scalar c, r; }; -struct s_comm { hash h; ec_point key; ec_point comm; }; +namespace xmrig { -static inline void random_scalar(ec_scalar& res) +struct ec_scalar { uint8_t data[32]; }; +struct hash { uint8_t data[32]; }; +struct ec_point { uint8_t data[32]; }; +struct signature { ec_scalar c, r; }; +struct s_comm { hash h; ec_point key; ec_point comm; }; + + +static inline void random_scalar(ec_scalar &res) { // Don't care about bias or possible 0 after reduce: probability ~10^-76, not happening in this universe. // Performance matters more. It's a miner after all. - xmrig::Cvt::randomBytes(res.data, sizeof(res.data)); - sc_reduce32((uint8_t*) res.data); + Cvt::randomBytes(res.data, sizeof(res.data)); + sc_reduce32(res.data); } -static void hash_to_scalar(const void* data, size_t length, ec_scalar& res) +static void hash_to_scalar(const void* data, size_t length, ec_scalar &res) { - xmrig::keccak((const uint8_t*) data, length, (uint8_t*) &res, sizeof(res)); - sc_reduce32((uint8_t*) &res); + keccak(reinterpret_cast(data), length, res.data, sizeof(res)); + sc_reduce32(res.data); } -static void derivation_to_scalar(const uint8_t* derivation, size_t output_index, ec_scalar& res) +static void derivation_to_scalar(const uint8_t *derivation, size_t output_index, ec_scalar &res) { struct { uint8_t derivation[32]; @@ -81,10 +86,11 @@ static void derivation_to_scalar(const uint8_t* derivation, size_t output_index, } -namespace xmrig { +} // namespace xmrig -void generate_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sec, uint8_t* sig_bytes) +// NOLINTNEXTLINE(readability-non-const-parameter) +void xmrig::generate_signature(const uint8_t *prefix_hash, const uint8_t *pub, const uint8_t *sec, uint8_t *sig_bytes) { PROFILE_SCOPE(GenerateSignature); @@ -95,24 +101,24 @@ void generate_signature(const uint8_t* prefix_hash, const uint8_t* pub, const ui memcpy(buf.h.data, prefix_hash, sizeof(buf.h.data)); memcpy(buf.key.data, pub, sizeof(buf.key.data)); - signature& sig = *reinterpret_cast(sig_bytes); + signature &sig = *reinterpret_cast(sig_bytes); do { random_scalar(k); - ge_scalarmult_base(&tmp3, (unsigned char*)&k); - ge_p3_tobytes((unsigned char*)&buf.comm, &tmp3); + ge_scalarmult_base(&tmp3, k.data); + ge_p3_tobytes(buf.comm.data, &tmp3); hash_to_scalar(&buf, sizeof(s_comm), sig.c); - if (!sc_isnonzero((const unsigned char*)sig.c.data)) { + if (!sc_isnonzero(sig.c.data)) { continue; } - sc_mulsub((unsigned char*)&sig.r, (unsigned char*)&sig.c, sec, (unsigned char*)&k); - } while (!sc_isnonzero((const unsigned char*)sig.r.data)); + sc_mulsub(sig.r.data, sig.c.data, sec, k.data); + } while (!sc_isnonzero(sig.r.data)); } -bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sig_bytes) +bool xmrig::check_signature(const uint8_t *prefix_hash, const uint8_t *pub, const uint8_t *sig_bytes) { ge_p2 tmp2; ge_p3 tmp3; @@ -126,14 +132,14 @@ bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8 return false; } - const signature& sig = *reinterpret_cast(sig_bytes); + const signature &sig = *reinterpret_cast(sig_bytes); - if (sc_check((const uint8_t*)&sig.c) != 0 || sc_check((const uint8_t*)&sig.r) != 0 || !sc_isnonzero((const uint8_t*)&sig.c)) { + if (sc_check(sig.c.data) != 0 || sc_check(sig.r.data) != 0 || !sc_isnonzero(sig.c.data)) { return false; } - ge_double_scalarmult_base_vartime(&tmp2, (const uint8_t*)&sig.c, &tmp3, (const uint8_t*)&sig.r); - ge_tobytes((uint8_t*)&buf.comm, &tmp2); + ge_double_scalarmult_base_vartime(&tmp2, sig.c.data, &tmp3, sig.r.data); + ge_tobytes(buf.comm.data, &tmp2); static const ec_point infinity = { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; if (memcmp(&buf.comm, &infinity, 32) == 0) { @@ -141,13 +147,13 @@ bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8 } hash_to_scalar(&buf, sizeof(s_comm), c); - sc_sub((uint8_t*)&c, (uint8_t*)&c, (const uint8_t*)&sig.c); + sc_sub(c.data, c.data, sig.c.data); - return sc_isnonzero((uint8_t*)&c) == 0; + return sc_isnonzero(c.data) == 0; } -bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation) +bool xmrig::generate_key_derivation(const uint8_t *key1, const uint8_t *key2, uint8_t *derivation) { ge_p3 point; ge_p2 point2; @@ -166,16 +172,16 @@ bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* } -void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key) +void xmrig::derive_secret_key(const uint8_t *derivation, size_t output_index, const uint8_t *base, uint8_t *derived_key) { ec_scalar scalar; derivation_to_scalar(derivation, output_index, scalar); - sc_add(derived_key, base, (uint8_t*) &scalar); + sc_add(derived_key, base, scalar.data); } -bool derive_public_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key) +bool xmrig::derive_public_key(const uint8_t *derivation, size_t output_index, const uint8_t *base, uint8_t *derived_key) { ec_scalar scalar; ge_p3 point1; @@ -189,7 +195,7 @@ bool derive_public_key(const uint8_t* derivation, size_t output_index, const uin } derivation_to_scalar(derivation, output_index, scalar); - ge_scalarmult_base(&point2, (uint8_t*) &scalar); + ge_scalarmult_base(&point2, scalar.data); ge_p3_to_cached(&point3, &point2); ge_add(&point4, &point1, &point3); ge_p1p1_to_p2(&point5, &point4); @@ -199,14 +205,14 @@ bool derive_public_key(const uint8_t* derivation, size_t output_index, const uin } -void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key) +void xmrig::derive_view_secret_key(const uint8_t *spend_secret_key, uint8_t *view_secret_key) { keccak(spend_secret_key, 32, view_secret_key, 32); sc_reduce32(view_secret_key); } -void generate_keys(uint8_t* pub, uint8_t* sec) +void xmrig::generate_keys(uint8_t *pub, uint8_t *sec) { random_scalar(*((ec_scalar*)sec)); @@ -216,7 +222,7 @@ void generate_keys(uint8_t* pub, uint8_t* sec) } -bool secret_key_to_public_key(const uint8_t* sec, uint8_t* pub) +bool xmrig::secret_key_to_public_key(const uint8_t *sec, uint8_t *pub) { if (sc_check(sec) != 0) { return false; @@ -228,6 +234,3 @@ bool secret_key_to_public_key(const uint8_t* sec, uint8_t* pub) return true; } - - -} /* namespace xmrig */ diff --git a/src/base/tools/cryptonote/Signatures.h b/src/base/tools/cryptonote/Signatures.h index 048133139..98846fb1d 100644 --- a/src/base/tools/cryptonote/Signatures.h +++ b/src/base/tools/cryptonote/Signatures.h @@ -1,8 +1,8 @@ /* XMRig - * Copyright 2012-2013 The Cryptonote developers - * Copyright 2014-2021 The Monero Project - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright (c) 2012-2013 The Cryptonote developers + * Copyright (c) 2014-2021 The Monero Project + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,19 +28,19 @@ namespace xmrig { -void generate_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sec, uint8_t* sig); -bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8_t* sig); +void generate_signature(const uint8_t *prefix_hash, const uint8_t *pub, const uint8_t *sec, uint8_t *sig); +bool check_signature(const uint8_t *prefix_hash, const uint8_t *pub, const uint8_t *sig_bytes); -bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation); -void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); -bool derive_public_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); +bool generate_key_derivation(const uint8_t *key1, const uint8_t *key2, uint8_t *derivation); +void derive_secret_key(const uint8_t *derivation, size_t output_index, const uint8_t *base, uint8_t *derived_key); +bool derive_public_key(const uint8_t *derivation, size_t output_index, const uint8_t *base, uint8_t *derived_key); -void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key); +void derive_view_secret_key(const uint8_t *spend_secret_key, uint8_t *view_secret_key); -void generate_keys(uint8_t* pub, uint8_t* sec); -bool secret_key_to_public_key(const uint8_t* sec, uint8_t* pub); +void generate_keys(uint8_t *pub, uint8_t *sec); +bool secret_key_to_public_key(const uint8_t *sec, uint8_t *pub); -} /* namespace xmrig */ +} // namespace xmrig -#endif /* XMRIG_SIGNATURES_H */ +#endif // XMRIG_SIGNATURES_H diff --git a/src/base/tools/cryptonote/umul128.h b/src/base/tools/cryptonote/umul128.h index 3c9d1c2ae..fd326b582 100644 --- a/src/base/tools/cryptonote/umul128.h +++ b/src/base/tools/cryptonote/umul128.h @@ -1,33 +1,32 @@ -/* - * 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 - * 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 . - * +/* XMRig + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * * Additional permission under GNU GPL version 3 section 7 * * If you modify this Program, or any covered work, by linking or combining * it with OpenSSL (or a modified version of that library), containing parts * covered by the terms of OpenSSL License and SSLeay License, the licensors * of this Program grant you additional permission to convey the resulting work. - * - */ + */ #ifndef XMRIG_UMUL128_H #define XMRIG_UMUL128_H -#include "version.h" - - #include @@ -72,7 +71,7 @@ static inline uint64_t xmrig_umul128(uint64_t multiplier, uint64_t multiplicand, #endif -#if !defined(XMRIG_BASE_VERSION) +#if defined(XMRIG_LEGACY) # define __umul128 xmrig_umul128 #endif diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 8bfccd642..075cce2be 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,19 +22,20 @@ #include "core/Miner.h" -#include "core/Taskbar.h" #include "3rdparty/rapidjson/document.h" #include "backend/common/Hashrate.h" #include "backend/cpu/Cpu.h" #include "backend/cpu/CpuBackend.h" #include "base/io/log/Log.h" #include "base/io/log/Tags.h" -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" +#include "base/kernel/Process.h" #include "base/net/stratum/Job.h" #include "base/tools/Object.h" #include "base/tools/Timer.h" #include "core/config/Config.h" #include "core/Controller.h" +#include "core/Taskbar.h" #include "crypto/common/Nonce.h" #include "version.h" @@ -154,7 +155,7 @@ public: reply.AddMember("version", APP_VERSION, allocator); reply.AddMember("kind", APP_KIND, allocator); - reply.AddMember("ua", Platform::userAgent().toJSON(), allocator); + reply.AddMember("ua", Process::userAgent().toJSON(), allocator); reply.AddMember("cpu", Cpu::toJSON(doc), allocator); reply.AddMember("donate_level", controller->config()->pools().donateLevel(), allocator); reply.AddMember("paused", !enabled, allocator); @@ -387,8 +388,8 @@ xmrig::Miner::Miner(Controller *controller) { const int priority = controller->config()->cpu().priority(); if (priority >= 0) { - Platform::setProcessPriority(priority); - Platform::setThreadPriority(std::min(priority + 1, 5)); + OS::setProcessPriority(priority); + OS::setThreadPriority(std::min(priority + 1, 5)); } # ifdef XMRIG_FEATURE_PROFILING @@ -669,11 +670,11 @@ void xmrig::Miner::onTimer(const Timer *) }; if (config->isPauseOnBattery()) { - autoPause(d_ptr->battery_power, Platform::isOnBatteryPower(), YELLOW_BOLD("on battery power"), GREEN_BOLD("on AC power")); + autoPause(d_ptr->battery_power, OS::isOnBatteryPower(), YELLOW_BOLD("on battery power"), GREEN_BOLD("on AC power")); } if (config->isPauseOnActive()) { - autoPause(d_ptr->user_active, Platform::isUserActive(config->idleTime()), YELLOW_BOLD("user active"), GREEN_BOLD("user inactive")); + autoPause(d_ptr->user_active, OS::isUserActive(config->idleTime()), YELLOW_BOLD("user active"), GREEN_BOLD("user inactive")); } if (stopMiner) { diff --git a/src/core/Miner.h b/src/core/Miner.h index bb4293d08..3564ca7d7 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/crypto/ghostrider/ghostrider.cpp b/src/crypto/ghostrider/ghostrider.cpp index 0ce0976eb..942525956 100644 --- a/src/crypto/ghostrider/ghostrider.cpp +++ b/src/crypto/ghostrider/ghostrider.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright 2018-2022 SChernykh + * Copyright 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,7 +16,6 @@ * along with this program. If not, see . */ - #include "ghostrider.h" #include "sph_blake.h" #include "sph_bmw.h" @@ -48,7 +47,7 @@ #include #ifdef XMRIG_FEATURE_HWLOC -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include "backend/cpu/platform/HwlocCpuInfo.h" #include #endif @@ -241,7 +240,7 @@ struct HelperThread } } - Platform::setThreadPriority(m_priority); + OS::setThreadPriority(m_priority); uv_mutex_lock(&m_mutex); m_ready = true; @@ -299,8 +298,8 @@ void benchmark() std::swap(thread_index1, thread_index2); } - Platform::setThreadAffinity(thread_index1); - Platform::setThreadPriority(3); + OS::setThreadAffinity(thread_index1); + OS::setThreadPriority(3); constexpr uint32_t N = 1U << 21; diff --git a/src/crypto/ghostrider/ghostrider.h b/src/crypto/ghostrider/ghostrider.h index e6c08df1b..ccc5dde6e 100644 --- a/src/crypto/ghostrider/ghostrider.h +++ b/src/crypto/ghostrider/ghostrider.h @@ -1,6 +1,6 @@ /* XMRig - * Copyright 2018-2021 SChernykh - * Copyright 2016-2021 XMRig , + * Copyright 2018-2022 SChernykh + * Copyright 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,4 +49,4 @@ void hash_octa(const uint8_t* data, size_t size, uint8_t* output, cryptonight_ct } // namespace xmrig -#endif // XMRIG_GR_HASH_H \ No newline at end of file +#endif // XMRIG_GR_HASH_H diff --git a/src/crypto/rx/RxDataset.cpp b/src/crypto/rx/RxDataset.cpp index 86b3a3f6d..71fa1c8ae 100644 --- a/src/crypto/rx/RxDataset.cpp +++ b/src/crypto/rx/RxDataset.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018-2019 tevador - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +21,7 @@ #include "backend/cpu/Cpu.h" #include "base/io/log/Log.h" #include "base/io/log/Tags.h" -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include "crypto/common/VirtualMemory.h" #include "crypto/randomx/randomx.h" #include "crypto/rx/RxAlgo.h" @@ -37,7 +37,7 @@ namespace xmrig { static void init_dataset_wrapper(randomx_dataset *dataset, randomx_cache *cache, uint32_t startItem, uint32_t itemCount, int priority) { - Platform::setThreadPriority(priority); + OS::setThreadPriority(priority); if (Cpu::info()->hasAVX2() && (itemCount % 5)) { randomx_init_dataset(dataset, cache, startItem, itemCount - (itemCount % 5)); diff --git a/src/crypto/rx/RxDataset.h b/src/crypto/rx/RxDataset.h index 4f9caadf4..97e78285e 100644 --- a/src/crypto/rx/RxDataset.h +++ b/src/crypto/rx/RxDataset.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018-2019 tevador - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/crypto/rx/RxNUMAStorage.cpp b/src/crypto/rx/RxNUMAStorage.cpp index b6345a061..e64a35927 100644 --- a/src/crypto/rx/RxNUMAStorage.cpp +++ b/src/crypto/rx/RxNUMAStorage.cpp @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018-2019 tevador - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #include "backend/cpu/platform/HwlocCpuInfo.h" #include "base/io/log/Log.h" #include "base/io/log/Tags.h" -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include "base/tools/Chrono.h" #include "crypto/rx/RxAlgo.h" #include "crypto/rx/RxCache.h" @@ -52,7 +52,7 @@ static bool bindToNUMANode(uint32_t nodeId) } if (cpu->membind(node->nodeset)) { - Platform::setThreadAffinity(static_cast(hwloc_bitmap_first(node->cpuset))); + OS::setThreadAffinity(static_cast(hwloc_bitmap_first(node->cpuset))); return true; } diff --git a/src/crypto/rx/RxNUMAStorage.h b/src/crypto/rx/RxNUMAStorage.h index 33d5b92ab..59ca75184 100644 --- a/src/crypto/rx/RxNUMAStorage.h +++ b/src/crypto/rx/RxNUMAStorage.h @@ -1,7 +1,7 @@ /* XMRig * Copyright (c) 2018-2019 tevador - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/hw/msr/Msr_win.cpp b/src/hw/msr/Msr_win.cpp index ee5cc85af..06f55f6a3 100644 --- a/src/hw/msr/Msr_win.cpp +++ b/src/hw/msr/Msr_win.cpp @@ -1,6 +1,6 @@ /* XMRig - * Copyright (c) 2018-2021 SChernykh - * Copyright (c) 2016-2021 XMRig , + * Copyright (c) 2018-2022 SChernykh + * Copyright (c) 2016-2022 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,11 +16,10 @@ * along with this program. If not, see . */ - #include "hw/msr/Msr.h" #include "backend/cpu/Cpu.h" #include "base/io/log/Log.h" -#include "base/kernel/Platform.h" +#include "base/kernel/OS.h" #include @@ -213,7 +212,7 @@ bool xmrig::Msr::write(Callback &&callback) std::thread thread([&callback, &units, &success]() { for (int32_t pu : units) { - if (!Platform::setThreadAffinity(pu)) { + if (!OS::setThreadAffinity(pu)) { continue; } diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index cdaf2258f..3f643ef75 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -24,7 +24,7 @@ #include "net/strategies/DonateStrategy.h" #include "3rdparty/rapidjson/document.h" #include "base/crypto/keccak.h" -#include "base/kernel/Platform.h" +#include "base/kernel/Process.h" #include "base/net/stratum/Client.h" #include "base/net/stratum/Job.h" #include "base/net/stratum/strategies/FailoverStrategy.h" @@ -262,7 +262,7 @@ xmrig::IClient *xmrig::DonateStrategy::createProxy() pool.setAlgo(client->pool().algorithm()); pool.setProxy(client->pool().proxy()); - IClient *proxy = new Client(-1, Platform::userAgent(), this); + IClient *proxy = new Client(-1, Process::userAgent(), this); proxy->setPool(pool); proxy->setQuiet(true); diff --git a/src/version.h b/src/version.h index 50c6fd273..d15804d8d 100644 --- a/src/version.h +++ b/src/version.h @@ -14,6 +14,13 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * Additional permission under GNU GPL version 3 section 7 + * + * If you modify this Program, or any covered work, by linking or combining + * it with OpenSSL (or a modified version of that library), containing parts + * covered by the terms of OpenSSL License and SSLeay License, the licensors + * of this Program grant you additional permission to convey the resulting work. */ #ifndef XMRIG_VERSION_H @@ -22,34 +29,12 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "XMRig miner" -#define APP_VERSION "6.17.1-dev" -#define APP_DOMAIN "xmrig.com" -#define APP_SITE "www.xmrig.com" -#define APP_COPYRIGHT "Copyright (C) 2016-2022 xmrig.com" #define APP_KIND "miner" #define APP_VER_MAJOR 6 -#define APP_VER_MINOR 17 -#define APP_VER_PATCH 1 +#define APP_VER_MINOR 99 +#define APP_VER_PATCH 0 -#ifdef _MSC_VER -# if (_MSC_VER >= 1930) -# define MSVC_VERSION 2022 -# elif (_MSC_VER >= 1920 && _MSC_VER < 1930) -# define MSVC_VERSION 2019 -# elif (_MSC_VER >= 1910 && _MSC_VER < 1920) -# define MSVC_VERSION 2017 -# elif _MSC_VER == 1900 -# define MSVC_VERSION 2015 -# elif _MSC_VER == 1800 -# define MSVC_VERSION 2013 -# elif _MSC_VER == 1700 -# define MSVC_VERSION 2012 -# elif _MSC_VER == 1600 -# define MSVC_VERSION 2010 -# else -# define MSVC_VERSION 0 -# endif -#endif +#include "base/kernel/base-version.h" #endif /* XMRIG_VERSION_H */