Title: [231297] trunk/Source/WebCore
- Revision
- 231297
- Author
- [email protected]
- Date
- 2018-05-03 00:23:08 -0700 (Thu, 03 May 2018)
Log Message
[Curl] Add OpenSSL/LibreSSL multi-threading support
https://bugs.webkit.org/show_bug.cgi?id=185138
The older OpenSSL manual says the locking_function and threadid_function should
be set when use it in multi-threading environment. This applies to LibreSSL also.
https://www.openssl.org/docs/man1.0.2/crypto/threads.html
For unix and other similar os, the default threadId_function implementation is
good enough. We'll set custom callback only for Windows OS.
Note it's not required for OpenSSL 1.1.0 and after.
https://www.openssl.org/blog/blog/2017/02/21/threads/
Patch by Basuke Suzuki <[email protected]> on 2018-05-03
Reviewed by Per Arne Vollan.
* platform/network/curl/CurlSSLHandle.cpp:
(WebCore::CurlSSLHandle::CurlSSLHandle):
(WebCore::CurlSSLHandle::ThreadSupport::ThreadSupport):
(WebCore::CurlSSLHandle::ThreadSupport::lockingCallback):
(WebCore::CurlSSLHandle::ThreadSupport::threadIdCallback):
* platform/network/curl/CurlSSLHandle.h:
(WebCore::CurlSSLHandle::ThreadSupport::setup):
(WebCore::CurlSSLHandle::ThreadSupport::singleton):
(WebCore::CurlSSLHandle::ThreadSupport::lock):
(WebCore::CurlSSLHandle::ThreadSupport::unlock):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (231296 => 231297)
--- trunk/Source/WebCore/ChangeLog 2018-05-03 07:06:16 UTC (rev 231296)
+++ trunk/Source/WebCore/ChangeLog 2018-05-03 07:23:08 UTC (rev 231297)
@@ -1,3 +1,31 @@
+2018-05-03 Basuke Suzuki <[email protected]>
+
+ [Curl] Add OpenSSL/LibreSSL multi-threading support
+ https://bugs.webkit.org/show_bug.cgi?id=185138
+
+ The older OpenSSL manual says the locking_function and threadid_function should
+ be set when use it in multi-threading environment. This applies to LibreSSL also.
+ https://www.openssl.org/docs/man1.0.2/crypto/threads.html
+
+ For unix and other similar os, the default threadId_function implementation is
+ good enough. We'll set custom callback only for Windows OS.
+
+ Note it's not required for OpenSSL 1.1.0 and after.
+ https://www.openssl.org/blog/blog/2017/02/21/threads/
+
+ Reviewed by Per Arne Vollan.
+
+ * platform/network/curl/CurlSSLHandle.cpp:
+ (WebCore::CurlSSLHandle::CurlSSLHandle):
+ (WebCore::CurlSSLHandle::ThreadSupport::ThreadSupport):
+ (WebCore::CurlSSLHandle::ThreadSupport::lockingCallback):
+ (WebCore::CurlSSLHandle::ThreadSupport::threadIdCallback):
+ * platform/network/curl/CurlSSLHandle.h:
+ (WebCore::CurlSSLHandle::ThreadSupport::setup):
+ (WebCore::CurlSSLHandle::ThreadSupport::singleton):
+ (WebCore::CurlSSLHandle::ThreadSupport::lock):
+ (WebCore::CurlSSLHandle::ThreadSupport::unlock):
+
2018-05-02 Ryosuke Niwa <[email protected]>
Remove superfluous check for a null attribute value check in Element::removeAttributeInternal
Modified: trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.cpp (231296 => 231297)
--- trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.cpp 2018-05-03 07:06:16 UTC (rev 231296)
+++ trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.cpp 2018-05-03 07:23:08 UTC (rev 231297)
@@ -37,6 +37,10 @@
#include <wtf/RetainPtr.h>
#endif
+#if NEED_OPENSSL_THREAD_SUPPORT && OS(WINDOWS)
+#include <wtf/Threading.h>
+#endif
+
namespace WebCore {
CurlSSLHandle::CurlSSLHandle()
@@ -45,6 +49,10 @@
char* ignoreSSLErrors = getenv("WEBKIT_IGNORE_SSL_ERRORS");
if (ignoreSSLErrors)
m_ignoreSSLErrors = true;
+
+#if NEED_OPENSSL_THREAD_SUPPORT
+ ThreadSupport::setup();
+#endif
}
CString CurlSSLHandle::getCACertPathEnv()
@@ -120,6 +128,46 @@
return it->value;
}
+#if NEED_OPENSSL_THREAD_SUPPORT
+
+void CurlSSLHandle::ThreadSupport::setup()
+{
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ singleton();
+ });
}
+CurlSSLHandle::ThreadSupport::ThreadSupport()
+{
+ CRYPTO_set_locking_callback(lockingCallback);
+#if OS(WINDOWS)
+ CRYPTO_THREADID_set_callback(threadIdCallback);
#endif
+}
+
+void CurlSSLHandle::ThreadSupport::lockingCallback(int mode, int type, const char*, int)
+{
+ RELEASE_ASSERT(type >= 0 && type < CRYPTO_NUM_LOCKS);
+ auto& locker = ThreadSupport::singleton();
+
+ if (mode & CRYPTO_LOCK)
+ locker.lock(type);
+ else
+ locker.unlock(type);
+}
+
+#if OS(WINDOWS)
+
+void CurlSSLHandle::ThreadSupport::threadIdCallback(CRYPTO_THREADID* threadId)
+{
+ CRYPTO_THREADID_set_numeric(threadId, static_cast<unsigned long>(Thread::currentID()));
+}
+
+#endif
+
+#endif
+
+}
+
+#endif
Modified: trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.h (231296 => 231297)
--- trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.h 2018-05-03 07:06:16 UTC (rev 231296)
+++ trunk/Source/WebCore/platform/network/curl/CurlSSLHandle.h 2018-05-03 07:23:08 UTC (rev 231297)
@@ -26,11 +26,20 @@
#pragma once
+#include <openssl/crypto.h>
#include <wtf/HashMap.h>
#include <wtf/ListHashSet.h>
+#include <wtf/NeverDestroyed.h>
#include <wtf/Noncopyable.h>
#include <wtf/text/StringHash.h>
+// all version of LibreSSL and OpenSSL prior to 1.1.0 need thread support
+#if defined(LIBRESSL_VERSION_NUMBER) || (defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1010000fL)
+#define NEED_OPENSSL_THREAD_SUPPORT 1
+#else
+#define NEED_OPENSSL_THREAD_SUPPORT 0
+#endif
+
namespace WebCore {
class CurlSSLHandle {
@@ -55,6 +64,33 @@
private:
CString getCACertPathEnv();
+#if NEED_OPENSSL_THREAD_SUPPORT
+ class ThreadSupport {
+ friend NeverDestroyed<CurlSSLHandle::ThreadSupport>;
+
+ public:
+ static void setup();
+
+ private:
+ static ThreadSupport& singleton()
+ {
+ static NeverDestroyed<CurlSSLHandle::ThreadSupport> shared;
+ return shared;
+ }
+
+ ThreadSupport();
+ void lock(int type) { m_locks[type].lock(); }
+ void unlock(int type) { m_locks[type].unlock(); }
+
+ Lock m_locks[CRYPTO_NUM_LOCKS];
+
+ static void lockingCallback(int mode, int type, const char* file, int line);
+#if OS(WINDOWS)
+ static void threadIdCallback(CRYPTO_THREADID*);
+#endif
+ };
+#endif
+
bool m_ignoreSSLErrors { false };
CString m_caCertPath;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes