1*5ac3bc71Schristos.\" $NetBSD: gelf_newphdr.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_newphdr.3 3958 2022-03-12 14:31:32Z jkoshy 279dd9d0cfSchristos.\" 28c5261b83Sjkoshy.Dd June 12, 2019 299dd9d0cfSchristos.Dt GELF_NEWPHDR 3 30c5261b83Sjkoshy.Os 319dd9d0cfSchristos.Sh NAME 329dd9d0cfSchristos.Nm elf32_newphdr , 339dd9d0cfSchristos.Nm elf64_newphdr , 349dd9d0cfSchristos.Nm gelf_newphdr 359dd9d0cfSchristos.Nd allocate an ELF program header table 369dd9d0cfSchristos.Sh LIBRARY 379dd9d0cfSchristos.Lb libelf 389dd9d0cfSchristos.Sh SYNOPSIS 399dd9d0cfSchristos.In libelf.h 409dd9d0cfSchristos.Ft "Elf32_Phdr *" 419dd9d0cfSchristos.Fn elf32_newphdr "Elf *elf" "size_t count" 429dd9d0cfSchristos.Ft "Elf64_Phdr *" 439dd9d0cfSchristos.Fn elf64_newphdr "Elf *elf" "size_t count" 449dd9d0cfSchristos.In gelf.h 459dd9d0cfSchristos.Ft "void *" 469dd9d0cfSchristos.Fn gelf_newphdr "Elf *elf" "size_t count" 479dd9d0cfSchristos.Sh DESCRIPTION 489dd9d0cfSchristosThese functions allocate an ELF Program Header table 499dd9d0cfSchristosfor an ELF descriptor. 509dd9d0cfSchristos.Vt Elf32_Phdr 519dd9d0cfSchristosand 529dd9d0cfSchristos.Vt Elf64_Phdr 539dd9d0cfSchristosdescriptors are described further in 549dd9d0cfSchristos.Xr elf 5 . 559dd9d0cfSchristos.Pp 569dd9d0cfSchristosFunctions 579dd9d0cfSchristos.Fn elf32_newphdr 589dd9d0cfSchristosand 599dd9d0cfSchristos.Fn elf64_newphdr 609dd9d0cfSchristosallocate a table of 613f622274Sjkoshy.Fa count 629dd9d0cfSchristos.Vt Elf32_Phdr 639dd9d0cfSchristosand 649dd9d0cfSchristos.Vt Elf64_Phdr 659dd9d0cfSchristosdescriptors respectively, 669dd9d0cfSchristosdiscarding any existing program header table 679dd9d0cfSchristosalready present in the ELF descriptor 683f622274Sjkoshy.Fa elf . 699dd9d0cfSchristosA value of zero for argument 703f622274Sjkoshy.Fa count 719dd9d0cfSchristosmay be used to delete an existing program header table 729dd9d0cfSchristosfrom an ELF descriptor. 739dd9d0cfSchristos.Pp 749dd9d0cfSchristosFunction 759dd9d0cfSchristos.Fn gelf_newphdr 769dd9d0cfSchristoswill return a table of 779dd9d0cfSchristos.Vt Elf32_Phdr 789dd9d0cfSchristosor 799dd9d0cfSchristos.Vt Elf64_Phdr 809dd9d0cfSchristoswith 813f622274Sjkoshy.Fa count 829dd9d0cfSchristoselements depending on the ELF class of ELF descriptor 833f622274Sjkoshy.Fa elf . 849dd9d0cfSchristos.Pp 859dd9d0cfSchristosThe functions set the 869dd9d0cfSchristos.Dv ELF_F_DIRTY 879dd9d0cfSchristosflag on the program header table. 889dd9d0cfSchristosAll members of the returned array of Phdr structures 899dd9d0cfSchristoswill be initialized to zero. 909dd9d0cfSchristos.Pp 919dd9d0cfSchristosAfter a successful call to these functions, the pointer returned 929dd9d0cfSchristosby a prior call to 939dd9d0cfSchristos.Fn elf32_getphdr 949dd9d0cfSchristosor 959dd9d0cfSchristos.Fn elf64_getphdr 969dd9d0cfSchristoson the same descriptor 973f622274Sjkoshy.Fa elf 989dd9d0cfSchristoswill no longer be valid. 999dd9d0cfSchristos.Sh RETURN VALUES 100c5261b83SjkoshyThe functions a valid pointer if successful, or 101c5261b83Sjkoshy.Dv NULL 102c5261b83Sjkoshyin case an error was encountered. 103c5261b83Sjkoshy.Sh COMPATIBILITY 104c5261b83SjkoshyThe 105c5261b83Sjkoshy.Fn gelf_newphdr 106c5261b83Sjkoshyfunction uses a type of 107c5261b83Sjkoshy.Ft "void *" 108c5261b83Sjkoshyfor its returned value. 109c5261b83SjkoshyThis differs from some other implementations of the 110c5261b83Sjkoshy.Xr elf 3 111c5261b83SjkoshyAPI, which use an 112c5261b83Sjkoshy.Ft "unsigned long" 113c5261b83Sjkoshyreturn type. 1149dd9d0cfSchristos.Sh ERRORS 1159dd9d0cfSchristosThese functions may fail with the following errors: 1169dd9d0cfSchristos.Bl -tag -width "[ELF_E_RESOURCE]" 1179dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1189dd9d0cfSchristosArgument 1193f622274Sjkoshy.Fa elf 120c5261b83Sjkoshywas 121c5261b83Sjkoshy.Dv NULL . 1229dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1239dd9d0cfSchristosArgument 1243f622274Sjkoshy.Fa elf 1259dd9d0cfSchristoswas not a descriptor for an ELF object. 1269dd9d0cfSchristos.It Bq Er ELF_E_CLASS 1279dd9d0cfSchristosELF descriptor 1283f622274Sjkoshy.Fa elf 1299dd9d0cfSchristoswas of an unrecognized class. 1309dd9d0cfSchristos.It Bq Er ELF_E_RESOURCE 1319dd9d0cfSchristosAn out of memory condition was detected. 1329dd9d0cfSchristos.It Bq Er ELF_E_SEQUENCE 1339dd9d0cfSchristosAn executable header was not allocated for ELF descriptor 1343f622274Sjkoshy.Fa elf 1359dd9d0cfSchristosbefore using these APIs. 1369dd9d0cfSchristos.El 1379dd9d0cfSchristos.Sh SEE ALSO 1389dd9d0cfSchristos.Xr elf 3 , 1399dd9d0cfSchristos.Xr elf32_getphdr 3 , 1409dd9d0cfSchristos.Xr elf32_newehdr 3 , 1419dd9d0cfSchristos.Xr elf64_getphdr 3 , 1429dd9d0cfSchristos.Xr elf64_newehdr 3 , 1439dd9d0cfSchristos.Xr elf_flagphdr 3 , 1449dd9d0cfSchristos.Xr elf_getphnum 3 , 1459dd9d0cfSchristos.Xr gelf 3 , 1469dd9d0cfSchristos.Xr gelf_getphdr 3 , 1479dd9d0cfSchristos.Xr gelf_newehdr 3 , 1489dd9d0cfSchristos.Xr elf 5 149