1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_ELFCORE_H
3 #define _LINUX_ELFCORE_H
4 
5 #include <linux/user.h>
6 #include <linux/bug.h>
7 #include <linux/sched/task_stack.h>
8 
9 #include <asm/elf.h>
10 #include <uapi/linux/elfcore.h>
11 
12 struct coredump_params;
13 
elf_core_copy_regs(elf_gregset_t * elfregs,struct pt_regs * regs)14 static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
15 {
16 #ifdef ELF_CORE_COPY_REGS
17 	ELF_CORE_COPY_REGS((*elfregs), regs)
18 #else
19 	BUG_ON(sizeof(*elfregs) != sizeof(*regs));
20 	*(struct pt_regs *)elfregs = *regs;
21 #endif
22 }
23 
elf_core_copy_kernel_regs(elf_gregset_t * elfregs,struct pt_regs * regs)24 static inline void elf_core_copy_kernel_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
25 {
26 #ifdef ELF_CORE_COPY_KERNEL_REGS
27 	ELF_CORE_COPY_KERNEL_REGS((*elfregs), regs);
28 #else
29 	elf_core_copy_regs(elfregs, regs);
30 #endif
31 }
32 
elf_core_copy_task_regs(struct task_struct * t,elf_gregset_t * elfregs)33 static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
34 {
35 #if defined (ELF_CORE_COPY_TASK_REGS)
36 	return ELF_CORE_COPY_TASK_REGS(t, elfregs);
37 #elif defined (task_pt_regs)
38 	elf_core_copy_regs(elfregs, task_pt_regs(t));
39 #endif
40 	return 0;
41 }
42 
43 extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
44 
elf_core_copy_task_fpregs(struct task_struct * t,struct pt_regs * regs,elf_fpregset_t * fpu)45 static inline int elf_core_copy_task_fpregs(struct task_struct *t, struct pt_regs *regs, elf_fpregset_t *fpu)
46 {
47 #ifdef ELF_CORE_COPY_FPREGS
48 	return ELF_CORE_COPY_FPREGS(t, fpu);
49 #else
50 	return dump_fpu(regs, fpu);
51 #endif
52 }
53 
54 #ifdef ELF_CORE_COPY_XFPREGS
elf_core_copy_task_xfpregs(struct task_struct * t,elf_fpxregset_t * xfpu)55 static inline int elf_core_copy_task_xfpregs(struct task_struct *t, elf_fpxregset_t *xfpu)
56 {
57 	return ELF_CORE_COPY_XFPREGS(t, xfpu);
58 }
59 #endif
60 
61 #if (defined(CONFIG_UML) && defined(CONFIG_X86_32)) || defined(CONFIG_IA64)
62 /*
63  * These functions parameterize elf_core_dump in fs/binfmt_elf.c to write out
64  * extra segments containing the gate DSO contents.  Dumping its
65  * contents makes post-mortem fully interpretable later without matching up
66  * the same kernel and hardware config to see what PC values meant.
67  * Dumping its extra ELF program headers includes all the other information
68  * a debugger needs to easily find how the gate DSO was being used.
69  */
70 extern Elf_Half elf_core_extra_phdrs(void);
71 extern int
72 elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset);
73 extern int
74 elf_core_write_extra_data(struct coredump_params *cprm);
75 extern size_t elf_core_extra_data_size(void);
76 #else
elf_core_extra_phdrs(void)77 static inline Elf_Half elf_core_extra_phdrs(void)
78 {
79 	return 0;
80 }
81 
elf_core_write_extra_phdrs(struct coredump_params * cprm,loff_t offset)82 static inline int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
83 {
84 	return 1;
85 }
86 
elf_core_write_extra_data(struct coredump_params * cprm)87 static inline int elf_core_write_extra_data(struct coredump_params *cprm)
88 {
89 	return 1;
90 }
91 
elf_core_extra_data_size(void)92 static inline size_t elf_core_extra_data_size(void)
93 {
94 	return 0;
95 }
96 #endif
97 
98 #endif /* _LINUX_ELFCORE_H */
99