Lines Matching refs:elfFile

97 static int readElfHeader(ifstream& elfFile, Elf64_Ehdr* eh) {  in readElfHeader()  argument
98 elfFile.seekg(0); in readElfHeader()
99 if (elfFile.fail()) return -1; in readElfHeader()
101 if (!elfFile.read((char*)eh, sizeof(*eh))) return -1; in readElfHeader()
107 static int readSectionHeadersAll(ifstream& elfFile, vector<Elf64_Shdr>& shTable) { in readSectionHeadersAll() argument
111 ret = readElfHeader(elfFile, &eh); in readSectionHeadersAll()
114 elfFile.seekg(eh.e_shoff); in readSectionHeadersAll()
115 if (elfFile.fail()) return -1; in readSectionHeadersAll()
120 if (!elfFile.read((char*)shTable.data(), (eh.e_shnum * eh.e_shentsize))) return -ENOMEM; in readSectionHeadersAll()
126 static int readSectionByIdx(ifstream& elfFile, int id, vector<char>& sec) { in readSectionByIdx() argument
130 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByIdx()
134 elfFile.seekg(shTable[id].sh_offset); in readSectionByIdx()
135 if (elfFile.fail()) return -1; in readSectionByIdx()
138 if (!elfFile.read(sec.data(), shTable[id].sh_size)) return -1; in readSectionByIdx()
144 static int readSectionHeaderStrtab(ifstream& elfFile, vector<char>& strtab) { in readSectionHeaderStrtab() argument
148 ret = readElfHeader(elfFile, &eh); in readSectionHeaderStrtab()
151 ret = readSectionByIdx(elfFile, eh.e_shstrndx, strtab); in readSectionHeaderStrtab()
158 static int getSymName(ifstream& elfFile, int nameOff, string& name) { in getSymName() argument
162 ret = readSectionHeaderStrtab(elfFile, secStrTab); in getSymName()
172 static int readSectionByName(const char* name, ifstream& elfFile, vector<char>& data) { in readSectionByName() argument
177 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByName()
180 ret = readSectionHeaderStrtab(elfFile, secStrTab); in readSectionByName()
191 elfFile.seekg(shTable[i].sh_offset); in readSectionByName()
192 if (elfFile.fail()) return -1; in readSectionByName()
194 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByName()
203 static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) { in readSectionByType() argument
207 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByType()
216 elfFile.seekg(shTable[i].sh_offset); in readSectionByType()
217 if (elfFile.fail()) return -1; in readSectionByType()
219 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByType()
231 static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) { in readSymTab() argument
236 ret = readSectionByType(elfFile, SHT_SYMTAB, secData); in readSymTab()
279 static int readProgDefs(ifstream& elfFile, vector<struct bpf_prog_def>& pd) { in readProgDefs() argument
281 int ret = readSectionByName("progs", elfFile, pdData); in readProgDefs()
290 static int getSectionSymNames(ifstream& elfFile, const string& sectionName, vector<string>& names) { in getSectionSymNames() argument
296 ret = readSymTab(elfFile, 1 /* sort */, symtab); in getSectionSymNames()
300 ret = readSectionHeadersAll(elfFile, shTable); in getSectionSymNames()
305 ret = getSymName(elfFile, shTable[i].sh_name, name); in getSectionSymNames()
323 ret = getSymName(elfFile, symtab[i].st_name, s); in getSectionSymNames()
333 static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs) { in readCodeSections() argument
337 ret = readSectionHeadersAll(elfFile, shTable); in readCodeSections()
342 ret = readProgDefs(elfFile, pd); in readCodeSections()
345 ret = getSectionSymNames(elfFile, "progs", progDefNames); in readCodeSections()
353 ret = getSymName(elfFile, shTable[i].sh_name, name); in readCodeSections()
363 ret = readSectionByIdx(elfFile, i, cs_temp.data); in readCodeSections()
368 ret = getSectionSymNames(elfFile, oldName, csSymNames); in readCodeSections()
380 ret = getSymName(elfFile, shTable[i + 1].sh_name, name); in readCodeSections()
384 ret = readSectionByIdx(elfFile, i + 1, cs_temp.rel_data); in readCodeSections()
398 static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { in getSymNameByIdx() argument
402 ret = readSymTab(elfFile, 0 /* !sort */, symtab); in getSymNameByIdx()
407 return getSymName(elfFile, symtab[index].st_name, name); in getSymNameByIdx()
410 static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds) { in createMaps() argument
417 ret = readSectionByName("maps", elfFile, mdData); in createMaps()
423 ret = getSectionSymNames(elfFile, "maps", mapNames); in createMaps()
506 static void applyMapRelo(ifstream& elfFile, vector<unique_fd> &mapFds, vector<codeSection>& cs) { in applyMapRelo() argument
509 int ret = getSectionSymNames(elfFile, "maps", mapNames); in applyMapRelo()
520 ret = getSymNameByIdx(elfFile, symIndex, symName); in applyMapRelo()
626 ifstream elfFile(elfPath, ios::in | ios::binary); in loadProg() local
627 if (!elfFile.is_open()) return -1; in loadProg()
629 ret = readSectionByName("critical", elfFile, critical); in loadProg()
632 ret = readSectionByName("license", elfFile, license); in loadProg()
642 ret = readCodeSections(elfFile, cs); in loadProg()
651 ret = createMaps(elfPath, elfFile, mapFds); in loadProg()
660 applyMapRelo(elfFile, mapFds, cs); in loadProg()