ROSE  0.9.10.91
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 <Sawyer/Map.h>
9 #include <string>
10 #include <vector>
11 
12 namespace Rose {
13 namespace BinaryAnalysis {
14 
19 class SystemCall {
20 public:
22  class Exception: public std::runtime_error {
23  public:
25  Exception(const std::string &mesg): std::runtime_error(mesg) {}
26 
28  ~Exception() throw () {}
29  };
30 
32  struct Declaration {
33  uint64_t id;
34  std::string name;
38  : id(0) {}
39 
41  Declaration(uint64_t id, const std::string &name)
42  : id(id), name(name) {}
43  };
44 
46  typedef Sawyer::Container::Map<uint64_t /*id*/, Declaration> Declarations;
47 
48 private:
49  Declarations declarations_; // table describing all known system calls index by system call number
50  AbstractLocation ident_; // location that identifies the system call
51 
52 public:
53  virtual ~SystemCall() {}
54 
56  void declare(const Declaration &declaration);
57 
59  void declare(const std::vector<Declaration> &declarations);
60 
62  void declare(const boost::filesystem::path &headerFileName);
63 
65  const Declarations& declarations() const { return declarations_; }
66 
68  Sawyer::Optional<Declaration> lookup(uint64_t id) const;
69 
71  std::vector<Declaration> lookup(const std::string &name) const;
72 
74  static std::vector<Declaration> parseHeaderFile(const boost::filesystem::path &headerFileName);
75 
82 
89  const AbstractLocation& ident() const { return ident_; }
90  void ident(const AbstractLocation &location) { ident_ = location; }
107  const SmtSolver::Ptr &solver = SmtSolver::Ptr()) const;
108 
110  virtual bool isSystemCall(SgAsmInstruction*) const;
111 };
112 
113 } // namespace
114 } // namespace
115 
116 #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.
STL namespace.
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
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.