1//===--- rtsan_assertions.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// Part of the RealtimeSanitizer runtime library
10//
11//===----------------------------------------------------------------------===//
12
13#pragma once
14
15#include "rtsan/rtsan.h"
16#include "rtsan/rtsan_context.h"
17#include "rtsan/rtsan_diagnostics.h"
18#include "rtsan/rtsan_stats.h"
19#include "rtsan/rtsan_suppressions.h"
20
21#include "sanitizer_common/sanitizer_stacktrace.h"
22
23namespace __rtsan {
24
25template <typename OnViolationAction>
26void ExpectNotRealtime(Context &context, const DiagnosticsInfo &info,
27 OnViolationAction &&OnViolation) {
28 CHECK(__rtsan_is_initialized());
29 if (context.InRealtimeContext() && !context.IsBypassed()) {
30 ScopedBypass sb{context};
31
32 if (IsFunctionSuppressed(function_name: info.func_name)) {
33 IncrementSuppressedCount();
34 return;
35 }
36
37 __sanitizer::BufferedStackTrace stack;
38
39 // We use the unwind_on_fatal flag here because of precedent with other
40 // sanitizers, this action is not necessarily fatal if halt_on_error=false
41 stack.Unwind(pc: info.pc, bp: info.bp, context: nullptr,
42 request_fast: __sanitizer::common_flags()->fast_unwind_on_fatal);
43
44 if (IsStackTraceSuppressed(stack)) {
45 IncrementSuppressedCount();
46 return;
47 }
48
49 OnViolation(stack, info);
50 }
51}
52
53} // namespace __rtsan
54