1 /* Definitions for PRPSINFO structures under ELF on GNU/Linux.
2 Copyright (C) 2013-2017 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]; /* Filename of executable. */
49 char pr_psargs[80]; /* 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]; /* Filename of executable. */
101 char pr_psargs[80]; /* 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 structure will ultimately be written in the corefile's note
133 section, as the PRPSINFO. */
135 struct elf_external_linux_prpsinfo64
137 char pr_state; /* Numeric process state. */
138 char pr_sname; /* Char for pr_state. */
139 char pr_zomb; /* Zombie. */
140 char pr_nice; /* Nice val. */
142 char pr_flag[8]; /* Flags. */
149 char pr_fname[16]; /* Filename of executable. */
150 char pr_psargs[80]; /* Initial part of arg list. */
153 /* Helper function to copy an elf_internal_linux_prpsinfo in host
154 endian to an elf_external_linux_prpsinfo64 in target endian. */
157 swap_linux_prpsinfo64_out (bfd *obfd,
158 const struct elf_internal_linux_prpsinfo *from,
159 struct elf_external_linux_prpsinfo64 *to)
161 bfd_put_8 (obfd, from->pr_state, &to->pr_state);
162 bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
163 bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
164 bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
165 bfd_put_64 (obfd, from->pr_flag, to->pr_flag);
166 bfd_put_32 (obfd, from->pr_uid, to->pr_uid);
167 bfd_put_32 (obfd, from->pr_gid, to->pr_gid);
168 bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
169 bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
170 bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
171 bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
172 strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
173 strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));