Skip to content

2. ThreadSanitizer Overview

Andrew Chin edited this page May 1, 2019 · 3 revisions

For implementation purposes, it is helpful to understand the structure of TSan itself, as the UFO runtime is built on top of TSan. The pseudocode of TSan's core race detection algorithm can be found at the project wiki [1]. The core algorithm contains two main routines: HandleMemoryAccess and UpdateOneShadowState.

HandleMemoryAccess

HandleMemoryAccess is implemented as two different function paths. The corresponding functions are MemoryAccess in tsan/rtl/tsan_rtl.cc:796 and MemoryAccessRange in tsan/rtl/tsan_rtl_thread.cc:319.

  • MemoryAccess -> MemoryAccessImpl1
  • MemoryAccessRange -> MemoryAccessRangeImpl -> MemoryAccessImpl1
  • MemoryAccessImpl1 "calls" UpdateOneShadowState (see below)

UpdateOneShadowState

UpdateOneShadowState corresponds to the file tsan/rtl/tsan_update_shadow_word_inl.h. This can be thought of as a function. However, in this case, including the file rather than calling a function leads to generation of more efficient code. Thus, you can think of #include "tsan_update_shadow_word_inl.h" as simply a call to UpdateOneShadowState.

References

[1] https://github.com/google/sanitizers/wiki/ThreadSanitizerAlgorithm#State-Machine

Clone this wiki locally