forked from OSchip/llvm-project
[ORC] Change SPSExecutorAddr serialization, SupportFunctionCall struct.
SPSExecutorAddr will now be serializable to/from ExecutorAddr, rather than uint64_t. This improves type safety when working with serialized addresses. Also updates the SupportFunctionCall to use an ExecutorAddrRange (rather than a separate ExecutorAddr addr and uint64_t size field), and updates the tpctypes::*Write data structures to use ExecutorAddr rather than JITTargetAddress.
This commit is contained in:
parent
ef922c692f
commit
e32b1eee6a
|
@ -160,6 +160,8 @@ struct ExecutorAddrRange {
|
|||
|
||||
namespace shared {
|
||||
|
||||
class SPSExecutorAddr {};
|
||||
|
||||
/// SPS serializatior for ExecutorAddr.
|
||||
template <> class SPSSerializationTraits<SPSExecutorAddr, ExecutorAddr> {
|
||||
public:
|
||||
|
|
|
@ -195,13 +195,6 @@ template <typename SPSElementTagT> class SPSSequence;
|
|||
/// SPS tag type for strings, which are equivalent to sequences of chars.
|
||||
using SPSString = SPSSequence<char>;
|
||||
|
||||
/// SPS tag type for executor addresseses.
|
||||
class SPSExecutorAddr {};
|
||||
|
||||
template <>
|
||||
class SPSSerializationTraits<SPSExecutorAddr, uint64_t>
|
||||
: public SPSSerializationTraits<uint64_t, uint64_t> {};
|
||||
|
||||
/// SPS tag type for maps.
|
||||
///
|
||||
/// SPS maps are just sequences of (Key, Value) tuples.
|
||||
|
|
|
@ -73,12 +73,19 @@ struct SupportFunctionCall {
|
|||
using FnTy = shared::detail::CWrapperFunctionResult(const char *ArgData,
|
||||
size_t ArgSize);
|
||||
ExecutorAddr Func;
|
||||
ExecutorAddr ArgData;
|
||||
uint64_t ArgSize;
|
||||
ExecutorAddrRange ArgDataRange;
|
||||
|
||||
SupportFunctionCall() = default;
|
||||
SupportFunctionCall(ExecutorAddr Func, ExecutorAddr ArgData,
|
||||
ExecutorAddrDiff ArgSize)
|
||||
: Func(Func), ArgDataRange(ArgData, ArgSize) {}
|
||||
SupportFunctionCall(ExecutorAddr Func, ExecutorAddrRange ArgDataRange)
|
||||
: Func(Func), ArgDataRange(ArgDataRange) {}
|
||||
|
||||
Error run() {
|
||||
shared::WrapperFunctionResult WFR(
|
||||
Func.toPtr<FnTy *>()(ArgData.toPtr<const char *>(), ArgSize));
|
||||
shared::WrapperFunctionResult WFR(Func.toPtr<FnTy *>()(
|
||||
ArgDataRange.Start.toPtr<const char *>(),
|
||||
static_cast<size_t>(ArgDataRange.size().getValue())));
|
||||
if (const char *ErrMsg = WFR.getOutOfBandError())
|
||||
return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
|
||||
if (!WFR.empty())
|
||||
|
@ -108,10 +115,9 @@ struct FinalizeRequest {
|
|||
|
||||
template <typename T> struct UIntWrite {
|
||||
UIntWrite() = default;
|
||||
UIntWrite(JITTargetAddress Address, T Value)
|
||||
: Address(Address), Value(Value) {}
|
||||
UIntWrite(ExecutorAddr Addr, T Value) : Addr(Addr), Value(Value) {}
|
||||
|
||||
JITTargetAddress Address = 0;
|
||||
ExecutorAddr Addr;
|
||||
T Value = 0;
|
||||
};
|
||||
|
||||
|
@ -131,10 +137,10 @@ using UInt64Write = UIntWrite<uint64_t>;
|
|||
/// For use with TargetProcessControl::MemoryAccess objects.
|
||||
struct BufferWrite {
|
||||
BufferWrite() = default;
|
||||
BufferWrite(JITTargetAddress Address, StringRef Buffer)
|
||||
: Address(Address), Buffer(Buffer) {}
|
||||
BufferWrite(ExecutorAddr Addr, StringRef Buffer)
|
||||
: Addr(Addr), Buffer(Buffer) {}
|
||||
|
||||
JITTargetAddress Address = 0;
|
||||
ExecutorAddr Addr;
|
||||
StringRef Buffer;
|
||||
};
|
||||
|
||||
|
@ -149,8 +155,7 @@ namespace shared {
|
|||
|
||||
class SPSMemoryProtectionFlags {};
|
||||
|
||||
using SPSSupportFunctionCall =
|
||||
SPSTuple<SPSExecutorAddr, SPSExecutorAddr, uint64_t>;
|
||||
using SPSSupportFunctionCall = SPSTuple<SPSExecutorAddr, SPSExecutorAddrRange>;
|
||||
|
||||
using SPSSegFinalizeRequest =
|
||||
SPSTuple<SPSMemoryProtectionFlags, SPSExecutorAddr, uint64_t,
|
||||
|
@ -202,17 +207,17 @@ class SPSSerializationTraits<SPSSupportFunctionCall,
|
|||
|
||||
public:
|
||||
static size_t size(const tpctypes::SupportFunctionCall &SFC) {
|
||||
return AL::size(SFC.Func, SFC.ArgData, SFC.ArgSize);
|
||||
return AL::size(SFC.Func, SFC.ArgDataRange);
|
||||
}
|
||||
|
||||
static bool serialize(SPSOutputBuffer &OB,
|
||||
const tpctypes::SupportFunctionCall &SFC) {
|
||||
return AL::serialize(OB, SFC.Func, SFC.ArgData, SFC.ArgSize);
|
||||
return AL::serialize(OB, SFC.Func, SFC.ArgDataRange);
|
||||
}
|
||||
|
||||
static bool deserialize(SPSInputBuffer &IB,
|
||||
tpctypes::SupportFunctionCall &SFC) {
|
||||
return AL::deserialize(IB, SFC.Func, SFC.ArgData, SFC.ArgSize);
|
||||
return AL::deserialize(IB, SFC.Func, SFC.ArgDataRange);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -282,16 +287,16 @@ class SPSSerializationTraits<SPSMemoryAccessUIntWrite<T>,
|
|||
tpctypes::UIntWrite<T>> {
|
||||
public:
|
||||
static size_t size(const tpctypes::UIntWrite<T> &W) {
|
||||
return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Address, W.Value);
|
||||
return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Addr, W.Value);
|
||||
}
|
||||
|
||||
static bool serialize(SPSOutputBuffer &OB, const tpctypes::UIntWrite<T> &W) {
|
||||
return SPSTuple<SPSExecutorAddr, T>::AsArgList::serialize(OB, W.Address,
|
||||
return SPSTuple<SPSExecutorAddr, T>::AsArgList::serialize(OB, W.Addr,
|
||||
W.Value);
|
||||
}
|
||||
|
||||
static bool deserialize(SPSInputBuffer &IB, tpctypes::UIntWrite<T> &W) {
|
||||
return SPSTuple<SPSExecutorAddr, T>::AsArgList::deserialize(IB, W.Address,
|
||||
return SPSTuple<SPSExecutorAddr, T>::AsArgList::deserialize(IB, W.Addr,
|
||||
W.Value);
|
||||
}
|
||||
};
|
||||
|
@ -302,17 +307,17 @@ class SPSSerializationTraits<SPSMemoryAccessBufferWrite,
|
|||
public:
|
||||
static size_t size(const tpctypes::BufferWrite &W) {
|
||||
return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList::size(
|
||||
W.Address, W.Buffer);
|
||||
W.Addr, W.Buffer);
|
||||
}
|
||||
|
||||
static bool serialize(SPSOutputBuffer &OB, const tpctypes::BufferWrite &W) {
|
||||
return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
|
||||
OB, W.Address, W.Buffer);
|
||||
OB, W.Addr, W.Buffer);
|
||||
}
|
||||
|
||||
static bool deserialize(SPSInputBuffer &IB, tpctypes::BufferWrite &W) {
|
||||
return SPSTuple<SPSExecutorAddr,
|
||||
SPSSequence<char>>::AsArgList ::deserialize(IB, W.Address,
|
||||
SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
|
||||
W.Buffer);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -59,14 +59,14 @@ EPCEHFrameRegistrar::Create(ExecutionSession &ES) {
|
|||
Error EPCEHFrameRegistrar::registerEHFrames(JITTargetAddress EHFrameSectionAddr,
|
||||
size_t EHFrameSectionSize) {
|
||||
return ES.callSPSWrapper<void(SPSExecutorAddr, uint64_t)>(
|
||||
RegisterEHFrameWrapperFnAddr, EHFrameSectionAddr,
|
||||
RegisterEHFrameWrapperFnAddr, ExecutorAddr(EHFrameSectionAddr),
|
||||
static_cast<uint64_t>(EHFrameSectionSize));
|
||||
}
|
||||
|
||||
Error EPCEHFrameRegistrar::deregisterEHFrames(
|
||||
JITTargetAddress EHFrameSectionAddr, size_t EHFrameSectionSize) {
|
||||
return ES.callSPSWrapper<void(SPSExecutorAddr, uint64_t)>(
|
||||
DeregisterEHFrameWrapperFnAddr, EHFrameSectionAddr,
|
||||
DeregisterEHFrameWrapperFnAddr, ExecutorAddr(EHFrameSectionAddr),
|
||||
static_cast<uint64_t>(EHFrameSectionSize));
|
||||
}
|
||||
|
||||
|
|
|
@ -60,11 +60,12 @@ public:
|
|||
// turn this into a std::swap.
|
||||
FR.Actions.reserve(G.allocActions().size());
|
||||
for (auto &ActPair : G.allocActions())
|
||||
FR.Actions.push_back(
|
||||
{{ExecutorAddr(ActPair.Finalize.FnAddr),
|
||||
ExecutorAddr(ActPair.Finalize.CtxAddr), ActPair.Finalize.CtxSize},
|
||||
{ExecutorAddr(ActPair.Dealloc.FnAddr),
|
||||
ExecutorAddr(ActPair.Dealloc.CtxAddr), ActPair.Dealloc.CtxSize}});
|
||||
FR.Actions.push_back({{ExecutorAddr(ActPair.Finalize.FnAddr),
|
||||
{ExecutorAddr(ActPair.Finalize.CtxAddr),
|
||||
ExecutorAddrDiff(ActPair.Finalize.CtxSize)}},
|
||||
{ExecutorAddr(ActPair.Dealloc.FnAddr),
|
||||
{ExecutorAddr(ActPair.Dealloc.CtxAddr),
|
||||
ExecutorAddrDiff(ActPair.Dealloc.CtxSize)}}});
|
||||
G.allocActions().clear();
|
||||
|
||||
Parent.EPC.callSPSWrapperAsync<
|
||||
|
|
|
@ -262,8 +262,11 @@ bool EPCGenericRTDyldMemoryManager::finalizeMemory(std::string *ErrMsg) {
|
|||
}
|
||||
|
||||
for (auto &Frame : ObjAllocs.UnfinalizedEHFrames)
|
||||
FR.Actions.push_back({{SAs.RegisterEHFrame, Frame.Addr, Frame.Size},
|
||||
{SAs.DeregisterEHFrame, Frame.Addr, Frame.Size}});
|
||||
FR.Actions.push_back(
|
||||
{{SAs.RegisterEHFrame,
|
||||
{ExecutorAddr(Frame.Addr), ExecutorAddrDiff(Frame.Size)}},
|
||||
{SAs.DeregisterEHFrame,
|
||||
{ExecutorAddr(Frame.Addr), ExecutorAddrDiff(Frame.Size)}}});
|
||||
|
||||
// We'll also need to make an extra allocation for the eh-frame wrapper call
|
||||
// arguments.
|
||||
|
|
|
@ -161,16 +161,18 @@ Error EPCIndirectStubsManager::createStubs(const StubInitsMap &StubInits) {
|
|||
unsigned ASIdx = 0;
|
||||
std::vector<tpctypes::UInt32Write> PtrUpdates;
|
||||
for (auto &SI : StubInits)
|
||||
PtrUpdates.push_back({(*AvailableStubInfos)[ASIdx++].PointerAddress,
|
||||
static_cast<uint32_t>(SI.second.first)});
|
||||
PtrUpdates.push_back(
|
||||
{ExecutorAddr((*AvailableStubInfos)[ASIdx++].PointerAddress),
|
||||
static_cast<uint32_t>(SI.second.first)});
|
||||
return MemAccess.writeUInt32s(PtrUpdates);
|
||||
}
|
||||
case 8: {
|
||||
unsigned ASIdx = 0;
|
||||
std::vector<tpctypes::UInt64Write> PtrUpdates;
|
||||
for (auto &SI : StubInits)
|
||||
PtrUpdates.push_back({(*AvailableStubInfos)[ASIdx++].PointerAddress,
|
||||
static_cast<uint64_t>(SI.second.first)});
|
||||
PtrUpdates.push_back(
|
||||
{ExecutorAddr((*AvailableStubInfos)[ASIdx++].PointerAddress),
|
||||
static_cast<uint64_t>(SI.second.first)});
|
||||
return MemAccess.writeUInt64s(PtrUpdates);
|
||||
}
|
||||
default:
|
||||
|
@ -212,11 +214,11 @@ Error EPCIndirectStubsManager::updatePointer(StringRef Name,
|
|||
auto &MemAccess = EPCIU.getExecutorProcessControl().getMemoryAccess();
|
||||
switch (EPCIU.getABISupport().getPointerSize()) {
|
||||
case 4: {
|
||||
tpctypes::UInt32Write PUpdate(PtrAddr, NewAddr);
|
||||
tpctypes::UInt32Write PUpdate(ExecutorAddr(PtrAddr), NewAddr);
|
||||
return MemAccess.writeUInt32s(PUpdate);
|
||||
}
|
||||
case 8: {
|
||||
tpctypes::UInt64Write PUpdate(PtrAddr, NewAddr);
|
||||
tpctypes::UInt64Write PUpdate(ExecutorAddr(PtrAddr), NewAddr);
|
||||
return MemAccess.writeUInt64s(PUpdate);
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -138,36 +138,35 @@ Error SelfExecutorProcessControl::disconnect() {
|
|||
void SelfExecutorProcessControl::writeUInt8sAsync(
|
||||
ArrayRef<tpctypes::UInt8Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<uint8_t *>(W.Address) = W.Value;
|
||||
*W.Addr.toPtr<uint8_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::writeUInt16sAsync(
|
||||
ArrayRef<tpctypes::UInt16Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<uint16_t *>(W.Address) = W.Value;
|
||||
*W.Addr.toPtr<uint16_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::writeUInt32sAsync(
|
||||
ArrayRef<tpctypes::UInt32Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<uint32_t *>(W.Address) = W.Value;
|
||||
*W.Addr.toPtr<uint32_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::writeUInt64sAsync(
|
||||
ArrayRef<tpctypes::UInt64Write> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<uint64_t *>(W.Address) = W.Value;
|
||||
*W.Addr.toPtr<uint64_t *>() = W.Value;
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
void SelfExecutorProcessControl::writeBuffersAsync(
|
||||
ArrayRef<tpctypes::BufferWrite> Ws, WriteResultFn OnWriteComplete) {
|
||||
for (auto &W : Ws)
|
||||
memcpy(jitTargetAddressToPointer<char *>(W.Address), W.Buffer.data(),
|
||||
W.Buffer.size());
|
||||
memcpy(W.Addr.toPtr<char *>(), W.Buffer.data(), W.Buffer.size());
|
||||
OnWriteComplete(Error::success());
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
|
|||
ArgData, ArgSize,
|
||||
[](std::vector<WriteT> Ws) {
|
||||
for (auto &W : Ws)
|
||||
*jitTargetAddressToPointer<decltype(W.Value) *>(W.Address) =
|
||||
W.Value;
|
||||
*W.Addr.template toPtr<decltype(W.Value) *>() = W.Value;
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
@ -40,8 +39,8 @@ writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
|
|||
ArgData, ArgSize,
|
||||
[](std::vector<tpctypes::BufferWrite> Ws) {
|
||||
for (auto &W : Ws)
|
||||
memcpy(jitTargetAddressToPointer<char *>(W.Address),
|
||||
W.Buffer.data(), W.Buffer.size());
|
||||
memcpy(W.Addr.template toPtr<char *>(), W.Buffer.data(),
|
||||
W.Buffer.size());
|
||||
})
|
||||
.release();
|
||||
}
|
||||
|
|
|
@ -176,14 +176,12 @@ llvm_orc_deregisterEHFrameSectionCustomDirectWrapper(
|
|||
return llvm::orc::shared::detail::CWrapperFunctionResult();
|
||||
}
|
||||
|
||||
static Error registerEHFrameWrapper(JITTargetAddress Addr, uint64_t Size) {
|
||||
return llvm::orc::registerEHFrameSection(
|
||||
jitTargetAddressToPointer<const void *>(Addr), Size);
|
||||
static Error registerEHFrameWrapper(ExecutorAddr Addr, uint64_t Size) {
|
||||
return llvm::orc::registerEHFrameSection(Addr.toPtr<const void *>(), Size);
|
||||
}
|
||||
|
||||
static Error deregisterEHFrameWrapper(JITTargetAddress Addr, uint64_t Size) {
|
||||
return llvm::orc::deregisterEHFrameSection(
|
||||
jitTargetAddressToPointer<const void *>(Addr), Size);
|
||||
static Error deregisterEHFrameWrapper(ExecutorAddr Addr, uint64_t Size) {
|
||||
return llvm::orc::deregisterEHFrameSection(Addr.toPtr<const void *>(), Size);
|
||||
}
|
||||
|
||||
extern "C" orc::shared::detail::CWrapperFunctionResult
|
||||
|
|
Loading…
Reference in New Issue