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 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/ConnectionSharedMemory.h"
16 #include "lldb/Host/windows/windows.h"
21 #include <sys/types.h>
25 // Other libraries and framework includes
27 #include "lldb/lldb-private-log.h"
28 #include "lldb/Core/Communication.h"
29 #include "lldb/Core/Log.h"
32 using namespace lldb_private;
34 ConnectionSharedMemory::ConnectionSharedMemory () :
42 ConnectionSharedMemory::~ConnectionSharedMemory ()
48 ConnectionSharedMemory::IsConnected () const
54 ConnectionSharedMemory::Connect (const char *s, Error *error_ptr)
58 // if (strstr(s, "shm-create://"))
61 // else if (strstr(s, "shm-connect://"))
65 // error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
66 // return eConnectionStatusError;
69 error_ptr->SetErrorString("invalid connect arguments");
70 return eConnectionStatusError;
74 ConnectionSharedMemory::Disconnect (Error *error_ptr)
83 shm_unlink (m_name.c_str());
87 return eConnectionStatusSuccess;
91 ConnectionSharedMemory::Read (void *dst,
93 uint32_t timeout_usec,
94 ConnectionStatus &status,
97 status = eConnectionStatusSuccess;
102 ConnectionSharedMemory::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
104 status = eConnectionStatusSuccess;
109 ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
111 return eConnectionStatusLostConnection;
115 ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error *error_ptr)
120 error_ptr->SetErrorString("already open");
121 return eConnectionStatusError;
124 m_name.assign (name);
129 handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, (DWORD)(size >> 32), (DWORD)(size), name);
131 handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
133 m_fd = _open_osfhandle((intptr_t)handle, 0);
138 m_fd = ::shm_open (m_name.c_str(), oflag, S_IRUSR|S_IWUSR);
141 ::ftruncate (m_fd, size);
144 if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
145 return eConnectionStatusSuccess;
148 return eConnectionStatusError;