1 //===-- DataBufferMemoryMap.h -----------------------------------*- 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 #ifndef liblldb_DataBufferMemoryMap_h_
11 #define liblldb_DataBufferMemoryMap_h_
12 #if defined(__cplusplus)
15 #include "lldb/lldb-private.h"
16 #include "lldb/Core/DataBuffer.h"
17 #include "lldb/Core/Error.h"
20 namespace lldb_private {
22 //----------------------------------------------------------------------
23 /// @class DataBufferMemoryMap DataBufferMemoryMap.h "lldb/Core/DataBufferMemoryMap.h"
24 /// @brief A subclass of DataBuffer that memory maps data.
26 /// This class memory maps data and stores any needed data for the
27 /// memory mapping in its internal state. Memory map requests are not
28 /// required to have any alignment or size constraints, this class will
29 /// work around any host OS issues regarding such things.
31 /// This class is designed to allow pages to be faulted in as needed and
32 /// works well data from large files that won't be accessed all at once.
33 //----------------------------------------------------------------------
34 class DataBufferMemoryMap : public DataBuffer
37 //------------------------------------------------------------------
38 /// Default Constructor
39 //------------------------------------------------------------------
40 DataBufferMemoryMap ();
42 //------------------------------------------------------------------
45 /// Virtual destructor since this class inherits from a pure virtual
46 /// base class #DataBuffer.
47 //------------------------------------------------------------------
49 ~DataBufferMemoryMap ();
51 //------------------------------------------------------------------
52 /// Reverts this object to an empty state by unmapping any memory
53 /// that is currently owned.
54 //------------------------------------------------------------------
58 //------------------------------------------------------------------
59 /// @copydoc DataBuffer::GetBytes()
60 //------------------------------------------------------------------
64 //------------------------------------------------------------------
65 /// @copydoc DataBuffer::GetBytes() const
66 //------------------------------------------------------------------
67 virtual const uint8_t *
70 //------------------------------------------------------------------
71 /// @copydoc DataBuffer::GetByteSize() const
72 //------------------------------------------------------------------
73 virtual lldb::offset_t
76 //------------------------------------------------------------------
77 /// Error get accessor.
80 /// A const reference to Error object in case memory mapping
82 //------------------------------------------------------------------
86 //------------------------------------------------------------------
87 /// Memory map all or part of a file.
89 /// Memory map \a length bytes from \a file starting \a offset
90 /// bytes into the file. If \a length is set to \c SIZE_MAX,
91 /// then map as many bytes as possible.
94 /// The file specification from which to map data.
97 /// The offset in bytes from the beginning of the file where
98 /// memory mapping should begin.
100 /// @param[in] length
101 /// The size in bytes that should be mapped starting \a offset
102 /// bytes into the file. If \a length is \c SIZE_MAX, map
103 /// as many bytes as possible.
106 /// The number of bytes mapped starting from the \a offset.
107 //------------------------------------------------------------------
109 MemoryMapFromFileSpec (const FileSpec* file,
110 lldb::offset_t offset = 0,
111 lldb::offset_t length = SIZE_MAX,
112 bool writeable = false);
114 //------------------------------------------------------------------
115 /// Memory map all or part of a file.
117 /// Memory map \a length bytes from an opened file descriptor \a fd
118 /// starting \a offset bytes into the file. If \a length is set to
119 /// \c SIZE_MAX, then map as many bytes as possible.
122 /// The posix file descriptor for an already opened file
123 /// from which to map data.
125 /// @param[in] offset
126 /// The offset in bytes from the beginning of the file where
127 /// memory mapping should begin.
129 /// @param[in] length
130 /// The size in bytes that should be mapped starting \a offset
131 /// bytes into the file. If \a length is \c SIZE_MAX, map
132 /// as many bytes as possible.
135 /// The number of bytes mapped starting from the \a offset.
136 //------------------------------------------------------------------
138 MemoryMapFromFileDescriptor (int fd,
139 lldb::offset_t offset,
140 lldb::offset_t length,
145 //------------------------------------------------------------------
146 // Classes that inherit from DataBufferMemoryMap can see and modify these
147 //------------------------------------------------------------------
148 uint8_t * m_mmap_addr; ///< The actual pointer that was returned from \c mmap()
149 size_t m_mmap_size; ///< The actual number of bytes that were mapped when \c mmap() was called
150 uint8_t *m_data; ///< The data the user requested somewhere within the memory mapped data.
151 lldb::offset_t m_size; ///< The size of the data the user got when data was requested
154 DISALLOW_COPY_AND_ASSIGN (DataBufferMemoryMap);
157 } // namespace lldb_private
159 #endif // #if defined(__cplusplus)
160 #endif // liblldb_DataBufferMemoryMap_h_