• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Update additional required symbol version information.
2    Copyright (C) 2001, 2002 Red Hat, Inc.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2001.
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 int
gelf_update_vernaux(data,offset,src)30 gelf_update_vernaux (data, offset, src)
31      Elf_Data *data;
32      int offset;
33      GElf_Vernaux *src;
34 {
35   Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
36 
37   if (data == NULL)
38     return 0;
39 
40   /* The types for 32 and 64 bit are the same.  Lucky us.  */
41   assert (sizeof (GElf_Vernaux) == sizeof (Elf32_Vernaux));
42   assert (sizeof (GElf_Vernaux) == sizeof (Elf64_Vernaux));
43 
44   /* Check whether we have to resize the data buffer.  */
45   if (unlikely (offset < 0)
46       || unlikely ((offset + sizeof (GElf_Vernaux)) > data_scn->d.d_size))
47     {
48       __libelf_seterrno (ELF_E_INVALID_INDEX);
49       return 0;
50     }
51 
52   if (unlikely (data_scn->d.d_type != ELF_T_VNEED))
53     {
54       /* The type of the data better should match.  */
55       __libelf_seterrno (ELF_E_DATA_MISMATCH);
56       return 0;
57     }
58 
59   rwlock_wrlock (data_scn->s->elf->lock);
60 
61   memcpy ((char *) data_scn->d.d_buf + offset, src, sizeof (GElf_Vernaux));
62 
63   /* Mark the section as modified.  */
64   data_scn->s->flags |= ELF_F_DIRTY;
65 
66   rwlock_unlock (data_scn->s->elf->lock);
67 
68   return 1;
69 }
70