xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/elf_open.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1.\"	$NetBSD: elf_open.3,v 1.6 2024/03/03 17:37:33 christos Exp $
2.\"
3.\" Copyright (c) 2012 Joseph Koshy.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
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.
13.\"
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
24.\" such damage.
25.\"
26.\" Id: elf_open.3 3957 2022-03-12 14:11:52Z jkoshy
27.\"
28.Dd June 12, 2019
29.Dt ELF_OPEN 3
30.Os
31.Sh NAME
32.Nm elf_open
33.Nd open ELF objects and ar(1) archives
34.Sh LIBRARY
35.Lb libelf
36.Sh SYNOPSIS
37.In libelf.h
38.Ft "Elf *"
39.Fn elf_open "int fd"
40.Ft "Elf *"
41.Fn elf_openmemory "char *image" "size_t sz"
42.Sh DESCRIPTION
43.Em Important :
44The functions
45.Fn elf_open
46and
47.Fn elf_openmemory
48are extensions to the
49.Xr elf 3
50API, for the internal use of the
51Elftoolchain project.
52Portable applications should not use these functions.
53.Pp
54The function
55.Fn elf_open
56returns an Elf descriptor opened with mode
57.Dv ELF_C_READ
58for the ELF object or
59.Xr ar 1
60archive referenced by the file descriptor in argument
61.Fa fd .
62.Pp
63The function
64.Fn elf_openmemory
65returns an ELF descriptor opened with mode
66.Dv ELF_C_READ
67for the ELF object or
68.Xr ar 1
69archive contained in the memory area pointed to by the argument
70.Fa image .
71The argument
72.Fa sz
73specifies the size of the memory area in bytes.
74.Sh RETURN VALUES
75The function returns a pointer to a ELF descriptor if successful, or
76.Dv NULL
77if an error occurred.
78.Sh COMPATIBILITY
79These functions are non-standard extensions to the
80.Xr elf 3
81API set.
82.Pp
83The behavior of these functions differs from their counterparts
84.Xr elf_begin 3
85and
86.Xr elf_memory 3
87in that these functions will successfully open malformed ELF objects
88and
89.Xr ar 1
90archives, returning an Elf descriptor of type
91.Dv ELF_K_NONE .
92.Sh ERRORS
93These functions can fail with the following errors:
94.Bl -tag -width "[ELF_E_RESOURCE]"
95.It Bq Er ELF_E_ARGUMENT
96The argument
97.Fa fd
98was of an unsupported file type.
99.It Bq Er ELF_E_ARGUMENT
100The argument
101.Fa sz
102was zero, or the argument
103.Fa image
104was
105.Dv NULL .
106.It Bq Er ELF_E_IO
107The file descriptor in argument
108.Fa fd
109was invalid.
110.It Bq Er ELF_E_IO
111The file descriptor in argument
112.Fa fd
113could not be read.
114.It Bq Er ELF_E_RESOURCE
115An out of memory condition was encountered.
116.It Bq Er ELF_E_SEQUENCE
117Functions
118.Fn elf_open
119or
120.Fn elf_openmemory
121was called before a working version was established with
122.Xr elf_version 3 .
123.El
124.Sh SEE ALSO
125.Xr elf 3 ,
126.Xr elf_begin 3 ,
127.Xr elf_errno 3 ,
128.Xr elf_memory 3 ,
129.Xr gelf 3
130