ROSE 0.11.145.229
|
Simple list-based memory state.
MemoryCellList uses a list of MemoryCell objects to represent the memory state. Each memory cell contains at least an address and a value, both of which have a run-time width. The default MemoryCellList configuration restricts memory cell values to be one byte wide and requires the caller to perform any necessary byte extraction or concatenation when higher software layers are reading/writing multi-byte values. Using one-byte values simplifies the aliasing calculations. The super class defines a byteRestricted
property that can be set to false to allow the memory to store variable-width cell values.
MemoryCellList also provides a scan() method that returns a list of memory cells that alias a specified address. This method can be used by a higher-level readMemory() operation in preference to the usual MemoryState::readMemory().
There is no requirement that a State use a MemoryCellList as its memory state; it can use any subclass of MemoryState. Since MemoryCellList is derived from MemoryState it must provide virtual allocating constructors, which makes it possible for users to define their own subclasses and use them in the semantic framework.
This implementation stores memory cells in reverse chronological order: the most recently created cells appear at the beginning of the list. Subclasses, of course, are free to reorder the list however they want.
Definition at line 41 of file MemoryCellList.h.
#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellList.h>
Public Types | |
using | Super = MemoryCellState |
Base type. | |
using | Ptr = MemoryCellListPtr |
Shared-ownership pointer. | |
![]() | |
using | Super = MemoryState |
Base type. | |
using | Ptr = MemoryCellStatePtr |
Shared-ownership pointer. | |
![]() | |
typedef MemoryStatePtr | Ptr |
Shared-ownership pointer. | |
![]() | |
using | Ptr = AddressSpacePtr |
Shared-ownership pointer. | |
using | Purpose = AddressSpacePurpose |
Purpose for the address space. | |
Public Member Functions | |
virtual MemoryStatePtr | create (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) const override |
Virtual allocating constructor. | |
virtual MemoryStatePtr | create (const MemoryCellPtr &protocell) const |
Virtual allocating constructor. | |
virtual AddressSpacePtr | clone () const override |
Deep-copy of this address space. | |
virtual void | clear () override |
Clear memory. | |
virtual bool | merge (const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override |
Merge address spaces for data flow analysis. | |
virtual std::vector< MemoryCellPtr > | matchingCells (MemoryCell::Predicate &) const override |
Find all matching cells. | |
virtual std::vector< MemoryCellPtr > | leadingCells (MemoryCell::Predicate &) const override |
Find leading matching cells. | |
virtual void | eraseMatchingCells (MemoryCell::Predicate &) override |
Remove all matching cells. | |
virtual void | eraseLeadingCells (MemoryCell::Predicate &) override |
Remove leading matching cells. | |
virtual void | traverse (MemoryCell::Visitor &) override |
Traverse and modify cells. | |
virtual void | hash (Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override |
Hash this address space. | |
virtual SValuePtr | readMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override |
Read a value from memory. | |
virtual SValuePtr | peekMemory (const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override |
Read a value from memory without side effects. | |
virtual void | writeMemory (const SValuePtr &addr, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) override |
Write a value to memory. | |
virtual void | print (std::ostream &, Formatter &) const override |
Print an address space. | |
bool | mergeNoAliasing (const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) |
Merge two states without aliasing. | |
bool | mergeWithAliasing (const AddressSpacePtr &other, RiscOperators *addrOps, RiscOperators *valOps) |
Merge two states with aliasing. | |
virtual bool | isAllPresent (const SValuePtr &address, size_t nBytes, RiscOperators *addrOps, RiscOperators *valOps) const |
Predicate to determine whether all bytes are present. | |
template<class Iterator > | |
CellList | scan (Iterator &cursor, const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) const |
Scan cell list to find matching cells. | |
virtual AddressSet | getWritersUnion (const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override |
Writers for an address. | |
virtual AddressSet | getWritersIntersection (const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override |
Writers for an address. | |
bool | occlusionsErased () const |
Property: erase occluded cells. | |
void | occlusionsErased (bool b) |
Property: erase occluded cells. | |
virtual const CellList & | get_cells () const |
Returns the list of all memory cells. | |
virtual CellList & | get_cells () |
Returns the list of all memory cells. | |
![]() | |
virtual void | updateReadProperties (const CellList &) |
Adjust I/O properties after reading memory. | |
virtual void | updateWriteProperties (const CellList &, InputOutputPropertySet) |
Adjust I/O properties after writing memory. | |
void | eraseNonWritten () |
Erase cells that have no writers. | |
std::vector< MemoryCellPtr > | allCells () const |
All cells. | |
virtual MemoryCellPtr | latestWrittenCell () const |
Property: Cell most recently written. | |
virtual void | latestWrittenCell (const MemoryCellPtr &) |
Property: Cell most recently written. | |
![]() | |
SValuePtr | get_addr_protoval () const |
Return the address protoval. | |
SValuePtr | get_val_protoval () const |
Return the value protoval. | |
MergerPtr | merger () const |
Property: Merger. | |
void | merger (const MergerPtr &) |
Property: Merger. | |
bool | byteRestricted () const |
Indicates whether memory cell values are required to be eight bits wide. | |
void | byteRestricted (bool) |
Indicates whether memory cell values are required to be eight bits wide. | |
ByteOrder::Endianness | get_byteOrder () const |
Memory byte order. | |
void | set_byteOrder (ByteOrder::Endianness) |
Memory byte order. | |
![]() | |
virtual SValuePtr | read (const AddressSpaceAddress &, const SValuePtr &dflt, RiscOperators &addrOps, RiscOperators &valOps) |
Read a value from the address space. | |
virtual SValuePtr | peek (const AddressSpaceAddress &, const SValuePtr &dflt, RiscOperators &addrOps, RiscOperators &valOps) |
Read without causing side effects. | |
virtual void | write (const AddressSpaceAddress &, const SValuePtr &value, RiscOperators &addrOps, RiscOperators &valOps) |
Write a value to an address space. | |
std::string | printableName () const |
Printable name for this address space. | |
Purpose | purpose () const |
Property: Purpose of this address space. | |
void | purpose (Purpose) |
Property: Purpose of this address space. | |
const std::string & | name () const |
Property: Name for this address space. | |
void | name (const std::string &) |
Property: Name for this address space. | |
void | print (std::ostream &, const std::string &prefix="") const |
Print an address space. | |
WithFormatter | with_format (Formatter &) |
Used for printing address spaces with formatting. | |
WithFormatter | operator+ (Formatter &) |
Used for printing address spaces with formatting. | |
WithFormatter | operator+ (const std::string &linePrefix) |
Used for printing address spaces with formatting. | |
Static Public Member Functions | |
static MemoryCellListPtr | instance (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) |
Instantiate a new prototypical memory state. | |
static MemoryCellListPtr | instance (const MemoryCellPtr &protocell) |
Instantiate a new memory state with prototypical memory cell. | |
static MemoryCellListPtr | instance (const MemoryCellListPtr &other) |
Instantiate a new copy of an existing memory state. | |
static MemoryCellListPtr | promote (const BaseSemantics::AddressSpacePtr &m) |
Promote a base address space pointer to a BaseSemantics::MemoryCellList pointer. | |
![]() | |
static MemoryCellStatePtr | promote (const BaseSemantics::AddressSpacePtr &) |
Promote a base address space pointer to a BaseSemantics::MemoryCellState pointer. | |
![]() | |
static MemoryStatePtr | promote (const AddressSpacePtr &) |
Protected Member Functions | |
MemoryCellList (const MemoryCellPtr &protocell) | |
MemoryCellList (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) | |
MemoryCellList (const MemoryCellList &other) | |
virtual SValuePtr | mergeCellValues (const CellList &cells, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) |
virtual AddressSet | mergeCellWriters (const CellList &cells) |
virtual InputOutputPropertySet | mergeCellProperties (const CellList &cells) |
virtual MemoryCellPtr | insertReadCell (const SValuePtr &addr, const SValuePtr &value) |
virtual MemoryCellPtr | insertReadCell (const SValuePtr &addr, const SValuePtr &value, const AddressSet &writers, const InputOutputPropertySet &props) |
![]() | |
MemoryCellState (const MemoryCellPtr &protocell) | |
MemoryCellState (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) | |
MemoryCellState (const MemoryCellState &other) | |
![]() | |
MemoryState (const SValuePtr &addrProtoval, const SValuePtr &valProtoval) | |
MemoryState (const MemoryStatePtr &other) | |
![]() | |
AddressSpace (Purpose, const std::string &name) | |
AddressSpace (const AddressSpace &) | |
AddressSpace & | operator= (const AddressSpace &)=delete |
Protected Attributes | |
CellList | cells |
bool | occlusionsErased_ |
![]() | |
MemoryCellPtr | protocell |
MemoryCellPtr | latestWrittenCell_ |
using Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList::Super = MemoryCellState |
Base type.
Definition at line 44 of file MemoryCellList.h.
using Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList::Ptr = MemoryCellListPtr |
Shared-ownership pointer.
Definition at line 47 of file MemoryCellList.h.
|
static |
Instantiate a new prototypical memory state.
This constructor uses the default type for the cell type (based on the semantic domain). The prototypical values are usually the same (addresses and stored values are normally the same type).
|
overridevirtual |
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.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, and Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
|
virtual |
Virtual allocating constructor.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, and Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
|
overridevirtual |
Deep-copy of this address space.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::AddressSpace.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, and Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
|
static |
Promote a base address space pointer to a BaseSemantics::MemoryCellList pointer.
The memory state m
must have a BaseSemantics::MemoryCellList dynamic type.
|
overridevirtual |
Clear memory.
Removes all memory cells from this memory state.
Reimplemented from Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Merge address spaces for data flow analysis.
Merges the other
address space into this address space, returning true if this space changed.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::AddressSpace.
|
overridevirtual |
Find all matching cells.
Returns a vector of cells for which the predicate
returns true.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Find leading matching cells.
Returns the vector of cells obtained by invoking the predicate on each cell and returning those leading cells for which the predicate is true. The first cell for which the predicate is false terminates the traversal and does not appear in the return value.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Remove all matching cells.
Traverses the memory cells and removes those for which the predicate returns true.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Remove leading matching cells.
Traverses the memory cells and removes those for which the predicate returns true. The traversal is terminated the first time the predicate returns false.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Traverse and modify cells.
Traverse cells and optionally modify them.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Hash this address space.
Hashes this address space by appending its data to the specified hasher. The goal is to identify when two address spaces are the "same" and allow certain kinds of analyses to take shortcuts. The address space purpose and name are not included in the hash. Separate RISC operators are passed for the addresses and values of this address space and are used if the hashing requires any operations on the addresses or values.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::AddressSpace.
|
overridevirtual |
Read a value from memory.
See BaseSemantics::MemoryState() for requirements. This implementation scans the reverse chronological cell list until it finds a cell that must alias the specified addresses and value size. Along the way, it accumulates a list of cells that may alias the specified address. If the accumulated list does not contain exactly one cell, or the scan fell off the end of the list, then dflt
becomes the return value, otherwise the return value is the single value on the accumulated list. If the dflt
value is returned, then it is also pushed onto the front of the cell list.
The width of the dflt
value determines how much data is read. The base implementation assumes that all cells contain 8-bit values.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, and Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
|
overridevirtual |
Read a value from memory without side effects.
This is similar to readMemory except there are no side effects. The memory state is not modified by this function.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, and Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
|
overridevirtual |
Write a value to memory.
See BaseSemantics::MemoryState() for requirements. This implementation creates a new memory cell and pushes it onto the front of the cell list.
The base implementation assumes that all cells contain 8-bit values.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryState.
Reimplemented in Rose::BinaryAnalysis::InstructionSemantics::IntervalSemantics::MemoryState, Rose::BinaryAnalysis::InstructionSemantics::SymbolicSemantics::MemoryListState, and Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
|
overridevirtual |
Print an address space.
The output most likely occupies more than one line and each emitted line will be terminated with a line feed.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::AddressSpace.
Reimplemented in Rose::BinaryAnalysis::Partitioner2::Semantics::MemoryState< Super >.
bool Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList::mergeNoAliasing | ( | const AddressSpacePtr & | other, |
RiscOperators * | addrOps, | ||
RiscOperators * | valOps | ||
) |
Merge two states without aliasing.
The other
state is merged into this state without considering any aliasing. Returns true if this state changed, false otherwise.
bool Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellList::mergeWithAliasing | ( | const AddressSpacePtr & | other, |
RiscOperators * | addrOps, | ||
RiscOperators * | valOps | ||
) |
Merge two states with aliasing.
The other
state is merged into this state while considering any aliasing. Returns true if this state changed, false otherwise.
|
virtual |
Predicate to determine whether all bytes are present.
Returns true if bytes at the specified address and the following consecutive addresses are all present in this memory state.
|
inline |
Property: erase occluded cells.
If this property is true, then writing a new cell to memory will also erase all older cells that must alias the new cell. Erasing occlusions can adversely affect performance for some semantic domains.
Definition at line 179 of file MemoryCellList.h.
|
inline |
Property: erase occluded cells.
If this property is true, then writing a new cell to memory will also erase all older cells that must alias the new cell. Erasing occlusions can adversely affect performance for some semantic domains.
Definition at line 180 of file MemoryCellList.h.
|
inline |
Scan cell list to find matching cells.
Scans the cell list from front to back (reverse chronological order) and build a list of cells that may alias the given address and size. The returned list is also in reverse chronological order. The scanning begins at the specified cursor and ends either when an exact alias is found or the end of the list is reached. In either case, the cell that caused the scan to terminate is returned–either the exact alias or the end iterator.
Typical usage is like this:
Definition at line 199 of file MemoryCellList.h.
References Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::RiscOperators::undefined_().
|
inlinevirtual |
Returns the list of all memory cells.
Definition at line 216 of file MemoryCellList.h.
|
inlinevirtual |
Returns the list of all memory cells.
Definition at line 217 of file MemoryCellList.h.
|
overridevirtual |
Writers for an address.
Returns the set of all writers that wrote to the specified address or any address that might alias the specified address. Memory states that don't normally compute aliases (e.g., MemoryCellMap) return only the writers for the specified address, not any aliases, and in this case getWritersUnion and getWritersIntersection return the same set.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
overridevirtual |
Writers for an address.
Returns the set of all writers that wrote to the specified address and any address that might alias the specified address. Memory states that don't normally compute aliases (e.g., MemoryCellMap) return only the writers for the specified address, not any aliases, and in this case getWritersUnion and getWritersIntersection return the same set.
Implements Rose::BinaryAnalysis::InstructionSemantics::BaseSemantics::MemoryCellState.
|
protected |
Definition at line 50 of file MemoryCellList.h.
|
protected |
Definition at line 51 of file MemoryCellList.h.