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