ELF/BFD,GDB: Handle both variants of the 32-bit Linux core PRPSINFO note
[deliverable/binutils-gdb.git] / bfd / elf-linux-core.h
CommitLineData
70a38d42 1/* Definitions for PRPSINFO structures under ELF on GNU/Linux.
2571583a 2 Copyright (C) 2013-2017 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
35struct 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
55static inline void
56swap_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);
72 strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
73 strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
74}
70a38d42
SDJ
75
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.
79
a2f63b2e
MR
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.
83
70a38d42
SDJ
84 This structure will ultimately be written in the corefile's note
85 section, as the PRPSINFO. */
86
a2f63b2e 87struct elf_external_linux_prpsinfo32_ugid16
70a38d42
SDJ
88 {
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. */
94 char pr_uid[2];
95 char pr_gid[2];
96 char pr_pid[4];
97 char pr_ppid[4];
98 char pr_pgrp[4];
99 char pr_sid[4];
100 char pr_fname[16]; /* Filename of executable. */
101 char pr_psargs[80]; /* Initial part of arg list. */
102 };
103
aeb70569 104/* Helper function to copy an elf_internal_linux_prpsinfo in host
a2f63b2e 105 endian to an elf_external_linux_prpsinfo32_ugid16 in target endian. */
aeb70569
AM
106
107static inline void
a2f63b2e
MR
108swap_linux_prpsinfo32_ugid16_out
109 (bfd *obfd,
110 const struct elf_internal_linux_prpsinfo *from,
111 struct elf_external_linux_prpsinfo32_ugid16 *to)
aeb70569
AM
112{
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));
126}
70a38d42
SDJ
127
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.
131
132 This structure will ultimately be written in the corefile's note
133 section, as the PRPSINFO. */
134
135struct elf_external_linux_prpsinfo64
136 {
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. */
70a38d42 141 char gap[4];
72bc1bb9 142 char pr_flag[8]; /* Flags. */
70a38d42
SDJ
143 char pr_uid[4];
144 char pr_gid[4];
145 char pr_pid[4];
146 char pr_ppid[4];
147 char pr_pgrp[4];
148 char pr_sid[4];
149 char pr_fname[16]; /* Filename of executable. */
150 char pr_psargs[80]; /* Initial part of arg list. */
151 };
152
aeb70569
AM
153/* Helper function to copy an elf_internal_linux_prpsinfo in host
154 endian to an elf_external_linux_prpsinfo64 in target endian. */
155
156static inline void
157swap_linux_prpsinfo64_out (bfd *obfd,
158 const struct elf_internal_linux_prpsinfo *from,
159 struct elf_external_linux_prpsinfo64 *to)
160{
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));
174}
70a38d42
SDJ
175
176#endif
This page took 0.242767 seconds and 4 git commands to generate.