tsan: add AccessVptr

Add AccessVptr access type.
For now it's converted to the same thr->is_vptr_access,
but later it will be passed directly to ReportRace
and will enable efficient tail calling in MemoryAccess function
(currently __tsan_vptr_update/__tsan_vptr_read can't use
tail calls in MemoryAccess because of the trailing assignment
to thr->is_vptr_access).

Depends on D107276.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D107282
This commit is contained in:
Dmitry Vyukov 2021-08-02 16:43:01 +02:00
parent 831910c5c4
commit 18c6ed2f0f
2 changed files with 11 additions and 12 deletions

View File

@ -83,21 +83,15 @@ void __tsan_write8_pc(void *addr, void *pc) {
}
void __tsan_vptr_update(void **vptr_p, void *new_val) {
CHECK_EQ(sizeof(vptr_p), 8);
if (*vptr_p != new_val) {
ThreadState *thr = cur_thread();
thr->is_vptr_access = true;
MemoryAccess(thr, CALLERPC, (uptr)vptr_p, 8, kAccessWrite);
thr->is_vptr_access = false;
}
if (*vptr_p == new_val)
return;
MemoryAccess(cur_thread(), CALLERPC, (uptr)vptr_p, sizeof(*vptr_p),
kAccessWrite | kAccessVptr);
}
void __tsan_vptr_read(void **vptr_p) {
CHECK_EQ(sizeof(vptr_p), 8);
ThreadState *thr = cur_thread();
thr->is_vptr_access = true;
MemoryAccess(thr, CALLERPC, (uptr)vptr_p, 8, kAccessRead);
thr->is_vptr_access = false;
MemoryAccess(cur_thread(), CALLERPC, (uptr)vptr_p, sizeof(*vptr_p),
kAccessRead | kAccessVptr);
}
void __tsan_func_entry(void *pc) { FuncEntry(cur_thread(), STRIP_PAC_PC(pc)); }

View File

@ -698,6 +698,7 @@ enum : AccessType {
kAccessWrite = 0,
kAccessRead = 1 << 0,
kAccessAtomic = 1 << 1,
kAccessVptr = 1 << 2,
};
void MemoryAccess(ThreadState *thr, uptr pc, uptr addr,
@ -738,7 +739,11 @@ void MemoryAccess(ThreadState *thr, uptr pc, uptr addr, uptr size,
}
bool is_write = !(typ & kAccessRead);
bool is_atomic = typ & kAccessAtomic;
if (typ & kAccessVptr)
thr->is_vptr_access = true;
MemoryAccess(thr, pc, addr, size_log, is_write, is_atomic);
if (typ & kAccessVptr)
thr->is_vptr_access = false;
}
void MemoryResetRange(ThreadState *thr, uptr pc, uptr addr, uptr size);