Merge branch 'master' of git@github.com:tevador/RandomX.git

This commit is contained in:
tevador 2019-10-23 16:57:44 +02:00
commit e3c5ab7002
9 changed files with 32 additions and 4 deletions

View File

@ -100,6 +100,7 @@ if (ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "
src/jit_compiler_x86.cpp) src/jit_compiler_x86.cpp)
# cheat because cmake and ccache hate each other # cheat because cmake and ccache hate each other
set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY LANGUAGE C) set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY LANGUAGE C)
set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.asm)
if(ARCH STREQUAL "native") if(ARCH STREQUAL "native")
add_flag("-march=native") add_flag("-march=native")
@ -132,6 +133,7 @@ if (ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64" OR ARM_ID STREQUAL "arm
src/jit_compiler_a64.cpp) src/jit_compiler_a64.cpp)
# cheat because cmake and ccache hate each other # cheat because cmake and ccache hate each other
set_property(SOURCE src/jit_compiler_a64_static.S PROPERTY LANGUAGE C) set_property(SOURCE src/jit_compiler_a64_static.S PROPERTY LANGUAGE C)
set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.asm)
# not sure if this check is needed # not sure if this check is needed
include(CheckIncludeFile) include(CheckIncludeFile)

View File

@ -934,7 +934,7 @@ The item data is represented by 8 64-bit integer registers: `r0`-`r7`.
1. XOR all registers with the 64 bytes loaded in step 4 (8 bytes per column in order `r0`-`r7`). 1. XOR all registers with the 64 bytes loaded in step 4 (8 bytes per column in order `r0`-`r7`).
1. Set `cacheIndex` to the value of the register that has the longest dependency chain in the SuperscalarHash function executed in step 5. 1. Set `cacheIndex` to the value of the register that has the longest dependency chain in the SuperscalarHash function executed in step 5.
1. Set `i = i + 1` and go back to step 4 if `i < RANDOMX_CACHE_ACCESSES`. 1. Set `i = i + 1` and go back to step 4 if `i < RANDOMX_CACHE_ACCESSES`.
1. Concatenate registers `r0`-`r7` in little endian format to get the final Datset item data. 1. Concatenate registers `r0`-`r7` in little endian format to get the final Dataset item data.
The constants used to initialize register values in step 1 were determined as follows: The constants used to initialize register values in step 1 were determined as follows:

View File

@ -100,6 +100,7 @@
# v30 -> E 'or' mask = 0x3*00000000******3*00000000****** # v30 -> E 'or' mask = 0x3*00000000******3*00000000******
# v31 -> scale mask = 0x81f000000000000081f0000000000000 # v31 -> scale mask = 0x81f000000000000081f0000000000000
.balign 4
randomx_program_aarch64: randomx_program_aarch64:
# Save callee-saved registers # Save callee-saved registers
sub sp, sp, 192 sub sp, sp, 192

View File

@ -42,6 +42,11 @@ extern "C" {
randomx_flags randomx_get_flags() { randomx_flags randomx_get_flags() {
randomx_flags flags = RANDOMX_HAVE_COMPILER ? RANDOMX_FLAG_JIT : RANDOMX_FLAG_DEFAULT; randomx_flags flags = RANDOMX_HAVE_COMPILER ? RANDOMX_FLAG_JIT : RANDOMX_FLAG_DEFAULT;
randomx::Cpu cpu; randomx::Cpu cpu;
#ifdef __OpenBSD__
if (flags == RANDOMX_FLAG_JIT) {
flags |= RANDOMX_FLAG_SECURE;
}
#endif
if (HAVE_AES && cpu.hasAes()) { if (HAVE_AES && cpu.hasAes()) {
flags |= RANDOMX_FLAG_HARD_AES; flags |= RANDOMX_FLAG_HARD_AES;
} }

View File

@ -83,6 +83,7 @@ extern "C" {
* RANDOMX_FLAG_FULL_MEM * RANDOMX_FLAG_FULL_MEM
* RANDOMX_FLAG_SECURE * RANDOMX_FLAG_SECURE
* These flags must be added manually if desired. * These flags must be added manually if desired.
* On OpenBSD RANDOMX_FLAG_SECURE is enabled by default in JIT mode as W^X is enforced by the OS.
*/ */
RANDOMX_EXPORT randomx_flags randomx_get_flags(void); RANDOMX_EXPORT randomx_flags randomx_get_flags(void);

View File

@ -65,7 +65,7 @@ set_thread_affinity(std::thread::native_handle_type thread,
(thread_policy_t)&policy, 1); (thread_policy_t)&policy, 1);
#elif defined(_WIN32) || defined(__CYGWIN__) #elif defined(_WIN32) || defined(__CYGWIN__)
rc = SetThreadAffinityMask(reinterpret_cast<HANDLE>(thread), 1ULL << cpuid) == 0 ? -2 : 0; rc = SetThreadAffinityMask(reinterpret_cast<HANDLE>(thread), 1ULL << cpuid) == 0 ? -2 : 0;
#else #elif !defined(__OpenBSD__)
cpu_set_t cs; cpu_set_t cs;
CPU_ZERO(&cs); CPU_ZERO(&cs);
CPU_SET(cpuid, &cs); CPU_SET(cpuid, &cs);

View File

@ -190,6 +190,9 @@ int main(int argc, char** argv) {
} }
if (jit) { if (jit) {
flags |= RANDOMX_FLAG_JIT; flags |= RANDOMX_FLAG_JIT;
#ifdef __OpenBSD__
flags |= RANDOMX_FLAG_SECURE;
#endif
} }
} }
@ -199,9 +202,11 @@ int main(int argc, char** argv) {
if (miningMode) { if (miningMode) {
flags |= RANDOMX_FLAG_FULL_MEM; flags |= RANDOMX_FLAG_FULL_MEM;
} }
#ifndef __OpenBSD__
if (secure) { if (secure) {
flags |= RANDOMX_FLAG_SECURE; flags |= RANDOMX_FLAG_SECURE;
} }
#endif
if (flags & RANDOMX_FLAG_ARGON2_AVX2) { if (flags & RANDOMX_FLAG_ARGON2_AVX2) {
std::cout << " - Argon2 implementation: AVX2" << std::endl; std::cout << " - Argon2 implementation: AVX2" << std::endl;

View File

@ -143,7 +143,11 @@ int main() {
randomx::JitCompiler jit; randomx::JitCompiler jit;
jit.generateSuperscalarHash(cache->programs, cache->reciprocalCache); jit.generateSuperscalarHash(cache->programs, cache->reciprocalCache);
jit.generateDatasetInitCode(); jit.generateDatasetInitCode();
#ifdef __OpenBSD__
jit.enableExecution();
#else
jit.enableAll(); jit.enableAll();
#endif
uint64_t datasetItem[8]; uint64_t datasetItem[8];
jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 0, 1); jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 0, 1);
assert(datasetItem[0] == 0x680588a85ae222db); assert(datasetItem[0] == 0x680588a85ae222db);
@ -950,7 +954,11 @@ int main() {
assert(ibc.memMask == randomx::ScratchpadL3Mask); assert(ibc.memMask == randomx::ScratchpadL3Mask);
}); });
#ifdef __OpenBSD__
vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT | RANDOMX_FLAG_SECURE, cache, nullptr);
#else
vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, nullptr); vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, nullptr);
#endif
auto test_a = [&] { auto test_a = [&] {
char hash[RANDOMX_HASH_SIZE]; char hash[RANDOMX_HASH_SIZE];
@ -1001,7 +1009,11 @@ int main() {
vm = nullptr; vm = nullptr;
cache = randomx_alloc_cache(RANDOMX_FLAG_JIT); cache = randomx_alloc_cache(RANDOMX_FLAG_JIT);
initCache("test key 000"); initCache("test key 000");
vm = randomx_create_vm(RANDOMX_FLAG_JIT, cache, nullptr); #ifdef __OpenBSD__
vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT | RANDOMX_FLAG_SECURE, cache, nullptr);
#else
vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, nullptr);
#endif
} }
runTest("Hash test 2a (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_a); runTest("Hash test 2a (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_a);
@ -1050,4 +1062,4 @@ int main() {
if (skipped) { if (skipped) {
std::cout << skipped << " tests were SKIPPED due to incompatible configuration (see above)" << std::endl; std::cout << skipped << " tests were SKIPPED due to incompatible configuration (see above)" << std::endl;
} }
} }

View File

@ -141,6 +141,8 @@ void* allocLargePagesMemory(std::size_t bytes) {
mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER, -1, 0); mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER, -1, 0);
#elif defined(__OpenBSD__)
mem = MAP_FAILED; // OpenBSD does not support huge pages
#else #else
mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1, 0); mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1, 0);
#endif #endif