1 /* Definitions for PRPSINFO structures under ELF on GNU/Linux. 2 Copyright (C) 2013-2014 Free Software Foundation, Inc. 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 21 #ifndef ELF_LINUX_PSINFO_H 22 #define ELF_LINUX_PSINFO_H 23 24 /* The PRPSINFO structures defined below are used by most 25 architectures, although some of them define their own versions 26 (like e.g., PPC). */ 27 28 /* External 32-bit structure for PRPSINFO. This structure is 29 ABI-defined, thus we choose to use char arrays here in order to 30 avoid dealing with different types in different architectures. 31 32 This structure will ultimately be written in the corefile's note 33 section, as the PRPSINFO. */ 34 35 struct elf_external_linux_prpsinfo32 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[2]; 43 char pr_gid[2]; 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 macro to swap (properly handling endianess) things from the 53 `elf_internal_linux_prpsinfo' structure to the 54 `elf_external_linux_prpsinfo32' structure. 55 56 Note that FROM should be a pointer, and TO should be the explicit 57 type. */ 58 59 #define LINUX_PRPSINFO32_SWAP_FIELDS(abfd, from, to) \ 60 do \ 61 { \ 62 H_PUT_8 (abfd, from->pr_state, &to.pr_state); \ 63 H_PUT_8 (abfd, from->pr_sname, &to.pr_sname); \ 64 H_PUT_8 (abfd, from->pr_zomb, &to.pr_zomb); \ 65 H_PUT_8 (abfd, from->pr_nice, &to.pr_nice); \ 66 H_PUT_32 (abfd, from->pr_flag, to.pr_flag); \ 67 H_PUT_16 (abfd, from->pr_uid, to.pr_uid); \ 68 H_PUT_16 (abfd, from->pr_gid, to.pr_gid); \ 69 H_PUT_32 (abfd, from->pr_pid, to.pr_pid); \ 70 H_PUT_32 (abfd, from->pr_ppid, to.pr_ppid); \ 71 H_PUT_32 (abfd, from->pr_pgrp, to.pr_pgrp); \ 72 H_PUT_32 (abfd, from->pr_sid, to.pr_sid); \ 73 strncpy (to.pr_fname, from->pr_fname, sizeof (to.pr_fname)); \ 74 strncpy (to.pr_psargs, from->pr_psargs, sizeof (to.pr_psargs)); \ 75 } while (0) 76 77 /* External 64-bit structure for PRPSINFO. This structure is 78 ABI-defined, thus we choose to use char arrays here in order to 79 avoid dealing with different types in different architectures. 80 81 This structure will ultimately be written in the corefile's note 82 section, as the PRPSINFO. */ 83 84 struct elf_external_linux_prpsinfo64 85 { 86 char pr_state; /* Numeric process state. */ 87 char pr_sname; /* Char for pr_state. */ 88 char pr_zomb; /* Zombie. */ 89 char pr_nice; /* Nice val. */ 90 char pr_flag[8]; /* Flags. */ 91 char gap[4]; 92 char pr_uid[4]; 93 char pr_gid[4]; 94 char pr_pid[4]; 95 char pr_ppid[4]; 96 char pr_pgrp[4]; 97 char pr_sid[4]; 98 char pr_fname[16]; /* Filename of executable. */ 99 char pr_psargs[80]; /* Initial part of arg list. */ 100 }; 101 102 /* Helper macro to swap (properly handling endianess) things from the 103 `elf_internal_linux_prpsinfo' structure to the 104 `elf_external_linux_prpsinfo64' structure. 105 106 Note that FROM should be a pointer, and TO should be the explicit 107 type. */ 108 109 #define LINUX_PRPSINFO64_SWAP_FIELDS(abfd, from, to) \ 110 do \ 111 { \ 112 H_PUT_8 (abfd, from->pr_state, &to.pr_state); \ 113 H_PUT_8 (abfd, from->pr_sname, &to.pr_sname); \ 114 H_PUT_8 (abfd, from->pr_zomb, &to.pr_zomb); \ 115 H_PUT_8 (abfd, from->pr_nice, &to.pr_nice); \ 116 H_PUT_64 (abfd, from->pr_flag, to.pr_flag); \ 117 H_PUT_32 (abfd, from->pr_uid, to.pr_uid); \ 118 H_PUT_32 (abfd, from->pr_gid, to.pr_gid); \ 119 H_PUT_32 (abfd, from->pr_pid, to.pr_pid); \ 120 H_PUT_32 (abfd, from->pr_ppid, to.pr_ppid); \ 121 H_PUT_32 (abfd, from->pr_pgrp, to.pr_pgrp); \ 122 H_PUT_32 (abfd, from->pr_sid, to.pr_sid); \ 123 strncpy (to.pr_fname, from->pr_fname, sizeof (to.pr_fname)); \ 124 strncpy (to.pr_psargs, from->pr_psargs, sizeof (to.pr_psargs)); \ 125 } while (0) 126 127 #endif 128