PERFORCE change 103901 for review
John Birrell
jb at FreeBSD.org
Mon Aug 14 20:35:58 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=103901
Change 103901 by jb at 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)
{
More information about the p4-projects
mailing list