ROSE  0.11.101.0
MemoryCellMap.h
1 #ifndef ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCellMap_H
2 #define ROSE_BinaryAnalysis_InstructionSemantics_BaseSemantics_MemoryCellMap_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/Types.h>
7 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/MemoryCellState.h>
8 
9 #include <Sawyer/Map.h>
10 
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/base_object.hpp>
13 #include <boost/serialization/export.hpp>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 namespace InstructionSemantics {
18 namespace BaseSemantics {
19 
21 typedef boost::shared_ptr<class MemoryCellMap> MemoryCellMapPtr;
22 
30 public:
33 
36 
42  typedef uint64_t CellKey;
43 
46 
47 private:
48  uint32_t lastPosition_ = 0; // used when inserting new cells
49 
50 protected:
51  CellMap cells;
52 
53 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
54 private:
55  friend class boost::serialization::access;
56 
57  template<class S>
58  void serialize(S &s, const unsigned /*version*/) {
59  s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(MemoryCellState);
60  s & BOOST_SERIALIZATION_NVP(cells);
61  }
62 #endif
63 
64 protected:
65  MemoryCellMap() {} // for serialization
66 
67  explicit MemoryCellMap(const MemoryCellPtr &protocell)
68  : MemoryCellState(protocell) {}
69 
70  MemoryCellMap(const SValuePtr &addrProtoval, const SValuePtr &valProtoval)
71  : MemoryCellState(addrProtoval, valProtoval) {}
72 
73  MemoryCellMap(const MemoryCellMap&);
74 
75 private:
76  MemoryCellMap& operator=(MemoryCellMap&) /*delete*/;
77 
78 public:
81  static MemoryCellMapPtr promote(const MemoryStatePtr &x) {
82  MemoryCellMapPtr retval = boost::dynamic_pointer_cast<MemoryCellMap>(x);
83  ASSERT_not_null(retval);
84  return retval;
85  }
86 
87 public:
91  virtual CellKey generateCellKey(const SValuePtr &address) const = 0;
92 
98  virtual MemoryCellPtr findCell(const SValuePtr &addr) const;
99 
104  virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const;
105 
106 public:
107  virtual void hash(Combinatorics::Hasher&, RiscOperators *addrOps, RiscOperators *valOps) const override;
108  virtual void clear() override;
109  virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override;
110  virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt,
111  RiscOperators *addrOps, RiscOperators *valOps) override;
112  virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt,
113  RiscOperators *addrOps, RiscOperators *valOps) override;
114  virtual void writeMemory(const SValuePtr &address, const SValuePtr &value,
115  RiscOperators *addrOps, RiscOperators *valOps) override;
116  virtual void print(std::ostream&, Formatter&) const override;
117  virtual std::vector<MemoryCellPtr> matchingCells(MemoryCell::Predicate&) const override;
118  virtual std::vector<MemoryCellPtr> leadingCells(MemoryCell::Predicate&) const override;
119  virtual void eraseMatchingCells(MemoryCell::Predicate&) override;
120  virtual void eraseLeadingCells(MemoryCell::Predicate&) override;
121  virtual void traverse(MemoryCell::Visitor&) override;
122  virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
123  RiscOperators *valOps) override;
124  virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps,
125  RiscOperators *valOps) override;
126 
127 private:
128  // Increment lastPosition_ and return its new value.
129  unsigned nextPosition();
130 
131  // Last position returned by nextPosition
132  unsigned lastPosition() const;
133  void lastPosition(unsigned);
134 };
135 
136 } // namespace
137 } // namespace
138 } // namespace
139 } // namespace
140 
141 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
143 #endif
144 
145 #endif
146 #endif
virtual CellKey generateCellKey(const SValuePtr &address) const =0
Generate a cell lookup key.
Base classes for instruction semantics.
Definition: Dispatcher.h:18
virtual void eraseMatchingCells(MemoryCell::Predicate &) override
Remove all matching cells.
virtual bool isAllPresent(const SValuePtr &address, size_t nBytes, RiscOperators *addrOps) const
Predicate to determine whether all bytes are present.
boost::shared_ptr< class MemoryCellMap > MemoryCellMapPtr
Shared-ownership pointer to a map-based memory state.
Definition: MemoryCellMap.h:21
virtual std::vector< MemoryCellPtr > leadingCells(MemoryCell::Predicate &) const override
Find leading matching cells.
virtual AddressSet getWritersUnion(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override
Writers for an address.
virtual SValuePtr peekMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory without side effects.
virtual SValuePtr readMemory(const SValuePtr &address, const SValuePtr &dflt, RiscOperators *addrOps, RiscOperators *valOps) override
Read a value from memory.
Main namespace for the ROSE library.
virtual void traverse(MemoryCell::Visitor &) override
Traverse and modify cells.
boost::shared_ptr< MemoryCell > MemoryCellPtr
Shared-ownership pointer to a memory cell.
static MemoryCellMapPtr promote(const MemoryStatePtr &x)
Promote a base memory state pointer to a MemoryCellMap pointer.
Definition: MemoryCellMap.h:81
virtual void writeMemory(const SValuePtr &address, const SValuePtr &value, RiscOperators *addrOps, RiscOperators *valOps) override
Write a value to memory.
virtual void eraseLeadingCells(MemoryCell::Predicate &) override
Remove leading matching cells.
boost::shared_ptr< MemoryState > MemoryStatePtr
Shared-ownership pointer to a memory state.
Sawyer::Container::Map< CellKey, MemoryCellPtr > CellMap
Map of memory cells indexed by cell keys.
Definition: MemoryCellMap.h:45
virtual void hash(Combinatorics::Hasher &, RiscOperators *addrOps, RiscOperators *valOps) const override
Calculate a hash for this memory state.
virtual std::vector< MemoryCellPtr > matchingCells(MemoryCell::Predicate &) const override
Find all matching cells.
Binary analysis.
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.
virtual bool merge(const MemoryStatePtr &other, RiscOperators *addrOps, RiscOperators *valOps) override
Merge memory states for data flow analysis.
virtual void print(std::ostream &, Formatter &) const override
Print a memory state to more than one line of output.
Base class for most instruction semantics RISC operators.
Definition: RiscOperators.h:48
virtual MemoryCellPtr findCell(const SValuePtr &addr) const
Look up memory cell for address.
virtual AddressSet getWritersIntersection(const SValuePtr &addr, size_t nBits, RiscOperators *addrOps, RiscOperators *valOps) override
Writers for an address.