Răsfoiți Sursa

JitCompilerX86: use mmap to allocate an executable buffer
compile as c++11

tevador 7 ani în urmă
părinte
comite
ca59925495
2 a modificat fișierele cu 6 adăugiri și 16 ștergeri
  1. 1 1
      makefile
  2. 5 15
      src/JitCompilerX86.cpp

+ 1 - 1
makefile

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

+ 5 - 15
src/JitCompilerX86.cpp

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