-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
14,911 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
if (WITH_ASM AND NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
set(XMRIG_ASM_LIBRARY "xmrig-asm") | ||
|
||
if (CMAKE_C_COMPILER_ID MATCHES MSVC) | ||
enable_language(ASM_MASM) | ||
|
||
if (MSVC_TOOLSET_VERSION GREATER_EQUAL 141) | ||
set(XMRIG_ASM_FILE | ||
"src/crypto/asm/cn_main_loop.asm" | ||
"src/crypto/asm/CryptonightR_template.asm" | ||
) | ||
else() | ||
set(XMRIG_ASM_FILE | ||
"src/crypto/asm/win64/cn_main_loop.asm" | ||
"src/crypto/asm/win64/CryptonightR_template.asm" | ||
) | ||
endif() | ||
|
||
set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY ASM_MASM) | ||
else() | ||
enable_language(ASM) | ||
|
||
if (WIN32 AND CMAKE_C_COMPILER_ID MATCHES GNU) | ||
set(XMRIG_ASM_FILE | ||
"src/crypto/asm/win64/cn_main_loop.S" | ||
"src/crypto/asm/win64/CryptonightR_template.S" | ||
) | ||
else() | ||
set(XMRIG_ASM_FILE | ||
"src/crypto/asm/cn_main_loop.S" | ||
"src/crypto/asm/CryptonightR_template.S" | ||
) | ||
endif() | ||
|
||
set_property(SOURCE ${XMRIG_ASM_FILE} PROPERTY C) | ||
endif() | ||
|
||
add_library(${XMRIG_ASM_LIBRARY} STATIC ${XMRIG_ASM_FILE}) | ||
set(XMRIG_ASM_SOURCES "") | ||
set_property(TARGET ${XMRIG_ASM_LIBRARY} PROPERTY LINKER_LANGUAGE C) | ||
else() | ||
set(XMRIG_ASM_SOURCES "") | ||
set(XMRIG_ASM_LIBRARY "") | ||
add_definitions(/DXMRIG_NO_ASM) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* XMRig | ||
* Copyright 2010 Jeff Garzik <[email protected]> | ||
* Copyright 2012-2014 pooler <[email protected]> | ||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> | ||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> | ||
* Copyright 2016 Jay D Dee <[email protected]> | ||
* 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 2016-2019 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* | ||
* 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 "common/utils/mm_malloc.h" | ||
#include "crypto/CryptoNight.h" | ||
#include "crypto/CryptoNight_constants.h" | ||
#include "Mem.h" | ||
|
||
|
||
bool Mem::m_enabled = true; | ||
int Mem::m_flags = 0; | ||
|
||
|
||
MemInfo Mem::create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count) | ||
{ | ||
using namespace xmrig; | ||
|
||
MemInfo info; | ||
info.size = cn_select_memory(algorithm) * count; | ||
|
||
constexpr const size_t align_size = 2 * 1024 * 1024; | ||
info.size = ((info.size + align_size - 1) / align_size) * align_size; | ||
info.pages = info.size / align_size; | ||
|
||
allocate(info, m_enabled); | ||
|
||
for (size_t i = 0; i < count; ++i) { | ||
cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096)); | ||
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>(p); | ||
c->generated_code_double = reinterpret_cast<cn_mainloop_double_fun_ms_abi>(p + 0x2000); | ||
c->generated_code_height = (uint64_t)(-1); | ||
c->generated_code_double_height = (uint64_t)(-1); | ||
|
||
ctx[i] = c; | ||
} | ||
|
||
return info; | ||
} | ||
|
||
|
||
void Mem::release(cryptonight_ctx **ctx, size_t count, MemInfo &info) | ||
{ | ||
release(info); | ||
|
||
for (size_t i = 0; i < count; ++i) { | ||
_mm_free(ctx[i]); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* XMRig | ||
* Copyright 2010 Jeff Garzik <[email protected]> | ||
* Copyright 2012-2014 pooler <[email protected]> | ||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> | ||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> | ||
* Copyright 2016 Jay D Dee <[email protected]> | ||
* 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 2016-2019 XMRig <https://github.com/xmrig>, <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef XMRIG_MEM_H | ||
#define XMRIG_MEM_H | ||
|
||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
|
||
#include "common/xmrig.h" | ||
|
||
|
||
struct cryptonight_ctx; | ||
|
||
|
||
struct MemInfo | ||
{ | ||
alignas(16) uint8_t *memory; | ||
|
||
size_t hugePages; | ||
size_t pages; | ||
size_t size; | ||
}; | ||
|
||
|
||
class Mem | ||
{ | ||
public: | ||
enum Flags { | ||
HugepagesAvailable = 1, | ||
HugepagesEnabled = 2, | ||
Lock = 4 | ||
}; | ||
|
||
static MemInfo create(cryptonight_ctx **ctx, xmrig::Algo algorithm, size_t count); | ||
static void init(bool enabled); | ||
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; } | ||
|
||
private: | ||
static void allocate(MemInfo &info, bool enabled); | ||
static void release(MemInfo &info); | ||
|
||
static int m_flags; | ||
static bool m_enabled; | ||
}; | ||
|
||
|
||
#endif /* XMRIG_MEM_H */ |
Oops, something went wrong.