xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/gelf_newphdr.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1.\"	$NetBSD: gelf_newphdr.3,v 1.6 2024/03/03 17:37:34 christos Exp $
2.\"
3.\" Copyright (c) 2006-2008 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: gelf_newphdr.3 3958 2022-03-12 14:31:32Z jkoshy
27.\"
28.Dd June 12, 2019
29.Dt GELF_NEWPHDR 3
30.Os
31.Sh NAME
32.Nm elf32_newphdr ,
33.Nm elf64_newphdr ,
34.Nm gelf_newphdr
35.Nd allocate an ELF program header table
36.Sh LIBRARY
37.Lb libelf
38.Sh SYNOPSIS
39.In libelf.h
40.Ft "Elf32_Phdr *"
41.Fn elf32_newphdr "Elf *elf" "size_t count"
42.Ft "Elf64_Phdr *"
43.Fn elf64_newphdr "Elf *elf" "size_t count"
44.In gelf.h
45.Ft "void *"
46.Fn gelf_newphdr "Elf *elf" "size_t count"
47.Sh DESCRIPTION
48These functions allocate an ELF Program Header table
49for an ELF descriptor.
50.Vt Elf32_Phdr
51and
52.Vt Elf64_Phdr
53descriptors are described further in
54.Xr elf 5 .
55.Pp
56Functions
57.Fn elf32_newphdr
58and
59.Fn elf64_newphdr
60allocate a table of
61.Fa count
62.Vt Elf32_Phdr
63and
64.Vt Elf64_Phdr
65descriptors respectively,
66discarding any existing program header table
67already present in the ELF descriptor
68.Fa elf .
69A value of zero for argument
70.Fa count
71may be used to delete an existing program header table
72from an ELF descriptor.
73.Pp
74Function
75.Fn gelf_newphdr
76will return a table of
77.Vt Elf32_Phdr
78or
79.Vt Elf64_Phdr
80with
81.Fa count
82elements depending on the ELF class of ELF descriptor
83.Fa elf .
84.Pp
85The functions set the
86.Dv ELF_F_DIRTY
87flag on the program header table.
88All members of the returned array of Phdr structures
89will be initialized to zero.
90.Pp
91After a successful call to these functions, the pointer returned
92by a prior call to
93.Fn elf32_getphdr
94or
95.Fn elf64_getphdr
96on the same descriptor
97.Fa elf
98will no longer be valid.
99.Sh RETURN VALUES
100The functions a valid pointer if successful, or
101.Dv NULL
102in case an error was encountered.
103.Sh COMPATIBILITY
104The
105.Fn gelf_newphdr
106function uses a type of
107.Ft "void *"
108for its returned value.
109This differs from some other implementations of the
110.Xr elf 3
111API, which use an
112.Ft "unsigned long"
113return type.
114.Sh ERRORS
115These functions may fail with the following errors:
116.Bl -tag -width "[ELF_E_RESOURCE]"
117.It Bq Er ELF_E_ARGUMENT
118Argument
119.Fa elf
120was
121.Dv NULL .
122.It Bq Er ELF_E_ARGUMENT
123Argument
124.Fa elf
125was not a descriptor for an ELF object.
126.It Bq Er ELF_E_CLASS
127ELF descriptor
128.Fa elf
129was of an unrecognized class.
130.It Bq Er ELF_E_RESOURCE
131An out of memory condition was detected.
132.It Bq Er ELF_E_SEQUENCE
133An executable header was not allocated for ELF descriptor
134.Fa elf
135before using these APIs.
136.El
137.Sh SEE ALSO
138.Xr elf 3 ,
139.Xr elf32_getphdr 3 ,
140.Xr elf32_newehdr 3 ,
141.Xr elf64_getphdr 3 ,
142.Xr elf64_newehdr 3 ,
143.Xr elf_flagphdr 3 ,
144.Xr elf_getphnum 3 ,
145.Xr gelf 3 ,
146.Xr gelf_getphdr 3 ,
147.Xr gelf_newehdr 3 ,
148.Xr elf 5
149