Check for mmap call failure

This commit is contained in:
Nikita Lisitsa 2026-01-11 15:47:57 +03:00
parent 4def0b096d
commit 687cf31063

View file

@ -1,4 +1,3 @@
#include <memory>
#include <pslang/jit/executable.hpp>
#include <stdexcept>
@ -20,6 +19,8 @@ namespace pslang::jit
#if defined(__linux__) || defined(__APPLE__)
auto size = code.size();
auto ptr = (std::uint8_t *)mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (ptr == MAP_FAILED)
throw std::system_error(errno, std::generic_category());
std::copy(code.begin(), code.end(), ptr);
if (mprotect(ptr, size, PROT_READ | PROT_EXEC) != 0)
throw std::system_error(errno, std::generic_category());