12de3b87aSKai Wang.\" Copyright (c) 2006,2008 Joseph Koshy. All rights reserved. 22de3b87aSKai Wang.\" 32de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 42de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 52de3b87aSKai Wang.\" are met: 62de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 72de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 82de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 92de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 102de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 112de3b87aSKai Wang.\" 122de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and 132de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the 142de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose 152de3b87aSKai Wang.\" are disclaimed. in no event shall Joseph Koshy be liable 162de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential 172de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods 182de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption) 192de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict 202de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way 212de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of 222de3b87aSKai Wang.\" such damage. 232de3b87aSKai Wang.\" 24*ae500c1fSEd Maste.\" $Id: elf_memory.3 3639 2018-10-14 14:07:02Z jkoshy $ 252de3b87aSKai Wang.\" 262de3b87aSKai Wang.Dd June 28, 2006 272de3b87aSKai Wang.Dt ELF_MEMORY 3 28*ae500c1fSEd Maste.Os 292de3b87aSKai Wang.Sh NAME 302de3b87aSKai Wang.Nm elf_memory 312de3b87aSKai Wang.Nd process an ELF or ar(1) archive mapped into memory 322de3b87aSKai Wang.Sh LIBRARY 332de3b87aSKai Wang.Lb libelf 342de3b87aSKai Wang.Sh SYNOPSIS 352de3b87aSKai Wang.In libelf.h 362de3b87aSKai Wang.Ft "Elf *" 372de3b87aSKai Wang.Fn elf_memory "char *image" "size_t size" 382de3b87aSKai Wang.Sh DESCRIPTION 392de3b87aSKai WangFunction 402de3b87aSKai Wang.Fn elf_memory 412de3b87aSKai Wangis used to process an ELF file or 422de3b87aSKai Wang.Xr ar 1 432de3b87aSKai Wangarchive whose image is present in memory. 442de3b87aSKai Wang.Pp 452de3b87aSKai WangArgument 462de3b87aSKai Wang.Ar image 472de3b87aSKai Wangpoints to the start of the memory image of the file or archive. 482de3b87aSKai WangArgument 492de3b87aSKai Wang.Ar size 502de3b87aSKai Wangcontains the size in bytes of the memory image. 512de3b87aSKai Wang.Pp 522de3b87aSKai WangThe ELF descriptor is created for reading (i.e., analogous to the 532de3b87aSKai Wanguse of 542de3b87aSKai Wang.Xr elf_begin 3 552de3b87aSKai Wangwith a command argument value of 562de3b87aSKai Wang.Dv ELF_C_READ Ns ). 572de3b87aSKai Wang.Sh RETURN VALUES 582de3b87aSKai WangFunction 592de3b87aSKai Wang.Fn elf_memory 602de3b87aSKai Wangreturns a pointer to a new ELF descriptor if successful, or NULL if an 612de3b87aSKai Wangerror occurred. 622de3b87aSKai Wang.Pp 632de3b87aSKai WangThe return value may be queried for the file type using 642de3b87aSKai Wang.Xr elf_kind 3 . 652de3b87aSKai Wang.Sh EXAMPLES 662de3b87aSKai WangTo read parse an elf file, use: 672de3b87aSKai Wang.Bd -literal -offset indent 682de3b87aSKai Wangint fd; 692de3b87aSKai Wangvoid *p; 702de3b87aSKai Wangstruct stat sb; 712de3b87aSKai WangElf *e; 722de3b87aSKai Wang\&... 732de3b87aSKai Wangif ((fd = open("./elf-file", O_RDONLY)) < 0 || 742de3b87aSKai Wang fstat(fd, &sb) < 0 || 752de3b87aSKai Wang (p = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t) 0)) == 762de3b87aSKai Wang MAP_FAILED) { 772de3b87aSKai Wang ... handle system error ... 782de3b87aSKai Wang} 792de3b87aSKai Wang 802de3b87aSKai Wangif ((e = elf_memory(p, sb.st_size)) == NULL) { 812de3b87aSKai Wang ... handle elf(3) error ... 822de3b87aSKai Wang} 832de3b87aSKai Wang\&... use ELF descriptor "e" here ... 842de3b87aSKai Wang.Ed 852de3b87aSKai Wang.Sh ERRORS 862de3b87aSKai WangFunction 872de3b87aSKai Wang.Fn elf_memory 882de3b87aSKai Wangcan fail with the following errors: 892de3b87aSKai Wang.Bl -tag -width "[ELF_E_RESOURCE]" 902de3b87aSKai Wang.It Bq Er ELF_E_ARGUMENT 912de3b87aSKai WangA NULL value was used for argument 922de3b87aSKai Wang.Ar image 932de3b87aSKai Wangor the value of argument 942de3b87aSKai Wang.Ar sz 952de3b87aSKai Wangwas zero. 962de3b87aSKai Wang.It Bq Er ELF_E_HEADER 972de3b87aSKai WangThe header of the ELF object contained an unsupported value in its 982de3b87aSKai Wang.Va e_ident[EI_CLASS] 992de3b87aSKai Wangfield. 1002de3b87aSKai Wang.It Bq Er ELF_E_HEADER 1012de3b87aSKai WangThe header of the ELF object contained an unsupported value in its 1022de3b87aSKai Wang.Va e_ident[EI_DATA] 1032de3b87aSKai Wangfield. 1042de3b87aSKai Wang.It Bq Er ELF_E_RESOURCE 1052de3b87aSKai WangAn out of memory condition was detected. 1062de3b87aSKai Wang.It Bq Er ELF_E_SEQUENCE 1072de3b87aSKai WangFunction 1082de3b87aSKai Wang.Fn elf_memory 1092de3b87aSKai Wangwas called before a working version was set using 1102de3b87aSKai Wang.Xr elf_version 3 . 1112de3b87aSKai Wang.It Bq Er ELF_E_VERSION 1122de3b87aSKai WangThe ELF object referenced by argument 1132de3b87aSKai Wang.Ar image 1142de3b87aSKai Wangwas of an unsupported ELF version. 1152de3b87aSKai Wang.El 1162de3b87aSKai Wang.Sh SEE ALSO 1172de3b87aSKai Wang.Xr elf 3 , 1182de3b87aSKai Wang.Xr elf_begin 3 , 1192de3b87aSKai Wang.Xr elf_end 3 , 1202de3b87aSKai Wang.Xr elf_errno 3 , 1212de3b87aSKai Wang.Xr elf_kind 3 , 1222de3b87aSKai Wang.Xr gelf 3 123