summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/dso/dso_lib.c23
-rw-r--r--include/internal/dso.h11
-rw-r--r--util/libcrypto.num1
3 files changed, 32 insertions, 3 deletions
diff --git a/crypto/dso/dso_lib.c b/crypto/dso/dso_lib.c
index 2dac20082c..52816dfb9d 100644
--- a/crypto/dso/dso_lib.c
+++ b/crypto/dso/dso_lib.c
@@ -73,9 +73,11 @@ int DSO_free(DSO *dso)
return 1;
REF_ASSERT_ISNT(i < 0);
- if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
- DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
- return 0;
+ if ((dso->flags & DSO_FLAG_NO_UNLOAD_ON_FREE) == 0) {
+ if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
+ DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
+ return 0;
+ }
}
if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
@@ -316,6 +318,21 @@ int DSO_pathbyaddr(void *addr, char *path, int sz)
return (*meth->pathbyaddr) (addr, path, sz);
}
+DSO *DSO_dsobyaddr(void *addr, int flags)
+{
+ DSO *ret = NULL;
+ char *filename = NULL;
+ int len = DSO_pathbyaddr(addr, NULL, 0);
+
+ filename = OPENSSL_malloc(len);
+ if (filename != NULL
+ && DSO_pathbyaddr(addr, filename, len) == len)
+ ret = DSO_load(NULL, filename, NULL, flags);
+
+ OPENSSL_free(filename);
+ return ret;
+}
+
void *DSO_global_lookup(const char *name)
{
DSO_METHOD *meth = default_DSO_meth;
diff --git a/include/internal/dso.h b/include/internal/dso.h
index 6f50f005a9..6acd5013c1 100644
--- a/include/internal/dso.h
+++ b/include/internal/dso.h
@@ -43,6 +43,11 @@ extern "C" {
# define DSO_FLAG_NAME_TRANSLATION_EXT_ONLY 0x02
/*
+ * Don't unload the DSO when we call DSO_free()
+ */
+# define DSO_FLAG_NO_UNLOAD_ON_FREE 0x04
+
+/*
* This flag loads the library with public symbols. Meaning: The exported
* symbols of this library are public to all libraries loaded after this
* library. At the moment only implemented in unix.
@@ -142,6 +147,12 @@ DSO_METHOD *DSO_METHOD_openssl(void);
int DSO_pathbyaddr(void *addr, char *path, int sz);
/*
+ * Like DSO_pathbyaddr() but instead returns a handle to the DSO for the symbol
+ * or NULL on error.
+ */
+DSO *DSO_dsobyaddr(void *addr, int flags);
+
+/*
* This function should be used with caution! It looks up symbols in *all*
* loaded modules and if module gets unloaded by somebody else attempt to
* dereference the pointer is doomed to have fatal consequences. Primary
diff --git a/util/libcrypto.num b/util/libcrypto.num
index 3645c1ad1c..0b4190b2d2 100644
--- a/util/libcrypto.num
+++ b/util/libcrypto.num
@@ -4217,3 +4217,4 @@ BIO_write_ex 4167 1_1_1 EXIST::FUNCTION:
BIO_meth_get_write_ex 4168 1_1_1 EXIST::FUNCTION:
BIO_meth_set_write_ex 4169 1_1_1 EXIST::FUNCTION:
DSO_pathbyaddr 4170 1_1_0c EXIST::FUNCTION:
+DSO_dsobyaddr 4171 1_1_0c EXIST::FUNCTION: