summaryrefslogtreecommitdiffstats
path: root/libdwfl
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2020-11-26 15:10:47 +0100
committerMark Wielaard <mark@klomp.org>2020-11-28 02:00:33 +0100
commit0aa31e23be720bf573e44865eb82bc9216cdc065 (patch)
treed086aa8e275efb9417fca4faedb76b65943e5c51 /libdwfl
parentsegment_report_module: Pull finish_portion() into file scope (diff)
downloadelfutils-0aa31e23be720bf573e44865eb82bc9216cdc065.tar.gz
elfutils-0aa31e23be720bf573e44865eb82bc9216cdc065.tar.bz2
elfutils-0aa31e23be720bf573e44865eb82bc9216cdc065.tar.xz
segment_report_module: Pull read_portion() into file scope
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog6
-rw-r--r--libdwfl/dwfl_segment_report_module.c70
2 files changed, 46 insertions, 30 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index eb898ec8..f66ff3f0 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,5 +1,11 @@
12020-11-26 Timm Bäder <tbaeder@redhat.com> 12020-11-26 Timm Bäder <tbaeder@redhat.com>
2 2
3 * dwfl_segment_report_module.c (read_portion): New static function.
4 (dwfl_segment_report_module): Remove read_portion function.
5 Call static function with read_state, start and segment.
6
72020-11-26 Timm Bäder <tbaeder@redhat.com>
8
3 * dwfl_segment_report_module.c (struct read_state): New. 9 * dwfl_segment_report_module.c (struct read_state): New.
4 (finish_portion): New static function. 10 (finish_portion): New static function.
5 (dwfl_segment_report_module): Introduce read_state. Remove 11 (dwfl_segment_report_module): Introduce read_state. Remove
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 391fd761..aa4a47c1 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -256,6 +256,38 @@ finish_portion (struct read_state *read_state,
256 0, 0, read_state->memory_callback_arg); 256 0, 0, read_state->memory_callback_arg);
257} 257}
258 258
259static inline bool
260read_portion (struct read_state *read_state,
261 void **data, size_t *data_size,
262 GElf_Addr start, size_t segment,
263 GElf_Addr vaddr, size_t filesz)
264{
265 /* Check whether we will have to read the segment data, or if it
266 can be returned from the existing buffer. */
267 if (filesz > *read_state->buffer_available
268 || vaddr - start > *read_state->buffer_available - filesz
269 /* If we're in string mode, then don't consider the buffer we have
270 sufficient unless it contains the terminator of the string. */
271 || (filesz == 0 && memchr (vaddr - start + *read_state->buffer, '\0',
272 (*read_state->buffer_available
273 - (vaddr - start))) == NULL))
274 {
275 *data = NULL;
276 *data_size = filesz;
277 return !(*read_state->memory_callback) (read_state->dwfl,
278 addr_segndx (read_state->dwfl,
279 segment, vaddr,
280 false),
281 data, data_size, vaddr, filesz,
282 read_state->memory_callback_arg);
283 }
284
285 /* We already have this whole note segment from our initial read. */
286 *data = vaddr - start + (*read_state->buffer);
287 *data_size = 0;
288 return false;
289}
290
259int 291int
260dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, 292dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
261 Dwfl_Memory_Callback *memory_callback, 293 Dwfl_Memory_Callback *memory_callback,
@@ -304,32 +336,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
304 || memcmp (buffer, ELFMAG, SELFMAG) != 0) 336 || memcmp (buffer, ELFMAG, SELFMAG) != 0)
305 goto out; 337 goto out;
306 338
307 inline bool read_portion (void **data, size_t *data_size,
308 GElf_Addr vaddr, size_t filesz)
309 {
310 /* Check whether we will have to read the segment data, or if it
311 can be returned from the existing buffer. */
312 if (filesz > buffer_available
313 || vaddr - start > buffer_available - filesz
314 /* If we're in string mode, then don't consider the buffer we have
315 sufficient unless it contains the terminator of the string. */
316 || (filesz == 0 && memchr (vaddr - start + buffer, '\0',
317 buffer_available - (vaddr - start)) == NULL))
318 {
319 *data = NULL;
320 *data_size = filesz;
321 return ! (*memory_callback) (dwfl, addr_segndx (dwfl, segment,
322 vaddr, false),
323 data, data_size, vaddr, filesz,
324 memory_callback_arg);
325 }
326
327 /* We already have this whole note segment from our initial read. */
328 *data = vaddr - start + buffer;
329 *data_size = 0;
330 return false;
331 }
332
333 /* Extract the information we need from the file header. */ 339 /* Extract the information we need from the file header. */
334 const unsigned char *e_ident; 340 const unsigned char *e_ident;
335 unsigned char ei_class; 341 unsigned char ei_class;
@@ -410,7 +416,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
410 416
411 void *ph_buffer = NULL; 417 void *ph_buffer = NULL;
412 size_t ph_buffer_size = 0; 418 size_t ph_buffer_size = 0;
413 if (read_portion (&ph_buffer, &ph_buffer_size, 419 if (read_portion (&read_state, &ph_buffer, &ph_buffer_size,
420 start, segment,
414 start + phoff, xlatefrom.d_size)) 421 start + phoff, xlatefrom.d_size))
415 goto out; 422 goto out;
416 423
@@ -469,7 +476,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
469 476
470 void *data; 477 void *data;
471 size_t data_size; 478 size_t data_size;
472 if (read_portion (&data, &data_size, vaddr, filesz)) 479 if (read_portion (&read_state, &data, &data_size,
480 start, segment, vaddr, filesz))
473 return; 481 return;
474 482
475 /* data_size will be zero if we got everything from the initial 483 /* data_size will be zero if we got everything from the initial
@@ -756,7 +764,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
756 void *dyn_data = NULL; 764 void *dyn_data = NULL;
757 size_t dyn_data_size = 0; 765 size_t dyn_data_size = 0;
758 if (dyn_filesz != 0 && dyn_filesz % dyn_entsize == 0 766 if (dyn_filesz != 0 && dyn_filesz % dyn_entsize == 0
759 && ! read_portion (&dyn_data, &dyn_data_size, dyn_vaddr, dyn_filesz)) 767 && ! read_portion (&read_state, &dyn_data, &dyn_data_size,
768 start, segment, dyn_vaddr, dyn_filesz))
760 { 769 {
761 /* dyn_data_size will be zero if we got everything from the initial 770 /* dyn_data_size will be zero if we got everything from the initial
762 buffer, otherwise it will be the size of the new buffer that 771 buffer, otherwise it will be the size of the new buffer that
@@ -837,7 +846,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
837 846
838 /* Try to get the DT_SONAME string. */ 847 /* Try to get the DT_SONAME string. */
839 if (soname_stroff != 0 && soname_stroff + 1 < dynstrsz 848 if (soname_stroff != 0 && soname_stroff + 1 < dynstrsz
840 && ! read_portion (&soname, &soname_size, 849 && ! read_portion (&read_state, &soname, &soname_size,
850 start, segment,
841 dynstr_vaddr + soname_stroff, 0)) 851 dynstr_vaddr + soname_stroff, 0))
842 name = soname; 852 name = soname;
843 } 853 }