15#include "llvm/Config/llvm-config.h"
18#if !defined(_MSC_VER) && !defined(__MINGW32__)
24#include <sys/socket.h>
30 static constexpr unsigned MsgSizeOffset = 0;
31 static constexpr unsigned OpCOffset = MsgSizeOffset +
sizeof(
uint64_t);
32 static constexpr unsigned SeqNoOffset = OpCOffset +
sizeof(
uint64_t);
33 static constexpr unsigned TagAddrOffset = SeqNoOffset +
sizeof(
uint64_t);
34 static constexpr unsigned Size = TagAddrOffset +
sizeof(
uint64_t);
44 "__llvm_orc_SimpleRemoteEPC_dispatch_ctx";
55 bool Success = SPSSerialize::serialize(OB, SE);
57 assert(
Success &&
"Hangup payload serialization should not fail");
63 "Hangup payload should not be an out-of-band error buffer");
79#if LLVM_ENABLE_THREADS
88 std::unique_ptr<FDSimpleRemoteEPCTransport> FDT(
89 new FDSimpleRemoteEPCTransport(C, InFD, OutFD));
90 return std::move(FDT);
93 "thread support, but llvm was built with "
94 "LLVM_ENABLE_THREADS=Off",
100#if LLVM_ENABLE_THREADS
101 ListenerThread.join();
106#if LLVM_ENABLE_THREADS
107 ListenerThread = std::thread([
this]() { listenLoop(); });
117 char HeaderBuffer[FDMsgHeader::Size];
120 FDMsgHeader::Size + ArgBytes.
size();
127 std::lock_guard<std::mutex> Lock(M);
131 if (
int ErrNo = writeBytes(HeaderBuffer, FDMsgHeader::Size))
133 if (
int ErrNo = writeBytes(ArgBytes.
data(), ArgBytes.
size()))
143 bool CloseOutFD = InFD != OutFD;
150 ::shutdown(InFD, CloseOutFD ? SHUT_RD : SHUT_RDWR);
153 while (close(InFD) == -1) {
162 ::shutdown(OutFD, SHUT_WR);
164 while (close(OutFD) == -1) {
176Error FDSimpleRemoteEPCTransport::readBytes(
char *Dst,
size_t Size,
178 assert((
Size == 0 || Dst) &&
"Attempt to read into null.");
179 ssize_t Completed = 0;
180 while (Completed <
static_cast<ssize_t
>(
Size)) {
181 ssize_t
Read = ::read(InFD, Dst + Completed,
Size - Completed);
185 if (Completed == 0 && IsEOF) {
190 }
else if (ErrNo == EAGAIN || ErrNo == EINTR)
193 std::lock_guard<std::mutex> Lock(M);
194 if (Disconnected && IsEOF) {
199 std::error_code(ErrNo, std::generic_category()));
207int FDSimpleRemoteEPCTransport::writeBytes(
const char *Src,
size_t Size) {
208 assert((
Size == 0 || Src) &&
"Attempt to append from null.");
209 ssize_t Completed = 0;
210 while (Completed <
static_cast<ssize_t
>(
Size)) {
211 ssize_t Written =
::write(OutFD, Src + Completed,
Size - Completed);
214 if (ErrNo == EAGAIN || ErrNo == EINTR)
219 Completed += Written;
224void FDSimpleRemoteEPCTransport::listenLoop() {
228 char HeaderBuffer[FDMsgHeader::Size];
232 if (
auto Err2 = readBytes(HeaderBuffer, FDMsgHeader::Size, &IsEOF)) {
233 Err =
joinErrors(std::move(Err), std::move(Err2));
244 ExecutorAddr TagAddr;
255 if (MsgSize < FDMsgHeader::Size) {
265 if (
auto Err2 = readBytes(ArgBytes.data(), ArgBytes.size())) {
266 Err =
joinErrors(std::move(Err), std::move(Err2));
271 C.handleMessage(OpC, SeqNo, TagAddr, std::move(ArgBytes))) {
275 Err =
joinErrors(std::move(Err), Action.takeError());
285 C.handleDisconnect(std::move(Err));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Represents an address in the executor process.
uint64_t getValue() const
void disconnect() override
Trigger disconnection from the 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).
Error start() override
Called during setup of the client to indicate that the client is ready to receive messages.
Error sendMessage(SimpleRemoteEPCOpcode OpC, uint64_t SeqNo, ExecutorAddr TagAddr, ArrayRef< char > ArgBytes) override
Send a SimpleRemoteEPC message.
~FDSimpleRemoteEPCTransport() override
virtual ~SimpleRemoteEPCTransportClient()
virtual ~SimpleRemoteEPCTransport()
A utility class for serializing to a blob from a variadic list.
Output char buffer with overflow check.
C++ wrapper function buffer: Same as CWrapperFunctionBuffer but auto-releases memory.
const char * getOutOfBandError() const
If this value is an out-of-band error then this returns the error message, otherwise returns nullptr.
size_t size() const
Returns the size of the data contained in this instance.
char * data()
Get a pointer to the data contained in this instance.
static WrapperFunctionBuffer allocate(size_t Size)
Create a WrapperFunctionBuffer with the given size and return a pointer to the underlying memory.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI const char * DispatchFnName
LLVM_ABI const char * ExecutorSessionObjectName
SPSSerializableError toSPSSerializable(Error Err)
Error fromSPSSerializable(SPSSerializableError BSE)
LLVM_ABI shared::WrapperFunctionBuffer encodeHangupPayload(Error Err)
Encode an Error as the payload of a Hangup message.
LLVM_ABI Error decodeHangupPayload(shared::WrapperFunctionBuffer Payload)
Decode a Hangup payload produced by encodeHangupPayload.
static Error makeUnexpectedEOFError()
detail::packed_endian_specific_integral< uint64_t, llvm::endianness::little, unaligned > ulittle64_t
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error joinErrors(Error E1, Error E2)
Concatenate errors.
@ Success
The lock was released successfully.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
LLVM_ABI Error write(DWPWriter &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue, raw_pwrite_stream *OS=nullptr)
Helper type for serializing Errors.