summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/threads
diff options
context:
space:
mode:
authorbeck <>2000-03-19 11:13:58 +0000
committerbeck <>2000-03-19 11:13:58 +0000
commit796d609550df3a33fc11468741c5d2f6d3df4c11 (patch)
tree6c6d539061caa20372dad0ac4ddb1dfae2fbe7fe /src/lib/libcrypto/threads
parent5be3114c1fd7e0dfea1e38d3abb4cbba75244419 (diff)
downloadopenbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.gz
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.tar.bz2
openbsd-796d609550df3a33fc11468741c5d2f6d3df4c11.zip
OpenSSL 0.9.5 merge
*warning* this bumps shared lib minors for libssl and libcrypto from 2.1 to 2.2 if you are using the ssl26 packages for ssh and other things to work you will need to get new ones (see ~beck/libsslsnap/<arch>) on cvs or ~beck/src-patent.tar.gz on cvs
Diffstat (limited to 'src/lib/libcrypto/threads')
-rw-r--r--src/lib/libcrypto/threads/README14
-rw-r--r--src/lib/libcrypto/threads/mttest.c122
-rw-r--r--src/lib/libcrypto/threads/profile.sh4
-rw-r--r--src/lib/libcrypto/threads/ptest.bat4
-rw-r--r--src/lib/libcrypto/threads/pthread.sh9
-rw-r--r--src/lib/libcrypto/threads/pthread2.sh7
-rw-r--r--src/lib/libcrypto/threads/pthreads-vms.com9
-rw-r--r--src/lib/libcrypto/threads/purify.sh4
-rw-r--r--src/lib/libcrypto/threads/solaris.sh4
-rw-r--r--src/lib/libcrypto/threads/th-lock.c55
-rw-r--r--src/lib/libcrypto/threads/win32.bat4
11 files changed, 176 insertions, 60 deletions
diff --git a/src/lib/libcrypto/threads/README b/src/lib/libcrypto/threads/README
new file mode 100644
index 0000000000..df6b26e146
--- /dev/null
+++ b/src/lib/libcrypto/threads/README
@@ -0,0 +1,14 @@
1Mutithreading testing area.
2
3Since this stuff is very very platorm specific, this is not part of the
4normal build. Have a read of doc/threads.doc.
5
6mttest will do some testing and will currently build under Windows NT/95,
7Solaris and Linux. The IRIX stuff is not finished.
8
9I have tested this program on a 12 CPU ultra sparc box (solaris 2.5.1)
10and things seem to work ok.
11
12The Linux pthreads package can be retrieved from
13http://www.mit.edu:8001/people/proven/pthreads.html
14
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c
index 142623edda..24713a3157 100644
--- a/src/lib/libcrypto/threads/mttest.c
+++ b/src/lib/libcrypto/threads/mttest.c
@@ -74,26 +74,29 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
77#include <openssl/lhash.h> 80#include <openssl/lhash.h>
78#include <openssl/crypto.h> 81#include <openssl/crypto.h>
79#include <openssl/buffer.h> 82#include <openssl/buffer.h>
80#include "../e_os.h" 83#include "../../e_os.h"
81#include <openssl/x509.h> 84#include <openssl/x509.h>
82#include <openssl/ssl.h> 85#include <openssl/ssl.h>
83#include <openssl/err.h> 86#include <openssl/err.h>
87#include <openssl/rand.h>
84 88
85#ifdef NO_FP_API 89#ifdef NO_FP_API
86#define APPS_WIN16 90#define APPS_WIN16
87#include "../crypto/buffer/bss_file.c" 91#include "../buffer/bss_file.c"
88#endif 92#endif
89 93
90#define TEST_SERVER_CERT "../apps/server.pem" 94#define TEST_SERVER_CERT "../../apps/server.pem"
91#define TEST_CLIENT_CERT "../apps/client.pem" 95#define TEST_CLIENT_CERT "../../apps/client.pem"
92 96
93#define MAX_THREAD_NUMBER 100 97#define MAX_THREAD_NUMBER 100
94 98
95int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, 99int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs);
96 int error,char *arg);
97void thread_setup(void); 100void thread_setup(void);
98void thread_cleanup(void); 101void thread_cleanup(void);
99void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); 102void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
@@ -121,6 +124,8 @@ int number_of_loops=10;
121int reconnect=0; 124int reconnect=0;
122int cache_stats=0; 125int cache_stats=0;
123 126
127static const char rnd_seed[] = "string to make the random number generator think it has entropy";
128
124int doit(char *ctx[4]); 129int doit(char *ctx[4]);
125static void print_stats(FILE *fp, SSL_CTX *ctx) 130static void print_stats(FILE *fp, SSL_CTX *ctx)
126{ 131{
@@ -170,6 +175,8 @@ int main(int argc, char *argv[])
170 char *ccert=TEST_CLIENT_CERT; 175 char *ccert=TEST_CLIENT_CERT;
171 SSL_METHOD *ssl_method=SSLv23_method(); 176 SSL_METHOD *ssl_method=SSLv23_method();
172 177
178 RAND_seed(rnd_seed, sizeof rnd_seed);
179
173 if (bio_err == NULL) 180 if (bio_err == NULL)
174 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 181 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
175 if (bio_stdout == NULL) 182 if (bio_stdout == NULL)
@@ -244,7 +251,7 @@ bad:
244 if (cipher == NULL) cipher=getenv("SSL_CIPHER"); 251 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
245 252
246 SSL_load_error_strings(); 253 SSL_load_error_strings();
247 SSLeay_add_ssl_algorithms(); 254 OpenSSL_add_ssl_algorithms();
248 255
249 c_ctx=SSL_CTX_new(ssl_method); 256 c_ctx=SSL_CTX_new(ssl_method);
250 s_ctx=SSL_CTX_new(ssl_method); 257 s_ctx=SSL_CTX_new(ssl_method);
@@ -259,8 +266,15 @@ bad:
259 SSL_CTX_set_session_cache_mode(c_ctx, 266 SSL_CTX_set_session_cache_mode(c_ctx,
260 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); 267 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
261 268
262 SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); 269 if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM))
263 SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM); 270 {
271 ERR_print_errors(bio_err);
272 }
273 else if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM))
274 {
275 ERR_print_errors(bio_err);
276 goto end;
277 }
264 278
265 if (client_auth) 279 if (client_auth)
266 { 280 {
@@ -489,6 +503,7 @@ int doit(char *ctx[4])
489 else 503 else
490 { 504 {
491 fprintf(stderr,"ERROR in CLIENT\n"); 505 fprintf(stderr,"ERROR in CLIENT\n");
506 ERR_print_errors_fp(stderr);
492 return(1); 507 return(1);
493 } 508 }
494 } 509 }
@@ -520,6 +535,7 @@ int doit(char *ctx[4])
520 else 535 else
521 { 536 {
522 fprintf(stderr,"ERROR in CLIENT\n"); 537 fprintf(stderr,"ERROR in CLIENT\n");
538 ERR_print_errors_fp(stderr);
523 return(1); 539 return(1);
524 } 540 }
525 } 541 }
@@ -652,18 +668,23 @@ err:
652 return(0); 668 return(0);
653 } 669 }
654 670
655int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, 671int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
656 int error, char *arg)
657 { 672 {
658 char buf[256]; 673 char *s, buf[256];
659 674
660 if (verbose) 675 if (verbose)
661 { 676 {
662 X509_NAME_oneline(X509_get_subject_name(xs),buf,256); 677 s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),
663 if (ok) 678 buf,256);
664 fprintf(stderr,"depth=%d %s\n",depth,buf); 679 if (s != NULL)
665 else 680 {
666 fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf); 681 if (ok)
682 fprintf(stderr,"depth=%d %s\n",
683 ctx->error_depth,buf);
684 else
685 fprintf(stderr,"depth=%d error=%d %s\n",
686 ctx->error_depth,ctx->error,buf);
687 }
667 } 688 }
668 return(ok); 689 return(ok);
669 } 690 }
@@ -672,13 +693,14 @@ int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
672 693
673#ifdef WIN32 694#ifdef WIN32
674 695
675static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 696static HANDLE *lock_cs;
676 697
677void thread_setup(void) 698void thread_setup(void)
678 { 699 {
679 int i; 700 int i;
680 701
681 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 702 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE));
703 for (i=0; i<CRYPTO_num_locks(); i++)
682 { 704 {
683 lock_cs[i]=CreateMutex(NULL,FALSE,NULL); 705 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
684 } 706 }
@@ -692,8 +714,9 @@ void thread_cleanup(void)
692 int i; 714 int i;
693 715
694 CRYPTO_set_locking_callback(NULL); 716 CRYPTO_set_locking_callback(NULL);
695 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 717 for (i=0; i<CRYPTO_num_locks(); i++)
696 CloseHandle(lock_cs[i]); 718 CloseHandle(lock_cs[i]);
719 Free(lock_cs);
697 } 720 }
698 721
699void win32_locking_callback(int mode, int type, char *file, int line) 722void win32_locking_callback(int mode, int type, char *file, int line)
@@ -763,15 +786,17 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
763 786
764#ifdef SOLARIS 787#ifdef SOLARIS
765 788
766static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 789static mutex_t *lock_cs;
767/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ 790/*static rwlock_t *lock_cs; */
768static long lock_count[CRYPTO_NUM_LOCKS]; 791static long *lock_count;
769 792
770void thread_setup(void) 793void thread_setup(void)
771 { 794 {
772 int i; 795 int i;
773 796
774 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 797 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t));
798 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
799 for (i=0; i<CRYPTO_num_locks(); i++)
775 { 800 {
776 lock_count[i]=0; 801 lock_count[i]=0;
777 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ 802 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */
@@ -787,31 +812,37 @@ void thread_cleanup(void)
787 int i; 812 int i;
788 813
789 CRYPTO_set_locking_callback(NULL); 814 CRYPTO_set_locking_callback(NULL);
790fprintf(stderr,"cleanup\n"); 815
791 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 816 fprintf(stderr,"cleanup\n");
817
818 for (i=0; i<CRYPTO_num_locks(); i++)
792 { 819 {
793 /* rwlock_destroy(&(lock_cs[i])); */ 820 /* rwlock_destroy(&(lock_cs[i])); */
794 mutex_destroy(&(lock_cs[i])); 821 mutex_destroy(&(lock_cs[i]));
795 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); 822 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
796 } 823 }
797fprintf(stderr,"done cleanup\n"); 824 Free(lock_cs);
825 Free(lock_count);
826
827 fprintf(stderr,"done cleanup\n");
828
798 } 829 }
799 830
800void solaris_locking_callback(int mode, int type, char *file, int line) 831void solaris_locking_callback(int mode, int type, char *file, int line)
801 { 832 {
802#ifdef undef 833#ifdef undef
803fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", 834 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
804 CRYPTO_thread_id(), 835 CRYPTO_thread_id(),
805 (mode&CRYPTO_LOCK)?"l":"u", 836 (mode&CRYPTO_LOCK)?"l":"u",
806 (type&CRYPTO_READ)?"r":"w",file,line); 837 (type&CRYPTO_READ)?"r":"w",file,line);
807#endif 838#endif
808 839
809/* 840 /*
810if (CRYPTO_LOCK_SSL_CERT == type) 841 if (CRYPTO_LOCK_SSL_CERT == type)
811 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", 842 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
812 CRYPTO_thread_id(), 843 CRYPTO_thread_id(),
813 mode,file,line); 844 mode,file,line);
814*/ 845 */
815 if (mode & CRYPTO_LOCK) 846 if (mode & CRYPTO_LOCK)
816 { 847 {
817 /* if (mode & CRYPTO_READ) 848 /* if (mode & CRYPTO_READ)
@@ -871,7 +902,7 @@ unsigned long solaris_thread_id(void)
871 902
872 903
873static usptr_t *arena; 904static usptr_t *arena;
874static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 905static usema_t **lock_cs;
875 906
876void thread_setup(void) 907void thread_setup(void)
877 { 908 {
@@ -888,7 +919,8 @@ void thread_setup(void)
888 arena=usinit(filename); 919 arena=usinit(filename);
889 unlink(filename); 920 unlink(filename);
890 921
891 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 922 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *));
923 for (i=0; i<CRYPTO_num_locks(); i++)
892 { 924 {
893 lock_cs[i]=usnewsema(arena,1); 925 lock_cs[i]=usnewsema(arena,1);
894 } 926 }
@@ -902,7 +934,7 @@ void thread_cleanup(void)
902 int i; 934 int i;
903 935
904 CRYPTO_set_locking_callback(NULL); 936 CRYPTO_set_locking_callback(NULL);
905 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 937 for (i=0; i<CRYPTO_num_locks(); i++)
906 { 938 {
907 char buf[10]; 939 char buf[10];
908 940
@@ -910,6 +942,7 @@ void thread_cleanup(void)
910 usdumpsema(lock_cs[i],stdout,buf); 942 usdumpsema(lock_cs[i],stdout,buf);
911 usfreesema(lock_cs[i],arena); 943 usfreesema(lock_cs[i],arena);
912 } 944 }
945 Free(lock_cs);
913 } 946 }
914 947
915void irix_locking_callback(int mode, int type, char *file, int line) 948void irix_locking_callback(int mode, int type, char *file, int line)
@@ -962,14 +995,16 @@ unsigned long irix_thread_id(void)
962 995
963#ifdef PTHREADS 996#ifdef PTHREADS
964 997
965static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 998static pthread_mutex_t *lock_cs;
966static long lock_count[CRYPTO_NUM_LOCKS]; 999static long *lock_count;
967 1000
968void thread_setup(void) 1001void thread_setup(void)
969 { 1002 {
970 int i; 1003 int i;
971 1004
972 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 1005 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
1006 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
1007 for (i=0; i<CRYPTO_num_locks(); i++)
973 { 1008 {
974 lock_count[i]=0; 1009 lock_count[i]=0;
975 pthread_mutex_init(&(lock_cs[i]),NULL); 1010 pthread_mutex_init(&(lock_cs[i]),NULL);
@@ -985,12 +1020,15 @@ void thread_cleanup(void)
985 1020
986 CRYPTO_set_locking_callback(NULL); 1021 CRYPTO_set_locking_callback(NULL);
987 fprintf(stderr,"cleanup\n"); 1022 fprintf(stderr,"cleanup\n");
988 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 1023 for (i=0; i<CRYPTO_num_locks(); i++)
989 { 1024 {
990 pthread_mutex_destroy(&(lock_cs[i])); 1025 pthread_mutex_destroy(&(lock_cs[i]));
991 fprintf(stderr,"%8ld:%s\n",lock_count[i], 1026 fprintf(stderr,"%8ld:%s\n",lock_count[i],
992 CRYPTO_get_lock_name(i)); 1027 CRYPTO_get_lock_name(i));
993 } 1028 }
1029 Free(lock_cs);
1030 Free(lock_count);
1031
994 fprintf(stderr,"done cleanup\n"); 1032 fprintf(stderr,"done cleanup\n");
995 } 1033 }
996 1034
@@ -1045,7 +1083,7 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
1045 } 1083 }
1046 1084
1047 printf("pthreads threads done (%d,%d)\n", 1085 printf("pthreads threads done (%d,%d)\n",
1048 s_ctx->references,c_ctx->references); 1086 s_ctx->references,c_ctx->references);
1049 } 1087 }
1050 1088
1051unsigned long pthreads_thread_id(void) 1089unsigned long pthreads_thread_id(void)
diff --git a/src/lib/libcrypto/threads/profile.sh b/src/lib/libcrypto/threads/profile.sh
new file mode 100644
index 0000000000..6e3e342fc0
--- /dev/null
+++ b/src/lib/libcrypto/threads/profile.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -p -DSOLARIS -I../../include -g mttest.c -o mttest -L/usr/lib/libc -ldl -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/ptest.bat b/src/lib/libcrypto/threads/ptest.bat
new file mode 100644
index 0000000000..4071b5ffea
--- /dev/null
+++ b/src/lib/libcrypto/threads/ptest.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3purify cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssl32.lib ..\..\out\crypt32.lib
4
diff --git a/src/lib/libcrypto/threads/pthread.sh b/src/lib/libcrypto/threads/pthread.sh
new file mode 100644
index 0000000000..f1c49821d2
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread.sh
@@ -0,0 +1,9 @@
1#!/bin/sh
2#
3# build using pthreads
4#
5# http://www.mit.edu:8001/people/proven/pthreads.html
6#
7/bin/rm -f mttest
8pgcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto
9
diff --git a/src/lib/libcrypto/threads/pthread2.sh b/src/lib/libcrypto/threads/pthread2.sh
new file mode 100644
index 0000000000..41264c6a50
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread2.sh
@@ -0,0 +1,7 @@
1#!/bin/sh
2#
3# build using pthreads where it's already built into the system
4#
5/bin/rm -f mttest
6gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread
7
diff --git a/src/lib/libcrypto/threads/pthreads-vms.com b/src/lib/libcrypto/threads/pthreads-vms.com
new file mode 100644
index 0000000000..63f5b8cc2e
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthreads-vms.com
@@ -0,0 +1,9 @@
1$! To compile mttest on VMS.
2$!
3$! WARNING: only tested with DEC C so far.
4$
5$ arch := vax
6$ if f$getsyi("CPU") .ge. 128 then arch := axp
7$ define/user openssl [--.include.openssl]
8$ cc/def=PTHREADS mttest.c
9$ link mttest,[--.'arch'.exe.ssl]libssl/lib,[--.'arch'.exe.crypto]libcrypto/lib
diff --git a/src/lib/libcrypto/threads/purify.sh b/src/lib/libcrypto/threads/purify.sh
new file mode 100644
index 0000000000..6d44fe26b7
--- /dev/null
+++ b/src/lib/libcrypto/threads/purify.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3purify cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/solaris.sh b/src/lib/libcrypto/threads/solaris.sh
new file mode 100644
index 0000000000..bc93094a27
--- /dev/null
+++ b/src/lib/libcrypto/threads/solaris.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c
index afb4f4caf2..3ee978060c 100644
--- a/src/lib/libcrypto/threads/th-lock.c
+++ b/src/lib/libcrypto/threads/th-lock.c
@@ -74,6 +74,9 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
77#include <openssl/lhash.h> 80#include <openssl/lhash.h>
78#include <openssl/crypto.h> 81#include <openssl/crypto.h>
79#include <openssl/buffer.h> 82#include <openssl/buffer.h>
@@ -82,7 +85,7 @@
82#include <openssl/ssl.h> 85#include <openssl/ssl.h>
83#include <openssl/err.h> 86#include <openssl/err.h>
84 87
85int CRYPTO_thread_setup(void); 88void CRYPTO_thread_setup(void);
86void CRYPTO_thread_cleanup(void); 89void CRYPTO_thread_cleanup(void);
87 90
88static void irix_locking_callback(int mode,int type,char *file,int line); 91static void irix_locking_callback(int mode,int type,char *file,int line);
@@ -96,7 +99,7 @@ static unsigned long pthreads_thread_id(void );
96 99
97/* usage: 100/* usage:
98 * CRYPTO_thread_setup(); 101 * CRYPTO_thread_setup();
99 * applicaion code 102 * application code
100 * CRYPTO_thread_cleanup(); 103 * CRYPTO_thread_cleanup();
101 */ 104 */
102 105
@@ -104,13 +107,14 @@ static unsigned long pthreads_thread_id(void );
104 107
105#ifdef WIN32 108#ifdef WIN32
106 109
107static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 110static HANDLE *lock_cs;
108 111
109int CRYPTO_thread_setup(void) 112void CRYPTO_thread_setup(void)
110 { 113 {
111 int i; 114 int i;
112 115
113 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 116 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE));
117 for (i=0; i<CRYPTO_num_locks(); i++)
114 { 118 {
115 lock_cs[i]=CreateMutex(NULL,FALSE,NULL); 119 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
116 } 120 }
@@ -125,8 +129,9 @@ static void CRYPTO_thread_cleanup(void)
125 int i; 129 int i;
126 130
127 CRYPTO_set_locking_callback(NULL); 131 CRYPTO_set_locking_callback(NULL);
128 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 132 for (i=0; i<CRYPTO_num_locks(); i++)
129 CloseHandle(lock_cs[i]); 133 CloseHandle(lock_cs[i]);
134 Free(lock_cs);
130 } 135 }
131 136
132void win32_locking_callback(int mode, int type, char *file, int line) 137void win32_locking_callback(int mode, int type, char *file, int line)
@@ -147,18 +152,24 @@ void win32_locking_callback(int mode, int type, char *file, int line)
147 152
148#define USE_MUTEX 153#define USE_MUTEX
149 154
150static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
151#ifdef USE_MUTEX 155#ifdef USE_MUTEX
152static long lock_count[CRYPTO_NUM_LOCKS]; 156static mutex_t *lock_cs;
153#else 157#else
154static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; 158static rwlock_t *lock_cs;
155#endif 159#endif
160static long *lock_count;
156 161
157void CRYPTO_thread_setup(void) 162void CRYPTO_thread_setup(void)
158 { 163 {
159 int i; 164 int i;
160 165
161 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 166#ifdef USE_MUTEX
167 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t));
168#else
169 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(rwlock_t));
170#endif
171 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
172 for (i=0; i<CRYPTO_num_locks(); i++)
162 { 173 {
163 lock_count[i]=0; 174 lock_count[i]=0;
164#ifdef USE_MUTEX 175#ifdef USE_MUTEX
@@ -177,7 +188,7 @@ void CRYPTO_thread_cleanup(void)
177 int i; 188 int i;
178 189
179 CRYPTO_set_locking_callback(NULL); 190 CRYPTO_set_locking_callback(NULL);
180 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 191 for (i=0; i<CRYPTO_num_locks(); i++)
181 { 192 {
182#ifdef USE_MUTEX 193#ifdef USE_MUTEX
183 mutex_destroy(&(lock_cs[i])); 194 mutex_destroy(&(lock_cs[i]));
@@ -185,6 +196,8 @@ void CRYPTO_thread_cleanup(void)
185 rwlock_destroy(&(lock_cs[i])); 196 rwlock_destroy(&(lock_cs[i]));
186#endif 197#endif
187 } 198 }
199 Free(lock_cs);
200 Free(lock_count);
188 } 201 }
189 202
190void solaris_locking_callback(int mode, int type, char *file, int line) 203void solaris_locking_callback(int mode, int type, char *file, int line)
@@ -237,7 +250,7 @@ unsigned long solaris_thread_id(void)
237/* I don't think this works..... */ 250/* I don't think this works..... */
238 251
239static usptr_t *arena; 252static usptr_t *arena;
240static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 253static usema_t **lock_cs;
241 254
242void CRYPTO_thread_setup(void) 255void CRYPTO_thread_setup(void)
243 { 256 {
@@ -254,7 +267,8 @@ void CRYPTO_thread_setup(void)
254 arena=usinit(filename); 267 arena=usinit(filename);
255 unlink(filename); 268 unlink(filename);
256 269
257 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 270 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *));
271 for (i=0; i<CRYPTO_num_locks(); i++)
258 { 272 {
259 lock_cs[i]=usnewsema(arena,1); 273 lock_cs[i]=usnewsema(arena,1);
260 } 274 }
@@ -268,7 +282,7 @@ void CRYPTO_thread_cleanup(void)
268 int i; 282 int i;
269 283
270 CRYPTO_set_locking_callback(NULL); 284 CRYPTO_set_locking_callback(NULL);
271 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 285 for (i=0; i<CRYPTO_num_locks(); i++)
272 { 286 {
273 char buf[10]; 287 char buf[10];
274 288
@@ -276,6 +290,7 @@ void CRYPTO_thread_cleanup(void)
276 usdumpsema(lock_cs[i],stdout,buf); 290 usdumpsema(lock_cs[i],stdout,buf);
277 usfreesema(lock_cs[i],arena); 291 usfreesema(lock_cs[i],arena);
278 } 292 }
293 Free(lock_cs);
279 } 294 }
280 295
281void irix_locking_callback(int mode, int type, char *file, int line) 296void irix_locking_callback(int mode, int type, char *file, int line)
@@ -302,14 +317,16 @@ unsigned long irix_thread_id(void)
302/* Linux and a few others */ 317/* Linux and a few others */
303#ifdef PTHREADS 318#ifdef PTHREADS
304 319
305static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 320static pthread_mutex_t *lock_cs;
306static long lock_count[CRYPTO_NUM_LOCKS]; 321static long *lock_count;
307 322
308void CRYPTO_thread_setup(void) 323void CRYPTO_thread_setup(void)
309 { 324 {
310 int i; 325 int i;
311 326
312 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 327 lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
328 lock_count=Malloc(CRYPTO_num_locks() * sizeof(long));
329 for (i=0; i<CRYPTO_num_locks(); i++)
313 { 330 {
314 lock_count[i]=0; 331 lock_count[i]=0;
315 pthread_mutex_init(&(lock_cs[i]),NULL); 332 pthread_mutex_init(&(lock_cs[i]),NULL);
@@ -324,10 +341,12 @@ void thread_cleanup(void)
324 int i; 341 int i;
325 342
326 CRYPTO_set_locking_callback(NULL); 343 CRYPTO_set_locking_callback(NULL);
327 for (i=0; i<CRYPTO_NUM_LOCKS; i++) 344 for (i=0; i<CRYPTO_num_locks(); i++)
328 { 345 {
329 pthread_mutex_destroy(&(lock_cs[i])); 346 pthread_mutex_destroy(&(lock_cs[i]));
330 } 347 }
348 Free(lock_cs);
349 Free(lock_count);
331 } 350 }
332 351
333void pthreads_locking_callback(int mode, int type, char *file, 352void pthreads_locking_callback(int mode, int type, char *file,
diff --git a/src/lib/libcrypto/threads/win32.bat b/src/lib/libcrypto/threads/win32.bat
new file mode 100644
index 0000000000..ee6da80a07
--- /dev/null
+++ b/src/lib/libcrypto/threads/win32.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssleay32.lib ..\..\out\libeay32.lib
4