LLVM 22.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"
26#include "llvm/Support/Memory.h"
27
28#include <vector>
29
30namespace llvm {
31namespace orc {
32namespace tpctypes {
33
35 RemoteAllocGroup() = default;
39 RemoteAllocGroup(const AllocGroup &AG) : Prot(AG.getMemProt()) {
41 "Cannot use no-alloc memory in a remote alloc request");
43 }
44
46 bool FinalizeLifetime = false;
47};
48
55
57 std::vector<SegFinalizeRequest> Segments;
59};
60
66
68 std::vector<SharedMemorySegFinalizeRequest> Segments;
70};
71
72template <typename T> struct UIntWrite {
73 UIntWrite() = default;
75
77 T Value = 0;
78};
79
80/// Describes a write to a uint8_t.
82
83/// Describes a write to a uint16_t.
85
86/// Describes a write to a uint32_t.
88
89/// Describes a write to a uint64_t.
91
92/// Describes a write to a buffer.
93/// For use with TargetProcessControl::MemoryAccess objects.
102
103/// Describes a write to a pointer.
104/// For use with TargetProcessControl::MemoryAccess objects.
113
114/// A handle used to represent a loaded dylib in the target process.
116
117/// A handle used to reference the resolver associated with a loaded
118/// dylib in the target process.
120
121using LookupResult = std::vector<std::optional<ExecutorSymbolDef>>;
122
123} // end namespace tpctypes
124
125namespace shared {
126
127class SPSRemoteAllocGroup;
128
131
134
137
141
142template <typename T>
144
149
152
153template <>
154class SPSSerializationTraits<SPSRemoteAllocGroup, tpctypes::RemoteAllocGroup> {
155 enum WireBits {
156 ReadBit = 1 << 0,
157 WriteBit = 1 << 1,
158 ExecBit = 1 << 2,
159 FinalizeBit = 1 << 3
160 };
161
162public:
163 static size_t size(const tpctypes::RemoteAllocGroup &RAG) {
164 // All AllocGroup values encode to the same size.
166 }
167
168 static bool serialize(SPSOutputBuffer &OB,
169 const tpctypes::RemoteAllocGroup &RAG) {
170 uint8_t WireValue = 0;
171 if ((RAG.Prot & MemProt::Read) != MemProt::None)
172 WireValue |= ReadBit;
173 if ((RAG.Prot & MemProt::Write) != MemProt::None)
174 WireValue |= WriteBit;
175 if ((RAG.Prot & MemProt::Exec) != MemProt::None)
176 WireValue |= ExecBit;
177 if (RAG.FinalizeLifetime)
178 WireValue |= FinalizeBit;
179 return SPSArgList<uint8_t>::serialize(OB, WireValue);
180 }
181
183 uint8_t Val;
185 return false;
187 if (Val & ReadBit)
188 MP |= MemProt::Read;
189 if (Val & WriteBit)
190 MP |= MemProt::Write;
191 if (Val & ExecBit)
192 MP |= MemProt::Exec;
193 bool FinalizeLifetime = (Val & FinalizeBit) ? true : false;
194 RAG = {MP, FinalizeLifetime};
195 return true;
196 }
197};
198
199template <>
201 tpctypes::SegFinalizeRequest> {
203
204public:
205 static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
206 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
207 }
208
209 static bool serialize(SPSOutputBuffer &OB,
210 const tpctypes::SegFinalizeRequest &SFR) {
211 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
212 }
213
216 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size, SFR.Content);
217 }
218};
219
220template <>
223
224public:
225 static size_t size(const tpctypes::FinalizeRequest &FR) {
226 return FRAL::size(FR.Segments, FR.Actions);
227 }
228
229 static bool serialize(SPSOutputBuffer &OB,
230 const tpctypes::FinalizeRequest &FR) {
231 return FRAL::serialize(OB, FR.Segments, FR.Actions);
232 }
233
235 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
236 }
237};
238
239template <>
241 tpctypes::SharedMemorySegFinalizeRequest> {
243
244public:
246 return SFRAL::size(SFR.RAG, SFR.Addr, SFR.Size);
247 }
248
249 static bool serialize(SPSOutputBuffer &OB,
251 return SFRAL::serialize(OB, SFR.RAG, SFR.Addr, SFR.Size);
252 }
253
256 return SFRAL::deserialize(IB, SFR.RAG, SFR.Addr, SFR.Size);
257 }
258};
259
260template <>
262 tpctypes::SharedMemoryFinalizeRequest> {
264
265public:
267 return FRAL::size(FR.Segments, FR.Actions);
268 }
269
270 static bool serialize(SPSOutputBuffer &OB,
272 return FRAL::serialize(OB, FR.Segments, FR.Actions);
273 }
274
277 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
278 }
279};
280
281template <typename T>
283 tpctypes::UIntWrite<T>> {
284public:
285 static size_t size(const tpctypes::UIntWrite<T> &W) {
286 return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Addr, W.Value);
287 }
288
291 W.Value);
292 }
293
296 W.Value);
297 }
298};
299
300template <>
302 tpctypes::BufferWrite> {
303public:
304 static size_t size(const tpctypes::BufferWrite &W) {
305 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList::size(
306 W.Addr, W.Buffer);
307 }
308
310 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
311 OB, W.Addr, W.Buffer);
312 }
313
316 SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
317 W.Buffer);
318 }
319};
320
321template <>
323 tpctypes::PointerWrite> {
324public:
325 static size_t size(const tpctypes::PointerWrite &W) {
327 W.Value);
328 }
329
332 OB, W.Addr, W.Value);
333 }
334
339};
340
341} // end namespace shared
342} // end namespace orc
343} // end namespace llvm
344
345#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define T
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
A pair of memory protections and allocation policies.
MemLifetime getMemLifetime() const
Returns the MemLifetime for this group.
Represents an address in the executor process.
A utility class for serializing to a blob from a variadic list.
Input char buffer with underflow check.
Output char buffer with overflow check.
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
static bool serialize(SPSOutputBuffer &OB, const tpctypes::RemoteAllocGroup &RAG)
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SPSTuple< SPSExecutorAddr, SPSExecutorAddr > SPSMemoryAccessPointerWrite
SPSTuple< SPSExecutorAddr, SPSSequence< char > > SPSMemoryAccessBufferWrite
SPSTuple< SPSExecutorAddr, T > SPSMemoryAccessUIntWrite
SPSTuple< SPSSequence< SPSSegFinalizeRequest >, SPSSequence< SPSAllocActionCallPair > > SPSFinalizeRequest
SPSMemoryAccessUIntWrite< uint8_t > SPSMemoryAccessUInt8Write
SPSMemoryAccessUIntWrite< uint16_t > SPSMemoryAccessUInt16Write
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
SPSTuple< SPSSequence< SPSSharedMemorySegFinalizeRequest >, SPSSequence< SPSAllocActionCallPair > > SPSSharedMemoryFinalizeRequest
SPSMemoryAccessUIntWrite< uint64_t > SPSMemoryAccessUInt64Write
SPSTuple< SPSRemoteAllocGroup, SPSExecutorAddr, uint64_t > SPSSharedMemorySegFinalizeRequest
SPSMemoryAccessUIntWrite< uint32_t > SPSMemoryAccessUInt32Write
SPSTuple< SPSRemoteAllocGroup, SPSExecutorAddr, uint64_t, SPSSequence< char > > SPSSegFinalizeRequest
UIntWrite< uint64_t > UInt64Write
Describes a write to a uint64_t.
std::vector< std::optional< ExecutorSymbolDef > > LookupResult
UIntWrite< uint8_t > UInt8Write
Describes a write to a uint8_t.
ExecutorAddr DylibHandle
A handle used to represent a loaded dylib in the target process.
UIntWrite< uint32_t > UInt32Write
Describes a write to a uint32_t.
ExecutorAddr ResolverHandle
A handle used to reference the resolver associated with a loaded dylib in the target process.
UIntWrite< uint16_t > UInt16Write
Describes a write to a uint16_t.
MemProt
Describes Read/Write/Exec permissions for memory.
Definition MemoryFlags.h:27
@ NoAlloc
NoAlloc memory should not be allocated by the JITLinkMemoryManager at all.
Definition MemoryFlags.h:88
@ Finalize
Finalize memory should be allocated by the allocator, and then be overwritten and deallocated after a...
Definition MemoryFlags.h:83
This is an optimization pass for GlobalISel generic memory operations.
BufferWrite(ExecutorAddr Addr, ArrayRef< char > Buffer)
std::vector< SegFinalizeRequest > Segments
PointerWrite(ExecutorAddr Addr, ExecutorAddr Value)
RemoteAllocGroup(MemProt Prot, bool FinalizeLifetime)
std::vector< SharedMemorySegFinalizeRequest > Segments
UIntWrite(ExecutorAddr Addr, T Value)