[CRIU] [PATCH 05/10] zdtm/vdso01/ia32: add ia32 test version

Dmitry Safonov dsafonov at virtuozzo.com
Thu Feb 16 08:20:40 PST 2017


Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 test/zdtm/static/vdso01.c | 81 +++++++++++++++++++++++++++++++++--------------
 1 file changed, 57 insertions(+), 24 deletions(-)

diff --git a/test/zdtm/static/vdso01.c b/test/zdtm/static/vdso01.c
index d4ff920ad3cc..f571a87a8708 100644
--- a/test/zdtm/static/vdso01.c
+++ b/test/zdtm/static/vdso01.c
@@ -18,6 +18,47 @@
 const char *test_doc	= "Check if we can use vDSO using direct vDSO calls\n";
 const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org";
 
+#ifdef __i386__
+
+# define Ehdr_t		Elf32_Ehdr
+# define Sym_t		Elf32_Sym
+# define Phdr_t		Elf32_Phdr
+# define Word_t		Elf32_Word
+# define Dyn_t		Elf32_Dyn
+
+# define ELF_ST_TYPE	ELF32_ST_TYPE
+# define ELF_ST_BIND	ELF32_ST_BIND
+
+const char elf_ident[] = {
+	0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+#else /* non-i386 */
+
+# define Ehdr_t		Elf64_Ehdr
+# define Sym_t		Elf64_Sym
+# define Phdr_t		Elf64_Phdr
+# define Word_t		Elf64_Word
+# define Dyn_t		Elf64_Dyn
+
+# ifndef ELF_ST_TYPE
+#  define ELF_ST_TYPE	ELF64_ST_TYPE
+# endif
+# ifndef ELF_ST_BIND
+#  define ELF_ST_BIND	ELF64_ST_BIND
+# endif
+
+/*
+ * See Elf specification for this magic values.
+ */
+const char elf_ident[] = {
+	0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+#endif
+
 typedef int (__vdso_clock_gettime_t)(clockid_t clock, struct timespec *ts);
 typedef long (__vdso_getcpu_t)(unsigned *cpu, unsigned *node, void *unused);
 typedef int (__vdso_gettimeofday_t)(struct timeval *tv, struct timezone *tz);
@@ -96,27 +137,19 @@ static unsigned long elf_hash(const unsigned char *name)
 
 static int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
 {
-	Elf64_Phdr *dynamic = NULL, *load = NULL;
-	Elf64_Ehdr *ehdr = (void *)mem;
-	Elf64_Dyn *dyn_strtab = NULL;
-	Elf64_Dyn *dyn_symtab = NULL;
-	Elf64_Dyn *dyn_strsz = NULL;
-	Elf64_Dyn *dyn_syment = NULL;
-	Elf64_Dyn *dyn_hash = NULL;
-	Elf64_Word *hash = NULL;
-	Elf64_Phdr *phdr;
-	Elf64_Dyn *d;
-
-	Elf64_Word *bucket, *chain;
-	Elf64_Word nbucket, nchain;
-
-	/*
-	 * See Elf specification for this magic values.
-	 */
-	const char elf_ident[] = {
-		0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	};
+	Phdr_t *dynamic = NULL, *load = NULL;
+	Ehdr_t *ehdr = (void *)mem;
+	Dyn_t *dyn_strtab = NULL;
+	Dyn_t *dyn_symtab = NULL;
+	Dyn_t *dyn_strsz = NULL;
+	Dyn_t *dyn_syment = NULL;
+	Dyn_t *dyn_hash = NULL;
+	Word_t *hash = NULL;
+	Phdr_t *phdr;
+	Dyn_t *d;
+
+	Word_t *bucket, *chain;
+	Word_t nbucket, nchain;
 
 	char *dynsymbol_names;
 	unsigned int i, j, k;
@@ -214,15 +247,15 @@ static int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
 		k = elf_hash((const unsigned char *)vdso_symbols[i]);
 
 		for (j = bucket[k % nbucket]; j < nchain && chain[j] != STN_UNDEF; j = chain[j]) {
-			Elf64_Sym *sym = (void *)&mem[dyn_symtab->d_un.d_ptr - load->p_vaddr];
+			Sym_t *sym = (void *)&mem[dyn_symtab->d_un.d_ptr - load->p_vaddr];
 			char *name;
 
 			sym = &sym[j];
 			if (__ptr_oob(sym, mem, size))
 				continue;
 
-			if (ELF64_ST_TYPE(sym->st_info) != STT_FUNC &&
-			    ELF64_ST_BIND(sym->st_info) != STB_GLOBAL)
+			if (ELF_ST_TYPE(sym->st_info) != STT_FUNC &&
+			    ELF_ST_BIND(sym->st_info) != STB_GLOBAL)
 				continue;
 
 			name = &dynsymbol_names[sym->st_name];
-- 
2.11.1



More information about the CRIU mailing list