ROSE  0.11.145.0
HotPatch.h
1 #ifndef ROSE_BinaryAnalysis_HotPatch_H
2 #define ROSE_BinaryAnalysis_HotPatch_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/SValue.h>
7 #include <Rose/BinaryAnalysis/HotPatch.h>
8 #include <Rose/BinaryAnalysis/SmtSolver.h>
9 #include <Sawyer/Message.h>
10 
11 #include <boost/serialization/access.hpp>
12 #include <boost/serialization/nvp.hpp>
13 #include <boost/serialization/shared_ptr.hpp>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 
22 class HotPatch {
23 public:
26 
28  class Record {
29  public:
31  enum Type {
34  };
35 
37  enum Behavior {
40  };
41 
42  private:
43  Type type_; // record type
44  RegisterDescriptor register_; // register to be modified for PATCH_REGISTER types.
45  InstructionSemantics::BaseSemantics::SValuePtr oldValue_; // value to match
46  InstructionSemantics::BaseSemantics::SValuePtr newValue_; // replacement value
47  Behavior behavior_; // whether to continue matching more records
48 
49 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
50  private:
51  friend class boost::serialization::access;
52 
53  template<class S>
54  void serialize(S &s, const unsigned /*version*/) {
55  s & BOOST_SERIALIZATION_NVP(type_);
56  s & BOOST_SERIALIZATION_NVP(register_);
57  s & BOOST_SERIALIZATION_NVP(oldValue_);
58  s & BOOST_SERIALIZATION_NVP(newValue_);
59  s & BOOST_SERIALIZATION_NVP(behavior_);
60  }
61 #endif
62 
63  public:
66  : type_(PATCH_NONE), behavior_(MATCH_CONTINUE) {}
67 
74  : type_(PATCH_REGISTER), register_(reg), oldValue_(oldValue), newValue_(newValue), behavior_(behavior) {
75  ASSERT_not_null(newValue);
76  }
77 
81  Type type() const {
82  return type_;
83  }
84 
92  return register_;
93  }
95  register_ = r;
96  }
106  return oldValue_;
107  }
109  oldValue_ = v;
110  }
120  return newValue_;
121  }
123  newValue_ = v;
124  }
133  Behavior behavior() const {
134  return behavior_;
135  }
136  void behavior(Behavior b) {
137  behavior_ = b;
138  }
140  };
141 
142 
144  typedef std::vector<Record> Records;
145 
146 private:
147  Records records_;
148 
149  // Serialization
150 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
151 private:
152  friend class boost::serialization::access;
153 
154  template<class S>
155  void serialize(S &s, const unsigned /*version*/) {
156  s & BOOST_SERIALIZATION_NVP(records_);
157  }
158 #endif
159 
160 public:
166  const Records& records() const {
167  return records_;
168  }
169  Records& records() {
170  return records_;
171  }
175  size_t nRecords() const {
176  return records_.size();
177  }
178 
180  void clear() {
181  records_.clear();
182  }
183 
188  size_t append(const Record &record) {
189  records_.push_back(record);
190  return records_.size() - 1;
191  }
192 
198  const Record& operator[](size_t idx) const {
199  ASSERT_require(idx < records_.size());
200  return records_[idx];
201  }
202  Record& operator[](size_t idx) {
203  ASSERT_require(idx < records_.size());
204  return records_[idx];
205  }
219  return apply(ops);
220  }
224  static void initDiagnostics();
225 };
226 
227 
228 } // namespace
229 } // namespace
230 
231 #endif
232 #endif
InstructionSemantics::BaseSemantics::SValuePtr oldValue() const
Property: Value to match.
Definition: HotPatch.h:105
size_t apply(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &) const
Apply records to a machine state.
void reg(RegisterDescriptor r)
Property: Register to be matched.
Definition: HotPatch.h:94
Type for default-constructed records.
Definition: HotPatch.h:33
Describes how to modify machine state after each instruction.
Definition: HotPatch.h:22
Behavior behavior() const
Property: Behavior after matching.
Definition: HotPatch.h:133
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
Collection of streams.
Definition: Message.h:1606
Describes a single hot patch.
Definition: HotPatch.h:28
Type
Type of patch record.
Definition: HotPatch.h:31
Main namespace for the ROSE library.
Records & records()
Property: Hot patch records.
Definition: HotPatch.h:169
size_t nRecords() const
Number of hot-patch records in this object.
Definition: HotPatch.h:175
const Records & records() const
Property: Hot patch records.
Definition: HotPatch.h:166
Don't try to match more records after a match is found.
Definition: HotPatch.h:39
void behavior(Behavior b)
Property: Behavior after matching.
Definition: HotPatch.h:136
Try to match additional subsequent records.
Definition: HotPatch.h:38
Describes (part of) a physical CPU register.
const Record & operator[](size_t idx) const
Reference a particular record.
Definition: HotPatch.h:198
RegisterDescriptor reg() const
Property: Register to be matched.
Definition: HotPatch.h:91
void oldValue(const InstructionSemantics::BaseSemantics::SValuePtr &v)
Property: Value to match.
Definition: HotPatch.h:108
size_t append(const Record &record)
Append a hot-patch record.
Definition: HotPatch.h:188
Type type() const
Property: Type of record.
Definition: HotPatch.h:81
Record(RegisterDescriptor reg, const InstructionSemantics::BaseSemantics::SValuePtr &oldValue, const InstructionSemantics::BaseSemantics::SValuePtr &newValue, Behavior behavior=MATCH_CONTINUE)
Construct a record that substitutes a register.
Definition: HotPatch.h:72
Record & operator[](size_t idx)
Reference a particular record.
Definition: HotPatch.h:202
std::vector< Record > Records
Ordered list of hot patch records.
Definition: HotPatch.h:144
Record()
Construct a no-op record.
Definition: HotPatch.h:65
static Sawyer::Message::Facility mlog
Diagnostic output for hot patching.
Definition: HotPatch.h:25
size_t operator()(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops) const
Apply records to a machine state.
Definition: HotPatch.h:218
static void initDiagnostics()
Initialize diagnostic output.
void newValue(const InstructionSemantics::BaseSemantics::SValuePtr &v)
Property: Replacement value.
Definition: HotPatch.h:122
Behavior
Behavior when a record matches.
Definition: HotPatch.h:37
void clear()
Remove all records from this object.
Definition: HotPatch.h:180
InstructionSemantics::BaseSemantics::SValuePtr newValue() const
Property: Replacement value.
Definition: HotPatch.h:119