ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MemoryMap::Segment Class Reference

A contiguous, homogeneous region of an address space. More...

#include <MemoryMap.h>

Collaboration diagram for MemoryMap::Segment:

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 &)
 

Detailed Description

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.

Member Typedef Documentation

typedef std::map<std::string, std::set<std::string> > MemoryMap::Segment::NamePairings
private

Definition at line 376 of file MemoryMap.h.

Constructor & Destructor Documentation

MemoryMap::Segment::Segment ( )
inline

Definition at line 300 of file MemoryMap.h.

MemoryMap::Segment::Segment ( const BufferPtr buffer,
rose_addr_t  offset,
unsigned  perms,
std::string  name = "" 
)
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.

Member Function Documentation

BufferPtr MemoryMap::Segment::get_buffer ( ) const
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().

void MemoryMap::Segment::set_buffer ( const BufferPtr b)
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().

unsigned MemoryMap::Segment::get_mapperms ( ) const
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().

void MemoryMap::Segment::set_mapperms ( unsigned  p)
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().

rose_addr_t MemoryMap::Segment::get_buffer_offset ( ) const
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().

bool MemoryMap::Segment::is_cow ( ) const
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.

void MemoryMap::Segment::set_cow ( bool  b = true)
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().

void MemoryMap::Segment::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().

const std::string& MemoryMap::Segment::get_name ( ) const
inline

Name for debugging.

Definition at line 368 of file MemoryMap.h.

References name.

Referenced by merge_names().

void MemoryMap::Segment::set_name ( const std::string &  s)
inline

Name for debugging.

Definition at line 369 of file MemoryMap.h.

References name.

void MemoryMap::Segment::merge_names ( const Segment other)
private
std::string MemoryMap::Segment::get_name_pairings ( NamePairings pairings) const
private

Definition at line 401 of file MemoryMap.C.

References name.

Referenced by merge_names().

void MemoryMap::Segment::set_name ( const NamePairings pairings,
const std::string &  s1,
const std::string &  s2 
)
private

Definition at line 447 of file MemoryMap.C.

References SageInterface::set_name().

void MemoryMap::Segment::removing ( const Extent range)
private

Definition at line 482 of file MemoryMap.C.

References Range< T >::empty().

void MemoryMap::Segment::truncate ( const Extent range,
rose_addr_t  new_end 
)
private

Definition at line 489 of file MemoryMap.C.

References Range< T >::first(), and Range< T >::last().

bool MemoryMap::Segment::merge ( const Extent range,
const Extent other_range,
const Segment other_segment 
)
private
MemoryMap::Segment MemoryMap::Segment::split ( const Extent range,
rose_addr_t  new_end 
)
private

Definition at line 528 of file MemoryMap.C.

References Range< T >::first(), and set_buffer_offset().

void MemoryMap::Segment::print ( std::ostream &  o) const
private

Friends And Related Function Documentation

friend class RangeMap< Extent, Segment >
friend

Definition at line 382 of file MemoryMap.h.

std::ostream& operator<< ( std::ostream &  o,
const Segment x 
)
friend

Definition at line 36 of file MemoryMap.C.

Member Data Documentation

BufferPtr MemoryMap::Segment::buffer
private

The buffer holding data for this segment.

Definition at line 390 of file MemoryMap.h.

Referenced by get_buffer(), and set_buffer().

rose_addr_t MemoryMap::Segment::buffer_offset
private

Starting byte offset into the buffer.

Definition at line 391 of file MemoryMap.h.

Referenced by get_buffer_offset().

unsigned MemoryMap::Segment::mapperms
private

Permissions for this segment.

Definition at line 392 of file MemoryMap.h.

Referenced by get_mapperms(), and set_mapperms().

std::string MemoryMap::Segment::name
private

Name used for debugging purposes.

Definition at line 393 of file MemoryMap.h.

Referenced by get_name(), and set_name().

bool MemoryMap::Segment::copy_on_write
private

Does the buffer need to be copied on the next write operation?

Definition at line 394 of file MemoryMap.h.

Referenced by is_cow(), and set_cow().


The documentation for this class was generated from the following files: