coredump: move dump_write() and dump_seek() into a header file
Subsystems (3)
PATCH 131/160 coredump: move dump_write() and dump_seek() into a header file
From: Daisuke HATAYAMA <[email protected]>
My next patch will replace ELF_CORE_EXTRA_* macros by functions, putting them into other newly created *.c files. Then, each files will contain dump_write(), where each pair of binfmt_*.c and elfcore.c should be the same. So, this patch moves them into a header file with dump_seek(). Also, the patch deletes confusing DUMP_WRITE macros in each files.
Signed-off-by Daisuke HATAYAMA <[email protected]>
Cc "Luck, Tony" <[email protected]>
Cc Jeff Dike <[email protected]>
Cc David Howells <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Roland McGrath <[email protected]>
Cc Oleg Nesterov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Alan Cox <[email protected]>
Cc <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
fs/binfmt_aout.c | 49 ++++++--------------------------- fs/binfmt_elf.c | 52 +++++++++-------------------------- fs/binfmt_elf_fdpic.c | 54 ++++++++++--------------------------- include/linux/coredump.h | 41 ++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 117 deletions(-)
fs/binfmt_aout.c renamed from fs/binfmt_aout.c~coredump-move-dump_write-and-dump_seek-into-a-header-file +9 -40
@@ -24,6 +24,7 @@#include <linux/binfmts.h> #include <linux/personality.h> #include <linux/init.h> +#include <linux/coredump.h> #include <asm/system.h> #include <asm/uaccess.h>
@@ -60,42 +61,6 @@ static int set_brk(unsigned long start, }/* -* These are the only things you should do on a core-file: use only these -* macros to write out all the necessary info. -*/ - -static int dump_write (struct file *file,const void *addr,int nr) -{ -return file->f_op->write (file, addr, nr, &file->f_pos) == nr; -} - -static int dump_seek (struct file *file,loff_t off) -{ -if (file->f_op->llseek && file->f_op->llseek != no_llseek) { -if (file->f_op->llseek (file, off,SEEK_CUR ) <0 ) -return 0 ; - }else { -char *buf = (char *)get_zeroed_page (GFP_KERNEL ); -if (!buf) -return 0 ; -while (off >0 ) { -unsigned long n = off; -if (n >PAGE_SIZE ) - n =PAGE_SIZE ; -if (!dump_write (file, buf, n)) -return 0 ; - off -= n; - } -free_page ((unsigned long )buf); - } -return 1 ; -} - -#define DUMP_WRITE (addr, nr) \ - if (!dump_write(file, (void *)(addr), (nr))) \ - goto end_coredump; - -/* * Routine writes a core dump image in the current directory. * Currently only a stub-function. *
@@ -146,7 +111,8 @@ static int aout_core_dump(struct coredumset_fs (KERNEL_DS );/* struct user */ -DUMP_WRITE (&dump,sizeof (dump)); +if (!dump_write (file, &dump,sizeof (dump))) + goto end_coredump;/* Now dump all of the user data. Include malloced stuff as well */ if (!dump_seek (cprm->file,PAGE_SIZE -sizeof (dump))) goto end_coredump;
@@ -156,17 +122,20 @@ static int aout_core_dump(struct coredumif (dump.u_dsize !=0 ) { dump_start =START_DATA (dump); dump_size = dump.u_dsize <<PAGE_SHIFT ; -DUMP_WRITE (dump_start,dump_size); +if (!dump_write (file, dump_start, dump_size)) + goto end_coredump; }/* Now prepare to dump the stack area */ if (dump.u_ssize !=0 ) { dump_start =START_STACK (dump); dump_size = dump.u_ssize <<PAGE_SHIFT ; -DUMP_WRITE (dump_start,dump_size); +if (!dump_write (file, dump_start, dump_size)) + goto end_coredump; }/* Finally dump the task struct. Not be used by gdb, but could be useful */ set_fs (KERNEL_DS ); -DUMP_WRITE (current,sizeof (*current)); +if (!dump_write (file, current,sizeof (*current))) + goto end_coredump; end_coredump:set_fs (fs);return has_dumped;
fs/binfmt_elf.c renamed from fs/binfmt_elf.c~coredump-move-dump_write-and-dump_seek-into-a-header-file +14 -38
88 lines not on this page · raw message
fs/binfmt_elf_fdpic.c renamed from fs/binfmt_elf_fdpic.c~coredump-move-dump_write-and-dump_seek-into-a-header-file +15 -39
90 lines not on this page · raw message
include/linux/coredump.h new file +41 -0
41 lines not on this page · raw message
_