summaryrefslogtreecommitdiff
path: root/tools/lli/Unix/RemoteTargetExternal.inc
diff options
context:
space:
mode:
authorRenato Golin <renato.golin@linaro.org>2014-01-14 22:43:43 +0000
committerRenato Golin <renato.golin@linaro.org>2014-01-14 22:43:43 +0000
commit83ece7a4993edb295e71841bd51b298219186c4c (patch)
tree396a100a569c18057afe5c1ed288cabf65a2c0c0 /tools/lli/Unix/RemoteTargetExternal.inc
parent0445dc203b0e4001a153d9af4bd75f5242401d06 (diff)
downloadllvm-83ece7a4993edb295e71841bd51b298219186c4c.tar.gz
llvm-83ece7a4993edb295e71841bd51b298219186c4c.tar.bz2
llvm-83ece7a4993edb295e71841bd51b298219186c4c.tar.xz
Sanitize MCJIT remote execution
MCJIT remote execution (ChildTarget+RemoteTargetExternal) protocol was in dire need of refactoring. It was fail-prone, had no error reporting and implemented the same message logic on every single function. This patch rectifies it, and makes it work on ARM, where it was randomly failing. Other architectures shall profit from this change as well, making their buildbots and releases more reliable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199261 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli/Unix/RemoteTargetExternal.inc')
-rw-r--r--tools/lli/Unix/RemoteTargetExternal.inc49
1 files changed, 43 insertions, 6 deletions
diff --git a/tools/lli/Unix/RemoteTargetExternal.inc b/tools/lli/Unix/RemoteTargetExternal.inc
index 481c1d5156..ea8e4597d5 100644
--- a/tools/lli/Unix/RemoteTargetExternal.inc
+++ b/tools/lli/Unix/RemoteTargetExternal.inc
@@ -30,7 +30,7 @@ struct ConnectionData_t {
namespace llvm {
-void RemoteTargetExternal::create() {
+bool RemoteTargetExternal::create() {
int PipeFD[2][2];
pid_t ChildPID;
@@ -73,16 +73,53 @@ void RemoteTargetExternal::create() {
// Store the parent ends of the pipes
ConnectionData = (void*)new ConnectionData_t(PipeFD[1][0], PipeFD[0][1]);
- Receive(LLI_ChildActive);
+ // We must get Ack from the client (blocking read)
+ if (!Receive(LLI_ChildActive)) {
+ ErrorMsg += ", (RemoteTargetExternal::create) - Stopping process!";
+ stop();
+ return false;
+ }
+ }
+ return true;
+}
+
+static void ReportError(int rc, size_t Size, std::string &ErrorMsg) {
+ if (rc == -1) {
+ if (errno == EPIPE)
+ ErrorMsg += "pipe closed";
+ else if (errno == EINTR)
+ ErrorMsg += "interrupted";
+ else
+ ErrorMsg += "file descriptor error";
+ } else {
+ char Number[10] = { 0 };
+ ErrorMsg += "Expecting ";
+ sprintf(Number, "%d", (uint32_t)Size);
+ ErrorMsg += Number;
+ ErrorMsg += " bytes, Got ";
+ sprintf(Number, "%d", rc);
+ ErrorMsg += Number;
}
}
-int RemoteTargetExternal::WriteBytes(const void *Data, size_t Size) {
- return write(((ConnectionData_t*)ConnectionData)->OutputPipe, Data, Size);
+bool RemoteTargetExternal::WriteBytes(const void *Data, size_t Size) {
+ int rc = write(((ConnectionData_t*)ConnectionData)->OutputPipe, Data, Size);
+ if (rc != -1 && (size_t)rc == Size)
+ return true;
+
+ ErrorMsg = "WriteBytes: ";
+ ReportError(rc, Size, ErrorMsg);
+ return false;
}
-int RemoteTargetExternal::ReadBytes(void *Data, size_t Size) {
- return read(((ConnectionData_t*)ConnectionData)->InputPipe, Data, Size);
+bool RemoteTargetExternal::ReadBytes(void *Data, size_t Size) {
+ int rc = read(((ConnectionData_t*)ConnectionData)->InputPipe, Data, Size);
+ if (rc != -1 && (size_t)rc == Size)
+ return true;
+
+ ErrorMsg = "ReadBytes: ";
+ ReportError(rc, Size, ErrorMsg);
+ return false;
}
void RemoteTargetExternal::Wait() {