diff options
Diffstat (limited to 'src/libelfu/model/phdr.c')
-rw-r--r-- | src/libelfu/model/phdr.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/libelfu/model/phdr.c b/src/libelfu/model/phdr.c index 6896845..1159fbb 100644 --- a/src/libelfu/model/phdr.c +++ b/src/libelfu/model/phdr.c @@ -4,22 +4,62 @@ #include <libelfu/libelfu.h> -size_t elfu_mPhdrCount(ElfuElf *me) +/* Meta-functions */ + +void* elfu_mPhdrForall(ElfuElf *me, PhdrHandlerFunc f, void *aux1, void *aux2) { ElfuPhdr *mp; + + CIRCLEQ_FOREACH(mp, &me->phdrList, elem) { + ElfuPhdr *mp2; + void *rv = f(me, mp, aux1, aux2); + if (rv) { + return rv; + } + + CIRCLEQ_FOREACH(mp2, &mp->childPhdrList, elemChildPhdr) { + void *rv = f(me, mp2, aux1, aux2); + if (rv) { + return rv; + } + } + } + + return NULL; +} + + + + +/* Counting */ + +static void* subCounter(ElfuElf *me, ElfuPhdr *mp, void *aux1, void *aux2) +{ + size_t *i = (size_t*)aux1; + (void)aux2; + + *i += 1; + + /* Continue */ + return NULL; +} + + +size_t elfu_mPhdrCount(ElfuElf *me) +{ size_t i = 0; assert(me); - CIRCLEQ_FOREACH(mp, &me->phdrList, elem) { - i++; - } + elfu_mPhdrForall(me, subCounter, &i, NULL); return i; } +/* Layout update */ + void elfu_mPhdrUpdateChildOffsets(ElfuPhdr *mp) { ElfuScn *ms; @@ -69,7 +109,8 @@ void elfu_mPhdrDestroy(ElfuPhdr* mp) assert(mp); CIRCLEQ_FOREACH(mp2, &mp->childPhdrList, elem) { - // TODO ? + CIRCLEQ_REMOVE(&mp->childPhdrList, mp2, elem); + elfu_mPhdrDestroy(mp2); } CIRCLEQ_FOREACH(ms, &mp->childScnList, elem) { |