1/* Get additional required symbol version information at the given offset. 2 Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc. 3 Written by Ulrich Drepper <drepper@redhat.com>, 1999. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, version 2. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software Foundation, 16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 17 18#ifdef HAVE_CONFIG_H 19# include <config.h> 20#endif 21 22#include <assert.h> 23#include <gelf.h> 24#include <string.h> 25 26#include "libelfP.h" 27 28 29GElf_Vernaux * 30gelf_getvernaux (data, offset, dst) 31 Elf_Data *data; 32 int offset; 33 GElf_Vernaux *dst; 34{ 35 GElf_Vernaux *result; 36 37 if (data == NULL) 38 return NULL; 39 40 if (unlikely (data->d_type != ELF_T_VNEED)) 41 { 42 __libelf_seterrno (ELF_E_INVALID_HANDLE); 43 return NULL; 44 } 45 46 /* It's easy to handle this type. It has the same size for 32 and 47 64 bit objects. And fortunately the `ElfXXX_Vernaux' records 48 also have the same size. */ 49 assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Verneed)); 50 assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Verneed)); 51 assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux)); 52 assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux)); 53 54 rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock); 55 56 /* The data is already in the correct form. Just make sure the 57 index is OK. */ 58 if (unlikely (offset < 0) 59 || unlikely (offset + sizeof (GElf_Vernaux) > data->d_size) 60 || unlikely (offset % sizeof (GElf_Vernaux) != 0)) 61 { 62 __libelf_seterrno (ELF_E_OFFSET_RANGE); 63 result = NULL; 64 } 65 else 66 result = (GElf_Vernaux *) memcpy (dst, (char *) data->d_buf + offset, 67 sizeof (GElf_Verneed)); 68 69 rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock); 70 71 return result; 72} 73