Date: Mon, 14 Aug 2006 20:35:54 GMT From: John Birrell <jb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 103901 for review Message-ID: <200608142035.k7EKZsAJ026762@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103901 Change 103901 by jb@jb_freebsd2 on 2006/08/14 20:35:44 Implement libelf_ehdr() Affected files ... .. //depot/projects/dtrace/src/lib/libelf/gelf_getehdr.c#2 edit Differences ... ==== //depot/projects/dtrace/src/lib/libelf/gelf_getehdr.c#2 (text+ko) ==== @@ -28,12 +28,46 @@ __FBSDID("$FreeBSD$"); #include <assert.h> +#include <errno.h> #include <gelf.h> #include <libelf.h> +#include <stdlib.h> #include <string.h> #include "_libelf.h" +void * +libelf_ehdr(Elf *e, int elfclass, int allocate) +{ + size_t s; + void *eh; + + if (elfclass != e->e_class) { + LIBELF_SET_ERROR(CLASS, elfclass); + return (NULL); + } + + if ((s = _libelf_msize(ELF_T_EHDR, elfclass, EV_CURRENT)) == 0) + return (NULL); + + if (allocate) { + if ((eh = malloc(s)) == NULL) { + LIBELF_SET_ERROR(RESOURCE, errno); + return (NULL); + } + if (elfclass == ELFCLASS32) + memcpy(eh, &e->e_eh32, s); + else + memcpy(eh, &e->e_eh64, s); + + } else if (elfclass == ELFCLASS32) + eh = &e->e_eh32; + else + eh = &e->e_eh64; + + return (eh); +} + Elf32_Ehdr * elf32_getehdr(Elf *e) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200608142035.k7EKZsAJ026762>