diff options
Diffstat (limited to 'libdwfl')
| -rw-r--r-- | libdwfl/ChangeLog | 8 | ||||
| -rw-r--r-- | libdwfl/libdwflP.h | 4 | ||||
| -rw-r--r-- | libdwfl/open.c | 30 |
3 files changed, 34 insertions, 8 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 9e7bb316..45cc1b4e 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,11 @@ +2018-10-20 Mark Wielaard <[email protected]> + + * libdwflP.h (__libdw_open_elf): New internal function declaration. + * open.c (what_kind): Rename close_fd to may_close_fd. + (__libdw_open_file): Replaced (and renamed) by a call to ... + (libdw_open_elf): this. And add never_close_fd argument. + (__libdw_open_elf): New function that calls libdw_open_elf. + 2018-10-18 Mark Wielaard <[email protected]> * dwfl_segment_report_module.c (consider_note): Take align as new diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h index 31e6e190..941a8b66 100644 --- a/libdwfl/libdwflP.h +++ b/libdwfl/libdwflP.h @@ -626,6 +626,10 @@ extern Dwfl_Error __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) internal_function; +/* Same as __libdw_open_file, but never closes the given file + descriptor and ELF_K_AR is always an acceptable type. */ +extern Dwfl_Error __libdw_open_elf (int fd, Elf **elfp) internal_function; + /* Fetch PT_DYNAMIC P_VADDR from ELF and store it to *VADDRP. Return success. *VADDRP is not modified if the function fails. */ extern bool __libdwfl_dynamic_vaddr_get (Elf *elf, GElf_Addr *vaddrp) diff --git a/libdwfl/open.c b/libdwfl/open.c index 4e0461bd..74367359 100644 --- a/libdwfl/open.c +++ b/libdwfl/open.c @@ -95,7 +95,7 @@ decompress (int fd __attribute__ ((unused)), Elf **elf) } static Dwfl_Error -what_kind (int fd, Elf **elfp, Elf_Kind *kind, bool *close_fd) +what_kind (int fd, Elf **elfp, Elf_Kind *kind, bool *may_close_fd) { Dwfl_Error error = DWFL_E_NOERROR; *kind = elf_kind (*elfp); @@ -108,7 +108,7 @@ what_kind (int fd, Elf **elfp, Elf_Kind *kind, bool *close_fd) error = decompress (fd, elfp); if (error == DWFL_E_NOERROR) { - *close_fd = true; + *may_close_fd = true; *kind = elf_kind (*elfp); } } @@ -116,15 +116,16 @@ what_kind (int fd, Elf **elfp, Elf_Kind *kind, bool *close_fd) return error; } -Dwfl_Error internal_function -__libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) +static Dwfl_Error +libdw_open_elf (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok, + bool never_close_fd) { - bool close_fd = false; + bool may_close_fd = false; Elf *elf = elf_begin (*fdp, ELF_C_READ_MMAP_PRIVATE, NULL); Elf_Kind kind; - Dwfl_Error error = what_kind (*fdp, &elf, &kind, &close_fd); + Dwfl_Error error = what_kind (*fdp, &elf, &kind, &may_close_fd); if (error == DWFL_E_BADELF) { /* It's not an ELF file or a compressed file. @@ -153,7 +154,7 @@ __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) elf->flags &= ~(ELF_F_MMAPPED | ELF_F_MALLOCED); elf_end (elf); elf = subelf; - error = what_kind (*fdp, &elf, &kind, &close_fd); + error = what_kind (*fdp, &elf, &kind, &may_close_fd); } } } @@ -169,7 +170,8 @@ __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) elf = NULL; } - if (error == DWFL_E_NOERROR ? close_fd : close_on_fail) + if (! never_close_fd + && error == DWFL_E_NOERROR ? may_close_fd : close_on_fail) { close (*fdp); *fdp = -1; @@ -178,3 +180,15 @@ __libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) *elfp = elf; return error; } + +Dwfl_Error internal_function +__libdw_open_file (int *fdp, Elf **elfp, bool close_on_fail, bool archive_ok) +{ + return libdw_open_elf (fdp, elfp, close_on_fail, archive_ok, false); +} + +Dwfl_Error internal_function +__libdw_open_elf (int fd, Elf **elfp) +{ + return libdw_open_elf (&fd, elfp, false, true, true); +} |
