Path: blob/main/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.cpp
35323 views
//===------------------------ OrcRTBootstrap.cpp --------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "OrcRTBootstrap.h"910#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"11#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"12#include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"13#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"1415#define DEBUG_TYPE "orc"1617using namespace llvm::orc::shared;1819namespace llvm {20namespace orc {21namespace rt_bootstrap {2223template <typename WriteT, typename SPSWriteT>24static llvm::orc::shared::CWrapperFunctionResult25writeUIntsWrapper(const char *ArgData, size_t ArgSize) {26return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(27ArgData, ArgSize,28[](std::vector<WriteT> Ws) {29for (auto &W : Ws)30*W.Addr.template toPtr<decltype(W.Value) *>() = W.Value;31})32.release();33}3435static llvm::orc::shared::CWrapperFunctionResult36writeBuffersWrapper(const char *ArgData, size_t ArgSize) {37return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(38ArgData, ArgSize,39[](std::vector<tpctypes::BufferWrite> Ws) {40for (auto &W : Ws)41memcpy(W.Addr.template toPtr<char *>(), W.Buffer.data(),42W.Buffer.size());43})44.release();45}4647static llvm::orc::shared::CWrapperFunctionResult48runAsMainWrapper(const char *ArgData, size_t ArgSize) {49return WrapperFunction<rt::SPSRunAsMainSignature>::handle(50ArgData, ArgSize,51[](ExecutorAddr MainAddr,52std::vector<std::string> Args) -> int64_t {53return runAsMain(MainAddr.toPtr<int (*)(int, char *[])>(), Args);54})55.release();56}5758static llvm::orc::shared::CWrapperFunctionResult59runAsVoidFunctionWrapper(const char *ArgData, size_t ArgSize) {60return WrapperFunction<rt::SPSRunAsVoidFunctionSignature>::handle(61ArgData, ArgSize,62[](ExecutorAddr MainAddr) -> int32_t {63return runAsVoidFunction(MainAddr.toPtr<int32_t (*)(void)>());64})65.release();66}6768static llvm::orc::shared::CWrapperFunctionResult69runAsIntFunctionWrapper(const char *ArgData, size_t ArgSize) {70return WrapperFunction<rt::SPSRunAsIntFunctionSignature>::handle(71ArgData, ArgSize,72[](ExecutorAddr MainAddr, int32_t Arg) -> int32_t {73return runAsIntFunction(MainAddr.toPtr<int32_t (*)(int32_t)>(),74Arg);75})76.release();77}7879void addTo(StringMap<ExecutorAddr> &M) {80M[rt::MemoryWriteUInt8sWrapperName] = ExecutorAddr::fromPtr(81&writeUIntsWrapper<tpctypes::UInt8Write,82shared::SPSMemoryAccessUInt8Write>);83M[rt::MemoryWriteUInt16sWrapperName] = ExecutorAddr::fromPtr(84&writeUIntsWrapper<tpctypes::UInt16Write,85shared::SPSMemoryAccessUInt16Write>);86M[rt::MemoryWriteUInt32sWrapperName] = ExecutorAddr::fromPtr(87&writeUIntsWrapper<tpctypes::UInt32Write,88shared::SPSMemoryAccessUInt32Write>);89M[rt::MemoryWriteUInt64sWrapperName] = ExecutorAddr::fromPtr(90&writeUIntsWrapper<tpctypes::UInt64Write,91shared::SPSMemoryAccessUInt64Write>);92M[rt::MemoryWriteBuffersWrapperName] =93ExecutorAddr::fromPtr(&writeBuffersWrapper);94M[rt::RegisterEHFrameSectionWrapperName] =95ExecutorAddr::fromPtr(&llvm_orc_registerEHFrameSectionWrapper);96M[rt::DeregisterEHFrameSectionWrapperName] =97ExecutorAddr::fromPtr(&llvm_orc_deregisterEHFrameSectionWrapper);98M[rt::RunAsMainWrapperName] = ExecutorAddr::fromPtr(&runAsMainWrapper);99M[rt::RunAsVoidFunctionWrapperName] =100ExecutorAddr::fromPtr(&runAsVoidFunctionWrapper);101M[rt::RunAsIntFunctionWrapperName] =102ExecutorAddr::fromPtr(&runAsIntFunctionWrapper);103}104105} // end namespace rt_bootstrap106} // end namespace orc107} // end namespace llvm108109110