blob: 7bb89a27a5e43c266583d753e0e270aa73a0ceda [file] [log] [blame]
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -08001#include <linux/elf.h>
2#include <linux/coredump.h>
3#include <linux/fs.h>
4#include <linux/mm.h>
5
6#include <asm/elf.h>
7
8
9Elf32_Half elf_core_extra_phdrs(void)
10{
11 return vsyscall_ehdr ? (((struct elfhdr *)vsyscall_ehdr)->e_phnum) : 0;
12}
13
Al Viro506f21c2013-10-05 17:22:57 -040014int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080015{
16 if ( vsyscall_ehdr ) {
17 const struct elfhdr *const ehdrp =
18 (struct elfhdr *) vsyscall_ehdr;
19 const struct elf_phdr *const phdrp =
20 (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
21 int i;
22 Elf32_Off ofs = 0;
23
24 for (i = 0; i < ehdrp->e_phnum; ++i) {
25 struct elf_phdr phdr = phdrp[i];
26
27 if (phdr.p_type == PT_LOAD) {
28 ofs = phdr.p_offset = offset;
29 offset += phdr.p_filesz;
30 } else {
31 phdr.p_offset += ofs;
32 }
33 phdr.p_paddr = 0; /* match other core phdrs */
Al Viro506f21c2013-10-05 17:22:57 -040034 if (!dump_emit(cprm, &phdr, sizeof(phdr)))
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080035 return 0;
36 }
37 }
38 return 1;
39}
40
Al Viroaa3e7ea2013-10-05 17:50:15 -040041int elf_core_write_extra_data(struct coredump_params *cprm)
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080042{
43 if ( vsyscall_ehdr ) {
44 const struct elfhdr *const ehdrp =
45 (struct elfhdr *) vsyscall_ehdr;
46 const struct elf_phdr *const phdrp =
47 (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
48 int i;
49
50 for (i = 0; i < ehdrp->e_phnum; ++i) {
51 if (phdrp[i].p_type == PT_LOAD) {
52 void *addr = (void *) phdrp[i].p_vaddr;
53 size_t filesz = phdrp[i].p_filesz;
Al Viroaa3e7ea2013-10-05 17:50:15 -040054 if (!dump_emit(cprm, addr, filesz))
Daisuke HATAYAMA1fcccba2010-03-05 13:44:07 -080055 return 0;
56 }
57 }
58 }
59 return 1;
60}
Daisuke HATAYAMA8d9032b2010-03-05 13:44:10 -080061
62size_t elf_core_extra_data_size(void)
63{
64 if ( vsyscall_ehdr ) {
65 const struct elfhdr *const ehdrp =
66 (struct elfhdr *)vsyscall_ehdr;
67 const struct elf_phdr *const phdrp =
68 (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff);
69 int i;
70
71 for (i = 0; i < ehdrp->e_phnum; ++i)
72 if (phdrp[i].p_type == PT_LOAD)
73 return (size_t) phdrp[i].p_filesz;
74 }
75 return 0;
76}