ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
elf-cache.h
Go to the documentation of this file.
1 #ifndef ELF_CACHE_H
2 #define ELF_CACHE_H
3 
4 #include <string>
5 #include <stdint.h>
6 #include <elf.h>
7 #include <link.h>
8 #include <vector>
9 
10 namespace ns3 {
11 
12 class ElfCache
13 {
14 public:
15  ElfCache (std::string directory, uint32_t uid);
16 
18  {
19  std::string cachedFilename;
20  std::string basename;
23  uint32_t id;
24  std::vector<uint32_t> deps;
25  };
26  struct ElfCachedFile Add (std::string filename);
27 
28 private:
29  struct FileInfo
30  {
31  long p_vaddr;
32  long p_memsz;
33  std::vector<uint32_t> deps;
34  };
35  struct Overriden
36  {
37  std::string from;
38  std::string to;
39  };
40  std::string GetBasename (std::string filename) const;
41  void CopyFile (std::string source, std::string destination) const;
42  void WriteString (char *str, uint32_t uid) const;
43  uint8_t NumberToChar (uint8_t c) const;
44  static uint32_t AllocateId (void);
45  struct FileInfo EditBuffer (uint8_t *map, uint32_t selfId) const;
46  struct FileInfo EditFile (std::string filename, uint32_t selfId) const;
47  uint32_t GetDepId (std::string depname) const;
48  std::string EnsureCacheDirectory (void) const;
49  unsigned long GetBaseAddress (ElfW (Phdr) * phdr, long phnum) const;
50  long GetDtStrTab (ElfW (Dyn) * dyn, long baseAddress) const;
51 
52 
53  std::string m_directory;
54  uint32_t m_uid;
55  std::vector<struct ElfCachedFile> m_files;
56  std::vector<struct Overriden> m_overriden;
57 };
58 
59 } // namespace ns3
60 
61 #endif /* ELF_CACHE_H */