2005-04-16 16:20:36 -06:00
|
|
|
#ifndef _LINUX_ELFCORE_H
|
|
|
|
#define _LINUX_ELFCORE_H
|
|
|
|
|
|
|
|
#include <linux/user.h>
|
2011-11-23 18:12:59 -07:00
|
|
|
#include <linux/bug.h>
|
2017-02-08 10:51:37 -07:00
|
|
|
#include <linux/sched/task_stack.h>
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/elf.h>
|
2012-10-13 03:46:48 -06:00
|
|
|
#include <uapi/linux/elfcore.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-10-05 15:22:57 -06:00
|
|
|
struct coredump_params;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static inline void elf_core_copy_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
#ifdef ELF_CORE_COPY_REGS
|
|
|
|
ELF_CORE_COPY_REGS((*elfregs), regs)
|
|
|
|
#else
|
|
|
|
BUG_ON(sizeof(*elfregs) != sizeof(*regs));
|
|
|
|
*(struct pt_regs *)elfregs = *regs;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-09 06:17:39 -07:00
|
|
|
static inline void elf_core_copy_kernel_regs(elf_gregset_t *elfregs, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
#ifdef ELF_CORE_COPY_KERNEL_REGS
|
|
|
|
ELF_CORE_COPY_KERNEL_REGS((*elfregs), regs);
|
|
|
|
#else
|
|
|
|
elf_core_copy_regs(elfregs, regs);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static inline int elf_core_copy_task_regs(struct task_struct *t, elf_gregset_t* elfregs)
|
|
|
|
{
|
2009-07-08 09:46:02 -06:00
|
|
|
#if defined (ELF_CORE_COPY_TASK_REGS)
|
2005-04-16 16:20:36 -06:00
|
|
|
return ELF_CORE_COPY_TASK_REGS(t, elfregs);
|
2009-07-08 09:46:02 -06:00
|
|
|
#elif defined (task_pt_regs)
|
elf: fix multithreaded program core dumping on arm
Fix the multithread program core thread message error.
This issue affects arches with neither has CORE_DUMP_USE_REGSET nor
ELF_CORE_COPY_TASK_REGS, ARM is one of them.
The thread message of core file is generated in elf_dump_thread_status.
The register values is set by elf_core_copy_task_regs in this function.
If an arch doesn't define ELF_CORE_COPY_TASK_REGS,
elf_core_copy_task_regs() will do nothing. Then the core file will not
have the register message of thread.
So add elf_core_copy_regs to set regiser values if ELF_CORE_COPY_TASK_REGS
doesn't define.
The following is how to reproduce this issue:
cat 1.c
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
void td1(void * i)
{
while (1)
{
printf ("1\n");
sleep (1);
}
return;
}
void td2(void * i)
{
while (1)
{
printf ("2\n");
sleep (1);
}
return;
}
int
main(int argc,char *argv[],char *envp[])
{
pthread_t t1,t2;
pthread_create(&t1, NULL, (void*)td1, NULL);
pthread_create(&t2, NULL, (void*)td2, NULL);
sleep (10);
assert(0);
return (0);
}
arm-xxx-gcc -g -lpthread 1.c -o 1
copy 1.c and 1 to a arm board.
Goto this board.
ulimit -c 1800000
./1
# ./1
1
2
1
...
...
1
1: 1.c:37: main: Assertion `0' failed.
Aborted (core dumped)
Then you can get a core file.
gdb 1 core.xxx
Without the patch:
(gdb) info threads
3 process 909 0x00000000 in ?? ()
2 process 908 0x00000000 in ?? ()
* 1 process 907 0x4a6e2238 in raise () from /lib/libc.so.6
You can found that the pc of 909 and 908 is 0x00000000.
With the patch:
(gdb) info threads
3 process 885 0x4a749974 in nanosleep () from /lib/libc.so.6
2 process 884 0x4a749974 in nanosleep () from /lib/libc.so.6
* 1 process 883 0x4a6e2238 in raise () from /lib/libc.so.6
The pc of 885 and 884 is right.
Signed-off-by: Hui Zhu <teawater@gmail.com>
Cc: Amerigo Wang <xiyou.wangcong@gmail.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: David Howells <dhowells@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>
Cc: Russell King <rmk@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2009-07-05 13:08:15 -06:00
|
|
|
elf_core_copy_regs(elfregs, task_pt_regs(t));
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int dump_fpu (struct pt_regs *, elf_fpregset_t *);
|
|
|
|
|
|
|
|
static inline int elf_core_copy_task_fpregs(struct task_struct *t, struct pt_regs *regs, elf_fpregset_t *fpu)
|
|
|
|
{
|
|
|
|
#ifdef ELF_CORE_COPY_FPREGS
|
|
|
|
return ELF_CORE_COPY_FPREGS(t, fpu);
|
|
|
|
#else
|
|
|
|
return dump_fpu(regs, fpu);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ELF_CORE_COPY_XFPREGS
|
|
|
|
static inline int elf_core_copy_task_xfpregs(struct task_struct *t, elf_fpxregset_t *xfpu)
|
|
|
|
{
|
|
|
|
return ELF_CORE_COPY_XFPREGS(t, xfpu);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-05 14:44:07 -07:00
|
|
|
/*
|
|
|
|
* These functions parameterize elf_core_dump in fs/binfmt_elf.c to write out
|
|
|
|
* extra segments containing the gate DSO contents. Dumping its
|
|
|
|
* contents makes post-mortem fully interpretable later without matching up
|
|
|
|
* the same kernel and hardware config to see what PC values meant.
|
|
|
|
* Dumping its extra ELF program headers includes all the other information
|
|
|
|
* a debugger needs to easily find how the gate DSO was being used.
|
|
|
|
*/
|
|
|
|
extern Elf_Half elf_core_extra_phdrs(void);
|
|
|
|
extern int
|
2013-10-05 15:22:57 -06:00
|
|
|
elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset);
|
2010-03-05 14:44:07 -07:00
|
|
|
extern int
|
2013-10-05 15:50:15 -06:00
|
|
|
elf_core_write_extra_data(struct coredump_params *cprm);
|
2010-03-05 14:44:10 -07:00
|
|
|
extern size_t elf_core_extra_data_size(void);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#endif /* _LINUX_ELFCORE_H */
|