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