Skip to content

Commit 6f4a9bd

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Work around missing TSAN support for thread_suspend.
TEST=tsan Bug: #61478 Change-Id: I700f36eb07c998993682f046d82bbc9d04847f9c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449074 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 496a2bd commit 6f4a9bd

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

runtime/platform/memory_sanitizer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern "C" void __msan_check_mem_is_initialized(const volatile void*, size_t);
4747
#define MSAN_CHECK_INITIALIZED(ptr, len) \
4848
do { \
4949
} while (false && (ptr) == nullptr && (len) == 0)
50+
#define NO_SANITIZE_MEMORY
5051
#endif // defined(USING_MEMORY_SANITIZER)
5152

5253
#endif // RUNTIME_PLATFORM_MEMORY_SANITIZER_H_

runtime/vm/profiler.cc

Lines changed: 20 additions & 30 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 "platform/utils.h"
1112
#include "vm/allocation.h"
1213
#include "vm/code_patcher.h"
@@ -196,6 +197,18 @@ class ProfilerStackWalker : public ValueObject {
196197
intptr_t total_frames_;
197198
};
198199

200+
// MSAN/ASAN are unaware of frames initialized by generated code.
201+
NO_SANITIZE_ADDRESS
202+
NO_SANITIZE_MEMORY
203+
#if defined(DART_HOST_OS_MACOS)
204+
// Mac profiling is cross-thread and TSAN doesn't know that thread_suspend
205+
// establishes synchronization.
206+
NO_SANITIZE_THREAD
207+
#endif
208+
static uword* LoadStackSlot(uword* ptr) {
209+
return reinterpret_cast<uword*>(*ptr);
210+
}
211+
199212
// The layout of C stack frames.
200213
#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) || \
201214
defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64)
@@ -300,20 +313,12 @@ class ProfilerNativeStackWalker : public ProfilerStackWalker {
300313
private:
301314
uword* CallerPC(uword* fp) const {
302315
ASSERT(fp != nullptr);
303-
uword* caller_pc_ptr = fp + kHostSavedCallerPcSlotFromFp;
304-
// This may actually be uninitialized, by design (see class comment above).
305-
MSAN_UNPOISON(caller_pc_ptr, kWordSize);
306-
ASAN_UNPOISON(caller_pc_ptr, kWordSize);
307-
return reinterpret_cast<uword*>(*caller_pc_ptr);
316+
return LoadStackSlot(fp + kHostSavedCallerPcSlotFromFp);
308317
}
309318

310319
uword* CallerFP(uword* fp) const {
311320
ASSERT(fp != nullptr);
312-
uword* caller_fp_ptr = fp + kHostSavedCallerFpSlotFromFp;
313-
// This may actually be uninitialized, by design (see class comment above).
314-
MSAN_UNPOISON(caller_fp_ptr, kWordSize);
315-
ASAN_UNPOISON(caller_fp_ptr, kWordSize);
316-
return reinterpret_cast<uword*>(*caller_fp_ptr);
321+
return LoadStackSlot(fp + kHostSavedCallerFpSlotFromFp);
317322
}
318323

319324
bool ValidFramePointer(uword* fp) const {
@@ -1156,41 +1161,28 @@ class ProfilerDartStackWalker : public ProfilerStackWalker {
11561161
uword* caller_pc_ptr =
11571162
fp_ + (IsInterpretedFrame() ? kKBCSavedCallerPcSlotFromFp
11581163
: kSavedCallerPcSlotFromFp);
1159-
// MSan/ASan are unaware of frames initialized by generated code.
1160-
MSAN_UNPOISON(caller_pc_ptr, kWordSize);
1161-
ASAN_UNPOISON(caller_pc_ptr, kWordSize);
1162-
return reinterpret_cast<uword*>(*caller_pc_ptr);
1164+
return LoadStackSlot(caller_pc_ptr);
11631165
}
11641166

11651167
uword* CallerFP() const {
11661168
ASSERT(fp_ != nullptr);
11671169
uword* caller_fp_ptr =
11681170
fp_ + (IsInterpretedFrame() ? kKBCSavedCallerFpSlotFromFp
11691171
: kSavedCallerFpSlotFromFp);
1170-
// MSan/ASan are unaware of frames initialized by generated code.
1171-
MSAN_UNPOISON(caller_fp_ptr, kWordSize);
1172-
ASAN_UNPOISON(caller_fp_ptr, kWordSize);
1173-
return reinterpret_cast<uword*>(*caller_fp_ptr);
1172+
return LoadStackSlot(caller_fp_ptr);
11741173
}
11751174

11761175
uword* ExitLink() const {
11771176
ASSERT(fp_ != nullptr);
11781177
uword* exit_link_ptr =
11791178
fp_ + (IsInterpretedFrame() ? kKBCExitLinkSlotFromEntryFp
11801179
: kExitLinkSlotFromEntryFp);
1181-
// MSan/ASan are unaware of frames initialized by generated code.
1182-
MSAN_UNPOISON(exit_link_ptr, kWordSize);
1183-
ASAN_UNPOISON(exit_link_ptr, kWordSize);
1184-
return reinterpret_cast<uword*>(*exit_link_ptr);
1180+
return LoadStackSlot(exit_link_ptr);
11851181
}
11861182

11871183
uword Stack(intptr_t index) const {
11881184
ASSERT(sp_ != nullptr);
1189-
uword* stack_ptr = sp_ + index;
1190-
// MSan/ASan are unaware of frames initialized by generated code.
1191-
MSAN_UNPOISON(stack_ptr, kWordSize);
1192-
ASAN_UNPOISON(stack_ptr, kWordSize);
1193-
return *stack_ptr;
1185+
return reinterpret_cast<uword>(LoadStackSlot(sp_ + index));
11941186
}
11951187

11961188
Thread* const thread_;
@@ -1206,9 +1198,7 @@ static void CopyStackBuffer(Sample* sample, uword sp_addr) {
12061198
uword* buffer = sample->GetStackBuffer();
12071199
if (sp != nullptr) {
12081200
for (intptr_t i = 0; i < Sample::kStackBufferSizeInWords; i++) {
1209-
MSAN_UNPOISON(sp, kWordSize);
1210-
ASAN_UNPOISON(sp, kWordSize);
1211-
buffer[i] = *sp;
1201+
buffer[i] = reinterpret_cast<uword>(LoadStackSlot(sp));
12121202
sp++;
12131203
}
12141204
}

0 commit comments

Comments
 (0)