1*5ac3bc71Schristos.\" $NetBSD: elf_open.3,v 1.6 2024/03/03 17:37:33 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2012 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: elf_open.3 3957 2022-03-12 14:11:52Z jkoshy 279dd9d0cfSchristos.\" 28c5261b83Sjkoshy.Dd June 12, 2019 299dd9d0cfSchristos.Dt ELF_OPEN 3 30c5261b83Sjkoshy.Os 319dd9d0cfSchristos.Sh NAME 329dd9d0cfSchristos.Nm elf_open 339dd9d0cfSchristos.Nd open ELF objects and ar(1) archives 349dd9d0cfSchristos.Sh LIBRARY 359dd9d0cfSchristos.Lb libelf 369dd9d0cfSchristos.Sh SYNOPSIS 379dd9d0cfSchristos.In libelf.h 389dd9d0cfSchristos.Ft "Elf *" 399dd9d0cfSchristos.Fn elf_open "int fd" 409dd9d0cfSchristos.Ft "Elf *" 419dd9d0cfSchristos.Fn elf_openmemory "char *image" "size_t sz" 429dd9d0cfSchristos.Sh DESCRIPTION 439dd9d0cfSchristos.Em Important : 449dd9d0cfSchristosThe functions 459dd9d0cfSchristos.Fn elf_open 469dd9d0cfSchristosand 479dd9d0cfSchristos.Fn elf_openmemory 48c5261b83Sjkoshyare extensions to the 49c5261b83Sjkoshy.Xr elf 3 50c5261b83SjkoshyAPI, for the internal use of the 519dd9d0cfSchristosElftoolchain project. 529dd9d0cfSchristosPortable applications should not use these functions. 539dd9d0cfSchristos.Pp 549dd9d0cfSchristosThe function 559dd9d0cfSchristos.Fn elf_open 569dd9d0cfSchristosreturns an Elf descriptor opened with mode 579dd9d0cfSchristos.Dv ELF_C_READ 589dd9d0cfSchristosfor the ELF object or 599dd9d0cfSchristos.Xr ar 1 609dd9d0cfSchristosarchive referenced by the file descriptor in argument 613f622274Sjkoshy.Fa fd . 629dd9d0cfSchristos.Pp 639dd9d0cfSchristosThe function 649dd9d0cfSchristos.Fn elf_openmemory 659dd9d0cfSchristosreturns an ELF descriptor opened with mode 669dd9d0cfSchristos.Dv ELF_C_READ 679dd9d0cfSchristosfor the ELF object or 689dd9d0cfSchristos.Xr ar 1 699dd9d0cfSchristosarchive contained in the memory area pointed to by the argument 703f622274Sjkoshy.Fa image . 719dd9d0cfSchristosThe argument 723f622274Sjkoshy.Fa sz 739dd9d0cfSchristosspecifies the size of the memory area in bytes. 74c5261b83Sjkoshy.Sh RETURN VALUES 75c5261b83SjkoshyThe function returns a pointer to a ELF descriptor if successful, or 76c5261b83Sjkoshy.Dv NULL 77c5261b83Sjkoshyif an error occurred. 789dd9d0cfSchristos.Sh COMPATIBILITY 79c5261b83SjkoshyThese functions are non-standard extensions to the 80c5261b83Sjkoshy.Xr elf 3 81c5261b83SjkoshyAPI set. 829dd9d0cfSchristos.Pp 839dd9d0cfSchristosThe behavior of these functions differs from their counterparts 849dd9d0cfSchristos.Xr elf_begin 3 859dd9d0cfSchristosand 869dd9d0cfSchristos.Xr elf_memory 3 879dd9d0cfSchristosin that these functions will successfully open malformed ELF objects 889dd9d0cfSchristosand 899dd9d0cfSchristos.Xr ar 1 909dd9d0cfSchristosarchives, returning an Elf descriptor of type 919dd9d0cfSchristos.Dv ELF_K_NONE . 929dd9d0cfSchristos.Sh ERRORS 939dd9d0cfSchristosThese functions can fail with the following errors: 949dd9d0cfSchristos.Bl -tag -width "[ELF_E_RESOURCE]" 959dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 969dd9d0cfSchristosThe argument 973f622274Sjkoshy.Fa fd 989dd9d0cfSchristoswas of an unsupported file type. 999dd9d0cfSchristos.It Bq Er ELF_E_ARGUMENT 1009dd9d0cfSchristosThe argument 1013f622274Sjkoshy.Fa sz 1029dd9d0cfSchristoswas zero, or the argument 1033f622274Sjkoshy.Fa image 104c5261b83Sjkoshywas 105c5261b83Sjkoshy.Dv NULL . 1069dd9d0cfSchristos.It Bq Er ELF_E_IO 1079dd9d0cfSchristosThe file descriptor in argument 1083f622274Sjkoshy.Fa fd 1099dd9d0cfSchristoswas invalid. 1109dd9d0cfSchristos.It Bq Er ELF_E_IO 1119dd9d0cfSchristosThe file descriptor in argument 1123f622274Sjkoshy.Fa fd 1139dd9d0cfSchristoscould not be read. 1149dd9d0cfSchristos.It Bq Er ELF_E_RESOURCE 1159dd9d0cfSchristosAn out of memory condition was encountered. 1169dd9d0cfSchristos.It Bq Er ELF_E_SEQUENCE 1179dd9d0cfSchristosFunctions 1189dd9d0cfSchristos.Fn elf_open 1199dd9d0cfSchristosor 1209dd9d0cfSchristos.Fn elf_openmemory 1219dd9d0cfSchristoswas called before a working version was established with 1229dd9d0cfSchristos.Xr elf_version 3 . 1239dd9d0cfSchristos.El 1249dd9d0cfSchristos.Sh SEE ALSO 1259dd9d0cfSchristos.Xr elf 3 , 1269dd9d0cfSchristos.Xr elf_begin 3 , 1279dd9d0cfSchristos.Xr elf_errno 3 , 1289dd9d0cfSchristos.Xr elf_memory 3 , 1299dd9d0cfSchristos.Xr gelf 3 130