diff options
Diffstat (limited to 'iconv')
-rw-r--r-- | iconv/gconv.c | 2 | ||||
-rw-r--r-- | iconv/gconv_db.c | 1 | ||||
-rw-r--r-- | iconv/gconv_dl.c | 93 | ||||
-rw-r--r-- | iconv/gconv_int.h | 6 |
4 files changed, 12 insertions, 90 deletions
diff --git a/iconv/gconv.c b/iconv/gconv.c index 828db9d..3120f00 100644 --- a/iconv/gconv.c +++ b/iconv/gconv.c @@ -22,7 +22,7 @@ #include <assert.h> #include <gconv.h> #include <sys/param.h> - +#include <dlfcn.h> #include <ldsodefs.h> int diff --git a/iconv/gconv_db.c b/iconv/gconv_db.c index 727be41..3929299 100644 --- a/iconv/gconv_db.c +++ b/iconv/gconv_db.c @@ -25,6 +25,7 @@ #include <sys/param.h> #include <bits/libc-lock.h> +#include <dlfcn.h> #include <ldsodefs.h> #include <gconv_int.h> diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c index dc90986..7d327ed 100644 --- a/iconv/gconv_dl.c +++ b/iconv/gconv_dl.c @@ -26,10 +26,8 @@ #include <bits/libc-lock.h> #include <sys/param.h> -#include <ldsodefs.h> #include <gconv_int.h> - /* This is a tuning parameter. If a transformation module is not used anymore it gets not immediately unloaded. Instead we wait a certain number of load attempts for further modules. If none of the @@ -39,13 +37,10 @@ before unloading. */ #define TRIES_BEFORE_UNLOAD 2 - /* Array of loaded objects. This is shared by all threads so we have to use semaphores to access it. */ static void *loaded; - - /* Comparison function for searching `loaded_object' tree. */ static int known_compare (const void *p1, const void *p2) @@ -58,70 +53,6 @@ known_compare (const void *p1, const void *p2) return (intptr_t) s1->handle - (intptr_t) s2->handle; } - -static void -do_open (void *a) -{ - struct __gconv_loaded_object *args = (struct __gconv_loaded_object *) a; - /* Open and relocate the shared object. */ - args->handle = _dl_open (args->name, RTLD_LAZY, NULL); -} - - -static int -internal_function -dlerror_run (void (*operate) (void *), void *args) -{ - char *last_errstring = NULL; - int result; - - (void) _dl_catch_error (&last_errstring, operate, args); - - result = last_errstring != NULL; - if (result) - free (last_errstring); - - return result; -} - - -struct get_sym_args -{ - /* Arguments to get_sym. */ - struct link_map *map; - const char *name; - - /* Return values of get_sym. */ - ElfW(Addr) loadbase; - const ElfW(Sym) *ref; -}; - -static void -get_sym (void *a) -{ - struct get_sym_args *args = (struct get_sym_args *) a; - args->ref = NULL; - args->loadbase = _dl_lookup_symbol (args->name, &args->ref, - args->map->l_local_scope, - args->map->l_name, 0); -} - - -void * -internal_function -__gconv_find_func (void *handle, const char *name) -{ - struct get_sym_args args; - - args.map = handle; - args.name = name; - - return (dlerror_run (get_sym, &args) ? NULL - : (void *) (args.loadbase + args.ref->st_value)); -} - - - /* Open the gconv database if necessary. A non-negative return value means success. */ struct __gconv_loaded_object * @@ -170,9 +101,10 @@ __gconv_find_shlib (const char *name) { if (found->counter < -TRIES_BEFORE_UNLOAD) { - if (dlerror_run (do_open, found) == 0) + found->handle = __libc_dlopen (found->name); + if (found->handle != NULL) { - found->fct = __gconv_find_func (found->handle, "gconv"); + found->fct = __libc_dlsym (found->handle, "gconv"); if (found->fct == NULL) { /* Argh, no conversion function. There is something @@ -182,10 +114,8 @@ __gconv_find_shlib (const char *name) } else { - found->init_fct = __gconv_find_func (found->handle, - "gconv_init"); - found->end_fct = __gconv_find_func (found->handle, - "gconv_end"); + found->init_fct = __libc_dlsym (found->handle, "gconv_init"); + found->end_fct = __libc_dlsym (found->handle, "gconv_end"); /* We have succeeded in loading the shared object. */ found->counter = 1; @@ -224,11 +154,8 @@ do_release_shlib (const void *nodep, VISIT value, int level) { if (--obj->counter < -TRIES_BEFORE_UNLOAD && obj->handle != NULL) { - /* Unload the shared object. We don't use the trick to - catch errors since in the case an error is signalled - something is really wrong. */ - _dl_close (obj->handle); - + /* Unload the shared object. */ + __libc_dlclose (obj->handle); obj->handle = NULL; } } @@ -258,11 +185,9 @@ do_release_all (void *nodep) { struct __gconv_loaded_object *obj = (struct __gconv_loaded_object *) nodep; - /* Unload the shared object. We don't use the trick to - catch errors since in the case an error is signalled - something is really wrong. */ + /* Unload the shared object. */ if (obj->handle != NULL) - _dl_close (obj->handle); + __libc_dlclose (obj->handle); free (obj); } diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h index 29f495c..6048319 100644 --- a/iconv/gconv_int.h +++ b/iconv/gconv_int.h @@ -51,7 +51,7 @@ struct __gconv_loaded_object int counter; /* The handle for the shared object. */ - struct link_map *handle; + void *handle; /* Pointer to the functions the module defines. */ __gconv_fct fct; @@ -135,10 +135,6 @@ extern int __gconv_close_transform (struct __gconv_step *__steps, extern struct __gconv_loaded_object *__gconv_find_shlib (const char *__name) internal_function; -/* Find function named NAME in shared object referenced by HANDLE. */ -void *__gconv_find_func (void *handle, const char *name) - internal_function; - /* Release shared object. If no further reference is available unload the object. */ extern int __gconv_release_shlib (struct __gconv_loaded_object *__handle) |