Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_ELFCORE_H
0003 #define _LINUX_ELFCORE_H
0004 
0005 #include <linux/user.h>
0006 #include <linux/bug.h>
0007 #include <linux/sched/task_stack.h>
0008 #include <linux/types.h>
0009 #include <linux/signal.h>
0010 #include <linux/time.h>
0011 #include <linux/ptrace.h>
0012 #include <linux/fs.h>
0013 #include <linux/elf.h>
0014 
0015 struct coredump_params;
0016 
0017 struct elf_siginfo
0018 {
0019     int si_signo;           /* signal number */
0020     int si_code;            /* extra code */
0021     int si_errno;           /* errno */
0022 };
0023 
0024 /*
0025  * Definitions to generate Intel SVR4-like core files.
0026  * These mostly have the same names as the SVR4 types with "elf_"
0027  * tacked on the front to prevent clashes with linux definitions,
0028  * and the typedef forms have been avoided.  This is mostly like
0029  * the SVR4 structure, but more Linuxy, with things that Linux does
0030  * not support and which gdb doesn't really use excluded.
0031  */
0032 struct elf_prstatus_common
0033 {
0034     struct elf_siginfo pr_info; /* Info associated with signal */
0035     short   pr_cursig;      /* Current signal */
0036     unsigned long pr_sigpend;   /* Set of pending signals */
0037     unsigned long pr_sighold;   /* Set of held signals */
0038     pid_t   pr_pid;
0039     pid_t   pr_ppid;
0040     pid_t   pr_pgrp;
0041     pid_t   pr_sid;
0042     struct __kernel_old_timeval pr_utime;   /* User time */
0043     struct __kernel_old_timeval pr_stime;   /* System time */
0044     struct __kernel_old_timeval pr_cutime;  /* Cumulative user time */
0045     struct __kernel_old_timeval pr_cstime;  /* Cumulative system time */
0046 };
0047 
0048 struct elf_prstatus
0049 {
0050     struct elf_prstatus_common common;
0051     elf_gregset_t pr_reg;   /* GP registers */
0052     int pr_fpvalid;     /* True if math co-processor being used.  */
0053 };
0054 
0055 #define ELF_PRARGSZ (80)    /* Number of chars for args */
0056 
0057 struct elf_prpsinfo
0058 {
0059     char    pr_state;   /* numeric process state */
0060     char    pr_sname;   /* char for pr_state */
0061     char    pr_zomb;    /* zombie */
0062     char    pr_nice;    /* nice val */
0063     unsigned long pr_flag;  /* flags */
0064     __kernel_uid_t  pr_uid;
0065     __kernel_gid_t  pr_gid;
0066     pid_t   pr_pid, pr_ppid, pr_pgrp, pr_sid;
0067     /* Lots missing */
0068     /*
0069      * The hard-coded 16 is derived from TASK_COMM_LEN, but it can't be
0070      * changed as it is exposed to userspace. We'd better make it hard-coded
0071      * here.
0072      */
0073     char    pr_fname[16];   /* filename of executable */
0074     char    pr_psargs[ELF_PRARGSZ]; /* initial part of arg list */
0075 };
0076 
0077 static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
0078 {
0079 #ifdef ELF_CORE_COPY_REGS
0080     ELF_CORE_COPY_REGS((*elfregs), regs)
0081 #else
0082     BUG_ON(sizeof(*elfregs) != sizeof(*regs));
0083     *(struct pt_regs *)elfregs = *regs;
0084 #endif
0085 }
0086 
0087 static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
0088 {
0089 #if defined (ELF_CORE_COPY_TASK_REGS)
0090     return ELF_CORE_COPY_TASK_REGS(t, elfregs);
0091 #elif defined (task_pt_regs)
0092     elf_core_copy_regs(elfregs, task_pt_regs(t));
0093 #endif
0094     return 0;
0095 }
0096 
0097 extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
0098 
0099 static inline int elf_core_copy_task_fpregs(struct task_struct *t, struct pt_regs *regs, elf_fpregset_t *fpu)
0100 {
0101 #ifdef ELF_CORE_COPY_FPREGS
0102     return ELF_CORE_COPY_FPREGS(t, fpu);
0103 #else
0104     return dump_fpu(regs, fpu);
0105 #endif
0106 }
0107 
0108 #ifdef CONFIG_ARCH_BINFMT_ELF_EXTRA_PHDRS
0109 /*
0110  * These functions parameterize elf_core_dump in fs/binfmt_elf.c to write out
0111  * extra segments containing the gate DSO contents.  Dumping its
0112  * contents makes post-mortem fully interpretable later without matching up
0113  * the same kernel and hardware config to see what PC values meant.
0114  * Dumping its extra ELF program headers includes all the other information
0115  * a debugger needs to easily find how the gate DSO was being used.
0116  */
0117 extern Elf_Half elf_core_extra_phdrs(void);
0118 extern int
0119 elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset);
0120 extern int
0121 elf_core_write_extra_data(struct coredump_params *cprm);
0122 extern size_t elf_core_extra_data_size(void);
0123 #else
0124 static inline Elf_Half elf_core_extra_phdrs(void)
0125 {
0126     return 0;
0127 }
0128 
0129 static inline int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
0130 {
0131     return 1;
0132 }
0133 
0134 static inline int elf_core_write_extra_data(struct coredump_params *cprm)
0135 {
0136     return 1;
0137 }
0138 
0139 static inline size_t elf_core_extra_data_size(void)
0140 {
0141     return 0;
0142 }
0143 #endif /* CONFIG_ARCH_BINFMT_ELF_EXTRA_PHDRS */
0144 
0145 #endif /* _LINUX_ELFCORE_H */