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. Even though it may be possible
104 /// for a 32-bit host debugger to debug a 64-bit target, size_t
105 /// still dictates the maximum possible size that can be mapped
106 /// into this process. For this kind of cross-arch debugging
107 /// scenario, mappings and views should be managed at a higher
111 /// The number of bytes mapped starting from the \a offset.
112 //------------------------------------------------------------------
114 MemoryMapFromFileSpec (const FileSpec* file,
115 lldb::offset_t offset = 0,
116 size_t length = SIZE_MAX,
117 bool writeable = false);
119 //------------------------------------------------------------------
120 /// Memory map all or part of a file.
122 /// Memory map \a length bytes from an opened file descriptor \a fd
123 /// starting \a offset bytes into the file. If \a length is set to
124 /// \c SIZE_MAX, then map as many bytes as possible.
127 /// The posix file descriptor for an already opened file
128 /// from which to map data.
130 /// @param[in] offset
131 /// The offset in bytes from the beginning of the file where
132 /// memory mapping should begin.
134 /// @param[in] length
135 /// The size in bytes that should be mapped starting \a offset
136 /// bytes into the file. If \a length is \c SIZE_MAX, map
137 /// as many bytes as possible.
140 /// The number of bytes mapped starting from the \a offset.
141 //------------------------------------------------------------------
143 MemoryMapFromFileDescriptor (int fd,
144 lldb::offset_t offset,
150 //------------------------------------------------------------------
151 // Classes that inherit from DataBufferMemoryMap can see and modify these
152 //------------------------------------------------------------------
153 uint8_t * m_mmap_addr; ///< The actual pointer that was returned from \c mmap()
154 size_t m_mmap_size; ///< The actual number of bytes that were mapped when \c mmap() was called
155 uint8_t *m_data; ///< The data the user requested somewhere within the memory mapped data.
156 lldb::offset_t m_size; ///< The size of the data the user got when data was requested
159 DISALLOW_COPY_AND_ASSIGN (DataBufferMemoryMap);
162 } // namespace lldb_private
164 #endif // #if defined(__cplusplus)
165 #endif // liblldb_DataBufferMemoryMap_h_