elfcore.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_ELFCORE_H
  3. #define _LINUX_ELFCORE_H
  4. #include <linux/user.h>
  5. #include <linux/bug.h>
  6. #include <linux/sched/task_stack.h>
  7. #include <linux/types.h>
  8. #include <linux/signal.h>
  9. #include <linux/time.h>
  10. #include <linux/ptrace.h>
  11. #include <linux/fs.h>
  12. #include <linux/elf.h>
  13. struct coredump_params;
  14. struct elf_siginfo
  15. {
  16. int si_signo; /* signal number */
  17. int si_code; /* extra code */
  18. int si_errno; /* errno */
  19. };
  20. /*
  21. * Definitions to generate Intel SVR4-like core files.
  22. * These mostly have the same names as the SVR4 types with "elf_"
  23. * tacked on the front to prevent clashes with linux definitions,
  24. * and the typedef forms have been avoided. This is mostly like
  25. * the SVR4 structure, but more Linuxy, with things that Linux does
  26. * not support and which gdb doesn't really use excluded.
  27. */
  28. struct elf_prstatus_common
  29. {
  30. struct elf_siginfo pr_info; /* Info associated with signal */
  31. short pr_cursig; /* Current signal */
  32. unsigned long pr_sigpend; /* Set of pending signals */
  33. unsigned long pr_sighold; /* Set of held signals */
  34. pid_t pr_pid;
  35. pid_t pr_ppid;
  36. pid_t pr_pgrp;
  37. pid_t pr_sid;
  38. struct __kernel_old_timeval pr_utime; /* User time */
  39. struct __kernel_old_timeval pr_stime; /* System time */
  40. struct __kernel_old_timeval pr_cutime; /* Cumulative user time */
  41. struct __kernel_old_timeval pr_cstime; /* Cumulative system time */
  42. };
  43. struct elf_prstatus
  44. {
  45. struct elf_prstatus_common common;
  46. elf_gregset_t pr_reg; /* GP registers */
  47. int pr_fpvalid; /* True if math co-processor being used. */
  48. };
  49. #define ELF_PRARGSZ (80) /* Number of chars for args */
  50. struct elf_prpsinfo
  51. {
  52. char pr_state; /* numeric process state */
  53. char pr_sname; /* char for pr_state */
  54. char pr_zomb; /* zombie */
  55. char pr_nice; /* nice val */
  56. unsigned long pr_flag; /* flags */
  57. __kernel_uid_t pr_uid;
  58. __kernel_gid_t pr_gid;
  59. pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
  60. /* Lots missing */
  61. /*
  62. * The hard-coded 16 is derived from TASK_COMM_LEN, but it can't be
  63. * changed as it is exposed to userspace. We'd better make it hard-coded
  64. * here.
  65. */
  66. char pr_fname[16]; /* filename of executable */
  67. char pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
  68. };
  69. static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
  70. {
  71. #ifdef ELF_CORE_COPY_REGS
  72. ELF_CORE_COPY_REGS((*elfregs), regs)
  73. #else
  74. BUG_ON(sizeof(*elfregs) != sizeof(*regs));
  75. *(struct pt_regs *)elfregs = *regs;
  76. #endif
  77. }
  78. static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
  79. {
  80. #if defined (ELF_CORE_COPY_TASK_REGS)
  81. return ELF_CORE_COPY_TASK_REGS(t, elfregs);
  82. #elif defined (task_pt_regs)
  83. elf_core_copy_regs(elfregs, task_pt_regs(t));
  84. #endif
  85. return 0;
  86. }
  87. extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
  88. static inline int elf_core_copy_task_fpregs(struct task_struct *t, struct pt_regs *regs, elf_fpregset_t *fpu)
  89. {
  90. #ifdef ELF_CORE_COPY_FPREGS
  91. return ELF_CORE_COPY_FPREGS(t, fpu);
  92. #else
  93. return dump_fpu(regs, fpu);
  94. #endif
  95. }
  96. #ifdef CONFIG_ARCH_BINFMT_ELF_EXTRA_PHDRS
  97. /*
  98. * These functions parameterize elf_core_dump in fs/binfmt_elf.c to write out
  99. * extra segments containing the gate DSO contents. Dumping its
  100. * contents makes post-mortem fully interpretable later without matching up
  101. * the same kernel and hardware config to see what PC values meant.
  102. * Dumping its extra ELF program headers includes all the other information
  103. * a debugger needs to easily find how the gate DSO was being used.
  104. */
  105. extern Elf_Half elf_core_extra_phdrs(struct coredump_params *cprm);
  106. extern int
  107. elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset);
  108. extern int
  109. elf_core_write_extra_data(struct coredump_params *cprm);
  110. extern size_t elf_core_extra_data_size(struct coredump_params *cprm);
  111. #else
  112. static inline Elf_Half elf_core_extra_phdrs(struct coredump_params *cprm)
  113. {
  114. return 0;
  115. }
  116. static inline int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
  117. {
  118. return 1;
  119. }
  120. static inline int elf_core_write_extra_data(struct coredump_params *cprm)
  121. {
  122. return 1;
  123. }
  124. static inline size_t elf_core_extra_data_size(struct coredump_params *cprm)
  125. {
  126. return 0;
  127. }
  128. #endif /* CONFIG_ARCH_BINFMT_ELF_EXTRA_PHDRS */
  129. #endif /* _LINUX_ELFCORE_H */