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"
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 
85 template <typename T> struct UIntWrite {
86  UIntWrite() = default;
88 
90  T Value = 0;
91 };
92 
93 /// Describes a write to a uint8_t.
95 
96 /// Describes a write to a uint16_t.
98 
99 /// Describes a write to a uint32_t.
101 
102 /// Describes a write to a uint64_t.
104 
105 /// Describes a write to a buffer.
106 /// For use with TargetProcessControl::MemoryAccess objects.
107 struct BufferWrite {
108  BufferWrite() = default;
110  : Addr(Addr), Buffer(Buffer) {}
111 
114 };
115 
116 /// A handle used to represent a loaded dylib in the target process.
118 
119 using LookupResult = std::vector<JITTargetAddress>;
120 
121 } // end namespace tpctypes
122 
123 namespace shared {
124 
126 
127 using SPSSegFinalizeRequest =
130 
133 
134 template <typename T>
136 
141 
143 
144 template <>
146  tpctypes::WireProtectionFlags> {
147 public:
148  static size_t size(const tpctypes::WireProtectionFlags &WPF) {
149  return SPSArgList<uint8_t>::size(static_cast<uint8_t>(WPF));
150  }
151 
153  const tpctypes::WireProtectionFlags &WPF) {
154  return SPSArgList<uint8_t>::serialize(OB, static_cast<uint8_t>(WPF));
155  }
156 
157  static bool deserialize(SPSInputBuffer &IB,
159  uint8_t Val;
160  if (!SPSArgList<uint8_t>::deserialize(IB, Val))
161  return false;
162  WPF = static_cast<tpctypes::WireProtectionFlags>(Val);
163  return true;
164  }
165 };
166 
167 template <>
169  tpctypes::SegFinalizeRequest> {
171 
172 public:
173  static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
174  return SFRAL::size(SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
175  }
176 
178  const tpctypes::SegFinalizeRequest &SFR) {
179  return SFRAL::serialize(OB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
180  }
181 
182  static bool deserialize(SPSInputBuffer &IB,
184  return SFRAL::deserialize(IB, SFR.Prot, SFR.Addr, SFR.Size, SFR.Content);
185  }
186 };
187 
188 template <>
189 class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
191 
192 public:
193  static size_t size(const tpctypes::FinalizeRequest &FR) {
194  return FRAL::size(FR.Segments, FR.Actions);
195  }
196 
198  const tpctypes::FinalizeRequest &FR) {
199  return FRAL::serialize(OB, FR.Segments, FR.Actions);
200  }
201 
203  return FRAL::deserialize(IB, FR.Segments, FR.Actions);
204  }
205 };
206 
207 template <typename T>
209  tpctypes::UIntWrite<T>> {
210 public:
211  static size_t size(const tpctypes::UIntWrite<T> &W) {
213  }
214 
217  W.Value);
218  }
219 
222  W.Value);
223  }
224 };
225 
226 template <>
228  tpctypes::BufferWrite> {
229 public:
230  static size_t size(const tpctypes::BufferWrite &W) {
232  W.Addr, W.Buffer);
233  }
234 
236  return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
237  OB, W.Addr, W.Buffer);
238  }
239 
241  return SPSTuple<SPSExecutorAddr,
242  SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
243  W.Buffer);
244  }
245 };
246 
247 
248 } // end namespace shared
249 } // end namespace orc
250 } // end namespace llvm
251 
252 #endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
llvm::orc::tpctypes::toWireProtectionFlags
WireProtectionFlags toWireProtectionFlags(sys::Memory::ProtectionFlags PF)
Convert from sys::Memory::ProtectionFlags.
Definition: TargetProcessControlTypes.h:42
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:182
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::size
static size_t size(const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:173
llvm::orc::shared::SPSSerializationTraits< SPSSegFinalizeRequest, tpctypes::SegFinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Definition: TargetProcessControlTypes.h:177
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:204
llvm::orc::shared::SPSSerializationTraits< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:157
llvm::orc::shared::SPSSerializationTraits
Specialize to describe how to serialize/deserialize to/from the given concrete type.
Definition: SimplePackedSerialization.h:104
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:208
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:211
WrapperFunctionUtils.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::orc::shared::SPSInputBuffer
Input char buffer with underflow check.
Definition: SimplePackedSerialization.h:73
llvm::orc::tpctypes::UIntWrite::UIntWrite
UIntWrite(ExecutorAddr Addr, T Value)
Definition: TargetProcessControlTypes.h:87
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:194
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::size
static size_t size(const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:193
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:230
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::deserialize
static bool deserialize(SPSInputBuffer &IB, tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:202
llvm::orc::tpctypes::FinalizeRequest
Definition: TargetProcessControlTypes.h:80
llvm::orc::tpctypes::LookupResult
std::vector< JITTargetAddress > LookupResult
Definition: TargetProcessControlTypes.h:119
llvm::orc::tpctypes::fromWireProtectionFlags
sys::Memory::ProtectionFlags fromWireProtectionFlags(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:54
llvm::X86II::OB
@ OB
Definition: X86BaseInfo.h:801
llvm::sys::Memory::ProtectionFlags
ProtectionFlags
Definition: Memory.h:54
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:176
llvm::orc::shared::SPSSerializationTraits< SPSMemoryAccessUIntWrite< T >, tpctypes::UIntWrite< T > >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::UIntWrite< T > &W)
Definition: TargetProcessControlTypes.h:215
llvm::orc::tpctypes::BufferWrite
Describes a write to a buffer.
Definition: TargetProcessControlTypes.h:107
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:112
llvm::orc::tpctypes::BufferWrite::Buffer
StringRef Buffer
Definition: TargetProcessControlTypes.h:113
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:152
llvm::orc::tpctypes::SegFinalizeRequest::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:75
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:220
llvm::orc::tpctypes::BufferWrite::BufferWrite
BufferWrite(ExecutorAddr Addr, StringRef Buffer)
Definition: TargetProcessControlTypes.h:109
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:240
SimplePackedSerialization.h
llvm::orc::tpctypes::UIntWrite
Definition: TargetProcessControlTypes.h:85
llvm::ArrayRef< char >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
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:235
llvm::orc::shared::SPSTuple::AsArgList
SPSArgList< SPSTagTs... > AsArgList
Convenience typedef of the corresponding arg list.
Definition: SimplePackedSerialization.h:197
llvm::orc::tpctypes::getWireProtectionFlagsStr
std::string getWireProtectionFlagsStr(WireProtectionFlags WPF)
Definition: TargetProcessControlTypes.h:65
llvm::orc::tpctypes::UIntWrite::Addr
ExecutorAddr Addr
Definition: TargetProcessControlTypes.h:89
llvm::orc::tpctypes::WPF_Write
@ WPF_Write
Definition: TargetProcessControlTypes.h:35
ExecutorAddress.h
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< SPSMemoryProtectionFlags, tpctypes::WireProtectionFlags >::size
static size_t size(const tpctypes::WireProtectionFlags &WPF)
Definition: TargetProcessControlTypes.h:148
llvm::orc::shared::SPSMemoryProtectionFlags
Definition: TargetProcessControlTypes.h:125
llvm::orc::shared::SPSSerializationTraits< SPSFinalizeRequest, tpctypes::FinalizeRequest >::serialize
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
Definition: TargetProcessControlTypes.h:197
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:107
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