summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2020-12-07 12:11:06 +0100
committerMark Wielaard <mark@klomp.org>2020-12-10 13:56:58 +0100
commit3bf41d458fb6f78260e71ff318adf50e1afe4bb3 (patch)
tree2dbbfb89376cd9a01c00d1941128595dfa738537 /libdwfl
parentlink_map: Pull release_buffer() into file scope (diff)
downloadelfutils-3bf41d458fb6f78260e71ff318adf50e1afe4bb3.tar.gz
elfutils-3bf41d458fb6f78260e71ff318adf50e1afe4bb3.tar.bz2
elfutils-3bf41d458fb6f78260e71ff318adf50e1afe4bb3.tar.xz
link_map: Pull read_addrs() into file scope
Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/link_map.c104
2 files changed, 62 insertions, 47 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index ffb7f959..c7f81acd 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,10 @@
12020-12-07 Timm Bäder <tbaeder@redhat.com> 12020-12-07 Timm Bäder <tbaeder@redhat.com>
2 2
3 * link_map.c (report_r_debug): Pull read_addrs() function into
4 file scope.
5
62020-12-07 Timm Bäder <tbaeder@redhat.com>
7
3 * link_map.c (report_r_debug): Pull release_buffer() function into 8 * link_map.c (report_r_debug): Pull release_buffer() function into
4 file scope. Add memory_closure struct. 9 file scope. Add memory_closure struct.
5 10
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 0704dc31..0d8d1c17 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -243,6 +243,57 @@ release_buffer (struct memory_closure *closure,
243 return result; 243 return result;
244} 244}
245 245
246static inline bool
247read_addrs (struct memory_closure *closure,
248 uint_fast8_t elfclass, uint_fast8_t elfdata,
249 void **buffer, size_t *buffer_available,
250 GElf_Addr vaddr, GElf_Addr *read_vaddr,
251 size_t n, GElf_Addr *addrs /* [4] */)
252{
253 size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
254 Dwfl *dwfl = closure->dwfl;
255
256 /* Read a new buffer if the old one doesn't cover these words. */
257 if (buffer == NULL
258 || vaddr < *read_vaddr
259 || vaddr - (*read_vaddr) + nb > *buffer_available)
260 {
261 release_buffer (closure, buffer, buffer_available, 0);
262
263 *read_vaddr = vaddr;
264 int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
265 if (unlikely (segndx < 0)
266 || unlikely (! (*closure->callback) (dwfl, segndx,
267 buffer, buffer_available,
268 vaddr, nb, closure->arg)))
269 return true;
270 }
271
272 Elf32_Addr (*a32)[n] = vaddr - (*read_vaddr) + (*buffer);
273 Elf64_Addr (*a64)[n] = (void *) a32;
274
275 if (elfclass == ELFCLASS32)
276 {
277 if (elfdata == ELFDATA2MSB)
278 for (size_t i = 0; i < n; ++i)
279 addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
280 else
281 for (size_t i = 0; i < n; ++i)
282 addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
283 }
284 else
285 {
286 if (elfdata == ELFDATA2MSB)
287 for (size_t i = 0; i < n; ++i)
288 addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
289 else
290 for (size_t i = 0; i < n; ++i)
291 addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
292 }
293
294 return false;
295}
296
246/* Report a module for each struct link_map in the linked list at r_map 297/* Report a module for each struct link_map in the linked list at r_map
247 in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description 298 in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description
248 see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no 299 see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no
@@ -270,52 +321,9 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
270 GElf_Addr addrs[4]; 321 GElf_Addr addrs[4];
271 struct memory_closure memory_closure = { dwfl, memory_callback, 322 struct memory_closure memory_closure = { dwfl, memory_callback,
272 memory_callback_arg }; 323 memory_callback_arg };
273 inline bool read_addrs (GElf_Addr vaddr, size_t n) 324 if (unlikely (read_addrs (&memory_closure, elfclass, elfdata,
274 { 325 &buffer, &buffer_available, read_vaddr, &read_vaddr,
275 size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */ 326 1, addrs)))
276
277 /* Read a new buffer if the old one doesn't cover these words. */
278 if (buffer == NULL
279 || vaddr < read_vaddr
280 || vaddr - read_vaddr + nb > buffer_available)
281 {
282 release_buffer (&memory_closure, &buffer, &buffer_available, 0);
283
284 read_vaddr = vaddr;
285 int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
286 if (unlikely (segndx < 0)
287 || unlikely (! (*memory_callback) (dwfl, segndx,
288 &buffer, &buffer_available,
289 vaddr, nb, memory_callback_arg)))
290 return true;
291 }
292
293 Elf32_Addr (*a32)[n] = vaddr - read_vaddr + buffer;
294 Elf64_Addr (*a64)[n] = (void *) a32;
295
296 if (elfclass == ELFCLASS32)
297 {
298 if (elfdata == ELFDATA2MSB)
299 for (size_t i = 0; i < n; ++i)
300 addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
301 else
302 for (size_t i = 0; i < n; ++i)
303 addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
304 }
305 else
306 {
307 if (elfdata == ELFDATA2MSB)
308 for (size_t i = 0; i < n; ++i)
309 addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
310 else
311 for (size_t i = 0; i < n; ++i)
312 addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
313 }
314
315 return false;
316 }
317
318 if (unlikely (read_addrs (read_vaddr, 1)))
319 return release_buffer (&memory_closure, &buffer, &buffer_available, -1); 327 return release_buffer (&memory_closure, &buffer, &buffer_available, -1);
320 328
321 GElf_Addr next = addrs[0]; 329 GElf_Addr next = addrs[0];
@@ -330,7 +338,9 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
330 size_t iterations = 0; 338 size_t iterations = 0;
331 while (next != 0 && ++iterations < dwfl->lookup_elts) 339 while (next != 0 && ++iterations < dwfl->lookup_elts)
332 { 340 {
333 if (read_addrs (next, 4)) 341 if (read_addrs (&memory_closure, elfclass, elfdata,
342 &buffer, &buffer_available, next, &read_vaddr,
343 4, addrs))
334 return release_buffer (&memory_closure, &buffer, &buffer_available, -1); 344 return release_buffer (&memory_closure, &buffer, &buffer_available, -1);
335 345
336 /* Unused: l_addr is the difference between the address in memory 346 /* Unused: l_addr is the difference between the address in memory