2 Copyright (C) 2000, 2001, 2002, 2010 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
9 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version
19 or both in parallel, as here.
21 elfutils is distributed in the hope that it will be useful, but
22 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
26 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
41 gelf_update_ehdr (Elf *elf, GElf_Ehdr *src)
48 if (unlikely (elf->kind != ELF_K_ELF))
50 __libelf_seterrno (ELF_E_INVALID_HANDLE);
54 rwlock_wrlock (elf->lock);
56 if (elf->class == ELFCLASS32)
58 Elf32_Ehdr *ehdr = elf->state.elf32.ehdr;
62 __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
66 /* We have to convert the data to the 32 bit format. This might
67 overflow some fields so we have to test for this case before
69 if (unlikely (src->e_entry > 0xffffffffull)
70 || unlikely (src->e_phoff > 0xffffffffull)
71 || unlikely (src->e_shoff > 0xffffffffull))
73 __libelf_seterrno (ELF_E_INVALID_DATA);
78 memcpy (ehdr->e_ident, src->e_ident, EI_NIDENT);
80 ehdr->name = src->name
97 Elf64_Ehdr *ehdr = elf->state.elf64.ehdr;
101 __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
105 /* Just copy the data. */
106 memcpy (ehdr, src, sizeof (Elf64_Ehdr));
109 /* Mark the ELF header as modified. */
110 elf->state.elf.ehdr_flags |= ELF_F_DIRTY;
115 rwlock_unlock (elf->lock);