Merge branch 'evo' into beta

This commit is contained in:
XMRig 2019-06-25 14:17:06 +07:00
commit ee93095e06
95 changed files with 713 additions and 286 deletions

View file

@ -2,10 +2,11 @@ cmake_minimum_required(VERSION 2.8)
project(xmrig) project(xmrig)
option(WITH_LIBCPUID "Use Libcpuid" ON) option(WITH_LIBCPUID "Use Libcpuid" ON)
option(WITH_AEON "CryptoNight-Lite support" ON) option(WITH_CN_LITE "CryptoNight-Lite support" ON)
option(WITH_SUMO "CryptoNight-Heavy support" ON) option(WITH_CN_HEAVY "CryptoNight-Heavy support" ON)
option(WITH_CN_PICO "CryptoNight-Pico support" ON) option(WITH_CN_PICO "CryptoNight-Pico support" ON)
option(WITH_CN_GPU "CryptoNight-GPU support" ON) option(WITH_CN_GPU "CryptoNight-GPU support" ON)
option(WITH_RANDOMX "RandomX support" ON)
option(WITH_HTTP "HTTP protocol support (client/server)" ON) option(WITH_HTTP "HTTP protocol support (client/server)" ON)
option(WITH_DEBUG_LOG "Enable debug log output" OFF) option(WITH_DEBUG_LOG "Enable debug log output" OFF)
option(WITH_TLS "Enable OpenSSL support" ON) option(WITH_TLS "Enable OpenSSL support" ON)
@ -25,11 +26,9 @@ set(HEADERS
src/api/interfaces/IApiListener.h src/api/interfaces/IApiListener.h
src/App.h src/App.h
src/common/cpu/Cpu.h src/common/cpu/Cpu.h
src/common/crypto/Algorithm.h
src/common/crypto/keccak.h src/common/crypto/keccak.h
src/common/interfaces/ICpuInfo.h src/common/interfaces/ICpuInfo.h
src/common/Platform.h src/common/Platform.h
src/common/utils/mm_malloc.h
src/common/xmrig.h src/common/xmrig.h
src/core/config/Config_default.h src/core/config/Config_default.h
src/core/config/Config_platform.h src/core/config/Config_platform.h
@ -56,32 +55,34 @@ set(HEADERS
) )
set(HEADERS_CRYPTO set(HEADERS_CRYPTO
src/crypto/c_blake256.h src/crypto/cn/asm/CryptonightR_template.h
src/crypto/c_groestl.h src/crypto/cn/c_blake256.h
src/crypto/c_jh.h src/crypto/cn/c_groestl.h
src/crypto/c_skein.h src/crypto/cn/c_jh.h
src/crypto/CryptoNight.h src/crypto/cn/c_skein.h
src/crypto/CryptoNight_constants.h src/crypto/cn/CryptoNight_constants.h
src/crypto/CryptoNight_monero.h src/crypto/cn/CryptoNight_monero.h
src/crypto/CryptoNight_test.h src/crypto/cn/CryptoNight_test.h
src/crypto/groestl_tables.h src/crypto/cn/CryptoNight.h
src/crypto/hash.h src/crypto/cn/groestl_tables.h
src/crypto/skein_port.h src/crypto/cn/hash.h
src/crypto/soft_aes.h src/crypto/cn/skein_port.h
src/crypto/asm/CryptonightR_template.h src/crypto/cn/soft_aes.h
src/crypto/common/Algorithm.h
src/crypto/common/portable/mm_malloc.h
src/crypto/common/VirtualMemory.h
) )
if (XMRIG_ARM) if (XMRIG_ARM)
set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/CryptoNight_arm.h) set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/cn/CryptoNight_arm.h)
else() else()
set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/CryptoNight_x86.h) set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/cn/CryptoNight_x86.h)
endif() endif()
set(SOURCES set(SOURCES
"${SOURCES_BASE}" "${SOURCES_BASE}"
"${SOURCES_BASE_HTTP}" "${SOURCES_BASE_HTTP}"
src/App.cpp src/App.cpp
src/common/crypto/Algorithm.cpp
src/common/crypto/keccak.cpp src/common/crypto/keccak.cpp
src/common/Platform.cpp src/common/Platform.cpp
src/core/config/Config.cpp src/core/config/Config.cpp
@ -102,10 +103,11 @@ set(SOURCES
) )
set(SOURCES_CRYPTO set(SOURCES_CRYPTO
src/crypto/c_groestl.c src/crypto/cn/c_groestl.c
src/crypto/c_blake256.c src/crypto/cn/c_blake256.c
src/crypto/c_jh.c src/crypto/cn/c_jh.c
src/crypto/c_skein.c src/crypto/cn/c_skein.c
src/crypto/common/Algorithm.cpp
) )
if (WIN32) if (WIN32)
@ -115,6 +117,7 @@ if (WIN32)
src/App_win.cpp src/App_win.cpp
src/common/Platform_win.cpp src/common/Platform_win.cpp
src/Mem_win.cpp src/Mem_win.cpp
src/crypto/common/VirtualMemory_win.cpp
) )
add_definitions(/DWIN32) add_definitions(/DWIN32)
@ -125,6 +128,7 @@ elseif (APPLE)
src/App_unix.cpp src/App_unix.cpp
src/common/Platform_mac.cpp src/common/Platform_mac.cpp
src/Mem_unix.cpp src/Mem_unix.cpp
src/crypto/common/VirtualMemory_unix.cpp
) )
else() else()
set(SOURCES_OS set(SOURCES_OS
@ -132,6 +136,7 @@ else()
src/App_unix.cpp src/App_unix.cpp
src/common/Platform_unix.cpp src/common/Platform_unix.cpp
src/Mem_unix.cpp src/Mem_unix.cpp
src/crypto/common/VirtualMemory_unix.cpp
) )
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD) if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
@ -155,6 +160,17 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package(UV REQUIRED) find_package(UV REQUIRED)
if (WITH_RANDOMX)
find_package(RandomX REQUIRED)
include_directories(${RANDOMX_INCLUDE_DIR})
add_definitions(/DXMRIG_ALGO_RANDOMX)
else()
set(RANDOMX_LIBRARIES "")
remove_definitions(/DXMRIG_ALGO_RANDOMX)
endif()
include(cmake/flags.cmake) include(cmake/flags.cmake)
if (WITH_LIBCPUID) if (WITH_LIBCPUID)
@ -178,20 +194,16 @@ include(cmake/OpenSSL.cmake)
include(cmake/asm.cmake) include(cmake/asm.cmake)
include(cmake/cn-gpu.cmake) include(cmake/cn-gpu.cmake)
if (NOT WITH_AEON) if (WITH_CN_LITE)
add_definitions(/DXMRIG_NO_AEON) add_definitions(/DXMRIG_ALGO_CN_LITE)
endif() endif()
if (NOT WITH_SUMO) if (WITH_CN_HEAVY)
add_definitions(/DXMRIG_NO_SUMO) add_definitions(/DXMRIG_ALGO_CN_HEAVY)
endif() endif()
if (NOT WITH_IPBC) if (WITH_CN_PICO)
add_definitions(/DXMRIG_NO_IPBC) add_definitions(/DXMRIG_ALGO_CN_PICO)
endif()
if (NOT WITH_CN_PICO)
add_definitions(/DXMRIG_NO_CN_PICO)
endif() endif()
if (WITH_EMBEDDED_CONFIG) if (WITH_EMBEDDED_CONFIG)
@ -229,4 +241,4 @@ if (WITH_DEBUG_LOG)
endif() endif()
add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTP_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES} ${CN_GPU_SOURCES}) add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTP_SOURCES} ${TLS_SOURCES} ${XMRIG_ASM_SOURCES} ${CN_GPU_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB}) target_link_libraries(${CMAKE_PROJECT_NAME} ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${RANDOMX_LIBRARIES} ${EXTRA_LIBS} ${CPUID_LIB})

25
cmake/FindRandomX.cmake Normal file
View file

@ -0,0 +1,25 @@
find_path(
RANDOMX_INCLUDE_DIR
NAMES randomx.h
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
PATH_SUFFIXES "include"
NO_DEFAULT_PATH
)
find_path(RANDOMX_INCLUDE_DIR NAMES randomx.h)
find_library(
RANDOMX_LIBRARY
NAMES librandomx.a randomx librandomx
PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
PATH_SUFFIXES "lib"
NO_DEFAULT_PATH
)
find_library(RANDOMX_LIBRARY NAMES librandomx.a randomx librandomx)
set(RANDOMX_LIBRARIES ${RANDOMX_LIBRARY})
set(RANDOMX_INCLUDE_DIRS ${RANDOMX_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RANDOMX DEFAULT_MSG RANDOMX_LIBRARY RANDOMX_INCLUDE_DIR)

View file

@ -6,13 +6,13 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8)
if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141) if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141)
set(XMRIG_ASM_FILES set(XMRIG_ASM_FILES
"src/crypto/asm/cn_main_loop.asm" "src/crypto/cn/asm/cn_main_loop.asm"
"src/crypto/asm/CryptonightR_template.asm" "src/crypto/cn/asm/CryptonightR_template.asm"
) )
else() else()
set(XMRIG_ASM_FILES set(XMRIG_ASM_FILES
"src/crypto/asm/win64/cn_main_loop.asm" "src/crypto/cn/asm/win64/cn_main_loop.asm"
"src/crypto/asm/win64/CryptonightR_template.asm" "src/crypto/cn/asm/win64/CryptonightR_template.asm"
) )
endif() endif()
@ -22,13 +22,13 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8)
if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU) if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU)
set(XMRIG_ASM_FILES set(XMRIG_ASM_FILES
"src/crypto/asm/win64/cn_main_loop.S" "src/crypto/cn/asm/win64/cn_main_loop.S"
"src/crypto/asm/CryptonightR_template.S" "src/crypto/cn/asm/CryptonightR_template.S"
) )
else() else()
set(XMRIG_ASM_FILES set(XMRIG_ASM_FILES
"src/crypto/asm/cn_main_loop.S" "src/crypto/cn/asm/cn_main_loop.S"
"src/crypto/asm/CryptonightR_template.S" "src/crypto/cn/asm/CryptonightR_template.S"
) )
endif() endif()
@ -36,7 +36,7 @@ if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8)
endif() endif()
add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILES}) add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILES})
set(XMRIG_ASM_SOURCES src/crypto/Asm.h src/crypto/Asm.cpp src/crypto/CryptonightR_gen.cpp) set(XMRIG_ASM_SOURCES src/crypto/cn/Asm.h src/crypto/cn/Asm.cpp src/crypto/cn/r/CryptonightR_gen.cpp)
set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C)
else() else()
set(XMRIG_ASM_SOURCES "") set(XMRIG_ASM_SOURCES "")

View file

@ -1,23 +1,25 @@
if (WITH_CN_GPU AND CMAKE_SIZEOF_VOID_P EQUAL 8) if (WITH_CN_GPU AND CMAKE_SIZEOF_VOID_P EQUAL 8)
if (XMRIG_ARM) if (XMRIG_ARM)
set(CN_GPU_SOURCES src/crypto/cn_gpu_arm.cpp) set(CN_GPU_SOURCES src/crypto/cn/gpu/cn_gpu_arm.cpp)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang) if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/cn_gpu_arm.cpp PROPERTIES COMPILE_FLAGS "-O3") set_source_files_properties(src/crypto/cn/gpu/cn_gpu_arm.cpp PROPERTIES COMPILE_FLAGS "-O3")
endif() endif()
else() else()
set(CN_GPU_SOURCES src/crypto/cn_gpu_avx.cpp src/crypto/cn_gpu_ssse3.cpp) set(CN_GPU_SOURCES src/crypto/cn/gpu/cn_gpu_avx.cpp src/crypto/cn/gpu/cn_gpu_ssse3.cpp)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang) if (CMAKE_CXX_COMPILER_ID MATCHES GNU OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_source_files_properties(src/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-O3 -mavx2") set_source_files_properties(src/crypto/cn/gpu/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "-O3 -mavx2")
set_source_files_properties(src/crypto/cn_gpu_ssse3.cpp PROPERTIES COMPILE_FLAGS "-O3") set_source_files_properties(src/crypto/cn/gpu/cn_gpu_ssse3.cpp PROPERTIES COMPILE_FLAGS "-O3")
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set_source_files_properties(src/crypto/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX") set_source_files_properties(src/crypto/cn/gpu/cn_gpu_avx.cpp PROPERTIES COMPILE_FLAGS "/arch:AVX")
endif() endif()
endif() endif()
add_definitions(/DXMRIG_ALGO_CN_GPU)
else() else()
set(CN_GPU_SOURCES "") set(CN_GPU_SOURCES "")
add_definitions(/DXMRIG_NO_CN_GPU) remove_definitions(/DXMRIG_ALGO_CN_GPU)
endif() endif()

View file

@ -81,3 +81,10 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
endif() endif()
endif() endif()
if (NOT WIN32)
check_symbol_exists("__builtin___clear_cache" "stdlib.h" HAVE_BUILTIN_CLEAR_CACHE)
if (HAVE_BUILTIN_CLEAR_CACHE)
add_definitions(/DHAVE_BUILTIN_CLEAR_CACHE)
endif()
endif()

View file

@ -37,7 +37,6 @@
#include "common/Platform.h" #include "common/Platform.h"
#include "core/config/Config.h" #include "core/config/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "crypto/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
#include "net/Network.h" #include "net/Network.h"
#include "Summary.h" #include "Summary.h"

View file

@ -24,9 +24,13 @@
*/ */
#include "common/utils/mm_malloc.h" #include <limits>
#include "crypto/CryptoNight.h"
#include "crypto/CryptoNight_constants.h"
#include "crypto/cn/CryptoNight_constants.h"
#include "crypto/cn/CryptoNight.h"
#include "crypto/common/portable/mm_malloc.h"
#include "crypto/common/VirtualMemory.h"
#include "Mem.h" #include "Mem.h"
@ -51,13 +55,9 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)
cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096)); cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096));
c->memory = info.memory + (i * cn_select_memory(algorithm)); c->memory = info.memory + (i * cn_select_memory(algorithm));
uint8_t* p = reinterpret_cast<uint8_t*>(allocateExecutableMemory(0x4000)); c->generated_code = reinterpret_cast<cn_mainloop_fun_ms_abi>(xmrig::VirtualMemory::allocateExecutableMemory(0x4000));
c->generated_code = reinterpret_cast<cn_mainloop_fun_ms_abi>(p);
c->generated_code_double = reinterpret_cast<cn_mainloop_fun_ms_abi>(p + 0x2000);
c->generated_code_data.variant = xmrig::VARIANT_MAX; c->generated_code_data.variant = xmrig::VARIANT_MAX;
c->generated_code_data.height = (uint64_t)(-1); c->generated_code_data.height = std::numeric_limits<uint64_t>::max();
c->generated_code_double_data = c->generated_code_data;
ctx[i] = c; ctx[i] = c;
} }
@ -68,6 +68,10 @@ MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count)
void Mem::release(cryptonight_ctx **ctx, size_t count, MemInfo &info) void Mem::release(cryptonight_ctx **ctx, size_t count, MemInfo &info)
{ {
if (info.memory == nullptr) {
return;
}
release(info); release(info);
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {

View file

@ -39,11 +39,11 @@ struct cryptonight_ctx;
struct MemInfo struct MemInfo
{ {
alignas(16) uint8_t *memory; alignas(16) uint8_t *memory = nullptr;
size_t hugePages; size_t hugePages = 0;
size_t pages; size_t pages = 0;
size_t size; size_t size = 0;
}; };
@ -60,10 +60,6 @@ public:
static void init(bool enabled); static void init(bool enabled);
static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info); static void release(cryptonight_ctx **ctx, size_t count, MemInfo &info);
static void *allocateExecutableMemory(size_t size);
static void protectExecutableMemory(void *p, size_t size);
static void flushInstructionCache(void *p, size_t size);
static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; }
private: private:

View file

@ -29,9 +29,10 @@
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "common/utils/mm_malloc.h"
#include "common/xmrig.h" #include "common/xmrig.h"
#include "crypto/CryptoNight.h" #include "crypto/common/portable/mm_malloc.h"
#include "crypto/common/VirtualMemory.h"
#include "crypto/cn/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
@ -56,15 +57,8 @@ void Mem::allocate(MemInfo &info, bool enabled)
return; return;
} }
# if defined(__APPLE__) info.memory = static_cast<uint8_t*>(xmrig::VirtualMemory::allocateLargePagesMemory(info.size));
info.memory = static_cast<uint8_t*>(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0)); if (!info.memory) {
# elif defined(__FreeBSD__)
info.memory = static_cast<uint8_t*>(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0));
# else
info.memory = static_cast<uint8_t*>(mmap(0, info.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0));
# endif
if (info.memory == MAP_FAILED) {
return allocate(info, false);; return allocate(info, false);;
} }
@ -87,33 +81,9 @@ void Mem::release(MemInfo &info)
munlock(info.memory, info.size); munlock(info.memory, info.size);
} }
munmap(info.memory, info.size); xmrig::VirtualMemory::freeLargePagesMemory(info.memory, info.size);
} }
else { else {
_mm_free(info.memory); _mm_free(info.memory);
} }
} }
void *Mem::allocateExecutableMemory(size_t size)
{
# if defined(__APPLE__)
return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
# else
return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# endif
}
void Mem::protectExecutableMemory(void *p, size_t size)
{
mprotect(p, size, PROT_READ | PROT_EXEC);
}
void Mem::flushInstructionCache(void *p, size_t size)
{
# ifndef __FreeBSD__
__builtin___clear_cache(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p) + size);
# endif
}

View file

@ -31,10 +31,11 @@
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "common/utils/mm_malloc.h"
#include "common/xmrig.h" #include "common/xmrig.h"
#include "crypto/CryptoNight.h" #include "crypto/common/portable/mm_malloc.h"
#include "crypto/CryptoNight_constants.h" #include "crypto/common/VirtualMemory.h"
#include "crypto/cn/CryptoNight_constants.h"
#include "crypto/cn/CryptoNight.h"
#include "Mem.h" #include "Mem.h"
@ -163,7 +164,7 @@ void Mem::allocate(MemInfo &info, bool enabled)
return; return;
} }
info.memory = static_cast<uint8_t*>(VirtualAlloc(nullptr, info.size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); info.memory = static_cast<uint8_t*>(xmrig::VirtualMemory::allocateLargePagesMemory(info.size));
if (info.memory) { if (info.memory) {
info.hugePages = info.pages; info.hugePages = info.pages;
@ -177,28 +178,9 @@ void Mem::allocate(MemInfo &info, bool enabled)
void Mem::release(MemInfo &info) void Mem::release(MemInfo &info)
{ {
if (info.hugePages) { if (info.hugePages) {
VirtualFree(info.memory, 0, MEM_RELEASE); xmrig::VirtualMemory::freeLargePagesMemory(info.memory, info.size);
} }
else { else {
_mm_free(info.memory); _mm_free(info.memory);
} }
} }
void *Mem::allocateExecutableMemory(size_t size)
{
return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
}
void Mem::protectExecutableMemory(void *p, size_t size)
{
DWORD oldProtect;
VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect);
}
void Mem::flushInstructionCache(void *p, size_t size)
{
::FlushInstructionCache(GetCurrentProcess(), p, size);
}

View file

@ -33,7 +33,7 @@
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "core/config/Config.h" #include "core/config/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "crypto/Asm.h" #include "crypto/cn/Asm.h"
#include "Mem.h" #include "Mem.h"
#include "Summary.h" #include "Summary.h"
#include "version.h" #include "version.h"

View file

@ -26,7 +26,7 @@
#define XMRIG_ICONFIG_H #define XMRIG_ICONFIG_H
#include "common/crypto/Algorithm.h" #include "crypto/common/Algorithm.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"

View file

@ -26,7 +26,7 @@
#define XMRIG_ICONFIGTRANSFORM_H #define XMRIG_ICONFIGTRANSFORM_H
#include "common/crypto/Algorithm.h" #include "crypto/common/Algorithm.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"

View file

@ -37,6 +37,7 @@
#endif #endif
#include "base/io/json/Json.h"
#include "base/io/json/JsonRequest.h" #include "base/io/json/JsonRequest.h"
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/kernel/interfaces/IClientListener.h" #include "base/kernel/interfaces/IClientListener.h"
@ -344,13 +345,8 @@ bool xmrig::Client::parseJob(const rapidjson::Value &params, int *code)
} }
} }
if (params.HasMember("height")) { job.setSeedHash(Json::getString(params, "seed_hash"));
const rapidjson::Value &variant = params["height"]; job.setHeight(Json::getUint64(params, "height"));
if (variant.IsUint64()) {
job.setHeight(variant.GetUint64());
}
}
if (!verifyAlgorithm(job.algorithm())) { if (!verifyAlgorithm(job.algorithm())) {
*code = 6; *code = 6;

View file

@ -40,7 +40,7 @@
#include "base/net/stratum/SubmitResult.h" #include "base/net/stratum/SubmitResult.h"
#include "base/net/tools/RecvBuf.h" #include "base/net/tools/RecvBuf.h"
#include "base/net/tools/Storage.h" #include "base/net/tools/Storage.h"
#include "common/crypto/Algorithm.h" #include "crypto/common/Algorithm.h"
typedef struct bio_st BIO; typedef struct bio_st BIO;

View file

@ -220,6 +220,7 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value &params, int *code)
return false; return false;
} }
job.setSeedHash(Json::getString(params, "seed_hash"));
job.setHeight(Json::getUint64(params, kHeight)); job.setHeight(Json::getUint64(params, kHeight));
job.setDiff(Json::getUint64(params, "difficulty")); job.setDiff(Json::getUint64(params, "difficulty"));
job.setId(blocktemplate.data() + blocktemplate.size() - 32); job.setId(blocktemplate.data() + blocktemplate.size() - 32);

View file

@ -42,7 +42,8 @@ xmrig::Job::Job() :
m_diff(0), m_diff(0),
m_height(0), m_height(0),
m_target(0), m_target(0),
m_blob() m_blob(),
m_seedHash()
{ {
} }
@ -58,7 +59,8 @@ xmrig::Job::Job(int poolId, bool nicehash, const Algorithm &algorithm, const Str
m_diff(0), m_diff(0),
m_height(0), m_height(0),
m_target(0), m_target(0),
m_blob() m_blob(),
m_seedHash()
{ {
} }
@ -111,6 +113,20 @@ bool xmrig::Job::setBlob(const char *blob)
} }
bool xmrig::Job::setSeedHash(const char *hash)
{
if (!hash || (strlen(hash) != sizeof(m_seedHash) * 2)) {
return false;
}
# ifdef XMRIG_PROXY_PROJECT
m_rawSeedHash = hash;
# endif
return Buffer::fromHex(hash, sizeof(m_seedHash) * 2, m_seedHash);
}
bool xmrig::Job::setTarget(const char *target) bool xmrig::Job::setTarget(const char *target)
{ {
if (!target) { if (!target) {

View file

@ -33,7 +33,7 @@
#include "base/tools/String.h" #include "base/tools/String.h"
#include "common/crypto/Algorithm.h" #include "crypto/common/Algorithm.h"
namespace xmrig { namespace xmrig {
@ -52,6 +52,7 @@ public:
bool isEqual(const Job &other) const; bool isEqual(const Job &other) const;
bool setBlob(const char *blob); bool setBlob(const char *blob);
bool setSeedHash(const char *hash);
bool setTarget(const char *target); bool setTarget(const char *target);
void setAlgorithm(const char *algo); void setAlgorithm(const char *algo);
void setDiff(uint64_t diff); void setDiff(uint64_t diff);
@ -64,6 +65,7 @@ public:
inline const String &id() const { return m_id; } inline const String &id() const { return m_id; }
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); } inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
inline const uint8_t *blob() const { return m_blob; } inline const uint8_t *blob() const { return m_blob; }
inline const uint8_t *seedHash() const { return m_seedHash; }
inline int poolId() const { return m_poolId; } inline int poolId() const { return m_poolId; }
inline int threadId() const { return m_threadId; } inline int threadId() const { return m_threadId; }
inline size_t size() const { return m_size; } inline size_t size() const { return m_size; }
@ -84,6 +86,7 @@ public:
inline char *rawBlob() { return m_rawBlob; } inline char *rawBlob() { return m_rawBlob; }
inline const char *rawBlob() const { return m_rawBlob; } inline const char *rawBlob() const { return m_rawBlob; }
inline const char *rawTarget() const { return m_rawTarget; } inline const char *rawTarget() const { return m_rawTarget; }
inline const String &rawSeedHash() const { return m_rawSeedHash; }
# endif # endif
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); } static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
@ -107,10 +110,12 @@ private:
uint64_t m_height; uint64_t m_height;
uint64_t m_target; uint64_t m_target;
uint8_t m_blob[kMaxBlobSize]; uint8_t m_blob[kMaxBlobSize];
uint8_t m_seedHash[32];
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
char m_rawBlob[kMaxBlobSize * 2 + 8]; char m_rawBlob[kMaxBlobSize * 2 + 8];
char m_rawTarget[24]; char m_rawTarget[24];
String m_rawSeedHash;
# endif # endif
}; };

View file

@ -517,6 +517,7 @@ void xmrig::Pool::rebuild()
addVariant(VARIANT_RWZ); addVariant(VARIANT_RWZ);
addVariant(VARIANT_ZLS); addVariant(VARIANT_ZLS);
addVariant(VARIANT_DOUBLE); addVariant(VARIANT_DOUBLE);
addVariant(VARIANT_RX_WOW);
addVariant(VARIANT_AUTO); addVariant(VARIANT_AUTO);
# endif # endif
} }

View file

@ -32,7 +32,7 @@
#include "base/tools/String.h" #include "base/tools/String.h"
#include "common/crypto/Algorithm.h" #include "crypto/common/Algorithm.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"

View file

@ -25,7 +25,8 @@
#include <string.h> #include <string.h>
#include <thread> #include <thread>
#if __ARM_FEATURE_CRYPTO
#if __ARM_FEATURE_CRYPTO && !defined(__APPLE__)
# include <sys/auxv.h> # include <sys/auxv.h>
# include <asm/hwcap.h> # include <asm/hwcap.h>
#endif #endif
@ -47,7 +48,11 @@ xmrig::BasicCpuInfo::BasicCpuInfo() :
# endif # endif
# if __ARM_FEATURE_CRYPTO # if __ARM_FEATURE_CRYPTO
# if !defined(__APPLE__)
m_aes = getauxval(AT_HWCAP) & HWCAP_AES; m_aes = getauxval(AT_HWCAP) & HWCAP_AES;
# else
m_aes = true;
# endif
# endif # endif
} }

View file

@ -36,6 +36,7 @@ enum Algo {
CRYPTONIGHT_LITE, /* CryptoNight (1 MB) */ CRYPTONIGHT_LITE, /* CryptoNight (1 MB) */
CRYPTONIGHT_HEAVY, /* CryptoNight (4 MB) */ CRYPTONIGHT_HEAVY, /* CryptoNight (4 MB) */
CRYPTONIGHT_PICO, /* CryptoNight (256 KB) */ CRYPTONIGHT_PICO, /* CryptoNight (256 KB) */
RANDOM_X, /* RandomX */
ALGO_MAX ALGO_MAX
}; };
@ -79,6 +80,7 @@ enum Variant {
VARIANT_RWZ = 14, // CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft) VARIANT_RWZ = 14, // CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft)
VARIANT_ZLS = 15, // CryptoNight variant 2 with 3/4 iterations (Zelerius) VARIANT_ZLS = 15, // CryptoNight variant 2 with 3/4 iterations (Zelerius)
VARIANT_DOUBLE = 16, // CryptoNight variant 2 with double iterations (X-CASH) VARIANT_DOUBLE = 16, // CryptoNight variant 2 with double iterations (X-CASH)
VARIANT_RX_WOW = 17, // RandomX (Wownero)
VARIANT_MAX VARIANT_MAX
}; };

View file

@ -32,8 +32,8 @@
#include "base/kernel/interfaces/IJsonReader.h" #include "base/kernel/interfaces/IJsonReader.h"
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "core/config/Config.h" #include "core/config/Config.h"
#include "crypto/Asm.h" #include "crypto/cn/Asm.h"
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_constants.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/filewritestream.h" #include "rapidjson/filewritestream.h"
#include "rapidjson/prettywriter.h" #include "rapidjson/prettywriter.h"
@ -56,6 +56,12 @@ xmrig::Config::Config() :
} }
bool xmrig::Config::isHwAES() const
{
return (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_HW;
}
bool xmrig::Config::read(const IJsonReader &reader, const char *fileName) bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
{ {
if (!BaseConfig::read(reader, fileName)) { if (!BaseConfig::read(reader, fileName)) {
@ -148,10 +154,9 @@ bool xmrig::Config::finalize()
{ {
if (!m_threads.cpu.empty()) { if (!m_threads.cpu.empty()) {
m_threads.mode = Advanced; m_threads.mode = Advanced;
const bool softAES = (m_aesMode == AES_AUTO ? (Cpu::info()->hasAES() ? AES_HW : AES_SOFT) : m_aesMode) == AES_SOFT;
for (size_t i = 0; i < m_threads.cpu.size(); ++i) { for (size_t i = 0; i < m_threads.cpu.size(); ++i) {
m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm.algo(), m_threads.cpu[i], m_priority, softAES)); m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm.algo(), m_threads.cpu[i], m_priority, !isHwAES()));
} }
return true; return true;
@ -160,7 +165,8 @@ bool xmrig::Config::finalize()
const AlgoVariant av = getAlgoVariant(); const AlgoVariant av = getAlgoVariant();
m_threads.mode = m_threads.count ? Simple : Automatic; m_threads.mode = m_threads.count ? Simple : Automatic;
const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo()) / 1024; const Variant v = m_algorithm.variant();
const size_t size = CpuThread::multiway(av) * cn_select_memory(m_algorithm.algo(), v) / 1024;
if (!m_threads.count) { if (!m_threads.count) {
m_threads.count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage); m_threads.count = Cpu::info()->optimalThreadsCount(size, m_maxCpuUsage);
@ -244,7 +250,7 @@ void xmrig::Config::setThreads(const rapidjson::Value &threads)
xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
{ {
# ifndef XMRIG_NO_AEON # ifdef XMRIG_ALGO_CN_LITE
if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) { if (m_algorithm.algo() == xmrig::CRYPTONIGHT_LITE) {
return getAlgoVariantLite(); return getAlgoVariantLite();
} }
@ -262,7 +268,7 @@ xmrig::AlgoVariant xmrig::Config::getAlgoVariant() const
} }
#ifndef XMRIG_NO_AEON #ifdef XMRIG_ALGO_CN_LITE
xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const xmrig::AlgoVariant xmrig::Config::getAlgoVariantLite() const
{ {
if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) { if (m_algoVariant <= AV_AUTO || m_algoVariant >= AV_MAX) {

View file

@ -67,10 +67,10 @@ public:
Config(); Config();
bool isHwAES() const;
bool read(const IJsonReader &reader, const char *fileName) override; bool read(const IJsonReader &reader, const char *fileName) override;
void getJSON(rapidjson::Document &doc) const override; void getJSON(rapidjson::Document &doc) const override;
inline AesMode aesMode() const { return m_aesMode; }
inline AlgoVariant algoVariant() const { return m_algoVariant; } inline AlgoVariant algoVariant() const { return m_algoVariant; }
inline Assembly assembly() const { return m_assembly; } inline Assembly assembly() const { return m_assembly; }
inline bool isHugePages() const { return m_hugePages; } inline bool isHugePages() const { return m_hugePages; }
@ -90,7 +90,7 @@ private:
void setThreads(const rapidjson::Value &threads); void setThreads(const rapidjson::Value &threads);
AlgoVariant getAlgoVariant() const; AlgoVariant getAlgoVariant() const;
# ifndef XMRIG_NO_AEON # ifdef XMRIG_ALGO_CN_LITE
AlgoVariant getAlgoVariantLite() const; AlgoVariant getAlgoVariantLite() const;
# endif # endif

View file

@ -37,15 +37,15 @@ Usage: " APP_ID " [OPTIONS]\n\
Options:\n\ Options:\n\
-a, --algo=ALGO specify the algorithm to use\n\ -a, --algo=ALGO specify the algorithm to use\n\
cryptonight\n" cryptonight\n"
#ifndef XMRIG_NO_AEON #ifdef XMRIG_ALGO_CN_LITE
"\ "\
cryptonight-lite\n" cryptonight-lite\n"
#endif #endif
#ifndef XMRIG_NO_SUMO #ifdef XMRIG_ALGO_CN_HEAVY
"\ "\
cryptonight-heavy\n" cryptonight-heavy\n"
#endif #endif
#ifndef XMRIG_NO_CN_PICO #ifdef XMRIG_ALGO_CN_PICO
"\ "\
cryptonight-pico\n" cryptonight-pico\n"
#endif #endif

View file

@ -33,7 +33,7 @@
#endif #endif
#include "crypto/Asm.h" #include "crypto/cn/Asm.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"

View file

@ -6,6 +6,7 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -30,14 +31,16 @@
#include <stdint.h> #include <stdint.h>
#if defined _MSC_VER || defined XMRIG_ARM #if defined _MSC_VER || defined XMRIG_ARM
#define ABI_ATTRIBUTE # define ABI_ATTRIBUTE
#else #else
#define ABI_ATTRIBUTE __attribute__((ms_abi)) # define ABI_ATTRIBUTE __attribute__((ms_abi))
#endif #endif
struct cryptonight_ctx; struct cryptonight_ctx;
typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx**) ABI_ATTRIBUTE; typedef void(*cn_mainloop_fun_ms_abi)(cryptonight_ctx**) ABI_ATTRIBUTE;
struct cryptonight_r_data { struct cryptonight_r_data {
int variant; int variant;
uint64_t height; uint64_t height;
@ -45,17 +48,16 @@ struct cryptonight_r_data {
bool match(const int v, const uint64_t h) const { return (v == variant) && (h == height); } bool match(const int v, const uint64_t h) const { return (v == variant) && (h == height); }
}; };
struct cryptonight_ctx { struct cryptonight_ctx {
alignas(16) uint8_t state[224]; alignas(16) uint8_t state[224];
alignas(16) uint8_t *memory; alignas(16) uint8_t *memory;
uint8_t unused[40]; uint8_t unused[40];
const uint32_t* saes_table; const uint32_t *saes_table;
cn_mainloop_fun_ms_abi generated_code; cn_mainloop_fun_ms_abi generated_code;
cn_mainloop_fun_ms_abi generated_code_double;
cryptonight_r_data generated_code_data; cryptonight_r_data generated_code_data;
cryptonight_r_data generated_code_double_data;
}; };

View file

@ -29,19 +29,19 @@
#include "common/crypto/keccak.h" #include "common/crypto/keccak.h"
#include "common/utils/mm_malloc.h" #include "crypto/common/portable/mm_malloc.h"
#include "crypto/CryptoNight.h" #include "crypto/cn/CryptoNight_constants.h"
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_monero.h"
#include "crypto/CryptoNight_monero.h" #include "crypto/cn/CryptoNight.h"
#include "crypto/soft_aes.h" #include "crypto/cn/soft_aes.h"
extern "C" extern "C"
{ {
#include "crypto/c_groestl.h" #include "crypto/cn/c_groestl.h"
#include "crypto/c_blake256.h" #include "crypto/cn/c_blake256.h"
#include "crypto/c_jh.h" #include "crypto/cn/c_jh.h"
#include "crypto/c_skein.h" #include "crypto/cn/c_skein.h"
} }
@ -284,7 +284,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
} }
#ifndef XMRIG_NO_CN_GPU #ifdef XMRIG_ALGO_CN_GPU
template<xmrig::Algo ALGO, size_t MEM> template<xmrig::Algo ALGO, size_t MEM>
void cn_explode_scratchpad_gpu(const uint8_t *input, uint8_t *output) void cn_explode_scratchpad_gpu(const uint8_t *input, uint8_t *output)
{ {
@ -583,7 +583,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
} }
#ifndef XMRIG_NO_CN_GPU #ifdef XMRIG_ALGO_CN_GPU
template<size_t ITER, uint32_t MASK> template<size_t ITER, uint32_t MASK>
void cn_gpu_inner_arm(const uint8_t *spad, uint8_t *lpad); void cn_gpu_inner_arm(const uint8_t *spad, uint8_t *lpad);

View file

@ -70,7 +70,7 @@ template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_HEAVY>() { retur
template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_PICO>() { return CRYPTONIGHT_PICO_MEMORY; } template<> inline constexpr size_t cn_select_memory<CRYPTONIGHT_PICO>() { return CRYPTONIGHT_PICO_MEMORY; }
inline size_t cn_select_memory(Algo algorithm) inline size_t cn_select_memory(Algo algorithm, Variant v = VARIANT_AUTO)
{ {
switch(algorithm) switch(algorithm)
{ {
@ -86,6 +86,9 @@ inline size_t cn_select_memory(Algo algorithm)
case CRYPTONIGHT_PICO: case CRYPTONIGHT_PICO:
return CRYPTONIGHT_PICO_MEMORY; return CRYPTONIGHT_PICO_MEMORY;
case RANDOM_X:
return (v == VARIANT_RX_WOW) ? CRYPTONIGHT_LITE_MEMORY : CRYPTONIGHT_MEMORY;
default: default:
break; break;
} }

View file

@ -179,7 +179,7 @@
#endif #endif
#include "common/xmrig.h" #include "common/xmrig.h"
#include "variant4_random_math.h" #include "crypto/cn/r/variant4_random_math.h"
#define VARIANT4_RANDOM_MATH_INIT(part) \ #define VARIANT4_RANDOM_MATH_INIT(part) \
uint32_t r##part[9]; \ uint32_t r##part[9]; \

View file

@ -272,7 +272,7 @@ const static uint8_t test_output_double[160] = {
0x5E, 0x2E, 0xC1, 0x80, 0x89, 0x39, 0xB3, 0x54, 0x39, 0x52, 0x0E, 0x69, 0x3D, 0xF6, 0xC5, 0x4A 0x5E, 0x2E, 0xC1, 0x80, 0x89, 0x39, 0xB3, 0x54, 0x39, 0x52, 0x0E, 0x69, 0x3D, 0xF6, 0xC5, 0x4A
}; };
#ifndef XMRIG_NO_AEON #ifdef XMRIG_ALGO_CN_LITE
// "cn-lite/0" // "cn-lite/0"
const static uint8_t test_output_v0_lite[160] = { const static uint8_t test_output_v0_lite[160] = {
0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E,
@ -304,7 +304,7 @@ const static uint8_t test_output_v1_lite[160] = {
#endif #endif
#ifndef XMRIG_NO_SUMO #ifdef XMRIG_ALGO_CN_HEAVY
// "cn-heavy/0" // "cn-heavy/0"
const static uint8_t test_output_v0_heavy[160] = { const static uint8_t test_output_v0_heavy[160] = {
0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64, 0x99, 0x83, 0xF2, 0x1B, 0xDF, 0x20, 0x10, 0xA8, 0xD7, 0x07, 0xBB, 0x2F, 0x14, 0xD7, 0x86, 0x64,
@ -351,7 +351,7 @@ const static uint8_t test_output_tube_heavy[160] = {
#endif #endif
#ifndef XMRIG_NO_CN_PICO #ifdef XMRIG_ALGO_CN_PICO
// "cn-pico/trtl" // "cn-pico/trtl"
const static uint8_t test_output_pico_trtl[160] = { const static uint8_t test_output_pico_trtl[160] = {
0x08, 0xF4, 0x21, 0xD7, 0x83, 0x31, 0x17, 0x30, 0x0E, 0xDA, 0x66, 0xE9, 0x8F, 0x4A, 0x25, 0x69, 0x08, 0xF4, 0x21, 0xD7, 0x83, 0x31, 0x17, 0x30, 0x0E, 0xDA, 0x66, 0xE9, 0x8F, 0x4A, 0x25, 0x69,
@ -368,7 +368,7 @@ const static uint8_t test_output_pico_trtl[160] = {
#endif #endif
#ifndef XMRIG_NO_CN_GPU #ifdef XMRIG_ALGO_CN_GPU
// "cn/gpu" // "cn/gpu"
const static uint8_t test_output_gpu[160] = { const static uint8_t test_output_gpu[160] = {
0xE5, 0x5C, 0xB2, 0x3E, 0x51, 0x64, 0x9A, 0x59, 0xB1, 0x27, 0xB9, 0x6B, 0x51, 0x5F, 0x2B, 0xF7, 0xE5, 0x5C, 0xB2, 0x3E, 0x51, 0x64, 0x9A, 0x59, 0xB1, 0x27, 0xB9, 0x6B, 0x51, 0x5F, 0x2B, 0xF7,

View file

@ -37,18 +37,18 @@
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "common/crypto/keccak.h" #include "common/crypto/keccak.h"
#include "crypto/CryptoNight.h" #include "crypto/cn/CryptoNight.h"
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_constants.h"
#include "crypto/CryptoNight_monero.h" #include "crypto/cn/CryptoNight_monero.h"
#include "crypto/soft_aes.h" #include "crypto/cn/soft_aes.h"
extern "C" extern "C"
{ {
#include "crypto/c_groestl.h" #include "crypto/cn/c_groestl.h"
#include "crypto/c_blake256.h" #include "crypto/cn/c_blake256.h"
#include "crypto/c_jh.h" #include "crypto/cn/c_jh.h"
#include "crypto/c_skein.h" #include "crypto/cn/c_skein.h"
} }
@ -361,7 +361,7 @@ static inline void cn_explode_scratchpad(const __m128i *input, __m128i *output)
} }
#ifndef XMRIG_NO_CN_GPU #ifdef XMRIG_ALGO_CN_GPU
template<xmrig::Algo ALGO, size_t MEM> template<xmrig::Algo ALGO, size_t MEM>
void cn_explode_scratchpad_gpu(const uint8_t *input, uint8_t *output) void cn_explode_scratchpad_gpu(const uint8_t *input, uint8_t *output)
{ {
@ -708,7 +708,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
} }
#ifndef XMRIG_NO_CN_GPU #ifdef XMRIG_ALGO_CN_GPU
template<size_t ITER, uint32_t MASK> template<size_t ITER, uint32_t MASK>
void cn_gpu_inner_avx(const uint8_t *spad, uint8_t *lpad); void cn_gpu_inner_avx(const uint8_t *spad, uint8_t *lpad);
@ -895,12 +895,12 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_
{ {
constexpr size_t MEM = xmrig::cn_select_memory<ALGO>(); constexpr size_t MEM = xmrig::cn_select_memory<ALGO>();
if (xmrig::cn_is_cryptonight_r<VARIANT>() && !ctx[0]->generated_code_double_data.match(VARIANT, height)) { if (xmrig::cn_is_cryptonight_r<VARIANT>() && !ctx[0]->generated_code_data.match(VARIANT, height)) {
V4_Instruction code[256]; V4_Instruction code[256];
const int code_size = v4_random_math_init<VARIANT>(code, height); const int code_size = v4_random_math_init<VARIANT>(code, height);
cn_r_compile_code_double<VARIANT>(code, code_size, reinterpret_cast<void*>(ctx[0]->generated_code_double), ASM); cn_r_compile_code_double<VARIANT>(code, code_size, reinterpret_cast<void*>(ctx[0]->generated_code), ASM);
ctx[0]->generated_code_double_data.variant = VARIANT; ctx[0]->generated_code_data.variant = VARIANT;
ctx[0]->generated_code_double_data.height = height; ctx[0]->generated_code_data.height = height;
} }
xmrig::keccak(input, size, ctx[0]->state); xmrig::keccak(input, size, ctx[0]->state);
@ -928,7 +928,7 @@ inline void cryptonight_double_hash_asm(const uint8_t *__restrict__ input, size_
cn_double_double_mainloop_sandybridge_asm(ctx); cn_double_double_mainloop_sandybridge_asm(ctx);
} }
else if (xmrig::cn_is_cryptonight_r<VARIANT>()) { else if (xmrig::cn_is_cryptonight_r<VARIANT>()) {
ctx[0]->generated_code_double(ctx); ctx[0]->generated_code(ctx);
} }
cn_implode_scratchpad<ALGO, MEM, false>(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state)); cn_implode_scratchpad<ALGO, MEM, false>(reinterpret_cast<__m128i*>(ctx[0]->memory), reinterpret_cast<__m128i*>(ctx[0]->state));

View file

@ -26,7 +26,7 @@
#include <arm_neon.h> #include <arm_neon.h>
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_constants.h"
inline void vandq_f32(float32x4_t &v, uint32_t v2) inline void vandq_f32(float32x4_t &v, uint32_t v2)

View file

@ -22,7 +22,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_constants.h"
#ifdef __GNUC__ #ifdef __GNUC__
# include <x86intrin.h> # include <x86intrin.h>

View file

@ -22,7 +22,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_constants.h"
#ifdef __GNUC__ #ifdef __GNUC__
# include <x86intrin.h> # include <x86intrin.h>

View file

@ -24,11 +24,12 @@
*/ */
#include <cstring> #include <cstring>
#include "crypto/CryptoNight_monero.h" #include "crypto/cn/CryptoNight_monero.h"
typedef void(*void_func)(); typedef void(*void_func)();
#include "crypto/asm/CryptonightR_template.h" #include "crypto/cn/asm/CryptonightR_template.h"
#include "crypto/common/VirtualMemory.h"
#include "Mem.h" #include "Mem.h"
@ -109,7 +110,7 @@ void wow_compile_code(const V4_Instruction* code, int code_size, void* machine_c
*(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightWOW_template_mainloop) - ((const uint8_t*)CryptonightWOW_template_part1)) - (p - p0)); *(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightWOW_template_mainloop) - ((const uint8_t*)CryptonightWOW_template_part1)) - (p - p0));
add_code(p, CryptonightWOW_template_part3, CryptonightWOW_template_end); add_code(p, CryptonightWOW_template_part3, CryptonightWOW_template_end);
Mem::flushInstructionCache(machine_code, p - p0); xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0);
} }
void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM)
@ -123,7 +124,7 @@ void v4_compile_code(const V4_Instruction* code, int code_size, void* machine_co
*(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightR_template_mainloop) - ((const uint8_t*)CryptonightR_template_part1)) - (p - p0)); *(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightR_template_mainloop) - ((const uint8_t*)CryptonightR_template_part1)) - (p - p0));
add_code(p, CryptonightR_template_part3, CryptonightR_template_end); add_code(p, CryptonightR_template_part3, CryptonightR_template_end);
Mem::flushInstructionCache(machine_code, p - p0); xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0);
} }
void wow_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) void wow_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM)
@ -139,7 +140,7 @@ void wow_compile_code_double(const V4_Instruction* code, int code_size, void* ma
*(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightWOW_template_double_mainloop) - ((const uint8_t*)CryptonightWOW_template_double_part1)) - (p - p0)); *(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightWOW_template_double_mainloop) - ((const uint8_t*)CryptonightWOW_template_double_part1)) - (p - p0));
add_code(p, CryptonightWOW_template_double_part4, CryptonightWOW_template_double_end); add_code(p, CryptonightWOW_template_double_part4, CryptonightWOW_template_double_end);
Mem::flushInstructionCache(machine_code, p - p0); xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0);
} }
void v4_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) void v4_compile_code_double(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM)
@ -155,7 +156,7 @@ void v4_compile_code_double(const V4_Instruction* code, int code_size, void* mac
*(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightR_template_double_mainloop) - ((const uint8_t*)CryptonightR_template_double_part1)) - (p - p0)); *(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightR_template_double_mainloop) - ((const uint8_t*)CryptonightR_template_double_part1)) - (p - p0));
add_code(p, CryptonightR_template_double_part4, CryptonightR_template_double_end); add_code(p, CryptonightR_template_double_part4, CryptonightR_template_double_end);
Mem::flushInstructionCache(machine_code, p - p0); xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0);
} }
void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM)
@ -169,7 +170,7 @@ void wow_soft_aes_compile_code(const V4_Instruction* code, int code_size, void*
*(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightWOW_soft_aes_template_mainloop) - ((const uint8_t*)CryptonightWOW_soft_aes_template_part1)) - (p - p0)); *(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightWOW_soft_aes_template_mainloop) - ((const uint8_t*)CryptonightWOW_soft_aes_template_part1)) - (p - p0));
add_code(p, CryptonightWOW_soft_aes_template_part3, CryptonightWOW_soft_aes_template_end); add_code(p, CryptonightWOW_soft_aes_template_part3, CryptonightWOW_soft_aes_template_end);
Mem::flushInstructionCache(machine_code, p - p0); xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0);
} }
void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM) void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* machine_code, xmrig::Assembly ASM)
@ -183,5 +184,5 @@ void v4_soft_aes_compile_code(const V4_Instruction* code, int code_size, void* m
*(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightR_soft_aes_template_mainloop) - ((const uint8_t*)CryptonightR_soft_aes_template_part1)) - (p - p0)); *(int*)(p - 4) = static_cast<int>((((const uint8_t*)CryptonightR_soft_aes_template_mainloop) - ((const uint8_t*)CryptonightR_soft_aes_template_part1)) - (p - p0));
add_code(p, CryptonightR_soft_aes_template_part3, CryptonightR_soft_aes_template_end); add_code(p, CryptonightR_soft_aes_template_part3, CryptonightR_soft_aes_template_end);
Mem::flushInstructionCache(machine_code, p - p0); xmrig::VirtualMemory::flushInstructionCache(machine_code, p - p0);
} }

View file

@ -3,7 +3,7 @@
extern "C" extern "C"
{ {
#include "c_blake256.h" #include "crypto/cn/c_blake256.h"
} }
enum V4_Settings enum V4_Settings

View file

@ -28,7 +28,7 @@
#if defined(XMRIG_ARM) #if defined(XMRIG_ARM)
# include "crypto/SSE2NEON.h" # include "crypto/cn/SSE2NEON.h"
#elif defined(__GNUC__) #elif defined(__GNUC__)
# include <x86intrin.h> # include <x86intrin.h>
#else #else

View file

@ -30,7 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include "common/crypto/Algorithm.h" #include "crypto/common/Algorithm.h"
#ifdef _MSC_VER #ifdef _MSC_VER
@ -70,21 +70,26 @@ static AlgoData const algorithms[] = {
{ "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS }, { "cryptonight/zls", "cn/zls", xmrig::CRYPTONIGHT, xmrig::VARIANT_ZLS },
{ "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE }, { "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE },
# ifndef XMRIG_NO_AEON # ifdef XMRIG_ALGO_RANDOMX
{ "randomx/wow", "rx/wow", xmrig::RANDOM_X, xmrig::VARIANT_RX_WOW },
{ "randomx", "rx", xmrig::RANDOM_X, xmrig::VARIANT_RX_WOW },
# endif
# ifdef XMRIG_ALGO_CN_LITE
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
{ "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO }, { "cryptonight-light", "cn-light", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
{ "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 }, { "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 },
{ "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 }, { "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
# endif # endif
# ifndef XMRIG_NO_SUMO # ifdef XMRIG_ALGO_CN_HEAVY
{ "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO }, { "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_AUTO },
{ "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 }, { "cryptonight-heavy/0", "cn-heavy/0", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 },
{ "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV }, { "cryptonight-heavy/xhv", "cn-heavy/xhv", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_XHV },
{ "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE }, { "cryptonight-heavy/tube", "cn-heavy/tube", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_TUBE },
# endif # endif
# ifndef XMRIG_NO_CN_PICO # ifdef XMRIG_ALGO_CN_PICO
{ "cryptonight-pico/trtl", "cn-pico/trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight-pico/trtl", "cn-pico/trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight-pico", "cn-pico", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight-pico", "cn-pico", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
{ "cryptonight-turtle", "cn-trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight-turtle", "cn-trtl", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
@ -92,7 +97,7 @@ static AlgoData const algorithms[] = {
{ "cryptonight_turtle", "cn_turtle", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL }, { "cryptonight_turtle", "cn_turtle", xmrig::CRYPTONIGHT_PICO, xmrig::VARIANT_TRTL },
# endif # endif
# ifndef XMRIG_NO_CN_GPU # ifdef XMRIG_ALGO_CN_GPU
{ "cryptonight/gpu", "cn/gpu", xmrig::CRYPTONIGHT, xmrig::VARIANT_GPU }, { "cryptonight/gpu", "cn/gpu", xmrig::CRYPTONIGHT, xmrig::VARIANT_GPU },
# endif # endif
}; };
@ -138,7 +143,8 @@ static const char *variants[] = {
"r", "r",
"rwz", "rwz",
"zls", "zls",
"double" "double",
"rx/wow",
}; };

View file

@ -5,7 +5,10 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,23 +24,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __MM_MALLOC_PORTABLE_H__ #ifndef XMRIG_VIRTUALMEMORY_H
#define __MM_MALLOC_PORTABLE_H__ #define XMRIG_VIRTUALMEMORY_H
#ifdef _WIN32 #include <stddef.h>
# ifdef __GNUC__ #include <stdint.h>
# include <mm_malloc.h>
# else
# include <malloc.h>
# endif
#else
# if defined(XMRIG_ARM) && !defined(__clang__)
# include "aligned_malloc.h"
# else
# include <mm_malloc.h>
# endif
#endif
#endif /* __MM_MALLOC_PORTABLE_H__ */ namespace xmrig {
class VirtualMemory
{
public:
static void *allocateExecutableMemory(size_t size);
static void *allocateLargePagesMemory(size_t size);
static void flushInstructionCache(void *p, size_t size);
static void freeLargePagesMemory(void *p, size_t size);
static void protectExecutableMemory(void *p, size_t size);
static void unprotectExecutableMemory(void *p, size_t size);
};
} /* namespace xmrig */
#endif /* XMRIG_VIRTUALMEMORY_H */

View file

@ -0,0 +1,90 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <sys/mman.h>
#include "crypto/common/VirtualMemory.h"
#if defined(__APPLE__)
# include <mach/vm_statistics.h>
#endif
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
{
# if defined(__APPLE__)
void *mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
# else
void *mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# endif
return mem == MAP_FAILED ? nullptr : mem;
}
void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size)
{
# if defined(__APPLE__)
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
# elif defined(__FreeBSD__)
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0);
# else
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
# endif
return mem == MAP_FAILED ? nullptr : mem;
}
void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size)
{
# ifdef HAVE_BUILTIN_CLEAR_CACHE
__builtin___clear_cache(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p) + size);
# endif
}
void xmrig::VirtualMemory::freeLargePagesMemory(void *p, size_t size)
{
munmap(p, size);
}
void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size)
{
mprotect(p, size, PROT_READ | PROT_EXEC);
}
void xmrig::VirtualMemory::unprotectExecutableMemory(void *p, size_t size)
{
mprotect(p, size, PROT_WRITE | PROT_EXEC);
}

View file

@ -0,0 +1,86 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2018-2019 tevador <tevador@gmail.com>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <winsock2.h>
#include <windows.h>
#include "crypto/common/VirtualMemory.h"
namespace xmrig {
constexpr size_t align(size_t pos, size_t align) {
return ((pos - 1) / align + 1) * align;
}
}
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
{
return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
}
void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size)
{
const size_t min = GetLargePageMinimum();
void *mem = nullptr;
if (min > 0) {
mem = VirtualAlloc(nullptr, align(size, min), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
}
return mem;
}
void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size)
{
::FlushInstructionCache(GetCurrentProcess(), p, size);
}
void xmrig::VirtualMemory::freeLargePagesMemory(void *p, size_t)
{
VirtualFree(p, 0, MEM_RELEASE);
}
void xmrig::VirtualMemory::protectExecutableMemory(void *p, size_t size)
{
DWORD oldProtect;
VirtualProtect(p, size, PAGE_EXECUTE_READ, &oldProtect);
}
void xmrig::VirtualMemory::unprotectExecutableMemory(void *p, size_t size)
{
DWORD oldProtect;
VirtualProtect(p, size, PAGE_EXECUTE_READWRITE, &oldProtect);
}

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,22 +22,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ALIGNED_MALLOC_H__ #ifndef XMRIG_MM_MALLOC_PORTABLE_H
#define __ALIGNED_MALLOC_H__ #define XMRIG_MM_MALLOC_PORTABLE_H
#if defined(XMRIG_ARM) && !defined(__clang__)
#include <stdlib.h> #include <stdlib.h>
#ifndef __cplusplus #ifndef __cplusplus
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size); extern
#else #else
// Some systems (e.g. those with GNU libc) declare posix_memalign with an extern "C"
// exception specifier. Via an "egregious workaround" in
// Sema::CheckEquivalentExceptionSpec, Clang accepts the following as a valid
// redeclaration of glibc's declaration.
extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
#endif #endif
int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
static __inline__ void *__attribute__((__always_inline__, __malloc__)) _mm_malloc(size_t __size, size_t __align) static __inline__ void *__attribute__((__always_inline__, __malloc__)) _mm_malloc(size_t __size, size_t __align)
@ -45,12 +44,13 @@ static __inline__ void *__attribute__((__always_inline__, __malloc__)) _mm_mallo
return malloc(__size); return malloc(__size);
} }
if (!(__align & (__align - 1)) && __align < sizeof(void *)) if (!(__align & (__align - 1)) && __align < sizeof(void *)) {
__align = sizeof(void *); __align = sizeof(void *);
}
void *__mallocedMemory; void *__mallocedMemory;
if (posix_memalign(&__mallocedMemory, __align, __size)) { if (posix_memalign(&__mallocedMemory, __align, __size)) {
return 0; return nullptr;
} }
return __mallocedMemory; return __mallocedMemory;
@ -61,5 +61,11 @@ static __inline__ void __attribute__((__always_inline__)) _mm_free(void *__p)
{ {
free(__p); free(__p);
} }
#elif defined(_WIN32) && !defined(__GNUC__)
# include <malloc.h>
#else
# include <mm_malloc.h>
#endif
#endif /* __ALIGNED_MALLOC_H__ */
#endif /* XMRIG_MM_MALLOC_PORTABLE_H */

View file

@ -28,15 +28,15 @@
#define APP_ID "xmrig" #define APP_ID "xmrig"
#define APP_NAME "XMRig" #define APP_NAME "XMRig"
#define APP_DESC "XMRig CPU miner" #define APP_DESC "XMRig CPU miner"
#define APP_VERSION "2.15.4-beta" #define APP_VERSION "2.16.0-evo"
#define APP_DOMAIN "xmrig.com" #define APP_DOMAIN "xmrig.com"
#define APP_SITE "www.xmrig.com" #define APP_SITE "www.xmrig.com"
#define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2019 xmrig.com"
#define APP_KIND "cpu" #define APP_KIND "cpu"
#define APP_VER_MAJOR 2 #define APP_VER_MAJOR 2
#define APP_VER_MINOR 15 #define APP_VER_MINOR 16
#define APP_VER_PATCH 4 #define APP_VER_PATCH 0
#ifdef _MSC_VER #ifdef _MSC_VER
# if (_MSC_VER >= 1920) # if (_MSC_VER >= 1920)

View file

@ -27,16 +27,17 @@
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "common/cpu/Cpu.h" #include "common/cpu/Cpu.h"
#include "crypto/Asm.h" #include "crypto/cn/Asm.h"
#include "crypto/common/VirtualMemory.h"
#include "Mem.h" #include "Mem.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "workers/CpuThread.h" #include "workers/CpuThread.h"
#if defined(XMRIG_ARM) #if defined(XMRIG_ARM)
# include "crypto/CryptoNight_arm.h" # include "crypto/cn/CryptoNight_arm.h"
#else #else
# include "crypto/CryptoNight_x86.h" # include "crypto/cn/CryptoNight_x86.h"
#endif #endif
@ -120,7 +121,7 @@ xmrig::CpuThread::cn_mainloop_fun cn_double_double_mainloop_sandybridge_a
void xmrig::CpuThread::patchAsmVariants() void xmrig::CpuThread::patchAsmVariants()
{ {
const int allocation_size = 65536; const int allocation_size = 65536;
uint8_t *base = static_cast<uint8_t *>(Mem::allocateExecutableMemory(allocation_size)); uint8_t *base = static_cast<uint8_t *>(VirtualMemory::allocateExecutableMemory(allocation_size));
cn_half_mainloop_ivybridge_asm = reinterpret_cast<cn_mainloop_fun> (base + 0x0000); cn_half_mainloop_ivybridge_asm = reinterpret_cast<cn_mainloop_fun> (base + 0x0000);
cn_half_mainloop_ryzen_asm = reinterpret_cast<cn_mainloop_fun> (base + 0x1000); cn_half_mainloop_ryzen_asm = reinterpret_cast<cn_mainloop_fun> (base + 0x1000);
@ -162,8 +163,8 @@ void xmrig::CpuThread::patchAsmVariants()
patchCode(cn_double_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK); patchCode(cn_double_mainloop_bulldozer_asm, cnv2_mainloop_bulldozer_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK);
patchCode(cn_double_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK); patchCode(cn_double_double_mainloop_sandybridge_asm, cnv2_double_mainloop_sandybridge_asm, xmrig::CRYPTONIGHT_DOUBLE_ITER, xmrig::CRYPTONIGHT_MASK);
Mem::protectExecutableMemory(base, allocation_size); VirtualMemory::protectExecutableMemory(base, allocation_size);
Mem::flushInstructionCache(base, allocation_size); VirtualMemory::flushInstructionCache(base, allocation_size);
} }
#endif #endif
@ -206,7 +207,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
add_asm_func<CRYPTONIGHT, VARIANT_WOW>(asm_func_map); add_asm_func<CRYPTONIGHT, VARIANT_WOW>(asm_func_map);
add_asm_func<CRYPTONIGHT, VARIANT_4>(asm_func_map); add_asm_func<CRYPTONIGHT, VARIANT_4>(asm_func_map);
# ifndef XMRIG_NO_CN_PICO # ifdef XMRIG_ALGO_CN_PICO
add_asm_func<CRYPTONIGHT_PICO, VARIANT_TRTL>(asm_func_map); add_asm_func<CRYPTONIGHT_PICO, VARIANT_TRTL>(asm_func_map);
# endif # endif
@ -320,7 +321,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL
# ifndef XMRIG_NO_CN_GPU # ifdef XMRIG_ALGO_CN_GPU
cryptonight_single_hash_gpu<CRYPTONIGHT, false, VARIANT_GPU>, cryptonight_single_hash_gpu<CRYPTONIGHT, false, VARIANT_GPU>,
nullptr, nullptr,
cryptonight_single_hash_gpu<CRYPTONIGHT, true, VARIANT_GPU>, cryptonight_single_hash_gpu<CRYPTONIGHT, true, VARIANT_GPU>,
@ -389,8 +390,9 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>, cryptonight_triple_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>,
cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>, cryptonight_quad_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>,
cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>, cryptonight_penta_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# ifndef XMRIG_NO_AEON # ifdef XMRIG_ALGO_CN_LITE
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_0>,
cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_0>, cryptonight_double_hash<CRYPTONIGHT_LITE, false, VARIANT_0>,
cryptonight_single_hash<CRYPTONIGHT_LITE, true, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT_LITE, true, VARIANT_0>,
@ -428,6 +430,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# else # else
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1
@ -446,9 +449,10 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# endif # endif
# ifndef XMRIG_NO_SUMO # ifdef XMRIG_ALGO_CN_HEAVY
cryptonight_single_hash<CRYPTONIGHT_HEAVY, false, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT_HEAVY, false, VARIANT_0>,
cryptonight_double_hash<CRYPTONIGHT_HEAVY, false, VARIANT_0>, cryptonight_double_hash<CRYPTONIGHT_HEAVY, false, VARIANT_0>,
cryptonight_single_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>, cryptonight_single_hash<CRYPTONIGHT_HEAVY, true, VARIANT_0>,
@ -498,6 +502,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# else # else
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1
@ -516,9 +521,10 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# endif # endif
# ifndef XMRIG_NO_CN_PICO # ifdef XMRIG_ALGO_CN_PICO
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE
@ -547,6 +553,7 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# else # else
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1
@ -565,7 +572,26 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
# endif # endif
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_0
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_1
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TUBE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XTL
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_MSR
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XHV
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_XAO
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RTO
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_2
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_HALF
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_TRTL
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_GPU
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_WOW
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_4
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RWZ
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, // VARIANT_RX_WOW
}; };
static_assert(count == sizeof(func_table) / sizeof(func_table[0]), "func_table size mismatch"); static_assert(count == sizeof(func_table) / sizeof(func_table[0]), "func_table size mismatch");

View file

@ -27,7 +27,7 @@
#include <thread> #include <thread>
#include "crypto/CryptoNight_test.h" #include "crypto/cn/CryptoNight_test.h"
#include "workers/CpuThread.h" #include "workers/CpuThread.h"
#include "workers/MultiWorker.h" #include "workers/MultiWorker.h"
#include "workers/Workers.h" #include "workers/Workers.h"
@ -37,7 +37,9 @@ template<size_t N>
MultiWorker<N>::MultiWorker(ThreadHandle *handle) MultiWorker<N>::MultiWorker(ThreadHandle *handle)
: Worker(handle) : Worker(handle)
{ {
if (m_thread->algorithm() != xmrig::RANDOM_X) {
m_memory = Mem::create(m_ctx, m_thread->algorithm(), N); m_memory = Mem::create(m_ctx, m_thread->algorithm(), N);
}
} }
@ -45,9 +47,34 @@ template<size_t N>
MultiWorker<N>::~MultiWorker() MultiWorker<N>::~MultiWorker()
{ {
Mem::release(m_ctx, N, m_memory); Mem::release(m_ctx, N, m_memory);
# ifdef XMRIG_ALGO_RANDOMX
if (m_rx_vm) {
randomx_destroy_vm(m_rx_vm);
}
# endif
} }
#ifdef XMRIG_ALGO_RANDOMX
template<size_t N>
void MultiWorker<N>::allocateRandomX_VM()
{
if (!m_rx_vm) {
int flags = RANDOMX_FLAG_LARGE_PAGES | RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT;
if (!m_thread->isSoftAES()) {
flags |= RANDOMX_FLAG_HARD_AES;
}
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags), nullptr, Workers::getDataset());
if (!m_rx_vm) {
m_rx_vm = randomx_create_vm(static_cast<randomx_flags>(flags - RANDOMX_FLAG_LARGE_PAGES), nullptr, Workers::getDataset());
}
}
}
#endif
template<size_t N> template<size_t N>
bool MultiWorker<N>::selfTest() bool MultiWorker<N>::selfTest()
{ {
@ -68,7 +95,7 @@ bool MultiWorker<N>::selfTest()
verify(VARIANT_ZLS, test_output_zls) && verify(VARIANT_ZLS, test_output_zls) &&
verify(VARIANT_DOUBLE, test_output_double); verify(VARIANT_DOUBLE, test_output_double);
# ifndef XMRIG_NO_CN_GPU # ifdef XMRIG_ALGO_CN_GPU
if (!rc || N > 1) { if (!rc || N > 1) {
return rc; return rc;
} }
@ -79,14 +106,14 @@ bool MultiWorker<N>::selfTest()
# endif # endif
} }
# ifndef XMRIG_NO_AEON # ifdef XMRIG_ALGO_CN_LITE
if (m_thread->algorithm() == CRYPTONIGHT_LITE) { if (m_thread->algorithm() == CRYPTONIGHT_LITE) {
return verify(VARIANT_0, test_output_v0_lite) && return verify(VARIANT_0, test_output_v0_lite) &&
verify(VARIANT_1, test_output_v1_lite); verify(VARIANT_1, test_output_v1_lite);
} }
# endif # endif
# ifndef XMRIG_NO_SUMO # ifdef XMRIG_ALGO_CN_HEAVY
if (m_thread->algorithm() == CRYPTONIGHT_HEAVY) { if (m_thread->algorithm() == CRYPTONIGHT_HEAVY) {
return verify(VARIANT_0, test_output_v0_heavy) && return verify(VARIANT_0, test_output_v0_heavy) &&
verify(VARIANT_XHV, test_output_xhv_heavy) && verify(VARIANT_XHV, test_output_xhv_heavy) &&
@ -94,12 +121,18 @@ bool MultiWorker<N>::selfTest()
} }
# endif # endif
# ifndef XMRIG_NO_CN_PICO # ifdef XMRIG_ALGO_CN_PICO
if (m_thread->algorithm() == CRYPTONIGHT_PICO) { if (m_thread->algorithm() == CRYPTONIGHT_PICO) {
return verify(VARIANT_TRTL, test_output_pico_trtl); return verify(VARIANT_TRTL, test_output_pico_trtl);
} }
# endif # endif
# ifdef XMRIG_ALGO_RANDOMX
if (m_thread->algorithm() == RANDOM_X) {
return true;
}
# endif
return false; return false;
} }
@ -126,7 +159,19 @@ void MultiWorker<N>::start()
storeStats(); storeStats();
} }
m_thread->fn(m_state.job.algorithm().variant())(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height()); const xmrig::Variant v = m_state.job.algorithm().variant();
# ifdef XMRIG_ALGO_RANDOMX
if (v == xmrig::VARIANT_RX_WOW) {
allocateRandomX_VM();
Workers::updateDataset(m_state.job.seedHash(), m_totalWays);
randomx_calculate_hash(m_rx_vm, m_state.blob, m_state.job.size(), m_hash);
}
else
# endif
{
m_thread->fn(v)(m_state.blob, m_state.job.size(), m_hash, m_ctx, m_state.job.height());
}
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < N; ++i) {
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) { if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) {

View file

@ -27,6 +27,11 @@
#define XMRIG_MULTIWORKER_H #define XMRIG_MULTIWORKER_H
#ifdef XMRIG_ALGO_RANDOMX
# include <randomx.h>
#endif
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
#include "Mem.h" #include "Mem.h"
#include "net/JobResult.h" #include "net/JobResult.h"
@ -48,6 +53,10 @@ protected:
void start() override; void start() override;
private: private:
# ifdef XMRIG_ALGO_RANDOMX
void allocateRandomX_VM();
# endif
bool resume(const xmrig::Job &job); bool resume(const xmrig::Job &job);
bool verify(xmrig::Variant variant, const uint8_t *referenceValue); bool verify(xmrig::Variant variant, const uint8_t *referenceValue);
bool verify2(xmrig::Variant variant, const uint8_t *referenceValue); bool verify2(xmrig::Variant variant, const uint8_t *referenceValue);
@ -70,6 +79,10 @@ private:
State m_pausedState; State m_pausedState;
State m_state; State m_state;
uint8_t m_hash[N * 32]; uint8_t m_hash[N * 32];
# ifdef XMRIG_ALGO_RANDOMX
randomx_vm *m_rx_vm = nullptr;
# endif
}; };

View file

@ -32,7 +32,7 @@
#include "base/tools/Handle.h" #include "base/tools/Handle.h"
#include "core/config/Config.h" #include "core/config/Config.h"
#include "core/Controller.h" #include "core/Controller.h"
#include "crypto/CryptoNight_constants.h" #include "crypto/cn/CryptoNight_constants.h"
#include "interfaces/IJobResultListener.h" #include "interfaces/IJobResultListener.h"
#include "interfaces/IThread.h" #include "interfaces/IThread.h"
#include "Mem.h" #include "Mem.h"
@ -60,6 +60,14 @@ uv_rwlock_t Workers::m_rwlock;
uv_timer_t *Workers::m_timer = nullptr; uv_timer_t *Workers::m_timer = nullptr;
xmrig::Controller *Workers::m_controller = nullptr; xmrig::Controller *Workers::m_controller = nullptr;
#ifdef XMRIG_ALGO_RANDOMX
uv_rwlock_t Workers::m_rx_dataset_lock;
randomx_cache *Workers::m_rx_cache = nullptr;
randomx_dataset *Workers::m_rx_dataset = nullptr;
uint8_t Workers::m_rx_seed_hash[32] = {};
std::atomic<uint32_t> Workers::m_rx_dataset_init_thread_counter = {};
#endif
xmrig::Job Workers::job() xmrig::Job Workers::job()
{ {
@ -177,6 +185,7 @@ void Workers::start(xmrig::Controller *controller)
const std::vector<xmrig::IThread *> &threads = controller->config()->threads(); const std::vector<xmrig::IThread *> &threads = controller->config()->threads();
m_status.algo = controller->config()->algorithm().algo(); m_status.algo = controller->config()->algorithm().algo();
m_status.variant = controller->config()->algorithm().variant();
m_status.threads = threads.size(); m_status.threads = threads.size();
for (const xmrig::IThread *thread : threads) { for (const xmrig::IThread *thread : threads) {
@ -188,6 +197,10 @@ void Workers::start(xmrig::Controller *controller)
uv_mutex_init(&m_mutex); uv_mutex_init(&m_mutex);
uv_rwlock_init(&m_rwlock); uv_rwlock_init(&m_rwlock);
# ifdef XMRIG_ALGO_RANDOMX
uv_rwlock_init(&m_rx_dataset_lock);
# endif
m_sequence = 1; m_sequence = 1;
m_paused = 1; m_paused = 1;
@ -240,7 +253,7 @@ void Workers::threadsSummary(rapidjson::Document &doc)
{ {
uv_mutex_lock(&m_mutex); uv_mutex_lock(&m_mutex);
const uint64_t pages[2] = { m_status.hugePages, m_status.pages }; const uint64_t pages[2] = { m_status.hugePages, m_status.pages };
const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo); const uint64_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant);
uv_mutex_unlock(&m_mutex); uv_mutex_unlock(&m_mutex);
auto &allocator = doc.GetAllocator(); auto &allocator = doc.GetAllocator();
@ -344,15 +357,92 @@ void Workers::start(IWorker *worker)
if (m_status.started == m_status.threads) { if (m_status.started == m_status.threads) {
const double percent = (double) m_status.hugePages / m_status.pages * 100.0; const double percent = (double) m_status.hugePages / m_status.pages * 100.0;
const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo) / 1024; const size_t memory = m_status.ways * xmrig::cn_select_memory(m_status.algo, m_status.variant) / 1024;
# ifdef XMRIG_ALGO_RANDOMX
if (m_status.algo == xmrig::RANDOM_X) {
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " memory " CYAN_BOLD("%zu KB") "",
m_status.threads, m_status.ways, memory);
} else
# endif
{
LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "", LOG_INFO(GREEN_BOLD("READY (CPU)") " threads " CYAN_BOLD("%zu(%zu)") " huge pages %s%zu/%zu %1.0f%%\x1B[0m memory " CYAN_BOLD("%zu KB") "",
m_status.threads, m_status.ways, m_status.threads, m_status.ways,
(m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)), (m_status.hugePages == m_status.pages ? GREEN_BOLD_S : (m_status.hugePages == 0 ? RED_BOLD_S : YELLOW_BOLD_S)),
m_status.hugePages, m_status.pages, percent, memory); m_status.hugePages, m_status.pages, percent, memory);
} }
}
uv_mutex_unlock(&m_mutex); uv_mutex_unlock(&m_mutex);
worker->start(); worker->start();
} }
#ifdef XMRIG_ALGO_RANDOMX
void Workers::updateDataset(const uint8_t* seed_hash, const uint32_t num_threads)
{
// Check if we need to update cache and dataset
if (memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) == 0)
return;
const uint32_t thread_id = m_rx_dataset_init_thread_counter++;
LOG_DEBUG("Thread %u started updating RandomX dataset", thread_id);
// Wait for all threads to get here
do {
if (m_sequence.load(std::memory_order_relaxed) == 0) {
// Exit immediately if workers were stopped
return;
}
std::this_thread::yield();
} while (m_rx_dataset_init_thread_counter.load() != num_threads);
// One of the threads updates cache
uv_rwlock_wrlock(&m_rx_dataset_lock);
if (memcmp(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash)) != 0) {
memcpy(m_rx_seed_hash, seed_hash, sizeof(m_rx_seed_hash));
randomx_init_cache(m_rx_cache, m_rx_seed_hash, sizeof(m_rx_seed_hash));
}
uv_rwlock_wrunlock(&m_rx_dataset_lock);
// All threads update dataset
const uint32_t a = (randomx_dataset_item_count() * thread_id) / num_threads;
const uint32_t b = (randomx_dataset_item_count() * (thread_id + 1)) / num_threads;
randomx_init_dataset(m_rx_dataset, m_rx_cache, a, b - a);
LOG_DEBUG("Thread %u finished updating RandomX dataset", thread_id);
// Wait for all threads to complete
--m_rx_dataset_init_thread_counter;
do {
if (m_sequence.load(std::memory_order_relaxed) == 0) {
// Exit immediately if workers were stopped
return;
}
std::this_thread::yield();
} while (m_rx_dataset_init_thread_counter.load() != 0);
}
randomx_dataset* Workers::getDataset()
{
if (m_rx_dataset)
return m_rx_dataset;
uv_rwlock_wrlock(&m_rx_dataset_lock);
if (!m_rx_dataset) {
randomx_dataset* dataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES);
if (!dataset) {
dataset = randomx_alloc_dataset(RANDOMX_FLAG_DEFAULT);
}
m_rx_cache = randomx_alloc_cache(static_cast<randomx_flags>(RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES));
if (!m_rx_cache) {
m_rx_cache = randomx_alloc_cache(RANDOMX_FLAG_JIT);
}
m_rx_dataset = dataset;
}
uv_rwlock_wrunlock(&m_rx_dataset_lock);
return m_rx_dataset;
}
#endif

View file

@ -31,6 +31,10 @@
#include <uv.h> #include <uv.h>
#include <vector> #include <vector>
#ifdef XMRIG_ALGO_RANDOMX
# include <randomx.h>
#endif
#include "base/net/stratum/Job.h" #include "base/net/stratum/Job.h"
#include "net/JobResult.h" #include "net/JobResult.h"
#include "rapidjson/fwd.h" #include "rapidjson/fwd.h"
@ -72,6 +76,11 @@ public:
static void threadsSummary(rapidjson::Document &doc); static void threadsSummary(rapidjson::Document &doc);
# endif # endif
# ifdef XMRIG_ALGO_RANDOMX
static void updateDataset(const uint8_t* seed_hash, uint32_t num_threads);
static randomx_dataset* getDataset();
# endif
private: private:
static void onReady(void *arg); static void onReady(void *arg);
static void onResult(uv_async_t *handle); static void onResult(uv_async_t *handle);
@ -87,7 +96,8 @@ private:
started(0), started(0),
threads(0), threads(0),
ways(0), ways(0),
algo(xmrig::CRYPTONIGHT) algo(xmrig::CRYPTONIGHT),
variant(xmrig::VARIANT_AUTO)
{} {}
size_t hugePages; size_t hugePages;
@ -96,6 +106,7 @@ private:
size_t threads; size_t threads;
size_t ways; size_t ways;
xmrig::Algo algo; xmrig::Algo algo;
xmrig::Variant variant;
}; };
static bool m_active; static bool m_active;
@ -114,6 +125,14 @@ private:
static uv_rwlock_t m_rwlock; static uv_rwlock_t m_rwlock;
static uv_timer_t *m_timer; static uv_timer_t *m_timer;
static xmrig::Controller *m_controller; static xmrig::Controller *m_controller;
# ifdef XMRIG_ALGO_RANDOMX
static uv_rwlock_t m_rx_dataset_lock;
static randomx_cache *m_rx_cache;
static randomx_dataset *m_rx_dataset;
static uint8_t m_rx_seed_hash[32];
static std::atomic<uint32_t> m_rx_dataset_init_thread_counter;
# endif
}; };