Check for mmap call failure
This commit is contained in:
parent
4def0b096d
commit
687cf31063
1 changed files with 3 additions and 2 deletions
|
|
@ -1,4 +1,3 @@
|
|||
#include <memory>
|
||||
#include <pslang/jit/executable.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
|
@ -18,8 +17,10 @@ namespace pslang::jit
|
|||
blob make_host_executable(std::vector<std::uint8_t> const & code)
|
||||
{
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
auto size = code.size();
|
||||
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());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue