summaryrefslogtreecommitdiff
path: root/Cryptlib/OpenSSL/crypto/dso
diff options
context:
space:
mode:
Diffstat (limited to 'Cryptlib/OpenSSL/crypto/dso')
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_beos.c253
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_dl.c45
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_dlfcn.c135
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_err.c14
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_lib.c36
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_null.c4
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_openssl.c2
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_vms.c215
-rw-r--r--Cryptlib/OpenSSL/crypto/dso/dso_win32.c221
9 files changed, 791 insertions, 134 deletions
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_beos.c b/Cryptlib/OpenSSL/crypto/dso/dso_beos.c
new file mode 100644
index 00000000..68ebcd8a
--- /dev/null
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_beos.c
@@ -0,0 +1,253 @@
+/* dso_beos.c */
+/*
+ * Written by Marcin Konicki (ahwayakchih@neoni.net) for the OpenSSL project
+ * 2000.
+ */
+/* ====================================================================
+ * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com). This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include "cryptlib.h"
+#include <openssl/dso.h>
+
+#if !defined(OPENSSL_SYS_BEOS)
+DSO_METHOD *DSO_METHOD_beos(void)
+{
+ return NULL;
+}
+#else
+
+# include <kernel/image.h>
+
+static int beos_load(DSO *dso);
+static int beos_unload(DSO *dso);
+static void *beos_bind_var(DSO *dso, const char *symname);
+static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname);
+# if 0
+static int beos_unbind_var(DSO *dso, char *symname, void *symptr);
+static int beos_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
+static int beos_init(DSO *dso);
+static int beos_finish(DSO *dso);
+static long beos_ctrl(DSO *dso, int cmd, long larg, void *parg);
+# endif
+static char *beos_name_converter(DSO *dso, const char *filename);
+
+static DSO_METHOD dso_meth_beos = {
+ "OpenSSL 'beos' shared library method",
+ beos_load,
+ beos_unload,
+ beos_bind_var,
+ beos_bind_func,
+/* For now, "unbind" doesn't exist */
+# if 0
+ NULL, /* unbind_var */
+ NULL, /* unbind_func */
+# endif
+ NULL, /* ctrl */
+ beos_name_converter,
+ NULL, /* init */
+ NULL /* finish */
+};
+
+DSO_METHOD *DSO_METHOD_beos(void)
+{
+ return (&dso_meth_beos);
+}
+
+/*
+ * For this DSO_METHOD, our meth_data STACK will contain; (i) a pointer to
+ * the handle (image_id) returned from load_add_on().
+ */
+
+static int beos_load(DSO *dso)
+{
+ image_id id;
+ /* See applicable comments from dso_dl.c */
+ char *filename = DSO_convert_filename(dso, NULL);
+
+ if (filename == NULL) {
+ DSOerr(DSO_F_BEOS_LOAD, DSO_R_NO_FILENAME);
+ goto err;
+ }
+ id = load_add_on(filename);
+ if (id < 1) {
+ DSOerr(DSO_F_BEOS_LOAD, DSO_R_LOAD_FAILED);
+ ERR_add_error_data(3, "filename(", filename, ")");
+ goto err;
+ }
+ if (!sk_push(dso->meth_data, (char *)id)) {
+ DSOerr(DSO_F_BEOS_LOAD, DSO_R_STACK_ERROR);
+ goto err;
+ }
+ /* Success */
+ dso->loaded_filename = filename;
+ return (1);
+ err:
+ /* Cleanup ! */
+ if (filename != NULL)
+ OPENSSL_free(filename);
+ if (id > 0)
+ unload_add_on(id);
+ return (0);
+}
+
+static int beos_unload(DSO *dso)
+{
+ image_id id;
+ if (dso == NULL) {
+ DSOerr(DSO_F_BEOS_UNLOAD, ERR_R_PASSED_NULL_PARAMETER);
+ return (0);
+ }
+ if (sk_num(dso->meth_data) < 1)
+ return (1);
+ id = (image_id) sk_pop(dso->meth_data);
+ if (id < 1) {
+ DSOerr(DSO_F_BEOS_UNLOAD, DSO_R_NULL_HANDLE);
+ return (0);
+ }
+ if (unload_add_on(id) != B_OK) {
+ DSOerr(DSO_F_BEOS_UNLOAD, DSO_R_UNLOAD_FAILED);
+ /*
+ * We should push the value back onto the stack in case of a retry.
+ */
+ sk_push(dso->meth_data, (char *)id);
+ return (0);
+ }
+ return (1);
+}
+
+static void *beos_bind_var(DSO *dso, const char *symname)
+{
+ image_id id;
+ void *sym;
+
+ if ((dso == NULL) || (symname == NULL)) {
+ DSOerr(DSO_F_BEOS_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER);
+ return (NULL);
+ }
+ if (sk_num(dso->meth_data) < 1) {
+ DSOerr(DSO_F_BEOS_BIND_VAR, DSO_R_STACK_ERROR);
+ return (NULL);
+ }
+ id = (image_id) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+ if (id < 1) {
+ DSOerr(DSO_F_BEOS_BIND_VAR, DSO_R_NULL_HANDLE);
+ return (NULL);
+ }
+ if (get_image_symbol(id, symname, B_SYMBOL_TYPE_DATA, &sym) != B_OK) {
+ DSOerr(DSO_F_BEOS_BIND_VAR, DSO_R_SYM_FAILURE);
+ ERR_add_error_data(3, "symname(", symname, ")");
+ return (NULL);
+ }
+ return (sym);
+}
+
+static DSO_FUNC_TYPE beos_bind_func(DSO *dso, const char *symname)
+{
+ image_id id;
+ void *sym;
+
+ if ((dso == NULL) || (symname == NULL)) {
+ DSOerr(DSO_F_BEOS_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
+ return (NULL);
+ }
+ if (sk_num(dso->meth_data) < 1) {
+ DSOerr(DSO_F_BEOS_BIND_FUNC, DSO_R_STACK_ERROR);
+ return (NULL);
+ }
+ id = (image_id) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+ if (id < 1) {
+ DSOerr(DSO_F_BEOS_BIND_FUNC, DSO_R_NULL_HANDLE);
+ return (NULL);
+ }
+ if (get_image_symbol(id, symname, B_SYMBOL_TYPE_TEXT, &sym) != B_OK) {
+ DSOerr(DSO_F_BEOS_BIND_FUNC, DSO_R_SYM_FAILURE);
+ ERR_add_error_data(3, "symname(", symname, ")");
+ return (NULL);
+ }
+ return ((DSO_FUNC_TYPE)sym);
+}
+
+/* This one is the same as the one in dlfcn */
+static char *beos_name_converter(DSO *dso, const char *filename)
+{
+ char *translated;
+ int len, rsize, transform;
+
+ len = strlen(filename);
+ rsize = len + 1;
+ transform = (strstr(filename, "/") == NULL);
+ if (transform) {
+ /* We will convert this to "%s.so" or "lib%s.so" */
+ rsize += 3; /* The length of ".so" */
+ if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
+ rsize += 3; /* The length of "lib" */
+ }
+ translated = OPENSSL_malloc(rsize);
+ if (translated == NULL) {
+ DSOerr(DSO_F_BEOS_NAME_CONVERTER, DSO_R_NAME_TRANSLATION_FAILED);
+ return (NULL);
+ }
+ if (transform) {
+ if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
+ sprintf(translated, "lib%s.so", filename);
+ else
+ sprintf(translated, "%s.so", filename);
+ } else
+ sprintf(translated, "%s", filename);
+ return (translated);
+}
+
+#endif
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_dl.c b/Cryptlib/OpenSSL/crypto/dso/dso_dl.c
index 25c9c133..0087ac54 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_dl.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_dl.c
@@ -87,6 +87,8 @@ static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
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 void *dl_globallookup(const char *name);
static DSO_METHOD dso_meth_dl = {
"OpenSSL 'dl' shared library method",
@@ -103,7 +105,9 @@ static DSO_METHOD dso_meth_dl = {
dl_name_converter,
dl_merger,
NULL, /* init */
- NULL /* finish */
+ NULL, /* finish */
+ dl_pathbyaddr,
+ dl_globallookup
};
DSO_METHOD *DSO_METHOD_dl(void)
@@ -334,4 +338,43 @@ 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) {
+ union {
+ int (*f) (void *, char *, int);
+ void *p;
+ } t = {
+ dl_pathbyaddr
+ };
+ addr = t.p;
+ }
+
+ 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;
+}
+
+static void *dl_globallookup(const char *name)
+{
+ void *ret;
+ shl_t h = NULL;
+
+ return shl_findsym(&h, name, TYPE_UNDEFINED, &ret) ? NULL : ret;
+}
#endif /* DSO_DL */
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_dlfcn.c b/Cryptlib/OpenSSL/crypto/dso/dso_dlfcn.c
index f01255a7..f629f038 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_dlfcn.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_dlfcn.c
@@ -57,6 +57,15 @@
*
*/
+/*
+ * We need to do this early, because stdio.h includes the header files that
+ * handle _GNU_SOURCE and other similar macros. Defining it later is simply
+ * too late, because those headers are protected from re- inclusion.
+ */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE /* make sure dladdr is declared */
+#endif
+
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/dso.h>
@@ -69,7 +78,18 @@ DSO_METHOD *DSO_METHOD_dlfcn(void)
#else
# ifdef HAVE_DLFCN_H
+# ifdef __osf__
+# define __EXTENSIONS__
+# endif
# include <dlfcn.h>
+# define HAVE_DLINFO 1
+# if defined(_AIX) || defined(__CYGWIN__) || \
+ defined(__SCO_VERSION__) || defined(_SCO_ELF) || \
+ (defined(__osf__) && !defined(RTLD_NEXT)) || \
+ (defined(__OpenBSD__) && !defined(RTLD_SELF)) || \
+ defined(__ANDROID__)
+# undef HAVE_DLINFO
+# endif
# endif
/* Part of the hack in "dlfcn_load" ... */
@@ -88,6 +108,8 @@ static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
static char *dlfcn_name_converter(DSO *dso, const char *filename);
static char *dlfcn_merger(DSO *dso, const char *filespec1,
const char *filespec2);
+static int dlfcn_pathbyaddr(void *addr, char *path, int sz);
+static void *dlfcn_globallookup(const char *name);
static DSO_METHOD dso_meth_dlfcn = {
"OpenSSL 'dlfcn' shared library method",
@@ -104,7 +126,9 @@ static DSO_METHOD dso_meth_dlfcn = {
dlfcn_name_converter,
dlfcn_merger,
NULL, /* init */
- NULL /* finish */
+ NULL, /* finish */
+ dlfcn_pathbyaddr,
+ dlfcn_globallookup
};
DSO_METHOD *DSO_METHOD_dlfcn(void)
@@ -164,7 +188,7 @@ static int dlfcn_load(DSO *dso)
ERR_add_error_data(4, "filename(", filename, "): ", dlerror());
goto err;
}
- if (!sk_push(dso->meth_data, (char *)ptr)) {
+ if (!sk_void_push(dso->meth_data, (char *)ptr)) {
DSOerr(DSO_F_DLFCN_LOAD, DSO_R_STACK_ERROR);
goto err;
}
@@ -187,15 +211,15 @@ static int dlfcn_unload(DSO *dso)
DSOerr(DSO_F_DLFCN_UNLOAD, ERR_R_PASSED_NULL_PARAMETER);
return (0);
}
- if (sk_num(dso->meth_data) < 1)
+ if (sk_void_num(dso->meth_data) < 1)
return (1);
- ptr = (void *)sk_pop(dso->meth_data);
+ ptr = sk_void_pop(dso->meth_data);
if (ptr == NULL) {
DSOerr(DSO_F_DLFCN_UNLOAD, DSO_R_NULL_HANDLE);
/*
* Should push the value back onto the stack in case of a retry.
*/
- sk_push(dso->meth_data, (char *)ptr);
+ sk_void_push(dso->meth_data, ptr);
return (0);
}
/* For now I'm not aware of any errors associated with dlclose() */
@@ -211,11 +235,11 @@ static void *dlfcn_bind_var(DSO *dso, const char *symname)
DSOerr(DSO_F_DLFCN_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER);
return (NULL);
}
- if (sk_num(dso->meth_data) < 1) {
+ if (sk_void_num(dso->meth_data) < 1) {
DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_STACK_ERROR);
return (NULL);
}
- ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+ ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
if (ptr == NULL) {
DSOerr(DSO_F_DLFCN_BIND_VAR, DSO_R_NULL_HANDLE);
return (NULL);
@@ -241,11 +265,11 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
DSOerr(DSO_F_DLFCN_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
return (NULL);
}
- if (sk_num(dso->meth_data) < 1) {
+ if (sk_void_num(dso->meth_data) < 1) {
DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_STACK_ERROR);
return (NULL);
}
- ptr = (void *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+ ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
if (ptr == NULL) {
DSOerr(DSO_F_DLFCN_BIND_FUNC, DSO_R_NULL_HANDLE);
return (NULL);
@@ -272,7 +296,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
* If the first file specification is a rooted path, it rules. same goes
* if the second file specification is missing.
*/
- if (!filespec2 || filespec1[0] == '/') {
+ if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) {
merged = OPENSSL_malloc(strlen(filespec1) + 1);
if (!merged) {
DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
@@ -290,7 +314,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
return (NULL);
}
strcpy(merged, filespec2);
- } else
+ } else {
/*
* This part isn't as trivial as it looks. It assumes that the
* second file specification really is a directory, and makes no
@@ -298,13 +322,12 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
* concatenation of filespec2 followed by a slash followed by
* filespec1.
*/
- {
int spec2len, len;
- spec2len = (filespec2 ? strlen(filespec2) : 0);
- len = spec2len + (filespec1 ? strlen(filespec1) : 0);
+ spec2len = strlen(filespec2);
+ len = spec2len + strlen(filespec1);
- if (filespec2 && filespec2[spec2len - 1] == '/') {
+ if (spec2len && filespec2[spec2len - 1] == '/') {
spec2len--;
len--;
}
@@ -357,4 +380,86 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename)
return (translated);
}
+# ifdef __sgi
+/*-
+This is a quote from IRIX manual for dladdr(3c):
+
+ <dlfcn.h> does not contain a prototype for dladdr or definition of
+ Dl_info. The #include <dlfcn.h> in the SYNOPSIS line is traditional,
+ but contains no dladdr prototype and no IRIX library contains an
+ implementation. Write your own declaration based on the code below.
+
+ The following code is dependent on internal interfaces that are not
+ part of the IRIX compatibility guarantee; however, there is no future
+ intention to change this interface, so on a practical level, the code
+ below is safe to use on IRIX.
+*/
+# include <rld_interface.h>
+# ifndef _RLD_INTERFACE_DLFCN_H_DLADDR
+# define _RLD_INTERFACE_DLFCN_H_DLADDR
+typedef struct Dl_info {
+ const char *dli_fname;
+ void *dli_fbase;
+ const char *dli_sname;
+ void *dli_saddr;
+ int dli_version;
+ int dli_reserved1;
+ long dli_reserved[4];
+} Dl_info;
+# else
+typedef struct Dl_info Dl_info;
+# endif
+# define _RLD_DLADDR 14
+
+static int dladdr(void *address, Dl_info *dl)
+{
+ void *v;
+ v = _rld_new_interface(_RLD_DLADDR, address, dl);
+ return (int)v;
+}
+# endif /* __sgi */
+
+static int dlfcn_pathbyaddr(void *addr, char *path, int sz)
+{
+# ifdef HAVE_DLINFO
+ Dl_info dli;
+ int len;
+
+ if (addr == NULL) {
+ union {
+ int (*f) (void *, char *, int);
+ void *p;
+ } t = {
+ dlfcn_pathbyaddr
+ };
+ addr = t.p;
+ }
+
+ if (dladdr(addr, &dli)) {
+ len = (int)strlen(dli.dli_fname);
+ if (sz <= 0)
+ return len + 1;
+ if (len >= sz)
+ len = sz - 1;
+ memcpy(path, dli.dli_fname, len);
+ path[len++] = 0;
+ return len;
+ }
+
+ ERR_add_error_data(2, "dlfcn_pathbyaddr(): ", dlerror());
+# endif
+ return -1;
+}
+
+static void *dlfcn_globallookup(const char *name)
+{
+ void *ret = NULL, *handle = dlopen(NULL, RTLD_LAZY);
+
+ if (handle) {
+ ret = dlsym(handle, name);
+ dlclose(handle);
+ }
+
+ return ret;
+}
#endif /* DSO_DLFCN */
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_err.c b/Cryptlib/OpenSSL/crypto/dso/dso_err.c
index 7a1927e5..e143cc01 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_err.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_err.c
@@ -1,6 +1,6 @@
/* crypto/dso/dso_err.c */
/* ====================================================================
- * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -70,6 +70,11 @@
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSO,0,reason)
static ERR_STRING_DATA DSO_str_functs[] = {
+ {ERR_FUNC(DSO_F_BEOS_BIND_FUNC), "BEOS_BIND_FUNC"},
+ {ERR_FUNC(DSO_F_BEOS_BIND_VAR), "BEOS_BIND_VAR"},
+ {ERR_FUNC(DSO_F_BEOS_LOAD), "BEOS_LOAD"},
+ {ERR_FUNC(DSO_F_BEOS_NAME_CONVERTER), "BEOS_NAME_CONVERTER"},
+ {ERR_FUNC(DSO_F_BEOS_UNLOAD), "BEOS_UNLOAD"},
{ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"},
{ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"},
{ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"},
@@ -89,22 +94,29 @@ static ERR_STRING_DATA DSO_str_functs[] = {
{ERR_FUNC(DSO_F_DSO_FREE), "DSO_free"},
{ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"},
{ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"},
+ {ERR_FUNC(DSO_F_DSO_GLOBAL_LOOKUP), "DSO_global_lookup"},
{ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"},
{ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"},
{ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"},
+ {ERR_FUNC(DSO_F_DSO_PATHBYADDR), "DSO_pathbyaddr"},
{ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"},
{ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"},
{ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"},
+ {ERR_FUNC(DSO_F_GLOBAL_LOOKUP_FUNC), "GLOBAL_LOOKUP_FUNC"},
+ {ERR_FUNC(DSO_F_PATHBYADDR), "PATHBYADDR"},
{ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"},
{ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"},
{ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"},
{ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"},
{ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"},
{ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"},
+ {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP), "WIN32_GLOBALLOOKUP"},
+ {ERR_FUNC(DSO_F_WIN32_GLOBALLOOKUP_FUNC), "WIN32_GLOBALLOOKUP_FUNC"},
{ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"},
{ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"},
{ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"},
{ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"},
+ {ERR_FUNC(DSO_F_WIN32_PATHBYADDR), "WIN32_PATHBYADDR"},
{ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"},
{ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"},
{0, NULL}
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_lib.c b/Cryptlib/OpenSSL/crypto/dso/dso_lib.c
index f1584665..09b8eafc 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_lib.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_lib.c
@@ -109,7 +109,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
return (NULL);
}
memset(ret, 0, sizeof(DSO));
- ret->meth_data = sk_new_null();
+ ret->meth_data = sk_void_new_null();
if (ret->meth_data == NULL) {
/* sk_new doesn't generate any errors so we do */
DSOerr(DSO_F_DSO_NEW_METHOD, ERR_R_MALLOC_FAILURE);
@@ -160,7 +160,7 @@ int DSO_free(DSO *dso)
return (0);
}
- sk_free(dso->meth_data);
+ sk_void_free(dso->meth_data);
if (dso->filename != NULL)
OPENSSL_free(dso->filename);
if (dso->loaded_filename != NULL)
@@ -285,7 +285,7 @@ DSO_FUNC_TYPE DSO_bind_func(DSO *dso, const char *symname)
* honest. For one thing, I think I have to return a negative value for any
* error because possible DSO_ctrl() commands may return values such as
* "size"s that can legitimately be zero (making the standard
- * "if(DSO_cmd(...))" form that works almost everywhere else fail at odd
+ * "if (DSO_cmd(...))" form that works almost everywhere else fail at odd
* times. I'd prefer "output" values to be passed by reference and the return
* value as success/failure like usual ... but we conform when we must... :-)
*/
@@ -373,12 +373,6 @@ char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
DSOerr(DSO_F_DSO_MERGE, ERR_R_PASSED_NULL_PARAMETER);
return (NULL);
}
- if (filespec1 == NULL)
- filespec1 = dso->filename;
- if (filespec1 == NULL) {
- DSOerr(DSO_F_DSO_MERGE, DSO_R_NO_FILE_SPECIFICATION);
- return (NULL);
- }
if ((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0) {
if (dso->merger != NULL)
result = dso->merger(dso, filespec1, filespec2);
@@ -427,3 +421,27 @@ const char *DSO_get_loaded_filename(DSO *dso)
}
return (dso->loaded_filename);
}
+
+int DSO_pathbyaddr(void *addr, char *path, int sz)
+{
+ DSO_METHOD *meth = default_DSO_meth;
+ if (meth == NULL)
+ meth = DSO_METHOD_openssl();
+ if (meth->pathbyaddr == NULL) {
+ DSOerr(DSO_F_DSO_PATHBYADDR, DSO_R_UNSUPPORTED);
+ return -1;
+ }
+ return (*meth->pathbyaddr) (addr, path, sz);
+}
+
+void *DSO_global_lookup(const char *name)
+{
+ DSO_METHOD *meth = default_DSO_meth;
+ if (meth == NULL)
+ meth = DSO_METHOD_openssl();
+ if (meth->globallookup == NULL) {
+ DSOerr(DSO_F_DSO_GLOBAL_LOOKUP, DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+ return (*meth->globallookup) (name);
+}
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_null.c b/Cryptlib/OpenSSL/crypto/dso/dso_null.c
index 3d112729..20122d1c 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_null.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_null.c
@@ -81,7 +81,9 @@ static DSO_METHOD dso_meth_null = {
NULL, /* dso_name_converter */
NULL, /* dso_merger */
NULL, /* init */
- NULL /* finish */
+ NULL, /* finish */
+ NULL, /* pathbyaddr */
+ NULL /* globallookup */
};
DSO_METHOD *DSO_METHOD_null(void)
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_openssl.c b/Cryptlib/OpenSSL/crypto/dso/dso_openssl.c
index 27b7d559..087e989e 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_openssl.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_openssl.c
@@ -75,6 +75,8 @@ DSO_METHOD *DSO_METHOD_openssl(void)
return (DSO_METHOD_win32());
#elif defined(DSO_VMS)
return (DSO_METHOD_vms());
+#elif defined(DSO_BEOS)
+ return (DSO_METHOD_beos());
#else
return (DSO_METHOD_null());
#endif
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_vms.c b/Cryptlib/OpenSSL/crypto/dso/dso_vms.c
index 12e1db3f..d0794b8f 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_vms.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_vms.c
@@ -62,14 +62,6 @@
#include <errno.h>
#include "cryptlib.h"
#include <openssl/dso.h>
-#ifdef OPENSSL_SYS_VMS
-# pragma message disable DOLLARID
-# include <rms.h>
-# include <lib$routines.h>
-# include <stsdef.h>
-# include <descrip.h>
-# include <starlet.h>
-#endif
#ifndef OPENSSL_SYS_VMS
DSO_METHOD *DSO_METHOD_vms(void)
@@ -77,6 +69,26 @@ DSO_METHOD *DSO_METHOD_vms(void)
return NULL;
}
#else
+
+# pragma message disable DOLLARID
+# include <rms.h>
+# include <lib$routines.h>
+# include <stsdef.h>
+# include <descrip.h>
+# include <starlet.h>
+# include "vms_rms.h"
+
+/* Some compiler options may mask the declaration of "_malloc32". */
+# if __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE
+# if __INITIAL_POINTER_SIZE == 64
+# pragma pointer_size save
+# pragma pointer_size 32
+void *_malloc32(__size_t);
+# pragma pointer_size restore
+# endif /* __INITIAL_POINTER_SIZE == 64 */
+# endif /* __INITIAL_POINTER_SIZE && defined
+ * _ANSI_C_SOURCE */
+
# pragma message disable DOLLARID
static int vms_load(DSO *dso);
@@ -124,13 +136,13 @@ typedef struct dso_internal_st {
* but a name.
*/
struct dsc$descriptor_s filename_dsc;
- char filename[FILENAME_MAX + 1];
+ char filename[NAMX_MAXRSS + 1];
/*
* This contains whatever is not in filename, if needed. Normally not
* defined.
*/
struct dsc$descriptor_s imagename_dsc;
- char imagename[FILENAME_MAX + 1];
+ char imagename[NAMX_MAXRSS + 1];
} DSO_VMS_INTERNAL;
DSO_METHOD *DSO_METHOD_vms(void)
@@ -143,8 +155,24 @@ static int vms_load(DSO *dso)
void *ptr = NULL;
/* See applicable comments in dso_dl.c */
char *filename = DSO_convert_filename(dso, NULL);
- DSO_VMS_INTERNAL *p;
+
+/* Ensure 32-bit pointer for "p", and appropriate malloc() function. */
+# if __INITIAL_POINTER_SIZE == 64
+# define DSO_MALLOC _malloc32
+# pragma pointer_size save
+# pragma pointer_size 32
+# else /* __INITIAL_POINTER_SIZE == 64 */
+# define DSO_MALLOC OPENSSL_malloc
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+ DSO_VMS_INTERNAL *p = NULL;
+
+# if __INITIAL_POINTER_SIZE == 64
+# pragma pointer_size restore
+# endif /* __INITIAL_POINTER_SIZE == 64 */
+
const char *sp1, *sp2; /* Search result */
+ const char *ext = NULL; /* possible extension to add */
if (filename == NULL) {
DSOerr(DSO_F_VMS_LOAD, DSO_R_NO_FILENAME);
@@ -187,11 +215,19 @@ static int vms_load(DSO *dso)
/* Now, let's see if there's a type, and save the position in sp2 */
sp2 = strchr(sp1, '.');
/*
+ * If there is a period and the next character is a semi-colon,
+ * we need to add an extension
+ */
+ if (sp2 != NULL && sp2[1] == ';')
+ ext = ".EXE";
+ /*
* If we found it, that's where we'll cut. Otherwise, look for a version
* number and save the position in sp2
*/
- if (sp2 == NULL)
+ if (sp2 == NULL) {
sp2 = strchr(sp1, ';');
+ ext = ".EXE";
+ }
/*
* If there was still nothing to find, set sp2 to point at the end of the
* string
@@ -206,7 +242,7 @@ static int vms_load(DSO *dso)
goto err;
}
- p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
+ p = DSO_MALLOC(sizeof(DSO_VMS_INTERNAL));
if (p == NULL) {
DSOerr(DSO_F_VMS_LOAD, ERR_R_MALLOC_FAILURE);
goto err;
@@ -217,6 +253,11 @@ static int vms_load(DSO *dso)
strncpy(p->imagename, filename, sp1 - filename);
p->imagename[sp1 - filename] = '\0';
+ if (ext) {
+ strcat(p->imagename, ext);
+ if (*sp2 == '.')
+ sp2++;
+ }
strcat(p->imagename, sp2);
p->filename_dsc.dsc$w_length = strlen(p->filename);
@@ -228,7 +269,7 @@ static int vms_load(DSO *dso)
p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S;
p->imagename_dsc.dsc$a_pointer = p->imagename;
- if (!sk_push(dso->meth_data, (char *)p)) {
+ if (!sk_void_push(dso->meth_data, (char *)p)) {
DSOerr(DSO_F_VMS_LOAD, DSO_R_STACK_ERROR);
goto err;
}
@@ -257,9 +298,9 @@ static int vms_unload(DSO *dso)
DSOerr(DSO_F_VMS_UNLOAD, ERR_R_PASSED_NULL_PARAMETER);
return (0);
}
- if (sk_num(dso->meth_data) < 1)
+ if (sk_void_num(dso->meth_data) < 1)
return (1);
- p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
+ p = (DSO_VMS_INTERNAL *)sk_void_pop(dso->meth_data);
if (p == NULL) {
DSOerr(DSO_F_VMS_UNLOAD, DSO_R_NULL_HANDLE);
return (0);
@@ -304,23 +345,42 @@ void vms_bind_sym(DSO *dso, const char *symname, void **sym)
int flags = 0;
# endif
struct dsc$descriptor_s symname_dsc;
- *sym = NULL;
- symname_dsc.dsc$w_length = strlen(symname);
- symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
- symname_dsc.dsc$b_class = DSC$K_CLASS_S;
- symname_dsc.dsc$a_pointer = (char *)symname; /* The cast is needed */
+/* Arrange 32-bit pointer to (copied) string storage, if needed. */
+# if __INITIAL_POINTER_SIZE == 64
+# define SYMNAME symname_32p
+# pragma pointer_size save
+# pragma pointer_size 32
+ char *symname_32p;
+# pragma pointer_size restore
+ char symname_32[NAMX_MAXRSS + 1];
+# else /* __INITIAL_POINTER_SIZE == 64 */
+# define SYMNAME ((char *) symname)
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+ *sym = NULL;
if ((dso == NULL) || (symname == NULL)) {
DSOerr(DSO_F_VMS_BIND_SYM, ERR_R_PASSED_NULL_PARAMETER);
return;
}
- if (sk_num(dso->meth_data) < 1) {
+# if __INITIAL_POINTER_SIZE == 64
+ /* Copy the symbol name to storage with a 32-bit pointer. */
+ symname_32p = symname_32;
+ strcpy(symname_32p, symname);
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
+ symname_dsc.dsc$w_length = strlen(SYMNAME);
+ symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
+ symname_dsc.dsc$b_class = DSC$K_CLASS_S;
+ symname_dsc.dsc$a_pointer = SYMNAME;
+
+ if (sk_void_num(dso->meth_data) < 1) {
DSOerr(DSO_F_VMS_BIND_SYM, DSO_R_STACK_ERROR);
return;
}
- ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
- sk_num(dso->meth_data) - 1);
+ ptr = (DSO_VMS_INTERNAL *)sk_void_value(dso->meth_data,
+ sk_void_num(dso->meth_data) - 1);
if (ptr == NULL) {
DSOerr(DSO_F_VMS_BIND_SYM, DSO_R_NULL_HANDLE);
return;
@@ -387,15 +447,26 @@ static char *vms_merger(DSO *dso, const char *filespec1,
int status;
int filespec1len, filespec2len;
struct FAB fab;
-# ifdef NAML$C_MAXRSS
- struct NAML nam;
- char esa[NAML$C_MAXRSS];
-# else
- struct NAM nam;
- char esa[NAM$C_MAXRSS];
-# endif
+ struct NAMX_STRUCT nam;
+ char esa[NAMX_MAXRSS + 1];
char *merged;
+/* Arrange 32-bit pointer to (copied) string storage, if needed. */
+# if __INITIAL_POINTER_SIZE == 64
+# define FILESPEC1 filespec1_32p;
+# define FILESPEC2 filespec2_32p;
+# pragma pointer_size save
+# pragma pointer_size 32
+ char *filespec1_32p;
+ char *filespec2_32p;
+# pragma pointer_size restore
+ char filespec1_32[NAMX_MAXRSS + 1];
+ char filespec2_32[NAMX_MAXRSS + 1];
+# else /* __INITIAL_POINTER_SIZE == 64 */
+# define FILESPEC1 ((char *) filespec1)
+# define FILESPEC2 ((char *) filespec2)
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
if (!filespec1)
filespec1 = "";
if (!filespec2)
@@ -403,43 +474,29 @@ static char *vms_merger(DSO *dso, const char *filespec1,
filespec1len = strlen(filespec1);
filespec2len = strlen(filespec2);
+# if __INITIAL_POINTER_SIZE == 64
+ /* Copy the file names to storage with a 32-bit pointer. */
+ filespec1_32p = filespec1_32;
+ filespec2_32p = filespec2_32;
+ strcpy(filespec1_32p, filespec1);
+ strcpy(filespec2_32p, filespec2);
+# endif /* __INITIAL_POINTER_SIZE == 64 [else] */
+
fab = cc$rms_fab;
-# ifdef NAML$C_MAXRSS
- nam = cc$rms_naml;
-# else
- nam = cc$rms_nam;
-# endif
+ nam = CC_RMS_NAMX;
- fab.fab$l_fna = (char *)filespec1;
- fab.fab$b_fns = filespec1len;
- fab.fab$l_dna = (char *)filespec2;
- fab.fab$b_dns = filespec2len;
-# ifdef NAML$C_MAXRSS
- if (filespec1len > NAM$C_MAXRSS) {
- fab.fab$l_fna = 0;
- fab.fab$b_fns = 0;
- nam.naml$l_long_filename = (char *)filespec1;
- nam.naml$l_long_filename_size = filespec1len;
- }
- if (filespec2len > NAM$C_MAXRSS) {
- fab.fab$l_dna = 0;
- fab.fab$b_dns = 0;
- nam.naml$l_long_defname = (char *)filespec2;
- nam.naml$l_long_defname_size = filespec2len;
- }
- nam.naml$l_esa = esa;
- nam.naml$b_ess = NAM$C_MAXRSS;
- nam.naml$l_long_expand = esa;
- nam.naml$l_long_expand_alloc = sizeof(esa);
- nam.naml$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
- nam.naml$v_no_short_upcase = 1;
- fab.fab$l_naml = &nam;
-# else
- nam.nam$l_esa = esa;
- nam.nam$b_ess = NAM$C_MAXRSS;
- nam.nam$b_nop = NAM$M_SYNCHK | NAM$M_PWD;
- fab.fab$l_nam = &nam;
-# endif
+ FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNA = FILESPEC1;
+ FAB_OR_NAML(fab, nam).FAB_OR_NAML_FNS = filespec1len;
+ FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNA = FILESPEC2;
+ FAB_OR_NAML(fab, nam).FAB_OR_NAML_DNS = filespec2len;
+ NAMX_DNA_FNA_SET(fab)
+
+ nam.NAMX_ESA = esa;
+ nam.NAMX_ESS = NAMX_MAXRSS;
+ nam.NAMX_NOP = NAM$M_SYNCHK | NAM$M_PWD;
+ SET_NAMX_NO_SHORT_UPCASE(nam);
+
+ fab.FAB_NAMX = &nam;
status = sys$parse(&fab, 0, 0);
@@ -467,27 +524,12 @@ static char *vms_merger(DSO *dso, const char *filespec1,
}
return (NULL);
}
-# ifdef NAML$C_MAXRSS
- if (nam.naml$l_long_expand_size) {
- merged = OPENSSL_malloc(nam.naml$l_long_expand_size + 1);
- if (!merged)
- goto malloc_err;
- strncpy(merged, nam.naml$l_long_expand, nam.naml$l_long_expand_size);
- merged[nam.naml$l_long_expand_size] = '\0';
- } else {
- merged = OPENSSL_malloc(nam.naml$b_esl + 1);
- if (!merged)
- goto malloc_err;
- strncpy(merged, nam.naml$l_esa, nam.naml$b_esl);
- merged[nam.naml$b_esl] = '\0';
- }
-# else
- merged = OPENSSL_malloc(nam.nam$b_esl + 1);
+
+ merged = OPENSSL_malloc(nam.NAMX_ESL + 1);
if (!merged)
goto malloc_err;
- strncpy(merged, nam.nam$l_esa, nam.nam$b_esl);
- merged[nam.nam$b_esl] = '\0';
-# endif
+ strncpy(merged, nam.NAMX_ESA, nam.NAMX_ESL);
+ merged[nam.NAMX_ESL] = '\0';
return (merged);
malloc_err:
DSOerr(DSO_F_VMS_MERGER, ERR_R_MALLOC_FAILURE);
@@ -497,7 +539,8 @@ static char *vms_name_converter(DSO *dso, const char *filename)
{
int len = strlen(filename);
char *not_translated = OPENSSL_malloc(len + 1);
- strcpy(not_translated, filename);
+ if (not_translated)
+ strcpy(not_translated, filename);
return (not_translated);
}
diff --git a/Cryptlib/OpenSSL/crypto/dso/dso_win32.c b/Cryptlib/OpenSSL/crypto/dso/dso_win32.c
index 973e7ebf..c65234e9 100644
--- a/Cryptlib/OpenSSL/crypto/dso/dso_win32.c
+++ b/Cryptlib/OpenSSL/crypto/dso/dso_win32.c
@@ -98,9 +98,10 @@ static HINSTANCE LoadLibraryA(LPCSTR lpLibFileName)
# else
fnamw = (WCHAR *)alloca(len_0 * sizeof(WCHAR));
# endif
- if (fnamw == NULL)
+ if (fnamw == NULL) {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
-
+ }
# if defined(_WIN32_WCE) && _WIN32_WCE>=101
if (!MultiByteToWideChar(CP_ACP, 0, lpLibFileName, len_0, fnamw, len_0))
# endif
@@ -128,6 +129,8 @@ static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
static char *win32_name_converter(DSO *dso, const char *filename);
static char *win32_merger(DSO *dso, const char *filespec1,
const char *filespec2);
+static int win32_pathbyaddr(void *addr, char *path, int sz);
+static void *win32_globallookup(const char *name);
static const char *openssl_strnchr(const char *string, int c, size_t len);
@@ -146,7 +149,9 @@ static DSO_METHOD dso_meth_win32 = {
win32_name_converter,
win32_merger,
NULL, /* init */
- NULL /* finish */
+ NULL, /* finish */
+ win32_pathbyaddr,
+ win32_globallookup
};
DSO_METHOD *DSO_METHOD_win32(void)
@@ -181,7 +186,7 @@ static int win32_load(DSO *dso)
goto err;
}
*p = h;
- if (!sk_push(dso->meth_data, (char *)p)) {
+ if (!sk_void_push(dso->meth_data, p)) {
DSOerr(DSO_F_WIN32_LOAD, DSO_R_STACK_ERROR);
goto err;
}
@@ -206,9 +211,9 @@ static int win32_unload(DSO *dso)
DSOerr(DSO_F_WIN32_UNLOAD, ERR_R_PASSED_NULL_PARAMETER);
return (0);
}
- if (sk_num(dso->meth_data) < 1)
+ if (sk_void_num(dso->meth_data) < 1)
return (1);
- p = (HINSTANCE *) sk_pop(dso->meth_data);
+ p = sk_void_pop(dso->meth_data);
if (p == NULL) {
DSOerr(DSO_F_WIN32_UNLOAD, DSO_R_NULL_HANDLE);
return (0);
@@ -218,7 +223,7 @@ static int win32_unload(DSO *dso)
/*
* We should push the value back onto the stack in case of a retry.
*/
- sk_push(dso->meth_data, (char *)p);
+ sk_void_push(dso->meth_data, p);
return (0);
}
/* Cleanup */
@@ -239,11 +244,11 @@ static void *win32_bind_var(DSO *dso, const char *symname)
DSOerr(DSO_F_WIN32_BIND_VAR, ERR_R_PASSED_NULL_PARAMETER);
return (NULL);
}
- if (sk_num(dso->meth_data) < 1) {
+ if (sk_void_num(dso->meth_data) < 1) {
DSOerr(DSO_F_WIN32_BIND_VAR, DSO_R_STACK_ERROR);
return (NULL);
}
- ptr = (HINSTANCE *) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+ ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
if (ptr == NULL) {
DSOerr(DSO_F_WIN32_BIND_VAR, DSO_R_NULL_HANDLE);
return (NULL);
@@ -266,11 +271,11 @@ static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
DSOerr(DSO_F_WIN32_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
return (NULL);
}
- if (sk_num(dso->meth_data) < 1) {
+ if (sk_void_num(dso->meth_data) < 1) {
DSOerr(DSO_F_WIN32_BIND_FUNC, DSO_R_STACK_ERROR);
return (NULL);
}
- ptr = (HINSTANCE *) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
+ ptr = sk_void_value(dso->meth_data, sk_void_num(dso->meth_data) - 1);
if (ptr == NULL) {
DSOerr(DSO_F_WIN32_BIND_FUNC, DSO_R_NULL_HANDLE);
return (NULL);
@@ -343,7 +348,7 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
return (NULL);
}
result->device = start;
- result->devicelen = filename - start;
+ result->devicelen = (int)(filename - start);
position = IN_FILE;
start = ++filename;
result->dir = start;
@@ -351,7 +356,7 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
case '\\':
case '/':
if (position == IN_NODE) {
- result->nodelen = filename - start;
+ result->nodelen = (int)(filename - start);
position = IN_FILE;
start = ++filename;
result->dir = start;
@@ -359,17 +364,17 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
position = IN_FILE;
filename++;
result->dir = start;
- result->dirlen = filename - start;
+ result->dirlen = (int)(filename - start);
start = filename;
} else {
filename++;
- result->dirlen += filename - start;
+ result->dirlen += (int)(filename - start);
start = filename;
}
break;
case '\0':
if (position == IN_NODE) {
- result->nodelen = filename - start;
+ result->nodelen = (int)(filename - start);
} else {
if (filename - start > 0) {
if (assume_last_is_dir) {
@@ -377,10 +382,10 @@ static struct file_st *win32_splitter(DSO *dso, const char *filename,
result->dir = start;
result->dirlen = 0;
}
- result->dirlen += filename - start;
+ result->dirlen += (int)(filename - start);
} else {
result->file = start;
- result->filelen = filename - start;
+ result->filelen = (int)(filename - start);
}
}
}
@@ -466,7 +471,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
end = start
+ file_split->predirlen - (start - file_split->predir);
strncpy(&result[offset], start, end - start);
- offset += end - start;
+ offset += (int)(end - start);
result[offset] = '\\';
offset++;
start = end + 1;
@@ -486,7 +491,7 @@ static char *win32_joiner(DSO *dso, const struct file_st *file_split)
if (!end)
end = start + file_split->dirlen - (start - file_split->dir);
strncpy(&result[offset], start, end - start);
- offset += end - start;
+ offset += (int)(end - start);
result[offset] = '\\';
offset++;
start = end + 1;
@@ -606,4 +611,178 @@ static const char *openssl_strnchr(const char *string, int c, size_t len)
return NULL;
}
-#endif /* OPENSSL_SYS_WIN32 */
+# include <tlhelp32.h>
+# ifdef _WIN32_WCE
+# define DLLNAME "TOOLHELP.DLL"
+# else
+# ifdef MODULEENTRY32
+# undef MODULEENTRY32 /* unmask the ASCII version! */
+# endif
+# define DLLNAME "KERNEL32.DLL"
+# endif
+
+typedef HANDLE(WINAPI *CREATETOOLHELP32SNAPSHOT) (DWORD, DWORD);
+typedef BOOL(WINAPI *CLOSETOOLHELP32SNAPSHOT) (HANDLE);
+typedef BOOL(WINAPI *MODULE32) (HANDLE, MODULEENTRY32 *);
+
+static int win32_pathbyaddr(void *addr, char *path, int sz)
+{
+ HMODULE dll;
+ HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
+ MODULEENTRY32 me32;
+ CREATETOOLHELP32SNAPSHOT create_snap;
+ CLOSETOOLHELP32SNAPSHOT close_snap;
+ MODULE32 module_first, module_next;
+
+ if (addr == NULL) {
+ union {
+ int (*f) (void *, char *, int);
+ void *p;
+ } t = {
+ win32_pathbyaddr
+ };
+ addr = t.p;
+ }
+
+ dll = LoadLibrary(TEXT(DLLNAME));
+ if (dll == NULL) {
+ DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_UNSUPPORTED);
+ return -1;
+ }
+
+ create_snap = (CREATETOOLHELP32SNAPSHOT)
+ GetProcAddress(dll, "CreateToolhelp32Snapshot");
+ if (create_snap == NULL) {
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_UNSUPPORTED);
+ return -1;
+ }
+ /* We take the rest for granted... */
+# ifdef _WIN32_WCE
+ close_snap = (CLOSETOOLHELP32SNAPSHOT)
+ GetProcAddress(dll, "CloseToolhelp32Snapshot");
+# else
+ close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle;
+# endif
+ module_first = (MODULE32) GetProcAddress(dll, "Module32First");
+ module_next = (MODULE32) GetProcAddress(dll, "Module32Next");
+
+ hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0);
+ if (hModuleSnap == INVALID_HANDLE_VALUE) {
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_UNSUPPORTED);
+ return -1;
+ }
+
+ me32.dwSize = sizeof(me32);
+
+ if (!(*module_first) (hModuleSnap, &me32)) {
+ (*close_snap) (hModuleSnap);
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_PATHBYADDR, DSO_R_FAILURE);
+ return -1;
+ }
+
+ do {
+ if ((BYTE *) addr >= me32.modBaseAddr &&
+ (BYTE *) addr < me32.modBaseAddr + me32.modBaseSize) {
+ (*close_snap) (hModuleSnap);
+ FreeLibrary(dll);
+# ifdef _WIN32_WCE
+# if _WIN32_WCE >= 101
+ return WideCharToMultiByte(CP_ACP, 0, me32.szExePath, -1,
+ path, sz, NULL, NULL);
+# else
+ {
+ int i, len = (int)wcslen(me32.szExePath);
+ if (sz <= 0)
+ return len + 1;
+ if (len >= sz)
+ len = sz - 1;
+ for (i = 0; i < len; i++)
+ path[i] = (char)me32.szExePath[i];
+ path[len++] = 0;
+ return len;
+ }
+# endif
+# else
+ {
+ int len = (int)strlen(me32.szExePath);
+ if (sz <= 0)
+ return len + 1;
+ if (len >= sz)
+ len = sz - 1;
+ memcpy(path, me32.szExePath, len);
+ path[len++] = 0;
+ return len;
+ }
+# endif
+ }
+ } while ((*module_next) (hModuleSnap, &me32));
+
+ (*close_snap) (hModuleSnap);
+ FreeLibrary(dll);
+ return 0;
+}
+
+static void *win32_globallookup(const char *name)
+{
+ HMODULE dll;
+ HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
+ MODULEENTRY32 me32;
+ CREATETOOLHELP32SNAPSHOT create_snap;
+ CLOSETOOLHELP32SNAPSHOT close_snap;
+ MODULE32 module_first, module_next;
+ FARPROC ret = NULL;
+
+ dll = LoadLibrary(TEXT(DLLNAME));
+ if (dll == NULL) {
+ DSOerr(DSO_F_WIN32_GLOBALLOOKUP, DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+
+ create_snap = (CREATETOOLHELP32SNAPSHOT)
+ GetProcAddress(dll, "CreateToolhelp32Snapshot");
+ if (create_snap == NULL) {
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_GLOBALLOOKUP, DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+ /* We take the rest for granted... */
+# ifdef _WIN32_WCE
+ close_snap = (CLOSETOOLHELP32SNAPSHOT)
+ GetProcAddress(dll, "CloseToolhelp32Snapshot");
+# else
+ close_snap = (CLOSETOOLHELP32SNAPSHOT) CloseHandle;
+# endif
+ module_first = (MODULE32) GetProcAddress(dll, "Module32First");
+ module_next = (MODULE32) GetProcAddress(dll, "Module32Next");
+
+ hModuleSnap = (*create_snap) (TH32CS_SNAPMODULE, 0);
+ if (hModuleSnap == INVALID_HANDLE_VALUE) {
+ FreeLibrary(dll);
+ DSOerr(DSO_F_WIN32_GLOBALLOOKUP, DSO_R_UNSUPPORTED);
+ return NULL;
+ }
+
+ me32.dwSize = sizeof(me32);
+
+ if (!(*module_first) (hModuleSnap, &me32)) {
+ (*close_snap) (hModuleSnap);
+ FreeLibrary(dll);
+ return NULL;
+ }
+
+ do {
+ if ((ret = GetProcAddress(me32.hModule, name))) {
+ (*close_snap) (hModuleSnap);
+ FreeLibrary(dll);
+ return ret;
+ }
+ } while ((*module_next) (hModuleSnap, &me32));
+
+ (*close_snap) (hModuleSnap);
+ FreeLibrary(dll);
+ return NULL;
+}
+#endif /* DSO_WIN32 */