summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/posix/PipePosix.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2014-10-08 20:38:41 +0000
committerZachary Turner <zturner@google.com>2014-10-08 20:38:41 +0000
commitb2df30d6521069cb2f655213a1b31040f82ee7c3 (patch)
treec9b4d248569c80c5c19a8ec3caaabd5069ee0c8a /lldb/source/Host/posix/PipePosix.cpp
parent1947f863efd83ce21f7e7d99ed69b95a484d4a84 (diff)
downloadbcm5719-llvm-b2df30d6521069cb2f655213a1b31040f82ee7c3.tar.gz
bcm5719-llvm-b2df30d6521069cb2f655213a1b31040f82ee7c3.zip
Fix deadlock in Python one-line execution.
Python one-line execution was using ConnectionFileDescriptor to do a non-blocking read against a pipe. This won't work on Windows, as CFD is implemented using select(), and select() only works with sockets on Windows. The solution is to use ConnectionGenericFile on Windows, which uses the native API to do overlapped I/O on the pipe. This in turn requires re-implementing Host::Pipe on Windows using native OS handles instead of the more portable _pipe CRT api. Reviewed by: Greg Clayton Differential Revision: http://reviews.llvm.org/D5679 llvm-svn: 219339
Diffstat (limited to 'lldb/source/Host/posix/PipePosix.cpp')
-rw-r--r--lldb/source/Host/posix/PipePosix.cpp145
1 files changed, 145 insertions, 0 deletions
diff --git a/lldb/source/Host/posix/PipePosix.cpp b/lldb/source/Host/posix/PipePosix.cpp
new file mode 100644
index 00000000000..ebc2033268e
--- /dev/null
+++ b/lldb/source/Host/posix/PipePosix.cpp
@@ -0,0 +1,145 @@
+//===-- PipePosix.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Host/posix/PipePosix.h"
+
+#include <unistd.h>
+
+using namespace lldb_private;
+
+int Pipe::kInvalidDescriptor = -1;
+
+enum PIPES { READ, WRITE }; // Constants 0 and 1 for READ and WRITE
+
+Pipe::Pipe()
+{
+ m_fds[READ] = Pipe::kInvalidDescriptor;
+ m_fds[WRITE] = Pipe::kInvalidDescriptor;
+}
+
+Pipe::~Pipe()
+{
+ Close();
+}
+
+bool
+Pipe::Open()
+{
+ if (IsValid())
+ return true;
+
+ if (::pipe(m_fds) == 0)
+ return true;
+
+ m_fds[READ] = Pipe::kInvalidDescriptor;
+ m_fds[WRITE] = Pipe::kInvalidDescriptor;
+ return false;
+}
+
+int
+Pipe::GetReadFileDescriptor() const
+{
+ return m_fds[READ];
+}
+
+int
+Pipe::GetWriteFileDescriptor() const
+{
+ return m_fds[WRITE];
+}
+
+int
+Pipe::ReleaseReadFileDescriptor()
+{
+ const int fd = m_fds[READ];
+ m_fds[READ] = Pipe::kInvalidDescriptor;
+ return fd;
+}
+
+int
+Pipe::ReleaseWriteFileDescriptor()
+{
+ const int fd = m_fds[WRITE];
+ m_fds[WRITE] = Pipe::kInvalidDescriptor;
+ return fd;
+}
+
+void
+Pipe::Close()
+{
+ CloseReadFileDescriptor();
+ CloseWriteFileDescriptor();
+}
+
+bool
+Pipe::ReadDescriptorIsValid() const
+{
+ return m_fds[READ] != Pipe::kInvalidDescriptor;
+}
+
+bool
+Pipe::WriteDescriptorIsValid() const
+{
+ return m_fds[WRITE] != Pipe::kInvalidDescriptor;
+}
+
+bool
+Pipe::IsValid() const
+{
+ return ReadDescriptorIsValid() && WriteDescriptorIsValid();
+}
+
+bool
+Pipe::CloseReadFileDescriptor()
+{
+ if (ReadDescriptorIsValid())
+ {
+ int err;
+ err = close(m_fds[READ]);
+ m_fds[READ] = Pipe::kInvalidDescriptor;
+ return err == 0;
+ }
+ return true;
+}
+
+bool
+Pipe::CloseWriteFileDescriptor()
+{
+ if (WriteDescriptorIsValid())
+ {
+ int err;
+ err = close(m_fds[WRITE]);
+ m_fds[WRITE] = Pipe::kInvalidDescriptor;
+ return err == 0;
+ }
+ return true;
+}
+
+
+size_t
+Pipe::Read (void *buf, size_t num_bytes)
+{
+ if (ReadDescriptorIsValid())
+ {
+ const int fd = GetReadFileDescriptor();
+ return read (fd, buf, num_bytes);
+ }
+ return 0; // Return 0 since errno won't be set if we didn't call read
+}
+
+size_t
+Pipe::Write (const void *buf, size_t num_bytes)
+{
+ if (WriteDescriptorIsValid())
+ {
+ const int fd = GetWriteFileDescriptor();
+ return write (fd, buf, num_bytes);
+ }
+ return 0; // Return 0 since errno won't be set if we didn't call write
+}
OpenPOWER on IntegriCloud