LLVM  14.0.0git
TargetProcessControlTypes.h
Go to the documentation of this file.
1 //===--- TargetProcessControlTypes.h -- Shared Core/TPC types ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // TargetProcessControl types that are used by both the Orc and
10 // OrcTargetProcess libraries.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
15 #define LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
16 
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Memory.h"
24 
25 #include <vector>
26 
27 namespace llvm {
28 namespace orc {
29 namespace tpctypes {
30 
31 enum WireProtectionFlags : uint8_t {
32  WPF_None = 0,
33  WPF_Read = 1U << 0,
34  WPF_Write = 1U << 1,
35  WPF_Exec = 1U << 2,
37 };
38 
39 /// Convert from sys::Memory::ProtectionFlags
43  if (PF & sys::Memory::MF_READ)
44  WPF |= WPF_Read;
45  if (PF & sys::Memory::MF_WRITE)
46  WPF |= WPF_Write;
47  if (PF & sys::Memory::MF_EXEC)
48  WPF |= WPF_Exec;
49  return WPF;
50 }
51 
54  int PF = 0;
55  if (WPF & WPF_Read)
57  if (WPF & WPF_Write)
59  if (WPF & WPF_Exec)
61  return static_cast<sys::Memory::ProtectionFlags>(PF);
62 }
63 
65  std::string Result;
66  Result += (WPF & WPF_Read) ? 'R' : '-';
67  Result += (WPF & WPF_Write) ? 'W' : '-';
68  Result += (WPF & WPF_Exec) ? 'X' : '-';
69  return Result;
70 }
71 
75 
76  WrapperFunctionCall() = default;
78  ExecutorAddrDiff ArgSize)
79  : Func(Func), ArgData(ArgData, ArgSize) {}
81  : Func(Func), ArgData(ArgData) {}
82 
84  using FnTy =
85  shared::CWrapperFunctionResult(const char *ArgData, size_t ArgSize);
87  Func.toPtr<FnTy *>()(ArgData.Start.toPtr<const char *>(),
88  static_cast<size_t>(ArgData.size().getValue())));
89  }
90 
91  /// Run call and deserialize result using SPS.
92  template <typename SPSRetT, typename RetT> Error runWithSPSRet(RetT &RetVal) {
93  auto WFR = run();
94  if (const char *ErrMsg = WFR.getOutOfBandError())
95  return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
96  shared::SPSInputBuffer IB(WFR.data(), WFR.size());
98  return make_error<StringError>("Could not deserialize result from "
99  "serialized wrapper function call",
101  return Error::success();
102  }
103 
104  /// Overload for SPS functions returning void.
107  return runWithSPSRet<shared::SPSEmpty>(E);
108  }
109 };
110 
114 };
115 
121 };
122 
124  std::vector<SegFinalizeRequest> Segments;
125  std::vector<AllocationActionsPair> Actions;
126 };
127 
128 template <typename T> struct UIntWrite {
129  UIntWrite() = default;
131 
133  T Value = 0;
134 };
135 
136 /// Describes a write to a uint8_t.
138 
139 /// Describes a write to a uint16_t.
141 
142 /// Describes a write to a uint32_t.
144 
145 /// Describes a write to a uint64_t.
147 
148 /// Describes a write to a buffer.
149 /// For use with TargetProcessControl::MemoryAccess objects.
150 struct BufferWrite {
151  BufferWrite() = default;
153  : Addr(Addr), Buffer(Buffer) {}
154 
157 };
158 
159 /// A handle used to represent a loaded dylib in the target process.
161 
162 using LookupResult = std::vector<JITTargetAddress>;
163 
164 } // end namespace tpctypes
165 
166 namespace shared {
167 
169 
171 
172 using SPSSegFinalizeRequest =
175 
178 
181 
182 template <typename T>
184 
189 
191 
192 template <>
194  tpctypes::WireProtectionFlags> {
195 public:
196  static size_t size(const tpctypes::WireProtectionFlags &WPF) {
197  return SPSArgList<uint8_t>::size(static_cast<uint8_t>(WPF));
198  }
199 
201  const tpctypes::WireProtectionFlags &WPF) {
202  return SPSArgList<uint8_t>::serialize(OB, static_cast<uint8_t>(WPF));
203  }
204 
205  static bool deserialize(SPSInputBuffer &IB,
207  uint8_t Val;
208  if (!SPSArgList<uint8_t>::deserialize(IB, Val))
209  return false;
210  WPF = static_cast<tpctypes::WireProtectionFlags>(Val);
211  return true;
212  }
213 };
214 
215 template <>
217  tpctypes::WrapperFunctionCall> {
219 
220 public:
221  static size_t size(const tpctypes::WrapperFunctionCall &WFC) {
222  return AL::size(WFC.Func, WFC.ArgData);
223  }
224 
226  const tpctypes::WrapperFunctionCall &WFC) {
227  return AL::serialize(OB, WFC.Func, WFC.ArgData);
228  }
229 
230  static bool deserialize(SPSInputBuffer &IB,
232  return AL::deserialize(IB, WFC.Func, WFC.ArgData);
233  }
234 };
235 
236 template <>
238  tpctypes::AllocationActionsPair> {
240 
241 public:
242  static size_t size(const tpctypes::AllocationActionsPair &AAP) {
243  return AL::size(AAP.Finalize, AAP.Deallocate);
244  }
245 
247  const tpctypes::AllocationActionsPair &AAP) {
248  return AL::serialize(OB, AAP.Finalize, AAP.Deallocate);
249  }
250 
251  static bool deserialize(SPSInputBuffer &IB,
253  return AL::deserialize(IB, AAP.Finalize, AAP.Deallocate);
254  }
255 };
256 
257 template <>
259  tpctypes::SegFinalizeRequest> {
261 
262 public:
263  static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
264  return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
265  }
266 
268  const tpctypes::SegFinalizeRequest &SFR) {
269  return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
270  }
271 
272  static bool deserialize(SPSInputBuffer &IB,
274  return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
275  }
276 };
277 
278 template <>
279 class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
281 
282 public:
283  static size_t size(const tpctypes::FinalizeRequest &FR) {
284  return FRAL::size(FR.Segments, FR.Actions);
285  }
286 
288  const tpctypes::FinalizeRequest &FR) {
289  return FRAL::serialize(OB, FR.Segments, FR.Actions);
290  }
291 
293  return FRAL::deserialize(IB, FR.Segments, FR.Actions);
294  }
295 };
296 
297 template <typename T>
299  tpctypes::UIntWrite<T>> {
300 public:
301  static size_t size(const tpctypes::UIntWrite<T> &W) {
303  }
304 
307  W.Value);
308  }
309 
312  W.Value);
313  }
314 };
315 
316 template <>
318  tpctypes::BufferWrite> {
319 public:
320  static size_t size(const tpctypes::BufferWrite &W) {
322  W.Addr, W.Buffer);
323  }
324 
326  return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
327  OB, W.Addr, W.Buffer);
328  }
329 
331  return SPSTuple<SPSExecutorAddr,
332  SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
333  W.Buffer);
334  }
335 };
336 
337 
338 } // end namespace shared
339 } // end namespace orc
340 } // end namespace llvm
341 
342 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:37
llvm::orc::tpctypes::toWireProtectionFlags
WireProtectionFlags toWireProtectionFlags(sys::Memory::ProtectionFlags PF)
Convert from sys::Memory::ProtectionFlags.
Definition: TargetProcessControlTypes.h:41
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:272
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::size
static size_t size(const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:263
llvm::orc::tpctypes::WrapperFunctionCall::Func
ExecutorAddr Func
Definition: TargetProcessControlTypes.h:73
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:267
llvm::orc::shared::SPSSerializationTraits< SPSAllocationActionsPair, tpctypes::AllocationActionsPair >::size
static size_t size(const tpctypes::AllocationActionsPair &AAP)
Definition: TargetProcessControlTypes.h:242
llvm::orc::ExecutorAddrDiff
Represents the difference between two addresses in the executor process.
Definition: ExecutorAddress.h:25
llvm::sys::Memory::MF_READ
@ MF_READ
Definition: Memory.h:55
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::sys::Memory::MF_WRITE
@ MF_WRITE
Definition: Memory.h:56
JITSymbol.h
llvm::orc::shared::SPSSequence
SPS tag type for sequences.
Definition: SimplePackedSerialization.h:193
llvm::orc::shared::CWrapperFunctionResult
Definition: WrapperFunctionUtils.h:33
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:205
llvm::orc::tpctypes::AllocationActionsPair
Definition: TargetProcessControlTypes.h:111
llvm::orc::shared::SPSSerializationTraits
Specialize to describe how to serialize/deserialize to/from the given concrete type.
Definition: SimplePackedSerialization.h:103
LLVM_MARK_AS_BITMASK_ENUM
#define LLVM_MARK_AS_BITMASK_ENUM(LargestValue)
LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can perform bitwise operatio...
Definition: BitmaskEnum.h:41
StringRef.h
llvm::orc::tpctypes::WireProtectionFlags
WireProtectionFlags
Definition: TargetProcessControlTypes.h:31
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:208
llvm::orc::shared::SPSSerializationTraits< SPSAllocationActionsPair, tpctypes::AllocationActionsPair >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::AllocationActionsPair &AAP)
Definition: TargetProcessControlTypes.h:246
llvm::orc::shared::SPSOutputBuffer
Output char buffer with overflow check.
Definition: SimplePackedSerialization.h:53
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::orc::tpctypes::WrapperFunctionCall::run
shared::WrapperFunctionResult run()
Definition: TargetProcessControlTypes.h:83
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::size
static size_t size(const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:301
WrapperFunctionUtils.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::X86II::OB
@ OB
Definition: X86BaseInfo.h:801
llvm::orc::tpctypes::WrapperFunctionCall::runWithSPSRet
Error runWithSPSRet(RetT &RetVal)
Run call and deserialize result using SPS.
Definition: TargetProcessControlTypes.h:92
llvm::orc::shared::SPSInputBuffer
Input char buffer with underflow check.
Definition: SimplePackedSerialization.h:72
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite(ExecutorAddr Addr, T Value)
Definition: TargetProcessControlTypes.h:130
llvm::orc::tpctypes::SegFinalizeRequest
Definition: TargetProcessControlTypes.h:116
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:183
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::size
static size_t size(const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:283
llvm::orc::tpctypes::WrapperFunctionCall::WrapperFunctionCall
WrapperFunctionCall(ExecutorAddr Func, ExecutorAddrRange ArgData)
Definition: TargetProcessControlTypes.h:80
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite()=default
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::size
static size_t size(const tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:320
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:292
llvm::orc::tpctypes::FinalizeRequest
Definition: TargetProcessControlTypes.h:123
llvm::orc::tpctypes::LookupResult
std::vector< JITTargetAddress > LookupResult
Definition: TargetProcessControlTypes.h:162
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::orc::tpctypes::fromWireProtectionFlags
sys::Memory::ProtectionFlags fromWireProtectionFlags(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:53
llvm::orc::shared::SPSSerializationTraits< SPSWrapperFunctionCall, tpctypes::WrapperFunctionCall >::size
static size_t size(const tpctypes::WrapperFunctionCall &WFC)
Definition: TargetProcessControlTypes.h:221
llvm::sys::Memory::ProtectionFlags
ProtectionFlags
Definition: Memory.h:54
llvm::orc::shared::SPSSerializationTraits< SPSAllocationActionsPair, tpctypes::AllocationActionsPair >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::AllocationActionsPair &AAP)
Definition: TargetProcessControlTypes.h:251
llvm::orc::shared::SPSEmpty
Definition: SimplePackedSerialization.h:177
llvm::orc::ExecutorAddrDiff::getValue
uint64_t getValue() const
Definition: ExecutorAddress.h:30
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:163
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:305
llvm::orc::ExecutorAddrRange
Represents an address range in the exceutor process.
Definition: ExecutorAddress.h:134
llvm::orc::tpctypes::BufferWrite
Describes a write to a buffer.
Definition: TargetProcessControlTypes.h:150
llvm::orc::tpctypes::WrapperFunctionCall::ArgData
ExecutorAddrRange ArgData
Definition: TargetProcessControlTypes.h:74
llvm::sys::Memory::MF_EXEC
@ MF_EXEC
Definition: Memory.h:57
llvm::orc::tpctypes::SegFinalizeRequest::Content
ArrayRef< char > Content
Definition: TargetProcessControlTypes.h:120
llvm::orc::ExecutorAddrRange::size
ExecutorAddrDiff size() const
Definition: ExecutorAddress.h:142
llvm::orc::tpctypes::WrapperFunctionCall
Definition: TargetProcessControlTypes.h:72
llvm::orc::tpctypes::WrapperFunctionCall::runWithSPSRet
Error runWithSPSRet()
Overload for SPS functions returning void.
Definition: TargetProcessControlTypes.h:105
llvm::orc::shared::WrapperFunctionResult
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
Definition: WrapperFunctionUtils.h:40
llvm::orc::tpctypes::WPF_None
@ WPF_None
Definition: TargetProcessControlTypes.h:32
llvm::orc::tpctypes::WPF_Read
@ WPF_Read
Definition: TargetProcessControlTypes.h:33
uint64_t
llvm::orc::tpctypes::AllocationActionsPair::Deallocate
WrapperFunctionCall Deallocate
Definition: TargetProcessControlTypes.h:113
llvm::orc::tpctypes::BufferWrite::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:155
llvm::orc::tpctypes::BufferWrite::Buffer
StringRef Buffer
Definition: TargetProcessControlTypes.h:156
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite()=default
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:200
llvm::orc::tpctypes::SegFinalizeRequest::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:118
size
i< reg-> size
Definition: README.txt:166
llvm::orc::tpctypes::FinalizeRequest::Actions
std::vector< AllocationActionsPair > Actions
Definition: TargetProcessControlTypes.h:125
ArrayRef.h
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:310
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite(ExecutorAddr Addr, StringRef Buffer)
Definition: TargetProcessControlTypes.h:152
llvm::orc::tpctypes::FinalizeRequest::Segments
std::vector< SegFinalizeRequest > Segments
Definition: TargetProcessControlTypes.h:124
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:330
llvm::orc::ExecutorAddrRange::Start
ExecutorAddr Start
Definition: ExecutorAddress.h:157
SimplePackedSerialization.h
llvm::orc::shared::SPSSerializationTraits< SPSWrapperFunctionCall, tpctypes::WrapperFunctionCall >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::WrapperFunctionCall &WFC)
Definition: TargetProcessControlTypes.h:225
llvm::orc::tpctypes::AllocationActionsPair::Finalize
WrapperFunctionCall Finalize
Definition: TargetProcessControlTypes.h:112
llvm::orc::tpctypes::UIntWrite
Definition: TargetProcessControlTypes.h:128
llvm::ArrayRef< char >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
Memory.h
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:325
llvm::orc::shared::SPSTuple::AsArgList
SPSArgList< SPSTagTs... > AsArgList
Convenience typedef of the corresponding arg list.
Definition: SimplePackedSerialization.h:186
llvm::orc::tpctypes::getWireProtectionFlagsStr
std::string getWireProtectionFlagsStr(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:64
llvm::orc::tpctypes::UIntWrite::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:132
llvm::orc::tpctypes::WPF_Write
@ WPF_Write
Definition: TargetProcessControlTypes.h:34
llvm::orc::tpctypes::WrapperFunctionCall::WrapperFunctionCall
WrapperFunctionCall(ExecutorAddr Func, ExecutorAddr ArgData, ExecutorAddrDiff ArgSize)
Definition: TargetProcessControlTypes.h:77
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
ExecutorAddress.h
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::JITTargetAddress
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Definition: JITSymbol.h:42
llvm::orc::tpctypes::WPF_Exec
@ WPF_Exec
Definition: TargetProcessControlTypes.h:35
llvm::orc::tpctypes::WrapperFunctionCall::WrapperFunctionCall
WrapperFunctionCall()=default
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::size
static size_t size(const tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:196
llvm::orc::shared::SPSMemoryProtectionFlags
Definition: TargetProcessControlTypes.h:168
llvm::orc::shared::SPSSerializationTraits< SPSWrapperFunctionCall, tpctypes::WrapperFunctionCall >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::WrapperFunctionCall &WFC)
Definition: TargetProcessControlTypes.h:230
llvm::orc::ExecutorAddr::toPtr
T toPtr() const
Cast this ExecutorAddr to a pointer of the given type.
Definition: ExecutorAddress.h:53
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:287
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::orc::shared::SPSArgList
A utility class for serializing to a blob from a variadic list.
Definition: SimplePackedSerialization.h:106
llvm::orc::tpctypes::SegFinalizeRequest::Prot
WireProtectionFlags Prot
Definition: TargetProcessControlTypes.h:117
llvm::orc::tpctypes::SegFinalizeRequest::Size
uint64_t Size
Definition: TargetProcessControlTypes.h:119