Lines Matching refs:elfFile

118 static int readElfHeader(ifstream& elfFile, Elf64_Ehdr* eh) {  in readElfHeader()  argument
119 elfFile.seekg(0); in readElfHeader()
120 if (elfFile.fail()) return -1; in readElfHeader()
122 if (!elfFile.read((char*)eh, sizeof(*eh))) return -1; in readElfHeader()
128 static int readSectionHeadersAll(ifstream& elfFile, vector<Elf64_Shdr>& shTable) { in readSectionHeadersAll() argument
132 ret = readElfHeader(elfFile, &eh); in readSectionHeadersAll()
135 elfFile.seekg(eh.e_shoff); in readSectionHeadersAll()
136 if (elfFile.fail()) return -1; in readSectionHeadersAll()
141 if (!elfFile.read((char*)shTable.data(), (eh.e_shnum * eh.e_shentsize))) return -ENOMEM; in readSectionHeadersAll()
147 static int readSectionByIdx(ifstream& elfFile, int id, vector<char>& sec) { in readSectionByIdx() argument
149 int ret = readSectionHeadersAll(elfFile, shTable); in readSectionByIdx()
152 elfFile.seekg(shTable[id].sh_offset); in readSectionByIdx()
153 if (elfFile.fail()) return -1; in readSectionByIdx()
156 if (!elfFile.read(sec.data(), shTable[id].sh_size)) return -1; in readSectionByIdx()
162 static int readSectionHeaderStrtab(ifstream& elfFile, vector<char>& strtab) { in readSectionHeaderStrtab() argument
164 int ret = readElfHeader(elfFile, &eh); in readSectionHeaderStrtab()
167 ret = readSectionByIdx(elfFile, eh.e_shstrndx, strtab); in readSectionHeaderStrtab()
174 static int getSymName(ifstream& elfFile, int nameOff, string& name) { in getSymName() argument
178 ret = readSectionHeaderStrtab(elfFile, secStrTab); in getSymName()
188 static int readSectionByName(const char* name, ifstream& elfFile, vector<char>& data) { in readSectionByName() argument
193 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByName()
196 ret = readSectionHeaderStrtab(elfFile, secStrTab); in readSectionByName()
207 elfFile.seekg(shTable[i].sh_offset); in readSectionByName()
208 if (elfFile.fail()) return -1; in readSectionByName()
210 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByName()
219 unsigned int readSectionUint(const char* name, ifstream& elfFile, unsigned int defVal) { in readSectionUint() argument
221 int ret = readSectionByName(name, elfFile, theBytes); in readSectionUint()
242 static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) { in readSectionByType() argument
246 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByType()
255 elfFile.seekg(shTable[i].sh_offset); in readSectionByType()
256 if (elfFile.fail()) return -1; in readSectionByType()
258 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByType()
270 static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) { in readSymTab() argument
275 ret = readSectionByType(elfFile, SHT_SYMTAB, secData); in readSymTab()
311 static int readProgDefs(ifstream& elfFile, vector<struct bpf_prog_def>& pd) { in readProgDefs() argument
313 int ret = readSectionByName("progs", elfFile, pdData); in readProgDefs()
327 static int getSectionSymNames(ifstream& elfFile, const string& sectionName, vector<string>& names, in getSectionSymNames() argument
334 ret = readSymTab(elfFile, 1 /* sort */, symtab); in getSectionSymNames()
338 ret = readSectionHeadersAll(elfFile, shTable); in getSectionSymNames()
343 ret = getSymName(elfFile, shTable[i].sh_name, name); in getSectionSymNames()
363 ret = getSymName(elfFile, symtab[i].st_name, s); in getSectionSymNames()
386 static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs, in readCodeSections() argument
391 ret = readSectionHeadersAll(elfFile, shTable); in readCodeSections()
396 ret = readProgDefs(elfFile, pd); in readCodeSections()
399 ret = getSectionSymNames(elfFile, "progs", progDefNames); in readCodeSections()
407 ret = getSymName(elfFile, shTable[i].sh_name, name); in readCodeSections()
427 ret = readSectionByIdx(elfFile, i, cs_temp.data); in readCodeSections()
432 ret = getSectionSymNames(elfFile, oldName, csSymNames, STT_FUNC); in readCodeSections()
443 ret = getSymName(elfFile, shTable[i + 1].sh_name, name); in readCodeSections()
447 ret = readSectionByIdx(elfFile, i + 1, cs_temp.rel_data); in readCodeSections()
461 static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { in getSymNameByIdx() argument
465 ret = readSymTab(elfFile, 0 /* !sort */, symtab); in getSymNameByIdx()
470 return getSymName(elfFile, symtab[index].st_name, name); in getSymNameByIdx()
521 static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds, in createMaps() argument
529 ret = readSectionByName("maps", elfFile, mdData); in createMaps()
541 ret = getSectionSymNames(elfFile, "maps", mapNames); in createMaps()
679 static void applyMapRelo(ifstream& elfFile, vector<unique_fd> &mapFds, vector<codeSection>& cs) { in applyMapRelo() argument
682 int ret = getSectionSymNames(elfFile, "maps", mapNames); in applyMapRelo()
693 ret = getSymNameByIdx(elfFile, symIndex, symName); in applyMapRelo()
829 ifstream elfFile(elfPath, ios::in | ios::binary); in loadProg() local
830 if (!elfFile.is_open()) return -1; in loadProg()
832 ret = readSectionByName("critical", elfFile, critical); in loadProg()
835 ret = readSectionByName("license", elfFile, license); in loadProg()
845 ret = readCodeSections(elfFile, cs, location.allowedProgTypes, location.allowedProgTypesLength); in loadProg()
851 ret = createMaps(elfPath, elfFile, mapFds, location.prefix); in loadProg()
860 applyMapRelo(elfFile, mapFds, cs); in loadProg()