diff options
author | Andy Polyakov <appro@openssl.org> | 2005-06-05 18:13:38 +0000 |
---|---|---|
committer | Andy Polyakov <appro@openssl.org> | 2005-06-05 18:13:38 +0000 |
commit | 7ed876533aa7c8e721836c25cef737c3643f5e55 (patch) | |
tree | 3978ef9d2c18ec4e176bbf4b7e0c0517202fb012 /crypto/dso/dso_dl.c | |
parent | b2d91a69133e5b8e546f5316f1005e6553194d81 (diff) |
New function, DSO_pathbyaddr, to find pathname for loaded shared object
by an address within it. Tested on Linux, Solaris, IRIX, Tru64, Darwin,
HP-UX, Win32, few BSD flavors...
Diffstat (limited to 'crypto/dso/dso_dl.c')
-rw-r--r-- | crypto/dso/dso_dl.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/crypto/dso/dso_dl.c b/crypto/dso/dso_dl.c index fd1c758260..2de01b09e1 100644 --- a/crypto/dso/dso_dl.c +++ b/crypto/dso/dso_dl.c @@ -85,6 +85,7 @@ static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg); #endif static char *dl_name_converter(DSO *dso, const char *filename); static char *dl_merger(DSO *dso, const char *filespec1, const char *filespec2); +static int dl_pathbyaddr(void *addr,char *path,int sz); static DSO_METHOD dso_meth_dl = { "OpenSSL 'dl' shared library method", @@ -101,7 +102,8 @@ static DSO_METHOD dso_meth_dl = { dl_name_converter, dl_merger, NULL, /* init */ - NULL /* finish */ + NULL, /* finish */ + dl_pathbyaddr }; DSO_METHOD *DSO_METHOD_dl(void) @@ -349,4 +351,27 @@ static char *dl_name_converter(DSO *dso, const char *filename) return(translated); } +static int dl_pathbyaddr(void *addr,char *path,int sz) + { + struct shl_descriptor inf; + int i,len; + + if (addr == NULL) addr = dl_pathbyaddr; + + for (i=-1;shl_get_r(i,&inf)==0;i++) + { + if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) || + ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend)) + { + len = (int)strlen(inf.filename); + if (sz <= 0) return len+1; + if (len >= sz) len=sz-1; + memcpy(path,inf.filename,len); + path[len++] = 0; + return len; + } + } + + return -1; + } #endif /* DSO_DL */ |