summaryrefslogtreecommitdiff
path: root/src/linker
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-02-25 15:34:03 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-02-25 15:34:03 +0200
commitfb212eaa87d94f48d65925713b5a5bbf33eebf8b (patch)
tree5f28f39f3d7fe4f03ad5115282d31a2cb9e2176c /src/linker
parentb3c829d681287fd14c26ca25c6e188db37d1ef03 (diff)
dlfcn: Try dlsym glibc symbols first
Diffstat (limited to 'src/linker')
-rw-r--r--src/linker/dlfcn.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/linker/dlfcn.c b/src/linker/dlfcn.c
index a044094..b8d2914 100644
--- a/src/linker/dlfcn.c
+++ b/src/linker/dlfcn.c
@@ -89,6 +89,8 @@ enum {
WRAPPER_DYNHOOK,
};
+#define MIN(a,b) (((a)<(b))?(a):(b))
+
void *bionic_dlsym(void *handle, const char *symbol)
{
soinfo *found;
@@ -106,21 +108,17 @@ void *bionic_dlsym(void *handle, const char *symbol)
goto err;
}
-#if 0
- void *sym_addr;
- if(0 != (sym_addr = apkenv_get_hooked_symbol_dlfcn(handle, symbol)))
{
- LINKER_DEBUG_PRINTF("symbol %s hooked to %x\n",symbol,sym_addr);
- pthread_mutex_unlock(&apkenv_dl_lock);
- return sym_addr;
- }
-
- if (is_builtin_lib_handle(handle)) {
- /* must be hooked.. */
- set_dlerror(DL_ERR_SYMBOL_NOT_FOUND);
- goto err;
+ char wrap_sym_name[1024] = { 'b', 'i', 'o', 'n', 'i', 'c', '_' };
+ memcpy(wrap_sym_name + 7, symbol, MIN(sizeof(wrap_sym_name) - 7, strlen(symbol)));
+ if ((sym = dlsym(RTLD_DEFAULT, wrap_sym_name))) {
+ pthread_mutex_unlock(&apkenv_dl_lock);
+ return wrapper_create(symbol, sym);
+ } else if ((sym = dlsym(RTLD_DEFAULT, symbol))) {
+ pthread_mutex_unlock(&apkenv_dl_lock);
+ return wrapper_create(symbol, sym);
+ }
}
-#endif
if(handle == RTLD_DEFAULT) {
sym = apkenv_lookup(symbol, &found, NULL);