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