LLVM 22.0.0git
SimpleRemoteEPCUtils.h
Go to the documentation of this file.
1//===--- SimpleRemoteEPCUtils.h - Utils for Simple Remote EPC ---*- 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// Message definitions and other utilities for SimpleRemoteEPC and
10// SimpleRemoteEPCServer.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
15#define LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
16
17#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/StringMap.h"
23#include "llvm/Support/Error.h"
24
25#include <atomic>
26#include <mutex>
27#include <string>
28#include <thread>
29
30namespace llvm {
31namespace orc {
32
33namespace SimpleRemoteEPCDefaultBootstrapSymbolNames {
34LLVM_ABI extern const char *ExecutorSessionObjectName;
35LLVM_ABI extern const char *DispatchFnName;
36} // end namespace SimpleRemoteEPCDefaultBootstrapSymbolNames
37
39 Setup,
40 Hangup,
41 Result,
44};
45
47 std::string TargetTriple;
51};
52
54
56public:
58
60
61 /// Handle receipt of a message.
62 ///
63 /// Returns an Error if the message cannot be handled, 'EndSession' if the
64 /// client will not accept any further messages, and 'ContinueSession'
65 /// otherwise.
69
70 /// Handle a disconnection from the underlying transport. No further messages
71 /// should be sent to handleMessage after this is called.
72 /// Err may contain an Error value indicating unexpected disconnection. This
73 /// allows clients to log such errors, but no attempt should be made at
74 /// recovery (which should be handled inside the transport class, if it is
75 /// supported at all).
76 virtual void handleDisconnect(Error Err) = 0;
77};
78
80public:
82
83 /// Called during setup of the client to indicate that the client is ready
84 /// to receive messages.
85 ///
86 /// Transport objects should not access the client until this method is
87 /// called.
88 virtual Error start() = 0;
89
90 /// Send a SimpleRemoteEPC message.
91 ///
92 /// This function may be called concurrently. Subclasses should implement
93 /// locking if required for the underlying transport.
95 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes) = 0;
96
97 /// Trigger disconnection from the transport. The implementation should
98 /// respond by calling handleDisconnect on the client once disconnection
99 /// is complete. May be called more than once and from different threads.
100 virtual void disconnect() = 0;
101};
102
103/// Uses read/write on FileDescriptors for transport.
105public:
106 /// Create a FDSimpleRemoteEPCTransport using the given FDs for
107 /// reading (InFD) and writing (OutFD).
109 Create(SimpleRemoteEPCTransportClient &C, int InFD, int OutFD);
110
111 /// Create a FDSimpleRemoteEPCTransport using the given FD for both
112 /// reading and writing.
115 return Create(C, FD, FD);
116 }
117
119
120 Error start() override;
121
122 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
123 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes) override;
124
125 void disconnect() override;
126
127private:
129 int OutFD)
130 : C(C), InFD(InFD), OutFD(OutFD) {}
131
132 Error readBytes(char *Dst, size_t Size, bool *IsEOF = nullptr);
133 int writeBytes(const char *Src, size_t Size);
134 void listenLoop();
135
136 std::mutex M;
137 SimpleRemoteEPCTransportClient &C;
138 std::thread ListenerThread;
139 int InFD, OutFD;
140 std::atomic<bool> Disconnected{false};
141};
142
144 std::string Name;
146};
147
148using RemoteSymbolLookupSet = std::vector<RemoteSymbolLookupSetElement>;
149
153};
154
155namespace shared {
156
158
160
162
163/// Tuple containing target triple, page size, and bootstrap symbols.
168
169template <>
172public:
173 static size_t size(const RemoteSymbolLookupSetElement &V) {
174 return SPSArgList<SPSString, bool>::size(V.Name, V.Required);
175 }
176
177 static size_t serialize(SPSOutputBuffer &OB,
179 return SPSArgList<SPSString, bool>::serialize(OB, V.Name, V.Required);
180 }
181
182 static size_t deserialize(SPSInputBuffer &IB,
184 return SPSArgList<SPSString, bool>::deserialize(IB, V.Name, V.Required);
185 }
186};
187
188template <>
190public:
191 static size_t size(const RemoteSymbolLookup &V) {
193 }
194
195 static size_t serialize(SPSOutputBuffer &OB, const RemoteSymbolLookup &V) {
197 V.Symbols);
198 }
199
202 IB, V.H, V.Symbols);
203 }
204};
205
206template <>
209public:
210 static size_t size(const SimpleRemoteEPCExecutorInfo &SI) {
211 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::size(
212 SI.TargetTriple, SI.PageSize, SI.BootstrapMap, SI.BootstrapSymbols);
213 }
214
215 static bool serialize(SPSOutputBuffer &OB,
216 const SimpleRemoteEPCExecutorInfo &SI) {
217 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::serialize(
218 OB, SI.TargetTriple, SI.PageSize, SI.BootstrapMap, SI.BootstrapSymbols);
219 }
220
222 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::deserialize(
223 IB, SI.TargetTriple, SI.PageSize, SI.BootstrapMap, SI.BootstrapSymbols);
224 }
225};
226
229
233
234} // end namespace shared
235} // end namespace orc
236} // end namespace llvm
237
238#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
This file defines the StringMap class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition: Compiler.h:213
uint64_t Size
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
Represents an address in the executor process.
Uses read/write on FileDescriptors for transport.
static Expected< std::unique_ptr< FDSimpleRemoteEPCTransport > > Create(SimpleRemoteEPCTransportClient &C, int FD)
Create a FDSimpleRemoteEPCTransport using the given FD for both reading and writing.
virtual Expected< HandleMessageAction > handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, SimpleRemoteEPCArgBytesVector ArgBytes)=0
Handle receipt of a message.
virtual void handleDisconnect(Error Err)=0
Handle a disconnection from the underlying transport.
virtual void disconnect()=0
Trigger disconnection from the transport.
virtual Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, ArrayRef< char > ArgBytes)=0
Send a SimpleRemoteEPC message.
virtual Error start()=0
Called during setup of the client to indicate that the client is ready to receive messages.
A utility class for serializing to a blob from a variadic list.
SPS tag type for expecteds, which are either a T or a string representing an error.
Input char buffer with underflow check.
Output char buffer with overflow check.
static size_t serialize(SPSOutputBuffer &OB, const RemoteSymbolLookup &V)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SPSSequence< char > SPSString
SPS tag type for strings, which are equivalent to sequences of chars.
std::vector< RemoteSymbolLookupSetElement > RemoteSymbolLookupSet
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
StringMap< ExecutorAddr > BootstrapSymbols
StringMap< std::vector< char > > BootstrapMap