xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/gelf_getphdr.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1.\"	$NetBSD: gelf_getphdr.3,v 1.6 2024/03/03 17:37:34 christos Exp $
2.\"
3.\" Copyright (c) 2006-2008 Joseph Koshy.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" This software is provided by Joseph Koshy ``as is'' and
15.\" any express or implied warranties, including, but not limited to, the
16.\" implied warranties of merchantability and fitness for a particular purpose
17.\" are disclaimed.  in no event shall Joseph Koshy be liable
18.\" for any direct, indirect, incidental, special, exemplary, or consequential
19.\" damages (including, but not limited to, procurement of substitute goods
20.\" or services; loss of use, data, or profits; or business interruption)
21.\" however caused and on any theory of liability, whether in contract, strict
22.\" liability, or tort (including negligence or otherwise) arising in any way
23.\" out of the use of this software, even if advised of the possibility of
24.\" such damage.
25.\"
26.\" Id: gelf_getphdr.3 3958 2022-03-12 14:31:32Z jkoshy
27.\"
28.Dd October 21, 2007
29.Dt GELF_GETPHDR 3
30.Os
31.Sh NAME
32.Nm elf32_getphdr ,
33.Nm elf64_getphdr ,
34.Nm gelf_getphdr
35.Nd retrieve an ELF program header table
36.Sh LIBRARY
37.Lb libelf
38.Sh SYNOPSIS
39.In libelf.h
40.Ft "Elf32_Phdr *"
41.Fn elf32_getphdr "Elf *elf"
42.Ft "Elf64_Phdr *"
43.Fn elf64_getphdr "Elf *elf"
44.In gelf.h
45.Ft "GElf_Phdr *"
46.Fn gelf_getphdr "Elf *elf" "int index" "GElf_Phdr *dst"
47.Sh DESCRIPTION
48These functions retrieve and translate ELF program header information
49from an ELF descriptor, if this information exists.
50.Pp
51Functions
52.Fn elf32_getphdr
53and
54.Fn elf64_getphdr
55return a pointer to an array of translated
56.Vt Elf32_Phdr
57and
58.Vt Elf64_Phdr
59descriptors respectively.
60These descriptors are described in
61.Xr elf 5 .
62The number of entries in this array may be determined using the
63.Xr elf_getphnum 3
64function.
65.Pp
66Function
67.Fn gelf_getphdr
68will retrieve the program header table entry at index
69.Fa index
70from ELF descriptor
71.Fa elf .
72The translated program header table entry will be written to the
73address pointed to be argument
74.Fa dst .
75.Pp
76Applications may inform the library of modifications to a program header table entry
77by using the
78.Xr elf_flagphdr 3
79API.
80Applications using the
81.Xr gelf 3
82interface need to use the
83.Xr gelf_update_phdr 3
84API to copy modifications to a program header entry back to the underlying
85ELF descriptor.
86.Sh RETURN VALUES
87The functions a valid pointer if successful, or
88.Dv NULL
89in case an error was encountered.
90.Sh ERRORS
91These functions may fail with the following errors:
92.Bl -tag -width "[ELF_E_RESOURCE]"
93.It Bq Er ELF_E_ARGUMENT
94Argument
95.Fa elf
96was
97.Dv NULL .
98.It Bq Er ELF_E_ARGUMENT
99Argument
100.Fa elf
101was not a descriptor for an ELF object.
102.It Bq Er ELF_E_ARGUMENT
103Argument
104.Fa dst
105was
106.Dv NULL .
107.It Bq Er ELF_E_ARGUMENT
108Index
109.Fa index
110was out of range.
111.It Bq Er ELF_E_CLASS
112The class of ELF descriptor
113.Fa elf
114did not match the expected class of the function being called.
115.It Bq Er ELF_E_HEADER
116ELF descriptor
117.Fa elf
118did not possess an executable header.
119.It Bq Er ELF_E_HEADER
120ELF descriptor
121.Fa elf
122had a corrupt executable header.
123.It Bq Er ELF_E_RESOURCE
124An out of memory condition was detected.
125.It Bq Er ELF_E_SECTION
126The ELF descriptor in argument
127.Fa elf
128did not adhere to the conventions used for extended numbering.
129.It Bq Er ELF_VERSION
130ELF descriptor
131.Fa elf
132was of an unsupported version.
133.El
134.Sh SEE ALSO
135.Xr elf 3 ,
136.Xr elf32_getehdr 3 ,
137.Xr elf32_newphdr 3 ,
138.Xr elf64_getehdr 3 ,
139.Xr elf64_newphdr 3 ,
140.Xr elf_flagphdr 3 ,
141.Xr elf_getphnum 3 ,
142.Xr gelf 3 ,
143.Xr gelf_getehdr 3 ,
144.Xr gelf_newphdr 3 ,
145.Xr gelf_update_phdr 3 ,
146.Xr elf 5
147