Home | History | Annotate | Download | only in libdwfl

Lines Matching refs:dwfl

53 segment_start (Dwfl *dwfl, GElf_Addr start)
55 if (dwfl->segment_align > 1)
56 start &= -dwfl->segment_align;
61 segment_end (Dwfl *dwfl, GElf_Addr end)
63 if (dwfl->segment_align > 1)
64 end = (end + dwfl->segment_align - 1) & -dwfl->segment_align;
69 insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
71 bool need_start = (i == 0 || dwfl->lookup_addr[i - 1] != start);
72 bool need_end = (i >= dwfl->lookup_elts || dwfl->lookup_addr[i + 1] != end);
77 if (dwfl->lookup_alloc - dwfl->lookup_elts < need)
79 size_t n = dwfl->lookup_alloc == 0 ? 16 : dwfl->lookup_alloc * 2;
80 GElf_Addr *naddr = realloc (dwfl->lookup_addr, sizeof naddr[0] * n);
83 int *nsegndx = realloc (dwfl->lookup_segndx, sizeof nsegndx[0] * n);
86 if (naddr != dwfl->lookup_addr)
90 dwfl->lookup_alloc = n;
91 dwfl->lookup_addr = naddr;
92 dwfl->lookup_segndx = nsegndx;
94 if (dwfl->lookup_module != NULL)
97 Dwfl_Module **old = dwfl->lookup_module;
98 dwfl->lookup_module = realloc (dwfl->lookup_module,
99 sizeof dwfl->lookup_module[0] * n);
100 if (unlikely (dwfl->lookup_module == NULL))
108 if (unlikely (i < dwfl->lookup_elts))
110 const size_t move = dwfl->lookup_elts - i;
111 memmove (&dwfl->lookup_addr[i + need], &dwfl->lookup_addr[i],
112 move * sizeof dwfl->lookup_addr[0]);
113 memmove (&dwfl->lookup_segndx[i + need], &dwfl->lookup_segndx[i],
114 move * sizeof dwfl->lookup_segndx[0]);
115 if (dwfl->lookup_module != NULL)
116 memmove (&dwfl->lookup_module[i + need], &dwfl->lookup_module[i],
117 move * sizeof dwfl->lookup_module[0]);
122 dwfl->lookup_addr[i] = start;
123 dwfl->lookup_segndx[i] = segndx;
124 if (dwfl->lookup_module != NULL)
125 dwfl->lookup_module[i] = NULL;
129 dwfl->lookup_segndx[i - 1] = segndx;
133 dwfl->lookup_addr[i] = end;
134 dwfl->lookup_segndx[i] = -1;
135 if (dwfl->lookup_module != NULL)
136 dwfl->lookup_module[i] = NULL;
139 dwfl->lookup_elts += need;
145 lookup (Dwfl *dwfl, GElf_Addr address, int hint)
148 && address >= dwfl->lookup_addr[hint]
149 && ((size_t) hint + 1 == dwfl->lookup_elts
150 || address < dwfl->lookup_addr[hint + 1]))
154 size_t l = 0, u = dwfl->lookup_elts;
158 if (address < dwfl->lookup_addr[idx])
163 if (l == dwfl->lookup_elts || address < dwfl->lookup_addr[l])
172 reify_segments (Dwfl *dwfl)
177 for (Dwfl_Module *mod = dwfl->modulelist; mod != NULL; mod = mod->next)
180 const GElf_Addr start = segment_start (dwfl, mod->low_addr);
181 const GElf_Addr end = segment_end (dwfl, mod->high_addr);
184 int idx = lookup (dwfl, start, hint);
188 if (unlikely (insert (dwfl, 0, start, end, -1)))
193 else if (dwfl->lookup_addr[idx] > start)
196 if (unlikely (insert (dwfl, idx + 1, start, end,
197 dwfl->lookup_segndx[idx])))
202 else if (dwfl->lookup_addr[idx] < start)
206 if (unlikely (insert (dwfl, idx + 1, start, end, -1)))
212 if ((size_t) idx + 1 < dwfl->lookup_elts
213 && end < dwfl->lookup_addr[idx + 1])
216 if (unlikely (insert (dwfl, idx + 1,
217 end, dwfl->lookup_addr[idx + 1], -1)))
222 if (dwfl->lookup_module == NULL)
224 dwfl->lookup_module = calloc (dwfl->lookup_alloc,
225 sizeof dwfl->lookup_module[0]);
226 if (unlikely (dwfl->lookup_module == NULL))
235 dwfl->lookup_module[idx++] = mod;
236 while ((size_t) idx < dwfl->lookup_elts
237 && dwfl->lookup_addr[idx] < end);
238 assert (dwfl->lookup_module[mod->segment] == mod);
246 hint = (size_t) idx < dwfl->lookup_elts ? idx : -1;
251 for (size_t idx = 0; idx < dwfl->lookup_elts; ++idx)
252 if (dwfl->lookup_module[idx] != NULL)
253 dwfl->lookup_module[idx]->segment = idx;
259 dwfl_addrsegment (Dwfl *dwfl, Dwarf_Addr address, Dwfl_Module **mod)
261 if (unlikely (dwfl == NULL))
264 if (unlikely (dwfl->lookup_module == NULL)
266 && unlikely (reify_segments (dwfl)))
272 int idx = lookup (dwfl, address, -1);
275 if (unlikely (idx < 0) || unlikely (dwfl->lookup_module == NULL))
279 *mod = dwfl->lookup_module[idx];
283 if (*mod == NULL && idx > 0 && dwfl->lookup_addr[idx] == address)
285 *mod = dwfl->lookup_module[idx - 1];
294 idx = dwfl->lookup_segndx[idx];
301 dwfl_report_segment (Dwfl *dwfl, int ndx, const GElf_Phdr *phdr, GElf_Addr bias,
304 if (dwfl == NULL)
308 ndx = dwfl->lookup_tail_ndx;
310 if (phdr->p_align > 1 && (dwfl->segment_align <= 1 ||
311 phdr->p_align < dwfl->segment_align))
312 dwfl->segment_align = phdr->p_align;
314 if (unlikely (dwfl->lookup_module != NULL))
316 free (dwfl->lookup_module);
317 dwfl->lookup_module = NULL;
320 GElf_Addr start = segment_start (dwfl, bias + phdr->p_vaddr);
321 GElf_Addr end = segment_end (dwfl, bias + phdr->p_vaddr + phdr->p_memsz);
324 if (ndx != dwfl->lookup_tail_ndx
326 || ident != dwfl->lookup_tail_ident
327 || start != dwfl->lookup_tail_vaddr
328 || phdr->p_offset != dwfl->lookup_tail_offset)
332 size_t i = dwfl->lookup_elts;
333 while (i > 0 && unlikely (start < dwfl->lookup_addr[i - 1]))
336 if (unlikely (insert (dwfl, i, start, end, ndx)))
343 dwfl->lookup_tail_ident = ident;
344 dwfl->lookup_tail_vaddr = end;
345 dwfl->lookup_tail_offset = end - bias - phdr->p_vaddr + phdr->p_offset;
346 dwfl->lookup_tail_ndx = ndx + 1;