diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
| commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
| tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /arch/um/sys-i386/elfcore.c | |
| parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) | |
Diffstat (limited to 'arch/um/sys-i386/elfcore.c')
| -rw-r--r-- | arch/um/sys-i386/elfcore.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/arch/um/sys-i386/elfcore.c b/arch/um/sys-i386/elfcore.c new file mode 100644 index 00000000000..6bb49b687c9 --- /dev/null +++ b/arch/um/sys-i386/elfcore.c | |||
| @@ -0,0 +1,83 @@ | |||
| 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 | |||
| 14 | int elf_core_write_extra_phdrs(struct file *file, loff_t offset, size_t *size, | ||
| 15 | unsigned long limit) | ||
| 16 | { | ||
| 17 | if ( vsyscall_ehdr ) { | ||
| 18 | const struct elfhdr *const ehdrp = | ||
| 19 | (struct elfhdr *) vsyscall_ehdr; | ||
| 20 | const struct elf_phdr *const phdrp = | ||
| 21 | (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); | ||
| 22 | int i; | ||
| 23 | Elf32_Off ofs = 0; | ||
| 24 | |||
| 25 | for (i = 0; i < ehdrp->e_phnum; ++i) { | ||
| 26 | struct elf_phdr phdr = phdrp[i]; | ||
| 27 | |||
| 28 | if (phdr.p_type == PT_LOAD) { | ||
| 29 | ofs = phdr.p_offset = offset; | ||
| 30 | offset += phdr.p_filesz; | ||
| 31 | } else { | ||
| 32 | phdr.p_offset += ofs; | ||
| 33 | } | ||
| 34 | phdr.p_paddr = 0; /* match other core phdrs */ | ||
| 35 | *size += sizeof(phdr); | ||
| 36 | if (*size > limit | ||
| 37 | || !dump_write(file, &phdr, sizeof(phdr))) | ||
| 38 | return 0; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return 1; | ||
| 42 | } | ||
| 43 | |||
| 44 | int elf_core_write_extra_data(struct file *file, size_t *size, | ||
| 45 | unsigned long limit) | ||
| 46 | { | ||
| 47 | if ( vsyscall_ehdr ) { | ||
| 48 | const struct elfhdr *const ehdrp = | ||
| 49 | (struct elfhdr *) vsyscall_ehdr; | ||
| 50 | const struct elf_phdr *const phdrp = | ||
| 51 | (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); | ||
| 52 | int i; | ||
| 53 | |||
| 54 | for (i = 0; i < ehdrp->e_phnum; ++i) { | ||
| 55 | if (phdrp[i].p_type == PT_LOAD) { | ||
| 56 | void *addr = (void *) phdrp[i].p_vaddr; | ||
| 57 | size_t filesz = phdrp[i].p_filesz; | ||
| 58 | |||
| 59 | *size += filesz; | ||
| 60 | if (*size > limit | ||
| 61 | || !dump_write(file, addr, filesz)) | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | return 1; | ||
| 67 | } | ||
| 68 | |||
| 69 | size_t elf_core_extra_data_size(void) | ||
| 70 | { | ||
| 71 | if ( vsyscall_ehdr ) { | ||
| 72 | const struct elfhdr *const ehdrp = | ||
| 73 | (struct elfhdr *)vsyscall_ehdr; | ||
| 74 | const struct elf_phdr *const phdrp = | ||
| 75 | (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); | ||
| 76 | int i; | ||
| 77 | |||
| 78 | for (i = 0; i < ehdrp->e_phnum; ++i) | ||
| 79 | if (phdrp[i].p_type == PT_LOAD) | ||
| 80 | return (size_t) phdrp[i].p_filesz; | ||
| 81 | } | ||
| 82 | return 0; | ||
| 83 | } | ||
