diff options
author | Andreas Robinson <andr345@gmail.com> | 2009-05-15 15:34:47 +0200 |
---|---|---|
committer | Andreas Robinson <andr345@gmail.com> | 2009-05-15 15:34:47 +0200 |
commit | d1e6992067f6b06b572430d1ea90d88ec87f4221 (patch) | |
tree | 55c4eefbdaf04acc21b22d10ffe7e7ee6035489e | |
parent | a8b8b88794ea675d5c5c5399276e134daf0a1d9c (diff) | |
download | module-init-tools-d1e6992067f6b06b572430d1ea90d88ec87f4221.tar.gz |
elfops: use elf_file in, and return section header from, get_module()
Returning the section header allows invalidate/strip_section() to
use get_section(). get_module() is more robust than strip_section()'s
own section lookup.
Signed-off-by: Andreas Robinson <andr345@gmail.com>
-rw-r--r-- | elfops_core.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/elfops_core.c b/elfops_core.c index 8968593..64e353a 100644 --- a/elfops_core.c +++ b/elfops_core.c @@ -14,12 +14,15 @@ # error "Undefined ELF word length" #endif -static void *PERBIT(get_section)(void *data, - unsigned long len, +static void *PERBIT(get_section)(struct elf_file *module, const char *secname, - unsigned long *secsize, - int conv) + ElfPERBIT(Shdr) **sechdr, + unsigned long *secsize) { + void *data = module->data; + unsigned long len = module->len; + int conv = module->conv; + ElfPERBIT(Ehdr) *hdr; ElfPERBIT(Shdr) *sechdrs; ElfPERBIT(Off) e_shoff; @@ -45,13 +48,14 @@ static void *PERBIT(get_section)(void *data, if (len < END(sechdrs[e_shstrndx].sh_offset, conv)) return NULL; - /* Find section by name, return pointer and size. */ - + /* Find section by name; return header, pointer and size. */ secnames = data + END(sechdrs[e_shstrndx].sh_offset, conv); for (i = 1; i < e_shnum; i++) { if (streq(secnames + END(sechdrs[i].sh_name, conv), secname)) { *secsize = END(sechdrs[i].sh_size, conv); secoffset = END(sechdrs[i].sh_offset, conv); + if (sechdr) + *sechdr = sechdrs + i; if (len < secoffset + *secsize) return NULL; return data + secoffset; @@ -66,8 +70,7 @@ static void *PERBIT(load_section)(struct elf_file *module, const char *secname, unsigned long *secsize) { - return PERBIT(get_section)(module->data, module->len, - secname, secsize, module->conv); + return PERBIT(get_section)(module, secname, NULL, secsize); } static struct string_table *PERBIT(load_strings)(struct elf_file *module, |