File: elf_getphdrnum.3

package info (click to toggle)
elfutils 0.194-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,680 kB
  • sloc: ansic: 114,970; sh: 35,537; cpp: 4,998; makefile: 1,986; yacc: 1,388; lex: 130; asm: 77; sed: 39; awk: 35
file content (81 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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 ().

.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.

.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 .

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

.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/.