Skip to content

Commit

Permalink
new helper: dump_align()
Browse files Browse the repository at this point in the history
dump_skip to given alignment...

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Nov 9, 2013
1 parent 7b1f402 commit 22a8cb8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/cell/spufs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
if (!dump_emit(cprm, fullname, en.n_namesz))
goto Eio;

if (!dump_skip(cprm, roundup(cprm->written, 4) - cprm->written))
if (!dump_align(cprm, 4))
goto Eio;

do {
Expand Down
10 changes: 2 additions & 8 deletions fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,6 @@ static int notesize(struct memelfnote *en)
return sz;
}

static int alignfile(struct coredump_params *cprm)
{
static const char buf[4] = { 0, };
return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written);
}

static int writenote(struct memelfnote *men, struct coredump_params *cprm)
{
struct elf_note en;
Expand All @@ -1239,8 +1233,8 @@ static int writenote(struct memelfnote *men, struct coredump_params *cprm)
en.n_type = men->type;

return dump_emit(cprm, &en, sizeof(en)) &&
dump_emit(cprm, men->name, en.n_namesz) && alignfile(cprm) &&
dump_emit(cprm, men->data, men->datasz) && alignfile(cprm);
dump_emit(cprm, men->name, en.n_namesz) && dump_align(cprm, 4) &&
dump_emit(cprm, men->data, men->datasz) && dump_align(cprm, 4);
}

static void fill_elf_header(struct elfhdr *elf, int segs,
Expand Down
10 changes: 2 additions & 8 deletions fs/binfmt_elf_fdpic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,12 +1267,6 @@ static int notesize(struct memelfnote *en)

/* #define DEBUG */

static int alignfile(struct coredump_params *cprm)
{
static const char buf[4] = { 0, };
return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written);
}

static int writenote(struct memelfnote *men, struct coredump_params *cprm)
{
struct elf_note en;
Expand All @@ -1281,8 +1275,8 @@ static int writenote(struct memelfnote *men, struct coredump_params *cprm)
en.n_type = men->type;

return dump_emit(cprm, &en, sizeof(en)) &&
dump_emit(cprm, men->name, en.n_namesz) && alignfile(cprm) &&
dump_emit(cprm, men->data, men->datasz) && alignfile(cprm);
dump_emit(cprm, men->name, en.n_namesz) && dump_align(cprm, 4) &&
dump_emit(cprm, men->data, men->datasz) && dump_align(cprm, 4);
}

static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs)
Expand Down
9 changes: 9 additions & 0 deletions fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,12 @@ int dump_skip(struct coredump_params *cprm, size_t nr)
}
}
EXPORT_SYMBOL(dump_skip);

int dump_align(struct coredump_params *cprm, int align)
{
unsigned mod = cprm->written & (align - 1);
if (align & (align - 1))
return -EINVAL;
return mod ? dump_skip(cprm, align - mod) : 0;
}
EXPORT_SYMBOL(dump_align);
1 change: 1 addition & 0 deletions include/linux/coredump.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
struct coredump_params;
extern int dump_skip(struct coredump_params *cprm, size_t nr);
extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
extern int dump_align(struct coredump_params *cprm, int align);
#ifdef CONFIG_COREDUMP
extern void do_coredump(siginfo_t *siginfo);
#else
Expand Down

0 comments on commit 22a8cb8

Please sign in to comment.