Hi Aaron,

On Mon, 2025-08-04 at 23:24 -0400, Aaron Merey wrote:
> Signed-off-by: Aaron Merey <ame...@redhat.com>
> ---
> v2: Clarify that return value will not exceed bounds of
> elf32_getphdr/elf64_getphdr array when used as an index.
> 
>  doc/Makefile.am      |  1 +
>  doc/elf_getphdrnum.3 | 81 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 82 insertions(+)
>  create mode 100644 doc/elf_getphdrnum.3
> 
> diff --git a/doc/Makefile.am b/doc/Makefile.am
> index e53c00ae..122a712f 100644
> --- a/doc/Makefile.am
> +++ b/doc/Makefile.am
> @@ -69,6 +69,7 @@ notrans_dist_man3_MANS= elf32_checksum.3 \
>                       elf_getdata.3 \
>                       elf_getdata_rawchunk.3 \
>                       elf_getident.3 \
> +                     elf_getphdrnum.3 \
>                       elf_getscn.3 \
>                       elf_hash.3 \
>                       elf_kind.3 \

OK.

> diff --git a/doc/elf_getphdrnum.3 b/doc/elf_getphdrnum.3
> new file mode 100644
> index 00000000..e543f0e7
> --- /dev/null
> +++ b/doc/elf_getphdrnum.3
> @@ -0,0 +1,81 @@
> +.TH ELF_GETPHDRNUM 3 2025-06-30 "Libelf" "Libelf Programmer's Manual"
> +
> +.SH NAME
> +elf_getphdrnum \- retrieve the number of program headers in an ELF file
> +.SH SYNOPSIS
> +.nf
> +#include <libelf.h>
> +
> +.B int elf_getphdrnum("Elf *elf", "size_t *dst");
> +.fi
> +.SH DESCRIPTION
> +The
> +.BR elf_getphdrnum ()
> +function stores the number of program headers associated with the ELF 
> descriptor
> +.I elf
> +into the variable pointed to by
> +.IR dst .
> +
> +If the number of program headers exceeds the representable range of the
> +.I e_phnum
> +field in the ELF header, the ELF specification allows encoding the true count
> +in section header 0’s
> +.I sh_info
> +field, and sets
> +.I e_phnum
> +to the reserved value
> +.B PN_XNUM
> +(always 0xFFFF). This function transparently handles that case.
> +
> +The function also ensures the returned count of program headers does not
> +exceed the number that can actually be addressed in the program header table.
> +This is important when indexing into the array returned by
> +.BR elf32_getphdr ()
> +or
> +.BR elf64_getphdr ().

OK.

> +.SH PARAMETERS
> +.TP
> +.I elf
> +A pointer to an
> +.B Elf
> +descriptor.
> +The descriptor must represent an ELF binary with
> +.I Elf_Kind
> +.B ELF_K_ELF .
> +
> +.TP
> +.I dst
> +On success, the number of program headers in
> +.I elf
> +is written here.  Must not be NULL.

OK.

> +.SH RETURN VALUE
> +Returns 0 on success and stores the result in
> +.IR dst .
> +Returns \-1 on failure and sets elf_errno.  Returns \-1 without setting
> +errno if
> +.B elf
> +is NULL .

OK.

> +.SH SEE ALSO
> +.BR elf32_getphdr (3),
> +.BR elf64_getphdr (3),
> +.BR libelf (3),
> +.BR elf (5)

OK.

> +.SH ATTRIBUTES
> +.TS
> +allbox;
> +lbx lb lb
> +l l l.
> +Interface    Attribute       Value
> +T{
> +.na
> +.nh
> +.BR elf_getphdrnum ()
> +T}   Thread safety   MT-Safe
> +.TE
> +
> +.SH REPORTING BUGS
> +Report bugs to <elfutils-devel@sourceware.org> or 
> https://sourceware.org/bugzilla/.

OK.

Thanks,

Mark

Reply via email to