LLVM 17.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"
25#include "llvm/Support/Memory.h"
26
27#include <vector>
28
29namespace llvm {
30namespace orc {
31namespace tpctypes {
32
38};
39
41 std::vector<SegFinalizeRequest> Segments;
43};
44
49};
50
52 std::vector<SharedMemorySegFinalizeRequest> Segments;
54};
55
56template <typename T> struct UIntWrite {
57 UIntWrite() = default;
59
61 T Value = 0;
62};
63
64/// Describes a write to a uint8_t.
66
67/// Describes a write to a uint16_t.
69
70/// Describes a write to a uint32_t.
72
73/// Describes a write to a uint64_t.
75
76/// Describes a write to a buffer.
77/// For use with TargetProcessControl::MemoryAccess objects.
79 BufferWrite() = default;
81 : Addr(Addr), Buffer(Buffer) {}
82
85};
86
87/// A handle used to represent a loaded dylib in the target process.
89
90using LookupResult = std::vector<ExecutorAddr>;
91
92} // end namespace tpctypes
93
94namespace shared {
95
97
100
103
106
110
111template <typename T>
113
118
120
122 enum WireBits {
123 ReadBit = 1 << 0,
124 WriteBit = 1 << 1,
125 ExecBit = 1 << 2,
126 FinalizeBit = 1 << 3
127 };
128
129public:
130 static size_t size(const AllocGroup &AG) {
131 // All AllocGroup values encode to the same size.
132 return SPSArgList<uint8_t>::size(uint8_t(0));
133 }
134
135 static bool serialize(SPSOutputBuffer &OB, const AllocGroup &AG) {
136 uint8_t WireValue = 0;
137 if ((AG.getMemProt() & MemProt::Read) != MemProt::None)
138 WireValue |= ReadBit;
140 WireValue |= WriteBit;
141 if ((AG.getMemProt() & MemProt::Exec) != MemProt::None)
142 WireValue |= ExecBit;
144 WireValue |= FinalizeBit;
145 return SPSArgList<uint8_t>::serialize(OB, WireValue);
146 }
147
148 static bool deserialize(SPSInputBuffer &IB, AllocGroup &AG) {
149 uint8_t Val;
151 return false;
153 if (Val & ReadBit)
154 MP |= MemProt::Read;
155 if (Val & WriteBit)
156 MP |= MemProt::Write;
157 if (Val & ExecBit)
158 MP |= MemProt::Exec;
159 MemDeallocPolicy MDP = (Val & FinalizeBit) ? MemDeallocPolicy::Finalize
161 AG = AllocGroup(MP, MDP);
162 return true;
163 }
164};
165
166template <>
168 tpctypes::SegFinalizeRequest> {
170
171public:
172 static size_t size(const tpctypes::SegFinalizeRequest &SFR) {
173 return SFRAL::size(SFR.AG, SFR.Addr, SFR.Size, SFR.Content);
174 }
175
176 static bool serialize(SPSOutputBuffer &OB,
177 const tpctypes::SegFinalizeRequest &SFR) {
178 return SFRAL::serialize(OB, SFR.AG, SFR.Addr, SFR.Size, SFR.Content);
179 }
180
183 return SFRAL::deserialize(IB, SFR.AG, SFR.Addr, SFR.Size, SFR.Content);
184 }
185};
186
187template <>
188class SPSSerializationTraits<SPSFinalizeRequest, tpctypes::FinalizeRequest> {
190
191public:
192 static size_t size(const tpctypes::FinalizeRequest &FR) {
193 return FRAL::size(FR.Segments, FR.Actions);
194 }
195
196 static bool serialize(SPSOutputBuffer &OB,
197 const tpctypes::FinalizeRequest &FR) {
198 return FRAL::serialize(OB, FR.Segments, FR.Actions);
199 }
200
202 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
203 }
204};
205
206template <>
208 tpctypes::SharedMemorySegFinalizeRequest> {
210
211public:
213 return SFRAL::size(SFR.AG, SFR.Addr, SFR.Size);
214 }
215
216 static bool serialize(SPSOutputBuffer &OB,
218 return SFRAL::serialize(OB, SFR.AG, SFR.Addr, SFR.Size);
219 }
220
223 return SFRAL::deserialize(IB, SFR.AG, SFR.Addr, SFR.Size);
224 }
225};
226
227template <>
229 tpctypes::SharedMemoryFinalizeRequest> {
231
232public:
234 return FRAL::size(FR.Segments, FR.Actions);
235 }
236
237 static bool serialize(SPSOutputBuffer &OB,
239 return FRAL::serialize(OB, FR.Segments, FR.Actions);
240 }
241
244 return FRAL::deserialize(IB, FR.Segments, FR.Actions);
245 }
246};
247
248template <typename T>
250 tpctypes::UIntWrite<T>> {
251public:
252 static size_t size(const tpctypes::UIntWrite<T> &W) {
253 return SPSTuple<SPSExecutorAddr, T>::AsArgList::size(W.Addr, W.Value);
254 }
255
258 W.Value);
259 }
260
263 W.Value);
264 }
265};
266
267template <>
269 tpctypes::BufferWrite> {
270public:
271 static size_t size(const tpctypes::BufferWrite &W) {
272 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList::size(
273 W.Addr, W.Buffer);
274 }
275
277 return SPSTuple<SPSExecutorAddr, SPSSequence<char>>::AsArgList ::serialize(
278 OB, W.Addr, W.Buffer);
279 }
280
283 SPSSequence<char>>::AsArgList ::deserialize(IB, W.Addr,
284 W.Buffer);
285 }
286};
287
288} // end namespace shared
289} // end namespace orc
290} // end namespace llvm
291
292#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_TARGETPROCESSCONTROLTYPES_H
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
LLVM Value Representation.
Definition: Value.h:74
A pair of memory protections and allocation policies.
Definition: MemoryFlags.h:93
MemDeallocPolicy getMemDeallocPolicy() const
Returns the MemoryDeallocationPolicy for this group.
Definition: MemoryFlags.h:124
MemProt getMemProt() const
Returns the MemProt for this group.
Definition: MemoryFlags.h:119
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 AllocGroup &AG)
static bool serialize(SPSOutputBuffer &OB, const tpctypes::FinalizeRequest &FR)
static bool serialize(SPSOutputBuffer &OB, const tpctypes::SegFinalizeRequest &SFR)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SPSArgList< SPSTagTs... > AsArgList
Convenience typedef of the corresponding arg list.
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
std::vector< ExecutorAddr > LookupResult
MemProt
Describes Read/Write/Exec permissions for memory.
Definition: MemoryFlags.h:27
MemDeallocPolicy
Describes a memory deallocation policy for memory to be allocated by a JITLinkMemoryManager.
Definition: MemoryFlags.h:75
@ Standard
Standard memory should be deallocated when the deallocate method is called for the finalized allocati...
@ Finalize
Finalize memory should be overwritten and then deallocated after all finalization functions have been...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Describes a write to a buffer.
BufferWrite(ExecutorAddr Addr, StringRef Buffer)
std::vector< SegFinalizeRequest > Segments
std::vector< SharedMemorySegFinalizeRequest > Segments
UIntWrite(ExecutorAddr Addr, T Value)