ROSE
0.9.6a
|
A contiguous, homogeneous region of an address space. More...
#include <MemoryMap.h>
Public Member Functions | |
Segment () | |
Segment (const BufferPtr &buffer, rose_addr_t offset, unsigned perms, std::string name="") | |
Constructor. More... | |
bool | check (const Extent &range, rose_addr_t *first_bad_va=NULL) const |
Check segment-buffer compatibility. More... | |
bool | operator== (const Segment &other) const |
Segment equality. More... | |
BufferPtr | get_buffer () const |
Underlying buffer. More... | |
void | set_buffer (const BufferPtr &b) |
Underlying buffer. More... | |
unsigned | get_mapperms () const |
Mapping permissions. More... | |
void | set_mapperms (unsigned p) |
Mapping permissions. More... | |
rose_addr_t | get_buffer_offset () const |
Offset with respect to underlying Buffer. More... | |
rose_addr_t | get_buffer_offset (const Extent &my_range, rose_addr_t va) const |
Offset with respect to underlying Buffer. More... | |
void | set_buffer_offset (rose_addr_t n) |
Offset with respect to underlying Buffer. More... | |
bool | is_cow () const |
Copy on write property. More... | |
void | set_cow (bool b=true) |
Copy on write property. More... | |
void | clear_cow () |
Copy on write property. More... | |
const std::string & | get_name () const |
Name for debugging. More... | |
void | set_name (const std::string &s) |
Name for debugging. More... | |
Private Types | |
typedef std::map< std::string, std::set< std::string > > | NamePairings |
Private Member Functions | |
void | merge_names (const Segment &other) |
std::string | get_name_pairings (NamePairings *) const |
void | set_name (const NamePairings &, const std::string &s1, const std::string &s2) |
void | removing (const Extent &range) |
void | truncate (const Extent &range, rose_addr_t new_end) |
bool | merge (const Extent &range, const Extent &other_range, const Segment &other_segment) |
Segment | split (const Extent &range, rose_addr_t new_end) |
void | print (std::ostream &) const |
Private Attributes | |
BufferPtr | buffer |
The buffer holding data for this segment. More... | |
rose_addr_t | buffer_offset |
Starting byte offset into the buffer. More... | |
unsigned | mapperms |
Permissions for this segment. More... | |
std::string | name |
Name used for debugging purposes. More... | |
bool | copy_on_write |
Does the buffer need to be copied on the next write operation? More... | |
Friends | |
class | RangeMap< Extent, Segment > |
std::ostream & | operator<< (std::ostream &, const Segment &) |
A contiguous, homogeneous region of an address space.
A Segment is a contiguous region of the address space that does not overlap with any other segment of the address space, and which corresponds with (part of) a single MemoryMap::Buffer object. The addresses described by a Segment all have the same set of properties, such as the permission properties.
A segment doesn't know to which part of the virtual memory address space it's mapped–that's the responsibility of the MemoryMap class and the RangeMap on which it's implemented.
Segments reference count the MemoryMap::Buffer objects to which they point.
Definition at line 298 of file MemoryMap.h.
|
private |
Definition at line 376 of file MemoryMap.h.
|
inline |
Definition at line 300 of file MemoryMap.h.
|
inline |
Constructor.
Constructs a segment that points to a particular offset in a buffer. The segment also has certain access permissions.
Definition at line 304 of file MemoryMap.h.
|
inline |
Underlying buffer.
Every segment must point to some underlying buffer that contains the data for the segment. The addresses in the segment correspond 1:1 with the bytes in the buffer, although the segment's addresses can be shifted a constant offset within the buffer. All addresses defined by the segment must correspond to valid data elements within the buffer. Buffers are reference counted using boost::shared_ptr, so the caller should never free the buffer.
Definition at line 313 of file MemoryMap.h.
References buffer.
Referenced by MemoryMap::dump(), MemoryMap::erase_zeros(), merge(), operator==(), and MemoryMap::read1().
|
inline |
Underlying buffer.
Every segment must point to some underlying buffer that contains the data for the segment. The addresses in the segment correspond 1:1 with the bytes in the buffer, although the segment's addresses can be shifted a constant offset within the buffer. All addresses defined by the segment must correspond to valid data elements within the buffer. Buffers are reference counted using boost::shared_ptr, so the caller should never free the buffer.
Definition at line 314 of file MemoryMap.h.
References buffer.
bool MemoryMap::Segment::check | ( | const Extent & | range, |
rose_addr_t * | first_bad_va = NULL |
||
) | const |
Check segment-buffer compatibility.
The segment is verified to point to a Buffer object and that the addresses specified in the given range
map to valid data in the buffer. Returns true if everything checks out, false otherwise.
This method is necessary because a Segment doesn't actually know its range of addresses. The association between address ranges and segments is managed by the MemoryMap object and the RangeMap on which it's based.
If the first_bad_va
pointer is non-null, then it will be initialized with the lowest address in range
which is invalid. The initialization only occurs when check() returns false.
Definition at line 365 of file MemoryMap.C.
References Range< T >::empty(), Range< T >::first(), and Range< T >::size().
Referenced by MemoryMap::read1().
|
inline |
Mapping permissions.
The mapping permissions are a bit vector of MemoryMap::Protection bits. These bits describe what operations can be performed on a segment's address space. The set of operations can be further restricted by the underlying Buffer object.
Definition at line 332 of file MemoryMap.h.
References mapperms.
Referenced by MemoryMap::erase_zeros(), MemoryMap::exists(), merge(), operator==(), MemoryMap::prune(), MemoryMap::read1(), and Disassembler::search_next_address().
|
inline |
Mapping permissions.
The mapping permissions are a bit vector of MemoryMap::Protection bits. These bits describe what operations can be performed on a segment's address space. The set of operations can be further restricted by the underlying Buffer object.
Definition at line 333 of file MemoryMap.h.
References mapperms.
Referenced by MemoryMap::mprotect().
|
inline |
Offset with respect to underlying Buffer.
The addresses of a segment correspond 1:1 with the bytes of the underlying Buffer object, but they can be shifted by a constant amount. The shift amount is measured as a byte offset from the beginning of the buffer.
When setting an offset, the new offset must be compatible with the underlying buffer. In other words, the addresses represented by the Segment must all continue to map to valid data locations in the buffer. The actual consistency check is delayed until an operation like read() or write() because we don't have all the necessary information at the time of the set_buffer_offset() call.
The two-argument version of get_buffer_offset() computes the buffer offset for a virtual address that must be within the range of virtual addresses represented by this segment.
Definition at line 348 of file MemoryMap.h.
References buffer_offset.
Referenced by merge(), MemoryMap::mprotect(), operator==(), and MemoryMap::read1().
rose_addr_t MemoryMap::Segment::get_buffer_offset | ( | const Extent & | my_range, |
rose_addr_t | va | ||
) | const |
Offset with respect to underlying Buffer.
The addresses of a segment correspond 1:1 with the bytes of the underlying Buffer object, but they can be shifted by a constant amount. The shift amount is measured as a byte offset from the beginning of the buffer.
When setting an offset, the new offset must be compatible with the underlying buffer. In other words, the addresses represented by the Segment must all continue to map to valid data locations in the buffer. The actual consistency check is delayed until an operation like read() or write() because we don't have all the necessary information at the time of the set_buffer_offset() call.
The two-argument version of get_buffer_offset() computes the buffer offset for a virtual address that must be within the range of virtual addresses represented by this segment.
Definition at line 387 of file MemoryMap.C.
References Range< T >::contains(), and Range< T >::first().
void MemoryMap::Segment::set_buffer_offset | ( | rose_addr_t | n) |
Offset with respect to underlying Buffer.
The addresses of a segment correspond 1:1 with the bytes of the underlying Buffer object, but they can be shifted by a constant amount. The shift amount is measured as a byte offset from the beginning of the buffer.
When setting an offset, the new offset must be compatible with the underlying buffer. In other words, the addresses represented by the Segment must all continue to map to valid data locations in the buffer. The actual consistency check is delayed until an operation like read() or write() because we don't have all the necessary information at the time of the set_buffer_offset() call.
The two-argument version of get_buffer_offset() computes the buffer offset for a virtual address that must be within the range of virtual addresses represented by this segment.
Definition at line 394 of file MemoryMap.C.
References MemoryMap::size().
Referenced by MemoryMap::mprotect(), and split().
|
inline |
Copy on write property.
If the copy-on-write property is set then the next write operation on this segment will cause its buffer to be copied first. Once the buffer is copied the copy-on-write property is cleared. Doing a deep copy of a memory map will also clear the copy-on-write property in the new segments.
Definition at line 357 of file MemoryMap.h.
References copy_on_write.
|
inline |
Copy on write property.
If the copy-on-write property is set then the next write operation on this segment will cause its buffer to be copied first. Once the buffer is copied the copy-on-write property is cleared. Doing a deep copy of a memory map will also clear the copy-on-write property in the new segments.
Definition at line 358 of file MemoryMap.h.
References copy_on_write.
Referenced by clear_cow().
|
inline |
Copy on write property.
If the copy-on-write property is set then the next write operation on this segment will cause its buffer to be copied first. Once the buffer is copied the copy-on-write property is cleared. Doing a deep copy of a memory map will also clear the copy-on-write property in the new segments.
Definition at line 359 of file MemoryMap.h.
References set_cow().
bool MemoryMap::Segment::operator== | ( | const Segment & | other) | const |
Segment equality.
Segments are equal if they point to the same buffer, have the same buffer offset, and have the same permissions. Segment names are not used in the equality test.
Definition at line 537 of file MemoryMap.C.
References get_buffer(), get_buffer_offset(), and get_mapperms().
|
inline |
Name for debugging.
Definition at line 368 of file MemoryMap.h.
References name.
Referenced by merge_names().
|
inline |
|
private |
Definition at line 466 of file MemoryMap.C.
References MemoryMap::empty(), SageInterface::get_name(), get_name(), get_name_pairings(), and SageInterface::set_name().
|
private |
|
private |
Definition at line 447 of file MemoryMap.C.
References SageInterface::set_name().
|
private |
Definition at line 482 of file MemoryMap.C.
References Range< T >::empty().
|
private |
Definition at line 489 of file MemoryMap.C.
References Range< T >::first(), and Range< T >::last().
|
private |
Definition at line 496 of file MemoryMap.C.
References Range< T >::abuts_gt(), Range< T >::abuts_lt(), Range< T >::empty(), Range< T >::first(), get_buffer(), get_buffer_offset(), get_mapperms(), and Range< T >::last().
|
private |
Definition at line 528 of file MemoryMap.C.
References Range< T >::first(), and set_buffer_offset().
|
private |
Definition at line 545 of file MemoryMap.C.
References StringUtility::addrToString(), MemoryMap::empty(), escapeString(), SageInterface::get_name(), MemoryMap::MM_PROT_EXEC, MemoryMap::MM_PROT_PRIVATE, MemoryMap::MM_PROT_READ, MemoryMap::MM_PROT_WRITE, and name.
Referenced by operator<<().
Definition at line 382 of file MemoryMap.h.
|
friend |
Definition at line 36 of file MemoryMap.C.
|
private |
The buffer holding data for this segment.
Definition at line 390 of file MemoryMap.h.
Referenced by get_buffer(), and set_buffer().
|
private |
Starting byte offset into the buffer.
Definition at line 391 of file MemoryMap.h.
Referenced by get_buffer_offset().
|
private |
Permissions for this segment.
Definition at line 392 of file MemoryMap.h.
Referenced by get_mapperms(), and set_mapperms().
|
private |
Name used for debugging purposes.
Definition at line 393 of file MemoryMap.h.
Referenced by get_name(), and set_name().
|
private |
Does the buffer need to be copied on the next write operation?
Definition at line 394 of file MemoryMap.h.