forked from OSchip/llvm-project
[ORC] Move file-descriptor based raw byte channel into a public header.
This will enable re-use in other llvm tools.
This commit is contained in:
parent
989d8dc9fe
commit
eed19c8c7e
|
@ -0,0 +1,79 @@
|
||||||
|
//===- FDRawByteChannel.h - File descriptor based byte-channel -*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// File descriptor based RawByteChannel.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
|
||||||
|
#define LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
|
||||||
|
|
||||||
|
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER) && !defined(__MINGW32__)
|
||||||
|
#include <unistd.h>
|
||||||
|
#else
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
namespace orc {
|
||||||
|
namespace rpc {
|
||||||
|
|
||||||
|
/// RPC channel that reads from and writes from file descriptors.
|
||||||
|
class FDRawByteChannel final : public RawByteChannel {
|
||||||
|
public:
|
||||||
|
FDRawByteChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
|
||||||
|
|
||||||
|
llvm::Error readBytes(char *Dst, unsigned Size) override {
|
||||||
|
assert(Dst && "Attempt to read into null.");
|
||||||
|
ssize_t Completed = 0;
|
||||||
|
while (Completed < static_cast<ssize_t>(Size)) {
|
||||||
|
ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
|
||||||
|
if (Read <= 0) {
|
||||||
|
auto ErrNo = errno;
|
||||||
|
if (ErrNo == EAGAIN || ErrNo == EINTR)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
return llvm::errorCodeToError(
|
||||||
|
std::error_code(errno, std::generic_category()));
|
||||||
|
}
|
||||||
|
Completed += Read;
|
||||||
|
}
|
||||||
|
return llvm::Error::success();
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::Error appendBytes(const char *Src, unsigned Size) override {
|
||||||
|
assert(Src && "Attempt to append from null.");
|
||||||
|
ssize_t Completed = 0;
|
||||||
|
while (Completed < static_cast<ssize_t>(Size)) {
|
||||||
|
ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
|
||||||
|
if (Written < 0) {
|
||||||
|
auto ErrNo = errno;
|
||||||
|
if (ErrNo == EAGAIN || ErrNo == EINTR)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
return llvm::errorCodeToError(
|
||||||
|
std::error_code(errno, std::generic_category()));
|
||||||
|
}
|
||||||
|
Completed += Written;
|
||||||
|
}
|
||||||
|
return llvm::Error::success();
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::Error send() override { return llvm::Error::success(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int InFD, OutFD;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace rpc
|
||||||
|
} // namespace orc
|
||||||
|
} // namespace llvm
|
||||||
|
|
||||||
|
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_FDRAWBYTECHANNEL_H
|
|
@ -6,8 +6,8 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
|
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
|
||||||
#define LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
|
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
|
||||||
|
|
||||||
#include "llvm/ExecutionEngine/Orc/OrcError.h"
|
#include "llvm/ExecutionEngine/Orc/OrcError.h"
|
||||||
#include "llvm/Support/thread.h"
|
#include "llvm/Support/thread.h"
|
||||||
|
@ -699,4 +699,4 @@ public:
|
||||||
} // end namespace orc
|
} // end namespace orc
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // LLVM_EXECUTIONENGINE_ORC_RPCSERIALIZATION_H
|
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RPCSERIALIZATION_H
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RPCUTILS_H
|
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
|
||||||
#define LLVM_EXECUTIONENGINE_ORC_RPCUTILS_H
|
#define LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
@ -1684,4 +1684,4 @@ public:
|
||||||
} // end namespace orc
|
} // end namespace orc
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif
|
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RPCUTILS_H
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#ifndef LLVM_EXECUTIONENGINE_ORC_RAWBYTECHANNEL_H
|
#ifndef LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
|
||||||
#define LLVM_EXECUTIONENGINE_ORC_RAWBYTECHANNEL_H
|
#define LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
|
||||||
|
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h"
|
#include "llvm/ExecutionEngine/Orc/RPC/RPCSerialization.h"
|
||||||
|
@ -181,4 +181,4 @@ public:
|
||||||
} // end namespace orc
|
} // end namespace orc
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // LLVM_EXECUTIONENGINE_ORC_RAWBYTECHANNEL_H
|
#endif // LLVM_EXECUTIONENGINE_ORC_RPC_RAWBYTECHANNEL_H
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
|
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
|
||||||
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
|
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetServer.h"
|
||||||
|
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/DynamicLibrary.h"
|
#include "llvm/Support/DynamicLibrary.h"
|
||||||
#include "llvm/Support/Process.h"
|
#include "llvm/Support/Process.h"
|
||||||
|
@ -53,8 +54,9 @@ int main(int argc, char *argv[]) {
|
||||||
RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
|
RTDyldMemoryManager::deregisterEHFramesInProcess(Addr, Size);
|
||||||
};
|
};
|
||||||
|
|
||||||
FDRawChannel Channel(InFD, OutFD);
|
rpc::FDRawByteChannel Channel(InFD, OutFD);
|
||||||
typedef remote::OrcRemoteTargetServer<FDRawChannel, HostOrcArch> JITServer;
|
typedef remote::OrcRemoteTargetServer<rpc::FDRawByteChannel, HostOrcArch>
|
||||||
|
JITServer;
|
||||||
JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
|
JITServer Server(Channel, SymbolLookup, RegisterEHFrames, DeregisterEHFrames);
|
||||||
|
|
||||||
while (!Server.receivedTerminate())
|
while (!Server.receivedTerminate())
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
#ifndef LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
||||||
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
|
||||||
|
|
||||||
#include "llvm/ExecutionEngine/Orc/RPC/RawByteChannel.h"
|
#include "llvm/ExecutionEngine/Orc/RPC/FDRawByteChannel.h"
|
||||||
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
@ -23,55 +23,8 @@
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// RPC channel that reads from and writes from file descriptors.
|
|
||||||
class FDRawChannel final : public llvm::orc::rpc::RawByteChannel {
|
|
||||||
public:
|
|
||||||
FDRawChannel(int InFD, int OutFD) : InFD(InFD), OutFD(OutFD) {}
|
|
||||||
|
|
||||||
llvm::Error readBytes(char *Dst, unsigned Size) override {
|
|
||||||
assert(Dst && "Attempt to read into null.");
|
|
||||||
ssize_t Completed = 0;
|
|
||||||
while (Completed < static_cast<ssize_t>(Size)) {
|
|
||||||
ssize_t Read = ::read(InFD, Dst + Completed, Size - Completed);
|
|
||||||
if (Read <= 0) {
|
|
||||||
auto ErrNo = errno;
|
|
||||||
if (ErrNo == EAGAIN || ErrNo == EINTR)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
return llvm::errorCodeToError(
|
|
||||||
std::error_code(errno, std::generic_category()));
|
|
||||||
}
|
|
||||||
Completed += Read;
|
|
||||||
}
|
|
||||||
return llvm::Error::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::Error appendBytes(const char *Src, unsigned Size) override {
|
|
||||||
assert(Src && "Attempt to append from null.");
|
|
||||||
ssize_t Completed = 0;
|
|
||||||
while (Completed < static_cast<ssize_t>(Size)) {
|
|
||||||
ssize_t Written = ::write(OutFD, Src + Completed, Size - Completed);
|
|
||||||
if (Written < 0) {
|
|
||||||
auto ErrNo = errno;
|
|
||||||
if (ErrNo == EAGAIN || ErrNo == EINTR)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
return llvm::errorCodeToError(
|
|
||||||
std::error_code(errno, std::generic_category()));
|
|
||||||
}
|
|
||||||
Completed += Written;
|
|
||||||
}
|
|
||||||
return llvm::Error::success();
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::Error send() override { return llvm::Error::success(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
int InFD, OutFD;
|
|
||||||
};
|
|
||||||
|
|
||||||
// launch the remote process (see lli.cpp) and return a channel to it.
|
// launch the remote process (see lli.cpp) and return a channel to it.
|
||||||
std::unique_ptr<FDRawChannel> launchRemote();
|
std::unique_ptr<llvm::orc::rpc::FDRawByteChannel> launchRemote();
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
|
|
@ -674,7 +674,7 @@ int main(int argc, char **argv, char * const *envp) {
|
||||||
// MCJIT itself. FIXME.
|
// MCJIT itself. FIXME.
|
||||||
|
|
||||||
// Lanch the remote process and get a channel to it.
|
// Lanch the remote process and get a channel to it.
|
||||||
std::unique_ptr<FDRawChannel> C = launchRemote();
|
std::unique_ptr<orc::rpc::FDRawByteChannel> C = launchRemote();
|
||||||
if (!C) {
|
if (!C) {
|
||||||
WithColor::error(errs(), argv[0]) << "failed to launch remote JIT.\n";
|
WithColor::error(errs(), argv[0]) << "failed to launch remote JIT.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -1026,7 +1026,7 @@ void disallowOrcOptions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<FDRawChannel> launchRemote() {
|
std::unique_ptr<orc::rpc::FDRawByteChannel> launchRemote() {
|
||||||
#ifndef LLVM_ON_UNIX
|
#ifndef LLVM_ON_UNIX
|
||||||
llvm_unreachable("launchRemote not supported on non-Unix platforms");
|
llvm_unreachable("launchRemote not supported on non-Unix platforms");
|
||||||
#else
|
#else
|
||||||
|
@ -1076,6 +1076,7 @@ std::unique_ptr<FDRawChannel> launchRemote() {
|
||||||
close(PipeFD[1][1]);
|
close(PipeFD[1][1]);
|
||||||
|
|
||||||
// Return an RPC channel connected to our end of the pipes.
|
// Return an RPC channel connected to our end of the pipes.
|
||||||
return std::make_unique<FDRawChannel>(PipeFD[1][0], PipeFD[0][1]);
|
return std::make_unique<orc::rpc::FDRawByteChannel>(PipeFD[1][0],
|
||||||
|
PipeFD[0][1]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue