elf_data.c (210324) | elf_data.c (210338) |
---|---|
1/*- 2 * Copyright (c) 2006 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 Joseph Koshy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libelf/elf_data.c 210324 2010-07-21 08:54:46Z kaiw $"); | 28__FBSDID("$FreeBSD: head/lib/libelf/elf_data.c 210338 2010-07-21 10:25:02Z kaiw $"); |
29 30#include <assert.h> 31#include <errno.h> 32#include <libelf.h> 33#include <stdlib.h> 34 35#include "_libelf.h" 36 37 38Elf_Data * 39elf_getdata(Elf_Scn *s, Elf_Data *d) 40{ 41 Elf *e; 42 size_t fsz, msz, count; 43 int elfclass, elftype; 44 unsigned int sh_type; 45 uint64_t sh_align, sh_offset, sh_size; | 29 30#include <assert.h> 31#include <errno.h> 32#include <libelf.h> 33#include <stdlib.h> 34 35#include "_libelf.h" 36 37 38Elf_Data * 39elf_getdata(Elf_Scn *s, Elf_Data *d) 40{ 41 Elf *e; 42 size_t fsz, msz, count; 43 int elfclass, elftype; 44 unsigned int sh_type; 45 uint64_t sh_align, sh_offset, sh_size; |
46 void (*xlate)(char *_d, char *_s, size_t _c, int _swap); | 46 int (*xlate)(char *_d, size_t _dsz, char *_s, size_t _c, int _swap); |
47 48 if (s == NULL || (e = s->s_elf) == NULL || e->e_kind != ELF_K_ELF || 49 (d != NULL && s != d->d_scn)) { 50 LIBELF_SET_ERROR(ARGUMENT, 0); 51 return (NULL); 52 } 53 54 if (d == NULL && (d = STAILQ_FIRST(&s->s_data)) != NULL) --- 65 unchanged lines hidden (view full) --- 120 121 if ((d->d_buf = malloc(msz*count)) == NULL) { 122 (void) _libelf_release_data(d); 123 LIBELF_SET_ERROR(RESOURCE, 0); 124 return (NULL); 125 } 126 127 d->d_flags |= LIBELF_F_MALLOCED; | 47 48 if (s == NULL || (e = s->s_elf) == NULL || e->e_kind != ELF_K_ELF || 49 (d != NULL && s != d->d_scn)) { 50 LIBELF_SET_ERROR(ARGUMENT, 0); 51 return (NULL); 52 } 53 54 if (d == NULL && (d = STAILQ_FIRST(&s->s_data)) != NULL) --- 65 unchanged lines hidden (view full) --- 120 121 if ((d->d_buf = malloc(msz*count)) == NULL) { 122 (void) _libelf_release_data(d); 123 LIBELF_SET_ERROR(RESOURCE, 0); 124 return (NULL); 125 } 126 127 d->d_flags |= LIBELF_F_MALLOCED; |
128 STAILQ_INSERT_TAIL(&s->s_data, d, d_next); | |
129 130 xlate = _libelf_get_translator(elftype, ELF_TOMEMORY, elfclass); | 128 129 xlate = _libelf_get_translator(elftype, ELF_TOMEMORY, elfclass); |
131 (*xlate)(d->d_buf, e->e_rawfile + sh_offset, count, e->e_byteorder != 132 LIBELF_PRIVATE(byteorder)); | 130 if (!(*xlate)(d->d_buf, d->d_size, e->e_rawfile + sh_offset, count, 131 e->e_byteorder != LIBELF_PRIVATE(byteorder))) { 132 _libelf_release_data(d); 133 LIBELF_SET_ERROR(DATA, 0); 134 return (NULL); 135 } |
133 | 136 |
137 STAILQ_INSERT_TAIL(&s->s_data, d, d_next); 138 |
|
134 return (d); 135} 136 137Elf_Data * 138elf_newdata(Elf_Scn *s) 139{ 140 Elf *e; 141 Elf_Data *d; --- 90 unchanged lines hidden --- | 139 return (d); 140} 141 142Elf_Data * 143elf_newdata(Elf_Scn *s) 144{ 145 Elf *e; 146 Elf_Data *d; --- 90 unchanged lines hidden --- |