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#if LLVM_ENABLE_THREADS
64 std::unique_ptr<FDSimpleRemoteEPCTransport> FDT(
65 new FDSimpleRemoteEPCTransport(C, InFD, OutFD));
66 return std::move(FDT);
69 "thread support, but llvm was built with "
70 "LLVM_ENABLE_THREADS=Off",
76#if LLVM_ENABLE_THREADS
77 ListenerThread.join();
82#if LLVM_ENABLE_THREADS
83 ListenerThread = std::thread([
this]() { listenLoop(); });
93 char HeaderBuffer[FDMsgHeader::Size];
96 FDMsgHeader::Size + ArgBytes.
size();
103 std::lock_guard<std::mutex> Lock(M);
107 if (
int ErrNo = writeBytes(HeaderBuffer, FDMsgHeader::Size))
109 if (
int ErrNo = writeBytes(ArgBytes.
data(), ArgBytes.
size()))
119 bool CloseOutFD = InFD != OutFD;
126 ::shutdown(InFD, CloseOutFD ? SHUT_RD : SHUT_RDWR);
129 while (close(InFD) == -1) {
138 ::shutdown(OutFD, SHUT_WR);
140 while (close(OutFD) == -1) {
152Error FDSimpleRemoteEPCTransport::readBytes(
char *Dst,
size_t Size,
154 assert((
Size == 0 || Dst) &&
"Attempt to read into null.");
155 ssize_t Completed = 0;
156 while (Completed <
static_cast<ssize_t
>(
Size)) {
157 ssize_t
Read = ::read(InFD, Dst + Completed,
Size - Completed);
161 if (Completed == 0 && IsEOF) {
166 }
else if (ErrNo == EAGAIN || ErrNo == EINTR)
169 std::lock_guard<std::mutex> Lock(M);
170 if (Disconnected && IsEOF) {
175 std::error_code(ErrNo, std::generic_category()));
183int FDSimpleRemoteEPCTransport::writeBytes(
const char *Src,
size_t Size) {
184 assert((
Size == 0 || Src) &&
"Attempt to append from null.");
185 ssize_t Completed = 0;
186 while (Completed <
static_cast<ssize_t
>(
Size)) {
187 ssize_t Written =
::write(OutFD, Src + Completed,
Size - Completed);
190 if (ErrNo == EAGAIN || ErrNo == EINTR)
195 Completed += Written;
200void FDSimpleRemoteEPCTransport::listenLoop() {
204 char HeaderBuffer[FDMsgHeader::Size];
208 if (
auto Err2 = readBytes(HeaderBuffer, FDMsgHeader::Size, &IsEOF)) {
209 Err =
joinErrors(std::move(Err), std::move(Err2));
220 ExecutorAddr TagAddr;
231 if (MsgSize < FDMsgHeader::Size) {
241 if (
auto Err2 = readBytes(ArgBytes.data(), ArgBytes.size())) {
242 Err =
joinErrors(std::move(Err), std::move(Err2));
247 C.handleMessage(OpC, SeqNo, TagAddr, std::move(ArgBytes))) {
251 Err =
joinErrors(std::move(Err), Action.takeError());
261 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()
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
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.
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)