From d0111efeada9f21db085e0cc27abd94d408ddaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 17 Dec 2018 17:19:34 +0100 Subject: [PATCH] runtime_loader: Add missing locking around resizing the TLS DTV. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixes crashes when the DTV is concurrently resized by multiple threads. * Fixes JVM crash or endless loop when building OpenJDK. * Should help with #13154, #14129, #14304, #14342. Change-Id: I132600315d76a1a86236c6c70db09a3cdf0a8743 Reviewed-on: https://review.haiku-os.org/771 Reviewed-by: Stephan Aßmus --- src/system/runtime_loader/elf_tls.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/system/runtime_loader/elf_tls.cpp b/src/system/runtime_loader/elf_tls.cpp index f534cecc00..251467c70d 100644 --- a/src/system/runtime_loader/elf_tls.cpp +++ b/src/system/runtime_loader/elf_tls.cpp @@ -12,9 +12,14 @@ #include +#include #include +static const char* const kLockName = "runtime loader tls"; +static mutex sLock = MUTEX_INITIALIZER(kLockName); + + class TLSBlock { public: inline TLSBlock(); @@ -280,6 +285,13 @@ DynamicThreadVector::_ResizeVector(unsigned minimumSize) if (size <= oldSize) return B_OK; + MutexLocker _(sLock); + + // If the size has changed in the meantime, we're done. + oldSize = _Size(); + if (size <= oldSize) + return B_OK; + void* newVector = realloc(*fVector, (size + 1) * sizeof(TLSBlock)); if (newVector == NULL) return B_NO_MEMORY;