82 # define __EXTENSIONS__
85 # define HAVE_DLINFO 1
86 # if defined(_AIX) || defined(__CYGWIN__) || \
87 defined(__SCO_VERSION__) || defined(_SCO_ELF) || \
88 (defined(__osf__) && !defined(RTLD_NEXT)) || \
89 (defined(__OpenBSD__) && !defined(RTLD_SELF)) || \
96 #define DSO_MAX_TRANSLATED_SIZE 256
98 static int dlfcn_load(
DSO *dso);
99 static int dlfcn_unload(
DSO *dso);
100 static void *dlfcn_bind_var(
DSO *dso,
const char *symname);
103 static int dlfcn_unbind(
DSO *dso,
char *symname,
void *symptr);
104 static int dlfcn_init(
DSO *dso);
105 static int dlfcn_finish(
DSO *dso);
106 static long dlfcn_ctrl(
DSO *dso,
int cmd,
long larg,
void *parg);
108 static char *dlfcn_name_converter(
DSO *dso,
const char *
filename);
109 static char *dlfcn_merger(
DSO *dso,
const char *filespec1,
110 const char *filespec2);
111 static int dlfcn_pathbyaddr(
void *addr,
char *path,
int sz);
112 static void *dlfcn_globallookup(
const char *name);
115 "OpenSSL 'dlfcn' shared library method",
126 dlfcn_name_converter,
136 return(&dso_meth_dlfcn);
145 #if defined(__OpenBSD__) || defined(__NetBSD__)
147 # define DLOPEN_FLAG DL_LAZY
150 # define DLOPEN_FLAG RTLD_NOW
152 # define DLOPEN_FLAG 0
156 # ifdef OPENSSL_SYS_SUNOS
157 # define DLOPEN_FLAG 1
159 # define DLOPEN_FLAG RTLD_NOW
167 static int dlfcn_load(
DSO *dso)
172 int flags = DLOPEN_FLAG;
182 flags |= RTLD_GLOBAL;
184 ptr = dlopen(filename, flags);
208 static int dlfcn_unload(
DSO *dso)
232 static void *dlfcn_bind_var(
DSO *dso,
const char *symname)
236 if((dso == NULL) || (symname == NULL))
252 sym = dlsym(ptr, symname);
270 if((dso == NULL) || (symname == NULL))
286 u.dlret = dlsym(ptr, symname);
296 static char *dlfcn_merger(
DSO *dso,
const char *filespec1,
297 const char *filespec2)
301 if(!filespec1 && !filespec2)
309 if (!filespec2 || (filespec1 != NULL && filespec1[0] ==
'/'))
317 strcpy(merged, filespec1);
329 strcpy(merged, filespec2);
340 spec2len = strlen(filespec2);
341 len = spec2len + (filespec1 ? strlen(filespec1) : 0);
343 if(filespec2 && filespec2[spec2len - 1] ==
'/')
355 strcpy(merged, filespec2);
356 merged[spec2len] =
'/';
357 strcpy(&merged[spec2len + 1], filespec1);
362 #ifdef OPENSSL_SYS_MACOSX
363 #define DSO_ext ".dylib"
366 #define DSO_ext ".so"
371 static char *dlfcn_name_converter(
DSO *dso,
const char *filename)
374 int len, rsize, transform;
376 len = strlen(filename);
378 transform = (strstr(filename,
"/") == NULL);
387 if(translated == NULL)
396 sprintf(translated,
"lib%s" DSO_ext, filename);
398 sprintf(translated,
"%s" DSO_ext, filename);
401 sprintf(translated,
"%s", filename);
419 #include <rld_interface.h>
420 #ifndef _RLD_INTERFACE_DLFCN_H_DLADDR
421 #define _RLD_INTERFACE_DLFCN_H_DLADDR
422 typedef struct Dl_info {
423 const char * dli_fname;
425 const char * dli_sname;
429 long dli_reserved[4];
432 typedef struct Dl_info Dl_info;
434 #define _RLD_DLADDR 14
436 static int dladdr(
void *address, Dl_info *dl)
439 v = _rld_new_interface(_RLD_DLADDR,address,dl);
444 static int dlfcn_pathbyaddr(
void *addr,
char *path,
int sz)
452 union { int(*
f)(
void*,
char*,int);
void *
p; }
t =
453 { dlfcn_pathbyaddr };
457 if (dladdr(addr,&dli))
459 len = (int)strlen(dli.dli_fname);
460 if (sz <= 0)
return len+1;
461 if (len >= sz) len=sz-1;
462 memcpy(path,dli.dli_fname,len);
472 static void *dlfcn_globallookup(
const char *name)
474 void *ret = NULL,*
handle = dlopen(NULL,RTLD_LAZY);
478 ret = dlsym(handle,name);