1 //===-- ConnectionSharedMemory.cpp ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 #ifndef __ANDROID_NDK__
11 #include "lldb/Core/ConnectionSharedMemory.h"
17 #include "lldb/Host/windows/windows.h"
22 #include <sys/types.h>
26 // Other libraries and framework includes
28 #include "llvm/Support/MathExtras.h"
29 #include "lldb/lldb-private-log.h"
30 #include "lldb/Core/Communication.h"
31 #include "lldb/Core/Log.h"
34 using namespace lldb_private;
36 ConnectionSharedMemory::ConnectionSharedMemory () :
44 ConnectionSharedMemory::~ConnectionSharedMemory ()
50 ConnectionSharedMemory::IsConnected () const
56 ConnectionSharedMemory::Connect (const char *s, Error *error_ptr)
60 // if (strstr(s, "shm-create://"))
63 // else if (strstr(s, "shm-connect://"))
67 // error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
68 // return eConnectionStatusError;
71 error_ptr->SetErrorString("invalid connect arguments");
72 return eConnectionStatusError;
76 ConnectionSharedMemory::Disconnect (Error *error_ptr)
85 shm_unlink (m_name.c_str());
89 return eConnectionStatusSuccess;
93 ConnectionSharedMemory::Read (void *dst,
95 uint32_t timeout_usec,
96 ConnectionStatus &status,
99 status = eConnectionStatusSuccess;
104 ConnectionSharedMemory::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
106 status = eConnectionStatusSuccess;
111 ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
113 return eConnectionStatusLostConnection;
117 ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error *error_ptr)
122 error_ptr->SetErrorString("already open");
123 return eConnectionStatusError;
126 m_name.assign (name);
131 handle = CreateFileMapping(
132 INVALID_HANDLE_VALUE,
140 handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
142 m_fd = _open_osfhandle((intptr_t)handle, 0);
147 m_fd = ::shm_open (m_name.c_str(), oflag, S_IRUSR|S_IWUSR);
150 ::ftruncate (m_fd, size);
153 if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
154 return eConnectionStatusSuccess;
157 return eConnectionStatusError;
160 #endif // __ANDROID_NDK__