OLD | NEW |
1 /* dso_dl.c -*- mode:C; c-file-style: "eay" -*- */ | 1 /* dso_dl.c -*- mode:C; c-file-style: "eay" -*- */ |
2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL | 2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL |
3 * project 2000. | 3 * project 2000. |
4 */ | 4 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname); | 78 static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname); |
79 #if 0 | 79 #if 0 |
80 static int dl_unbind_var(DSO *dso, char *symname, void *symptr); | 80 static int dl_unbind_var(DSO *dso, char *symname, void *symptr); |
81 static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); | 81 static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr); |
82 static int dl_init(DSO *dso); | 82 static int dl_init(DSO *dso); |
83 static int dl_finish(DSO *dso); | 83 static int dl_finish(DSO *dso); |
84 static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); | 84 static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); |
85 #endif | 85 #endif |
86 static char *dl_name_converter(DSO *dso, const char *filename); | 86 static char *dl_name_converter(DSO *dso, const char *filename); |
87 static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2); | 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); |
88 | 90 |
89 static DSO_METHOD dso_meth_dl = { | 91 static DSO_METHOD dso_meth_dl = { |
90 "OpenSSL 'dl' shared library method", | 92 "OpenSSL 'dl' shared library method", |
91 dl_load, | 93 dl_load, |
92 dl_unload, | 94 dl_unload, |
93 dl_bind_var, | 95 dl_bind_var, |
94 dl_bind_func, | 96 dl_bind_func, |
95 /* For now, "unbind" doesn't exist */ | 97 /* For now, "unbind" doesn't exist */ |
96 #if 0 | 98 #if 0 |
97 NULL, /* unbind_var */ | 99 NULL, /* unbind_var */ |
98 NULL, /* unbind_func */ | 100 NULL, /* unbind_func */ |
99 #endif | 101 #endif |
100 NULL, /* ctrl */ | 102 NULL, /* ctrl */ |
101 dl_name_converter, | 103 dl_name_converter, |
102 dl_merger, | 104 dl_merger, |
103 NULL, /* init */ | 105 NULL, /* init */ |
104 » NULL /* finish */ | 106 » NULL, /* finish */ |
| 107 » dl_pathbyaddr, |
| 108 » dl_globallookup |
105 }; | 109 }; |
106 | 110 |
107 DSO_METHOD *DSO_METHOD_dl(void) | 111 DSO_METHOD *DSO_METHOD_dl(void) |
108 { | 112 { |
109 return(&dso_meth_dl); | 113 return(&dso_meth_dl); |
110 } | 114 } |
111 | 115 |
112 /* For this DSO_METHOD, our meth_data STACK will contain; | 116 /* For this DSO_METHOD, our meth_data STACK will contain; |
113 * (i) the handle (shl_t) returned from shl_load(). | 117 * (i) the handle (shl_t) returned from shl_load(). |
114 * NB: I checked on HPUX11 and shl_t is itself a pointer | 118 * NB: I checked on HPUX11 and shl_t is itself a pointer |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | 347 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) |
344 sprintf(translated, "lib%s%s", filename, extension); | 348 sprintf(translated, "lib%s%s", filename, extension); |
345 else | 349 else |
346 sprintf(translated, "%s%s", filename, extension); | 350 sprintf(translated, "%s%s", filename, extension); |
347 } | 351 } |
348 else | 352 else |
349 sprintf(translated, "%s", filename); | 353 sprintf(translated, "%s", filename); |
350 return(translated); | 354 return(translated); |
351 } | 355 } |
352 | 356 |
| 357 static int dl_pathbyaddr(void *addr,char *path,int sz) |
| 358 { |
| 359 struct shl_descriptor inf; |
| 360 int i,len; |
| 361 |
| 362 if (addr == NULL) |
| 363 { |
| 364 union { int(*f)(void*,char*,int); void *p; } t = |
| 365 { dl_pathbyaddr }; |
| 366 addr = t.p; |
| 367 } |
| 368 |
| 369 for (i=-1;shl_get_r(i,&inf)==0;i++) |
| 370 { |
| 371 if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) || |
| 372 ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend)) |
| 373 { |
| 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); |
| 378 path[len++] = 0; |
| 379 return len; |
| 380 } |
| 381 } |
| 382 |
| 383 return -1; |
| 384 } |
| 385 |
| 386 static void *dl_globallookup(const char *name) |
| 387 { |
| 388 void *ret; |
| 389 shl_t h = NULL; |
| 390 |
| 391 return shl_findsym(&h,name,TYPE_UNDEFINED,&ret) ? NULL : ret; |
| 392 } |
353 #endif /* DSO_DL */ | 393 #endif /* DSO_DL */ |
OLD | NEW |