1*ae500c1fSEd Maste.\" Copyright (c) 2006,2008,2018 Joseph Koshy. All rights reserved. 22de3b87aSKai Wang.\" 32de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 42de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 52de3b87aSKai Wang.\" are met: 62de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 72de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 82de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 92de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 102de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 112de3b87aSKai Wang.\" 122de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and 132de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the 142de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose 152de3b87aSKai Wang.\" are disclaimed. in no event shall Joseph Koshy be liable 162de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential 172de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods 182de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption) 192de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict 202de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way 212de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of 222de3b87aSKai Wang.\" such damage. 232de3b87aSKai Wang.\" 24*ae500c1fSEd Maste.\" $Id: gelf_xlatetof.3 3639 2018-10-14 14:07:02Z jkoshy $ 252de3b87aSKai Wang.\" 26*ae500c1fSEd Maste.Dd October 11, 2018 272de3b87aSKai Wang.Dt GELF_XLATETOF 3 28*ae500c1fSEd Maste.Os 292de3b87aSKai Wang.Sh NAME 302de3b87aSKai Wang.Nm elf32_xlate , 312de3b87aSKai Wang.Nm elf64_xlate , 322de3b87aSKai Wang.Nm gelf_xlate 332de3b87aSKai Wang.Nd translate data between files and memory 342de3b87aSKai Wang.Sh LIBRARY 352de3b87aSKai Wang.Lb libelf 362de3b87aSKai Wang.Sh SYNOPSIS 372de3b87aSKai Wang.In libelf.h 382de3b87aSKai Wang.Ft "Elf_Data *" 39*ae500c1fSEd Maste.Fn elf32_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding" 402de3b87aSKai Wang.Ft "Elf_Data *" 41*ae500c1fSEd Maste.Fn elf32_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding" 422de3b87aSKai Wang.Ft "Elf_Data *" 43*ae500c1fSEd Maste.Fn elf64_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding" 442de3b87aSKai Wang.Ft "Elf_Data *" 45*ae500c1fSEd Maste.Fn elf64_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int file_encoding" 462de3b87aSKai Wang.In gelf.h 472de3b87aSKai Wang.Ft "Elf_Data *" 482de3b87aSKai Wang.Fo gelf_xlatetof 492de3b87aSKai Wang.Fa "Elf *elf" 502de3b87aSKai Wang.Fa "Elf_Data *dst" 512de3b87aSKai Wang.Fa "Elf_Data *src" 52*ae500c1fSEd Maste.Fa "unsigned int file_encoding" 532de3b87aSKai Wang.Fc 542de3b87aSKai Wang.Ft "Elf_Data *" 552de3b87aSKai Wang.Fo gelf_xlatetom 562de3b87aSKai Wang.Fa "Elf *elf" 572de3b87aSKai Wang.Fa "Elf_Data *dst" 582de3b87aSKai Wang.Fa "Elf_Data *src" 59*ae500c1fSEd Maste.Fa "unsigned int file_encoding" 602de3b87aSKai Wang.Fc 612de3b87aSKai Wang.Sh DESCRIPTION 622de3b87aSKai WangThese functions translate between the file and memory representations 632de3b87aSKai Wangof ELF data structures. 64*ae500c1fSEd MasteThe in-memory representation of an ELF data structure would conform to 652de3b87aSKai Wangthe byte ordering and data alignment restrictions dictated by the host 662de3b87aSKai Wangprocessor. 67*ae500c1fSEd MasteAs described in 68*ae500c1fSEd Maste.Xr elf 3 , 69*ae500c1fSEd Mastethe file representation of this data structure could use a different byte 70*ae500c1fSEd Masteordering from that of the host, or could use a different layout within 71*ae500c1fSEd Mastethe file. 722de3b87aSKai Wang.Pp 732de3b87aSKai WangFunctions 742de3b87aSKai Wang.Fn elf32_xlatetom , 752de3b87aSKai Wang.Fn elf64_xlatetom , 762de3b87aSKai Wangand 772de3b87aSKai Wang.Fn gelf_xlatetom 782de3b87aSKai Wangtranslate data from file representations to native, in-memory representations. 792de3b87aSKai WangFunctions 802de3b87aSKai Wang.Fn elf32_xlatetof , 812de3b87aSKai Wang.Fn elf64_xlatetof , 822de3b87aSKai Wangand 832de3b87aSKai Wang.Fn gelf_xlatetof 842de3b87aSKai Wangtranslate data from in-memory representations to file representations. 852de3b87aSKai Wang.Pp 862de3b87aSKai WangArgument 872de3b87aSKai Wang.Ar src 882de3b87aSKai Wangdenotes an 892de3b87aSKai Wang.Vt Elf_Data 902de3b87aSKai Wangdescriptor describing the source to be translated. 912de3b87aSKai WangThe following elements of the descriptor need to be set before 922de3b87aSKai Wanginvoking these functions: 932de3b87aSKai Wang.Bl -hang -offset indent 942de3b87aSKai Wang.It Va d_buf 952de3b87aSKai WangSet to a valid pointer value denoting the beginning of the data area 962de3b87aSKai Wangto be translated. 972de3b87aSKai Wang.It Va d_size 982de3b87aSKai WangSet to the total size in bytes of the source data area to be 992de3b87aSKai Wangtranslated. 1002de3b87aSKai Wang.It Va d_type 1012de3b87aSKai WangSet to the type of the source data being translated. 1022de3b87aSKai WangThis value is one of the values defined in the 1032de3b87aSKai Wang.Vt Elf_Type 1042de3b87aSKai Wangenumeration. 1052de3b87aSKai WangThe 1062de3b87aSKai Wang.Vt Elf_Type 1072de3b87aSKai Wangenumeration is described in 1082de3b87aSKai Wang.Xr elf 3 . 1092de3b87aSKai Wang.It Va d_version 1102de3b87aSKai WangSet to the version number of the ELF data structures being 1112de3b87aSKai Wangtranslated. 1122de3b87aSKai WangCurrently only version 1132de3b87aSKai Wang.Dv EV_CURRENT 1142de3b87aSKai Wangis supported. 1152de3b87aSKai Wang.El 1162de3b87aSKai Wang.Pp 1172de3b87aSKai WangArgument 1182de3b87aSKai Wang.Ar dst 1192de3b87aSKai Wangdescribes the destination buffer. 1202de3b87aSKai WangThe following elements of the 1212de3b87aSKai Wang.Vt Elf_Data 1222de3b87aSKai Wangdescriptor need to be set before invoking these functions: 1232de3b87aSKai Wang.Bl -hang -offset indent 1242de3b87aSKai Wang.It Va d_buf 1252de3b87aSKai WangSet to a valid pointer value that denotes the start of the destination 1262de3b87aSKai Wangbuffer that will hold translated data. 1272de3b87aSKai WangThis value may be the same as that of the source buffer, in which case 1282de3b87aSKai Wangan in-place conversion will be attempted. 1292de3b87aSKai Wang.It Va d_size 1302de3b87aSKai WangSet to the size of the destination buffer in bytes. 1312de3b87aSKai WangThis value will be modified if the function call succeeds. 1322de3b87aSKai Wang.It Va d_version 1332de3b87aSKai WangSet to the desired version number of the destination. 1342de3b87aSKai WangCurrently only version 1352de3b87aSKai Wang.Dv EV_CURRENT 1362de3b87aSKai Wangis supported. 1372de3b87aSKai Wang.El 1382de3b87aSKai Wang.Pp 1392de3b87aSKai WangThese translations routines allow the source and destination buffers 1402de3b87aSKai Wangto coincide, in which case an in-place translation will be done 1412de3b87aSKai Wangif the destination is large enough to hold the translated data. 1422de3b87aSKai WangOther kinds of overlap between the source and destination buffers 1432de3b87aSKai Wangare not permitted. 1442de3b87aSKai Wang.Pp 1452de3b87aSKai WangOn successful completion of the translation request the following 1462de3b87aSKai Wangfields of the 1472de3b87aSKai Wang.Ar dst 1482de3b87aSKai Wangdescriptor would be modified: 1492de3b87aSKai Wang.Bl -hang -offset indent 1502de3b87aSKai Wang.It Va d_size 1512de3b87aSKai WangSet to the size in bytes of the translated data. 1522de3b87aSKai Wang.It Va d_type 1532de3b87aSKai WangSet to the 1542de3b87aSKai Wang.Va d_type 1552de3b87aSKai Wangvalue of the source data descriptor. 1562de3b87aSKai Wang.El 1572de3b87aSKai Wang.Pp 1582de3b87aSKai WangArgument 159*ae500c1fSEd Maste.Ar file_encoding 1602de3b87aSKai Wangspecifies the encoding in which the file objects are represented. 1612de3b87aSKai WangIt must be one of: 1622de3b87aSKai Wang.Bl -hang -offset indent 1632de3b87aSKai Wang.It Dv ELFDATANONE 1642de3b87aSKai WangFile objects use the library's native byte ordering. 1652de3b87aSKai Wang.It Dv ELFDATA2LSB 1662de3b87aSKai WangFile objects use a little-endian ordering. 1672de3b87aSKai Wang.It Dv ELFDATA2MSB 1682de3b87aSKai WangFile objects use a big-endian ordering. 1692de3b87aSKai Wang.El 1702de3b87aSKai Wang.Pp 1712de3b87aSKai WangThe functions 1722de3b87aSKai Wang.Fn gelf_xlatetof 1732de3b87aSKai Wangand 1742de3b87aSKai Wang.Fn gelf_xlatetom 175*ae500c1fSEd Masteselect the appropriate translation scheme based on the properties of 176*ae500c1fSEd Masteargument 1772de3b87aSKai Wang.Ar elf . 1782de3b87aSKai Wang.Sh RETURN VALUES 1792de3b87aSKai WangThese functions return argument 1802de3b87aSKai Wang.Ar dst 1812de3b87aSKai Wangif successful, or NULL in case of an error. 1822de3b87aSKai Wang.Sh EXAMPLES 183*ae500c1fSEd MasteTo translate a 184*ae500c1fSEd Maste.Vt GElf_Rel 185*ae500c1fSEd Mastestructure to its LSB file representation use: 186*ae500c1fSEd Maste.Bd -literal -offset indent 187*ae500c1fSEd MasteElf_Data dst, src; 188*ae500c1fSEd MasteGElf_Rel rel; 189*ae500c1fSEd MasteElf *e; 190*ae500c1fSEd Maste 191*ae500c1fSEd Mastee = ...; /* See elf_begin(3). */ 192*ae500c1fSEd Maste 193*ae500c1fSEd Maste/* Set up the 'src' descriptor. */ 194*ae500c1fSEd Mastememset(&src, 0, sizeof src); 195*ae500c1fSEd Mastesrc.d_buf = &rel; 196*ae500c1fSEd Mastesrc.d_size = sizeof(rel); 197*ae500c1fSEd Mastesrc.d_type = ELF_T_REL; 198*ae500c1fSEd Mastesrc.d_version = EV_CURRENT; 199*ae500c1fSEd Maste 200*ae500c1fSEd Maste/* Set up the 'dst' descriptor. */ 201*ae500c1fSEd Mastememset(&dst, 0, sizeof dst); 202*ae500c1fSEd Mastedst.d_buf = filebuf; 203*ae500c1fSEd Mastedst.d_size = gelf_fsize(e, ELF_T_REL, 1, EV_CURRENT); 204*ae500c1fSEd Mastedst.d_version = EV_CURRENT; 205*ae500c1fSEd Maste 206*ae500c1fSEd Masteif (gelf_xlatetof(e, &dst, &src, ELFDATA2LSB) == NULL) { 207*ae500c1fSEd Maste printf("error: %s", elf_errmsg(0)); 208*ae500c1fSEd Maste} 209*ae500c1fSEd Maste.Ed 2102de3b87aSKai Wang.Sh ERRORS 2112de3b87aSKai WangThese functions may fail with the following errors: 2122de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]" 2132de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 2142de3b87aSKai WangOne of arguments 2152de3b87aSKai Wang.Ar src , 2162de3b87aSKai Wang.Ar dst 2172de3b87aSKai Wangor 2182de3b87aSKai Wang.Ar elf 2192de3b87aSKai Wangwas NULL. 2202de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 2212de3b87aSKai WangArguments 2222de3b87aSKai Wang.Ar src 2232de3b87aSKai Wangand 2242de3b87aSKai Wang.Ar dst 2252de3b87aSKai Wangwere equal. 2262de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 2272de3b87aSKai WangThe desired encoding parameter was not one of 2282de3b87aSKai Wang.Dv ELFDATANONE , 2292de3b87aSKai Wang.Dv ELFDATA2LSB 2302de3b87aSKai Wangor 2312de3b87aSKai Wang.Dv ELFDATA2MSB . 2322de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 2332de3b87aSKai WangThe 2342de3b87aSKai Wang.Ar d_type 2352de3b87aSKai Wangfield of argument 2362de3b87aSKai Wang.Ar src 2372de3b87aSKai Wangspecified an unsupported type. 2382de3b87aSKai Wang.It Bq Er ELF_E_DATA 2392de3b87aSKai WangThe 2402de3b87aSKai Wang.Ar src 2412de3b87aSKai Wangargument specified a buffer size that was not an integral multiple of 2422de3b87aSKai Wangits underlying type. 2432de3b87aSKai Wang.It Bq Er ELF_E_DATA 2442de3b87aSKai WangThe 2452de3b87aSKai Wang.Ar dst 2462de3b87aSKai Wangargument specified a buffer size that was too small. 2472de3b87aSKai Wang.It Bq Er ELF_E_DATA 2482de3b87aSKai WangArgument 2492de3b87aSKai Wang.Ar dst 2502de3b87aSKai Wangspecified a destination buffer that overlaps with the source 2512de3b87aSKai Wangbuffer. 2522de3b87aSKai Wang.It Bq Er ELF_E_DATA 2532de3b87aSKai WangThe destination buffer for a conversion to memory had an alignment 2542de3b87aSKai Wanginappropriate for the underlying ELF type. 2552de3b87aSKai Wang.It Bq Er ELF_E_DATA 2562de3b87aSKai WangThe source buffer for a conversion to file had an alignment 2572de3b87aSKai Wanginappropriate for the underlying ELF type. 2582de3b87aSKai Wang.It Bq Er ELF_E_UNIMPL 2592de3b87aSKai WangThe version numbers for arguments 2602de3b87aSKai Wang.Ar dst 2612de3b87aSKai Wangand 2622de3b87aSKai Wang.Ar src 2632de3b87aSKai Wangwere not identical. 2642de3b87aSKai Wang.It Bq Er ELF_E_UNIMPL 2652de3b87aSKai WangThe argument 2662de3b87aSKai Wang.Ar src 2672de3b87aSKai Wangrequested conversion for a type which is not currently 2682de3b87aSKai Wangsupported. 2692de3b87aSKai Wang.It Bq Er ELF_E_VERSION 2702de3b87aSKai WangArgument 2712de3b87aSKai Wang.Ar src 2722de3b87aSKai Wangspecified an unsupported version number. 2732de3b87aSKai Wang.El 2742de3b87aSKai Wang.Sh SEE ALSO 2752de3b87aSKai Wang.Xr elf 3 , 2762de3b87aSKai Wang.Xr elf_getdata 3 , 2772de3b87aSKai Wang.Xr gelf 3 278