| OLD | NEW |
| 1 /* dso_dlfcn.c -*- mode:C; c-file-style: "eay" -*- */ | 1 /* dso_dlfcn.c -*- mode:C; c-file-style: "eay" -*- */ |
| 2 /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 /* Written by Geoff Thorpe (geoff@geoffthorpe.net) 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 50 * OF THE POSSIBILITY OF SUCH DAMAGE. | 50 * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 51 * ==================================================================== | 51 * ==================================================================== |
| 52 * | 52 * |
| 53 * This product includes cryptographic software written by Eric Young | 53 * This product includes cryptographic software written by Eric Young |
| 54 * (eay@cryptsoft.com). This product includes software written by Tim | 54 * (eay@cryptsoft.com). This product includes software written by Tim |
| 55 * Hudson (tjh@cryptsoft.com). | 55 * Hudson (tjh@cryptsoft.com). |
| 56 * | 56 * |
| 57 */ | 57 */ |
| 58 | 58 |
| 59 /* We need to do this early, because stdio.h includes the header files |
| 60 that handle _GNU_SOURCE and other similar macros. Defining it later |
| 61 is simply too late, because those headers are protected from re- |
| 62 inclusion. */ |
| 63 #ifdef __linux |
| 64 # ifndef _GNU_SOURCE |
| 65 # define _GNU_SOURCE /* make sure dladdr is declared */ |
| 66 # endif |
| 67 #endif |
| 68 |
| 59 #include <stdio.h> | 69 #include <stdio.h> |
| 60 #include "cryptlib.h" | 70 #include "cryptlib.h" |
| 61 #include <openssl/dso.h> | 71 #include <openssl/dso.h> |
| 62 | 72 |
| 63 #ifndef DSO_DLFCN | 73 #ifndef DSO_DLFCN |
| 64 DSO_METHOD *DSO_METHOD_dlfcn(void) | 74 DSO_METHOD *DSO_METHOD_dlfcn(void) |
| 65 { | 75 { |
| 66 return NULL; | 76 return NULL; |
| 67 } | 77 } |
| 68 #else | 78 #else |
| 69 | 79 |
| 70 #ifdef HAVE_DLFCN_H | 80 #ifdef HAVE_DLFCN_H |
| 71 #include <dlfcn.h> | 81 # ifdef __osf__ |
| 82 # define __EXTENSIONS__ |
| 83 # endif |
| 84 # include <dlfcn.h> |
| 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)) |
| 90 # undef HAVE_DLINFO |
| 91 # endif |
| 72 #endif | 92 #endif |
| 73 | 93 |
| 74 /* Part of the hack in "dlfcn_load" ... */ | 94 /* Part of the hack in "dlfcn_load" ... */ |
| 75 #define DSO_MAX_TRANSLATED_SIZE 256 | 95 #define DSO_MAX_TRANSLATED_SIZE 256 |
| 76 | 96 |
| 77 static int dlfcn_load(DSO *dso); | 97 static int dlfcn_load(DSO *dso); |
| 78 static int dlfcn_unload(DSO *dso); | 98 static int dlfcn_unload(DSO *dso); |
| 79 static void *dlfcn_bind_var(DSO *dso, const char *symname); | 99 static void *dlfcn_bind_var(DSO *dso, const char *symname); |
| 80 static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname); | 100 static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname); |
| 81 #if 0 | 101 #if 0 |
| 82 static int dlfcn_unbind(DSO *dso, char *symname, void *symptr); | 102 static int dlfcn_unbind(DSO *dso, char *symname, void *symptr); |
| 83 static int dlfcn_init(DSO *dso); | 103 static int dlfcn_init(DSO *dso); |
| 84 static int dlfcn_finish(DSO *dso); | 104 static int dlfcn_finish(DSO *dso); |
| 85 static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); | 105 static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); |
| 86 #endif | 106 #endif |
| 87 static char *dlfcn_name_converter(DSO *dso, const char *filename); | 107 static char *dlfcn_name_converter(DSO *dso, const char *filename); |
| 88 static char *dlfcn_merger(DSO *dso, const char *filespec1, | 108 static char *dlfcn_merger(DSO *dso, const char *filespec1, |
| 89 const char *filespec2); | 109 const char *filespec2); |
| 110 static int dlfcn_pathbyaddr(void *addr,char *path,int sz); |
| 111 static void *dlfcn_globallookup(const char *name); |
| 90 | 112 |
| 91 static DSO_METHOD dso_meth_dlfcn = { | 113 static DSO_METHOD dso_meth_dlfcn = { |
| 92 "OpenSSL 'dlfcn' shared library method", | 114 "OpenSSL 'dlfcn' shared library method", |
| 93 dlfcn_load, | 115 dlfcn_load, |
| 94 dlfcn_unload, | 116 dlfcn_unload, |
| 95 dlfcn_bind_var, | 117 dlfcn_bind_var, |
| 96 dlfcn_bind_func, | 118 dlfcn_bind_func, |
| 97 /* For now, "unbind" doesn't exist */ | 119 /* For now, "unbind" doesn't exist */ |
| 98 #if 0 | 120 #if 0 |
| 99 NULL, /* unbind_var */ | 121 NULL, /* unbind_var */ |
| 100 NULL, /* unbind_func */ | 122 NULL, /* unbind_func */ |
| 101 #endif | 123 #endif |
| 102 NULL, /* ctrl */ | 124 NULL, /* ctrl */ |
| 103 dlfcn_name_converter, | 125 dlfcn_name_converter, |
| 104 dlfcn_merger, | 126 dlfcn_merger, |
| 105 NULL, /* init */ | 127 NULL, /* init */ |
| 106 » NULL /* finish */ | 128 » NULL, /* finish */ |
| 129 » dlfcn_pathbyaddr, |
| 130 » dlfcn_globallookup |
| 107 }; | 131 }; |
| 108 | 132 |
| 109 DSO_METHOD *DSO_METHOD_dlfcn(void) | 133 DSO_METHOD *DSO_METHOD_dlfcn(void) |
| 110 { | 134 { |
| 111 return(&dso_meth_dlfcn); | 135 return(&dso_meth_dlfcn); |
| 112 } | 136 } |
| 113 | 137 |
| 114 /* Prior to using the dlopen() function, we should decide on the flag | 138 /* Prior to using the dlopen() function, we should decide on the flag |
| 115 * we send. There's a few different ways of doing this and it's a | 139 * we send. There's a few different ways of doing this and it's a |
| 116 * messy venn-diagram to match up which platforms support what. So | 140 * messy venn-diagram to match up which platforms support what. So |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS) | 180 if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS) |
| 157 flags |= RTLD_GLOBAL; | 181 flags |= RTLD_GLOBAL; |
| 158 #endif | 182 #endif |
| 159 ptr = dlopen(filename, flags); | 183 ptr = dlopen(filename, flags); |
| 160 if(ptr == NULL) | 184 if(ptr == NULL) |
| 161 { | 185 { |
| 162 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED); | 186 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED); |
| 163 ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); | 187 ERR_add_error_data(4, "filename(", filename, "): ", dlerror()); |
| 164 goto err; | 188 goto err; |
| 165 } | 189 } |
| 166 » if(!sk_push(dso->meth_data, (char *)ptr)) | 190 » if(!sk_void_push(dso->meth_data, (char *)ptr)) |
| 167 { | 191 { |
| 168 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); | 192 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_STACK_ERROR); |
| 169 goto err; | 193 goto err; |
| 170 } | 194 } |
| 171 /* Success */ | 195 /* Success */ |
| 172 dso->loaded_filename = filename; | 196 dso->loaded_filename = filename; |
| 173 return(1); | 197 return(1); |
| 174 err: | 198 err: |
| 175 /* Cleanup! */ | 199 /* Cleanup! */ |
| 176 if(filename != NULL) | 200 if(filename != NULL) |
| 177 OPENSSL_free(filename); | 201 OPENSSL_free(filename); |
| 178 if(ptr != NULL) | 202 if(ptr != NULL) |
| 179 dlclose(ptr); | 203 dlclose(ptr); |
| 180 return(0); | 204 return(0); |
| 181 } | 205 } |
| 182 | 206 |
| 183 static int dlfcn_unload(DSO *dso) | 207 static int dlfcn_unload(DSO *dso) |
| 184 { | 208 { |
| 185 void *ptr; | 209 void *ptr; |
| 186 if(dso == NULL) | 210 if(dso == NULL) |
| 187 { | 211 { |
| 188 DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); | 212 DSOerr(DSO_F_DLFCN_UNLOAD,ERR_R_PASSED_NULL_PARAMETER); |
| 189 return(0); | 213 return(0); |
| 190 } | 214 } |
| 191 » if(sk_num(dso->meth_data) < 1) | 215 » if(sk_void_num(dso->meth_data) < 1) |
| 192 return(1); | 216 return(1); |
| 193 » ptr = (void *)sk_pop(dso->meth_data); | 217 » ptr = sk_void_pop(dso->meth_data); |
| 194 if(ptr == NULL) | 218 if(ptr == NULL) |
| 195 { | 219 { |
| 196 DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE); | 220 DSOerr(DSO_F_DLFCN_UNLOAD,DSO_R_NULL_HANDLE); |
| 197 /* Should push the value back onto the stack in | 221 /* Should push the value back onto the stack in |
| 198 * case of a retry. */ | 222 * case of a retry. */ |
| 199 » » sk_push(dso->meth_data, (char *)ptr); | 223 » » sk_void_push(dso->meth_data, ptr); |
| 200 return(0); | 224 return(0); |
| 201 } | 225 } |
| 202 /* For now I'm not aware of any errors associated with dlclose() */ | 226 /* For now I'm not aware of any errors associated with dlclose() */ |
| 203 dlclose(ptr); | 227 dlclose(ptr); |
| 204 return(1); | 228 return(1); |
| 205 } | 229 } |
| 206 | 230 |
| 207 static void *dlfcn_bind_var(DSO *dso, const char *symname) | 231 static void *dlfcn_bind_var(DSO *dso, const char *symname) |
| 208 { | 232 { |
| 209 void *ptr, *sym; | 233 void *ptr, *sym; |
| 210 | 234 |
| 211 if((dso == NULL) || (symname == NULL)) | 235 if((dso == NULL) || (symname == NULL)) |
| 212 { | 236 { |
| 213 DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); | 237 DSOerr(DSO_F_DLFCN_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER); |
| 214 return(NULL); | 238 return(NULL); |
| 215 } | 239 } |
| 216 » if(sk_num(dso->meth_data) < 1) | 240 » if(sk_void_num(dso->meth_data) < 1) |
| 217 { | 241 { |
| 218 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR); | 242 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_STACK_ERROR); |
| 219 return(NULL); | 243 return(NULL); |
| 220 } | 244 } |
| 221 » ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | 245 » ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); |
| 222 if(ptr == NULL) | 246 if(ptr == NULL) |
| 223 { | 247 { |
| 224 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE); | 248 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_NULL_HANDLE); |
| 225 return(NULL); | 249 return(NULL); |
| 226 } | 250 } |
| 227 sym = dlsym(ptr, symname); | 251 sym = dlsym(ptr, symname); |
| 228 if(sym == NULL) | 252 if(sym == NULL) |
| 229 { | 253 { |
| 230 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE); | 254 DSOerr(DSO_F_DLFCN_BIND_VAR,DSO_R_SYM_FAILURE); |
| 231 ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); | 255 ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); |
| 232 return(NULL); | 256 return(NULL); |
| 233 } | 257 } |
| 234 return(sym); | 258 return(sym); |
| 235 } | 259 } |
| 236 | 260 |
| 237 static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname) | 261 static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname) |
| 238 { | 262 { |
| 239 void *ptr; | 263 void *ptr; |
| 240 union { | 264 union { |
| 241 DSO_FUNC_TYPE sym; | 265 DSO_FUNC_TYPE sym; |
| 242 void *dlret; | 266 void *dlret; |
| 243 } u; | 267 } u; |
| 244 | 268 |
| 245 if((dso == NULL) || (symname == NULL)) | 269 if((dso == NULL) || (symname == NULL)) |
| 246 { | 270 { |
| 247 DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); | 271 DSOerr(DSO_F_DLFCN_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER); |
| 248 return(NULL); | 272 return(NULL); |
| 249 } | 273 } |
| 250 » if(sk_num(dso->meth_data) < 1) | 274 » if(sk_void_num(dso->meth_data) < 1) |
| 251 { | 275 { |
| 252 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR); | 276 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_STACK_ERROR); |
| 253 return(NULL); | 277 return(NULL); |
| 254 } | 278 } |
| 255 » ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1); | 279 » ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1); |
| 256 if(ptr == NULL) | 280 if(ptr == NULL) |
| 257 { | 281 { |
| 258 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); | 282 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); |
| 259 return(NULL); | 283 return(NULL); |
| 260 } | 284 } |
| 261 u.dlret = dlsym(ptr, symname); | 285 u.dlret = dlsym(ptr, symname); |
| 262 if(u.dlret == NULL) | 286 if(u.dlret == NULL) |
| 263 { | 287 { |
| 264 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); | 288 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); |
| 265 ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); | 289 ERR_add_error_data(4, "symname(", symname, "): ", dlerror()); |
| 266 return(NULL); | 290 return(NULL); |
| 267 } | 291 } |
| 268 return u.sym; | 292 return u.sym; |
| 269 } | 293 } |
| 270 | 294 |
| 271 static char *dlfcn_merger(DSO *dso, const char *filespec1, | 295 static char *dlfcn_merger(DSO *dso, const char *filespec1, |
| 272 const char *filespec2) | 296 const char *filespec2) |
| 273 { | 297 { |
| 274 char *merged; | 298 char *merged; |
| 275 | 299 |
| 276 if(!filespec1 && !filespec2) | 300 if(!filespec1 && !filespec2) |
| 277 { | 301 { |
| 278 DSOerr(DSO_F_DLFCN_MERGER, | 302 DSOerr(DSO_F_DLFCN_MERGER, |
| 279 ERR_R_PASSED_NULL_PARAMETER); | 303 ERR_R_PASSED_NULL_PARAMETER); |
| 280 return(NULL); | 304 return(NULL); |
| 281 } | 305 } |
| 282 /* If the first file specification is a rooted path, it rules. | 306 /* If the first file specification is a rooted path, it rules. |
| 283 same goes if the second file specification is missing. */ | 307 same goes if the second file specification is missing. */ |
| 284 » if (!filespec2 || filespec1[0] == '/') | 308 » if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) |
| 285 { | 309 { |
| 286 merged = OPENSSL_malloc(strlen(filespec1) + 1); | 310 merged = OPENSSL_malloc(strlen(filespec1) + 1); |
| 287 if(!merged) | 311 if(!merged) |
| 288 { | 312 { |
| 289 » » » DSOerr(DSO_F_DLFCN_MERGER, | 313 » » » DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); |
| 290 » » » » ERR_R_MALLOC_FAILURE); | |
| 291 return(NULL); | 314 return(NULL); |
| 292 } | 315 } |
| 293 strcpy(merged, filespec1); | 316 strcpy(merged, filespec1); |
| 294 } | 317 } |
| 295 /* If the first file specification is missing, the second one rules. */ | 318 /* If the first file specification is missing, the second one rules. */ |
| 296 else if (!filespec1) | 319 else if (!filespec1) |
| 297 { | 320 { |
| 298 merged = OPENSSL_malloc(strlen(filespec2) + 1); | 321 merged = OPENSSL_malloc(strlen(filespec2) + 1); |
| 299 if(!merged) | 322 if(!merged) |
| 300 { | 323 { |
| 301 DSOerr(DSO_F_DLFCN_MERGER, | 324 DSOerr(DSO_F_DLFCN_MERGER, |
| 302 ERR_R_MALLOC_FAILURE); | 325 ERR_R_MALLOC_FAILURE); |
| 303 return(NULL); | 326 return(NULL); |
| 304 } | 327 } |
| 305 strcpy(merged, filespec2); | 328 strcpy(merged, filespec2); |
| 306 } | 329 } |
| 307 else | 330 else |
| 308 /* This part isn't as trivial as it looks. It assumes that | 331 /* This part isn't as trivial as it looks. It assumes that |
| 309 the second file specification really is a directory, and | 332 the second file specification really is a directory, and |
| 310 makes no checks whatsoever. Therefore, the result becomes | 333 makes no checks whatsoever. Therefore, the result becomes |
| 311 the concatenation of filespec2 followed by a slash followed | 334 the concatenation of filespec2 followed by a slash followed |
| 312 by filespec1. */ | 335 by filespec1. */ |
| 313 { | 336 { |
| 314 int spec2len, len; | 337 int spec2len, len; |
| 315 | 338 |
| 316 » » spec2len = (filespec2 ? strlen(filespec2) : 0); | 339 » » spec2len = strlen(filespec2); |
| 317 len = spec2len + (filespec1 ? strlen(filespec1) : 0); | 340 len = spec2len + (filespec1 ? strlen(filespec1) : 0); |
| 318 | 341 |
| 319 if(filespec2 && filespec2[spec2len - 1] == '/') | 342 if(filespec2 && filespec2[spec2len - 1] == '/') |
| 320 { | 343 { |
| 321 spec2len--; | 344 spec2len--; |
| 322 len--; | 345 len--; |
| 323 } | 346 } |
| 324 merged = OPENSSL_malloc(len + 2); | 347 merged = OPENSSL_malloc(len + 2); |
| 325 if(!merged) | 348 if(!merged) |
| 326 { | 349 { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) | 394 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) |
| 372 sprintf(translated, "lib%s" DSO_ext, filename); | 395 sprintf(translated, "lib%s" DSO_ext, filename); |
| 373 else | 396 else |
| 374 sprintf(translated, "%s" DSO_ext, filename); | 397 sprintf(translated, "%s" DSO_ext, filename); |
| 375 } | 398 } |
| 376 else | 399 else |
| 377 sprintf(translated, "%s", filename); | 400 sprintf(translated, "%s", filename); |
| 378 return(translated); | 401 return(translated); |
| 379 } | 402 } |
| 380 | 403 |
| 404 #ifdef __sgi |
| 405 /* |
| 406 This is a quote from IRIX manual for dladdr(3c): |
| 407 |
| 408 <dlfcn.h> does not contain a prototype for dladdr or definition of |
| 409 Dl_info. The #include <dlfcn.h> in the SYNOPSIS line is traditional, |
| 410 but contains no dladdr prototype and no IRIX library contains an |
| 411 implementation. Write your own declaration based on the code below. |
| 412 |
| 413 The following code is dependent on internal interfaces that are not |
| 414 part of the IRIX compatibility guarantee; however, there is no future |
| 415 intention to change this interface, so on a practical level, the code |
| 416 below is safe to use on IRIX. |
| 417 */ |
| 418 #include <rld_interface.h> |
| 419 #ifndef _RLD_INTERFACE_DLFCN_H_DLADDR |
| 420 #define _RLD_INTERFACE_DLFCN_H_DLADDR |
| 421 typedef struct Dl_info { |
| 422 const char * dli_fname; |
| 423 void * dli_fbase; |
| 424 const char * dli_sname; |
| 425 void * dli_saddr; |
| 426 int dli_version; |
| 427 int dli_reserved1; |
| 428 long dli_reserved[4]; |
| 429 } Dl_info; |
| 430 #else |
| 431 typedef struct Dl_info Dl_info; |
| 432 #endif |
| 433 #define _RLD_DLADDR 14 |
| 434 |
| 435 static int dladdr(void *address, Dl_info *dl) |
| 436 { |
| 437 void *v; |
| 438 v = _rld_new_interface(_RLD_DLADDR,address,dl); |
| 439 return (int)v; |
| 440 } |
| 441 #endif /* __sgi */ |
| 442 |
| 443 static int dlfcn_pathbyaddr(void *addr,char *path,int sz) |
| 444 { |
| 445 #ifdef HAVE_DLINFO |
| 446 Dl_info dli; |
| 447 int len; |
| 448 |
| 449 if (addr == NULL) |
| 450 { |
| 451 union { int(*f)(void*,char*,int); void *p; } t = |
| 452 { dlfcn_pathbyaddr }; |
| 453 addr = t.p; |
| 454 } |
| 455 |
| 456 if (dladdr(addr,&dli)) |
| 457 { |
| 458 len = (int)strlen(dli.dli_fname); |
| 459 if (sz <= 0) return len+1; |
| 460 if (len >= sz) len=sz-1; |
| 461 memcpy(path,dli.dli_fname,len); |
| 462 path[len++]=0; |
| 463 return len; |
| 464 } |
| 465 |
| 466 ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror()); |
| 467 #endif |
| 468 return -1; |
| 469 } |
| 470 |
| 471 static void *dlfcn_globallookup(const char *name) |
| 472 { |
| 473 void *ret = NULL,*handle = dlopen(NULL,RTLD_LAZY); |
| 474 |
| 475 if (handle) |
| 476 { |
| 477 ret = dlsym(handle,name); |
| 478 dlclose(handle); |
| 479 } |
| 480 |
| 481 return ret; |
| 482 } |
| 381 #endif /* DSO_DLFCN */ | 483 #endif /* DSO_DLFCN */ |
| OLD | NEW |