Skip to content

Commit a4a5bc4

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Fix TSAN crashes due to TSAN's own overflow.
TEST=vm/cc/DartAPI_StackOverflow Change-Id: If5456f4f0a194332b38901f9bd677f3cd9af561c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456421 Commit-Queue: Ryan Macnak <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent b2fa331 commit a4a5bc4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

runtime/vm/os_thread.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "platform/address_sanitizer.h"
88
#include "platform/atomic.h"
99
#include "platform/memory_sanitizer.h"
10+
#include "platform/thread_sanitizer.h"
1011
#include "vm/lockers.h"
1112
#include "vm/log.h"
1213
#include "vm/thread_interrupter.h"
@@ -52,6 +53,20 @@ OSThread::OSThread()
5253

5354
stack_headroom_ = CalculateHeadroom(stack_base_ - stack_limit_);
5455

56+
#if defined(USING_THREAD_SANITIZER)
57+
// The Mac default stack size of 8 MB results in TSAN's stack recording
58+
// overflowing in some tests before Dart reaches regular stack overflow.
59+
// Clamp the stack size used by Dart so we hit a Dart stack overflow
60+
// exception before corrupting TSAN. This is only relevant in run_vm_tests,
61+
// which runs Dart on the main thread. The standalone embedder runs even the
62+
// main isolate on thread pool workers, which the VM created with a smaller
63+
// stack size.
64+
const size_t kMaxDartStackSize = GetMaxStackSize();
65+
if (stack_base_ - stack_limit_ - stack_headroom_ > kMaxDartStackSize) {
66+
stack_headroom_ = stack_base_ - stack_limit_ - kMaxDartStackSize;
67+
}
68+
#endif
69+
5570
ASSERT(stack_base_ != 0);
5671
ASSERT(stack_limit_ != 0);
5772
ASSERT(stack_base_ > stack_limit_);

0 commit comments

Comments
 (0)