Skip to content

Commit

Permalink
Un-inline the core-dump helper functions
Browse files Browse the repository at this point in the history
Tony Luck reports that the addition of the access_ok() check in commit
0eead9a ("Don't dump task struct in a.out core-dumps") broke the
ia64 compile due to missing the necessary header file includes.

Rather than add yet another include (<asm/unistd.h>) to make everything
happy, just uninline the silly core dump helper functions and move the
bodies to fs/exec.c where they make a lot more sense.

dump_seek() in particular was too big to be an inline function anyway,
and none of them are in any way performance-critical.  And we really
don't need to mess up our include file headers more than they already
are.

Reported-and-tested-by: Tony Luck <tony.luck@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Linus Torvalds committed Oct 14, 2010
1 parent ae42d8d commit 3aa0ce8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
38 changes: 38 additions & 0 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2014,3 +2014,41 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
fail:
return;
}

/*
* Core dumping helper functions. These are the only things you should
* do on a core-file: use only these functions to write out all the
* necessary info.
*/
int dump_write(struct file *file, const void *addr, int nr)
{
return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
}

int dump_seek(struct file *file, loff_t off)
{
int ret = 1;

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)) {
ret = 0;
break;
}
off -= n;
}
free_page((unsigned long)buf);
}
return ret;
}
34 changes: 2 additions & 32 deletions include/linux/coredump.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,7 @@
* 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 access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
}

static inline int dump_seek(struct file *file, loff_t off)
{
int ret = 1;

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)) {
ret = 0;
break;
}
off -= n;
}
free_page((unsigned long)buf);
}
return ret;
}
extern int dump_write(struct file *file, const void *addr, int nr);
extern int dump_seek(struct file *file, loff_t off);

#endif /* _LINUX_COREDUMP_H */

0 comments on commit 3aa0ce8

Please sign in to comment.