Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/openssl_util.h" | 5 #include "crypto/openssl_util.h" |
| 6 | 6 |
| 7 #include <openssl/err.h> | 7 #include <openssl/err.h> |
| 8 #include <openssl/ssl.h> | 8 #include <openssl/ssl.h> |
| 9 #include <openssl/cpu.h> | 9 #include <openssl/cpu.h> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 // context) who's cleanup depends on the global environment here, but | 41 // context) who's cleanup depends on the global environment here, but |
| 42 // we can't control the order the AtExit handlers will run in so | 42 // we can't control the order the AtExit handlers will run in so |
| 43 // allowing the global environment to leak at least ensures it is | 43 // allowing the global environment to leak at least ensures it is |
| 44 // available for those other singletons to reliably cleanup. | 44 // available for those other singletons to reliably cleanup. |
| 45 return Singleton<OpenSSLInitSingleton, | 45 return Singleton<OpenSSLInitSingleton, |
| 46 LeakySingletonTraits<OpenSSLInitSingleton> >::get(); | 46 LeakySingletonTraits<OpenSSLInitSingleton> >::get(); |
| 47 } | 47 } |
| 48 private: | 48 private: |
| 49 friend struct DefaultSingletonTraits<OpenSSLInitSingleton>; | 49 friend struct DefaultSingletonTraits<OpenSSLInitSingleton>; |
| 50 OpenSSLInitSingleton() { | 50 OpenSSLInitSingleton() { |
| 51 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) | |
| 52 const bool has_neon = | |
| 53 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; | |
| 54 // CRYPTO_set_NEON_capable is called before |SSL_library_init| because this | |
| 55 // stops BoringSSL from probing for NEON support via SIGILL in the case | |
| 56 // that getauxval isn't present. | |
|
davidben
2015/02/02 19:47:16
Fun fact: this also avoids a deadlock were CRYPTO_
| |
| 57 CRYPTO_set_NEON_capable(has_neon); | |
| 58 // See https://code.google.com/p/chromium/issues/detail?id=341598 | |
| 59 base::CPU cpu; | |
| 60 CRYPTO_set_NEON_functional(!cpu.has_broken_neon()); | |
| 61 #endif | |
| 62 | |
| 51 SSL_load_error_strings(); | 63 SSL_load_error_strings(); |
| 52 SSL_library_init(); | 64 SSL_library_init(); |
| 53 int num_locks = CRYPTO_num_locks(); | 65 int num_locks = CRYPTO_num_locks(); |
| 54 locks_.reserve(num_locks); | 66 locks_.reserve(num_locks); |
| 55 for (int i = 0; i < num_locks; ++i) | 67 for (int i = 0; i < num_locks; ++i) |
| 56 locks_.push_back(new base::Lock()); | 68 locks_.push_back(new base::Lock()); |
| 57 CRYPTO_set_locking_callback(LockingCallback); | 69 CRYPTO_set_locking_callback(LockingCallback); |
| 58 CRYPTO_THREADID_set_callback(CurrentThreadId); | 70 CRYPTO_THREADID_set_callback(CurrentThreadId); |
| 59 | |
| 60 #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) | |
| 61 const bool has_neon = | |
| 62 (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0; | |
| 63 if (has_neon) | |
| 64 CRYPTO_set_NEON_capable(1); | |
| 65 // See https://code.google.com/p/chromium/issues/detail?id=341598 | |
| 66 base::CPU cpu; | |
| 67 CRYPTO_set_NEON_functional(!cpu.has_broken_neon()); | |
| 68 #endif | |
| 69 } | 71 } |
| 70 | 72 |
| 71 ~OpenSSLInitSingleton() { | 73 ~OpenSSLInitSingleton() { |
| 72 CRYPTO_set_locking_callback(NULL); | 74 CRYPTO_set_locking_callback(NULL); |
| 73 EVP_cleanup(); | 75 EVP_cleanup(); |
| 74 ERR_free_strings(); | 76 ERR_free_strings(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 static void LockingCallback(int mode, int n, const char* file, int line) { | 79 static void LockingCallback(int mode, int n, const char* file, int line) { |
| 78 OpenSSLInitSingleton::GetInstance()->OnLockingCallback(mode, n, file, line); | 80 OpenSSLInitSingleton::GetInstance()->OnLockingCallback(mode, n, file, line); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 std::string message; | 123 std::string message; |
| 122 location.Write(true, true, &message); | 124 location.Write(true, true, &message); |
| 123 DVLOG(1) << "OpenSSL ERR_get_error stack from " << message; | 125 DVLOG(1) << "OpenSSL ERR_get_error stack from " << message; |
| 124 ERR_print_errors_cb(&OpenSSLErrorCallback, NULL); | 126 ERR_print_errors_cb(&OpenSSLErrorCallback, NULL); |
| 125 } else { | 127 } else { |
| 126 ERR_clear_error(); | 128 ERR_clear_error(); |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 | 131 |
| 130 } // namespace crypto | 132 } // namespace crypto |
| OLD | NEW |