MCPcopy Create free account
hub / github.com/LUX-Core/lux / allocMemoryPages

Function allocMemoryPages

src/crypto/RandomX/virtual_memory.cpp:90–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88#endif
89
90void* allocMemoryPages(std::size_t bytes) {
91 void* mem;
92#if defined(_WIN32) || defined(__CYGWIN__)
93 mem = VirtualAlloc(nullptr, bytes, MEM_COMMIT, PAGE_READWRITE);
94 if (mem == nullptr)
95 throw std::runtime_error(getErrorMessage("allocMemoryPages - VirtualAlloc"));
96#else
97 #if defined(__NetBSD__)
98 #define RESERVED_FLAGS PROT_MPROTECT(PROT_EXEC)
99 #else
100 #define RESERVED_FLAGS 0
101 #endif
102 mem = mmap(nullptr, bytes, PAGE_READWRITE | RESERVED_FLAGS, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
103 if (mem == MAP_FAILED)
104 throw std::runtime_error("allocMemoryPages - mmap failed");
105#endif
106 return mem;
107}
108
109static inline void pageProtect(void* ptr, std::size_t bytes, int rules) {
110#if defined(_WIN32) || defined(__CYGWIN__)

Callers 2

JitCompilerA64Method · 0.85
JitCompilerX86Method · 0.85

Calls 2

getErrorMessageFunction · 0.85
mmapFunction · 0.85

Tested by

no test coverage detected