//===------------------------ OrcRTBootstrap.cpp --------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "OrcRTBootstrap.h" #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h" #include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h" #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h" #include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h" #define DEBUG_TYPE "orc" using namespace llvm::orc::shared; namespace llvm { namespace orc { namespace rt_bootstrap { template static llvm::orc::shared::CWrapperFunctionResult writeUIntsWrapper(const char *ArgData, size_t ArgSize) { return WrapperFunction)>::handle( ArgData, ArgSize, [](std::vector Ws) { for (auto &W : Ws) *W.Addr.template toPtr() = W.Value; }) .release(); } static llvm::orc::shared::CWrapperFunctionResult writeBuffersWrapper(const char *ArgData, size_t ArgSize) { return WrapperFunction)>::handle( ArgData, ArgSize, [](std::vector Ws) { for (auto &W : Ws) memcpy(W.Addr.template toPtr(), W.Buffer.data(), W.Buffer.size()); }) .release(); } static llvm::orc::shared::CWrapperFunctionResult runAsMainWrapper(const char *ArgData, size_t ArgSize) { return WrapperFunction::handle( ArgData, ArgSize, [](ExecutorAddr MainAddr, std::vector Args) -> int64_t { return runAsMain(MainAddr.toPtr(), Args); }) .release(); } static llvm::orc::shared::CWrapperFunctionResult runAsVoidFunctionWrapper(const char *ArgData, size_t ArgSize) { return WrapperFunction::handle( ArgData, ArgSize, [](ExecutorAddr MainAddr) -> int32_t { return runAsVoidFunction(MainAddr.toPtr()); }) .release(); } static llvm::orc::shared::CWrapperFunctionResult runAsIntFunctionWrapper(const char *ArgData, size_t ArgSize) { return WrapperFunction::handle( ArgData, ArgSize, [](ExecutorAddr MainAddr, int32_t Arg) -> int32_t { return runAsIntFunction(MainAddr.toPtr(), Arg); }) .release(); } void addTo(StringMap &M) { M[rt::MemoryWriteUInt8sWrapperName] = ExecutorAddr::fromPtr( &writeUIntsWrapper); M[rt::MemoryWriteUInt16sWrapperName] = ExecutorAddr::fromPtr( &writeUIntsWrapper); M[rt::MemoryWriteUInt32sWrapperName] = ExecutorAddr::fromPtr( &writeUIntsWrapper); M[rt::MemoryWriteUInt64sWrapperName] = ExecutorAddr::fromPtr( &writeUIntsWrapper); M[rt::MemoryWriteBuffersWrapperName] = ExecutorAddr::fromPtr(&writeBuffersWrapper); M[rt::RegisterEHFrameSectionWrapperName] = ExecutorAddr::fromPtr(&llvm_orc_registerEHFrameSectionWrapper); M[rt::DeregisterEHFrameSectionWrapperName] = ExecutorAddr::fromPtr(&llvm_orc_deregisterEHFrameSectionWrapper); M[rt::RunAsMainWrapperName] = ExecutorAddr::fromPtr(&runAsMainWrapper); M[rt::RunAsVoidFunctionWrapperName] = ExecutorAddr::fromPtr(&runAsVoidFunctionWrapper); M[rt::RunAsIntFunctionWrapperName] = ExecutorAddr::fromPtr(&runAsIntFunctionWrapper); } } // end namespace rt_bootstrap } // end namespace orc } // end namespace llvm