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 
74  size_t ArgSize);
78 
79  Error run() {
81  Func.toPtr<FnTy *>()(ArgData.toPtr<const char *>(), ArgSize));
82  if (const char *ErrMsg = WFR.getOutOfBandError())
83  return make_error<StringError>(ErrMsg, inconvertibleErrorCode());
84  if (!WFR.empty())
85  return make_error<StringError>("Unexpected result bytes from "
86  "support function call",
88  return Error::success();
89  }
90 };
91 
95 };
96 
102 };
103 
105  std::vector<SegFinalizeRequest> Segments;
106  std::vector<AllocationActionsPair> Actions;
107 };
108 
109 template <typename T> struct UIntWrite {
110  UIntWrite() = default;
112  : Address(Address), Value(Value) {}
113 
115  T Value = 0;
116 };
117 
118 /// Describes a write to a uint8_t.
120 
121 /// Describes a write to a uint16_t.
123 
124 /// Describes a write to a uint32_t.
126 
127 /// Describes a write to a uint64_t.
129 
130 /// Describes a write to a buffer.
131 /// For use with TargetProcessControl::MemoryAccess objects.
132 struct BufferWrite {
133  BufferWrite() = default;
135  : Address(Address), Buffer(Buffer) {}
136 
139 };
140 
141 /// A handle used to represent a loaded dylib in the target process.
143 
144 using LookupResult = std::vector<JITTargetAddress>;
145 
146 } // end namespace tpctypes
147 
148 namespace shared {
149 
151 
154 
155 using SPSSegFinalizeRequest =
158 
161 
164 
165 template <typename T>
167 
172 
174 
175 template <>
177  tpctypes::WireProtectionFlags> {
178 public:
179  static size_t size(const tpctypes::WireProtectionFlags &WPF) {
180  return SPSArgList<uint8_t>::size(static_cast<uint8_t>(WPF));
181  }
182 
184  const tpctypes::WireProtectionFlags &WPF) {
185  return SPSArgList<uint8_t>::serialize(OB, static_cast<uint8_t>(WPF));
186  }
187 
188  static bool deserialize(SPSInputBuffer &IB,
190  uint8_t Val;
191  if (!SPSArgList<uint8_t>::deserialize(IB, Val))
192  return false;
193  WPF = static_cast<tpctypes::WireProtectionFlags>(Val);
194  return true;
195  }
196 };
197 
198 template <>
200  tpctypes::SupportFunctionCall> {
202 
203 public:
204  static size_t size(const tpctypes::SupportFunctionCall &SFC) {
205  return AL::size(SFC.Func, SFC.ArgData, SFC.ArgSize);
206  }
207 
209  const tpctypes::SupportFunctionCall &SFC) {
210  return AL::serialize(OB, SFC.Func, SFC.ArgData, SFC.ArgSize);
211  }
212 
213  static bool deserialize(SPSInputBuffer &IB,
215  return AL::deserialize(IB, SFC.Func, SFC.ArgData, SFC.ArgSize);
216  }
217 };
218 
219 template <>
221  tpctypes::AllocationActionsPair> {
223 
224 public:
225  static size_t size(const tpctypes::AllocationActionsPair &AAP) {
226  return AL::size(AAP.Finalize, AAP.Deallocate);
227  }
228 
230  const tpctypes::AllocationActionsPair &AAP) {
231  return AL::serialize(OB, AAP.Finalize, AAP.Deallocate);
232  }
233 
234  static bool deserialize(SPSInputBuffer &IB,
236  return AL::deserialize(IB, AAP.Finalize, AAP.Deallocate);
237  }
238 };
239 
240 template <>
242  tpctypes::SegFinalizeRequest> {
244 
245 public:
246  static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
247  return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
248  }
249 
251  const tpctypes::SegFinalizeRequest &SFR) {
252  return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
253  }
254 
255  static bool deserialize(SPSInputBuffer &IB,
257  return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
258  }
259 };
260 
261 template <>
262 class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
264 
265 public:
266  static size_t size(const tpctypes::FinalizeRequest &FR) {
267  return FRAL::size(FR.Segments, FR.Actions);
268  }
269 
271  const tpctypes::FinalizeRequest &FR) {
272  return FRAL::serialize(OB, FR.Segments, FR.Actions);
273  }
274 
276  return FRAL::deserialize(IB, FR.Segments, FR.Actions);
277  }
278 };
279 
280 template <typename T>
282  tpctypes::UIntWrite<T>> {
283 public:
284  static size_t size(const tpctypes::UIntWrite<T> &W) {
285  return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Address, W.Value);
286  }
287 
290  W.Value);
291  }
292 
295  W.Value);
296  }
297 };
298 
299 template <>
301  tpctypes::BufferWrite> {
302 public:
303  static size_t size(const tpctypes::BufferWrite &W) {
305  W.Address, W.Buffer);
306  }
307 
309  return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
310  OB, W.Address, W.Buffer);
311  }
312 
314  return SPSTuple<SPSExecutorAddr,
315  SPSSequence<char>>::AsArgList ::deserialize(IB, W.Address,
316  W.Buffer);
317  }
318 };
319 
320 
321 } // end namespace shared
322 } // end namespace orc
323 } // end namespace llvm
324 
325 #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:255
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::size
static size_t size(const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:246
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:250
llvm::orc::shared::SPSSerializationTraits< SPSAllocationActionsPair, tpctypes::AllocationActionsPair >::size
static size_t size(const tpctypes::AllocationActionsPair &AAP)
Definition: TargetProcessControlTypes.h:225
llvm::sys::Memory::MF_READ
@ MF_READ
Definition: Memory.h:55
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::sys::Memory::MF_WRITE
@ MF_WRITE
Definition: Memory.h:56
llvm::orc::tpctypes::SupportFunctionCall::FnTy
shared::detail::CWrapperFunctionResult(const char *ArgData, size_t ArgSize) FnTy
Definition: TargetProcessControlTypes.h:74
JITSymbol.h
llvm::orc::shared::SPSSequence
SPS tag type for sequences.
Definition: SimplePackedSerialization.h:193
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:188
llvm::orc::tpctypes::AllocationActionsPair
Definition: TargetProcessControlTypes.h:92
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:199
llvm::orc::shared::SPSSerializationTraits< SPSAllocationActionsPair, tpctypes::AllocationActionsPair >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::AllocationActionsPair &AAP)
Definition: TargetProcessControlTypes.h:229
llvm::orc::shared::SPSOutputBuffer
Output char buffer with overflow check.
Definition: SimplePackedSerialization.h:53
llvm::orc::shared::SPSSerializationTraits< SPSSupportFunctionCall, tpctypes::SupportFunctionCall >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SupportFunctionCall &SFC)
Definition: TargetProcessControlTypes.h:208
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::size
static size_t size(const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:284
llvm::orc::shared::WrapperFunctionResult::empty
bool empty() const
Returns true if this value is equivalent to a default-constructed WrapperFunctionResult.
Definition: WrapperFunctionUtils.h:115
WrapperFunctionUtils.h
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite(JITTargetAddress Address, T Value)
Definition: TargetProcessControlTypes.h:111
llvm::orc::tpctypes::SupportFunctionCall
Definition: TargetProcessControlTypes.h:72
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::shared::SPSInputBuffer
Input char buffer with underflow check.
Definition: SimplePackedSerialization.h:72
llvm::orc::shared::SPSSerializationTraits< SPSSupportFunctionCall, tpctypes::SupportFunctionCall >::size
static size_t size(const tpctypes::SupportFunctionCall &SFC)
Definition: TargetProcessControlTypes.h:204
llvm::orc::tpctypes::SegFinalizeRequest
Definition: TargetProcessControlTypes.h:97
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:266
llvm::orc::shared::SPSSerializationTraits< SPSSupportFunctionCall, tpctypes::SupportFunctionCall >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::SupportFunctionCall &SFC)
Definition: TargetProcessControlTypes.h:213
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:303
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:275
llvm::orc::tpctypes::FinalizeRequest
Definition: TargetProcessControlTypes.h:104
llvm::orc::tpctypes::BufferWrite::Address
JITTargetAddress Address
Definition: TargetProcessControlTypes.h:137
llvm::orc::tpctypes::LookupResult
std::vector< JITTargetAddress > LookupResult
Definition: TargetProcessControlTypes.h:144
llvm::orc::tpctypes::fromWireProtectionFlags
sys::Memory::ProtectionFlags fromWireProtectionFlags(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:53
llvm::orc::tpctypes::SupportFunctionCall::ArgSize
uint64_t ArgSize
Definition: TargetProcessControlTypes.h:77
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:234
llvm::orc::shared::detail::CWrapperFunctionResult
Definition: WrapperFunctionUtils.h:37
llvm::orc::shared::SPSExecutorAddr
SPS tag type for executor addresseses.
Definition: SimplePackedSerialization.h:199
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:288
llvm::orc::tpctypes::AllocationActionsPair::Deallocate
SupportFunctionCall Deallocate
Definition: TargetProcessControlTypes.h:94
llvm::orc::tpctypes::AllocationActionsPair::Finalize
SupportFunctionCall Finalize
Definition: TargetProcessControlTypes.h:93
llvm::orc::tpctypes::UIntWrite::Address
JITTargetAddress Address
Definition: TargetProcessControlTypes.h:114
llvm::orc::tpctypes::BufferWrite
Describes a write to a buffer.
Definition: TargetProcessControlTypes.h:132
llvm::sys::Memory::MF_EXEC
@ MF_EXEC
Definition: Memory.h:57
llvm::orc::tpctypes::SegFinalizeRequest::Content
ArrayRef< char > Content
Definition: TargetProcessControlTypes.h:101
llvm::orc::shared::WrapperFunctionResult
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
Definition: WrapperFunctionUtils.h:46
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::SupportFunctionCall::ArgData
ExecutorAddr ArgData
Definition: TargetProcessControlTypes.h:76
llvm::orc::tpctypes::BufferWrite::Buffer
StringRef Buffer
Definition: TargetProcessControlTypes.h:138
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:183
llvm::orc::tpctypes::SegFinalizeRequest::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:99
size
i< reg-> size
Definition: README.txt:166
llvm::orc::tpctypes::FinalizeRequest::Actions
std::vector< AllocationActionsPair > Actions
Definition: TargetProcessControlTypes.h:106
ArrayRef.h
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:293
llvm::orc::tpctypes::FinalizeRequest::Segments
std::vector< SegFinalizeRequest > Segments
Definition: TargetProcessControlTypes.h:105
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:313
SimplePackedSerialization.h
llvm::orc::tpctypes::UIntWrite
Definition: TargetProcessControlTypes.h:109
llvm::ArrayRef< char >
llvm::orc::shared::WrapperFunctionResult::getOutOfBandError
const char * getOutOfBandError() const
If this value is an out-of-band error then this returns the error message, otherwise returns nullptr.
Definition: WrapperFunctionUtils.h:162
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::X86II::OB
@ OB
Definition: X86BaseInfo.h:796
Memory.h
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:308
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::WPF_Write
@ WPF_Write
Definition: TargetProcessControlTypes.h:34
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::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::size
static size_t size(const tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:179
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite(JITTargetAddress Address, StringRef Buffer)
Definition: TargetProcessControlTypes.h:134
llvm::orc::shared::SPSMemoryProtectionFlags
Definition: TargetProcessControlTypes.h:150
llvm::orc::ExecutorAddr::toPtr
T toPtr() const
Cast this ExecutorAddr to a pointer of the given type.
Definition: ExecutorAddress.h:53
llvm::orc::tpctypes::SupportFunctionCall::Func
ExecutorAddr Func
Definition: TargetProcessControlTypes.h:75
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:270
llvm::orc::tpctypes::SupportFunctionCall::run
Error run()
Definition: TargetProcessControlTypes.h:79
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:98
llvm::orc::tpctypes::SegFinalizeRequest::Size
uint64_t Size
Definition: TargetProcessControlTypes.h:100