[CRIU] [PATCH 3/9] pie/util-vdso: separate has_elf_identity
Dmitry Safonov
dsafonov at virtuozzo.com
Wed Mar 30 08:12:24 PDT 2016
Impact: refactor
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
criu/pie/util-vdso.c | 48 ++++++++++++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 20 deletions(-)
diff --git a/criu/pie/util-vdso.c b/criu/pie/util-vdso.c
index ed24ff95a94a..b388916fbc2f 100644
--- a/criu/pie/util-vdso.c
+++ b/criu/pie/util-vdso.c
@@ -50,6 +50,33 @@ static unsigned long elf_hash(const unsigned char *name)
return h;
}
+static int has_elf_identity(Ehdr_t *ehdr)
+{
+ /*
+ * See Elf specification for this magic values.
+ */
+#if defined(CONFIG_X86_32)
+ static const char elf_ident[] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+#else
+ static const char elf_ident[] = {
+ 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+#endif
+
+ BUILD_BUG_ON(sizeof(elf_ident) != sizeof(ehdr->e_ident));
+
+ if (builtin_memcmp(ehdr->e_ident, elf_ident, sizeof(elf_ident))) {
+ pr_err("Elf header magic mismatch\n");
+ return false;
+ }
+
+ return true;
+}
+
int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
{
const char *vdso_symbols[VDSO_SYMBOL_MAX] = {
@@ -72,35 +99,16 @@ int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
uintptr_t addr;
- /*
- * See Elf specification for this magic values.
- */
-#if defined(CONFIG_X86_32)
- static const char elf_ident[] = {
- 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
-#else
- static const char elf_ident[] = {
- 0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
-#endif
-
char *dynsymbol_names;
unsigned int i, j, k;
- BUILD_BUG_ON(sizeof(elf_ident) != sizeof(ehdr->e_ident));
-
pr_debug("Parsing at %lx %lx\n", (long)mem, (long)mem + (long)size);
/*
* Make sure it's a file we support.
*/
- if (builtin_memcmp(ehdr->e_ident, elf_ident, sizeof(elf_ident))) {
- pr_err("Elf header magic mismatch\n");
+ if (!has_elf_identity(ehdr))
return -EINVAL;
- }
/*
* We need PT_LOAD and PT_DYNAMIC here. Each once.
--
2.7.4
More information about the CRIU
mailing list