aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-23 14:19:51 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-23 14:19:51 +0000
commit4c4347e6987a5f6170c2a9008acc60eaed7301db (patch)
tree162f7417fc08bc3e2a2b9d0431b9f360ec95464e /ext
parenta84ea119868a36ed02761f9fcbd929de3d828205 (diff)
downloadruby-4c4347e6987a5f6170c2a9008acc60eaed7301db.tar.gz
* ext/openssl/extconf.rb (CRYPTO_THREADID): check exist or not.
* ext/openssl/ossl.c (ossl_thread_id): use rb_nativethread_self() implemented at r42137 to allow threads which doesn't associated with Ruby thread to use openssl functions. * ext/openssl/ossl.c (Init_ossl_locks): If CRYPTO_THREADID is defined (OpenSSL 1.0.0 or later has it) use CRYPTO_THREADID_set_callback() instead of CRYPTO_set_id_callback() because its argument is unsigned long; it may cause id collision on mswin64 whose sizeof(unsigned long) < sizeof(void*). http://www.openssl.org/docs/crypto/threads.html * ext/openssl/ossl.c (ossl_threadid_func): defined for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/extconf.rb1
-rw-r--r--ext/openssl/ossl.c15
2 files changed, 15 insertions, 1 deletions
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index 848e1f2bdc..986ee16cfe 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -144,6 +144,7 @@ if checking_for('OpenSSL version is 0.9.7 or later') {
}
have_header("openssl/ocsp.h")
end
+have_struct_member("CRYPTO_THREADID", "ptr", "openssl/crypto.h")
have_struct_member("EVP_CIPHER_CTX", "flags", "openssl/evp.h")
have_struct_member("EVP_CIPHER_CTX", "engine", "openssl/evp.h")
have_struct_member("X509_ATTRIBUTE", "single", "openssl/x509.h")
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 6032d916d8..f31592505c 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -473,10 +473,19 @@ static void ossl_lock_callback(int mode, int type, const char *file, int line)
}
}
+#ifdef HAVE_CRYPTO_THREADID_PTR
+static void ossl_threadid_func(CRYPTO_THREADID *id)
+{
+ /* register native thread id */
+ CRYPTO_THREADID_set_pointer(id, (void *)rb_nativethread_self());
+}
+#else
static unsigned long ossl_thread_id(void)
{
- return NUM2ULONG(rb_obj_id(rb_thread_current()));
+ /* before OpenSSL 1.0, this is 'unsigned long' */
+ return (unsigned long)rb_nativethread_self();
}
+#endif
static void Init_ossl_locks(void)
{
@@ -494,7 +503,11 @@ static void Init_ossl_locks(void)
rb_nativethread_lock_initialize(&ossl_locks[i]);
}
+#ifdef HAVE_CRYPTO_THREADID_PTR
+ CRYPTO_THREADID_set_callback(ossl_threadid_func);
+#else
CRYPTO_set_id_callback(ossl_thread_id);
+#endif
CRYPTO_set_locking_callback(ossl_lock_callback);
}