ROSE  0.9.11.35
BinarySystemCall.h
1 #ifndef Rose_BinaryAnalysis_LinuxSyscall_H
2 #define Rose_BinaryAnalysis_LinuxSyscall_H
3 
4 #include <AbstractLocation.h>
5 #include <BinarySmtSolver.h>
6 #include <boost/filesystem.hpp>
7 #include <Partitioner2/BasicTypes.h>
8 #include <RoseException.h>
9 #include <Sawyer/Map.h>
10 #include <string>
11 #include <vector>
12 
13 namespace Rose {
14 namespace BinaryAnalysis {
15 
20 class SystemCall {
21 public:
23  class Exception: public Rose::Exception {
24  public:
26  Exception(const std::string &mesg): Rose::Exception(mesg) {}
27 
29  ~Exception() throw () {}
30  };
31 
33  struct Declaration {
34  uint64_t id;
35  std::string name;
39  : id(0) {}
40 
42  Declaration(uint64_t id, const std::string &name)
43  : id(id), name(name) {}
44  };
45 
47  typedef Sawyer::Container::Map<uint64_t /*id*/, Declaration> Declarations;
48 
49 private:
50  Declarations declarations_; // table describing all known system calls index by system call number
51  AbstractLocation ident_; // location that identifies the system call
52 
53 public:
54  virtual ~SystemCall() {}
55 
57  void declare(const Declaration &declaration);
58 
60  void declare(const std::vector<Declaration> &declarations);
61 
63  void declare(const boost::filesystem::path &headerFileName);
64 
66  const Declarations& declarations() const { return declarations_; }
67 
69  Sawyer::Optional<Declaration> lookup(uint64_t id) const;
70 
72  std::vector<Declaration> lookup(const std::string &name) const;
73 
75  static std::vector<Declaration> parseHeaderFile(const boost::filesystem::path &headerFileName);
76 
83 
90  const AbstractLocation& ident() const { return ident_; }
91  void ident(const AbstractLocation &location) { ident_ = location; }
108  const SmtSolver::Ptr &solver = SmtSolver::Ptr()) const;
109 
111  virtual bool isSystemCall(SgAsmInstruction*) const;
112 };
113 
114 } // namespace
115 } // namespace
116 
117 #endif
Declarative information about a system call.
const AbstractLocation & ident() const
Property: Abstract location that identifies the particular system call.
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.
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.
Sawyer::Container::Map< uint64_t, Declaration > Declarations
Table of syscall declarations indexed by syscall IDs.
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.
Exceptions for system call analysis.
Declaration(uint64_t id, const std::string &name)
Constructor.
void declare(const Declaration &declaration)
Declare a system call.
void ident(const AbstractLocation &location)
Property: Abstract location that identifies the particular system call.
const Declarations & declarations() const
All declarations.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
Base class for all ROSE exceptions.
Definition: RoseException.h:9
Exception(const std::string &mesg)
Construct an exception with a message.
Container associating values with keys.
Definition: Sawyer/Map.h:66
virtual Sawyer::Optional< Declaration > analyze(const Partitioner2::Partitioner &, const Partitioner2::BasicBlockPtr &, SgAsmInstruction *, const SmtSolver::Ptr &solver=SmtSolver::Ptr()) const
Analyze a basic block and return the system calls.