ROSE  0.11.2.0
BinarySystemCall.h
1 #ifndef Rose_BinaryAnalysis_LinuxSyscall_H
2 #define Rose_BinaryAnalysis_LinuxSyscall_H
3 #include <rosePublicConfig.h>
4 #ifdef ROSE_BUILD_BINARY_ANALYSIS_SUPPORT
5 
6 #include <AbstractLocation.h>
7 #include <BinarySmtSolver.h>
8 #include <boost/filesystem.hpp>
9 #include <Partitioner2/BasicTypes.h>
10 #include <RoseException.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
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:322
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.