├── .gitignore ├── res ├── app.ico └── app.rc ├── android ├── libuv │ ├── lib │ │ ├── libuv_x86.a │ │ ├── libuv_armv7.a │ │ └── libuv_armv8.a │ └── include │ │ ├── uv-threadpool.h │ │ ├── uv-os390.h │ │ ├── uv-posix.h │ │ ├── uv-aix.h │ │ ├── uv-bsd.h │ │ ├── uv-linux.h │ │ ├── uv-version.h │ │ ├── android-ifaddrs.h │ │ ├── uv-sunos.h │ │ └── pthread-barrier.h └── jni │ └── Application.mk ├── cmake ├── FindUV.cmake ├── cpu.cmake ├── FindMHD.cmake └── flags.cmake ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── src ├── 3rdparty │ ├── libcpuid │ │ ├── CMakeLists.txt │ │ ├── recog_amd.h │ │ ├── recog_intel.h │ │ ├── libcpuid_types.h │ │ ├── amd_code_t.h │ │ ├── libcpuid_constants.h │ │ ├── intel_code_t.h │ │ ├── asm-bits.h │ │ ├── libcpuid_util.c │ │ └── libcpuid_util.h │ ├── rapidjson │ │ ├── internal │ │ │ ├── swap.h │ │ │ └── strfunc.h │ │ ├── ostreamwrapper.h │ │ ├── memorybuffer.h │ │ └── memorystream.h │ └── aligned_malloc.h ├── xmrig.cpp ├── interfaces │ ├── IConsoleListener.h │ ├── IJobResultListener.h │ ├── IConfigCreator.h │ ├── ILogBackend.h │ ├── IWatcherListener.h │ ├── IControllerListener.h │ ├── IWorker.h │ ├── IStrategy.h │ ├── IClientListener.h │ ├── IStrategyListener.h │ └── IThread.h ├── Cpu_win.cpp ├── Cpu_mac.cpp ├── common │ ├── log │ │ ├── SysLog.h │ │ ├── SysLog.cpp │ │ ├── FileLog.h │ │ ├── ConsoleLog.h │ │ ├── Log.cpp │ │ └── FileLog.cpp │ ├── api │ │ ├── HttpReply.h │ │ ├── HttpBody.h │ │ ├── Httpd.h │ │ └── HttpRequest.h │ ├── net │ │ ├── SubmitResult.cpp │ │ ├── SubmitResult.h │ │ ├── strategies │ │ │ ├── SinglePoolStrategy.h │ │ │ └── FailoverStrategy.h │ │ ├── Storage.h │ │ └── Id.h │ ├── utils │ │ └── mm_malloc.h │ ├── Console.h │ ├── Platform.h │ ├── crypto │ │ ├── keccak.h │ │ └── Algorithm.h │ ├── Platform.cpp │ ├── config │ │ ├── ConfigWatcher.h │ │ └── ConfigLoader.h │ ├── Console.cpp │ └── xmrig.h ├── Summary.h ├── core │ ├── ConfigCreator.h │ └── Controller.h ├── Cpu_unix.cpp ├── workers │ ├── Handle.cpp │ ├── Handle.h │ ├── Worker.cpp │ ├── MultiWorker.h │ ├── Worker.h │ └── Hashrate.h ├── App_win.cpp ├── api │ ├── Api.h │ ├── NetworkState.h │ ├── Api.cpp │ └── ApiRouter.h ├── Cpu_arm.cpp ├── config.json ├── Mem.cpp ├── App_unix.cpp ├── App.h ├── Mem.h ├── crypto │ ├── Lyra2_test.h │ └── Lyra2.h ├── net │ ├── JobResult.h │ ├── Network.h │ └── strategies │ │ └── DonateStrategy.h ├── version.h ├── donate.h ├── Cpu.h └── Mem_unix.cpp └── doc ├── ALGORITHMS.md ├── api └── 1 │ ├── threads.json │ ├── config.json │ └── summary.json └── API.md /.gitignore: -------------------------------------------------------------------------------- 1 | build/config.json 2 | /CMakeLists.txt.user 3 | -------------------------------------------------------------------------------- /res/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyX-Community/webchain-miner/master/res/app.ico -------------------------------------------------------------------------------- /android/libuv/lib/libuv_x86.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyX-Community/webchain-miner/master/android/libuv/lib/libuv_x86.a -------------------------------------------------------------------------------- /android/libuv/lib/libuv_armv7.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyX-Community/webchain-miner/master/android/libuv/lib/libuv_armv7.a -------------------------------------------------------------------------------- /android/libuv/lib/libuv_armv8.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EasyX-Community/webchain-miner/master/android/libuv/lib/libuv_armv8.a -------------------------------------------------------------------------------- /android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_PLATFORM := android-21 2 | NDK_TOOLCHAIN_VERSION := clang 3 | APP_STL := c++_static 4 | APP_ABI := armeabi-v7a arm64-v8a x86 5 | -------------------------------------------------------------------------------- /cmake/FindUV.cmake: -------------------------------------------------------------------------------- 1 | find_path( 2 | UV_INCLUDE_DIR 3 | NAMES uv.h 4 | PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" 5 | PATH_SUFFIXES "include" 6 | NO_DEFAULT_PATH 7 | ) 8 | 9 | find_path(UV_INCLUDE_DIR NAMES uv.h) 10 | 11 | find_library( 12 | UV_LIBRARY 13 | NAMES libuv.a uv libuv 14 | PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" 15 | PATH_SUFFIXES "lib" 16 | NO_DEFAULT_PATH 17 | ) 18 | 19 | find_library(UV_LIBRARY NAMES libuv.a uv libuv) 20 | 21 | set(UV_LIBRARIES ${UV_LIBRARY}) 22 | set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR}) 23 | 24 | include(FindPackageHandleStandardArgs) 25 | find_package_handle_standard_args(UV DEFAULT_MSG UV_LIBRARY UV_INCLUDE_DIR) 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.8) 2 | project (cpuid C) 3 | 4 | add_definitions(/DVERSION="0.4.0") 5 | 6 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os") 7 | 8 | set(HEADERS 9 | libcpuid.h 10 | libcpuid_types.h 11 | libcpuid_constants.h 12 | libcpuid_internal.h 13 | amd_code_t.h 14 | intel_code_t.h 15 | recog_amd.h 16 | recog_intel.h 17 | asm-bits.h 18 | libcpuid_util.h 19 | ) 20 | 21 | set(SOURCES 22 | cpuid_main.c 23 | asm-bits.c 24 | recog_amd.c 25 | recog_intel.c 26 | libcpuid_util.c 27 | ) 28 | 29 | if (CMAKE_CL_64) 30 | enable_language(ASM_MASM) 31 | set(SOURCES_ASM masm-x64.asm) 32 | endif() 33 | 34 | add_library(cpuid STATIC 35 | ${HEADERS} 36 | ${SOURCES} 37 | ${SOURCES_ASM} 38 | ) 39 | -------------------------------------------------------------------------------- /cmake/cpu.cmake: -------------------------------------------------------------------------------- 1 | if (NOT CMAKE_SYSTEM_PROCESSOR) 2 | message(WARNING "CMAKE_SYSTEM_PROCESSOR not defined") 3 | endif() 4 | 5 | 6 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") 7 | add_definitions(/DRAPIDJSON_SSE2) 8 | endif() 9 | 10 | 11 | if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64)$") 12 | set(XMRIG_ARM ON) 13 | set(XMRIG_ARMv8 ON) 14 | set(WITH_LIBCPUID OFF) 15 | 16 | add_definitions(/DXMRIG_ARM) 17 | add_definitions(/DXMRIG_ARMv8) 18 | elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7|armv7f|armv7s|armv7k|armv7-a|armv7l)$") 19 | set(XMRIG_ARM ON) 20 | set(XMRIG_ARMv7 ON) 21 | set(WITH_LIBCPUID OFF) 22 | 23 | add_definitions(/DXMRIG_ARM) 24 | add_definitions(/DXMRIG_ARMv7) 25 | elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^armv6") 26 | set(XMRIG_ARM ON) 27 | set(XMRIG_ARMv6 ON) 28 | set(WITH_LIBCPUID OFF) 29 | 30 | add_definitions(/DXMRIG_ARM) 31 | endif() 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /res/app.rc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../src/version.h" 3 | 4 | IDI_ICON1 ICON DISCARDABLE "app.ico" 5 | 6 | VS_VERSION_INFO VERSIONINFO 7 | FILEVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,APP_VER_REVISION 8 | PRODUCTVERSION APP_VER_MAJOR,APP_VER_MINOR,APP_VER_PATCH,APP_VER_REVISION 9 | FILEFLAGSMASK 0x3fL 10 | #ifdef _DEBUG 11 | FILEFLAGS VS_FF_DEBUG 12 | #else 13 | FILEFLAGS 0x0L 14 | #endif 15 | FILEOS VOS__WINDOWS32 16 | FILETYPE VFT_APP 17 | FILESUBTYPE 0x0L 18 | BEGIN 19 | BLOCK "StringFileInfo" 20 | BEGIN 21 | BLOCK "000004b0" 22 | BEGIN 23 | VALUE "CompanyName", APP_SITE 24 | VALUE "FileDescription", APP_DESC 25 | VALUE "FileVersion", APP_VERSION 26 | VALUE "LegalCopyright", APP_COPYRIGHT 27 | VALUE "OriginalFilename", "webchain-miner.exe" 28 | VALUE "ProductName", APP_NAME 29 | VALUE "ProductVersion", APP_VERSION 30 | END 31 | END 32 | BLOCK "VarFileInfo" 33 | BEGIN 34 | VALUE "Translation", 0x0, 1200 35 | END 36 | END 37 | -------------------------------------------------------------------------------- /src/xmrig.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #include "App.h" 25 | 26 | 27 | int main(int argc, char **argv) { 28 | App app(argc, argv); 29 | 30 | return app.exec(); 31 | } 32 | -------------------------------------------------------------------------------- /src/interfaces/IConsoleListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ICONSOLELISTENER_H__ 25 | #define __ICONSOLELISTENER_H__ 26 | 27 | 28 | class IConsoleListener 29 | { 30 | public: 31 | virtual ~IConsoleListener() {} 32 | 33 | virtual void onConsoleCommand(char command) = 0; 34 | }; 35 | 36 | 37 | #endif // __ICONSOLELISTENER_H__ 38 | -------------------------------------------------------------------------------- /src/Cpu_win.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | 27 | 28 | #include "Cpu.h" 29 | 30 | 31 | void Cpu::init() 32 | { 33 | # ifdef XMRIG_NO_LIBCPUID 34 | SYSTEM_INFO sysinfo; 35 | GetSystemInfo(&sysinfo); 36 | 37 | m_totalThreads = sysinfo.dwNumberOfProcessors; 38 | # endif 39 | 40 | initCommon(); 41 | } 42 | -------------------------------------------------------------------------------- /src/Cpu_mac.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016 Jay D Dee 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | #include "Cpu.h" 31 | 32 | 33 | void Cpu::init() 34 | { 35 | # ifdef XMRIG_NO_LIBCPUID 36 | m_totalThreads = sysconf(_SC_NPROCESSORS_CONF); 37 | # endif 38 | 39 | initCommon(); 40 | } 41 | -------------------------------------------------------------------------------- /src/interfaces/IJobResultListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __IJOBRESULTLISTENER_H__ 25 | #define __IJOBRESULTLISTENER_H__ 26 | 27 | 28 | class Client; 29 | class JobResult; 30 | 31 | 32 | class IJobResultListener 33 | { 34 | public: 35 | virtual ~IJobResultListener() {} 36 | 37 | virtual void onJobResult(const JobResult &result) = 0; 38 | }; 39 | 40 | 41 | #endif // __IJOBRESULTLISTENER_H__ 42 | -------------------------------------------------------------------------------- /src/interfaces/IConfigCreator.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2018 XMRig 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef __ICONFIGCREATOR_H__ 24 | #define __ICONFIGCREATOR_H__ 25 | 26 | 27 | namespace xmrig { 28 | 29 | 30 | class IConfig; 31 | 32 | 33 | class IConfigCreator 34 | { 35 | public: 36 | virtual ~IConfigCreator() {} 37 | 38 | virtual IConfig *create() const = 0; 39 | }; 40 | 41 | 42 | } /* namespace xmrig */ 43 | 44 | 45 | #endif // __ICONFIGCREATOR_H__ 46 | -------------------------------------------------------------------------------- /src/common/log/SysLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __SYSLOG_H__ 25 | #define __SYSLOG_H__ 26 | 27 | 28 | #include "interfaces/ILogBackend.h" 29 | 30 | 31 | class SysLog : public ILogBackend 32 | { 33 | public: 34 | SysLog(); 35 | 36 | void message(int level, const char *fmt, va_list args) override; 37 | void text(const char *fmt, va_list args) override; 38 | }; 39 | 40 | #endif /* __SYSLOG_BACKEND_H__ */ 41 | -------------------------------------------------------------------------------- /src/Summary.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __SUMMARY_H__ 25 | #define __SUMMARY_H__ 26 | 27 | 28 | namespace xmrig { 29 | class Controller; 30 | } 31 | 32 | 33 | class Summary 34 | { 35 | public: 36 | static void print(xmrig::Controller *controller); 37 | }; 38 | 39 | 40 | #endif /* __SUMMARY_H__ */ 41 | -------------------------------------------------------------------------------- /src/interfaces/ILogBackend.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ILOGBACKEND_H__ 25 | #define __ILOGBACKEND_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class ILogBackend 32 | { 33 | public: 34 | virtual ~ILogBackend() {} 35 | 36 | virtual void message(int level, const char* fmt, va_list args) = 0; 37 | virtual void text(const char* fmt, va_list args) = 0; 38 | }; 39 | 40 | 41 | #endif // __ILOGBACKEND_H__ 42 | -------------------------------------------------------------------------------- /src/common/log/SysLog.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | 27 | 28 | #include "common/log/SysLog.h" 29 | #include "version.h" 30 | 31 | 32 | SysLog::SysLog() 33 | { 34 | openlog(APP_ID, LOG_PID, LOG_USER); 35 | } 36 | 37 | 38 | void SysLog::message(int level, const char *fmt, va_list args) 39 | { 40 | vsyslog(level, fmt, args); 41 | } 42 | 43 | 44 | void SysLog::text(const char *fmt, va_list args) 45 | { 46 | message(LOG_INFO, fmt, args); 47 | } 48 | -------------------------------------------------------------------------------- /cmake/FindMHD.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find MHD 2 | # Once done this will define 3 | # 4 | # MHD_FOUND - system has MHD 5 | # MHD_INCLUDE_DIRS - the MHD include directory 6 | # MHD_LIBRARY - Link these to use MHD 7 | 8 | find_path( 9 | MHD_INCLUDE_DIR 10 | NAMES microhttpd.h 11 | PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" 12 | PATH_SUFFIXES "include" 13 | DOC "microhttpd include dir" 14 | NO_DEFAULT_PATH 15 | ) 16 | 17 | find_path(MHD_INCLUDE_DIR NAMES microhttpd.h) 18 | 19 | find_library( 20 | MHD_LIBRARY 21 | NAMES libmicrohttpd.a microhttpd libmicrohttpd 22 | PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS" 23 | PATH_SUFFIXES "lib" 24 | DOC "microhttpd library" 25 | NO_DEFAULT_PATH 26 | ) 27 | 28 | find_library(MHD_LIBRARY NAMES microhttpd libmicrohttpd) 29 | 30 | set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR}) 31 | set(MHD_LIBRARIES ${MHD_LIBRARY}) 32 | 33 | # debug library on windows 34 | # same naming convention as in qt (appending debug library with d) 35 | # boost is using the same "hack" as us with "optimized" and "debug" 36 | # official MHD project actually uses _d suffix 37 | if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) 38 | find_library( 39 | MHD_LIBRARY_DEBUG 40 | NAMES microhttpd_d microhttpd-10_d libmicrohttpd_d libmicrohttpd-dll_d 41 | DOC "mhd debug library" 42 | ) 43 | set(MHD_LIBRARIES optimized ${MHD_LIBRARIES} debug ${MHD_LIBRARY_DEBUG}) 44 | endif() 45 | 46 | include(FindPackageHandleStandardArgs) 47 | find_package_handle_standard_args(MHD DEFAULT_MSG MHD_LIBRARY MHD_INCLUDE_DIR) 48 | mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY) 49 | 50 | -------------------------------------------------------------------------------- /src/core/ConfigCreator.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2018 XMRig 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef __CONFIGCREATOR_H__ 24 | #define __CONFIGCREATOR_H__ 25 | 26 | 27 | #include "core/Config.h" 28 | #include "interfaces/IConfigCreator.h" 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class IConfig; 35 | 36 | 37 | class ConfigCreator : public IConfigCreator 38 | { 39 | public: 40 | inline IConfig *create() const override 41 | { 42 | return new Config(); 43 | } 44 | }; 45 | 46 | 47 | } /* namespace xmrig */ 48 | 49 | 50 | #endif // __CONFIGCREATOR_H__ 51 | -------------------------------------------------------------------------------- /src/3rdparty/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /android/libuv/include/uv-threadpool.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | /* 23 | * This file is private to libuv. It provides common functionality to both 24 | * Windows and Unix backends. 25 | */ 26 | 27 | #ifndef UV_THREADPOOL_H_ 28 | #define UV_THREADPOOL_H_ 29 | 30 | struct uv__work { 31 | void (*work)(struct uv__work *w); 32 | void (*done)(struct uv__work *w, int status); 33 | struct uv_loop_s* loop; 34 | void* wq[2]; 35 | }; 36 | 37 | #endif /* UV_THREADPOOL_H_ */ 38 | -------------------------------------------------------------------------------- /doc/ALGORITHMS.md: -------------------------------------------------------------------------------- 1 | # Algorithms 2 | 3 | XMRig uses a different way to specify algorithms, compared to other miners. 4 | 5 | Algorithm selection splitted to 2 parts: 6 | 7 | * Global base algorithm per miner or proxy instance, `algo` option. Possible values: `cryptonight`, `cryptonight-lite`, `cryptonight-heavy`. 8 | * Algorithm variant specified separately for each pool, `variant` option. 9 | 10 | Possible variants for `cryptonight`: 11 | 12 | * `0` Original cryptonight. 13 | * `1` cryptonight variant 1, also known as cryptonight v7 or monero7. 14 | * `"xtl"` Stellite coin variant. 15 | 16 | Possible variants for `cryptonight-lite`: 17 | 18 | * `0` Original cryptonight-lite. 19 | * `1` cryptonight-lite variant 1, also known as cryptonight-lite v7 or aeon7. 20 | * `"ipbc"` IPBC coin variant. 21 | 22 | For `cryptonight-heavy` currently no variants. 23 | 24 | 25 | ### Cheatsheet 26 | 27 | You mine **Sumokoin** or **Haven Protocol**? 28 | Your algorithm is `cryptonight-heavy` no variant option need. 29 | 30 | You mine **Aeon**, **TurtleCoin** or **IPBC**? 31 | Your base algorithm is `cryptonight-lite`: 32 | 33 | Variants: 34 | * Aeon: `-1` autodetect. `0` right now, `1` after fork. 35 | * TurtleCoin: `1`. 36 | * IPBC: `"ipbc"`. 37 | 38 | In all other cases base algorithm is `cryptonight`. 39 | 40 | ### Mining algorithm negotiation 41 | If your pool support [mining algorithm negotiation](https://github.com/xmrig/xmrig-proxy/issues/168) miner will choice proper variant automaticaly and if you choice wrong base algorithm you will see error message. 42 | 43 | Pools with mining algorithm negotiation support. 44 | * [www.hashvault.pro](https://www.hashvault.pro/) 45 | -------------------------------------------------------------------------------- /src/interfaces/IWatcherListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __IWATCHERLISTENER_H__ 25 | #define __IWATCHERLISTENER_H__ 26 | 27 | 28 | namespace xmrig { 29 | 30 | 31 | class IConfig; 32 | 33 | 34 | class IWatcherListener 35 | { 36 | public: 37 | virtual ~IWatcherListener() {} 38 | 39 | virtual void onNewConfig(IConfig *config) = 0; 40 | }; 41 | 42 | 43 | } /* namespace xmrig */ 44 | 45 | 46 | #endif // __IWATCHERLISTENER_H__ 47 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/recog_amd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __RECOG_AMD_H__ 27 | #define __RECOG_AMD_H__ 28 | 29 | int cpuid_identify_amd(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct internal_id_info_t* internal); 30 | 31 | #endif /* __RECOG_AMD_H__ */ 32 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/recog_intel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __RECOG_INTEL_H__ 27 | #define __RECOG_INTEL_H__ 28 | 29 | int cpuid_identify_intel(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct internal_id_info_t* internal); 30 | 31 | #endif /*__RECOG_INTEL_H__*/ 32 | -------------------------------------------------------------------------------- /android/libuv/include/uv-os390.h: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_MVS_H 23 | #define UV_MVS_H 24 | 25 | #define UV_PLATFORM_SEM_T int 26 | 27 | #define UV_PLATFORM_LOOP_FIELDS \ 28 | void* ep; \ 29 | 30 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 31 | char rfis_rftok[8]; \ 32 | 33 | #endif /* UV_MVS_H */ 34 | -------------------------------------------------------------------------------- /src/Cpu_unix.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #ifdef __FreeBSD__ 26 | # include 27 | # include 28 | # include 29 | # include 30 | #endif 31 | 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | #include "Cpu.h" 40 | 41 | 42 | #ifdef __FreeBSD__ 43 | typedef cpuset_t cpu_set_t; 44 | #endif 45 | 46 | 47 | void Cpu::init() 48 | { 49 | # ifdef XMRIG_NO_LIBCPUID 50 | m_totalThreads = sysconf(_SC_NPROCESSORS_CONF); 51 | # endif 52 | 53 | initCommon(); 54 | } 55 | -------------------------------------------------------------------------------- /src/common/log/FileLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __FILELOG_H__ 25 | #define __FILELOG_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #include "interfaces/ILogBackend.h" 32 | 33 | 34 | class FileLog : public ILogBackend 35 | { 36 | public: 37 | FileLog(const char *fileName); 38 | 39 | void message(int level, const char* fmt, va_list args) override; 40 | void text(const char* fmt, va_list args) override; 41 | 42 | private: 43 | static void onWrite(uv_fs_t *req); 44 | 45 | void write(char *data, size_t size); 46 | 47 | int m_file; 48 | }; 49 | 50 | #endif /* __FILELOG_H__ */ 51 | -------------------------------------------------------------------------------- /src/interfaces/IControllerListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ICONTROLLERLISTENER_H__ 25 | #define __ICONTROLLERLISTENER_H__ 26 | 27 | 28 | namespace xmrig { 29 | 30 | 31 | class Config; 32 | 33 | 34 | class IControllerListener 35 | { 36 | public: 37 | virtual ~IControllerListener() {} 38 | 39 | virtual void onConfigChanged(Config *config, Config *previousConfig) = 0; 40 | }; 41 | 42 | 43 | } /* namespace xmrig */ 44 | 45 | 46 | #endif // __ICONTROLLERLISTENER_H__ 47 | -------------------------------------------------------------------------------- /doc/api/1/threads.json: -------------------------------------------------------------------------------- 1 | { 2 | "hugepages": [ 3 | 4, 4 | 4 5 | ], 6 | "memory": 8388608, 7 | "threads": [ 8 | { 9 | "type": "cpu", 10 | "algo": "cryptonight", 11 | "av": 1, 12 | "low_power_mode": 1, 13 | "affine_to_cpu": 0, 14 | "priority": -1, 15 | "soft_aes": false, 16 | "hashrate": [ 17 | 73.39, 18 | 73.4, 19 | 73.28 20 | ] 21 | }, 22 | { 23 | "type": "cpu", 24 | "algo": "cryptonight", 25 | "av": 1, 26 | "low_power_mode": 1, 27 | "affine_to_cpu": 1, 28 | "priority": -1, 29 | "soft_aes": false, 30 | "hashrate": [ 31 | 74.72, 32 | 74.72, 33 | 74.7 34 | ] 35 | }, 36 | { 37 | "type": "cpu", 38 | "algo": "cryptonight", 39 | "av": 1, 40 | "low_power_mode": 1, 41 | "affine_to_cpu": 2, 42 | "priority": -1, 43 | "soft_aes": false, 44 | "hashrate": [ 45 | 74.71, 46 | 74.72, 47 | 74.7 48 | ] 49 | }, 50 | { 51 | "type": "cpu", 52 | "algo": "cryptonight", 53 | "av": 1, 54 | "low_power_mode": 1, 55 | "affine_to_cpu": 3, 56 | "priority": -1, 57 | "soft_aes": false, 58 | "hashrate": [ 59 | 73.39, 60 | 73.4, 61 | 73.28 62 | ] 63 | } 64 | ] 65 | } -------------------------------------------------------------------------------- /src/common/api/HttpReply.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __HTTPREPLY_H__ 26 | #define __HTTPREPLY_H__ 27 | 28 | 29 | #include 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class HttpReply 36 | { 37 | public: 38 | HttpReply() : 39 | buf(nullptr), 40 | status(200), 41 | size(0) 42 | {} 43 | 44 | char *buf; 45 | int status; 46 | size_t size; 47 | }; 48 | 49 | 50 | } /* namespace xmrig */ 51 | 52 | 53 | #endif /* __HTTPREPLY_H__ */ 54 | -------------------------------------------------------------------------------- /src/common/net/SubmitResult.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | 27 | 28 | #include "common/net/SubmitResult.h" 29 | 30 | 31 | SubmitResult::SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId) : 32 | reqId(reqId), 33 | seq(seq), 34 | diff(diff), 35 | actualDiff(actualDiff), 36 | elapsed(0) 37 | { 38 | start = uv_hrtime(); 39 | } 40 | 41 | 42 | void SubmitResult::done() 43 | { 44 | elapsed = (uv_hrtime() - start) / 1000000; 45 | } 46 | -------------------------------------------------------------------------------- /src/common/utils/mm_malloc.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __MM_MALLOC_PORTABLE_H__ 25 | #define __MM_MALLOC_PORTABLE_H__ 26 | 27 | 28 | #ifdef _WIN32 29 | # ifdef __GNUC__ 30 | # include 31 | # else 32 | # include 33 | # endif 34 | #else 35 | # if defined(XMRIG_ARM) && !defined(__clang__) 36 | # include "aligned_malloc.h" 37 | # else 38 | # include 39 | # endif 40 | #endif 41 | 42 | 43 | #endif /* __MM_MALLOC_PORTABLE_H__ */ 44 | -------------------------------------------------------------------------------- /src/interfaces/IWorker.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __IWORKER_H__ 25 | #define __IWORKER_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class IWorker 32 | { 33 | public: 34 | virtual ~IWorker() {} 35 | 36 | virtual bool selfTest() = 0; 37 | virtual size_t id() const = 0; 38 | virtual uint64_t hashCount() const = 0; 39 | virtual uint64_t timestamp() const = 0; 40 | virtual void start() = 0; 41 | }; 42 | 43 | 44 | #endif // __IWORKER_H__ 45 | -------------------------------------------------------------------------------- /src/workers/Handle.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include "workers/Handle.h" 26 | 27 | 28 | Handle::Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays) : 29 | m_worker(nullptr), 30 | m_totalWays(totalWays), 31 | m_offset(offset), 32 | m_config(config) 33 | { 34 | } 35 | 36 | 37 | void Handle::join() 38 | { 39 | uv_thread_join(&m_thread); 40 | } 41 | 42 | 43 | void Handle::start(void (*callback) (void *)) 44 | { 45 | uv_thread_create(&m_thread, callback, this); 46 | } 47 | -------------------------------------------------------------------------------- /android/libuv/include/uv-posix.h: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_POSIX_H 23 | #define UV_POSIX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | struct pollfd* poll_fds; \ 27 | size_t poll_fds_used; \ 28 | size_t poll_fds_size; \ 29 | unsigned char poll_fds_iterating; \ 30 | 31 | #endif /* UV_POSIX_H */ 32 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/libcpuid_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | /** 27 | * @File libcpuid_types.h 28 | * @Author Veselin Georgiev 29 | * @Brief Type specifications for libcpuid. 30 | */ 31 | 32 | #ifndef __LIBCPUID_TYPES_H__ 33 | #define __LIBCPUID_TYPES_H__ 34 | 35 | #include 36 | 37 | #endif /* __LIBCPUID_TYPES_H__ */ 38 | -------------------------------------------------------------------------------- /android/libuv/include/uv-aix.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_AIX_H 23 | #define UV_AIX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | int fs_fd; \ 27 | 28 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 29 | uv__io_t event_watcher; \ 30 | char *dir_filename; \ 31 | 32 | #endif /* UV_AIX_H */ 33 | -------------------------------------------------------------------------------- /android/libuv/include/uv-bsd.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_BSD_H 23 | #define UV_BSD_H 24 | 25 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 26 | uv__io_t event_watcher; \ 27 | 28 | #define UV_IO_PRIVATE_PLATFORM_FIELDS \ 29 | int rcount; \ 30 | int wcount; \ 31 | 32 | #define UV_HAVE_KQUEUE 1 33 | 34 | #endif /* UV_BSD_H */ 35 | -------------------------------------------------------------------------------- /src/App_win.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | 28 | 29 | #include "App.h" 30 | #include "core/Controller.h" 31 | #include "core/Config.h" 32 | 33 | 34 | void App::background() 35 | { 36 | if (!m_controller->config()->isBackground()) { 37 | return; 38 | } 39 | 40 | HWND hcon = GetConsoleWindow(); 41 | if (hcon) { 42 | ShowWindow(hcon, SW_HIDE); 43 | } else { 44 | HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); 45 | CloseHandle(h); 46 | FreeConsole(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/amd_code_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * This file contains a list of internal codes we use in detection. It is 29 | * of no external use and isn't a complete list of AMD products. 30 | */ 31 | CODE2(OPTERON_800, 1000), 32 | CODE(PHENOM), 33 | CODE(PHENOM2), 34 | CODE(FUSION_C), 35 | CODE(FUSION_E), 36 | CODE(FUSION_EA), 37 | CODE(FUSION_Z), 38 | CODE(FUSION_A), 39 | 40 | -------------------------------------------------------------------------------- /doc/api/1/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "algo": "cryptonight", 3 | "api": { 4 | "port": 44444, 5 | "access-token": "TOKEN", 6 | "worker-id": null, 7 | "ipv6": false, 8 | "restricted": false 9 | }, 10 | "av": 1, 11 | "background": false, 12 | "colors": true, 13 | "cpu-affinity": null, 14 | "cpu-priority": null, 15 | "donate-level": 5, 16 | "huge-pages": true, 17 | "hw-aes": null, 18 | "log-file": null, 19 | "max-cpu-usage": 75, 20 | "pools": [ 21 | { 22 | "url": "pool.monero.hashvault.pro:3333", 23 | "user": "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", 24 | "pass": "x", 25 | "keepalive": false, 26 | "nicehash": false, 27 | "variant": -1 28 | }, 29 | { 30 | "url": "pool.supportxmr.com:3333", 31 | "user": "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", 32 | "pass": "x", 33 | "keepalive": false, 34 | "nicehash": false, 35 | "variant": -1 36 | } 37 | ], 38 | "print-time": 60, 39 | "retries": 5, 40 | "retry-pause": 5, 41 | "safe": false, 42 | "threads": [ 43 | { 44 | "low_power_mode": 1, 45 | "affine_to_cpu": 0 46 | }, 47 | { 48 | "low_power_mode": 1, 49 | "affine_to_cpu": 1 50 | }, 51 | { 52 | "low_power_mode": 1, 53 | "affine_to_cpu": 2 54 | }, 55 | { 56 | "low_power_mode": 1, 57 | "affine_to_cpu": 3 58 | } 59 | ], 60 | "user-agent": null, 61 | "syslog": false, 62 | "watch": false 63 | } -------------------------------------------------------------------------------- /src/common/Console.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __CONSOLE_H__ 25 | #define __CONSOLE_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class IConsoleListener; 32 | 33 | 34 | class Console 35 | { 36 | public: 37 | Console(IConsoleListener *listener); 38 | 39 | private: 40 | static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf); 41 | static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf); 42 | 43 | char m_buf[1]; 44 | IConsoleListener *m_listener; 45 | uv_tty_t m_tty; 46 | }; 47 | 48 | 49 | #endif /* __CONSOLE_H__ */ 50 | -------------------------------------------------------------------------------- /src/common/Platform.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __PLATFORM_H__ 25 | #define __PLATFORM_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #include "common/utils/c_str.h" 32 | 33 | 34 | class Platform 35 | { 36 | public: 37 | static bool setThreadAffinity(uint64_t cpu_id); 38 | static const char *defaultConfigName(); 39 | static void init(const char *userAgent); 40 | static void setProcessPriority(int priority); 41 | static void setThreadPriority(int priority); 42 | 43 | static inline const char *userAgent() { return m_userAgent.data(); } 44 | 45 | private: 46 | static char m_defaultConfigName[520]; 47 | static xmrig::c_str m_userAgent; 48 | }; 49 | 50 | 51 | #endif /* __PLATFORM_H__ */ 52 | -------------------------------------------------------------------------------- /src/common/net/SubmitResult.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __SUBMITRESULT_H__ 25 | #define __SUBMITRESULT_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class SubmitResult 32 | { 33 | public: 34 | inline SubmitResult() : reqId(0), seq(0), diff(0), actualDiff(0), elapsed(0), start(0) {} 35 | SubmitResult(int64_t seq, uint32_t diff, uint64_t actualDiff, int64_t reqId = 0); 36 | 37 | void done(); 38 | 39 | int64_t reqId; 40 | int64_t seq; 41 | uint32_t diff; 42 | uint64_t actualDiff; 43 | uint64_t elapsed; 44 | 45 | private: 46 | uint64_t start; 47 | }; 48 | 49 | #endif /* __SUBMITRESULT_H__ */ 50 | -------------------------------------------------------------------------------- /doc/api/1/summary.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "92f3104f9a2ee78c", 3 | "worker_id": "Ubuntu-1604-xenial-64-minimal", 4 | "version": "2.6.0-beta3", 5 | "kind": "cpu", 6 | "ua": "XMRig/2.6.0-beta3 (Linux x86_64) libuv/1.8.0 gcc/5.4.0", 7 | "cpu": { 8 | "brand": "Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz", 9 | "aes": true, 10 | "x64": true, 11 | "sockets": 1 12 | }, 13 | "algo": "cryptonight", 14 | "hugepages": true, 15 | "donate_level": 5, 16 | "hashrate": { 17 | "total": [ 18 | 296.24, 19 | 296.23, 20 | 295.97 21 | ], 22 | "highest": 296.5, 23 | "threads": [ 24 | [ 25 | 73.39, 26 | 73.39, 27 | 73.28 28 | ], 29 | [ 30 | 74.72, 31 | 74.72, 32 | 74.71 33 | ], 34 | [ 35 | 74.72, 36 | 74.72, 37 | 74.71 38 | ], 39 | [ 40 | 73.39, 41 | 73.39, 42 | 73.27 43 | ] 44 | ] 45 | }, 46 | "results": { 47 | "diff_current": 9990, 48 | "shares_good": 30, 49 | "shares_total": 30, 50 | "avg_time": 31, 51 | "hashes_total": 311833, 52 | "best": [ 53 | 278199, 54 | 181923, 55 | 103717, 56 | 96632, 57 | 56154, 58 | 51580, 59 | 45667, 60 | 33159, 61 | 29581, 62 | 29514 63 | ], 64 | "error_log": [] 65 | }, 66 | "connection": { 67 | "pool": "pool.monero.hashvault.pro:3333", 68 | "uptime": 953, 69 | "ping": 35, 70 | "failures": 0, 71 | "error_log": [] 72 | } 73 | } -------------------------------------------------------------------------------- /src/interfaces/IStrategy.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ISTRATEGY_H__ 25 | #define __ISTRATEGY_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class JobResult; 32 | 33 | 34 | class IStrategy 35 | { 36 | public: 37 | virtual ~IStrategy() {} 38 | 39 | virtual bool isActive() const = 0; 40 | virtual int64_t submit(const JobResult &result) = 0; 41 | virtual void connect() = 0; 42 | virtual void resume() = 0; 43 | virtual void stop() = 0; 44 | virtual void tick(uint64_t now) = 0; 45 | }; 46 | 47 | 48 | #endif // __ISTRATEGY_H__ 49 | -------------------------------------------------------------------------------- /src/interfaces/IClientListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ICLIENTLISTENER_H__ 25 | #define __ICLIENTLISTENER_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class Client; 32 | class Job; 33 | class SubmitResult; 34 | 35 | 36 | class IClientListener 37 | { 38 | public: 39 | virtual ~IClientListener() {} 40 | 41 | virtual void onClose(Client *client, int failures) = 0; 42 | virtual void onJobReceived(Client *client, const Job &job) = 0; 43 | virtual void onLoginSuccess(Client *client) = 0; 44 | virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0; 45 | }; 46 | 47 | 48 | #endif // __ICLIENTLISTENER_H__ 49 | -------------------------------------------------------------------------------- /src/api/Api.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __API_H__ 25 | #define __API_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class ApiRouter; 32 | class Hashrate; 33 | class NetworkState; 34 | 35 | 36 | namespace xmrig { 37 | class Controller; 38 | class HttpReply; 39 | class HttpRequest; 40 | } 41 | 42 | 43 | class Api 44 | { 45 | public: 46 | static bool start(xmrig::Controller *controller); 47 | static void release(); 48 | 49 | static void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); 50 | static void tick(const NetworkState &results); 51 | 52 | private: 53 | static ApiRouter *m_router; 54 | }; 55 | 56 | #endif /* __API_H__ */ 57 | -------------------------------------------------------------------------------- /src/Cpu_arm.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | 27 | 28 | #include "Cpu.h" 29 | 30 | 31 | char Cpu::m_brand[64] = { 0 }; 32 | int Cpu::m_flags = 0; 33 | int Cpu::m_l2_cache = 0; 34 | int Cpu::m_l3_cache = 0; 35 | int Cpu::m_sockets = 1; 36 | int Cpu::m_totalCores = 0; 37 | size_t Cpu::m_totalThreads = 0; 38 | 39 | 40 | size_t Cpu::optimalThreadsCount(size_t size, int maxCpuUsage) 41 | { 42 | return m_totalThreads; 43 | } 44 | 45 | 46 | void Cpu::initCommon() 47 | { 48 | memcpy(m_brand, "Unknown", 7); 49 | 50 | # if defined(XMRIG_ARMv8) 51 | m_flags |= X86_64; 52 | m_flags |= AES; 53 | # endif 54 | } 55 | -------------------------------------------------------------------------------- /android/libuv/include/uv-linux.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_LINUX_H 23 | #define UV_LINUX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | uv__io_t inotify_read_watcher; \ 27 | void* inotify_watchers; \ 28 | int inotify_fd; \ 29 | 30 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 31 | void* watchers[2]; \ 32 | int wd; \ 33 | 34 | #endif /* UV_LINUX_H */ 35 | -------------------------------------------------------------------------------- /doc/API.md: -------------------------------------------------------------------------------- 1 | # HTTP API 2 | 3 | If you want use API you need choice a port where is internal HTTP server will listen for incoming connections. API will not available if miner built without `libmicrohttpd`. 4 | 5 | Example configuration: 6 | 7 | ```json 8 | "api": { 9 | "port": 44444, 10 | "access-token": "TOKEN", 11 | "worker-id": null, 12 | "ipv6": false, 13 | "restricted": false 14 | }, 15 | ``` 16 | 17 | * **port** Port for incoming connections `http://:`. 18 | * **access-token** [Bearer](https://gist.github.com/xmrig/c75fdd1f8e0f3bac05500be2ab718f8e#file-api-html-L54) access token to secure access to API. 19 | * **worker-id** Optional worker name, if not set will be detected automatically. 20 | * **ipv6** Enable (`true`) or disable (`false`) IPv6 for API. 21 | * **restricted** Use `false` to allow remote configuration. 22 | 23 | If you prefer use command line options instead of config file, you can use options: `--api-port`, `--api-access-token`, `--api-worker-id`, `--api-ipv6` and `api-no-restricted`. 24 | 25 | ## Endpoints 26 | 27 | ### GET /1/summary 28 | 29 | Get miner summary information. [Example](api/1/summary.json). 30 | 31 | ### GET /1/threads 32 | 33 | Get detailed information about miner threads. [Example](api/1/threads.json). 34 | 35 | 36 | ## Restricted endpoints 37 | 38 | All API endpoints below allow access to sensitive information and remote configure miner. You should set `access-token` and allow unrestricted access (`"restricted": false`). 39 | 40 | ### GET /1/config 41 | 42 | Get current miner configuration. [Example](api/1/config.json). 43 | 44 | 45 | ### PUT /1/config 46 | 47 | Update current miner configuration. Common use case, get current configuration, make changes, and upload it to miner. 48 | 49 | Curl example: 50 | 51 | ``` 52 | curl -v --data-binary @config.json -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer SECRET" http://127.0.0.1:44444/1/config 53 | ``` -------------------------------------------------------------------------------- /src/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "background": false, // true to run the miner in the background 3 | "colors": true, // false to disable colored output 4 | "cpu-affinity": null, // set process affinity to CPU core(s), mask "0x3" for cores 0 and 1 5 | "cpu-priority": null, // set process priority (0 idle, 2 normal to 5 highest) 6 | "donate-level": 5, // donate level, mininum 1% 7 | "huge-pages": true, 8 | "hw-aes": null, 9 | "log-file": null, // log all output to a file, example: "c:/some/path/webchain-miner.log" 10 | "max-cpu-usage": 75, // maximum CPU usage for automatic mode, usually limiting factor is CPU cache not this option. 11 | "print-time": 60, // print hashrate report every N seconds 12 | "retries": 5, // number of times to retry before switch to backup server 13 | "retry-pause": 5, // time to pause between retries 14 | "safe": false, // true to safe adjust threads and av settings for current CPU 15 | "threads": null, // number of miner threads 16 | "user-agent": null, 17 | "watch": false, 18 | "pools": [ 19 | { 20 | "url": "pool.webchain.network:3333", // URL of mining server 21 | "user": "YOUR_WALLET", // username for mining server 22 | "pass": "x", // password for mining server 23 | "keepalive": false, // send keepalived for prevent timeout (need pool support) 24 | "nicehash": false, 25 | "rig-id": null, 26 | } 27 | ], 28 | "api": { 29 | "port": 0, // port for the miner API https://github.com/xmrig/xmrig/wiki/API 30 | "access-token": null, // access token for API 31 | "worker-id": null, // custom worker-id for API 32 | "ipv6": false, 33 | "restricted": true 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Mem.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2016-2018 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include "common/utils/mm_malloc.h" 27 | #include "crypto/Lyra2.h" 28 | #include "Mem.h" 29 | 30 | 31 | bool Mem::m_enabled = true; 32 | int Mem::m_flags = 0; 33 | 34 | MemInfo Mem::create() 35 | { 36 | using namespace xmrig; 37 | 38 | MemInfo info; 39 | info.size = LYRA2_MEMSIZE; 40 | 41 | # ifndef XMRIG_NO_AEON 42 | info.size += info.size % (2 * 1024 * 1024); 43 | # endif 44 | 45 | info.pages = info.size / (2 * 1024 * 1024); 46 | 47 | allocate(info, m_enabled); 48 | 49 | return info; 50 | } 51 | 52 | 53 | void Mem::release(size_t count, MemInfo &info) 54 | { 55 | release(info); 56 | } 57 | -------------------------------------------------------------------------------- /src/common/crypto/keccak.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2011 Markku-Juhani O. Saarinen 4 | * Copyright 2012-2014 pooler 5 | * Copyright 2014 Lucas Jones 6 | * Copyright 2014-2016 Wolf9466 7 | * Copyright 2016 Jay D Dee 8 | * Copyright 2017-2018 XMR-Stak , 9 | * Copyright 2016-2018 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #ifndef KECCAK_H_ 27 | #define KECCAK_H_ 28 | 29 | #include 30 | #include 31 | 32 | 33 | namespace xmrig { 34 | 35 | // compute a keccak hash (md) of given byte length from "in" 36 | void keccak(const uint8_t *in, int inlen, uint8_t *md, int mdlen); 37 | 38 | 39 | inline void keccak(const uint8_t *in, size_t inlen, uint8_t *md) 40 | { 41 | keccak(in, static_cast(inlen), md, 200); 42 | } 43 | 44 | // update the state 45 | void keccakf(uint64_t st[25], int norounds); 46 | 47 | } /* namespace xmrig */ 48 | 49 | #endif /* KECCAK_H_ */ 50 | -------------------------------------------------------------------------------- /src/api/NetworkState.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __NETWORKSTATE_H__ 25 | #define __NETWORKSTATE_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | class SubmitResult; 33 | 34 | 35 | class NetworkState 36 | { 37 | public: 38 | NetworkState(); 39 | 40 | int connectionTime() const; 41 | uint32_t avgTime() const; 42 | uint32_t latency() const; 43 | void add(const SubmitResult &result, const char *error); 44 | void setPool(const char *host, int port, const char *ip); 45 | void stop(); 46 | 47 | char pool[256]; 48 | std::array topDiff { { } }; 49 | uint32_t diff; 50 | uint64_t accepted; 51 | uint64_t failures; 52 | uint64_t rejected; 53 | uint64_t total; 54 | 55 | private: 56 | bool m_active; 57 | std::vector m_latency; 58 | uint64_t m_connectionTime; 59 | }; 60 | 61 | #endif /* __NETWORKSTATE_H__ */ 62 | -------------------------------------------------------------------------------- /android/libuv/include/uv-version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_VERSION_H 23 | #define UV_VERSION_H 24 | 25 | /* 26 | * Versions with the same major number are ABI stable. API is allowed to 27 | * evolve between minor releases, but only in a backwards compatible way. 28 | * Make sure you update the -soname directives in configure.ac 29 | * and uv.gyp whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but 30 | * not UV_VERSION_PATCH.) 31 | */ 32 | 33 | #define UV_VERSION_MAJOR 1 34 | #define UV_VERSION_MINOR 18 35 | #define UV_VERSION_PATCH 1 36 | #define UV_VERSION_IS_RELEASE 0 37 | #define UV_VERSION_SUFFIX "dev" 38 | 39 | #define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \ 40 | (UV_VERSION_MINOR << 8) | \ 41 | (UV_VERSION_PATCH)) 42 | 43 | #endif /* UV_VERSION_H */ 44 | -------------------------------------------------------------------------------- /src/common/Platform.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | 28 | 29 | #include "Platform.h" 30 | 31 | 32 | char Platform::m_defaultConfigName[520] = { 0 }; 33 | xmrig::c_str Platform::m_userAgent; 34 | 35 | 36 | const char *Platform::defaultConfigName() 37 | { 38 | size_t size = 520; 39 | 40 | if (*m_defaultConfigName) { 41 | return m_defaultConfigName; 42 | } 43 | 44 | if (uv_exepath(m_defaultConfigName, &size) < 0) { 45 | return nullptr; 46 | } 47 | 48 | if (size < 500) { 49 | # ifdef WIN32 50 | char *p = strrchr(m_defaultConfigName, '\\'); 51 | # else 52 | char *p = strrchr(m_defaultConfigName, '/'); 53 | # endif 54 | 55 | if (p) { 56 | strcpy(p + 1, "config.json"); 57 | return m_defaultConfigName; 58 | } 59 | } 60 | 61 | *m_defaultConfigName = '\0'; 62 | return nullptr; 63 | } 64 | -------------------------------------------------------------------------------- /src/App_unix.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | 31 | #include "App.h" 32 | #include "common/log/Log.h" 33 | #include "core/Config.h" 34 | #include "core/Controller.h" 35 | 36 | 37 | void App::background() 38 | { 39 | signal(SIGPIPE, SIG_IGN); 40 | 41 | if (!m_controller->config()->isBackground()) { 42 | return; 43 | } 44 | 45 | int i = fork(); 46 | if (i < 0) { 47 | exit(1); 48 | } 49 | 50 | if (i > 0) { 51 | exit(0); 52 | } 53 | 54 | i = setsid(); 55 | 56 | if (i < 0) { 57 | LOG_ERR("setsid() failed (errno = %d)", errno); 58 | } 59 | 60 | i = chdir("/"); 61 | if (i < 0) { 62 | LOG_ERR("chdir() failed (errno = %d)", errno); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/common/log/ConsoleLog.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __CONSOLELOG_H__ 25 | #define __CONSOLELOG_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #include "interfaces/ILogBackend.h" 32 | 33 | 34 | namespace xmrig { 35 | class Controller; 36 | } 37 | 38 | 39 | class ConsoleLog : public ILogBackend 40 | { 41 | public: 42 | ConsoleLog(xmrig::Controller *controller); 43 | 44 | void message(int level, const char *fmt, va_list args) override; 45 | void text(const char *fmt, va_list args) override; 46 | 47 | private: 48 | bool isWritable() const; 49 | void print(va_list args); 50 | 51 | char m_buf[512]; 52 | char m_fmt[256]; 53 | uv_buf_t m_uvBuf; 54 | uv_stream_t *m_stream; 55 | uv_tty_t m_tty; 56 | xmrig::Controller *m_controller; 57 | }; 58 | 59 | #endif /* __CONSOLELOG_H__ */ 60 | -------------------------------------------------------------------------------- /src/common/api/HttpBody.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __HTTPBODY_H__ 26 | #define __HTTPBODY_H__ 27 | 28 | 29 | #include 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | class HttpBody 36 | { 37 | public: 38 | inline HttpBody() : 39 | m_pos(0) 40 | {} 41 | 42 | 43 | inline bool write(const char *data, size_t size) 44 | { 45 | if (size > (sizeof(m_data) - m_pos - 1)) { 46 | return false; 47 | } 48 | 49 | memcpy(m_data + m_pos, data, size); 50 | 51 | m_pos += size; 52 | m_data[m_pos] = '\0'; 53 | 54 | return true; 55 | } 56 | 57 | 58 | inline const char *data() const { return m_data; } 59 | 60 | private: 61 | char m_data[32768]; 62 | size_t m_pos; 63 | }; 64 | 65 | 66 | } /* namespace xmrig */ 67 | 68 | 69 | #endif /* __HTTPBODY_H__ */ 70 | -------------------------------------------------------------------------------- /src/core/Controller.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __CONTROLLER_H__ 25 | #define __CONTROLLER_H__ 26 | 27 | 28 | #include "interfaces/IWatcherListener.h" 29 | 30 | 31 | class Network; 32 | class StatsData; 33 | 34 | 35 | namespace xmrig { 36 | 37 | 38 | class Config; 39 | class ControllerPrivate; 40 | class IControllerListener; 41 | 42 | 43 | class Controller : public IWatcherListener 44 | { 45 | public: 46 | Controller(); 47 | ~Controller(); 48 | 49 | bool isReady() const; 50 | Config *config() const; 51 | int init(int argc, char **argv); 52 | Network *network() const; 53 | void addListener(IControllerListener *listener); 54 | 55 | protected: 56 | void onNewConfig(IConfig *config) override; 57 | 58 | private: 59 | ControllerPrivate *d_ptr; 60 | }; 61 | 62 | } /* namespace xmrig */ 63 | 64 | #endif /* __CONTROLLER_H__ */ 65 | -------------------------------------------------------------------------------- /android/libuv/include/android-ifaddrs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 1999 3 | * Berkeley Software Design, Inc. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND 12 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14 | * ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE 15 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 16 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 17 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 19 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 20 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 21 | * SUCH DAMAGE. 22 | * 23 | * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp 24 | */ 25 | 26 | #ifndef _IFADDRS_H_ 27 | #define _IFADDRS_H_ 28 | 29 | struct ifaddrs { 30 | struct ifaddrs *ifa_next; 31 | char *ifa_name; 32 | unsigned int ifa_flags; 33 | struct sockaddr *ifa_addr; 34 | struct sockaddr *ifa_netmask; 35 | struct sockaddr *ifa_dstaddr; 36 | void *ifa_data; 37 | }; 38 | 39 | /* 40 | * This may have been defined in . Note that if is 41 | * to be included it must be included before this header file. 42 | */ 43 | #ifndef ifa_broadaddr 44 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 45 | #endif 46 | 47 | #include 48 | 49 | __BEGIN_DECLS 50 | extern int getifaddrs(struct ifaddrs **ifap); 51 | extern void freeifaddrs(struct ifaddrs *ifa); 52 | __END_DECLS 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/libcpuid_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | /** 27 | * @File libcpuid_constants.h 28 | * @Author Veselin Georgiev 29 | * @Brief Some limits and constants for libcpuid 30 | */ 31 | 32 | #ifndef __LIBCPUID_CONSTANTS_H__ 33 | #define __LIBCPUID_CONSTANTS_H__ 34 | 35 | #define VENDOR_STR_MAX 16 36 | #define BRAND_STR_MAX 64 37 | #define CPU_FLAGS_MAX 128 38 | #define MAX_CPUID_LEVEL 32 39 | #define MAX_EXT_CPUID_LEVEL 32 40 | #define MAX_INTELFN4_LEVEL 8 41 | #define MAX_INTELFN11_LEVEL 4 42 | #define MAX_INTELFN12H_LEVEL 4 43 | #define MAX_INTELFN14H_LEVEL 4 44 | #define CPU_HINTS_MAX 16 45 | #define SGX_FLAGS_MAX 14 46 | 47 | #endif /* __LIBCPUID_CONSTANTS_H__ */ 48 | -------------------------------------------------------------------------------- /src/interfaces/IStrategyListener.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ISTRATEGYLISTENER_H__ 25 | #define __ISTRATEGYLISTENER_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class Client; 32 | class IStrategy; 33 | class Job; 34 | class SubmitResult; 35 | 36 | 37 | class IStrategyListener 38 | { 39 | public: 40 | virtual ~IStrategyListener() {} 41 | 42 | virtual void onActive(IStrategy *strategy, Client *client) = 0; 43 | virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0; 44 | virtual void onPause(IStrategy *strategy) = 0; 45 | virtual void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) = 0; 46 | }; 47 | 48 | 49 | #endif // __ISTRATEGYLISTENER_H__ 50 | -------------------------------------------------------------------------------- /src/3rdparty/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Custom strlen() which works on different character types. 24 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 25 | \param s Null-terminated input string. 26 | \return Number of characters in the string. 27 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 28 | */ 29 | template 30 | inline SizeType StrLen(const Ch* s) { 31 | const Ch* p = s; 32 | while (*p) ++p; 33 | return SizeType(p - s); 34 | } 35 | 36 | //! Returns number of code points in a encoded string. 37 | template 38 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 39 | GenericStringStream is(s); 40 | const typename Encoding::Ch* end = s + length; 41 | SizeType count = 0; 42 | while (is.src_ < end) { 43 | unsigned codepoint; 44 | if (!Encoding::Decode(is, &codepoint)) 45 | return false; 46 | count++; 47 | } 48 | *outCount = count; 49 | return true; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 56 | -------------------------------------------------------------------------------- /android/libuv/include/uv-sunos.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_SUNOS_H 23 | #define UV_SUNOS_H 24 | 25 | #include 26 | #include 27 | 28 | /* For the sake of convenience and reduced #ifdef-ery in src/unix/sunos.c, 29 | * add the fs_event fields even when this version of SunOS doesn't support 30 | * file watching. 31 | */ 32 | #define UV_PLATFORM_LOOP_FIELDS \ 33 | uv__io_t fs_event_watcher; \ 34 | int fs_fd; \ 35 | 36 | #if defined(PORT_SOURCE_FILE) 37 | 38 | # define UV_PLATFORM_FS_EVENT_FIELDS \ 39 | file_obj_t fo; \ 40 | int fd; \ 41 | 42 | #endif /* defined(PORT_SOURCE_FILE) */ 43 | 44 | #endif /* UV_SUNOS_H */ 45 | -------------------------------------------------------------------------------- /src/App.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __APP_H__ 25 | #define __APP_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #include "interfaces/IConsoleListener.h" 32 | 33 | 34 | class Console; 35 | class Httpd; 36 | class Network; 37 | class Options; 38 | 39 | 40 | namespace xmrig { 41 | class Controller; 42 | } 43 | 44 | 45 | class App : public IConsoleListener 46 | { 47 | public: 48 | App(int argc, char **argv); 49 | ~App(); 50 | 51 | int exec(); 52 | 53 | protected: 54 | void onConsoleCommand(char command) override; 55 | 56 | private: 57 | void background(); 58 | void close(); 59 | void release(); 60 | 61 | static void onSignal(uv_signal_t *handle, int signum); 62 | 63 | static App *m_self; 64 | 65 | Console *m_console; 66 | Httpd *m_httpd; 67 | uv_signal_t m_sigHUP; 68 | uv_signal_t m_sigINT; 69 | uv_signal_t m_sigTERM; 70 | xmrig::Controller *m_controller; 71 | }; 72 | 73 | 74 | #endif /* __APP_H__ */ 75 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/intel_code_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * This file contains a list of internal codes we use in detection. It is 29 | * of no external use and isn't a complete list of intel products. 30 | */ 31 | CODE2(PENTIUM, 2000), 32 | 33 | CODE(IRWIN), 34 | CODE(POTOMAC), 35 | CODE(GAINESTOWN), 36 | CODE(WESTMERE), 37 | 38 | CODE(PENTIUM_M), 39 | CODE(NOT_CELERON), 40 | 41 | CODE(CORE_SOLO), 42 | CODE(MOBILE_CORE_SOLO), 43 | CODE(CORE_DUO), 44 | CODE(MOBILE_CORE_DUO), 45 | 46 | CODE(WOLFDALE), 47 | CODE(MEROM), 48 | CODE(PENRYN), 49 | CODE(QUAD_CORE), 50 | CODE(DUAL_CORE_HT), 51 | CODE(QUAD_CORE_HT), 52 | CODE(MORE_THAN_QUADCORE), 53 | CODE(PENTIUM_D), 54 | 55 | CODE(SILVERTHORNE), 56 | CODE(DIAMONDVILLE), 57 | CODE(PINEVIEW), 58 | CODE(CEDARVIEW), 59 | -------------------------------------------------------------------------------- /src/api/Api.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #include 25 | 26 | 27 | #include "api/Api.h" 28 | #include "api/ApiRouter.h" 29 | #include "common/api/HttpReply.h" 30 | #include "common/api/HttpRequest.h" 31 | 32 | 33 | ApiRouter *Api::m_router = nullptr; 34 | 35 | 36 | bool Api::start(xmrig::Controller *controller) 37 | { 38 | m_router = new ApiRouter(controller); 39 | 40 | return true; 41 | } 42 | 43 | 44 | void Api::release() 45 | { 46 | delete m_router; 47 | } 48 | 49 | 50 | void Api::exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) 51 | { 52 | if (!m_router) { 53 | reply.status = 500; 54 | return; 55 | } 56 | 57 | if (req.method() == xmrig::HttpRequest::Get) { 58 | return m_router->get(req, reply); 59 | } 60 | 61 | m_router->exec(req, reply); 62 | } 63 | 64 | 65 | void Api::tick(const NetworkState &network) 66 | { 67 | if (!m_router) { 68 | return; 69 | } 70 | 71 | m_router->tick(network); 72 | } 73 | -------------------------------------------------------------------------------- /src/Mem.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2016-2018 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __MEM_H__ 26 | #define __MEM_H__ 27 | 28 | 29 | #include 30 | #include 31 | 32 | 33 | #include "common/xmrig.h" 34 | 35 | 36 | struct MemInfo 37 | { 38 | alignas(16) uint8_t *memory; 39 | 40 | size_t hugePages; 41 | size_t pages; 42 | size_t size; 43 | }; 44 | 45 | 46 | class Mem 47 | { 48 | public: 49 | enum Flags { 50 | HugepagesAvailable = 1, 51 | HugepagesEnabled = 2, 52 | Lock = 4 53 | }; 54 | 55 | static MemInfo create(); 56 | static void init(bool enabled); 57 | static void release(size_t count, MemInfo &info); 58 | 59 | static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } 60 | 61 | private: 62 | static void allocate(MemInfo &info, bool enabled); 63 | static void release(MemInfo &info); 64 | 65 | static int m_flags; 66 | static bool m_enabled; 67 | }; 68 | 69 | 70 | #endif /* __MEM_H__ */ 71 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/asm-bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __ASM_BITS_H__ 27 | #define __ASM_BITS_H__ 28 | #include "libcpuid.h" 29 | 30 | /* Determine Compiler: */ 31 | #if defined(_MSC_VER) 32 | # define COMPILER_MICROSOFT 33 | #elif defined(__GNUC__) 34 | # define COMPILER_GCC 35 | #endif 36 | 37 | /* Determine Platform */ 38 | #if defined(__x86_64__) || defined(_M_AMD64) 39 | # define PLATFORM_X64 40 | #elif defined(__i386__) || defined(_M_IX86) 41 | # define PLATFORM_X86 42 | #endif 43 | 44 | /* Under Windows/AMD64 with MSVC, inline assembly isn't supported */ 45 | #if (defined(COMPILER_GCC) && defined(PLATFORM_X64)) || defined(PLATFORM_X86) 46 | # define INLINE_ASM_SUPPORTED 47 | #endif 48 | 49 | int cpuid_exists_by_eflags(void); 50 | void exec_cpuid(uint32_t *regs); 51 | void busy_sse_loop(int cycles); 52 | 53 | #endif /* __ASM_BITS_H__ */ 54 | -------------------------------------------------------------------------------- /src/crypto/Lyra2_test.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2016-2018 XMRig , 10 | * Copyright 2018-2019 Webchain project 11 | * 12 | * This program is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | */ 25 | 26 | #ifndef __LYRA2_TEST_H__ 27 | #define __LYRA2_TEST_H__ 28 | 29 | 30 | const static uint8_t test_input[76] = { 31 | 0x03, 0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00, 32 | 0x7C, 0xBF, 0x34, 0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B, 33 | 0x30, 0x9A, 0xCE, 0x19, 0x23, 0xA0, 0x96, 0x4B, 0x00, 0x00, 0x00, 0x08, 0xBA, 0x93, 0x9A, 0x62, 34 | 0x72, 0x4C, 0x0D, 0x75, 0x81, 0xFC, 0xE5, 0x76, 0x1E, 0x9D, 0x8A, 0x0E, 0x6A, 0x1C, 0x3F, 0x92, 35 | 0x4F, 0xDD, 0x84, 0x93, 0xD1, 0x11, 0x56, 0x49, 0xC0, 0x5E, 0xB6, 0x01, 36 | }; 37 | 38 | // Webchain 39 | const static uint8_t test_output_v1[] = { 40 | 0x76, 0x98, 0xA3, 0xE1, 0x1C, 0x42, 0x91, 0x51, 0x6A, 0x7F, 0xD7, 0x3C, 0x4B, 0x83, 0x8B, 0x4D, 41 | 0xC5, 0x42, 0xF8, 0xB1, 0xE5, 0x57, 0x67, 0x90, 0x7B, 0x9F, 0x0E, 0xA2, 0x58, 0x34, 0x9D, 0xFA, 42 | }; 43 | 44 | #endif /* __LYRA2_TEST_H__ */ 45 | -------------------------------------------------------------------------------- /src/net/JobResult.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * Copyright 2018 Webchain project 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __JOBRESULT_H__ 26 | #define __JOBRESULT_H__ 27 | 28 | 29 | #include 30 | #include 31 | 32 | 33 | #include "common/net/Job.h" 34 | 35 | 36 | class JobResult 37 | { 38 | public: 39 | inline JobResult() : poolId(0), diff(0), nonce(0) {} 40 | inline JobResult(int poolId, const xmrig::Id &jobId, uint64_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) : 41 | poolId(poolId), 42 | diff(diff), 43 | nonce(nonce), 44 | algorithm(algorithm), 45 | jobId(jobId) 46 | { 47 | memcpy(this->result, result, sizeof(this->result)); 48 | } 49 | 50 | 51 | inline uint64_t actualDiff() const 52 | { 53 | return Job::toDiff(reinterpret_cast(result)[3]); 54 | } 55 | 56 | 57 | int poolId; 58 | uint32_t diff; 59 | uint64_t nonce; 60 | uint8_t result[32]; 61 | xmrig::Algorithm algorithm; 62 | xmrig::Id jobId; 63 | }; 64 | 65 | #endif /* __JOBRESULT_H__ */ 66 | -------------------------------------------------------------------------------- /src/workers/Handle.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __HANDLE_H__ 25 | #define __HANDLE_H__ 26 | 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | #include "interfaces/IThread.h" 34 | 35 | 36 | class IWorker; 37 | 38 | 39 | class Handle 40 | { 41 | public: 42 | Handle(xmrig::IThread *config, uint32_t offset, size_t totalWays); 43 | void join(); 44 | void start(void (*callback) (void *)); 45 | 46 | inline IWorker *worker() const { return m_worker; } 47 | inline size_t threadId() const { return m_config->index(); } 48 | inline size_t totalWays() const { return m_totalWays; } 49 | inline uint32_t offset() const { return m_offset; } 50 | inline void setWorker(IWorker *worker) { assert(worker != nullptr); m_worker = worker; } 51 | inline xmrig::IThread *config() const { return m_config; } 52 | 53 | private: 54 | IWorker *m_worker; 55 | size_t m_totalWays; 56 | uint32_t m_offset; 57 | uv_thread_t m_thread; 58 | xmrig::IThread *m_config; 59 | }; 60 | 61 | 62 | #endif /* __HANDLE_H__ */ 63 | -------------------------------------------------------------------------------- /src/common/config/ConfigWatcher.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __CONFIGWATCHER_H__ 25 | #define __CONFIGWATCHER_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | #include "common/utils/c_str.h" 33 | #include "rapidjson/fwd.h" 34 | 35 | 36 | struct option; 37 | 38 | 39 | namespace xmrig { 40 | 41 | 42 | class IConfigCreator; 43 | class IWatcherListener; 44 | 45 | 46 | class ConfigWatcher 47 | { 48 | public: 49 | ConfigWatcher(const char *path, IConfigCreator *creator, IWatcherListener *listener); 50 | ~ConfigWatcher(); 51 | 52 | private: 53 | constexpr static int kDelay = 500; 54 | 55 | static void onFsEvent(uv_fs_event_t* handle, const char *filename, int events, int status); 56 | static void onTimer(uv_timer_t* handle); 57 | void queueUpdate(); 58 | void reload(); 59 | void start(); 60 | 61 | IConfigCreator *m_creator; 62 | IWatcherListener *m_listener; 63 | uv_fs_event_t m_fsEvent; 64 | uv_timer_t m_timer; 65 | xmrig::c_str m_path; 66 | }; 67 | 68 | 69 | } /* namespace xmrig */ 70 | 71 | #endif /* __CONFIGWATCHER_H__ */ 72 | -------------------------------------------------------------------------------- /src/workers/Worker.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #include 25 | 26 | 27 | #include "common/Platform.h" 28 | #include "Cpu.h" 29 | #include "workers/CpuThread.h" 30 | #include "workers/Handle.h" 31 | #include "workers/Worker.h" 32 | 33 | 34 | Worker::Worker(Handle *handle) : 35 | m_id(handle->threadId()), 36 | m_totalWays(handle->totalWays()), 37 | m_offset(handle->offset()), 38 | m_hashCount(0), 39 | m_timestamp(0), 40 | m_count(0), 41 | m_sequence(0), 42 | m_thread(static_cast(handle->config())) 43 | { 44 | if (Cpu::threads() > 1 && m_thread->affinity() != -1L) { 45 | Platform::setThreadAffinity(m_thread->affinity()); 46 | } 47 | 48 | Platform::setThreadPriority(m_thread->priority()); 49 | } 50 | 51 | 52 | void Worker::storeStats() 53 | { 54 | using namespace std::chrono; 55 | 56 | const uint64_t timestamp = time_point_cast(high_resolution_clock::now()).time_since_epoch().count(); 57 | m_hashCount.store(m_count, std::memory_order_relaxed); 58 | m_timestamp.store(timestamp, std::memory_order_relaxed); 59 | } 60 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * Copyright 2018-2019 Webchain project 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __VERSION_H__ 26 | #define __VERSION_H__ 27 | 28 | #define APP_ID "webchain-miner" 29 | #define APP_NAME "webchain-miner" 30 | #define APP_DESC "webchain-miner CPU miner" 31 | #define APP_VERSION "2.8.0" 32 | #define APP_DOMAIN "webchain.network" 33 | #define APP_SITE "webchain.network" 34 | #define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com; Copyright (C) 2018-2019 Webchain project" 35 | #define APP_KIND "cpu" 36 | 37 | #define APP_VER_MAJOR 2 38 | #define APP_VER_MINOR 8 39 | #define APP_VER_PATCH 0 40 | #define APP_VER_REVISION 0 41 | 42 | #ifdef _MSC_VER 43 | # if (_MSC_VER >= 1910) 44 | # define MSVC_VERSION 2017 45 | # elif _MSC_VER == 1900 46 | # define MSVC_VERSION 2015 47 | # elif _MSC_VER == 1800 48 | # define MSVC_VERSION 2013 49 | # elif _MSC_VER == 1700 50 | # define MSVC_VERSION 2012 51 | # elif _MSC_VER == 1600 52 | # define MSVC_VERSION 2010 53 | # else 54 | # define MSVC_VERSION 0 55 | # endif 56 | #endif 57 | 58 | #endif /* __VERSION_H__ */ 59 | -------------------------------------------------------------------------------- /android/libuv/include/pthread-barrier.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2016, Kari Tristan Helgason 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef _UV_PTHREAD_BARRIER_ 18 | #define _UV_PTHREAD_BARRIER_ 19 | #include 20 | #include 21 | #if !defined(__MVS__) 22 | #include /* sem_t */ 23 | #endif 24 | 25 | #define PTHREAD_BARRIER_SERIAL_THREAD 0x12345 26 | #define UV__PTHREAD_BARRIER_FALLBACK 1 27 | 28 | /* 29 | * To maintain ABI compatibility with 30 | * libuv v1.x struct is padded according 31 | * to target platform 32 | */ 33 | #if defined(__ANDROID__) 34 | # define UV_BARRIER_STRUCT_PADDING \ 35 | sizeof(pthread_mutex_t) + \ 36 | sizeof(pthread_cond_t) + \ 37 | sizeof(unsigned int) - \ 38 | sizeof(void *) 39 | #elif defined(__APPLE__) 40 | # define UV_BARRIER_STRUCT_PADDING \ 41 | sizeof(pthread_mutex_t) + \ 42 | 2 * sizeof(sem_t) + \ 43 | 2 * sizeof(unsigned int) - \ 44 | sizeof(void *) 45 | #else 46 | # define UV_BARRIER_STRUCT_PADDING 0 47 | #endif 48 | 49 | typedef struct { 50 | pthread_mutex_t mutex; 51 | pthread_cond_t cond; 52 | unsigned threshold; 53 | unsigned in; 54 | unsigned out; 55 | } _uv_barrier; 56 | 57 | typedef struct { 58 | _uv_barrier* b; 59 | char _pad[UV_BARRIER_STRUCT_PADDING]; 60 | } pthread_barrier_t; 61 | 62 | int pthread_barrier_init(pthread_barrier_t* barrier, 63 | const void* barrier_attr, 64 | unsigned count); 65 | 66 | int pthread_barrier_wait(pthread_barrier_t* barrier); 67 | int pthread_barrier_destroy(pthread_barrier_t *barrier); 68 | 69 | #endif /* _UV_PTHREAD_BARRIER_ */ 70 | -------------------------------------------------------------------------------- /src/3rdparty/aligned_malloc.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ALIGNED_MALLOC_H__ 25 | #define __ALIGNED_MALLOC_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #ifndef __cplusplus 32 | extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size); 33 | #else 34 | // Some systems (e.g. those with GNU libc) declare posix_memalign with an 35 | // exception specifier. Via an "egregious workaround" in 36 | // Sema::CheckEquivalentExceptionSpec, Clang accepts the following as a valid 37 | // redeclaration of glibc's declaration. 38 | extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size); 39 | #endif 40 | 41 | 42 | static __inline__ void *__attribute__((__always_inline__, __malloc__)) _mm_malloc(size_t __size, size_t __align) 43 | { 44 | if (__align == 1) { 45 | return malloc(__size); 46 | } 47 | 48 | if (!(__align & (__align - 1)) && __align < sizeof(void *)) 49 | __align = sizeof(void *); 50 | 51 | void *__mallocedMemory; 52 | if (posix_memalign(&__mallocedMemory, __align, __size)) { 53 | return 0; 54 | } 55 | 56 | return __mallocedMemory; 57 | } 58 | 59 | 60 | static __inline__ void __attribute__((__always_inline__)) _mm_free(void *__p) 61 | { 62 | free(__p); 63 | } 64 | 65 | #endif /* __ALIGNED_MALLOC_H__ */ 66 | -------------------------------------------------------------------------------- /src/common/api/Httpd.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __HTTPD_H__ 25 | #define __HTTPD_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | struct MHD_Connection; 32 | struct MHD_Daemon; 33 | struct MHD_Response; 34 | 35 | 36 | class UploadCtx; 37 | 38 | 39 | namespace xmrig { 40 | class HttpRequest; 41 | } 42 | 43 | 44 | class Httpd 45 | { 46 | public: 47 | Httpd(int port, const char *accessToken, bool IPv6, bool restricted); 48 | ~Httpd(); 49 | bool start(); 50 | 51 | private: 52 | constexpr static const int kIdleInterval = 200; 53 | constexpr static const int kActiveInterval = 25; 54 | 55 | int process(xmrig::HttpRequest &req); 56 | void run(); 57 | 58 | static int handler(void *cls, MHD_Connection *connection, const char *url, const char *method, const char *version, const char *uploadData, size_t *uploadSize, void **con_cls); 59 | static void onTimer(uv_timer_t *handle); 60 | 61 | bool m_idle; 62 | bool m_IPv6; 63 | bool m_restricted; 64 | const char *m_accessToken; 65 | const int m_port; 66 | MHD_Daemon *m_daemon; 67 | uv_timer_t m_timer; 68 | }; 69 | 70 | #endif /* __HTTPD_H__ */ 71 | -------------------------------------------------------------------------------- /src/common/Console.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include "common/Console.h" 26 | #include "interfaces/IConsoleListener.h" 27 | 28 | 29 | Console::Console(IConsoleListener *listener) 30 | : m_listener(listener) 31 | { 32 | m_tty.data = this; 33 | uv_tty_init(uv_default_loop(), &m_tty, 0, 1); 34 | 35 | if (!uv_is_readable(reinterpret_cast(&m_tty))) { 36 | return; 37 | } 38 | 39 | uv_tty_set_mode(&m_tty, UV_TTY_MODE_RAW); 40 | uv_read_start(reinterpret_cast(&m_tty), Console::onAllocBuffer, Console::onRead); 41 | } 42 | 43 | 44 | void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) 45 | { 46 | auto console = static_cast(handle->data); 47 | buf->len = 1; 48 | buf->base = console->m_buf; 49 | } 50 | 51 | 52 | void Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) 53 | { 54 | if (nread < 0) { 55 | return uv_close(reinterpret_cast(stream), nullptr); 56 | } 57 | 58 | if (nread == 1) { 59 | static_cast(stream->data)->m_listener->onConsoleCommand(buf->base[0]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/workers/MultiWorker.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2016-2018 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __MULTIWORKER_H__ 26 | #define __MULTIWORKER_H__ 27 | 28 | 29 | #include "common/net/Job.h" 30 | #include "Mem.h" 31 | #include "net/JobResult.h" 32 | #include "workers/Worker.h" 33 | 34 | 35 | class Handle; 36 | 37 | 38 | template 39 | class MultiWorker : public Worker 40 | { 41 | public: 42 | MultiWorker(Handle *handle); 43 | ~MultiWorker(); 44 | 45 | protected: 46 | bool selfTest() override; 47 | void start() override; 48 | 49 | private: 50 | bool resume(const Job &job); 51 | void consumeJob(); 52 | void save(const Job &job); 53 | 54 | inline uint64_t *nonce(size_t index) 55 | { 56 | return reinterpret_cast(m_state.blob + ((index + 1) * m_state.job.size()) - 8); 57 | } 58 | 59 | struct State 60 | { 61 | alignas(16) uint8_t blob[BLOB_SIZE * N]; 62 | Job job; 63 | }; 64 | 65 | 66 | void *lyra2_ctx; 67 | State m_pausedState; 68 | State m_state; 69 | uint8_t m_hash[N * 32]; 70 | }; 71 | 72 | 73 | #endif /* __MULTIWORKER_H__ */ 74 | -------------------------------------------------------------------------------- /src/workers/Worker.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __WORKER_H__ 25 | #define __WORKER_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | #include "interfaces/IWorker.h" 33 | #include "Mem.h" 34 | 35 | 36 | class Handle; 37 | 38 | 39 | namespace xmrig { 40 | class CpuThread; 41 | } 42 | 43 | 44 | class Worker : public IWorker 45 | { 46 | public: 47 | Worker(Handle *handle); 48 | 49 | inline const MemInfo &memory() const { return m_memory; } 50 | inline size_t id() const override { return m_id; } 51 | inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); } 52 | inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); } 53 | 54 | protected: 55 | void storeStats(); 56 | 57 | const size_t m_id; 58 | const size_t m_totalWays; 59 | const uint32_t m_offset; 60 | MemInfo m_memory; 61 | std::atomic m_hashCount; 62 | std::atomic m_timestamp; 63 | uint64_t m_count; 64 | uint64_t m_sequence; 65 | xmrig::CpuThread *m_thread; 66 | }; 67 | 68 | 69 | #endif /* __WORKER_H__ */ 70 | -------------------------------------------------------------------------------- /src/interfaces/IThread.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2018 XMRig 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef __ITHREAD_H__ 24 | #define __ITHREAD_H__ 25 | 26 | 27 | #include 28 | 29 | 30 | #include "common/xmrig.h" 31 | #include "rapidjson/fwd.h" 32 | 33 | 34 | namespace xmrig { 35 | 36 | 37 | class IThread 38 | { 39 | public: 40 | enum Type { 41 | CPU, 42 | OpenCL, 43 | CUDA 44 | }; 45 | 46 | enum Multiway { 47 | SingleWay = 1, 48 | DoubleWay, 49 | TripleWay, 50 | QuadWay, 51 | PentaWay 52 | }; 53 | 54 | virtual ~IThread() {} 55 | 56 | virtual Algo algorithm() const = 0; 57 | virtual int priority() const = 0; 58 | virtual int64_t affinity() const = 0; 59 | virtual Multiway multiway() const = 0; 60 | virtual rapidjson::Value toConfig(rapidjson::Document &doc) const = 0; 61 | virtual size_t index() const = 0; 62 | virtual Type type() const = 0; 63 | 64 | # ifndef XMRIG_NO_API 65 | virtual rapidjson::Value toAPI(rapidjson::Document &doc) const = 0; 66 | # endif 67 | }; 68 | 69 | 70 | } /* namespace xmrig */ 71 | 72 | 73 | #endif // __ITHREAD_H__ 74 | -------------------------------------------------------------------------------- /src/donate.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __DONATE_H__ 25 | #define __DONATE_H__ 26 | 27 | 28 | /* 29 | * Dev donation. 30 | * 31 | * Percentage of your hashing power that you want to donate to the developer, can be 0 if you don't want to do that. 32 | * 33 | * Example of how it works for the setting of 1%: 34 | * You miner will mine into your usual pool for random time (in range from 49.5 to 148.5 minutes), 35 | * then switch to the developer's pool for 1 minute, then switch again to your pool for 99 minutes 36 | * and then switch agaiin to developer's pool for 1 minute, these rounds will continue until miner working. 37 | * 38 | * Randomised only first round, to prevent waves on the donation pool. 39 | * 40 | * Switching is instant, and only happens after a successful connection, so you never loose any hashes. 41 | * 42 | * If you plan on changing this setting to 0 please consider making a one off donation to my wallet: 43 | * XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD 44 | * BTC: 1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT 45 | */ 46 | constexpr const int kDefaultDonateLevel = 0; 47 | constexpr const int kMinimumDonateLevel = 0; 48 | 49 | 50 | #endif /* __DONATE_H__ */ 51 | -------------------------------------------------------------------------------- /src/common/log/Log.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #include "common/log/Log.h" 33 | #include "interfaces/ILogBackend.h" 34 | 35 | 36 | Log *Log::m_self = nullptr; 37 | 38 | 39 | void Log::message(Log::Level level, const char* fmt, ...) 40 | { 41 | uv_mutex_lock(&m_mutex); 42 | 43 | va_list args; 44 | va_list copy; 45 | va_start(args, fmt); 46 | 47 | for (ILogBackend *backend : m_backends) { 48 | va_copy(copy, args); 49 | backend->message(level, fmt, copy); 50 | va_end(copy); 51 | } 52 | 53 | va_end(args); 54 | 55 | uv_mutex_unlock(&m_mutex); 56 | } 57 | 58 | 59 | void Log::text(const char* fmt, ...) 60 | { 61 | uv_mutex_lock(&m_mutex); 62 | 63 | va_list args; 64 | va_list copy; 65 | va_start(args, fmt); 66 | 67 | for (ILogBackend *backend : m_backends) { 68 | va_copy(copy, args); 69 | backend->text(fmt, copy); 70 | va_end(copy); 71 | } 72 | 73 | va_end(args); 74 | 75 | uv_mutex_unlock(&m_mutex); 76 | } 77 | 78 | 79 | Log::~Log() 80 | { 81 | for (auto backend : m_backends) { 82 | delete backend; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Cpu.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __CPU_H__ 25 | #define __CPU_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | class Cpu 32 | { 33 | public: 34 | enum Flags { 35 | X86_64 = 1, 36 | AES = 2, 37 | BMI2 = 4 38 | }; 39 | 40 | static size_t optimalThreadsCount(size_t size, int maxCpuUsage); 41 | static void init(); 42 | 43 | static inline bool hasAES() { return (m_flags & AES) != 0; } 44 | static inline bool isX64() { return (m_flags & X86_64) != 0; } 45 | static inline const char *brand() { return m_brand; } 46 | static inline int cores() { return m_totalCores; } 47 | static inline int l2() { return m_l2_cache; } 48 | static inline int l3() { return m_l3_cache; } 49 | static inline int sockets() { return m_sockets; } 50 | static inline int threads() { return m_totalThreads; } 51 | 52 | private: 53 | static void initCommon(); 54 | 55 | static bool m_l2_exclusive; 56 | static char m_brand[64]; 57 | static int m_flags; 58 | static int m_l2_cache; 59 | static int m_l3_cache; 60 | static int m_sockets; 61 | static int m_totalCores; 62 | static size_t m_totalThreads; 63 | }; 64 | 65 | 66 | #endif /* __CPU_H__ */ 67 | -------------------------------------------------------------------------------- /src/workers/Hashrate.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __HASHRATE_H__ 25 | #define __HASHRATE_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | namespace xmrig { 33 | class Controller; 34 | } 35 | 36 | 37 | class Hashrate 38 | { 39 | public: 40 | enum Intervals { 41 | ShortInterval = 2500, 42 | MediumInterval = 60000, 43 | LargeInterval = 900000 44 | }; 45 | 46 | Hashrate(size_t threads, xmrig::Controller *controller); 47 | double calc(size_t ms) const; 48 | double calc(size_t threadId, size_t ms) const; 49 | void add(size_t threadId, uint64_t count, uint64_t timestamp); 50 | void print(); 51 | void stop(); 52 | void updateHighest(); 53 | 54 | inline double highest() const { return m_highest; } 55 | inline size_t threads() const { return m_threads; } 56 | 57 | private: 58 | static void onReport(uv_timer_t *handle); 59 | 60 | constexpr static size_t kBucketSize = 2 << 11; 61 | constexpr static size_t kBucketMask = kBucketSize - 1; 62 | 63 | double m_highest; 64 | size_t m_threads; 65 | uint32_t* m_top; 66 | uint64_t** m_counts; 67 | uint64_t** m_timestamps; 68 | uv_timer_t m_timer; 69 | xmrig::Controller *m_controller; 70 | }; 71 | 72 | 73 | #endif /* __HASHRATE_H__ */ 74 | -------------------------------------------------------------------------------- /src/common/net/strategies/SinglePoolStrategy.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __SINGLEPOOLSTRATEGY_H__ 25 | #define __SINGLEPOOLSTRATEGY_H__ 26 | 27 | 28 | #include "interfaces/IClientListener.h" 29 | #include "interfaces/IStrategy.h" 30 | 31 | 32 | class Client; 33 | class IStrategyListener; 34 | class Url; 35 | 36 | 37 | class SinglePoolStrategy : public IStrategy, public IClientListener 38 | { 39 | public: 40 | SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); 41 | ~SinglePoolStrategy(); 42 | 43 | public: 44 | inline bool isActive() const override { return m_active; } 45 | 46 | int64_t submit(const JobResult &result) override; 47 | void connect() override; 48 | void resume() override; 49 | void stop() override; 50 | void tick(uint64_t now) override; 51 | 52 | protected: 53 | void onClose(Client *client, int failures) override; 54 | void onJobReceived(Client *client, const Job &job) override; 55 | void onLoginSuccess(Client *client) override; 56 | void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; 57 | 58 | private: 59 | bool m_active; 60 | Client *m_client; 61 | IStrategyListener *m_listener; 62 | }; 63 | 64 | #endif /* __SINGLEPOOLSTRATEGY_H__ */ 65 | -------------------------------------------------------------------------------- /src/common/config/ConfigLoader.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __CONFIGLOADER_H__ 25 | #define __CONFIGLOADER_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #include "rapidjson/fwd.h" 32 | 33 | 34 | struct option; 35 | 36 | 37 | namespace xmrig { 38 | 39 | 40 | class ConfigWatcher; 41 | class IConfigCreator; 42 | class IWatcherListener; 43 | class IConfig; 44 | 45 | 46 | class ConfigLoader 47 | { 48 | public: 49 | static bool loadFromFile(IConfig *config, const char *fileName); 50 | static bool loadFromJSON(IConfig *config, const char *json); 51 | static bool loadFromJSON(IConfig *config, const rapidjson::Document &doc); 52 | static bool reload(IConfig *oldConfig, const char *json); 53 | static IConfig *load(int argc, char **argv, IConfigCreator *creator, IWatcherListener *listener); 54 | static void release(); 55 | 56 | private: 57 | static bool getJSON(const char *fileName, rapidjson::Document &doc); 58 | static bool parseArg(IConfig *config, int key, const char *arg); 59 | static void parseJSON(IConfig *config, const struct option *option, const rapidjson::Value &object); 60 | static void showUsage(); 61 | static void showVersion(); 62 | 63 | static ConfigWatcher *m_watcher; 64 | static IConfigCreator *m_creator; 65 | static IWatcherListener *m_listener; 66 | }; 67 | 68 | 69 | } /* namespace xmrig */ 70 | 71 | #endif /* __CONFIGLOADER_H__ */ 72 | -------------------------------------------------------------------------------- /src/net/Network.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __NETWORK_H__ 25 | #define __NETWORK_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | #include "api/NetworkState.h" 33 | #include "interfaces/IJobResultListener.h" 34 | #include "interfaces/IStrategyListener.h" 35 | 36 | 37 | class IStrategy; 38 | class Url; 39 | 40 | 41 | namespace xmrig { 42 | class Controller; 43 | } 44 | 45 | 46 | class Network : public IJobResultListener, public IStrategyListener 47 | { 48 | public: 49 | Network(xmrig::Controller *controller); 50 | ~Network(); 51 | 52 | void connect(); 53 | void stop(); 54 | 55 | protected: 56 | void onActive(IStrategy *strategy, Client *client) override; 57 | void onJob(IStrategy *strategy, Client *client, const Job &job) override; 58 | void onJobResult(const JobResult &result) override; 59 | void onPause(IStrategy *strategy) override; 60 | void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; 61 | 62 | private: 63 | constexpr static int kTickInterval = 1 * 1000; 64 | 65 | bool isColors() const; 66 | void setJob(Client *client, const Job &job, bool donate); 67 | void tick(); 68 | 69 | static void onTick(uv_timer_t *handle); 70 | 71 | IStrategy *m_donate; 72 | IStrategy *m_strategy; 73 | NetworkState m_state; 74 | uv_timer_t m_timer; 75 | xmrig::Controller *m_controller; 76 | }; 77 | 78 | 79 | #endif /* __NETWORK_H__ */ 80 | -------------------------------------------------------------------------------- /src/3rdparty/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /src/common/api/HttpRequest.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __HTTPREQUEST_H__ 26 | #define __HTTPREQUEST_H__ 27 | 28 | 29 | #include 30 | 31 | 32 | struct MHD_Connection; 33 | struct MHD_Response; 34 | 35 | 36 | namespace xmrig { 37 | 38 | 39 | class HttpBody; 40 | class HttpReply; 41 | 42 | 43 | class HttpRequest 44 | { 45 | public: 46 | enum Method { 47 | Unsupported, 48 | Options, 49 | Get, 50 | Put 51 | }; 52 | 53 | HttpRequest(MHD_Connection *connection, const char *url, const char *method, const char *uploadData, size_t *uploadSize, void **cls); 54 | ~HttpRequest(); 55 | 56 | inline bool isFulfilled() const { return m_fulfilled; } 57 | inline bool isRestricted() const { return m_restricted; } 58 | inline Method method() const { return m_method; } 59 | 60 | bool match(const char *path) const; 61 | bool process(const char *accessToken, bool restricted, xmrig::HttpReply &reply); 62 | const char *body() const; 63 | int end(const HttpReply &reply); 64 | int end(int status, MHD_Response *rsp); 65 | 66 | private: 67 | int auth(const char *accessToken); 68 | 69 | bool m_fulfilled; 70 | bool m_restricted; 71 | const char *m_uploadData; 72 | const char *m_url; 73 | HttpBody *m_body; 74 | Method m_method; 75 | MHD_Connection *m_connection; 76 | size_t *m_uploadSize; 77 | void **m_cls; 78 | }; 79 | 80 | 81 | } /* namespace xmrig */ 82 | 83 | 84 | #endif /* __HTTPREQUEST_H__ */ 85 | -------------------------------------------------------------------------------- /src/common/net/Storage.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __STORAGE_H__ 25 | #define __STORAGE_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | namespace xmrig { 33 | 34 | 35 | template 36 | class Storage 37 | { 38 | public: 39 | inline Storage() : 40 | m_counter(0) 41 | { 42 | } 43 | 44 | 45 | inline uintptr_t add(TYPE *ptr) 46 | { 47 | m_data[m_counter] = ptr; 48 | 49 | return m_counter++; 50 | } 51 | 52 | 53 | inline static void *ptr(uintptr_t id) { return reinterpret_cast(id); } 54 | 55 | 56 | inline TYPE *get(void *id) const { return get(reinterpret_cast(id)); } 57 | inline TYPE *get(uintptr_t id) const 58 | { 59 | assert(m_data.count(id) > 0); 60 | 61 | if (m_data.count(id) == 0) { 62 | return nullptr; 63 | } 64 | 65 | return m_data.at(id); 66 | } 67 | 68 | 69 | inline void remove(void *id) { remove(reinterpret_cast(id)); } 70 | inline void remove(uintptr_t id) 71 | { 72 | TYPE *obj = get(id); 73 | if (obj == nullptr) { 74 | return; 75 | } 76 | 77 | auto it = m_data.find(id); 78 | if (it != m_data.end()) { 79 | m_data.erase(it); 80 | } 81 | 82 | delete obj; 83 | } 84 | 85 | 86 | private: 87 | std::map m_data; 88 | uint64_t m_counter; 89 | }; 90 | 91 | 92 | } /* namespace xmrig */ 93 | 94 | 95 | #endif /* __STORAGE_H__ */ 96 | -------------------------------------------------------------------------------- /src/common/net/Id.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __ID_H__ 25 | #define __ID_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | namespace xmrig { 32 | 33 | 34 | class Id 35 | { 36 | public: 37 | inline Id() : 38 | m_data() 39 | { 40 | } 41 | 42 | 43 | inline Id(const char *id, size_t sizeFix = 0) 44 | { 45 | setId(id, sizeFix); 46 | } 47 | 48 | 49 | inline bool operator==(const Id &other) const 50 | { 51 | return memcmp(m_data, other.m_data, sizeof(m_data)) == 0; 52 | } 53 | 54 | 55 | inline bool operator!=(const Id &other) const 56 | { 57 | return memcmp(m_data, other.m_data, sizeof(m_data)) != 0; 58 | } 59 | 60 | 61 | Id &operator=(const Id &other) 62 | { 63 | memcpy(m_data, other.m_data, sizeof(m_data)); 64 | 65 | return *this; 66 | } 67 | 68 | 69 | inline bool setId(const char *id, size_t sizeFix = 0) 70 | { 71 | memset(m_data, 0, sizeof(m_data)); 72 | if (!id) { 73 | return false; 74 | } 75 | 76 | const size_t size = strlen(id); 77 | if (size >= sizeof(m_data)) { 78 | return false; 79 | } 80 | 81 | memcpy(m_data, id, size - sizeFix); 82 | return true; 83 | } 84 | 85 | 86 | inline const char *data() const { return m_data; } 87 | inline bool isValid() const { return *m_data != '\0'; } 88 | 89 | 90 | private: 91 | char m_data[64]; 92 | }; 93 | 94 | 95 | } /* namespace xmrig */ 96 | 97 | 98 | #endif /* __ID_H__ */ 99 | -------------------------------------------------------------------------------- /src/common/net/strategies/FailoverStrategy.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __FAILOVERSTRATEGY_H__ 25 | #define __FAILOVERSTRATEGY_H__ 26 | 27 | 28 | #include 29 | 30 | 31 | #include "common/net/Pool.h" 32 | #include "interfaces/IClientListener.h" 33 | #include "interfaces/IStrategy.h" 34 | 35 | 36 | class Client; 37 | class IStrategyListener; 38 | class Url; 39 | 40 | 41 | class FailoverStrategy : public IStrategy, public IClientListener 42 | { 43 | public: 44 | FailoverStrategy(const std::vector &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); 45 | ~FailoverStrategy(); 46 | 47 | public: 48 | inline bool isActive() const override { return m_active >= 0; } 49 | 50 | int64_t submit(const JobResult &result) override; 51 | void connect() override; 52 | void resume() override; 53 | void stop() override; 54 | void tick(uint64_t now) override; 55 | 56 | protected: 57 | void onClose(Client *client, int failures) override; 58 | void onJobReceived(Client *client, const Job &job) override; 59 | void onLoginSuccess(Client *client) override; 60 | void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override; 61 | 62 | private: 63 | void add(const Pool &pool); 64 | 65 | const bool m_quiet; 66 | const int m_retries; 67 | const int m_retryPause; 68 | int m_active; 69 | int m_index; 70 | IStrategyListener *m_listener; 71 | std::vector m_pools; 72 | }; 73 | 74 | #endif /* __FAILOVERSTRATEGY_H__ */ 75 | -------------------------------------------------------------------------------- /src/api/ApiRouter.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __APIROUTER_H__ 25 | #define __APIROUTER_H__ 26 | 27 | 28 | #include "api/NetworkState.h" 29 | #include "interfaces/IControllerListener.h" 30 | #include "rapidjson/fwd.h" 31 | 32 | 33 | class Hashrate; 34 | 35 | 36 | namespace xmrig { 37 | class Controller; 38 | class HttpReply; 39 | class HttpRequest; 40 | } 41 | 42 | 43 | class ApiRouter : public xmrig::IControllerListener 44 | { 45 | public: 46 | ApiRouter(xmrig::Controller *controller); 47 | ~ApiRouter(); 48 | 49 | void get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const; 50 | void exec(const xmrig::HttpRequest &req, xmrig::HttpReply &reply); 51 | 52 | void tick(const NetworkState &results); 53 | 54 | protected: 55 | void onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig) override; 56 | 57 | private: 58 | void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const; 59 | void genId(); 60 | void getConnection(rapidjson::Document &doc) const; 61 | void getHashrate(rapidjson::Document &doc) const; 62 | void getIdentify(rapidjson::Document &doc) const; 63 | void getMiner(rapidjson::Document &doc) const; 64 | void getResults(rapidjson::Document &doc) const; 65 | void getThreads(rapidjson::Document &doc) const; 66 | void setWorkerId(const char *id); 67 | void updateWorkerId(const char *id, const char *previousId); 68 | 69 | char m_id[17]; 70 | char m_workerId[128]; 71 | NetworkState m_network; 72 | xmrig::Controller *m_controller; 73 | }; 74 | 75 | #endif /* __APIROUTER_H__ */ 76 | -------------------------------------------------------------------------------- /src/3rdparty/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /src/crypto/Lyra2.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Header file for the Lyra2 Password Hashing Scheme (PHS). 3 | * 4 | * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014. 5 | * 6 | * This software is hereby placed in the public domain. 7 | * 8 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 9 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 12 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 15 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 16 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 17 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 18 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 19 | */ 20 | #ifndef LYRA2_H_ 21 | #define LYRA2_H_ 22 | 23 | #include 24 | 25 | typedef unsigned char byte; 26 | 27 | struct LYRA2_ctx { 28 | uint64_t *wholeMatrix; 29 | }; 30 | 31 | //Block length required so Blake2's Initialization Vector (IV) is not overwritten (THIS SHOULD NOT BE MODIFIED) 32 | #define BLOCK_LEN_BLAKE2_SAFE_INT64 8 //512 bits (=64 bytes, =8 uint64_t) 33 | #define BLOCK_LEN_BLAKE2_SAFE_BYTES (BLOCK_LEN_BLAKE2_SAFE_INT64 * 8) //same as above, in bytes 34 | 35 | 36 | #ifdef BLOCK_LEN_BITS 37 | #define BLOCK_LEN_INT64 (BLOCK_LEN_BITS/64) //Block length: 768 bits (=96 bytes, =12 uint64_t) 38 | #define BLOCK_LEN_BYTES (BLOCK_LEN_BITS/8) //Block length, in bytes 39 | #else //default block lenght: 768 bits 40 | #define BLOCK_LEN_INT64 12 //Block length: 768 bits (=96 bytes, =12 uint64_t) 41 | #define BLOCK_LEN_BYTES (BLOCK_LEN_INT64 * 8) //Block length, in bytes 42 | #endif 43 | 44 | #define NROWS 16384 45 | #define NCOLS 4 46 | #define LYRA2_MEMSIZE (BLOCK_LEN_INT64 * NCOLS * 8 * NROWS) 47 | 48 | #define memMatrix(x) (&ctx->wholeMatrix[x * BLOCK_LEN_INT64 * NCOLS]) 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | int LYRA2(void *ctx2, void *K, int64_t kLen, const void *pwd, int32_t pwdlen, uint32_t tcost); 54 | void *LYRA2_create(void); 55 | void LYRA2_destroy(void *c); 56 | 57 | 58 | static inline void lyra2_hash(const uint8_t *input, size_t size, uint8_t *output, void *ctx) 59 | { 60 | LYRA2(ctx, output, 32, input, size, 4); 61 | } 62 | 63 | static inline void lyra2v2_hash(const uint8_t *input, size_t size, uint8_t *output, void *ctx) 64 | { 65 | LYRA2(ctx, output, 32, input, size, 1); 66 | } 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* LYRA2_H_ */ 72 | -------------------------------------------------------------------------------- /src/common/xmrig.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __XMRIG_H__ 25 | #define __XMRIG_H__ 26 | 27 | #define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32)) 28 | 29 | namespace xmrig 30 | { 31 | 32 | 33 | enum Algo { 34 | INVALID_ALGO = -1, 35 | LYRA2, /* LYRA2 (Webchain) */ 36 | LYRA2v2 /* LYRA2v2 (Webchain) */ 37 | }; 38 | 39 | 40 | //--av=1 For CPUs with hardware AES. 41 | //--av=2 Lower power mode (double hash) of 1. 42 | //--av=3 Software AES implementation. 43 | //--av=4 Lower power mode (double hash) of 3. 44 | enum AlgoVariant { 45 | AV_AUTO, // --av=0 Automatic mode. 46 | AV_SINGLE, // --av=1 Single hash mode 47 | AV_DOUBLE, // --av=2 Double hash mode 48 | AV_SINGLE_SOFT, // --av=3 Single hash mode (Software AES) 49 | AV_DOUBLE_SOFT, // --av=4 Double hash mode (Software AES) 50 | AV_TRIPLE, // --av=5 Triple hash mode 51 | AV_QUAD, // --av=6 Quard hash mode 52 | AV_PENTA, // --av=7 Penta hash mode 53 | AV_TRIPLE_SOFT, // --av=8 Triple hash mode (Software AES) 54 | AV_QUAD_SOFT, // --av=9 Quard hash mode (Software AES) 55 | AV_PENTA_SOFT, // --av=10 Penta hash mode (Software AES) 56 | AV_MAX 57 | }; 58 | 59 | 60 | enum Variant { 61 | VARIANT_AUTO = -1, // Autodetect 62 | VARIANT_0 = 0, // Original CryptoNight or CryptoNight-Heavy 63 | VARIANT_1 = 1, // CryptoNight variant 1 also known as Monero7 and CryptoNightV7 64 | }; 65 | 66 | 67 | enum AesMode { 68 | AES_AUTO, 69 | AES_HW, 70 | AES_SOFT 71 | }; 72 | 73 | 74 | } /* namespace xmrig */ 75 | 76 | 77 | #endif /* __XMRIG_H__ */ 78 | -------------------------------------------------------------------------------- /src/net/strategies/DonateStrategy.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2016-2018 XMRig , 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef __DONATESTRATEGY_H__ 25 | #define __DONATESTRATEGY_H__ 26 | 27 | 28 | #include 29 | #include 30 | 31 | 32 | #include "common/net/Pool.h" 33 | #include "interfaces/IClientListener.h" 34 | #include "interfaces/IStrategy.h" 35 | #include "interfaces/IStrategyListener.h" 36 | 37 | 38 | class Client; 39 | class IStrategyListener; 40 | class Url; 41 | 42 | 43 | class DonateStrategy : public IStrategy, public IStrategyListener 44 | { 45 | public: 46 | DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); 47 | ~DonateStrategy(); 48 | 49 | public: 50 | inline bool isActive() const override { return m_active; } 51 | inline void resume() override {} 52 | 53 | int64_t submit(const JobResult &result) override; 54 | void connect() override; 55 | void stop() override; 56 | void tick(uint64_t now) override; 57 | 58 | protected: 59 | void onActive(IStrategy *strategy, Client *client) override; 60 | void onJob(IStrategy *strategy, Client *client, const Job &job) override; 61 | void onPause(IStrategy *strategy) override; 62 | void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override; 63 | 64 | private: 65 | void idle(uint64_t timeout); 66 | void suspend(); 67 | 68 | static void onTimer(uv_timer_t *handle); 69 | 70 | bool m_active; 71 | const int m_donateTime; 72 | const int m_idleTime; 73 | IStrategy *m_strategy; 74 | IStrategyListener *m_listener; 75 | std::vector m_pools; 76 | uv_timer_t m_timer; 77 | }; 78 | 79 | #endif /* __DONATESTRATEGY_H__ */ 80 | -------------------------------------------------------------------------------- /src/3rdparty/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /src/common/log/FileLog.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2016-2017 XMRig 8 | * 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #include "common/log/FileLog.h" 33 | 34 | 35 | FileLog::FileLog(const char *fileName) 36 | { 37 | uv_fs_t req; 38 | m_file = uv_fs_open(uv_default_loop(), &req, fileName, O_CREAT | O_APPEND | O_WRONLY, 0644, nullptr); 39 | uv_fs_req_cleanup(&req); 40 | } 41 | 42 | 43 | void FileLog::message(int level, const char* fmt, va_list args) 44 | { 45 | if (m_file < 0) { 46 | return; 47 | } 48 | 49 | time_t now = time(nullptr); 50 | tm stime; 51 | 52 | # ifdef _WIN32 53 | localtime_s(&stime, &now); 54 | # else 55 | localtime_r(&now, &stime); 56 | # endif 57 | 58 | char *buf = new char[512]; 59 | int size = snprintf(buf, 23, "[%d-%02d-%02d %02d:%02d:%02d] ", 60 | stime.tm_year + 1900, 61 | stime.tm_mon + 1, 62 | stime.tm_mday, 63 | stime.tm_hour, 64 | stime.tm_min, 65 | stime.tm_sec); 66 | 67 | size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size; 68 | buf[size] = '\n'; 69 | 70 | write(buf, size + 1); 71 | } 72 | 73 | 74 | void FileLog::text(const char* fmt, va_list args) 75 | { 76 | message(0, fmt, args); 77 | } 78 | 79 | 80 | 81 | void FileLog::onWrite(uv_fs_t *req) 82 | { 83 | delete [] static_cast(req->data); 84 | 85 | uv_fs_req_cleanup(req); 86 | delete req; 87 | } 88 | 89 | 90 | void FileLog::write(char *data, size_t size) 91 | { 92 | uv_buf_t buf = uv_buf_init(data, (unsigned int) size); 93 | uv_fs_t *req = new uv_fs_t; 94 | req->data = buf.base; 95 | 96 | uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, 0, FileLog::onWrite); 97 | } 98 | -------------------------------------------------------------------------------- /cmake/flags.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 2 | set(CMAKE_CXX_EXTENSIONS OFF) 3 | set(CMAKE_CXX_STANDARD 11) 4 | 5 | if ("${CMAKE_BUILD_TYPE}" STREQUAL "") 6 | set(CMAKE_BUILD_TYPE Release) 7 | endif() 8 | 9 | if (CMAKE_BUILD_TYPE STREQUAL "Release") 10 | add_definitions(/DNDEBUG) 11 | endif() 12 | 13 | if (CMAKE_CXX_COMPILER_ID MATCHES GNU) 14 | 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing") 16 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast") 17 | 18 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti") 19 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s") 20 | 21 | if (XMRIG_ARMv8) 22 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto") 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crypto -flax-vector-conversions") 24 | elseif (XMRIG_ARMv7) 25 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon") 26 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -flax-vector-conversions") 27 | elseif (XMRIG_ARMv6) 28 | else() 29 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes") 30 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes") 31 | endif() 32 | 33 | if (WIN32) 34 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") 35 | else() 36 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") 37 | endif() 38 | 39 | add_definitions(/D_GNU_SOURCE) 40 | 41 | if (${CMAKE_VERSION} VERSION_LESS "3.1.0") 42 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 43 | endif() 44 | 45 | #set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -gdwarf-2") 46 | 47 | elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) 48 | 49 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL") 50 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL") 51 | add_definitions(/D_CRT_SECURE_NO_WARNINGS) 52 | add_definitions(/D_CRT_NONSTDC_NO_WARNINGS) 53 | add_definitions(/DNOMINMAX) 54 | 55 | elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) 56 | 57 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") 58 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants") 59 | 60 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-exceptions -fno-rtti -Wno-missing-braces") 61 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants") 62 | 63 | if (XMRIG_ARMv8) 64 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto") 65 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a+crypto") 66 | elseif (XMRIG_ARMv7) 67 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") 68 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -march=${CMAKE_SYSTEM_PROCESSOR}") 69 | else() 70 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes") 71 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes") 72 | endif() 73 | 74 | endif() 75 | -------------------------------------------------------------------------------- /src/Mem_unix.cpp: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2016-2018 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | 26 | #include 27 | #include 28 | 29 | 30 | #include "common/log/Log.h" 31 | #include "common/utils/mm_malloc.h" 32 | #include "common/xmrig.h" 33 | #include "Mem.h" 34 | 35 | 36 | void Mem::init(bool enabled) 37 | { 38 | m_enabled = enabled; 39 | } 40 | 41 | 42 | void Mem::allocate(MemInfo &info, bool enabled) 43 | { 44 | info.hugePages = 0; 45 | 46 | if (!enabled) { 47 | info.memory = static_cast(_mm_malloc(info.size, 4096)); 48 | 49 | return; 50 | } 51 | 52 | # if defined(__APPLE__) 53 | info.memory = static_cast(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0)); 54 | # elif defined(__FreeBSD__) 55 | info.memory = static_cast(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0)); 56 | # else 57 | info.memory = static_cast(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0)); 58 | # endif 59 | 60 | if (info.memory == MAP_FAILED) { 61 | return allocate(info, false);; 62 | } 63 | 64 | info.hugePages = info.pages; 65 | 66 | if (madvise(info.memory, info.size, MADV_RANDOM | MADV_WILLNEED) != 0) { 67 | LOG_ERR("madvise failed"); 68 | } 69 | 70 | if (mlock(info.memory, info.size) == 0) { 71 | m_flags |= Lock; 72 | } 73 | } 74 | 75 | 76 | void Mem::release(MemInfo &info) 77 | { 78 | if (info.hugePages) { 79 | if (m_flags & Lock) { 80 | munlock(info.memory, info.size); 81 | } 82 | 83 | munmap(info.memory, info.size); 84 | } 85 | else { 86 | _mm_free(info.memory); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/libcpuid_util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "libcpuid.h" 33 | #include "libcpuid_util.h" 34 | 35 | void match_features(const struct feature_map_t* matchtable, int count, uint32_t reg, struct cpu_id_t* data) 36 | { 37 | int i; 38 | for (i = 0; i < count; i++) 39 | if (reg & (1u << matchtable[i].bit)) 40 | data->flags[matchtable[i].feature] = 1; 41 | } 42 | 43 | static int xmatch_entry(char c, const char* p) 44 | { 45 | int i, j; 46 | if (c == 0) return -1; 47 | if (c == p[0]) return 1; 48 | if (p[0] == '.') return 1; 49 | if (p[0] == '#' && isdigit(c)) return 1; 50 | if (p[0] == '[') { 51 | j = 1; 52 | while (p[j] && p[j] != ']') j++; 53 | if (!p[j]) return -1; 54 | for (i = 1; i < j; i++) 55 | if (p[i] == c) return j + 1; 56 | } 57 | return -1; 58 | } 59 | 60 | int match_pattern(const char* s, const char* p) 61 | { 62 | int i, j, dj, k, n, m; 63 | n = (int) strlen(s); 64 | m = (int) strlen(p); 65 | for (i = 0; i < n; i++) { 66 | if (xmatch_entry(s[i], p) != -1) { 67 | j = 0; 68 | k = 0; 69 | while (j < m && ((dj = xmatch_entry(s[i + k], p + j)) != -1)) { 70 | k++; 71 | j += dj; 72 | } 73 | if (j == m) return i + 1; 74 | } 75 | } 76 | return 0; 77 | } 78 | 79 | struct cpu_id_t* get_cached_cpuid(void) 80 | { 81 | static int initialized = 0; 82 | static struct cpu_id_t id; 83 | if (initialized) return &id; 84 | if (cpu_identify(NULL, &id)) 85 | memset(&id, 0, sizeof(id)); 86 | initialized = 1; 87 | return &id; 88 | } 89 | 90 | int match_all(uint64_t bits, uint64_t mask) 91 | { 92 | return (bits & mask) == mask; 93 | } 94 | -------------------------------------------------------------------------------- /src/common/crypto/Algorithm.h: -------------------------------------------------------------------------------- 1 | /* XMRig 2 | * Copyright 2010 Jeff Garzik 3 | * Copyright 2012-2014 pooler 4 | * Copyright 2014 Lucas Jones 5 | * Copyright 2014-2016 Wolf9466 6 | * Copyright 2016 Jay D Dee 7 | * Copyright 2017-2018 XMR-Stak , 8 | * Copyright 2018 Lee Clagett 9 | * Copyright 2016-2018 XMRig , 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef __ALGORITHM_H__ 26 | #define __ALGORITHM_H__ 27 | 28 | 29 | #include 30 | 31 | 32 | #include "common/xmrig.h" 33 | 34 | 35 | namespace xmrig { 36 | 37 | 38 | class Algorithm 39 | { 40 | public: 41 | inline Algorithm() : 42 | m_algo(INVALID_ALGO), 43 | m_variant(VARIANT_AUTO) 44 | {} 45 | 46 | inline Algorithm(Algo algo, Variant variant) : 47 | m_variant(variant) 48 | { 49 | setAlgo(algo); 50 | } 51 | 52 | inline Algorithm(const char *algo) 53 | { 54 | parseAlgorithm(algo); 55 | } 56 | 57 | bool isEqual(const Algorithm &other) const { return m_algo == other.m_algo && m_variant == other.m_variant; } 58 | inline Algo algo() const { return m_algo; } 59 | inline const char *name() const { return name(false); } 60 | inline const char *shortName() const { return name(true); } 61 | inline Variant variant() const { return m_variant; } 62 | inline void setVariant(Variant variant) { m_variant = variant; } 63 | 64 | inline bool operator!=(const Algorithm &other) const { return !isEqual(other); } 65 | inline bool operator==(const Algorithm &other) const { return isEqual(other); } 66 | 67 | bool isValid() const; 68 | const char *variantName() const; 69 | void parseAlgorithm(const char *algo); 70 | void parseVariant(const char *variant); 71 | void parseVariant(int variant); 72 | void setAlgo(Algo algo); 73 | 74 | # ifdef XMRIG_PROXY_PROJECT 75 | void parseXmrStakAlgorithm(const char *algo); 76 | # endif 77 | 78 | private: 79 | const char *name(bool shortName) const; 80 | 81 | Algo m_algo; 82 | Variant m_variant; 83 | }; 84 | 85 | 86 | typedef std::vector Algorithms; 87 | 88 | 89 | } /* namespace xmrig */ 90 | 91 | #endif /* __ALGORITHM_H__ */ 92 | -------------------------------------------------------------------------------- /src/3rdparty/libcpuid/libcpuid_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Veselin Georgiev, 3 | * anrieffNOSPAM @ mgail_DOT.com (convert to gmail) 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #ifndef __LIBCPUID_UTIL_H__ 27 | #define __LIBCPUID_UTIL_H__ 28 | 29 | #define COUNT_OF(array) (sizeof(array) / sizeof(array[0])) 30 | 31 | struct feature_map_t { 32 | unsigned bit; 33 | cpu_feature_t feature; 34 | }; 35 | 36 | void match_features(const struct feature_map_t* matchtable, int count, 37 | uint32_t reg, struct cpu_id_t* data); 38 | 39 | struct match_entry_t { 40 | int family, model, stepping, ext_family, ext_model; 41 | int ncores, l2cache, l3cache, brand_code; 42 | uint64_t model_bits; 43 | int model_code; 44 | char name[32]; 45 | }; 46 | 47 | // returns the match score: 48 | int match_cpu_codename(const struct match_entry_t* matchtable, int count, 49 | struct cpu_id_t* data, int brand_code, uint64_t bits, 50 | int model_code); 51 | /* 52 | * Seek for a pattern in `haystack'. 53 | * Pattern may be an fixed string, or contain the special metacharacters 54 | * '.' - match any single character 55 | * '#' - match any digit 56 | * '[] - match any of the given chars (regex-like ranges are not 57 | * supported) 58 | * Return val: 0 if the pattern is not found. Nonzero if it is found (actually, 59 | * x + 1 where x is the index where the match is found). 60 | */ 61 | int match_pattern(const char* haystack, const char* pattern); 62 | 63 | /* 64 | * Gets an initialized cpu_id_t. It is cached, so that internal libcpuid 65 | * machinery doesn't need to issue cpu_identify more than once. 66 | */ 67 | struct cpu_id_t* get_cached_cpuid(void); 68 | 69 | 70 | /* returns true if all bits of mask are present in `bits'. */ 71 | int match_all(uint64_t bits, uint64_t mask); 72 | 73 | /* 74 | * Sets the current errno 75 | */ 76 | int set_error(cpu_error_t err); 77 | 78 | #endif /* __LIBCPUID_UTIL_H__ */ 79 | --------------------------------------------------------------------------------