mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 07:31:28 +00:00
[ORC] Add Shared/OrcRTBridge, and TargetProcess/OrcRTBootstrap.
This is a small first step towards reorganization of the ORC libraries: Declarations for types and function names (as strings) to be found in the "ORC runtime bootstrap" set are moved into OrcRTBridge.h / OrcRTBridge.cpp. The current implementation of the "ORC runtime bootstrap" functions is moved into OrcRTBootstrap.h and OrcRTBootstrap.cpp. It is likely that this code will eventually be moved into ORT-RT proper (in compiler RT). The immediate goal of this change is to make these bootstrap functions usable for clients other than SimpleRemoteEPC/SimpleRemoteEPCServer. The first planned client is a new RuntimeDyld::MemoryManager that will run over EPC, which will allow us to remove the old OrcRemoteTarget code.
This commit is contained in:
parent
42dace9c5b
commit
2c8e784915
46
llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
Normal file
46
llvm/include/llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h
Normal file
@ -0,0 +1,46 @@
|
||||
//===---- OrcRTBridge.h -- Utils for interacting with orc-rt ----*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Declares types and symbol names provided by the ORC runtime.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_ORCRTBRIDGE_H
|
||||
#define LLVM_EXECUTIONENGINE_ORC_SHARED_ORCRTBRIDGE_H
|
||||
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rt {
|
||||
|
||||
extern const char *MemoryReserveWrapperName;
|
||||
extern const char *MemoryFinalizeWrapperName;
|
||||
extern const char *MemoryDeallocateWrapperName;
|
||||
extern const char *MemoryWriteUInt8sWrapperName;
|
||||
extern const char *MemoryWriteUInt16sWrapperName;
|
||||
extern const char *MemoryWriteUInt32sWrapperName;
|
||||
extern const char *MemoryWriteUInt64sWrapperName;
|
||||
extern const char *MemoryWriteBuffersWrapperName;
|
||||
extern const char *RunAsMainWrapperName;
|
||||
|
||||
using SPSMemoryReserveSignature =
|
||||
shared::SPSExpected<shared::SPSExecutorAddress>(uint64_t);
|
||||
using SPSMemoryFinalizeSignature = shared::SPSError(shared::SPSFinalizeRequest);
|
||||
using SPSMemoryDeallocateSignature =
|
||||
shared::SPSError(shared::SPSExecutorAddress, uint64_t);
|
||||
using SPSRunAsMainSignature = int64_t(shared::SPSExecutorAddress,
|
||||
shared::SPSSequence<shared::SPSString>);
|
||||
|
||||
} // end namespace rt
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_ORCRTBRIDGE_H
|
@ -211,9 +211,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
using SPSRunAsMainSignature = int64_t(SPSExecutorAddress,
|
||||
SPSSequence<SPSString>);
|
||||
|
||||
using SPSLoadDylibSignature =
|
||||
SPSExpected<SPSExecutorAddress>(SPSExecutorAddress, SPSString, uint64_t);
|
||||
|
||||
|
@ -222,9 +222,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
using SPSOrcTargetProcessAllocate = SPSExpected<SPSExecutorAddress>(uint64_t);
|
||||
using SPSOrcTargetProcessFinalize = SPSError(SPSFinalizeRequest);
|
||||
using SPSOrcTargetProcessDeallocate = SPSError(SPSExecutorAddress, uint64_t);
|
||||
|
||||
} // end namespace shared
|
||||
} // end namespace orc
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/LookupAndRecordAddrs.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
@ -58,7 +59,7 @@ public:
|
||||
{WorkingMem, static_cast<size_t>(KV.second.ContentSize)}});
|
||||
WorkingMem += KV.second.ContentSize;
|
||||
}
|
||||
Parent.EPC.callSPSWrapperAsync<shared::SPSOrcTargetProcessFinalize>(
|
||||
Parent.EPC.callSPSWrapperAsync<rt::SPSMemoryFinalizeSignature>(
|
||||
[OnFinalize = std::move(OnFinalize)](Error SerializationErr,
|
||||
Error FinalizeErr) {
|
||||
if (SerializationErr)
|
||||
@ -71,9 +72,8 @@ public:
|
||||
|
||||
Error deallocate() override {
|
||||
Error Err = Error::success();
|
||||
if (auto E2 =
|
||||
Parent.EPC.callSPSWrapper<shared::SPSOrcTargetProcessDeallocate>(
|
||||
Parent.FAs.Deallocate.getValue(), Err, TargetAddr, TargetSize))
|
||||
if (auto E2 = Parent.EPC.callSPSWrapper<rt::SPSMemoryDeallocateSignature>(
|
||||
Parent.FAs.Deallocate.getValue(), Err, TargetAddr, TargetSize))
|
||||
return E2;
|
||||
return Err;
|
||||
}
|
||||
@ -111,7 +111,7 @@ EPCGenericJITLinkMemoryManager::allocate(const jitlink::JITLinkDylib *JD,
|
||||
if (WorkingSize > 0)
|
||||
WorkingBuffer = std::make_unique<char[]>(WorkingSize);
|
||||
Expected<ExecutorAddress> TargetAllocAddr((ExecutorAddress()));
|
||||
if (auto Err = EPC.callSPSWrapper<shared::SPSOrcTargetProcessAllocate>(
|
||||
if (auto Err = EPC.callSPSWrapper<rt::SPSMemoryReserveSignature>(
|
||||
FAs.Reserve.getValue(), TargetAllocAddr, AllocSize))
|
||||
return std::move(Err);
|
||||
if (!TargetAllocAddr)
|
||||
|
@ -1,5 +1,6 @@
|
||||
add_llvm_component_library(LLVMOrcShared
|
||||
OrcError.cpp
|
||||
OrcRTBridge.cpp
|
||||
RPCError.cpp
|
||||
SimpleRemoteEPCUtils.cpp
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
|
35
llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp
Normal file
35
llvm/lib/ExecutionEngine/Orc/Shared/OrcRTBridge.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
//===------ OrcRTBridge.cpp - Executor functions for bootstrap -----===//
|
||||
//
|
||||
// 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 "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rt {
|
||||
|
||||
const char *MemoryReserveWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_reserve_wrapper";
|
||||
const char *MemoryFinalizeWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_finalize_wrapper";
|
||||
const char *MemoryDeallocateWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_deallocate_wrapper";
|
||||
const char *MemoryWriteUInt8sWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_write_uint8s_wrapper";
|
||||
const char *MemoryWriteUInt16sWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_write_uint16s_wrapper";
|
||||
const char *MemoryWriteUInt32sWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_write_uint32s_wrapper";
|
||||
const char *MemoryWriteUInt64sWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_write_uint64s_wrapper";
|
||||
const char *MemoryWriteBuffersWrapperName =
|
||||
"__llvm_orc_bootstrap_mem_write_buffers_wrapper";
|
||||
const char *RunAsMainWrapperName = "__llvm_orc_bootstrap_run_as_main_wrapper";
|
||||
|
||||
} // end namespace rt
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
@ -9,6 +9,7 @@
|
||||
#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericMemoryAccess.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
@ -89,7 +90,7 @@ SimpleRemoteEPC::lookupSymbols(ArrayRef<LookupRequest> Request) {
|
||||
Expected<int32_t> SimpleRemoteEPC::runAsMain(JITTargetAddress MainFnAddr,
|
||||
ArrayRef<std::string> Args) {
|
||||
int64_t Result = 0;
|
||||
if (auto Err = callSPSWrapper<shared::SPSRunAsMainSignature>(
|
||||
if (auto Err = callSPSWrapper<rt::SPSRunAsMainSignature>(
|
||||
RunAsMainAddr.getValue(), Result, ExecutorAddress(MainFnAddr), Args))
|
||||
return std::move(Err);
|
||||
return Result;
|
||||
@ -171,9 +172,9 @@ Expected<std::unique_ptr<jitlink::JITLinkMemoryManager>>
|
||||
SimpleRemoteEPC::createMemoryManager() {
|
||||
EPCGenericJITLinkMemoryManager::FuncAddrs FAs;
|
||||
if (auto Err = getBootstrapSymbols(
|
||||
{{FAs.Reserve, "__llvm_orc_memory_reserve"},
|
||||
{FAs.Finalize, "__llvm_orc_memory_finalize"},
|
||||
{FAs.Deallocate, "__llvm_orc_memory_deallocate"}}))
|
||||
{{FAs.Reserve, rt::MemoryReserveWrapperName},
|
||||
{FAs.Finalize, rt::MemoryFinalizeWrapperName},
|
||||
{FAs.Deallocate, rt::MemoryDeallocateWrapperName}}))
|
||||
return std::move(Err);
|
||||
|
||||
return std::make_unique<EPCGenericJITLinkMemoryManager>(*this, FAs);
|
||||
@ -252,7 +253,7 @@ Error SimpleRemoteEPC::setup(std::unique_ptr<SimpleRemoteEPCTransport> T,
|
||||
{JDI.JITDispatchFunctionAddress, DispatchFnName},
|
||||
{LoadDylibAddr, "__llvm_orc_load_dylib"},
|
||||
{LookupSymbolsAddr, "__llvm_orc_lookup_symbols"},
|
||||
{RunAsMainAddr, "__llvm_orc_run_as_main"}}))
|
||||
{RunAsMainAddr, rt::RunAsMainWrapperName}}))
|
||||
return Err;
|
||||
|
||||
if (auto MemMgr = createMemoryManager()) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
add_llvm_component_library(LLVMOrcTargetProcess
|
||||
JITLoaderGDB.cpp
|
||||
OrcRTBootstrap.cpp
|
||||
RegisterEHFrames.cpp
|
||||
SimpleRemoteEPCServer.cpp
|
||||
TargetExecutionUtils.cpp
|
||||
|
134
llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.cpp
Normal file
134
llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
//===------------------------ 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/TargetExecutionUtils.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
|
||||
using namespace llvm::orc::shared;
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rt_bootstrap {
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
reserveWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<rt::SPSMemoryReserveSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](uint64_t Size) -> Expected<ExecutorAddress> {
|
||||
std::error_code EC;
|
||||
auto MB = sys::Memory::allocateMappedMemory(
|
||||
Size, 0, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
|
||||
if (EC)
|
||||
return errorCodeToError(EC);
|
||||
return ExecutorAddress::fromPtr(MB.base());
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
finalizeWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<rt::SPSMemoryFinalizeSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](const tpctypes::FinalizeRequest &FR) -> Error {
|
||||
for (auto &Seg : FR) {
|
||||
char *Mem = Seg.Addr.toPtr<char *>();
|
||||
memcpy(Mem, Seg.Content.data(), Seg.Content.size());
|
||||
memset(Mem + Seg.Content.size(), 0,
|
||||
Seg.Size - Seg.Content.size());
|
||||
assert(Seg.Size <= std::numeric_limits<size_t>::max());
|
||||
if (auto EC = sys::Memory::protectMappedMemory(
|
||||
{Mem, static_cast<size_t>(Seg.Size)},
|
||||
tpctypes::fromWireProtectionFlags(Seg.Prot)))
|
||||
return errorCodeToError(EC);
|
||||
if (Seg.Prot & tpctypes::WPF_Exec)
|
||||
sys::Memory::InvalidateInstructionCache(Mem, Seg.Size);
|
||||
}
|
||||
return Error::success();
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
deallocateWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<rt::SPSMemoryDeallocateSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](ExecutorAddress Base, uint64_t Size) -> Error {
|
||||
sys::MemoryBlock MB(Base.toPtr<void *>(), Size);
|
||||
if (auto EC = sys::Memory::releaseMappedMemory(MB))
|
||||
return errorCodeToError(EC);
|
||||
return Error::success();
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
template <typename WriteT, typename SPSWriteT>
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](std::vector<WriteT> Ws) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<decltype(W.Value) *>(W.Address) =
|
||||
W.Value;
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](std::vector<tpctypes::BufferWrite> Ws) {
|
||||
for (auto &W : Ws)
|
||||
memcpy(jitTargetAddressToPointer<char *>(W.Address),
|
||||
W.Buffer.data(), W.Buffer.size());
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
runAsMainWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<rt::SPSRunAsMainSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](ExecutorAddress MainAddr,
|
||||
std::vector<std::string> Args) -> int64_t {
|
||||
return runAsMain(MainAddr.toPtr<int (*)(int, char *[])>(), Args);
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
void addTo(StringMap<ExecutorAddress> &M) {
|
||||
M[rt::MemoryReserveWrapperName] = ExecutorAddress::fromPtr(&reserveWrapper);
|
||||
M[rt::MemoryFinalizeWrapperName] = ExecutorAddress::fromPtr(&finalizeWrapper);
|
||||
M[rt::MemoryDeallocateWrapperName] =
|
||||
ExecutorAddress::fromPtr(&deallocateWrapper);
|
||||
M[rt::MemoryWriteUInt8sWrapperName] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt8Write,
|
||||
shared::SPSMemoryAccessUInt8Write>);
|
||||
M[rt::MemoryWriteUInt16sWrapperName] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt16Write,
|
||||
shared::SPSMemoryAccessUInt16Write>);
|
||||
M[rt::MemoryWriteUInt32sWrapperName] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt32Write,
|
||||
shared::SPSMemoryAccessUInt32Write>);
|
||||
M[rt::MemoryWriteUInt64sWrapperName] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt64Write,
|
||||
shared::SPSMemoryAccessUInt64Write>);
|
||||
M[rt::MemoryWriteBuffersWrapperName] =
|
||||
ExecutorAddress::fromPtr(&writeBuffersWrapper);
|
||||
M[rt::RunAsMainWrapperName] = ExecutorAddress::fromPtr(&runAsMainWrapper);
|
||||
}
|
||||
|
||||
} // end namespace rt_bootstrap
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
36
llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.h
Normal file
36
llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.h
Normal file
@ -0,0 +1,36 @@
|
||||
//===----------------------- OrcRTBootstrap.h -------------------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// OrcRTPrelinkImpl provides functions that should be linked into the executor
|
||||
// to bootstrap common JIT functionality (e.g. memory allocation and memory
|
||||
// access).
|
||||
//
|
||||
// Call rt_impl::addTo to add these functions to a bootstrap symbols map.
|
||||
//
|
||||
// FIXME: The functionality in this file should probably be moved to an ORC
|
||||
// runtime bootstrap library in compiler-rt.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LIB_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRTBOOTSTRAP_H
|
||||
#define LIB_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRTBOOTSTRAP_H
|
||||
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
namespace rt_bootstrap {
|
||||
|
||||
void addTo(StringMap<ExecutorAddress> &M);
|
||||
|
||||
} // namespace rt_bootstrap
|
||||
} // end namespace orc
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_ORCRTBOOTSTRAP_H
|
@ -9,11 +9,12 @@
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/SimpleRemoteEPCServer.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
#include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
|
||||
#include "llvm/Support/FormatVariadic.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
|
||||
#include "OrcRTBootstrap.h"
|
||||
|
||||
#define DEBUG_TYPE "orc"
|
||||
|
||||
using namespace llvm::orc::shared;
|
||||
@ -21,93 +22,6 @@ using namespace llvm::orc::shared;
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
reserveWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSOrcTargetProcessAllocate>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](uint64_t Size) -> Expected<ExecutorAddress> {
|
||||
std::error_code EC;
|
||||
auto MB = sys::Memory::allocateMappedMemory(
|
||||
Size, 0, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC);
|
||||
if (EC)
|
||||
return errorCodeToError(EC);
|
||||
return ExecutorAddress::fromPtr(MB.base());
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
finalizeWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSOrcTargetProcessFinalize>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](const tpctypes::FinalizeRequest &FR) -> Error {
|
||||
for (auto &Seg : FR) {
|
||||
char *Mem = Seg.Addr.toPtr<char *>();
|
||||
memcpy(Mem, Seg.Content.data(), Seg.Content.size());
|
||||
memset(Mem + Seg.Content.size(), 0,
|
||||
Seg.Size - Seg.Content.size());
|
||||
assert(Seg.Size <= std::numeric_limits<size_t>::max());
|
||||
if (auto EC = sys::Memory::protectMappedMemory(
|
||||
{Mem, static_cast<size_t>(Seg.Size)},
|
||||
tpctypes::fromWireProtectionFlags(Seg.Prot)))
|
||||
return errorCodeToError(EC);
|
||||
if (Seg.Prot & tpctypes::WPF_Exec)
|
||||
sys::Memory::InvalidateInstructionCache(Mem, Seg.Size);
|
||||
}
|
||||
return Error::success();
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
deallocateWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSOrcTargetProcessDeallocate>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](ExecutorAddress Base, uint64_t Size) -> Error {
|
||||
sys::MemoryBlock MB(Base.toPtr<void *>(), Size);
|
||||
if (auto EC = sys::Memory::releaseMappedMemory(MB))
|
||||
return errorCodeToError(EC);
|
||||
return Error::success();
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
template <typename WriteT, typename SPSWriteT>
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](std::vector<WriteT> Ws) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<decltype(W.Value) *>(W.Address) =
|
||||
W.Value;
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](std::vector<tpctypes::BufferWrite> Ws) {
|
||||
for (auto &W : Ws)
|
||||
memcpy(jitTargetAddressToPointer<char *>(W.Address),
|
||||
W.Buffer.data(), W.Buffer.size());
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
static llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
runAsMainWrapper(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSRunAsMainSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](ExecutorAddress MainAddr,
|
||||
std::vector<std::string> Args) -> int64_t {
|
||||
return runAsMain(MainAddr.toPtr<int (*)(int, char *[])>(), Args);
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
||||
SimpleRemoteEPCServer::Dispatcher::~Dispatcher() {}
|
||||
|
||||
#if LLVM_ENABLE_THREADS
|
||||
@ -137,27 +51,7 @@ void SimpleRemoteEPCServer::ThreadDispatcher::shutdown() {
|
||||
|
||||
StringMap<ExecutorAddress> SimpleRemoteEPCServer::defaultBootstrapSymbols() {
|
||||
StringMap<ExecutorAddress> DBS;
|
||||
|
||||
DBS["__llvm_orc_memory_reserve"] = ExecutorAddress::fromPtr(&reserveWrapper);
|
||||
DBS["__llvm_orc_memory_finalize"] =
|
||||
ExecutorAddress::fromPtr(&finalizeWrapper);
|
||||
DBS["__llvm_orc_memory_deallocate"] =
|
||||
ExecutorAddress::fromPtr(&deallocateWrapper);
|
||||
DBS["__llvm_orc_memory_write_uint8s"] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt8Write,
|
||||
shared::SPSMemoryAccessUInt8Write>);
|
||||
DBS["__llvm_orc_memory_write_uint16s"] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt16Write,
|
||||
shared::SPSMemoryAccessUInt16Write>);
|
||||
DBS["__llvm_orc_memory_write_uint32s"] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt32Write,
|
||||
shared::SPSMemoryAccessUInt32Write>);
|
||||
DBS["__llvm_orc_memory_write_uint64s"] = ExecutorAddress::fromPtr(
|
||||
&writeUIntsWrapper<tpctypes::UInt64Write,
|
||||
shared::SPSMemoryAccessUInt64Write>);
|
||||
DBS["__llvm_orc_memory_write_buffers"] =
|
||||
ExecutorAddress::fromPtr(&writeBuffersWrapper);
|
||||
DBS["__llvm_orc_run_as_main"] = ExecutorAddress::fromPtr(&runAsMainWrapper);
|
||||
rt_bootstrap::addTo(DBS);
|
||||
DBS["__llvm_orc_load_dylib"] = ExecutorAddress::fromPtr(&loadDylibWrapper);
|
||||
DBS["__llvm_orc_lookup_symbols"] =
|
||||
ExecutorAddress::fromPtr(&lookupSymbolsWrapper);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "OrcTestCommon.h"
|
||||
|
||||
#include "llvm/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManager.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
||||
#include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
|
||||
#include "llvm/Support/Memory.h"
|
||||
#include "llvm/Testing/Support/Error.h"
|
||||
@ -23,7 +24,7 @@ namespace {
|
||||
|
||||
llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
testReserve(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSOrcTargetProcessAllocate>::handle(
|
||||
return WrapperFunction<rt::SPSMemoryReserveSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](uint64_t Size) -> Expected<ExecutorAddress> {
|
||||
std::error_code EC;
|
||||
@ -38,7 +39,7 @@ testReserve(const char *ArgData, size_t ArgSize) {
|
||||
|
||||
llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
testFinalize(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSOrcTargetProcessFinalize>::handle(
|
||||
return WrapperFunction<rt::SPSMemoryFinalizeSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](const tpctypes::FinalizeRequest &FR) -> Error {
|
||||
for (auto &Seg : FR) {
|
||||
@ -61,7 +62,7 @@ testFinalize(const char *ArgData, size_t ArgSize) {
|
||||
|
||||
llvm::orc::shared::detail::CWrapperFunctionResult
|
||||
testDeallocate(const char *ArgData, size_t ArgSize) {
|
||||
return WrapperFunction<SPSOrcTargetProcessDeallocate>::handle(
|
||||
return WrapperFunction<rt::SPSMemoryDeallocateSignature>::handle(
|
||||
ArgData, ArgSize,
|
||||
[](ExecutorAddress Base, uint64_t Size) -> Error {
|
||||
sys::MemoryBlock MB(Base.toPtr<void *>(), Size);
|
||||
|
Loading…
Reference in New Issue
Block a user