1/* Get additional symbol information from symbol table at the given index.
2   Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
3   Written by Ulrich Drepper <drepper@redhat.com>, 2000.
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_Syminfo *
30gelf_getsyminfo (data, ndx, dst)
31     Elf_Data *data;
32     int ndx;
33     GElf_Syminfo *dst;
34{
35  GElf_Syminfo *result = NULL;
36
37  if (data == NULL)
38    return NULL;
39
40  if (unlikely (data->d_type != ELF_T_SYMINFO))
41    {
42      __libelf_seterrno (ELF_E_INVALID_HANDLE);
43      return NULL;
44    }
45
46  /* The types for 32 and 64 bit are the same.  Lucky us.  */
47  assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo));
48  assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo));
49
50  rwlock_rdlock (((Elf_Data_Scn *) data)->s->elf->lock);
51
52  /* The data is already in the correct form.  Just make sure the
53     index is OK.  */
54  if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size))
55    {
56      __libelf_seterrno (ELF_E_INVALID_INDEX);
57      goto out;
58    }
59
60  *dst = ((GElf_Syminfo *) data->d_buf)[ndx];
61
62  result = dst;
63
64 out:
65  rwlock_unlock (((Elf_Data_Scn *) data)->s->elf->lock);
66
67  return result;
68}
69