aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/tsi
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-02-03 15:04:45 -0800
committerGravatar Julien Boeuf <jboeuf@google.com>2015-02-03 15:04:45 -0800
commit4a0a394758d4f169173c221fe58284fee65970e4 (patch)
tree799be2ace8f0e57b3c111c6bc3bb3bf7b31402c7 /src/core/tsi
parent0825f70ca44730cb4b37042ffaa8cae5fd8c6f04 (diff)
Fixing tsan errors in OpenSSL (#319)
- Added cross-platform implementation of gpr_thd_currentid(); - OpenSSL still shows some TSAN errors on OPENSSL_cleanse which is inherently not thread-safe but this should not matter: see http://stackoverflow.com/questions/26433772/why-does-openssl-cleanse-look-so-complex-and-thread-unsafe
Diffstat (limited to 'src/core/tsi')
-rw-r--r--src/core/tsi/ssl_transport_security.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c
index 0f8cbccb62..e23421fc15 100644
--- a/src/core/tsi/ssl_transport_security.c
+++ b/src/core/tsi/ssl_transport_security.c
@@ -37,6 +37,7 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
+#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security.h"
@@ -103,11 +104,32 @@ typedef struct {
/* --- Library Initialization. ---*/
static gpr_once init_openssl_once = GPR_ONCE_INIT;
+static gpr_mu *openssl_mutexes = NULL;
+
+static void openssl_locking_cb(int mode, int type, const char* file, int line) {
+ if (mode & CRYPTO_LOCK) {
+ gpr_mu_lock(&openssl_mutexes[type]);
+ } else {
+ gpr_mu_unlock(&openssl_mutexes[type]);
+ }
+}
+
+static unsigned long openssl_thread_id_cb(void) {
+ return (unsigned long)gpr_thd_currentid();
+}
static void init_openssl(void) {
+ int i;
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
+ openssl_mutexes = malloc(CRYPTO_num_locks() * sizeof(gpr_mu));
+ GPR_ASSERT(openssl_mutexes != NULL);
+ for (i = 0; i < CRYPTO_num_locks(); i++) {
+ gpr_mu_init(&openssl_mutexes[i]);
+ }
+ CRYPTO_set_locking_callback(openssl_locking_cb);
+ CRYPTO_set_id_callback(openssl_thread_id_cb);
}
/* --- Ssl utils. ---*/