00001 #ifndef ROSE_LOADER_H
00002 #define ROSE_LOADER_H
00003
00004
00005 #define ALIGN_UP(ADDR,ALMNT) ((((ADDR)+(ALMNT)-1)/(ALMNT))*(ALMNT))
00006 #define ALIGN_DN(ADDR,ALMNT) (((ADDR)/(ALMNT))*(ALMNT))
00007
00008
00040 class Loader {
00041 public:
00042 Loader(): p_debug(NULL) { ctor(); }
00043 virtual ~Loader() {}
00044
00045
00046
00047
00048 public:
00049
00054 static void register_subclass(Loader*);
00055
00060 static Loader *find_loader(SgAsmGenericHeader*);
00061
00067 virtual bool can_handle(SgAsmGenericHeader*) { return true; }
00068
00070 static void initclass();
00071
00072
00073
00074
00075 public:
00076
00079 virtual MemoryMap *map_all_sections(MemoryMap *map, SgAsmGenericFile *file, bool allow_overmap=true) {
00080 return map_all_sections(map, file->get_sections(), allow_overmap);
00081 }
00082
00085 virtual MemoryMap *map_all_sections(MemoryMap *map, SgAsmGenericHeader *fhdr, bool allow_overmap=true) {
00086 return map_all_sections(map, fhdr->get_sections()->get_sections(), allow_overmap);
00087 }
00088
00091 virtual MemoryMap *map_all_sections(MemoryMap*, const SgAsmGenericSectionPtrList §ions, bool allow_overmap=true);
00092
00093
00094
00097 virtual MemoryMap *map_code_sections(MemoryMap *map, SgAsmGenericFile *file, bool allow_overmap=true) {
00098 return map_code_sections(map, file->get_sections(), allow_overmap);
00099 }
00100
00103 virtual MemoryMap *map_code_sections(MemoryMap *map, SgAsmGenericHeader *fhdr, bool allow_overmap=true) {
00104 return map_code_sections(map, fhdr->get_sections()->get_sections(), allow_overmap);
00105 }
00106
00109 virtual MemoryMap *map_code_sections(MemoryMap*, const SgAsmGenericSectionPtrList §ions, bool allow_overmap=true);
00110
00111
00112
00115 virtual MemoryMap *map_executable_sections(MemoryMap *map, SgAsmGenericFile *file, bool allow_overmap=true) {
00116 return map_executable_sections(map, file->get_sections(), allow_overmap);
00117 }
00118
00121 virtual MemoryMap *map_executable_sections(MemoryMap *map, SgAsmGenericHeader *fhdr, bool allow_overmap=true) {
00122 return map_executable_sections(map, fhdr->get_sections()->get_sections(), allow_overmap);
00123 }
00124
00127 virtual MemoryMap *map_executable_sections(MemoryMap*, const SgAsmGenericSectionPtrList §ions, bool allow_overmap=true);
00128
00129
00130
00133 virtual MemoryMap *map_writable_sections(MemoryMap *map, SgAsmGenericFile *file, bool allow_overmap=true) {
00134 return map_writable_sections(map, file->get_sections(), allow_overmap);
00135 }
00136
00139 virtual MemoryMap *map_writable_sections(MemoryMap *map, SgAsmGenericHeader *fhdr, bool allow_overmap=true) {
00140 return map_writable_sections(map, fhdr->get_sections()->get_sections(), allow_overmap);
00141 }
00142
00145 virtual MemoryMap *map_writable_sections(MemoryMap*, const SgAsmGenericSectionPtrList §ions, bool allow_overmap=true);
00146
00147
00148
00149
00150 public:
00151
00152 enum Contribution {
00153 CONTRIBUTE_NONE,
00154 CONTRIBUTE_ADD,
00155 CONTRIBUTE_SUB
00156 };
00157
00164 class Selector {
00165 public:
00166 virtual ~Selector() {}
00167 virtual Contribution contributes(SgAsmGenericSection*) = 0;
00168 };
00169
00170
00171
00172
00173 public:
00174
00203 virtual rose_addr_t align_values(SgAsmGenericSection*, Contribution,
00204 rose_addr_t *va, rose_addr_t *mem_size,
00205 rose_addr_t *offset, rose_addr_t *file_size,
00206 const MemoryMap *current);
00207
00217 virtual SgAsmGenericSectionPtrList order_sections(const SgAsmGenericSectionPtrList&);
00218
00229 virtual MemoryMap *create_map(MemoryMap *map, const SgAsmGenericSectionPtrList&, Selector*, bool allow_overmap=true);
00230
00231
00232
00233
00234
00237 void set_debug(FILE *f) { p_debug=f; }
00238
00241 FILE *get_debug() const { return p_debug; }
00242
00243 private:
00244 void ctor();
00245 static std::vector<Loader*> p_registered;
00246 FILE *p_debug;
00247 };
00248
00249 #endif