-/* Finding */
+/* Finding by exact address/offset */
static void* subFindLoadByAddr(ElfuElf *me, ElfuPhdr *mp, void *aux1, void *aux2)
{
+/* Find lowest/highest address/offset */
+
+void elfu_mPhdrLoadLowestHighest(ElfuElf *me,
+ ElfuPhdr **lowestAddr, ElfuPhdr **highestAddr,
+ ElfuPhdr **lowestOffs, ElfuPhdr **highestOffsEnd)
+{
+ ElfuPhdr *mp;
+
+ assert(me);
+ assert(lowestAddr);
+ assert(highestAddr);
+ assert(lowestOffs);
+ assert(highestOffsEnd);
+
+ *lowestAddr = NULL;
+ *highestAddr = NULL;
+ *lowestOffs = NULL;
+ *highestOffsEnd = NULL;
+
+ /* Find first and last LOAD PHDRs.
+ * Don't compare p_memsz - segments don't overlap in memory. */
+ CIRCLEQ_FOREACH(mp, &me->phdrList, elem) {
+ if (mp->phdr.p_type != PT_LOAD) {
+ continue;
+ }
+ if (!*lowestAddr || mp->phdr.p_vaddr < (*lowestAddr)->phdr.p_vaddr) {
+ *lowestAddr = mp;
+ }
+ if (!*highestAddr || mp->phdr.p_vaddr > (*highestAddr)->phdr.p_vaddr) {
+ *highestAddr = mp;
+ }
+ if (!*lowestOffs || mp->phdr.p_offset < (*lowestOffs)->phdr.p_offset) {
+ *lowestOffs = mp;
+ }
+ if (!*highestOffsEnd
+ || (OFFS_END(mp->phdr.p_offset,
+ mp->phdr.p_filesz)
+ > OFFS_END((*highestOffsEnd)->phdr.p_offset,
+ (*highestOffsEnd)->phdr.p_filesz))) {
+ *highestOffsEnd = mp;
+ }
+ }
+}
+
+
+
+
/* Layout update */
void elfu_mPhdrUpdateChildOffsets(ElfuPhdr *mp)
assert(mp);
- CIRCLEQ_FOREACH(mp2, &mp->childPhdrList, elem) {
- CIRCLEQ_REMOVE(&mp->childPhdrList, mp2, elem);
+ CIRCLEQ_FOREACH(mp2, &mp->childPhdrList, elemChildPhdr) {
+ CIRCLEQ_REMOVE(&mp->childPhdrList, mp2, elemChildPhdr);
elfu_mPhdrDestroy(mp2);
}
- CIRCLEQ_FOREACH(ms, &mp->childScnList, elem) {
- CIRCLEQ_REMOVE(&mp->childScnList, ms, elem);
+ CIRCLEQ_FOREACH(ms, &mp->childScnList, elemChildScn) {
+ CIRCLEQ_REMOVE(&mp->childScnList, ms, elemChildScn);
elfu_mScnDestroy(ms);
}