tsan: fix false positive during fd close
authorDmitry Vyukov <dvyukov@google.com>
Mon, 7 Mar 2022 19:30:38 +0000 (20:30 +0100)
committerDmitry Vyukov <dvyukov@google.com>
Tue, 8 Mar 2022 09:40:56 +0000 (10:40 +0100)
commitf831d6fc800ccf22c1c09888fce3e3c8ebc2c992
treed31453ce3363566fc355760353389ef0caa34833
parentde0b4f4b86fdba0c41723484221575c21bc24ab2
tsan: fix false positive during fd close

FdClose is a subjet to the same atomicity problem as MemoryRangeFreed
(memory state is not "monotoic" wrt race detection).
So we need to lock the thread slot in FdClose the same way we do
in MemoryRangeFreed.
This fixes the modified stress.cpp test.

Reviewed By: vitalybuka, melver

Differential Revision: https://reviews.llvm.org/D121143
compiler-rt/lib/tsan/rtl/tsan_defs.h
compiler-rt/lib/tsan/rtl/tsan_fd.cpp
compiler-rt/lib/tsan/rtl/tsan_rtl_access.cpp
compiler-rt/lib/tsan/rtl/tsan_rtl_mutex.cpp
compiler-rt/test/tsan/fd_close_race.cpp [new file with mode: 0644]
compiler-rt/test/tsan/stress.cpp