Commit | Line | Data |
---|---|---|
70a38d42 | 1 | /* Definitions for PRPSINFO structures under ELF on GNU/Linux. |
219d1afa | 2 | Copyright (C) 2013-2018 Free Software Foundation, Inc. |
70a38d42 SDJ |
3 | |
4 | This file is part of BFD, the Binary File Descriptor library. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
20 | ||
aeb70569 AM |
21 | #ifndef ELF_LINUX_CORE_H |
22 | #define ELF_LINUX_CORE_H | |
70a38d42 | 23 | |
d99b4b92 AM |
24 | /* gcc-8 warns (*) on all the strncpy calls in this file about |
25 | possible string truncation. The "truncation" is not a bug. We | |
26 | have an external representation of structs with fields that are not | |
27 | necessarily NULL terminated and corresponding internal | |
28 | representation fields that are one larger so that they can always | |
29 | be NULL terminated. | |
30 | gcc versions between 4.2 and 4.6 do not allow pragma control of | |
31 | diagnostics inside functions, giving a hard error if you try to use | |
32 | the finer control available with later versions. | |
33 | gcc prior to 4.2 warns about diagnostic push and pop. | |
34 | gcc-5, gcc-6 and gcc-7 warn that -Wstringop-truncation is unknown, | |
35 | unless you also add #pragma GCC diagnostic ignored "-Wpragma". | |
36 | (*) Depending on your system header files! */ | |
37 | ||
38 | #if GCC_VERSION >= 8000 | |
39 | #pragma GCC diagnostic push | |
40 | #pragma GCC diagnostic ignored "-Wstringop-truncation" | |
41 | #endif | |
42 | ||
a2f63b2e MR |
43 | /* External 32-bit structure for PRPSINFO. This structure is |
44 | ABI-defined, thus we choose to use char arrays here in order to | |
45 | avoid dealing with different types in different architectures. | |
46 | ||
47 | This is the variant for targets which use a 32-bit data type for | |
48 | UID and GID, as all modern Linux ports do. Some older ports use | |
49 | a 16-bit data type instead; see below for the alternative variant. | |
50 | ||
51 | This structure will ultimately be written in the corefile's note | |
52 | section, as the PRPSINFO. */ | |
53 | ||
54 | struct elf_external_linux_prpsinfo32_ugid32 | |
55 | { | |
56 | char pr_state; /* Numeric process state. */ | |
57 | char pr_sname; /* Char for pr_state. */ | |
58 | char pr_zomb; /* Zombie. */ | |
59 | char pr_nice; /* Nice val. */ | |
60 | char pr_flag[4]; /* Flags. */ | |
61 | char pr_uid[4]; | |
62 | char pr_gid[4]; | |
63 | char pr_pid[4]; | |
64 | char pr_ppid[4]; | |
65 | char pr_pgrp[4]; | |
66 | char pr_sid[4]; | |
67 | char pr_fname[16]; /* Filename of executable. */ | |
68 | char pr_psargs[80]; /* Initial part of arg list. */ | |
69 | }; | |
70 | ||
71 | /* Helper function to copy an elf_internal_linux_prpsinfo in host | |
72 | endian to an elf_external_linux_prpsinfo32_ugid32 in target endian. */ | |
73 | ||
74 | static inline void | |
75 | swap_linux_prpsinfo32_ugid32_out | |
76 | (bfd *obfd, | |
77 | const struct elf_internal_linux_prpsinfo *from, | |
78 | struct elf_external_linux_prpsinfo32_ugid32 *to) | |
79 | { | |
80 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
81 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
82 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
83 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
84 | bfd_put_32 (obfd, from->pr_flag, to->pr_flag); | |
85 | bfd_put_32 (obfd, from->pr_uid, to->pr_uid); | |
86 | bfd_put_32 (obfd, from->pr_gid, to->pr_gid); | |
87 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
88 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
89 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
90 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
91 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); | |
92 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
93 | } | |
70a38d42 SDJ |
94 | |
95 | /* External 32-bit structure for PRPSINFO. This structure is | |
96 | ABI-defined, thus we choose to use char arrays here in order to | |
97 | avoid dealing with different types in different architectures. | |
98 | ||
a2f63b2e MR |
99 | This is the variant for targets which use a 16-bit data type for |
100 | UID and GID, as some older Linux ports do. All modern ports use | |
101 | a 32-bit data type instead; see above for the alternative variant. | |
102 | ||
70a38d42 SDJ |
103 | This structure will ultimately be written in the corefile's note |
104 | section, as the PRPSINFO. */ | |
105 | ||
a2f63b2e | 106 | struct elf_external_linux_prpsinfo32_ugid16 |
70a38d42 SDJ |
107 | { |
108 | char pr_state; /* Numeric process state. */ | |
109 | char pr_sname; /* Char for pr_state. */ | |
110 | char pr_zomb; /* Zombie. */ | |
111 | char pr_nice; /* Nice val. */ | |
112 | char pr_flag[4]; /* Flags. */ | |
113 | char pr_uid[2]; | |
114 | char pr_gid[2]; | |
115 | char pr_pid[4]; | |
116 | char pr_ppid[4]; | |
117 | char pr_pgrp[4]; | |
118 | char pr_sid[4]; | |
119 | char pr_fname[16]; /* Filename of executable. */ | |
120 | char pr_psargs[80]; /* Initial part of arg list. */ | |
121 | }; | |
122 | ||
aeb70569 | 123 | /* Helper function to copy an elf_internal_linux_prpsinfo in host |
a2f63b2e | 124 | endian to an elf_external_linux_prpsinfo32_ugid16 in target endian. */ |
aeb70569 AM |
125 | |
126 | static inline void | |
a2f63b2e MR |
127 | swap_linux_prpsinfo32_ugid16_out |
128 | (bfd *obfd, | |
129 | const struct elf_internal_linux_prpsinfo *from, | |
130 | struct elf_external_linux_prpsinfo32_ugid16 *to) | |
aeb70569 AM |
131 | { |
132 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
133 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
134 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
135 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
136 | bfd_put_32 (obfd, from->pr_flag, to->pr_flag); | |
137 | bfd_put_16 (obfd, from->pr_uid, to->pr_uid); | |
138 | bfd_put_16 (obfd, from->pr_gid, to->pr_gid); | |
139 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
140 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
141 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
142 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
143 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); | |
144 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
145 | } | |
70a38d42 SDJ |
146 | |
147 | /* External 64-bit structure for PRPSINFO. This structure is | |
148 | ABI-defined, thus we choose to use char arrays here in order to | |
149 | avoid dealing with different types in different architectures. | |
150 | ||
3c9a7b0d MR |
151 | This is the variant for targets which use a 32-bit data type for |
152 | UID and GID, as most Linux ports do. The SH64 port uses a 16-bit | |
153 | data type instead; see below for the alternative variant. | |
154 | ||
70a38d42 SDJ |
155 | This structure will ultimately be written in the corefile's note |
156 | section, as the PRPSINFO. */ | |
157 | ||
3c9a7b0d | 158 | struct elf_external_linux_prpsinfo64_ugid32 |
70a38d42 SDJ |
159 | { |
160 | char pr_state; /* Numeric process state. */ | |
161 | char pr_sname; /* Char for pr_state. */ | |
162 | char pr_zomb; /* Zombie. */ | |
163 | char pr_nice; /* Nice val. */ | |
70a38d42 | 164 | char gap[4]; |
72bc1bb9 | 165 | char pr_flag[8]; /* Flags. */ |
70a38d42 SDJ |
166 | char pr_uid[4]; |
167 | char pr_gid[4]; | |
168 | char pr_pid[4]; | |
169 | char pr_ppid[4]; | |
170 | char pr_pgrp[4]; | |
171 | char pr_sid[4]; | |
172 | char pr_fname[16]; /* Filename of executable. */ | |
173 | char pr_psargs[80]; /* Initial part of arg list. */ | |
174 | }; | |
175 | ||
aeb70569 | 176 | /* Helper function to copy an elf_internal_linux_prpsinfo in host |
3c9a7b0d | 177 | endian to an elf_external_linux_prpsinfo64_ugid32 in target endian. */ |
aeb70569 AM |
178 | |
179 | static inline void | |
3c9a7b0d MR |
180 | swap_linux_prpsinfo64_ugid32_out |
181 | (bfd *obfd, | |
182 | const struct elf_internal_linux_prpsinfo *from, | |
183 | struct elf_external_linux_prpsinfo64_ugid32 *to) | |
aeb70569 AM |
184 | { |
185 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
186 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
187 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
188 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
189 | bfd_put_64 (obfd, from->pr_flag, to->pr_flag); | |
190 | bfd_put_32 (obfd, from->pr_uid, to->pr_uid); | |
191 | bfd_put_32 (obfd, from->pr_gid, to->pr_gid); | |
192 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
193 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
194 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
195 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
196 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); | |
197 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
198 | } | |
70a38d42 | 199 | |
3c9a7b0d MR |
200 | /* External 64-bit structure for PRPSINFO. This structure is |
201 | ABI-defined, thus we choose to use char arrays here in order to | |
202 | avoid dealing with different types in different architectures. | |
203 | ||
204 | This is the variant for the SH64 port which uses a 16-bit data | |
205 | type for UID and GID. Most Linux ports use a 32-bit data type | |
206 | instead; see above for the alternative variant. | |
207 | ||
208 | This structure will ultimately be written in the corefile's note | |
209 | section, as the PRPSINFO. */ | |
210 | ||
211 | struct elf_external_linux_prpsinfo64_ugid16 | |
212 | { | |
213 | char pr_state; /* Numeric process state. */ | |
214 | char pr_sname; /* Char for pr_state. */ | |
215 | char pr_zomb; /* Zombie. */ | |
216 | char pr_nice; /* Nice val. */ | |
217 | char gap[4]; | |
218 | char pr_flag[8]; /* Flags. */ | |
219 | char pr_uid[2]; | |
220 | char pr_gid[2]; | |
221 | char pr_pid[4]; | |
222 | char pr_ppid[4]; | |
223 | char pr_pgrp[4]; | |
224 | char pr_sid[4]; | |
225 | char pr_fname[16]; /* Filename of executable. */ | |
226 | char pr_psargs[80]; /* Initial part of arg list. */ | |
227 | }; | |
228 | ||
229 | /* Helper function to copy an elf_internal_linux_prpsinfo in host | |
230 | endian to an elf_external_linux_prpsinfo64_ugid16 in target endian. */ | |
231 | ||
232 | static inline void | |
233 | swap_linux_prpsinfo64_ugid16_out | |
234 | (bfd *obfd, | |
235 | const struct elf_internal_linux_prpsinfo *from, | |
236 | struct elf_external_linux_prpsinfo64_ugid16 *to) | |
237 | { | |
238 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
239 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
240 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
241 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
242 | bfd_put_64 (obfd, from->pr_flag, to->pr_flag); | |
243 | bfd_put_16 (obfd, from->pr_uid, to->pr_uid); | |
244 | bfd_put_16 (obfd, from->pr_gid, to->pr_gid); | |
245 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
246 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
247 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
248 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
249 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); | |
250 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
251 | } | |
252 | ||
d99b4b92 AM |
253 | #if GCC_VERSION >= 8000 |
254 | #pragma GCC diagnostic pop | |
255 | #endif | |
256 | ||
70a38d42 | 257 | #endif |