Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4237373

Browse filesBrowse files
bnoordhuisrvagg
authored andcommitted
crypto: replace rwlocks with simple mutexes
It was pointed out by Zhou Ran that the Windows XP implementation of uv_rwlock_rdlock() and friends may unlock the inner write mutex on a different thread than the one that locked it, resulting in undefined behavior. The only place that uses rwlocks is the crypto module. Make that use normal (simple) mutexes instead. OpenSSL's critical sections are generally very short, with exclusive access outnumbering shared access by a factor of three or more, so it's not as if using rwlocks gives a decisive performance advantage. PR-URL: #2723 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent 28c2d31 commit 4237373
Copy full SHA for 4237373

File tree

Expand file treeCollapse file tree

1 file changed

+9
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-16
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+9-16Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ struct ClearErrorOnReturn {
124124
~ClearErrorOnReturn() { ERR_clear_error(); }
125125
};
126126

127-
static uv_rwlock_t* locks;
127+
static uv_mutex_t* locks;
128128

129129
const char* const root_certs[] = {
130130
#include "node_root_certs.h" // NOLINT(build/include_order)
@@ -179,29 +179,22 @@ static void crypto_lock_init(void) {
179179
int i, n;
180180

181181
n = CRYPTO_num_locks();
182-
locks = new uv_rwlock_t[n];
182+
locks = new uv_mutex_t[n];
183183

184184
for (i = 0; i < n; i++)
185-
if (uv_rwlock_init(locks + i))
185+
if (uv_mutex_init(locks + i))
186186
abort();
187187
}
188188

189189

190190
static void crypto_lock_cb(int mode, int n, const char* file, int line) {
191-
CHECK((mode & CRYPTO_LOCK) || (mode & CRYPTO_UNLOCK));
192-
CHECK((mode & CRYPTO_READ) || (mode & CRYPTO_WRITE));
191+
CHECK(!(mode & CRYPTO_LOCK) ^ !(mode & CRYPTO_UNLOCK));
192+
CHECK(!(mode & CRYPTO_READ) ^ !(mode & CRYPTO_WRITE));
193193

194-
if (mode & CRYPTO_LOCK) {
195-
if (mode & CRYPTO_READ)
196-
uv_rwlock_rdlock(locks + n);
197-
else
198-
uv_rwlock_wrlock(locks + n);
199-
} else {
200-
if (mode & CRYPTO_READ)
201-
uv_rwlock_rdunlock(locks + n);
202-
else
203-
uv_rwlock_wrunlock(locks + n);
204-
}
194+
if (mode & CRYPTO_LOCK)
195+
uv_mutex_lock(locks + n);
196+
else
197+
uv_mutex_unlock(locks + n);
205198
}
206199

207200

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.