diff options
| author | markus <> | 2002-09-05 12:51:52 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-05 12:51:52 +0000 |
| commit | 5514995a9d5ed91db089875adb509c7781357c0e (patch) | |
| tree | 2484410a46ba6c05ef94c253da36fbceef990b64 /src/lib/libcrypto/threads/mttest.c | |
| parent | fd9566423b542798f5c8b06e68101a9ea5bb9885 (diff) | |
| download | openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.gz openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.bz2 openbsd-5514995a9d5ed91db089875adb509c7781357c0e.zip | |
import openssl-0.9.7-beta1
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/threads/mttest.c | 247 |
1 files changed, 116 insertions, 131 deletions
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c index be395f2bc4..7142e4edc7 100644 --- a/src/lib/libcrypto/threads/mttest.c +++ b/src/lib/libcrypto/threads/mttest.c | |||
| @@ -63,7 +63,7 @@ | |||
| 63 | #ifdef LINUX | 63 | #ifdef LINUX |
| 64 | #include <typedefs.h> | 64 | #include <typedefs.h> |
| 65 | #endif | 65 | #endif |
| 66 | #ifdef WIN32 | 66 | #ifdef OPENSSL_SYS_WIN32 |
| 67 | #include <windows.h> | 67 | #include <windows.h> |
| 68 | #endif | 68 | #endif |
| 69 | #ifdef SOLARIS | 69 | #ifdef SOLARIS |
| @@ -74,27 +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 | #include "lhash.h" | 77 | #ifdef PTHREADS |
| 78 | #include "crypto.h" | 78 | #include <pthread.h> |
| 79 | #include "buffer.h" | 79 | #endif |
| 80 | #include "../e_os.h" | 80 | #include <openssl/lhash.h> |
| 81 | #include "x509.h" | 81 | #include <openssl/crypto.h> |
| 82 | #include "ssl.h" | 82 | #include <openssl/buffer.h> |
| 83 | #include "err.h" | 83 | #include "../../e_os.h" |
| 84 | 84 | #include <openssl/x509.h> | |
| 85 | #ifdef NO_FP_API | 85 | #include <openssl/ssl.h> |
| 86 | #include <openssl/err.h> | ||
| 87 | #include <openssl/rand.h> | ||
| 88 | |||
| 89 | #ifdef OPENSSL_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 | ||
| 95 | #ifndef NOPROTO | 99 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs); |
| 96 | int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, | ||
| 97 | int error,char *arg); | ||
| 98 | void thread_setup(void); | 100 | void thread_setup(void); |
| 99 | void thread_cleanup(void); | 101 | void thread_cleanup(void); |
| 100 | void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); | 102 | void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); |
| @@ -108,23 +110,6 @@ unsigned long irix_thread_id(void ); | |||
| 108 | unsigned long solaris_thread_id(void ); | 110 | unsigned long solaris_thread_id(void ); |
| 109 | unsigned long pthreads_thread_id(void ); | 111 | unsigned long pthreads_thread_id(void ); |
| 110 | 112 | ||
| 111 | #else | ||
| 112 | int MS_CALLBACK verify_callback(); | ||
| 113 | void thread_setup(); | ||
| 114 | void thread_cleanup(); | ||
| 115 | void do_threads(); | ||
| 116 | |||
| 117 | void irix_locking_callback(); | ||
| 118 | void solaris_locking_callback(); | ||
| 119 | void win32_locking_callback(); | ||
| 120 | void pthreads_locking_callback(); | ||
| 121 | |||
| 122 | unsigned long irix_thread_id(); | ||
| 123 | unsigned long solaris_thread_id(); | ||
| 124 | unsigned long pthreads_thread_id(); | ||
| 125 | |||
| 126 | #endif | ||
| 127 | |||
| 128 | BIO *bio_err=NULL; | 113 | BIO *bio_err=NULL; |
| 129 | BIO *bio_stdout=NULL; | 114 | BIO *bio_stdout=NULL; |
| 130 | 115 | ||
| @@ -139,15 +124,10 @@ int number_of_loops=10; | |||
| 139 | int reconnect=0; | 124 | int reconnect=0; |
| 140 | int cache_stats=0; | 125 | int cache_stats=0; |
| 141 | 126 | ||
| 142 | #ifndef NOPROTO | 127 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; |
| 143 | int doit(char *ctx[4]); | ||
| 144 | #else | ||
| 145 | int doit(); | ||
| 146 | #endif | ||
| 147 | 128 | ||
| 148 | static void print_stats(fp,ctx) | 129 | int doit(char *ctx[4]); |
| 149 | FILE *fp; | 130 | static void print_stats(FILE *fp, SSL_CTX *ctx) |
| 150 | SSL_CTX *ctx; | ||
| 151 | { | 131 | { |
| 152 | fprintf(fp,"%4ld items in the session cache\n", | 132 | fprintf(fp,"%4ld items in the session cache\n", |
| 153 | SSL_CTX_sess_number(ctx)); | 133 | SSL_CTX_sess_number(ctx)); |
| @@ -164,7 +144,7 @@ SSL_CTX *ctx; | |||
| 164 | fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx)); | 144 | fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx)); |
| 165 | } | 145 | } |
| 166 | 146 | ||
| 167 | static void sv_usage() | 147 | static void sv_usage(void) |
| 168 | { | 148 | { |
| 169 | fprintf(stderr,"usage: ssltest [args ...]\n"); | 149 | fprintf(stderr,"usage: ssltest [args ...]\n"); |
| 170 | fprintf(stderr,"\n"); | 150 | fprintf(stderr,"\n"); |
| @@ -182,9 +162,7 @@ static void sv_usage() | |||
| 182 | fprintf(stderr," -ssl3 - just SSLv3n\n"); | 162 | fprintf(stderr," -ssl3 - just SSLv3n\n"); |
| 183 | } | 163 | } |
| 184 | 164 | ||
| 185 | int main(argc, argv) | 165 | int main(int argc, char *argv[]) |
| 186 | int argc; | ||
| 187 | char *argv[]; | ||
| 188 | { | 166 | { |
| 189 | char *CApath=NULL,*CAfile=NULL; | 167 | char *CApath=NULL,*CAfile=NULL; |
| 190 | int badop=0; | 168 | int badop=0; |
| @@ -197,6 +175,8 @@ char *argv[]; | |||
| 197 | char *ccert=TEST_CLIENT_CERT; | 175 | char *ccert=TEST_CLIENT_CERT; |
| 198 | SSL_METHOD *ssl_method=SSLv23_method(); | 176 | SSL_METHOD *ssl_method=SSLv23_method(); |
| 199 | 177 | ||
| 178 | RAND_seed(rnd_seed, sizeof rnd_seed); | ||
| 179 | |||
| 200 | if (bio_err == NULL) | 180 | if (bio_err == NULL) |
| 201 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | 181 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); |
| 202 | if (bio_stdout == NULL) | 182 | if (bio_stdout == NULL) |
| @@ -271,7 +251,7 @@ bad: | |||
| 271 | if (cipher == NULL) cipher=getenv("SSL_CIPHER"); | 251 | if (cipher == NULL) cipher=getenv("SSL_CIPHER"); |
| 272 | 252 | ||
| 273 | SSL_load_error_strings(); | 253 | SSL_load_error_strings(); |
| 274 | SSLeay_add_ssl_algorithms(); | 254 | OpenSSL_add_ssl_algorithms(); |
| 275 | 255 | ||
| 276 | c_ctx=SSL_CTX_new(ssl_method); | 256 | c_ctx=SSL_CTX_new(ssl_method); |
| 277 | s_ctx=SSL_CTX_new(ssl_method); | 257 | s_ctx=SSL_CTX_new(ssl_method); |
| @@ -286,8 +266,15 @@ bad: | |||
| 286 | SSL_CTX_set_session_cache_mode(c_ctx, | 266 | SSL_CTX_set_session_cache_mode(c_ctx, |
| 287 | SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); | 267 | SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); |
| 288 | 268 | ||
| 289 | SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); | 269 | if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM)) |
| 290 | 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 | } | ||
| 291 | 278 | ||
| 292 | if (client_auth) | 279 | if (client_auth) |
| 293 | { | 280 | { |
| @@ -358,8 +345,7 @@ end: | |||
| 358 | #define C_DONE 1 | 345 | #define C_DONE 1 |
| 359 | #define S_DONE 2 | 346 | #define S_DONE 2 |
| 360 | 347 | ||
| 361 | int ndoit(ssl_ctx) | 348 | int ndoit(SSL_CTX *ssl_ctx[2]) |
| 362 | SSL_CTX *ssl_ctx[2]; | ||
| 363 | { | 349 | { |
| 364 | int i; | 350 | int i; |
| 365 | int ret; | 351 | int ret; |
| @@ -405,8 +391,7 @@ SSL_CTX *ssl_ctx[2]; | |||
| 405 | return(0); | 391 | return(0); |
| 406 | } | 392 | } |
| 407 | 393 | ||
| 408 | int doit(ctx) | 394 | int doit(char *ctx[4]) |
| 409 | char *ctx[4]; | ||
| 410 | { | 395 | { |
| 411 | SSL_CTX *s_ctx,*c_ctx; | 396 | SSL_CTX *s_ctx,*c_ctx; |
| 412 | static char cbuf[200],sbuf[200]; | 397 | static char cbuf[200],sbuf[200]; |
| @@ -518,6 +503,7 @@ char *ctx[4]; | |||
| 518 | else | 503 | else |
| 519 | { | 504 | { |
| 520 | fprintf(stderr,"ERROR in CLIENT\n"); | 505 | fprintf(stderr,"ERROR in CLIENT\n"); |
| 506 | ERR_print_errors_fp(stderr); | ||
| 521 | return(1); | 507 | return(1); |
| 522 | } | 508 | } |
| 523 | } | 509 | } |
| @@ -549,6 +535,7 @@ char *ctx[4]; | |||
| 549 | else | 535 | else |
| 550 | { | 536 | { |
| 551 | fprintf(stderr,"ERROR in CLIENT\n"); | 537 | fprintf(stderr,"ERROR in CLIENT\n"); |
| 538 | ERR_print_errors_fp(stderr); | ||
| 552 | return(1); | 539 | return(1); |
| 553 | } | 540 | } |
| 554 | } | 541 | } |
| @@ -681,38 +668,39 @@ err: | |||
| 681 | return(0); | 668 | return(0); |
| 682 | } | 669 | } |
| 683 | 670 | ||
| 684 | int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg) | 671 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx) |
| 685 | int ok; | ||
| 686 | X509 *xs; | ||
| 687 | X509 *xi; | ||
| 688 | int depth; | ||
| 689 | int error; | ||
| 690 | char *arg; | ||
| 691 | { | 672 | { |
| 692 | char buf[256]; | 673 | char *s, buf[256]; |
| 693 | 674 | ||
| 694 | if (verbose) | 675 | if (verbose) |
| 695 | { | 676 | { |
| 696 | X509_NAME_oneline(X509_get_subject_name(xs),buf,256); | 677 | s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert), |
| 697 | if (ok) | 678 | buf,256); |
| 698 | fprintf(stderr,"depth=%d %s\n",depth,buf); | 679 | if (s != NULL) |
| 699 | else | 680 | { |
| 700 | 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 | } | ||
| 701 | } | 688 | } |
| 702 | return(ok); | 689 | return(ok); |
| 703 | } | 690 | } |
| 704 | 691 | ||
| 705 | #define THREAD_STACK_SIZE (16*1024) | 692 | #define THREAD_STACK_SIZE (16*1024) |
| 706 | 693 | ||
| 707 | #ifdef WIN32 | 694 | #ifdef OPENSSL_SYS_WIN32 |
| 708 | 695 | ||
| 709 | static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; | 696 | static HANDLE *lock_cs; |
| 710 | 697 | ||
| 711 | void thread_setup() | 698 | void thread_setup(void) |
| 712 | { | 699 | { |
| 713 | int i; | 700 | int i; |
| 714 | 701 | ||
| 715 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 702 | lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(HANDLE)); |
| 703 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
| 716 | { | 704 | { |
| 717 | lock_cs[i]=CreateMutex(NULL,FALSE,NULL); | 705 | lock_cs[i]=CreateMutex(NULL,FALSE,NULL); |
| 718 | } | 706 | } |
| @@ -721,20 +709,17 @@ void thread_setup() | |||
| 721 | /* id callback defined */ | 709 | /* id callback defined */ |
| 722 | } | 710 | } |
| 723 | 711 | ||
| 724 | void thread_cleanup() | 712 | void thread_cleanup(void) |
| 725 | { | 713 | { |
| 726 | int i; | 714 | int i; |
| 727 | 715 | ||
| 728 | CRYPTO_set_locking_callback(NULL); | 716 | CRYPTO_set_locking_callback(NULL); |
| 729 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 717 | for (i=0; i<CRYPTO_num_locks(); i++) |
| 730 | CloseHandle(lock_cs[i]); | 718 | CloseHandle(lock_cs[i]); |
| 719 | OPENSSL_free(lock_cs); | ||
| 731 | } | 720 | } |
| 732 | 721 | ||
| 733 | void win32_locking_callback(mode,type,file,line) | 722 | void win32_locking_callback(int mode, int type, char *file, int line) |
| 734 | int mode; | ||
| 735 | int type; | ||
| 736 | char *file; | ||
| 737 | int line; | ||
| 738 | { | 723 | { |
| 739 | if (mode & CRYPTO_LOCK) | 724 | if (mode & CRYPTO_LOCK) |
| 740 | { | 725 | { |
| @@ -746,8 +731,7 @@ int line; | |||
| 746 | } | 731 | } |
| 747 | } | 732 | } |
| 748 | 733 | ||
| 749 | void do_threads(s_ctx,c_ctx) | 734 | void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) |
| 750 | SSL_CTX *s_ctx,*c_ctx; | ||
| 751 | { | 735 | { |
| 752 | double ret; | 736 | double ret; |
| 753 | SSL_CTX *ssl_ctx[2]; | 737 | SSL_CTX *ssl_ctx[2]; |
| @@ -798,19 +782,21 @@ SSL_CTX *s_ctx,*c_ctx; | |||
| 798 | printf("win32 threads done - %.3f seconds\n",ret); | 782 | printf("win32 threads done - %.3f seconds\n",ret); |
| 799 | } | 783 | } |
| 800 | 784 | ||
| 801 | #endif /* WIN32 */ | 785 | #endif /* OPENSSL_SYS_WIN32 */ |
| 802 | 786 | ||
| 803 | #ifdef SOLARIS | 787 | #ifdef SOLARIS |
| 804 | 788 | ||
| 805 | static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | 789 | static mutex_t *lock_cs; |
| 806 | /*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ | 790 | /*static rwlock_t *lock_cs; */ |
| 807 | static long lock_count[CRYPTO_NUM_LOCKS]; | 791 | static long *lock_count; |
| 808 | 792 | ||
| 809 | void thread_setup() | 793 | void thread_setup(void) |
| 810 | { | 794 | { |
| 811 | int i; | 795 | int i; |
| 812 | 796 | ||
| 813 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 797 | lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(mutex_t)); |
| 798 | lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); | ||
| 799 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
| 814 | { | 800 | { |
| 815 | lock_count[i]=0; | 801 | lock_count[i]=0; |
| 816 | /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ | 802 | /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ |
| @@ -821,40 +807,42 @@ void thread_setup() | |||
| 821 | CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); | 807 | CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); |
| 822 | } | 808 | } |
| 823 | 809 | ||
| 824 | void thread_cleanup() | 810 | void thread_cleanup(void) |
| 825 | { | 811 | { |
| 826 | int i; | 812 | int i; |
| 827 | 813 | ||
| 828 | CRYPTO_set_locking_callback(NULL); | 814 | CRYPTO_set_locking_callback(NULL); |
| 829 | fprintf(stderr,"cleanup\n"); | 815 | |
| 830 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 816 | fprintf(stderr,"cleanup\n"); |
| 817 | |||
| 818 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
| 831 | { | 819 | { |
| 832 | /* rwlock_destroy(&(lock_cs[i])); */ | 820 | /* rwlock_destroy(&(lock_cs[i])); */ |
| 833 | mutex_destroy(&(lock_cs[i])); | 821 | mutex_destroy(&(lock_cs[i])); |
| 834 | 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)); |
| 835 | } | 823 | } |
| 836 | fprintf(stderr,"done cleanup\n"); | 824 | OPENSSL_free(lock_cs); |
| 825 | OPENSSL_free(lock_count); | ||
| 826 | |||
| 827 | fprintf(stderr,"done cleanup\n"); | ||
| 828 | |||
| 837 | } | 829 | } |
| 838 | 830 | ||
| 839 | void solaris_locking_callback(mode,type,file,line) | 831 | void solaris_locking_callback(int mode, int type, char *file, int line) |
| 840 | int mode; | ||
| 841 | int type; | ||
| 842 | char *file; | ||
| 843 | int line; | ||
| 844 | { | 832 | { |
| 845 | #ifdef undef | 833 | #ifdef undef |
| 846 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | 834 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", |
| 847 | CRYPTO_thread_id(), | 835 | CRYPTO_thread_id(), |
| 848 | (mode&CRYPTO_LOCK)?"l":"u", | 836 | (mode&CRYPTO_LOCK)?"l":"u", |
| 849 | (type&CRYPTO_READ)?"r":"w",file,line); | 837 | (type&CRYPTO_READ)?"r":"w",file,line); |
| 850 | #endif | 838 | #endif |
| 851 | 839 | ||
| 852 | /* | 840 | /* |
| 853 | if (CRYPTO_LOCK_SSL_CERT == type) | 841 | if (CRYPTO_LOCK_SSL_CERT == type) |
| 854 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", | 842 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", |
| 855 | CRYPTO_thread_id(), | 843 | CRYPTO_thread_id(), |
| 856 | mode,file,line); | 844 | mode,file,line); |
| 857 | */ | 845 | */ |
| 858 | if (mode & CRYPTO_LOCK) | 846 | if (mode & CRYPTO_LOCK) |
| 859 | { | 847 | { |
| 860 | /* if (mode & CRYPTO_READ) | 848 | /* if (mode & CRYPTO_READ) |
| @@ -872,8 +860,7 @@ if (CRYPTO_LOCK_SSL_CERT == type) | |||
| 872 | } | 860 | } |
| 873 | } | 861 | } |
| 874 | 862 | ||
| 875 | void do_threads(s_ctx,c_ctx) | 863 | void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) |
| 876 | SSL_CTX *s_ctx,*c_ctx; | ||
| 877 | { | 864 | { |
| 878 | SSL_CTX *ssl_ctx[2]; | 865 | SSL_CTX *ssl_ctx[2]; |
| 879 | thread_t thread_ctx[MAX_THREAD_NUMBER]; | 866 | thread_t thread_ctx[MAX_THREAD_NUMBER]; |
| @@ -902,7 +889,7 @@ SSL_CTX *s_ctx,*c_ctx; | |||
| 902 | s_ctx->references,c_ctx->references); | 889 | s_ctx->references,c_ctx->references); |
| 903 | } | 890 | } |
| 904 | 891 | ||
| 905 | unsigned long solaris_thread_id() | 892 | unsigned long solaris_thread_id(void) |
| 906 | { | 893 | { |
| 907 | unsigned long ret; | 894 | unsigned long ret; |
| 908 | 895 | ||
| @@ -915,9 +902,9 @@ unsigned long solaris_thread_id() | |||
| 915 | 902 | ||
| 916 | 903 | ||
| 917 | static usptr_t *arena; | 904 | static usptr_t *arena; |
| 918 | static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; | 905 | static usema_t **lock_cs; |
| 919 | 906 | ||
| 920 | void thread_setup() | 907 | void thread_setup(void) |
| 921 | { | 908 | { |
| 922 | int i; | 909 | int i; |
| 923 | char filename[20]; | 910 | char filename[20]; |
| @@ -932,7 +919,8 @@ void thread_setup() | |||
| 932 | arena=usinit(filename); | 919 | arena=usinit(filename); |
| 933 | unlink(filename); | 920 | unlink(filename); |
| 934 | 921 | ||
| 935 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 922 | lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(usema_t *)); |
| 923 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
| 936 | { | 924 | { |
| 937 | lock_cs[i]=usnewsema(arena,1); | 925 | lock_cs[i]=usnewsema(arena,1); |
| 938 | } | 926 | } |
| @@ -941,12 +929,12 @@ void thread_setup() | |||
| 941 | CRYPTO_set_locking_callback((void (*)())irix_locking_callback); | 929 | CRYPTO_set_locking_callback((void (*)())irix_locking_callback); |
| 942 | } | 930 | } |
| 943 | 931 | ||
| 944 | void thread_cleanup() | 932 | void thread_cleanup(void) |
| 945 | { | 933 | { |
| 946 | int i; | 934 | int i; |
| 947 | 935 | ||
| 948 | CRYPTO_set_locking_callback(NULL); | 936 | CRYPTO_set_locking_callback(NULL); |
| 949 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 937 | for (i=0; i<CRYPTO_num_locks(); i++) |
| 950 | { | 938 | { |
| 951 | char buf[10]; | 939 | char buf[10]; |
| 952 | 940 | ||
| @@ -954,13 +942,10 @@ void thread_cleanup() | |||
| 954 | usdumpsema(lock_cs[i],stdout,buf); | 942 | usdumpsema(lock_cs[i],stdout,buf); |
| 955 | usfreesema(lock_cs[i],arena); | 943 | usfreesema(lock_cs[i],arena); |
| 956 | } | 944 | } |
| 945 | OPENSSL_free(lock_cs); | ||
| 957 | } | 946 | } |
| 958 | 947 | ||
| 959 | void irix_locking_callback(mode,type,file,line) | 948 | void irix_locking_callback(int mode, int type, char *file, int line) |
| 960 | int mode; | ||
| 961 | int type; | ||
| 962 | char *file; | ||
| 963 | int line; | ||
| 964 | { | 949 | { |
| 965 | if (mode & CRYPTO_LOCK) | 950 | if (mode & CRYPTO_LOCK) |
| 966 | { | 951 | { |
| @@ -974,8 +959,7 @@ int line; | |||
| 974 | } | 959 | } |
| 975 | } | 960 | } |
| 976 | 961 | ||
| 977 | void do_threads(s_ctx,c_ctx) | 962 | void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) |
| 978 | SSL_CTX *s_ctx,*c_ctx; | ||
| 979 | { | 963 | { |
| 980 | SSL_CTX *ssl_ctx[2]; | 964 | SSL_CTX *ssl_ctx[2]; |
| 981 | int thread_ctx[MAX_THREAD_NUMBER]; | 965 | int thread_ctx[MAX_THREAD_NUMBER]; |
| @@ -1000,7 +984,7 @@ SSL_CTX *s_ctx,*c_ctx; | |||
| 1000 | s_ctx->references,c_ctx->references); | 984 | s_ctx->references,c_ctx->references); |
| 1001 | } | 985 | } |
| 1002 | 986 | ||
| 1003 | unsigned long irix_thread_id() | 987 | unsigned long irix_thread_id(void) |
| 1004 | { | 988 | { |
| 1005 | unsigned long ret; | 989 | unsigned long ret; |
| 1006 | 990 | ||
| @@ -1011,14 +995,16 @@ unsigned long irix_thread_id() | |||
| 1011 | 995 | ||
| 1012 | #ifdef PTHREADS | 996 | #ifdef PTHREADS |
| 1013 | 997 | ||
| 1014 | static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | 998 | static pthread_mutex_t *lock_cs; |
| 1015 | static long lock_count[CRYPTO_NUM_LOCKS]; | 999 | static long *lock_count; |
| 1016 | 1000 | ||
| 1017 | void thread_setup() | 1001 | void thread_setup(void) |
| 1018 | { | 1002 | { |
| 1019 | int i; | 1003 | int i; |
| 1020 | 1004 | ||
| 1021 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 1005 | lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); |
| 1006 | lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); | ||
| 1007 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
| 1022 | { | 1008 | { |
| 1023 | lock_count[i]=0; | 1009 | lock_count[i]=0; |
| 1024 | pthread_mutex_init(&(lock_cs[i]),NULL); | 1010 | pthread_mutex_init(&(lock_cs[i]),NULL); |
| @@ -1028,26 +1014,26 @@ void thread_setup() | |||
| 1028 | CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); | 1014 | CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); |
| 1029 | } | 1015 | } |
| 1030 | 1016 | ||
| 1031 | void thread_cleanup() | 1017 | void thread_cleanup(void) |
| 1032 | { | 1018 | { |
| 1033 | int i; | 1019 | int i; |
| 1034 | 1020 | ||
| 1035 | CRYPTO_set_locking_callback(NULL); | 1021 | CRYPTO_set_locking_callback(NULL); |
| 1036 | fprintf(stderr,"cleanup\n"); | 1022 | fprintf(stderr,"cleanup\n"); |
| 1037 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 1023 | for (i=0; i<CRYPTO_num_locks(); i++) |
| 1038 | { | 1024 | { |
| 1039 | pthread_mutex_destroy(&(lock_cs[i])); | 1025 | pthread_mutex_destroy(&(lock_cs[i])); |
| 1040 | fprintf(stderr,"%8ld:%s\n",lock_count[i], | 1026 | fprintf(stderr,"%8ld:%s\n",lock_count[i], |
| 1041 | CRYPTO_get_lock_name(i)); | 1027 | CRYPTO_get_lock_name(i)); |
| 1042 | } | 1028 | } |
| 1029 | OPENSSL_free(lock_cs); | ||
| 1030 | OPENSSL_free(lock_count); | ||
| 1031 | |||
| 1043 | fprintf(stderr,"done cleanup\n"); | 1032 | fprintf(stderr,"done cleanup\n"); |
| 1044 | } | 1033 | } |
| 1045 | 1034 | ||
| 1046 | void pthreads_locking_callback(mode,type,file,line) | 1035 | void pthreads_locking_callback(int mode, int type, char *file, |
| 1047 | int mode; | 1036 | int line) |
| 1048 | int type; | ||
| 1049 | char *file; | ||
| 1050 | int line; | ||
| 1051 | { | 1037 | { |
| 1052 | #ifdef undef | 1038 | #ifdef undef |
| 1053 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | 1039 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", |
| @@ -1072,8 +1058,7 @@ int line; | |||
| 1072 | } | 1058 | } |
| 1073 | } | 1059 | } |
| 1074 | 1060 | ||
| 1075 | void do_threads(s_ctx,c_ctx) | 1061 | void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) |
| 1076 | SSL_CTX *s_ctx,*c_ctx; | ||
| 1077 | { | 1062 | { |
| 1078 | SSL_CTX *ssl_ctx[2]; | 1063 | SSL_CTX *ssl_ctx[2]; |
| 1079 | pthread_t thread_ctx[MAX_THREAD_NUMBER]; | 1064 | pthread_t thread_ctx[MAX_THREAD_NUMBER]; |
| @@ -1098,10 +1083,10 @@ SSL_CTX *s_ctx,*c_ctx; | |||
| 1098 | } | 1083 | } |
| 1099 | 1084 | ||
| 1100 | printf("pthreads threads done (%d,%d)\n", | 1085 | printf("pthreads threads done (%d,%d)\n", |
| 1101 | s_ctx->references,c_ctx->references); | 1086 | s_ctx->references,c_ctx->references); |
| 1102 | } | 1087 | } |
| 1103 | 1088 | ||
| 1104 | unsigned long pthreads_thread_id() | 1089 | unsigned long pthreads_thread_id(void) |
| 1105 | { | 1090 | { |
| 1106 | unsigned long ret; | 1091 | unsigned long ret; |
| 1107 | 1092 | ||
