1.\" $NetBSD: elf_getscn.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2.\" 3.\" Copyright (c) 2006-2008 Joseph Koshy. All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" This software is provided by Joseph Koshy ``as is'' and 15.\" any express or implied warranties, including, but not limited to, the 16.\" implied warranties of merchantability and fitness for a particular purpose 17.\" are disclaimed. in no event shall Joseph Koshy be liable 18.\" for any direct, indirect, incidental, special, exemplary, or consequential 19.\" damages (including, but not limited to, procurement of substitute goods 20.\" or services; loss of use, data, or profits; or business interruption) 21.\" however caused and on any theory of liability, whether in contract, strict 22.\" liability, or tort (including negligence or otherwise) arising in any way 23.\" out of the use of this software, even if advised of the possibility of 24.\" such damage. 25.\" 26.\" Id: elf_getscn.3 189 2008-07-20 10:38:08Z jkoshy 27.\" 28.Dd October 22, 2007 29.Os 30.Dt ELF_GETSCN 3 31.Sh NAME 32.Nm elf_getscn , 33.Nm elf_ndxscn , 34.Nm elf_newscn , 35.Nm elf_nextscn 36.Nd get/allocate section information for an ELF object 37.Sh LIBRARY 38.Lb libelf 39.Sh SYNOPSIS 40.In libelf.h 41.Ft "Elf_Scn *" 42.Fn elf_getscn "Elf *elf" "size_t index" 43.Ft size_t 44.Fn elf_ndxscn "Elf_Scn *scn" 45.Ft "Elf_Scn *" 46.Fn elf_newscn "Elf *elf" 47.Ft "Elf_Scn *" 48.Fn elf_nextscn "Elf *elf" "Elf_Scn *scn" 49.Sh DESCRIPTION 50These functions are used to iterate through the sections associated 51with an ELF descriptor. 52.Pp 53Function 54.Fn elf_getscn 55will return a section descriptor for the section at index 56.Ar index 57in the object denoted by ELF descriptor 58.Ar elf . 59An error will be signalled if the specified section does not 60exist. 61.Pp 62Function 63.Fn elf_ndxscn 64returns the section table index associated with section descriptor 65.Ar scn . 66.Pp 67Function 68.Fn elf_newscn 69creates a new section and appends it to the list of sections 70associated with descriptor 71.Ar elf . 72The library will automatically increment the 73.Va e_shnum 74field of the ELF header associated with descriptor 75.Ar elf , 76and will set the 77.Dv ELF_F_DIRTY 78flag on the returned section descriptor. 79For ELF descriptors opened for writing, the ELF library will 80automatically create an empty section at index zero 81.Dv ( SHN_UNDEF ) 82on the first call to 83.Fn elf_newscn . 84.Pp 85Function 86.Fn elf_nextscn 87takes a section descriptor 88.Ar scn 89and returns a pointer to the section descriptor at the next higher 90index. 91Argument 92.Ar scn 93is allowed to be NULL, in which case this function will return a 94pointer to the section descriptor at index 1. 95If no further sections are present, function 96.Fn elf_nextscn 97will return a NULL pointer. 98.Sh RETURN VALUES 99Functions 100.Fn elf_getscn , 101.Fn elf_newscn 102and 103.Fn elf_nextscn 104return a valid pointer to a section descriptor if successful, or 105NULL if an error occurs. 106.Pp 107Function 108.Fn elf_ndxscn 109returns a valid section table index if successful, or 110.Dv SHN_UNDEF 111if an error occurs. 112.Sh ERRORS 113These functions may fail with the following errors: 114.Bl -tag -width "[ELF_E_RESOURCE]" 115.It Bq Er ELF_E_ARGUMENT 116Arguments 117.Ar elf 118or 119.Ar scn 120were NULL. 121.It Bq Er ELF_E_ARGUMENT 122Argument 123.Ar index 124exceeded the current number of sections in the ELF object. 125.It Bq Er ELF_E_ARGUMENT 126Argument 127.Ar elf 128was not a descriptor for an ELF file. 129.It Bq Er ELF_E_ARGUMENT 130Section descriptor 131.Ar scn 132was not associated with ELF descriptor 133.Ar elf . 134.It Bq Er ELF_E_CLASS 135Descriptor 136.Ar elf 137was of an unknown ELF class. 138.It Bq Er ELF_E_SECTION 139Argument 140.Ar elf 141specified extended section numbering in the ELF header with the section header at 142index 143.Dv SHN_UNDEF 144not being of type 145.Dv SHT_NULL . 146.El 147.Sh SEE ALSO 148.Xr elf 3 , 149.Xr elf_flagdata 3 , 150.Xr elf_flagscn 3 , 151.Xr elf_getdata 3 , 152.Xr elf_getshdr 3 , 153.Xr gelf 3 154