1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 25c48b108SAl Viro #include <linux/elf.h> 35c48b108SAl Viro #include <linux/coredump.h> 45c48b108SAl Viro #include <linux/fs.h> 55c48b108SAl Viro #include <linux/mm.h> 65c48b108SAl Viro 75c48b108SAl Viro #include <asm/elf.h> 85c48b108SAl Viro 95c48b108SAl Viro elf_core_extra_phdrs(struct coredump_params * cprm)10*19e183b5SCatalin MarinasElf32_Half elf_core_extra_phdrs(struct coredump_params *cprm) 115c48b108SAl Viro { 125c48b108SAl Viro return vsyscall_ehdr ? (((struct elfhdr *)vsyscall_ehdr)->e_phnum) : 0; 135c48b108SAl Viro } 145c48b108SAl Viro elf_core_write_extra_phdrs(struct coredump_params * cprm,loff_t offset)15506f21c5SAl Viroint elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset) 165c48b108SAl Viro { 175c48b108SAl Viro if ( vsyscall_ehdr ) { 185c48b108SAl Viro const struct elfhdr *const ehdrp = 195c48b108SAl Viro (struct elfhdr *) vsyscall_ehdr; 205c48b108SAl Viro const struct elf_phdr *const phdrp = 215c48b108SAl Viro (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); 225c48b108SAl Viro int i; 235c48b108SAl Viro Elf32_Off ofs = 0; 245c48b108SAl Viro 255c48b108SAl Viro for (i = 0; i < ehdrp->e_phnum; ++i) { 265c48b108SAl Viro struct elf_phdr phdr = phdrp[i]; 275c48b108SAl Viro 285c48b108SAl Viro if (phdr.p_type == PT_LOAD) { 295c48b108SAl Viro ofs = phdr.p_offset = offset; 305c48b108SAl Viro offset += phdr.p_filesz; 315c48b108SAl Viro } else { 325c48b108SAl Viro phdr.p_offset += ofs; 335c48b108SAl Viro } 345c48b108SAl Viro phdr.p_paddr = 0; /* match other core phdrs */ 35506f21c5SAl Viro if (!dump_emit(cprm, &phdr, sizeof(phdr))) 365c48b108SAl Viro return 0; 375c48b108SAl Viro } 385c48b108SAl Viro } 395c48b108SAl Viro return 1; 405c48b108SAl Viro } 415c48b108SAl Viro elf_core_write_extra_data(struct coredump_params * cprm)42aa3e7eafSAl Viroint elf_core_write_extra_data(struct coredump_params *cprm) 435c48b108SAl Viro { 445c48b108SAl Viro if ( vsyscall_ehdr ) { 455c48b108SAl Viro const struct elfhdr *const ehdrp = 465c48b108SAl Viro (struct elfhdr *) vsyscall_ehdr; 475c48b108SAl Viro const struct elf_phdr *const phdrp = 485c48b108SAl Viro (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); 495c48b108SAl Viro int i; 505c48b108SAl Viro 515c48b108SAl Viro for (i = 0; i < ehdrp->e_phnum; ++i) { 525c48b108SAl Viro if (phdrp[i].p_type == PT_LOAD) { 535c48b108SAl Viro void *addr = (void *) phdrp[i].p_vaddr; 545c48b108SAl Viro size_t filesz = phdrp[i].p_filesz; 55aa3e7eafSAl Viro if (!dump_emit(cprm, addr, filesz)) 565c48b108SAl Viro return 0; 575c48b108SAl Viro } 585c48b108SAl Viro } 595c48b108SAl Viro } 605c48b108SAl Viro return 1; 615c48b108SAl Viro } 625c48b108SAl Viro elf_core_extra_data_size(struct coredump_params * cprm)63*19e183b5SCatalin Marinassize_t elf_core_extra_data_size(struct coredump_params *cprm) 645c48b108SAl Viro { 655c48b108SAl Viro if ( vsyscall_ehdr ) { 665c48b108SAl Viro const struct elfhdr *const ehdrp = 675c48b108SAl Viro (struct elfhdr *)vsyscall_ehdr; 685c48b108SAl Viro const struct elf_phdr *const phdrp = 695c48b108SAl Viro (const struct elf_phdr *) (vsyscall_ehdr + ehdrp->e_phoff); 705c48b108SAl Viro int i; 715c48b108SAl Viro 725c48b108SAl Viro for (i = 0; i < ehdrp->e_phnum; ++i) 735c48b108SAl Viro if (phdrp[i].p_type == PT_LOAD) 745c48b108SAl Viro return (size_t) phdrp[i].p_filesz; 755c48b108SAl Viro } 765c48b108SAl Viro return 0; 775c48b108SAl Viro } 78