1*a9fa9459Szrj /* Definitions for PRPSINFO structures under ELF on GNU/Linux.
2*a9fa9459Szrj Copyright (C) 2013-2016 Free Software Foundation, Inc.
3*a9fa9459Szrj
4*a9fa9459Szrj This file is part of BFD, the Binary File Descriptor library.
5*a9fa9459Szrj
6*a9fa9459Szrj This program is free software; you can redistribute it and/or modify
7*a9fa9459Szrj it under the terms of the GNU General Public License as published by
8*a9fa9459Szrj the Free Software Foundation; either version 3 of the License, or
9*a9fa9459Szrj (at your option) any later version.
10*a9fa9459Szrj
11*a9fa9459Szrj This program is distributed in the hope that it will be useful,
12*a9fa9459Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
13*a9fa9459Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*a9fa9459Szrj GNU General Public License for more details.
15*a9fa9459Szrj
16*a9fa9459Szrj You should have received a copy of the GNU General Public License
17*a9fa9459Szrj along with this program; if not, write to the Free Software
18*a9fa9459Szrj Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19*a9fa9459Szrj MA 02110-1301, USA. */
20*a9fa9459Szrj
21*a9fa9459Szrj #ifndef ELF_LINUX_CORE_H
22*a9fa9459Szrj #define ELF_LINUX_CORE_H
23*a9fa9459Szrj
24*a9fa9459Szrj /* The PRPSINFO structures defined below are used by most
25*a9fa9459Szrj architectures, although some of them define their own versions
26*a9fa9459Szrj (like e.g., PPC). */
27*a9fa9459Szrj
28*a9fa9459Szrj /* External 32-bit structure for PRPSINFO. This structure is
29*a9fa9459Szrj ABI-defined, thus we choose to use char arrays here in order to
30*a9fa9459Szrj avoid dealing with different types in different architectures.
31*a9fa9459Szrj
32*a9fa9459Szrj This structure will ultimately be written in the corefile's note
33*a9fa9459Szrj section, as the PRPSINFO. */
34*a9fa9459Szrj
35*a9fa9459Szrj struct elf_external_linux_prpsinfo32
36*a9fa9459Szrj {
37*a9fa9459Szrj char pr_state; /* Numeric process state. */
38*a9fa9459Szrj char pr_sname; /* Char for pr_state. */
39*a9fa9459Szrj char pr_zomb; /* Zombie. */
40*a9fa9459Szrj char pr_nice; /* Nice val. */
41*a9fa9459Szrj char pr_flag[4]; /* Flags. */
42*a9fa9459Szrj char pr_uid[2];
43*a9fa9459Szrj char pr_gid[2];
44*a9fa9459Szrj char pr_pid[4];
45*a9fa9459Szrj char pr_ppid[4];
46*a9fa9459Szrj char pr_pgrp[4];
47*a9fa9459Szrj char pr_sid[4];
48*a9fa9459Szrj char pr_fname[16]; /* Filename of executable. */
49*a9fa9459Szrj char pr_psargs[80]; /* Initial part of arg list. */
50*a9fa9459Szrj };
51*a9fa9459Szrj
52*a9fa9459Szrj /* Helper function to copy an elf_internal_linux_prpsinfo in host
53*a9fa9459Szrj endian to an elf_external_linux_prpsinfo32 in target endian. */
54*a9fa9459Szrj
55*a9fa9459Szrj static inline void
swap_linux_prpsinfo32_out(bfd * obfd,const struct elf_internal_linux_prpsinfo * from,struct elf_external_linux_prpsinfo32 * to)56*a9fa9459Szrj swap_linux_prpsinfo32_out (bfd *obfd,
57*a9fa9459Szrj const struct elf_internal_linux_prpsinfo *from,
58*a9fa9459Szrj struct elf_external_linux_prpsinfo32 *to)
59*a9fa9459Szrj {
60*a9fa9459Szrj bfd_put_8 (obfd, from->pr_state, &to->pr_state);
61*a9fa9459Szrj bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
62*a9fa9459Szrj bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
63*a9fa9459Szrj bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
64*a9fa9459Szrj bfd_put_32 (obfd, from->pr_flag, to->pr_flag);
65*a9fa9459Szrj bfd_put_16 (obfd, from->pr_uid, to->pr_uid);
66*a9fa9459Szrj bfd_put_16 (obfd, from->pr_gid, to->pr_gid);
67*a9fa9459Szrj bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
68*a9fa9459Szrj bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
69*a9fa9459Szrj bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
70*a9fa9459Szrj bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
71*a9fa9459Szrj strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
72*a9fa9459Szrj strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
73*a9fa9459Szrj }
74*a9fa9459Szrj
75*a9fa9459Szrj /* External 64-bit structure for PRPSINFO. This structure is
76*a9fa9459Szrj ABI-defined, thus we choose to use char arrays here in order to
77*a9fa9459Szrj avoid dealing with different types in different architectures.
78*a9fa9459Szrj
79*a9fa9459Szrj This structure will ultimately be written in the corefile's note
80*a9fa9459Szrj section, as the PRPSINFO. */
81*a9fa9459Szrj
82*a9fa9459Szrj struct elf_external_linux_prpsinfo64
83*a9fa9459Szrj {
84*a9fa9459Szrj char pr_state; /* Numeric process state. */
85*a9fa9459Szrj char pr_sname; /* Char for pr_state. */
86*a9fa9459Szrj char pr_zomb; /* Zombie. */
87*a9fa9459Szrj char pr_nice; /* Nice val. */
88*a9fa9459Szrj char pr_flag[8]; /* Flags. */
89*a9fa9459Szrj char gap[4];
90*a9fa9459Szrj char pr_uid[4];
91*a9fa9459Szrj char pr_gid[4];
92*a9fa9459Szrj char pr_pid[4];
93*a9fa9459Szrj char pr_ppid[4];
94*a9fa9459Szrj char pr_pgrp[4];
95*a9fa9459Szrj char pr_sid[4];
96*a9fa9459Szrj char pr_fname[16]; /* Filename of executable. */
97*a9fa9459Szrj char pr_psargs[80]; /* Initial part of arg list. */
98*a9fa9459Szrj };
99*a9fa9459Szrj
100*a9fa9459Szrj /* Helper function to copy an elf_internal_linux_prpsinfo in host
101*a9fa9459Szrj endian to an elf_external_linux_prpsinfo64 in target endian. */
102*a9fa9459Szrj
103*a9fa9459Szrj static inline void
swap_linux_prpsinfo64_out(bfd * obfd,const struct elf_internal_linux_prpsinfo * from,struct elf_external_linux_prpsinfo64 * to)104*a9fa9459Szrj swap_linux_prpsinfo64_out (bfd *obfd,
105*a9fa9459Szrj const struct elf_internal_linux_prpsinfo *from,
106*a9fa9459Szrj struct elf_external_linux_prpsinfo64 *to)
107*a9fa9459Szrj {
108*a9fa9459Szrj bfd_put_8 (obfd, from->pr_state, &to->pr_state);
109*a9fa9459Szrj bfd_put_8 (obfd, from->pr_sname, &to->pr_sname);
110*a9fa9459Szrj bfd_put_8 (obfd, from->pr_zomb, &to->pr_zomb);
111*a9fa9459Szrj bfd_put_8 (obfd, from->pr_nice, &to->pr_nice);
112*a9fa9459Szrj bfd_put_64 (obfd, from->pr_flag, to->pr_flag);
113*a9fa9459Szrj bfd_put_32 (obfd, from->pr_uid, to->pr_uid);
114*a9fa9459Szrj bfd_put_32 (obfd, from->pr_gid, to->pr_gid);
115*a9fa9459Szrj bfd_put_32 (obfd, from->pr_pid, to->pr_pid);
116*a9fa9459Szrj bfd_put_32 (obfd, from->pr_ppid, to->pr_ppid);
117*a9fa9459Szrj bfd_put_32 (obfd, from->pr_pgrp, to->pr_pgrp);
118*a9fa9459Szrj bfd_put_32 (obfd, from->pr_sid, to->pr_sid);
119*a9fa9459Szrj strncpy (to->pr_fname, from->pr_fname, sizeof (to->pr_fname));
120*a9fa9459Szrj strncpy (to->pr_psargs, from->pr_psargs, sizeof (to->pr_psargs));
121*a9fa9459Szrj }
122*a9fa9459Szrj
123*a9fa9459Szrj #endif
124