ROSE 0.11.145.192
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
15namespace Rose {
16namespace BinaryAnalysis {
17
22class HotPatch {
23public:
26
28 class Record {
29 public:
35
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
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 }
134 return behavior_;
135 }
137 behavior_ = b;
138 }
140 };
141
142
144 typedef std::vector<Record> Records;
145
146private:
147 Records records_;
148
149 // Serialization
150#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
151private:
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
160public:
166 const Records& records() const {
167 return records_;
168 }
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
Describes a single hot patch.
Definition HotPatch.h:28
InstructionSemantics::BaseSemantics::SValuePtr oldValue() const
Property: Value to match.
Definition HotPatch.h:105
Type type() const
Property: Type of record.
Definition HotPatch.h:81
void newValue(const InstructionSemantics::BaseSemantics::SValuePtr &v)
Property: Replacement value.
Definition HotPatch.h:122
Behavior
Behavior when a record matches.
Definition HotPatch.h:37
@ MATCH_BREAK
Don't try to match more records after a match is found.
Definition HotPatch.h:39
@ MATCH_CONTINUE
Try to match additional subsequent records.
Definition HotPatch.h:38
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
void reg(RegisterDescriptor r)
Property: Register to be matched.
Definition HotPatch.h:94
RegisterDescriptor reg() const
Property: Register to be matched.
Definition HotPatch.h:91
Record()
Construct a no-op record.
Definition HotPatch.h:65
void behavior(Behavior b)
Property: Behavior after matching.
Definition HotPatch.h:136
@ PATCH_NONE
Type for default-constructed records.
Definition HotPatch.h:33
@ PATCH_REGISTER
Change the value of a register.
Definition HotPatch.h:32
void oldValue(const InstructionSemantics::BaseSemantics::SValuePtr &v)
Property: Value to match.
Definition HotPatch.h:108
InstructionSemantics::BaseSemantics::SValuePtr newValue() const
Property: Replacement value.
Definition HotPatch.h:119
Behavior behavior() const
Property: Behavior after matching.
Definition HotPatch.h:133
Describes how to modify machine state after each instruction.
Definition HotPatch.h:22
void clear()
Remove all records from this object.
Definition HotPatch.h:180
std::vector< Record > Records
Ordered list of hot patch records.
Definition HotPatch.h:144
Records & records()
Property: Hot patch records.
Definition HotPatch.h:169
const Record & operator[](size_t idx) const
Reference a particular record.
Definition HotPatch.h:198
size_t apply(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &) const
Apply records to a machine state.
static Sawyer::Message::Facility mlog
Diagnostic output for hot patching.
Definition HotPatch.h:25
size_t append(const Record &record)
Append a hot-patch record.
Definition HotPatch.h:188
Record & operator[](size_t idx)
Reference a particular record.
Definition HotPatch.h:202
const Records & records() const
Property: Hot patch records.
Definition HotPatch.h:166
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.
size_t nRecords() const
Number of hot-patch records in this object.
Definition HotPatch.h:175
Describes (part of) a physical CPU register.
Collection of streams.
Definition Message.h:1606
boost::shared_ptr< RiscOperators > RiscOperatorsPtr
Shared-ownership pointer to a RISC operators object.
The ROSE library.