xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/gelf_getehdr.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1.\"	$NetBSD: gelf_getehdr.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_getehdr.3 3958 2022-03-12 14:31:32Z jkoshy
27.\"
28.Dd December 16, 2006
29.Dt GELF_GETEHDR 3
30.Os
31.Sh NAME
32.Nm elf32_getehdr ,
33.Nm elf64_getehdr ,
34.Nm gelf_getehdr
35.Nd retrieve the object file header
36.Sh LIBRARY
37.Lb libelf
38.Sh SYNOPSIS
39.In libelf.h
40.Ft "Elf32_Ehdr *"
41.Fn elf32_getehdr "Elf *elf"
42.Ft "Elf64_Ehdr *"
43.Fn elf64_getehdr "Elf *elf"
44.In gelf.h
45.Ft "GElf_Ehdr *"
46.Fn gelf_getehdr "Elf *elf" "GElf_Ehdr *dst"
47.Sh DESCRIPTION
48These functions retrieve the ELF object file
49header from the ELF descriptor
50.Fa elf
51and return a translated header descriptor to their callers.
52.Pp
53Functions
54.Fn elf32_getehdr
55and
56.Fn elf64_getehdr
57return a pointer to the appropriate class-specific header descriptor
58if it exists in the file referenced by descriptor
59.Fa elf .
60These functions return
61.Dv NULL
62if an ELF header was not found in file
63.Fa elf .
64.Pp
65Function
66.Fn gelf_getehdr
67stores a translated copy of the header for ELF file
68.Fa elf
69into the descriptor pointed to by argument
70.Fa dst .
71It returns argument
72.Fa dst
73if successful or
74.Dv NULL
75in case of failure.
76.Sh RETURN VALUES
77These functions return a pointer to a translated header descriptor
78if successful, or
79.Dv NULL
80on failure.
81.Sh ERRORS
82These functions can fail with the following errors:
83.Bl -tag -width "[ELF_E_RESOURCE]"
84.It Bq Er ELF_E_ARGUMENT
85The argument
86.Fa elf
87was null.
88.It Bq Er ELF_E_ARGUMENT
89Argument
90.Fa elf
91was not a descriptor for an ELF file.
92.It Bq Er ELF_E_ARGUMENT
93The elf class of descriptor
94.Fa elf
95was not recognized.
96.It Bq Er ELF_E_ARGUMENT
97Argument
98.Fa dst
99was null.
100.It Bq Er ELF_E_CLASS
101The ELF class of descriptor
102.Fa elf
103did not match that of the API function being called.
104.It Bq Er ELF_E_HEADER
105ELF descriptor
106.Fa elf
107does not have an associated header.
108.It Bq Er ELF_E_RESOURCE
109An out of memory condition was detected during execution.
110.It Bq Er ELF_E_SECTION
111The ELF descriptor in argument
112.Fa elf
113did not adhere to the conventions used for extended numbering.
114.It Bq Er ELF_E_VERSION
115The ELF descriptor
116.Fa elf
117had an unsupported ELF version number.
118.El
119.Sh SEE ALSO
120.Xr elf 3 ,
121.Xr elf32_newehdr 3 ,
122.Xr elf64_newehdr 3 ,
123.Xr elf_flagehdr 3 ,
124.Xr elf_getident 3 ,
125.Xr gelf 3 ,
126.Xr gelf_newehdr 3 ,
127.Xr elf 5
128