pslang/libs/jit/source/executable.cpp

32 lines
849 B
C++

#include <pslang/jit/executable.hpp>
#include <stdexcept>
#ifdef __linux__
#include <sys/mman.h>
#endif
namespace pslang::jit
{
compiled_module make_host_executable(compiled_module module)
{
#ifdef __linux__
if (module.abi != abi::itanium)
throw std::runtime_error("Abi mismatch");
auto ptr = (std::uint8_t *)mmap(nullptr, module.memory.size, PROT_READ | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
auto shared_ptr = std::shared_ptr<std::uint8_t>(ptr, [size = module.memory.size](std::uint8_t * ptr){ munmap(ptr, size); });
return compiled_module {
.memory = blob(shared_ptr, module.memory.size),
.symbol_table = std::move(module.symbol_table),
.entry_point = module.entry_point,
.abi = module.abi,
};
#else
throw std::runtime_error("Host-executable modules are not supported for this platform");
#endif
}
}