summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2006-07-05 19:05:55 +0000
committerMike Frysinger <vapier@gentoo.org>2006-07-05 19:05:55 +0000
commitb536763f513920b64d73ead1bd7b083159866a85 (patch)
treed4d3b8291e918c1abbafa95a5dccc9d1f77584ba
parente5657ed358ddb5956171df3144e4e698205de1b4 (diff)
patch from Bernd Schmidt to abstract away load address checks
-rw-r--r--ldso/include/dl-defs.h15
-rw-r--r--ldso/libdl/libdl.c10
2 files changed, 18 insertions, 7 deletions
diff --git a/ldso/include/dl-defs.h b/ldso/include/dl-defs.h
index 2d4f1d655..18f718bef 100644
--- a/ldso/include/dl-defs.h
+++ b/ldso/include/dl-defs.h
@@ -75,4 +75,19 @@ typedef struct {
((LOADADDR) = (BASEADDR))
#endif
+/* Test whether a given ADDR is more likely to be within the memory
+ * region mapped to TPNT (a struct elf_resolve *) than to TFROM.
+ * Everywhere that this is used, TFROM is initially NULL, and whenever
+ * a potential match is found, it's updated. One might want to walk
+ * the chain of elf_resolve to locate the best match and return false
+ * whenever TFROM is non-NULL, or use an exact-matching algorithm
+ * using additional information encoded in DL_LOADADDR_TYPE to test
+ * for exact containment.
+ */
+#ifndef DL_ADDR_IN_LOADADDR
+# define DL_ADDR_IN_LOADADDR(ADDR, TPNT, TFROM) \
+ ((void*)(TPNT)->loadaddr < (void*)(ADDR) \
+ && (!(TFROM) || (TFROM)->loadaddr < (TPNT)->loadaddr))
+#endif
+
#endif /* _LD_DEFS_H */
diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
index 322230860..418a720e0 100644
--- a/ldso/libdl/libdl.c
+++ b/ldso/libdl/libdl.c
@@ -175,8 +175,7 @@ void *dlopen(const char *libname, int flag)
tfrom = NULL;
for (dpnt = _dl_symbol_tables; dpnt; dpnt = dpnt->next) {
tpnt = dpnt->dyn;
- if (tpnt->loadaddr < from
- && (tfrom == NULL || tfrom->loadaddr < tpnt->loadaddr))
+ if (DL_ADDR_IN_LOADADDR(from, tpnt, tfrom))
tfrom = tpnt;
}
}
@@ -436,8 +435,7 @@ void *dlsym(void *vhandle, const char *name)
tfrom = NULL;
for (rpnt = _dl_symbol_tables; rpnt; rpnt = rpnt->next) {
tpnt = rpnt->dyn;
- if (tpnt->loadaddr < from
- && (tfrom == NULL || tfrom->loadaddr < tpnt->loadaddr)) {
+ if (DL_ADDR_IN_LOADADDR(from, tpnt, tfrom)) {
tfrom = tpnt;
handle = rpnt->next;
}
@@ -664,10 +662,8 @@ int dladdr(const void *__address, Dl_info * __info)
fprintf(stderr, "Module \"%s\" at %p\n",
tpnt->libname, tpnt->loadaddr);
#endif
- if (tpnt->loadaddr < (ElfW(Addr)) __address
- && (pelf == NULL || pelf->loadaddr < tpnt->loadaddr)) {
+ if (DL_ADDR_IN_LOADADDR((ElfW(Addr)) __address, tpnt, pelf))
pelf = tpnt;
- }
}
if (!pelf) {