JitCompilerX86: use mmap to allocate an executable buffer

compile as c++11
This commit is contained in:
tevador 2018-12-23 14:09:09 +01:00
parent 740c40b218
commit ca59925495
2 changed files with 6 additions and 16 deletions

View file

@ -1,7 +1,7 @@
#CXX=g++-8 #CXX=g++-8
#CC=gcc-8 #CC=gcc-8
PLATFORM=$(shell uname -i) PLATFORM=$(shell uname -i)
CXXFLAGS=-std=c++17 CXXFLAGS=-std=c++11
CCFLAGS= CCFLAGS=
ifeq ($(PLATFORM),x86_64) ifeq ($(PLATFORM),x86_64)
CXXFLAGS += -maes CXXFLAGS += -maes

View file

@ -24,12 +24,9 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#elif defined(__linux__)
#include <unistd.h>
#include <malloc.h>
#include <sys/mman.h>
#else #else
#error "Unsupported operating system" #include <sys/types.h>
#include <sys/mman.h>
#endif #endif
namespace RandomX { namespace RandomX {
@ -204,16 +201,9 @@ namespace RandomX {
if (code == nullptr) if (code == nullptr)
throw std::runtime_error("VirtualAlloc failed"); throw std::runtime_error("VirtualAlloc failed");
#else #else
auto pagesize = sysconf(_SC_PAGE_SIZE); code = (uint8_t*)mmap(nullptr, CodeSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (pagesize == -1) if (code == (uint8_t*)-1)
throw std::runtime_error("sysconf failed"); throw std::runtime_error("mmap failed");
code = (uint8_t*)memalign(pagesize, CodeSize);
if (code == nullptr)
throw std::runtime_error("memalign failed");
if (mprotect(code, CodeSize, PROT_READ | PROT_WRITE | PROT_EXEC) == -1)
throw std::runtime_error("mprotect failed");
#endif #endif
memcpy(code, prologue, sizeof(prologue)); memcpy(code, prologue, sizeof(prologue));
if (startOffsetAligned - sizeof(prologue) > 4) { if (startOffsetAligned - sizeof(prologue) > 4) {