1*5ac3bc71Schristos.\" $NetBSD: gelf_newehdr.3,v 1.6 2024/03/03 17:37:34 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2006-2008 Joseph Koshy. All rights reserved. 49dd9d0cfSchristos.\" 59dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 69dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 79dd9d0cfSchristos.\" are met: 89dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 99dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 109dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 119dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 129dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 139dd9d0cfSchristos.\" 149dd9d0cfSchristos.\" This software is provided by Joseph Koshy ``as is'' and 159dd9d0cfSchristos.\" any express or implied warranties, including, but not limited to, the 169dd9d0cfSchristos.\" implied warranties of merchantability and fitness for a particular purpose 179dd9d0cfSchristos.\" are disclaimed. in no event shall Joseph Koshy be liable 189dd9d0cfSchristos.\" for any direct, indirect, incidental, special, exemplary, or consequential 199dd9d0cfSchristos.\" damages (including, but not limited to, procurement of substitute goods 209dd9d0cfSchristos.\" or services; loss of use, data, or profits; or business interruption) 219dd9d0cfSchristos.\" however caused and on any theory of liability, whether in contract, strict 229dd9d0cfSchristos.\" liability, or tort (including negligence or otherwise) arising in any way 239dd9d0cfSchristos.\" out of the use of this software, even if advised of the possibility of 249dd9d0cfSchristos.\" such damage. 259dd9d0cfSchristos.\" 263f622274Sjkoshy.\" Id: gelf_newehdr.3 3958 2022-03-12 14:31:32Z jkoshy 279dd9d0cfSchristos.\" 28c5261b83Sjkoshy.Dd June 12, 2019 299dd9d0cfSchristos.Dt GELF_NEWEHDR 3 30c5261b83Sjkoshy.Os 319dd9d0cfSchristos.Sh NAME 329dd9d0cfSchristos.Nm elf32_newehdr , 339dd9d0cfSchristos.Nm elf64_newehdr , 349dd9d0cfSchristos.Nm gelf_newehdr 359dd9d0cfSchristos.Nd retrieve or allocate the object file header 369dd9d0cfSchristos.Sh LIBRARY 379dd9d0cfSchristos.Lb libelf 389dd9d0cfSchristos.Sh SYNOPSIS 399dd9d0cfSchristos.In libelf.h 409dd9d0cfSchristos.Ft "Elf32_Ehdr *" 419dd9d0cfSchristos.Fn elf32_newehdr "Elf *elf" 429dd9d0cfSchristos.Ft "Elf64_Ehdr *" 439dd9d0cfSchristos.Fn elf64_newehdr "Elf *elf" 449dd9d0cfSchristos.In gelf.h 459dd9d0cfSchristos.Ft "void *" 469dd9d0cfSchristos.Fn gelf_newehdr "Elf *elf" "int elfclass" 479dd9d0cfSchristos.Sh DESCRIPTION 489dd9d0cfSchristosThese functions retrieve the ELF header from the ELF descriptor 493f622274Sjkoshy.Fa elf , 509dd9d0cfSchristosallocating a new header if needed. 519dd9d0cfSchristosFile data structures are translated to their in-memory representations 529dd9d0cfSchristosas described in 539dd9d0cfSchristos.Xr elf 3 . 549dd9d0cfSchristos.Pp 559dd9d0cfSchristosFunction 569dd9d0cfSchristos.Fn elf32_newehdr 579dd9d0cfSchristosreturns a pointer to a 32 bit 589dd9d0cfSchristos.Vt Elf32_Ehdr 599dd9d0cfSchristosstructure. 609dd9d0cfSchristosFunction 619dd9d0cfSchristos.Fn elf64_newehdr 629dd9d0cfSchristosreturns a pointer to a 64 bit 63c5261b83Sjkoshy.Vt Elf64_Ehdr 64c5261b83Sjkoshystructure. 659dd9d0cfSchristos.Pp 669dd9d0cfSchristosWhen argument 673f622274Sjkoshy.Fa elfclass 689dd9d0cfSchristoshas value 699dd9d0cfSchristos.Dv ELFCLASS32 , 709dd9d0cfSchristosfunction 719dd9d0cfSchristos.Fn gelf_newehdr 729dd9d0cfSchristosreturns the value returned by 739dd9d0cfSchristos.Fn elf32_newehdr "elf" . 749dd9d0cfSchristosWhen argument 753f622274Sjkoshy.Fa elfclass 769dd9d0cfSchristoshas value 779dd9d0cfSchristos.Dv ELFCLASS64 789dd9d0cfSchristosit returns the value returned by 799dd9d0cfSchristos.Fn elf64_newehdr "elf" . 809dd9d0cfSchristos.Pp 819dd9d0cfSchristosIf a fresh header structure is allocated, the members of the 829dd9d0cfSchristosstructure are initialized as follows: 839dd9d0cfSchristos.Bl -tag -width indent 849dd9d0cfSchristos.It Va "e_ident[EI_MAG0..EI_MAG3]" 859dd9d0cfSchristosIdentification bytes at offsets 869dd9d0cfSchristos.Dv EI_MAG0 , 879dd9d0cfSchristos.Dv EI_MAG1 , 889dd9d0cfSchristos.Dv EI_MAG2 899dd9d0cfSchristosand 909dd9d0cfSchristos.Dv EI_MAG3 919dd9d0cfSchristosare set to the ELF signature. 929dd9d0cfSchristos.It Va "e_ident[EI_CLASS]" 939dd9d0cfSchristosThe identification byte at offset 949dd9d0cfSchristos.Dv EI_CLASS 959dd9d0cfSchristosis set to the ELF class associated with the function being called 969dd9d0cfSchristosor to argument 973f622274Sjkoshy.Fa elfclass 989dd9d0cfSchristosfor function 999dd9d0cfSchristos.Fn gelf_newehdr . 1009dd9d0cfSchristos.It Va "e_ident[EI_DATA]" 1019dd9d0cfSchristosThe identification byte at offset 1029dd9d0cfSchristos.Dv EI_DATA 1039dd9d0cfSchristosis set to 1049dd9d0cfSchristos.Dv ELFDATANONE . 1059dd9d0cfSchristos.It Va "e_ident[EI_VERSION]" 1069dd9d0cfSchristosThe identification byte at offset 1079dd9d0cfSchristos.Dv EI_VERSION 1089dd9d0cfSchristosis set to the ELF library's operating version set by a prior call to 1099dd9d0cfSchristos.Xr elf_version 3 . 1109dd9d0cfSchristos.It Va e_machine 1119dd9d0cfSchristosis set to 1129dd9d0cfSchristos.Dv EM_NONE . 1139dd9d0cfSchristos.It Va e_type 1149dd9d0cfSchristosis set to 1159dd9d0cfSchristos.Dv ELF_K_NONE . 1169dd9d0cfSchristos.It Va e_version 1179dd9d0cfSchristosis set to the ELF library's operating version set by a prior call to 1189dd9d0cfSchristos.Xr elf_version 3 . 1199dd9d0cfSchristos.El 1209dd9d0cfSchristos.Pp 1219dd9d0cfSchristosOther members of the header are set to zero. 1229dd9d0cfSchristosThe application is responsible for changing these values 1239dd9d0cfSchristosas needed before calling 1249dd9d0cfSchristos.Fn elf_update . 1259dd9d0cfSchristos.Pp 1269dd9d0cfSchristosIf successful, these three functions set the 1279dd9d0cfSchristos.Dv ELF_F_DIRTY 1289dd9d0cfSchristosflag on ELF descriptor 1293f622274Sjkoshy.Fa elf . 1309dd9d0cfSchristos.Sh RETURN VALUES 1319dd9d0cfSchristosThese functions return a pointer to a translated header descriptor 132c5261b83Sjkoshyif successful, or 133c5261b83Sjkoshy.Dv NULL 134c5261b83Sjkoshyon failure. 135c5261b83Sjkoshy.Sh COMPATIBILITY 136c5261b83SjkoshyThe 137c5261b83Sjkoshy.Fn gelf_newehdr 138c5261b83Sjkoshyfunction uses a type of 139c5261b83Sjkoshy.Ft "void *" 140c5261b83Sjkoshyfor its returned value. 141c5261b83SjkoshyThis differs from some other implementations of the 142c5261b83Sjkoshy.Xr elf 3 143c5261b83SjkoshyAPI, which use an 144c5261b83Sjkoshy.Ft "unsigned long" 145c5261b83Sjkoshyreturn type. 1469dd9d0cfSchristos.Sh ERRORS 1479dd9d0cfSchristosThese functions can fail with the following errors: 1489dd9d0cfSchristos.Bl -tag -width "[ELF_E_RESOURCE]" 1499dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1509dd9d0cfSchristosThe argument 1513f622274Sjkoshy.Fa elf 1529dd9d0cfSchristoswas null. 1539dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1549dd9d0cfSchristosArgument 1553f622274Sjkoshy.Fa elf 1569dd9d0cfSchristoswas not a descriptor for an ELF object. 1579dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1589dd9d0cfSchristosArgument 1593f622274Sjkoshy.Fa elfclass 1609dd9d0cfSchristoshad an unsupported value. 1619dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1629dd9d0cfSchristosThe class of the ELF descriptor 1633f622274Sjkoshy.Fa elf 1649dd9d0cfSchristosdid not match that of the requested operation. 1659dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1669dd9d0cfSchristosFor function 1679dd9d0cfSchristos.Fn gelf_newehdr , 1689dd9d0cfSchristosthe class of argument 1693f622274Sjkoshy.Fa elf 1709dd9d0cfSchristoswas not 1719dd9d0cfSchristos.Dv ELFCLASSNONE 1729dd9d0cfSchristosand did not match the argument 1733f622274Sjkoshy.Fa elfclass . 1749dd9d0cfSchristos.It Bq Er ELF_E_CLASS 1759dd9d0cfSchristosThe ELF class of descriptor 1763f622274Sjkoshy.Fa elf 1779dd9d0cfSchristosdid not match that of the API function being called. 1789dd9d0cfSchristos.It Bq Er ELF_E_HEADER 1799dd9d0cfSchristosA malformed ELF header was detected. 1809dd9d0cfSchristos.It Bq Er ELF_E_RESOURCE 1819dd9d0cfSchristosAn out of memory condition was detected during execution. 1829dd9d0cfSchristos.It Bq Er ELF_E_SECTION 1839dd9d0cfSchristosThe ELF descriptor in argument 1843f622274Sjkoshy.Fa elf 1859dd9d0cfSchristosdid not adhere to the conventions used for extended numbering. 1869dd9d0cfSchristos.It Bq Er ELF_E_VERSION 1879dd9d0cfSchristosThe ELF descriptor 1883f622274Sjkoshy.Fa elf 1899dd9d0cfSchristoshad an unsupported ELF version number. 1909dd9d0cfSchristos.El 1919dd9d0cfSchristos.Sh SEE ALSO 1929dd9d0cfSchristos.Xr elf 3 , 1939dd9d0cfSchristos.Xr elf32_getehdr 3 , 1949dd9d0cfSchristos.Xr elf64_getehdr 3 , 1959dd9d0cfSchristos.Xr elf_flagdata 3 , 1969dd9d0cfSchristos.Xr elf_getident 3 , 1979dd9d0cfSchristos.Xr elf_update 3 , 1989dd9d0cfSchristos.Xr elf_version 3 , 1999dd9d0cfSchristos.Xr gelf 3 , 2009dd9d0cfSchristos.Xr gelf_getehdr 3 , 2019dd9d0cfSchristos.Xr elf 5 202