ROSE  0.11.82.0
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/InstructionSemantics2/BaseSemantics/Types.h>
8 #include <Rose/BinaryAnalysis/SymbolicExpr.h>
9 
10 #include <Sawyer/Optional.h>
11 #include <Sawyer/SharedObject.h>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 namespace Concolic {
16 
18 // Shared memory context for callbacks
20 
24 class SharedMemoryContext {
25 public:
26  SharedMemoryContext() = delete;
27 
29  SharedMemoryContext(const ArchitecturePtr&, const ExecutionEventPtr &sharedMemoryEvent);
30 
32  SharedMemoryContext(const ArchitecturePtr&, const Emulation::RiscOperatorsPtr&,
33  const ExecutionEventPtr &sharedMemoryEvent);
34 
35  virtual ~SharedMemoryContext();
36 
37  /*------------------------------------------------------------------------------------------------------------
38  * Inputs to the callback
39  *------------------------------------------------------------------------------------------------------------*/
40 
47  ConcolicPhase phase = ConcolicPhase::EMULATION;
48 
50  ArchitecturePtr architecture;
51 
55  Emulation::RiscOperatorsPtr ops;
56 
58  rose_addr_t ip = 0;
59 
61  AddressInterval accessedVas;
62 
64  IoDirection direction = IoDirection::READ;
65 
69  ExecutionEventPtr sharedMemoryEvent;
70 
78  SymbolicExpr::Ptr valueRead;
79 };
80 
82 // Callbacks to handle shared memory operations.
84 
86 class SharedMemoryCallback: public Sawyer::SharedObject {
87  AddressInterval registeredVas_; // where in memory this callback was initially registered
88 
89 public:
91  using Ptr = SharedMemoryCallbackPtr;
92 
93  virtual ~SharedMemoryCallback() {}
94 
103  const AddressInterval& registeredVas() const;
104  void registeredVas(const AddressInterval&);
110  void hello(const std::string &myName, const SharedMemoryContext&) const;
111 
117  virtual void playback(SharedMemoryContext&) = 0;
118 
137  virtual void handlePreSharedMemory(SharedMemoryContext&) = 0;
138  virtual void handlePostSharedMemory(const SharedMemoryContext&) {}
146  void normalRead(SharedMemoryContext&) const;
147 
152  void notAnInput(SharedMemoryContext&) const;
153 
160  void returns(SharedMemoryContext&, const SymbolicExpr::Ptr&) const;
161  void returns(SharedMemoryContext&, const InstructionSemantics2::BaseSemantics::SValuePtr&) const;
169  SymbolicExprPtr inputVariable(const SharedMemoryContext&) const;
170 
171 
172  virtual bool operator()(bool handled, SharedMemoryContext&) final;
173 };
174 
175 } // namespace
176 } // namespace
177 } // namespace
178 
179 #endif
180 #endif
Sawyer::SharedPointer< Node > Ptr
Shared-ownership pointer to an expression Node.
Definition: SymbolicExpr.h:166
const char * ops(int64_t)
Convert ops enum constant to a string.
const char * IoDirection(int64_t)
Convert Rose::BinaryAnalysis::Concolic::IoDirection enum constant to a string.
Main namespace for the ROSE library.
const char * ConcolicPhase(int64_t)
Convert Rose::BinaryAnalysis::Concolic::ConcolicPhase enum constant to a string.
const char * direction(int64_t)
Convert CGFunction::iterator::direction enum constant to a string.
Base class for reference counted objects.
Definition: SharedObject.h:64
Sawyer::SharedPointer< SValue > SValuePtr
Shared-ownership pointer to a semantic value in any domain.