1 //===--- rtsan_context.h - Realtime Sanitizer -------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 //===----------------------------------------------------------------------===// 10 11 #pragma once 12 13 namespace __rtsan { 14 15 class Context { 16 public: 17 Context(); 18 19 void RealtimePush(); 20 void RealtimePop(); 21 22 void BypassPush(); 23 void BypassPop(); 24 25 bool InRealtimeContext() const; 26 bool IsBypassed() const; 27 28 Context(const Context &) = delete; 29 Context(Context &&) = delete; 30 Context &operator=(const Context &) = delete; 31 Context &operator=(Context &&) = delete; 32 33 private: 34 int realtime_depth_{0}; 35 int bypass_depth_{0}; 36 }; 37 38 class ScopedBypass { 39 public: 40 [[nodiscard]] explicit ScopedBypass(Context &context) : context_(context) { 41 context_.BypassPush(); 42 } 43 44 ~ScopedBypass() { context_.BypassPop(); } 45 46 ScopedBypass(const ScopedBypass &) = delete; 47 ScopedBypass &operator=(const ScopedBypass &) = delete; 48 ScopedBypass(ScopedBypass &&) = delete; 49 ScopedBypass &operator=(ScopedBypass &&) = delete; 50 51 private: 52 Context &context_; 53 }; 54 55 Context &GetContextForThisThread(); 56 } // namespace __rtsan 57