1 .\" Copyright (c) 2006,2008,2018 Joseph Koshy. All rights reserved.
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
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.
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
24 .\" $Id: gelf_xlatetof.3 3639 2018-10-14 14:07:02Z jkoshy $
33 .Nd translate data between files and memory
39 .Fn elf32_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding"
41 .Fn elf32_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding"
43 .Fn elf64_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding"
45 .Fn elf64_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding"
52 .Fa "unsigned int file_encoding"
59 .Fa "unsigned int file_encoding"
62 These functions translate between the file and memory representations
63 of ELF data structures.
64 The in-memory representation of an ELF data structure would conform to
65 the byte ordering and data alignment restrictions dictated by the host
69 the file representation of this data structure could use a different byte
70 ordering from that of the host, or could use a different layout within
78 translate data from file representations to native, in-memory representations.
84 translate data from in-memory representations to file representations.
90 descriptor describing the source to be translated.
91 The following elements of the descriptor need to be set before
92 invoking these functions:
93 .Bl -hang -offset indent
95 Set to a valid pointer value denoting the beginning of the data area
98 Set to the total size in bytes of the source data area to be
101 Set to the type of the source data being translated.
102 This value is one of the values defined in the
107 enumeration is described in
110 Set to the version number of the ELF data structures being
112 Currently only version
119 describes the destination buffer.
120 The following elements of the
122 descriptor need to be set before invoking these functions:
123 .Bl -hang -offset indent
125 Set to a valid pointer value that denotes the start of the destination
126 buffer that will hold translated data.
127 This value may be the same as that of the source buffer, in which case
128 an in-place conversion will be attempted.
130 Set to the size of the destination buffer in bytes.
131 This value will be modified if the function call succeeds.
133 Set to the desired version number of the destination.
134 Currently only version
139 These translations routines allow the source and destination buffers
140 to coincide, in which case an in-place translation will be done
141 if the destination is large enough to hold the translated data.
142 Other kinds of overlap between the source and destination buffers
145 On successful completion of the translation request the following
148 descriptor would be modified:
149 .Bl -hang -offset indent
151 Set to the size in bytes of the translated data.
155 value of the source data descriptor.
160 specifies the encoding in which the file objects are represented.
162 .Bl -hang -offset indent
164 File objects use the library's native byte ordering.
166 File objects use a little-endian ordering.
168 File objects use a big-endian ordering.
175 select the appropriate translation scheme based on the properties of
179 These functions return argument
181 if successful, or NULL in case of an error.
185 structure to its LSB file representation use:
186 .Bd -literal -offset indent
191 e = ...; /* See elf_begin(3). */
193 /* Set up the 'src' descriptor. */
194 memset(&src, 0, sizeof src);
196 src.d_size = sizeof(rel);
197 src.d_type = ELF_T_REL;
198 src.d_version = EV_CURRENT;
200 /* Set up the 'dst' descriptor. */
201 memset(&dst, 0, sizeof dst);
203 dst.d_size = gelf_fsize(e, ELF_T_REL, 1, EV_CURRENT);
204 dst.d_version = EV_CURRENT;
206 if (gelf_xlatetof(e, &dst, &src, ELFDATA2LSB) == NULL) {
207 printf("error: %s", elf_errmsg(0));
211 These functions may fail with the following errors:
212 .Bl -tag -width "[ELF_E_RESOURCE]"
213 .It Bq Er ELF_E_ARGUMENT
220 .It Bq Er ELF_E_ARGUMENT
226 .It Bq Er ELF_E_ARGUMENT
227 The desired encoding parameter was not one of
232 .It Bq Er ELF_E_ARGUMENT
237 specified an unsupported type.
241 argument specified a buffer size that was not an integral multiple of
246 argument specified a buffer size that was too small.
250 specified a destination buffer that overlaps with the source
253 The destination buffer for a conversion to memory had an alignment
254 inappropriate for the underlying ELF type.
256 The source buffer for a conversion to file had an alignment
257 inappropriate for the underlying ELF type.
258 .It Bq Er ELF_E_UNIMPL
259 The version numbers for arguments
264 .It Bq Er ELF_E_UNIMPL
267 requested conversion for a type which is not currently
269 .It Bq Er ELF_E_VERSION
272 specified an unsupported version number.