diff --git a/libs/jit/include/pslang/jit/abi.hpp b/libs/jit/include/pslang/jit/abi.hpp index 9f3c098..c55c3b6 100644 --- a/libs/jit/include/pslang/jit/abi.hpp +++ b/libs/jit/include/pslang/jit/abi.hpp @@ -7,7 +7,7 @@ namespace pslang::jit { itanium, msvc, - arm, + armv8, }; } diff --git a/libs/jit/include/pslang/jit/compiled_module.hpp b/libs/jit/include/pslang/jit/compiled_module.hpp index c0de14f..6f8ab6c 100644 --- a/libs/jit/include/pslang/jit/compiled_module.hpp +++ b/libs/jit/include/pslang/jit/compiled_module.hpp @@ -11,9 +11,15 @@ namespace pslang::jit struct compiled_module { - blob memory; - std::unordered_map symbol_table; - std::size_t entry_point; + struct segment + { + blob memory; + std::unordered_map symbol_table; + }; + + segment data; + segment code; + std::size_t entry_point; // in code segment jit::abi abi; }; diff --git a/libs/jit/source/executable.cpp b/libs/jit/source/executable.cpp index 50a29ae..911bb4d 100644 --- a/libs/jit/source/executable.cpp +++ b/libs/jit/source/executable.cpp @@ -6,24 +6,23 @@ #include #endif +#ifdef __APPLE__ +#include +#endif + namespace pslang::jit { compiled_module make_host_executable(compiled_module module) { -#ifdef __linux__ - if (module.abi != abi::itanium) +#if defined(__linux__) || defined(__APPLE__) + if (module.abi != abi::itanium && module.abi != abi::armv8) 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(ptr, [size = module.memory.size](std::uint8_t * ptr){ munmap(ptr, size); }); + // Assume the module code memory was obtained via mmap + mprotect(module.code.memory.data.get(), module.code.memory.size, PROT_READ | PROT_EXEC); - 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, - }; + return module; #else throw std::runtime_error("Host-executable modules are not supported for this platform"); #endif diff --git a/libs/jit/source/jit.cpp b/libs/jit/source/jit.cpp index 228feb0..5992cac 100644 --- a/libs/jit/source/jit.cpp +++ b/libs/jit/source/jit.cpp @@ -6,8 +6,8 @@ namespace pslang::jit compiled_module compile(ast::statement_list_ptr const & /* statements */, jit::abi abi) { return { - .memory = {}, - .symbol_table = {}, + .data = {}, + .code = {}, .entry_point = 0, .abi = abi, };