1 /* Get move structure 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 <stddef.h> 25 26 #include "libelfP.h" 27 28 29 GElf_Move * 30 gelf_getmove (data, ndx, dst) 31 Elf_Data *data; 32 int ndx; 33 GElf_Move *dst; 34 { 35 GElf_Move *result = NULL; 36 Elf *elf; 37 38 if (data == NULL) 39 return NULL; 40 41 if (unlikely (data->d_type != ELF_T_MOVE)) 42 { 43 __libelf_seterrno (ELF_E_INVALID_HANDLE); 44 return NULL; 45 } 46 47 /* The types for 32 and 64 bit are the same. Lucky us. */ 48 assert (sizeof (GElf_Move) == sizeof (Elf32_Move)); 49 assert (sizeof (GElf_Move) == sizeof (Elf64_Move)); 50 51 /* The data is already in the correct form. Just make sure the 52 index is OK. */ 53 if (unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) 54 { 55 __libelf_seterrno (ELF_E_INVALID_INDEX); 56 goto out; 57 } 58 59 elf = ((Elf_Data_Scn *) data)->s->elf; 60 rwlock_rdlock (elf->lock); 61 62 *dst = ((GElf_Move *) data->d_buf)[ndx]; 63 64 rwlock_unlock (elf->lock); 65 66 result = dst; 67 68 out: 69 return result; 70 } 71