aboutsummaryrefslogtreecommitdiffstats
path: root/fs/binfmt_elf_fdpic.c
diff options
context:
space:
mode:
authorDaisuke HATAYAMA <d.hatayama@jp.fujitsu.com>2010-03-05 16:44:06 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-06 14:26:45 -0500
commit088e7af73a962fcc8883b7a6392544d8342553d6 (patch)
tree5dce5b991cad1071522b464bd83943a1b6e885b2 /fs/binfmt_elf_fdpic.c
parent05f47fda9fc5b17bfab189e9d54228025befc996 (diff)
coredump: move dump_write() and dump_seek() into a header file
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 <d.hatayama@jp.fujitsu.com> Cc: "Luck, Tony" <tony.luck@intel.com> Cc: Jeff Dike <jdike@addtoit.com> Cc: David Howells <dhowells@redhat.com> Cc: Greg Ungerer <gerg@snapgear.com> Cc: Roland McGrath <roland@redhat.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andi Kleen <andi@firstfloor.org> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/binfmt_elf_fdpic.c')
-rw-r--r--fs/binfmt_elf_fdpic.c54
1 files changed, 15 insertions, 39 deletions
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 32d9b44c3cb9..63edf40b569b 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -34,6 +34,7 @@
34#include <linux/elf.h> 34#include <linux/elf.h>
35#include <linux/elf-fdpic.h> 35#include <linux/elf-fdpic.h>
36#include <linux/elfcore.h> 36#include <linux/elfcore.h>
37#include <linux/coredump.h>
37 38
38#include <asm/uaccess.h> 39#include <asm/uaccess.h>
39#include <asm/param.h> 40#include <asm/param.h>
@@ -1216,37 +1217,6 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params,
1216#ifdef CONFIG_ELF_CORE 1217#ifdef CONFIG_ELF_CORE
1217 1218
1218/* 1219/*
1219 * These are the only things you should do on a core-file: use only these
1220 * functions to write out all the necessary info.
1221 */
1222static int dump_write(struct file *file, const void *addr, int nr)
1223{
1224 return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
1225}
1226
1227static int dump_seek(struct file *file, loff_t off)
1228{
1229 if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
1230 if (file->f_op->llseek(file, off, SEEK_CUR) < 0)
1231 return 0;
1232 } else {
1233 char *buf = (char *)get_zeroed_page(GFP_KERNEL);
1234 if (!buf)
1235 return 0;
1236 while (off > 0) {
1237 unsigned long n = off;
1238 if (n > PAGE_SIZE)
1239 n = PAGE_SIZE;
1240 if (!dump_write(file, buf, n))
1241 return 0;
1242 off -= n;
1243 }
1244 free_page((unsigned long)buf);
1245 }
1246 return 1;
1247}
1248
1249/*
1250 * Decide whether a segment is worth dumping; default is yes to be 1220 * Decide whether a segment is worth dumping; default is yes to be
1251 * sure (missing info is worse than too much; etc). 1221 * sure (missing info is worse than too much; etc).
1252 * Personally I'd include everything, and use the coredump limit... 1222 * Personally I'd include everything, and use the coredump limit...
@@ -1354,11 +1324,6 @@ static int writenote(struct memelfnote *men, struct file *file,
1354} 1324}
1355#undef DUMP_WRITE 1325#undef DUMP_WRITE
1356 1326
1357#define DUMP_WRITE(addr, nr) \
1358 if ((size += (nr)) > cprm->limit || \
1359 !dump_write(cprm->file, (addr), (nr))) \
1360 goto end_coredump;
1361
1362static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) 1327static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs)
1363{ 1328{
1364 memcpy(elf->e_ident, ELFMAG, SELFMAG); 1329 memcpy(elf->e_ident, ELFMAG, SELFMAG);
@@ -1743,7 +1708,11 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1743 fs = get_fs(); 1708 fs = get_fs();
1744 set_fs(KERNEL_DS); 1709 set_fs(KERNEL_DS);
1745 1710
1746 DUMP_WRITE(elf, sizeof(*elf)); 1711 size += sizeof(*elf);
1712 if (size > cprm->limit
1713 || !dump_write(cprm->file, elf, sizeof(*elf)))
1714 goto end_coredump;
1715
1747 offset += sizeof(*elf); /* Elf header */ 1716 offset += sizeof(*elf); /* Elf header */
1748 offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */ 1717 offset += (segs+1) * sizeof(struct elf_phdr); /* Program headers */
1749 foffset = offset; 1718 foffset = offset;
@@ -1760,7 +1729,11 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1760 1729
1761 fill_elf_note_phdr(&phdr, sz, offset); 1730 fill_elf_note_phdr(&phdr, sz, offset);
1762 offset += sz; 1731 offset += sz;
1763 DUMP_WRITE(&phdr, sizeof(phdr)); 1732
1733 size += sizeof(phdr);
1734 if (size > cprm->limit
1735 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
1736 goto end_coredump;
1764 } 1737 }
1765 1738
1766 /* Page-align dumped data */ 1739 /* Page-align dumped data */
@@ -1794,7 +1767,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
1794 phdr.p_flags |= PF_X; 1767 phdr.p_flags |= PF_X;
1795 phdr.p_align = ELF_EXEC_PAGESIZE; 1768 phdr.p_align = ELF_EXEC_PAGESIZE;
1796 1769
1797 DUMP_WRITE(&phdr, sizeof(phdr)); 1770 size += sizeof(phdr);
1771 if (size > cprm->limit
1772 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
1773 goto end_coredump;
1798 } 1774 }
1799 1775
1800#ifdef ELF_CORE_WRITE_EXTRA_PHDRS 1776#ifdef ELF_CORE_WRITE_EXTRA_PHDRS