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 | |
a2f63b2e MR |
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. | |
27 | ||
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. | |
31 | ||
32 | This structure will ultimately be written in the corefile's note | |
33 | section, as the PRPSINFO. */ | |
34 | ||
35 | struct elf_external_linux_prpsinfo32_ugid32 | |
36 | { | |
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. */ | |
42 | char pr_uid[4]; | |
43 | char pr_gid[4]; | |
44 | char pr_pid[4]; | |
45 | char pr_ppid[4]; | |
46 | char pr_pgrp[4]; | |
47 | char pr_sid[4]; | |
48 | char pr_fname[16]; /* Filename of executable. */ | |
49 | char pr_psargs[80]; /* Initial part of arg list. */ | |
50 | }; | |
51 | ||
52 | /* Helper function to copy an elf_internal_linux_prpsinfo in host | |
53 | endian to an elf_external_linux_prpsinfo32_ugid32 in target endian. */ | |
54 | ||
55 | static inline void | |
56 | swap_linux_prpsinfo32_ugid32_out | |
57 | (bfd *obfd, | |
58 | const struct elf_internal_linux_prpsinfo *from, | |
59 | struct elf_external_linux_prpsinfo32_ugid32 *to) | |
60 | { | |
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); | |
5a6312e8 AM |
72 | #pragma GCC diagnostic push |
73 | #pragma GCC diagnostic ignored "-Wpragmas" | |
74 | #pragma GCC diagnostic ignored "-Wstringop-truncation" | |
a2f63b2e MR |
75 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); |
76 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
5a6312e8 | 77 | #pragma GCC diagnostic pop |
a2f63b2e | 78 | } |
70a38d42 SDJ |
79 | |
80 | /* External 32-bit structure for PRPSINFO. This structure is | |
81 | ABI-defined, thus we choose to use char arrays here in order to | |
82 | avoid dealing with different types in different architectures. | |
83 | ||
a2f63b2e MR |
84 | This is the variant for targets which use a 16-bit data type for |
85 | UID and GID, as some older Linux ports do. All modern ports use | |
86 | a 32-bit data type instead; see above for the alternative variant. | |
87 | ||
70a38d42 SDJ |
88 | This structure will ultimately be written in the corefile's note |
89 | section, as the PRPSINFO. */ | |
90 | ||
a2f63b2e | 91 | struct elf_external_linux_prpsinfo32_ugid16 |
70a38d42 SDJ |
92 | { |
93 | char pr_state; /* Numeric process state. */ | |
94 | char pr_sname; /* Char for pr_state. */ | |
95 | char pr_zomb; /* Zombie. */ | |
96 | char pr_nice; /* Nice val. */ | |
97 | char pr_flag[4]; /* Flags. */ | |
98 | char pr_uid[2]; | |
99 | char pr_gid[2]; | |
100 | char pr_pid[4]; | |
101 | char pr_ppid[4]; | |
102 | char pr_pgrp[4]; | |
103 | char pr_sid[4]; | |
104 | char pr_fname[16]; /* Filename of executable. */ | |
105 | char pr_psargs[80]; /* Initial part of arg list. */ | |
106 | }; | |
107 | ||
aeb70569 | 108 | /* Helper function to copy an elf_internal_linux_prpsinfo in host |
a2f63b2e | 109 | endian to an elf_external_linux_prpsinfo32_ugid16 in target endian. */ |
aeb70569 AM |
110 | |
111 | static inline void | |
a2f63b2e MR |
112 | swap_linux_prpsinfo32_ugid16_out |
113 | (bfd *obfd, | |
114 | const struct elf_internal_linux_prpsinfo *from, | |
115 | struct elf_external_linux_prpsinfo32_ugid16 *to) | |
aeb70569 AM |
116 | { |
117 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
118 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
119 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
120 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
121 | bfd_put_32 (obfd, from->pr_flag, to->pr_flag); | |
122 | bfd_put_16 (obfd, from->pr_uid, to->pr_uid); | |
123 | bfd_put_16 (obfd, from->pr_gid, to->pr_gid); | |
124 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
125 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
126 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
127 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
5a6312e8 AM |
128 | #pragma GCC diagnostic push |
129 | #pragma GCC diagnostic ignored "-Wpragmas" | |
130 | #pragma GCC diagnostic ignored "-Wstringop-truncation" | |
aeb70569 AM |
131 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); |
132 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
5a6312e8 | 133 | #pragma GCC diagnostic pop |
aeb70569 | 134 | } |
70a38d42 SDJ |
135 | |
136 | /* External 64-bit structure for PRPSINFO. This structure is | |
137 | ABI-defined, thus we choose to use char arrays here in order to | |
138 | avoid dealing with different types in different architectures. | |
139 | ||
3c9a7b0d MR |
140 | This is the variant for targets which use a 32-bit data type for |
141 | UID and GID, as most Linux ports do. The SH64 port uses a 16-bit | |
142 | data type instead; see below for the alternative variant. | |
143 | ||
70a38d42 SDJ |
144 | This structure will ultimately be written in the corefile's note |
145 | section, as the PRPSINFO. */ | |
146 | ||
3c9a7b0d | 147 | struct elf_external_linux_prpsinfo64_ugid32 |
70a38d42 SDJ |
148 | { |
149 | char pr_state; /* Numeric process state. */ | |
150 | char pr_sname; /* Char for pr_state. */ | |
151 | char pr_zomb; /* Zombie. */ | |
152 | char pr_nice; /* Nice val. */ | |
70a38d42 | 153 | char gap[4]; |
72bc1bb9 | 154 | char pr_flag[8]; /* Flags. */ |
70a38d42 SDJ |
155 | char pr_uid[4]; |
156 | char pr_gid[4]; | |
157 | char pr_pid[4]; | |
158 | char pr_ppid[4]; | |
159 | char pr_pgrp[4]; | |
160 | char pr_sid[4]; | |
161 | char pr_fname[16]; /* Filename of executable. */ | |
162 | char pr_psargs[80]; /* Initial part of arg list. */ | |
163 | }; | |
164 | ||
aeb70569 | 165 | /* Helper function to copy an elf_internal_linux_prpsinfo in host |
3c9a7b0d | 166 | endian to an elf_external_linux_prpsinfo64_ugid32 in target endian. */ |
aeb70569 AM |
167 | |
168 | static inline void | |
3c9a7b0d MR |
169 | swap_linux_prpsinfo64_ugid32_out |
170 | (bfd *obfd, | |
171 | const struct elf_internal_linux_prpsinfo *from, | |
172 | struct elf_external_linux_prpsinfo64_ugid32 *to) | |
aeb70569 AM |
173 | { |
174 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
175 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
176 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
177 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
178 | bfd_put_64 (obfd, from->pr_flag, to->pr_flag); | |
179 | bfd_put_32 (obfd, from->pr_uid, to->pr_uid); | |
180 | bfd_put_32 (obfd, from->pr_gid, to->pr_gid); | |
181 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
182 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
183 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
184 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
5a6312e8 AM |
185 | #pragma GCC diagnostic push |
186 | #pragma GCC diagnostic ignored "-Wpragmas" | |
187 | #pragma GCC diagnostic ignored "-Wstringop-truncation" | |
aeb70569 AM |
188 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); |
189 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
5a6312e8 | 190 | #pragma GCC diagnostic pop |
aeb70569 | 191 | } |
70a38d42 | 192 | |
3c9a7b0d MR |
193 | /* External 64-bit structure for PRPSINFO. This structure is |
194 | ABI-defined, thus we choose to use char arrays here in order to | |
195 | avoid dealing with different types in different architectures. | |
196 | ||
197 | This is the variant for the SH64 port which uses a 16-bit data | |
198 | type for UID and GID. Most Linux ports use a 32-bit data type | |
199 | instead; see above for the alternative variant. | |
200 | ||
201 | This structure will ultimately be written in the corefile's note | |
202 | section, as the PRPSINFO. */ | |
203 | ||
204 | struct elf_external_linux_prpsinfo64_ugid16 | |
205 | { | |
206 | char pr_state; /* Numeric process state. */ | |
207 | char pr_sname; /* Char for pr_state. */ | |
208 | char pr_zomb; /* Zombie. */ | |
209 | char pr_nice; /* Nice val. */ | |
210 | char gap[4]; | |
211 | char pr_flag[8]; /* Flags. */ | |
212 | char pr_uid[2]; | |
213 | char pr_gid[2]; | |
214 | char pr_pid[4]; | |
215 | char pr_ppid[4]; | |
216 | char pr_pgrp[4]; | |
217 | char pr_sid[4]; | |
218 | char pr_fname[16]; /* Filename of executable. */ | |
219 | char pr_psargs[80]; /* Initial part of arg list. */ | |
220 | }; | |
221 | ||
222 | /* Helper function to copy an elf_internal_linux_prpsinfo in host | |
223 | endian to an elf_external_linux_prpsinfo64_ugid16 in target endian. */ | |
224 | ||
225 | static inline void | |
226 | swap_linux_prpsinfo64_ugid16_out | |
227 | (bfd *obfd, | |
228 | const struct elf_internal_linux_prpsinfo *from, | |
229 | struct elf_external_linux_prpsinfo64_ugid16 *to) | |
230 | { | |
231 | bfd_put_8 (obfd, from->pr_state, &to->pr_state); | |
232 | bfd_put_8 (obfd, from->pr_sname, &to->pr_sname); | |
233 | bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb); | |
234 | bfd_put_8 (obfd, from->pr_nice, &to->pr_nice); | |
235 | bfd_put_64 (obfd, from->pr_flag, to->pr_flag); | |
236 | bfd_put_16 (obfd, from->pr_uid, to->pr_uid); | |
237 | bfd_put_16 (obfd, from->pr_gid, to->pr_gid); | |
238 | bfd_put_32 (obfd, from->pr_pid, to->pr_pid); | |
239 | bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid); | |
240 | bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp); | |
241 | bfd_put_32 (obfd, from->pr_sid, to->pr_sid); | |
5a6312e8 AM |
242 | #pragma GCC diagnostic push |
243 | #pragma GCC diagnostic ignored "-Wpragmas" | |
244 | #pragma GCC diagnostic ignored "-Wstringop-truncation" | |
3c9a7b0d MR |
245 | strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname)); |
246 | strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs)); | |
5a6312e8 | 247 | #pragma GCC diagnostic pop |
3c9a7b0d MR |
248 | } |
249 | ||
70a38d42 | 250 | #endif |