dump_skip to given alignment...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
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 {
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;
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,
/* #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;
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)
}
}
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);
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