73 #define DSO_MAX_TRANSLATED_SIZE 256
75 static int dl_load(
DSO *dso);
76 static int dl_unload(
DSO *dso);
77 static void *dl_bind_var(
DSO *dso,
const char *symname);
80 static int dl_unbind_var(
DSO *dso,
char *symname,
void *symptr);
82 static int dl_init(
DSO *dso);
83 static int dl_finish(
DSO *dso);
84 static int dl_ctrl(
DSO *dso,
int cmd,
long larg,
void *parg);
86 static char *dl_name_converter(
DSO *dso,
const char *
filename);
87 static char *dl_merger(
DSO *dso,
const char *filespec1,
const char *filespec2);
88 static int dl_pathbyaddr(
void *addr,
char *path,
int sz);
89 static void *dl_globallookup(
const char *name);
92 "OpenSSL 'dl' shared library method",
113 return(&dso_meth_dl);
122 static int dl_load(
DSO *dso)
135 ptr = shl_load(filename, BIND_IMMEDIATE |
144 if(!
sk_push(dso->meth_data, (
char *)ptr))
162 static int dl_unload(
DSO *dso)
170 if(
sk_num(dso->meth_data) < 1)
173 ptr = (shl_t)
sk_pop(dso->meth_data);
179 sk_push(dso->meth_data, (
char *)ptr);
186 static void *dl_bind_var(
DSO *dso,
const char *symname)
191 if((dso == NULL) || (symname == NULL))
196 if(
sk_num(dso->meth_data) < 1)
201 ptr = (shl_t)
sk_value(dso->meth_data,
sk_num(dso->meth_data) - 1);
207 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
222 if((dso == NULL) || (symname == NULL))
227 if(
sk_num(dso->meth_data) < 1)
232 ptr = (shl_t)
sk_value(dso->meth_data,
sk_num(dso->meth_data) - 1);
238 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
248 static char *dl_merger(
DSO *dso,
const char *filespec1,
const char *filespec2)
252 if(!filespec1 && !filespec2)
260 if (!filespec2 || filespec1[0] ==
'/')
269 strcpy(merged, filespec1);
281 strcpy(merged, filespec2);
292 spec2len = (filespec2 ? strlen(filespec2) : 0);
293 len = spec2len + (filespec1 ? strlen(filespec1) : 0);
295 if(filespec2 && filespec2[spec2len - 1] ==
'/')
307 strcpy(merged, filespec2);
308 merged[spec2len] =
'/';
309 strcpy(&merged[spec2len + 1], filespec1);
320 static const char extension[] =
".sl";
322 static const char extension[] =
".so";
324 static char *dl_name_converter(
DSO *dso,
const char *filename)
327 int len, rsize, transform;
329 len = strlen(filename);
331 transform = (strstr(filename,
"/") == NULL);
334 rsize += strlen(extension);
339 if(translated == NULL)
348 sprintf(translated,
"lib%s%s", filename, extension);
350 sprintf(translated,
"%s%s", filename, extension);
353 sprintf(translated,
"%s", filename);
357 static int dl_pathbyaddr(
void *addr,
char *path,
int sz)
359 struct shl_descriptor inf;
364 union { int(*
f)(
void*,
char*,int);
void *
p; }
t =
369 for (i=-1;shl_get_r(i,&inf)==0;i++)
371 if (((
size_t)addr >= inf.tstart && (
size_t)addr < inf.tend) ||
372 ((size_t)addr >= inf.dstart && (
size_t)addr < inf.dend))
374 len = (int)strlen(inf.filename);
375 if (sz <= 0)
return len+1;
376 if (len >= sz) len=sz-1;
377 memcpy(path,inf.filename,len);
386 static void *dl_globallookup(
const char *name)
391 return shl_findsym(&h,name,TYPE_UNDEFINED,&ret) ? NULL : ret;