Skip to content

Commit 1c42b53

Browse files
committed
Use GET_STACK_TRACE (and only use it if track_poison is enabled)
1 parent 4cffa15 commit 1c42b53

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

compiler-rt/lib/asan/asan_poisoning.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,12 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) {
147147

148148
u32 poison_magic = kAsanUserPoisonedMemoryMagic;
149149

150-
GET_CALLER_PC_BP;
151-
GET_STORE_STACK_TRACE_PC_BP(pc, bp);
152-
// TODO: garbage collect stacks once they fall off the ring buffer?
153-
// StackDepot doesn't currently have a way to delete stacks.
154-
u32 stack_id = StackDepotPut(stack);
155-
156150
if (flags()->track_poison > 0) {
151+
GET_STACK_TRACE(/*max_size=*/ 16, /*fast=*/ false);
152+
// TODO: garbage collect stacks once they fall off the ring buffer?
153+
// StackDepot doesn't currently have a way to delete stacks.
154+
u32 stack_id = StackDepotPut(stack);
155+
157156
u32 current_tid = GetCurrentTidOrInvalid();
158157
u32 poison_index = ((stack_id * 151157) ^ (current_tid * 733123)) %
159158
NumPoisonTrackingMagicValues;
@@ -162,7 +161,7 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) {
162161
.thread_id = current_tid,
163162
.begin = beg_addr,
164163
.end = end_addr};
165-
// This is racy: with concurrent writes, some records may be lost,
164+
// This is a data race: with concurrent writes, some records may be lost,
166165
// but it's a sacrifice I am willing to make for speed.
167166
// The sharding across PoisonRecords reduces the likelihood of
168167
// concurrent writes.

compiler-rt/lib/asan/asan_poisoning.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,6 @@
2323
#include "sanitizer_common/sanitizer_platform.h"
2424
#include "sanitizer_common/sanitizer_ring_buffer.h"
2525

26-
// For platforms which support slow unwinder only, we restrict the store context
27-
// size to 1, basically only storing the current pc. We do this because the slow
28-
// unwinder which is based on libunwind is not async signal safe and causes
29-
// random freezes in forking applications as well as in signal handlers.
30-
#define GET_STORE_STACK_TRACE_PC_BP(pc, bp) \
31-
UNINITIALIZED BufferedStackTrace stack; \
32-
int max_stack = 16; \
33-
if (!SANITIZER_CAN_FAST_UNWIND) \
34-
max_stack = Min(max_stack, 1); \
35-
stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_malloc, \
36-
max_stack);
37-
38-
#define GET_STORE_STACK_TRACE \
39-
GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
40-
4126
namespace __asan {
4227

4328
// These need to be negative chars (i.e., in the range [0x80 .. 0xff]) for

0 commit comments

Comments
 (0)