1*2de3b87aSKai Wang.\" Copyright (c) 2006,2008,2010-2011 Joseph Koshy. All rights reserved. 2*2de3b87aSKai Wang.\" 3*2de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 4*2de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 5*2de3b87aSKai Wang.\" are met: 6*2de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 7*2de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 8*2de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 9*2de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 10*2de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 11*2de3b87aSKai Wang.\" 12*2de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and 13*2de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the 14*2de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose 15*2de3b87aSKai Wang.\" are disclaimed. in no event shall Joseph Koshy be liable 16*2de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential 17*2de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods 18*2de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption) 19*2de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict 20*2de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way 21*2de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of 22*2de3b87aSKai Wang.\" such damage. 23*2de3b87aSKai Wang.\" 24*2de3b87aSKai Wang.\" $Id: elf_getdata.3 1766 2011-08-22 06:01:03Z jkoshy $ 25*2de3b87aSKai Wang.\" 26*2de3b87aSKai Wang.Dd January 26, 2011 27*2de3b87aSKai Wang.Os 28*2de3b87aSKai Wang.Dt ELF_GETDATA 3 29*2de3b87aSKai Wang.Sh NAME 30*2de3b87aSKai Wang.Nm elf_getdata , 31*2de3b87aSKai Wang.Nm elf_newdata , 32*2de3b87aSKai Wang.Nm elf_rawdata 33*2de3b87aSKai Wang.Nd iterate through or allocate section data 34*2de3b87aSKai Wang.Sh LIBRARY 35*2de3b87aSKai Wang.Lb libelf 36*2de3b87aSKai Wang.Sh SYNOPSIS 37*2de3b87aSKai Wang.In libelf.h 38*2de3b87aSKai Wang.Ft "Elf_Data *" 39*2de3b87aSKai Wang.Fn elf_getdata "Elf_Scn *scn" "Elf_Data *data" 40*2de3b87aSKai Wang.Ft "Elf_Data *" 41*2de3b87aSKai Wang.Fn elf_newdata "Elf_Scn *scn" 42*2de3b87aSKai Wang.Ft "Elf_Data *" 43*2de3b87aSKai Wang.Fn elf_rawdata "Elf_Scn *scn" "Elf_Data *data" 44*2de3b87aSKai Wang.Sh DESCRIPTION 45*2de3b87aSKai WangThese functions are used to access and manipulate data descriptors 46*2de3b87aSKai Wangassociated with section descriptors. 47*2de3b87aSKai WangData descriptors used by the ELF library are described in 48*2de3b87aSKai Wang.Xr elf 3 . 49*2de3b87aSKai Wang.Pp 50*2de3b87aSKai WangFunction 51*2de3b87aSKai Wang.Fn elf_getdata 52*2de3b87aSKai Wangwill return the next data descriptor associated with section descriptor 53*2de3b87aSKai Wang.Ar scn . 54*2de3b87aSKai WangThe returned data descriptor will be setup to contain translated data. 55*2de3b87aSKai WangArgument 56*2de3b87aSKai Wang.Ar data 57*2de3b87aSKai Wangmay be NULL, in which case the function returns the first data descriptor 58*2de3b87aSKai Wangassociated with section 59*2de3b87aSKai Wang.Ar scn . 60*2de3b87aSKai WangIf argument 61*2de3b87aSKai Wang.Ar data 62*2de3b87aSKai Wangis not NULL, it must be a pointer to a data descriptor associated with 63*2de3b87aSKai Wangsection descriptor 64*2de3b87aSKai Wang.Ar scn , 65*2de3b87aSKai Wangand function 66*2de3b87aSKai Wang.Fn elf_getdata 67*2de3b87aSKai Wangwill return a pointer to the next data descriptor for the section, 68*2de3b87aSKai Wangor NULL when the end of the section's descriptor list is reached. 69*2de3b87aSKai Wang.Pp 70*2de3b87aSKai WangFunction 71*2de3b87aSKai Wang.Fn elf_newdata 72*2de3b87aSKai Wangwill allocate a new data descriptor and append it to the list of data 73*2de3b87aSKai Wangdescriptors associated with section descriptor 74*2de3b87aSKai Wang.Ar scn . 75*2de3b87aSKai WangThe new data descriptor will be initialized as follows: 76*2de3b87aSKai Wang.Bl -tag -width "d_version" -compact -offset indent 77*2de3b87aSKai Wang.It Va d_align 78*2de3b87aSKai WangSet to 1. 79*2de3b87aSKai Wang.It Va d_buf 80*2de3b87aSKai WangInitialized to NULL. 81*2de3b87aSKai Wang.It Va d_off 82*2de3b87aSKai WangSet to (off_t) -1. 83*2de3b87aSKai WangThis field is under application control if the 84*2de3b87aSKai Wang.Dv ELF_F_LAYOUT 85*2de3b87aSKai Wangflag was set on the ELF descriptor. 86*2de3b87aSKai Wang.It Va d_size 87*2de3b87aSKai WangSet to zero. 88*2de3b87aSKai Wang.It Va d_type 89*2de3b87aSKai WangInitialized to 90*2de3b87aSKai Wang.Dv ELF_T_BYTE . 91*2de3b87aSKai Wang.It Va d_version 92*2de3b87aSKai WangSet to the current working version of the library, as set by 93*2de3b87aSKai Wang.Xr elf_version 3 . 94*2de3b87aSKai Wang.El 95*2de3b87aSKai WangThe application must set these values as appropriate before 96*2de3b87aSKai Wangcalling 97*2de3b87aSKai Wang.Xr elf_update 3 . 98*2de3b87aSKai WangSection 99*2de3b87aSKai Wang.Ar scn 100*2de3b87aSKai Wangmust be associated with an ELF file opened for writing. 101*2de3b87aSKai WangIf the application has not requested full control of layout by 102*2de3b87aSKai Wangsetting the 103*2de3b87aSKai Wang.Dv ELF_F_LAYOUT 104*2de3b87aSKai Wangflag on descriptor 105*2de3b87aSKai Wang.Ar elf , 106*2de3b87aSKai Wangthen the data referenced by the returned descriptor will be positioned 107*2de3b87aSKai Wangafter the existing content of the section, honoring the file alignment 108*2de3b87aSKai Wangspecified in member 109*2de3b87aSKai Wang.Va d_align . 110*2de3b87aSKai WangOn successful completion of a call to 111*2de3b87aSKai Wang.Fn elf_newdata , 112*2de3b87aSKai Wangthe ELF library will mark the section 113*2de3b87aSKai Wang.Ar scn 114*2de3b87aSKai Wangas 115*2de3b87aSKai Wang.Dq dirty . 116*2de3b87aSKai Wang.Pp 117*2de3b87aSKai WangFunction 118*2de3b87aSKai Wang.Fn elf_rawdata 119*2de3b87aSKai Wangis used to step through the data descriptors associated with 120*2de3b87aSKai Wangsection 121*2de3b87aSKai Wang.Ar scn . 122*2de3b87aSKai WangIn contrast to function 123*2de3b87aSKai Wang.Fn elf_getdata , 124*2de3b87aSKai Wangthis function returns untranslated data. 125*2de3b87aSKai WangIf argument 126*2de3b87aSKai Wang.Ar data 127*2de3b87aSKai Wangis NULL, the first data descriptor associated with section 128*2de3b87aSKai Wang.Ar scn 129*2de3b87aSKai Wangis returned. 130*2de3b87aSKai WangIf argument 131*2de3b87aSKai Wang.Ar data 132*2de3b87aSKai Wangis not NULL, is must be a data descriptor associated with 133*2de3b87aSKai Wangsection 134*2de3b87aSKai Wang.Ar scn , 135*2de3b87aSKai Wangand function 136*2de3b87aSKai Wang.Fn elf_rawdata 137*2de3b87aSKai Wangwill return the next data descriptor in the list, or NULL 138*2de3b87aSKai Wangif no further descriptors are present. 139*2de3b87aSKai WangFunction 140*2de3b87aSKai Wang.Fn elf_rawdata 141*2de3b87aSKai Wangalways returns 142*2de3b87aSKai Wang.Vt Elf_Data 143*2de3b87aSKai Wangstructures of type 144*2de3b87aSKai Wang.Dv ELF_T_BYTE . 145*2de3b87aSKai Wang.Ss Special handling of zero-sized and SHT_NOBITS sections 146*2de3b87aSKai WangFor sections of type 147*2de3b87aSKai Wang.Dv SHT_NOBITS, 148*2de3b87aSKai Wangand for zero-sized sections, 149*2de3b87aSKai Wangthe functions 150*2de3b87aSKai Wang.Fn elf_getdata 151*2de3b87aSKai Wangand 152*2de3b87aSKai Wang.Fn elf_rawdata 153*2de3b87aSKai Wangreturn a pointer to a valid 154*2de3b87aSKai Wang.Vt Elf_Data 155*2de3b87aSKai Wangstructure that has its 156*2de3b87aSKai Wang.Va d_buf 157*2de3b87aSKai Wangmember set to NULL and its 158*2de3b87aSKai Wang.Va d_size 159*2de3b87aSKai Wangmember set to the size of the section. 160*2de3b87aSKai Wang.Pp 161*2de3b87aSKai WangIf an application wishes to create a section of type 162*2de3b87aSKai Wang.Dv SHT_NOBITS , 163*2de3b87aSKai Wangit should add a data buffer to the section using function 164*2de3b87aSKai Wang.Fn elf_newdata . 165*2de3b87aSKai WangIt should then set the 166*2de3b87aSKai Wang.Va d_buf 167*2de3b87aSKai Wangand 168*2de3b87aSKai Wang.Va d_size 169*2de3b87aSKai Wangmembers of the returned 170*2de3b87aSKai Wang.Vt Elf_Data 171*2de3b87aSKai Wangstructure to NULL and the desired size of the section respectively. 172*2de3b87aSKai Wang.Sh RETURN VALUES 173*2de3b87aSKai WangThese functions return a valid pointer to a data descriptor if successful, or 174*2de3b87aSKai WangNULL if an error occurs. 175*2de3b87aSKai Wang.Sh ERRORS 176*2de3b87aSKai WangThese functions may fail with the following errors: 177*2de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]" 178*2de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 179*2de3b87aSKai WangEither of the arguments 180*2de3b87aSKai Wang.Ar scn 181*2de3b87aSKai Wangor 182*2de3b87aSKai Wang.Ar data 183*2de3b87aSKai Wangwas NULL. 184*2de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 185*2de3b87aSKai WangThe data descriptor referenced by argument 186*2de3b87aSKai Wang.Ar data 187*2de3b87aSKai Wangis not associated with section descriptor 188*2de3b87aSKai Wang.Ar scn . 189*2de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 190*2de3b87aSKai WangThe section denoted by argument 191*2de3b87aSKai Wang.Ar scn 192*2de3b87aSKai Wanghad no data associated with it. 193*2de3b87aSKai Wang.It Bq Er ELF_E_DATA 194*2de3b87aSKai WangRetrieval of data from the underlying object failed. 195*2de3b87aSKai Wang.It Bq Er ELF_E_RESOURCE 196*2de3b87aSKai WangAn out of memory condition was detected. 197*2de3b87aSKai Wang.It Bq Er ELF_E_SECTION 198*2de3b87aSKai WangSection 199*2de3b87aSKai Wang.Ar scn 200*2de3b87aSKai Wanghad type 201*2de3b87aSKai Wang.Dv SHT_NULL . 202*2de3b87aSKai Wang.It Bq Er ELF_E_SECTION 203*2de3b87aSKai WangThe type of the section 204*2de3b87aSKai Wang.Ar scn 205*2de3b87aSKai Wangwas not recognized by the library. 206*2de3b87aSKai Wang.It Bq Er ELF_E_SECTION 207*2de3b87aSKai WangThe size of the section 208*2de3b87aSKai Wang.Ar scn 209*2de3b87aSKai Wangis not a multiple of the file size for its section type. 210*2de3b87aSKai Wang.It Bq Er ELF_E_SECTION 211*2de3b87aSKai WangThe file offset for section 212*2de3b87aSKai Wang.Ar scn 213*2de3b87aSKai Wangis incorrect. 214*2de3b87aSKai Wang.It Bq Er ELF_E_UNIMPL 215*2de3b87aSKai WangThe section type associated with section 216*2de3b87aSKai Wang.Ar scn 217*2de3b87aSKai Wangis currently unsupported by the library. 218*2de3b87aSKai Wang.El 219*2de3b87aSKai Wang.Sh SEE ALSO 220*2de3b87aSKai Wang.Xr elf 3 , 221*2de3b87aSKai Wang.Xr elf_flagdata 3 , 222*2de3b87aSKai Wang.Xr elf_flagscn 3 , 223*2de3b87aSKai Wang.Xr elf_getscn 3 , 224*2de3b87aSKai Wang.Xr elf_getshdr 3 , 225*2de3b87aSKai Wang.Xr elf_newscn 3 , 226*2de3b87aSKai Wang.Xr elf_rawfile 3 , 227*2de3b87aSKai Wang.Xr elf_update 3 , 228*2de3b87aSKai Wang.Xr elf_version 3 , 229*2de3b87aSKai Wang.Xr gelf 3 230