ROSE  0.11.145.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState Class Referenceabstract

Description

Represents all memory in the state.

MemoryState objects are allocated on the heap and reference counted. The BaseSemantics::MemoryState is an abstract class that defines the interface. See the Rose::BinaryAnalysis::InstructionSemantics namespace for an overview of how the parts fit together.

Definition at line 25 of file MemoryState.h.

#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryState.h>

Inheritance diagram for Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState:
Inheritance graph
[legend]
Collaboration diagram for Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState:
Collaboration graph
[legend]

Classes

class  WithFormatter
 MemoryState with formatter. More...
 

Public Types

typedef MemoryStatePtr Ptr
 Shared-ownership pointer. More...
 

Public Member Functions

virtual MemoryStatePtr create (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const =0
 Virtual allocating constructor. More...
 
virtual MemoryStatePtr clone () const =0
 Virtual allocating copy constructor. More...
 
SValuePtr get_addr_protoval () const
 Return the address protoval. More...
 
SValuePtr get_val_protoval () const
 Return the value protoval. More...
 
virtual void clear ()=0
 Clear memory. More...
 
virtual bool merge (const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps)=0
 Merge memory states for data flow analysis. More...
 
virtual SValuePtr readMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
 Read a value from memory. More...
 
virtual SValuePtr peekMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps)=0
 Read a value from memory without side effects. More...
 
virtual void writeMemory (const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps)=0
 Write a value to memory. More...
 
virtual void hash (Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const =0
 Calculate a hash for this memory state. More...
 
MergerPtr merger () const
 Property: Merger. More...
 
void merger (const MergerPtr &)
 Property: Merger. More...
 
bool byteRestricted () const
 Indicates whether memory cell values are required to be eight bits wide. More...
 
void byteRestricted (bool)
 Indicates whether memory cell values are required to be eight bits wide. More...
 
ByteOrder::Endianness get_byteOrder () const
 Memory byte order.
 
void set_byteOrder (ByteOrder::Endianness)
 Memory byte order.
 
void print (std::ostream &, const std::string prefix="") const
 Print a memory state to more than one line of output.
 
virtual void print (std::ostream &, Formatter &) const =0
 Print a memory state to more than one line of output.
 
WithFormatter with_format (Formatter &)
 Used for printing memory states with formatting. More...
 
WithFormatter operator+ (Formatter &)
 Used for printing memory states with formatting. More...
 
WithFormatter operator+ (const std::string &linePrefix)
 Used for printing memory states with formatting. More...
 

Static Public Member Functions

static MemoryStatePtr promote (const MemoryStatePtr &)
 

Protected Member Functions

 MemoryState (const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
 
 MemoryState (const MemoryStatePtr &other)
 

Member Typedef Documentation

Shared-ownership pointer.

Definition at line 28 of file MemoryState.h.

Member Function Documentation

virtual MemoryStatePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::create ( const SValuePtr addrProtoval,
const SValuePtr valProtoval 
) const
pure virtual

Virtual allocating constructor.

Allocates and constructs a new MemoryState object having the same dynamic type as this object. A prototypical SValue must be supplied and will be used to construct any additional SValue objects needed during the operation of a MemoryState. Two prototypical values are supplied, one for addresses and another for values stored at those addresses, although they will almost always be the same.

Implemented in Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryMapState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList, and Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::SymbolicMemory.

virtual MemoryStatePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::clone ( ) const
pure virtual
MergerPtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::merger ( ) const

Property: Merger.

This property is optional details about how to merge two states. It is passed down to the register and memory state merge operation and to the semantic value merge operation. Users can subclass this to hold whatever information is necessary for merging. Unless the user overrides merge functions to do something else, all merging will use the same merger object – the one set for this property.

void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::merger ( const MergerPtr )

Property: Merger.

This property is optional details about how to merge two states. It is passed down to the register and memory state merge operation and to the semantic value merge operation. Users can subclass this to hold whatever information is necessary for merging. Unless the user overrides merge functions to do something else, all merging will use the same merger object – the one set for this property.

SValuePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::get_addr_protoval ( ) const

Return the address protoval.

The address protoval is used to construct other memory addresses via its virtual constructors.

SValuePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::get_val_protoval ( ) const

Return the value protoval.

The value protoval is used to construct other stored values via its virtual constructors.

virtual void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::clear ( )
pure virtual
bool Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::byteRestricted ( ) const

Indicates whether memory cell values are required to be eight bits wide.

The default is true since this simplifies the calculations for whether two memory cells are alias and how to combine the value from two or more aliasing cells. A memory that contains only eight-bit values requires that the caller concatenate/extract individual bytes when reading/writing multi-byte values.

void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::byteRestricted ( bool  )

Indicates whether memory cell values are required to be eight bits wide.

The default is true since this simplifies the calculations for whether two memory cells are alias and how to combine the value from two or more aliasing cells. A memory that contains only eight-bit values requires that the caller concatenate/extract individual bytes when reading/writing multi-byte values.

virtual bool Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::merge ( const MemoryStatePtr other,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual
virtual SValuePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::readMemory ( const SValuePtr address,
const SValuePtr dflt,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual

Read a value from memory.

Consults the memory represented by this MemoryState object and returns a semantic value. Depending on the semantic domain, the value can be a value that is already stored in the memory state, a supplied default value, a new value constructed from some combination of existing values and/or the default value, or anything else. For instance, in a symbolic domain the address could alias multiple existing memory locations and the implementation may choose to return a McCarthy expression. Additional data (such as SMT solvers) may be passed via the RiscOperators argument.

The size of the value being read does not necessarily need to be equal to the size of values stored in the memory state, though it typically is(1). For instance, an implementation may allow reading a 32-bit little endian value from a memory state that stores only bytes. A RiscOperators object is provided for use in these situations.

In order to support cases where an address does not match any existing location, the dflt value can be used to initialize a new memory location. The manner in which the default is used depends on the implementation. In any case, the width of the dflt value determines how much to read.

Footnote 1: A MemoryState::readMemory() call is the last in a sequence of delegations starting with RiscOperators::readMemory(). The designers of the MemoryState, State, and RiscOperators subclasses will need to coordinate to decide which layer should handle concatenating values from individual memory locations.

Implemented in Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellMap, and Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::SymbolicMemory.

virtual SValuePtr Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::peekMemory ( const SValuePtr address,
const SValuePtr dflt,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual
virtual void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::writeMemory ( const SValuePtr addr,
const SValuePtr value,
RiscOperators addrOps,
RiscOperators valOps 
)
pure virtual

Write a value to memory.

Consults the memory represented by this MemoryState object and possibly inserts the specified value. The details of how a value is inserted into a memory state depends entirely on the implementation in a subclass and will probably be different for each semantic domain.

A MemoryState::writeMemory() call is the last in a sequence of delegations starting with RiscOperators::writeMemory(). The designers of the MemoryState, State, and RiscOperators will need to coordinate to decide which layer (if any) should handle splitting a multi-byte value into multiple memory locations.

Implemented in Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellMap, and Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::SymbolicMemory.

virtual void Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::hash ( Combinatorics::Hasher ,
RiscOperators addrOps,
RiscOperators valOps 
) const
pure virtual

Calculate a hash for this memory state.

This hashes the addresses and values stored in memory. The goal is to be able to identify when two memory states are the "same". An analysis might be able to take shortcuts if it encounters a state that it has seen before.

Implemented in Rose::BinaryAnalysis::InstructionSemantics::NullSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::ConcreteSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList, Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellMap, and Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::SymbolicMemory.

WithFormatter Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::with_format ( Formatter )

Used for printing memory states with formatting.

The usual way to use this is:

MemoryStatePtr obj = ...;
Formatter fmt = ...;
std::cout <<"The value is: " <<(*obj+fmt) <<"\n";

Since specifying a line prefix string for indentation purposes is such a common use case, the indentation can be given instead of a format, as in the following code that indents the prefixes each line of the expression with four spaces.

std::cout <<"Memory state:\n" <<*(obj + " ");
WithFormatter Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::operator+ ( Formatter )

Used for printing memory states with formatting.

The usual way to use this is:

MemoryStatePtr obj = ...;
Formatter fmt = ...;
std::cout <<"The value is: " <<(*obj+fmt) <<"\n";

Since specifying a line prefix string for indentation purposes is such a common use case, the indentation can be given instead of a format, as in the following code that indents the prefixes each line of the expression with four spaces.

std::cout <<"Memory state:\n" <<*(obj + " ");
WithFormatter Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState::operator+ ( const std::string &  linePrefix)

Used for printing memory states with formatting.

The usual way to use this is:

MemoryStatePtr obj = ...;
Formatter fmt = ...;
std::cout <<"The value is: " <<(*obj+fmt) <<"\n";

Since specifying a line prefix string for indentation purposes is such a common use case, the indentation can be given instead of a format, as in the following code that indents the prefixes each line of the expression with four spaces.

std::cout <<"Memory state:\n" <<*(obj + " ");

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