ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryLoader.h
Go to the documentation of this file.
1 #ifndef ROSE_BINARYLOADER_H
2 #define ROSE_BINARYLOADER_H
3 
43 class BinaryLoader {
44  /*========================================================================================================================
45  * Types
46  *======================================================================================================================== */
47 public:
48 
51  {
55  };
56 
59  {
64  };
65 
66 
67 
68  /*========================================================================================================================
69  * Exceptions
70  *======================================================================================================================== */
71 public:
73  class Exception: public std::runtime_error {
74  public:
75  Exception(const std::string &reason): std::runtime_error(reason) {}
76  void print(std::ostream&) const;
77  friend std::ostream& operator<<(std::ostream&, const Exception&);
78  };
79 
80 
81 
82  /*========================================================================================================================
83  * Constructors, etc.
84  *======================================================================================================================== */
85 public:
88  { init(); }
89 
90  BinaryLoader(const BinaryLoader &other)
93  preloads = other.preloads;
94  directories = other.directories;
95  }
96 
97  virtual ~BinaryLoader(){}
98 
99 private:
101  static void initclass();
102 
103 
104 
105  /*==========================================================================================================================
106  * Registration and lookup methods
107  *========================================================================================================================== */
108 public:
111  static void register_subclass(BinaryLoader*);
112 
117  virtual bool can_load(SgAsmGenericHeader*) const {
118  return true;
119  }
120 
125 
131 
135  virtual BinaryLoader *clone() const {
136  return new BinaryLoader(*this);
137  }
138 
139 
140 
141  /*========================================================================================================================
142  * Accessors for properties.
143  *======================================================================================================================== */
144 public:
148 
151 
155  void set_perform_remap(bool b) { p_perform_remap = b; }
156 
158  bool get_perform_remap() const { return p_perform_remap; }
159 
165 
168 
171  void set_debug(FILE *f) { debug = f; }
172 
174  FILE *get_debug() const { return debug; }
175 
176 
177 
178  /*========================================================================================================================
179  * Searching for shared objects
180  *======================================================================================================================== */
181 public:
185  void add_preload(const std::string &libname) {
186  preloads.push_back(libname);
187  }
188 
191  const std::vector<std::string>& get_preloads() const {
192  return preloads;
193  }
194 
200  void add_directory(const std::string &dirname) {
201  directories.push_back(dirname);
202  }
203 
207  void add_directories(const std::vector<std::string> &dirnames) {
208  directories.insert(directories.end(), dirnames.begin(), dirnames.end());
209  }
210 
212  const std::vector<std::string>& get_directories() const {
213  return directories;
214  }
215 
218  virtual std::string find_so_file(const std::string &libname) const;
219 
220 
221 
222  /*========================================================================================================================
223  * The main interface.
224  *======================================================================================================================== */
225 public:
230  static void load(SgBinaryComposite* composite, bool read_executable_file_format_only=false);
231 
235  virtual void load(SgAsmInterpretation*);
236 
255  virtual void link(SgAsmInterpretation *interp);
256 
272  virtual void remap(SgAsmInterpretation *interp);
273 
274  typedef std::vector<Exception> FixupErrors;
275 
279  virtual void fixup(SgAsmInterpretation *interp, FixupErrors *errors=NULL);
280 
281  /*========================================================================================================================
282  * Supporting types and functions
283  *======================================================================================================================== */
284 public:
286  virtual bool is_linked(SgBinaryComposite *composite, const std::string &filename);
288  virtual bool is_linked(SgAsmInterpretation *interp, const std::string &filename);
289 
294  static SgAsmGenericFile *createAsmAST(SgBinaryComposite *composite, std::string filePath);
295 
300  virtual std::vector<std::string> dependencies(SgAsmGenericHeader*);
301 
304  virtual void remap(MemoryMap*, SgAsmGenericHeader*);
305 
308  return header->get_mapped_sections();
309  }
310 
319  return header->get_base_va();
320  }
321 
330  static int64_t gcd(int64_t a, int64_t b, int64_t *x=NULL/*out*/, int64_t *y=NULL/*out*/);
331 
338  rose_addr_t val2, rose_addr_t align2);
339 
381  rose_addr_t *malign_lo, rose_addr_t *malign_hi,
382  rose_addr_t *va, rose_addr_t *mem_size,
383  rose_addr_t *offset, rose_addr_t *file_size, bool *map_private,
384  rose_addr_t *va_offset, bool *anon_lo, bool *anon_hi,
385  ConflictResolution *resolve);
386 
387 
391  virtual void addSectionsForRemap(SgAsmGenericHeader* header, SgAsmGenericSectionPtrList &allSections);
392 
398  SgAsmGenericHeaderPtrList &candidateHeaders);
399 
403 
404 
405 
406  /*========================================================================================================================
407  * Private stuff
408  *======================================================================================================================== */
409 private:
410  void init();
412  static std::vector<BinaryLoader*> loaders;
413  std::vector<std::string> preloads;
414  std::vector<std::string> directories;
415  FILE *debug;
420 };
421 
422 #endif /* ROSE_BINARYLOADER_H */