1 /* Get symbol version definition 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
29 GElf_Verdef *
gelf_getverdef(data,offset,dst)30 gelf_getverdef (data, offset, dst)
31 Elf_Data *data;
32 int offset;
33 GElf_Verdef *dst;
34 {
35 GElf_Verdef *result;
36
37 if (data == NULL)
38 return NULL;
39
40 if (unlikely (data->d_type != ELF_T_VDEF))
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. */
48 assert (sizeof (GElf_Verdef) == sizeof (Elf32_Verdef));
49 assert (sizeof (GElf_Verdef) == sizeof (Elf64_Verdef));
50
51 rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
52
53 /* The data is already in the correct form. Just make sure the
54 index is OK. */
55 if (unlikely (offset < 0)
56 || unlikely (offset + sizeof (GElf_Verdef) > data->d_size)
57 || unlikely (offset % __alignof__ (GElf_Verdef) != 0))
58 {
59 __libelf_seterrno (ELF_E_OFFSET_RANGE);
60 result = NULL;
61 }
62 else
63 result = (GElf_Verdef *) memcpy (dst, (char *) data->d_buf + offset,
64 sizeof (GElf_Verdef));
65
66 rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
67
68 return result;
69 }
70