runtime_loader: Add missing locking around resizing the TLS DTV.
* 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 <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
6109c51d55
commit
d0111efead
@@ -12,9 +12,14 @@
|
|||||||
|
|
||||||
#include <tls.h>
|
#include <tls.h>
|
||||||
|
|
||||||
|
#include <locks.h>
|
||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const char* const kLockName = "runtime loader tls";
|
||||||
|
static mutex sLock = MUTEX_INITIALIZER(kLockName);
|
||||||
|
|
||||||
|
|
||||||
class TLSBlock {
|
class TLSBlock {
|
||||||
public:
|
public:
|
||||||
inline TLSBlock();
|
inline TLSBlock();
|
||||||
@@ -280,6 +285,13 @@ DynamicThreadVector::_ResizeVector(unsigned minimumSize)
|
|||||||
if (size <= oldSize)
|
if (size <= oldSize)
|
||||||
return B_OK;
|
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));
|
void* newVector = realloc(*fVector, (size + 1) * sizeof(TLSBlock));
|
||||||
if (newVector == NULL)
|
if (newVector == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|||||||
Reference in New Issue
Block a user