1*0a6a1f1dSLionel Sambuc.\" $NetBSD: gelf_xlatetof.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2006,2008 Joseph Koshy. All rights reserved. 4*0a6a1f1dSLionel Sambuc.\" 5*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 6*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 7*0a6a1f1dSLionel Sambuc.\" are met: 8*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 9*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 10*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 11*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 12*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 13*0a6a1f1dSLionel Sambuc.\" 14*0a6a1f1dSLionel Sambuc.\" This software is provided by Joseph Koshy ``as is'' and 15*0a6a1f1dSLionel Sambuc.\" any express or implied warranties, including, but not limited to, the 16*0a6a1f1dSLionel Sambuc.\" implied warranties of merchantability and fitness for a particular purpose 17*0a6a1f1dSLionel Sambuc.\" are disclaimed. in no event shall Joseph Koshy be liable 18*0a6a1f1dSLionel Sambuc.\" for any direct, indirect, incidental, special, exemplary, or consequential 19*0a6a1f1dSLionel Sambuc.\" damages (including, but not limited to, procurement of substitute goods 20*0a6a1f1dSLionel Sambuc.\" or services; loss of use, data, or profits; or business interruption) 21*0a6a1f1dSLionel Sambuc.\" however caused and on any theory of liability, whether in contract, strict 22*0a6a1f1dSLionel Sambuc.\" liability, or tort (including negligence or otherwise) arising in any way 23*0a6a1f1dSLionel Sambuc.\" out of the use of this software, even if advised of the possibility of 24*0a6a1f1dSLionel Sambuc.\" such damage. 25*0a6a1f1dSLionel Sambuc.\" 26*0a6a1f1dSLionel Sambuc.\" Id: gelf_xlatetof.3 189 2008-07-20 10:38:08Z jkoshy 27*0a6a1f1dSLionel Sambuc.\" 28*0a6a1f1dSLionel Sambuc.Dd July 24, 2006 29*0a6a1f1dSLionel Sambuc.Os 30*0a6a1f1dSLionel Sambuc.Dt GELF_XLATETOF 3 31*0a6a1f1dSLionel Sambuc.Sh NAME 32*0a6a1f1dSLionel Sambuc.Nm elf32_xlate , 33*0a6a1f1dSLionel Sambuc.Nm elf64_xlate , 34*0a6a1f1dSLionel Sambuc.Nm gelf_xlate 35*0a6a1f1dSLionel Sambuc.Nd translate data between files and memory 36*0a6a1f1dSLionel Sambuc.Sh LIBRARY 37*0a6a1f1dSLionel Sambuc.Lb libelf 38*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 39*0a6a1f1dSLionel Sambuc.In libelf.h 40*0a6a1f1dSLionel Sambuc.Ft "Elf_Data *" 41*0a6a1f1dSLionel Sambuc.Fn elf32_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int encode" 42*0a6a1f1dSLionel Sambuc.Ft "Elf_Data *" 43*0a6a1f1dSLionel Sambuc.Fn elf32_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int encode" 44*0a6a1f1dSLionel Sambuc.Ft "Elf_Data *" 45*0a6a1f1dSLionel Sambuc.Fn elf64_xlatetof "Elf_Data *dst" "Elf_Data *src" "unsigned int encode" 46*0a6a1f1dSLionel Sambuc.Ft "Elf_Data *" 47*0a6a1f1dSLionel Sambuc.Fn elf64_xlatetom "Elf_Data *dst" "Elf_Data *src" "unsigned int encode" 48*0a6a1f1dSLionel Sambuc.In gelf.h 49*0a6a1f1dSLionel Sambuc.Ft "Elf_Data *" 50*0a6a1f1dSLionel Sambuc.Fo gelf_xlatetof 51*0a6a1f1dSLionel Sambuc.Fa "Elf *elf" 52*0a6a1f1dSLionel Sambuc.Fa "Elf_Data *dst" 53*0a6a1f1dSLionel Sambuc.Fa "Elf_Data *src" 54*0a6a1f1dSLionel Sambuc.Fa "unsigned int encode" 55*0a6a1f1dSLionel Sambuc.Fc 56*0a6a1f1dSLionel Sambuc.Ft "Elf_Data *" 57*0a6a1f1dSLionel Sambuc.Fo gelf_xlatetom 58*0a6a1f1dSLionel Sambuc.Fa "Elf *elf" 59*0a6a1f1dSLionel Sambuc.Fa "Elf_Data *dst" 60*0a6a1f1dSLionel Sambuc.Fa "Elf_Data *src" 61*0a6a1f1dSLionel Sambuc.Fa "unsigned int encode" 62*0a6a1f1dSLionel Sambuc.Fc 63*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 64*0a6a1f1dSLionel SambucThese functions translate between the file and memory representations 65*0a6a1f1dSLionel Sambucof ELF data structures. 66*0a6a1f1dSLionel SambucThe in-memory representation of an ELF data structure would confirm to 67*0a6a1f1dSLionel Sambucthe byte ordering and data alignment restrictions dictated by the host 68*0a6a1f1dSLionel Sambucprocessor. 69*0a6a1f1dSLionel SambucA file representation of the same data structure could use a non-native byte 70*0a6a1f1dSLionel Sambucordering and in addition may be laid out differently with the file. 71*0a6a1f1dSLionel Sambuc.Pp 72*0a6a1f1dSLionel SambucFunctions 73*0a6a1f1dSLionel Sambuc.Fn elf32_xlatetom , 74*0a6a1f1dSLionel Sambuc.Fn elf64_xlatetom , 75*0a6a1f1dSLionel Sambucand 76*0a6a1f1dSLionel Sambuc.Fn gelf_xlatetom 77*0a6a1f1dSLionel Sambuctranslate data from file representations to native, in-memory representations. 78*0a6a1f1dSLionel SambucFunctions 79*0a6a1f1dSLionel Sambuc.Fn elf32_xlatetof , 80*0a6a1f1dSLionel Sambuc.Fn elf64_xlatetof , 81*0a6a1f1dSLionel Sambucand 82*0a6a1f1dSLionel Sambuc.Fn gelf_xlatetof 83*0a6a1f1dSLionel Sambuctranslate data from in-memory representations to file representations. 84*0a6a1f1dSLionel Sambuc.Pp 85*0a6a1f1dSLionel SambucArgument 86*0a6a1f1dSLionel Sambuc.Ar src 87*0a6a1f1dSLionel Sambucdenotes an 88*0a6a1f1dSLionel Sambuc.Vt Elf_Data 89*0a6a1f1dSLionel Sambucdescriptor describing the source to be translated. 90*0a6a1f1dSLionel SambucThe following elements of the descriptor need to be set before 91*0a6a1f1dSLionel Sambucinvoking these functions: 92*0a6a1f1dSLionel Sambuc.Bl -hang -offset indent 93*0a6a1f1dSLionel Sambuc.It Va d_buf 94*0a6a1f1dSLionel SambucSet to a valid pointer value denoting the beginning of the data area 95*0a6a1f1dSLionel Sambucto be translated. 96*0a6a1f1dSLionel Sambuc.It Va d_size 97*0a6a1f1dSLionel SambucSet to the total size in bytes of the source data area to be 98*0a6a1f1dSLionel Sambuctranslated. 99*0a6a1f1dSLionel Sambuc.It Va d_type 100*0a6a1f1dSLionel SambucSet to the type of the source data being translated. 101*0a6a1f1dSLionel SambucThis value is one of the values defined in the 102*0a6a1f1dSLionel Sambuc.Vt Elf_Type 103*0a6a1f1dSLionel Sambucenumeration. 104*0a6a1f1dSLionel SambucThe 105*0a6a1f1dSLionel Sambuc.Vt Elf_Type 106*0a6a1f1dSLionel Sambucenumeration is described in 107*0a6a1f1dSLionel Sambuc.Xr elf 3 . 108*0a6a1f1dSLionel Sambuc.It Va d_version 109*0a6a1f1dSLionel SambucSet to the version number of the ELF data structures being 110*0a6a1f1dSLionel Sambuctranslated. 111*0a6a1f1dSLionel SambucCurrently only version 112*0a6a1f1dSLionel Sambuc.Dv EV_CURRENT 113*0a6a1f1dSLionel Sambucis supported. 114*0a6a1f1dSLionel Sambuc.El 115*0a6a1f1dSLionel Sambuc.Pp 116*0a6a1f1dSLionel SambucArgument 117*0a6a1f1dSLionel Sambuc.Ar dst 118*0a6a1f1dSLionel Sambucdescribes the destination buffer. 119*0a6a1f1dSLionel SambucThe following elements of the 120*0a6a1f1dSLionel Sambuc.Vt Elf_Data 121*0a6a1f1dSLionel Sambucdescriptor need to be set before invoking these functions: 122*0a6a1f1dSLionel Sambuc.Bl -hang -offset indent 123*0a6a1f1dSLionel Sambuc.It Va d_buf 124*0a6a1f1dSLionel SambucSet to a valid pointer value that denotes the start of the destination 125*0a6a1f1dSLionel Sambucbuffer that will hold translated data. 126*0a6a1f1dSLionel SambucThis value may be the same as that of the source buffer, in which case 127*0a6a1f1dSLionel Sambucan in-place conversion will be attempted. 128*0a6a1f1dSLionel Sambuc.It Va d_size 129*0a6a1f1dSLionel SambucSet to the size of the destination buffer in bytes. 130*0a6a1f1dSLionel SambucThis value will be modified if the function call succeeds. 131*0a6a1f1dSLionel Sambuc.It Va d_version 132*0a6a1f1dSLionel SambucSet to the desired version number of the destination. 133*0a6a1f1dSLionel SambucCurrently only version 134*0a6a1f1dSLionel Sambuc.Dv EV_CURRENT 135*0a6a1f1dSLionel Sambucis supported. 136*0a6a1f1dSLionel Sambuc.El 137*0a6a1f1dSLionel Sambuc.Pp 138*0a6a1f1dSLionel SambucThese translations routines allow the source and destination buffers 139*0a6a1f1dSLionel Sambucto coincide, in which case an in-place translation will be done 140*0a6a1f1dSLionel Sambucif the destination is large enough to hold the translated data. 141*0a6a1f1dSLionel SambucOther kinds of overlap between the source and destination buffers 142*0a6a1f1dSLionel Sambucare not permitted. 143*0a6a1f1dSLionel Sambuc.Pp 144*0a6a1f1dSLionel SambucOn successful completion of the translation request the following 145*0a6a1f1dSLionel Sambucfields of the 146*0a6a1f1dSLionel Sambuc.Ar dst 147*0a6a1f1dSLionel Sambucdescriptor would be modified: 148*0a6a1f1dSLionel Sambuc.Bl -hang -offset indent 149*0a6a1f1dSLionel Sambuc.It Va d_size 150*0a6a1f1dSLionel SambucSet to the size in bytes of the translated data. 151*0a6a1f1dSLionel Sambuc.It Va d_type 152*0a6a1f1dSLionel SambucSet to the 153*0a6a1f1dSLionel Sambuc.Va d_type 154*0a6a1f1dSLionel Sambucvalue of the source data descriptor. 155*0a6a1f1dSLionel Sambuc.El 156*0a6a1f1dSLionel Sambuc.Pp 157*0a6a1f1dSLionel SambucArgument 158*0a6a1f1dSLionel Sambuc.Ar encode 159*0a6a1f1dSLionel Sambucspecifies the encoding in which the file objects are represented. 160*0a6a1f1dSLionel SambucIt must be one of: 161*0a6a1f1dSLionel Sambuc.Bl -hang -offset indent 162*0a6a1f1dSLionel Sambuc.It Dv ELFDATANONE 163*0a6a1f1dSLionel SambucFile objects use the library's native byte ordering. 164*0a6a1f1dSLionel Sambuc.It Dv ELFDATA2LSB 165*0a6a1f1dSLionel SambucFile objects use a little-endian ordering. 166*0a6a1f1dSLionel Sambuc.It Dv ELFDATA2MSB 167*0a6a1f1dSLionel SambucFile objects use a big-endian ordering. 168*0a6a1f1dSLionel Sambuc.El 169*0a6a1f1dSLionel Sambuc.Pp 170*0a6a1f1dSLionel SambucThe functions 171*0a6a1f1dSLionel Sambuc.Fn gelf_xlatetof 172*0a6a1f1dSLionel Sambucand 173*0a6a1f1dSLionel Sambuc.Fn gelf_xlatetom 174*0a6a1f1dSLionel Sambucselect the appropriate 32 or 64 bit translations based on the class of argument 175*0a6a1f1dSLionel Sambuc.Ar elf . 176*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES 177*0a6a1f1dSLionel SambucThese functions return argument 178*0a6a1f1dSLionel Sambuc.Ar dst 179*0a6a1f1dSLionel Sambucif successful, or NULL in case of an error. 180*0a6a1f1dSLionel Sambuc.Sh EXAMPLES 181*0a6a1f1dSLionel SambucTODO 182*0a6a1f1dSLionel Sambuc.Sh ERRORS 183*0a6a1f1dSLionel SambucThese functions may fail with the following errors: 184*0a6a1f1dSLionel Sambuc.Bl -tag -width "[ELF_E_RESOURCE]" 185*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT 186*0a6a1f1dSLionel SambucOne of arguments 187*0a6a1f1dSLionel Sambuc.Ar src , 188*0a6a1f1dSLionel Sambuc.Ar dst 189*0a6a1f1dSLionel Sambucor 190*0a6a1f1dSLionel Sambuc.Ar elf 191*0a6a1f1dSLionel Sambucwas NULL. 192*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT 193*0a6a1f1dSLionel SambucArguments 194*0a6a1f1dSLionel Sambuc.Ar src 195*0a6a1f1dSLionel Sambucand 196*0a6a1f1dSLionel Sambuc.Ar dst 197*0a6a1f1dSLionel Sambucwere equal. 198*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT 199*0a6a1f1dSLionel SambucThe desired encoding parameter was not one of 200*0a6a1f1dSLionel Sambuc.Dv ELFDATANONE , 201*0a6a1f1dSLionel Sambuc.Dv ELFDATA2LSB 202*0a6a1f1dSLionel Sambucor 203*0a6a1f1dSLionel Sambuc.Dv ELFDATA2MSB . 204*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_ARGUMENT 205*0a6a1f1dSLionel SambucThe 206*0a6a1f1dSLionel Sambuc.Ar d_type 207*0a6a1f1dSLionel Sambucfield of argument 208*0a6a1f1dSLionel Sambuc.Ar src 209*0a6a1f1dSLionel Sambucspecified an unsupported type. 210*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_DATA 211*0a6a1f1dSLionel SambucThe 212*0a6a1f1dSLionel Sambuc.Ar src 213*0a6a1f1dSLionel Sambucargument specified a buffer size that was not an integral multiple of 214*0a6a1f1dSLionel Sambucits underlying type. 215*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_DATA 216*0a6a1f1dSLionel SambucThe 217*0a6a1f1dSLionel Sambuc.Ar dst 218*0a6a1f1dSLionel Sambucargument specified a buffer size that was too small. 219*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_DATA 220*0a6a1f1dSLionel SambucArgument 221*0a6a1f1dSLionel Sambuc.Ar dst 222*0a6a1f1dSLionel Sambucspecified a destination buffer that overlaps with the source 223*0a6a1f1dSLionel Sambucbuffer. 224*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_DATA 225*0a6a1f1dSLionel SambucThe destination buffer for a conversion to memory had an alignment 226*0a6a1f1dSLionel Sambucinappropriate for the underlying ELF type. 227*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_DATA 228*0a6a1f1dSLionel SambucThe source buffer for a conversion to file had an alignment 229*0a6a1f1dSLionel Sambucinappropriate for the underlying ELF type. 230*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_UNIMPL 231*0a6a1f1dSLionel SambucThe version numbers for arguments 232*0a6a1f1dSLionel Sambuc.Ar dst 233*0a6a1f1dSLionel Sambucand 234*0a6a1f1dSLionel Sambuc.Ar src 235*0a6a1f1dSLionel Sambucwere not identical. 236*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_UNIMPL 237*0a6a1f1dSLionel SambucThe argument 238*0a6a1f1dSLionel Sambuc.Ar src 239*0a6a1f1dSLionel Sambucrequested conversion for a type which is not currently 240*0a6a1f1dSLionel Sambucsupported. 241*0a6a1f1dSLionel Sambuc.It Bq Er ELF_E_VERSION 242*0a6a1f1dSLionel SambucArgument 243*0a6a1f1dSLionel Sambuc.Ar src 244*0a6a1f1dSLionel Sambucspecified an unsupported version number. 245*0a6a1f1dSLionel Sambuc.El 246*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 247*0a6a1f1dSLionel Sambuc.Xr elf 3 , 248*0a6a1f1dSLionel Sambuc.Xr elf_getdata 3 , 249*0a6a1f1dSLionel Sambuc.Xr gelf 3 250