libelf_xlate.c (173924) | libelf_xlate.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/libelf_xlate.c 173924 2007-11-26 03:09:33Z jkoshy $"); | 28__FBSDID("$FreeBSD: head/lib/libelf/libelf_xlate.c 210338 2010-07-21 10:25:02Z kaiw $"); |
29 30#include <assert.h> 31#include <libelf.h> 32 33#include "_libelf.h" 34 35/* 36 * Translate to/from the file representation of ELF objects. --- 6 unchanged lines hidden (view full) --- 43 * can differ from their in-memory representation. 44 * - a change in representation due to a layout version change. 45 */ 46 47Elf_Data * 48_libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding, 49 int elfclass, int direction) 50{ | 29 30#include <assert.h> 31#include <libelf.h> 32 33#include "_libelf.h" 34 35/* 36 * Translate to/from the file representation of ELF objects. --- 6 unchanged lines hidden (view full) --- 43 * can differ from their in-memory representation. 44 * - a change in representation due to a layout version change. 45 */ 46 47Elf_Data * 48_libelf_xlate(Elf_Data *dst, const Elf_Data *src, unsigned int encoding, 49 int elfclass, int direction) 50{ |
51 int byteswap; |
|
51 size_t cnt, dsz, fsz, msz; 52 uintptr_t sb, se, db, de; 53 54 if (encoding == ELFDATANONE) 55 encoding = LIBELF_PRIVATE(byteorder); 56 57 if ((encoding != ELFDATA2LSB && encoding != ELFDATA2MSB) || 58 dst == NULL || src == NULL || dst == src) { --- 68 unchanged lines hidden (view full) --- 127 _libelf_malign(src->d_type, elfclass)) { 128 LIBELF_SET_ERROR(DATA, 0); 129 return (NULL); 130 } 131 132 dst->d_type = src->d_type; 133 dst->d_size = dsz; 134 | 52 size_t cnt, dsz, fsz, msz; 53 uintptr_t sb, se, db, de; 54 55 if (encoding == ELFDATANONE) 56 encoding = LIBELF_PRIVATE(byteorder); 57 58 if ((encoding != ELFDATA2LSB && encoding != ELFDATA2MSB) || 59 dst == NULL || src == NULL || dst == src) { --- 68 unchanged lines hidden (view full) --- 128 _libelf_malign(src->d_type, elfclass)) { 129 LIBELF_SET_ERROR(DATA, 0); 130 return (NULL); 131 } 132 133 dst->d_type = src->d_type; 134 dst->d_size = dsz; 135 |
136 byteswap = encoding != LIBELF_PRIVATE(byteorder); 137 |
|
135 if (src->d_size == 0 || | 138 if (src->d_size == 0 || |
136 (db == sb && encoding == LIBELF_PRIVATE(byteorder) && fsz == msz)) | 139 (db == sb && !byteswap && fsz == msz)) |
137 return (dst); /* nothing more to do */ 138 | 140 return (dst); /* nothing more to do */ 141 |
139 (_libelf_get_translator(src->d_type, direction, elfclass))(dst->d_buf, 140 src->d_buf, cnt, encoding != LIBELF_PRIVATE(byteorder)); | 142 if (!(_libelf_get_translator(src->d_type, direction, elfclass)) 143 (dst->d_buf, dsz, src->d_buf, cnt, byteswap)) { 144 LIBELF_SET_ERROR(DATA, 0); 145 return (NULL); 146 } |
141 142 return (dst); 143} | 147 148 return (dst); 149} |