Lines Matching refs:elfFile

209 static int readElfHeader(ifstream& elfFile, Elf64_Ehdr* eh) {  in readElfHeader()  argument
210 elfFile.seekg(0); in readElfHeader()
211 if (elfFile.fail()) return -1; in readElfHeader()
213 if (!elfFile.read((char*)eh, sizeof(*eh))) return -1; in readElfHeader()
219 static int readSectionHeadersAll(ifstream& elfFile, vector<Elf64_Shdr>& shTable) { in readSectionHeadersAll() argument
223 ret = readElfHeader(elfFile, &eh); in readSectionHeadersAll()
226 elfFile.seekg(eh.e_shoff); in readSectionHeadersAll()
227 if (elfFile.fail()) return -1; in readSectionHeadersAll()
232 if (!elfFile.read((char*)shTable.data(), (eh.e_shnum * eh.e_shentsize))) return -ENOMEM; in readSectionHeadersAll()
238 static int readSectionByIdx(ifstream& elfFile, int id, vector<char>& sec) { in readSectionByIdx() argument
240 int ret = readSectionHeadersAll(elfFile, shTable); in readSectionByIdx()
243 elfFile.seekg(shTable[id].sh_offset); in readSectionByIdx()
244 if (elfFile.fail()) return -1; in readSectionByIdx()
247 if (!elfFile.read(sec.data(), shTable[id].sh_size)) return -1; in readSectionByIdx()
253 static int readSectionHeaderStrtab(ifstream& elfFile, vector<char>& strtab) { in readSectionHeaderStrtab() argument
255 int ret = readElfHeader(elfFile, &eh); in readSectionHeaderStrtab()
258 ret = readSectionByIdx(elfFile, eh.e_shstrndx, strtab); in readSectionHeaderStrtab()
265 static int getSymName(ifstream& elfFile, int nameOff, string& name) { in getSymName() argument
269 ret = readSectionHeaderStrtab(elfFile, secStrTab); in getSymName()
279 static int readSectionByName(const char* name, ifstream& elfFile, vector<char>& data) { in readSectionByName() argument
284 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByName()
287 ret = readSectionHeaderStrtab(elfFile, secStrTab); in readSectionByName()
298 elfFile.seekg(shTable[i].sh_offset); in readSectionByName()
299 if (elfFile.fail()) return -1; in readSectionByName()
301 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByName()
310 unsigned int readSectionUint(const char* name, ifstream& elfFile, unsigned int defVal) { in readSectionUint() argument
312 int ret = readSectionByName(name, elfFile, theBytes); in readSectionUint()
333 static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) { in readSectionByType() argument
337 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByType()
346 elfFile.seekg(shTable[i].sh_offset); in readSectionByType()
347 if (elfFile.fail()) return -1; in readSectionByType()
349 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByType()
361 static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) { in readSymTab() argument
366 ret = readSectionByType(elfFile, SHT_SYMTAB, secData); in readSymTab()
401 static int readProgDefs(ifstream& elfFile, vector<struct bpf_prog_def>& pd, in readProgDefs() argument
404 int ret = readSectionByName("progs", elfFile, pdData); in readProgDefs()
431 static int getSectionSymNames(ifstream& elfFile, const string& sectionName, vector<string>& names, in getSectionSymNames() argument
438 ret = readSymTab(elfFile, 1 /* sort */, symtab); in getSectionSymNames()
442 ret = readSectionHeadersAll(elfFile, shTable); in getSectionSymNames()
447 ret = getSymName(elfFile, shTable[i].sh_name, name); in getSectionSymNames()
467 ret = getSymName(elfFile, symtab[i].st_name, s); in getSectionSymNames()
477 static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs, size_t sizeOfBpfProgDef) { in readCodeSections() argument
481 ret = readSectionHeadersAll(elfFile, shTable); in readCodeSections()
486 ret = readProgDefs(elfFile, pd, sizeOfBpfProgDef); in readCodeSections()
489 ret = getSectionSymNames(elfFile, "progs", progDefNames); in readCodeSections()
497 ret = getSymName(elfFile, shTable[i].sh_name, name); in readCodeSections()
515 ret = readSectionByIdx(elfFile, i, cs_temp.data); in readCodeSections()
520 ret = getSectionSymNames(elfFile, oldName, csSymNames, STT_FUNC); in readCodeSections()
531 ret = getSymName(elfFile, shTable[i + 1].sh_name, name); in readCodeSections()
535 ret = readSectionByIdx(elfFile, i + 1, cs_temp.rel_data); in readCodeSections()
549 static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { in getSymNameByIdx() argument
553 ret = readSymTab(elfFile, 0 /* !sort */, symtab); in getSymNameByIdx()
558 return getSymName(elfFile, symtab[index].st_name, name); in getSymNameByIdx()
617 static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds, in createMaps() argument
626 ret = readSectionByName("maps", elfFile, mdData); in createMaps()
653 ret = getSectionSymNames(elfFile, "maps", mapNames); in createMaps()
890 static void applyMapRelo(ifstream& elfFile, vector<unique_fd> &mapFds, vector<codeSection>& cs) { in applyMapRelo() argument
893 int ret = getSectionSymNames(elfFile, "maps", mapNames); in applyMapRelo()
904 ret = getSymNameByIdx(elfFile, symIndex, symName); in applyMapRelo()
1104 ifstream elfFile(elfPath, ios::in | ios::binary); in loadProg() local
1105 if (!elfFile.is_open()) return -1; in loadProg()
1107 ret = readSectionByName("critical", elfFile, critical); in loadProg()
1110 ret = readSectionByName("license", elfFile, license); in loadProg()
1122 readSectionUint("bpfloader_min_ver", elfFile, DEFAULT_BPFLOADER_MIN_VER); in loadProg()
1124 readSectionUint("bpfloader_max_ver", elfFile, DEFAULT_BPFLOADER_MAX_VER); in loadProg()
1126 readSectionUint("bpfloader_min_required_ver", elfFile, 0); in loadProg()
1128 readSectionUint("netbpfload_min_ver", elfFile, 0); in loadProg()
1130 readSectionUint("size_of_bpf_map_def", elfFile, DEFAULT_SIZEOF_BPF_MAP_DEF); in loadProg()
1132 readSectionUint("size_of_bpf_prog_def", elfFile, DEFAULT_SIZEOF_BPF_PROG_DEF); in loadProg()
1176 ret = readCodeSections(elfFile, cs, sizeOfBpfProgDef); in loadProg()
1185 ret = createMaps(elfPath, elfFile, mapFds, location.prefix, sizeOfBpfMapDef, bpfloader_ver); in loadProg()
1194 applyMapRelo(elfFile, mapFds, cs); in loadProg()