ROSE 0.11.145.192
SharedMemory.h
1#ifndef ROSE_BinaryAnalysis_Concolic_SharedMemory_H
2#define ROSE_BinaryAnalysis_Concolic_SharedMemory_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_CONCOLIC_TESTING
5
6#include <Rose/BinaryAnalysis/Concolic/BasicTypes.h>
7#include <Rose/BinaryAnalysis/InstructionSemantics/BaseSemantics/BasicTypes.h>
8#include <Rose/BinaryAnalysis/SymbolicExpression.h>
9#include <Rose/Yaml.h>
10
11#include <Sawyer/Optional.h>
12#include <Sawyer/SharedObject.h>
13
14namespace Rose {
15namespace BinaryAnalysis {
16namespace Concolic {
17
19// Shared memory context for callbacks
21
25class SharedMemoryContext {
26public:
27 SharedMemoryContext() = delete;
28
30 SharedMemoryContext(const ArchitecturePtr&, const ExecutionEventPtr &sharedMemoryEvent);
31
33 SharedMemoryContext(const ArchitecturePtr&, const Emulation::RiscOperatorsPtr&,
34 const ExecutionEventPtr &sharedMemoryEvent);
35
37 SharedMemoryContext(const ArchitecturePtr&, const Emulation::RiscOperatorsPtr&, rose_addr_t accessingInstructionVa,
38 rose_addr_t accessedVa, const SymbolicExpression::Ptr &value);
39
40 virtual ~SharedMemoryContext();
41
42 /*------------------------------------------------------------------------------------------------------------
43 * Inputs to the callback
44 *------------------------------------------------------------------------------------------------------------*/
45
52 ConcolicPhase phase = ConcolicPhase::EMULATION;
53
55 ArchitecturePtr architecture;
56
60 Emulation::RiscOperatorsPtr ops;
61
63 rose_addr_t ip = 0;
64
66 AddressInterval accessedVas;
67
69 IoDirection direction = IoDirection::READ;
70
74 ExecutionEventPtr sharedMemoryEvent;
75
83 SymbolicExpression::Ptr valueRead;
84
88 SymbolicExpression::Ptr valueWritten;
89};
90
92// Callbacks to handle shared memory operations.
94
96class SharedMemoryCallback: public Sawyer::SharedObject {
97public:
99 using Ptr = SharedMemoryCallbackPtr;
100
101private:
102 AddressInterval registrationVas_; // where in memory this callback was initially registered
103 std::string name_; // name of the callback in registrations and debugging
104
105public:
106 virtual ~SharedMemoryCallback();
107protected:
108 SharedMemoryCallback(const std::string &name); // for factories
109 SharedMemoryCallback(const AddressInterval&, const std::string &name);
110
111public:
113 static void registerFactory(const Ptr &factory);
114
119 static bool deregisterFactory(const Ptr &factory);
120
125 static std::vector<Ptr> registeredFactories();
126
132 static Ptr forge(const AddressInterval &where, const Yaml::Node &config);
133
135 virtual bool matchFactory(const Yaml::Node &config) const;
136
141 virtual Ptr instanceFromFactory(const AddressInterval &where, const Yaml::Node &config) const;
142
144 bool isFactory() const;
145
146public:
150 const std::string& name() const;
151 void name(const std::string&);
162 const AddressInterval& registrationVas() const;
163 void registrationVas(const AddressInterval&);
167 void hello(const SharedMemoryContext&) const;
168
174 virtual void playback(SharedMemoryContext&) = 0;
175
194 virtual void handlePreSharedMemory(SharedMemoryContext&) = 0;
195 virtual void handlePostSharedMemory(const SharedMemoryContext&) {}
203 void normalRead(SharedMemoryContext&) const;
204
209 void notAnInput(SharedMemoryContext&) const;
210
217 void returns(SharedMemoryContext&, const SymbolicExpression::Ptr&) const;
218 void returns(SharedMemoryContext&, const InstructionSemantics::BaseSemantics::SValuePtr&) const;
226 SymbolicExpressionPtr inputVariable(const SharedMemoryContext&) const;
227
228
229 virtual bool operator()(bool handled, SharedMemoryContext&) final;
230};
231
232} // namespace
233} // namespace
234} // namespace
235
236#endif
237#endif
Base class for reference counted objects.
Sawyer::SharedPointer< Node > Ptr
Reference counting pointer.
Sawyer::Container::Interval< Address > AddressInterval
An interval of addresses.
The ROSE library.
const char * direction(int64_t)
Convert CGFunction::iterator::direction enum constant to a string.
const char * ConcolicPhase(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ConcolicPhase enum constant to a string.
const char * IoDirection(int64_t)
Convert Rose::BinaryAnalysis::Concolic::IoDirection enum constant to a string.
const char * ops(int64_t)
Convert ops enum constant to a string.