Browse Source

Sync with base.

pull/3093/head
XMRig 2 years ago
parent
commit
8a167cb2a7
No known key found for this signature in database GPG Key ID: 446A53638BE94409
  1. 2
      CMakeLists.txt
  2. 2
      res/app.rc
  3. 1
      src/App.cpp
  4. 10
      src/backend/common/Worker.cpp
  5. 7
      src/base/api/Api.cpp
  6. 16
      src/base/base.cmake
  7. 8
      src/base/crypto/Algorithm.h
  8. 4
      src/base/crypto/Coin.cpp
  9. 8
      src/base/crypto/Coin.h
  10. 44
      src/base/io/Env.cpp
  11. 5
      src/base/io/Env.h
  12. 11
      src/base/kernel/Base.cpp
  13. 14
      src/base/kernel/Entry.cpp
  14. 10
      src/base/kernel/Entry.h
  15. 78
      src/base/kernel/Lib.cpp
  16. 53
      src/base/kernel/Lib.h
  17. 99
      src/base/kernel/OS.cpp
  18. 43
      src/base/kernel/OS.h
  19. 9
      src/base/kernel/OS_hwloc.cpp
  20. 84
      src/base/kernel/OS_mac.cpp
  21. 92
      src/base/kernel/OS_unix.cpp
  22. 145
      src/base/kernel/OS_win.cpp
  23. 261
      src/base/kernel/Process.cpp
  24. 41
      src/base/kernel/Process.h
  25. 203
      src/base/kernel/Versions.cpp
  26. 83
      src/base/kernel/Versions.h
  27. 49
      src/base/kernel/base-version.h
  28. 1
      src/base/kernel/config/BaseTransform.cpp
  29. 5
      src/base/net/http/HttpClient.cpp
  30. 10
      src/base/net/stratum/Pool.cpp
  31. 3
      src/base/net/tls/TlsGen.cpp
  32. 101
      src/base/tools/cryptonote/Signatures.cpp
  33. 28
      src/base/tools/cryptonote/Signatures.h
  34. 39
      src/base/tools/cryptonote/umul128.h
  35. 19
      src/core/Miner.cpp
  36. 4
      src/core/Miner.h
  37. 13
      src/crypto/ghostrider/ghostrider.cpp
  38. 6
      src/crypto/ghostrider/ghostrider.h
  39. 8
      src/crypto/rx/RxDataset.cpp
  40. 4
      src/crypto/rx/RxDataset.h
  41. 8
      src/crypto/rx/RxNUMAStorage.cpp
  42. 4
      src/crypto/rx/RxNUMAStorage.h
  43. 9
      src/hw/msr/Msr_win.cpp
  44. 4
      src/net/strategies/DonateStrategy.cpp
  45. 35
      src/version.h

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

2
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

1
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"

10
src/backend/common/Worker.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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);
}

7
src/base/api/Api.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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();
}
}

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

8
src/base/crypto/Algorithm.h

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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<Algorithm>;
} /* namespace xmrig */
} // namespace xmrig
#endif /* XMRIG_ALGORITHM_H */
#endif // XMRIG_ALGORITHM_H

4
src/base/crypto/Coin.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

8
src/base/crypto/Coin.h

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

44
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 <regex>
#include <uv.h>
#include <map>
#ifndef _WIN32
# include <unistd.h>
#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<String, String>
return static_cast<const char *>(getenv(name)); // NOLINT(concurrency-mt-unsafe)
}
xmrig::String xmrig::Env::hostname()
{
char buf[UV_MAXHOSTNAMESIZE]{};
if (gethostname(buf, sizeof(buf)) == 0) {
return static_cast<const char *>(buf);
}
return {};
}

5
src/base/io/Env.h

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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<String, String> &extra = {});
static String get(const String &name, const std::map<String, String> &extra = {});
static String hostname();
};

11
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);

14
src/base/kernel/Entry.cpp

@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2016-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <cstdio>
#include <uv.h>
@ -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);

10
src/base/kernel/Entry.h

@ -1,12 +1,6 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2016-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

78
src/base/kernel/Lib.cpp

@ -0,0 +1,78 @@
/* XMRig
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/Lib.h"
#include <cassert>
#include <uv.h>
namespace xmrig {
class Lib::Private
{
public:
bool open = false;
uv_lib_t lib{};
};
} // namespace xmrig
xmrig::Lib::Lib() :
d(std::make_shared<Private>())
{
}
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;
}
}

53
src/base/kernel/Platform.cpp → src/base/kernel/Lib.h

@ -1,5 +1,5 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
@ -16,42 +16,39 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_LIB_H
#define XMRIG_LIB_H
#include "base/kernel/Platform.h"
#include "base/tools/Object.h"
#include <cstring>
#include <uv.h>
namespace xmrig {
#ifdef XMRIG_FEATURE_TLS
# include <openssl/ssl.h>
# include <openssl/err.h>
#endif
class Lib
{
public:
XMRIG_DISABLE_COPY_MOVE(Lib)
Lib();
inline ~Lib() { close(); }
namespace xmrig {
bool isOpen() const;
bool open(const char *filename);
bool sym(const char *name, void **ptr);
const char *lastError() const;
void close();
template<typename T>
inline bool sym(const char *name, T t) { return sym(name, reinterpret_cast<void **>(t)); }
private:
XMRIG_DECL_PRIVATE()
};
String Platform::m_userAgent;
} // 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

99
src/base/kernel/OS.cpp

@ -0,0 +1,99 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <uv.h>
#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 <unistd.h>
#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<const char *>(buf);
}
return {};
}
#endif
uint64_t xmrig::OS::freemem()
{
return uv_get_free_memory();
}
uint64_t xmrig::OS::totalmem()
{
return uv_get_total_memory();
}

43
src/base/kernel/Platform.h → src/base/kernel/OS.h

@ -16,50 +16,43 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_PLATFORM_H
#define XMRIG_PLATFORM_H
#ifndef XMRIG_OS_H
#define XMRIG_OS_H
#include <cstdint>
#include "base/tools/String.h"
#include "base/tools/String.h"
#include <string>
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<uint64_t>(cpu_id));
}
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<uint64_t>(cpu_id)); }
static bool isOnBatteryPower();
static bool setThreadAffinity(uint64_t cpu_id);
static void init(const char *userAgent);
static std::string name();
static std::string userAgent();
static String hostname();
static uint64_t freemem();
static uint64_t idleTime();
static uint64_t totalmem();
static void destroy();
static void init();
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 bool isOnBatteryPower();
static uint64_t idleTime();
private:
static char *createUserAgent();
static String m_userAgent;
};
} // namespace xmrig
#endif /* XMRIG_PLATFORM_H */
#endif // XMRIG_OS_H

9
src/base/kernel/Platform_hwloc.cpp → src/base/kernel/OS_hwloc.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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<HwlocCpuInfo *>(Cpu::info());
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast<unsigned>(cpu_id));

84
src/base/kernel/Platform_mac.cpp → src/base/kernel/OS_mac.cpp

@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <IOKit/IOKitLib.h>
#include <IOKit/ps/IOPowerSources.h>
#include <stdio.h>
@ -27,46 +26,58 @@
#include <fstream>
#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::OS::init()
{
}
void xmrig::Platform::setThreadPriority(int priority)
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;
}

92
src/base/kernel/Platform_unix.cpp → src/base/kernel/OS_unix.cpp

@ -37,8 +37,7 @@
#include <limits>
#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<uint64_t>::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<uint64_t>::max();
}

145
src/base/kernel/Platform_win.cpp → src/base/kernel/OS_win.cpp

@ -16,16 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <winsock2.h>
#include <windows.h>
#include <uv.h>
#include <limits>
#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()
{
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
} // namespace xmrig
# 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;
bool xmrig::OS::isOnBatteryPower()
{
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<const char *>(buf);
}
return {};
}
uint64_t xmrig::OS::idleTime()
{
LASTINPUTINFO info{};
info.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&info)) {
return std::numeric_limits<uint64_t>::max();
}
return static_cast<uint64_t>(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<uint64_t>::max();
}
return static_cast<uint64_t>(GetTickCount() - info.dwTime);
}

261
src/base/kernel/Process.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <openssl/ssl.h>
# include <openssl/err.h>
#endif
#ifdef XMRIG_OS_WIN
# ifdef _MSC_VER
# include <direct.h>
@ -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;
# 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;
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::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<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(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);
auto path = locate(location);
if (path.isNull() || fileName == nullptr) {
return path;
}
return uv_exepath(pathBuf, &size) < 0 ? String("") : String(pathBuf, size);
return fmt::format("{}" XMRIG_DIR_SEPARATOR "{}", path, fileName).c_str();
}
xmrig::String xmrig::Process::location(Location location, const char *fileName)
xmrig::String xmrig::Process::locate(Location location)
{
auto path = getPath(location);
if (path.empty() || fileName == nullptr) {
return path.c_str();
char buf[520]{};
size_t size = sizeof(buf);
if (location == ExePathLocation && uv_exepath(buf, &size) >= 0) {
return { buf, size };
}
return fmt::format("{}" XMRIG_DIR_SEPARATOR "{}", path, fileName).c_str();
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<ExitEvent>(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;
}

41
src/base/kernel/Process.h

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

203
src/base/kernel/Versions.cpp

@ -0,0 +1,203 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "base/kernel/Versions.h"
#include "3rdparty/fmt/core.h"
#include "3rdparty/rapidjson/document.h"
#include "version.h"
#include <uv.h>
#ifdef XMRIG_FEATURE_HTTP
# include "3rdparty/llhttp/llhttp.h"
#endif
#ifdef XMRIG_FEATURE_TLS
# include <openssl/opensslv.h>
#endif
#ifdef XMRIG_FEATURE_SODIUM
# include <sodium.h>
#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 <libpq-fe.h>
#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);
}
}

83
src/base/kernel/Versions.h

@ -0,0 +1,83 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_VERSIONS_H
#define XMRIG_VERSIONS_H
#include "base/tools/String.h"
#include <map>
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<String, String> &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<String, String> m_data;
};
} /* namespace xmrig */
#endif /* XMRIG_VERSIONS_H */

49
src/base/kernel/base-version.h

@ -0,0 +1,49 @@
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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

1
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"

5
src/base/net/http/HttpClient.cpp

@ -17,11 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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()) });

10
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

3
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 <openssl/ssl.h>
@ -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
}

101
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 <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2012-2013 The Cryptonote developers
* Copyright (c) 2014-2021 The Monero Project
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 {
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)
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<const uint8_t*>(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<signature*>(sig_bytes);
signature &sig = *reinterpret_cast<signature*>(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<const signature*>(sig_bytes);
const signature &sig = *reinterpret_cast<const signature *>(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 */

28
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 <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2012-2013 The Cryptonote developers
* Copyright (c) 2014-2021 The Monero Project
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

39
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 <http://www.gnu.org/licenses/>.
*
/* XMRig
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*
* 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 <cstdint>
@ -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

19
src/core/Miner.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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) {

4
src/core/Miner.h

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

13
src/crypto/ghostrider/ghostrider.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "ghostrider.h"
#include "sph_blake.h"
#include "sph_bmw.h"
@ -48,7 +47,7 @@
#include <uv.h>
#ifdef XMRIG_FEATURE_HWLOC
#include "base/kernel/Platform.h"
#include "base/kernel/OS.h"
#include "backend/cpu/platform/HwlocCpuInfo.h"
#include <hwloc.h>
#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;

6
src/crypto/ghostrider/ghostrider.h

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
#endif // XMRIG_GR_HASH_H

8
src/crypto/rx/RxDataset.cpp

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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));

4
src/crypto/rx/RxDataset.h

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

8
src/crypto/rx/RxNUMAStorage.cpp

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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<uint64_t>(hwloc_bitmap_first(node->cpuset)));
OS::setThreadAffinity(static_cast<uint64_t>(hwloc_bitmap_first(node->cpuset)));
return true;
}

4
src/crypto/rx/RxNUMAStorage.h

@ -1,7 +1,7 @@
/* XMRig
* Copyright (c) 2018-2019 tevador <tevador@gmail.com>
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

9
src/hw/msr/Msr_win.cpp

@ -1,6 +1,6 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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 <string>
@ -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;
}

4
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);

35
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 <http://www.gnu.org/licenses/>.
*
* 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 */

Loading…
Cancel
Save