Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6151dfe authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Linus Torvalds
Browse files

mm: introduce coredump parameter structure



Introduce coredump parameter data structure (struct coredump_params) to
simplify binfmt->core_dump() arguments.

Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Suggested-by: default avatarIngo Molnar <mingo@elte.hu>
Cc: Hidehiro Kawai <hidehiro.kawai.ez@hitachi.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9cd80bbb
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@

static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs);
static int load_aout_library(struct file*);
static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
static int aout_core_dump(struct coredump_params *cprm);

static struct linux_binfmt aout_format = {
	.module		= THIS_MODULE,
@@ -89,8 +89,9 @@ if (file->f_op->llseek) { \
 * dumping of the process results in another error..
 */

static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit)
static int aout_core_dump(struct coredump_params *cprm)
{
	struct file *file = cprm->file;
	mm_segment_t fs;
	int has_dumped = 0;
	unsigned long dump_start, dump_size;
@@ -108,16 +109,16 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
	current->flags |= PF_DUMPCORE;
       	strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));
	dump.u_ar0 = offsetof(struct user, regs);
	dump.signal = signr;
	aout_dump_thread(regs, &dump);
	dump.signal = cprm->signr;
	aout_dump_thread(cprm->regs, &dump);

/* If the size of the dump file exceeds the rlimit, then see what would happen
   if we wrote the stack, but not the data area.  */
	if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
	if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
		dump.u_dsize = 0;

/* Make sure we have enough room to write the stack and data areas. */
	if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
	if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
		dump.u_ssize = 0;

/* make sure we actually have a data and stack area to dump */
+13 −11
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
 * don't even try.
 */
#ifdef CONFIG_ELF_CORE
static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
static int elf_core_dump(struct coredump_params *cprm);
#else
#define elf_core_dump	NULL
#endif
@@ -1273,7 +1273,8 @@ static int writenote(struct memelfnote *men, struct file *file,
#undef DUMP_WRITE

#define DUMP_WRITE(addr, nr)				\
	if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
	if ((size += (nr)) > cprm->limit ||		\
	    !dump_write(cprm->file, (addr), (nr)))	\
		goto end_coredump;

static void fill_elf_header(struct elfhdr *elf, int segs,
@@ -1901,7 +1902,7 @@ static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
 * and then they are actually written out.  If we run out of core limit
 * we just truncate.
 */
static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit)
static int elf_core_dump(struct coredump_params *cprm)
{
	int has_dumped = 0;
	mm_segment_t fs;
@@ -1947,7 +1948,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
	 * notes.  This also sets up the file header.
	 */
	if (!fill_note_info(elf, segs + 1, /* including notes section */
			    &info, signr, regs))
			    &info, cprm->signr, cprm->regs))
		goto cleanup;

	has_dumped = 1;
@@ -2009,14 +2010,14 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
#endif

 	/* write out the notes section */
	if (!write_note_info(&info, file, &foffset))
	if (!write_note_info(&info, cprm->file, &foffset))
		goto end_coredump;

	if (elf_coredump_extra_notes_write(file, &foffset))
	if (elf_coredump_extra_notes_write(cprm->file, &foffset))
		goto end_coredump;

	/* Align to page */
	if (!dump_seek(file, dataoff - foffset))
	if (!dump_seek(cprm->file, dataoff - foffset))
		goto end_coredump;

	for (vma = first_vma(current, gate_vma); vma != NULL;
@@ -2033,12 +2034,13 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
			page = get_dump_page(addr);
			if (page) {
				void *kaddr = kmap(page);
				stop = ((size += PAGE_SIZE) > limit) ||
					!dump_write(file, kaddr, PAGE_SIZE);
				stop = ((size += PAGE_SIZE) > cprm->limit) ||
					!dump_write(cprm->file, kaddr,
						    PAGE_SIZE);
				kunmap(page);
				page_cache_release(page);
			} else
				stop = !dump_seek(file, PAGE_SIZE);
				stop = !dump_seek(cprm->file, PAGE_SIZE);
			if (stop)
				goto end_coredump;
		}
+15 −14
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *,
					     struct file *, struct mm_struct *);

#ifdef CONFIG_ELF_CORE
static int elf_fdpic_core_dump(long, struct pt_regs *, struct file *, unsigned long limit);
static int elf_fdpic_core_dump(struct coredump_params *cprm);
#endif

static struct linux_binfmt elf_fdpic_format = {
@@ -1327,7 +1327,8 @@ static int writenote(struct memelfnote *men, struct file *file)
#undef DUMP_SEEK

#define DUMP_WRITE(addr, nr)				\
	if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
	if ((size += (nr)) > cprm->limit ||		\
	    !dump_write(cprm->file, (addr), (nr)))	\
		goto end_coredump;

static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs)
@@ -1582,8 +1583,7 @@ static int elf_fdpic_dump_segments(struct file *file, size_t *size,
 * and then they are actually written out.  If we run out of core limit
 * we just truncate.
 */
static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
			       struct file *file, unsigned long limit)
static int elf_fdpic_core_dump(struct coredump_params *cprm)
{
#define	NUM_NOTES	6
	int has_dumped = 0;
@@ -1642,7 +1642,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
		goto cleanup;
#endif

	if (signr) {
	if (cprm->signr) {
		struct core_thread *ct;
		struct elf_thread_status *tmp;

@@ -1661,14 +1661,14 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
			int sz;

			tmp = list_entry(t, struct elf_thread_status, list);
			sz = elf_dump_thread_status(signr, tmp);
			sz = elf_dump_thread_status(cprm->signr, tmp);
			thread_status_size += sz;
		}
	}

	/* now collect the dump for the current */
	fill_prstatus(prstatus, current, signr);
	elf_core_copy_regs(&prstatus->pr_reg, regs);
	fill_prstatus(prstatus, current, cprm->signr);
	elf_core_copy_regs(&prstatus->pr_reg, cprm->regs);

	segs = current->mm->map_count;
#ifdef ELF_CORE_EXTRA_PHDRS
@@ -1703,7 +1703,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,

  	/* Try to dump the FPU. */
	if ((prstatus->pr_fpvalid =
	     elf_core_copy_task_fpregs(current, regs, fpu)))
	     elf_core_copy_task_fpregs(current, cprm->regs, fpu)))
		fill_note(notes + numnote++,
			  "CORE", NT_PRFPREG, sizeof(*fpu), fpu);
#ifdef ELF_CORE_COPY_XFPREGS
@@ -1774,7 +1774,7 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,

 	/* write out the notes section */
	for (i = 0; i < numnote; i++)
		if (!writenote(notes + i, file))
		if (!writenote(notes + i, cprm->file))
			goto end_coredump;

	/* write out the thread status notes section */
@@ -1783,14 +1783,15 @@ static int elf_fdpic_core_dump(long signr, struct pt_regs *regs,
				list_entry(t, struct elf_thread_status, list);

		for (i = 0; i < tmp->num_notes; i++)
			if (!writenote(&tmp->notes[i], file))
			if (!writenote(&tmp->notes[i], cprm->file))
				goto end_coredump;
	}

	if (!dump_seek(file, dataoff))
	if (!dump_seek(cprm->file, dataoff))
		goto end_coredump;

	if (elf_fdpic_dump_segments(file, &size, &limit, mm_flags) < 0)
	if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit,
				    mm_flags) < 0)
		goto end_coredump;

#ifdef ELF_CORE_WRITE_EXTRA_DATA
+3 −3
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ static int load_flat_shared_library(int id, struct lib_info *p);
#endif

static int load_flat_binary(struct linux_binprm *, struct pt_regs * regs);
static int flat_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
static int flat_core_dump(struct coredump_params *cprm);

static struct linux_binfmt flat_format = {
	.module		= THIS_MODULE,
@@ -102,10 +102,10 @@ static struct linux_binfmt flat_format = {
 * Currently only a stub-function.
 */

static int flat_core_dump(long signr, struct pt_regs *regs, struct file *file, unsigned long limit)
static int flat_core_dump(struct coredump_params *cprm)
{
	printk("Process %s:%d received signr %d and should have core dumped\n",
			current->comm, current->pid, (int) signr);
			current->comm, current->pid, (int) cprm->signr);
	return(1);
}

+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ static int load_som_library(struct file *);
 * don't even try.
 */
#if 0
static int som_core_dump(long signr, struct pt_regs *regs, unsigned long limit);
static int som_core_dump(struct coredump_params *cprm);
#else
#define som_core_dump	NULL
#endif
Loading