[CRIU] [PATCH 1/9] pie: make util-vdso a little less 64-specific
Dmitry Safonov
dsafonov at virtuozzo.com
Wed Mar 30 08:34:00 PDT 2016
On 03/30/2016 06:12 PM, Dmitry Safonov wrote:
> Add Elf32 types and wrap them with Elf64 into some more generic types.
> This is for parsing vDSO from image file.
Oh, it should say that this is for pie parsing vDSO too,
but I forget to glance this commit after cherry-picking.
>
> Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
> ---
> criu/include/util-vdso.h | 28 ++++++++++++++++++++++++++++
> criu/pie/util-vdso.c | 39 +++++++++++++++++++++++----------------
> 2 files changed, 51 insertions(+), 16 deletions(-)
>
> diff --git a/criu/include/util-vdso.h b/criu/include/util-vdso.h
> index c8dfa054f825..d3903572a97c 100644
> --- a/criu/include/util-vdso.h
> +++ b/criu/include/util-vdso.h
> @@ -49,6 +49,34 @@ struct vdso_symtable {
> }, \
> }
>
> +#ifdef CONFIG_X86_32
> +
> +#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
> +
> +#else /* !CONFIG_X86_32 */
> +
> +#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
> +
> +#endif /* !CONFIG_X86_32 */
> +
> /* Size of VMA associated with vdso */
> static inline unsigned long vdso_vma_size(struct vdso_symtable *t)
> {
> diff --git a/criu/pie/util-vdso.c b/criu/pie/util-vdso.c
> index e93b110fe43b..ebdc4f4d3d75 100644
> --- a/criu/pie/util-vdso.c
> +++ b/criu/pie/util-vdso.c
> @@ -53,27 +53,34 @@ int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
> ARCH_VDSO_SYMBOLS
> };
>
> - 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;
> + 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;
>
> /*
> * 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;
> @@ -177,15 +184,15 @@ int vdso_fill_symtable(char *mem, size_t size, struct vdso_symtable *t)
> k = elf_hash((const unsigned char *)symbol);
>
> 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];
--
Regards,
Dmitry Safonov
More information about the CRIU
mailing list