]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libelf/gelf_newehdr.3
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libelf / gelf_newehdr.3
1 .\" Copyright (c) 2006,2007 Joseph Koshy.  All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" This software is provided by Joseph Koshy ``as is'' and
13 .\" any express or implied warranties, including, but not limited to, the
14 .\" implied warranties of merchantability and fitness for a particular purpose
15 .\" are disclaimed.  in no event shall Joseph Koshy be liable
16 .\" for any direct, indirect, incidental, special, exemplary, or consequential
17 .\" damages (including, but not limited to, procurement of substitute goods
18 .\" or services; loss of use, data, or profits; or business interruption)
19 .\" however caused and on any theory of liability, whether in contract, strict
20 .\" liability, or tort (including negligence or otherwise) arising in any way
21 .\" out of the use of this software, even if advised of the possibility of
22 .\" such damage.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd October 22, 2007
27 .Dt GELF_NEWEHDR 3
28 .Os
29 .Sh NAME
30 .Nm elf32_newehdr ,
31 .Nm elf64_newehdr ,
32 .Nm gelf_newehdr
33 .Nd retrieve or allocate the object file header
34 .Sh LIBRARY
35 .Lb libelf
36 .Sh SYNOPSIS
37 .In libelf.h
38 .Ft "Elf32_Ehdr *"
39 .Fn elf32_newehdr "Elf *elf"
40 .Ft "Elf64_Ehdr *"
41 .Fn elf64_newehdr "Elf *elf"
42 .In gelf.h
43 .Ft "void *"
44 .Fn gelf_newehdr "Elf *elf" "int elfclass"
45 .Sh DESCRIPTION
46 These functions retrieve the ELF header from the ELF descriptor
47 .Ar elf ,
48 allocating a new header if needed.
49 File data structures are translated to their in-memory representations
50 as described in
51 .Xr elf 3 .
52 .Pp
53 Function
54 .Fn elf32_newehdr
55 returns a pointer to a 32 bit
56 .Vt Elf32_Ehdr
57 structure.
58 Function
59 .Fn elf64_newehdr
60 returns a pointer to a 64 bit
61 .Vt Elf64_Ehdr
62 structure.
63 .Pp
64 When argument
65 .Ar elfclass
66 has value
67 .Dv ELFCLASS32 ,
68 function
69 .Fn gelf_newehdr
70 returns the value returned by
71 .Fn elf32_newehdr "elf" .
72 When argument
73 .Ar elfclass
74 has value
75 .Dv ELFCLASS64
76 it returns the value returned by
77 .Fn elf64_newehdr "elf" .
78 .Pp
79 If a fresh header structure is allocated, the members of the
80 structure are initialized as follows:
81 .Bl -tag -width indent
82 .It Va "e_ident[EI_MAG0..EI_MAG3]"
83 Identification bytes at offsets
84 .Dv EI_MAG0 ,
85 .Dv EI_MAG1 ,
86 .Dv EI_MAG2
87 and
88 .Dv EI_MAG3
89 are set to the ELF signature.
90 .It Va "e_ident[EI_CLASS]"
91 The identification byte at offset
92 .Dv EI_CLASS
93 is set to the ELF class associated with the function being called
94 or to argument
95 .Ar elfclass
96 for function
97 .Fn gelf_newehdr .
98 .It Va "e_ident[EI_DATA]"
99 The identification byte at offset
100 .Dv EI_DATA
101 is set to
102 .Dv ELFDATANONE .
103 .It Va "e_ident[EI_VERSION]"
104 The identification byte at offset
105 .Dv EI_VERSION
106 is set to the ELF library's operating version set by a prior call to
107 .Xr elf_version 3 .
108 .It Va e_machine
109 is set to
110 .Dv EM_NONE .
111 .It Va e_type
112 is set to
113 .Dv ELF_K_NONE .
114 .It Va e_version
115 is set to the ELF library's operating version set by a prior call to
116 .Xr elf_version 3 .
117 .El
118 .Pp
119 Other members of the header are set to zero.
120 The application is responsible for changing these values
121 as needed before calling
122 .Fn elf_update .
123 .Pp
124 If successful, these three functions set the
125 .Dv ELF_F_DIRTY
126 flag on ELF descriptor
127 .Ar elf .
128 .Sh RETURN VALUES
129 These functions return a pointer to a translated header descriptor
130 if successful, or NULL on failure.
131 .Sh ERRORS
132 These functions can fail with the following errors:
133 .Bl -tag -width "[ELF_E_RESOURCE]"
134 .It Bq Er ELF_E_ARGUMENT
135 The argument
136 .Ar elf
137 was null.
138 .It Bq Er ELF_E_ARGUMENT
139 Argument
140 .Ar elf
141 was not a descriptor for an ELF object.
142 .It Bq Er ELF_E_ARGUMENT
143 Argument
144 .Ar elfclass
145 had an unsupported value.
146 .It Bq Er ELF_E_ARGUMENT
147 The class of the ELF descriptor
148 .Ar elf
149 did not match that of the requested operation.
150 .It Bq Er ELF_E_ARGUMENT
151 For function
152 .Fn gelf_newehdr ,
153 the class of argument
154 .Ar elf
155 was not
156 .Dv ELFCLASSNONE
157 and did not match the argument
158 .Ar elfclass .
159 .It Bq Er ELF_E_CLASS
160 The ELF class of descriptor
161 .Ar elf
162 did not match that of the API function being called.
163 .It Bq Er ELF_E_HEADER
164 A malformed ELF header was detected.
165 .It Bq Er ELF_E_RESOURCE
166 An out of memory condition was detected during execution.
167 .It Bq Er ELF_E_SECTION
168 The ELF descriptor in argument
169 .Ar elf
170 did not adhere to the conventions used for extended numbering.
171 .It Bq Er ELF_E_VERSION
172 The ELF descriptor
173 .Ar elf
174 had an unsupported ELF version number.
175 .El
176 .Sh SEE ALSO
177 .Xr elf 3 ,
178 .Xr elf32_getehdr 3 ,
179 .Xr elf64_getehdr 3 ,
180 .Xr elf_flagdata 3 ,
181 .Xr elf_getident 3 ,
182 .Xr elf_update 3 ,
183 .Xr elf_version 3 ,
184 .Xr gelf 3 ,
185 .Xr gelf_getehdr 3 ,
186 .Xr elf 5