mirror of
https://github.com/dynup/kpatch
synced 2025-02-17 02:06:53 +00:00
kpatch-elf: add kpatch_remove_and_free_section()
Add kpatch_remove_and_free_section(), which, given a section name, removes and frees all matching sections from the passed in kpatch_elf.
This commit is contained in:
parent
dac26b8cb2
commit
52e2ad66ca
@ -671,6 +671,40 @@ struct section *create_section_pair(struct kpatch_elf *kelf, char *name,
|
||||
return sec;
|
||||
}
|
||||
|
||||
void kpatch_remove_and_free_section(struct kpatch_elf *kelf, char *secname)
|
||||
{
|
||||
struct section *sec, *safesec;
|
||||
struct rela *rela, *saferela;
|
||||
|
||||
list_for_each_entry_safe(sec, safesec, &kelf->sections, list) {
|
||||
if (strcmp(secname, sec->name))
|
||||
continue;
|
||||
|
||||
if (is_rela_section(sec)) {
|
||||
list_for_each_entry_safe(rela, saferela, &sec->relas, list) {
|
||||
list_del(&rela->list);
|
||||
memset(rela, 0, sizeof(*rela));
|
||||
free(rela);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the STT_SECTION symbol from the symtab,
|
||||
* otherwise when we remove the section we'll end up
|
||||
* with UNDEF section symbols in the symtab.
|
||||
*/
|
||||
if (!is_rela_section(sec) && sec->secsym) {
|
||||
list_del(&sec->secsym->list);
|
||||
memset(sec->secsym, 0, sizeof(*sec->secsym));
|
||||
free(sec->secsym);
|
||||
}
|
||||
|
||||
list_del(&sec->list);
|
||||
memset(sec, 0, sizeof(*sec));
|
||||
free(sec);
|
||||
}
|
||||
}
|
||||
|
||||
void kpatch_reindex_elements(struct kpatch_elf *kelf)
|
||||
{
|
||||
struct section *sec;
|
||||
|
@ -150,6 +150,7 @@ void kpatch_create_strtab(struct kpatch_elf *kelf);
|
||||
void kpatch_create_symtab(struct kpatch_elf *kelf);
|
||||
struct section *create_section_pair(struct kpatch_elf *kelf, char *name,
|
||||
int entsize, int nr);
|
||||
void kpatch_remove_and_free_section(struct kpatch_elf *kelf, char *secname);
|
||||
void kpatch_reindex_elements(struct kpatch_elf *kelf);
|
||||
void kpatch_rebuild_rela_section_data(struct section *sec);
|
||||
void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile);
|
||||
|
Loading…
Reference in New Issue
Block a user