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/Core/Communication.h"
30 #include "lldb/Core/Log.h"
33 using namespace lldb_private;
35 ConnectionSharedMemory::ConnectionSharedMemory () :
43 ConnectionSharedMemory::~ConnectionSharedMemory ()
49 ConnectionSharedMemory::IsConnected () const
55 ConnectionSharedMemory::Connect (const char *s, Error *error_ptr)
59 // if (strstr(s, "shm-create://"))
62 // else if (strstr(s, "shm-connect://"))
66 // error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
67 // return eConnectionStatusError;
70 error_ptr->SetErrorString("invalid connect arguments");
71 return eConnectionStatusError;
75 ConnectionSharedMemory::Disconnect (Error *error_ptr)
84 shm_unlink (m_name.c_str());
88 return eConnectionStatusSuccess;
92 ConnectionSharedMemory::Read (void *dst,
94 uint32_t timeout_usec,
95 ConnectionStatus &status,
98 status = eConnectionStatusSuccess;
103 ConnectionSharedMemory::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
105 status = eConnectionStatusSuccess;
110 ConnectionSharedMemory::GetURI()
112 // TODO: fix when Connect is fixed?
117 ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
119 return eConnectionStatusLostConnection;
123 ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error *error_ptr)
128 error_ptr->SetErrorString("already open");
129 return eConnectionStatusError;
132 m_name.assign (name);
137 handle = CreateFileMapping(
138 INVALID_HANDLE_VALUE,
146 handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
148 m_fd = _open_osfhandle((intptr_t)handle, 0);
153 m_fd = ::shm_open (m_name.c_str(), oflag, S_IRUSR|S_IWUSR);
156 ::ftruncate (m_fd, size);
159 if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
160 return eConnectionStatusSuccess;
163 return eConnectionStatusError;
166 #endif // __ANDROID_NDK__