elf-linux-psinfo.h 4.8 KB

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