blob: 4cad0e784b286b62aa4dc5fc5ad07b07964e0d57 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_ELFCORE_H
3#define _LINUX_ELFCORE_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/user.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -05006#include <linux/bug.h>
Ingo Molnar68db0cf2017-02-08 18:51:37 +01007#include <linux/sched/task_stack.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <asm/elf.h>
David Howells607ca462012-10-13 10:46:48 +010010#include <uapi/linux/elfcore.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Al Viro506f21c2013-10-05 17:22:57 -040012struct coredump_params;
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014static 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
Tejun Heo6cd61c02009-02-09 22:17:39 +090024static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
34{
Parag Warudkare9bf0cc2009-07-08 11:46:02 -040035#if defined (ELF_CORE_COPY_TASK_REGS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 return ELF_CORE_COPY_TASK_REGS(t, elfregs);
Parag Warudkare9bf0cc2009-07-08 11:46:02 -040037#elif defined (task_pt_regs)
Hui Zhua65e7bf2009-07-05 12:08:15 -070038 elf_core_copy_regs(elfregs, task_pt_regs(t));
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#endif
40 return 0;
41}
42
43extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
44
45static 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
55static 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
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080061/*
62 * These functions parameterize elf_core_dump in fs/binfmt_elf.c to write out
63 * extra segments containing the gate DSO contents. Dumping its
64 * contents makes post-mortem fully interpretable later without matching up
65 * the same kernel and hardware config to see what PC values meant.
66 * Dumping its extra ELF program headers includes all the other information
67 * a debugger needs to easily find how the gate DSO was being used.
68 */
69extern Elf_Half elf_core_extra_phdrs(void);
70extern int
Al Viro506f21c2013-10-05 17:22:57 -040071elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset);
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080072extern int
Al Viroaa3e7ea2013-10-05 17:50:15 -040073elf_core_write_extra_data(struct coredump_params *cprm);
Daisuke HATAYAMA8d9032b2010-03-05 13:44:10 -080074extern size_t elf_core_extra_data_size(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#endif /* _LINUX_ELFCORE_H */