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"
24#include "llvm/Support/Error.h"
25
26#include <atomic>
27#include <mutex>
28#include <string>
29#include <thread>
30
31namespace llvm {
32namespace orc {
33
35LLVM_ABI extern const char *ExecutorSessionObjectName;
36LLVM_ABI extern const char *DispatchFnName;
37} // end namespace SimpleRemoteEPCDefaultBootstrapSymbolNames
38
46
53
55public:
57
59
60 /// Handle receipt of a message.
61 ///
62 /// Returns an Error if the message cannot be handled, 'EndSession' if the
63 /// client will not accept any further messages, and 'ContinueSession'
64 /// otherwise.
68
69 /// Handle a disconnection from the underlying transport. No further messages
70 /// should be sent to handleMessage after this is called.
71 /// Err may contain an Error value indicating unexpected disconnection. This
72 /// allows clients to log such errors, but no attempt should be made at
73 /// recovery (which should be handled inside the transport class, if it is
74 /// supported at all).
75 virtual void handleDisconnect(Error Err) = 0;
76};
77
79public:
81
82 /// Called during setup of the client to indicate that the client is ready
83 /// to receive messages.
84 ///
85 /// Transport objects should not access the client until this method is
86 /// called.
87 virtual Error start() = 0;
88
89 /// Send a SimpleRemoteEPC message.
90 ///
91 /// This function may be called concurrently. Subclasses should implement
92 /// locking if required for the underlying transport.
94 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes) = 0;
95
96 /// Trigger disconnection from the transport. The implementation should
97 /// respond by calling handleDisconnect on the client once disconnection
98 /// is complete. May be called more than once and from different threads.
99 virtual void disconnect() = 0;
100};
101
102/// Uses read/write on FileDescriptors for transport.
103class LLVM_ABI FDSimpleRemoteEPCTransport : public SimpleRemoteEPCTransport {
104public:
105 /// Create a FDSimpleRemoteEPCTransport using the given FDs for
106 /// reading (InFD) and writing (OutFD).
108 Create(SimpleRemoteEPCTransportClient &C, int InFD, int OutFD);
109
110 /// Create a FDSimpleRemoteEPCTransport using the given FD for both
111 /// reading and writing.
114 return Create(C, FD, FD);
115 }
116
118
119 Error start() override;
120
121 Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo,
122 ExecutorAddr TagAddr, ArrayRef<char> ArgBytes) override;
123
124 void disconnect() override;
125
126private:
128 int OutFD)
129 : C(C), InFD(InFD), OutFD(OutFD) {}
130
131 Error readBytes(char *Dst, size_t Size, bool *IsEOF = nullptr);
132 int writeBytes(const char *Src, size_t Size);
133 void listenLoop();
134
135 std::mutex M;
136 SimpleRemoteEPCTransportClient &C;
137 std::thread ListenerThread;
138 int InFD, OutFD;
139 std::atomic<bool> Disconnected{false};
140};
141
143 std::string Name;
145};
146
147using RemoteSymbolLookupSet = std::vector<RemoteSymbolLookupSetElement>;
148
153
154namespace shared {
155
157
159
161
162/// Tuple containing target triple, page size, and bootstrap symbols.
167
168template <>
171public:
172 static size_t size(const RemoteSymbolLookupSetElement &V) {
173 return SPSArgList<SPSString, bool>::size(V.Name, V.Required);
174 }
175
176 static size_t serialize(SPSOutputBuffer &OB,
178 return SPSArgList<SPSString, bool>::serialize(OB, V.Name, V.Required);
179 }
180
181 static size_t deserialize(SPSInputBuffer &IB,
183 return SPSArgList<SPSString, bool>::deserialize(IB, V.Name, V.Required);
184 }
185};
186
187template <>
189public:
190 static size_t size(const RemoteSymbolLookup &V) {
192 }
193
194 static size_t serialize(SPSOutputBuffer &OB, const RemoteSymbolLookup &V) {
196 V.Symbols);
197 }
198
201 IB, V.H, V.Symbols);
202 }
203};
204
205template <>
208public:
209 static size_t size(const SimpleRemoteEPCExecutorInfo &SI) {
210 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::size(
211 SI.TargetTriple, SI.PageSize, SI.BootstrapMap, SI.BootstrapSymbols);
212 }
213
214 static bool serialize(SPSOutputBuffer &OB,
216 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::serialize(
217 OB, SI.TargetTriple, SI.PageSize, SI.BootstrapMap, SI.BootstrapSymbols);
218 }
219
221 return SPSSimpleRemoteEPCExecutorInfo::AsArgList ::deserialize(
222 IB, SI.TargetTriple, SI.PageSize, SI.BootstrapMap, SI.BootstrapSymbols);
223 }
224};
225
228
232
233} // end namespace shared
234} // end namespace orc
235} // end namespace llvm
236
237#endif // LLVM_EXECUTIONENGINE_ORC_SHARED_SIMPLEREMOTEEPCUTILS_H
This file defines the StringMap class.
#define LLVM_ABI
Definition Compiler.h:213
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
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
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 InFD, int OutFD)
Create a FDSimpleRemoteEPCTransport using the given FDs for reading (InFD) and writing (OutFD).
static Expected< std::unique_ptr< FDSimpleRemoteEPCTransport > > Create(SimpleRemoteEPCTransportClient &C, int FD)
Create a FDSimpleRemoteEPCTransport using the given FD for both reading and writing.
virtual void handleDisconnect(Error Err)=0
Handle a disconnection from the underlying transport.
virtual Expected< HandleMessageAction > handleMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, shared::WrapperFunctionBuffer ArgBytes)=0
Handle receipt of a message.
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.
C++ wrapper function buffer: Same as CWrapperFunctionBuffer but auto-releases memory.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
SPSExpected< SPSSequence< SPSSequence< SPSExecutorAddr > > >( SPSExecutorAddr, SPSSequence< SPSRemoteSymbolLookup >) SPSLookupSymbolsSignature
SPSSequence< char > SPSString
SPS tag type for strings, which are equivalent to sequences of chars.
SPSTuple< SPSString, uint64_t, SPSSequence< SPSTuple< SPSString, SPSSequence< char > > >, SPSSequence< SPSTuple< SPSString, SPSExecutorAddr > > > SPSSimpleRemoteEPCExecutorInfo
Tuple containing target triple, page size, and bootstrap symbols.
SPSTuple< SPSString, bool > SPSRemoteSymbolLookupSetElement
SPSTuple< uint64_t, SPSRemoteSymbolLookupSet > SPSRemoteSymbolLookup
SPSSequence< SPSRemoteSymbolLookupSetElement > SPSRemoteSymbolLookupSet
SPSExpected< SPSExecutorAddr >(SPSExecutorAddr, SPSString, uint64_t) SPSLoadDylibSignature
std::vector< RemoteSymbolLookupSetElement > RemoteSymbolLookupSet
This is an optimization pass for GlobalISel generic memory operations.
StringMap< std::vector< char > > BootstrapMap