Changeset View
Changeset View
Standalone View
Standalone View
contrib/elftoolchain/libelf/elf_data.c
Show All 21 Lines | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <libelf.h> | #include <libelf.h> | ||||
#include <stdbool.h> | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
emaste: alpha order | |||||
#include "_libelf.h" | #include "_libelf.h" | ||||
ELFTC_VCSID("$Id: elf_data.c 3466 2016-05-11 18:35:44Z emaste $"); | ELFTC_VCSID("$Id: elf_data.c 3466 2016-05-11 18:35:44Z emaste $"); | ||||
Elf_Data * | Elf_Data * | ||||
elf_getdata(Elf_Scn *s, Elf_Data *ed) | _libelf_getdata(Elf_Scn *s, Elf_Data *ed, bool updating) | ||||
{ | { | ||||
Elf *e; | Elf *e; | ||||
unsigned int sh_type; | unsigned int sh_type; | ||||
int elfclass, elftype; | int elfclass, elftype; | ||||
size_t count, fsz, msz; | size_t count, fsz, msz; | ||||
struct _Libelf_Data *d; | struct _Libelf_Data *d; | ||||
uint64_t sh_align, sh_offset, sh_size; | uint64_t sh_align, sh_offset, sh_size; | ||||
int (*xlate)(unsigned char *_d, size_t _dsz, unsigned char *_s, | int (*xlate)(unsigned char *_d, size_t _dsz, unsigned char *_s, | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | _libelf_getdata(Elf_Scn *s, Elf_Data *ed, bool updating) | ||||
if (sh_type == SHT_NULL) { | if (sh_type == SHT_NULL) { | ||||
LIBELF_SET_ERROR(SECTION, 0); | LIBELF_SET_ERROR(SECTION, 0); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST || | if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST || | ||||
elftype > ELF_T_LAST || (sh_type != SHT_NOBITS && | elftype > ELF_T_LAST || (sh_type != SHT_NOBITS && | ||||
(sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset))) { | (!updating && | ||||
(sh_offset > e->e_rawsize || | |||||
sh_size > e->e_rawsize - sh_offset)))) { | |||||
LIBELF_SET_ERROR(SECTION, 0); | LIBELF_SET_ERROR(SECTION, 0); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
if ((fsz = (elfclass == ELFCLASS32 ? elf32_fsize : elf64_fsize) | if ((fsz = (elfclass == ELFCLASS32 ? elf32_fsize : elf64_fsize) | ||||
(elftype, (size_t) 1, e->e_version)) == 0) { | (elftype, (size_t) 1, e->e_version)) == 0) { | ||||
LIBELF_SET_ERROR(UNIMPL, 0); | LIBELF_SET_ERROR(UNIMPL, 0); | ||||
return (NULL); | return (NULL); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | _libelf_getdata(Elf_Scn *s, Elf_Data *ed, bool updating) | ||||
} | } | ||||
STAILQ_INSERT_TAIL(&s->s_data, d, d_next); | STAILQ_INSERT_TAIL(&s->s_data, d, d_next); | ||||
return (&d->d_data); | return (&d->d_data); | ||||
} | } | ||||
Elf_Data * | Elf_Data * | ||||
elf_getdata(Elf_Scn *s, Elf_Data *ed) | |||||
{ | |||||
return (_libelf_getdata(s, ed, false)); | |||||
} | |||||
Elf_Data * | |||||
elf_newdata(Elf_Scn *s) | elf_newdata(Elf_Scn *s) | ||||
{ | { | ||||
Elf *e; | Elf *e; | ||||
struct _Libelf_Data *d; | struct _Libelf_Data *d; | ||||
if (s == NULL || (e = s->s_elf) == NULL) { | if (s == NULL || (e = s->s_elf) == NULL) { | ||||
LIBELF_SET_ERROR(ARGUMENT, 0); | LIBELF_SET_ERROR(ARGUMENT, 0); | ||||
return (NULL); | return (NULL); | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | elf_rawdata(Elf_Scn *s, Elf_Data *ed) | ||||
} | } | ||||
if (sh_type == SHT_NULL) { | if (sh_type == SHT_NULL) { | ||||
LIBELF_SET_ERROR(SECTION, 0); | LIBELF_SET_ERROR(SECTION, 0); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
if (sh_type != SHT_NOBITS && | if (sh_type != SHT_NOBITS && | ||||
(sh_offset > e->e_rawsize || sh_size > e->e_rawsize - sh_offset)) { | (!updating && | ||||
(sh_offset > e->e_rawsize || | |||||
sh_size > e->e_rawsize - sh_offset))) { | |||||
LIBELF_SET_ERROR(SECTION, 0); | LIBELF_SET_ERROR(SECTION, 0); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
if ((d = _libelf_allocate_data(s)) == NULL) | if ((d = _libelf_allocate_data(s)) == NULL) | ||||
return (NULL); | return (NULL); | ||||
d->d_data.d_buf = (sh_type == SHT_NOBITS || sh_size == 0) ? NULL : | d->d_data.d_buf = (sh_type == SHT_NOBITS || sh_size == 0) ? NULL : | ||||
Show All 11 Lines |
alpha order