diff options
author | Andreas Robinson <andr345@gmail.com> | 2009-05-09 13:01:50 +0200 |
---|---|---|
committer | Andreas Robinson <andr345@gmail.com> | 2009-05-12 12:55:40 +0200 |
commit | 042a3cf35db4f00b55141750fe368e368070fb55 (patch) | |
tree | eabe31ae65c46a772a4753b80f7f475fcb793453 | |
parent | fff8e6472aa31c8e7034ae5615b19f8742fe484c (diff) | |
download | module-init-tools-042a3cf35db4f00b55141750fe368e368070fb55.tar.gz |
moduleops: add load_strings() operation
load_string() treats the data in an ELF-file section as a collection
of strings and builds a string table from those. It can be used to
read .modinfo, __ksymtab_strings and similar sections.
load_symbols() is updated to take advantage of the new function.
Signed-off-by: Andreas Robinson <andr345@gmail.com>
-rw-r--r-- | moduleops.h | 2 | ||||
-rw-r--r-- | moduleops_core.c | 51 |
2 files changed, 28 insertions, 25 deletions
diff --git a/moduleops.h b/moduleops.h index 2624fa7..88616ce 100644 --- a/moduleops.h +++ b/moduleops.h @@ -16,6 +16,8 @@ struct kernel_symbol64 { struct module_ops { + struct string_table *(*load_strings)(struct module *module, + const char *secname, struct string_table *tbl); struct string_table *(*load_symbols)(struct module *module); struct string_table *(*load_dep_syms)(struct module *module, struct string_table **types); diff --git a/moduleops_core.c b/moduleops_core.c index ea9b110..053c84e 100644 --- a/moduleops_core.c +++ b/moduleops_core.c @@ -7,41 +7,41 @@ static void *PERBIT(load_section)(ElfPERBIT(Ehdr) *hdr, return PERBIT(get_section)(hdr, 0, secname, secsize, conv); } +static struct string_table *PERBIT(load_strings)(struct module *module, + const char *secname, + struct string_table *tbl) +{ + unsigned long size; + const char *strings; + + strings = PERBIT(load_section)(module->data, secname, &size, module->conv); + if (strings) { + /* Skip any zero padding. */ + while (!strings[0]) { + strings++; + if (size-- <= 1) + return tbl; + } + for (; strings; strings = next_string(strings, &size)) + tbl = NOFAIL(strtbl_add(strings, tbl)); + } + return tbl; +} + static struct string_table *PERBIT(load_symbols)(struct module *module) { struct PERBIT(kernel_symbol) *ksyms; struct string_table *symtbl; - char *ksymstrings; unsigned long i, size; symtbl = NULL; /* New-style: strings are in this section. */ - ksymstrings = PERBIT(load_section)(module->data, "__ksymtab_strings", - &size, module->conv); - if (ksymstrings) { - unsigned int i = 0; - for (;;) { - /* Skip any zero padding. */ - while (!ksymstrings[i]) - if (++i >= size) - return symtbl; - symtbl = NOFAIL(strtbl_add(ksymstrings + i, symtbl)); - i += strlen(ksymstrings+i); - } + symtbl = PERBIT(load_strings)(module, "__ksymtab_strings", symtbl); + if (symtbl) { /* GPL symbols too */ - ksymstrings = PERBIT(load_section)(module->data, - "__ksymtab_strings_gpl", - &size, module->conv); - for (;;) { - /* Skip any zero padding. */ - while (!ksymstrings[i]) - if (++i >= size) - return symtbl; - symtbl = NOFAIL(strtbl_add(ksymstrings + i, symtbl)); - i += strlen(ksymstrings+i); - } - return symtbl; + return PERBIT(load_strings)(module, "__ksymtab_strings_gpl", + symtbl); } /* Old-style. */ @@ -234,6 +234,7 @@ static void PERBIT(fetch_tables)(struct module *module) } struct module_ops PERBIT(mod_ops) = { + .load_strings = PERBIT(load_strings), .load_symbols = PERBIT(load_symbols), .load_dep_syms = PERBIT(load_dep_syms), .fetch_tables = PERBIT(fetch_tables), |