1 /* Definitions for PRPSINFO structures under ELF on GNU/Linux.
2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #ifndef ELF_LINUX_CORE_H
22 #define ELF_LINUX_CORE_H
24 /* External 32-bit structure for PRPSINFO. This structure is
25 ABI-defined, thus we choose to use char arrays here in order to
26 avoid dealing with different types in different architectures.
28 This is the variant for targets which use a 32-bit data type for
29 UID and GID, as all modern Linux ports do. Some older ports use
30 a 16-bit data type instead; see below for the alternative variant.
32 This structure will ultimately be written in the corefile's note
33 section, as the PRPSINFO. */
35 struct elf_external_linux_prpsinfo32_ugid32
37 char pr_state
; /* Numeric process state. */
38 char pr_sname
; /* Char for pr_state. */
39 char pr_zomb
; /* Zombie. */
40 char pr_nice
; /* Nice val. */
41 char pr_flag
[4]; /* Flags. */
48 char pr_fname
[16] ATTRIBUTE_NONSTRING
; /* Filename of executable. */
49 char pr_psargs
[80] ATTRIBUTE_NONSTRING
; /* Initial part of arg list. */
52 /* Helper function to copy an elf_internal_linux_prpsinfo in host
53 endian to an elf_external_linux_prpsinfo32_ugid32 in target endian. */
56 swap_linux_prpsinfo32_ugid32_out
58 const struct elf_internal_linux_prpsinfo
*from
,
59 struct elf_external_linux_prpsinfo32_ugid32
*to
)
61 bfd_put_8 (obfd
, from
->pr_state
, &to
->pr_state
);
62 bfd_put_8 (obfd
, from
->pr_sname
, &to
->pr_sname
);
63 bfd_put_8 (obfd
, from
->pr_zomb
, &to
->pr_zomb
);
64 bfd_put_8 (obfd
, from
->pr_nice
, &to
->pr_nice
);
65 bfd_put_32 (obfd
, from
->pr_flag
, to
->pr_flag
);
66 bfd_put_32 (obfd
, from
->pr_uid
, to
->pr_uid
);
67 bfd_put_32 (obfd
, from
->pr_gid
, to
->pr_gid
);
68 bfd_put_32 (obfd
, from
->pr_pid
, to
->pr_pid
);
69 bfd_put_32 (obfd
, from
->pr_ppid
, to
->pr_ppid
);
70 bfd_put_32 (obfd
, from
->pr_pgrp
, to
->pr_pgrp
);
71 bfd_put_32 (obfd
, from
->pr_sid
, to
->pr_sid
);
72 strncpy (to
->pr_fname
, from
->pr_fname
, sizeof (to
->pr_fname
));
73 strncpy (to
->pr_psargs
, from
->pr_psargs
, sizeof (to
->pr_psargs
));
76 /* External 32-bit structure for PRPSINFO. This structure is
77 ABI-defined, thus we choose to use char arrays here in order to
78 avoid dealing with different types in different architectures.
80 This is the variant for targets which use a 16-bit data type for
81 UID and GID, as some older Linux ports do. All modern ports use
82 a 32-bit data type instead; see above for the alternative variant.
84 This structure will ultimately be written in the corefile's note
85 section, as the PRPSINFO. */
87 struct elf_external_linux_prpsinfo32_ugid16
89 char pr_state
; /* Numeric process state. */
90 char pr_sname
; /* Char for pr_state. */
91 char pr_zomb
; /* Zombie. */
92 char pr_nice
; /* Nice val. */
93 char pr_flag
[4]; /* Flags. */
100 char pr_fname
[16] ATTRIBUTE_NONSTRING
; /* Filename of executable. */
101 char pr_psargs
[80] ATTRIBUTE_NONSTRING
; /* Initial part of arg list. */
104 /* Helper function to copy an elf_internal_linux_prpsinfo in host
105 endian to an elf_external_linux_prpsinfo32_ugid16 in target endian. */
108 swap_linux_prpsinfo32_ugid16_out
110 const struct elf_internal_linux_prpsinfo
*from
,
111 struct elf_external_linux_prpsinfo32_ugid16
*to
)
113 bfd_put_8 (obfd
, from
->pr_state
, &to
->pr_state
);
114 bfd_put_8 (obfd
, from
->pr_sname
, &to
->pr_sname
);
115 bfd_put_8 (obfd
, from
->pr_zomb
, &to
->pr_zomb
);
116 bfd_put_8 (obfd
, from
->pr_nice
, &to
->pr_nice
);
117 bfd_put_32 (obfd
, from
->pr_flag
, to
->pr_flag
);
118 bfd_put_16 (obfd
, from
->pr_uid
, to
->pr_uid
);
119 bfd_put_16 (obfd
, from
->pr_gid
, to
->pr_gid
);
120 bfd_put_32 (obfd
, from
->pr_pid
, to
->pr_pid
);
121 bfd_put_32 (obfd
, from
->pr_ppid
, to
->pr_ppid
);
122 bfd_put_32 (obfd
, from
->pr_pgrp
, to
->pr_pgrp
);
123 bfd_put_32 (obfd
, from
->pr_sid
, to
->pr_sid
);
124 strncpy (to
->pr_fname
, from
->pr_fname
, sizeof (to
->pr_fname
));
125 strncpy (to
->pr_psargs
, from
->pr_psargs
, sizeof (to
->pr_psargs
));
128 /* External 64-bit structure for PRPSINFO. This structure is
129 ABI-defined, thus we choose to use char arrays here in order to
130 avoid dealing with different types in different architectures.
132 This is the variant for targets which use a 32-bit data type for
133 UID and GID, as most Linux ports do. The SH64 port uses a 16-bit
134 data type instead; see below for the alternative variant.
136 This structure will ultimately be written in the corefile's note
137 section, as the PRPSINFO. */
139 struct elf_external_linux_prpsinfo64_ugid32
141 char pr_state
; /* Numeric process state. */
142 char pr_sname
; /* Char for pr_state. */
143 char pr_zomb
; /* Zombie. */
144 char pr_nice
; /* Nice val. */
146 char pr_flag
[8]; /* Flags. */
153 char pr_fname
[16] ATTRIBUTE_NONSTRING
; /* Filename of executable. */
154 char pr_psargs
[80] ATTRIBUTE_NONSTRING
; /* Initial part of arg list. */
157 /* Helper function to copy an elf_internal_linux_prpsinfo in host
158 endian to an elf_external_linux_prpsinfo64_ugid32 in target endian. */
161 swap_linux_prpsinfo64_ugid32_out
163 const struct elf_internal_linux_prpsinfo
*from
,
164 struct elf_external_linux_prpsinfo64_ugid32
*to
)
166 bfd_put_8 (obfd
, from
->pr_state
, &to
->pr_state
);
167 bfd_put_8 (obfd
, from
->pr_sname
, &to
->pr_sname
);
168 bfd_put_8 (obfd
, from
->pr_zomb
, &to
->pr_zomb
);
169 bfd_put_8 (obfd
, from
->pr_nice
, &to
->pr_nice
);
170 bfd_put_64 (obfd
, from
->pr_flag
, to
->pr_flag
);
171 bfd_put_32 (obfd
, from
->pr_uid
, to
->pr_uid
);
172 bfd_put_32 (obfd
, from
->pr_gid
, to
->pr_gid
);
173 bfd_put_32 (obfd
, from
->pr_pid
, to
->pr_pid
);
174 bfd_put_32 (obfd
, from
->pr_ppid
, to
->pr_ppid
);
175 bfd_put_32 (obfd
, from
->pr_pgrp
, to
->pr_pgrp
);
176 bfd_put_32 (obfd
, from
->pr_sid
, to
->pr_sid
);
177 strncpy (to
->pr_fname
, from
->pr_fname
, sizeof (to
->pr_fname
));
178 strncpy (to
->pr_psargs
, from
->pr_psargs
, sizeof (to
->pr_psargs
));
181 /* External 64-bit structure for PRPSINFO. This structure is
182 ABI-defined, thus we choose to use char arrays here in order to
183 avoid dealing with different types in different architectures.
185 This is the variant for the SH64 port which uses a 16-bit data
186 type for UID and GID. Most Linux ports use a 32-bit data type
187 instead; see above for the alternative variant.
189 This structure will ultimately be written in the corefile's note
190 section, as the PRPSINFO. */
192 struct elf_external_linux_prpsinfo64_ugid16
194 char pr_state
; /* Numeric process state. */
195 char pr_sname
; /* Char for pr_state. */
196 char pr_zomb
; /* Zombie. */
197 char pr_nice
; /* Nice val. */
199 char pr_flag
[8]; /* Flags. */
206 char pr_fname
[16] ATTRIBUTE_NONSTRING
; /* Filename of executable. */
207 char pr_psargs
[80] ATTRIBUTE_NONSTRING
; /* Initial part of arg list. */
210 /* Helper function to copy an elf_internal_linux_prpsinfo in host
211 endian to an elf_external_linux_prpsinfo64_ugid16 in target endian. */
214 swap_linux_prpsinfo64_ugid16_out
216 const struct elf_internal_linux_prpsinfo
*from
,
217 struct elf_external_linux_prpsinfo64_ugid16
*to
)
219 bfd_put_8 (obfd
, from
->pr_state
, &to
->pr_state
);
220 bfd_put_8 (obfd
, from
->pr_sname
, &to
->pr_sname
);
221 bfd_put_8 (obfd
, from
->pr_zomb
, &to
->pr_zomb
);
222 bfd_put_8 (obfd
, from
->pr_nice
, &to
->pr_nice
);
223 bfd_put_64 (obfd
, from
->pr_flag
, to
->pr_flag
);
224 bfd_put_16 (obfd
, from
->pr_uid
, to
->pr_uid
);
225 bfd_put_16 (obfd
, from
->pr_gid
, to
->pr_gid
);
226 bfd_put_32 (obfd
, from
->pr_pid
, to
->pr_pid
);
227 bfd_put_32 (obfd
, from
->pr_ppid
, to
->pr_ppid
);
228 bfd_put_32 (obfd
, from
->pr_pgrp
, to
->pr_pgrp
);
229 bfd_put_32 (obfd
, from
->pr_sid
, to
->pr_sid
);
230 strncpy (to
->pr_fname
, from
->pr_fname
, sizeof (to
->pr_fname
));
231 strncpy (to
->pr_psargs
, from
->pr_psargs
, sizeof (to
->pr_psargs
));