forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[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]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
4 changed files
with
79 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
#include <linux/random.h> | ||
#include <linux/elf.h> | ||
#include <linux/utsname.h> | ||
#include <linux/coredump.h> | ||
#include <asm/uaccess.h> | ||
#include <asm/param.h> | ||
#include <asm/page.h> | ||
|
@@ -1085,36 +1086,6 @@ static int load_elf_library(struct file *file) | |
* Modelled on fs/exec.c:aout_core_dump() | ||
* Jeremy Fitzhardinge <[email protected]> | ||
*/ | ||
/* | ||
* These are the only things you should do on a core-file: use only these | ||
* functions 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; | ||
} | ||
|
||
/* | ||
* Decide what to dump of a segment, part, all or none. | ||
|
@@ -1249,11 +1220,6 @@ static int writenote(struct memelfnote *men, struct file *file, | |
} | ||
#undef DUMP_WRITE | ||
|
||
#define DUMP_WRITE(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, | ||
u16 machine, u32 flags, u8 osabi) | ||
{ | ||
|
@@ -1934,7 +1900,10 @@ static int elf_core_dump(struct coredump_params *cprm) | |
fs = get_fs(); | ||
set_fs(KERNEL_DS); | ||
|
||
DUMP_WRITE(elf, sizeof(*elf)); | ||
size += sizeof(*elf); | ||
if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf))) | ||
goto end_coredump; | ||
|
||
offset += sizeof(*elf); /* Elf header */ | ||
offset += (segs + 1) * sizeof(struct elf_phdr); /* Program headers */ | ||
foffset = offset; | ||
|
@@ -1948,7 +1917,11 @@ static int elf_core_dump(struct coredump_params *cprm) | |
|
||
fill_elf_note_phdr(&phdr, sz, offset); | ||
offset += sz; | ||
DUMP_WRITE(&phdr, sizeof(phdr)); | ||
|
||
size += sizeof(phdr); | ||
if (size > cprm->limit | ||
|| !dump_write(cprm->file, &phdr, sizeof(phdr))) | ||
goto end_coredump; | ||
} | ||
|
||
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE); | ||
|
@@ -1979,7 +1952,10 @@ static int elf_core_dump(struct coredump_params *cprm) | |
phdr.p_flags |= PF_X; | ||
phdr.p_align = ELF_EXEC_PAGESIZE; | ||
|
||
DUMP_WRITE(&phdr, sizeof(phdr)); | ||
size += sizeof(phdr); | ||
if (size > cprm->limit | ||
|| !dump_write(cprm->file, &phdr, sizeof(phdr))) | ||
goto end_coredump; | ||
} | ||
|
||
#ifdef ELF_CORE_WRITE_EXTRA_PHDRS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef _LINUX_COREDUMP_H | ||
#define _LINUX_COREDUMP_H | ||
|
||
#include <linux/types.h> | ||
#include <linux/mm.h> | ||
#include <linux/fs.h> | ||
|
||
/* | ||
* These are the only things you should do on a core-file: use only these | ||
* functions to write out all the necessary info. | ||
*/ | ||
static inline int dump_write(struct file *file, const void *addr, int nr) | ||
{ | ||
return file->f_op->write(file, addr, nr, &file->f_pos) == nr; | ||
} | ||
|
||
static inline 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; | ||
} | ||
|
||
#endif /* _LINUX_COREDUMP_H */ |