~ubuntu-core-dev/module-init-tools/ubuntu

« back to all changes in this revision

Viewing changes to elf_core.c

  • Committer: Scott James Remnant
  • Date: 2009-07-16 15:24:17 UTC
  • mfrom: (152.1.38)
  • Revision ID: scott@netsplit.com-20090716152417-7ak1sklxb59cs4fz
MergeĀ 3.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
void *PERBIT(get_section)(void *file,
2
 
                          unsigned long fsize,
3
 
                          const char *secname,
4
 
                          unsigned long *secsize,
5
 
                          int conv)
6
 
{
7
 
        ElfPERBIT(Ehdr) *hdr;
8
 
        ElfPERBIT(Shdr) *sechdrs;
9
 
        ElfPERBIT(Off) e_shoff;
10
 
        ElfPERBIT(Half) e_shnum, e_shstrndx;
11
 
 
12
 
        const char *secnames;
13
 
        unsigned int i;
14
 
 
15
 
        if (fsize > 0 && fsize < sizeof(*hdr))
16
 
                return NULL;
17
 
 
18
 
        hdr = file;
19
 
        e_shoff = END(hdr->e_shoff, conv);
20
 
        e_shnum = END(hdr->e_shnum, conv);
21
 
        e_shstrndx = END(hdr->e_shstrndx, conv);
22
 
 
23
 
        if (fsize > 0 && fsize < e_shoff + e_shnum * sizeof(sechdrs[0]))
24
 
                return NULL;
25
 
 
26
 
        sechdrs = file + e_shoff;
27
 
 
28
 
        if (fsize > 0 && fsize < END(sechdrs[e_shstrndx].sh_offset, conv))
29
 
                return NULL;
30
 
 
31
 
        /* Find section by name, return pointer and size. */
32
 
 
33
 
        secnames = file + END(sechdrs[e_shstrndx].sh_offset, conv);
34
 
        for (i = 1; i < e_shnum; i++) {
35
 
                if (streq(secnames + END(sechdrs[i].sh_name, conv), secname)) {
36
 
                        *secsize = END(sechdrs[i].sh_size, conv);
37
 
                        return file + END(sechdrs[i].sh_offset, conv);
38
 
                }
39
 
        }
40
 
        *secsize = 0;
41
 
        return NULL;
42
 
}
43