xref: /openbmc/linux/arch/ia64/kernel/elfcore.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21fcccbacSDaisuke HATAYAMA #include <linux/elf.h>
31fcccbacSDaisuke HATAYAMA #include <linux/coredump.h>
41fcccbacSDaisuke HATAYAMA #include <linux/fs.h>
51fcccbacSDaisuke HATAYAMA #include <linux/mm.h>
61fcccbacSDaisuke HATAYAMA 
71fcccbacSDaisuke HATAYAMA #include <asm/elf.h>
81fcccbacSDaisuke HATAYAMA 
91fcccbacSDaisuke HATAYAMA 
elf_core_extra_phdrs(struct coredump_params * cprm)10*19e183b5SCatalin Marinas Elf64_Half elf_core_extra_phdrs(struct coredump_params *cprm)
111fcccbacSDaisuke HATAYAMA {
121fcccbacSDaisuke HATAYAMA 	return GATE_EHDR->e_phnum;
131fcccbacSDaisuke HATAYAMA }
141fcccbacSDaisuke HATAYAMA 
elf_core_write_extra_phdrs(struct coredump_params * cprm,loff_t offset)15506f21c5SAl Viro int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
161fcccbacSDaisuke HATAYAMA {
171fcccbacSDaisuke HATAYAMA 	const struct elf_phdr *const gate_phdrs =
181fcccbacSDaisuke HATAYAMA 		(const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
191fcccbacSDaisuke HATAYAMA 	int i;
201fcccbacSDaisuke HATAYAMA 	Elf64_Off ofs = 0;
211fcccbacSDaisuke HATAYAMA 
221fcccbacSDaisuke HATAYAMA 	for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
231fcccbacSDaisuke HATAYAMA 		struct elf_phdr phdr = gate_phdrs[i];
241fcccbacSDaisuke HATAYAMA 
251fcccbacSDaisuke HATAYAMA 		if (phdr.p_type == PT_LOAD) {
261fcccbacSDaisuke HATAYAMA 			phdr.p_memsz = PAGE_ALIGN(phdr.p_memsz);
271fcccbacSDaisuke HATAYAMA 			phdr.p_filesz = phdr.p_memsz;
281fcccbacSDaisuke HATAYAMA 			if (ofs == 0) {
291fcccbacSDaisuke HATAYAMA 				ofs = phdr.p_offset = offset;
301fcccbacSDaisuke HATAYAMA 				offset += phdr.p_filesz;
311fcccbacSDaisuke HATAYAMA 			} else {
321fcccbacSDaisuke HATAYAMA 				phdr.p_offset = ofs;
331fcccbacSDaisuke HATAYAMA 			}
341fcccbacSDaisuke HATAYAMA 		} else {
351fcccbacSDaisuke HATAYAMA 			phdr.p_offset += ofs;
361fcccbacSDaisuke HATAYAMA 		}
371fcccbacSDaisuke HATAYAMA 		phdr.p_paddr = 0; /* match other core phdrs */
38506f21c5SAl Viro 		if (!dump_emit(cprm, &phdr, sizeof(phdr)))
391fcccbacSDaisuke HATAYAMA 			return 0;
401fcccbacSDaisuke HATAYAMA 	}
411fcccbacSDaisuke HATAYAMA 	return 1;
421fcccbacSDaisuke HATAYAMA }
431fcccbacSDaisuke HATAYAMA 
elf_core_write_extra_data(struct coredump_params * cprm)44aa3e7eafSAl Viro int elf_core_write_extra_data(struct coredump_params *cprm)
451fcccbacSDaisuke HATAYAMA {
461fcccbacSDaisuke HATAYAMA 	const struct elf_phdr *const gate_phdrs =
471fcccbacSDaisuke HATAYAMA 		(const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
481fcccbacSDaisuke HATAYAMA 	int i;
491fcccbacSDaisuke HATAYAMA 
501fcccbacSDaisuke HATAYAMA 	for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
511fcccbacSDaisuke HATAYAMA 		if (gate_phdrs[i].p_type == PT_LOAD) {
521fcccbacSDaisuke HATAYAMA 			void *addr = (void *)gate_phdrs[i].p_vaddr;
531fcccbacSDaisuke HATAYAMA 			size_t memsz = PAGE_ALIGN(gate_phdrs[i].p_memsz);
541fcccbacSDaisuke HATAYAMA 
55aa3e7eafSAl Viro 			if (!dump_emit(cprm, addr, memsz))
561fcccbacSDaisuke HATAYAMA 				return 0;
571fcccbacSDaisuke HATAYAMA 			break;
581fcccbacSDaisuke HATAYAMA 		}
591fcccbacSDaisuke HATAYAMA 	}
601fcccbacSDaisuke HATAYAMA 	return 1;
611fcccbacSDaisuke HATAYAMA }
628d9032bbSDaisuke HATAYAMA 
elf_core_extra_data_size(struct coredump_params * cprm)63*19e183b5SCatalin Marinas size_t elf_core_extra_data_size(struct coredump_params *cprm)
648d9032bbSDaisuke HATAYAMA {
658d9032bbSDaisuke HATAYAMA 	const struct elf_phdr *const gate_phdrs =
668d9032bbSDaisuke HATAYAMA 		(const struct elf_phdr *) (GATE_ADDR + GATE_EHDR->e_phoff);
678d9032bbSDaisuke HATAYAMA 	int i;
688d9032bbSDaisuke HATAYAMA 	size_t size = 0;
698d9032bbSDaisuke HATAYAMA 
708d9032bbSDaisuke HATAYAMA 	for (i = 0; i < GATE_EHDR->e_phnum; ++i) {
718d9032bbSDaisuke HATAYAMA 		if (gate_phdrs[i].p_type == PT_LOAD) {
728d9032bbSDaisuke HATAYAMA 			size += PAGE_ALIGN(gate_phdrs[i].p_memsz);
738d9032bbSDaisuke HATAYAMA 			break;
748d9032bbSDaisuke HATAYAMA 		}
758d9032bbSDaisuke HATAYAMA 	}
768d9032bbSDaisuke HATAYAMA 	return size;
778d9032bbSDaisuke HATAYAMA }
78