xref: /freebsd/contrib/elftoolchain/libelf/elf_open.3 (revision f81cdf24ba5436367377f7c8e8f51f6df2a75ca7)
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 3743 2019-06-12 19:36:30Z jkoshy $
25.\"
26.Dd June 12, 2019
27.Dt ELF_OPEN 3
28.Os
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
47.Xr elf 3
48API, for the internal use of the
49Elftoolchain project.
50Portable applications should not use these functions.
51.Pp
52The function
53.Fn elf_open
54returns an Elf descriptor opened with mode
55.Dv ELF_C_READ
56for the ELF object or
57.Xr ar 1
58archive referenced by the file descriptor in argument
59.Ar fd .
60.Pp
61The function
62.Fn elf_openmemory
63returns an ELF descriptor opened with mode
64.Dv ELF_C_READ
65for the ELF object or
66.Xr ar 1
67archive contained in the memory area pointed to by the argument
68.Ar image .
69The argument
70.Ar sz
71specifies the size of the memory area in bytes.
72.Sh RETURN VALUES
73The function returns a pointer to a ELF descriptor if successful, or
74NULL if an error occurred.
75.Sh COMPATIBILITY
76These functions are non-standard extensions to the
77.Xr elf 3
78API set.
79.Pp
80The behavior of these functions differs from their counterparts
81.Xr elf_begin 3
82and
83.Xr elf_memory 3
84in that these functions will successfully open malformed ELF objects
85and
86.Xr ar 1
87archives, returning an Elf descriptor of type
88.Dv ELF_K_NONE .
89.Sh ERRORS
90These functions can fail with the following errors:
91.Bl -tag -width "[ELF_E_RESOURCE]"
92.It Bq Er ELF_E_ARGUMENT
93The argument
94.Ar fd
95was of an unsupported file type.
96.It Bq Er ELF_E_ARGUMENT
97The argument
98.Ar sz
99was zero, or the argument
100.Ar image
101was NULL.
102.It Bq Er ELF_E_IO
103The file descriptor in argument
104.Ar fd
105was invalid.
106.It Bq Er ELF_E_IO
107The file descriptor in argument
108.Ar fd
109could not be read.
110.It Bq Er ELF_E_RESOURCE
111An out of memory condition was encountered.
112.It Bq Er ELF_E_SEQUENCE
113Functions
114.Fn elf_open
115or
116.Fn elf_openmemory
117was called before a working version was established with
118.Xr elf_version 3 .
119.El
120.Sh SEE ALSO
121.Xr elf 3 ,
122.Xr elf_begin 3 ,
123.Xr elf_errno 3 ,
124.Xr elf_memory 3 ,
125.Xr gelf 3
126