1 .\" $NetBSD: elf_memory.3,v 1.2 2014/03/09 16:58:04 christos Exp $
3 .\" Copyright (c) 2006,2008 Joseph Koshy. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
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.
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
26 .\" Id: elf_memory.3 2314 2011-12-11 06:19:51Z jkoshy
33 .Nd process an ELF or ar(1) archive mapped into memory
39 .Fn elf_memory "char *image" "size_t size"
43 is used to process an ELF file or
45 archive whose image is present in memory.
49 points to the start of the memory image of the file or archive.
52 contains the size in bytes of the memory image.
54 The ELF descriptor is created for reading (i.e., analogous to the
57 with a command argument value of
62 returns a pointer to a new ELF descriptor if successful, or NULL if an
65 The return value may be queried for the file type using
68 To read parse an elf file, use:
69 .Bd -literal -offset indent
75 if ((fd = open("./elf-file", O_RDONLY)) < 0 ||
77 (p = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t) 0)) ==
79 ... handle system error ...
82 if ((e = elf_memory(p, sb.st_size)) == NULL) {
83 ... handle elf(3) error ...
85 \&... use ELF descriptor "e" here ...
90 can fail with the following errors:
91 .Bl -tag -width "[ELF_E_RESOURCE]"
92 .It Bq Er ELF_E_ARGUMENT
93 A NULL value was used for argument
95 or the value of argument
98 .It Bq Er ELF_E_HEADER
99 The header of the ELF object contained an unsupported value in its
100 .Va e_ident[EI_CLASS]
102 .It Bq Er ELF_E_HEADER
103 The header of the ELF object contained an unsupported value in its
106 .It Bq Er ELF_E_RESOURCE
107 An out of memory condition was detected.
108 .It Bq Er ELF_E_SEQUENCE
111 was called before a working version was set using
113 .It Bq Er ELF_E_VERSION
114 The ELF object referenced by argument
116 was of an unsupported ELF version.