xref: /freebsd/contrib/elftoolchain/libelf/elf_open.3 (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
1.\" Copyright (c) 2012 Joseph Koshy.  All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" This software is provided by Joseph Koshy ``as is'' and
13.\" any express or implied warranties, including, but not limited to, the
14.\" implied warranties of merchantability and fitness for a particular purpose
15.\" are disclaimed.  in no event shall Joseph Koshy be liable
16.\" for any direct, indirect, incidental, special, exemplary, or consequential
17.\" damages (including, but not limited to, procurement of substitute goods
18.\" or services; loss of use, data, or profits; or business interruption)
19.\" however caused and on any theory of liability, whether in contract, strict
20.\" liability, or tort (including negligence or otherwise) arising in any way
21.\" out of the use of this software, even if advised of the possibility of
22.\" such damage.
23.\"
24.\" $Id: elf_open.3 3181 2015-04-10 13:22:51Z emaste $
25.\"
26.Dd May 31, 2012
27.Os
28.Dt ELF_OPEN 3
29.Sh NAME
30.Nm elf_open
31.Nd open ELF objects and ar(1) archives
32.Sh LIBRARY
33.Lb libelf
34.Sh SYNOPSIS
35.In libelf.h
36.Ft "Elf *"
37.Fn elf_open "int fd"
38.Ft "Elf *"
39.Fn elf_openmemory "char *image" "size_t sz"
40.Sh DESCRIPTION
41.Em Important :
42The functions
43.Fn elf_open
44and
45.Fn elf_openmemory
46are extensions to the ELF(3) API, for the internal use of the
47Elftoolchain project.
48Portable applications should not use these functions.
49.Pp
50The function
51.Fn elf_open
52returns an Elf descriptor opened with mode
53.Dv ELF_C_READ
54for the ELF object or
55.Xr ar 1
56archive referenced by the file descriptor in argument
57.Ar fd .
58.Pp
59The function
60.Fn elf_openmemory
61returns an ELF descriptor opened with mode
62.Dv ELF_C_READ
63for the ELF object or
64.Xr ar 1
65archive contained in the memory area pointed to by the argument
66.Ar image .
67The argument
68.Ar sz
69specifies the size of the memory area in bytes.
70.Sh COMPATIBILITY
71These functions are non-standard extensions to the ELF(3) API set.
72.Pp
73The behavior of these functions differs from their counterparts
74.Xr elf_begin 3
75and
76.Xr elf_memory 3
77in that these functions will successfully open malformed ELF objects
78and
79.Xr ar 1
80archives, returning an Elf descriptor of type
81.Dv ELF_K_NONE .
82.Sh RETURN VALUES
83The function returns a pointer to a ELF descriptor if successful, or
84NULL if an error occurred.
85.Sh ERRORS
86These functions can fail with the following errors:
87.Bl -tag -width "[ELF_E_RESOURCE]"
88.It Bq Er ELF_E_ARGUMENT
89The argument
90.Ar fd
91was of an unsupported file type.
92.It Bq Er ELF_E_ARGUMENT
93The argument
94.Ar sz
95was zero, or the argument
96.Ar image
97was NULL.
98.It Bq Er ELF_E_IO
99The file descriptor in argument
100.Ar fd
101was invalid.
102.It Bq Er ELF_E_IO
103The file descriptor in argument
104.Ar fd
105could not be read.
106.It Bq Er ELF_E_RESOURCE
107An out of memory condition was encountered.
108.It Bq Er ELF_E_SEQUENCE
109Functions
110.Fn elf_open
111or
112.Fn elf_openmemory
113was called before a working version was established with
114.Xr elf_version 3 .
115.El
116.Sh SEE ALSO
117.Xr elf 3 ,
118.Xr elf_begin 3 ,
119.Xr elf_errno 3 ,
120.Xr elf_memory 3 ,
121.Xr gelf 3
122