• Home
  • Raw
  • Download

Lines Matching refs:elfFile

112 static int readElfHeader(ifstream& elfFile, Elf64_Ehdr* eh) {  in readElfHeader()  argument
113 elfFile.seekg(0); in readElfHeader()
114 if (elfFile.fail()) return -1; in readElfHeader()
116 if (!elfFile.read((char*)eh, sizeof(*eh))) return -1; in readElfHeader()
122 static int readSectionHeadersAll(ifstream& elfFile, vector<Elf64_Shdr>& shTable) { in readSectionHeadersAll() argument
126 ret = readElfHeader(elfFile, &eh); in readSectionHeadersAll()
129 elfFile.seekg(eh.e_shoff); in readSectionHeadersAll()
130 if (elfFile.fail()) return -1; in readSectionHeadersAll()
135 if (!elfFile.read((char*)shTable.data(), (eh.e_shnum * eh.e_shentsize))) return -ENOMEM; in readSectionHeadersAll()
141 static int readSectionByIdx(ifstream& elfFile, int id, vector<char>& sec) { in readSectionByIdx() argument
143 int ret = readSectionHeadersAll(elfFile, shTable); in readSectionByIdx()
146 elfFile.seekg(shTable[id].sh_offset); in readSectionByIdx()
147 if (elfFile.fail()) return -1; in readSectionByIdx()
150 if (!elfFile.read(sec.data(), shTable[id].sh_size)) return -1; in readSectionByIdx()
156 static int readSectionHeaderStrtab(ifstream& elfFile, vector<char>& strtab) { in readSectionHeaderStrtab() argument
158 int ret = readElfHeader(elfFile, &eh); in readSectionHeaderStrtab()
161 ret = readSectionByIdx(elfFile, eh.e_shstrndx, strtab); in readSectionHeaderStrtab()
168 static int getSymName(ifstream& elfFile, int nameOff, string& name) { in getSymName() argument
172 ret = readSectionHeaderStrtab(elfFile, secStrTab); in getSymName()
182 static int readSectionByName(const char* name, ifstream& elfFile, vector<char>& data) { in readSectionByName() argument
187 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByName()
190 ret = readSectionHeaderStrtab(elfFile, secStrTab); in readSectionByName()
201 elfFile.seekg(shTable[i].sh_offset); in readSectionByName()
202 if (elfFile.fail()) return -1; in readSectionByName()
204 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByName()
213 unsigned int readSectionUint(const char* name, ifstream& elfFile, unsigned int defVal) { in readSectionUint() argument
215 int ret = readSectionByName(name, elfFile, theBytes); in readSectionUint()
236 static int readSectionByType(ifstream& elfFile, int type, vector<char>& data) { in readSectionByType() argument
240 ret = readSectionHeadersAll(elfFile, shTable); in readSectionByType()
249 elfFile.seekg(shTable[i].sh_offset); in readSectionByType()
250 if (elfFile.fail()) return -1; in readSectionByType()
252 if (!elfFile.read((char*)dataTmp.data(), shTable[i].sh_size)) return -1; in readSectionByType()
264 static int readSymTab(ifstream& elfFile, int sort, vector<Elf64_Sym>& data) { in readSymTab() argument
269 ret = readSectionByType(elfFile, SHT_SYMTAB, secData); in readSymTab()
312 static int readProgDefs(ifstream& elfFile, vector<struct bpf_prog_def>& pd, in readProgDefs() argument
315 int ret = readSectionByName("progs", elfFile, pdData); in readProgDefs()
345 static int getSectionSymNames(ifstream& elfFile, const string& sectionName, vector<string>& names) { in getSectionSymNames() argument
351 ret = readSymTab(elfFile, 1 /* sort */, symtab); in getSectionSymNames()
355 ret = readSectionHeadersAll(elfFile, shTable); in getSectionSymNames()
360 ret = getSymName(elfFile, shTable[i].sh_name, name); in getSectionSymNames()
378 ret = getSymName(elfFile, symtab[i].st_name, s); in getSectionSymNames()
388 static int readCodeSections(ifstream& elfFile, vector<codeSection>& cs, size_t sizeOfBpfProgDef) { in readCodeSections() argument
392 ret = readSectionHeadersAll(elfFile, shTable); in readCodeSections()
397 ret = readProgDefs(elfFile, pd, sizeOfBpfProgDef); in readCodeSections()
400 ret = getSectionSymNames(elfFile, "progs", progDefNames); in readCodeSections()
408 ret = getSymName(elfFile, shTable[i].sh_name, name); in readCodeSections()
421 ret = readSectionByIdx(elfFile, i, cs_temp.data); in readCodeSections()
426 ret = getSectionSymNames(elfFile, oldName, csSymNames); in readCodeSections()
438 ret = getSymName(elfFile, shTable[i + 1].sh_name, name); in readCodeSections()
442 ret = readSectionByIdx(elfFile, i + 1, cs_temp.rel_data); in readCodeSections()
456 static int getSymNameByIdx(ifstream& elfFile, int index, string& name) { in getSymNameByIdx() argument
460 ret = readSymTab(elfFile, 0 /* !sort */, symtab); in getSymNameByIdx()
465 return getSymName(elfFile, symtab[index].st_name, name); in getSymNameByIdx()
468 static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds, in createMaps() argument
476 ret = readSectionByName("maps", elfFile, mdData); in createMaps()
503 ret = getSectionSymNames(elfFile, "maps", mapNames); in createMaps()
639 static void applyMapRelo(ifstream& elfFile, vector<unique_fd> &mapFds, vector<codeSection>& cs) { in applyMapRelo() argument
642 int ret = getSectionSymNames(elfFile, "maps", mapNames); in applyMapRelo()
653 ret = getSymNameByIdx(elfFile, symIndex, symName); in applyMapRelo()
772 ifstream elfFile(elfPath, ios::in | ios::binary); in loadProg() local
773 if (!elfFile.is_open()) return -1; in loadProg()
775 ret = readSectionByName("critical", elfFile, critical); in loadProg()
778 ret = readSectionByName("license", elfFile, license); in loadProg()
790 readSectionUint("bpfloader_min_ver", elfFile, DEFAULT_BPFLOADER_MIN_VER); in loadProg()
792 readSectionUint("bpfloader_max_ver", elfFile, DEFAULT_BPFLOADER_MAX_VER); in loadProg()
794 readSectionUint("size_of_bpf_map_def", elfFile, DEFAULT_SIZEOF_BPF_MAP_DEF); in loadProg()
796 readSectionUint("size_of_bpf_prog_def", elfFile, DEFAULT_SIZEOF_BPF_PROG_DEF); in loadProg()
827 ret = readCodeSections(elfFile, cs, sizeOfBpfProgDef); in loadProg()
836 ret = createMaps(elfPath, elfFile, mapFds, prefix, sizeOfBpfMapDef); in loadProg()
845 applyMapRelo(elfFile, mapFds, cs); in loadProg()