From b368ffacdb37b3c1df78b5426fe4be9f0aac223c Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 14 Feb 2019 18:14:38 +0700 Subject: [PATCH 01/22] Added class Json. --- CMakeLists.txt | 5 ++ src/base/io/Json.cpp | 38 +++++++++ src/base/io/Json.h | 48 +++++++++++ src/base/io/Json_unix.cpp | 62 +++++++++++++++ src/base/io/Json_win.cpp | 124 +++++++++++++++++++++++++++++ src/common/config/CommonConfig.cpp | 30 ++----- src/common/config/CommonConfig.h | 17 ++-- src/common/config/ConfigLoader.cpp | 30 +++---- src/common/config/ConfigLoader.h | 1 + src/common/interfaces/IConfig.h | 6 +- 10 files changed, 309 insertions(+), 52 deletions(-) create mode 100644 src/base/io/Json.cpp create mode 100644 src/base/io/Json.h create mode 100644 src/base/io/Json_unix.cpp create mode 100644 src/base/io/Json_win.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c39776b1..41e809a40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ include (cmake/cpu.cmake) set(HEADERS src/api/NetworkState.h src/App.h + src/base/io/Json.h src/base/tools/String.h src/common/config/CommonConfig.h src/common/config/ConfigLoader.h @@ -98,6 +99,7 @@ endif() set(SOURCES src/api/NetworkState.cpp src/App.cpp + src/base/io/Json.cpp src/base/tools/String.cpp src/common/config/CommonConfig.cpp src/common/config/ConfigLoader.cpp @@ -143,6 +145,7 @@ if (WIN32) set(SOURCES_OS res/app.rc src/App_win.cpp + src/base/io/Json_win.cpp src/common/Platform_win.cpp src/Mem_win.cpp ) @@ -152,12 +155,14 @@ if (WIN32) elseif (APPLE) set(SOURCES_OS src/App_unix.cpp + src/base/io/Json_unix.cpp src/common/Platform_mac.cpp src/Mem_unix.cpp ) else() set(SOURCES_OS src/App_unix.cpp + src/base/io/Json_unix.cpp src/common/Platform_unix.cpp src/Mem_unix.cpp ) diff --git a/src/base/io/Json.cpp b/src/base/io/Json.cpp new file mode 100644 index 000000000..13a0d7e3d --- /dev/null +++ b/src/base/io/Json.cpp @@ -0,0 +1,38 @@ +/* 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 , + * + * 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/io/Json.h" +#include "rapidjson/document.h" + + +bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool defaultValue) +{ + auto i = obj.FindMember(key); + if (i != obj.MemberEnd() && i->value.IsBool()) { + return i->value.GetBool(); + } + + return defaultValue; +} diff --git a/src/base/io/Json.h b/src/base/io/Json.h new file mode 100644 index 000000000..54f927583 --- /dev/null +++ b/src/base/io/Json.h @@ -0,0 +1,48 @@ +/* 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 , + * + * 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_JSON_H +#define XMRIG_JSON_H + + +#include "rapidjson/fwd.h" + + +namespace xmrig { + + +class Json +{ +public: + static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false); + + static bool get(const char *fileName, rapidjson::Document &doc); + static bool save(const char *fileName, const rapidjson::Document &doc); +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_JSON_H */ diff --git a/src/base/io/Json_unix.cpp b/src/base/io/Json_unix.cpp new file mode 100644 index 000000000..da3902d8d --- /dev/null +++ b/src/base/io/Json_unix.cpp @@ -0,0 +1,62 @@ +/* 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 , + * + * 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/io/Json.h" +#include "rapidjson/document.h" +#include "rapidjson/istreamwrapper.h" +#include "rapidjson/ostreamwrapper.h" +#include "rapidjson/prettywriter.h" + + +bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc) +{ + std::ifstream ifs(fileName, std::ios_base::in | std::ios_base::binary); + if (!ifs.is_open()) { + return false; + } + + rapidjson::IStreamWrapper isw(ifs); + doc.ParseStream(isw); + + return !doc.HasParseError() && doc.IsObject(); +} + + +bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc) +{ + std::ofstream ofs(fileName, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); + if (!ofs.is_open()) { + return false; + } + + rapidjson::OStreamWrapper osw(ofs); + rapidjson::PrettyWriter writer(osw); + doc.Accept(writer); + + return true; +} diff --git a/src/base/io/Json_win.cpp b/src/base/io/Json_win.cpp new file mode 100644 index 000000000..4a1c52664 --- /dev/null +++ b/src/base/io/Json_win.cpp @@ -0,0 +1,124 @@ +/* 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 , + * + * 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 + + +#ifdef __GNUC__ +# include +# include +#endif + + +#include + + +#include "base/io/Json.h" +#include "rapidjson/document.h" +#include "rapidjson/istreamwrapper.h" +#include "rapidjson/ostreamwrapper.h" +#include "rapidjson/prettywriter.h" + + +#if defined(_MSC_VER) || defined (__GNUC__) +static std::wstring toUtf16(const char *str) +{ + const int size = static_cast(strlen(str)); + std::wstring ret; + + int len = MultiByteToWideChar(CP_UTF8, 0, str, size, nullptr, 0); + if (len > 0) { + ret.resize(static_cast(len)); + MultiByteToWideChar(CP_UTF8, 0, str, size, &ret[0], len); + } + + return ret; +} +#endif + + +bool xmrig::Json::get(const char *fileName, rapidjson::Document &doc) +{ + using namespace rapidjson; + constexpr const std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary; + +# if defined(_MSC_VER) + std::ifstream ifs(toUtf16(fileName), mode); + if (!ifs.is_open()) { + return false; + } +# elif defined(__GNUC__) + const int fd = _wopen(toUtf16(fileName).c_str(), _O_RDONLY | _O_BINARY); + if (fd == -1) { + return false; + } + + __gnu_cxx::stdio_filebuf buf(fd, mode); + std::istream ifs(&buf); +# else + std::ifstream ifs(fileName, mode); + if (!ifs.is_open()) { + return false; + } +# endif + + IStreamWrapper isw(ifs); + doc.ParseStream(isw); + + return !doc.HasParseError() && doc.IsObject(); +} + + +bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc) +{ + using namespace rapidjson; + constexpr const std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary | std::ios_base::trunc; + +# if defined(_MSC_VER) + std::ofstream ofs(toUtf16(fileName), mode); + if (!ofs.is_open()) { + return false; + } +# elif defined(__GNUC__) + const int fd = _wopen(toUtf16(fileName).c_str(), _O_WRONLY | _O_BINARY | _O_TRUNC); + if (fd == -1) { + return false; + } + + __gnu_cxx::stdio_filebuf buf(fd, mode); + std::ostream ofs(&buf); +# else + std::ofstream ofs(fileName, mode); + if (!ofs.is_open()) { + return false; + } +# endif + + OStreamWrapper osw(ofs); + PrettyWriter writer(osw); + doc.Accept(writer); + + return true; +} diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index f2a001829..1207db487 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -53,6 +54,7 @@ #endif +#include "base/io/Json.h" #include "common/config/CommonConfig.h" #include "common/log/Log.h" #include "donate.h" @@ -203,31 +205,15 @@ bool xmrig::CommonConfig::save() return false; } - uv_fs_t req; - const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); - if (fd < 0) { - return false; - } - - uv_fs_req_cleanup(&req); - rapidjson::Document doc; getJSON(doc); - FILE *fp = fdopen(fd, "w"); + if (Json::save(m_fileName, doc)) { + LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); + return true; + } - char buf[4096]; - rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); - rapidjson::PrettyWriter writer(os); - doc.Accept(writer); - - fflush(fp); - - uv_fs_close(uv_default_loop(), &req, fd, nullptr); - uv_fs_req_cleanup(&req); - - LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); - return true; + return false; } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index a864033b0..40124b370 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,9 +29,9 @@ #include +#include "base/tools/String.h" #include "common/interfaces/IConfig.h" #include "common/net/Pool.h" -#include "common/utils/c_str.h" #include "common/xmrig.h" @@ -103,12 +104,12 @@ protected: State m_state; std::vector m_activePools; std::vector m_pools; - xmrig::c_str m_apiId; - xmrig::c_str m_apiToken; - xmrig::c_str m_apiWorkerId; - xmrig::c_str m_fileName; - xmrig::c_str m_logFile; - xmrig::c_str m_userAgent; + xmrig::String m_apiId; + xmrig::String m_apiToken; + xmrig::String m_apiWorkerId; + xmrig::String m_fileName; + xmrig::String m_logFile; + xmrig::String m_userAgent; private: bool parseInt(int key, int arg); diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index b3b3ecb0f..6ce918d69 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -37,6 +38,7 @@ #endif +#include "base/io/Json.h" #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" #include "common/interfaces/IConfig.h" @@ -151,7 +153,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator int key; while (1) { - key = getopt_long(argc, argv, short_options, options, NULL); + key = getopt_long(argc, argv, short_options, options, nullptr); if (key < 0) { break; } @@ -207,30 +209,18 @@ void xmrig::ConfigLoader::release() bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc) { - uv_fs_t req; - const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr); - if (fd < 0) { - fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd)); - return false; + if (Json::get(fileName, doc)) { + return true; } - uv_fs_req_cleanup(&req); - - FILE *fp = fdopen(fd, "rb"); - char buf[8192]; - rapidjson::FileReadStream is(fp, buf, sizeof(buf)); - - doc.ParseStream(is); - - uv_fs_close(uv_default_loop(), &req, fd, nullptr); - uv_fs_req_cleanup(&req); - if (doc.HasParseError()) { - printf("%s<%d>: %s\n", fileName, (int) doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError())); - return false; + printf("%s: \"%s\"\n", fileName, doc.GetErrorOffset(), rapidjson::GetParseError_En(doc.GetParseError())); + } + else { + fprintf(stderr, "unable to open \"%s\".\n", fileName); } - return doc.IsObject(); + return false; } diff --git a/src/common/config/ConfigLoader.h b/src/common/config/ConfigLoader.h index b9e045379..b0bd67eb4 100644 --- a/src/common/config/ConfigLoader.h +++ b/src/common/config/ConfigLoader.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 0c8cfc28d..48809fa17 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -4,7 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2018 XMRig + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -125,7 +127,7 @@ public: CudaMaxUsageKey = 1206, }; - virtual ~IConfig() {} + virtual ~IConfig() = default; virtual bool finalize() = 0; virtual bool isWatch() const = 0; From 0450c314494218b7084b48c32491456be3b310c1 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Feb 2019 04:59:20 +0700 Subject: [PATCH 02/22] Rewritten watch feature. --- CMakeLists.txt | 7 +- src/base/io/Watcher.cpp | 94 +++++++++++++++++++ src/base/io/Watcher.h | 67 +++++++++++++ src/base/kernel/interfaces/IConfigListener.h | 47 ++++++++++ .../kernel}/interfaces/IWatcherListener.h | 15 +-- src/base/tools/Handle.cpp | 79 ++++++++++++++++ src/base/tools/Handle.h | 55 +++++++++++ src/common/config/CommonConfig.h | 2 +- src/common/config/ConfigLoader.cpp | 12 +-- src/common/config/ConfigLoader.h | 6 +- src/common/config/ConfigWatcher.cpp | 65 +++---------- src/common/config/ConfigWatcher.h | 40 ++++---- src/common/interfaces/IConfig.h | 5 +- src/common/interfaces/IConfigCreator.h | 12 ++- src/core/Config.cpp | 2 +- src/core/Config.h | 4 +- src/core/ConfigLoader_platform.h | 6 +- src/core/Controller.cpp | 3 +- src/core/Controller.h | 9 +- 19 files changed, 419 insertions(+), 111 deletions(-) create mode 100644 src/base/io/Watcher.cpp create mode 100644 src/base/io/Watcher.h create mode 100644 src/base/kernel/interfaces/IConfigListener.h rename src/{common => base/kernel}/interfaces/IWatcherListener.h (77%) create mode 100644 src/base/tools/Handle.cpp create mode 100644 src/base/tools/Handle.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 41e809a40..3eb8a0fcf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ set(HEADERS src/api/NetworkState.h src/App.h src/base/io/Json.h + src/base/io/Watcher.h + src/base/kernel/interfaces/IConfigListener.h + src/base/kernel/interfaces/IWatcherListener.h + src/base/tools/Handle.h src/base/tools/String.h src/common/config/CommonConfig.h src/common/config/ConfigLoader.h @@ -38,7 +42,6 @@ set(HEADERS src/common/interfaces/ILogBackend.h src/common/interfaces/IStrategy.h src/common/interfaces/IStrategyListener.h - src/common/interfaces/IWatcherListener.h src/common/log/BasicLog.h src/common/log/ConsoleLog.h src/common/log/FileLog.h @@ -100,6 +103,8 @@ set(SOURCES src/api/NetworkState.cpp src/App.cpp src/base/io/Json.cpp + src/base/io/Watcher.cpp + src/base/tools/Handle.cpp src/base/tools/String.cpp src/common/config/CommonConfig.cpp src/common/config/ConfigLoader.cpp diff --git a/src/base/io/Watcher.cpp b/src/base/io/Watcher.cpp new file mode 100644 index 000000000..93b666431 --- /dev/null +++ b/src/base/io/Watcher.cpp @@ -0,0 +1,94 @@ +/* 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 , + * + * 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/interfaces/IWatcherListener.h" +#include "base/io/Watcher.h" +#include "base/tools/Handle.h" + + +xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) : + m_listener(listener), + m_path(path) +{ + m_fsEvent = new uv_fs_event_t; + uv_fs_event_init(uv_default_loop(), m_fsEvent); + + m_timer = new uv_timer_t; + uv_timer_init(uv_default_loop(), m_timer); + + m_fsEvent->data = m_timer->data = this; + + start(); +} + + +xmrig::Watcher::~Watcher() +{ + Handle::close(m_timer); + Handle::close(m_fsEvent); +} + + +void xmrig::Watcher::onTimer(uv_timer_t *handle) +{ + static_cast(handle->data)->reload(); +} + + +void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int, int) +{ + if (!filename) { + return; + } + + static_cast(handle->data)->queueUpdate(); +} + + +void xmrig::Watcher::queueUpdate() +{ + uv_timer_stop(m_timer); + uv_timer_start(m_timer, xmrig::Watcher::onTimer, kDelay, 0); +} + + +void xmrig::Watcher::reload() +{ + m_listener->onFileChanged(m_path); + +# ifndef _WIN32 + uv_fs_event_stop(&m_fsEvent); + start(); +# endif +} + + +void xmrig::Watcher::start() +{ + uv_fs_event_start(m_fsEvent, xmrig::Watcher::onFsEvent, m_path, 0); +} diff --git a/src/base/io/Watcher.h b/src/base/io/Watcher.h new file mode 100644 index 000000000..4fec4c687 --- /dev/null +++ b/src/base/io/Watcher.h @@ -0,0 +1,67 @@ +/* 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 , + * + * 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_WATCHER_H +#define XMRIG_WATCHER_H + + +#include "base/tools/String.h" + + +typedef struct uv_fs_event_s uv_fs_event_t; +typedef struct uv_timer_s uv_timer_t; + + +namespace xmrig { + + +class IWatcherListener; + + +class Watcher +{ +public: + Watcher(const String &path, IWatcherListener *listener); + ~Watcher(); + +private: + constexpr static int kDelay = 500; + + static void onFsEvent(uv_fs_event_t *handle, const char *filename, int events, int status); + static void onTimer(uv_timer_t *handle); + + void queueUpdate(); + void reload(); + void start(); + + IWatcherListener *m_listener; + String m_path; + uv_fs_event_t *m_fsEvent; + uv_timer_t *m_timer; +}; + + +} /* namespace xmrig */ + +#endif /* XMRIG_WATCHER_H */ diff --git a/src/base/kernel/interfaces/IConfigListener.h b/src/base/kernel/interfaces/IConfigListener.h new file mode 100644 index 000000000..a6fa835f2 --- /dev/null +++ b/src/base/kernel/interfaces/IConfigListener.h @@ -0,0 +1,47 @@ +/* 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 , + * + * 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_ICONFIGLISTENER_H +#define XMRIG_ICONFIGLISTENER_H + + +namespace xmrig { + + +class IConfig; + + +class IConfigListener +{ +public: + virtual ~IConfigListener() = default; + + virtual void onNewConfig(IConfig *config) = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_ICONFIGLISTENER_H diff --git a/src/common/interfaces/IWatcherListener.h b/src/base/kernel/interfaces/IWatcherListener.h similarity index 77% rename from src/common/interfaces/IWatcherListener.h rename to src/base/kernel/interfaces/IWatcherListener.h index bfafb9a01..a62b4b533 100644 --- a/src/common/interfaces/IWatcherListener.h +++ b/src/base/kernel/interfaces/IWatcherListener.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,26 +22,26 @@ * along with this program. If not, see . */ -#ifndef __IWATCHERLISTENER_H__ -#define __IWATCHERLISTENER_H__ +#ifndef XMRIG_IWATCHERLISTENER_H +#define XMRIG_IWATCHERLISTENER_H namespace xmrig { -class IConfig; +class String; class IWatcherListener { public: - virtual ~IWatcherListener() {} + virtual ~IWatcherListener() = default; - virtual void onNewConfig(IConfig *config) = 0; + virtual void onFileChanged(const String &fileName) = 0; }; } /* namespace xmrig */ -#endif // __IWATCHERLISTENER_H__ +#endif // XMRIG_IWATCHERLISTENER_H diff --git a/src/base/tools/Handle.cpp b/src/base/tools/Handle.cpp new file mode 100644 index 000000000..d486ab39f --- /dev/null +++ b/src/base/tools/Handle.cpp @@ -0,0 +1,79 @@ +/* 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 , + * + * 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/tools/Handle.h" + + +void xmrig::Handle::close(uv_fs_event_t *handle) +{ + if (handle) { + uv_fs_event_stop(handle); + close(reinterpret_cast(handle)); + } +} + + +void xmrig::Handle::close(uv_getaddrinfo_t *handle) +{ + if (handle) { + uv_cancel(reinterpret_cast(handle)); + close(reinterpret_cast(handle)); + } +} + + +void xmrig::Handle::close(uv_handle_t *handle) +{ + uv_close(handle, [](uv_handle_t *handle) { delete handle; }); +} + + +void xmrig::Handle::close(uv_signal_t *handle) +{ + if (handle) { + uv_signal_stop(handle); + close(reinterpret_cast(handle)); + } +} + + +void xmrig::Handle::close(uv_tcp_t *handle) +{ + if (handle) { + close(reinterpret_cast(handle)); + } +} + + +void xmrig::Handle::close(uv_timer_s *handle) +{ + if (handle) { + uv_timer_stop(handle); + close(reinterpret_cast(handle)); + } +} diff --git a/src/base/tools/Handle.h b/src/base/tools/Handle.h new file mode 100644 index 000000000..547c92026 --- /dev/null +++ b/src/base/tools/Handle.h @@ -0,0 +1,55 @@ +/* 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 , + * + * 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_HANDLE_H +#define XMRIG_HANDLE_H + + +typedef struct uv_fs_event_s uv_fs_event_t; +typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; +typedef struct uv_handle_s uv_handle_t; +typedef struct uv_signal_s uv_signal_t; +typedef struct uv_tcp_s uv_tcp_t; +typedef struct uv_timer_s uv_timer_t; + + +namespace xmrig { + + +class Handle +{ +public: + static void close(uv_fs_event_t *handle); + static void close(uv_getaddrinfo_t *handle); + static void close(uv_handle_t *handle); + static void close(uv_signal_t *handle); + static void close(uv_tcp_t *handle); + static void close(uv_timer_t *handle); +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_HANDLE_H */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 40124b370..619f4b03a 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -65,7 +65,7 @@ public: inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const Algorithm &algorithm() const override { return m_algorithm; } - inline const char *fileName() const override { return m_fileName.data(); } + inline const String &fileName() const override { return m_fileName; } bool save() override; diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 6ce918d69..c60953a12 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -39,23 +39,22 @@ #include "base/io/Json.h" +#include "base/kernel/interfaces/IConfigListener.h" #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" #include "common/interfaces/IConfig.h" -#include "common/interfaces/IWatcherListener.h" #include "common/net/Pool.h" #include "common/Platform.h" #include "core/ConfigCreator.h" #include "core/ConfigLoader_platform.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" -#include "rapidjson/filereadstream.h" bool xmrig::ConfigLoader::m_done = false; xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr; xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr; -xmrig::IWatcherListener *xmrig::ConfigLoader::m_listener = nullptr; +xmrig::IConfigListener *xmrig::ConfigLoader::m_listener = nullptr; #ifndef ARRAY_SIZE @@ -78,8 +77,9 @@ bool xmrig::ConfigLoader::loadFromFile(xmrig::IConfig *config, const char *fileN bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const char *json) { - rapidjson::Document doc; - doc.Parse(json); + using namespace rapidjson; + Document doc; + doc.Parse(json); if (doc.HasParseError() || !doc.IsObject()) { return false; @@ -144,7 +144,7 @@ bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json) } -xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener) +xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator *creator, IConfigListener *listener) { m_creator = creator; m_listener = listener; diff --git a/src/common/config/ConfigLoader.h b/src/common/config/ConfigLoader.h index b0bd67eb4..13ac357bf 100644 --- a/src/common/config/ConfigLoader.h +++ b/src/common/config/ConfigLoader.h @@ -40,7 +40,7 @@ namespace xmrig { class ConfigWatcher; class IConfigCreator; -class IWatcherListener; +class IConfigListener; class IConfig; @@ -51,7 +51,7 @@ public: static bool loadFromJSON(IConfig *config, const char *json); static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc); static bool reload(IConfig *oldConfig, const char *json); - static IConfig *load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener); + static IConfig *load(int argc, char **argv, IConfigCreator *creator, IConfigListener *listener); static void release(); static inline bool isDone() { return m_done; } @@ -66,7 +66,7 @@ private: static bool m_done; static ConfigWatcher *m_watcher; static IConfigCreator *m_creator; - static IWatcherListener *m_listener; + static IConfigListener *m_listener; }; diff --git a/src/common/config/ConfigWatcher.cpp b/src/common/config/ConfigWatcher.cpp index 14107b62c..1e35bc9b7 100644 --- a/src/common/config/ConfigWatcher.cpp +++ b/src/common/config/ConfigWatcher.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,66 +23,35 @@ */ -#include - - +#include "base/io/Watcher.h" +#include "base/kernel/interfaces/IConfigListener.h" #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" -#include "common/interfaces/IWatcherListener.h" #include "common/log/Log.h" #include "core/ConfigCreator.h" -xmrig::ConfigWatcher::ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener) : +xmrig::ConfigWatcher::ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener) : m_creator(creator), - m_listener(listener), - m_path(path) + m_listener(listener) { - uv_fs_event_init(uv_default_loop(), &m_fsEvent); - uv_timer_init(uv_default_loop(), &m_timer); - - m_fsEvent.data = m_timer.data = this; - - start(); + m_watcher = new Watcher(path, this); } xmrig::ConfigWatcher::~ConfigWatcher() { - uv_timer_stop(&m_timer); - uv_fs_event_stop(&m_fsEvent); + delete m_watcher; } -void xmrig::ConfigWatcher::onTimer(uv_timer_t* handle) + +void xmrig::ConfigWatcher::onFileChanged(const String &fileName) { - static_cast(handle->data)->reload(); -} - - -void xmrig::ConfigWatcher::onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status) -{ - if (!filename) { - return; - } - - static_cast(handle->data)->queueUpdate(); -} - - -void xmrig::ConfigWatcher::queueUpdate() -{ - uv_timer_stop(&m_timer); - uv_timer_start(&m_timer, xmrig::ConfigWatcher::onTimer, kDelay, 0); -} - - -void xmrig::ConfigWatcher::reload() -{ - LOG_WARN("\"%s\" was changed, reloading configuration", m_path.data()); + LOG_WARN("\"%s\" was changed, reloading configuration", fileName.data()); IConfig *config = m_creator->create(); - ConfigLoader::loadFromFile(config, m_path.data()); + ConfigLoader::loadFromFile(config, fileName); if (!config->finalize()) { LOG_ERR("reloading failed"); @@ -91,15 +61,4 @@ void xmrig::ConfigWatcher::reload() } m_listener->onNewConfig(config); - -# ifndef _WIN32 - uv_fs_event_stop(&m_fsEvent); - start(); -# endif -} - - -void xmrig::ConfigWatcher::start() -{ - uv_fs_event_start(&m_fsEvent, xmrig::ConfigWatcher::onFsEvent, m_path.data(), 0); } diff --git a/src/common/config/ConfigWatcher.h b/src/common/config/ConfigWatcher.h index 7f38b45a8..c2c3ee29b 100644 --- a/src/common/config/ConfigWatcher.h +++ b/src/common/config/ConfigWatcher.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,15 +22,12 @@ * along with this program. If not, see . */ -#ifndef __CONFIGWATCHER_H__ -#define __CONFIGWATCHER_H__ +#ifndef XMRIG_CONFIGWATCHER_H +#define XMRIG_CONFIGWATCHER_H -#include -#include - - -#include "common/utils/c_str.h" +#include "base/kernel/interfaces/IWatcherListener.h" +#include "base/tools/String.h" #include "rapidjson/fwd.h" @@ -40,29 +38,23 @@ namespace xmrig { class IConfigCreator; -class IWatcherListener; +class IConfigListener; +class Watcher; -class ConfigWatcher +class ConfigWatcher : public IWatcherListener { public: - ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener); - ~ConfigWatcher(); + ConfigWatcher(const String &path, IConfigCreator *creator, IConfigListener *listener); + ~ConfigWatcher() override; + +protected: + void onFileChanged(const String &fileName) override; private: - constexpr static int kDelay = 500; - - static void onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status); - static void onTimer(uv_timer_t* handle); - void queueUpdate(); - void reload(); - void start(); - IConfigCreator *m_creator; - IWatcherListener *m_listener; - uv_fs_event_t m_fsEvent; - uv_timer_t m_timer; - xmrig::c_str m_path; + IConfigListener *m_listener; + Watcher *m_watcher; }; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index 48809fa17..d5f67c492 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -33,6 +33,9 @@ namespace xmrig { +class String; + + class IConfig { public: @@ -136,7 +139,7 @@ public: virtual bool parseUint64(int key, uint64_t arg) = 0; virtual bool save() = 0; virtual const Algorithm &algorithm() const = 0; - virtual const char *fileName() const = 0; + virtual const String &fileName() const = 0; virtual void getJSON(rapidjson::Document &doc) const = 0; virtual void parseJSON(const rapidjson::Document &doc) = 0; virtual void setFileName(const char *fileName) = 0; diff --git a/src/common/interfaces/IConfigCreator.h b/src/common/interfaces/IConfigCreator.h index 597a6b742..c2e0e62ea 100644 --- a/src/common/interfaces/IConfigCreator.h +++ b/src/common/interfaces/IConfigCreator.h @@ -4,7 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2018 XMRig + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __ICONFIGCREATOR_H__ -#define __ICONFIGCREATOR_H__ +#ifndef XMRIG_ICONFIGCREATOR_H +#define XMRIG_ICONFIGCREATOR_H namespace xmrig { @@ -33,7 +35,7 @@ class IConfig; class IConfigCreator { public: - virtual ~IConfigCreator() {} + virtual ~IConfigCreator() = default; virtual IConfig *create() const = 0; }; @@ -42,4 +44,4 @@ public: } /* namespace xmrig */ -#endif // __ICONFIGCREATOR_H__ +#endif // XMRIG_ICONFIGCREATOR_H diff --git a/src/core/Config.cpp b/src/core/Config.cpp index e91a9f2b4..1decb9410 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -139,7 +139,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const } -xmrig::Config *xmrig::Config::load(int argc, char **argv, IWatcherListener *listener) +xmrig::Config *xmrig::Config::load(int argc, char **argv, IConfigListener *listener) { return static_cast(ConfigLoader::load(argc, argv, new ConfigCreator(), listener)); } diff --git a/src/core/Config.h b/src/core/Config.h index eb33ee145..5b40a47e4 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -44,7 +44,7 @@ namespace xmrig { class ConfigLoader; class IThread; -class IWatcherListener; +class IConfigListener; /** @@ -85,7 +85,7 @@ public: inline int64_t affinity() const { return m_threads.mask; } inline ThreadsMode threadsMode() const { return m_threads.mode; } - static Config *load(int argc, char **argv, IWatcherListener *listener); + static Config *load(int argc, char **argv, IConfigListener *listener); protected: bool finalize() override; diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 807d80e25..ceaf7a3fd 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , - * + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -122,6 +122,7 @@ static struct option const options[] = { { "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey }, { "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey }, { "no-color", 0, nullptr, xmrig::IConfig::ColorKey }, + { "no-watch", 0, nullptr, xmrig::IConfig::WatchKey }, { "no-huge-pages", 0, nullptr, xmrig::IConfig::HugePagesKey }, { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, { "pass", 1, nullptr, xmrig::IConfig::PasswordKey }, @@ -163,6 +164,7 @@ static struct option const config_options[] = { { "syslog", 0, nullptr, xmrig::IConfig::SyslogKey }, { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, + { "watch", 0, nullptr, xmrig::IConfig::WatchKey }, { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, { "autosave", 0, nullptr, xmrig::IConfig::AutoSaveKey }, diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 7a9b8284a..b9c64ca1c 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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/core/Controller.h b/src/core/Controller.h index abb11ecfb..199343734 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -25,7 +26,7 @@ #define XMRIG_CONTROLLER_H -#include "common/interfaces/IWatcherListener.h" +#include "base/kernel/interfaces/IConfigListener.h" class Network; @@ -40,11 +41,11 @@ class ControllerPrivate; class IControllerListener; -class Controller : public IWatcherListener +class Controller : public IConfigListener { public: Controller(); - ~Controller(); + ~Controller() override; bool isDone() const; bool isReady() const; From f4d2dec628edae884ae7c5ac5ace99b8dbbb7949 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Feb 2019 05:42:46 +0700 Subject: [PATCH 03/22] Added classes Process and Arguments. --- CMakeLists.txt | 4 ++ src/App.cpp | 24 +++---- src/App.h | 24 ++++--- src/App_unix.cpp | 5 +- src/App_win.cpp | 5 +- src/base/kernel/Process.cpp | 101 +++++++++++++++++++++++++++++ src/base/kernel/Process.h | 64 ++++++++++++++++++ src/base/tools/Arguments.cpp | 76 ++++++++++++++++++++++ src/base/tools/Arguments.h | 61 +++++++++++++++++ src/common/Platform.cpp | 35 +--------- src/common/Platform.h | 8 +-- src/common/config/ConfigLoader.cpp | 7 +- src/common/config/ConfigLoader.h | 3 +- src/core/Config.cpp | 4 +- src/core/Config.h | 7 +- src/core/Controller.cpp | 12 ++-- src/core/Controller.h | 5 +- src/xmrig.cpp | 10 ++- 18 files changed, 373 insertions(+), 82 deletions(-) create mode 100644 src/base/kernel/Process.cpp create mode 100644 src/base/kernel/Process.h create mode 100644 src/base/tools/Arguments.cpp create mode 100644 src/base/tools/Arguments.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eb8a0fcf..238a9b7f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ set(HEADERS src/base/io/Watcher.h src/base/kernel/interfaces/IConfigListener.h src/base/kernel/interfaces/IWatcherListener.h + src/base/kernel/Process.h + src/base/tools/Arguments.h src/base/tools/Handle.h src/base/tools/String.h src/common/config/CommonConfig.h @@ -104,6 +106,8 @@ set(SOURCES src/App.cpp src/base/io/Json.cpp src/base/io/Watcher.cpp + src/base/kernel/Process.cpp + src/base/tools/Arguments.cpp src/base/tools/Handle.cpp src/base/tools/String.cpp src/common/config/CommonConfig.cpp diff --git a/src/App.cpp b/src/App.cpp index e3c4c222d..d6ed7190e 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -5,7 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018 Lee Clagett + * Copyright 2018 SChernykh + * Copyright 2016-2019 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 @@ -47,18 +49,18 @@ #endif -App *App::m_self = nullptr; +xmrig::App *xmrig::App::m_self = nullptr; -App::App(int argc, char **argv) : +xmrig::App::App(Process *process) : m_console(nullptr), m_httpd(nullptr) { m_self = this; - m_controller = new xmrig::Controller(); - if (m_controller->init(argc, argv) != 0) { + m_controller = new xmrig::Controller(process); + if (m_controller->init() != 0) { return; } @@ -72,7 +74,7 @@ App::App(int argc, char **argv) : } -App::~App() +xmrig::App::~App() { uv_tty_reset_mode(); @@ -85,7 +87,7 @@ App::~App() } -int App::exec() +int xmrig::App::exec() { if (m_controller->isDone()) { return 0; @@ -139,7 +141,7 @@ int App::exec() } -void App::onConsoleCommand(char command) +void xmrig::App::onConsoleCommand(char command) { switch (command) { case 'h': @@ -174,7 +176,7 @@ void App::onConsoleCommand(char command) } -void App::close() +void xmrig::App::close() { m_controller->network()->stop(); Workers::stop(); @@ -183,12 +185,12 @@ void App::close() } -void App::release() +void xmrig::App::release() { } -void App::onSignal(uv_signal_t *handle, int signum) +void xmrig::App::onSignal(uv_signal_t *handle, int signum) { switch (signum) { diff --git a/src/App.h b/src/App.h index 964400e6b..b93fc4a1d 100644 --- a/src/App.h +++ b/src/App.h @@ -5,7 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +23,8 @@ * along with this program. If not, see . */ -#ifndef __APP_H__ -#define __APP_H__ +#ifndef XMRIG_APP_H +#define XMRIG_APP_H #include @@ -34,19 +36,20 @@ class Console; class Httpd; class Network; -class Options; namespace xmrig { - class Controller; -} + + +class Controller; +class Process; class App : public IConsoleListener { public: - App(int argc, char **argv); - ~App(); + App(Process *process); + ~App() override; int exec(); @@ -71,4 +74,7 @@ private: }; -#endif /* __APP_H__ */ +} /* namespace xmrig */ + + +#endif /* XMRIG_APP_H */ diff --git a/src/App_unix.cpp b/src/App_unix.cpp index 45f73d2dc..2b598c229 100644 --- a/src/App_unix.cpp +++ b/src/App_unix.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 +35,7 @@ #include "core/Controller.h" -void App::background() +void xmrig::App::background() { signal(SIGPIPE, SIG_IGN); diff --git a/src/App_win.cpp b/src/App_win.cpp index 9b923870e..57f57a6df 100644 --- a/src/App_win.cpp +++ b/src/App_win.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +32,7 @@ #include "core/Config.h" -void App::background() +void xmrig::App::background() { if (!m_controller->config()->isBackground()) { return; diff --git a/src/base/kernel/Process.cpp b/src/base/kernel/Process.cpp new file mode 100644 index 000000000..0bc40e2da --- /dev/null +++ b/src/base/kernel/Process.cpp @@ -0,0 +1,101 @@ +/* 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 , + * + * 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 + + +#include "base/kernel/Process.h" + + +static size_t location(xmrig::Process::Location location, char *buf, size_t max) +{ + using namespace xmrig; + + size_t size = max; + if (location == Process::ExeLocation) { + return uv_exepath(buf, &size) < 0 ? 0 : size; + } + + if (location == Process::CwdLocation) { + return uv_cwd(buf, &size) < 0 ? 0 : size; + } + + return 0; +} + + +xmrig::Process::Process(int argc, char **argv) : + m_arguments(argc, argv) +{ + srand(static_cast(static_cast(time(nullptr)) ^ reinterpret_cast(this))); +} + + +xmrig::Process::~Process() +{ +} + + +xmrig::String xmrig::Process::location(Location location, const char *fileName) const +{ + constexpr const size_t max = 520; + + char *buf = new char[max](); + size_t size = ::location(location, buf, max); + + if (size == 0) { + delete [] buf; + + return String(); + } + + if (fileName == nullptr) { + return buf; + } + + if (location == ExeLocation) { + char *p = strrchr(buf, kDirSeparator); + + if (p == nullptr) { + delete [] buf; + + return String(); + } + + size = static_cast(p - buf); + } + + if ((size + strlen(fileName) + 2) >= max) { + delete [] buf; + + return String(); + } + + buf[size] = kDirSeparator; + strcpy(buf + size + 1, fileName); + + return buf; +} diff --git a/src/base/kernel/Process.h b/src/base/kernel/Process.h new file mode 100644 index 000000000..9b29eb57f --- /dev/null +++ b/src/base/kernel/Process.h @@ -0,0 +1,64 @@ +/* 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 , + * + * 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_PROCESS_H +#define XMRIG_PROCESS_H + + +#include "base/tools/Arguments.h" + + +namespace xmrig { + + +class Process +{ +public: + enum Location { + ExeLocation, + CwdLocation + }; + +# ifdef WIN32 + constexpr const static char kDirSeparator = '\\'; +# else + constexpr const static char kDirSeparator = '/'; +# endif + + Process(int argc, char **argv); + ~Process(); + + String location(Location location, const char *fileName = nullptr) const; + + inline const Arguments &arguments() const { return m_arguments; } + +private: + Arguments m_arguments; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_PROCESS_H */ diff --git a/src/base/tools/Arguments.cpp b/src/base/tools/Arguments.cpp new file mode 100644 index 000000000..3713dd116 --- /dev/null +++ b/src/base/tools/Arguments.cpp @@ -0,0 +1,76 @@ +/* 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 , + * + * 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 + + +#include "base/tools/Arguments.h" + + +xmrig::Arguments::Arguments(int argc, char **argv) : + m_argv(argv), + m_argc(argc) +{ + uv_setup_args(argc, argv); + + for (size_t i = 0; i < static_cast(argc); ++i) { + add(argv[i]); + } +} + + +bool xmrig::Arguments::hasArg(const char *name) const +{ + if (m_argc == 1) { + return false; + } + + return std::find(m_data.begin() + 1, m_data.end(), name) != m_data.end(); +} + + +void xmrig::Arguments::add(const char *arg) +{ + if (arg == nullptr) { + return; + } + + const size_t size = strlen(arg); + if (size > 4 && arg[0] == '-' && arg[1] == '-') { + const char *p = strstr(arg, "="); + + if (p) { + const size_t keySize = static_cast(p - arg); + + m_data.push_back(String(arg, keySize)); + m_data.push_back(arg + keySize + 1); + + return; + } + } + + m_data.push_back(arg); +} diff --git a/src/base/tools/Arguments.h b/src/base/tools/Arguments.h new file mode 100644 index 000000000..e47e39e38 --- /dev/null +++ b/src/base/tools/Arguments.h @@ -0,0 +1,61 @@ +/* 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 , + * + * 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_ARGUMENTS_H +#define XMRIG_ARGUMENTS_H + + +#include + + +#include "base/tools/String.h" + + +namespace xmrig { + + +class Arguments +{ +public: + Arguments(int argc, char **argv); + + bool hasArg(const char *name) const; + + inline char **argv() const { return m_argv; } + inline const std::vector &data() const { return m_data; } + inline int argc() const { return m_argc; } + +private: + void add(const char *arg); + + char **m_argv; + int m_argc; + std::vector m_data; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_ARGUMENTS_H */ diff --git a/src/common/Platform.cpp b/src/common/Platform.cpp index 17fcc38e6..6bd0ac80d 100644 --- a/src/common/Platform.cpp +++ b/src/common/Platform.cpp @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -36,40 +36,9 @@ #include "Platform.h" -char Platform::m_defaultConfigName[520] = { 0 }; xmrig::String Platform::m_userAgent; -const char *Platform::defaultConfigName() -{ - size_t size = 520; - - if (*m_defaultConfigName) { - return m_defaultConfigName; - } - - if (uv_exepath(m_defaultConfigName, &size) < 0) { - return nullptr; - } - - if (size < 500) { -# ifdef WIN32 - char *p = strrchr(m_defaultConfigName, '\\'); -# else - char *p = strrchr(m_defaultConfigName, '/'); -# endif - - if (p) { - strcpy(p + 1, "config.json"); - return m_defaultConfigName; - } - } - - *m_defaultConfigName = '\0'; - return nullptr; -} - - void Platform::init(const char *userAgent) { # ifndef XMRIG_NO_TLS diff --git a/src/common/Platform.h b/src/common/Platform.h index fc10e83b3..85f08a2eb 100644 --- a/src/common/Platform.h +++ b/src/common/Platform.h @@ -5,8 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -36,19 +36,17 @@ class Platform { public: static bool setThreadAffinity(uint64_t cpu_id); - static const char *defaultConfigName(); static uint32_t setTimerResolution(uint32_t resolution); static void init(const char *userAgent); static void restoreTimerResolution(); static void setProcessPriority(int priority); static void setThreadPriority(int priority); - static inline const char *userAgent() { return m_userAgent.data(); } + static inline const char *userAgent() { return m_userAgent; } private: static char *createUserAgent(); - static char m_defaultConfigName[520]; static xmrig::String m_userAgent; }; diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index c60953a12..42c93f5c3 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -40,6 +40,7 @@ #include "base/io/Json.h" #include "base/kernel/interfaces/IConfigListener.h" +#include "base/kernel/Process.h" #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" #include "common/interfaces/IConfig.h" @@ -144,13 +145,15 @@ bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json) } -xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator *creator, IConfigListener *listener) +xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *creator, IConfigListener *listener) { m_creator = creator; m_listener = listener; xmrig::IConfig *config = m_creator->create(); int key; + int argc = process->arguments().argc(); + char **argv = process->arguments().argv(); while (1) { key = getopt_long(argc, argv, short_options, options, nullptr); @@ -174,7 +177,7 @@ xmrig::IConfig *xmrig::ConfigLoader::load(int argc, char **argv, IConfigCreator delete config; config = m_creator->create(); - loadFromFile(config, Platform::defaultConfigName()); + loadFromFile(config, process->location(Process::ExeLocation, "config.json")); } if (!config->finalize()) { diff --git a/src/common/config/ConfigLoader.h b/src/common/config/ConfigLoader.h index 13ac357bf..0a85ab944 100644 --- a/src/common/config/ConfigLoader.h +++ b/src/common/config/ConfigLoader.h @@ -42,6 +42,7 @@ class ConfigWatcher; class IConfigCreator; class IConfigListener; class IConfig; +class Process; class ConfigLoader @@ -51,7 +52,7 @@ public: static bool loadFromJSON(IConfig *config, const char *json); static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc); static bool reload(IConfig *oldConfig, const char *json); - static IConfig *load(int argc, char **argv, IConfigCreator *creator, IConfigListener *listener); + static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener); static void release(); static inline bool isDone() { return m_done; } diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 1decb9410..f54f092b7 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -139,9 +139,9 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const } -xmrig::Config *xmrig::Config::load(int argc, char **argv, IConfigListener *listener) +xmrig::Config *xmrig::Config::load(Process *process, IConfigListener *listener) { - return static_cast(ConfigLoader::load(argc, argv, new ConfigCreator(), listener)); + return static_cast(ConfigLoader::load(process, new ConfigCreator(), listener)); } diff --git a/src/core/Config.h b/src/core/Config.h index 5b40a47e4..d2e8c166e 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -35,16 +35,13 @@ #include "workers/CpuThread.h" -class Addr; -class Url; - - namespace xmrig { class ConfigLoader; class IThread; class IConfigListener; +class Process; /** @@ -85,7 +82,7 @@ public: inline int64_t affinity() const { return m_threads.mask; } inline ThreadsMode threadsMode() const { return m_threads.mode; } - static Config *load(int argc, char **argv, IConfigListener *listener); + static Config *load(Process *process, IConfigListener *listener); protected: bool finalize() override; diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index b9c64ca1c..1113c6d5d 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -46,8 +46,9 @@ class xmrig::ControllerPrivate { public: - inline ControllerPrivate() : + inline ControllerPrivate(Process *process) : network(nullptr), + process(process), config(nullptr) {} @@ -60,13 +61,14 @@ public: Network *network; + Process *process; std::vector listeners; xmrig::Config *config; }; -xmrig::Controller::Controller() - : d_ptr(new ControllerPrivate()) +xmrig::Controller::Controller(Process *process) + : d_ptr(new ControllerPrivate(process)) { } @@ -99,11 +101,11 @@ xmrig::Config *xmrig::Controller::config() const } -int xmrig::Controller::init(int argc, char **argv) +int xmrig::Controller::init() { Cpu::init(); - d_ptr->config = xmrig::Config::load(argc, argv, this); + d_ptr->config = xmrig::Config::load(d_ptr->process, this); if (!d_ptr->config) { return 1; } diff --git a/src/core/Controller.h b/src/core/Controller.h index 199343734..7bb34db2f 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -39,18 +39,19 @@ namespace xmrig { class Config; class ControllerPrivate; class IControllerListener; +class Process; class Controller : public IConfigListener { public: - Controller(); + Controller(Process *process); ~Controller() override; bool isDone() const; bool isReady() const; Config *config() const; - int init(int argc, char **argv); + int init(); Network *network() const; void addListener(IControllerListener *listener); diff --git a/src/xmrig.cpp b/src/xmrig.cpp index 48362adaa..eec5f5faf 100644 --- a/src/xmrig.cpp +++ b/src/xmrig.cpp @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,10 +23,13 @@ */ #include "App.h" +#include "base/kernel/Process.h" int main(int argc, char **argv) { - App app(argc, argv); + xmrig::Process process(argc, argv); + + xmrig::App app(&process); return app.exec(); } From 14e7c825122c9b87507f541ffbe7681efda74d79 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Feb 2019 07:06:48 +0700 Subject: [PATCH 04/22] Prevent config reload after initial save. --- src/common/config/CommonConfig.cpp | 6 ------ src/common/config/ConfigLoader.cpp | 18 ++++++++++++++---- src/common/config/ConfigLoader.h | 1 + src/core/Controller.cpp | 14 ++++++++++++++ src/core/Controller.h | 1 + src/workers/Workers.cpp | 4 +--- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 1207db487..4d02de603 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -74,13 +74,7 @@ xmrig::CommonConfig::CommonConfig() : m_colors(true), m_dryRun(false), m_syslog(false), - -# ifdef XMRIG_PROXY_PROJECT m_watch(true), -# else - m_watch(false), // TODO: enable config file watch by default when this feature propertly handled and tested. -# endif - m_apiPort(0), m_donateLevel(kDefaultDonateLevel), m_printTime(60), diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index 42c93f5c3..bc20d8fe6 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -23,6 +23,7 @@ */ +#include #include #include #include @@ -145,6 +146,19 @@ bool xmrig::ConfigLoader::reload(xmrig::IConfig *oldConfig, const char *json) } +bool xmrig::ConfigLoader::watch(IConfig *config) +{ + if (!config->isWatch()) { + return false; + } + + assert(m_watcher == nullptr); + + m_watcher = new xmrig::ConfigWatcher(config->fileName(), m_creator, m_listener); + return true; +} + + xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *creator, IConfigListener *listener) { m_creator = creator; @@ -192,10 +206,6 @@ xmrig::IConfig *xmrig::ConfigLoader::load(Process *process, IConfigCreator *crea return nullptr; } - if (config->isWatch()) { - m_watcher = new xmrig::ConfigWatcher(config->fileName(), creator, listener); - } - return config; } diff --git a/src/common/config/ConfigLoader.h b/src/common/config/ConfigLoader.h index 0a85ab944..5b36fd812 100644 --- a/src/common/config/ConfigLoader.h +++ b/src/common/config/ConfigLoader.h @@ -52,6 +52,7 @@ public: static bool loadFromJSON(IConfig *config, const char *json); static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc); static bool reload(IConfig *oldConfig, const char *json); + static bool watch(IConfig *config); static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener); static void release(); diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 1113c6d5d..e54924634 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -147,6 +147,20 @@ void xmrig::Controller::addListener(IControllerListener *listener) } +void xmrig::Controller::save() +{ + if (!config()) { + return; + } + + if (d_ptr->config->isShouldSave()) { + d_ptr->config->save(); + } + + ConfigLoader::watch(d_ptr->config); +} + + void xmrig::Controller::onNewConfig(IConfig *config) { Config *previousConfig = d_ptr->config; diff --git a/src/core/Controller.h b/src/core/Controller.h index 7bb34db2f..4f81fd82f 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -54,6 +54,7 @@ public: int init(); Network *network() const; void addListener(IControllerListener *listener); + void save(); protected: void onNewConfig(IConfig *config) override; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 735ed5864..f6a584544 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -206,9 +206,7 @@ void Workers::start(xmrig::Controller *controller) handle->start(Workers::onReady); } - if (controller->config()->isShouldSave()) { - controller->config()->save(); - } + controller->save(); } From 70d6e0e62c79dcadfce8627b6ee0618f49bb70e3 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Feb 2019 09:11:18 +0700 Subject: [PATCH 05/22] Use early exit for --help and --version options. --- CMakeLists.txt | 2 + src/App.cpp | 4 - src/base/kernel/Entry.cpp | 120 +++++++++++++++++++++++++++++ src/base/kernel/Entry.h | 52 +++++++++++++ src/common/config/ConfigLoader.cpp | 73 +----------------- src/common/config/ConfigLoader.h | 5 -- src/common/interfaces/IConfig.h | 2 - src/core/ConfigLoader_platform.h | 62 +-------------- src/core/Controller.cpp | 6 -- src/core/Controller.h | 1 - src/core/usage.h | 95 +++++++++++++++++++++++ src/xmrig.cpp | 11 ++- 12 files changed, 282 insertions(+), 151 deletions(-) create mode 100644 src/base/kernel/Entry.cpp create mode 100644 src/base/kernel/Entry.h create mode 100644 src/core/usage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 238a9b7f3..619b9c766 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ set(HEADERS src/base/io/Watcher.h src/base/kernel/interfaces/IConfigListener.h src/base/kernel/interfaces/IWatcherListener.h + src/base/kernel/Entry.h src/base/kernel/Process.h src/base/tools/Arguments.h src/base/tools/Handle.h @@ -106,6 +107,7 @@ set(SOURCES src/App.cpp src/base/io/Json.cpp src/base/io/Watcher.cpp + src/base/kernel/Entry.cpp src/base/kernel/Process.cpp src/base/tools/Arguments.cpp src/base/tools/Handle.cpp diff --git a/src/App.cpp b/src/App.cpp index d6ed7190e..07acc09a2 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -89,10 +89,6 @@ xmrig::App::~App() int xmrig::App::exec() { - if (m_controller->isDone()) { - return 0; - } - if (!m_controller->isReady()) { return 2; } diff --git a/src/base/kernel/Entry.cpp b/src/base/kernel/Entry.cpp new file mode 100644 index 000000000..abdfd1e10 --- /dev/null +++ b/src/base/kernel/Entry.cpp @@ -0,0 +1,120 @@ +/* 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 , + * + * 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 + + +#ifndef XMRIG_NO_HTTPD +# include +#endif + + +#ifndef XMRIG_NO_TLS +# include +#endif + + +#include "base/kernel/Entry.h" +#include "base/kernel/Process.h" +#include "core/usage.h" +#include "version.h" + + +static int showVersion() +{ + printf(APP_NAME " " APP_VERSION "\n built on " __DATE__ + +# if defined(__clang__) + " with clang " __clang_version__); +# elif defined(__GNUC__) + " with GCC"); + printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +# elif defined(_MSC_VER) + " with MSVC"); + printf(" %d", MSVC_VERSION); +# else + ); +# endif + + printf("\n features:" +# if defined(__i386__) || defined(_M_IX86) + " 32-bit" +# elif defined(__x86_64__) || defined(_M_AMD64) + " 64-bit" +# endif + +# if defined(__AES__) || defined(_MSC_VER) + " AES" +# endif + "\n"); + + printf("\nlibuv/%s\n", uv_version_string()); + +# ifndef XMRIG_NO_HTTPD + printf("microhttpd/%s\n", MHD_get_version()); +# endif + +# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT) + { + constexpr const char *v = OPENSSL_VERSION_TEXT + 8; + printf("OpenSSL/%.*s\n", static_cast(strchr(v, ' ') - v), v); + } +# endif + + return 0; +} + + +xmrig::Entry::Id xmrig::Entry::get(const Process &process) +{ + const Arguments &args = process.arguments(); + if (args.hasArg("-h") || args.hasArg("--help")) { + return Usage; + } + + if (args.hasArg("-V") || args.hasArg("--version")) { + return Version; + } + + return Default; +} + + +int xmrig::Entry::exec(const Process &, Id id) +{ + switch (id) { + case Usage: + printf(usage); + return 0; + + case Version: + return showVersion(); + + default: + break; + } + + return 1; +} diff --git a/src/base/kernel/Entry.h b/src/base/kernel/Entry.h new file mode 100644 index 000000000..0208ecdb2 --- /dev/null +++ b/src/base/kernel/Entry.h @@ -0,0 +1,52 @@ +/* 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 , + * + * 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_ENTRY_H +#define XMRIG_ENTRY_H + + +namespace xmrig { + + +class Process; + + +class Entry +{ +public: + enum Id { + Default, + Usage, + Version + }; + + static Id get(const Process &process); + static int exec(const Process &process, Id id); +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_ENTRY_H */ diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index bc20d8fe6..edd80c4db 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -53,7 +53,6 @@ #include "rapidjson/error/en.h" -bool xmrig::ConfigLoader::m_done = false; xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr; xmrig::IConfigCreator *xmrig::ConfigLoader::m_creator = nullptr; xmrig::IConfigListener *xmrig::ConfigLoader::m_listener = nullptr; @@ -239,24 +238,11 @@ bool xmrig::ConfigLoader::getJSON(const char *fileName, rapidjson::Document &doc bool xmrig::ConfigLoader::parseArg(xmrig::IConfig *config, int key, const char *arg) { - switch (key) { - case xmrig::IConfig::VersionKey: /* --version */ - showVersion(); - return false; - - case xmrig::IConfig::HelpKey: /* --help */ - showUsage(); - return false; - - case xmrig::IConfig::ConfigKey: /* --config */ - loadFromFile(config, arg); - break; - - default: - return config->parseString(key, arg);; + if (key == xmrig::IConfig::ConfigKey) { + return loadFromFile(config, arg); } - return true; + return config->parseString(key, arg); } @@ -283,56 +269,3 @@ void xmrig::ConfigLoader::parseJSON(xmrig::IConfig *config, const struct option config->parseBoolean(option->val, value.IsTrue()); } } - - -void xmrig::ConfigLoader::showUsage() -{ - m_done = true; - - printf(usage); -} - - -void xmrig::ConfigLoader::showVersion() -{ - m_done = true; - - printf(APP_NAME " " APP_VERSION "\n built on " __DATE__ - -# if defined(__clang__) - " with clang " __clang_version__); -# elif defined(__GNUC__) - " with GCC"); - printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); -# elif defined(_MSC_VER) - " with MSVC"); - printf(" %d", MSVC_VERSION); -# else - ); -# endif - - printf("\n features:" -# if defined(__i386__) || defined(_M_IX86) - " 32-bit" -# elif defined(__x86_64__) || defined(_M_AMD64) - " 64-bit" -# endif - -# if defined(__AES__) || defined(_MSC_VER) - " AES" -# endif - "\n"); - - printf("\nlibuv/%s\n", uv_version_string()); - -# ifndef XMRIG_NO_HTTPD - printf("microhttpd/%s\n", MHD_get_version()); -# endif - -# if !defined(XMRIG_NO_TLS) && defined(OPENSSL_VERSION_TEXT) - { - constexpr const char *v = OPENSSL_VERSION_TEXT + 8; - printf("OpenSSL/%.*s\n", static_cast(strchr(v, ' ') - v), v); - } -# endif -} diff --git a/src/common/config/ConfigLoader.h b/src/common/config/ConfigLoader.h index 5b36fd812..99d6143f6 100644 --- a/src/common/config/ConfigLoader.h +++ b/src/common/config/ConfigLoader.h @@ -56,16 +56,11 @@ public: static IConfig *load(Process *process, IConfigCreator *creator, IConfigListener *listener); static void release(); - static inline bool isDone() { return m_done; } - private: static bool getJSON(const char *fileName, rapidjson::Document &doc); static bool parseArg(IConfig *config, int key, const char *arg); static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object); - static void showUsage(); - static void showVersion(); - static bool m_done; static ConfigWatcher *m_watcher; static IConfigCreator *m_creator; static IConfigListener *m_listener; diff --git a/src/common/interfaces/IConfig.h b/src/common/interfaces/IConfig.h index d5f67c492..7e6931a89 100644 --- a/src/common/interfaces/IConfig.h +++ b/src/common/interfaces/IConfig.h @@ -52,7 +52,6 @@ public: ColorKey = 1002, ConfigKey = 'c', DonateLevelKey = 1003, - HelpKey = 'h', KeepAliveKey = 'k', LogFileKey = 'l', PasswordKey = 'p', @@ -66,7 +65,6 @@ public: UserpassKey = 'O', VariantKey = 1010, VerboseKey = 1100, - VersionKey = 'V', WatchKey = 1105, TlsKey = 1013, FingerprintKey = 1014, diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index ceaf7a3fd..749585df8 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -40,65 +40,7 @@ namespace xmrig { -static char const usage[] = "\ -Usage: " APP_ID " [OPTIONS]\n\ -Options:\n\ - -a, --algo=ALGO specify the algorithm to use\n\ - cryptonight\n" -#ifndef XMRIG_NO_AEON -"\ - cryptonight-lite\n" -#endif -#ifndef XMRIG_NO_SUMO -"\ - cryptonight-heavy\n" -#endif -"\ - -o, --url=URL URL of mining server\n\ - -O, --userpass=U:P username:password pair for mining server\n\ - -u, --user=USERNAME username for mining server\n\ - -p, --pass=PASSWORD password for mining server\n\ - --rig-id=ID rig identifier for pool-side statistics (needs pool support)\n\ - -t, --threads=N number of miner threads\n\ - -v, --av=N algorithm variation, 0 auto select\n\ - -k, --keepalive send keepalived packet for prevent timeout (needs pool support)\n\ - --nicehash enable nicehash.com support\n\ - --tls enable SSL/TLS support (needs pool support)\n\ - --tls-fingerprint=F pool TLS certificate fingerprint, if set enable strict certificate pinning\n\ - -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ - -R, --retry-pause=N time to pause between retries (default: 5)\n\ - --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ - --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ - --no-huge-pages disable huge pages support\n\ - --no-color disable colored output\n\ - --variant algorithm PoW variant\n\ - --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ - --user-agent set custom user-agent string for pool\n\ - -B, --background run the miner in the background\n\ - -c, --config=FILE load a JSON-format configuration file\n\ - -l, --log-file=FILE log all output to a file\n" -# ifdef HAVE_SYSLOG_H -"\ - -S, --syslog use system log for output messages\n" -# endif -"\ - --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\ - --safe safe adjust threads and av settings for current CPU\n\ - --asm=ASM ASM code for cn/2, possible values: auto, none, intel, ryzen, bulldozer.\n\ - --print-time=N print hashrate report every N seconds\n\ - --api-port=N port for the miner API\n\ - --api-access-token=T access token for API\n\ - --api-worker-id=ID custom worker-id for API\n\ - --api-id=ID custom instance ID for API\n\ - --api-ipv6 enable IPv6 support for API\n\ - --api-no-restricted enable full remote access (only if API token set)\n\ - --dry-run test configuration and exit\n\ - -h, --help display this help and exit\n\ - -V, --version output version information and exit\n\ -"; - - -static char const short_options[] = "a:c:khBp:Px:r:R:s:t:T:o:u:O:v:Vl:S"; +static char const short_options[] = "a:c:kBp:Px:r:R:s:t:T:o:u:O:v:l:S"; static struct option const options[] = { @@ -116,7 +58,6 @@ static struct option const options[] = { { "cpu-priority", 1, nullptr, xmrig::IConfig::CPUPriorityKey }, { "donate-level", 1, nullptr, xmrig::IConfig::DonateLevelKey }, { "dry-run", 0, nullptr, xmrig::IConfig::DryRunKey }, - { "help", 0, nullptr, xmrig::IConfig::HelpKey }, { "keepalive", 0, nullptr, xmrig::IConfig::KeepAliveKey }, { "log-file", 1, nullptr, xmrig::IConfig::LogFileKey }, { "max-cpu-usage", 1, nullptr, xmrig::IConfig::MaxCPUUsageKey }, @@ -139,7 +80,6 @@ static struct option const options[] = { { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, { "tls", 0, nullptr, xmrig::IConfig::TlsKey }, { "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey }, - { "version", 0, nullptr, xmrig::IConfig::VersionKey }, { "asm", 1, nullptr, xmrig::IConfig::AssemblyKey }, { nullptr, 0, nullptr, 0 } }; diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index e54924634..abe6d46d9 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -81,12 +81,6 @@ xmrig::Controller::~Controller() } -bool xmrig::Controller::isDone() const -{ - return ConfigLoader::isDone(); -} - - bool xmrig::Controller::isReady() const { return d_ptr->config && d_ptr->network; diff --git a/src/core/Controller.h b/src/core/Controller.h index 4f81fd82f..89a462f9c 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -48,7 +48,6 @@ public: Controller(Process *process); ~Controller() override; - bool isDone() const; bool isReady() const; Config *config() const; int init(); diff --git a/src/core/usage.h b/src/core/usage.h new file mode 100644 index 000000000..0d5c47816 --- /dev/null +++ b/src/core/usage.h @@ -0,0 +1,95 @@ +/* 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 , + * + * 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_USAGE_H +#define XMRIG_USAGE_H + + +#include "version.h" + + +namespace xmrig { + + +static char const usage[] = "\ +Usage: " APP_ID " [OPTIONS]\n\ +Options:\n\ + -a, --algo=ALGO specify the algorithm to use\n\ + cryptonight\n" +#ifndef XMRIG_NO_AEON +"\ + cryptonight-lite\n" +#endif +#ifndef XMRIG_NO_SUMO +"\ + cryptonight-heavy\n" +#endif +"\ + -o, --url=URL URL of mining server\n\ + -O, --userpass=U:P username:password pair for mining server\n\ + -u, --user=USERNAME username for mining server\n\ + -p, --pass=PASSWORD password for mining server\n\ + --rig-id=ID rig identifier for pool-side statistics (needs pool support)\n\ + -t, --threads=N number of miner threads\n\ + -v, --av=N algorithm variation, 0 auto select\n\ + -k, --keepalive send keepalived packet for prevent timeout (needs pool support)\n\ + --nicehash enable nicehash.com support\n\ + --tls enable SSL/TLS support (needs pool support)\n\ + --tls-fingerprint=F pool TLS certificate fingerprint, if set enable strict certificate pinning\n\ + -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ + -R, --retry-pause=N time to pause between retries (default: 5)\n\ + --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ + --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ + --no-huge-pages disable huge pages support\n\ + --no-color disable colored output\n\ + --variant algorithm PoW variant\n\ + --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ + --user-agent set custom user-agent string for pool\n\ + -B, --background run the miner in the background\n\ + -c, --config=FILE load a JSON-format configuration file\n\ + -l, --log-file=FILE log all output to a file\n" +# ifdef HAVE_SYSLOG_H +"\ + -S, --syslog use system log for output messages\n" +# endif +"\ + --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75)\n\ + --safe safe adjust threads and av settings for current CPU\n\ + --asm=ASM ASM code for cn/2, possible values: auto, none, intel, ryzen, bulldozer.\n\ + --print-time=N print hashrate report every N seconds\n\ + --api-port=N port for the miner API\n\ + --api-access-token=T access token for API\n\ + --api-worker-id=ID custom worker-id for API\n\ + --api-id=ID custom instance ID for API\n\ + --api-ipv6 enable IPv6 support for API\n\ + --api-no-restricted enable full remote access (only if API token set)\n\ + --dry-run test configuration and exit\n\ + -h, --help display this help and exit\n\ + -V, --version output version information and exit\n\ +"; + + +} /* namespace xmrig */ + +#endif /* XMRIG_USAGE_H */ diff --git a/src/xmrig.cpp b/src/xmrig.cpp index eec5f5faf..07f18e372 100644 --- a/src/xmrig.cpp +++ b/src/xmrig.cpp @@ -23,13 +23,20 @@ */ #include "App.h" +#include "base/kernel/Entry.h" #include "base/kernel/Process.h" int main(int argc, char **argv) { - xmrig::Process process(argc, argv); + using namespace xmrig; - xmrig::App app(&process); + Process process(argc, argv); + const Entry::Id entry = Entry::get(process); + if (entry) { + return Entry::exec(process, entry); + } + + App app(&process); return app.exec(); } From 4f188a2cd80110275d2be14647b01bdc683302f4 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 15 Feb 2019 14:21:40 +0700 Subject: [PATCH 06/22] Add Signals class. --- CMakeLists.txt | 3 + src/App.cpp | 52 +++++++--------- src/App.h | 16 ++--- src/base/kernel/Signals.cpp | 63 ++++++++++++++++++++ src/base/kernel/Signals.h | 62 +++++++++++++++++++ src/base/kernel/interfaces/ISignalListener.h | 47 +++++++++++++++ 6 files changed, 201 insertions(+), 42 deletions(-) create mode 100644 src/base/kernel/Signals.cpp create mode 100644 src/base/kernel/Signals.h create mode 100644 src/base/kernel/interfaces/ISignalListener.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 619b9c766..121e711ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,11 @@ set(HEADERS src/base/io/Json.h src/base/io/Watcher.h src/base/kernel/interfaces/IConfigListener.h + src/base/kernel/interfaces/ISignalListener.h src/base/kernel/interfaces/IWatcherListener.h src/base/kernel/Entry.h src/base/kernel/Process.h + src/base/kernel/Signals.h src/base/tools/Arguments.h src/base/tools/Handle.h src/base/tools/String.h @@ -109,6 +111,7 @@ set(SOURCES src/base/io/Watcher.cpp src/base/kernel/Entry.cpp src/base/kernel/Process.cpp + src/base/kernel/Signals.cpp src/base/tools/Arguments.cpp src/base/tools/Handle.cpp src/base/tools/String.cpp diff --git a/src/App.cpp b/src/App.cpp index 07acc09a2..31691fbf3 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -30,6 +30,7 @@ #include "api/Api.h" #include "App.h" +#include "base/kernel/Signals.h" #include "common/Console.h" #include "common/cpu/Cpu.h" #include "common/log/Log.h" @@ -49,16 +50,11 @@ #endif -xmrig::App *xmrig::App::m_self = nullptr; - - - xmrig::App::App(Process *process) : m_console(nullptr), - m_httpd(nullptr) + m_httpd(nullptr), + m_signals(nullptr) { - m_self = this; - m_controller = new xmrig::Controller(process); if (m_controller->init() != 0) { return; @@ -67,10 +63,6 @@ xmrig::App::App(Process *process) : if (!m_controller->config()->isBackground()) { m_console = new Console(this); } - - uv_signal_init(uv_default_loop(), &m_sigHUP); - uv_signal_init(uv_default_loop(), &m_sigINT); - uv_signal_init(uv_default_loop(), &m_sigTERM); } @@ -78,6 +70,7 @@ xmrig::App::~App() { uv_tty_reset_mode(); + delete m_signals; delete m_console; delete m_controller; @@ -93,9 +86,7 @@ int xmrig::App::exec() return 2; } - uv_signal_start(&m_sigHUP, App::onSignal, SIGHUP); - uv_signal_start(&m_sigINT, App::onSignal, SIGINT); - uv_signal_start(&m_sigTERM, App::onSignal, SIGTERM); + m_signals = new Signals(this); background(); @@ -172,21 +163,7 @@ void xmrig::App::onConsoleCommand(char command) } -void xmrig::App::close() -{ - m_controller->network()->stop(); - Workers::stop(); - - uv_stop(uv_default_loop()); -} - - -void xmrig::App::release() -{ -} - - -void xmrig::App::onSignal(uv_signal_t *handle, int signum) +void xmrig::App::onSignal(int signum) { switch (signum) { @@ -206,6 +183,19 @@ void xmrig::App::onSignal(uv_signal_t *handle, int signum) break; } - uv_signal_stop(handle); - m_self->close(); + close(); +} + + +void xmrig::App::close() +{ + m_controller->network()->stop(); + Workers::stop(); + + uv_stop(uv_default_loop()); +} + + +void xmrig::App::release() +{ } diff --git a/src/App.h b/src/App.h index b93fc4a1d..9ec8edcc5 100644 --- a/src/App.h +++ b/src/App.h @@ -27,9 +27,7 @@ #define XMRIG_APP_H -#include - - +#include "base/kernel/interfaces/ISignalListener.h" #include "common/interfaces/IConsoleListener.h" @@ -43,9 +41,10 @@ namespace xmrig { class Controller; class Process; +class Signals; -class App : public IConsoleListener +class App : public IConsoleListener, public ISignalListener { public: App(Process *process); @@ -55,21 +54,16 @@ public: protected: void onConsoleCommand(char command) override; + void onSignal(int signum) override; private: void background(); void close(); void release(); - static void onSignal(uv_signal_t *handle, int signum); - - static App *m_self; - Console *m_console; Httpd *m_httpd; - uv_signal_t m_sigHUP; - uv_signal_t m_sigINT; - uv_signal_t m_sigTERM; + Signals *m_signals; xmrig::Controller *m_controller; }; diff --git a/src/base/kernel/Signals.cpp b/src/base/kernel/Signals.cpp new file mode 100644 index 000000000..a37c49c6f --- /dev/null +++ b/src/base/kernel/Signals.cpp @@ -0,0 +1,63 @@ +/* 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 SChernykh + * Copyright 2016-2018 XMRig , + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include + + +#include "base/kernel/interfaces/ISignalListener.h" +#include "base/kernel/Signals.h" +#include "base/tools/Handle.h" + + +static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM }; + + +xmrig::Signals::Signals(ISignalListener *listener) + : m_listener(listener) +{ + for (size_t i = 0; i < kSignalsCount; ++i) { + uv_signal_t *signal = new uv_signal_t; + signal->data = this; + + m_signals[i] = signal; + + uv_signal_init(uv_default_loop(), signal); + uv_signal_start(signal, xmrig::Signals::onSignal, signums[i]); + } +} + + +xmrig::Signals::~Signals() +{ + for (size_t i = 0; i < kSignalsCount; ++i) { + Handle::close(m_signals[i]); + } +} + + +void xmrig::Signals::onSignal(uv_signal_t *handle, int signum) +{ + static_cast(handle->data)->m_listener->onSignal(signum); +} diff --git a/src/base/kernel/Signals.h b/src/base/kernel/Signals.h new file mode 100644 index 000000000..8ef4a4bb4 --- /dev/null +++ b/src/base/kernel/Signals.h @@ -0,0 +1,62 @@ +/* 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 , + * + * 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_SIGNALS_H +#define XMRIG_SIGNALS_H + + +#include + + +typedef struct uv_signal_s uv_signal_t; + + +namespace xmrig { + + +class ISignalListener; + + +class Signals +{ +public: + constexpr static const size_t kSignalsCount = 3; + + Signals(ISignalListener *listener); + ~Signals(); + +private: + void close(int signum); + + static void onSignal(uv_signal_t *handle, int signum); + + ISignalListener *m_listener; + uv_signal_t *m_signals[kSignalsCount]; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_SIGNALS_H */ diff --git a/src/base/kernel/interfaces/ISignalListener.h b/src/base/kernel/interfaces/ISignalListener.h new file mode 100644 index 000000000..bbcd11f12 --- /dev/null +++ b/src/base/kernel/interfaces/ISignalListener.h @@ -0,0 +1,47 @@ +/* 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 , + * + * 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_ISIGNALLISTENER_H +#define XMRIG_ISIGNALLISTENER_H + + +namespace xmrig { + + +class String; + + +class ISignalListener +{ +public: + virtual ~ISignalListener() = default; + + virtual void onSignal(int signum) = 0; +}; + + +} /* namespace xmrig */ + + +#endif // XMRIG_ISIGNALLISTENER_H From dbdcc1467265818ae39bebd52370f1ec1647331e Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 16 Feb 2019 09:56:08 +0700 Subject: [PATCH 07/22] Move Pool.h/Pool.cpp. --- CMakeLists.txt | 6 ++- src/Summary.cpp | 2 +- src/{common => base}/net/Pool.cpp | 2 +- src/{common => base}/net/Pool.h | 2 +- src/base/net/Pools.cpp | 32 ++++++++++++ src/base/net/Pools.h | 51 ++++++++++++++++++++ src/common/config/CommonConfig.cpp | 8 +-- src/common/config/CommonConfig.h | 5 +- src/common/config/ConfigLoader.cpp | 2 +- src/common/net/Client.h | 2 +- src/common/net/strategies/FailoverStrategy.h | 2 +- src/net/strategies/DonateStrategy.h | 2 +- src/workers/CpuThread.cpp | 1 - 13 files changed, 99 insertions(+), 18 deletions(-) rename src/{common => base}/net/Pool.cpp (99%) rename src/{common => base}/net/Pool.h (99%) create mode 100644 src/base/net/Pools.cpp create mode 100644 src/base/net/Pools.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 121e711ab..d2009b84d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ set(HEADERS src/base/kernel/Entry.h src/base/kernel/Process.h src/base/kernel/Signals.h + src/base/net/Pool.h + src/base/net/Pools.h src/base/tools/Arguments.h src/base/tools/Handle.h src/base/tools/String.h @@ -54,7 +56,6 @@ set(HEADERS src/common/net/Client.h src/common/net/Id.h src/common/net/Job.h - src/common/net/Pool.h src/common/net/Storage.h src/common/net/strategies/FailoverStrategy.h src/common/net/strategies/SinglePoolStrategy.h @@ -112,6 +113,8 @@ set(SOURCES src/base/kernel/Entry.cpp src/base/kernel/Process.cpp src/base/kernel/Signals.cpp + src/base/net/Pool.cpp + src/base/net/Pools.cpp src/base/tools/Arguments.cpp src/base/tools/Handle.cpp src/base/tools/String.cpp @@ -127,7 +130,6 @@ set(SOURCES src/common/log/Log.cpp src/common/net/Client.cpp src/common/net/Job.cpp - src/common/net/Pool.cpp src/common/net/strategies/FailoverStrategy.cpp src/common/net/strategies/SinglePoolStrategy.cpp src/common/net/SubmitResult.cpp diff --git a/src/Summary.cpp b/src/Summary.cpp index dc671438e..60a9278f9 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -28,9 +28,9 @@ #include +#include "base/net/Pool.h" #include "common/cpu/Cpu.h" #include "common/log/Log.h" -#include "common/net/Pool.h" #include "core/Config.h" #include "core/Controller.h" #include "crypto/Asm.h" diff --git a/src/common/net/Pool.cpp b/src/base/net/Pool.cpp similarity index 99% rename from src/common/net/Pool.cpp rename to src/base/net/Pool.cpp index 585e45966..c53377e8a 100644 --- a/src/common/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -29,7 +29,7 @@ #include -#include "common/net/Pool.h" +#include "base/net/Pool.h" #include "rapidjson/document.h" diff --git a/src/common/net/Pool.h b/src/base/net/Pool.h similarity index 99% rename from src/common/net/Pool.h rename to src/base/net/Pool.h index c051b0ee2..59bc9eb89 100644 --- a/src/common/net/Pool.h +++ b/src/base/net/Pool.h @@ -111,6 +111,6 @@ private: }; -typedef std::vector Pools; +//typedef std::vector Pools; #endif /* XMRIG_POOL_H */ diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp new file mode 100644 index 000000000..ab5609fcc --- /dev/null +++ b/src/base/net/Pools.cpp @@ -0,0 +1,32 @@ +/* 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 , + * + * 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/net/Pools.h" + + +xmrig::Pools::Pools() +{ + +} diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h new file mode 100644 index 000000000..5d2aa0d48 --- /dev/null +++ b/src/base/net/Pools.h @@ -0,0 +1,51 @@ +/* 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 , + * + * 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_POOLS_H +#define XMRIG_POOLS_H + + +#include + + +#include "base/net/Pool.h" + + +namespace xmrig { + + +class Pools +{ +public: + Pools(); + +private: + std::vector m_data; +}; + + +} /* namespace xmrig */ + + +#endif /* XMRIG_POOLS_H */ diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 4d02de603..9a2f8c9e0 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -109,19 +109,19 @@ void xmrig::CommonConfig::printPools() { for (size_t i = 0; i < m_activePools.size(); ++i) { if (!isColors()) { - Log::i()->text(" * POOL #%-7zu%s variant=%s, TLS=%d", + Log::i()->text(" * POOL #%-7zu%s algo=%s, TLS=%d", i + 1, m_activePools[i].url(), - m_activePools[i].algorithm().variantName(), + m_activePools[i].algorithm().shortName(), static_cast(m_activePools[i].isTLS()) ); } else { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"), + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"), i + 1, m_activePools[i].isTLS() ? 32 : 36, m_activePools[i].url(), - m_activePools[i].algorithm().variantName() + m_activePools[i].algorithm().shortName() ); } } diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 619f4b03a..058d6eddb 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -26,12 +26,9 @@ #define XMRIG_COMMONCONFIG_H -#include - - +#include "base/net/Pools.h" #include "base/tools/String.h" #include "common/interfaces/IConfig.h" -#include "common/net/Pool.h" #include "common/xmrig.h" diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index edd80c4db..e5eeb2b9f 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -45,12 +45,12 @@ #include "common/config/ConfigLoader.h" #include "common/config/ConfigWatcher.h" #include "common/interfaces/IConfig.h" -#include "common/net/Pool.h" #include "common/Platform.h" #include "core/ConfigCreator.h" #include "core/ConfigLoader_platform.h" #include "rapidjson/document.h" #include "rapidjson/error/en.h" +#include "rapidjson/fwd.h" xmrig::ConfigWatcher *xmrig::ConfigLoader::m_watcher = nullptr; diff --git a/src/common/net/Client.h b/src/common/net/Client.h index a05710fc3..4594a90fa 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -30,10 +30,10 @@ #include +#include "base/net/Pool.h" #include "common/crypto/Algorithm.h" #include "common/net/Id.h" #include "common/net/Job.h" -#include "common/net/Pool.h" #include "common/net/Storage.h" #include "common/net/SubmitResult.h" #include "rapidjson/fwd.h" diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index 9fe9f9d8f..cfc8e92ae 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -29,9 +29,9 @@ #include +#include "base/net/Pool.h" #include "common/interfaces/IClientListener.h" #include "common/interfaces/IStrategy.h" -#include "common/net/Pool.h" class Client; diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index d012c1b9d..eab01370e 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -30,7 +30,7 @@ #include -#include "common/net/Pool.h" +#include "base/net/Pool.h" #include "common/interfaces/IClientListener.h" #include "common/interfaces/IStrategy.h" #include "common/interfaces/IStrategyListener.h" diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 4b539bb3f..c1daaf5a9 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -27,7 +27,6 @@ #include "common/cpu/Cpu.h" #include "common/log/Log.h" -#include "common/net/Pool.h" #include "crypto/Asm.h" #include "Mem.h" #include "rapidjson/document.h" From ee667144e82473a52c80393d7a6f6ee5080e66ea Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 06:59:19 +0700 Subject: [PATCH 08/22] Move network classes into xmrig namespace. --- src/App.h | 4 +- src/api/Api.cpp | 5 +- src/api/Api.h | 13 ++- src/api/ApiRouter.cpp | 9 +- src/api/ApiRouter.h | 15 +-- src/api/NetworkState.cpp | 14 +-- src/api/NetworkState.h | 18 ++- src/base/net/Pool.cpp | 108 ++++++++++++------ src/base/net/Pool.h | 43 ++++--- src/base/net/Pools.cpp | 4 +- src/base/net/Pools.h | 1 + src/common/config/CommonConfig.cpp | 8 +- src/common/config/CommonConfig.h | 13 ++- src/common/crypto/Algorithm.h | 2 +- src/common/interfaces/IClientListener.h | 23 ++-- src/common/interfaces/IStrategy.h | 12 +- src/common/interfaces/IStrategyListener.h | 17 ++- src/common/net/Client.cpp | 91 ++++++++------- src/common/net/Client.h | 21 ++-- src/common/net/Job.cpp | 40 +++---- src/common/net/Job.h | 19 ++- src/common/net/SubmitResult.cpp | 7 +- src/common/net/SubmitResult.h | 16 ++- src/common/net/Tls.cpp | 24 ++-- src/common/net/Tls.h | 5 +- .../net/strategies/FailoverStrategy.cpp | 26 ++--- src/common/net/strategies/FailoverStrategy.h | 9 +- .../net/strategies/SinglePoolStrategy.cpp | 24 ++-- .../net/strategies/SinglePoolStrategy.h | 9 +- src/core/Config.cpp | 2 + src/core/Controller.cpp | 6 +- src/core/Controller.h | 4 +- src/interfaces/IJobResultListener.h | 19 ++- src/net/JobResult.h | 27 +++-- src/net/Network.cpp | 32 +++--- src/net/Network.h | 17 +-- src/net/strategies/DonateStrategy.cpp | 32 +++--- src/net/strategies/DonateStrategy.h | 12 +- src/workers/MultiWorker.cpp | 10 +- src/workers/MultiWorker.h | 8 +- src/workers/Workers.cpp | 16 +-- src/workers/Workers.h | 28 ++--- 42 files changed, 481 insertions(+), 332 deletions(-) diff --git a/src/App.h b/src/App.h index 9ec8edcc5..3a1777979 100644 --- a/src/App.h +++ b/src/App.h @@ -33,13 +33,13 @@ class Console; class Httpd; -class Network; namespace xmrig { class Controller; +class Network; class Process; class Signals; @@ -62,9 +62,9 @@ private: void release(); Console *m_console; + Controller *m_controller; Httpd *m_httpd; Signals *m_signals; - xmrig::Controller *m_controller; }; diff --git a/src/api/Api.cpp b/src/api/Api.cpp index 3fff45b52..2abdf4be0 100644 --- a/src/api/Api.cpp +++ b/src/api/Api.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -62,7 +63,7 @@ void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) } -void Api::tick(const NetworkState &network) +void Api::tick(const xmrig::NetworkState &network) { if (!m_router) { return; diff --git a/src/api/Api.h b/src/api/Api.h index 316bb0fa2..caee887a6 100644 --- a/src/api/Api.h +++ b/src/api/Api.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __API_H__ -#define __API_H__ +#ifndef XMRIG_API_H +#define XMRIG_API_H #include @@ -30,13 +31,13 @@ class ApiRouter; class Hashrate; -class NetworkState; namespace xmrig { class Controller; class HttpReply; class HttpRequest; + class NetworkState; } @@ -47,10 +48,10 @@ public: static void release(); static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); - static void tick(const NetworkState &results); + static void tick(const xmrig::NetworkState &results); private: static ApiRouter *m_router; }; -#endif /* __API_H__ */ +#endif /* XMRIG_API_H */ diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index dd7accf69..69fa15949 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -119,7 +120,7 @@ void ApiRouter::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) } -void ApiRouter::tick(const NetworkState &network) +void ApiRouter::tick(const xmrig::NetworkState &network) { m_network = network; } @@ -133,7 +134,7 @@ void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousCo void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const { - rapidjson::StringBuffer buffer(0, 4096); + rapidjson::StringBuffer buffer(nullptr, 4096); rapidjson::PrettyWriter writer(buffer); writer.SetMaxDecimalPlaces(10); doc.Accept(writer); @@ -173,7 +174,7 @@ void ApiRouter::genId(const char *id) memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); xmrig::keccak(input, inSize, hash); - Job::toHex(hash, 8, m_id); + xmrig::Job::toHex(hash, 8, m_id); delete [] input; break; diff --git a/src/api/ApiRouter.h b/src/api/ApiRouter.h index b781d5a28..a92173ce4 100644 --- a/src/api/ApiRouter.h +++ b/src/api/ApiRouter.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __APIROUTER_H__ -#define __APIROUTER_H__ +#ifndef XMRIG_APIROUTER_H +#define XMRIG_APIROUTER_H #include "api/NetworkState.h" @@ -44,12 +45,12 @@ class ApiRouter : public xmrig::IControllerListener { public: ApiRouter(xmrig::Controller *controller); - ~ApiRouter(); + ~ApiRouter() override; void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const; void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); - void tick(const NetworkState &results); + void tick(const xmrig::NetworkState &results); protected: void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override; @@ -68,8 +69,8 @@ private: char m_id[32]; char m_workerId[128]; - NetworkState m_network; + xmrig::NetworkState m_network; xmrig::Controller *m_controller; }; -#endif /* __APIROUTER_H__ */ +#endif /* XMRIG_APIROUTER_H */ diff --git a/src/api/NetworkState.cpp b/src/api/NetworkState.cpp index 0ab800935..0d60cbd2e 100644 --- a/src/api/NetworkState.cpp +++ b/src/api/NetworkState.cpp @@ -32,7 +32,7 @@ #include "common/net/SubmitResult.h" -NetworkState::NetworkState() : +xmrig::NetworkState::NetworkState() : diff(0), accepted(0), failures(0), @@ -44,13 +44,13 @@ NetworkState::NetworkState() : } -int NetworkState::connectionTime() const +int xmrig::NetworkState::connectionTime() const { return m_active ? (int)((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0; } -uint32_t NetworkState::avgTime() const +uint32_t xmrig::NetworkState::avgTime() const { if (m_latency.empty()) { return 0; @@ -60,7 +60,7 @@ uint32_t NetworkState::avgTime() const } -uint32_t NetworkState::latency() const +uint32_t xmrig::NetworkState::latency() const { const size_t calls = m_latency.size(); if (calls == 0) { @@ -74,7 +74,7 @@ uint32_t NetworkState::latency() const } -void NetworkState::add(const SubmitResult &result, const char *error) +void xmrig::NetworkState::add(const SubmitResult &result, const char *error) { if (error) { rejected++; @@ -94,7 +94,7 @@ void NetworkState::add(const SubmitResult &result, const char *error) } -void NetworkState::setPool(const char *host, int port, const char *ip) +void xmrig::NetworkState::setPool(const char *host, int port, const char *ip) { snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port); @@ -103,7 +103,7 @@ void NetworkState::setPool(const char *host, int port, const char *ip) } -void NetworkState::stop() +void xmrig::NetworkState::stop() { m_active = false; diff = 0; diff --git a/src/api/NetworkState.h b/src/api/NetworkState.h index d09980741..c45761fb2 100644 --- a/src/api/NetworkState.h +++ b/src/api/NetworkState.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,14 +22,17 @@ * along with this program. If not, see . */ -#ifndef __NETWORKSTATE_H__ -#define __NETWORKSTATE_H__ +#ifndef XMRIG_NETWORKSTATE_H +#define XMRIG_NETWORKSTATE_H #include #include +namespace xmrig { + + class SubmitResult; @@ -58,4 +62,8 @@ private: uint64_t m_connectionTime; }; -#endif /* __NETWORKSTATE_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_NETWORKSTATE_H */ diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index c53377e8a..b81593b40 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -44,7 +44,7 @@ #endif -Pool::Pool() : +xmrig::Pool::Pool() : m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -64,7 +64,7 @@ Pool::Pool() : * * @param url */ -Pool::Pool(const char *url) : +xmrig::Pool::Pool(const char *url) : m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -74,14 +74,54 @@ Pool::Pool(const char *url) : } -Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : +xmrig::Pool::Pool(const rapidjson::Value &object) : + m_nicehash(false), + m_tls(false), + m_keepAlive(0), + m_port(kDefaultPort) +{ + if (!parse(object["url"].GetString())) { + return; + } + + setUser(object["user"].GetString()); + setPassword(object["pass"].GetString()); + setRigId(object["rig-id"].GetString()); + setNicehash(object["nicehash"].GetBool()); + + const rapidjson::Value &keepalive = object["keepalive"]; + if (keepalive.IsInt()) { + setKeepAlive(keepalive.GetInt()); + } + else if (keepalive.IsBool()) { + setKeepAlive(keepalive.IsTrue() ? kKeepAliveTimeout : 0); + } + + const rapidjson::Value &variant = object["variant"]; + if (variant.IsString()) { + algorithm().parseVariant(variant.GetString()); + } + else if (variant.IsInt()) { + algorithm().parseVariant(variant.GetInt()); + } + + const rapidjson::Value &tls = object["tls"]; + if (tls.IsBool()) { + m_tls = tls.IsTrue(); + } + + m_fingerprint = object["tls-fingerprint"].GetString(); +} + + +xmrig::Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, bool tls) : m_nicehash(nicehash), m_tls(tls), m_keepAlive(keepAlive), - m_port(port), m_host(host), m_password(password), - m_user(user) + m_user(user), + m_port(port) { const size_t size = m_host.size() + 8; assert(size > 8); @@ -93,7 +133,7 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo } -bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const +bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const { if (m_algorithms.empty()) { return true; @@ -115,7 +155,7 @@ bool Pool::isCompatible(const xmrig::Algorithm &algorithm) const } -bool Pool::isEqual(const Pool &other) const +bool xmrig::Pool::isEqual(const Pool &other) const { return (m_nicehash == other.m_nicehash && m_tls == other.m_tls @@ -131,7 +171,7 @@ bool Pool::isEqual(const Pool &other) const } -bool Pool::parse(const char *url) +bool xmrig::Pool::parse(const char *url) { assert(url != nullptr); @@ -178,7 +218,7 @@ bool Pool::parse(const char *url) } -bool Pool::setUserpass(const char *userpass) +bool xmrig::Pool::setUserpass(const char *userpass) { const char *p = strchr(userpass, ':'); if (!p) { @@ -195,7 +235,7 @@ bool Pool::setUserpass(const char *userpass) } -rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const +rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const { using namespace rapidjson; @@ -220,13 +260,13 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const } switch (m_algorithm.variant()) { - case xmrig::VARIANT_AUTO: - case xmrig::VARIANT_0: - case xmrig::VARIANT_1: + case VARIANT_AUTO: + case VARIANT_0: + case VARIANT_1: obj.AddMember("variant", m_algorithm.variant(), allocator); break; - case xmrig::VARIANT_2: + case VARIANT_2: obj.AddMember("variant", 2, allocator); break; @@ -242,7 +282,7 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const } -void Pool::adjust(const xmrig::Algorithm &algorithm) +void xmrig::Pool::adjust(const Algorithm &algorithm) { if (!isValid()) { return; @@ -257,7 +297,7 @@ void Pool::adjust(const xmrig::Algorithm &algorithm) } -void Pool::setAlgo(const xmrig::Algorithm &algorithm) +void xmrig::Pool::setAlgo(const xmrig::Algorithm &algorithm) { m_algorithm = algorithm; @@ -266,7 +306,7 @@ void Pool::setAlgo(const xmrig::Algorithm &algorithm) #ifdef APP_DEBUG -void Pool::print() const +void xmrig::Pool::print() const { LOG_NOTICE("url: %s", m_url.data()); LOG_DEBUG ("host: %s", m_host.data()); @@ -281,7 +321,7 @@ void Pool::print() const #endif -bool Pool::parseIPv6(const char *addr) +bool xmrig::Pool::parseIPv6(const char *addr) { const char *end = strchr(addr, ']'); if (!end) { @@ -304,7 +344,7 @@ bool Pool::parseIPv6(const char *addr) } -void Pool::addVariant(xmrig::Variant variant) +void xmrig::Pool::addVariant(xmrig::Variant variant) { const xmrig::Algorithm algorithm(m_algorithm.algo(), variant); if (!algorithm.isValid() || m_algorithm == algorithm) { @@ -315,7 +355,7 @@ void Pool::addVariant(xmrig::Variant variant) } -void Pool::adjustVariant(const xmrig::Variant variantHint) +void xmrig::Pool::adjustVariant(const xmrig::Variant variantHint) { # ifndef XMRIG_PROXY_PROJECT using namespace xmrig; @@ -401,7 +441,7 @@ void Pool::adjustVariant(const xmrig::Variant variantHint) } -void Pool::rebuild() +void xmrig::Pool::rebuild() { m_algorithms.clear(); @@ -412,18 +452,18 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - addVariant(xmrig::VARIANT_WOW); - addVariant(xmrig::VARIANT_2); - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_HALF); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_TUBE); - addVariant(xmrig::VARIANT_MSR); - addVariant(xmrig::VARIANT_XHV); - addVariant(xmrig::VARIANT_XAO); - addVariant(xmrig::VARIANT_RTO); - addVariant(xmrig::VARIANT_GPU); - addVariant(xmrig::VARIANT_AUTO); + addVariant(VARIANT_WOW); + addVariant(VARIANT_2); + addVariant(VARIANT_1); + addVariant(VARIANT_0); + addVariant(VARIANT_HALF); + addVariant(VARIANT_XTL); + addVariant(VARIANT_TUBE); + addVariant(VARIANT_MSR); + addVariant(VARIANT_XHV); + addVariant(VARIANT_XAO); + addVariant(VARIANT_RTO); + addVariant(VARIANT_GPU); + addVariant(VARIANT_AUTO); # endif } diff --git a/src/base/net/Pool.h b/src/base/net/Pool.h index 59bc9eb89..06ccf2bc9 100644 --- a/src/base/net/Pool.h +++ b/src/base/net/Pool.h @@ -5,7 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -29,11 +29,14 @@ #include +#include "base/tools/String.h" #include "common/crypto/Algorithm.h" -#include "common/utils/c_str.h" #include "rapidjson/fwd.h" +namespace xmrig { + + class Pool { public: @@ -44,6 +47,7 @@ public: Pool(); Pool(const char *url); + Pool(const rapidjson::Value &object); Pool(const char *host, uint16_t port, const char *user = nullptr, @@ -62,8 +66,8 @@ public: inline const char *rigId() const { return m_rigId.data(); } inline const char *url() const { return m_url.data(); } inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; } - inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } - inline const xmrig::Algorithms &algorithms() const { return m_algorithms; } + inline const Algorithm &algorithm() const { return m_algorithm; } + inline const Algorithms &algorithms() const { return m_algorithms; } inline int keepAlive() const { return m_keepAlive; } inline uint16_t port() const { return m_port; } inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } @@ -73,18 +77,18 @@ public: inline void setRigId(const char *rigId) { m_rigId = rigId; } inline void setTLS(bool tls) { m_tls = tls; } inline void setUser(const char *user) { m_user = user; } - inline xmrig::Algorithm &algorithm() { return m_algorithm; } + inline Algorithm &algorithm() { return m_algorithm; } inline bool operator!=(const Pool &other) const { return !isEqual(other); } inline bool operator==(const Pool &other) const { return isEqual(other); } - bool isCompatible(const xmrig::Algorithm &algorithm) const; + bool isCompatible(const Algorithm &algorithm) const; bool isEqual(const Pool &other) const; bool parse(const char *url); bool setUserpass(const char *userpass); rapidjson::Value toJSON(rapidjson::Document &doc) const; - void adjust(const xmrig::Algorithm &algorithm); - void setAlgo(const xmrig::Algorithm &algorithm); + void adjust(const Algorithm &algorithm); + void setAlgo(const Algorithm &algorithm); # ifdef APP_DEBUG void print() const; @@ -92,25 +96,26 @@ public: private: bool parseIPv6(const char *addr); - void addVariant(xmrig::Variant variant); - void adjustVariant(const xmrig::Variant variantHint); + void addVariant(Variant variant); + void adjustVariant(const Variant variantHint); void rebuild(); + Algorithm m_algorithm; + Algorithms m_algorithms; bool m_nicehash; bool m_tls; int m_keepAlive; + String m_fingerprint; + String m_host; + String m_password; + String m_rigId; + String m_url; + String m_user; uint16_t m_port; - xmrig::Algorithm m_algorithm; - xmrig::Algorithms m_algorithms; - xmrig::c_str m_fingerprint; - xmrig::c_str m_host; - xmrig::c_str m_password; - xmrig::c_str m_rigId; - xmrig::c_str m_url; - xmrig::c_str m_user; }; -//typedef std::vector Pools; +} /* namespace xmrig */ + #endif /* XMRIG_POOL_H */ diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index ab5609fcc..49a1607c3 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -26,7 +26,7 @@ #include "base/net/Pools.h" -xmrig::Pools::Pools() +xmrig::Pools::Pools() : + m_index(0) { - } diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index 5d2aa0d48..1f8a8c771 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -41,6 +41,7 @@ public: Pools(); private: + size_t m_index; std::vector m_data; }; diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 9a2f8c9e0..604ab0890 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -425,6 +425,12 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) } +void xmrig::CommonConfig::parseJSON(const rapidjson::Document &doc) +{ + +} + + void xmrig::CommonConfig::setFileName(const char *fileName) { m_fileName = fileName; @@ -480,7 +486,7 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) } -Pool &xmrig::CommonConfig::currentPool() +xmrig::Pool &xmrig::CommonConfig::currentPool() { fixup(); diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 058d6eddb..6316a078b 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -81,6 +81,7 @@ protected: bool parseBoolean(int key, bool enable) override; bool parseString(int key, const char *arg) override; bool parseUint64(int key, uint64_t arg) override; + void parseJSON(const rapidjson::Document &doc) override; void setFileName(const char *fileName) override; Algorithm m_algorithm; @@ -101,12 +102,12 @@ protected: State m_state; std::vector m_activePools; std::vector m_pools; - xmrig::String m_apiId; - xmrig::String m_apiToken; - xmrig::String m_apiWorkerId; - xmrig::String m_fileName; - xmrig::String m_logFile; - xmrig::String m_userAgent; + String m_apiId; + String m_apiToken; + String m_apiWorkerId; + String m_fileName; + String m_logFile; + String m_userAgent; private: bool parseInt(int key, int arg); diff --git a/src/common/crypto/Algorithm.h b/src/common/crypto/Algorithm.h index f4380d45f..664552aa5 100644 --- a/src/common/crypto/Algorithm.h +++ b/src/common/crypto/Algorithm.h @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify diff --git a/src/common/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h index f6e7fd3c5..029d140d6 100644 --- a/src/common/interfaces/IClientListener.h +++ b/src/common/interfaces/IClientListener.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,22 +22,27 @@ * along with this program. If not, see . */ -#ifndef __ICLIENTLISTENER_H__ -#define __ICLIENTLISTENER_H__ +#ifndef XMRIG_ICLIENTLISTENER_H +#define XMRIG_ICLIENTLISTENER_H #include -class Client; class Job; class SubmitResult; +namespace xmrig { + + +class Client; + + class IClientListener { public: - virtual ~IClientListener() {} + virtual ~IClientListener() = default; virtual void onClose(Client *client, int failures) = 0; virtual void onJobReceived(Client *client, const Job &job) = 0; @@ -45,4 +51,7 @@ public: }; -#endif // __ICLIENTLISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_ICLIENTLISTENER_H diff --git a/src/common/interfaces/IStrategy.h b/src/common/interfaces/IStrategy.h index b3ac7f9cb..1e9c19bc4 100644 --- a/src/common/interfaces/IStrategy.h +++ b/src/common/interfaces/IStrategy.h @@ -33,23 +33,27 @@ class JobResult; namespace xmrig { - class Algorithm; -} + + +class Algorithm; class IStrategy { public: - virtual ~IStrategy() {} + virtual ~IStrategy() = default; virtual bool isActive() const = 0; virtual int64_t submit(const JobResult &result) = 0; virtual void connect() = 0; virtual void resume() = 0; - virtual void setAlgo(const xmrig::Algorithm &algo) = 0; + virtual void setAlgo(const Algorithm &algo) = 0; virtual void stop() = 0; virtual void tick(uint64_t now) = 0; }; +} /* namespace xmrig */ + + #endif // XMRIG_ISTRATEGY_H diff --git a/src/common/interfaces/IStrategyListener.h b/src/common/interfaces/IStrategyListener.h index 9f2c4487a..cbec7742e 100644 --- a/src/common/interfaces/IStrategyListener.h +++ b/src/common/interfaces/IStrategyListener.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,13 +22,16 @@ * along with this program. If not, see . */ -#ifndef __ISTRATEGYLISTENER_H__ -#define __ISTRATEGYLISTENER_H__ +#ifndef XMRIG_ISTRATEGYLISTENER_H +#define XMRIG_ISTRATEGYLISTENER_H #include +namespace xmrig { + + class Client; class IStrategy; class Job; @@ -37,7 +41,7 @@ class SubmitResult; class IStrategyListener { public: - virtual ~IStrategyListener() {} + virtual ~IStrategyListener() = default; virtual void onActive(IStrategy *strategy, Client *client) = 0; virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0; @@ -46,4 +50,7 @@ public: }; -#endif // __ISTRATEGYLISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_ISTRATEGYLISTENER_H diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index 36ddba31b..d846175df 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -51,8 +52,12 @@ #endif +namespace xmrig { + int64_t Client::m_sequence = 1; -xmrig::Storage Client::m_storage; +Storage Client::m_storage; + +} /* namespace xmrig */ #ifdef APP_DEBUG @@ -66,7 +71,7 @@ static const char *states[] = { #endif -Client::Client(int id, const char *agent, IClientListener *listener) : +xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : m_ipv6(false), m_nicehash(false), m_quiet(false), @@ -103,13 +108,13 @@ Client::Client(int id, const char *agent, IClientListener *listener) : } -Client::~Client() +xmrig::Client::~Client() { delete m_socket; } -void Client::connect() +void xmrig::Client::connect() { # ifndef XMRIG_NO_TLS if (m_pool.isTLS()) { @@ -126,14 +131,14 @@ void Client::connect() * * @param url */ -void Client::connect(const Pool &url) +void xmrig::Client::connect(const Pool &url) { setPool(url); connect(); } -void Client::deleteLater() +void xmrig::Client::deleteLater() { if (!m_listener) { return; @@ -148,7 +153,7 @@ void Client::deleteLater() -void Client::setPool(const Pool &pool) +void xmrig::Client::setPool(const Pool &pool) { if (!pool.isValid()) { return; @@ -158,7 +163,7 @@ void Client::setPool(const Pool &pool) } -void Client::tick(uint64_t now) +void xmrig::Client::tick(uint64_t now) { if (m_state == ConnectedState) { if (m_expire && now > m_expire) { @@ -176,7 +181,7 @@ void Client::tick(uint64_t now) } -bool Client::disconnect() +bool xmrig::Client::disconnect() { m_keepAlive = 0; m_expire = 0; @@ -186,7 +191,7 @@ bool Client::disconnect() } -const char *Client::tlsFingerprint() const +const char *xmrig::Client::tlsFingerprint() const { # ifndef XMRIG_NO_TLS if (isTLS() && m_pool.fingerprint() == nullptr) { @@ -198,7 +203,7 @@ const char *Client::tlsFingerprint() const } -const char *Client::tlsVersion() const +const char *xmrig::Client::tlsVersion() const { # ifndef XMRIG_NO_TLS if (isTLS()) { @@ -210,7 +215,7 @@ const char *Client::tlsVersion() const } -int64_t Client::submit(const JobResult &result) +int64_t xmrig::Client::submit(const JobResult &result) { # ifndef XMRIG_PROXY_PROJECT if (result.clientId != m_rpcId) { @@ -218,7 +223,7 @@ int64_t Client::submit(const JobResult &result) } # endif - if (m_job.algorithm().variant() == xmrig::VARIANT_WOW && m_job.id() != result.jobId) { + if (m_job.algorithm().variant() == VARIANT_WOW && m_job.id() != result.jobId) { return -1; } @@ -267,7 +272,7 @@ int64_t Client::submit(const JobResult &result) } -bool Client::close() +bool xmrig::Client::close() { if (m_state == ClosingState) { return m_socket != nullptr; @@ -287,7 +292,7 @@ bool Client::close() } -bool Client::isCriticalError(const char *message) +bool xmrig::Client::isCriticalError(const char *message) { if (!message) { return false; @@ -309,7 +314,7 @@ bool Client::isCriticalError(const char *message) } -bool Client::isTLS() const +bool xmrig::Client::isTLS() const { # ifndef XMRIG_NO_TLS return m_pool.isTLS() && m_tls; @@ -319,7 +324,7 @@ bool Client::isTLS() const } -bool Client::parseJob(const rapidjson::Value ¶ms, int *code) +bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code) { if (!params.IsObject()) { *code = 2; @@ -394,7 +399,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code) } -bool Client::parseLogin(const rapidjson::Value &result, int *code) +bool xmrig::Client::parseLogin(const rapidjson::Value &result, int *code) { if (!m_rpcId.setId(result["id"].GetString())) { *code = 1; @@ -414,7 +419,7 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code) } -bool Client::send(BIO *bio) +bool xmrig::Client::send(BIO *bio) { # ifndef XMRIG_NO_TLS uv_buf_t buf; @@ -447,10 +452,10 @@ bool Client::send(BIO *bio) } -bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const +bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm) const { # ifdef XMRIG_PROXY_PROJECT - if (m_pool.algorithm().variant() == xmrig::VARIANT_AUTO || m_id == -1) { + if (m_pool.algorithm().variant() == VARIANT_AUTO || m_id == -1) { return true; } # endif @@ -474,7 +479,7 @@ bool Client::verifyAlgorithm(const xmrig::Algorithm &algorithm) const } -int Client::resolve(const char *host) +int xmrig::Client::resolve(const char *host) { setState(HostLookupState); @@ -497,7 +502,7 @@ int Client::resolve(const char *host) } -int64_t Client::send(const rapidjson::Document &doc) +int64_t xmrig::Client::send(const rapidjson::Document &doc) { using namespace rapidjson; @@ -520,7 +525,7 @@ int64_t Client::send(const rapidjson::Document &doc) } -int64_t Client::send(size_t size) +int64_t xmrig::Client::send(size_t size) { LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_pool.url(), size, m_sendBuf); @@ -551,7 +556,7 @@ int64_t Client::send(size_t size) } -void Client::connect(const std::vector &ipv4, const std::vector &ipv6) +void xmrig::Client::connect(const std::vector &ipv4, const std::vector &ipv6) { addrinfo *addr = nullptr; m_ipv6 = ipv4.empty() && !ipv6.empty(); @@ -569,7 +574,7 @@ void Client::connect(const std::vector &ipv4, const std::vectordata); if (!client) { @@ -903,7 +908,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t } -void Client::onClose(uv_handle_t *handle) +void xmrig::Client::onClose(uv_handle_t *handle) { auto client = getClient(handle->data); if (!client) { @@ -914,7 +919,7 @@ void Client::onClose(uv_handle_t *handle) } -void Client::onConnect(uv_connect_t *req, int status) +void xmrig::Client::onConnect(uv_connect_t *req, int status) { auto client = getClient(req->data); if (!client) { @@ -943,7 +948,7 @@ void Client::onConnect(uv_connect_t *req, int status) } -void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) +void xmrig::Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { auto client = getClient(stream->data); if (!client) { @@ -986,7 +991,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) } -void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) +void xmrig::Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res) { auto client = getClient(req->data); if (!client) { diff --git a/src/common/net/Client.h b/src/common/net/Client.h index 4594a90fa..9314739a2 100644 --- a/src/common/net/Client.h +++ b/src/common/net/Client.h @@ -5,6 +5,7 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -39,13 +40,16 @@ #include "rapidjson/fwd.h" +typedef struct bio_st BIO; + + +namespace xmrig { + + class IClientListener; class JobResult; -typedef struct bio_st BIO; - - class Client { public: @@ -85,7 +89,7 @@ public: inline int id() const { return m_id; } inline SocketState state() const { return m_state; } inline uint16_t port() const { return m_pool.port(); } - inline void setAlgo(const xmrig::Algorithm &algo) { m_pool.setAlgo(algo); } + inline void setAlgo(const Algorithm &algo) { m_pool.setAlgo(algo); } inline void setQuiet(bool quiet) { m_quiet = quiet; } inline void setRetries(int retries) { m_retries = retries; } inline void setRetryPause(int ms) { m_retryPause = ms; } @@ -105,7 +109,7 @@ private: bool parseJob(const rapidjson::Value ¶ms, int *code); bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); - bool verifyAlgorithm(const xmrig::Algorithm &algorithm) const; + bool verifyAlgorithm(const Algorithm &algorithm) const; int resolve(const char *host); int64_t send(const rapidjson::Document &doc); int64_t send(size_t size); @@ -162,11 +166,14 @@ private: uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; - xmrig::Id m_rpcId; + Id m_rpcId; static int64_t m_sequence; - static xmrig::Storage m_storage; + static Storage m_storage; }; +} /* namespace xmrig */ + + #endif /* XMRIG_CLIENT_H */ diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index ee76f732b..2bca5af62 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -58,7 +58,7 @@ char hf_bin2hex(unsigned char c) } -Job::Job() : +xmrig::Job::Job() : m_autoVariant(false), m_nicehash(false), m_poolId(-2), @@ -72,8 +72,8 @@ Job::Job() : } -Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId) : - m_autoVariant(algorithm.variant() == xmrig::VARIANT_AUTO), +xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId) : + m_autoVariant(algorithm.variant() == VARIANT_AUTO), m_nicehash(nicehash), m_poolId(poolId), m_threadId(-1), @@ -88,18 +88,18 @@ Job::Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmr } -Job::~Job() +xmrig::Job::~Job() { } -bool Job::isEqual(const Job &other) const +bool xmrig::Job::isEqual(const Job &other) const { return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0; } -bool Job::setBlob(const char *blob) +bool xmrig::Job::setBlob(const char *blob) { if (!blob) { return false; @@ -128,14 +128,14 @@ bool Job::setBlob(const char *blob) } if (!m_algorithm.isForced()) { - if (m_algorithm.variant() == xmrig::VARIANT_XTL && m_blob[0] >= 9) { - m_algorithm.setVariant(xmrig::VARIANT_HALF); + if (m_algorithm.variant() == VARIANT_XTL && m_blob[0] >= 9) { + m_algorithm.setVariant(VARIANT_HALF); } - else if (m_algorithm.variant() == xmrig::VARIANT_MSR && m_blob[0] >= 8) { - m_algorithm.setVariant(xmrig::VARIANT_HALF); + else if (m_algorithm.variant() == VARIANT_MSR && m_blob[0] >= 8) { + m_algorithm.setVariant(VARIANT_HALF); } - else if (m_algorithm.variant() == xmrig::VARIANT_WOW && m_blob[0] < 11) { - m_algorithm.setVariant(xmrig::VARIANT_2); + else if (m_algorithm.variant() == VARIANT_WOW && m_blob[0] < 11) { + m_algorithm.setVariant(VARIANT_2); } } @@ -148,7 +148,7 @@ bool Job::setBlob(const char *blob) } -bool Job::setTarget(const char *target) +bool xmrig::Job::setTarget(const char *target) { if (!target) { return false; @@ -190,7 +190,7 @@ bool Job::setTarget(const char *target) } -void Job::setAlgorithm(const char *algo) +void xmrig::Job::setAlgorithm(const char *algo) { m_algorithm.parseAlgorithm(algo); @@ -200,13 +200,13 @@ void Job::setAlgorithm(const char *algo) } -void Job::setHeight(uint64_t height) +void xmrig::Job::setHeight(uint64_t height) { m_height = height; } -bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) +bool xmrig::Job::fromHex(const char* in, unsigned int len, unsigned char* out) { bool error = false; for (unsigned int i = 0; i < len; i += 2) { @@ -220,7 +220,7 @@ bool Job::fromHex(const char* in, unsigned int len, unsigned char* out) } -void Job::toHex(const unsigned char* in, unsigned int len, char* out) +void xmrig::Job::toHex(const unsigned char* in, unsigned int len, char* out) { for (unsigned int i = 0; i < len; i++) { out[i * 2] = hf_bin2hex((in[i] & 0xF0) >> 4); @@ -230,7 +230,7 @@ void Job::toHex(const unsigned char* in, unsigned int len, char* out) #ifdef APP_DEBUG -char *Job::toHex(const unsigned char* in, unsigned int len) +char *xmrig::Job::toHex(const unsigned char* in, unsigned int len) { char *out = new char[len * 2 + 1](); toHex(in, len, out); @@ -240,10 +240,8 @@ char *Job::toHex(const unsigned char* in, unsigned int len) #endif -xmrig::Variant Job::variant() const +xmrig::Variant xmrig::Job::variant() const { - using namespace xmrig; - switch (m_algorithm.algo()) { case CRYPTONIGHT: return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1; diff --git a/src/common/net/Job.h b/src/common/net/Job.h index 4fdac3ada..49ddc7da3 100644 --- a/src/common/net/Job.h +++ b/src/common/net/Job.h @@ -35,6 +35,9 @@ #include "common/net/Id.h" +namespace xmrig { + + class Job { public: @@ -43,7 +46,7 @@ public: static constexpr const size_t kMaxBlobSize = 128; Job(); - Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId); + Job(int poolId, bool nicehash, const Algorithm &algorithm, const Id &clientId); ~Job(); bool isEqual(const Job &other) const; @@ -57,9 +60,9 @@ public: inline bool setId(const char *id) { return m_id.setId(id); } inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } - inline const xmrig::Algorithm &algorithm() const { return m_algorithm; } - inline const xmrig::Id &clientId() const { return m_clientId; } - inline const xmrig::Id &id() const { return m_id; } + inline const Algorithm &algorithm() const { return m_algorithm; } + inline const Id &clientId() const { return m_clientId; } + inline const Id &id() const { return m_id; } inline int poolId() const { return m_poolId; } inline int threadId() const { return m_threadId; } inline size_t size() const { return m_size; } @@ -68,7 +71,7 @@ public: inline uint64_t target() const { return m_target; } inline uint64_t height() const { return m_height; } inline void reset() { m_size = 0; m_diff = 0; } - inline void setClientId(const xmrig::Id &id) { m_clientId = id; } + inline void setClientId(const Id &id) { m_clientId = id; } inline void setPoolId(int poolId) { m_poolId = poolId; } inline void setThreadId(int threadId) { m_threadId = threadId; } inline void setVariant(const char *variant) { m_algorithm.parseVariant(variant); } @@ -92,7 +95,7 @@ public: inline bool operator!=(const Job &other) const { return !isEqual(other); } private: - xmrig::Variant variant() const; + Variant variant() const; bool m_autoVariant; bool m_nicehash; @@ -113,4 +116,8 @@ private: # endif }; + +} /* namespace xmrig */ + + #endif /* XMRIG_JOB_H */ diff --git a/src/common/net/SubmitResult.cpp b/src/common/net/SubmitResult.cpp index 251b2bf16..d14bbb408 100644 --- a/src/common/net/SubmitResult.cpp +++ b/src/common/net/SubmitResult.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,7 +29,7 @@ #include "common/net/SubmitResult.h" -SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : +xmrig::SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : reqId(reqId), seq(seq), diff(diff), @@ -39,7 +40,7 @@ SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int6 } -void SubmitResult::done() +void xmrig::SubmitResult::done() { elapsed = (uv_hrtime() - start) / 1000000; } diff --git a/src/common/net/SubmitResult.h b/src/common/net/SubmitResult.h index e812cbf8a..db97ac38a 100644 --- a/src/common/net/SubmitResult.h +++ b/src/common/net/SubmitResult.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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,13 +22,16 @@ * along with this program. If not, see . */ -#ifndef __SUBMITRESULT_H__ -#define __SUBMITRESULT_H__ +#ifndef XMRIG_SUBMITRESULT_H +#define XMRIG_SUBMITRESULT_H #include +namespace xmrig { + + class SubmitResult { public: @@ -46,4 +50,8 @@ private: uint64_t start; }; -#endif /* __SUBMITRESULT_H__ */ + +} /* namespace xmrig */ + + +#endif /* XMRIG_SUBMITRESULT_H */ diff --git a/src/common/net/Tls.cpp b/src/common/net/Tls.cpp index 182d86ff5..a9b3fa7de 100644 --- a/src/common/net/Tls.cpp +++ b/src/common/net/Tls.cpp @@ -6,8 +6,8 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ #endif -Client::Tls::Tls(Client *client) : +xmrig::Client::Tls::Tls(Client *client) : m_ready(false), m_buf(), m_fingerprint(), @@ -57,7 +57,7 @@ Client::Tls::Tls(Client *client) : } -Client::Tls::~Tls() +xmrig::Client::Tls::~Tls() { if (m_ctx) { SSL_CTX_free(m_ctx); @@ -69,7 +69,7 @@ Client::Tls::~Tls() } -bool Client::Tls::handshake() +bool xmrig::Client::Tls::handshake() { m_ssl = SSL_new(m_ctx); assert(m_ssl != nullptr); @@ -86,7 +86,7 @@ bool Client::Tls::handshake() } -bool Client::Tls::send(const char *data, size_t size) +bool xmrig::Client::Tls::send(const char *data, size_t size) { SSL_write(m_ssl, data, size); @@ -94,19 +94,19 @@ bool Client::Tls::send(const char *data, size_t size) } -const char *Client::Tls::fingerprint() const +const char *xmrig::Client::Tls::fingerprint() const { return m_ready ? m_fingerprint : nullptr; } -const char *Client::Tls::version() const +const char *xmrig::Client::Tls::version() const { return m_ready ? SSL_get_version(m_ssl) : nullptr; } -void Client::Tls::read(const char *data, size_t size) +void xmrig::Client::Tls::read(const char *data, size_t size) { BIO_write(m_readBio, data, size); @@ -139,13 +139,13 @@ void Client::Tls::read(const char *data, size_t size) } -bool Client::Tls::send() +bool xmrig::Client::Tls::send() { return m_client->send(m_writeBio); } -bool Client::Tls::verify(X509 *cert) +bool xmrig::Client::Tls::verify(X509 *cert) { if (cert == nullptr) { LOG_ERR("[%s] Failed to get server certificate", m_client->m_pool.url()); @@ -169,7 +169,7 @@ bool Client::Tls::verify(X509 *cert) } -bool Client::Tls::verifyFingerprint(X509 *cert) +bool xmrig::Client::Tls::verifyFingerprint(X509 *cert) { const EVP_MD *digest = EVP_get_digestbyname("sha256"); if (digest == nullptr) { diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h index 083adfc45..937d255c2 100644 --- a/src/common/net/Tls.h +++ b/src/common/net/Tls.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,7 +32,7 @@ #include "common/net/Client.h" -class Client::Tls +class xmrig::Client::Tls { public: Tls(Client *client); diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index 3be3687d6..95883f701 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -29,7 +29,7 @@ #include "common/Platform.h" -FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : +xmrig::FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_quiet(quiet), m_retries(retries), m_retryPause(retryPause), @@ -43,7 +43,7 @@ FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause } -FailoverStrategy::~FailoverStrategy() +xmrig::FailoverStrategy::~FailoverStrategy() { for (Client *client : m_pools) { client->deleteLater(); @@ -51,7 +51,7 @@ FailoverStrategy::~FailoverStrategy() } -int64_t FailoverStrategy::submit(const JobResult &result) +int64_t xmrig::FailoverStrategy::submit(const JobResult &result) { if (m_active == -1) { return -1; @@ -61,13 +61,13 @@ int64_t FailoverStrategy::submit(const JobResult &result) } -void FailoverStrategy::connect() +void xmrig::FailoverStrategy::connect() { m_pools[m_index]->connect(); } -void FailoverStrategy::resume() +void xmrig::FailoverStrategy::resume() { if (!isActive()) { return; @@ -77,7 +77,7 @@ void FailoverStrategy::resume() } -void FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) +void xmrig::FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) { for (Client *client : m_pools) { client->setAlgo(algo); @@ -85,7 +85,7 @@ void FailoverStrategy::setAlgo(const xmrig::Algorithm &algo) } -void FailoverStrategy::stop() +void xmrig::FailoverStrategy::stop() { for (size_t i = 0; i < m_pools.size(); ++i) { m_pools[i]->disconnect(); @@ -98,7 +98,7 @@ void FailoverStrategy::stop() } -void FailoverStrategy::tick(uint64_t now) +void xmrig::FailoverStrategy::tick(uint64_t now) { for (Client *client : m_pools) { client->tick(now); @@ -106,7 +106,7 @@ void FailoverStrategy::tick(uint64_t now) } -void FailoverStrategy::onClose(Client *client, int failures) +void xmrig::FailoverStrategy::onClose(Client *client, int failures) { if (failures == -1) { return; @@ -127,7 +127,7 @@ void FailoverStrategy::onClose(Client *client, int failures) } -void FailoverStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job) { if (m_active == client->id()) { m_listener->onJob(this, client, job); @@ -135,7 +135,7 @@ void FailoverStrategy::onJobReceived(Client *client, const Job &job) } -void FailoverStrategy::onLoginSuccess(Client *client) +void xmrig::FailoverStrategy::onLoginSuccess(Client *client) { int active = m_active; @@ -156,13 +156,13 @@ void FailoverStrategy::onLoginSuccess(Client *client) } -void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) +void xmrig::FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } -void FailoverStrategy::add(const Pool &pool) +void xmrig::FailoverStrategy::add(const Pool &pool) { Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this); client->setPool(pool); diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index cfc8e92ae..0bff0e0ab 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -34,9 +34,11 @@ #include "common/interfaces/IStrategy.h" +namespace xmrig { + + class Client; class IStrategyListener; -class Url; class FailoverStrategy : public IStrategy, public IClientListener @@ -51,7 +53,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void resume() override; - void setAlgo(const xmrig::Algorithm &algo) override; + void setAlgo(const Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -73,4 +75,7 @@ private: std::vector m_pools; }; + +} /* namespace xmrig */ + #endif /* XMRIG_FAILOVERSTRATEGY_H */ diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index 354bf6d6a..f0a51a493 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -29,7 +29,7 @@ #include "common/Platform.h" -SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : +xmrig::SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_active(false), m_listener(listener) { @@ -41,25 +41,25 @@ SinglePoolStrategy::SinglePoolStrategy(const Pool &pool, int retryPause, int ret } -SinglePoolStrategy::~SinglePoolStrategy() +xmrig::SinglePoolStrategy::~SinglePoolStrategy() { m_client->deleteLater(); } -int64_t SinglePoolStrategy::submit(const JobResult &result) +int64_t xmrig::SinglePoolStrategy::submit(const JobResult &result) { return m_client->submit(result); } -void SinglePoolStrategy::connect() +void xmrig::SinglePoolStrategy::connect() { m_client->connect(); } -void SinglePoolStrategy::resume() +void xmrig::SinglePoolStrategy::resume() { if (!isActive()) { return; @@ -69,25 +69,25 @@ void SinglePoolStrategy::resume() } -void SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo) +void xmrig::SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo) { m_client->setAlgo(algo); } -void SinglePoolStrategy::stop() +void xmrig::SinglePoolStrategy::stop() { m_client->disconnect(); } -void SinglePoolStrategy::tick(uint64_t now) +void xmrig::SinglePoolStrategy::tick(uint64_t now) { m_client->tick(now); } -void SinglePoolStrategy::onClose(Client *client, int failures) +void xmrig::SinglePoolStrategy::onClose(Client *client, int failures) { if (!isActive()) { return; @@ -98,20 +98,20 @@ void SinglePoolStrategy::onClose(Client *client, int failures) } -void SinglePoolStrategy::onJobReceived(Client *client, const Job &job) +void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job) { m_listener->onJob(this, client, job); } -void SinglePoolStrategy::onLoginSuccess(Client *client) +void xmrig::SinglePoolStrategy::onLoginSuccess(Client *client) { m_active = true; m_listener->onActive(this, client); } -void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) +void xmrig::SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } diff --git a/src/common/net/strategies/SinglePoolStrategy.h b/src/common/net/strategies/SinglePoolStrategy.h index f258d9cd3..eeb6903e8 100644 --- a/src/common/net/strategies/SinglePoolStrategy.h +++ b/src/common/net/strategies/SinglePoolStrategy.h @@ -30,6 +30,9 @@ #include "common/interfaces/IStrategy.h" +namespace xmrig { + + class Client; class IStrategyListener; class Pool; @@ -47,7 +50,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void resume() override; - void setAlgo(const xmrig::Algorithm &algo) override; + void setAlgo(const Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -63,4 +66,8 @@ private: IStrategyListener *m_listener; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_SINGLEPOOLSTRATEGY_H */ diff --git a/src/core/Config.cpp b/src/core/Config.cpp index f54f092b7..f3487b15b 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -292,6 +292,8 @@ bool xmrig::Config::parseUint64(int key, uint64_t arg) void xmrig::Config::parseJSON(const rapidjson::Document &doc) { + CommonConfig::parseJSON(doc); + const rapidjson::Value &threads = doc["threads"]; if (threads.IsArray()) { diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index abe6d46d9..766ddbab6 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -62,8 +62,8 @@ public: Network *network; Process *process; - std::vector listeners; - xmrig::Config *config; + std::vector listeners; + Config *config; }; @@ -127,7 +127,7 @@ int xmrig::Controller::init() } -Network *xmrig::Controller::network() const +xmrig::Network *xmrig::Controller::network() const { assert(d_ptr->network != nullptr); diff --git a/src/core/Controller.h b/src/core/Controller.h index 89a462f9c..8d2f26745 100644 --- a/src/core/Controller.h +++ b/src/core/Controller.h @@ -29,7 +29,6 @@ #include "base/kernel/interfaces/IConfigListener.h" -class Network; class StatsData; @@ -39,6 +38,7 @@ namespace xmrig { class Config; class ControllerPrivate; class IControllerListener; +class Network; class Process; @@ -62,6 +62,8 @@ private: ControllerPrivate *d_ptr; }; + } /* namespace xmrig */ + #endif /* XMRIG_CONTROLLER_H */ diff --git a/src/interfaces/IJobResultListener.h b/src/interfaces/IJobResultListener.h index 483a2062d..e99db502a 100644 --- a/src/interfaces/IJobResultListener.h +++ b/src/interfaces/IJobResultListener.h @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +22,11 @@ * along with this program. If not, see . */ -#ifndef __IJOBRESULTLISTENER_H__ -#define __IJOBRESULTLISTENER_H__ +#ifndef XMRIG_IJOBRESULTLISTENER_H +#define XMRIG_IJOBRESULTLISTENER_H + + +namespace xmrig { class Client; @@ -32,10 +36,13 @@ class JobResult; class IJobResultListener { public: - virtual ~IJobResultListener() {} + virtual ~IJobResultListener() = default; virtual void onJobResult(const JobResult &result) = 0; }; -#endif // __IJOBRESULTLISTENER_H__ +} /* namespace xmrig */ + + +#endif // XMRIG_IJOBRESULTLISTENER_H diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 071cbb8b1..5ab4d2942 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -5,7 +5,9 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018 Lee Clagett + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,17 +34,20 @@ #include "common/net/Job.h" +namespace xmrig { + + class JobResult { public: inline JobResult() : poolId(0), diff(0), nonce(0) {} - inline JobResult(int poolId, const xmrig::Id &jobId, const xmrig::Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) : - poolId(poolId), - diff(diff), - nonce(nonce), + inline JobResult(int poolId, const Id &jobId, const Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const Algorithm &algorithm) : algorithm(algorithm), clientId(clientId), - jobId(jobId) + jobId(jobId), + poolId(poolId), + diff(diff), + nonce(nonce) { memcpy(this->result, result, sizeof(this->result)); } @@ -65,13 +70,17 @@ public: } + Algorithm algorithm; + Id clientId; + Id jobId; int poolId; uint32_t diff; uint32_t nonce; uint8_t result[32]; - xmrig::Algorithm algorithm; - xmrig::Id clientId; - xmrig::Id jobId; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_JOBRESULT_H */ diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 08e96d1d6..78ace87c3 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -44,12 +44,10 @@ #include "workers/Workers.h" -Network::Network(xmrig::Controller *controller) : - m_donate(nullptr), - m_controller(controller) +xmrig::Network::Network(Controller *controller) : + m_controller(controller), + m_donate(nullptr) { - srand(time(0) ^ (uintptr_t) this); - Workers::setListener(this); const std::vector &pools = controller->config()->pools(); @@ -72,18 +70,18 @@ Network::Network(xmrig::Controller *controller) : } -Network::~Network() +xmrig::Network::~Network() { } -void Network::connect() +void xmrig::Network::connect() { m_strategy->connect(); } -void Network::stop() +void xmrig::Network::stop() { if (m_donate) { m_donate->stop(); @@ -93,7 +91,7 @@ void Network::stop() } -void Network::onActive(IStrategy *strategy, Client *client) +void xmrig::Network::onActive(IStrategy *strategy, Client *client) { if (m_donate && m_donate == strategy) { LOG_NOTICE("dev donate started"); @@ -114,7 +112,7 @@ void Network::onActive(IStrategy *strategy, Client *client) } -void Network::onJob(IStrategy *strategy, Client *client, const Job &job) +void xmrig::Network::onJob(IStrategy *strategy, Client *client, const Job &job) { if (m_donate && m_donate->isActive() && m_donate != strategy) { return; @@ -124,7 +122,7 @@ void Network::onJob(IStrategy *strategy, Client *client, const Job &job) } -void Network::onJobResult(const JobResult &result) +void xmrig::Network::onJobResult(const JobResult &result) { if (result.poolId == -1 && m_donate) { m_donate->submit(result); @@ -135,7 +133,7 @@ void Network::onJobResult(const JobResult &result) } -void Network::onPause(IStrategy *strategy) +void xmrig::Network::onPause(IStrategy *strategy) { if (m_donate && m_donate == strategy) { LOG_NOTICE("dev donate finished"); @@ -150,7 +148,7 @@ void Network::onPause(IStrategy *strategy) } -void Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) +void xmrig::Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) { m_state.add(result, error); @@ -167,13 +165,13 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit } -bool Network::isColors() const +bool xmrig::Network::isColors() const { return m_controller->config()->isColors(); } -void Network::setJob(Client *client, const Job &job, bool donate) +void xmrig::Network::setJob(Client *client, const Job &job, bool donate) { if (job.height()) { LOG_INFO(isColors() ? MAGENTA_BOLD("new job") " from " WHITE_BOLD("%s:%d") " diff " WHITE_BOLD("%d") " algo " WHITE_BOLD("%s") " height " WHITE_BOLD("%" PRIu64) @@ -195,7 +193,7 @@ void Network::setJob(Client *client, const Job &job, bool donate) } -void Network::tick() +void xmrig::Network::tick() { const uint64_t now = uv_now(uv_default_loop()); @@ -211,7 +209,7 @@ void Network::tick() } -void Network::onTick(uv_timer_t *handle) +void xmrig::Network::onTick(uv_timer_t *handle) { static_cast(handle->data)->tick(); } diff --git a/src/net/Network.h b/src/net/Network.h index aac4010bd..e9b073ae9 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -35,19 +35,17 @@ #include "interfaces/IJobResultListener.h" -class IStrategy; -class Url; - - namespace xmrig { - class Controller; -} + + +class Controller; +class IStrategy; class Network : public IJobResultListener, public IStrategyListener { public: - Network(xmrig::Controller *controller); + Network(Controller *controller); ~Network() override; void connect(); @@ -69,12 +67,15 @@ private: static void onTick(uv_timer_t *handle); + Controller *m_controller; IStrategy *m_donate; IStrategy *m_strategy; NetworkState m_state; uv_timer_t m_timer; - xmrig::Controller *m_controller; }; +} /* namespace xmrig */ + + #endif /* XMRIG_NETWORK_H */ diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 417a31fbf..9593dc9a8 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -39,7 +39,7 @@ static inline float randomf(float min, float max) { } -DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener) : +xmrig::DonateStrategy::DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener) : m_active(false), m_donateTime(level * 60 * 1000), m_idleTime((100 - level) * 60 * 1000), @@ -51,7 +51,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS uint8_t hash[200]; char userId[65] = { 0 }; - xmrig::keccak(reinterpret_cast(user), strlen(user), hash); + keccak(reinterpret_cast(user), strlen(user), hash); Job::toHex(hash, 32, userId); # ifndef XMRIG_NO_TLS @@ -61,7 +61,7 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS m_pools.push_back(Pool("donate.v2.xmrig.com", 3333, userId, nullptr, false, true)); for (Pool &pool : m_pools) { - pool.adjust(xmrig::Algorithm(algo, xmrig::VARIANT_AUTO)); + pool.adjust(Algorithm(algo, VARIANT_AUTO)); } if (m_pools.size() > 1) { @@ -78,38 +78,38 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS } -DonateStrategy::~DonateStrategy() +xmrig::DonateStrategy::~DonateStrategy() { delete m_strategy; } -int64_t DonateStrategy::submit(const JobResult &result) +int64_t xmrig::DonateStrategy::submit(const JobResult &result) { return m_strategy->submit(result); } -void DonateStrategy::connect() +void xmrig::DonateStrategy::connect() { m_strategy->connect(); } -void DonateStrategy::setAlgo(const xmrig::Algorithm &algo) +void xmrig::DonateStrategy::setAlgo(const xmrig::Algorithm &algo) { m_strategy->setAlgo(algo); } -void DonateStrategy::stop() +void xmrig::DonateStrategy::stop() { uv_timer_stop(&m_timer); m_strategy->stop(); } -void DonateStrategy::tick(uint64_t now) +void xmrig::DonateStrategy::tick(uint64_t now) { m_now = now; @@ -122,7 +122,7 @@ void DonateStrategy::tick(uint64_t now) } -void DonateStrategy::onActive(IStrategy *strategy, Client *client) +void xmrig::DonateStrategy::onActive(IStrategy *strategy, Client *client) { if (!isActive()) { uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0); @@ -133,7 +133,7 @@ void DonateStrategy::onActive(IStrategy *strategy, Client *client) } -void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) +void xmrig::DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) { if (isActive()) { m_listener->onJob(this, client, job); @@ -141,24 +141,24 @@ void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) } -void DonateStrategy::onPause(IStrategy *strategy) +void xmrig::DonateStrategy::onPause(IStrategy *strategy) { } -void DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) +void xmrig::DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) { m_listener->onResultAccepted(this, client, result, error); } -void DonateStrategy::idle(uint64_t timeout) +void xmrig::DonateStrategy::idle(uint64_t timeout) { uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0); } -void DonateStrategy::suspend() +void xmrig::DonateStrategy::suspend() { # if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT) m_stop = m_now + 5000; @@ -173,7 +173,7 @@ void DonateStrategy::suspend() } -void DonateStrategy::onTimer(uv_timer_t *handle) +void xmrig::DonateStrategy::onTimer(uv_timer_t *handle) { auto strategy = static_cast(handle->data); diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index eab01370e..76702ef32 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -36,15 +36,17 @@ #include "common/interfaces/IStrategyListener.h" +namespace xmrig { + + class Client; class IStrategyListener; -class Url; class DonateStrategy : public IStrategy, public IStrategyListener { public: - DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); + DonateStrategy(int level, const char *user, Algo algo, IStrategyListener *listener); ~DonateStrategy() override; public: @@ -53,7 +55,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; - void setAlgo(const xmrig::Algorithm &algo) override; + void setAlgo(const Algorithm &algo) override; void stop() override; void tick(uint64_t now) override; @@ -80,4 +82,8 @@ private: uv_timer_t m_timer; }; + +} /* namespace xmrig */ + + #endif /* XMRIG_DONATESTRATEGY_H */ diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 2a6153d5b..1b166d0dc 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -6,7 +6,7 @@ * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , * Copyright 2018 Lee Clagett - * Copyright 2018 SChernykh + * Copyright 2018-2019 SChernykh * Copyright 2016-2019 XMRig , * * This program is free software: you can redistribute it and/or modify @@ -132,7 +132,7 @@ void MultiWorker::start() for (size_t i = 0; i < N; ++i) { if (*reinterpret_cast(m_hash + (i * 32) + 24) < m_state.job.target()) { - Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); + Workers::submit(xmrig::JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); } *nonce(i) += 1; @@ -149,7 +149,7 @@ void MultiWorker::start() template -bool MultiWorker::resume(const Job &job) +bool MultiWorker::resume(const xmrig::Job &job) { if (m_state.job.poolId() == -1 && job.poolId() >= 0 && job.id() == m_pausedState.job.id()) { m_state = m_pausedState; @@ -237,7 +237,7 @@ bool MultiWorker::verify2(xmrig::Variant variant, const char *test_data) template void MultiWorker::consumeJob() { - Job job = Workers::job(); + xmrig::Job job = Workers::job(); m_sequence = Workers::sequence(); if (m_state.job == job) { return; @@ -272,7 +272,7 @@ void MultiWorker::consumeJob() template -void MultiWorker::save(const Job &job) +void MultiWorker::save(const xmrig::Job &job) { if (job.poolId() == -1 && m_state.job.poolId() >= 0) { m_pausedState = m_state; diff --git a/src/workers/MultiWorker.h b/src/workers/MultiWorker.h index 1db6a2bf2..8560b510a 100644 --- a/src/workers/MultiWorker.h +++ b/src/workers/MultiWorker.h @@ -48,11 +48,11 @@ protected: void start() override; private: - bool resume(const Job &job); + bool resume(const xmrig::Job &job); bool verify(xmrig::Variant variant, const uint8_t *referenceValue); bool verify2(xmrig::Variant variant, const char *test_data); void consumeJob(); - void save(const Job &job); + void save(const xmrig::Job &job); inline uint32_t *nonce(size_t index) { @@ -61,8 +61,8 @@ private: struct State { - alignas(16) uint8_t blob[Job::kMaxBlobSize * N]; - Job job; + alignas(16) uint8_t blob[xmrig::Job::kMaxBlobSize * N]; + xmrig::Job job; }; diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index f6a584544..f718a52c5 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -45,12 +45,12 @@ bool Workers::m_active = false; bool Workers::m_enabled = true; Hashrate *Workers::m_hashrate = nullptr; -IJobResultListener *Workers::m_listener = nullptr; -Job Workers::m_job; +xmrig::IJobResultListener *Workers::m_listener = nullptr; +xmrig::Job Workers::m_job; Workers::LaunchStatus Workers::m_status; std::atomic Workers::m_paused; std::atomic Workers::m_sequence; -std::list Workers::m_queue; +std::list Workers::m_queue; std::vector Workers::m_workers; uint64_t Workers::m_ticks = 0; uv_async_t Workers::m_async; @@ -60,10 +60,10 @@ uv_timer_t Workers::m_timer; xmrig::Controller *Workers::m_controller = nullptr; -Job Workers::job() +xmrig::Job Workers::job() { uv_rwlock_rdlock(&m_rwlock); - Job job = m_job; + xmrig::Job job = m_job; uv_rwlock_rdunlock(&m_rwlock); return job; @@ -139,7 +139,7 @@ void Workers::setEnabled(bool enabled) } -void Workers::setJob(const Job &job, bool donate) +void Workers::setJob(const xmrig::Job &job, bool donate) { uv_rwlock_wrlock(&m_rwlock); m_job = job; @@ -225,7 +225,7 @@ void Workers::stop() } -void Workers::submit(const JobResult &result) +void Workers::submit(const xmrig::JobResult &result) { uv_mutex_lock(&m_mutex); m_queue.push_back(result); @@ -300,7 +300,7 @@ void Workers::onReady(void *arg) void Workers::onResult(uv_async_t *handle) { - std::list results; + std::list results; uv_mutex_lock(&m_mutex); while (!m_queue.empty()) { diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 61868819f..a9b8e6958 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -38,35 +38,35 @@ class Handle; class Hashrate; -class IJobResultListener; class IWorker; namespace xmrig { class Controller; + class IJobResultListener; } class Workers { public: - static Job job(); + static xmrig::Job job(); static size_t hugePages(); static size_t threads(); static void printHashrate(bool detail); static void setEnabled(bool enabled); - static void setJob(const Job &job, bool donate); + static void setJob(const xmrig::Job &job, bool donate); static void start(xmrig::Controller *controller); static void stop(); - static void submit(const JobResult &result); + static void submit(const xmrig::JobResult &result); - static inline bool isEnabled() { return m_enabled; } - static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; } - static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; } - static inline Hashrate *hashrate() { return m_hashrate; } - static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); } - static inline void pause() { m_active = false; m_paused = 1; m_sequence++; } - static inline void setListener(IJobResultListener *listener) { m_listener = listener; } + static inline bool isEnabled() { return m_enabled; } + static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; } + static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; } + static inline Hashrate *hashrate() { return m_hashrate; } + static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); } + static inline void pause() { m_active = false; m_paused = 1; m_sequence++; } + static inline void setListener(xmrig::IJobResultListener *listener) { m_listener = listener; } # ifndef XMRIG_NO_API static void threadsSummary(rapidjson::Document &doc); @@ -103,12 +103,12 @@ private: static bool m_active; static bool m_enabled; static Hashrate *m_hashrate; - static IJobResultListener *m_listener; - static Job m_job; + static xmrig::IJobResultListener *m_listener; + static xmrig::Job m_job; static LaunchStatus m_status; static std::atomic m_paused; static std::atomic m_sequence; - static std::list m_queue; + static std::list m_queue; static std::vector m_workers; static uint64_t m_ticks; static uv_async_t m_async; From f6699b5929aa24f14a215632d5ee0334f5e02c16 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 08:53:37 +0700 Subject: [PATCH 09/22] [WIP] Use unified Pools class. --- src/base/net/Pool.cpp | 12 ++++ src/base/net/Pool.h | 1 + src/base/net/Pools.cpp | 53 ++++++++++++++- src/base/net/Pools.h | 20 +++++- src/common/config/CommonConfig.cpp | 106 ++++++----------------------- src/common/config/CommonConfig.h | 7 +- src/core/Config.cpp | 2 +- 7 files changed, 107 insertions(+), 94 deletions(-) diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index b81593b40..cacf3494f 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -155,6 +155,18 @@ bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const } +bool xmrig::Pool::isEnabled() const +{ +# ifdef XMRIG_NO_TLS + if (isTLS()) { + return false; + } +# endif + + return isValid() && algorithm().isValid(); +} + + bool xmrig::Pool::isEqual(const Pool &other) const { return (m_nicehash == other.m_nicehash diff --git a/src/base/net/Pool.h b/src/base/net/Pool.h index 06ccf2bc9..ec051277e 100644 --- a/src/base/net/Pool.h +++ b/src/base/net/Pool.h @@ -83,6 +83,7 @@ public: inline bool operator==(const Pool &other) const { return isEqual(other); } bool isCompatible(const Algorithm &algorithm) const; + bool isEnabled() const; bool isEqual(const Pool &other) const; bool parse(const char *url); bool setUserpass(const char *userpass); diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index 49a1607c3..6ebafdc35 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -26,7 +26,56 @@ #include "base/net/Pools.h" -xmrig::Pools::Pools() : - m_index(0) +xmrig::Pools::Pools() { } + + +xmrig::Pool &xmrig::Pools::current() +{ + if (m_data.empty()) { + m_data.push_back(Pool()); + } + + return m_data.back(); +} + + +bool xmrig::Pools::setUrl(const char *url) +{ + if (m_data.empty() || m_data.back().isValid()) { + Pool pool(url); + + if (pool.isValid()) { + m_data.push_back(pool); + return true; + } + + return false; + } + + current().parse(url); + + return m_data.back().isValid(); +} + + +size_t xmrig::Pools::active() const +{ + size_t count = 0; + for (const Pool &pool : m_data) { + if (pool.isEnabled()) { + count++; + } + } + + return count; +} + + +void xmrig::Pools::adjust(const Algorithm &algorithm) +{ + for (Pool &pool : m_data) { + pool.adjust(algorithm); + } +} diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index 1f8a8c771..d882a6b30 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -40,8 +40,26 @@ class Pools public: Pools(); + inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); } + inline const std::vector &data() const { return m_data; } + inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); } + inline void setKeepAlive(bool enable) { setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); } + inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); } + inline void setNicehash(bool enable) { current().setNicehash(enable); } + inline void setPassword(const char *password) { current().setPassword(password); } + inline void setRigId(const char *rigId) { current().setRigId(rigId); } + inline void setTLS(bool enable) { current().setTLS(enable); } + inline void setUser(const char *user) { current().setUser(user); } + inline void setVariant(const char *variant) { current().algorithm().parseVariant(variant); } + inline void setVariant(int variant) { current().algorithm().parseVariant(variant); } + + bool setUrl(const char *url); + size_t active() const; + void adjust(const Algorithm &algorithm); + private: - size_t m_index; + Pool ¤t(); + std::vector m_data; }; diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 604ab0890..10a7b03a1 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -82,8 +82,6 @@ xmrig::CommonConfig::CommonConfig() : m_retryPause(5), m_state(NoneState) { - m_pools.push_back(Pool()); - # ifdef XMRIG_PROXY_PROJECT m_retries = 2; m_retryPause = 1; @@ -107,21 +105,21 @@ void xmrig::CommonConfig::printAPI() void xmrig::CommonConfig::printPools() { - for (size_t i = 0; i < m_activePools.size(); ++i) { + for (size_t i = 0; i < m_pools.data().size(); ++i) { if (!isColors()) { Log::i()->text(" * POOL #%-7zu%s algo=%s, TLS=%d", i + 1, - m_activePools[i].url(), - m_activePools[i].algorithm().shortName(), - static_cast(m_activePools[i].isTLS()) + m_pools.data()[i].url(), + m_pools.data()[i].algorithm().shortName(), + static_cast(m_pools.data()[i].isTLS()) ); } else { Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"), i + 1, - m_activePools[i].isTLS() ? 32 : 36, - m_activePools[i].url(), - m_activePools[i].algorithm().shortName() + m_pools.data()[i].isTLS() ? 32 : 36, + m_pools.data()[i].url(), + m_pools.data()[i].algorithm().shortName() ); } } @@ -225,23 +223,9 @@ bool xmrig::CommonConfig::finalize() return false; } - for (Pool &pool : m_pools) { - pool.adjust(m_algorithm); + m_pools.adjust(m_algorithm); - if (pool.isValid() && pool.algorithm().isValid()) { -# ifdef XMRIG_NO_TLS - if (pool.isTLS()) { - continue; - } -# endif - - m_activePools.push_back(std::move(pool)); - } - } - - m_pools.clear(); - - if (m_activePools.empty()) { + if (!m_pools.active()) { m_state = ErrorState; return false; } @@ -263,16 +247,16 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) break; case KeepAliveKey: /* --keepalive */ - currentPool().setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); + m_pools.setKeepAlive(enable); break; case TlsKey: /* --tls */ - currentPool().setTLS(enable); + m_pools.setTLS(enable); break; # ifndef XMRIG_PROXY_PROJECT case NicehashKey: /* --nicehash */ - currentPool().setNicehash(enable); + m_pools.setNicehash(enable); break; # endif @@ -316,50 +300,29 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg) break; case UserpassKey: /* --userpass */ - if (!currentPool().setUserpass(arg)) { - return false; - } - - break; + return m_pools.setUserpass(arg); case UrlKey: /* --url */ - fixup(); - - if (m_pools.size() > 1 || m_pools[0].isValid()) { - Pool pool(arg); - - if (pool.isValid()) { - m_pools.push_back(std::move(pool)); - } - } - else { - m_pools[0].parse(arg); - } - - if (!m_pools.back().isValid()) { - return false; - } - - break; + return m_pools.setUrl(arg); case UserKey: /* --user */ - currentPool().setUser(arg); + m_pools.setUser(arg); break; case PasswordKey: /* --pass */ - currentPool().setPassword(arg); + m_pools.setPassword(arg); break; case RigIdKey: /* --rig-id */ - currentPool().setRigId(arg); + m_pools.setRigId(arg); break; case FingerprintKey: /* --tls-fingerprint */ - currentPool().setFingerprint(arg); + m_pools.setFingerprint(arg); break; case VariantKey: /* --variant */ - currentPool().algorithm().parseVariant(arg); + m_pools.setVariant(arg); break; case LogFileKey: /* --log-file */ @@ -453,11 +416,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) break; case KeepAliveKey: /* --keepalive */ - currentPool().setKeepAlive(arg); + m_pools.setKeepAlive(arg); break; case VariantKey: /* --variant */ - currentPool().algorithm().parseVariant(arg); + m_pools.setVariant(arg); break; case DonateLevelKey: /* --donate-level */ @@ -484,30 +447,3 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) return true; } - - -xmrig::Pool &xmrig::CommonConfig::currentPool() -{ - fixup(); - - return m_pools.back(); -} - - -void xmrig::CommonConfig::fixup() -{ - if (m_state == NoneState) { - return; - } - - if (m_pools.empty()) { - if (!m_activePools.empty()) { - std::swap(m_pools, m_activePools); - } - else { - m_pools.push_back(Pool()); - } - - m_state = NoneState; - } -} diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 6316a078b..9c6c32bb4 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -52,7 +52,7 @@ public: inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *logFile() const { return m_logFile.data(); } inline const char *userAgent() const { return m_userAgent.data(); } - inline const std::vector &pools() const { return m_activePools; } + inline const std::vector &pools() const { return m_pools.data(); } inline int apiPort() const { return m_apiPort; } inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } @@ -99,9 +99,8 @@ protected: int m_printTime; int m_retries; int m_retryPause; + Pools m_pools; State m_state; - std::vector m_activePools; - std::vector m_pools; String m_apiId; String m_apiToken; String m_apiWorkerId; @@ -111,8 +110,6 @@ protected: private: bool parseInt(int key, int arg); - Pool ¤tPool(); - void fixup(); }; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index f3487b15b..6ff195880 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -106,7 +106,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const Value pools(kArrayType); - for (const Pool &pool : m_activePools) { + for (const Pool &pool : m_pools.data()) { pools.PushBack(pool.toJSON(doc), allocator); } From ee4f6e28f030b4f98db3cefdf0b71f6e24554a71 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 10:51:32 +0700 Subject: [PATCH 10/22] * [WIP] More unification in Pools class. --- src/base/net/Pools.cpp | 78 ++++++++++++++++++++++++- src/base/net/Pools.h | 8 +++ src/common/config/CommonConfig.cpp | 50 ++++------------ src/common/config/CommonConfig.h | 10 +--- src/common/interfaces/IClientListener.h | 6 +- src/common/log/ConsoleLog.cpp | 2 +- src/common/log/Log.cpp | 8 ++- src/common/log/Log.h | 5 +- src/common/net/Tls.h | 8 ++- src/core/Config.cpp | 9 +-- 10 files changed, 118 insertions(+), 66 deletions(-) diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index 6ebafdc35..247e13d96 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -24,10 +24,18 @@ #include "base/net/Pools.h" +#include "common/log/Log.h" +#include "rapidjson/document.h" -xmrig::Pools::Pools() +xmrig::Pools::Pools() : + m_retries(5), + m_retryPause(5) { +# ifdef XMRIG_PROXY_PROJECT + m_retries = 2; + m_retryPause = 1; +# endif } @@ -60,6 +68,21 @@ bool xmrig::Pools::setUrl(const char *url) } +rapidjson::Value xmrig::Pools::toJSON(rapidjson::Document &doc) const +{ + using namespace rapidjson; + auto &allocator = doc.GetAllocator(); + + Value pools(kArrayType); + + for (const Pool &pool : m_data) { + pools.PushBack(pool.toJSON(doc), allocator); + } + + return pools; +} + + size_t xmrig::Pools::active() const { size_t count = 0; @@ -79,3 +102,56 @@ void xmrig::Pools::adjust(const Algorithm &algorithm) pool.adjust(algorithm); } } + + +void xmrig::Pools::print() +{ + size_t i = 1; + for (const Pool &pool : m_data) { + if (Log::colors) { + const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31; + + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"), + i, + color, + pool.url(), + pool.algorithm().shortName() + ); + } + else { + Log::i()->text(" * POOL #%-7zu%s%s algo=%s %s", + i, + pool.isEnabled() ? "" : "-", + pool.url(), + pool.algorithm().shortName(), + pool.isTLS() ? "TLS" : "" + ); + } + + i++; + } + +# ifdef APP_DEBUG + LOG_NOTICE("POOLS --------------------------------------------------------------------"); + for (const Pool &pool : m_data) { + pool.print(); + } + LOG_NOTICE("--------------------------------------------------------------------------"); +# endif +} + + +void xmrig::Pools::setRetries(int retries) +{ + if (retries > 0 && retries <= 1000) { + m_retries = retries; + } +} + + +void xmrig::Pools::setRetryPause(int retryPause) +{ + if (retryPause > 0 && retryPause <= 3600) { + m_retryPause = retryPause; + } +} diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index d882a6b30..0822af074 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -42,6 +42,8 @@ public: inline bool setUserpass(const char *userpass) { return current().setUserpass(userpass); } inline const std::vector &data() const { return m_data; } + inline int retries() const { return m_retries; } + inline int retryPause() const { return m_retryPause; } inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); } inline void setKeepAlive(bool enable) { setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); } inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); } @@ -54,12 +56,18 @@ public: inline void setVariant(int variant) { current().algorithm().parseVariant(variant); } bool setUrl(const char *url); + rapidjson::Value toJSON(rapidjson::Document &doc) const; size_t active() const; void adjust(const Algorithm &algorithm); + void print(); + void setRetries(int retries); + void setRetryPause(int retryPause); private: Pool ¤t(); + int m_retries; + int m_retryPause; std::vector m_data; }; diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 10a7b03a1..7acc58a0f 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -71,21 +71,20 @@ xmrig::CommonConfig::CommonConfig() : m_apiRestricted(true), m_autoSave(true), m_background(false), - m_colors(true), m_dryRun(false), m_syslog(false), m_watch(true), m_apiPort(0), m_donateLevel(kDefaultDonateLevel), m_printTime(60), - m_retries(5), - m_retryPause(5), m_state(NoneState) { -# ifdef XMRIG_PROXY_PROJECT - m_retries = 2; - m_retryPause = 1; -# endif +} + + +bool xmrig::CommonConfig::isColors() const +{ + return Log::colors; } @@ -105,32 +104,7 @@ void xmrig::CommonConfig::printAPI() void xmrig::CommonConfig::printPools() { - for (size_t i = 0; i < m_pools.data().size(); ++i) { - if (!isColors()) { - Log::i()->text(" * POOL #%-7zu%s algo=%s, TLS=%d", - i + 1, - m_pools.data()[i].url(), - m_pools.data()[i].algorithm().shortName(), - static_cast(m_pools.data()[i].isTLS()) - ); - } - else { - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"), - i + 1, - m_pools.data()[i].isTLS() ? 32 : 36, - m_pools.data()[i].url(), - m_pools.data()[i].algorithm().shortName() - ); - } - } - -# ifdef APP_DEBUG - LOG_NOTICE("POOLS --------------------------------------------------------------------"); - for (const Pool &pool : m_activePools) { - pool.print(); - } - LOG_NOTICE("--------------------------------------------------------------------------"); -# endif + m_pools.print(); } @@ -261,7 +235,7 @@ bool xmrig::CommonConfig::parseBoolean(int key, bool enable) # endif case ColorKey: /* --no-color */ - m_colors = enable; + Log::colors = enable; break; case WatchKey: /* watch */ @@ -404,15 +378,11 @@ bool xmrig::CommonConfig::parseInt(int key, int arg) { switch (key) { case RetriesKey: /* --retries */ - if (arg > 0 && arg <= 1000) { - m_retries = arg; - } + m_pools.setRetries(arg); break; case RetryPauseKey: /* --retry-pause */ - if (arg > 0 && arg <= 3600) { - m_retryPause = arg; - } + m_pools.setRetryPause(arg); break; case KeepAliveKey: /* --keepalive */ diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 9c6c32bb4..77d4b202b 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -44,7 +44,6 @@ public: inline bool isApiRestricted() const { return m_apiRestricted; } inline bool isAutoSave() const { return m_autoSave; } inline bool isBackground() const { return m_background; } - inline bool isColors() const { return m_colors; } inline bool isDryRun() const { return m_dryRun; } inline bool isSyslog() const { return m_syslog; } inline const char *apiId() const { return m_apiId.data(); } @@ -56,9 +55,8 @@ public: inline int apiPort() const { return m_apiPort; } inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } - inline int retries() const { return m_retries; } - inline int retryPause() const { return m_retryPause; } - inline void setColors(bool colors) { m_colors = colors; } + inline int retries() const { return m_pools.retries(); } + inline int retryPause() const { return m_pools.retryPause(); } inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const Algorithm &algorithm() const override { return m_algorithm; } @@ -66,6 +64,7 @@ public: bool save() override; + bool isColors() const; void printAPI(); void printPools(); void printVersions(); @@ -90,15 +89,12 @@ protected: bool m_apiRestricted; bool m_autoSave; bool m_background; - bool m_colors; bool m_dryRun; bool m_syslog; bool m_watch; int m_apiPort; int m_donateLevel; int m_printTime; - int m_retries; - int m_retryPause; Pools m_pools; State m_state; String m_apiId; diff --git a/src/common/interfaces/IClientListener.h b/src/common/interfaces/IClientListener.h index 029d140d6..70a3d1d0f 100644 --- a/src/common/interfaces/IClientListener.h +++ b/src/common/interfaces/IClientListener.h @@ -29,14 +29,12 @@ #include -class Job; -class SubmitResult; - - namespace xmrig { class Client; +class Job; +class SubmitResult; class IClientListener diff --git a/src/common/log/ConsoleLog.cpp b/src/common/log/ConsoleLog.cpp index 6cf61980b..b10812a6d 100644 --- a/src/common/log/ConsoleLog.cpp +++ b/src/common/log/ConsoleLog.cpp @@ -45,7 +45,7 @@ ConsoleLog::ConsoleLog(xmrig::Controller *controller) : m_controller(controller) { if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { - controller->config()->setColors(false); + Log::colors = false; return; } diff --git a/src/common/log/Log.cpp b/src/common/log/Log.cpp index 2af902099..07e4f2998 100644 --- a/src/common/log/Log.cpp +++ b/src/common/log/Log.cpp @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -35,9 +36,10 @@ Log *Log::m_self = nullptr; +bool Log::colors = true; -static const char *colors[5] = { +static const char *color[5] = { "\x1B[0;31m", /* ERR */ "\x1B[0;33m", /* WARNING */ "\x1B[1;37m", /* NOTICE */ @@ -96,7 +98,7 @@ const char *Log::colorByLevel(ILogBackend::Level level, bool isColors) return ""; } - return colors[level]; + return color[level]; } diff --git a/src/common/log/Log.h b/src/common/log/Log.h index aa03a7435..c32edddd4 100644 --- a/src/common/log/Log.h +++ b/src/common/log/Log.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 @@ -48,6 +49,8 @@ public: static const char *endl(bool isColors = true); static void defaultInit(); + static bool colors; + private: inline Log() { assert(m_self == nullptr); diff --git a/src/common/net/Tls.h b/src/common/net/Tls.h index 937d255c2..cce78eeb4 100644 --- a/src/common/net/Tls.h +++ b/src/common/net/Tls.h @@ -32,7 +32,10 @@ #include "common/net/Client.h" -class xmrig::Client::Tls +namespace xmrig { + + +class Client::Tls { public: Tls(Client *client); @@ -60,4 +63,7 @@ private: }; +} /* namespace xmrig */ + + #endif /* XMRIG_CLIENT_TLS_H */ diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 6ff195880..b477c1e53 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -103,14 +103,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("hw-aes", m_aesMode == AES_AUTO ? Value(kNullType) : Value(m_aesMode == AES_HW), allocator); doc.AddMember("log-file", logFile() ? Value(StringRef(logFile())).Move() : Value(kNullType).Move(), allocator); doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator); - - Value pools(kArrayType); - - for (const Pool &pool : m_pools.data()) { - pools.PushBack(pool.toJSON(doc), allocator); - } - - doc.AddMember("pools", pools, allocator); + doc.AddMember("pools", m_pools.toJSON(doc), allocator); doc.AddMember("print-time", printTime(), allocator); doc.AddMember("retries", retries(), allocator); doc.AddMember("retry-pause", retryPause(), allocator); From 3a0fdcac6f8fab850739b1e2d5985e6808c21440 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 11:25:25 +0700 Subject: [PATCH 11/22] Create network strategies in Pools class. --- src/base/net/Pools.cpp | 23 +++++++++ src/base/net/Pools.h | 5 ++ src/common/config/CommonConfig.h | 4 +- .../net/strategies/FailoverStrategy.cpp | 51 +++++++++++-------- src/common/net/strategies/FailoverStrategy.h | 7 ++- .../net/strategies/SinglePoolStrategy.cpp | 2 +- src/core/Config.cpp | 4 +- src/net/Network.cpp | 14 ++--- 8 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index 247e13d96..9d4e6db46 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -25,6 +25,8 @@ #include "base/net/Pools.h" #include "common/log/Log.h" +#include "common/net/strategies/FailoverStrategy.h" +#include "common/net/strategies/SinglePoolStrategy.h" #include "rapidjson/document.h" @@ -68,6 +70,27 @@ bool xmrig::Pools::setUrl(const char *url) } +xmrig::IStrategy *xmrig::Pools::createStrategy(IStrategyListener *listener) const +{ + if (active() == 1) { + for (const Pool &pool : m_data) { + if (pool.isEnabled()) { + return new SinglePoolStrategy(pool, retryPause(), retries(), listener); + } + } + } + + FailoverStrategy *strategy = new FailoverStrategy(retryPause(), retries(), listener); + for (const Pool &pool : m_data) { + if (pool.isEnabled()) { + strategy->add(pool); + } + } + + return strategy; +} + + rapidjson::Value xmrig::Pools::toJSON(rapidjson::Document &doc) const { using namespace rapidjson; diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index 0822af074..d0755aac7 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -35,6 +35,10 @@ namespace xmrig { +class IStrategy; +class IStrategyListener; + + class Pools { public: @@ -56,6 +60,7 @@ public: inline void setVariant(int variant) { current().algorithm().parseVariant(variant); } bool setUrl(const char *url); + IStrategy *createStrategy(IStrategyListener *listener) const; rapidjson::Value toJSON(rapidjson::Document &doc) const; size_t active() const; void adjust(const Algorithm &algorithm); diff --git a/src/common/config/CommonConfig.h b/src/common/config/CommonConfig.h index 77d4b202b..103e69d24 100644 --- a/src/common/config/CommonConfig.h +++ b/src/common/config/CommonConfig.h @@ -51,12 +51,10 @@ public: inline const char *apiWorkerId() const { return m_apiWorkerId.data(); } inline const char *logFile() const { return m_logFile.data(); } inline const char *userAgent() const { return m_userAgent.data(); } - inline const std::vector &pools() const { return m_pools.data(); } + inline const Pools &pools() const { return m_pools; } inline int apiPort() const { return m_apiPort; } inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } - inline int retries() const { return m_pools.retries(); } - inline int retryPause() const { return m_pools.retryPause(); } inline bool isWatch() const override { return m_watch && !m_fileName.isNull(); } inline const Algorithm &algorithm() const override { return m_algorithm; } diff --git a/src/common/net/strategies/FailoverStrategy.cpp b/src/common/net/strategies/FailoverStrategy.cpp index 95883f701..c833f6e6e 100644 --- a/src/common/net/strategies/FailoverStrategy.cpp +++ b/src/common/net/strategies/FailoverStrategy.cpp @@ -29,7 +29,7 @@ #include "common/Platform.h" -xmrig::FailoverStrategy::FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) : +xmrig::FailoverStrategy::FailoverStrategy(const std::vector &pools, int retryPause, int retries, IStrategyListener *listener, bool quiet) : m_quiet(quiet), m_retries(retries), m_retryPause(retryPause), @@ -37,12 +37,23 @@ xmrig::FailoverStrategy::FailoverStrategy(const std::vector &urls, int ret m_index(0), m_listener(listener) { - for (const Pool &url : urls) { - add(url); + for (const Pool &pool : pools) { + add(pool); } } +xmrig::FailoverStrategy::FailoverStrategy(int retryPause, int retries, IStrategyListener *listener, bool quiet) : + m_quiet(quiet), + m_retries(retries), + m_retryPause(retryPause), + m_active(-1), + m_index(0), + m_listener(listener) +{ +} + + xmrig::FailoverStrategy::~FailoverStrategy() { for (Client *client : m_pools) { @@ -51,19 +62,31 @@ xmrig::FailoverStrategy::~FailoverStrategy() } +void xmrig::FailoverStrategy::add(const Pool &pool) +{ + Client *client = new Client(static_cast(m_pools.size()), Platform::userAgent(), this); + client->setPool(pool); + client->setRetries(m_retries); + client->setRetryPause(m_retryPause * 1000); + client->setQuiet(m_quiet); + + m_pools.push_back(client); +} + + int64_t xmrig::FailoverStrategy::submit(const JobResult &result) { if (m_active == -1) { return -1; } - return m_pools[m_active]->submit(result); + return active()->submit(result); } void xmrig::FailoverStrategy::connect() { - m_pools[m_index]->connect(); + m_pools[static_cast(m_index)]->connect(); } @@ -73,7 +96,7 @@ void xmrig::FailoverStrategy::resume() return; } - m_listener->onJob(this, m_pools[m_active], m_pools[m_active]->job()); + m_listener->onJob(this, active(), active()->job()); } @@ -121,8 +144,8 @@ void xmrig::FailoverStrategy::onClose(Client *client, int failures) return; } - if (m_index == client->id() && (m_pools.size() - m_index) > 1) { - m_pools[++m_index]->connect(); + if (m_index == client->id() && (m_pools.size() - static_cast(m_index)) > 1) { + m_pools[static_cast(++m_index)]->connect(); } } @@ -160,15 +183,3 @@ void xmrig::FailoverStrategy::onResultAccepted(Client *client, const SubmitResul { m_listener->onResultAccepted(this, client, result, error); } - - -void xmrig::FailoverStrategy::add(const Pool &pool) -{ - Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this); - client->setPool(pool); - client->setRetries(m_retries); - client->setRetryPause(m_retryPause * 1000); - client->setQuiet(m_quiet); - - m_pools.push_back(client); -} diff --git a/src/common/net/strategies/FailoverStrategy.h b/src/common/net/strategies/FailoverStrategy.h index 0bff0e0ab..d2231a30b 100644 --- a/src/common/net/strategies/FailoverStrategy.h +++ b/src/common/net/strategies/FailoverStrategy.h @@ -44,9 +44,12 @@ class IStrategyListener; class FailoverStrategy : public IStrategy, public IClientListener { public: - FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); + FailoverStrategy(const std::vector &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); + FailoverStrategy(int retryPause, int retries, IStrategyListener *listener, bool quiet = false); ~FailoverStrategy() override; + void add(const Pool &pool); + public: inline bool isActive() const override { return m_active >= 0; } @@ -64,7 +67,7 @@ protected: void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; private: - void add(const Pool &pool); + inline Client *active() const { return m_pools[static_cast(m_active)]; } const bool m_quiet; const int m_retries; diff --git a/src/common/net/strategies/SinglePoolStrategy.cpp b/src/common/net/strategies/SinglePoolStrategy.cpp index f0a51a493..d17a43da1 100644 --- a/src/common/net/strategies/SinglePoolStrategy.cpp +++ b/src/common/net/strategies/SinglePoolStrategy.cpp @@ -87,7 +87,7 @@ void xmrig::SinglePoolStrategy::tick(uint64_t now) } -void xmrig::SinglePoolStrategy::onClose(Client *client, int failures) +void xmrig::SinglePoolStrategy::onClose(Client *, int) { if (!isActive()) { return; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index b477c1e53..82a961178 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -105,8 +105,8 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const doc.AddMember("max-cpu-usage", m_maxCpuUsage, allocator); doc.AddMember("pools", m_pools.toJSON(doc), allocator); doc.AddMember("print-time", printTime(), allocator); - doc.AddMember("retries", retries(), allocator); - doc.AddMember("retry-pause", retryPause(), allocator); + doc.AddMember("retries", m_pools.retries(), allocator); + doc.AddMember("retry-pause", m_pools.retryPause(), allocator); doc.AddMember("safe", m_safe, allocator); if (threadsMode() != Simple) { diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 78ace87c3..7be630fa3 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -34,8 +34,6 @@ #include "api/Api.h" #include "common/log/Log.h" #include "common/net/Client.h" -#include "common/net/strategies/FailoverStrategy.h" -#include "common/net/strategies/SinglePoolStrategy.h" #include "common/net/SubmitResult.h" #include "core/Config.h" #include "core/Controller.h" @@ -50,17 +48,11 @@ xmrig::Network::Network(Controller *controller) : { Workers::setListener(this); - const std::vector &pools = controller->config()->pools(); - - if (pools.size() > 1) { - m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this); - } - else { - m_strategy = new SinglePoolStrategy(pools.front(), controller->config()->retryPause(), controller->config()->retries(), this); - } + const Pools &pools = controller->config()->pools(); + m_strategy = pools.createStrategy(this); if (controller->config()->donateLevel() > 0) { - m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front().user(), controller->config()->algorithm().algo(), this); + m_donate = new DonateStrategy(controller->config()->donateLevel(), pools.data().front().user(), controller->config()->algorithm().algo(), this); } m_timer.data = this; From bdff4064a295b47b3c98858f29645a76c3af6969 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 15:43:55 +0700 Subject: [PATCH 12/22] Create pools directly from JSON objects. --- src/base/io/Json.cpp | 11 +++++ src/base/io/Json.h | 1 + src/base/net/Pool.cpp | 66 +++++++++++++++++------------- src/base/net/Pool.h | 1 + src/base/net/Pools.cpp | 19 ++++++++- src/base/net/Pools.h | 3 +- src/common/config/CommonConfig.cpp | 5 ++- src/common/config/ConfigLoader.cpp | 13 ------ src/net/Network.cpp | 4 +- 9 files changed, 76 insertions(+), 47 deletions(-) diff --git a/src/base/io/Json.cpp b/src/base/io/Json.cpp index 13a0d7e3d..ee5211d8c 100644 --- a/src/base/io/Json.cpp +++ b/src/base/io/Json.cpp @@ -36,3 +36,14 @@ bool xmrig::Json::getBool(const rapidjson::Value &obj, const char *key, bool def return defaultValue; } + + +const char *xmrig::Json::getString(const rapidjson::Value &obj, const char *key, const char *defaultValue) +{ + auto i = obj.FindMember(key); + if (i != obj.MemberEnd() && i->value.IsString()) { + return i->value.GetString(); + } + + return defaultValue; +} diff --git a/src/base/io/Json.h b/src/base/io/Json.h index 54f927583..c6cde0d82 100644 --- a/src/base/io/Json.h +++ b/src/base/io/Json.h @@ -36,6 +36,7 @@ class Json { public: static bool getBool(const rapidjson::Value &obj, const char *key, bool defaultValue = false); + static const char *getString(const rapidjson::Value &obj, const char *key, const char *defaultValue = nullptr); static bool get(const char *fileName, rapidjson::Document &doc); static bool save(const char *fileName, const rapidjson::Document &doc); diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index cacf3494f..850d23fa2 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -29,6 +29,7 @@ #include +#include "base/io/Json.h" #include "base/net/Pool.h" #include "rapidjson/document.h" @@ -44,6 +45,17 @@ #endif +static const char *kTls = "tls"; +static const char *kUrl = "url"; +static const char *kUser = "user"; +static const char *kPass = "pass"; +static const char *kRigId = "rig-id"; +static const char *kNicehash = "nicehash"; +static const char *kKeepalive = "keepalive"; +static const char *kVariant = "variant"; +static const char *kFingerprint = "tls-fingerprint"; + + xmrig::Pool::Pool() : m_nicehash(false), m_tls(false), @@ -80,24 +92,24 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : m_keepAlive(0), m_port(kDefaultPort) { - if (!parse(object["url"].GetString())) { + if (!parse(Json::getString(object, kUrl))) { return; } - setUser(object["user"].GetString()); - setPassword(object["pass"].GetString()); - setRigId(object["rig-id"].GetString()); - setNicehash(object["nicehash"].GetBool()); + setUser(Json::getString(object, kUser)); + setPassword(Json::getString(object, kPass)); + setRigId(Json::getString(object, kRigId)); + setNicehash(Json::getBool(object, kNicehash)); - const rapidjson::Value &keepalive = object["keepalive"]; + const rapidjson::Value &keepalive = object[kKeepalive]; if (keepalive.IsInt()) { setKeepAlive(keepalive.GetInt()); } else if (keepalive.IsBool()) { - setKeepAlive(keepalive.IsTrue() ? kKeepAliveTimeout : 0); + setKeepAlive(keepalive.GetBool()); } - const rapidjson::Value &variant = object["variant"]; + const rapidjson::Value &variant = object[kVariant]; if (variant.IsString()) { algorithm().parseVariant(variant.GetString()); } @@ -105,12 +117,8 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : algorithm().parseVariant(variant.GetInt()); } - const rapidjson::Value &tls = object["tls"]; - if (tls.IsBool()) { - m_tls = tls.IsTrue(); - } - - m_fingerprint = object["tls-fingerprint"].GetString(); + m_tls = Json::getBool(object, kTls); + m_fingerprint = Json::getString(object, kFingerprint); } @@ -219,7 +227,7 @@ bool xmrig::Pool::parse(const char *url) return true; } - const size_t size = port++ - base + 1; + const size_t size = static_cast(port++ - base + 1); char *host = new char[size](); memcpy(host, base, size - 1); @@ -238,7 +246,7 @@ bool xmrig::Pool::setUserpass(const char *userpass) } char *user = new char[p - userpass + 1](); - strncpy(user, userpass, p - userpass); + strncpy(user, userpass, static_cast(p - userpass)); m_user = user; m_password = p + 1; @@ -255,40 +263,40 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const Value obj(kObjectType); - obj.AddMember("url", m_url.toJSON(), allocator); - obj.AddMember("user", m_user.toJSON(), allocator); - obj.AddMember("pass", m_password.toJSON(), allocator); - obj.AddMember("rig-id", m_rigId.toJSON(), allocator); + obj.AddMember(StringRef(kUrl), m_url.toJSON(), allocator); + obj.AddMember(StringRef(kUser), m_user.toJSON(), allocator); + obj.AddMember(StringRef(kPass), m_password.toJSON(), allocator); + obj.AddMember(StringRef(kRigId), m_rigId.toJSON(), allocator); # ifndef XMRIG_PROXY_PROJECT - obj.AddMember("nicehash", isNicehash(), allocator); + obj.AddMember(StringRef(kNicehash), isNicehash(), allocator); # endif if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) { - obj.AddMember("keepalive", m_keepAlive > 0, allocator); + obj.AddMember(StringRef(kKeepalive), m_keepAlive > 0, allocator); } else { - obj.AddMember("keepalive", m_keepAlive, allocator); + obj.AddMember(StringRef(kKeepalive), m_keepAlive, allocator); } switch (m_algorithm.variant()) { case VARIANT_AUTO: case VARIANT_0: case VARIANT_1: - obj.AddMember("variant", m_algorithm.variant(), allocator); + obj.AddMember(StringRef(kVariant), m_algorithm.variant(), allocator); break; case VARIANT_2: - obj.AddMember("variant", 2, allocator); + obj.AddMember(StringRef(kVariant), 2, allocator); break; default: - obj.AddMember("variant", StringRef(m_algorithm.variantName()), allocator); + obj.AddMember(StringRef(kVariant), StringRef(m_algorithm.variantName()), allocator); break; } - obj.AddMember("tls", isTLS(), allocator); - obj.AddMember("tls-fingerprint", m_fingerprint.toJSON(), allocator); + obj.AddMember(StringRef(kTls), isTLS(), allocator); + obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator); return obj; } @@ -345,7 +353,7 @@ bool xmrig::Pool::parseIPv6(const char *addr) return false; } - const size_t size = end - addr; + const size_t size = static_cast(end - addr); char *host = new char[size](); memcpy(host, addr + 1, size - 1); diff --git a/src/base/net/Pool.h b/src/base/net/Pool.h index ec051277e..3d25e7082 100644 --- a/src/base/net/Pool.h +++ b/src/base/net/Pool.h @@ -72,6 +72,7 @@ public: inline uint16_t port() const { return m_port; } inline void setFingerprint(const char *fingerprint) { m_fingerprint = fingerprint; } inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; } + inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } inline void setPassword(const char *password) { m_password = password; } inline void setRigId(const char *rigId) { m_rigId = rigId; } diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index 9d4e6db46..c21cfe214 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -57,7 +57,7 @@ bool xmrig::Pools::setUrl(const char *url) Pool pool(url); if (pool.isValid()) { - m_data.push_back(pool); + m_data.push_back(std::move(pool)); return true; } @@ -127,6 +127,23 @@ void xmrig::Pools::adjust(const Algorithm &algorithm) } +void xmrig::Pools::load(const rapidjson::Value &pools) +{ + m_data.clear(); + + for (const rapidjson::Value &value : pools.GetArray()) { + if (!value.IsObject()) { + continue; + } + + Pool pool(value); + if (pool.isValid()) { + m_data.push_back(std::move(pool)); + } + } +} + + void xmrig::Pools::print() { size_t i = 1; diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index d0755aac7..8657b7750 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -49,7 +49,7 @@ public: inline int retries() const { return m_retries; } inline int retryPause() const { return m_retryPause; } inline void setFingerprint(const char *fingerprint) { current().setFingerprint(fingerprint); } - inline void setKeepAlive(bool enable) { setKeepAlive(enable ? Pool::kKeepAliveTimeout : 0); } + inline void setKeepAlive(bool enable) { current().setKeepAlive(enable); } inline void setKeepAlive(int keepAlive) { current().setKeepAlive(keepAlive); } inline void setNicehash(bool enable) { current().setNicehash(enable); } inline void setPassword(const char *password) { current().setPassword(password); } @@ -64,6 +64,7 @@ public: rapidjson::Value toJSON(rapidjson::Document &doc) const; size_t active() const; void adjust(const Algorithm &algorithm); + void load(const rapidjson::Value &pools); void print(); void setRetries(int retries); void setRetryPause(int retryPause); diff --git a/src/common/config/CommonConfig.cpp b/src/common/config/CommonConfig.cpp index 7acc58a0f..36d156a31 100644 --- a/src/common/config/CommonConfig.cpp +++ b/src/common/config/CommonConfig.cpp @@ -364,7 +364,10 @@ bool xmrig::CommonConfig::parseUint64(int key, uint64_t arg) void xmrig::CommonConfig::parseJSON(const rapidjson::Document &doc) { - + const rapidjson::Value &pools = doc["pools"]; + if (pools.IsArray()) { + m_pools.load(pools); + } } diff --git a/src/common/config/ConfigLoader.cpp b/src/common/config/ConfigLoader.cpp index e5eeb2b9f..fd46e7916 100644 --- a/src/common/config/ConfigLoader.cpp +++ b/src/common/config/ConfigLoader.cpp @@ -96,19 +96,6 @@ bool xmrig::ConfigLoader::loadFromJSON(xmrig::IConfig *config, const rapidjson:: parseJSON(config, &config_options[i], doc); } - const rapidjson::Value &pools = doc["pools"]; - if (pools.IsArray()) { - for (const rapidjson::Value &value : pools.GetArray()) { - if (!value.IsObject()) { - continue; - } - - for (size_t i = 0; i < ARRAY_SIZE(pool_options); i++) { - parseJSON(config, &pool_options[i], value); - } - } - } - const rapidjson::Value &api = doc["api"]; if (api.IsObject()) { for (size_t i = 0; i < ARRAY_SIZE(api_options); i++) { diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 7be630fa3..e2df21f79 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -140,7 +140,7 @@ void xmrig::Network::onPause(IStrategy *strategy) } -void xmrig::Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) +void xmrig::Network::onResultAccepted(IStrategy *, Client *, const SubmitResult &result, const char *error) { m_state.add(result, error); @@ -159,7 +159,7 @@ void xmrig::Network::onResultAccepted(IStrategy *strategy, Client *client, const bool xmrig::Network::isColors() const { - return m_controller->config()->isColors(); + return Log::colors; } From 7c789a0d3c01523795bec3b7c42aa7f800483b39 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 15:55:05 +0700 Subject: [PATCH 13/22] Added "enabled" field to pools. --- src/base/net/Pool.cpp | 19 +++++++++++++------ src/base/net/Pool.h | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index 850d23fa2..e3bdeaa9d 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -45,18 +45,20 @@ #endif +static const char *kEnabled = "enabled"; +static const char *kFingerprint = "tls-fingerprint"; +static const char *kKeepalive = "keepalive"; +static const char *kNicehash = "nicehash"; +static const char *kPass = "pass"; +static const char *kRigId = "rig-id"; static const char *kTls = "tls"; static const char *kUrl = "url"; static const char *kUser = "user"; -static const char *kPass = "pass"; -static const char *kRigId = "rig-id"; -static const char *kNicehash = "nicehash"; -static const char *kKeepalive = "keepalive"; static const char *kVariant = "variant"; -static const char *kFingerprint = "tls-fingerprint"; xmrig::Pool::Pool() : + m_enabled(true), m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -77,6 +79,7 @@ xmrig::Pool::Pool() : * @param url */ xmrig::Pool::Pool(const char *url) : + m_enabled(true), m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -87,6 +90,7 @@ xmrig::Pool::Pool(const char *url) : xmrig::Pool::Pool(const rapidjson::Value &object) : + m_enabled(true), m_nicehash(false), m_tls(false), m_keepAlive(0), @@ -117,6 +121,7 @@ xmrig::Pool::Pool(const rapidjson::Value &object) : algorithm().parseVariant(variant.GetInt()); } + m_enabled = Json::getBool(object, kEnabled, true); m_tls = Json::getBool(object, kTls); m_fingerprint = Json::getString(object, kFingerprint); } @@ -171,13 +176,14 @@ bool xmrig::Pool::isEnabled() const } # endif - return isValid() && algorithm().isValid(); + return m_enabled && isValid() && algorithm().isValid(); } bool xmrig::Pool::isEqual(const Pool &other) const { return (m_nicehash == other.m_nicehash + && m_enabled == other.m_enabled && m_tls == other.m_tls && m_keepAlive == other.m_keepAlive && m_port == other.m_port @@ -295,6 +301,7 @@ rapidjson::Value xmrig::Pool::toJSON(rapidjson::Document &doc) const break; } + obj.AddMember(StringRef(kEnabled), m_enabled, allocator); obj.AddMember(StringRef(kTls), isTLS(), allocator); obj.AddMember(StringRef(kFingerprint), m_fingerprint.toJSON(), allocator); diff --git a/src/base/net/Pool.h b/src/base/net/Pool.h index 3d25e7082..a16cc15b9 100644 --- a/src/base/net/Pool.h +++ b/src/base/net/Pool.h @@ -104,6 +104,7 @@ private: Algorithm m_algorithm; Algorithms m_algorithms; + bool m_enabled; bool m_nicehash; bool m_tls; int m_keepAlive; From 9c088eabc21e66f8dd64bab0e72c7b6da674b3a2 Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 17 Feb 2019 19:29:33 +0700 Subject: [PATCH 14/22] Implemented dynamic pool reload. --- src/base/net/Pools.cpp | 12 +++++- src/base/net/Pools.h | 6 ++- src/common/interfaces/IControllerListener.h | 5 ++- src/net/Network.cpp | 18 +++++++++ src/net/Network.h | 42 +++++++++++---------- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index c21cfe214..1513541bc 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -51,6 +51,16 @@ xmrig::Pool &xmrig::Pools::current() } +bool xmrig::Pools::isEqual(const Pools &other) const +{ + if (m_data.size() != other.m_data.size() || m_retries != other.m_retries || m_retryPause != other.m_retryPause) { + return false; + } + + return std::equal(m_data.begin(), m_data.end(), other.m_data.begin()); +} + + bool xmrig::Pools::setUrl(const char *url) { if (m_data.empty() || m_data.back().isValid()) { @@ -144,7 +154,7 @@ void xmrig::Pools::load(const rapidjson::Value &pools) } -void xmrig::Pools::print() +void xmrig::Pools::print() const { size_t i = 1; for (const Pool &pool : m_data) { diff --git a/src/base/net/Pools.h b/src/base/net/Pools.h index 8657b7750..a6038a044 100644 --- a/src/base/net/Pools.h +++ b/src/base/net/Pools.h @@ -59,13 +59,17 @@ public: inline void setVariant(const char *variant) { current().algorithm().parseVariant(variant); } inline void setVariant(int variant) { current().algorithm().parseVariant(variant); } + inline bool operator!=(const Pools &other) const { return !isEqual(other); } + inline bool operator==(const Pools &other) const { return isEqual(other); } + + bool isEqual(const Pools &other) const; bool setUrl(const char *url); IStrategy *createStrategy(IStrategyListener *listener) const; rapidjson::Value toJSON(rapidjson::Document &doc) const; size_t active() const; void adjust(const Algorithm &algorithm); void load(const rapidjson::Value &pools); - void print(); + void print() const; void setRetries(int retries); void setRetryPause(int retryPause); diff --git a/src/common/interfaces/IControllerListener.h b/src/common/interfaces/IControllerListener.h index 35249bcde..c61574083 100644 --- a/src/common/interfaces/IControllerListener.h +++ b/src/common/interfaces/IControllerListener.h @@ -5,7 +5,8 @@ * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee * Copyright 2017-2018 XMR-Stak , - * Copyright 2016-2018 XMRig , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 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 +35,7 @@ class Config; class IControllerListener { public: - virtual ~IControllerListener() {} + virtual ~IControllerListener() = default; virtual void onConfigChanged(Config *config, Config *previousConfig) = 0; }; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index e2df21f79..a7177571d 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -47,6 +47,7 @@ xmrig::Network::Network(Controller *controller) : m_donate(nullptr) { Workers::setListener(this); + controller->addListener(this); const Pools &pools = controller->config()->pools(); m_strategy = pools.createStrategy(this); @@ -64,6 +65,7 @@ xmrig::Network::Network(Controller *controller) : xmrig::Network::~Network() { + delete m_strategy; } @@ -104,6 +106,22 @@ void xmrig::Network::onActive(IStrategy *strategy, Client *client) } +void xmrig::Network::onConfigChanged(Config *config, Config *previousConfig) +{ + if (config->pools() == previousConfig->pools() || !config->pools().active()) { + return; + } + + m_strategy->stop(); + + config->pools().print(); + + delete m_strategy; + m_strategy = config->pools().createStrategy(this); + connect(); +} + + void xmrig::Network::onJob(IStrategy *strategy, Client *client, const Job &job) { if (m_donate && m_donate->isActive() && m_donate != strategy) { diff --git a/src/net/Network.h b/src/net/Network.h index e9b073ae9..b11d6998e 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -31,6 +31,7 @@ #include "api/NetworkState.h" +#include "common/interfaces/IControllerListener.h" #include "common/interfaces/IStrategyListener.h" #include "interfaces/IJobResultListener.h" @@ -42,36 +43,37 @@ class Controller; class IStrategy; -class Network : public IJobResultListener, public IStrategyListener +class Network : public IJobResultListener, public IStrategyListener, public IControllerListener { public: - Network(Controller *controller); - ~Network() override; + Network(Controller *controller); + ~Network() override; - void connect(); - void stop(); + void connect(); + void stop(); protected: - void onActive(IStrategy *strategy, Client *client) override; - void onJob(IStrategy *strategy, Client *client, const Job &job) override; - void onJobResult(const JobResult &result) override; - void onPause(IStrategy *strategy) override; - void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; + void onActive(IStrategy *strategy, Client *client) override; + void onConfigChanged(Config *config, Config *previousConfig) override; + void onJob(IStrategy *strategy, Client *client, const Job &job) override; + void onJobResult(const JobResult &result) override; + void onPause(IStrategy *strategy) override; + void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; private: - constexpr static int kTickInterval = 1 * 1000; + constexpr static int kTickInterval = 1 * 1000; - bool isColors() const; - void setJob(Client *client, const Job &job, bool donate); - void tick(); + bool isColors() const; + void setJob(Client *client, const Job &job, bool donate); + void tick(); - static void onTick(uv_timer_t *handle); + static void onTick(uv_timer_t *handle); - Controller *m_controller; - IStrategy *m_donate; - IStrategy *m_strategy; - NetworkState m_state; - uv_timer_t m_timer; + Controller *m_controller; + IStrategy *m_donate; + IStrategy *m_strategy; + NetworkState m_state; + uv_timer_t m_timer; }; From 764767d3172bf23017a15554e0b9f2d1ae612e00 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 17 Feb 2019 18:17:14 +0100 Subject: [PATCH 15/22] Support for Cryptonight variant 4 (Monero) --- src/Mem.cpp | 6 +- src/common/crypto/Algorithm.cpp | 2 + src/common/net/Job.cpp | 2 +- src/common/net/Pool.cpp | 1 + src/common/xmrig.h | 1 + src/crypto/CryptoNight.h | 11 +- src/crypto/CryptoNight_arm.h | 40 +- src/crypto/CryptoNight_constants.h | 6 + src/crypto/CryptoNight_monero.h | 20 +- src/crypto/CryptoNight_test.h | 17 +- src/crypto/CryptoNight_x86.h | 112 +++- src/crypto/CryptonightR_gen.cpp | 32 +- src/crypto/asm/CryptonightR_template.S | 25 +- src/crypto/asm/CryptonightR_template.asm | 25 +- src/crypto/asm/CryptonightR_template.h | 13 + src/crypto/asm/CryptonightR_template.inc | 117 +++-- src/crypto/asm/CryptonightR_template_win.inc | 117 +++-- src/crypto/asm/CryptonightWOW_template.inc | 486 ++++++++++++++++++ .../asm/CryptonightWOW_template_win.inc | 486 ++++++++++++++++++ src/crypto/asm/win64/CryptonightR_template.S | 24 +- .../asm/win64/CryptonightR_template.asm | 24 +- .../asm/win64/CryptonightR_template.inc | 117 +++-- .../asm/win64/CryptonightR_template_win.inc | 117 +++-- .../asm/win64/CryptonightWOW_template.inc | 486 ++++++++++++++++++ .../asm/win64/CryptonightWOW_template_win.inc | 486 ++++++++++++++++++ src/crypto/variant4_random_math.h | 68 ++- src/workers/CpuThread.cpp | 18 + src/workers/MultiWorker.cpp | 4 + 28 files changed, 2610 insertions(+), 253 deletions(-) create mode 100644 src/crypto/asm/CryptonightWOW_template.inc create mode 100644 src/crypto/asm/CryptonightWOW_template_win.inc create mode 100644 src/crypto/asm/win64/CryptonightWOW_template.inc create mode 100644 src/crypto/asm/win64/CryptonightWOW_template_win.inc diff --git a/src/Mem.cpp b/src/Mem.cpp index 1aa2f0180..4fa794d65 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -54,8 +54,10 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) uint8_t* p = reinterpret_cast(allocateExecutableMemory(0x4000)); c->generated_code = reinterpret_cast(p); c->generated_code_double = reinterpret_cast(p + 0x2000); - c->generated_code_height = (uint64_t)(-1); - c->generated_code_double_height = (uint64_t)(-1); + + c->generated_code_data.variant = xmrig::VARIANT_MAX; + c->generated_code_data.height = (uint64_t)(-1); + c->generated_code_double_data = c->generated_code_data; ctx[i] = c; } diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 0d360a408..8437555d9 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -65,6 +65,7 @@ static AlgoData const algorithms[] = { { "cryptonight/half", "cn/half", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/wow", "cn/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_WOW }, + { "cryptonight/4", "cn/4", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -130,6 +131,7 @@ static const char *variants[] = { "trtl", "gpu", "wow", + "4", }; diff --git a/src/common/net/Job.cpp b/src/common/net/Job.cpp index ee76f732b..2f6d9f8ed 100644 --- a/src/common/net/Job.cpp +++ b/src/common/net/Job.cpp @@ -246,7 +246,7 @@ xmrig::Variant Job::variant() const switch (m_algorithm.algo()) { case CRYPTONIGHT: - return (m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1; + return (m_blob[0] >= 10) ? VARIANT_4 : ((m_blob[0] >= 8) ? VARIANT_2 : VARIANT_1); case CRYPTONIGHT_LITE: return VARIANT_1; diff --git a/src/common/net/Pool.cpp b/src/common/net/Pool.cpp index 585e45966..0df7b8457 100644 --- a/src/common/net/Pool.cpp +++ b/src/common/net/Pool.cpp @@ -412,6 +412,7 @@ void Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT + addVariant(xmrig::VARIANT_4); addVariant(xmrig::VARIANT_WOW); addVariant(xmrig::VARIANT_2); addVariant(xmrig::VARIANT_1); diff --git a/src/common/xmrig.h b/src/common/xmrig.h index c861d11c9..c6a5f5688 100644 --- a/src/common/xmrig.h +++ b/src/common/xmrig.h @@ -75,6 +75,7 @@ enum Variant { VARIANT_TRTL = 10, // CryptoNight Turtle (TRTL) VARIANT_GPU = 11, // CryptoNight-GPU (Ryo) VARIANT_WOW = 12, // CryptoNightR (Wownero) + VARIANT_4 = 13, // CryptoNightR (Monero's variant 4) VARIANT_MAX }; diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index 8a48eafd0..b92945e4e 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -39,13 +39,20 @@ struct cryptonight_ctx; typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx*) ABI_ATTRIBUTE; typedef void(*cn_mainloop_double_fun_ms_abi)(cryptonight_ctx*, cryptonight_ctx*) ABI_ATTRIBUTE; +struct cryptonight_r_data { + int variant; + uint64_t height; + + bool match(const int v, const uint64_t h) const { return (v == variant) && (h == height); } +}; + struct cryptonight_ctx { alignas(16) uint8_t state[224]; alignas(16) uint8_t *memory; cn_mainloop_fun_ms_abi generated_code; cn_mainloop_double_fun_ms_abi generated_code_double; - uint64_t generated_code_height; - uint64_t generated_code_double_height; + cryptonight_r_data generated_code_data; + cryptonight_r_data generated_code_double_data; }; diff --git a/src/crypto/CryptoNight_arm.h b/src/crypto/CryptoNight_arm.h index f04c27f13..e7232eb1f 100644 --- a/src/crypto/CryptoNight_arm.h +++ b/src/crypto/CryptoNight_arm.h @@ -431,12 +431,12 @@ static inline __m128i aes_round_tweak_div(const __m128i &in, const __m128i &key) template -static inline void cryptonight_monero_tweak(const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i cx) +static inline void cryptonight_monero_tweak(const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i& cx) { uint64_t* mem_out = (uint64_t*)&l[idx]; if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1); + VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1, cx); _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); } else { __m128i tmp = _mm_xor_si128(bx0, cx); @@ -515,8 +515,12 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ch = ((uint64_t*) &l0[idx0 & MASK])[1]; if (BASE == xmrig::VARIANT_2) { - if (VARIANT == xmrig::VARIANT_WOW) { + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { VARIANT4_RANDOM_MATH(0, al0, ah0, cl, bx0, bx1); + if (VARIANT == xmrig::VARIANT_4) { + al0 ^= r0[2] | ((uint64_t)(r0[3]) << 32); + ah0 ^= r0[0] | ((uint64_t)(r0[1]) << 32); + } } else { VARIANT2_INTEGER_MATH(0, cl, cx); } @@ -525,7 +529,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx0, cl, &hi); if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); + if (VARIANT == xmrig::VARIANT_4) { + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1, cx); + } else { + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); + } } al0 += hi; @@ -686,8 +694,12 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ch = ((uint64_t*) &l0[idx0 & MASK])[1]; if (BASE == xmrig::VARIANT_2) { - if (VARIANT == xmrig::VARIANT_WOW) { + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { VARIANT4_RANDOM_MATH(0, al0, ah0, cl, bx00, bx01); + if (VARIANT == xmrig::VARIANT_4) { + al0 ^= r0[2] | ((uint64_t)(r0[3]) << 32); + ah0 ^= r0[0] | ((uint64_t)(r0[1]) << 32); + } } else { VARIANT2_INTEGER_MATH(0, cl, cx0); } @@ -696,7 +708,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx0, cl, &hi); if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); + if (VARIANT == xmrig::VARIANT_4) { + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01, cx0); + } else { + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); + } } al0 += hi; @@ -736,8 +752,12 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ch = ((uint64_t*) &l1[idx1 & MASK])[1]; if (BASE == xmrig::VARIANT_2) { - if (VARIANT == xmrig::VARIANT_WOW) { + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { VARIANT4_RANDOM_MATH(1, al1, ah1, cl, bx10, bx11); + if (VARIANT == xmrig::VARIANT_4) { + al1 ^= r1[2] | ((uint64_t)(r1[3]) << 32); + ah1 ^= r1[0] | ((uint64_t)(r1[1]) << 32); + } } else { VARIANT2_INTEGER_MATH(1, cl, cx1); } @@ -746,7 +766,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx1, cl, &hi); if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); + if (VARIANT == xmrig::VARIANT_4) { + VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11, cx1); + } else { + VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); + } } al1 += hi; diff --git a/src/crypto/CryptoNight_constants.h b/src/crypto/CryptoNight_constants.h index 2bb24de7b..4ea1adb3b 100644 --- a/src/crypto/CryptoNight_constants.h +++ b/src/crypto/CryptoNight_constants.h @@ -127,6 +127,7 @@ template<> inline constexpr uint32_t cn_select_iter() template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } +template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HALF_ITER; } template<> inline constexpr uint32_t cn_select_iter() { return CRYPTONIGHT_HALF_ITER; } @@ -197,8 +198,13 @@ template<> inline constexpr Variant cn_base_variant() { return VA template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } template<> inline constexpr Variant cn_base_variant() { return VARIANT_GPU; } template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template<> inline constexpr Variant cn_base_variant() { return VARIANT_2; } +template inline constexpr bool cn_is_cryptonight_r() { return false; } +template<> inline constexpr bool cn_is_cryptonight_r() { return true; } +template<> inline constexpr bool cn_is_cryptonight_r() { return true; } + } /* namespace xmrig */ diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h index 9c26ae5f9..26c1fff0e 100644 --- a/src/crypto/CryptoNight_monero.h +++ b/src/crypto/CryptoNight_monero.h @@ -83,7 +83,7 @@ sqrt_result_xmm_##part = int_sqrt_v2(cx_0 + division_result); \ } while (0) -# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1) \ +# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1, _c) \ do { \ const __m128i chunk1 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))); \ const __m128i chunk2 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20))); \ @@ -91,6 +91,9 @@ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \ _mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \ + if (VARIANT == xmrig::VARIANT_4) { \ + _c = _mm_xor_si128(_mm_xor_si128(_c, chunk3), _mm_xor_si128(chunk1, chunk2)); \ + } \ } while (0) # define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo) \ @@ -125,7 +128,7 @@ sqrt_result_##part += ((r2 + b > sqrt_input) ? -1 : 0) + ((r2 + (1ULL << 32) < sqrt_input - s) ? 1 : 0); \ } while (0) -# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1) \ +# define VARIANT2_SHUFFLE(base_ptr, offset, _a, _b, _b1, _c) \ do { \ const uint64x2_t chunk1 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10))); \ const uint64x2_t chunk2 = vld1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20))); \ @@ -133,6 +136,9 @@ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \ vst1q_u64((uint64_t*)((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \ + if (VARIANT == xmrig::VARIANT_4) { \ + _c = veorq_u64(veorq_u64(_c, chunk3), veorq_u64(chunk1, chunk2)); \ + } \ } while (0) # define VARIANT2_SHUFFLE2(base_ptr, offset, _a, _b, _b1, hi, lo) \ @@ -152,26 +158,28 @@ #define SWAP64LE(x) x #define hash_extra_blake(data, length, hash) blake256_hash((uint8_t*)(hash), (uint8_t*)(data), (length)) +#include "common/xmrig.h" #include "variant4_random_math.h" #define VARIANT4_RANDOM_MATH_INIT(part) \ - uint32_t r##part[8]; \ + uint32_t r##part[9]; \ struct V4_Instruction code##part[256]; \ - if (VARIANT == xmrig::VARIANT_WOW) { \ + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { \ r##part[0] = (uint32_t)(h##part[12]); \ r##part[1] = (uint32_t)(h##part[12] >> 32); \ r##part[2] = (uint32_t)(h##part[13]); \ r##part[3] = (uint32_t)(h##part[13] >> 32); \ } \ - v4_random_math_init(code##part, height); + v4_random_math_init(code##part, height); #define VARIANT4_RANDOM_MATH(part, al, ah, cl, bx0, bx1) \ - if (VARIANT == xmrig::VARIANT_WOW) { \ + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { \ cl ^= (r##part[0] + r##part[1]) | ((uint64_t)(r##part[2] + r##part[3]) << 32); \ r##part[4] = static_cast(al); \ r##part[5] = static_cast(ah); \ r##part[6] = static_cast(_mm_cvtsi128_si32(bx0)); \ r##part[7] = static_cast(_mm_cvtsi128_si32(bx1)); \ + r##part[8] = static_cast(_mm_cvtsi128_si32(_mm_srli_si128(bx1, 8))); \ v4_random_math(code##part, r##part); \ } diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index d3da28c1e..237fe31bf 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -58,8 +58,7 @@ const static uint8_t test_input[380] = { 0xCF, 0x50, 0x29, 0x6A, 0x07, 0x0B, 0x93, 0x8F, 0x8F, 0xA8, 0x10, 0x04 }; -const static char* test_input_WOW = R"===( -9d47bf4c41b7e8e727e681715acb47fa1677cdba9ca7bcb05ad8cc8abd5daa66 5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374 1806260 +const static char* test_input_WOW = R"===(9d47bf4c41b7e8e727e681715acb47fa1677cdba9ca7bcb05ad8cc8abd5daa66 5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374 1806260 0d4a495cb844a3ca8ba4edb8e6bcf829ef1c06d9cdea2b62ca46c2a21b8b0a79 4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67 1806261 a1d6d848b5c5915fccd2f64cf216c6b1a02cf7c77bc80d8d4e51b419e88ff0dd 656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265 1806262 af3a8544a0221a148c2ac90484b19861e3afca33fe17021efb8ad6496b567915 657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c 1806263 @@ -68,8 +67,18 @@ af3a8544a0221a148c2ac90484b19861e3afca33fe17021efb8ad6496b567915 657420646f6c6f7 2b13000535f3db5f9b9b84a65c4351f386cd2cdedebb8c3ad2eab086e6a3fee5 697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974 1806266 fc0e1dad8e895749dc90eb690bc1ba059a1cd772afaaf65a106bf9e5e6b80503 657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e 1806267 b60b0afe144deff7d903ed2d5545e77ebe66a3c51fee7016eeb8fee9eb630c0f 4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c 1806268 -64774b27e7d5fec862fc4c0c13ac6bf09123b6f05bb0e4b75c97f379a2b3a679 73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e 1806269 -)==="; +64774b27e7d5fec862fc4c0c13ac6bf09123b6f05bb0e4b75c97f379a2b3a679 73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e 1806269)==="; + +const static char* test_input_R = R"===(f759588ad57e758467295443a9bd71490abff8e9dad1b95b6bf2f5d0d78387bc 5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374 1806260 +5bb833deca2bdd7252a9ccd7b4ce0b6a4854515794b56c207262f7a5b9bdb566 4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67 1806261 +1ee6728da60fbd8d7d55b2b1ade487a3cf52a2c3ac6f520db12c27d8921f6cab 656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265 1806262 +6969fe2ddfb758438d48049f302fc2108a4fcc93e37669170e6db4b0b9b4c4cb 657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c 1806263 +7f3048b4e90d0cbe7a57c0394f37338a01fae3adfdc0e5126d863a895eb04e02 71756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e697369 1806264 +1d290443a4b542af04a82f6b2494a6ee7f20f2754c58e0849032483a56e8e2ef 757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e20447569732061757465 1806265 +c43cc6567436a86afbd6aa9eaa7c276e9806830334b614b2bee23cc76634f6fd 697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974 1806266 +87be2479c0c4e8edfdfaa5603e93f4265b3f8224c1c5946feb424819d18990a4 657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e 1806267 +dd9d6a6d8e47465cceac0877ef889b93e7eba979557e3935d7f86dce11b070f3 4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c 1806268 +75c6f2ae49a20521de97285b431e717125847fb8935ed84a61e7f8d36a2c3d8e 73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e 1806269)==="; // "cn/0" const static uint8_t test_output_v0[160] = { diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h index b6969571f..4c5d4ac04 100644 --- a/src/crypto/CryptoNight_x86.h +++ b/src/crypto/CryptoNight_x86.h @@ -457,10 +457,10 @@ static inline __m128i int_sqrt_v2(const uint64_t n0) template -static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i cx) +static inline void cryptonight_monero_tweak(uint64_t* mem_out, const uint8_t* l, uint64_t idx, __m128i ax0, __m128i bx0, __m128i bx1, __m128i& cx) { if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1); + VARIANT2_SHUFFLE(l, idx, ax0, bx0, bx1, cx); _mm_store_si128((__m128i *)mem_out, _mm_xor_si128(bx0, cx)); } else { __m128i tmp = _mm_xor_si128(bx0, cx); @@ -543,8 +543,12 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si ch = ((uint64_t*) &l0[idx0 & MASK])[1]; if (BASE == xmrig::VARIANT_2) { - if (VARIANT == xmrig::VARIANT_WOW) { + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { VARIANT4_RANDOM_MATH(0, al0, ah0, cl, bx0, bx1); + if (VARIANT == xmrig::VARIANT_4) { + al0 ^= r0[2] | ((uint64_t)(r0[3]) << 32); + ah0 ^= r0[0] | ((uint64_t)(r0[1]) << 32); + } } else { VARIANT2_INTEGER_MATH(0, cl, cx); } @@ -553,7 +557,11 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx0, cl, &hi); if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); + if (VARIANT == xmrig::VARIANT_4) { + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx0, bx1, cx); + } else { + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx0, bx1, hi, lo); + } } al0 += hi; @@ -658,21 +666,46 @@ extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_ryzen_asm; extern xmrig::CpuThread::cn_mainloop_fun cn_trtl_mainloop_bulldozer_asm; extern xmrig::CpuThread::cn_mainloop_double_fun cn_trtl_double_mainloop_sandybridge_asm; +void wow_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); -void v4_64_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); +void wow_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); void v4_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); -void v4_64_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM); + +template +void cn_r_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + v4_compile_code(code, code_size, machine_code, ASM); +} + +template +void cn_r_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + v4_compile_code_double(code, code_size, machine_code, ASM); +} + +template<> +void cn_r_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + wow_compile_code(code, code_size, machine_code, ASM); +} + +template<> +void cn_r_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + wow_compile_code_double(code, code_size, machine_code, ASM); +} template inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx **__restrict__ ctx, uint64_t height) { constexpr size_t MEM = xmrig::cn_select_memory(); - if ((VARIANT == xmrig::VARIANT_WOW) && (height != ctx[0]->generated_code_height)) { + if (xmrig::cn_is_cryptonight_r() && !ctx[0]->generated_code_data.match(VARIANT, height)) { V4_Instruction code[256]; - const int code_size = v4_random_math_init(code, height); - v4_compile_code(code, code_size, reinterpret_cast(ctx[0]->generated_code), ASM); - ctx[0]->generated_code_height = height; + const int code_size = v4_random_math_init(code, height); + cn_r_compile_code(code, code_size, reinterpret_cast(ctx[0]->generated_code), ASM); + ctx[0]->generated_code_data.variant = VARIANT; + ctx[0]->generated_code_data.height = height; } xmrig::keccak(input, size, ctx[0]->state); @@ -711,7 +744,7 @@ inline void cryptonight_single_hash_asm(const uint8_t *__restrict__ input, size_ cn_trtl_mainloop_bulldozer_asm(ctx[0]); } } - else if (VARIANT == xmrig::VARIANT_WOW) { + else if (xmrig::cn_is_cryptonight_r()) { ctx[0]->generated_code(ctx[0]); } @@ -726,11 +759,12 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ { constexpr size_t MEM = xmrig::cn_select_memory(); - if ((VARIANT == xmrig::VARIANT_WOW) && (height != ctx[0]->generated_code_double_height)) { + if (xmrig::cn_is_cryptonight_r() && !ctx[0]->generated_code_double_data.match(VARIANT, height)) { V4_Instruction code[256]; - const int code_size = v4_random_math_init(code, height); - v4_compile_code_double(code, code_size, reinterpret_cast(ctx[0]->generated_code_double), ASM); - ctx[0]->generated_code_double_height = height; + const int code_size = v4_random_math_init(code, height); + cn_r_compile_code_double(code, code_size, reinterpret_cast(ctx[0]->generated_code_double), ASM); + ctx[0]->generated_code_double_data.variant = VARIANT; + ctx[0]->generated_code_double_data.height = height; } xmrig::keccak(input, size, ctx[0]->state); @@ -748,7 +782,7 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_ else if (VARIANT == xmrig::VARIANT_TRTL) { cn_trtl_double_mainloop_sandybridge_asm(ctx[0], ctx[1]); } - else if (VARIANT == xmrig::VARIANT_WOW) { + else if (xmrig::cn_is_cryptonight_r()) { ctx[0]->generated_code_double(ctx[0], ctx[1]); } @@ -847,8 +881,12 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ch = ((uint64_t*) &l0[idx0 & MASK])[1]; if (BASE == xmrig::VARIANT_2) { - if (VARIANT == xmrig::VARIANT_WOW) { + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { VARIANT4_RANDOM_MATH(0, al0, ah0, cl, bx00, bx01); + if (VARIANT == xmrig::VARIANT_4) { + al0 ^= r0[2] | ((uint64_t)(r0[3]) << 32); + ah0 ^= r0[0] | ((uint64_t)(r0[1]) << 32); + } } else { VARIANT2_INTEGER_MATH(0, cl, cx0); } @@ -857,7 +895,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx0, cl, &hi); if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); + if (VARIANT == xmrig::VARIANT_4) { + VARIANT2_SHUFFLE(l0, idx0 & MASK, ax0, bx00, bx01, cx0); + } else { + VARIANT2_SHUFFLE2(l0, idx0 & MASK, ax0, bx00, bx01, hi, lo); + } } al0 += hi; @@ -895,8 +937,12 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si ch = ((uint64_t*) &l1[idx1 & MASK])[1]; if (BASE == xmrig::VARIANT_2) { - if (VARIANT == xmrig::VARIANT_WOW) { + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { VARIANT4_RANDOM_MATH(1, al1, ah1, cl, bx10, bx11); + if (VARIANT == xmrig::VARIANT_4) { + al1 ^= r1[2] | ((uint64_t)(r1[3]) << 32); + ah1 ^= r1[0] | ((uint64_t)(r1[1]) << 32); + } } else { VARIANT2_INTEGER_MATH(1, cl, cx1); } @@ -905,7 +951,11 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si lo = __umul128(idx1, cl, &hi); if (BASE == xmrig::VARIANT_2) { - VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); + if (VARIANT == xmrig::VARIANT_4) { + VARIANT2_SHUFFLE(l1, idx1 & MASK, ax1, bx10, bx11, cx1); + } else { + VARIANT2_SHUFFLE2(l1, idx1 & MASK, ax1, bx10, bx11, hi, lo); + } } al1 += hi; @@ -989,18 +1039,30 @@ inline void cryptonight_double_hash(const uint8_t *__restrict__ input, size_t si #define CN_STEP4(part, a, b0, b1, c, l, mc, ptr, idx) \ + uint64_t al##part, ah##part; \ if (BASE == xmrig::VARIANT_2) { \ - if (VARIANT == xmrig::VARIANT_WOW) { \ - const uint64_t al = _mm_cvtsi128_si64(a); \ - const uint64_t ah = _mm_cvtsi128_si64(_mm_srli_si128(a, 8)); \ - VARIANT4_RANDOM_MATH(part, al, ah, cl##part, b0, b1); \ + if ((VARIANT == xmrig::VARIANT_WOW) || (VARIANT == xmrig::VARIANT_4)) { \ + al##part = _mm_cvtsi128_si64(a); \ + ah##part = _mm_cvtsi128_si64(_mm_srli_si128(a, 8)); \ + VARIANT4_RANDOM_MATH(part, al##part, ah##part, cl##part, b0, b1); \ + if (VARIANT == xmrig::VARIANT_4) { \ + al##part ^= r##part[2] | ((uint64_t)(r##part[3]) << 32); \ + ah##part ^= r##part[0] | ((uint64_t)(r##part[1]) << 32); \ + } \ } else { \ VARIANT2_INTEGER_MATH(part, cl##part, c); \ } \ } \ lo = __umul128(idx, cl##part, &hi); \ if (BASE == xmrig::VARIANT_2) { \ - VARIANT2_SHUFFLE2(l, idx & MASK, a, b0, b1, hi, lo); \ + if (VARIANT == xmrig::VARIANT_4) { \ + VARIANT2_SHUFFLE(l, idx & MASK, a, b0, b1, c); \ + } else { \ + VARIANT2_SHUFFLE2(l, idx & MASK, a, b0, b1, hi, lo); \ + } \ + } \ + if (VARIANT == xmrig::VARIANT_4) { \ + a = _mm_set_epi64x(ah##part, al##part); \ } \ a = _mm_add_epi64(a, _mm_set_epi64x(lo, hi)); \ \ diff --git a/src/crypto/CryptonightR_gen.cpp b/src/crypto/CryptonightR_gen.cpp index 382259556..55f94662c 100644 --- a/src/crypto/CryptonightR_gen.cpp +++ b/src/crypto/CryptonightR_gen.cpp @@ -58,7 +58,7 @@ static inline void add_random_math(uint8_t* &p, const V4_Instruction* code, int const uint32_t a = inst.dst_index; const uint32_t b = inst.src_index; - const uint8_t c = opcode | (dst_index << V4_OPCODE_BITS) | (src_index << (V4_OPCODE_BITS + V4_DST_INDEX_BITS)); + const uint8_t c = opcode | (dst_index << V4_OPCODE_BITS) | (((src_index == 8) ? dst_index : src_index) << (V4_OPCODE_BITS + V4_DST_INDEX_BITS)); switch (inst.opcode) { case ROR: @@ -99,6 +99,20 @@ static inline void add_random_math(uint8_t* &p, const V4_Instruction* code, int } } +void wow_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + uint8_t* p0 = reinterpret_cast(machine_code); + uint8_t* p = p0; + + add_code(p, CryptonightWOW_template_part1, CryptonightWOW_template_part2); + add_random_math(p, code, code_size, instructions, instructions_mov, false, ASM); + add_code(p, CryptonightWOW_template_part2, CryptonightWOW_template_part3); + *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightWOW_template_mainloop) - ((const uint8_t*)CryptonightWOW_template_part1)) - (p - p0)); + add_code(p, CryptonightWOW_template_part3, CryptonightWOW_template_end); + + Mem::flushInstructionCache(machine_code, p - p0); +} + void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) { uint8_t* p0 = reinterpret_cast(machine_code); @@ -113,6 +127,22 @@ void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_co Mem::flushInstructionCache(machine_code, p - p0); } +void wow_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) +{ + uint8_t* p0 = reinterpret_cast(machine_code); + uint8_t* p = p0; + + add_code(p, CryptonightWOW_template_double_part1, CryptonightWOW_template_double_part2); + add_random_math(p, code, code_size, instructions, instructions_mov, false, ASM); + add_code(p, CryptonightWOW_template_double_part2, CryptonightWOW_template_double_part3); + add_random_math(p, code, code_size, instructions, instructions_mov, false, ASM); + add_code(p, CryptonightWOW_template_double_part3, CryptonightWOW_template_double_part4); + *(int*)(p - 4) = static_cast((((const uint8_t*)CryptonightWOW_template_double_mainloop) - ((const uint8_t*)CryptonightWOW_template_double_part1)) - (p - p0)); + add_code(p, CryptonightWOW_template_double_part4, CryptonightWOW_template_double_end); + + Mem::flushInstructionCache(machine_code, p - p0); +} + void v4_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) { uint8_t* p0 = reinterpret_cast(machine_code); diff --git a/src/crypto/asm/CryptonightR_template.S b/src/crypto/asm/CryptonightR_template.S index e8478beb9..5f3046cb9 100644 --- a/src/crypto/asm/CryptonightR_template.S +++ b/src/crypto/asm/CryptonightR_template.S @@ -529,6 +529,7 @@ PUBLIC FN_PREFIX(CryptonightR_instruction_mov254) PUBLIC FN_PREFIX(CryptonightR_instruction_mov255) PUBLIC FN_PREFIX(CryptonightR_instruction_mov256) +#include "CryptonightWOW_template.inc" #include "CryptonightR_template.inc" FN_PREFIX(CryptonightR_instruction0): @@ -538,16 +539,16 @@ FN_PREFIX(CryptonightR_instruction1): FN_PREFIX(CryptonightR_instruction2): imul rbx, rbx FN_PREFIX(CryptonightR_instruction3): - add rbx, rbx + add rbx, r9 add rbx, 2147483647 FN_PREFIX(CryptonightR_instruction4): - sub rbx, rbx + sub rbx, r9 FN_PREFIX(CryptonightR_instruction5): ror ebx, cl FN_PREFIX(CryptonightR_instruction6): rol ebx, cl FN_PREFIX(CryptonightR_instruction7): - xor rbx, rbx + xor rbx, r9 FN_PREFIX(CryptonightR_instruction8): imul rsi, rbx FN_PREFIX(CryptonightR_instruction9): @@ -623,16 +624,16 @@ FN_PREFIX(CryptonightR_instruction41): FN_PREFIX(CryptonightR_instruction42): imul rsi, rsi FN_PREFIX(CryptonightR_instruction43): - add rsi, rsi + add rsi, r9 add rsi, 2147483647 FN_PREFIX(CryptonightR_instruction44): - sub rsi, rsi + sub rsi, r9 FN_PREFIX(CryptonightR_instruction45): ror esi, cl FN_PREFIX(CryptonightR_instruction46): rol esi, cl FN_PREFIX(CryptonightR_instruction47): - xor rsi, rsi + xor rsi, r9 FN_PREFIX(CryptonightR_instruction48): imul rdi, rsi FN_PREFIX(CryptonightR_instruction49): @@ -708,16 +709,16 @@ FN_PREFIX(CryptonightR_instruction81): FN_PREFIX(CryptonightR_instruction82): imul rdi, rdi FN_PREFIX(CryptonightR_instruction83): - add rdi, rdi + add rdi, r9 add rdi, 2147483647 FN_PREFIX(CryptonightR_instruction84): - sub rdi, rdi + sub rdi, r9 FN_PREFIX(CryptonightR_instruction85): ror edi, cl FN_PREFIX(CryptonightR_instruction86): rol edi, cl FN_PREFIX(CryptonightR_instruction87): - xor rdi, rdi + xor rdi, r9 FN_PREFIX(CryptonightR_instruction88): imul rbp, rdi FN_PREFIX(CryptonightR_instruction89): @@ -793,16 +794,16 @@ FN_PREFIX(CryptonightR_instruction121): FN_PREFIX(CryptonightR_instruction122): imul rbp, rbp FN_PREFIX(CryptonightR_instruction123): - add rbp, rbp + add rbp, r9 add rbp, 2147483647 FN_PREFIX(CryptonightR_instruction124): - sub rbp, rbp + sub rbp, r9 FN_PREFIX(CryptonightR_instruction125): ror ebp, cl FN_PREFIX(CryptonightR_instruction126): rol ebp, cl FN_PREFIX(CryptonightR_instruction127): - xor rbp, rbp + xor rbp, r9 FN_PREFIX(CryptonightR_instruction128): imul rbx, rsp FN_PREFIX(CryptonightR_instruction129): diff --git a/src/crypto/asm/CryptonightR_template.asm b/src/crypto/asm/CryptonightR_template.asm index ec8ad5afe..25b72c3c0 100644 --- a/src/crypto/asm/CryptonightR_template.asm +++ b/src/crypto/asm/CryptonightR_template.asm @@ -516,6 +516,7 @@ PUBLIC CryptonightR_instruction_mov254 PUBLIC CryptonightR_instruction_mov255 PUBLIC CryptonightR_instruction_mov256 +INCLUDE CryptonightWOW_template_win.inc INCLUDE CryptonightR_template_win.inc CryptonightR_instruction0: @@ -525,16 +526,16 @@ CryptonightR_instruction1: CryptonightR_instruction2: imul rbx, rbx CryptonightR_instruction3: - add rbx, rbx + add rbx, r9 add rbx, 2147483647 CryptonightR_instruction4: - sub rbx, rbx + sub rbx, r9 CryptonightR_instruction5: ror ebx, cl CryptonightR_instruction6: rol ebx, cl CryptonightR_instruction7: - xor rbx, rbx + xor rbx, r9 CryptonightR_instruction8: imul rsi, rbx CryptonightR_instruction9: @@ -610,16 +611,16 @@ CryptonightR_instruction41: CryptonightR_instruction42: imul rsi, rsi CryptonightR_instruction43: - add rsi, rsi + add rsi, r9 add rsi, 2147483647 CryptonightR_instruction44: - sub rsi, rsi + sub rsi, r9 CryptonightR_instruction45: ror esi, cl CryptonightR_instruction46: rol esi, cl CryptonightR_instruction47: - xor rsi, rsi + xor rsi, r9 CryptonightR_instruction48: imul rdi, rsi CryptonightR_instruction49: @@ -695,16 +696,16 @@ CryptonightR_instruction81: CryptonightR_instruction82: imul rdi, rdi CryptonightR_instruction83: - add rdi, rdi + add rdi, r9 add rdi, 2147483647 CryptonightR_instruction84: - sub rdi, rdi + sub rdi, r9 CryptonightR_instruction85: ror edi, cl CryptonightR_instruction86: rol edi, cl CryptonightR_instruction87: - xor rdi, rdi + xor rdi, r9 CryptonightR_instruction88: imul rbp, rdi CryptonightR_instruction89: @@ -780,16 +781,16 @@ CryptonightR_instruction121: CryptonightR_instruction122: imul rbp, rbp CryptonightR_instruction123: - add rbp, rbp + add rbp, r9 add rbp, 2147483647 CryptonightR_instruction124: - sub rbp, rbp + sub rbp, r9 CryptonightR_instruction125: ror ebp, cl CryptonightR_instruction126: rol ebp, cl CryptonightR_instruction127: - xor rbp, rbp + xor rbp, r9 CryptonightR_instruction128: imul rbx, rsp CryptonightR_instruction129: diff --git a/src/crypto/asm/CryptonightR_template.h b/src/crypto/asm/CryptonightR_template.h index 182c6870f..c2054705b 100644 --- a/src/crypto/asm/CryptonightR_template.h +++ b/src/crypto/asm/CryptonightR_template.h @@ -2,6 +2,18 @@ extern "C" { + void CryptonightWOW_template_part1(); + void CryptonightWOW_template_mainloop(); + void CryptonightWOW_template_part2(); + void CryptonightWOW_template_part3(); + void CryptonightWOW_template_end(); + void CryptonightWOW_template_double_part1(); + void CryptonightWOW_template_double_mainloop(); + void CryptonightWOW_template_double_part2(); + void CryptonightWOW_template_double_part3(); + void CryptonightWOW_template_double_part4(); + void CryptonightWOW_template_double_end(); + void CryptonightR_template_part1(); void CryptonightR_template_mainloop(); void CryptonightR_template_part2(); @@ -13,6 +25,7 @@ extern "C" void CryptonightR_template_double_part3(); void CryptonightR_template_double_part4(); void CryptonightR_template_double_end(); + void CryptonightR_instruction0(); void CryptonightR_instruction1(); void CryptonightR_instruction2(); diff --git a/src/crypto/asm/CryptonightR_template.inc b/src/crypto/asm/CryptonightR_template.inc index 468eb87b6..b54486a57 100644 --- a/src/crypto/asm/CryptonightR_template.inc +++ b/src/crypto/asm/CryptonightR_template.inc @@ -10,6 +10,7 @@ PUBLIC FN_PREFIX(CryptonightR_template_double_part3) PUBLIC FN_PREFIX(CryptonightR_template_double_part4) PUBLIC FN_PREFIX(CryptonightR_template_double_end) +ALIGN(64) FN_PREFIX(CryptonightR_template_part1): mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp @@ -68,8 +69,6 @@ FN_PREFIX(CryptonightR_template_mainloop): lea rdx, QWORD PTR [r9+r11] aesenc xmm5, xmm4 - movd r10d, xmm5 - and r10d, 2097136 mov r12d, r9d mov eax, r9d @@ -77,16 +76,23 @@ FN_PREFIX(CryptonightR_template_mainloop): xor r12d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] + movaps xmm3, xmm0 movdqu xmm2, XMMWORD PTR [r12+r11] movdqu xmm1, XMMWORD PTR [rax+r11] - paddq xmm0, xmm7 + pxor xmm0, xmm2 + pxor xmm5, xmm1 + pxor xmm5, xmm0 + paddq xmm3, xmm7 paddq xmm2, xmm6 paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm0 - movq r12, xmm5 + movdqu XMMWORD PTR [r12+r11], xmm3 movdqu XMMWORD PTR [rax+r11], xmm2 movdqu XMMWORD PTR [r9+r11], xmm1 + movq r12, xmm5 + movd r10d, xmm5 + and r10d, 2097136 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -101,13 +107,23 @@ FN_PREFIX(CryptonightR_template_mainloop): movd eax, xmm6 movd edx, xmm7 + pextrd r9d, xmm7, 2 FN_PREFIX(CryptonightR_template_part2): + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor rsp, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r15, rax + mov rax, r13 mul r12 - movq xmm0, rax - movq xmm3, rdx - punpcklqdq xmm3, xmm0 mov r9d, r10d mov r12d, r10d @@ -115,16 +131,18 @@ FN_PREFIX(CryptonightR_template_part2): xor r12d, 32 xor r10d, 48 movdqa xmm1, XMMWORD PTR [r12+r11] - xor rdx, QWORD PTR [r12+r11] - xor rax, QWORD PTR [r11+r12+8] + movaps xmm3, xmm1 movdqa xmm2, XMMWORD PTR [r9+r11] - pxor xmm3, xmm2 - paddq xmm7, XMMWORD PTR [r10+r11] - paddq xmm1, xmm4 - paddq xmm3, xmm6 - movdqu XMMWORD PTR [r9+r11], xmm7 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [r10+r11], xmm1 + movdqa xmm0, XMMWORD PTR [r10+r11] + pxor xmm1, xmm2 + pxor xmm5, xmm0 + pxor xmm5, xmm1 + paddq xmm3, xmm4 + paddq xmm2, xmm6 + paddq xmm0, xmm7 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqu XMMWORD PTR [r12+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 add r15, rax @@ -247,18 +265,21 @@ FN_PREFIX(CryptonightR_template_double_mainloop): punpcklqdq xmm3, xmm0 xor ebx, 16 aesenc xmm6, xmm3 - movq rdx, xmm6 movq xmm4, r15 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 xor ebx, 48 paddq xmm0, xmm7 movdqu xmm1, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm1 movdqu XMMWORD PTR [rbx+rsi], xmm0 paddq xmm1, xmm3 xor ebx, 16 mov eax, ebx xor rax, 32 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 + movq rdx, xmm6 movdqu XMMWORD PTR [rbx+rsi], xmm1 paddq xmm0, xmm9 movdqu XMMWORD PTR [rax+rsi], xmm0 @@ -274,15 +295,18 @@ FN_PREFIX(CryptonightR_template_double_mainloop): xor r8d, 16 aesenc xmm5, xmm4 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 xor r8d, 48 paddq xmm0, xmm8 movdqu xmm1, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm1 movdqu XMMWORD PTR [r8+rdi], xmm0 paddq xmm1, xmm4 xor r8d, 16 mov eax, r8d xor rax, 32 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 movdqu XMMWORD PTR [r8+rdi], xmm1 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rdi], xmm0 @@ -303,7 +327,8 @@ FN_PREFIX(CryptonightR_template_double_mainloop): movq xmm11, rbp movq xmm12, r15 movq xmm13, rdx - mov [rsp+112], rcx + mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp+16] mov esi, DWORD PTR [rsp+20] @@ -320,9 +345,22 @@ FN_PREFIX(CryptonightR_template_double_mainloop): pextrd r15d, xmm3, 2 movd eax, xmm7 movd edx, xmm9 + pextrd r9d, xmm9, 2 FN_PREFIX(CryptonightR_template_double_part2): + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r14, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r12, rax + movq rsp, xmm0 mov DWORD PTR [rsp+16], ebx mov DWORD PTR [rsp+20], esi @@ -334,28 +372,27 @@ FN_PREFIX(CryptonightR_template_double_part2): movq rbp, xmm11 movq r15, xmm12 movq rdx, xmm13 - mov rcx, [rsp+112] + mov rcx, [rsp+104] + mov r9, [rsp+112] mov rbx, r8 mov rax, r8 mul rdx and ebp, 2097136 mov r8, rax - movq xmm1, rdx - movq xmm0, r8 - punpcklqdq xmm1, xmm0 - pxor xmm1, XMMWORD PTR [rcx+rsi] + movdqu xmm1, XMMWORD PTR [rcx+rsi] + pxor xmm6, xmm1 xor esi, 48 paddq xmm1, xmm7 movdqu xmm2, XMMWORD PTR [rsi+rcx] - xor rdx, QWORD PTR [rsi+rcx] + pxor xmm6, xmm2 paddq xmm2, xmm3 - xor r8, QWORD PTR [rsi+rcx+8] movdqu XMMWORD PTR [rsi+rcx], xmm1 xor esi, 16 mov eax, esi mov rsi, rcx movdqu xmm0, XMMWORD PTR [rax+rcx] + pxor xmm6, xmm0 movdqu XMMWORD PTR [rax+rcx], xmm2 paddq xmm0, xmm9 add r12, r8 @@ -383,6 +420,7 @@ FN_PREFIX(CryptonightR_template_double_part2): movq xmm12, rbp movq xmm13, r15 mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp] mov esi, DWORD PTR [rsp+4] @@ -401,9 +439,24 @@ FN_PREFIX(CryptonightR_template_double_part2): pextrd r15d, xmm4, 2 movd eax, xmm8 movd edx, xmm10 + pextrd r9d, xmm10, 2 FN_PREFIX(CryptonightR_template_double_part3): + movq r15, xmm13 + + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r15, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r13, rax + movq rsp, xmm0 mov DWORD PTR [rsp], ebx mov DWORD PTR [rsp+4], esi @@ -414,23 +467,20 @@ FN_PREFIX(CryptonightR_template_double_part3): movq rsi, xmm2 movq rdi, xmm11 movq rbp, xmm12 - movq r15, xmm13 mov rcx, [rsp+104] + mov r9, [rsp+112] mov rax, r8 mul rdi - movq xmm1, rdx - movq xmm0, rax - punpcklqdq xmm1, xmm0 mov rdi, rcx mov r8, rax - pxor xmm1, XMMWORD PTR [rbp+rcx] + movdqu xmm1, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm1 xor ebp, 48 paddq xmm1, xmm8 - xor r8, QWORD PTR [rbp+rcx+8] - xor rdx, QWORD PTR [rbp+rcx] add r13, r8 movdqu xmm2, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm2 add r15, rdx movdqu XMMWORD PTR [rbp+rcx], xmm1 paddq xmm2, xmm4 @@ -438,6 +488,7 @@ FN_PREFIX(CryptonightR_template_double_part3): mov eax, ebp xor rax, 32 movdqu xmm0, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm0 movdqu XMMWORD PTR [rbp+rcx], xmm2 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rcx], xmm0 diff --git a/src/crypto/asm/CryptonightR_template_win.inc b/src/crypto/asm/CryptonightR_template_win.inc index efa1f3f53..150bb0e35 100644 --- a/src/crypto/asm/CryptonightR_template_win.inc +++ b/src/crypto/asm/CryptonightR_template_win.inc @@ -10,6 +10,7 @@ PUBLIC CryptonightR_template_double_part3 PUBLIC CryptonightR_template_double_part4 PUBLIC CryptonightR_template_double_end +ALIGN(64) CryptonightR_template_part1: mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp @@ -68,8 +69,6 @@ CryptonightR_template_mainloop: lea rdx, QWORD PTR [r9+r11] aesenc xmm5, xmm4 - movd r10d, xmm5 - and r10d, 2097136 mov r12d, r9d mov eax, r9d @@ -77,16 +76,23 @@ CryptonightR_template_mainloop: xor r12d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] + movaps xmm3, xmm0 movdqu xmm2, XMMWORD PTR [r12+r11] movdqu xmm1, XMMWORD PTR [rax+r11] - paddq xmm0, xmm7 + pxor xmm0, xmm2 + pxor xmm5, xmm1 + pxor xmm5, xmm0 + paddq xmm3, xmm7 paddq xmm2, xmm6 paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm0 - movq r12, xmm5 + movdqu XMMWORD PTR [r12+r11], xmm3 movdqu XMMWORD PTR [rax+r11], xmm2 movdqu XMMWORD PTR [r9+r11], xmm1 + movq r12, xmm5 + movd r10d, xmm5 + and r10d, 2097136 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -101,13 +107,23 @@ CryptonightR_template_mainloop: movd eax, xmm6 movd edx, xmm7 + pextrd r9d, xmm7, 2 CryptonightR_template_part2: + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor rsp, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r15, rax + mov rax, r13 mul r12 - movq xmm0, rax - movq xmm3, rdx - punpcklqdq xmm3, xmm0 mov r9d, r10d mov r12d, r10d @@ -115,16 +131,18 @@ CryptonightR_template_part2: xor r12d, 32 xor r10d, 48 movdqa xmm1, XMMWORD PTR [r12+r11] - xor rdx, QWORD PTR [r12+r11] - xor rax, QWORD PTR [r11+r12+8] + movaps xmm3, xmm1 movdqa xmm2, XMMWORD PTR [r9+r11] - pxor xmm3, xmm2 - paddq xmm7, XMMWORD PTR [r10+r11] - paddq xmm1, xmm4 - paddq xmm3, xmm6 - movdqu XMMWORD PTR [r9+r11], xmm7 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [r10+r11], xmm1 + movdqa xmm0, XMMWORD PTR [r10+r11] + pxor xmm1, xmm2 + pxor xmm5, xmm0 + pxor xmm5, xmm1 + paddq xmm3, xmm4 + paddq xmm2, xmm6 + paddq xmm0, xmm7 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqu XMMWORD PTR [r12+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 add r15, rax @@ -247,18 +265,21 @@ CryptonightR_template_double_mainloop: punpcklqdq xmm3, xmm0 xor ebx, 16 aesenc xmm6, xmm3 - movq rdx, xmm6 movq xmm4, r15 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 xor ebx, 48 paddq xmm0, xmm7 movdqu xmm1, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm1 movdqu XMMWORD PTR [rbx+rsi], xmm0 paddq xmm1, xmm3 xor ebx, 16 mov eax, ebx xor rax, 32 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 + movq rdx, xmm6 movdqu XMMWORD PTR [rbx+rsi], xmm1 paddq xmm0, xmm9 movdqu XMMWORD PTR [rax+rsi], xmm0 @@ -274,15 +295,18 @@ CryptonightR_template_double_mainloop: xor r8d, 16 aesenc xmm5, xmm4 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 xor r8d, 48 paddq xmm0, xmm8 movdqu xmm1, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm1 movdqu XMMWORD PTR [r8+rdi], xmm0 paddq xmm1, xmm4 xor r8d, 16 mov eax, r8d xor rax, 32 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 movdqu XMMWORD PTR [r8+rdi], xmm1 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rdi], xmm0 @@ -303,7 +327,8 @@ CryptonightR_template_double_mainloop: movq xmm11, rbp movq xmm12, r15 movq xmm13, rdx - mov [rsp+112], rcx + mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp+16] mov esi, DWORD PTR [rsp+20] @@ -320,9 +345,22 @@ CryptonightR_template_double_mainloop: pextrd r15d, xmm3, 2 movd eax, xmm7 movd edx, xmm9 + pextrd r9d, xmm9, 2 CryptonightR_template_double_part2: + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r14, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r12, rax + movq rsp, xmm0 mov DWORD PTR [rsp+16], ebx mov DWORD PTR [rsp+20], esi @@ -334,28 +372,27 @@ CryptonightR_template_double_part2: movq rbp, xmm11 movq r15, xmm12 movq rdx, xmm13 - mov rcx, [rsp+112] + mov rcx, [rsp+104] + mov r9, [rsp+112] mov rbx, r8 mov rax, r8 mul rdx and ebp, 2097136 mov r8, rax - movq xmm1, rdx - movq xmm0, r8 - punpcklqdq xmm1, xmm0 - pxor xmm1, XMMWORD PTR [rcx+rsi] + movdqu xmm1, XMMWORD PTR [rcx+rsi] + pxor xmm6, xmm1 xor esi, 48 paddq xmm1, xmm7 movdqu xmm2, XMMWORD PTR [rsi+rcx] - xor rdx, QWORD PTR [rsi+rcx] + pxor xmm6, xmm2 paddq xmm2, xmm3 - xor r8, QWORD PTR [rsi+rcx+8] movdqu XMMWORD PTR [rsi+rcx], xmm1 xor esi, 16 mov eax, esi mov rsi, rcx movdqu xmm0, XMMWORD PTR [rax+rcx] + pxor xmm6, xmm0 movdqu XMMWORD PTR [rax+rcx], xmm2 paddq xmm0, xmm9 add r12, r8 @@ -383,6 +420,7 @@ CryptonightR_template_double_part2: movq xmm12, rbp movq xmm13, r15 mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp] mov esi, DWORD PTR [rsp+4] @@ -401,9 +439,24 @@ CryptonightR_template_double_part2: pextrd r15d, xmm4, 2 movd eax, xmm8 movd edx, xmm10 + pextrd r9d, xmm10, 2 CryptonightR_template_double_part3: + movq r15, xmm13 + + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r15, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r13, rax + movq rsp, xmm0 mov DWORD PTR [rsp], ebx mov DWORD PTR [rsp+4], esi @@ -414,23 +467,20 @@ CryptonightR_template_double_part3: movq rsi, xmm2 movq rdi, xmm11 movq rbp, xmm12 - movq r15, xmm13 mov rcx, [rsp+104] + mov r9, [rsp+112] mov rax, r8 mul rdi - movq xmm1, rdx - movq xmm0, rax - punpcklqdq xmm1, xmm0 mov rdi, rcx mov r8, rax - pxor xmm1, XMMWORD PTR [rbp+rcx] + movdqu xmm1, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm1 xor ebp, 48 paddq xmm1, xmm8 - xor r8, QWORD PTR [rbp+rcx+8] - xor rdx, QWORD PTR [rbp+rcx] add r13, r8 movdqu xmm2, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm2 add r15, rdx movdqu XMMWORD PTR [rbp+rcx], xmm1 paddq xmm2, xmm4 @@ -438,6 +488,7 @@ CryptonightR_template_double_part3: mov eax, ebp xor rax, 32 movdqu xmm0, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm0 movdqu XMMWORD PTR [rbp+rcx], xmm2 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rcx], xmm0 diff --git a/src/crypto/asm/CryptonightWOW_template.inc b/src/crypto/asm/CryptonightWOW_template.inc new file mode 100644 index 000000000..7183a659f --- /dev/null +++ b/src/crypto/asm/CryptonightWOW_template.inc @@ -0,0 +1,486 @@ +PUBLIC FN_PREFIX(CryptonightWOW_template_part1) +PUBLIC FN_PREFIX(CryptonightWOW_template_mainloop) +PUBLIC FN_PREFIX(CryptonightWOW_template_part2) +PUBLIC FN_PREFIX(CryptonightWOW_template_part3) +PUBLIC FN_PREFIX(CryptonightWOW_template_end) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part1) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_mainloop) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part2) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part3) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part4) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_end) + +ALIGN(64) +FN_PREFIX(CryptonightWOW_template_part1): + mov QWORD PTR [rsp+16], rbx + mov QWORD PTR [rsp+24], rbp + mov QWORD PTR [rsp+32], rsi + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + push rdi + sub rsp, 64 + mov r12, rcx + mov r8, QWORD PTR [r12+32] + mov rdx, r12 + xor r8, QWORD PTR [r12] + mov r15, QWORD PTR [r12+40] + mov r9, r8 + xor r15, QWORD PTR [r12+8] + mov r11, QWORD PTR [r12+224] + mov r12, QWORD PTR [r12+56] + xor r12, QWORD PTR [rdx+24] + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + movaps XMMWORD PTR [rsp+48], xmm6 + movq xmm0, r12 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+16], xmm8 + movaps XMMWORD PTR [rsp], xmm9 + mov r12, QWORD PTR [rdx+88] + xor r12, QWORD PTR [rdx+72] + movq xmm6, rax + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm6, xmm0 + and r9d, 2097136 + movq xmm0, r12 + movq xmm7, rax + punpcklqdq xmm7, xmm0 + mov r10d, r9d + movq xmm9, rsp + mov rsp, r8 + mov r8d, 524288 + + mov ebx, [rdx+96] + mov esi, [rdx+100] + mov edi, [rdx+104] + mov ebp, [rdx+108] + + ALIGN(64) +FN_PREFIX(CryptonightWOW_template_mainloop): + movdqa xmm5, XMMWORD PTR [r9+r11] + movq xmm0, r15 + movq xmm4, rsp + punpcklqdq xmm4, xmm0 + lea rdx, QWORD PTR [r9+r11] + + aesenc xmm5, xmm4 + movd r10d, xmm5 + and r10d, 2097136 + + mov r12d, r9d + mov eax, r9d + xor r9d, 48 + xor r12d, 16 + xor eax, 32 + movdqu xmm0, XMMWORD PTR [r9+r11] + movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm1, XMMWORD PTR [rax+r11] + paddq xmm0, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r12+r11], xmm0 + movq r12, xmm5 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + + movdqa xmm0, xmm5 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [rdx], xmm0 + + lea r13d, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or r13, rdx + + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + + movd eax, xmm6 + movd edx, xmm7 + pextrd r9d, xmm7, 2 + +FN_PREFIX(CryptonightWOW_template_part2): + mov rax, r13 + mul r12 + movq xmm0, rax + movq xmm3, rdx + punpcklqdq xmm3, xmm0 + + mov r9d, r10d + mov r12d, r10d + xor r9d, 16 + xor r12d, 32 + xor r10d, 48 + movdqa xmm1, XMMWORD PTR [r12+r11] + xor rdx, QWORD PTR [r12+r11] + xor rax, QWORD PTR [r11+r12+8] + movdqa xmm2, XMMWORD PTR [r9+r11] + pxor xmm3, xmm2 + paddq xmm7, XMMWORD PTR [r10+r11] + paddq xmm1, xmm4 + paddq xmm3, xmm6 + movdqu XMMWORD PTR [r9+r11], xmm7 + movdqu XMMWORD PTR [r12+r11], xmm3 + movdqu XMMWORD PTR [r10+r11], xmm1 + + movdqa xmm7, xmm6 + add r15, rax + add rsp, rdx + xor r10, 48 + mov QWORD PTR [r10+r11], rsp + xor rsp, r13 + mov r9d, esp + mov QWORD PTR [r10+r11+8], r15 + and r9d, 2097136 + xor r15, r14 + movdqa xmm6, xmm5 + dec r8d + jnz FN_PREFIX(CryptonightWOW_template_mainloop) + +FN_PREFIX(CryptonightWOW_template_part3): + movq rsp, xmm9 + + mov rbx, QWORD PTR [rsp+136] + mov rbp, QWORD PTR [rsp+144] + mov rsi, QWORD PTR [rsp+152] + movaps xmm6, XMMWORD PTR [rsp+48] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+16] + movaps xmm9, XMMWORD PTR [rsp] + add rsp, 64 + pop rdi + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + ret 0 +FN_PREFIX(CryptonightWOW_template_end): + +ALIGN(64) +FN_PREFIX(CryptonightWOW_template_double_part1): + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 320 + mov r14, QWORD PTR [rcx+32] + mov r8, rcx + xor r14, QWORD PTR [rcx] + mov r12, QWORD PTR [rcx+40] + mov ebx, r14d + mov rsi, QWORD PTR [rcx+224] + and ebx, 2097136 + xor r12, QWORD PTR [rcx+8] + mov rcx, QWORD PTR [rcx+56] + xor rcx, QWORD PTR [r8+24] + mov rax, QWORD PTR [r8+48] + xor rax, QWORD PTR [r8+16] + mov r15, QWORD PTR [rdx+32] + xor r15, QWORD PTR [rdx] + movq xmm0, rcx + mov rcx, QWORD PTR [r8+88] + xor rcx, QWORD PTR [r8+72] + mov r13, QWORD PTR [rdx+40] + mov rdi, QWORD PTR [rdx+224] + xor r13, QWORD PTR [rdx+8] + movaps XMMWORD PTR [rsp+160], xmm6 + movaps XMMWORD PTR [rsp+176], xmm7 + movaps XMMWORD PTR [rsp+192], xmm8 + movaps XMMWORD PTR [rsp+208], xmm9 + movaps XMMWORD PTR [rsp+224], xmm10 + movaps XMMWORD PTR [rsp+240], xmm11 + movaps XMMWORD PTR [rsp+256], xmm12 + movaps XMMWORD PTR [rsp+272], xmm13 + movaps XMMWORD PTR [rsp+288], xmm14 + movaps XMMWORD PTR [rsp+304], xmm15 + movq xmm7, rax + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + + movaps xmm1, XMMWORD PTR [rdx+96] + movaps xmm2, XMMWORD PTR [r8+96] + movaps XMMWORD PTR [rsp], xmm1 + movaps XMMWORD PTR [rsp+16], xmm2 + + mov r8d, r15d + punpcklqdq xmm7, xmm0 + movq xmm0, rcx + mov rcx, QWORD PTR [rdx+56] + xor rcx, QWORD PTR [rdx+24] + movq xmm9, rax + mov QWORD PTR [rsp+128], rsi + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + punpcklqdq xmm9, xmm0 + movq xmm0, rcx + mov rcx, QWORD PTR [rdx+88] + xor rcx, QWORD PTR [rdx+72] + movq xmm8, rax + mov QWORD PTR [rsp+136], rdi + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm8, xmm0 + and r8d, 2097136 + movq xmm0, rcx + mov r11d, 524288 + movq xmm10, rax + punpcklqdq xmm10, xmm0 + + movq xmm14, QWORD PTR [rsp+128] + movq xmm15, QWORD PTR [rsp+136] + + ALIGN(64) +FN_PREFIX(CryptonightWOW_template_double_mainloop): + movdqu xmm6, XMMWORD PTR [rbx+rsi] + movq xmm0, r12 + mov ecx, ebx + movq xmm3, r14 + punpcklqdq xmm3, xmm0 + xor ebx, 16 + aesenc xmm6, xmm3 + movq rdx, xmm6 + movq xmm4, r15 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + xor ebx, 48 + paddq xmm0, xmm7 + movdqu xmm1, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm0 + paddq xmm1, xmm3 + xor ebx, 16 + mov eax, ebx + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm1 + paddq xmm0, xmm9 + movdqu XMMWORD PTR [rax+rsi], xmm0 + movdqa xmm0, xmm6 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [rcx+rsi], xmm0 + mov esi, edx + movdqu xmm5, XMMWORD PTR [r8+rdi] + and esi, 2097136 + mov ecx, r8d + movq xmm0, r13 + punpcklqdq xmm4, xmm0 + xor r8d, 16 + aesenc xmm5, xmm4 + movdqu xmm0, XMMWORD PTR [r8+rdi] + xor r8d, 48 + paddq xmm0, xmm8 + movdqu xmm1, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm0 + paddq xmm1, xmm4 + xor r8d, 16 + mov eax, r8d + xor rax, 32 + movdqu xmm0, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm1 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rdi], xmm0 + movdqa xmm0, xmm5 + pxor xmm0, xmm8 + movdqu XMMWORD PTR [rcx+rdi], xmm0 + movq rdi, xmm5 + movq rcx, xmm14 + mov ebp, edi + mov r8, QWORD PTR [rcx+rsi] + mov r10, QWORD PTR [rcx+rsi+8] + lea r9, QWORD PTR [rcx+rsi] + xor esi, 16 + + movq xmm0, rsp + movq xmm1, rsi + movq xmm2, rdi + movq xmm11, rbp + movq xmm12, r15 + movq xmm13, rdx + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp+16] + mov esi, DWORD PTR [rsp+20] + mov edi, DWORD PTR [rsp+24] + mov ebp, DWORD PTR [rsp+28] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + xor r8, rax + + movd esp, xmm3 + pextrd r15d, xmm3, 2 + movd eax, xmm7 + movd edx, xmm9 + pextrd r9d, xmm9, 2 + +FN_PREFIX(CryptonightWOW_template_double_part2): + + movq rsp, xmm0 + mov DWORD PTR [rsp+16], ebx + mov DWORD PTR [rsp+20], esi + mov DWORD PTR [rsp+24], edi + mov DWORD PTR [rsp+28], ebp + + movq rsi, xmm1 + movq rdi, xmm2 + movq rbp, xmm11 + movq r15, xmm12 + movq rdx, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rbx, r8 + mov rax, r8 + mul rdx + and ebp, 2097136 + mov r8, rax + movq xmm1, rdx + movq xmm0, r8 + punpcklqdq xmm1, xmm0 + pxor xmm1, XMMWORD PTR [rcx+rsi] + xor esi, 48 + paddq xmm1, xmm7 + movdqu xmm2, XMMWORD PTR [rsi+rcx] + xor rdx, QWORD PTR [rsi+rcx] + paddq xmm2, xmm3 + xor r8, QWORD PTR [rsi+rcx+8] + movdqu XMMWORD PTR [rsi+rcx], xmm1 + xor esi, 16 + mov eax, esi + mov rsi, rcx + movdqu xmm0, XMMWORD PTR [rax+rcx] + movdqu XMMWORD PTR [rax+rcx], xmm2 + paddq xmm0, xmm9 + add r12, r8 + xor rax, 32 + add r14, rdx + movdqa xmm9, xmm7 + movdqa xmm7, xmm6 + movdqu XMMWORD PTR [rax+rcx], xmm0 + mov QWORD PTR [r9+8], r12 + xor r12, r10 + mov QWORD PTR [r9], r14 + movq rcx, xmm15 + xor r14, rbx + mov r10d, ebp + mov ebx, r14d + xor ebp, 16 + and ebx, 2097136 + mov r8, QWORD PTR [r10+rcx] + mov r9, QWORD PTR [r10+rcx+8] + + movq xmm0, rsp + movq xmm1, rbx + movq xmm2, rsi + movq xmm11, rdi + movq xmm12, rbp + movq xmm13, r15 + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp] + mov esi, DWORD PTR [rsp+4] + mov edi, DWORD PTR [rsp+8] + mov ebp, DWORD PTR [rsp+12] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + + xor r8, rax + movq xmm3, r8 + + movd esp, xmm4 + pextrd r15d, xmm4, 2 + movd eax, xmm8 + movd edx, xmm10 + pextrd r9d, xmm10, 2 + +FN_PREFIX(CryptonightWOW_template_double_part3): + + movq rsp, xmm0 + mov DWORD PTR [rsp], ebx + mov DWORD PTR [rsp+4], esi + mov DWORD PTR [rsp+8], edi + mov DWORD PTR [rsp+12], ebp + + movq rbx, xmm1 + movq rsi, xmm2 + movq rdi, xmm11 + movq rbp, xmm12 + movq r15, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rax, r8 + mul rdi + movq xmm1, rdx + movq xmm0, rax + punpcklqdq xmm1, xmm0 + mov rdi, rcx + mov r8, rax + pxor xmm1, XMMWORD PTR [rbp+rcx] + xor ebp, 48 + paddq xmm1, xmm8 + xor r8, QWORD PTR [rbp+rcx+8] + xor rdx, QWORD PTR [rbp+rcx] + add r13, r8 + movdqu xmm2, XMMWORD PTR [rbp+rcx] + add r15, rdx + movdqu XMMWORD PTR [rbp+rcx], xmm1 + paddq xmm2, xmm4 + xor ebp, 16 + mov eax, ebp + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbp+rcx] + movdqu XMMWORD PTR [rbp+rcx], xmm2 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rcx], xmm0 + movq rax, xmm3 + movdqa xmm10, xmm8 + mov QWORD PTR [r10+rcx], r15 + movdqa xmm8, xmm5 + xor r15, rax + mov QWORD PTR [r10+rcx+8], r13 + mov r8d, r15d + xor r13, r9 + and r8d, 2097136 + dec r11d + jnz FN_PREFIX(CryptonightWOW_template_double_mainloop) + +FN_PREFIX(CryptonightWOW_template_double_part4): + + mov rbx, QWORD PTR [rsp+400] + movaps xmm6, XMMWORD PTR [rsp+160] + movaps xmm7, XMMWORD PTR [rsp+176] + movaps xmm8, XMMWORD PTR [rsp+192] + movaps xmm9, XMMWORD PTR [rsp+208] + movaps xmm10, XMMWORD PTR [rsp+224] + movaps xmm11, XMMWORD PTR [rsp+240] + movaps xmm12, XMMWORD PTR [rsp+256] + movaps xmm13, XMMWORD PTR [rsp+272] + movaps xmm14, XMMWORD PTR [rsp+288] + movaps xmm15, XMMWORD PTR [rsp+304] + add rsp, 320 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + ret 0 +FN_PREFIX(CryptonightWOW_template_double_end): diff --git a/src/crypto/asm/CryptonightWOW_template_win.inc b/src/crypto/asm/CryptonightWOW_template_win.inc new file mode 100644 index 000000000..c5652e278 --- /dev/null +++ b/src/crypto/asm/CryptonightWOW_template_win.inc @@ -0,0 +1,486 @@ +PUBLIC CryptonightWOW_template_part1 +PUBLIC CryptonightWOW_template_mainloop +PUBLIC CryptonightWOW_template_part2 +PUBLIC CryptonightWOW_template_part3 +PUBLIC CryptonightWOW_template_end +PUBLIC CryptonightWOW_template_double_part1 +PUBLIC CryptonightWOW_template_double_mainloop +PUBLIC CryptonightWOW_template_double_part2 +PUBLIC CryptonightWOW_template_double_part3 +PUBLIC CryptonightWOW_template_double_part4 +PUBLIC CryptonightWOW_template_double_end + +ALIGN(64) +CryptonightWOW_template_part1: + mov QWORD PTR [rsp+16], rbx + mov QWORD PTR [rsp+24], rbp + mov QWORD PTR [rsp+32], rsi + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + push rdi + sub rsp, 64 + mov r12, rcx + mov r8, QWORD PTR [r12+32] + mov rdx, r12 + xor r8, QWORD PTR [r12] + mov r15, QWORD PTR [r12+40] + mov r9, r8 + xor r15, QWORD PTR [r12+8] + mov r11, QWORD PTR [r12+224] + mov r12, QWORD PTR [r12+56] + xor r12, QWORD PTR [rdx+24] + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + movaps XMMWORD PTR [rsp+48], xmm6 + movq xmm0, r12 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+16], xmm8 + movaps XMMWORD PTR [rsp], xmm9 + mov r12, QWORD PTR [rdx+88] + xor r12, QWORD PTR [rdx+72] + movq xmm6, rax + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm6, xmm0 + and r9d, 2097136 + movq xmm0, r12 + movq xmm7, rax + punpcklqdq xmm7, xmm0 + mov r10d, r9d + movq xmm9, rsp + mov rsp, r8 + mov r8d, 524288 + + mov ebx, [rdx+96] + mov esi, [rdx+100] + mov edi, [rdx+104] + mov ebp, [rdx+108] + + ALIGN(64) +CryptonightWOW_template_mainloop: + movdqa xmm5, XMMWORD PTR [r9+r11] + movq xmm0, r15 + movq xmm4, rsp + punpcklqdq xmm4, xmm0 + lea rdx, QWORD PTR [r9+r11] + + aesenc xmm5, xmm4 + movd r10d, xmm5 + and r10d, 2097136 + + mov r12d, r9d + mov eax, r9d + xor r9d, 48 + xor r12d, 16 + xor eax, 32 + movdqu xmm0, XMMWORD PTR [r9+r11] + movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm1, XMMWORD PTR [rax+r11] + paddq xmm0, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r12+r11], xmm0 + movq r12, xmm5 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + + movdqa xmm0, xmm5 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [rdx], xmm0 + + lea r13d, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or r13, rdx + + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + + movd eax, xmm6 + movd edx, xmm7 + pextrd r9d, xmm7, 2 + +CryptonightWOW_template_part2: + mov rax, r13 + mul r12 + movq xmm0, rax + movq xmm3, rdx + punpcklqdq xmm3, xmm0 + + mov r9d, r10d + mov r12d, r10d + xor r9d, 16 + xor r12d, 32 + xor r10d, 48 + movdqa xmm1, XMMWORD PTR [r12+r11] + xor rdx, QWORD PTR [r12+r11] + xor rax, QWORD PTR [r11+r12+8] + movdqa xmm2, XMMWORD PTR [r9+r11] + pxor xmm3, xmm2 + paddq xmm7, XMMWORD PTR [r10+r11] + paddq xmm1, xmm4 + paddq xmm3, xmm6 + movdqu XMMWORD PTR [r9+r11], xmm7 + movdqu XMMWORD PTR [r12+r11], xmm3 + movdqu XMMWORD PTR [r10+r11], xmm1 + + movdqa xmm7, xmm6 + add r15, rax + add rsp, rdx + xor r10, 48 + mov QWORD PTR [r10+r11], rsp + xor rsp, r13 + mov r9d, esp + mov QWORD PTR [r10+r11+8], r15 + and r9d, 2097136 + xor r15, r14 + movdqa xmm6, xmm5 + dec r8d + jnz CryptonightWOW_template_mainloop + +CryptonightWOW_template_part3: + movq rsp, xmm9 + + mov rbx, QWORD PTR [rsp+136] + mov rbp, QWORD PTR [rsp+144] + mov rsi, QWORD PTR [rsp+152] + movaps xmm6, XMMWORD PTR [rsp+48] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+16] + movaps xmm9, XMMWORD PTR [rsp] + add rsp, 64 + pop rdi + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + ret 0 +CryptonightWOW_template_end: + +ALIGN(64) +CryptonightWOW_template_double_part1: + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 320 + mov r14, QWORD PTR [rcx+32] + mov r8, rcx + xor r14, QWORD PTR [rcx] + mov r12, QWORD PTR [rcx+40] + mov ebx, r14d + mov rsi, QWORD PTR [rcx+224] + and ebx, 2097136 + xor r12, QWORD PTR [rcx+8] + mov rcx, QWORD PTR [rcx+56] + xor rcx, QWORD PTR [r8+24] + mov rax, QWORD PTR [r8+48] + xor rax, QWORD PTR [r8+16] + mov r15, QWORD PTR [rdx+32] + xor r15, QWORD PTR [rdx] + movq xmm0, rcx + mov rcx, QWORD PTR [r8+88] + xor rcx, QWORD PTR [r8+72] + mov r13, QWORD PTR [rdx+40] + mov rdi, QWORD PTR [rdx+224] + xor r13, QWORD PTR [rdx+8] + movaps XMMWORD PTR [rsp+160], xmm6 + movaps XMMWORD PTR [rsp+176], xmm7 + movaps XMMWORD PTR [rsp+192], xmm8 + movaps XMMWORD PTR [rsp+208], xmm9 + movaps XMMWORD PTR [rsp+224], xmm10 + movaps XMMWORD PTR [rsp+240], xmm11 + movaps XMMWORD PTR [rsp+256], xmm12 + movaps XMMWORD PTR [rsp+272], xmm13 + movaps XMMWORD PTR [rsp+288], xmm14 + movaps XMMWORD PTR [rsp+304], xmm15 + movq xmm7, rax + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + + movaps xmm1, XMMWORD PTR [rdx+96] + movaps xmm2, XMMWORD PTR [r8+96] + movaps XMMWORD PTR [rsp], xmm1 + movaps XMMWORD PTR [rsp+16], xmm2 + + mov r8d, r15d + punpcklqdq xmm7, xmm0 + movq xmm0, rcx + mov rcx, QWORD PTR [rdx+56] + xor rcx, QWORD PTR [rdx+24] + movq xmm9, rax + mov QWORD PTR [rsp+128], rsi + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + punpcklqdq xmm9, xmm0 + movq xmm0, rcx + mov rcx, QWORD PTR [rdx+88] + xor rcx, QWORD PTR [rdx+72] + movq xmm8, rax + mov QWORD PTR [rsp+136], rdi + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm8, xmm0 + and r8d, 2097136 + movq xmm0, rcx + mov r11d, 524288 + movq xmm10, rax + punpcklqdq xmm10, xmm0 + + movq xmm14, QWORD PTR [rsp+128] + movq xmm15, QWORD PTR [rsp+136] + + ALIGN(64) +CryptonightWOW_template_double_mainloop: + movdqu xmm6, XMMWORD PTR [rbx+rsi] + movq xmm0, r12 + mov ecx, ebx + movq xmm3, r14 + punpcklqdq xmm3, xmm0 + xor ebx, 16 + aesenc xmm6, xmm3 + movq rdx, xmm6 + movq xmm4, r15 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + xor ebx, 48 + paddq xmm0, xmm7 + movdqu xmm1, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm0 + paddq xmm1, xmm3 + xor ebx, 16 + mov eax, ebx + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm1 + paddq xmm0, xmm9 + movdqu XMMWORD PTR [rax+rsi], xmm0 + movdqa xmm0, xmm6 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [rcx+rsi], xmm0 + mov esi, edx + movdqu xmm5, XMMWORD PTR [r8+rdi] + and esi, 2097136 + mov ecx, r8d + movq xmm0, r13 + punpcklqdq xmm4, xmm0 + xor r8d, 16 + aesenc xmm5, xmm4 + movdqu xmm0, XMMWORD PTR [r8+rdi] + xor r8d, 48 + paddq xmm0, xmm8 + movdqu xmm1, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm0 + paddq xmm1, xmm4 + xor r8d, 16 + mov eax, r8d + xor rax, 32 + movdqu xmm0, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm1 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rdi], xmm0 + movdqa xmm0, xmm5 + pxor xmm0, xmm8 + movdqu XMMWORD PTR [rcx+rdi], xmm0 + movq rdi, xmm5 + movq rcx, xmm14 + mov ebp, edi + mov r8, QWORD PTR [rcx+rsi] + mov r10, QWORD PTR [rcx+rsi+8] + lea r9, QWORD PTR [rcx+rsi] + xor esi, 16 + + movq xmm0, rsp + movq xmm1, rsi + movq xmm2, rdi + movq xmm11, rbp + movq xmm12, r15 + movq xmm13, rdx + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp+16] + mov esi, DWORD PTR [rsp+20] + mov edi, DWORD PTR [rsp+24] + mov ebp, DWORD PTR [rsp+28] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + xor r8, rax + + movd esp, xmm3 + pextrd r15d, xmm3, 2 + movd eax, xmm7 + movd edx, xmm9 + pextrd r9d, xmm9, 2 + +CryptonightWOW_template_double_part2: + + movq rsp, xmm0 + mov DWORD PTR [rsp+16], ebx + mov DWORD PTR [rsp+20], esi + mov DWORD PTR [rsp+24], edi + mov DWORD PTR [rsp+28], ebp + + movq rsi, xmm1 + movq rdi, xmm2 + movq rbp, xmm11 + movq r15, xmm12 + movq rdx, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rbx, r8 + mov rax, r8 + mul rdx + and ebp, 2097136 + mov r8, rax + movq xmm1, rdx + movq xmm0, r8 + punpcklqdq xmm1, xmm0 + pxor xmm1, XMMWORD PTR [rcx+rsi] + xor esi, 48 + paddq xmm1, xmm7 + movdqu xmm2, XMMWORD PTR [rsi+rcx] + xor rdx, QWORD PTR [rsi+rcx] + paddq xmm2, xmm3 + xor r8, QWORD PTR [rsi+rcx+8] + movdqu XMMWORD PTR [rsi+rcx], xmm1 + xor esi, 16 + mov eax, esi + mov rsi, rcx + movdqu xmm0, XMMWORD PTR [rax+rcx] + movdqu XMMWORD PTR [rax+rcx], xmm2 + paddq xmm0, xmm9 + add r12, r8 + xor rax, 32 + add r14, rdx + movdqa xmm9, xmm7 + movdqa xmm7, xmm6 + movdqu XMMWORD PTR [rax+rcx], xmm0 + mov QWORD PTR [r9+8], r12 + xor r12, r10 + mov QWORD PTR [r9], r14 + movq rcx, xmm15 + xor r14, rbx + mov r10d, ebp + mov ebx, r14d + xor ebp, 16 + and ebx, 2097136 + mov r8, QWORD PTR [r10+rcx] + mov r9, QWORD PTR [r10+rcx+8] + + movq xmm0, rsp + movq xmm1, rbx + movq xmm2, rsi + movq xmm11, rdi + movq xmm12, rbp + movq xmm13, r15 + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp] + mov esi, DWORD PTR [rsp+4] + mov edi, DWORD PTR [rsp+8] + mov ebp, DWORD PTR [rsp+12] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + + xor r8, rax + movq xmm3, r8 + + movd esp, xmm4 + pextrd r15d, xmm4, 2 + movd eax, xmm8 + movd edx, xmm10 + pextrd r9d, xmm10, 2 + +CryptonightWOW_template_double_part3: + + movq rsp, xmm0 + mov DWORD PTR [rsp], ebx + mov DWORD PTR [rsp+4], esi + mov DWORD PTR [rsp+8], edi + mov DWORD PTR [rsp+12], ebp + + movq rbx, xmm1 + movq rsi, xmm2 + movq rdi, xmm11 + movq rbp, xmm12 + movq r15, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rax, r8 + mul rdi + movq xmm1, rdx + movq xmm0, rax + punpcklqdq xmm1, xmm0 + mov rdi, rcx + mov r8, rax + pxor xmm1, XMMWORD PTR [rbp+rcx] + xor ebp, 48 + paddq xmm1, xmm8 + xor r8, QWORD PTR [rbp+rcx+8] + xor rdx, QWORD PTR [rbp+rcx] + add r13, r8 + movdqu xmm2, XMMWORD PTR [rbp+rcx] + add r15, rdx + movdqu XMMWORD PTR [rbp+rcx], xmm1 + paddq xmm2, xmm4 + xor ebp, 16 + mov eax, ebp + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbp+rcx] + movdqu XMMWORD PTR [rbp+rcx], xmm2 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rcx], xmm0 + movq rax, xmm3 + movdqa xmm10, xmm8 + mov QWORD PTR [r10+rcx], r15 + movdqa xmm8, xmm5 + xor r15, rax + mov QWORD PTR [r10+rcx+8], r13 + mov r8d, r15d + xor r13, r9 + and r8d, 2097136 + dec r11d + jnz CryptonightWOW_template_double_mainloop + +CryptonightWOW_template_double_part4: + + mov rbx, QWORD PTR [rsp+400] + movaps xmm6, XMMWORD PTR [rsp+160] + movaps xmm7, XMMWORD PTR [rsp+176] + movaps xmm8, XMMWORD PTR [rsp+192] + movaps xmm9, XMMWORD PTR [rsp+208] + movaps xmm10, XMMWORD PTR [rsp+224] + movaps xmm11, XMMWORD PTR [rsp+240] + movaps xmm12, XMMWORD PTR [rsp+256] + movaps xmm13, XMMWORD PTR [rsp+272] + movaps xmm14, XMMWORD PTR [rsp+288] + movaps xmm15, XMMWORD PTR [rsp+304] + add rsp, 320 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + ret 0 +CryptonightWOW_template_double_end: diff --git a/src/crypto/asm/win64/CryptonightR_template.S b/src/crypto/asm/win64/CryptonightR_template.S index e8478beb9..4390bd455 100644 --- a/src/crypto/asm/win64/CryptonightR_template.S +++ b/src/crypto/asm/win64/CryptonightR_template.S @@ -538,16 +538,16 @@ FN_PREFIX(CryptonightR_instruction1): FN_PREFIX(CryptonightR_instruction2): imul rbx, rbx FN_PREFIX(CryptonightR_instruction3): - add rbx, rbx + add rbx, r9 add rbx, 2147483647 FN_PREFIX(CryptonightR_instruction4): - sub rbx, rbx + sub rbx, r9 FN_PREFIX(CryptonightR_instruction5): ror ebx, cl FN_PREFIX(CryptonightR_instruction6): rol ebx, cl FN_PREFIX(CryptonightR_instruction7): - xor rbx, rbx + xor rbx, r9 FN_PREFIX(CryptonightR_instruction8): imul rsi, rbx FN_PREFIX(CryptonightR_instruction9): @@ -623,16 +623,16 @@ FN_PREFIX(CryptonightR_instruction41): FN_PREFIX(CryptonightR_instruction42): imul rsi, rsi FN_PREFIX(CryptonightR_instruction43): - add rsi, rsi + add rsi, r9 add rsi, 2147483647 FN_PREFIX(CryptonightR_instruction44): - sub rsi, rsi + sub rsi, r9 FN_PREFIX(CryptonightR_instruction45): ror esi, cl FN_PREFIX(CryptonightR_instruction46): rol esi, cl FN_PREFIX(CryptonightR_instruction47): - xor rsi, rsi + xor rsi, r9 FN_PREFIX(CryptonightR_instruction48): imul rdi, rsi FN_PREFIX(CryptonightR_instruction49): @@ -708,16 +708,16 @@ FN_PREFIX(CryptonightR_instruction81): FN_PREFIX(CryptonightR_instruction82): imul rdi, rdi FN_PREFIX(CryptonightR_instruction83): - add rdi, rdi + add rdi, r9 add rdi, 2147483647 FN_PREFIX(CryptonightR_instruction84): - sub rdi, rdi + sub rdi, r9 FN_PREFIX(CryptonightR_instruction85): ror edi, cl FN_PREFIX(CryptonightR_instruction86): rol edi, cl FN_PREFIX(CryptonightR_instruction87): - xor rdi, rdi + xor rdi, r9 FN_PREFIX(CryptonightR_instruction88): imul rbp, rdi FN_PREFIX(CryptonightR_instruction89): @@ -793,16 +793,16 @@ FN_PREFIX(CryptonightR_instruction121): FN_PREFIX(CryptonightR_instruction122): imul rbp, rbp FN_PREFIX(CryptonightR_instruction123): - add rbp, rbp + add rbp, r9 add rbp, 2147483647 FN_PREFIX(CryptonightR_instruction124): - sub rbp, rbp + sub rbp, r9 FN_PREFIX(CryptonightR_instruction125): ror ebp, cl FN_PREFIX(CryptonightR_instruction126): rol ebp, cl FN_PREFIX(CryptonightR_instruction127): - xor rbp, rbp + xor rbp, r9 FN_PREFIX(CryptonightR_instruction128): imul rbx, rsp FN_PREFIX(CryptonightR_instruction129): diff --git a/src/crypto/asm/win64/CryptonightR_template.asm b/src/crypto/asm/win64/CryptonightR_template.asm index ec8ad5afe..a16cf3289 100644 --- a/src/crypto/asm/win64/CryptonightR_template.asm +++ b/src/crypto/asm/win64/CryptonightR_template.asm @@ -525,16 +525,16 @@ CryptonightR_instruction1: CryptonightR_instruction2: imul rbx, rbx CryptonightR_instruction3: - add rbx, rbx + add rbx, r9 add rbx, 2147483647 CryptonightR_instruction4: - sub rbx, rbx + sub rbx, r9 CryptonightR_instruction5: ror ebx, cl CryptonightR_instruction6: rol ebx, cl CryptonightR_instruction7: - xor rbx, rbx + xor rbx, r9 CryptonightR_instruction8: imul rsi, rbx CryptonightR_instruction9: @@ -610,16 +610,16 @@ CryptonightR_instruction41: CryptonightR_instruction42: imul rsi, rsi CryptonightR_instruction43: - add rsi, rsi + add rsi, r9 add rsi, 2147483647 CryptonightR_instruction44: - sub rsi, rsi + sub rsi, r9 CryptonightR_instruction45: ror esi, cl CryptonightR_instruction46: rol esi, cl CryptonightR_instruction47: - xor rsi, rsi + xor rsi, r9 CryptonightR_instruction48: imul rdi, rsi CryptonightR_instruction49: @@ -695,16 +695,16 @@ CryptonightR_instruction81: CryptonightR_instruction82: imul rdi, rdi CryptonightR_instruction83: - add rdi, rdi + add rdi, r9 add rdi, 2147483647 CryptonightR_instruction84: - sub rdi, rdi + sub rdi, r9 CryptonightR_instruction85: ror edi, cl CryptonightR_instruction86: rol edi, cl CryptonightR_instruction87: - xor rdi, rdi + xor rdi, r9 CryptonightR_instruction88: imul rbp, rdi CryptonightR_instruction89: @@ -780,16 +780,16 @@ CryptonightR_instruction121: CryptonightR_instruction122: imul rbp, rbp CryptonightR_instruction123: - add rbp, rbp + add rbp, r9 add rbp, 2147483647 CryptonightR_instruction124: - sub rbp, rbp + sub rbp, r9 CryptonightR_instruction125: ror ebp, cl CryptonightR_instruction126: rol ebp, cl CryptonightR_instruction127: - xor rbp, rbp + xor rbp, r9 CryptonightR_instruction128: imul rbx, rsp CryptonightR_instruction129: diff --git a/src/crypto/asm/win64/CryptonightR_template.inc b/src/crypto/asm/win64/CryptonightR_template.inc index f6e6ef451..1dae434a2 100644 --- a/src/crypto/asm/win64/CryptonightR_template.inc +++ b/src/crypto/asm/win64/CryptonightR_template.inc @@ -10,6 +10,7 @@ PUBLIC FN_PREFIX(CryptonightR_template_double_part3) PUBLIC FN_PREFIX(CryptonightR_template_double_part4) PUBLIC FN_PREFIX(CryptonightR_template_double_end) +ALIGN(64) FN_PREFIX(CryptonightR_template_part1): mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp @@ -68,8 +69,6 @@ FN_PREFIX(CryptonightR_template_mainloop): lea rdx, QWORD PTR [r9+r11] aesenc xmm5, xmm4 - movd r10d, xmm5 - and r10d, 2097136 mov r12d, r9d mov eax, r9d @@ -77,16 +76,23 @@ FN_PREFIX(CryptonightR_template_mainloop): xor r12d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] + movaps xmm3, xmm0 movdqu xmm2, XMMWORD PTR [r12+r11] movdqu xmm1, XMMWORD PTR [rax+r11] - paddq xmm0, xmm7 + pxor xmm0, xmm2 + pxor xmm5, xmm1 + pxor xmm5, xmm0 + paddq xmm3, xmm7 paddq xmm2, xmm6 paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm0 - movd r12, xmm5 + movdqu XMMWORD PTR [r12+r11], xmm3 movdqu XMMWORD PTR [rax+r11], xmm2 movdqu XMMWORD PTR [r9+r11], xmm1 + movd r12, xmm5 + movd r10d, xmm5 + and r10d, 2097136 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -101,13 +107,23 @@ FN_PREFIX(CryptonightR_template_mainloop): movd eax, xmm6 movd edx, xmm7 + pextrd r9d, xmm7, 2 FN_PREFIX(CryptonightR_template_part2): + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor rsp, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r15, rax + mov rax, r13 mul r12 - movd xmm0, rax - movd xmm3, rdx - punpcklqdq xmm3, xmm0 mov r9d, r10d mov r12d, r10d @@ -115,16 +131,18 @@ FN_PREFIX(CryptonightR_template_part2): xor r12d, 32 xor r10d, 48 movdqa xmm1, XMMWORD PTR [r12+r11] - xor rdx, QWORD PTR [r12+r11] - xor rax, QWORD PTR [r11+r12+8] + movaps xmm3, xmm1 movdqa xmm2, XMMWORD PTR [r9+r11] - pxor xmm3, xmm2 - paddq xmm7, XMMWORD PTR [r10+r11] - paddq xmm1, xmm4 - paddq xmm3, xmm6 - movdqu XMMWORD PTR [r9+r11], xmm7 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [r10+r11], xmm1 + movdqa xmm0, XMMWORD PTR [r10+r11] + pxor xmm1, xmm2 + pxor xmm5, xmm0 + pxor xmm5, xmm1 + paddq xmm3, xmm4 + paddq xmm2, xmm6 + paddq xmm0, xmm7 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqu XMMWORD PTR [r12+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 add r15, rax @@ -247,18 +265,21 @@ FN_PREFIX(CryptonightR_template_double_mainloop): punpcklqdq xmm3, xmm0 xor ebx, 16 aesenc xmm6, xmm3 - movd rdx, xmm6 movd xmm4, r15 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 xor ebx, 48 paddq xmm0, xmm7 movdqu xmm1, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm1 movdqu XMMWORD PTR [rbx+rsi], xmm0 paddq xmm1, xmm3 xor ebx, 16 mov eax, ebx xor rax, 32 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 + movd rdx, xmm6 movdqu XMMWORD PTR [rbx+rsi], xmm1 paddq xmm0, xmm9 movdqu XMMWORD PTR [rax+rsi], xmm0 @@ -274,15 +295,18 @@ FN_PREFIX(CryptonightR_template_double_mainloop): xor r8d, 16 aesenc xmm5, xmm4 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 xor r8d, 48 paddq xmm0, xmm8 movdqu xmm1, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm1 movdqu XMMWORD PTR [r8+rdi], xmm0 paddq xmm1, xmm4 xor r8d, 16 mov eax, r8d xor rax, 32 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 movdqu XMMWORD PTR [r8+rdi], xmm1 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rdi], xmm0 @@ -303,7 +327,8 @@ FN_PREFIX(CryptonightR_template_double_mainloop): movd xmm11, rbp movd xmm12, r15 movd xmm13, rdx - mov [rsp+112], rcx + mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp+16] mov esi, DWORD PTR [rsp+20] @@ -320,9 +345,22 @@ FN_PREFIX(CryptonightR_template_double_mainloop): pextrd r15d, xmm3, 2 movd eax, xmm7 movd edx, xmm9 + pextrd r9d, xmm9, 2 FN_PREFIX(CryptonightR_template_double_part2): + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r14, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r12, rax + movd rsp, xmm0 mov DWORD PTR [rsp+16], ebx mov DWORD PTR [rsp+20], esi @@ -334,28 +372,27 @@ FN_PREFIX(CryptonightR_template_double_part2): movd rbp, xmm11 movd r15, xmm12 movd rdx, xmm13 - mov rcx, [rsp+112] + mov rcx, [rsp+104] + mov r9, [rsp+112] mov rbx, r8 mov rax, r8 mul rdx and ebp, 2097136 mov r8, rax - movd xmm1, rdx - movd xmm0, r8 - punpcklqdq xmm1, xmm0 - pxor xmm1, XMMWORD PTR [rcx+rsi] + movdqu xmm1, XMMWORD PTR [rcx+rsi] + pxor xmm6, xmm1 xor esi, 48 paddq xmm1, xmm7 movdqu xmm2, XMMWORD PTR [rsi+rcx] - xor rdx, QWORD PTR [rsi+rcx] + pxor xmm6, xmm2 paddq xmm2, xmm3 - xor r8, QWORD PTR [rsi+rcx+8] movdqu XMMWORD PTR [rsi+rcx], xmm1 xor esi, 16 mov eax, esi mov rsi, rcx movdqu xmm0, XMMWORD PTR [rax+rcx] + pxor xmm6, xmm0 movdqu XMMWORD PTR [rax+rcx], xmm2 paddq xmm0, xmm9 add r12, r8 @@ -383,6 +420,7 @@ FN_PREFIX(CryptonightR_template_double_part2): movd xmm12, rbp movd xmm13, r15 mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp] mov esi, DWORD PTR [rsp+4] @@ -401,9 +439,24 @@ FN_PREFIX(CryptonightR_template_double_part2): pextrd r15d, xmm4, 2 movd eax, xmm8 movd edx, xmm10 + pextrd r9d, xmm10, 2 FN_PREFIX(CryptonightR_template_double_part3): + movd r15, xmm13 + + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r15, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r13, rax + movd rsp, xmm0 mov DWORD PTR [rsp], ebx mov DWORD PTR [rsp+4], esi @@ -414,23 +467,20 @@ FN_PREFIX(CryptonightR_template_double_part3): movd rsi, xmm2 movd rdi, xmm11 movd rbp, xmm12 - movd r15, xmm13 mov rcx, [rsp+104] + mov r9, [rsp+112] mov rax, r8 mul rdi - movd xmm1, rdx - movd xmm0, rax - punpcklqdq xmm1, xmm0 mov rdi, rcx mov r8, rax - pxor xmm1, XMMWORD PTR [rbp+rcx] + movdqu xmm1, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm1 xor ebp, 48 paddq xmm1, xmm8 - xor r8, QWORD PTR [rbp+rcx+8] - xor rdx, QWORD PTR [rbp+rcx] add r13, r8 movdqu xmm2, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm2 add r15, rdx movdqu XMMWORD PTR [rbp+rcx], xmm1 paddq xmm2, xmm4 @@ -438,6 +488,7 @@ FN_PREFIX(CryptonightR_template_double_part3): mov eax, ebp xor rax, 32 movdqu xmm0, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm0 movdqu XMMWORD PTR [rbp+rcx], xmm2 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rcx], xmm0 diff --git a/src/crypto/asm/win64/CryptonightR_template_win.inc b/src/crypto/asm/win64/CryptonightR_template_win.inc index b0217e046..2f2d71a25 100644 --- a/src/crypto/asm/win64/CryptonightR_template_win.inc +++ b/src/crypto/asm/win64/CryptonightR_template_win.inc @@ -10,6 +10,7 @@ PUBLIC CryptonightR_template_double_part3 PUBLIC CryptonightR_template_double_part4 PUBLIC CryptonightR_template_double_end +ALIGN(64) CryptonightR_template_part1: mov QWORD PTR [rsp+16], rbx mov QWORD PTR [rsp+24], rbp @@ -68,8 +69,6 @@ CryptonightR_template_mainloop: lea rdx, QWORD PTR [r9+r11] aesenc xmm5, xmm4 - movd r10d, xmm5 - and r10d, 2097136 mov r12d, r9d mov eax, r9d @@ -77,16 +76,23 @@ CryptonightR_template_mainloop: xor r12d, 16 xor eax, 32 movdqu xmm0, XMMWORD PTR [r9+r11] + movaps xmm3, xmm0 movdqu xmm2, XMMWORD PTR [r12+r11] movdqu xmm1, XMMWORD PTR [rax+r11] - paddq xmm0, xmm7 + pxor xmm0, xmm2 + pxor xmm5, xmm1 + pxor xmm5, xmm0 + paddq xmm3, xmm7 paddq xmm2, xmm6 paddq xmm1, xmm4 - movdqu XMMWORD PTR [r12+r11], xmm0 - movd r12, xmm5 + movdqu XMMWORD PTR [r12+r11], xmm3 movdqu XMMWORD PTR [rax+r11], xmm2 movdqu XMMWORD PTR [r9+r11], xmm1 + movd r12, xmm5 + movd r10d, xmm5 + and r10d, 2097136 + movdqa xmm0, xmm5 pxor xmm0, xmm6 movdqu XMMWORD PTR [rdx], xmm0 @@ -101,13 +107,23 @@ CryptonightR_template_mainloop: movd eax, xmm6 movd edx, xmm7 + pextrd r9d, xmm7, 2 CryptonightR_template_part2: + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor rsp, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r15, rax + mov rax, r13 mul r12 - movd xmm0, rax - movd xmm3, rdx - punpcklqdq xmm3, xmm0 mov r9d, r10d mov r12d, r10d @@ -115,16 +131,18 @@ CryptonightR_template_part2: xor r12d, 32 xor r10d, 48 movdqa xmm1, XMMWORD PTR [r12+r11] - xor rdx, QWORD PTR [r12+r11] - xor rax, QWORD PTR [r11+r12+8] + movaps xmm3, xmm1 movdqa xmm2, XMMWORD PTR [r9+r11] - pxor xmm3, xmm2 - paddq xmm7, XMMWORD PTR [r10+r11] - paddq xmm1, xmm4 - paddq xmm3, xmm6 - movdqu XMMWORD PTR [r9+r11], xmm7 - movdqu XMMWORD PTR [r12+r11], xmm3 - movdqu XMMWORD PTR [r10+r11], xmm1 + movdqa xmm0, XMMWORD PTR [r10+r11] + pxor xmm1, xmm2 + pxor xmm5, xmm0 + pxor xmm5, xmm1 + paddq xmm3, xmm4 + paddq xmm2, xmm6 + paddq xmm0, xmm7 + movdqu XMMWORD PTR [r9+r11], xmm0 + movdqu XMMWORD PTR [r12+r11], xmm2 + movdqu XMMWORD PTR [r10+r11], xmm3 movdqa xmm7, xmm6 add r15, rax @@ -247,18 +265,21 @@ CryptonightR_template_double_mainloop: punpcklqdq xmm3, xmm0 xor ebx, 16 aesenc xmm6, xmm3 - movd rdx, xmm6 movd xmm4, r15 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 xor ebx, 48 paddq xmm0, xmm7 movdqu xmm1, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm1 movdqu XMMWORD PTR [rbx+rsi], xmm0 paddq xmm1, xmm3 xor ebx, 16 mov eax, ebx xor rax, 32 movdqu xmm0, XMMWORD PTR [rbx+rsi] + pxor xmm6, xmm0 + movd rdx, xmm6 movdqu XMMWORD PTR [rbx+rsi], xmm1 paddq xmm0, xmm9 movdqu XMMWORD PTR [rax+rsi], xmm0 @@ -274,15 +295,18 @@ CryptonightR_template_double_mainloop: xor r8d, 16 aesenc xmm5, xmm4 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 xor r8d, 48 paddq xmm0, xmm8 movdqu xmm1, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm1 movdqu XMMWORD PTR [r8+rdi], xmm0 paddq xmm1, xmm4 xor r8d, 16 mov eax, r8d xor rax, 32 movdqu xmm0, XMMWORD PTR [r8+rdi] + pxor xmm5, xmm0 movdqu XMMWORD PTR [r8+rdi], xmm1 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rdi], xmm0 @@ -303,7 +327,8 @@ CryptonightR_template_double_mainloop: movd xmm11, rbp movd xmm12, r15 movd xmm13, rdx - mov [rsp+112], rcx + mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp+16] mov esi, DWORD PTR [rsp+20] @@ -320,9 +345,22 @@ CryptonightR_template_double_mainloop: pextrd r15d, xmm3, 2 movd eax, xmm7 movd edx, xmm9 + pextrd r9d, xmm9, 2 CryptonightR_template_double_part2: + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r14, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r12, rax + movd rsp, xmm0 mov DWORD PTR [rsp+16], ebx mov DWORD PTR [rsp+20], esi @@ -334,28 +372,27 @@ CryptonightR_template_double_part2: movd rbp, xmm11 movd r15, xmm12 movd rdx, xmm13 - mov rcx, [rsp+112] + mov rcx, [rsp+104] + mov r9, [rsp+112] mov rbx, r8 mov rax, r8 mul rdx and ebp, 2097136 mov r8, rax - movd xmm1, rdx - movd xmm0, r8 - punpcklqdq xmm1, xmm0 - pxor xmm1, XMMWORD PTR [rcx+rsi] + movdqu xmm1, XMMWORD PTR [rcx+rsi] + pxor xmm6, xmm1 xor esi, 48 paddq xmm1, xmm7 movdqu xmm2, XMMWORD PTR [rsi+rcx] - xor rdx, QWORD PTR [rsi+rcx] + pxor xmm6, xmm2 paddq xmm2, xmm3 - xor r8, QWORD PTR [rsi+rcx+8] movdqu XMMWORD PTR [rsi+rcx], xmm1 xor esi, 16 mov eax, esi mov rsi, rcx movdqu xmm0, XMMWORD PTR [rax+rcx] + pxor xmm6, xmm0 movdqu XMMWORD PTR [rax+rcx], xmm2 paddq xmm0, xmm9 add r12, r8 @@ -383,6 +420,7 @@ CryptonightR_template_double_part2: movd xmm12, rbp movd xmm13, r15 mov [rsp+104], rcx + mov [rsp+112], r9 mov ebx, DWORD PTR [rsp] mov esi, DWORD PTR [rsp+4] @@ -401,9 +439,24 @@ CryptonightR_template_double_part2: pextrd r15d, xmm4, 2 movd eax, xmm8 movd edx, xmm10 + pextrd r9d, xmm10, 2 CryptonightR_template_double_part3: + movd r15, xmm13 + + mov eax, edi + mov edx, ebp + shl rdx, 32 + or rax, rdx + xor r15, rax + + mov eax, ebx + mov edx, esi + shl rdx, 32 + or rax, rdx + xor r13, rax + movd rsp, xmm0 mov DWORD PTR [rsp], ebx mov DWORD PTR [rsp+4], esi @@ -414,23 +467,20 @@ CryptonightR_template_double_part3: movd rsi, xmm2 movd rdi, xmm11 movd rbp, xmm12 - movd r15, xmm13 mov rcx, [rsp+104] + mov r9, [rsp+112] mov rax, r8 mul rdi - movd xmm1, rdx - movd xmm0, rax - punpcklqdq xmm1, xmm0 mov rdi, rcx mov r8, rax - pxor xmm1, XMMWORD PTR [rbp+rcx] + movdqu xmm1, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm1 xor ebp, 48 paddq xmm1, xmm8 - xor r8, QWORD PTR [rbp+rcx+8] - xor rdx, QWORD PTR [rbp+rcx] add r13, r8 movdqu xmm2, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm2 add r15, rdx movdqu XMMWORD PTR [rbp+rcx], xmm1 paddq xmm2, xmm4 @@ -438,6 +488,7 @@ CryptonightR_template_double_part3: mov eax, ebp xor rax, 32 movdqu xmm0, XMMWORD PTR [rbp+rcx] + pxor xmm5, xmm0 movdqu XMMWORD PTR [rbp+rcx], xmm2 paddq xmm0, xmm10 movdqu XMMWORD PTR [rax+rcx], xmm0 diff --git a/src/crypto/asm/win64/CryptonightWOW_template.inc b/src/crypto/asm/win64/CryptonightWOW_template.inc new file mode 100644 index 000000000..47fbc94f8 --- /dev/null +++ b/src/crypto/asm/win64/CryptonightWOW_template.inc @@ -0,0 +1,486 @@ +PUBLIC FN_PREFIX(CryptonightWOW_template_part1) +PUBLIC FN_PREFIX(CryptonightWOW_template_mainloop) +PUBLIC FN_PREFIX(CryptonightWOW_template_part2) +PUBLIC FN_PREFIX(CryptonightWOW_template_part3) +PUBLIC FN_PREFIX(CryptonightWOW_template_end) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part1) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_mainloop) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part2) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part3) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_part4) +PUBLIC FN_PREFIX(CryptonightWOW_template_double_end) + +ALIGN(64) +FN_PREFIX(CryptonightWOW_template_part1): + mov QWORD PTR [rsp+16], rbx + mov QWORD PTR [rsp+24], rbp + mov QWORD PTR [rsp+32], rsi + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + push rdi + sub rsp, 64 + mov r12, rcx + mov r8, QWORD PTR [r12+32] + mov rdx, r12 + xor r8, QWORD PTR [r12] + mov r15, QWORD PTR [r12+40] + mov r9, r8 + xor r15, QWORD PTR [r12+8] + mov r11, QWORD PTR [r12+224] + mov r12, QWORD PTR [r12+56] + xor r12, QWORD PTR [rdx+24] + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + movaps XMMWORD PTR [rsp+48], xmm6 + movd xmm0, r12 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+16], xmm8 + movaps XMMWORD PTR [rsp], xmm9 + mov r12, QWORD PTR [rdx+88] + xor r12, QWORD PTR [rdx+72] + movd xmm6, rax + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm6, xmm0 + and r9d, 2097136 + movd xmm0, r12 + movd xmm7, rax + punpcklqdq xmm7, xmm0 + mov r10d, r9d + movd xmm9, rsp + mov rsp, r8 + mov r8d, 524288 + + mov ebx, [rdx+96] + mov esi, [rdx+100] + mov edi, [rdx+104] + mov ebp, [rdx+108] + + ALIGN(64) +FN_PREFIX(CryptonightWOW_template_mainloop): + movdqa xmm5, XMMWORD PTR [r9+r11] + movd xmm0, r15 + movd xmm4, rsp + punpcklqdq xmm4, xmm0 + lea rdx, QWORD PTR [r9+r11] + + aesenc xmm5, xmm4 + movd r10d, xmm5 + and r10d, 2097136 + + mov r12d, r9d + mov eax, r9d + xor r9d, 48 + xor r12d, 16 + xor eax, 32 + movdqu xmm0, XMMWORD PTR [r9+r11] + movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm1, XMMWORD PTR [rax+r11] + paddq xmm0, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r12+r11], xmm0 + movd r12, xmm5 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + + movdqa xmm0, xmm5 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [rdx], xmm0 + + lea r13d, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or r13, rdx + + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + + movd eax, xmm6 + movd edx, xmm7 + pextrd r9d, xmm7, 2 + +FN_PREFIX(CryptonightWOW_template_part2): + mov rax, r13 + mul r12 + movd xmm0, rax + movd xmm3, rdx + punpcklqdq xmm3, xmm0 + + mov r9d, r10d + mov r12d, r10d + xor r9d, 16 + xor r12d, 32 + xor r10d, 48 + movdqa xmm1, XMMWORD PTR [r12+r11] + xor rdx, QWORD PTR [r12+r11] + xor rax, QWORD PTR [r11+r12+8] + movdqa xmm2, XMMWORD PTR [r9+r11] + pxor xmm3, xmm2 + paddq xmm7, XMMWORD PTR [r10+r11] + paddq xmm1, xmm4 + paddq xmm3, xmm6 + movdqu XMMWORD PTR [r9+r11], xmm7 + movdqu XMMWORD PTR [r12+r11], xmm3 + movdqu XMMWORD PTR [r10+r11], xmm1 + + movdqa xmm7, xmm6 + add r15, rax + add rsp, rdx + xor r10, 48 + mov QWORD PTR [r10+r11], rsp + xor rsp, r13 + mov r9d, esp + mov QWORD PTR [r10+r11+8], r15 + and r9d, 2097136 + xor r15, r14 + movdqa xmm6, xmm5 + dec r8d + jnz FN_PREFIX(CryptonightWOW_template_mainloop) + +FN_PREFIX(CryptonightWOW_template_part3): + movd rsp, xmm9 + + mov rbx, QWORD PTR [rsp+136] + mov rbp, QWORD PTR [rsp+144] + mov rsi, QWORD PTR [rsp+152] + movaps xmm6, XMMWORD PTR [rsp+48] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+16] + movaps xmm9, XMMWORD PTR [rsp] + add rsp, 64 + pop rdi + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + ret 0 +FN_PREFIX(CryptonightWOW_template_end): + +ALIGN(64) +FN_PREFIX(CryptonightWOW_template_double_part1): + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 320 + mov r14, QWORD PTR [rcx+32] + mov r8, rcx + xor r14, QWORD PTR [rcx] + mov r12, QWORD PTR [rcx+40] + mov ebx, r14d + mov rsi, QWORD PTR [rcx+224] + and ebx, 2097136 + xor r12, QWORD PTR [rcx+8] + mov rcx, QWORD PTR [rcx+56] + xor rcx, QWORD PTR [r8+24] + mov rax, QWORD PTR [r8+48] + xor rax, QWORD PTR [r8+16] + mov r15, QWORD PTR [rdx+32] + xor r15, QWORD PTR [rdx] + movd xmm0, rcx + mov rcx, QWORD PTR [r8+88] + xor rcx, QWORD PTR [r8+72] + mov r13, QWORD PTR [rdx+40] + mov rdi, QWORD PTR [rdx+224] + xor r13, QWORD PTR [rdx+8] + movaps XMMWORD PTR [rsp+160], xmm6 + movaps XMMWORD PTR [rsp+176], xmm7 + movaps XMMWORD PTR [rsp+192], xmm8 + movaps XMMWORD PTR [rsp+208], xmm9 + movaps XMMWORD PTR [rsp+224], xmm10 + movaps XMMWORD PTR [rsp+240], xmm11 + movaps XMMWORD PTR [rsp+256], xmm12 + movaps XMMWORD PTR [rsp+272], xmm13 + movaps XMMWORD PTR [rsp+288], xmm14 + movaps XMMWORD PTR [rsp+304], xmm15 + movd xmm7, rax + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + + movaps xmm1, XMMWORD PTR [rdx+96] + movaps xmm2, XMMWORD PTR [r8+96] + movaps XMMWORD PTR [rsp], xmm1 + movaps XMMWORD PTR [rsp+16], xmm2 + + mov r8d, r15d + punpcklqdq xmm7, xmm0 + movd xmm0, rcx + mov rcx, QWORD PTR [rdx+56] + xor rcx, QWORD PTR [rdx+24] + movd xmm9, rax + mov QWORD PTR [rsp+128], rsi + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + punpcklqdq xmm9, xmm0 + movd xmm0, rcx + mov rcx, QWORD PTR [rdx+88] + xor rcx, QWORD PTR [rdx+72] + movd xmm8, rax + mov QWORD PTR [rsp+136], rdi + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm8, xmm0 + and r8d, 2097136 + movd xmm0, rcx + mov r11d, 524288 + movd xmm10, rax + punpcklqdq xmm10, xmm0 + + movd xmm14, QWORD PTR [rsp+128] + movd xmm15, QWORD PTR [rsp+136] + + ALIGN(64) +FN_PREFIX(CryptonightWOW_template_double_mainloop): + movdqu xmm6, XMMWORD PTR [rbx+rsi] + movd xmm0, r12 + mov ecx, ebx + movd xmm3, r14 + punpcklqdq xmm3, xmm0 + xor ebx, 16 + aesenc xmm6, xmm3 + movd rdx, xmm6 + movd xmm4, r15 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + xor ebx, 48 + paddq xmm0, xmm7 + movdqu xmm1, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm0 + paddq xmm1, xmm3 + xor ebx, 16 + mov eax, ebx + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm1 + paddq xmm0, xmm9 + movdqu XMMWORD PTR [rax+rsi], xmm0 + movdqa xmm0, xmm6 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [rcx+rsi], xmm0 + mov esi, edx + movdqu xmm5, XMMWORD PTR [r8+rdi] + and esi, 2097136 + mov ecx, r8d + movd xmm0, r13 + punpcklqdq xmm4, xmm0 + xor r8d, 16 + aesenc xmm5, xmm4 + movdqu xmm0, XMMWORD PTR [r8+rdi] + xor r8d, 48 + paddq xmm0, xmm8 + movdqu xmm1, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm0 + paddq xmm1, xmm4 + xor r8d, 16 + mov eax, r8d + xor rax, 32 + movdqu xmm0, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm1 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rdi], xmm0 + movdqa xmm0, xmm5 + pxor xmm0, xmm8 + movdqu XMMWORD PTR [rcx+rdi], xmm0 + movd rdi, xmm5 + movd rcx, xmm14 + mov ebp, edi + mov r8, QWORD PTR [rcx+rsi] + mov r10, QWORD PTR [rcx+rsi+8] + lea r9, QWORD PTR [rcx+rsi] + xor esi, 16 + + movd xmm0, rsp + movd xmm1, rsi + movd xmm2, rdi + movd xmm11, rbp + movd xmm12, r15 + movd xmm13, rdx + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp+16] + mov esi, DWORD PTR [rsp+20] + mov edi, DWORD PTR [rsp+24] + mov ebp, DWORD PTR [rsp+28] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + xor r8, rax + + movd esp, xmm3 + pextrd r15d, xmm3, 2 + movd eax, xmm7 + movd edx, xmm9 + pextrd r9d, xmm9, 2 + +FN_PREFIX(CryptonightWOW_template_double_part2): + + movd rsp, xmm0 + mov DWORD PTR [rsp+16], ebx + mov DWORD PTR [rsp+20], esi + mov DWORD PTR [rsp+24], edi + mov DWORD PTR [rsp+28], ebp + + movd rsi, xmm1 + movd rdi, xmm2 + movd rbp, xmm11 + movd r15, xmm12 + movd rdx, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rbx, r8 + mov rax, r8 + mul rdx + and ebp, 2097136 + mov r8, rax + movd xmm1, rdx + movd xmm0, r8 + punpcklqdq xmm1, xmm0 + pxor xmm1, XMMWORD PTR [rcx+rsi] + xor esi, 48 + paddq xmm1, xmm7 + movdqu xmm2, XMMWORD PTR [rsi+rcx] + xor rdx, QWORD PTR [rsi+rcx] + paddq xmm2, xmm3 + xor r8, QWORD PTR [rsi+rcx+8] + movdqu XMMWORD PTR [rsi+rcx], xmm1 + xor esi, 16 + mov eax, esi + mov rsi, rcx + movdqu xmm0, XMMWORD PTR [rax+rcx] + movdqu XMMWORD PTR [rax+rcx], xmm2 + paddq xmm0, xmm9 + add r12, r8 + xor rax, 32 + add r14, rdx + movdqa xmm9, xmm7 + movdqa xmm7, xmm6 + movdqu XMMWORD PTR [rax+rcx], xmm0 + mov QWORD PTR [r9+8], r12 + xor r12, r10 + mov QWORD PTR [r9], r14 + movd rcx, xmm15 + xor r14, rbx + mov r10d, ebp + mov ebx, r14d + xor ebp, 16 + and ebx, 2097136 + mov r8, QWORD PTR [r10+rcx] + mov r9, QWORD PTR [r10+rcx+8] + + movd xmm0, rsp + movd xmm1, rbx + movd xmm2, rsi + movd xmm11, rdi + movd xmm12, rbp + movd xmm13, r15 + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp] + mov esi, DWORD PTR [rsp+4] + mov edi, DWORD PTR [rsp+8] + mov ebp, DWORD PTR [rsp+12] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + + xor r8, rax + movd xmm3, r8 + + movd esp, xmm4 + pextrd r15d, xmm4, 2 + movd eax, xmm8 + movd edx, xmm10 + pextrd r9d, xmm10, 2 + +FN_PREFIX(CryptonightWOW_template_double_part3): + + movd rsp, xmm0 + mov DWORD PTR [rsp], ebx + mov DWORD PTR [rsp+4], esi + mov DWORD PTR [rsp+8], edi + mov DWORD PTR [rsp+12], ebp + + movd rbx, xmm1 + movd rsi, xmm2 + movd rdi, xmm11 + movd rbp, xmm12 + movd r15, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rax, r8 + mul rdi + movd xmm1, rdx + movd xmm0, rax + punpcklqdq xmm1, xmm0 + mov rdi, rcx + mov r8, rax + pxor xmm1, XMMWORD PTR [rbp+rcx] + xor ebp, 48 + paddq xmm1, xmm8 + xor r8, QWORD PTR [rbp+rcx+8] + xor rdx, QWORD PTR [rbp+rcx] + add r13, r8 + movdqu xmm2, XMMWORD PTR [rbp+rcx] + add r15, rdx + movdqu XMMWORD PTR [rbp+rcx], xmm1 + paddq xmm2, xmm4 + xor ebp, 16 + mov eax, ebp + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbp+rcx] + movdqu XMMWORD PTR [rbp+rcx], xmm2 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rcx], xmm0 + movd rax, xmm3 + movdqa xmm10, xmm8 + mov QWORD PTR [r10+rcx], r15 + movdqa xmm8, xmm5 + xor r15, rax + mov QWORD PTR [r10+rcx+8], r13 + mov r8d, r15d + xor r13, r9 + and r8d, 2097136 + dec r11d + jnz FN_PREFIX(CryptonightWOW_template_double_mainloop) + +FN_PREFIX(CryptonightWOW_template_double_part4): + + mov rbx, QWORD PTR [rsp+400] + movaps xmm6, XMMWORD PTR [rsp+160] + movaps xmm7, XMMWORD PTR [rsp+176] + movaps xmm8, XMMWORD PTR [rsp+192] + movaps xmm9, XMMWORD PTR [rsp+208] + movaps xmm10, XMMWORD PTR [rsp+224] + movaps xmm11, XMMWORD PTR [rsp+240] + movaps xmm12, XMMWORD PTR [rsp+256] + movaps xmm13, XMMWORD PTR [rsp+272] + movaps xmm14, XMMWORD PTR [rsp+288] + movaps xmm15, XMMWORD PTR [rsp+304] + add rsp, 320 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + ret 0 +FN_PREFIX(CryptonightWOW_template_double_end): diff --git a/src/crypto/asm/win64/CryptonightWOW_template_win.inc b/src/crypto/asm/win64/CryptonightWOW_template_win.inc new file mode 100644 index 000000000..9db2cf397 --- /dev/null +++ b/src/crypto/asm/win64/CryptonightWOW_template_win.inc @@ -0,0 +1,486 @@ +PUBLIC CryptonightWOW_template_part1 +PUBLIC CryptonightWOW_template_mainloop +PUBLIC CryptonightWOW_template_part2 +PUBLIC CryptonightWOW_template_part3 +PUBLIC CryptonightWOW_template_end +PUBLIC CryptonightWOW_template_double_part1 +PUBLIC CryptonightWOW_template_double_mainloop +PUBLIC CryptonightWOW_template_double_part2 +PUBLIC CryptonightWOW_template_double_part3 +PUBLIC CryptonightWOW_template_double_part4 +PUBLIC CryptonightWOW_template_double_end + +ALIGN(64) +CryptonightWOW_template_part1: + mov QWORD PTR [rsp+16], rbx + mov QWORD PTR [rsp+24], rbp + mov QWORD PTR [rsp+32], rsi + push r10 + push r11 + push r12 + push r13 + push r14 + push r15 + push rdi + sub rsp, 64 + mov r12, rcx + mov r8, QWORD PTR [r12+32] + mov rdx, r12 + xor r8, QWORD PTR [r12] + mov r15, QWORD PTR [r12+40] + mov r9, r8 + xor r15, QWORD PTR [r12+8] + mov r11, QWORD PTR [r12+224] + mov r12, QWORD PTR [r12+56] + xor r12, QWORD PTR [rdx+24] + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + movaps XMMWORD PTR [rsp+48], xmm6 + movd xmm0, r12 + movaps XMMWORD PTR [rsp+32], xmm7 + movaps XMMWORD PTR [rsp+16], xmm8 + movaps XMMWORD PTR [rsp], xmm9 + mov r12, QWORD PTR [rdx+88] + xor r12, QWORD PTR [rdx+72] + movd xmm6, rax + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm6, xmm0 + and r9d, 2097136 + movd xmm0, r12 + movd xmm7, rax + punpcklqdq xmm7, xmm0 + mov r10d, r9d + movd xmm9, rsp + mov rsp, r8 + mov r8d, 524288 + + mov ebx, [rdx+96] + mov esi, [rdx+100] + mov edi, [rdx+104] + mov ebp, [rdx+108] + + ALIGN(64) +CryptonightWOW_template_mainloop: + movdqa xmm5, XMMWORD PTR [r9+r11] + movd xmm0, r15 + movd xmm4, rsp + punpcklqdq xmm4, xmm0 + lea rdx, QWORD PTR [r9+r11] + + aesenc xmm5, xmm4 + movd r10d, xmm5 + and r10d, 2097136 + + mov r12d, r9d + mov eax, r9d + xor r9d, 48 + xor r12d, 16 + xor eax, 32 + movdqu xmm0, XMMWORD PTR [r9+r11] + movdqu xmm2, XMMWORD PTR [r12+r11] + movdqu xmm1, XMMWORD PTR [rax+r11] + paddq xmm0, xmm7 + paddq xmm2, xmm6 + paddq xmm1, xmm4 + movdqu XMMWORD PTR [r12+r11], xmm0 + movd r12, xmm5 + movdqu XMMWORD PTR [rax+r11], xmm2 + movdqu XMMWORD PTR [r9+r11], xmm1 + + movdqa xmm0, xmm5 + pxor xmm0, xmm6 + movdqu XMMWORD PTR [rdx], xmm0 + + lea r13d, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or r13, rdx + + xor r13, QWORD PTR [r10+r11] + mov r14, QWORD PTR [r10+r11+8] + + movd eax, xmm6 + movd edx, xmm7 + pextrd r9d, xmm7, 2 + +CryptonightWOW_template_part2: + mov rax, r13 + mul r12 + movd xmm0, rax + movd xmm3, rdx + punpcklqdq xmm3, xmm0 + + mov r9d, r10d + mov r12d, r10d + xor r9d, 16 + xor r12d, 32 + xor r10d, 48 + movdqa xmm1, XMMWORD PTR [r12+r11] + xor rdx, QWORD PTR [r12+r11] + xor rax, QWORD PTR [r11+r12+8] + movdqa xmm2, XMMWORD PTR [r9+r11] + pxor xmm3, xmm2 + paddq xmm7, XMMWORD PTR [r10+r11] + paddq xmm1, xmm4 + paddq xmm3, xmm6 + movdqu XMMWORD PTR [r9+r11], xmm7 + movdqu XMMWORD PTR [r12+r11], xmm3 + movdqu XMMWORD PTR [r10+r11], xmm1 + + movdqa xmm7, xmm6 + add r15, rax + add rsp, rdx + xor r10, 48 + mov QWORD PTR [r10+r11], rsp + xor rsp, r13 + mov r9d, esp + mov QWORD PTR [r10+r11+8], r15 + and r9d, 2097136 + xor r15, r14 + movdqa xmm6, xmm5 + dec r8d + jnz CryptonightWOW_template_mainloop + +CryptonightWOW_template_part3: + movd rsp, xmm9 + + mov rbx, QWORD PTR [rsp+136] + mov rbp, QWORD PTR [rsp+144] + mov rsi, QWORD PTR [rsp+152] + movaps xmm6, XMMWORD PTR [rsp+48] + movaps xmm7, XMMWORD PTR [rsp+32] + movaps xmm8, XMMWORD PTR [rsp+16] + movaps xmm9, XMMWORD PTR [rsp] + add rsp, 64 + pop rdi + pop r15 + pop r14 + pop r13 + pop r12 + pop r11 + pop r10 + ret 0 +CryptonightWOW_template_end: + +ALIGN(64) +CryptonightWOW_template_double_part1: + mov QWORD PTR [rsp+24], rbx + push rbp + push rsi + push rdi + push r12 + push r13 + push r14 + push r15 + sub rsp, 320 + mov r14, QWORD PTR [rcx+32] + mov r8, rcx + xor r14, QWORD PTR [rcx] + mov r12, QWORD PTR [rcx+40] + mov ebx, r14d + mov rsi, QWORD PTR [rcx+224] + and ebx, 2097136 + xor r12, QWORD PTR [rcx+8] + mov rcx, QWORD PTR [rcx+56] + xor rcx, QWORD PTR [r8+24] + mov rax, QWORD PTR [r8+48] + xor rax, QWORD PTR [r8+16] + mov r15, QWORD PTR [rdx+32] + xor r15, QWORD PTR [rdx] + movd xmm0, rcx + mov rcx, QWORD PTR [r8+88] + xor rcx, QWORD PTR [r8+72] + mov r13, QWORD PTR [rdx+40] + mov rdi, QWORD PTR [rdx+224] + xor r13, QWORD PTR [rdx+8] + movaps XMMWORD PTR [rsp+160], xmm6 + movaps XMMWORD PTR [rsp+176], xmm7 + movaps XMMWORD PTR [rsp+192], xmm8 + movaps XMMWORD PTR [rsp+208], xmm9 + movaps XMMWORD PTR [rsp+224], xmm10 + movaps XMMWORD PTR [rsp+240], xmm11 + movaps XMMWORD PTR [rsp+256], xmm12 + movaps XMMWORD PTR [rsp+272], xmm13 + movaps XMMWORD PTR [rsp+288], xmm14 + movaps XMMWORD PTR [rsp+304], xmm15 + movd xmm7, rax + mov rax, QWORD PTR [r8+80] + xor rax, QWORD PTR [r8+64] + + movaps xmm1, XMMWORD PTR [rdx+96] + movaps xmm2, XMMWORD PTR [r8+96] + movaps XMMWORD PTR [rsp], xmm1 + movaps XMMWORD PTR [rsp+16], xmm2 + + mov r8d, r15d + punpcklqdq xmm7, xmm0 + movd xmm0, rcx + mov rcx, QWORD PTR [rdx+56] + xor rcx, QWORD PTR [rdx+24] + movd xmm9, rax + mov QWORD PTR [rsp+128], rsi + mov rax, QWORD PTR [rdx+48] + xor rax, QWORD PTR [rdx+16] + punpcklqdq xmm9, xmm0 + movd xmm0, rcx + mov rcx, QWORD PTR [rdx+88] + xor rcx, QWORD PTR [rdx+72] + movd xmm8, rax + mov QWORD PTR [rsp+136], rdi + mov rax, QWORD PTR [rdx+80] + xor rax, QWORD PTR [rdx+64] + punpcklqdq xmm8, xmm0 + and r8d, 2097136 + movd xmm0, rcx + mov r11d, 524288 + movd xmm10, rax + punpcklqdq xmm10, xmm0 + + movd xmm14, QWORD PTR [rsp+128] + movd xmm15, QWORD PTR [rsp+136] + + ALIGN(64) +CryptonightWOW_template_double_mainloop: + movdqu xmm6, XMMWORD PTR [rbx+rsi] + movd xmm0, r12 + mov ecx, ebx + movd xmm3, r14 + punpcklqdq xmm3, xmm0 + xor ebx, 16 + aesenc xmm6, xmm3 + movd rdx, xmm6 + movd xmm4, r15 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + xor ebx, 48 + paddq xmm0, xmm7 + movdqu xmm1, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm0 + paddq xmm1, xmm3 + xor ebx, 16 + mov eax, ebx + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbx+rsi] + movdqu XMMWORD PTR [rbx+rsi], xmm1 + paddq xmm0, xmm9 + movdqu XMMWORD PTR [rax+rsi], xmm0 + movdqa xmm0, xmm6 + pxor xmm0, xmm7 + movdqu XMMWORD PTR [rcx+rsi], xmm0 + mov esi, edx + movdqu xmm5, XMMWORD PTR [r8+rdi] + and esi, 2097136 + mov ecx, r8d + movd xmm0, r13 + punpcklqdq xmm4, xmm0 + xor r8d, 16 + aesenc xmm5, xmm4 + movdqu xmm0, XMMWORD PTR [r8+rdi] + xor r8d, 48 + paddq xmm0, xmm8 + movdqu xmm1, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm0 + paddq xmm1, xmm4 + xor r8d, 16 + mov eax, r8d + xor rax, 32 + movdqu xmm0, XMMWORD PTR [r8+rdi] + movdqu XMMWORD PTR [r8+rdi], xmm1 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rdi], xmm0 + movdqa xmm0, xmm5 + pxor xmm0, xmm8 + movdqu XMMWORD PTR [rcx+rdi], xmm0 + movd rdi, xmm5 + movd rcx, xmm14 + mov ebp, edi + mov r8, QWORD PTR [rcx+rsi] + mov r10, QWORD PTR [rcx+rsi+8] + lea r9, QWORD PTR [rcx+rsi] + xor esi, 16 + + movd xmm0, rsp + movd xmm1, rsi + movd xmm2, rdi + movd xmm11, rbp + movd xmm12, r15 + movd xmm13, rdx + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp+16] + mov esi, DWORD PTR [rsp+20] + mov edi, DWORD PTR [rsp+24] + mov ebp, DWORD PTR [rsp+28] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + xor r8, rax + + movd esp, xmm3 + pextrd r15d, xmm3, 2 + movd eax, xmm7 + movd edx, xmm9 + pextrd r9d, xmm9, 2 + +CryptonightWOW_template_double_part2: + + movd rsp, xmm0 + mov DWORD PTR [rsp+16], ebx + mov DWORD PTR [rsp+20], esi + mov DWORD PTR [rsp+24], edi + mov DWORD PTR [rsp+28], ebp + + movd rsi, xmm1 + movd rdi, xmm2 + movd rbp, xmm11 + movd r15, xmm12 + movd rdx, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rbx, r8 + mov rax, r8 + mul rdx + and ebp, 2097136 + mov r8, rax + movd xmm1, rdx + movd xmm0, r8 + punpcklqdq xmm1, xmm0 + pxor xmm1, XMMWORD PTR [rcx+rsi] + xor esi, 48 + paddq xmm1, xmm7 + movdqu xmm2, XMMWORD PTR [rsi+rcx] + xor rdx, QWORD PTR [rsi+rcx] + paddq xmm2, xmm3 + xor r8, QWORD PTR [rsi+rcx+8] + movdqu XMMWORD PTR [rsi+rcx], xmm1 + xor esi, 16 + mov eax, esi + mov rsi, rcx + movdqu xmm0, XMMWORD PTR [rax+rcx] + movdqu XMMWORD PTR [rax+rcx], xmm2 + paddq xmm0, xmm9 + add r12, r8 + xor rax, 32 + add r14, rdx + movdqa xmm9, xmm7 + movdqa xmm7, xmm6 + movdqu XMMWORD PTR [rax+rcx], xmm0 + mov QWORD PTR [r9+8], r12 + xor r12, r10 + mov QWORD PTR [r9], r14 + movd rcx, xmm15 + xor r14, rbx + mov r10d, ebp + mov ebx, r14d + xor ebp, 16 + and ebx, 2097136 + mov r8, QWORD PTR [r10+rcx] + mov r9, QWORD PTR [r10+rcx+8] + + movd xmm0, rsp + movd xmm1, rbx + movd xmm2, rsi + movd xmm11, rdi + movd xmm12, rbp + movd xmm13, r15 + mov [rsp+104], rcx + mov [rsp+112], r9 + + mov ebx, DWORD PTR [rsp] + mov esi, DWORD PTR [rsp+4] + mov edi, DWORD PTR [rsp+8] + mov ebp, DWORD PTR [rsp+12] + + lea eax, [ebx+esi] + lea edx, [edi+ebp] + shl rdx, 32 + or rax, rdx + + xor r8, rax + movd xmm3, r8 + + movd esp, xmm4 + pextrd r15d, xmm4, 2 + movd eax, xmm8 + movd edx, xmm10 + pextrd r9d, xmm10, 2 + +CryptonightWOW_template_double_part3: + + movd rsp, xmm0 + mov DWORD PTR [rsp], ebx + mov DWORD PTR [rsp+4], esi + mov DWORD PTR [rsp+8], edi + mov DWORD PTR [rsp+12], ebp + + movd rbx, xmm1 + movd rsi, xmm2 + movd rdi, xmm11 + movd rbp, xmm12 + movd r15, xmm13 + mov rcx, [rsp+104] + mov r9, [rsp+112] + + mov rax, r8 + mul rdi + movd xmm1, rdx + movd xmm0, rax + punpcklqdq xmm1, xmm0 + mov rdi, rcx + mov r8, rax + pxor xmm1, XMMWORD PTR [rbp+rcx] + xor ebp, 48 + paddq xmm1, xmm8 + xor r8, QWORD PTR [rbp+rcx+8] + xor rdx, QWORD PTR [rbp+rcx] + add r13, r8 + movdqu xmm2, XMMWORD PTR [rbp+rcx] + add r15, rdx + movdqu XMMWORD PTR [rbp+rcx], xmm1 + paddq xmm2, xmm4 + xor ebp, 16 + mov eax, ebp + xor rax, 32 + movdqu xmm0, XMMWORD PTR [rbp+rcx] + movdqu XMMWORD PTR [rbp+rcx], xmm2 + paddq xmm0, xmm10 + movdqu XMMWORD PTR [rax+rcx], xmm0 + movd rax, xmm3 + movdqa xmm10, xmm8 + mov QWORD PTR [r10+rcx], r15 + movdqa xmm8, xmm5 + xor r15, rax + mov QWORD PTR [r10+rcx+8], r13 + mov r8d, r15d + xor r13, r9 + and r8d, 2097136 + dec r11d + jnz CryptonightWOW_template_double_mainloop + +CryptonightWOW_template_double_part4: + + mov rbx, QWORD PTR [rsp+400] + movaps xmm6, XMMWORD PTR [rsp+160] + movaps xmm7, XMMWORD PTR [rsp+176] + movaps xmm8, XMMWORD PTR [rsp+192] + movaps xmm9, XMMWORD PTR [rsp+208] + movaps xmm10, XMMWORD PTR [rsp+224] + movaps xmm11, XMMWORD PTR [rsp+240] + movaps xmm12, XMMWORD PTR [rsp+256] + movaps xmm13, XMMWORD PTR [rsp+272] + movaps xmm14, XMMWORD PTR [rsp+288] + movaps xmm15, XMMWORD PTR [rsp+304] + add rsp, 320 + pop r15 + pop r14 + pop r13 + pop r12 + pop rdi + pop rsi + pop rbp + ret 0 +CryptonightWOW_template_double_end: diff --git a/src/crypto/variant4_random_math.h b/src/crypto/variant4_random_math.h index 793e9e034..1f3ea0ac3 100644 --- a/src/crypto/variant4_random_math.h +++ b/src/crypto/variant4_random_math.h @@ -12,8 +12,11 @@ enum V4_Settings TOTAL_LATENCY = 15 * 3, // Always generate at least 60 instructions - NUM_INSTRUCTIONS = 60, - + NUM_INSTRUCTIONS_MIN = 60, + + // Never generate more than 70 instructions (final RET instruction doesn't count here) + NUM_INSTRUCTIONS_MAX = 70, + // Available ALUs for MUL // Modern CPUs typically have only 1 ALU which can do multiplications ALU_COUNT_MUL = 1, @@ -38,10 +41,9 @@ enum V4_InstructionList // V4_InstructionDefinition is used to generate code from random data // Every random sequence of bytes is a valid code // -// There are 8 registers in total: +// There are 9 registers in total: // - 4 variable registers -// - 4 constant registers initialized from loop variables -// +// - 5 constant registers initialized from loop variables // This is why dst_index is 2 bits enum V4_InstructionDefinition { @@ -144,16 +146,16 @@ static void v4_random_math(const struct V4_Instruction* code, v4_reg* r) // Generated program can have 60 + a few more (usually 2-3) instructions to achieve required latency // I've checked all block heights < 10,000,000 and here is the distribution of program sizes: // - // 60 28495 - // 61 106077 - // 62 2455855 - // 63 5114930 - // 64 1020868 - // 65 1109026 - // 66 151756 - // 67 8429 - // 68 4477 - // 69 87 + // 60 27960 + // 61 105054 + // 62 2452759 + // 63 5115997 + // 64 1022269 + // 65 1109635 + // 66 153145 + // 67 8550 + // 68 4529 + // 69 102 // Unroll 70 instructions here V4_EXEC_10(0); // instructions 0-9 @@ -179,6 +181,8 @@ static FORCEINLINE void check_data(size_t* data_index, const size_t bytes_needed } // Generates as many random math operations as possible with given latency and ALU restrictions +// "code" array must have space for NUM_INSTRUCTIONS_MAX+1 instructions +template static int v4_random_math_init(struct V4_Instruction* code, const uint64_t height) { // MUL is 3 cycles, 3-way addition and rotations are 2 cycles, SUB/XOR are 1 cycle @@ -200,6 +204,10 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh memset(data, 0, sizeof(data)); uint64_t tmp = SWAP64LE(height); memcpy(data, &tmp, sizeof(uint64_t)); + if (VARIANT == xmrig::VARIANT_4) + { + data[20] = -38; + } // Set data_index past the last byte in data // to trigger full data update with blake hash @@ -207,18 +215,22 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh size_t data_index = sizeof(data); int code_size; + + // There is a small chance (1.8%) that register R8 won't be used in the generated program + // So we keep track of it and try again if it's not used + bool r8_used; do { - int latency[8]; - int asic_latency[8]; + int latency[9]; + int asic_latency[9]; // Tracks previous instruction and value of the source operand for registers R0-R3 throughout code execution // byte 0: current value of the destination register // byte 1: instruction opcode // byte 2: current value of the source register // - // Registers R4-R7 are constant and are treated as having the same value because when we do + // Registers R4-R8 are constant and are treated as having the same value because when we do // the same operation twice with two constant source registers, it can be optimized into a single operation - uint32_t inst_data[8] = { 0, 1, 2, 3, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF }; + uint32_t inst_data[9] = { 0, 1, 2, 3, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF }; bool alu_busy[TOTAL_LATENCY + 1][ALU_COUNT]; bool is_rotation[V4_INSTRUCTION_COUNT]; @@ -237,6 +249,7 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh code_size = 0; int total_iterations = 0; + r8_used = (VARIANT == xmrig::VARIANT_WOW); // Generate random code to achieve minimal required latency for our abstract CPU // Try to get this latency for all 4 registers @@ -281,7 +294,7 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh if (((opcode == ADD) || (opcode == SUB) || (opcode == XOR)) && (a == b)) { // a is always < 4, so we don't need to check bounds here - b = a + 4; + b = (VARIANT == xmrig::VARIANT_WOW) ? (a + 4) : 8; src_index = b; } @@ -362,6 +375,11 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh code[code_size].src_index = src_index; code[code_size].C = 0; + if (src_index == 8) + { + r8_used = true; + } + if (opcode == ADD) { // ADD instruction is implemented as two 1-cycle instructions on a real CPU, so mark ALU as busy for the next cycle too @@ -376,7 +394,7 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh } ++code_size; - if (code_size >= NUM_INSTRUCTIONS) + if (code_size >= NUM_INSTRUCTIONS_MIN) { break; } @@ -391,7 +409,7 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh // We need to add a few more MUL and ROR instructions to achieve minimal required latency for ASIC // Get this latency for at least 1 of the 4 registers const int prev_code_size = code_size; - while ((asic_latency[0] < TOTAL_LATENCY) && (asic_latency[1] < TOTAL_LATENCY) && (asic_latency[2] < TOTAL_LATENCY) && (asic_latency[3] < TOTAL_LATENCY)) + while ((code_size < NUM_INSTRUCTIONS_MAX) && (asic_latency[0] < TOTAL_LATENCY) && (asic_latency[1] < TOTAL_LATENCY) && (asic_latency[2] < TOTAL_LATENCY) && (asic_latency[3] < TOTAL_LATENCY)) { int min_idx = 0; int max_idx = 0; @@ -413,9 +431,11 @@ static int v4_random_math_init(struct V4_Instruction* code, const uint64_t heigh ++code_size; } - // There is ~99.8% chance that code_size >= NUM_INSTRUCTIONS here, so second iteration is required rarely - } while (code_size < NUM_INSTRUCTIONS); + // There is ~98.15% chance that loop condition is false, so this loop will execute only 1 iteration most of the time + // It never does more than 4 iterations for all block heights < 10,000,000 + } while (!r8_used || (code_size < NUM_INSTRUCTIONS_MIN) || (code_size > NUM_INSTRUCTIONS_MAX)); + // It's guaranteed that NUM_INSTRUCTIONS_MIN <= code_size <= NUM_INSTRUCTIONS_MAX here // Add final instruction to stop the interpreter code[code_size].opcode = RET; code[code_size].dst_index = 0; diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 4b539bb3f..3d5ec59ea 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -175,6 +175,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a add_asm_func(asm_func_map); add_asm_func(asm_func_map); add_asm_func(asm_func_map); + add_asm_func(asm_func_map); add_asm_func(asm_func_map); @@ -310,6 +311,17 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a cryptonight_quad_hash, cryptonight_penta_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_single_hash, + cryptonight_double_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + cryptonight_triple_hash, + cryptonight_quad_hash, + cryptonight_penta_hash, + # ifndef XMRIG_NO_AEON cryptonight_single_hash, cryptonight_double_hash, @@ -344,6 +356,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 @@ -358,6 +371,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 # endif # ifndef XMRIG_NO_SUMO @@ -406,6 +420,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 @@ -420,6 +435,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 # endif # ifndef XMRIG_NO_CN_PICO @@ -447,6 +463,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 # else nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 @@ -461,6 +478,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW + nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4 # endif }; diff --git a/src/workers/MultiWorker.cpp b/src/workers/MultiWorker.cpp index 2a6153d5b..946fbda6b 100644 --- a/src/workers/MultiWorker.cpp +++ b/src/workers/MultiWorker.cpp @@ -60,6 +60,10 @@ bool MultiWorker::selfTest() LOG_WARN("CryptonightR (Wownero) self-test failed"); return false; } + if (!verify2(VARIANT_4, test_input_R)) { + LOG_WARN("CryptonightR self-test failed"); + return false; + } const bool rc = verify(VARIANT_0, test_output_v0) && verify(VARIANT_1, test_output_v1) && From de975adb8af5397f33a303908ce6c97a7411fe28 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 18 Feb 2019 08:14:42 +0700 Subject: [PATCH 16/22] Revert variant into summary output. --- src/base/net/Pools.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base/net/Pools.cpp b/src/base/net/Pools.cpp index 1513541bc..e3b86acac 100644 --- a/src/base/net/Pools.cpp +++ b/src/base/net/Pools.cpp @@ -161,19 +161,19 @@ void xmrig::Pools::print() const if (Log::colors) { const int color = pool.isEnabled() ? (pool.isTLS() ? 32 : 36) : 31; - Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m algo " WHITE_BOLD("%s"), + Log::i()->text(GREEN_BOLD(" * ") WHITE_BOLD("POOL #%-7zu") "\x1B[1;%dm%s\x1B[0m variant " WHITE_BOLD("%s"), i, color, pool.url(), - pool.algorithm().shortName() + pool.algorithm().variantName() ); } else { - Log::i()->text(" * POOL #%-7zu%s%s algo=%s %s", + Log::i()->text(" * POOL #%-7zu%s%s variant=%s %s", i, pool.isEnabled() ? "" : "-", pool.url(), - pool.algorithm().shortName(), + pool.algorithm().variantName(), pool.isTLS() ? "TLS" : "" ); } From b7c17cf1a04031c3e4f63c95dc96876c630a5bd4 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 18 Feb 2019 12:39:52 +0700 Subject: [PATCH 17/22] Fixed Linux build. --- src/base/io/Watcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/io/Watcher.cpp b/src/base/io/Watcher.cpp index 93b666431..b8ea4c3b9 100644 --- a/src/base/io/Watcher.cpp +++ b/src/base/io/Watcher.cpp @@ -82,7 +82,7 @@ void xmrig::Watcher::reload() m_listener->onFileChanged(m_path); # ifndef _WIN32 - uv_fs_event_stop(&m_fsEvent); + uv_fs_event_stop(m_fsEvent); start(); # endif } From 415600b8c90e6ab65c7a5458f91759218b20af3a Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 18 Feb 2019 08:03:41 +0100 Subject: [PATCH 18/22] Use public name CryptonightR for Monero's variant 4 --- src/common/crypto/Algorithm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/crypto/Algorithm.cpp b/src/common/crypto/Algorithm.cpp index 8437555d9..dd864705b 100644 --- a/src/common/crypto/Algorithm.cpp +++ b/src/common/crypto/Algorithm.cpp @@ -65,7 +65,7 @@ static AlgoData const algorithms[] = { { "cryptonight/half", "cn/half", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/xtlv9", "cn/xtlv9", xmrig::CRYPTONIGHT, xmrig::VARIANT_HALF }, { "cryptonight/wow", "cn/wow", xmrig::CRYPTONIGHT, xmrig::VARIANT_WOW }, - { "cryptonight/4", "cn/4", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, + { "cryptonight/r", "cn/r", xmrig::CRYPTONIGHT, xmrig::VARIANT_4 }, # ifndef XMRIG_NO_AEON { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, @@ -131,7 +131,7 @@ static const char *variants[] = { "trtl", "gpu", "wow", - "4", + "r", }; From 84f85b42006d7316b663b3da3926861d413c7e91 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 18 Feb 2019 19:02:40 +0700 Subject: [PATCH 19/22] Sync changes. --- src/App.cpp | 7 ------- src/App.h | 23 +++++++++++------------ src/core/Controller.cpp | 6 +++--- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 31691fbf3..96d1688ba 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -96,7 +96,6 @@ int xmrig::App::exec() if (m_controller->config()->isDryRun()) { LOG_NOTICE("OK"); - release(); return 0; } @@ -123,7 +122,6 @@ int xmrig::App::exec() const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_loop_close(uv_default_loop()); - release(); return r; } @@ -194,8 +192,3 @@ void xmrig::App::close() uv_stop(uv_default_loop()); } - - -void xmrig::App::release() -{ -} diff --git a/src/App.h b/src/App.h index 3a1777979..fc9449673 100644 --- a/src/App.h +++ b/src/App.h @@ -47,24 +47,23 @@ class Signals; class App : public IConsoleListener, public ISignalListener { public: - App(Process *process); - ~App() override; + App(Process *process); + ~App() override; - int exec(); + int exec(); protected: - void onConsoleCommand(char command) override; - void onSignal(int signum) override; + void onConsoleCommand(char command) override; + void onSignal(int signum) override; private: - void background(); - void close(); - void release(); + void background(); + void close(); - Console *m_console; - Controller *m_controller; - Httpd *m_httpd; - Signals *m_signals; + Console *m_console; + Controller *m_controller; + Httpd *m_httpd; + Signals *m_signals; }; diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 766ddbab6..1b30b4cdc 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -47,9 +47,9 @@ class xmrig::ControllerPrivate { public: inline ControllerPrivate(Process *process) : + config(nullptr), network(nullptr), - process(process), - config(nullptr) + process(process) {} @@ -60,10 +60,10 @@ public: } + Config *config; Network *network; Process *process; std::vector listeners; - Config *config; }; From 3393ea346b53da206c6fc23bceaafe15df466955 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Feb 2019 07:49:39 +0700 Subject: [PATCH 20/22] Removed unused code. --- src/core/ConfigLoader_platform.h | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index 749585df8..0b71c3fda 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -112,21 +112,6 @@ static struct option const config_options[] = { }; -static struct option const pool_options[] = { - { "url", 1, nullptr, xmrig::IConfig::UrlKey }, - { "pass", 1, nullptr, xmrig::IConfig::PasswordKey }, - { "user", 1, nullptr, xmrig::IConfig::UserKey }, - { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, - { "nicehash", 0, nullptr, xmrig::IConfig::NicehashKey }, - { "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey }, - { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, - { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, - { "tls", 0, nullptr, xmrig::IConfig::TlsKey }, - { "tls-fingerprint", 1, nullptr, xmrig::IConfig::FingerprintKey }, - { nullptr, 0, nullptr, 0 } -}; - - static struct option const api_options[] = { { "port", 1, nullptr, xmrig::IConfig::ApiPort }, { "access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey }, From 1bd51dcf2efb124d7b1bbd62fd0bc5f2f0ff6a17 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Feb 2019 09:15:06 +0700 Subject: [PATCH 21/22] Fixed msvc2015/msys2 build & code cleanup. --- cmake/asm.cmake | 14 +++++----- src/base/net/Pool.cpp | 28 +++++++++---------- src/crypto/asm/win64/CryptonightR_template.S | 1 + .../asm/win64/CryptonightR_template.asm | 1 + src/crypto/asm/win64/CryptonightR_template.h | 13 +++++++++ src/net/Network.cpp | 1 - src/net/Network.h | 1 - 7 files changed, 36 insertions(+), 23 deletions(-) diff --git a/cmake/asm.cmake b/cmake/asm.cmake index 143bc6d7b..dc6424ff2 100644 --- a/cmake/asm.cmake +++ b/cmake/asm.cmake @@ -5,37 +5,37 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) enable_language(ASM_MASM) if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141) - set(XMRIG_ASM_FILE + set(XMRIG_ASM_FILES "src/crypto/asm/cn_main_loop.asm" "src/crypto/asm/CryptonightR_template.asm" ) else() - set(XMRIG_ASM_FILE + set(XMRIG_ASM_FILES "src/crypto/asm/win64/cn_main_loop.asm" "src/crypto/asm/win64/CryptonightR_template.asm" ) endif() - set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY ASM_MASM) + set_property(SOURCE ${XMRIG_ASM_FILES} PROPERTY ASM_MASM) else() enable_language(ASM) if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU) - set(XMRIG_ASM_FILE + set(XMRIG_ASM_FILES "src/crypto/asm/win64/cn_main_loop.S" "src/crypto/asm/win64/CryptonightR_template.S" ) else() - set(XMRIG_ASM_FILE + set(XMRIG_ASM_FILES "src/crypto/asm/cn_main_loop.S" "src/crypto/asm/CryptonightR_template.S" ) endif() - set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY C) + set_property(SOURCE ${XMRIG_ASM_FILES} PROPERTY C) endif() - add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILE}) + add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILES}) set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) else() diff --git a/src/base/net/Pool.cpp b/src/base/net/Pool.cpp index 02f77b200..f66a8c9b6 100644 --- a/src/base/net/Pool.cpp +++ b/src/base/net/Pool.cpp @@ -479,19 +479,19 @@ void xmrig::Pool::rebuild() m_algorithms.push_back(m_algorithm); # ifndef XMRIG_PROXY_PROJECT - addVariant(xmrig::VARIANT_4); - addVariant(xmrig::VARIANT_WOW); - addVariant(xmrig::VARIANT_2); - addVariant(xmrig::VARIANT_1); - addVariant(xmrig::VARIANT_0); - addVariant(xmrig::VARIANT_HALF); - addVariant(xmrig::VARIANT_XTL); - addVariant(xmrig::VARIANT_TUBE); - addVariant(xmrig::VARIANT_MSR); - addVariant(xmrig::VARIANT_XHV); - addVariant(xmrig::VARIANT_XAO); - addVariant(xmrig::VARIANT_RTO); - addVariant(xmrig::VARIANT_GPU); - addVariant(xmrig::VARIANT_AUTO); + addVariant(VARIANT_4); + addVariant(VARIANT_WOW); + addVariant(VARIANT_2); + addVariant(VARIANT_1); + addVariant(VARIANT_0); + addVariant(VARIANT_HALF); + addVariant(VARIANT_XTL); + addVariant(VARIANT_TUBE); + addVariant(VARIANT_MSR); + addVariant(VARIANT_XHV); + addVariant(VARIANT_XAO); + addVariant(VARIANT_RTO); + addVariant(VARIANT_GPU); + addVariant(VARIANT_AUTO); # endif } diff --git a/src/crypto/asm/win64/CryptonightR_template.S b/src/crypto/asm/win64/CryptonightR_template.S index 4390bd455..5f3046cb9 100644 --- a/src/crypto/asm/win64/CryptonightR_template.S +++ b/src/crypto/asm/win64/CryptonightR_template.S @@ -529,6 +529,7 @@ PUBLIC FN_PREFIX(CryptonightR_instruction_mov254) PUBLIC FN_PREFIX(CryptonightR_instruction_mov255) PUBLIC FN_PREFIX(CryptonightR_instruction_mov256) +#include "CryptonightWOW_template.inc" #include "CryptonightR_template.inc" FN_PREFIX(CryptonightR_instruction0): diff --git a/src/crypto/asm/win64/CryptonightR_template.asm b/src/crypto/asm/win64/CryptonightR_template.asm index a16cf3289..25b72c3c0 100644 --- a/src/crypto/asm/win64/CryptonightR_template.asm +++ b/src/crypto/asm/win64/CryptonightR_template.asm @@ -516,6 +516,7 @@ PUBLIC CryptonightR_instruction_mov254 PUBLIC CryptonightR_instruction_mov255 PUBLIC CryptonightR_instruction_mov256 +INCLUDE CryptonightWOW_template_win.inc INCLUDE CryptonightR_template_win.inc CryptonightR_instruction0: diff --git a/src/crypto/asm/win64/CryptonightR_template.h b/src/crypto/asm/win64/CryptonightR_template.h index 182c6870f..c2054705b 100644 --- a/src/crypto/asm/win64/CryptonightR_template.h +++ b/src/crypto/asm/win64/CryptonightR_template.h @@ -2,6 +2,18 @@ extern "C" { + void CryptonightWOW_template_part1(); + void CryptonightWOW_template_mainloop(); + void CryptonightWOW_template_part2(); + void CryptonightWOW_template_part3(); + void CryptonightWOW_template_end(); + void CryptonightWOW_template_double_part1(); + void CryptonightWOW_template_double_mainloop(); + void CryptonightWOW_template_double_part2(); + void CryptonightWOW_template_double_part3(); + void CryptonightWOW_template_double_part4(); + void CryptonightWOW_template_double_end(); + void CryptonightR_template_part1(); void CryptonightR_template_mainloop(); void CryptonightR_template_part2(); @@ -13,6 +25,7 @@ extern "C" void CryptonightR_template_double_part3(); void CryptonightR_template_double_part4(); void CryptonightR_template_double_end(); + void CryptonightR_instruction0(); void CryptonightR_instruction1(); void CryptonightR_instruction2(); diff --git a/src/net/Network.cpp b/src/net/Network.cpp index a7177571d..34714c8ad 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -43,7 +43,6 @@ xmrig::Network::Network(Controller *controller) : - m_controller(controller), m_donate(nullptr) { Workers::setListener(this); diff --git a/src/net/Network.h b/src/net/Network.h index b11d6998e..5a5cbc3ef 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -69,7 +69,6 @@ private: static void onTick(uv_timer_t *handle); - Controller *m_controller; IStrategy *m_donate; IStrategy *m_strategy; NetworkState m_state; From 601453bff6a25347eb4cd693ec5b9db767278882 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 19 Feb 2019 09:57:21 +0700 Subject: [PATCH 22/22] Expired shares not allowed for cn/r. --- src/common/net/Client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/net/Client.cpp b/src/common/net/Client.cpp index d846175df..e87266619 100644 --- a/src/common/net/Client.cpp +++ b/src/common/net/Client.cpp @@ -223,7 +223,8 @@ int64_t xmrig::Client::submit(const JobResult &result) } # endif - if (m_job.algorithm().variant() == VARIANT_WOW && m_job.id() != result.jobId) { + const Variant variant = m_job.algorithm().variant(); + if ((variant == VARIANT_WOW || variant == VARIANT_4) && m_job.id() != result.jobId) { return -1; }