Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed tests on OpenBSD #142

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/randomx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ extern "C" {
randomx_flags randomx_get_flags() {
randomx_flags flags = RANDOMX_HAVE_COMPILER ? RANDOMX_FLAG_JIT : RANDOMX_FLAG_DEFAULT;
randomx::Cpu cpu;
#ifdef __OpenBSD__
if (flags == RANDOMX_FLAG_JIT) {
flags |= RANDOMX_FLAG_SECURE;
}
#endif
if (HAVE_AES && cpu.hasAes()) {
flags |= RANDOMX_FLAG_HARD_AES;
}
Expand Down
1 change: 1 addition & 0 deletions src/randomx.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ extern "C" {
* RANDOMX_FLAG_FULL_MEM
* RANDOMX_FLAG_SECURE
* 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);

Expand Down
2 changes: 1 addition & 1 deletion src/tests/affinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ set_thread_affinity(std::thread::native_handle_type thread,
(thread_policy_t)&policy, 1);
#elif defined(_WIN32) || defined(__CYGWIN__)
rc = SetThreadAffinityMask(reinterpret_cast<HANDLE>(thread), 1ULL << cpuid) == 0 ? -2 : 0;
#else
#elif !defined(__OpenBSD__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with this on OpenBSD?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, I missed your comment.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should actually be rewritten for OpenBSD: https://man.openbsd.org/NetBSD-7.0.1/affinity.3
Struct name is cpuset_t there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be mistaken but you are referring to a man page of NetBSD.
I can't find either one of these in the OpenBSD sources: cpu_set_t, cpuset_t, CPU_ZERO, CPU_SET.

I think there is no thread affinity for OpenBSD: https://man.openbsd.org/pthreads.3

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right and it seems to be a design decision for OpenBSD.

cpu_set_t cs;
CPU_ZERO(&cs);
CPU_SET(cpuid, &cs);
Expand Down
5 changes: 5 additions & 0 deletions src/tests/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ int main(int argc, char** argv) {
}
if (jit) {
flags |= RANDOMX_FLAG_JIT;
#ifdef __OpenBSD__
flags |= RANDOMX_FLAG_SECURE;
#endif
}
}

Expand All @@ -199,9 +202,11 @@ int main(int argc, char** argv) {
if (miningMode) {
flags |= RANDOMX_FLAG_FULL_MEM;
}
#ifndef __OpenBSD__
if (secure) {
flags |= RANDOMX_FLAG_SECURE;
}
#endif

if (flags & RANDOMX_FLAG_ARGON2_AVX2) {
std::cout << " - Argon2 implementation: AVX2" << std::endl;
Expand Down
16 changes: 14 additions & 2 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ int main() {
randomx::JitCompiler jit;
jit.generateSuperscalarHash(cache->programs, cache->reciprocalCache);
jit.generateDatasetInitCode();
#ifdef __OpenBSD__
jit.enableExecution();
#else
jit.enableAll();
#endif
uint64_t datasetItem[8];
jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 0, 1);
assert(datasetItem[0] == 0x680588a85ae222db);
Expand Down Expand Up @@ -950,7 +954,11 @@ int main() {
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);
#endif

auto test_a = [&] {
char hash[RANDOMX_HASH_SIZE];
Expand Down Expand Up @@ -1001,7 +1009,11 @@ int main() {
vm = nullptr;
cache = randomx_alloc_cache(RANDOMX_FLAG_JIT);
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);
Expand Down Expand Up @@ -1048,4 +1060,4 @@ int main() {
if (skipped) {
std::cout << skipped << " tests were SKIPPED due to incompatible configuration (see above)" << std::endl;
}
}
}