Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 1 | #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 | |
| 9 | Elf32_Half elf_core_extra_phdrs(void) |
| 10 | { |
| 11 | return vsyscall_ehdr ? (((struct elfhdr *)vsyscall_ehdr)->e_phnum) : 0; |
| 12 | } |
| 13 | |
Al Viro | 506f21c | 2013-10-05 17:22:57 -0400 | [diff] [blame] | 14 | int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset) |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 15 | { |
| 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 Viro | 506f21c | 2013-10-05 17:22:57 -0400 | [diff] [blame] | 34 | if (!dump_emit(cprm, &phdr, sizeof(phdr))) |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 35 | return 0; |
| 36 | } |
| 37 | } |
| 38 | return 1; |
| 39 | } |
| 40 | |
Al Viro | aa3e7ea | 2013-10-05 17:50:15 -0400 | [diff] [blame] | 41 | int elf_core_write_extra_data(struct coredump_params *cprm) |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 42 | { |
| 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 Viro | aa3e7ea | 2013-10-05 17:50:15 -0400 | [diff] [blame] | 54 | if (!dump_emit(cprm, addr, filesz)) |
Daisuke HATAYAMA | 1fcccba | 2010-03-05 13:44:07 -0800 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | return 1; |
| 60 | } |
Daisuke HATAYAMA | 8d9032b | 2010-03-05 13:44:10 -0800 | [diff] [blame] | 61 | |
| 62 | size_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 | } |