From d92c1a54dea9a10cf491a7a183a160f9b3a6d219 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 5 Mar 2019 01:07:01 +0700 Subject: [PATCH] Fixed macOS build. --- mac/memory_mac.c | 23 +++++++++++++++++++++-- unix/memory_unix.c | 4 ---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/mac/memory_mac.c b/mac/memory_mac.c index 3f5f714cb..949b0ea6a 100644 --- a/mac/memory_mac.c +++ b/mac/memory_mac.c @@ -4,8 +4,9 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2018-2019 SChernykh + * Copyright 2016-2019 XMRig , * * 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 @@ -74,3 +75,21 @@ void persistent_memory_free() { _mm_free(persistent_memory); } } + + +void *allocate_executable_memory(size_t size) +{ + return mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); +} + + +void protect_executable_memory(void *p, size_t size) +{ + mprotect(p, size, PROT_READ | PROT_EXEC); +} + + +void flush_instruction_cache(void *p, size_t size) +{ + __builtin___clear_cache((char*) p, (char*)(p) + size); +} diff --git a/unix/memory_unix.c b/unix/memory_unix.c index e6775add3..8954aebe8 100644 --- a/unix/memory_unix.c +++ b/unix/memory_unix.c @@ -78,11 +78,7 @@ void persistent_memory_free() { void *allocate_executable_memory(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 }