diff options
Diffstat (limited to 'src/libelfu/model/elf.c')
-rw-r--r-- | src/libelfu/model/elf.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/libelfu/model/elf.c b/src/libelfu/model/elf.c new file mode 100644 index 0000000..46dc120 --- /dev/null +++ b/src/libelfu/model/elf.c @@ -0,0 +1,51 @@ +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <libelfu/libelfu.h> + + +/* + * Allocation, destruction + */ + +ElfuElf* elfu_mElfAlloc() +{ + ElfuElf *me; + + me = malloc(sizeof(ElfuElf)); + if (!me) { + ELFU_WARN("mElfAlloc: malloc() failed for ElfuElf.\n"); + return NULL; + } + + memset(me, 0, sizeof(*me)); + + CIRCLEQ_INIT(&me->phdrList); + CIRCLEQ_INIT(&me->orphanScnList); + + return me; +} + + +void elfu_mElfDestroy(ElfuElf* me) +{ + ElfuPhdr *mp; + ElfuScn *ms; + + assert(me); + + CIRCLEQ_INIT(&me->phdrList); + CIRCLEQ_INIT(&me->orphanScnList); + + CIRCLEQ_FOREACH(mp, &me->phdrList, elem) { + CIRCLEQ_REMOVE(&me->phdrList, mp, elem); + elfu_mPhdrDestroy(mp); + } + + CIRCLEQ_FOREACH(ms, &me->orphanScnList, elem) { + CIRCLEQ_REMOVE(&me->orphanScnList, ms, elem); + elfu_mScnDestroy(ms); + } + + free(me); +} |