aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/CryptonightR_JIT.c
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-03-21 14:47:43 +0200
committerRiccardo Spagni <ric@spagni.net>2019-03-21 14:47:43 +0200
commit39107e18d5603046bbb301538986e5334547d42a (patch)
tree9851fa4affe668d24101b8b18c86d11be9153304 /src/crypto/CryptonightR_JIT.c
parentMerge pull request #5250 (diff)
parentcrypto: fix PaX issue on NetBSD with CNv4 JIT (diff)
downloadmonero-39107e18d5603046bbb301538986e5334547d42a.tar.xz
Merge pull request #5251
7632dede crypto: fix PaX issue on NetBSD with CNv4 JIT (moneromooo-monero) 89b1630e gtest: build fix for NetBSD (moneromooo-monero) fa43b547 tests: handle any cmake detected python interpreter (moneromooo-monero)
Diffstat (limited to 'src/crypto/CryptonightR_JIT.c')
-rw-r--r--src/crypto/CryptonightR_JIT.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/crypto/CryptonightR_JIT.c b/src/crypto/CryptonightR_JIT.c
index 68258a959..ee8f3f36f 100644
--- a/src/crypto/CryptonightR_JIT.c
+++ b/src/crypto/CryptonightR_JIT.c
@@ -4,6 +4,9 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+#include <sys/mman.h>
+#endif
#include "int-util.h"
#include "hash-ops.h"
@@ -58,6 +61,11 @@ int v4_generate_JIT_code(const struct V4_Instruction* code, v4_random_math_JIT_f
uint8_t* JIT_code = (uint8_t*) buf;
const uint8_t* JIT_code_end = JIT_code + buf_size;
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+ if (mprotect((void*)buf, buf_size, PROT_READ | PROT_WRITE))
+ return 1;
+#endif
+
APPEND_CODE(prologue, sizeof(prologue));
uint32_t prev_rot_src = 0xFFFFFFFFU;
@@ -101,6 +109,11 @@ int v4_generate_JIT_code(const struct V4_Instruction* code, v4_random_math_JIT_f
APPEND_CODE(epilogue, sizeof(epilogue));
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+ if (mprotect((void*)buf, buf_size, PROT_READ | PROT_EXEC))
+ return 1;
+#endif
+
__builtin___clear_cache((char*)buf, (char*)JIT_code);
return 0;