void elfu_mRelocate(ElfuElf *metarget, ElfuScn *mstarget, ElfuScn *msrt);
-size_t elfu_mPhdrCount(ElfuElf *me);
-void elfu_mPhdrUpdateChildOffsets(ElfuPhdr *mp);
+ size_t elfu_mPhdrCount(ElfuElf *me);
+ void elfu_mPhdrUpdateChildOffsets(ElfuPhdr *mp);
+ElfuPhdr* elfu_mPhdrAlloc();
typedef void* (SectionHandlerFunc)(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2);
ElfuScn* elfu_mScnByOldscn(ElfuElf *me, ElfuScn *oldscn);
char* elfu_mScnName(ElfuElf *me, ElfuScn *ms);
ElfuScn** elfu_mScnSortedByOffset(ElfuElf *me, size_t *count);
-ElfuScn* elfu_mScnAlloc();
+ ElfuScn* elfu_mScnAlloc();
GElf_Addr elfu_mLayoutGetSpaceInPhdr(ElfuElf *me, GElf_Word size,
#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
#include <libelfu/libelfu.h>
ms->shdr.sh_offset = mp->phdr.p_offset + (ms->shdr.sh_addr - mp->phdr.p_vaddr);
}
}
+
+
+
+/*
+ * Allocation, destruction
+ */
+
+ElfuPhdr* elfu_mPhdrAlloc()
+{
+ ElfuPhdr *mp;
+
+ mp = malloc(sizeof(ElfuPhdr));
+ if (!mp) {
+ ELFU_WARN("mPhdrAlloc: malloc() failed for ElfuPhdr.\n");
+ return NULL;
+ }
+
+ memset(mp, 0, sizeof(*mp));
+
+ CIRCLEQ_INIT(&mp->childScnList);
+ CIRCLEQ_INIT(&mp->childPhdrList);
+
+ return mp;
+}
assert(phdr);
- mp = malloc(sizeof(ElfuPhdr));
+ mp = elfu_mPhdrAlloc();
if (!mp) {
- ELFU_WARN("modelFromPhdr: malloc() failed for ElfuPhdr.\n");
return NULL;
}
mp->phdr = *phdr;
- CIRCLEQ_INIT(&mp->childScnList);
- CIRCLEQ_INIT(&mp->childPhdrList);
-
return mp;
}