• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Define GRPC_BUILD_HAS_ASAN as 1 or 0 depending on if we're building under
16 // ASAN.
17 #if defined(__has_feature)
18 #if __has_feature(address_sanitizer)
19 #define GRPC_BUILD_HAS_ASAN 1
20 #else
21 #define GRPC_BUILD_HAS_ASAN 0
22 #endif
23 #else
24 #ifdef ADDRESS_SANITIZER
25 #define GRPC_BUILD_HAS_ASAN 1
26 #else
27 #define GRPC_BUILD_HAS_ASAN 0
28 #endif
29 #endif
30 
31 // Define GRPC_BUILD_HAS_TSAN as 1 or 0 depending on if we're building under
32 // TSAN.
33 #if defined(__has_feature)
34 #if __has_feature(thread_sanitizer)
35 #define GRPC_BUILD_HAS_TSAN 1
36 #else
37 #define GRPC_BUILD_HAS_TSAN 0
38 #endif
39 #else
40 #ifdef THREAD_SANITIZER
41 #define GRPC_BUILD_HAS_TSAN 1
42 #else
43 #define GRPC_BUILD_HAS_TSAN 0
44 #endif
45 #endif
46 
47 // Define GRPC_BUILD_HAS_MSAN as 1 or 0 depending on if we're building under
48 // MSAN.
49 #if defined(__has_feature)
50 #if __has_feature(memory_sanitizer)
51 #define GRPC_BUILD_HAS_MSAN 1
52 #else
53 #define GRPC_BUILD_HAS_MSAN 0
54 #endif
55 #else
56 #ifdef MEMORY_SANITIZER
57 #define GRPC_BUILD_HAS_MSAN 1
58 #else
59 #define GRPC_BUILD_HAS_MSAN 0
60 #endif
61 #endif
62 
63 #if GRPC_BUILD_HAS_ASAN
64 #include <sanitizer/lsan_interface.h>
65 #endif
66 
BuiltUnderValgrind()67 bool BuiltUnderValgrind() {
68 #ifdef RUNNING_ON_VALGRIND
69   return true;
70 #else
71   return false;
72 #endif
73 }
74 
BuiltUnderTsan()75 bool BuiltUnderTsan() { return GRPC_BUILD_HAS_TSAN != 0; }
76 
BuiltUnderAsan()77 bool BuiltUnderAsan() { return GRPC_BUILD_HAS_ASAN != 0; }
78 
AsanAssertNoLeaks()79 void AsanAssertNoLeaks() {
80 #if GRPC_BUILD_HAS_ASAN
81   __lsan_do_leak_check();
82 #endif
83 }
84 
BuiltUnderMsan()85 bool BuiltUnderMsan() { return GRPC_BUILD_HAS_MSAN != 0; }
86 
BuiltUnderUbsan()87 bool BuiltUnderUbsan() {
88 #ifdef GRPC_UBSAN
89   return true;
90 #else
91   return false;
92 #endif
93 }
94