ROSE  0.11.145.0
SystemCall.h
1 #ifndef ROSE_BinaryAnalysis_SystemCall_H
2 #define ROSE_BinaryAnalysis_SystemCall_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
5 
6 #include <Rose/BinaryAnalysis/AbstractLocation.h>
7 #include <Rose/BinaryAnalysis/SmtSolver.h>
8 #include <boost/filesystem.hpp>
9 #include <Rose/BinaryAnalysis/Partitioner2/BasicTypes.h>
10 #include <Rose/Exception.h>
11 #include <Sawyer/Map.h>
12 #include <string>
13 #include <vector>
14 
15 namespace Rose {
16 namespace BinaryAnalysis {
17 
22 class SystemCall {
23 public:
25  class Exception: public Rose::Exception {
26  public:
28  Exception(const std::string &mesg): Rose::Exception(mesg) {}
29 
31  ~Exception() throw () {}
32  };
33 
35  struct Declaration {
36  uint64_t id;
37  std::string name;
41  : id(0) {}
42 
44  Declaration(uint64_t id, const std::string &name)
45  : id(id), name(name) {}
46  };
47 
49  typedef Sawyer::Container::Map<uint64_t /*id*/, Declaration> Declarations;
50 
51 private:
52  Declarations declarations_; // table describing all known system calls index by system call number
53  AbstractLocation ident_; // location that identifies the system call
54 
55 public:
56  virtual ~SystemCall() {}
57 
59  void declare(const Declaration &declaration);
60 
62  void declare(const std::vector<Declaration> &declarations);
63 
65  void declare(const boost::filesystem::path &headerFileName);
66 
68  const Declarations& declarations() const { return declarations_; }
69 
71  Sawyer::Optional<Declaration> lookup(uint64_t id) const;
72 
74  std::vector<Declaration> lookup(const std::string &name) const;
75 
77  static std::vector<Declaration> parseHeaderFile(const boost::filesystem::path &headerFileName);
78 
85 
92  const AbstractLocation& ident() const { return ident_; }
93  void ident(const AbstractLocation &location) { ident_ = location; }
110  const SmtSolver::Ptr &solver = SmtSolver::Ptr()) const;
111 
113  virtual bool isSystemCall(SgAsmInstruction*) const;
114 };
115 
116 } // namespace
117 } // namespace
118 
119 #endif
120 #endif
SmtSolverPtr Ptr
Reference counting pointer for SMT solvers.
Definition: SmtSolver.h:45
Declarative information about a system call.
Definition: SystemCall.h:35
uint64_t id
Identification number.
Definition: SystemCall.h:36
const AbstractLocation & ident() const
Property: Abstract location that identifies the particular system call.
Definition: SystemCall.h:92
static std::vector< Declaration > parseHeaderFile(const boost::filesystem::path &headerFileName)
Parse a Linux header file to obtain declarations for system calls.
Base class for machine instructions.
Holds a value or nothing.
Definition: Optional.h:49
std::string name
Name of system call.
Definition: SystemCall.h:37
Main namespace for the ROSE library.
SgAsmInstruction * hasSystemCall(const Partitioner2::BasicBlockPtr &) const
Determine whether a basic block has a system call.
Analyzes basic blocks to get system call names.
Definition: SystemCall.h:22
Sawyer::Container::Map< uint64_t, Declaration > Declarations
Table of syscall declarations indexed by syscall IDs.
Definition: SystemCall.h:49
Sawyer::Optional< Declaration > lookup(uint64_t id) const
Look up a system call by ID number.
virtual bool isSystemCall(SgAsmInstruction *) const
Predicate to determine whether an instruction is a system call.
virtual Sawyer::Optional< Declaration > analyze(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &, SgAsmInstruction *, const SmtSolver::Ptr &solver=SmtSolver::Ptr()) const
Analyze a basic block and return the system calls.
Exceptions for system call analysis.
Definition: SystemCall.h:25
Declaration(uint64_t id, const std::string &name)
Constructor.
Definition: SystemCall.h:44
void declare(const Declaration &declaration)
Declare a system call.
void ident(const AbstractLocation &location)
Property: Abstract location that identifies the particular system call.
Definition: SystemCall.h:93
const Declarations & declarations() const
All declarations.
Definition: SystemCall.h:68
Base class for all ROSE exceptions.
Definition: Rose/Exception.h:9
Exception(const std::string &mesg)
Construct an exception with a message.
Definition: SystemCall.h:28
Container associating values with keys.
Definition: Sawyer/Map.h:66