summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2013-10-08 11:05:01 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2013-11-09 00:16:27 -0500
commit22a8cb8248ba5d340307ba72432253b1dbdb5cf7 (patch)
treeddb88cce781598c909769c4d92f1e38d2716cd52 /fs
parent7b1f4020d0d16a17b9c48570bdb7b4ad99be3553 (diff)
new helper: dump_align()
dump_skip to given alignment... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/binfmt_elf.c10
-rw-r--r--fs/binfmt_elf_fdpic.c10
-rw-r--r--fs/coredump.c9
3 files changed, 13 insertions, 16 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index c56ae3264a65..864154972670 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -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;
@@ -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,
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index a69fc4ae1c85..645f6e56f378 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -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;
@@ -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)
diff --git a/fs/coredump.c b/fs/coredump.c
index 18baf2c009d4..dc1f937413d5 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -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);