1 /* Update additional symbol information in symbol table at the given index. 2 Copyright (C) 2000, 2001, 2002 Red Hat, Inc. 3 Written by Ulrich Drepper <drepper (at) 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 <stdlib.h> 25 26 #include "libelfP.h" 27 28 29 int 30 gelf_update_syminfo (data, ndx, src) 31 Elf_Data *data; 32 int ndx; 33 GElf_Syminfo *src; 34 { 35 Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data; 36 Elf_Scn *scn; 37 int result = 0; 38 39 if (data == NULL) 40 return 0; 41 42 if (unlikely (ndx < 0)) 43 { 44 __libelf_seterrno (ELF_E_INVALID_INDEX); 45 return 0; 46 } 47 48 if (unlikely (data_scn->d.d_type != ELF_T_SYMINFO)) 49 { 50 /* The type of the data better should match. */ 51 __libelf_seterrno (ELF_E_DATA_MISMATCH); 52 return 0; 53 } 54 55 /* The types for 32 and 64 bit are the same. Lucky us. */ 56 assert (sizeof (GElf_Syminfo) == sizeof (Elf32_Syminfo)); 57 assert (sizeof (GElf_Syminfo) == sizeof (Elf64_Syminfo)); 58 59 scn = data_scn->s; 60 rwlock_wrlock (scn->elf->lock); 61 62 /* Check whether we have to resize the data buffer. */ 63 if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) 64 { 65 __libelf_seterrno (ELF_E_INVALID_INDEX); 66 goto out; 67 } 68 69 ((GElf_Syminfo *) data_scn->d.d_buf)[ndx] = *src; 70 71 result = 1; 72 73 /* Mark the section as modified. */ 74 scn->flags |= ELF_F_DIRTY; 75 76 out: 77 rwlock_unlock (scn->elf->lock); 78 79 return result; 80 } 81