ROSE 0.11.145.250
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#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
12#include <boost/serialization/access.hpp>
13#include <boost/serialization/nvp.hpp>
14#include <boost/serialization/shared_ptr.hpp>
15#endif
16
17namespace Rose {
18namespace BinaryAnalysis {
19
24class HotPatch {
25public:
28
30 class Record {
31 public:
37
43
44 private:
45 Type type_; // record type
46 RegisterDescriptor register_; // register to be modified for PATCH_REGISTER types.
47 InstructionSemantics::BaseSemantics::SValuePtr oldValue_; // value to match
48 InstructionSemantics::BaseSemantics::SValuePtr newValue_; // replacement value
49 Behavior behavior_; // whether to continue matching more records
50
51#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
52 private:
53 friend class boost::serialization::access;
54
55 template<class S>
56 void serialize(S &s, const unsigned /*version*/) {
57 s & BOOST_SERIALIZATION_NVP(type_);
58 s & BOOST_SERIALIZATION_NVP(register_);
59 s & BOOST_SERIALIZATION_NVP(oldValue_);
60 s & BOOST_SERIALIZATION_NVP(newValue_);
61 s & BOOST_SERIALIZATION_NVP(behavior_);
62 }
63#endif
64
65 public:
68 : type_(PATCH_NONE), behavior_(MATCH_CONTINUE) {}
69
79
83 Type type() const {
84 return type_;
85 }
86
94 return register_;
95 }
97 register_ = r;
98 }
108 return oldValue_;
109 }
111 oldValue_ = v;
112 }
122 return newValue_;
123 }
125 newValue_ = v;
126 }
136 return behavior_;
137 }
139 behavior_ = b;
140 }
142 };
143
144
146 typedef std::vector<Record> Records;
147
148private:
149 Records records_;
150
151 // Serialization
152#ifdef ROSE_ENABLE_BOOST_SERIALIZATION
153private:
154 friend class boost::serialization::access;
155
156 template<class S>
157 void serialize(S &s, const unsigned /*version*/) {
158 s & BOOST_SERIALIZATION_NVP(records_);
159 }
160#endif
161
162public:
168 const Records& records() const {
169 return records_;
170 }
172 return records_;
173 }
177 size_t nRecords() const {
178 return records_.size();
179 }
180
182 void clear() {
183 records_.clear();
184 }
185
189 size_t append(const Record &record) {
190 records_.push_back(record);
191 return records_.size() - 1;
192 }
193
199 const Record& operator[](size_t idx) const {
200 ASSERT_require(idx < records_.size());
201 return records_[idx];
202 }
203 Record& operator[](size_t idx) {
204 ASSERT_require(idx < records_.size());
205 return records_[idx];
206 }
220 return apply(ops);
221 }
225 static void initDiagnostics();
226};
227
228
229} // namespace
230} // namespace
231
232#endif
233#endif
Describes a single hot patch.
Definition HotPatch.h:30
InstructionSemantics::BaseSemantics::SValuePtr oldValue() const
Property: Value to match.
Definition HotPatch.h:107
Type type() const
Property: Type of record.
Definition HotPatch.h:83
void newValue(const InstructionSemantics::BaseSemantics::SValuePtr &v)
Property: Replacement value.
Definition HotPatch.h:124
Behavior
Behavior when a record matches.
Definition HotPatch.h:39
@ MATCH_BREAK
Don't try to match more records after a match is found.
Definition HotPatch.h:41
@ MATCH_CONTINUE
Try to match additional subsequent records.
Definition HotPatch.h:40
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:74
void reg(RegisterDescriptor r)
Property: Register to be matched.
Definition HotPatch.h:96
RegisterDescriptor reg() const
Property: Register to be matched.
Definition HotPatch.h:93
Record()
Construct a no-op record.
Definition HotPatch.h:67
void behavior(Behavior b)
Property: Behavior after matching.
Definition HotPatch.h:138
@ PATCH_NONE
Type for default-constructed records.
Definition HotPatch.h:35
@ PATCH_REGISTER
Change the value of a register.
Definition HotPatch.h:34
void oldValue(const InstructionSemantics::BaseSemantics::SValuePtr &v)
Property: Value to match.
Definition HotPatch.h:110
InstructionSemantics::BaseSemantics::SValuePtr newValue() const
Property: Replacement value.
Definition HotPatch.h:121
Behavior behavior() const
Property: Behavior after matching.
Definition HotPatch.h:135
Describes how to modify machine state after each instruction.
Definition HotPatch.h:24
void clear()
Remove all records from this object.
Definition HotPatch.h:182
std::vector< Record > Records
Ordered list of hot patch records.
Definition HotPatch.h:146
Records & records()
Property: Hot patch records.
Definition HotPatch.h:171
const Record & operator[](size_t idx) const
Reference a particular record.
Definition HotPatch.h:199
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:27
size_t append(const Record &record)
Append a hot-patch record.
Definition HotPatch.h:189
Record & operator[](size_t idx)
Reference a particular record.
Definition HotPatch.h:203
const Records & records() const
Property: Hot patch records.
Definition HotPatch.h:168
size_t operator()(const InstructionSemantics::BaseSemantics::RiscOperatorsPtr &ops) const
Apply records to a machine state.
Definition HotPatch.h:219
static void initDiagnostics()
Initialize diagnostic output.
size_t nRecords() const
Number of hot-patch records in this object.
Definition HotPatch.h:177
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.