grpc 1.26.0 → 1.27.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1654 -1519
  3. data/etc/roots.pem +44 -0
  4. data/include/grpc/grpc_security.h +37 -15
  5. data/include/grpc/grpc_security_constants.h +27 -0
  6. data/include/grpc/impl/codegen/grpc_types.h +14 -0
  7. data/include/grpc/impl/codegen/port_platform.h +1 -1
  8. data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
  9. data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
  10. data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
  11. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
  12. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
  24. data/src/core/ext/filters/client_channel/server_address.cc +6 -9
  25. data/src/core/ext/filters/client_channel/server_address.h +3 -10
  26. data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
  27. data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
  28. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
  29. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
  30. data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
  31. data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
  32. data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
  33. data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
  34. data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
  35. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  36. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
  37. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
  38. data/src/core/lib/channel/channelz.h +11 -1
  39. data/src/core/lib/gpr/time_precise.cc +1 -1
  40. data/src/core/lib/gprpp/optional.h +26 -0
  41. data/src/core/lib/gprpp/string_view.h +14 -10
  42. data/src/core/lib/iomgr/executor.cc +1 -1
  43. data/src/core/lib/iomgr/fork_posix.cc +4 -0
  44. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
  45. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
  46. data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
  47. data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
  48. data/src/core/lib/iomgr/tcp_custom.h +3 -0
  49. data/src/core/lib/iomgr/tcp_posix.cc +607 -56
  50. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
  51. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
  52. data/src/core/lib/json/json.h +11 -1
  53. data/src/core/lib/json/json_reader.cc +206 -28
  54. data/src/core/lib/json/json_writer.cc +111 -24
  55. data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
  56. data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
  57. data/src/core/lib/security/credentials/credentials.h +10 -1
  58. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
  59. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
  60. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
  61. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
  62. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
  63. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
  64. data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
  65. data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
  66. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
  67. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
  68. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
  69. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
  70. data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
  71. data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
  72. data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
  73. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
  74. data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
  75. data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
  76. data/src/core/lib/surface/completion_queue.cc +22 -1
  77. data/src/core/lib/surface/version.cc +1 -1
  78. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
  79. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
  80. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
  81. data/src/core/tsi/fake_transport_security.cc +7 -3
  82. data/src/core/tsi/fake_transport_security.h +2 -0
  83. data/src/core/tsi/ssl_transport_security.cc +144 -8
  84. data/src/core/tsi/ssl_transport_security.h +15 -1
  85. data/src/core/tsi/transport_security.cc +13 -0
  86. data/src/core/tsi/transport_security_grpc.cc +2 -2
  87. data/src/core/tsi/transport_security_grpc.h +2 -2
  88. data/src/core/tsi/transport_security_interface.h +12 -0
  89. data/src/ruby/bin/math_pb.rb +5 -5
  90. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
  91. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  92. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
  93. data/src/ruby/lib/grpc/version.rb +1 -1
  94. data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
  95. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
  96. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
  97. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
  98. data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
  99. data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
  100. data/third_party/abseil-cpp/absl/base/casts.h +184 -0
  101. data/third_party/abseil-cpp/absl/base/config.h +622 -0
  102. data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
  103. data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
  104. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
  105. data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
  106. data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
  107. data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
  108. data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
  109. data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
  110. data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
  111. data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
  112. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
  113. data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
  114. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
  115. data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
  116. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
  117. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
  118. data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
  119. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
  120. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
  121. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
  122. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
  123. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
  124. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
  125. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
  126. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
  127. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
  128. data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
  129. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
  130. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
  131. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
  132. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
  133. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
  134. data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
  135. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
  136. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
  137. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
  138. data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
  139. data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
  140. data/third_party/abseil-cpp/absl/base/macros.h +220 -0
  141. data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
  142. data/third_party/abseil-cpp/absl/base/options.h +214 -0
  143. data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
  144. data/third_party/abseil-cpp/absl/base/port.h +26 -0
  145. data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
  146. data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
  147. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
  148. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
  149. data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
  150. data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
  151. data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
  152. data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
  153. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
  154. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
  155. data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
  156. data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
  157. data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
  158. data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
  159. data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
  160. data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
  161. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
  162. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
  163. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
  164. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
  165. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
  166. data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
  167. data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
  168. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
  169. data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
  170. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
  171. data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
  172. data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
  173. data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
  174. data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
  175. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
  176. data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
  177. data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
  178. data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
  179. data/third_party/abseil-cpp/absl/strings/match.h +90 -0
  180. data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
  181. data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
  182. data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
  183. data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
  184. data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
  185. data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
  186. data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
  187. data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
  188. data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
  189. data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
  190. data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
  191. data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
  192. data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
  193. data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
  194. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
  195. data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
  196. data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
  197. data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
  198. data/third_party/abseil-cpp/absl/types/optional.h +776 -0
  199. data/third_party/abseil-cpp/absl/types/span.h +713 -0
  200. data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
  201. data/third_party/upb/upb/decode.c +4 -0
  202. data/third_party/upb/upb/port.c +0 -1
  203. data/third_party/upb/upb/port_def.inc +1 -3
  204. data/third_party/upb/upb/table.c +2 -1
  205. metadata +147 -43
  206. data/src/core/lib/json/json_common.h +0 -34
  207. data/src/core/lib/json/json_reader.h +0 -146
  208. data/src/core/lib/json/json_string.cc +0 -367
  209. data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,76 @@
1
+ // Copyright 2017 The Abseil 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
+ // https://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
+ // -----------------------------------------------------------------------------
16
+ // kConstInit
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // A constructor tag used to mark an object as safe for use as a global
20
+ // variable, avoiding the usual lifetime issues that can affect globals.
21
+
22
+ #ifndef ABSL_BASE_CONST_INIT_H_
23
+ #define ABSL_BASE_CONST_INIT_H_
24
+
25
+ #include "absl/base/config.h"
26
+
27
+ // In general, objects with static storage duration (such as global variables)
28
+ // can trigger tricky object lifetime situations. Attempting to access them
29
+ // from the constructors or destructors of other global objects can result in
30
+ // undefined behavior, unless their constructors and destructors are designed
31
+ // with this issue in mind.
32
+ //
33
+ // The normal way to deal with this issue in C++11 is to use constant
34
+ // initialization and trivial destructors.
35
+ //
36
+ // Constant initialization is guaranteed to occur before any other code
37
+ // executes. Constructors that are declared 'constexpr' are eligible for
38
+ // constant initialization. You can annotate a variable declaration with the
39
+ // ABSL_CONST_INIT macro to express this intent. For compilers that support
40
+ // it, this annotation will cause a compilation error for declarations that
41
+ // aren't subject to constant initialization (perhaps because a runtime value
42
+ // was passed as a constructor argument).
43
+ //
44
+ // On program shutdown, lifetime issues can be avoided on global objects by
45
+ // ensuring that they contain trivial destructors. A class has a trivial
46
+ // destructor unless it has a user-defined destructor, a virtual method or base
47
+ // class, or a data member or base class with a non-trivial destructor of its
48
+ // own. Objects with static storage duration and a trivial destructor are not
49
+ // cleaned up on program shutdown, and are thus safe to access from other code
50
+ // running during shutdown.
51
+ //
52
+ // For a few core Abseil classes, we make a best effort to allow for safe global
53
+ // instances, even though these classes have non-trivial destructors. These
54
+ // objects can be created with the absl::kConstInit tag. For example:
55
+ // ABSL_CONST_INIT absl::Mutex global_mutex(absl::kConstInit);
56
+ //
57
+ // The line above declares a global variable of type absl::Mutex which can be
58
+ // accessed at any point during startup or shutdown. global_mutex's destructor
59
+ // will still run, but will not invalidate the object. Note that C++ specifies
60
+ // that accessing an object after its destructor has run results in undefined
61
+ // behavior, but this pattern works on the toolchains we support.
62
+ //
63
+ // The absl::kConstInit tag should only be used to define objects with static
64
+ // or thread_local storage duration.
65
+
66
+ namespace absl {
67
+ ABSL_NAMESPACE_BEGIN
68
+
69
+ enum ConstInitType {
70
+ kConstInit,
71
+ };
72
+
73
+ ABSL_NAMESPACE_END
74
+ } // namespace absl
75
+
76
+ #endif // ABSL_BASE_CONST_INIT_H_
@@ -0,0 +1,129 @@
1
+ // Copyright 2017 The Abseil 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
+ // https://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
+ #include <stdlib.h>
16
+ #include <string.h>
17
+
18
+ #include "absl/base/dynamic_annotations.h"
19
+
20
+ #ifndef __has_feature
21
+ #define __has_feature(x) 0
22
+ #endif
23
+
24
+ /* Compiler-based ThreadSanitizer defines
25
+ DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL = 1
26
+ and provides its own definitions of the functions. */
27
+
28
+ #ifndef DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL
29
+ # define DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL 0
30
+ #endif
31
+
32
+ /* Each function is empty and called (via a macro) only in debug mode.
33
+ The arguments are captured by dynamic tools at runtime. */
34
+
35
+ #if DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 && !defined(__native_client__)
36
+
37
+ #if __has_feature(memory_sanitizer)
38
+ #include <sanitizer/msan_interface.h>
39
+ #endif
40
+
41
+ #ifdef __cplusplus
42
+ extern "C" {
43
+ #endif
44
+
45
+ void AnnotateRWLockCreate(const char *, int,
46
+ const volatile void *){}
47
+ void AnnotateRWLockDestroy(const char *, int,
48
+ const volatile void *){}
49
+ void AnnotateRWLockAcquired(const char *, int,
50
+ const volatile void *, long){}
51
+ void AnnotateRWLockReleased(const char *, int,
52
+ const volatile void *, long){}
53
+ void AnnotateBenignRace(const char *, int,
54
+ const volatile void *,
55
+ const char *){}
56
+ void AnnotateBenignRaceSized(const char *, int,
57
+ const volatile void *,
58
+ size_t,
59
+ const char *) {}
60
+ void AnnotateThreadName(const char *, int,
61
+ const char *){}
62
+ void AnnotateIgnoreReadsBegin(const char *, int){}
63
+ void AnnotateIgnoreReadsEnd(const char *, int){}
64
+ void AnnotateIgnoreWritesBegin(const char *, int){}
65
+ void AnnotateIgnoreWritesEnd(const char *, int){}
66
+ void AnnotateEnableRaceDetection(const char *, int, int){}
67
+ void AnnotateMemoryIsInitialized(const char *, int,
68
+ const volatile void *mem, size_t size) {
69
+ #if __has_feature(memory_sanitizer)
70
+ __msan_unpoison(mem, size);
71
+ #else
72
+ (void)mem;
73
+ (void)size;
74
+ #endif
75
+ }
76
+
77
+ void AnnotateMemoryIsUninitialized(const char *, int,
78
+ const volatile void *mem, size_t size) {
79
+ #if __has_feature(memory_sanitizer)
80
+ __msan_allocated_memory(mem, size);
81
+ #else
82
+ (void)mem;
83
+ (void)size;
84
+ #endif
85
+ }
86
+
87
+ static int GetRunningOnValgrind(void) {
88
+ #ifdef RUNNING_ON_VALGRIND
89
+ if (RUNNING_ON_VALGRIND) return 1;
90
+ #endif
91
+ char *running_on_valgrind_str = getenv("RUNNING_ON_VALGRIND");
92
+ if (running_on_valgrind_str) {
93
+ return strcmp(running_on_valgrind_str, "0") != 0;
94
+ }
95
+ return 0;
96
+ }
97
+
98
+ /* See the comments in dynamic_annotations.h */
99
+ int RunningOnValgrind(void) {
100
+ static volatile int running_on_valgrind = -1;
101
+ int local_running_on_valgrind = running_on_valgrind;
102
+ /* C doesn't have thread-safe initialization of statics, and we
103
+ don't want to depend on pthread_once here, so hack it. */
104
+ ANNOTATE_BENIGN_RACE(&running_on_valgrind, "safe hack");
105
+ if (local_running_on_valgrind == -1)
106
+ running_on_valgrind = local_running_on_valgrind = GetRunningOnValgrind();
107
+ return local_running_on_valgrind;
108
+ }
109
+
110
+ /* See the comments in dynamic_annotations.h */
111
+ double ValgrindSlowdown(void) {
112
+ /* Same initialization hack as in RunningOnValgrind(). */
113
+ static volatile double slowdown = 0.0;
114
+ double local_slowdown = slowdown;
115
+ ANNOTATE_BENIGN_RACE(&slowdown, "safe hack");
116
+ if (RunningOnValgrind() == 0) {
117
+ return 1.0;
118
+ }
119
+ if (local_slowdown == 0.0) {
120
+ char *env = getenv("VALGRIND_SLOWDOWN");
121
+ slowdown = local_slowdown = env ? atof(env) : 50.0;
122
+ }
123
+ return local_slowdown;
124
+ }
125
+
126
+ #ifdef __cplusplus
127
+ } // extern "C"
128
+ #endif
129
+ #endif /* DYNAMIC_ANNOTATIONS_EXTERNAL_IMPL == 0 */
@@ -0,0 +1,389 @@
1
+ /*
2
+ * Copyright 2017 The Abseil Authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /* This file defines dynamic annotations for use with dynamic analysis
17
+ tool such as valgrind, PIN, etc.
18
+
19
+ Dynamic annotation is a source code annotation that affects
20
+ the generated code (that is, the annotation is not a comment).
21
+ Each such annotation is attached to a particular
22
+ instruction and/or to a particular object (address) in the program.
23
+
24
+ The annotations that should be used by users are macros in all upper-case
25
+ (e.g., ANNOTATE_THREAD_NAME).
26
+
27
+ Actual implementation of these macros may differ depending on the
28
+ dynamic analysis tool being used.
29
+
30
+ This file supports the following configurations:
31
+ - Dynamic Annotations enabled (with static thread-safety warnings disabled).
32
+ In this case, macros expand to functions implemented by Thread Sanitizer,
33
+ when building with TSan. When not provided an external implementation,
34
+ dynamic_annotations.cc provides no-op implementations.
35
+
36
+ - Static Clang thread-safety warnings enabled.
37
+ When building with a Clang compiler that supports thread-safety warnings,
38
+ a subset of annotations can be statically-checked at compile-time. We
39
+ expand these macros to static-inline functions that can be analyzed for
40
+ thread-safety, but afterwards elided when building the final binary.
41
+
42
+ - All annotations are disabled.
43
+ If neither Dynamic Annotations nor Clang thread-safety warnings are
44
+ enabled, then all annotation-macros expand to empty. */
45
+
46
+ #ifndef ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
47
+ #define ABSL_BASE_DYNAMIC_ANNOTATIONS_H_
48
+
49
+ #ifndef DYNAMIC_ANNOTATIONS_ENABLED
50
+ # define DYNAMIC_ANNOTATIONS_ENABLED 0
51
+ #endif
52
+
53
+ #if DYNAMIC_ANNOTATIONS_ENABLED != 0
54
+
55
+ /* -------------------------------------------------------------
56
+ Annotations that suppress errors. It is usually better to express the
57
+ program's synchronization using the other annotations, but these can
58
+ be used when all else fails. */
59
+
60
+ /* Report that we may have a benign race at "pointer", with size
61
+ "sizeof(*(pointer))". "pointer" must be a non-void* pointer. Insert at the
62
+ point where "pointer" has been allocated, preferably close to the point
63
+ where the race happens. See also ANNOTATE_BENIGN_RACE_STATIC. */
64
+ #define ANNOTATE_BENIGN_RACE(pointer, description) \
65
+ AnnotateBenignRaceSized(__FILE__, __LINE__, pointer, \
66
+ sizeof(*(pointer)), description)
67
+
68
+ /* Same as ANNOTATE_BENIGN_RACE(address, description), but applies to
69
+ the memory range [address, address+size). */
70
+ #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) \
71
+ AnnotateBenignRaceSized(__FILE__, __LINE__, address, size, description)
72
+
73
+ /* Enable (enable!=0) or disable (enable==0) race detection for all threads.
74
+ This annotation could be useful if you want to skip expensive race analysis
75
+ during some period of program execution, e.g. during initialization. */
76
+ #define ANNOTATE_ENABLE_RACE_DETECTION(enable) \
77
+ AnnotateEnableRaceDetection(__FILE__, __LINE__, enable)
78
+
79
+ /* -------------------------------------------------------------
80
+ Annotations useful for debugging. */
81
+
82
+ /* Report the current thread name to a race detector. */
83
+ #define ANNOTATE_THREAD_NAME(name) \
84
+ AnnotateThreadName(__FILE__, __LINE__, name)
85
+
86
+ /* -------------------------------------------------------------
87
+ Annotations useful when implementing locks. They are not
88
+ normally needed by modules that merely use locks.
89
+ The "lock" argument is a pointer to the lock object. */
90
+
91
+ /* Report that a lock has been created at address "lock". */
92
+ #define ANNOTATE_RWLOCK_CREATE(lock) \
93
+ AnnotateRWLockCreate(__FILE__, __LINE__, lock)
94
+
95
+ /* Report that a linker initialized lock has been created at address "lock".
96
+ */
97
+ #ifdef THREAD_SANITIZER
98
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) \
99
+ AnnotateRWLockCreateStatic(__FILE__, __LINE__, lock)
100
+ #else
101
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) ANNOTATE_RWLOCK_CREATE(lock)
102
+ #endif
103
+
104
+ /* Report that the lock at address "lock" is about to be destroyed. */
105
+ #define ANNOTATE_RWLOCK_DESTROY(lock) \
106
+ AnnotateRWLockDestroy(__FILE__, __LINE__, lock)
107
+
108
+ /* Report that the lock at address "lock" has been acquired.
109
+ is_w=1 for writer lock, is_w=0 for reader lock. */
110
+ #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) \
111
+ AnnotateRWLockAcquired(__FILE__, __LINE__, lock, is_w)
112
+
113
+ /* Report that the lock at address "lock" is about to be released. */
114
+ #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) \
115
+ AnnotateRWLockReleased(__FILE__, __LINE__, lock, is_w)
116
+
117
+ #else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
118
+
119
+ #define ANNOTATE_RWLOCK_CREATE(lock) /* empty */
120
+ #define ANNOTATE_RWLOCK_CREATE_STATIC(lock) /* empty */
121
+ #define ANNOTATE_RWLOCK_DESTROY(lock) /* empty */
122
+ #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) /* empty */
123
+ #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) /* empty */
124
+ #define ANNOTATE_BENIGN_RACE(address, description) /* empty */
125
+ #define ANNOTATE_BENIGN_RACE_SIZED(address, size, description) /* empty */
126
+ #define ANNOTATE_THREAD_NAME(name) /* empty */
127
+ #define ANNOTATE_ENABLE_RACE_DETECTION(enable) /* empty */
128
+
129
+ #endif /* DYNAMIC_ANNOTATIONS_ENABLED */
130
+
131
+ /* These annotations are also made available to LLVM's Memory Sanitizer */
132
+ #if DYNAMIC_ANNOTATIONS_ENABLED == 1 || defined(MEMORY_SANITIZER)
133
+ #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) \
134
+ AnnotateMemoryIsInitialized(__FILE__, __LINE__, address, size)
135
+
136
+ #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) \
137
+ AnnotateMemoryIsUninitialized(__FILE__, __LINE__, address, size)
138
+ #else
139
+ #define ANNOTATE_MEMORY_IS_INITIALIZED(address, size) /* empty */
140
+ #define ANNOTATE_MEMORY_IS_UNINITIALIZED(address, size) /* empty */
141
+ #endif /* DYNAMIC_ANNOTATIONS_ENABLED || MEMORY_SANITIZER */
142
+
143
+ /* TODO(delesley) -- Replace __CLANG_SUPPORT_DYN_ANNOTATION__ with the
144
+ appropriate feature ID. */
145
+ #if defined(__clang__) && (!defined(SWIG)) \
146
+ && defined(__CLANG_SUPPORT_DYN_ANNOTATION__)
147
+
148
+ #if DYNAMIC_ANNOTATIONS_ENABLED == 0
149
+ #define ANNOTALYSIS_ENABLED
150
+ #endif
151
+
152
+ /* When running in opt-mode, GCC will issue a warning, if these attributes are
153
+ compiled. Only include them when compiling using Clang. */
154
+ #define ATTRIBUTE_IGNORE_READS_BEGIN \
155
+ __attribute((exclusive_lock_function("*")))
156
+ #define ATTRIBUTE_IGNORE_READS_END \
157
+ __attribute((unlock_function("*")))
158
+ #else
159
+ #define ATTRIBUTE_IGNORE_READS_BEGIN /* empty */
160
+ #define ATTRIBUTE_IGNORE_READS_END /* empty */
161
+ #endif /* defined(__clang__) && ... */
162
+
163
+ #if (DYNAMIC_ANNOTATIONS_ENABLED != 0) || defined(ANNOTALYSIS_ENABLED)
164
+ #define ANNOTATIONS_ENABLED
165
+ #endif
166
+
167
+ #if (DYNAMIC_ANNOTATIONS_ENABLED != 0)
168
+
169
+ /* Request the analysis tool to ignore all reads in the current thread
170
+ until ANNOTATE_IGNORE_READS_END is called.
171
+ Useful to ignore intentional racey reads, while still checking
172
+ other reads and all writes.
173
+ See also ANNOTATE_UNPROTECTED_READ. */
174
+ #define ANNOTATE_IGNORE_READS_BEGIN() \
175
+ AnnotateIgnoreReadsBegin(__FILE__, __LINE__)
176
+
177
+ /* Stop ignoring reads. */
178
+ #define ANNOTATE_IGNORE_READS_END() \
179
+ AnnotateIgnoreReadsEnd(__FILE__, __LINE__)
180
+
181
+ /* Similar to ANNOTATE_IGNORE_READS_BEGIN, but ignore writes instead. */
182
+ #define ANNOTATE_IGNORE_WRITES_BEGIN() \
183
+ AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
184
+
185
+ /* Stop ignoring writes. */
186
+ #define ANNOTATE_IGNORE_WRITES_END() \
187
+ AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
188
+
189
+ /* Clang provides limited support for static thread-safety analysis
190
+ through a feature called Annotalysis. We configure macro-definitions
191
+ according to whether Annotalysis support is available. */
192
+ #elif defined(ANNOTALYSIS_ENABLED)
193
+
194
+ #define ANNOTATE_IGNORE_READS_BEGIN() \
195
+ StaticAnnotateIgnoreReadsBegin(__FILE__, __LINE__)
196
+
197
+ #define ANNOTATE_IGNORE_READS_END() \
198
+ StaticAnnotateIgnoreReadsEnd(__FILE__, __LINE__)
199
+
200
+ #define ANNOTATE_IGNORE_WRITES_BEGIN() \
201
+ StaticAnnotateIgnoreWritesBegin(__FILE__, __LINE__)
202
+
203
+ #define ANNOTATE_IGNORE_WRITES_END() \
204
+ StaticAnnotateIgnoreWritesEnd(__FILE__, __LINE__)
205
+
206
+ #else
207
+ #define ANNOTATE_IGNORE_READS_BEGIN() /* empty */
208
+ #define ANNOTATE_IGNORE_READS_END() /* empty */
209
+ #define ANNOTATE_IGNORE_WRITES_BEGIN() /* empty */
210
+ #define ANNOTATE_IGNORE_WRITES_END() /* empty */
211
+ #endif
212
+
213
+ /* Implement the ANNOTATE_IGNORE_READS_AND_WRITES_* annotations using the more
214
+ primitive annotations defined above. */
215
+ #if defined(ANNOTATIONS_ENABLED)
216
+
217
+ /* Start ignoring all memory accesses (both reads and writes). */
218
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() \
219
+ do { \
220
+ ANNOTATE_IGNORE_READS_BEGIN(); \
221
+ ANNOTATE_IGNORE_WRITES_BEGIN(); \
222
+ }while (0)
223
+
224
+ /* Stop ignoring both reads and writes. */
225
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_END() \
226
+ do { \
227
+ ANNOTATE_IGNORE_WRITES_END(); \
228
+ ANNOTATE_IGNORE_READS_END(); \
229
+ }while (0)
230
+
231
+ #else
232
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN() /* empty */
233
+ #define ANNOTATE_IGNORE_READS_AND_WRITES_END() /* empty */
234
+ #endif
235
+
236
+ /* Use the macros above rather than using these functions directly. */
237
+ #include <stddef.h>
238
+ #ifdef __cplusplus
239
+ extern "C" {
240
+ #endif
241
+ void AnnotateRWLockCreate(const char *file, int line,
242
+ const volatile void *lock);
243
+ void AnnotateRWLockCreateStatic(const char *file, int line,
244
+ const volatile void *lock);
245
+ void AnnotateRWLockDestroy(const char *file, int line,
246
+ const volatile void *lock);
247
+ void AnnotateRWLockAcquired(const char *file, int line,
248
+ const volatile void *lock, long is_w); /* NOLINT */
249
+ void AnnotateRWLockReleased(const char *file, int line,
250
+ const volatile void *lock, long is_w); /* NOLINT */
251
+ void AnnotateBenignRace(const char *file, int line,
252
+ const volatile void *address,
253
+ const char *description);
254
+ void AnnotateBenignRaceSized(const char *file, int line,
255
+ const volatile void *address,
256
+ size_t size,
257
+ const char *description);
258
+ void AnnotateThreadName(const char *file, int line,
259
+ const char *name);
260
+ void AnnotateEnableRaceDetection(const char *file, int line, int enable);
261
+ void AnnotateMemoryIsInitialized(const char *file, int line,
262
+ const volatile void *mem, size_t size);
263
+ void AnnotateMemoryIsUninitialized(const char *file, int line,
264
+ const volatile void *mem, size_t size);
265
+
266
+ /* Annotations expand to these functions, when Dynamic Annotations are enabled.
267
+ These functions are either implemented as no-op calls, if no Sanitizer is
268
+ attached, or provided with externally-linked implementations by a library
269
+ like ThreadSanitizer. */
270
+ void AnnotateIgnoreReadsBegin(const char *file, int line)
271
+ ATTRIBUTE_IGNORE_READS_BEGIN;
272
+ void AnnotateIgnoreReadsEnd(const char *file, int line)
273
+ ATTRIBUTE_IGNORE_READS_END;
274
+ void AnnotateIgnoreWritesBegin(const char *file, int line);
275
+ void AnnotateIgnoreWritesEnd(const char *file, int line);
276
+
277
+ #if defined(ANNOTALYSIS_ENABLED)
278
+ /* When Annotalysis is enabled without Dynamic Annotations, the use of
279
+ static-inline functions allows the annotations to be read at compile-time,
280
+ while still letting the compiler elide the functions from the final build.
281
+
282
+ TODO(delesley) -- The exclusive lock here ignores writes as well, but
283
+ allows IGNORE_READS_AND_WRITES to work properly. */
284
+ #pragma GCC diagnostic push
285
+ #pragma GCC diagnostic ignored "-Wunused-function"
286
+ static inline void StaticAnnotateIgnoreReadsBegin(const char *file, int line)
287
+ ATTRIBUTE_IGNORE_READS_BEGIN { (void)file; (void)line; }
288
+ static inline void StaticAnnotateIgnoreReadsEnd(const char *file, int line)
289
+ ATTRIBUTE_IGNORE_READS_END { (void)file; (void)line; }
290
+ static inline void StaticAnnotateIgnoreWritesBegin(
291
+ const char *file, int line) { (void)file; (void)line; }
292
+ static inline void StaticAnnotateIgnoreWritesEnd(
293
+ const char *file, int line) { (void)file; (void)line; }
294
+ #pragma GCC diagnostic pop
295
+ #endif
296
+
297
+ /* Return non-zero value if running under valgrind.
298
+
299
+ If "valgrind.h" is included into dynamic_annotations.cc,
300
+ the regular valgrind mechanism will be used.
301
+ See http://valgrind.org/docs/manual/manual-core-adv.html about
302
+ RUNNING_ON_VALGRIND and other valgrind "client requests".
303
+ The file "valgrind.h" may be obtained by doing
304
+ svn co svn://svn.valgrind.org/valgrind/trunk/include
305
+
306
+ If for some reason you can't use "valgrind.h" or want to fake valgrind,
307
+ there are two ways to make this function return non-zero:
308
+ - Use environment variable: export RUNNING_ON_VALGRIND=1
309
+ - Make your tool intercept the function RunningOnValgrind() and
310
+ change its return value.
311
+ */
312
+ int RunningOnValgrind(void);
313
+
314
+ /* ValgrindSlowdown returns:
315
+ * 1.0, if (RunningOnValgrind() == 0)
316
+ * 50.0, if (RunningOnValgrind() != 0 && getenv("VALGRIND_SLOWDOWN") == NULL)
317
+ * atof(getenv("VALGRIND_SLOWDOWN")) otherwise
318
+ This function can be used to scale timeout values:
319
+ EXAMPLE:
320
+ for (;;) {
321
+ DoExpensiveBackgroundTask();
322
+ SleepForSeconds(5 * ValgrindSlowdown());
323
+ }
324
+ */
325
+ double ValgrindSlowdown(void);
326
+
327
+ #ifdef __cplusplus
328
+ }
329
+ #endif
330
+
331
+ /* ANNOTATE_UNPROTECTED_READ is the preferred way to annotate racey reads.
332
+
333
+ Instead of doing
334
+ ANNOTATE_IGNORE_READS_BEGIN();
335
+ ... = x;
336
+ ANNOTATE_IGNORE_READS_END();
337
+ one can use
338
+ ... = ANNOTATE_UNPROTECTED_READ(x); */
339
+ #if defined(__cplusplus) && defined(ANNOTATIONS_ENABLED)
340
+ template <typename T>
341
+ inline T ANNOTATE_UNPROTECTED_READ(const volatile T &x) { /* NOLINT */
342
+ ANNOTATE_IGNORE_READS_BEGIN();
343
+ T res = x;
344
+ ANNOTATE_IGNORE_READS_END();
345
+ return res;
346
+ }
347
+ #else
348
+ #define ANNOTATE_UNPROTECTED_READ(x) (x)
349
+ #endif
350
+
351
+ #if DYNAMIC_ANNOTATIONS_ENABLED != 0 && defined(__cplusplus)
352
+ /* Apply ANNOTATE_BENIGN_RACE_SIZED to a static variable. */
353
+ #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) \
354
+ namespace { \
355
+ class static_var ## _annotator { \
356
+ public: \
357
+ static_var ## _annotator() { \
358
+ ANNOTATE_BENIGN_RACE_SIZED(&static_var, \
359
+ sizeof(static_var), \
360
+ # static_var ": " description); \
361
+ } \
362
+ }; \
363
+ static static_var ## _annotator the ## static_var ## _annotator;\
364
+ } // namespace
365
+ #else /* DYNAMIC_ANNOTATIONS_ENABLED == 0 */
366
+ #define ANNOTATE_BENIGN_RACE_STATIC(static_var, description) /* empty */
367
+ #endif /* DYNAMIC_ANNOTATIONS_ENABLED */
368
+
369
+ #ifdef ADDRESS_SANITIZER
370
+ /* Describe the current state of a contiguous container such as e.g.
371
+ * std::vector or std::string. For more details see
372
+ * sanitizer/common_interface_defs.h, which is provided by the compiler. */
373
+ #include <sanitizer/common_interface_defs.h>
374
+ #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid) \
375
+ __sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid)
376
+ #define ADDRESS_SANITIZER_REDZONE(name) \
377
+ struct { char x[8] __attribute__ ((aligned (8))); } name
378
+ #else
379
+ #define ANNOTATE_CONTIGUOUS_CONTAINER(beg, end, old_mid, new_mid)
380
+ #define ADDRESS_SANITIZER_REDZONE(name) static_assert(true, "")
381
+ #endif // ADDRESS_SANITIZER
382
+
383
+ /* Undefine the macros intended only in this file. */
384
+ #undef ANNOTALYSIS_ENABLED
385
+ #undef ANNOTATIONS_ENABLED
386
+ #undef ATTRIBUTE_IGNORE_READS_BEGIN
387
+ #undef ATTRIBUTE_IGNORE_READS_END
388
+
389
+ #endif /* ABSL_BASE_DYNAMIC_ANNOTATIONS_H_ */