LLVM  16.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"
24 #include "llvm/Support/Memory.h"
25 
26 #include <vector>
27 
28 namespace llvm {
29 namespace orc {
30 namespace tpctypes {
31 
32 enum WireProtectionFlags : uint8_t {
33  WPF_None = 0,
34  WPF_Read = 1U << 0,
35  WPF_Write = 1U << 1,
36  WPF_Exec = 1U << 2,
38 };
39 
40 /// Convert from sys::Memory::ProtectionFlags
44  if (PF & sys::Memory::MF_READ)
45  WPF |= WPF_Read;
46  if (PF & sys::Memory::MF_WRITE)
47  WPF |= WPF_Write;
48  if (PF & sys::Memory::MF_EXEC)
49  WPF |= WPF_Exec;
50  return WPF;
51 }
52 
55  int PF = 0;
56  if (WPF & WPF_Read)
58  if (WPF & WPF_Write)
60  if (WPF & WPF_Exec)
62  return static_cast<sys::Memory::ProtectionFlags>(PF);
63 }
64 
66  std::string Result;
67  Result += (WPF & WPF_Read) ? 'R' : '-';
68  Result += (WPF & WPF_Write) ? 'W' : '-';
69  Result += (WPF & WPF_Exec) ? 'X' : '-';
70  return Result;
71 }
72 
78 };
79 
81  std::vector<SegFinalizeRequest> Segments;
83 };
84 
89 };
90 
92  std::vector<SharedMemorySegFinalizeRequest> Segments;
94 };
95 
96 template <typename T> struct UIntWrite {
97  UIntWrite() = default;
99 
101  T Value = 0;
102 };
103 
104 /// Describes a write to a uint8_t.
106 
107 /// Describes a write to a uint16_t.
109 
110 /// Describes a write to a uint32_t.
112 
113 /// Describes a write to a uint64_t.
115 
116 /// Describes a write to a buffer.
117 /// For use with TargetProcessControl::MemoryAccess objects.
118 struct BufferWrite {
119  BufferWrite() = default;
121  : Addr(Addr), Buffer(Buffer) {}
122 
125 };
126 
127 /// A handle used to represent a loaded dylib in the target process.
129 
130 using LookupResult = std::vector<JITTargetAddress>;
131 
132 } // end namespace tpctypes
133 
134 namespace shared {
135 
137 
138 using SPSSegFinalizeRequest =
141 
144 
147 
151 
152 template <typename T>
154 
159 
161 
162 template <>
164  tpctypes::WireProtectionFlags> {
165 public:
166  static size_t size(const tpctypes::WireProtectionFlags &WPF) {
167  return SPSArgList<uint8_t>::size(static_cast<uint8_t>(WPF));
168  }
169 
171  const tpctypes::WireProtectionFlags &WPF) {
172  return SPSArgList<uint8_t>::serialize(OB, static_cast<uint8_t>(WPF));
173  }
174 
175  static bool deserialize(SPSInputBuffer &IB,
177  uint8_t Val;
178  if (!SPSArgList<uint8_t>::deserialize(IB, Val))
179  return false;
180  WPF = static_cast<tpctypes::WireProtectionFlags>(Val);
181  return true;
182  }
183 };
184 
185 template <>
187  tpctypes::SegFinalizeRequest> {
189 
190 public:
191  static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
192  return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
193  }
194 
196  const tpctypes::SegFinalizeRequest &SFR) {
197  return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
198  }
199 
200  static bool deserialize(SPSInputBuffer &IB,
202  return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
203  }
204 };
205 
206 template <>
207 class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
209 
210 public:
211  static size_t size(const tpctypes::FinalizeRequest &FR) {
212  return FRAL::size(FR.Segments, FR.Actions);
213  }
214 
216  const tpctypes::FinalizeRequest &FR) {
217  return FRAL::serialize(OB, FR.Segments, FR.Actions);
218  }
219 
221  return FRAL::deserialize(IB, FR.Segments, FR.Actions);
222  }
223 };
224 
225 template <>
227  tpctypes::SharedMemorySegFinalizeRequest> {
229 
230 public:
231  static size_t size(const tpctypes::SharedMemorySegFinalizeRequest &SFR) {
232  return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size);
233  }
234 
237  return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size);
238  }
239 
240  static bool deserialize(SPSInputBuffer &IB,
242  return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size);
243  }
244 };
245 
246 template <>
248  tpctypes::SharedMemoryFinalizeRequest> {
250 
251 public:
252  static size_t size(const tpctypes::SharedMemoryFinalizeRequest &FR) {
253  return FRAL::size(FR.Segments, FR.Actions);
254  }
255 
258  return FRAL::serialize(OB, FR.Segments, FR.Actions);
259  }
260 
261  static bool deserialize(SPSInputBuffer &IB,
263  return FRAL::deserialize(IB, FR.Segments, FR.Actions);
264  }
265 };
266 
267 template <typename T>
269  tpctypes::UIntWrite<T>> {
270 public:
271  static size_t size(const tpctypes::UIntWrite<T> &W) {
273  }
274 
277  W.Value);
278  }
279 
282  W.Value);
283  }
284 };
285 
286 template <>
288  tpctypes::BufferWrite> {
289 public:
290  static size_t size(const tpctypes::BufferWrite &W) {
292  W.Addr, W.Buffer);
293  }
294 
296  return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
297  OB, W.Addr, W.Buffer);
298  }
299 
301  return SPSTuple<SPSExecutorAddr,
302  SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
303  W.Buffer);
304  }
305 };
306 
307 } // end namespace shared
308 } // end namespace orc
309 } // end namespace llvm
310 
311 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
llvm::orc::shared::SPSSerializationTraits< SPSSharedMemorySegFinalizeRequest, tpctypes::SharedMemorySegFinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SharedMemorySegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:235
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:31
llvm::orc::tpctypes::toWireProtectionFlags
WireProtectionFlags toWireProtectionFlags(sys::Memory::ProtectionFlags PF)
Convert from sys::Memory::ProtectionFlags.
Definition: TargetProcessControlTypes.h:42
llvm::orc::shared::SPSSerializationTraits< SPSSharedMemoryFinalizeRequest, tpctypes::SharedMemoryFinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::SharedMemoryFinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:261
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:200
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::size
static size_t size(const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:191
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:195
llvm::sys::Memory::MF_READ
@ MF_READ
Definition: Memory.h:55
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:205
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:175
llvm::orc::shared::SPSSerializationTraits< SPSSharedMemoryFinalizeRequest, tpctypes::SharedMemoryFinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SharedMemoryFinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:256
llvm::orc::shared::SPSSerializationTraits
Specialize to describe how to serialize/deserialize to/from the given concrete type.
Definition: SimplePackedSerialization.h:105
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:32
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:266
llvm::orc::tpctypes::SharedMemoryFinalizeRequest
Definition: TargetProcessControlTypes.h:91
llvm::orc::shared::SPSOutputBuffer
Output char buffer with overflow check.
Definition: SimplePackedSerialization.h:54
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::size
static size_t size(const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:271
WrapperFunctionUtils.h
llvm::orc::tpctypes::SharedMemorySegFinalizeRequest::Prot
WireProtectionFlags Prot
Definition: TargetProcessControlTypes.h:86
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::shared::SPSInputBuffer
Input char buffer with underflow check.
Definition: SimplePackedSerialization.h:74
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite(ExecutorAddr Addr, T Value)
Definition: TargetProcessControlTypes.h:98
llvm::orc::tpctypes::SegFinalizeRequest
Definition: TargetProcessControlTypes.h:73
llvm::orc::tpctypes::FinalizeRequest::Actions
shared::AllocActions Actions
Definition: TargetProcessControlTypes.h:82
llvm::orc::shared::SPSTuple
SPS tag type for tuples.
Definition: SimplePackedSerialization.h:195
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::size
static size_t size(const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:211
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:290
llvm::X86II::OB
@ OB
Definition: X86BaseInfo.h:801
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:220
llvm::orc::tpctypes::SharedMemorySegFinalizeRequest
Definition: TargetProcessControlTypes.h:85
llvm::orc::tpctypes::FinalizeRequest
Definition: TargetProcessControlTypes.h:80
llvm::orc::tpctypes::LookupResult
std::vector< JITTargetAddress > LookupResult
Definition: TargetProcessControlTypes.h:130
llvm::orc::tpctypes::SharedMemorySegFinalizeRequest::Size
uint64_t Size
Definition: TargetProcessControlTypes.h:88
llvm::orc::tpctypes::fromWireProtectionFlags
sys::Memory::ProtectionFlags fromWireProtectionFlags(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:54
llvm::sys::Memory::ProtectionFlags
ProtectionFlags
Definition: Memory.h:54
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:228
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:275
llvm::orc::shared::SPSSerializationTraits< SPSSharedMemorySegFinalizeRequest, tpctypes::SharedMemorySegFinalizeRequest >::size
static size_t size(const tpctypes::SharedMemorySegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:231
llvm::orc::tpctypes::BufferWrite
Describes a write to a buffer.
Definition: TargetProcessControlTypes.h:118
llvm::sys::Memory::MF_EXEC
@ MF_EXEC
Definition: Memory.h:57
llvm::orc::tpctypes::SegFinalizeRequest::Content
ArrayRef< char > Content
Definition: TargetProcessControlTypes.h:77
llvm::orc::tpctypes::WPF_None
@ WPF_None
Definition: TargetProcessControlTypes.h:33
llvm::orc::tpctypes::WPF_Read
@ WPF_Read
Definition: TargetProcessControlTypes.h:34
uint64_t
llvm::orc::tpctypes::BufferWrite::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:123
llvm::orc::tpctypes::SharedMemoryFinalizeRequest::Segments
std::vector< SharedMemorySegFinalizeRequest > Segments
Definition: TargetProcessControlTypes.h:92
llvm::orc::tpctypes::BufferWrite::Buffer
StringRef Buffer
Definition: TargetProcessControlTypes.h:124
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:170
llvm::orc::tpctypes::SegFinalizeRequest::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:75
llvm::orc::shared::SPSSerializationTraits< SPSSharedMemoryFinalizeRequest, tpctypes::SharedMemoryFinalizeRequest >::size
static size_t size(const tpctypes::SharedMemoryFinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:252
size
i< reg-> size
Definition: README.txt:166
ArrayRef.h
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:280
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite(ExecutorAddr Addr, StringRef Buffer)
Definition: TargetProcessControlTypes.h:120
llvm::orc::tpctypes::FinalizeRequest::Segments
std::vector< SegFinalizeRequest > Segments
Definition: TargetProcessControlTypes.h:81
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:300
SimplePackedSerialization.h
llvm::orc::tpctypes::UIntWrite
Definition: TargetProcessControlTypes.h:96
llvm::ArrayRef< char >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::orc::shared::AllocActions
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
Definition: AllocationActions.h:44
Memory.h
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessBufferWrite, tpctypes::BufferWrite >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::BufferWrite &W)
Definition: TargetProcessControlTypes.h:295
llvm::orc::shared::SPSTuple::AsArgList
SPSArgList< SPSTagTs... > AsArgList
Convenience typedef of the corresponding arg list.
Definition: SimplePackedSerialization.h:198
llvm::orc::tpctypes::getWireProtectionFlagsStr
std::string getWireProtectionFlagsStr(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:65
llvm::orc::tpctypes::UIntWrite::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:100
llvm::orc::tpctypes::WPF_Write
@ WPF_Write
Definition: TargetProcessControlTypes.h:35
ExecutorAddress.h
llvm::orc::tpctypes::SharedMemorySegFinalizeRequest::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:87
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:36
llvm::orc::shared::SPSSerializationTraits< SPSSharedMemorySegFinalizeRequest, tpctypes::SharedMemorySegFinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::SharedMemorySegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:240
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::size
static size_t size(const tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:166
llvm::orc::shared::SPSMemoryProtectionFlags
Definition: TargetProcessControlTypes.h:136
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:215
llvm::orc::tpctypes::SharedMemoryFinalizeRequest::Actions
shared::AllocActions Actions
Definition: TargetProcessControlTypes.h:93
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:108
llvm::orc::tpctypes::SegFinalizeRequest::Prot
WireProtectionFlags Prot
Definition: TargetProcessControlTypes.h:74
AllocationActions.h
llvm::orc::tpctypes::SegFinalizeRequest::Size
uint64_t Size
Definition: TargetProcessControlTypes.h:76