Skip to content

Commit f080021

Browse files
committed
Add mutex
1 parent 32a8dda commit f080021

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

compiler-rt/lib/asan/asan_errors.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ static void CheckPoisonRecords(uptr addr) {
612612
if (poison_magic != kAsanUserPoisonedMemoryMagic)
613613
return;
614614

615-
PoisonRecordRingBuffer *PoisonRecord = GetPoisonRecord();
615+
PoisonRecordRingBuffer *PoisonRecord = AcquirePoisonRecords();
616616
if (PoisonRecord) {
617617
bool FoundMatch = false;
618618

@@ -637,6 +637,7 @@ static void CheckPoisonRecords(uptr addr) {
637637
Printf("Try setting a larger track_poison value.\n");
638638
}
639639
}
640+
ReleasePoisonRecords();
640641
}
641642

642643
void ErrorGeneric::Print() {

compiler-rt/lib/asan/asan_poisoning.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace __asan {
2626

2727
static atomic_uint8_t can_poison_memory;
2828

29+
static Mutex PoisonRecordsMutex;
2930
static PoisonRecordRingBuffer *PoisonRecords = nullptr;
3031

3132
void InitializePoisonTracking() {
@@ -35,10 +36,16 @@ void InitializePoisonTracking() {
3536
PoisonRecords = PoisonRecordRingBuffer::New(flags()->track_poison);
3637
}
3738

38-
PoisonRecordRingBuffer* GetPoisonRecord() {
39+
PoisonRecordRingBuffer* SANITIZER_ACQUIRE(PoisonRecordsMutex) AcquirePoisonRecords() {
40+
PoisonRecordsMutex.Lock();
41+
3942
return PoisonRecords;
4043
}
4144

45+
void SANITIZER_RELEASE(PoisonRecordsMutex) ReleasePoisonRecords() {
46+
PoisonRecordsMutex.Unlock();
47+
}
48+
4249
void SetCanPoisonMemory(bool value) {
4350
atomic_store(&can_poison_memory, value, memory_order_release);
4451
}
@@ -136,8 +143,8 @@ void __asan_poison_memory_region(void const volatile *addr, uptr size) {
136143
.thread_id = current_tid,
137144
.begin = beg_addr,
138145
.end = end_addr};
139-
// TODO: mutex
140-
GetPoisonRecord()->push(record);
146+
AcquirePoisonRecords()->push(record);
147+
ReleasePoisonRecords();
141148
}
142149

143150
ShadowSegmentEndpoint beg(beg_addr);

compiler-rt/lib/asan/asan_poisoning.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
// Shadow memory poisoning by ASan RTL and by user application.
1212
//===----------------------------------------------------------------------===//
13+
1314
#ifndef ASAN_POISONING_H
1415
#define ASAN_POISONING_H
1516

@@ -37,7 +38,8 @@ using PoisonRecordRingBuffer = RingBuffer<struct PoisonRecord>;
3738
// Set up data structures for track_poison.
3839
void InitializePoisonTracking();
3940

40-
PoisonRecordRingBuffer* GetPoisonRecord();
41+
PoisonRecordRingBuffer* AcquirePoisonRecords();
42+
void ReleasePoisonRecords();
4143

4244
// Enable/disable memory poisoning.
4345
void SetCanPoisonMemory(bool value);

0 commit comments

Comments
 (0)