summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2020-12-07 12:11:05 +0100
committerMark Wielaard <mark@klomp.org>2020-12-10 13:55:16 +0100
commitbe70c464abc3b745223b80d48a2b3042966a2ad6 (patch)
tree3b7d849b5b4cd446e3c10a2919418d50eeed8b8d /libdwfl
parentFix automake warnings (diff)
downloadelfutils-be70c464abc3b745223b80d48a2b3042966a2ad6.tar.gz
elfutils-be70c464abc3b745223b80d48a2b3042966a2ad6.tar.bz2
elfutils-be70c464abc3b745223b80d48a2b3042966a2ad6.tar.xz
link_map: Pull release_buffer() into file scope
Get rid of a nested function this way. Add a memory_closure struct to keep the functions clean. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog5
-rw-r--r--libdwfl/link_map.c48
2 files changed, 37 insertions, 16 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 444e093c..ffb7f959 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
12020-12-07 Timm Bäder <tbaeder@redhat.com>
2
3 * link_map.c (report_r_debug): Pull release_buffer() function into
4 file scope. Add memory_closure struct.
5
12020-12-08 Dmitry V. Levin <ldv@altlinux.org> 62020-12-08 Dmitry V. Levin <ldv@altlinux.org>
2 7
3 * debuginfod-client.c (__libdwfl_debuginfod_init): Replace 8 * debuginfod-client.c (__libdwfl_debuginfod_init): Replace
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index bcff8db5..0704dc31 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -225,6 +225,24 @@ addrsize (uint_fast8_t elfclass)
225 return elfclass * 4; 225 return elfclass * 4;
226} 226}
227 227
228struct memory_closure
229{
230 Dwfl *dwfl;
231 Dwfl_Memory_Callback *callback;
232 void *arg;
233};
234
235static inline int
236release_buffer (struct memory_closure *closure,
237 void **buffer, size_t *buffer_available, int result)
238{
239 if (*buffer != NULL)
240 (*closure->callback) (closure->dwfl, -1, buffer, buffer_available, 0, 0,
241 closure->arg);
242
243 return result;
244}
245
228/* Report a module for each struct link_map in the linked list at r_map 246/* Report a module for each struct link_map in the linked list at r_map
229 in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description 247 in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description
230 see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no 248 see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no
@@ -249,15 +267,9 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
249 267
250 void *buffer = NULL; 268 void *buffer = NULL;
251 size_t buffer_available = 0; 269 size_t buffer_available = 0;
252 inline int release_buffer (int result)
253 {
254 if (buffer != NULL)
255 (void) (*memory_callback) (dwfl, -1, &buffer, &buffer_available, 0, 0,
256 memory_callback_arg);
257 return result;
258 }
259
260 GElf_Addr addrs[4]; 270 GElf_Addr addrs[4];
271 struct memory_closure memory_closure = { dwfl, memory_callback,
272 memory_callback_arg };
261 inline bool read_addrs (GElf_Addr vaddr, size_t n) 273 inline bool read_addrs (GElf_Addr vaddr, size_t n)
262 { 274 {
263 size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */ 275 size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
@@ -267,7 +279,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
267 || vaddr < read_vaddr 279 || vaddr < read_vaddr
268 || vaddr - read_vaddr + nb > buffer_available) 280 || vaddr - read_vaddr + nb > buffer_available)
269 { 281 {
270 release_buffer (0); 282 release_buffer (&memory_closure, &buffer, &buffer_available, 0);
271 283
272 read_vaddr = vaddr; 284 read_vaddr = vaddr;
273 int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL); 285 int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
@@ -304,7 +316,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
304 } 316 }
305 317
306 if (unlikely (read_addrs (read_vaddr, 1))) 318 if (unlikely (read_addrs (read_vaddr, 1)))
307 return release_buffer (-1); 319 return release_buffer (&memory_closure, &buffer, &buffer_available, -1);
308 320
309 GElf_Addr next = addrs[0]; 321 GElf_Addr next = addrs[0];
310 322
@@ -319,7 +331,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
319 while (next != 0 && ++iterations < dwfl->lookup_elts) 331 while (next != 0 && ++iterations < dwfl->lookup_elts)
320 { 332 {
321 if (read_addrs (next, 4)) 333 if (read_addrs (next, 4))
322 return release_buffer (-1); 334 return release_buffer (&memory_closure, &buffer, &buffer_available, -1);
323 335
324 /* Unused: l_addr is the difference between the address in memory 336 /* Unused: l_addr is the difference between the address in memory
325 and the ELF file when the core was created. We need to 337 and the ELF file when the core was created. We need to
@@ -345,7 +357,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
345 name = l_name - read_vaddr + buffer; 357 name = l_name - read_vaddr + buffer;
346 else 358 else
347 { 359 {
348 release_buffer (0); 360 release_buffer (&memory_closure, &buffer, &buffer_available, 0);
349 read_vaddr = l_name; 361 read_vaddr = l_name;
350 int segndx = INTUSE(dwfl_addrsegment) (dwfl, l_name, NULL); 362 int segndx = INTUSE(dwfl_addrsegment) (dwfl, l_name, NULL);
351 if (likely (segndx >= 0) 363 if (likely (segndx >= 0)
@@ -372,7 +384,8 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
372 r_debug_info_module = malloc (sizeof (*r_debug_info_module) 384 r_debug_info_module = malloc (sizeof (*r_debug_info_module)
373 + strlen (name1) + 1); 385 + strlen (name1) + 1);
374 if (unlikely (r_debug_info_module == NULL)) 386 if (unlikely (r_debug_info_module == NULL))
375 return release_buffer (result); 387 release_buffer (&memory_closure, &buffer,
388 &buffer_available, result);
376 r_debug_info_module->fd = -1; 389 r_debug_info_module->fd = -1;
377 r_debug_info_module->elf = NULL; 390 r_debug_info_module->elf = NULL;
378 r_debug_info_module->l_ld = l_ld; 391 r_debug_info_module->l_ld = l_ld;
@@ -413,7 +426,8 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
413 GElf_Addr build_id_vaddr = (build_id_elfaddr 426 GElf_Addr build_id_vaddr = (build_id_elfaddr
414 - elf_dynamic_vaddr + l_ld); 427 - elf_dynamic_vaddr + l_ld);
415 428
416 release_buffer (0); 429 release_buffer (&memory_closure, &buffer,
430 &buffer_available, 0);
417 int segndx = INTUSE(dwfl_addrsegment) (dwfl, 431 int segndx = INTUSE(dwfl_addrsegment) (dwfl,
418 build_id_vaddr, 432 build_id_vaddr,
419 NULL); 433 NULL);
@@ -432,7 +446,9 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
432 /* File has valid build-id which does not match 446 /* File has valid build-id which does not match
433 the one in memory. */ 447 the one in memory. */
434 valid = false; 448 valid = false;
435 release_buffer (0); 449 release_buffer (&memory_closure, &buffer,
450 &buffer_available, 0);
451
436 } 452 }
437 } 453 }
438 454
@@ -498,7 +514,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
498 } 514 }
499 } 515 }
500 516
501 return release_buffer (result); 517 return release_buffer (&memory_closure, &buffer, &buffer_available, result);
502} 518}
503 519
504static GElf_Addr 520static GElf_Addr