xref: /dflybsd-src/contrib/binutils-2.34/bfd/elf-linux-core.h (revision b52ef7118d1621abed722c5bbbd542210290ecef)
1*fae548d3Szrj /* Definitions for PRPSINFO structures under ELF on GNU/Linux.
2*fae548d3Szrj    Copyright (C) 2013-2020 Free Software Foundation, Inc.
3*fae548d3Szrj 
4*fae548d3Szrj    This file is part of BFD, the Binary File Descriptor library.
5*fae548d3Szrj 
6*fae548d3Szrj    This program is free software; you can redistribute it and/or modify
7*fae548d3Szrj    it under the terms of the GNU General Public License as published by
8*fae548d3Szrj    the Free Software Foundation; either version 3 of the License, or
9*fae548d3Szrj    (at your option) any later version.
10*fae548d3Szrj 
11*fae548d3Szrj    This program is distributed in the hope that it will be useful,
12*fae548d3Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*fae548d3Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*fae548d3Szrj    GNU General Public License for more details.
15*fae548d3Szrj 
16*fae548d3Szrj    You should have received a copy of the GNU General Public License
17*fae548d3Szrj    along with this program; if not, write to the Free Software
18*fae548d3Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19*fae548d3Szrj    MA 02110-1301, USA.  */
20*fae548d3Szrj 
21*fae548d3Szrj #ifndef ELF_LINUX_CORE_H
22*fae548d3Szrj #define ELF_LINUX_CORE_H
23*fae548d3Szrj 
24*fae548d3Szrj /* External 32-bit structure for PRPSINFO.  This structure is
25*fae548d3Szrj    ABI-defined, thus we choose to use char arrays here in order to
26*fae548d3Szrj    avoid dealing with different types in different architectures.
27*fae548d3Szrj 
28*fae548d3Szrj    This is the variant for targets which use a 32-bit data type for
29*fae548d3Szrj    UID and GID, as all modern Linux ports do.  Some older ports use
30*fae548d3Szrj    a 16-bit data type instead; see below for the alternative variant.
31*fae548d3Szrj 
32*fae548d3Szrj    This structure will ultimately be written in the corefile's note
33*fae548d3Szrj    section, as the PRPSINFO.  */
34*fae548d3Szrj 
35*fae548d3Szrj struct elf_external_linux_prpsinfo32_ugid32
36*fae548d3Szrj   {
37*fae548d3Szrj     char pr_state;			/* Numeric process state.  */
38*fae548d3Szrj     char pr_sname;			/* Char for pr_state.  */
39*fae548d3Szrj     char pr_zomb;			/* Zombie.  */
40*fae548d3Szrj     char pr_nice;			/* Nice val.  */
41*fae548d3Szrj     char pr_flag[4];			/* Flags.  */
42*fae548d3Szrj     char pr_uid[4];
43*fae548d3Szrj     char pr_gid[4];
44*fae548d3Szrj     char pr_pid[4];
45*fae548d3Szrj     char pr_ppid[4];
46*fae548d3Szrj     char pr_pgrp[4];
47*fae548d3Szrj     char pr_sid[4];
48*fae548d3Szrj     char pr_fname[16] ATTRIBUTE_NONSTRING;  /* Filename of executable.  */
49*fae548d3Szrj     char pr_psargs[80] ATTRIBUTE_NONSTRING; /* Initial part of arg list.  */
50*fae548d3Szrj   };
51*fae548d3Szrj 
52*fae548d3Szrj /* Helper function to copy an elf_internal_linux_prpsinfo in host
53*fae548d3Szrj    endian to an elf_external_linux_prpsinfo32_ugid32 in target endian.  */
54*fae548d3Szrj 
55*fae548d3Szrj static inline void
swap_linux_prpsinfo32_ugid32_out(bfd * obfd,const struct elf_internal_linux_prpsinfo * from,struct elf_external_linux_prpsinfo32_ugid32 * to)56*fae548d3Szrj swap_linux_prpsinfo32_ugid32_out
57*fae548d3Szrj   (bfd *obfd,
58*fae548d3Szrj    const struct elf_internal_linux_prpsinfo *from,
59*fae548d3Szrj    struct elf_external_linux_prpsinfo32_ugid32 *to)
60*fae548d3Szrj {
61*fae548d3Szrj   bfd_put_8 (obfd, from->pr_state, &to->pr_state);
62*fae548d3Szrj   bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
63*fae548d3Szrj   bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
64*fae548d3Szrj   bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
65*fae548d3Szrj   bfd_put_32 (obfd, from->pr_flag, to->pr_flag);
66*fae548d3Szrj   bfd_put_32 (obfd, from->pr_uid, to->pr_uid);
67*fae548d3Szrj   bfd_put_32 (obfd, from->pr_gid, to->pr_gid);
68*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
69*fae548d3Szrj   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
70*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
71*fae548d3Szrj   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
72*fae548d3Szrj   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
73*fae548d3Szrj   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
74*fae548d3Szrj }
75*fae548d3Szrj 
76*fae548d3Szrj /* External 32-bit structure for PRPSINFO.  This structure is
77*fae548d3Szrj    ABI-defined, thus we choose to use char arrays here in order to
78*fae548d3Szrj    avoid dealing with different types in different architectures.
79*fae548d3Szrj 
80*fae548d3Szrj    This is the variant for targets which use a 16-bit data type for
81*fae548d3Szrj    UID and GID, as some older Linux ports do.  All modern ports use
82*fae548d3Szrj    a 32-bit data type instead; see above for the alternative variant.
83*fae548d3Szrj 
84*fae548d3Szrj    This structure will ultimately be written in the corefile's note
85*fae548d3Szrj    section, as the PRPSINFO.  */
86*fae548d3Szrj 
87*fae548d3Szrj struct elf_external_linux_prpsinfo32_ugid16
88*fae548d3Szrj   {
89*fae548d3Szrj     char pr_state;			/* Numeric process state.  */
90*fae548d3Szrj     char pr_sname;			/* Char for pr_state.  */
91*fae548d3Szrj     char pr_zomb;			/* Zombie.  */
92*fae548d3Szrj     char pr_nice;			/* Nice val.  */
93*fae548d3Szrj     char pr_flag[4];			/* Flags.  */
94*fae548d3Szrj     char pr_uid[2];
95*fae548d3Szrj     char pr_gid[2];
96*fae548d3Szrj     char pr_pid[4];
97*fae548d3Szrj     char pr_ppid[4];
98*fae548d3Szrj     char pr_pgrp[4];
99*fae548d3Szrj     char pr_sid[4];
100*fae548d3Szrj     char pr_fname[16] ATTRIBUTE_NONSTRING;  /* Filename of executable.  */
101*fae548d3Szrj     char pr_psargs[80] ATTRIBUTE_NONSTRING; /* Initial part of arg list.  */
102*fae548d3Szrj   };
103*fae548d3Szrj 
104*fae548d3Szrj /* Helper function to copy an elf_internal_linux_prpsinfo in host
105*fae548d3Szrj    endian to an elf_external_linux_prpsinfo32_ugid16 in target endian.  */
106*fae548d3Szrj 
107*fae548d3Szrj static inline void
swap_linux_prpsinfo32_ugid16_out(bfd * obfd,const struct elf_internal_linux_prpsinfo * from,struct elf_external_linux_prpsinfo32_ugid16 * to)108*fae548d3Szrj swap_linux_prpsinfo32_ugid16_out
109*fae548d3Szrj   (bfd *obfd,
110*fae548d3Szrj    const struct elf_internal_linux_prpsinfo *from,
111*fae548d3Szrj    struct elf_external_linux_prpsinfo32_ugid16 *to)
112*fae548d3Szrj {
113*fae548d3Szrj   bfd_put_8 (obfd, from->pr_state, &to->pr_state);
114*fae548d3Szrj   bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
115*fae548d3Szrj   bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
116*fae548d3Szrj   bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
117*fae548d3Szrj   bfd_put_32 (obfd, from->pr_flag, to->pr_flag);
118*fae548d3Szrj   bfd_put_16 (obfd, from->pr_uid, to->pr_uid);
119*fae548d3Szrj   bfd_put_16 (obfd, from->pr_gid, to->pr_gid);
120*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
121*fae548d3Szrj   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
122*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
123*fae548d3Szrj   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
124*fae548d3Szrj   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
125*fae548d3Szrj   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
126*fae548d3Szrj }
127*fae548d3Szrj 
128*fae548d3Szrj /* External 64-bit structure for PRPSINFO.  This structure is
129*fae548d3Szrj    ABI-defined, thus we choose to use char arrays here in order to
130*fae548d3Szrj    avoid dealing with different types in different architectures.
131*fae548d3Szrj 
132*fae548d3Szrj    This is the variant for targets which use a 32-bit data type for
133*fae548d3Szrj    UID and GID, as most Linux ports do.  The SH64 port uses a 16-bit
134*fae548d3Szrj    data type instead; see below for the alternative variant.
135*fae548d3Szrj 
136*fae548d3Szrj    This structure will ultimately be written in the corefile's note
137*fae548d3Szrj    section, as the PRPSINFO.  */
138*fae548d3Szrj 
139*fae548d3Szrj struct elf_external_linux_prpsinfo64_ugid32
140*fae548d3Szrj   {
141*fae548d3Szrj     char pr_state;			/* Numeric process state.  */
142*fae548d3Szrj     char pr_sname;			/* Char for pr_state.  */
143*fae548d3Szrj     char pr_zomb;			/* Zombie.  */
144*fae548d3Szrj     char pr_nice;			/* Nice val.  */
145*fae548d3Szrj     char gap[4];
146*fae548d3Szrj     char pr_flag[8];			/* Flags.  */
147*fae548d3Szrj     char pr_uid[4];
148*fae548d3Szrj     char pr_gid[4];
149*fae548d3Szrj     char pr_pid[4];
150*fae548d3Szrj     char pr_ppid[4];
151*fae548d3Szrj     char pr_pgrp[4];
152*fae548d3Szrj     char pr_sid[4];
153*fae548d3Szrj     char pr_fname[16] ATTRIBUTE_NONSTRING;  /* Filename of executable.  */
154*fae548d3Szrj     char pr_psargs[80] ATTRIBUTE_NONSTRING; /* Initial part of arg list.  */
155*fae548d3Szrj   };
156*fae548d3Szrj 
157*fae548d3Szrj /* Helper function to copy an elf_internal_linux_prpsinfo in host
158*fae548d3Szrj    endian to an elf_external_linux_prpsinfo64_ugid32 in target endian.  */
159*fae548d3Szrj 
160*fae548d3Szrj static inline void
swap_linux_prpsinfo64_ugid32_out(bfd * obfd,const struct elf_internal_linux_prpsinfo * from,struct elf_external_linux_prpsinfo64_ugid32 * to)161*fae548d3Szrj swap_linux_prpsinfo64_ugid32_out
162*fae548d3Szrj   (bfd *obfd,
163*fae548d3Szrj    const struct elf_internal_linux_prpsinfo *from,
164*fae548d3Szrj    struct elf_external_linux_prpsinfo64_ugid32 *to)
165*fae548d3Szrj {
166*fae548d3Szrj   bfd_put_8 (obfd, from->pr_state, &to->pr_state);
167*fae548d3Szrj   bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
168*fae548d3Szrj   bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
169*fae548d3Szrj   bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
170*fae548d3Szrj   bfd_put_64 (obfd, from->pr_flag, to->pr_flag);
171*fae548d3Szrj   bfd_put_32 (obfd, from->pr_uid, to->pr_uid);
172*fae548d3Szrj   bfd_put_32 (obfd, from->pr_gid, to->pr_gid);
173*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
174*fae548d3Szrj   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
175*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
176*fae548d3Szrj   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
177*fae548d3Szrj   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
178*fae548d3Szrj   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
179*fae548d3Szrj }
180*fae548d3Szrj 
181*fae548d3Szrj /* External 64-bit structure for PRPSINFO.  This structure is
182*fae548d3Szrj    ABI-defined, thus we choose to use char arrays here in order to
183*fae548d3Szrj    avoid dealing with different types in different architectures.
184*fae548d3Szrj 
185*fae548d3Szrj    This is the variant for the SH64 port which uses a 16-bit data
186*fae548d3Szrj    type for UID and GID.  Most Linux ports use a 32-bit data type
187*fae548d3Szrj    instead; see above for the alternative variant.
188*fae548d3Szrj 
189*fae548d3Szrj    This structure will ultimately be written in the corefile's note
190*fae548d3Szrj    section, as the PRPSINFO.  */
191*fae548d3Szrj 
192*fae548d3Szrj struct elf_external_linux_prpsinfo64_ugid16
193*fae548d3Szrj   {
194*fae548d3Szrj     char pr_state;			/* Numeric process state.  */
195*fae548d3Szrj     char pr_sname;			/* Char for pr_state.  */
196*fae548d3Szrj     char pr_zomb;			/* Zombie.  */
197*fae548d3Szrj     char pr_nice;			/* Nice val.  */
198*fae548d3Szrj     char gap[4];
199*fae548d3Szrj     char pr_flag[8];			/* Flags.  */
200*fae548d3Szrj     char pr_uid[2];
201*fae548d3Szrj     char pr_gid[2];
202*fae548d3Szrj     char pr_pid[4];
203*fae548d3Szrj     char pr_ppid[4];
204*fae548d3Szrj     char pr_pgrp[4];
205*fae548d3Szrj     char pr_sid[4];
206*fae548d3Szrj     char pr_fname[16] ATTRIBUTE_NONSTRING;  /* Filename of executable.  */
207*fae548d3Szrj     char pr_psargs[80] ATTRIBUTE_NONSTRING; /* Initial part of arg list.  */
208*fae548d3Szrj   };
209*fae548d3Szrj 
210*fae548d3Szrj /* Helper function to copy an elf_internal_linux_prpsinfo in host
211*fae548d3Szrj    endian to an elf_external_linux_prpsinfo64_ugid16 in target endian.  */
212*fae548d3Szrj 
213*fae548d3Szrj static inline void
swap_linux_prpsinfo64_ugid16_out(bfd * obfd,const struct elf_internal_linux_prpsinfo * from,struct elf_external_linux_prpsinfo64_ugid16 * to)214*fae548d3Szrj swap_linux_prpsinfo64_ugid16_out
215*fae548d3Szrj   (bfd *obfd,
216*fae548d3Szrj    const struct elf_internal_linux_prpsinfo *from,
217*fae548d3Szrj    struct elf_external_linux_prpsinfo64_ugid16 *to)
218*fae548d3Szrj {
219*fae548d3Szrj   bfd_put_8 (obfd, from->pr_state, &to->pr_state);
220*fae548d3Szrj   bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
221*fae548d3Szrj   bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
222*fae548d3Szrj   bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
223*fae548d3Szrj   bfd_put_64 (obfd, from->pr_flag, to->pr_flag);
224*fae548d3Szrj   bfd_put_16 (obfd, from->pr_uid, to->pr_uid);
225*fae548d3Szrj   bfd_put_16 (obfd, from->pr_gid, to->pr_gid);
226*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
227*fae548d3Szrj   bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
228*fae548d3Szrj   bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
229*fae548d3Szrj   bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
230*fae548d3Szrj   strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
231*fae548d3Szrj   strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
232*fae548d3Szrj }
233*fae548d3Szrj 
234*fae548d3Szrj #endif
235