summaryrefslogtreecommitdiff
path: root/src/model/section.c
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-06-01 17:42:36 +0100
committernorly <ny-git@enpas.org>2013-06-03 02:08:46 +0100
commitd217921268e5b2d9e38023c25e55dc315b8e3263 (patch)
tree801a0e9248d071a8f7f98e1bef4d8c87692b059a /src/model/section.c
parent030aeb591f867263f734ca2e232c45dc98f3ec50 (diff)
Basic 32-bit SYMTAB and REL (not RELA) support
Diffstat (limited to 'src/model/section.c')
-rw-r--r--src/model/section.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/model/section.c b/src/model/section.c
index 4b8b230..a96377c 100644
--- a/src/model/section.c
+++ b/src/model/section.c
@@ -5,7 +5,7 @@
/* Meta-functions */
-int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2)
+void* elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2)
{
ElfuPhdr *mp;
ElfuScn *ms;
@@ -18,7 +18,7 @@ int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2)
}
CIRCLEQ_FOREACH(ms, &mp->childScnList, elemChildScn) {
- int rv = f(me, ms, aux1, aux2);
+ void *rv = f(me, ms, aux1, aux2);
if (rv) {
return rv;
@@ -27,14 +27,14 @@ int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2)
}
CIRCLEQ_FOREACH(ms, &me->orphanScnList, elemChildScn) {
- int rv = f(me, ms, aux1, aux2);
+ void *rv = f(me, ms, aux1, aux2);
if (rv) {
return rv;
}
}
- return 0;
+ return NULL;
}
@@ -42,18 +42,19 @@ int elfu_mScnForall(ElfuElf *me, SectionHandlerFunc f, void *aux1, void *aux2)
/* Counting */
-static int subCounter(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
+static void* subCounter(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
{
size_t *i = (size_t*)aux1;
ElfuScn *otherScn = (ElfuScn*)aux2;
if (ms == otherScn) {
- return 1;
+ return ms;
}
*i += 1;
- return 0;
+ /* Continue */
+ return NULL;
}
@@ -70,7 +71,7 @@ size_t elfu_mScnCount(ElfuElf *me)
}
-/* Returns the section index equivalent to the model flattened to ELF */
+/* Returns the index a section would have in the flattened ELF */
size_t elfu_mScnIndex(ElfuElf *me, ElfuScn *ms)
{
/* NULL section *is* counted */
@@ -87,6 +88,29 @@ size_t elfu_mScnIndex(ElfuElf *me, ElfuScn *ms)
}
+static void* subOldscn(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
+{
+ ElfuScn *otherScn = (ElfuScn*)aux1;
+ (void)aux2;
+
+ if (ms->oldptr == otherScn) {
+ return ms;
+ }
+
+ /* Continue */
+ return NULL;
+}
+
+/* Returns the section with oldscn == oldscn */
+ElfuScn* elfu_mScnByOldscn(ElfuElf *me, ElfuScn *oldscn)
+{
+ assert(me);
+ assert(oldscn);
+
+ return elfu_mScnForall(me, subOldscn, oldscn, NULL);
+}
+
+
/* Convenience */
@@ -108,7 +132,7 @@ char* elfu_mScnName(ElfuElf *me, ElfuScn *ms)
}
-static int subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
+static void* subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
{
ElfuScn **arr = (ElfuScn**)aux1;
size_t *i = (size_t*)aux2;
@@ -116,7 +140,8 @@ static int subScnsToArray(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
arr[(*i)] = ms;
*i += 1;
- return 0;
+ /* Continue */
+ return NULL;
}
static int cmpScnOffs(const void *ms1, const void *ms2)