diff options
Diffstat (limited to 'elfutils/libdwfl/segment.c')
-rw-r--r-- | elfutils/libdwfl/segment.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/elfutils/libdwfl/segment.c b/elfutils/libdwfl/segment.c index 78220e3b..36c850f0 100644 --- a/elfutils/libdwfl/segment.c +++ b/elfutils/libdwfl/segment.c @@ -1,5 +1,5 @@ /* Manage address space lookup table for libdwfl. - Copyright (C) 2008 Red Hat, Inc. + Copyright (C) 2008, 2009 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -83,12 +83,26 @@ insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx) int *nsegndx = realloc (dwfl->lookup_segndx, sizeof nsegndx[0] * n); if (unlikely (nsegndx == NULL)) { - free (naddr); + if (naddr != dwfl->lookup_addr) + free (naddr); return true; } dwfl->lookup_alloc = n; dwfl->lookup_addr = naddr; dwfl->lookup_segndx = nsegndx; + + if (dwfl->lookup_module != NULL) + { + /* Make sure this array is big enough too. */ + Dwfl_Module **old = dwfl->lookup_module; + dwfl->lookup_module = realloc (dwfl->lookup_module, + sizeof dwfl->lookup_module[0] * n); + if (unlikely (dwfl->lookup_module == NULL)) + { + free (old); + return true; + } + } } if (unlikely (i < dwfl->lookup_elts)) @@ -128,7 +142,7 @@ lookup (Dwfl *dwfl, GElf_Addr address, int hint) if (hint >= 0 && address >= dwfl->lookup_addr[hint] && ((size_t) hint + 1 == dwfl->lookup_elts - || address <= dwfl->lookup_addr[hint + 1])) + || address < dwfl->lookup_addr[hint + 1])) return hint; /* Do binary search on the array indexed by module load address. */ @@ -175,9 +189,17 @@ reify_segments (Dwfl *dwfl) return true; ++idx; } + else if (dwfl->lookup_addr[idx] < start) + { + /* The module starts past the end of this segment. + Add a new one. */ + if (unlikely (insert (dwfl, idx + 1, start, end, -1))) + return true; + ++idx; + } - if (((size_t) idx + 1 == dwfl->lookup_elts - || end < dwfl->lookup_addr[idx + 1]) + if ((size_t) idx + 1 < dwfl->lookup_elts + && end < dwfl->lookup_addr[idx + 1] /* The module ends in the middle of this segment. Split it. */ && unlikely (insert (dwfl, idx + 1, end, dwfl->lookup_addr[idx + 1], -1))) @@ -261,6 +283,12 @@ dwfl_report_segment (Dwfl *dwfl, int ndx, const GElf_Phdr *phdr, GElf_Addr bias, phdr->p_align < dwfl->segment_align)) dwfl->segment_align = phdr->p_align; + if (unlikely (dwfl->lookup_module != NULL)) + { + free (dwfl->lookup_module); + dwfl->lookup_module = NULL; + } + GElf_Addr start = segment_start (dwfl, bias + phdr->p_vaddr); GElf_Addr end = segment_end (dwfl, bias + phdr->p_vaddr + phdr->p_memsz); @@ -289,12 +317,6 @@ dwfl_report_segment (Dwfl *dwfl, int ndx, const GElf_Phdr *phdr, GElf_Addr bias, dwfl->lookup_tail_offset = end - bias - phdr->p_vaddr + phdr->p_offset; dwfl->lookup_tail_ndx = ndx + 1; - if (unlikely (dwfl->lookup_module != NULL)) - { - free (dwfl->lookup_module); - dwfl->lookup_module = NULL; - } - return ndx; } INTDEF (dwfl_report_segment) |