grpc 1.31.1 → 1.32.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 (431) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +595 -15723
  3. data/include/grpc/grpc_security.h +31 -14
  4. data/include/grpc/impl/codegen/README.md +22 -0
  5. data/include/grpc/impl/codegen/port_platform.h +6 -1
  6. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -2
  7. data/src/core/ext/filters/client_channel/client_channel.cc +64 -20
  8. data/src/core/ext/filters/client_channel/client_channel.h +1 -1
  9. data/src/core/ext/filters/client_channel/client_channel_channelz.h +0 -3
  10. data/src/core/ext/filters/client_channel/health/health_check_client.cc +6 -1
  11. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -3
  12. data/src/core/ext/filters/client_channel/lb_policy.h +2 -0
  13. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +6 -4
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +20 -13
  15. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +0 -13
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +0 -3
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -37
  18. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +19 -13
  19. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +29 -10
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -4
  21. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +20 -9
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +18 -12
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/eds.cc +22 -14
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/lrs.cc +18 -9
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +54 -56
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +3 -3
  27. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  29. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +1 -1
  30. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +363 -14
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +0 -1
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +5 -4
  34. data/src/core/ext/filters/client_channel/server_address.cc +40 -7
  35. data/src/core/ext/filters/client_channel/server_address.h +42 -4
  36. data/src/core/ext/filters/client_channel/subchannel.cc +64 -23
  37. data/src/core/ext/filters/client_channel/subchannel.h +16 -4
  38. data/src/core/ext/filters/max_age/max_age_filter.cc +2 -1
  39. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +87 -31
  40. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +18 -1
  41. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +10 -35
  42. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +19 -25
  43. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -1
  44. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +2 -2
  45. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +6 -6
  46. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -2
  47. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +239 -277
  48. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  49. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +2 -2
  50. data/src/core/ext/transport/chttp2/transport/internal.h +5 -1
  51. data/src/core/ext/transport/chttp2/transport/parsing.cc +1 -28
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -5
  53. data/src/core/ext/transport/inproc/inproc_transport.cc +12 -12
  54. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +224 -0
  55. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +700 -0
  56. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +74 -0
  57. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +226 -0
  58. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +380 -0
  59. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +1378 -0
  60. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/filter.upb.c +8 -8
  61. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +69 -0
  62. data/src/core/ext/upb-generated/envoy/{api/v2/cluster → config/cluster/v3}/outlier_detection.upb.c +8 -8
  63. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +323 -0
  64. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +112 -0
  65. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +334 -0
  66. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/backoff.upb.c +8 -8
  67. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +79 -0
  68. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +309 -0
  69. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +869 -0
  70. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +96 -0
  71. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +328 -0
  72. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +34 -0
  73. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +71 -0
  74. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +195 -0
  75. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +634 -0
  76. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +170 -0
  77. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +684 -0
  78. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/http_uri.upb.c +8 -8
  79. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +80 -0
  80. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +152 -0
  81. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +536 -0
  82. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +28 -0
  83. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +58 -0
  84. data/src/core/ext/upb-generated/envoy/{api/v2/core → config/core/v3}/socket_option.upb.c +6 -6
  85. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +88 -0
  86. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +91 -0
  87. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +220 -0
  88. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +91 -0
  89. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +273 -0
  90. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +112 -0
  91. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +332 -0
  92. data/src/core/ext/upb-generated/envoy/config/listener/{v2 → v3}/api_listener.upb.c +8 -8
  93. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +65 -0
  94. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +108 -0
  95. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +401 -0
  96. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +138 -0
  97. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +490 -0
  98. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +41 -0
  99. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +94 -0
  100. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +174 -0
  101. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +599 -0
  102. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +63 -0
  103. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +204 -0
  104. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +773 -0
  105. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +2855 -0
  106. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +59 -0
  107. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +135 -0
  108. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +50 -0
  109. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +108 -0
  110. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +312 -0
  111. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +1125 -0
  112. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +20 -0
  113. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +34 -0
  114. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +111 -0
  115. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +401 -0
  116. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +72 -0
  117. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +198 -0
  118. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +105 -0
  119. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +388 -0
  120. data/src/core/ext/upb-generated/envoy/{api/v2 → service/cluster/v3}/cds.upb.c +5 -6
  121. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +49 -0
  122. data/src/core/ext/upb-generated/envoy/service/discovery/{v2 → v3}/ads.upb.c +5 -4
  123. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +49 -0
  124. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +129 -0
  125. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +386 -0
  126. data/src/core/ext/upb-generated/envoy/{api/v2 → service/endpoint/v3}/eds.upb.c +5 -6
  127. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +49 -0
  128. data/src/core/ext/upb-generated/envoy/{api/v2 → service/listener/v3}/lds.upb.c +5 -6
  129. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +49 -0
  130. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +55 -0
  131. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +136 -0
  132. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/rds.upb.c +5 -6
  133. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +49 -0
  134. data/src/core/ext/upb-generated/envoy/{api/v2 → service/route/v3}/srds.upb.c +5 -6
  135. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +49 -0
  136. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +47 -0
  137. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +114 -0
  138. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +35 -0
  139. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +77 -0
  140. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +34 -0
  141. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +71 -0
  142. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +64 -0
  143. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +145 -0
  144. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +53 -0
  145. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +127 -0
  146. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +63 -0
  147. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +188 -0
  148. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +88 -0
  149. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +258 -0
  150. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +90 -0
  151. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +250 -0
  152. data/src/core/ext/upb-generated/envoy/type/{http.upb.c → v3/http.upb.c} +2 -2
  153. data/src/core/ext/upb-generated/envoy/type/{http.upb.h → v3/http.upb.h} +8 -8
  154. data/src/core/ext/upb-generated/envoy/type/{percent.upb.c → v3/percent.upb.c} +9 -8
  155. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +86 -0
  156. data/src/core/ext/upb-generated/envoy/type/{range.upb.c → v3/range.upb.c} +12 -11
  157. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +111 -0
  158. data/src/core/ext/upb-generated/envoy/type/{semantic_version.upb.c → v3/semantic_version.upb.c} +6 -5
  159. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +61 -0
  160. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +234 -0
  161. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +759 -0
  162. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +36 -36
  163. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +1 -1
  164. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +27 -0
  165. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +53 -0
  166. data/src/core/ext/upb-generated/validate/validate.upb.c +11 -11
  167. data/src/core/ext/upb-generated/validate/validate.upb.h +1 -1
  168. data/src/core/ext/{filters/client_channel/xds → xds}/xds_api.cc +1045 -767
  169. data/src/core/ext/{filters/client_channel/xds → xds}/xds_api.h +114 -99
  170. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.cc +44 -2
  171. data/src/core/ext/{filters/client_channel/xds → xds}/xds_bootstrap.h +8 -3
  172. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel.h +4 -4
  173. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_args.h +3 -3
  174. data/src/core/ext/{filters/client_channel/xds → xds}/xds_channel_secure.cc +2 -5
  175. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.cc +85 -417
  176. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client.h +12 -45
  177. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.cc +2 -2
  178. data/src/core/ext/{filters/client_channel/xds → xds}/xds_client_stats.h +3 -3
  179. data/src/core/lib/channel/channelz.cc +14 -15
  180. data/src/core/lib/channel/channelz.h +1 -1
  181. data/src/core/lib/channel/channelz_registry.cc +3 -1
  182. data/src/core/lib/gpr/sync_posix.cc +2 -8
  183. data/src/core/lib/iomgr/endpoint.cc +5 -1
  184. data/src/core/lib/iomgr/endpoint.h +7 -3
  185. data/src/core/lib/iomgr/endpoint_cfstream.cc +32 -11
  186. data/src/core/lib/iomgr/ev_posix.cc +0 -2
  187. data/src/core/lib/iomgr/iomgr.cc +0 -10
  188. data/src/core/lib/iomgr/iomgr.h +0 -10
  189. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.cc +1 -1
  190. data/src/core/{ext/filters/client_channel → lib/iomgr}/parse_address.h +3 -3
  191. data/src/core/lib/iomgr/sockaddr_utils.cc +2 -1
  192. data/src/core/lib/iomgr/sockaddr_utils.h +2 -1
  193. data/src/core/lib/iomgr/tcp_custom.cc +32 -16
  194. data/src/core/lib/iomgr/tcp_posix.cc +31 -13
  195. data/src/core/lib/iomgr/tcp_windows.cc +26 -10
  196. data/src/core/lib/security/authorization/authorization_engine.cc +177 -0
  197. data/src/core/lib/security/authorization/authorization_engine.h +84 -0
  198. data/src/core/lib/security/authorization/evaluate_args.cc +153 -0
  199. data/src/core/lib/security/authorization/evaluate_args.h +59 -0
  200. data/src/core/lib/security/authorization/mock_cel/activation.h +57 -0
  201. data/src/core/lib/security/authorization/mock_cel/cel_expr_builder_factory.h +42 -0
  202. data/src/core/lib/security/authorization/mock_cel/cel_expression.h +68 -0
  203. data/src/core/lib/security/authorization/mock_cel/cel_value.h +93 -0
  204. data/src/core/lib/security/authorization/mock_cel/evaluator_core.h +67 -0
  205. data/src/core/lib/security/authorization/mock_cel/flat_expr_builder.h +56 -0
  206. data/src/core/lib/security/authorization/mock_cel/statusor.h +50 -0
  207. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +56 -38
  208. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -2
  209. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  210. data/src/core/lib/surface/call.cc +12 -12
  211. data/src/core/lib/surface/call.h +2 -1
  212. data/src/core/lib/surface/channel.cc +28 -20
  213. data/src/core/lib/surface/channel.h +12 -2
  214. data/src/core/lib/surface/completion_queue.cc +10 -272
  215. data/src/core/lib/surface/completion_queue.h +0 -8
  216. data/src/core/lib/surface/init.cc +1 -3
  217. data/src/core/lib/surface/server.cc +1066 -1244
  218. data/src/core/lib/surface/server.h +363 -87
  219. data/src/core/lib/surface/version.cc +2 -2
  220. data/src/core/lib/transport/authority_override.cc +38 -0
  221. data/src/core/lib/transport/authority_override.h +32 -0
  222. data/src/core/lib/transport/connectivity_state.cc +18 -13
  223. data/src/core/lib/transport/connectivity_state.h +18 -6
  224. data/src/core/lib/transport/error_utils.cc +13 -0
  225. data/src/core/lib/transport/error_utils.h +6 -0
  226. data/src/core/lib/transport/static_metadata.cc +295 -276
  227. data/src/core/lib/transport/static_metadata.h +80 -73
  228. data/src/core/lib/transport/transport.h +7 -0
  229. data/src/core/lib/uri/uri_parser.cc +23 -21
  230. data/src/core/lib/uri/uri_parser.h +3 -1
  231. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +22 -0
  232. data/src/core/tsi/ssl_transport_security.cc +3 -9
  233. data/src/ruby/ext/grpc/rb_channel_credentials.c +9 -0
  234. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -2
  235. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -4
  236. data/src/ruby/lib/grpc/version.rb +1 -1
  237. data/src/ruby/spec/channel_credentials_spec.rb +10 -0
  238. data/src/ruby/spec/generic/active_call_spec.rb +19 -8
  239. data/third_party/abseil-cpp/absl/algorithm/container.h +1727 -0
  240. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +161 -0
  241. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.cc +93 -0
  242. data/third_party/abseil-cpp/absl/base/internal/exponential_biased.h +130 -0
  243. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +620 -0
  244. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.h +126 -0
  245. data/third_party/abseil-cpp/absl/container/fixed_array.h +515 -0
  246. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +503 -0
  247. data/third_party/abseil-cpp/absl/container/internal/common.h +202 -0
  248. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +440 -0
  249. data/third_party/abseil-cpp/absl/container/internal/hash_function_defaults.h +146 -0
  250. data/third_party/abseil-cpp/absl/container/internal/hash_policy_traits.h +191 -0
  251. data/third_party/abseil-cpp/absl/container/internal/hashtable_debug_hooks.h +85 -0
  252. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +269 -0
  253. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +297 -0
  254. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +30 -0
  255. data/third_party/abseil-cpp/absl/container/internal/have_sse.h +49 -0
  256. data/third_party/abseil-cpp/absl/container/internal/layout.h +741 -0
  257. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +48 -0
  258. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +1882 -0
  259. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +138 -0
  260. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.h +32 -0
  261. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +1895 -0
  262. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +71 -0
  263. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.cc +382 -0
  264. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +134 -0
  265. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +192 -0
  266. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_arm-inl.inc +125 -0
  267. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +70 -0
  268. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_generic-inl.inc +99 -0
  269. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +248 -0
  270. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_unimplemented-inl.inc +24 -0
  271. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_win32-inl.inc +85 -0
  272. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_x86-inl.inc +346 -0
  273. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +128 -0
  274. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.cc +194 -0
  275. data/third_party/abseil-cpp/absl/debugging/internal/vdso_support.h +158 -0
  276. data/third_party/abseil-cpp/absl/debugging/stacktrace.cc +140 -0
  277. data/third_party/abseil-cpp/absl/debugging/stacktrace.h +231 -0
  278. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +25 -0
  279. data/third_party/abseil-cpp/absl/debugging/symbolize.h +99 -0
  280. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +1480 -0
  281. data/third_party/abseil-cpp/absl/debugging/symbolize_unimplemented.inc +40 -0
  282. data/third_party/abseil-cpp/absl/debugging/symbolize_win32.inc +81 -0
  283. data/third_party/abseil-cpp/absl/functional/function_ref.h +139 -0
  284. data/third_party/abseil-cpp/absl/functional/internal/function_ref.h +106 -0
  285. data/third_party/abseil-cpp/absl/hash/hash.h +324 -0
  286. data/third_party/abseil-cpp/absl/hash/internal/city.cc +346 -0
  287. data/third_party/abseil-cpp/absl/hash/internal/city.h +96 -0
  288. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +55 -0
  289. data/third_party/abseil-cpp/absl/hash/internal/hash.h +988 -0
  290. data/third_party/abseil-cpp/absl/status/status.cc +447 -0
  291. data/third_party/abseil-cpp/absl/status/status.h +428 -0
  292. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +43 -0
  293. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +51 -0
  294. data/third_party/abseil-cpp/absl/strings/cord.cc +2019 -0
  295. data/third_party/abseil-cpp/absl/strings/cord.h +1121 -0
  296. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +151 -0
  297. data/third_party/abseil-cpp/absl/synchronization/barrier.cc +52 -0
  298. data/third_party/abseil-cpp/absl/synchronization/barrier.h +79 -0
  299. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +57 -0
  300. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +99 -0
  301. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +140 -0
  302. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h +60 -0
  303. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +697 -0
  304. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h +141 -0
  305. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +155 -0
  306. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +261 -0
  307. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +106 -0
  308. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +115 -0
  309. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +484 -0
  310. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +159 -0
  311. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +2728 -0
  312. data/third_party/abseil-cpp/absl/synchronization/mutex.h +1056 -0
  313. data/third_party/abseil-cpp/absl/synchronization/notification.cc +78 -0
  314. data/third_party/abseil-cpp/absl/synchronization/notification.h +123 -0
  315. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +64 -0
  316. data/third_party/abseil-cpp/absl/types/bad_variant_access.h +82 -0
  317. data/third_party/abseil-cpp/absl/types/internal/variant.h +1646 -0
  318. data/third_party/abseil-cpp/absl/types/variant.h +861 -0
  319. data/third_party/boringssl-with-bazel/err_data.c +263 -257
  320. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.c +16 -0
  321. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +456 -0
  322. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +192 -0
  323. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +20 -0
  324. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +52 -0
  325. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +1 -1
  326. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +39 -7
  327. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -3
  328. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +11 -0
  329. data/third_party/boringssl-with-bazel/src/ssl/internal.h +4 -0
  330. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +3 -6
  331. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +10 -0
  332. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +34 -9
  333. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +5 -0
  334. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +5 -3
  335. data/third_party/upb/upb/decode.c +64 -15
  336. data/third_party/upb/upb/encode.c +2 -2
  337. data/third_party/upb/upb/msg.h +2 -2
  338. data/third_party/upb/upb/port_def.inc +1 -1
  339. data/third_party/upb/upb/table.c +0 -11
  340. data/third_party/upb/upb/table.int.h +0 -9
  341. data/third_party/upb/upb/upb.c +16 -14
  342. data/third_party/upb/upb/upb.h +26 -0
  343. data/third_party/upb/upb/upb.hpp +2 -0
  344. metadata +257 -155
  345. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +0 -21
  346. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +0 -34
  347. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.c +0 -114
  348. data/src/core/ext/upb-generated/envoy/api/v2/auth/common.upb.h +0 -429
  349. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.c +0 -72
  350. data/src/core/ext/upb-generated/envoy/api/v2/auth/secret.upb.h +0 -198
  351. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.c +0 -105
  352. data/src/core/ext/upb-generated/envoy/api/v2/auth/tls.upb.h +0 -388
  353. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +0 -52
  354. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.c +0 -403
  355. data/src/core/ext/upb-generated/envoy/api/v2/cluster.upb.h +0 -1453
  356. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +0 -74
  357. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +0 -226
  358. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +0 -69
  359. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +0 -323
  360. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +0 -112
  361. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +0 -334
  362. data/src/core/ext/upb-generated/envoy/api/v2/core/backoff.upb.h +0 -79
  363. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +0 -313
  364. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +0 -891
  365. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +0 -96
  366. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +0 -328
  367. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.c +0 -34
  368. data/src/core/ext/upb-generated/envoy/api/v2/core/event_service_config.upb.h +0 -71
  369. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +0 -197
  370. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +0 -649
  371. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +0 -172
  372. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +0 -693
  373. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +0 -80
  374. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +0 -152
  375. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +0 -536
  376. data/src/core/ext/upb-generated/envoy/api/v2/core/socket_option.upb.h +0 -88
  377. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +0 -129
  378. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +0 -386
  379. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +0 -52
  380. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.c +0 -92
  381. data/src/core/ext/upb-generated/envoy/api/v2/endpoint.upb.h +0 -224
  382. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +0 -18
  383. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +0 -32
  384. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.c +0 -91
  385. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint_components.upb.h +0 -273
  386. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +0 -112
  387. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +0 -332
  388. data/src/core/ext/upb-generated/envoy/api/v2/lds.upb.h +0 -52
  389. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.c +0 -109
  390. data/src/core/ext/upb-generated/envoy/api/v2/listener.upb.h +0 -415
  391. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.c +0 -18
  392. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener.upb.h +0 -32
  393. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.c +0 -145
  394. data/src/core/ext/upb-generated/envoy/api/v2/listener/listener_components.upb.h +0 -538
  395. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.c +0 -43
  396. data/src/core/ext/upb-generated/envoy/api/v2/listener/udp_listener_config.upb.h +0 -111
  397. data/src/core/ext/upb-generated/envoy/api/v2/rds.upb.h +0 -52
  398. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.c +0 -63
  399. data/src/core/ext/upb-generated/envoy/api/v2/route.upb.h +0 -204
  400. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.c +0 -18
  401. data/src/core/ext/upb-generated/envoy/api/v2/route/route.upb.h +0 -32
  402. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.c +0 -815
  403. data/src/core/ext/upb-generated/envoy/api/v2/route/route_components.upb.h +0 -2984
  404. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.c +0 -59
  405. data/src/core/ext/upb-generated/envoy/api/v2/scoped_route.upb.h +0 -135
  406. data/src/core/ext/upb-generated/envoy/api/v2/srds.upb.h +0 -52
  407. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.c +0 -228
  408. data/src/core/ext/upb-generated/envoy/config/filter/accesslog/v2/accesslog.upb.h +0 -732
  409. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.c +0 -316
  410. data/src/core/ext/upb-generated/envoy/config/filter/network/http_connection_manager/v2/http_connection_manager.upb.h +0 -1167
  411. data/src/core/ext/upb-generated/envoy/config/listener/v2/api_listener.upb.h +0 -65
  412. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.c +0 -51
  413. data/src/core/ext/upb-generated/envoy/config/trace/v2/http_tracer.upb.h +0 -125
  414. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +0 -49
  415. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +0 -54
  416. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +0 -136
  417. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.c +0 -63
  418. data/src/core/ext/upb-generated/envoy/type/matcher/regex.upb.h +0 -145
  419. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.c +0 -53
  420. data/src/core/ext/upb-generated/envoy/type/matcher/string.upb.h +0 -133
  421. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.c +0 -88
  422. data/src/core/ext/upb-generated/envoy/type/metadata/v2/metadata.upb.h +0 -258
  423. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +0 -86
  424. data/src/core/ext/upb-generated/envoy/type/range.upb.h +0 -111
  425. data/src/core/ext/upb-generated/envoy/type/semantic_version.upb.h +0 -61
  426. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.c +0 -89
  427. data/src/core/ext/upb-generated/envoy/type/tracing/v2/custom_tag.upb.h +0 -250
  428. data/src/core/lib/security/transport/target_authority_table.cc +0 -75
  429. data/src/core/lib/security/transport/target_authority_table.h +0 -40
  430. data/src/core/lib/slice/slice_hash_table.h +0 -199
  431. data/src/core/lib/slice/slice_weak_hash_table.h +0 -102
@@ -0,0 +1,231 @@
1
+ // Copyright 2018 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
+ // File: stacktrace.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file contains routines to extract the current stack trace and associated
20
+ // stack frames. These functions are thread-safe and async-signal-safe.
21
+ //
22
+ // Note that stack trace functionality is platform dependent and requires
23
+ // additional support from the compiler/build system in most cases. (That is,
24
+ // this functionality generally only works on platforms/builds that have been
25
+ // specifically configured to support it.)
26
+ //
27
+ // Note: stack traces in Abseil that do not utilize a symbolizer will result in
28
+ // frames consisting of function addresses rather than human-readable function
29
+ // names. (See symbolize.h for information on symbolizing these values.)
30
+
31
+ #ifndef ABSL_DEBUGGING_STACKTRACE_H_
32
+ #define ABSL_DEBUGGING_STACKTRACE_H_
33
+
34
+ #include "absl/base/config.h"
35
+
36
+ namespace absl {
37
+ ABSL_NAMESPACE_BEGIN
38
+
39
+ // GetStackFrames()
40
+ //
41
+ // Records program counter values for up to `max_depth` frames, skipping the
42
+ // most recent `skip_count` stack frames, stores their corresponding values
43
+ // and sizes in `results` and `sizes` buffers, and returns the number of frames
44
+ // stored. (Note that the frame generated for the `absl::GetStackFrames()`
45
+ // routine itself is also skipped.)
46
+ //
47
+ // Example:
48
+ //
49
+ // main() { foo(); }
50
+ // foo() { bar(); }
51
+ // bar() {
52
+ // void* result[10];
53
+ // int sizes[10];
54
+ // int depth = absl::GetStackFrames(result, sizes, 10, 1);
55
+ // }
56
+ //
57
+ // The current stack frame would consist of three function calls: `bar()`,
58
+ // `foo()`, and then `main()`; however, since the `GetStackFrames()` call sets
59
+ // `skip_count` to `1`, it will skip the frame for `bar()`, the most recently
60
+ // invoked function call. It will therefore return 2 and fill `result` with
61
+ // program counters within the following functions:
62
+ //
63
+ // result[0] foo()
64
+ // result[1] main()
65
+ //
66
+ // (Note: in practice, a few more entries after `main()` may be added to account
67
+ // for startup processes.)
68
+ //
69
+ // Corresponding stack frame sizes will also be recorded:
70
+ //
71
+ // sizes[0] 16
72
+ // sizes[1] 16
73
+ //
74
+ // (Stack frame sizes of `16` above are just for illustration purposes.)
75
+ //
76
+ // Stack frame sizes of 0 or less indicate that those frame sizes couldn't
77
+ // be identified.
78
+ //
79
+ // This routine may return fewer stack frame entries than are
80
+ // available. Also note that `result` and `sizes` must both be non-null.
81
+ extern int GetStackFrames(void** result, int* sizes, int max_depth,
82
+ int skip_count);
83
+
84
+ // GetStackFramesWithContext()
85
+ //
86
+ // Records program counter values obtained from a signal handler. Records
87
+ // program counter values for up to `max_depth` frames, skipping the most recent
88
+ // `skip_count` stack frames, stores their corresponding values and sizes in
89
+ // `results` and `sizes` buffers, and returns the number of frames stored. (Note
90
+ // that the frame generated for the `absl::GetStackFramesWithContext()` routine
91
+ // itself is also skipped.)
92
+ //
93
+ // The `uc` parameter, if non-null, should be a pointer to a `ucontext_t` value
94
+ // passed to a signal handler registered via the `sa_sigaction` field of a
95
+ // `sigaction` struct. (See
96
+ // http://man7.org/linux/man-pages/man2/sigaction.2.html.) The `uc` value may
97
+ // help a stack unwinder to provide a better stack trace under certain
98
+ // conditions. `uc` may safely be null.
99
+ //
100
+ // The `min_dropped_frames` output parameter, if non-null, points to the
101
+ // location to note any dropped stack frames, if any, due to buffer limitations
102
+ // or other reasons. (This value will be set to `0` if no frames were dropped.)
103
+ // The number of total stack frames is guaranteed to be >= skip_count +
104
+ // max_depth + *min_dropped_frames.
105
+ extern int GetStackFramesWithContext(void** result, int* sizes, int max_depth,
106
+ int skip_count, const void* uc,
107
+ int* min_dropped_frames);
108
+
109
+ // GetStackTrace()
110
+ //
111
+ // Records program counter values for up to `max_depth` frames, skipping the
112
+ // most recent `skip_count` stack frames, stores their corresponding values
113
+ // in `results`, and returns the number of frames
114
+ // stored. Note that this function is similar to `absl::GetStackFrames()`
115
+ // except that it returns the stack trace only, and not stack frame sizes.
116
+ //
117
+ // Example:
118
+ //
119
+ // main() { foo(); }
120
+ // foo() { bar(); }
121
+ // bar() {
122
+ // void* result[10];
123
+ // int depth = absl::GetStackTrace(result, 10, 1);
124
+ // }
125
+ //
126
+ // This produces:
127
+ //
128
+ // result[0] foo
129
+ // result[1] main
130
+ // .... ...
131
+ //
132
+ // `result` must not be null.
133
+ extern int GetStackTrace(void** result, int max_depth, int skip_count);
134
+
135
+ // GetStackTraceWithContext()
136
+ //
137
+ // Records program counter values obtained from a signal handler. Records
138
+ // program counter values for up to `max_depth` frames, skipping the most recent
139
+ // `skip_count` stack frames, stores their corresponding values in `results`,
140
+ // and returns the number of frames stored. (Note that the frame generated for
141
+ // the `absl::GetStackFramesWithContext()` routine itself is also skipped.)
142
+ //
143
+ // The `uc` parameter, if non-null, should be a pointer to a `ucontext_t` value
144
+ // passed to a signal handler registered via the `sa_sigaction` field of a
145
+ // `sigaction` struct. (See
146
+ // http://man7.org/linux/man-pages/man2/sigaction.2.html.) The `uc` value may
147
+ // help a stack unwinder to provide a better stack trace under certain
148
+ // conditions. `uc` may safely be null.
149
+ //
150
+ // The `min_dropped_frames` output parameter, if non-null, points to the
151
+ // location to note any dropped stack frames, if any, due to buffer limitations
152
+ // or other reasons. (This value will be set to `0` if no frames were dropped.)
153
+ // The number of total stack frames is guaranteed to be >= skip_count +
154
+ // max_depth + *min_dropped_frames.
155
+ extern int GetStackTraceWithContext(void** result, int max_depth,
156
+ int skip_count, const void* uc,
157
+ int* min_dropped_frames);
158
+
159
+ // SetStackUnwinder()
160
+ //
161
+ // Provides a custom function for unwinding stack frames that will be used in
162
+ // place of the default stack unwinder when invoking the static
163
+ // GetStack{Frames,Trace}{,WithContext}() functions above.
164
+ //
165
+ // The arguments passed to the unwinder function will match the
166
+ // arguments passed to `absl::GetStackFramesWithContext()` except that sizes
167
+ // will be non-null iff the caller is interested in frame sizes.
168
+ //
169
+ // If unwinder is set to null, we revert to the default stack-tracing behavior.
170
+ //
171
+ // *****************************************************************************
172
+ // WARNING
173
+ // *****************************************************************************
174
+ //
175
+ // absl::SetStackUnwinder is not suitable for general purpose use. It is
176
+ // provided for custom runtimes.
177
+ // Some things to watch out for when calling `absl::SetStackUnwinder()`:
178
+ //
179
+ // (a) The unwinder may be called from within signal handlers and
180
+ // therefore must be async-signal-safe.
181
+ //
182
+ // (b) Even after a custom stack unwinder has been unregistered, other
183
+ // threads may still be in the process of using that unwinder.
184
+ // Therefore do not clean up any state that may be needed by an old
185
+ // unwinder.
186
+ // *****************************************************************************
187
+ extern void SetStackUnwinder(int (*unwinder)(void** pcs, int* sizes,
188
+ int max_depth, int skip_count,
189
+ const void* uc,
190
+ int* min_dropped_frames));
191
+
192
+ // DefaultStackUnwinder()
193
+ //
194
+ // Records program counter values of up to `max_depth` frames, skipping the most
195
+ // recent `skip_count` stack frames, and stores their corresponding values in
196
+ // `pcs`. (Note that the frame generated for this call itself is also skipped.)
197
+ // This function acts as a generic stack-unwinder; prefer usage of the more
198
+ // specific `GetStack{Trace,Frames}{,WithContext}()` functions above.
199
+ //
200
+ // If you have set your own stack unwinder (with the `SetStackUnwinder()`
201
+ // function above, you can still get the default stack unwinder by calling
202
+ // `DefaultStackUnwinder()`, which will ignore any previously set stack unwinder
203
+ // and use the default one instead.
204
+ //
205
+ // Because this function is generic, only `pcs` is guaranteed to be non-null
206
+ // upon return. It is legal for `sizes`, `uc`, and `min_dropped_frames` to all
207
+ // be null when called.
208
+ //
209
+ // The semantics are the same as the corresponding `GetStack*()` function in the
210
+ // case where `absl::SetStackUnwinder()` was never called. Equivalents are:
211
+ //
212
+ // null sizes | non-nullptr sizes
213
+ // |==========================================================|
214
+ // null uc | GetStackTrace() | GetStackFrames() |
215
+ // non-null uc | GetStackTraceWithContext() | GetStackFramesWithContext() |
216
+ // |==========================================================|
217
+ extern int DefaultStackUnwinder(void** pcs, int* sizes, int max_depth,
218
+ int skip_count, const void* uc,
219
+ int* min_dropped_frames);
220
+
221
+ namespace debugging_internal {
222
+ // Returns true for platforms which are expected to have functioning stack trace
223
+ // implementations. Intended to be used for tests which want to exclude
224
+ // verification of logic known to be broken because stack traces are not
225
+ // working.
226
+ extern bool StackTraceWorksForTest();
227
+ } // namespace debugging_internal
228
+ ABSL_NAMESPACE_END
229
+ } // namespace absl
230
+
231
+ #endif // ABSL_DEBUGGING_STACKTRACE_H_
@@ -0,0 +1,25 @@
1
+ // Copyright 2018 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 "absl/debugging/symbolize.h"
16
+
17
+ #if defined(ABSL_INTERNAL_HAVE_ELF_SYMBOLIZE)
18
+ #include "absl/debugging/symbolize_elf.inc"
19
+ #elif defined(_WIN32)
20
+ // The Windows Symbolizer only works if PDB files containing the debug info
21
+ // are available to the program at runtime.
22
+ #include "absl/debugging/symbolize_win32.inc"
23
+ #else
24
+ #include "absl/debugging/symbolize_unimplemented.inc"
25
+ #endif
@@ -0,0 +1,99 @@
1
+ // Copyright 2018 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
+ // File: symbolize.h
17
+ // -----------------------------------------------------------------------------
18
+ //
19
+ // This file configures the Abseil symbolizer for use in converting instruction
20
+ // pointer addresses (program counters) into human-readable names (function
21
+ // calls, etc.) within Abseil code.
22
+ //
23
+ // The symbolizer may be invoked from several sources:
24
+ //
25
+ // * Implicitly, through the installation of an Abseil failure signal handler.
26
+ // (See failure_signal_handler.h for more information.)
27
+ // * By calling `Symbolize()` directly on a program counter you obtain through
28
+ // `absl::GetStackTrace()` or `absl::GetStackFrames()`. (See stacktrace.h
29
+ // for more information.
30
+ // * By calling `Symbolize()` directly on a program counter you obtain through
31
+ // other means (which would be platform-dependent).
32
+ //
33
+ // In all of the above cases, the symbolizer must first be initialized before
34
+ // any program counter values can be symbolized. If you are installing a failure
35
+ // signal handler, initialize the symbolizer before you do so.
36
+ //
37
+ // Example:
38
+ //
39
+ // int main(int argc, char** argv) {
40
+ // // Initialize the Symbolizer before installing the failure signal handler
41
+ // absl::InitializeSymbolizer(argv[0]);
42
+ //
43
+ // // Now you may install the failure signal handler
44
+ // absl::FailureSignalHandlerOptions options;
45
+ // absl::InstallFailureSignalHandler(options);
46
+ //
47
+ // // Start running your main program
48
+ // ...
49
+ // return 0;
50
+ // }
51
+ //
52
+ #ifndef ABSL_DEBUGGING_SYMBOLIZE_H_
53
+ #define ABSL_DEBUGGING_SYMBOLIZE_H_
54
+
55
+ #include "absl/debugging/internal/symbolize.h"
56
+
57
+ namespace absl {
58
+ ABSL_NAMESPACE_BEGIN
59
+
60
+ // InitializeSymbolizer()
61
+ //
62
+ // Initializes the program counter symbolizer, given the path of the program
63
+ // (typically obtained through `main()`s `argv[0]`). The Abseil symbolizer
64
+ // allows you to read program counters (instruction pointer values) using their
65
+ // human-readable names within output such as stack traces.
66
+ //
67
+ // Example:
68
+ //
69
+ // int main(int argc, char *argv[]) {
70
+ // absl::InitializeSymbolizer(argv[0]);
71
+ // // Now you can use the symbolizer
72
+ // }
73
+ void InitializeSymbolizer(const char* argv0);
74
+ //
75
+ // Symbolize()
76
+ //
77
+ // Symbolizes a program counter (instruction pointer value) `pc` and, on
78
+ // success, writes the name to `out`. The symbol name is demangled, if possible.
79
+ // Note that the symbolized name may be truncated and will be NUL-terminated.
80
+ // Demangling is supported for symbols generated by GCC 3.x or newer). Returns
81
+ // `false` on failure.
82
+ //
83
+ // Example:
84
+ //
85
+ // // Print a program counter and its symbol name.
86
+ // static void DumpPCAndSymbol(void *pc) {
87
+ // char tmp[1024];
88
+ // const char *symbol = "(unknown)";
89
+ // if (absl::Symbolize(pc, tmp, sizeof(tmp))) {
90
+ // symbol = tmp;
91
+ // }
92
+ // absl::PrintF("%p %s\n", pc, symbol);
93
+ // }
94
+ bool Symbolize(const void *pc, char *out, int out_size);
95
+
96
+ ABSL_NAMESPACE_END
97
+ } // namespace absl
98
+
99
+ #endif // ABSL_DEBUGGING_SYMBOLIZE_H_
@@ -0,0 +1,1480 @@
1
+ // Copyright 2018 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
+ // This library provides Symbolize() function that symbolizes program
16
+ // counters to their corresponding symbol names on linux platforms.
17
+ // This library has a minimal implementation of an ELF symbol table
18
+ // reader (i.e. it doesn't depend on libelf, etc.).
19
+ //
20
+ // The algorithm used in Symbolize() is as follows.
21
+ //
22
+ // 1. Go through a list of maps in /proc/self/maps and find the map
23
+ // containing the program counter.
24
+ //
25
+ // 2. Open the mapped file and find a regular symbol table inside.
26
+ // Iterate over symbols in the symbol table and look for the symbol
27
+ // containing the program counter. If such a symbol is found,
28
+ // obtain the symbol name, and demangle the symbol if possible.
29
+ // If the symbol isn't found in the regular symbol table (binary is
30
+ // stripped), try the same thing with a dynamic symbol table.
31
+ //
32
+ // Note that Symbolize() is originally implemented to be used in
33
+ // signal handlers, hence it doesn't use malloc() and other unsafe
34
+ // operations. It should be both thread-safe and async-signal-safe.
35
+ //
36
+ // Implementation note:
37
+ //
38
+ // We don't use heaps but only use stacks. We want to reduce the
39
+ // stack consumption so that the symbolizer can run on small stacks.
40
+ //
41
+ // Here are some numbers collected with GCC 4.1.0 on x86:
42
+ // - sizeof(Elf32_Sym) = 16
43
+ // - sizeof(Elf32_Shdr) = 40
44
+ // - sizeof(Elf64_Sym) = 24
45
+ // - sizeof(Elf64_Shdr) = 64
46
+ //
47
+ // This implementation is intended to be async-signal-safe but uses some
48
+ // functions which are not guaranteed to be so, such as memchr() and
49
+ // memmove(). We assume they are async-signal-safe.
50
+
51
+ #include <dlfcn.h>
52
+ #include <elf.h>
53
+ #include <fcntl.h>
54
+ #include <link.h> // For ElfW() macro.
55
+ #include <sys/stat.h>
56
+ #include <sys/types.h>
57
+ #include <unistd.h>
58
+
59
+ #include <algorithm>
60
+ #include <atomic>
61
+ #include <cerrno>
62
+ #include <cinttypes>
63
+ #include <climits>
64
+ #include <cstdint>
65
+ #include <cstdio>
66
+ #include <cstdlib>
67
+ #include <cstring>
68
+
69
+ #include "absl/base/casts.h"
70
+ #include "absl/base/dynamic_annotations.h"
71
+ #include "absl/base/internal/low_level_alloc.h"
72
+ #include "absl/base/internal/raw_logging.h"
73
+ #include "absl/base/internal/spinlock.h"
74
+ #include "absl/base/port.h"
75
+ #include "absl/debugging/internal/demangle.h"
76
+ #include "absl/debugging/internal/vdso_support.h"
77
+
78
+ namespace absl {
79
+ ABSL_NAMESPACE_BEGIN
80
+
81
+ // Value of argv[0]. Used by MaybeInitializeObjFile().
82
+ static char *argv0_value = nullptr;
83
+
84
+ void InitializeSymbolizer(const char *argv0) {
85
+ if (argv0_value != nullptr) {
86
+ free(argv0_value);
87
+ argv0_value = nullptr;
88
+ }
89
+ if (argv0 != nullptr && argv0[0] != '\0') {
90
+ argv0_value = strdup(argv0);
91
+ }
92
+ }
93
+
94
+ namespace debugging_internal {
95
+ namespace {
96
+
97
+ // Re-runs fn until it doesn't cause EINTR.
98
+ #define NO_INTR(fn) \
99
+ do { \
100
+ } while ((fn) < 0 && errno == EINTR)
101
+
102
+ // On Linux, ELF_ST_* are defined in <linux/elf.h>. To make this portable
103
+ // we define our own ELF_ST_BIND and ELF_ST_TYPE if not available.
104
+ #ifndef ELF_ST_BIND
105
+ #define ELF_ST_BIND(info) (((unsigned char)(info)) >> 4)
106
+ #endif
107
+
108
+ #ifndef ELF_ST_TYPE
109
+ #define ELF_ST_TYPE(info) (((unsigned char)(info)) & 0xF)
110
+ #endif
111
+
112
+ // Some platforms use a special .opd section to store function pointers.
113
+ const char kOpdSectionName[] = ".opd";
114
+
115
+ #if (defined(__powerpc__) && !(_CALL_ELF > 1)) || defined(__ia64)
116
+ // Use opd section for function descriptors on these platforms, the function
117
+ // address is the first word of the descriptor.
118
+ enum { kPlatformUsesOPDSections = 1 };
119
+ #else // not PPC or IA64
120
+ enum { kPlatformUsesOPDSections = 0 };
121
+ #endif
122
+
123
+ // This works for PowerPC & IA64 only. A function descriptor consist of two
124
+ // pointers and the first one is the function's entry.
125
+ const size_t kFunctionDescriptorSize = sizeof(void *) * 2;
126
+
127
+ const int kMaxDecorators = 10; // Seems like a reasonable upper limit.
128
+
129
+ struct InstalledSymbolDecorator {
130
+ SymbolDecorator fn;
131
+ void *arg;
132
+ int ticket;
133
+ };
134
+
135
+ int g_num_decorators;
136
+ InstalledSymbolDecorator g_decorators[kMaxDecorators];
137
+
138
+ struct FileMappingHint {
139
+ const void *start;
140
+ const void *end;
141
+ uint64_t offset;
142
+ const char *filename;
143
+ };
144
+
145
+ // Protects g_decorators.
146
+ // We are using SpinLock and not a Mutex here, because we may be called
147
+ // from inside Mutex::Lock itself, and it prohibits recursive calls.
148
+ // This happens in e.g. base/stacktrace_syscall_unittest.
149
+ // Moreover, we are using only TryLock(), if the decorator list
150
+ // is being modified (is busy), we skip all decorators, and possibly
151
+ // loose some info. Sorry, that's the best we could do.
152
+ base_internal::SpinLock g_decorators_mu(base_internal::kLinkerInitialized);
153
+
154
+ const int kMaxFileMappingHints = 8;
155
+ int g_num_file_mapping_hints;
156
+ FileMappingHint g_file_mapping_hints[kMaxFileMappingHints];
157
+ // Protects g_file_mapping_hints.
158
+ base_internal::SpinLock g_file_mapping_mu(base_internal::kLinkerInitialized);
159
+
160
+ // Async-signal-safe function to zero a buffer.
161
+ // memset() is not guaranteed to be async-signal-safe.
162
+ static void SafeMemZero(void* p, size_t size) {
163
+ unsigned char *c = static_cast<unsigned char *>(p);
164
+ while (size--) {
165
+ *c++ = 0;
166
+ }
167
+ }
168
+
169
+ struct ObjFile {
170
+ ObjFile()
171
+ : filename(nullptr),
172
+ start_addr(nullptr),
173
+ end_addr(nullptr),
174
+ offset(0),
175
+ fd(-1),
176
+ elf_type(-1) {
177
+ SafeMemZero(&elf_header, sizeof(elf_header));
178
+ }
179
+
180
+ char *filename;
181
+ const void *start_addr;
182
+ const void *end_addr;
183
+ uint64_t offset;
184
+
185
+ // The following fields are initialized on the first access to the
186
+ // object file.
187
+ int fd;
188
+ int elf_type;
189
+ ElfW(Ehdr) elf_header;
190
+ };
191
+
192
+ // Build 4-way associative cache for symbols. Within each cache line, symbols
193
+ // are replaced in LRU order.
194
+ enum {
195
+ ASSOCIATIVITY = 4,
196
+ };
197
+ struct SymbolCacheLine {
198
+ const void *pc[ASSOCIATIVITY];
199
+ char *name[ASSOCIATIVITY];
200
+
201
+ // age[i] is incremented when a line is accessed. it's reset to zero if the
202
+ // i'th entry is read.
203
+ uint32_t age[ASSOCIATIVITY];
204
+ };
205
+
206
+ // ---------------------------------------------------------------
207
+ // An async-signal-safe arena for LowLevelAlloc
208
+ static std::atomic<base_internal::LowLevelAlloc::Arena *> g_sig_safe_arena;
209
+
210
+ static base_internal::LowLevelAlloc::Arena *SigSafeArena() {
211
+ return g_sig_safe_arena.load(std::memory_order_acquire);
212
+ }
213
+
214
+ static void InitSigSafeArena() {
215
+ if (SigSafeArena() == nullptr) {
216
+ base_internal::LowLevelAlloc::Arena *new_arena =
217
+ base_internal::LowLevelAlloc::NewArena(
218
+ base_internal::LowLevelAlloc::kAsyncSignalSafe);
219
+ base_internal::LowLevelAlloc::Arena *old_value = nullptr;
220
+ if (!g_sig_safe_arena.compare_exchange_strong(old_value, new_arena,
221
+ std::memory_order_release,
222
+ std::memory_order_relaxed)) {
223
+ // We lost a race to allocate an arena; deallocate.
224
+ base_internal::LowLevelAlloc::DeleteArena(new_arena);
225
+ }
226
+ }
227
+ }
228
+
229
+ // ---------------------------------------------------------------
230
+ // An AddrMap is a vector of ObjFile, using SigSafeArena() for allocation.
231
+
232
+ class AddrMap {
233
+ public:
234
+ AddrMap() : size_(0), allocated_(0), obj_(nullptr) {}
235
+ ~AddrMap() { base_internal::LowLevelAlloc::Free(obj_); }
236
+ int Size() const { return size_; }
237
+ ObjFile *At(int i) { return &obj_[i]; }
238
+ ObjFile *Add();
239
+ void Clear();
240
+
241
+ private:
242
+ int size_; // count of valid elements (<= allocated_)
243
+ int allocated_; // count of allocated elements
244
+ ObjFile *obj_; // array of allocated_ elements
245
+ AddrMap(const AddrMap &) = delete;
246
+ AddrMap &operator=(const AddrMap &) = delete;
247
+ };
248
+
249
+ void AddrMap::Clear() {
250
+ for (int i = 0; i != size_; i++) {
251
+ At(i)->~ObjFile();
252
+ }
253
+ size_ = 0;
254
+ }
255
+
256
+ ObjFile *AddrMap::Add() {
257
+ if (size_ == allocated_) {
258
+ int new_allocated = allocated_ * 2 + 50;
259
+ ObjFile *new_obj_ =
260
+ static_cast<ObjFile *>(base_internal::LowLevelAlloc::AllocWithArena(
261
+ new_allocated * sizeof(*new_obj_), SigSafeArena()));
262
+ if (obj_) {
263
+ memcpy(new_obj_, obj_, allocated_ * sizeof(*new_obj_));
264
+ base_internal::LowLevelAlloc::Free(obj_);
265
+ }
266
+ obj_ = new_obj_;
267
+ allocated_ = new_allocated;
268
+ }
269
+ return new (&obj_[size_++]) ObjFile;
270
+ }
271
+
272
+ // ---------------------------------------------------------------
273
+
274
+ enum FindSymbolResult { SYMBOL_NOT_FOUND = 1, SYMBOL_TRUNCATED, SYMBOL_FOUND };
275
+
276
+ class Symbolizer {
277
+ public:
278
+ Symbolizer();
279
+ ~Symbolizer();
280
+ const char *GetSymbol(const void *const pc);
281
+
282
+ private:
283
+ char *CopyString(const char *s) {
284
+ int len = strlen(s);
285
+ char *dst = static_cast<char *>(
286
+ base_internal::LowLevelAlloc::AllocWithArena(len + 1, SigSafeArena()));
287
+ ABSL_RAW_CHECK(dst != nullptr, "out of memory");
288
+ memcpy(dst, s, len + 1);
289
+ return dst;
290
+ }
291
+ ObjFile *FindObjFile(const void *const start,
292
+ size_t size) ABSL_ATTRIBUTE_NOINLINE;
293
+ static bool RegisterObjFile(const char *filename,
294
+ const void *const start_addr,
295
+ const void *const end_addr, uint64_t offset,
296
+ void *arg);
297
+ SymbolCacheLine *GetCacheLine(const void *const pc);
298
+ const char *FindSymbolInCache(const void *const pc);
299
+ const char *InsertSymbolInCache(const void *const pc, const char *name);
300
+ void AgeSymbols(SymbolCacheLine *line);
301
+ void ClearAddrMap();
302
+ FindSymbolResult GetSymbolFromObjectFile(const ObjFile &obj,
303
+ const void *const pc,
304
+ const ptrdiff_t relocation,
305
+ char *out, int out_size,
306
+ char *tmp_buf, int tmp_buf_size);
307
+
308
+ enum {
309
+ SYMBOL_BUF_SIZE = 3072,
310
+ TMP_BUF_SIZE = 1024,
311
+ SYMBOL_CACHE_LINES = 128,
312
+ };
313
+
314
+ AddrMap addr_map_;
315
+
316
+ bool ok_;
317
+ bool addr_map_read_;
318
+
319
+ char symbol_buf_[SYMBOL_BUF_SIZE];
320
+
321
+ // tmp_buf_ will be used to store arrays of ElfW(Shdr) and ElfW(Sym)
322
+ // so we ensure that tmp_buf_ is properly aligned to store either.
323
+ alignas(16) char tmp_buf_[TMP_BUF_SIZE];
324
+ static_assert(alignof(ElfW(Shdr)) <= 16,
325
+ "alignment of tmp buf too small for Shdr");
326
+ static_assert(alignof(ElfW(Sym)) <= 16,
327
+ "alignment of tmp buf too small for Sym");
328
+
329
+ SymbolCacheLine symbol_cache_[SYMBOL_CACHE_LINES];
330
+ };
331
+
332
+ static std::atomic<Symbolizer *> g_cached_symbolizer;
333
+
334
+ } // namespace
335
+
336
+ static int SymbolizerSize() {
337
+ #if defined(__wasm__) || defined(__asmjs__)
338
+ int pagesize = getpagesize();
339
+ #else
340
+ int pagesize = sysconf(_SC_PAGESIZE);
341
+ #endif
342
+ return ((sizeof(Symbolizer) - 1) / pagesize + 1) * pagesize;
343
+ }
344
+
345
+ // Return (and set null) g_cached_symbolized_state if it is not null.
346
+ // Otherwise return a new symbolizer.
347
+ static Symbolizer *AllocateSymbolizer() {
348
+ InitSigSafeArena();
349
+ Symbolizer *symbolizer =
350
+ g_cached_symbolizer.exchange(nullptr, std::memory_order_acquire);
351
+ if (symbolizer != nullptr) {
352
+ return symbolizer;
353
+ }
354
+ return new (base_internal::LowLevelAlloc::AllocWithArena(
355
+ SymbolizerSize(), SigSafeArena())) Symbolizer();
356
+ }
357
+
358
+ // Set g_cached_symbolize_state to s if it is null, otherwise
359
+ // delete s.
360
+ static void FreeSymbolizer(Symbolizer *s) {
361
+ Symbolizer *old_cached_symbolizer = nullptr;
362
+ if (!g_cached_symbolizer.compare_exchange_strong(old_cached_symbolizer, s,
363
+ std::memory_order_release,
364
+ std::memory_order_relaxed)) {
365
+ s->~Symbolizer();
366
+ base_internal::LowLevelAlloc::Free(s);
367
+ }
368
+ }
369
+
370
+ Symbolizer::Symbolizer() : ok_(true), addr_map_read_(false) {
371
+ for (SymbolCacheLine &symbol_cache_line : symbol_cache_) {
372
+ for (size_t j = 0; j < ABSL_ARRAYSIZE(symbol_cache_line.name); ++j) {
373
+ symbol_cache_line.pc[j] = nullptr;
374
+ symbol_cache_line.name[j] = nullptr;
375
+ symbol_cache_line.age[j] = 0;
376
+ }
377
+ }
378
+ }
379
+
380
+ Symbolizer::~Symbolizer() {
381
+ for (SymbolCacheLine &symbol_cache_line : symbol_cache_) {
382
+ for (char *s : symbol_cache_line.name) {
383
+ base_internal::LowLevelAlloc::Free(s);
384
+ }
385
+ }
386
+ ClearAddrMap();
387
+ }
388
+
389
+ // We don't use assert() since it's not guaranteed to be
390
+ // async-signal-safe. Instead we define a minimal assertion
391
+ // macro. So far, we don't need pretty printing for __FILE__, etc.
392
+ #define SAFE_ASSERT(expr) ((expr) ? static_cast<void>(0) : abort())
393
+
394
+ // Read up to "count" bytes from file descriptor "fd" into the buffer
395
+ // starting at "buf" while handling short reads and EINTR. On
396
+ // success, return the number of bytes read. Otherwise, return -1.
397
+ static ssize_t ReadPersistent(int fd, void *buf, size_t count) {
398
+ SAFE_ASSERT(fd >= 0);
399
+ SAFE_ASSERT(count <= SSIZE_MAX);
400
+ char *buf0 = reinterpret_cast<char *>(buf);
401
+ size_t num_bytes = 0;
402
+ while (num_bytes < count) {
403
+ ssize_t len;
404
+ NO_INTR(len = read(fd, buf0 + num_bytes, count - num_bytes));
405
+ if (len < 0) { // There was an error other than EINTR.
406
+ ABSL_RAW_LOG(WARNING, "read failed: errno=%d", errno);
407
+ return -1;
408
+ }
409
+ if (len == 0) { // Reached EOF.
410
+ break;
411
+ }
412
+ num_bytes += len;
413
+ }
414
+ SAFE_ASSERT(num_bytes <= count);
415
+ return static_cast<ssize_t>(num_bytes);
416
+ }
417
+
418
+ // Read up to "count" bytes from "offset" in the file pointed by file
419
+ // descriptor "fd" into the buffer starting at "buf". On success,
420
+ // return the number of bytes read. Otherwise, return -1.
421
+ static ssize_t ReadFromOffset(const int fd, void *buf, const size_t count,
422
+ const off_t offset) {
423
+ off_t off = lseek(fd, offset, SEEK_SET);
424
+ if (off == (off_t)-1) {
425
+ ABSL_RAW_LOG(WARNING, "lseek(%d, %ju, SEEK_SET) failed: errno=%d", fd,
426
+ static_cast<uintmax_t>(offset), errno);
427
+ return -1;
428
+ }
429
+ return ReadPersistent(fd, buf, count);
430
+ }
431
+
432
+ // Try reading exactly "count" bytes from "offset" bytes in a file
433
+ // pointed by "fd" into the buffer starting at "buf" while handling
434
+ // short reads and EINTR. On success, return true. Otherwise, return
435
+ // false.
436
+ static bool ReadFromOffsetExact(const int fd, void *buf, const size_t count,
437
+ const off_t offset) {
438
+ ssize_t len = ReadFromOffset(fd, buf, count, offset);
439
+ return len >= 0 && static_cast<size_t>(len) == count;
440
+ }
441
+
442
+ // Returns elf_header.e_type if the file pointed by fd is an ELF binary.
443
+ static int FileGetElfType(const int fd) {
444
+ ElfW(Ehdr) elf_header;
445
+ if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
446
+ return -1;
447
+ }
448
+ if (memcmp(elf_header.e_ident, ELFMAG, SELFMAG) != 0) {
449
+ return -1;
450
+ }
451
+ return elf_header.e_type;
452
+ }
453
+
454
+ // Read the section headers in the given ELF binary, and if a section
455
+ // of the specified type is found, set the output to this section header
456
+ // and return true. Otherwise, return false.
457
+ // To keep stack consumption low, we would like this function to not get
458
+ // inlined.
459
+ static ABSL_ATTRIBUTE_NOINLINE bool GetSectionHeaderByType(
460
+ const int fd, ElfW(Half) sh_num, const off_t sh_offset, ElfW(Word) type,
461
+ ElfW(Shdr) * out, char *tmp_buf, int tmp_buf_size) {
462
+ ElfW(Shdr) *buf = reinterpret_cast<ElfW(Shdr) *>(tmp_buf);
463
+ const int buf_entries = tmp_buf_size / sizeof(buf[0]);
464
+ const int buf_bytes = buf_entries * sizeof(buf[0]);
465
+
466
+ for (int i = 0; i < sh_num;) {
467
+ const ssize_t num_bytes_left = (sh_num - i) * sizeof(buf[0]);
468
+ const ssize_t num_bytes_to_read =
469
+ (buf_bytes > num_bytes_left) ? num_bytes_left : buf_bytes;
470
+ const off_t offset = sh_offset + i * sizeof(buf[0]);
471
+ const ssize_t len = ReadFromOffset(fd, buf, num_bytes_to_read, offset);
472
+ if (len % sizeof(buf[0]) != 0) {
473
+ ABSL_RAW_LOG(
474
+ WARNING,
475
+ "Reading %zd bytes from offset %ju returned %zd which is not a "
476
+ "multiple of %zu.",
477
+ num_bytes_to_read, static_cast<uintmax_t>(offset), len,
478
+ sizeof(buf[0]));
479
+ return false;
480
+ }
481
+ const ssize_t num_headers_in_buf = len / sizeof(buf[0]);
482
+ SAFE_ASSERT(num_headers_in_buf <= buf_entries);
483
+ for (int j = 0; j < num_headers_in_buf; ++j) {
484
+ if (buf[j].sh_type == type) {
485
+ *out = buf[j];
486
+ return true;
487
+ }
488
+ }
489
+ i += num_headers_in_buf;
490
+ }
491
+ return false;
492
+ }
493
+
494
+ // There is no particular reason to limit section name to 63 characters,
495
+ // but there has (as yet) been no need for anything longer either.
496
+ const int kMaxSectionNameLen = 64;
497
+
498
+ bool ForEachSection(int fd,
499
+ const std::function<bool(const std::string &name,
500
+ const ElfW(Shdr) &)> &callback) {
501
+ ElfW(Ehdr) elf_header;
502
+ if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
503
+ return false;
504
+ }
505
+
506
+ ElfW(Shdr) shstrtab;
507
+ off_t shstrtab_offset =
508
+ (elf_header.e_shoff + elf_header.e_shentsize * elf_header.e_shstrndx);
509
+ if (!ReadFromOffsetExact(fd, &shstrtab, sizeof(shstrtab), shstrtab_offset)) {
510
+ return false;
511
+ }
512
+
513
+ for (int i = 0; i < elf_header.e_shnum; ++i) {
514
+ ElfW(Shdr) out;
515
+ off_t section_header_offset =
516
+ (elf_header.e_shoff + elf_header.e_shentsize * i);
517
+ if (!ReadFromOffsetExact(fd, &out, sizeof(out), section_header_offset)) {
518
+ return false;
519
+ }
520
+ off_t name_offset = shstrtab.sh_offset + out.sh_name;
521
+ char header_name[kMaxSectionNameLen + 1];
522
+ ssize_t n_read =
523
+ ReadFromOffset(fd, &header_name, kMaxSectionNameLen, name_offset);
524
+ if (n_read == -1) {
525
+ return false;
526
+ } else if (n_read > kMaxSectionNameLen) {
527
+ // Long read?
528
+ return false;
529
+ }
530
+ header_name[n_read] = '\0';
531
+
532
+ std::string name(header_name);
533
+ if (!callback(name, out)) {
534
+ break;
535
+ }
536
+ }
537
+ return true;
538
+ }
539
+
540
+ // name_len should include terminating '\0'.
541
+ bool GetSectionHeaderByName(int fd, const char *name, size_t name_len,
542
+ ElfW(Shdr) * out) {
543
+ char header_name[kMaxSectionNameLen];
544
+ if (sizeof(header_name) < name_len) {
545
+ ABSL_RAW_LOG(WARNING,
546
+ "Section name '%s' is too long (%zu); "
547
+ "section will not be found (even if present).",
548
+ name, name_len);
549
+ // No point in even trying.
550
+ return false;
551
+ }
552
+
553
+ ElfW(Ehdr) elf_header;
554
+ if (!ReadFromOffsetExact(fd, &elf_header, sizeof(elf_header), 0)) {
555
+ return false;
556
+ }
557
+
558
+ ElfW(Shdr) shstrtab;
559
+ off_t shstrtab_offset =
560
+ (elf_header.e_shoff + elf_header.e_shentsize * elf_header.e_shstrndx);
561
+ if (!ReadFromOffsetExact(fd, &shstrtab, sizeof(shstrtab), shstrtab_offset)) {
562
+ return false;
563
+ }
564
+
565
+ for (int i = 0; i < elf_header.e_shnum; ++i) {
566
+ off_t section_header_offset =
567
+ (elf_header.e_shoff + elf_header.e_shentsize * i);
568
+ if (!ReadFromOffsetExact(fd, out, sizeof(*out), section_header_offset)) {
569
+ return false;
570
+ }
571
+ off_t name_offset = shstrtab.sh_offset + out->sh_name;
572
+ ssize_t n_read = ReadFromOffset(fd, &header_name, name_len, name_offset);
573
+ if (n_read < 0) {
574
+ return false;
575
+ } else if (static_cast<size_t>(n_read) != name_len) {
576
+ // Short read -- name could be at end of file.
577
+ continue;
578
+ }
579
+ if (memcmp(header_name, name, name_len) == 0) {
580
+ return true;
581
+ }
582
+ }
583
+ return false;
584
+ }
585
+
586
+ // Compare symbols at in the same address.
587
+ // Return true if we should pick symbol1.
588
+ static bool ShouldPickFirstSymbol(const ElfW(Sym) & symbol1,
589
+ const ElfW(Sym) & symbol2) {
590
+ // If one of the symbols is weak and the other is not, pick the one
591
+ // this is not a weak symbol.
592
+ char bind1 = ELF_ST_BIND(symbol1.st_info);
593
+ char bind2 = ELF_ST_BIND(symbol1.st_info);
594
+ if (bind1 == STB_WEAK && bind2 != STB_WEAK) return false;
595
+ if (bind2 == STB_WEAK && bind1 != STB_WEAK) return true;
596
+
597
+ // If one of the symbols has zero size and the other is not, pick the
598
+ // one that has non-zero size.
599
+ if (symbol1.st_size != 0 && symbol2.st_size == 0) {
600
+ return true;
601
+ }
602
+ if (symbol1.st_size == 0 && symbol2.st_size != 0) {
603
+ return false;
604
+ }
605
+
606
+ // If one of the symbols has no type and the other is not, pick the
607
+ // one that has a type.
608
+ char type1 = ELF_ST_TYPE(symbol1.st_info);
609
+ char type2 = ELF_ST_TYPE(symbol1.st_info);
610
+ if (type1 != STT_NOTYPE && type2 == STT_NOTYPE) {
611
+ return true;
612
+ }
613
+ if (type1 == STT_NOTYPE && type2 != STT_NOTYPE) {
614
+ return false;
615
+ }
616
+
617
+ // Pick the first one, if we still cannot decide.
618
+ return true;
619
+ }
620
+
621
+ // Return true if an address is inside a section.
622
+ static bool InSection(const void *address, const ElfW(Shdr) * section) {
623
+ const char *start = reinterpret_cast<const char *>(section->sh_addr);
624
+ size_t size = static_cast<size_t>(section->sh_size);
625
+ return start <= address && address < (start + size);
626
+ }
627
+
628
+ static const char *ComputeOffset(const char *base, ptrdiff_t offset) {
629
+ // Note: cast to uintptr_t to avoid undefined behavior when base evaluates to
630
+ // zero and offset is non-zero.
631
+ return reinterpret_cast<const char *>(
632
+ reinterpret_cast<uintptr_t>(base) + offset);
633
+ }
634
+
635
+ // Read a symbol table and look for the symbol containing the
636
+ // pc. Iterate over symbols in a symbol table and look for the symbol
637
+ // containing "pc". If the symbol is found, and its name fits in
638
+ // out_size, the name is written into out and SYMBOL_FOUND is returned.
639
+ // If the name does not fit, truncated name is written into out,
640
+ // and SYMBOL_TRUNCATED is returned. Out is NUL-terminated.
641
+ // If the symbol is not found, SYMBOL_NOT_FOUND is returned;
642
+ // To keep stack consumption low, we would like this function to not get
643
+ // inlined.
644
+ static ABSL_ATTRIBUTE_NOINLINE FindSymbolResult FindSymbol(
645
+ const void *const pc, const int fd, char *out, int out_size,
646
+ ptrdiff_t relocation, const ElfW(Shdr) * strtab, const ElfW(Shdr) * symtab,
647
+ const ElfW(Shdr) * opd, char *tmp_buf, int tmp_buf_size) {
648
+ if (symtab == nullptr) {
649
+ return SYMBOL_NOT_FOUND;
650
+ }
651
+
652
+ // Read multiple symbols at once to save read() calls.
653
+ ElfW(Sym) *buf = reinterpret_cast<ElfW(Sym) *>(tmp_buf);
654
+ const int buf_entries = tmp_buf_size / sizeof(buf[0]);
655
+
656
+ const int num_symbols = symtab->sh_size / symtab->sh_entsize;
657
+
658
+ // On platforms using an .opd section (PowerPC & IA64), a function symbol
659
+ // has the address of a function descriptor, which contains the real
660
+ // starting address. However, we do not always want to use the real
661
+ // starting address because we sometimes want to symbolize a function
662
+ // pointer into the .opd section, e.g. FindSymbol(&foo,...).
663
+ const bool pc_in_opd =
664
+ kPlatformUsesOPDSections && opd != nullptr && InSection(pc, opd);
665
+ const bool deref_function_descriptor_pointer =
666
+ kPlatformUsesOPDSections && opd != nullptr && !pc_in_opd;
667
+
668
+ ElfW(Sym) best_match;
669
+ SafeMemZero(&best_match, sizeof(best_match));
670
+ bool found_match = false;
671
+ for (int i = 0; i < num_symbols;) {
672
+ off_t offset = symtab->sh_offset + i * symtab->sh_entsize;
673
+ const int num_remaining_symbols = num_symbols - i;
674
+ const int entries_in_chunk = std::min(num_remaining_symbols, buf_entries);
675
+ const int bytes_in_chunk = entries_in_chunk * sizeof(buf[0]);
676
+ const ssize_t len = ReadFromOffset(fd, buf, bytes_in_chunk, offset);
677
+ SAFE_ASSERT(len % sizeof(buf[0]) == 0);
678
+ const ssize_t num_symbols_in_buf = len / sizeof(buf[0]);
679
+ SAFE_ASSERT(num_symbols_in_buf <= entries_in_chunk);
680
+ for (int j = 0; j < num_symbols_in_buf; ++j) {
681
+ const ElfW(Sym) &symbol = buf[j];
682
+
683
+ // For a DSO, a symbol address is relocated by the loading address.
684
+ // We keep the original address for opd redirection below.
685
+ const char *const original_start_address =
686
+ reinterpret_cast<const char *>(symbol.st_value);
687
+ const char *start_address =
688
+ ComputeOffset(original_start_address, relocation);
689
+
690
+ if (deref_function_descriptor_pointer &&
691
+ InSection(original_start_address, opd)) {
692
+ // The opd section is mapped into memory. Just dereference
693
+ // start_address to get the first double word, which points to the
694
+ // function entry.
695
+ start_address = *reinterpret_cast<const char *const *>(start_address);
696
+ }
697
+
698
+ // If pc is inside the .opd section, it points to a function descriptor.
699
+ const size_t size = pc_in_opd ? kFunctionDescriptorSize : symbol.st_size;
700
+ const void *const end_address = ComputeOffset(start_address, size);
701
+ if (symbol.st_value != 0 && // Skip null value symbols.
702
+ symbol.st_shndx != 0 && // Skip undefined symbols.
703
+ #ifdef STT_TLS
704
+ ELF_ST_TYPE(symbol.st_info) != STT_TLS && // Skip thread-local data.
705
+ #endif // STT_TLS
706
+ ((start_address <= pc && pc < end_address) ||
707
+ (start_address == pc && pc == end_address))) {
708
+ if (!found_match || ShouldPickFirstSymbol(symbol, best_match)) {
709
+ found_match = true;
710
+ best_match = symbol;
711
+ }
712
+ }
713
+ }
714
+ i += num_symbols_in_buf;
715
+ }
716
+
717
+ if (found_match) {
718
+ const size_t off = strtab->sh_offset + best_match.st_name;
719
+ const ssize_t n_read = ReadFromOffset(fd, out, out_size, off);
720
+ if (n_read <= 0) {
721
+ // This should never happen.
722
+ ABSL_RAW_LOG(WARNING,
723
+ "Unable to read from fd %d at offset %zu: n_read = %zd", fd,
724
+ off, n_read);
725
+ return SYMBOL_NOT_FOUND;
726
+ }
727
+ ABSL_RAW_CHECK(n_read <= out_size, "ReadFromOffset read too much data.");
728
+
729
+ // strtab->sh_offset points into .strtab-like section that contains
730
+ // NUL-terminated strings: '\0foo\0barbaz\0...".
731
+ //
732
+ // sh_offset+st_name points to the start of symbol name, but we don't know
733
+ // how long the symbol is, so we try to read as much as we have space for,
734
+ // and usually over-read (i.e. there is a NUL somewhere before n_read).
735
+ if (memchr(out, '\0', n_read) == nullptr) {
736
+ // Either out_size was too small (n_read == out_size and no NUL), or
737
+ // we tried to read past the EOF (n_read < out_size) and .strtab is
738
+ // corrupt (missing terminating NUL; should never happen for valid ELF).
739
+ out[n_read - 1] = '\0';
740
+ return SYMBOL_TRUNCATED;
741
+ }
742
+ return SYMBOL_FOUND;
743
+ }
744
+
745
+ return SYMBOL_NOT_FOUND;
746
+ }
747
+
748
+ // Get the symbol name of "pc" from the file pointed by "fd". Process
749
+ // both regular and dynamic symbol tables if necessary.
750
+ // See FindSymbol() comment for description of return value.
751
+ FindSymbolResult Symbolizer::GetSymbolFromObjectFile(
752
+ const ObjFile &obj, const void *const pc, const ptrdiff_t relocation,
753
+ char *out, int out_size, char *tmp_buf, int tmp_buf_size) {
754
+ ElfW(Shdr) symtab;
755
+ ElfW(Shdr) strtab;
756
+ ElfW(Shdr) opd;
757
+ ElfW(Shdr) *opd_ptr = nullptr;
758
+
759
+ // On platforms using an .opd sections for function descriptor, read
760
+ // the section header. The .opd section is in data segment and should be
761
+ // loaded but we check that it is mapped just to be extra careful.
762
+ if (kPlatformUsesOPDSections) {
763
+ if (GetSectionHeaderByName(obj.fd, kOpdSectionName,
764
+ sizeof(kOpdSectionName) - 1, &opd) &&
765
+ FindObjFile(reinterpret_cast<const char *>(opd.sh_addr) + relocation,
766
+ opd.sh_size) != nullptr) {
767
+ opd_ptr = &opd;
768
+ } else {
769
+ return SYMBOL_NOT_FOUND;
770
+ }
771
+ }
772
+
773
+ // Consult a regular symbol table, then fall back to the dynamic symbol table.
774
+ for (const auto symbol_table_type : {SHT_SYMTAB, SHT_DYNSYM}) {
775
+ if (!GetSectionHeaderByType(obj.fd, obj.elf_header.e_shnum,
776
+ obj.elf_header.e_shoff, symbol_table_type,
777
+ &symtab, tmp_buf, tmp_buf_size)) {
778
+ continue;
779
+ }
780
+ if (!ReadFromOffsetExact(
781
+ obj.fd, &strtab, sizeof(strtab),
782
+ obj.elf_header.e_shoff + symtab.sh_link * sizeof(symtab))) {
783
+ continue;
784
+ }
785
+ const FindSymbolResult rc =
786
+ FindSymbol(pc, obj.fd, out, out_size, relocation, &strtab, &symtab,
787
+ opd_ptr, tmp_buf, tmp_buf_size);
788
+ if (rc != SYMBOL_NOT_FOUND) {
789
+ return rc;
790
+ }
791
+ }
792
+
793
+ return SYMBOL_NOT_FOUND;
794
+ }
795
+
796
+ namespace {
797
+ // Thin wrapper around a file descriptor so that the file descriptor
798
+ // gets closed for sure.
799
+ class FileDescriptor {
800
+ public:
801
+ explicit FileDescriptor(int fd) : fd_(fd) {}
802
+ FileDescriptor(const FileDescriptor &) = delete;
803
+ FileDescriptor &operator=(const FileDescriptor &) = delete;
804
+
805
+ ~FileDescriptor() {
806
+ if (fd_ >= 0) {
807
+ NO_INTR(close(fd_));
808
+ }
809
+ }
810
+
811
+ int get() const { return fd_; }
812
+
813
+ private:
814
+ const int fd_;
815
+ };
816
+
817
+ // Helper class for reading lines from file.
818
+ //
819
+ // Note: we don't use ProcMapsIterator since the object is big (it has
820
+ // a 5k array member) and uses async-unsafe functions such as sscanf()
821
+ // and snprintf().
822
+ class LineReader {
823
+ public:
824
+ explicit LineReader(int fd, char *buf, int buf_len)
825
+ : fd_(fd),
826
+ buf_len_(buf_len),
827
+ buf_(buf),
828
+ bol_(buf),
829
+ eol_(buf),
830
+ eod_(buf) {}
831
+
832
+ LineReader(const LineReader &) = delete;
833
+ LineReader &operator=(const LineReader &) = delete;
834
+
835
+ // Read '\n'-terminated line from file. On success, modify "bol"
836
+ // and "eol", then return true. Otherwise, return false.
837
+ //
838
+ // Note: if the last line doesn't end with '\n', the line will be
839
+ // dropped. It's an intentional behavior to make the code simple.
840
+ bool ReadLine(const char **bol, const char **eol) {
841
+ if (BufferIsEmpty()) { // First time.
842
+ const ssize_t num_bytes = ReadPersistent(fd_, buf_, buf_len_);
843
+ if (num_bytes <= 0) { // EOF or error.
844
+ return false;
845
+ }
846
+ eod_ = buf_ + num_bytes;
847
+ bol_ = buf_;
848
+ } else {
849
+ bol_ = eol_ + 1; // Advance to the next line in the buffer.
850
+ SAFE_ASSERT(bol_ <= eod_); // "bol_" can point to "eod_".
851
+ if (!HasCompleteLine()) {
852
+ const int incomplete_line_length = eod_ - bol_;
853
+ // Move the trailing incomplete line to the beginning.
854
+ memmove(buf_, bol_, incomplete_line_length);
855
+ // Read text from file and append it.
856
+ char *const append_pos = buf_ + incomplete_line_length;
857
+ const int capacity_left = buf_len_ - incomplete_line_length;
858
+ const ssize_t num_bytes =
859
+ ReadPersistent(fd_, append_pos, capacity_left);
860
+ if (num_bytes <= 0) { // EOF or error.
861
+ return false;
862
+ }
863
+ eod_ = append_pos + num_bytes;
864
+ bol_ = buf_;
865
+ }
866
+ }
867
+ eol_ = FindLineFeed();
868
+ if (eol_ == nullptr) { // '\n' not found. Malformed line.
869
+ return false;
870
+ }
871
+ *eol_ = '\0'; // Replace '\n' with '\0'.
872
+
873
+ *bol = bol_;
874
+ *eol = eol_;
875
+ return true;
876
+ }
877
+
878
+ private:
879
+ char *FindLineFeed() const {
880
+ return reinterpret_cast<char *>(memchr(bol_, '\n', eod_ - bol_));
881
+ }
882
+
883
+ bool BufferIsEmpty() const { return buf_ == eod_; }
884
+
885
+ bool HasCompleteLine() const {
886
+ return !BufferIsEmpty() && FindLineFeed() != nullptr;
887
+ }
888
+
889
+ const int fd_;
890
+ const int buf_len_;
891
+ char *const buf_;
892
+ char *bol_;
893
+ char *eol_;
894
+ const char *eod_; // End of data in "buf_".
895
+ };
896
+ } // namespace
897
+
898
+ // Place the hex number read from "start" into "*hex". The pointer to
899
+ // the first non-hex character or "end" is returned.
900
+ static const char *GetHex(const char *start, const char *end,
901
+ uint64_t *const value) {
902
+ uint64_t hex = 0;
903
+ const char *p;
904
+ for (p = start; p < end; ++p) {
905
+ int ch = *p;
906
+ if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') ||
907
+ (ch >= 'a' && ch <= 'f')) {
908
+ hex = (hex << 4) | (ch < 'A' ? ch - '0' : (ch & 0xF) + 9);
909
+ } else { // Encountered the first non-hex character.
910
+ break;
911
+ }
912
+ }
913
+ SAFE_ASSERT(p <= end);
914
+ *value = hex;
915
+ return p;
916
+ }
917
+
918
+ static const char *GetHex(const char *start, const char *end,
919
+ const void **const addr) {
920
+ uint64_t hex = 0;
921
+ const char *p = GetHex(start, end, &hex);
922
+ *addr = reinterpret_cast<void *>(hex);
923
+ return p;
924
+ }
925
+
926
+ // Normally we are only interested in "r?x" maps.
927
+ // On the PowerPC, function pointers point to descriptors in the .opd
928
+ // section. The descriptors themselves are not executable code, so
929
+ // we need to relax the check below to "r??".
930
+ static bool ShouldUseMapping(const char *const flags) {
931
+ return flags[0] == 'r' && (kPlatformUsesOPDSections || flags[2] == 'x');
932
+ }
933
+
934
+ // Read /proc/self/maps and run "callback" for each mmapped file found. If
935
+ // "callback" returns false, stop scanning and return true. Else continue
936
+ // scanning /proc/self/maps. Return true if no parse error is found.
937
+ static ABSL_ATTRIBUTE_NOINLINE bool ReadAddrMap(
938
+ bool (*callback)(const char *filename, const void *const start_addr,
939
+ const void *const end_addr, uint64_t offset, void *arg),
940
+ void *arg, void *tmp_buf, int tmp_buf_size) {
941
+ // Use /proc/self/task/<pid>/maps instead of /proc/self/maps. The latter
942
+ // requires kernel to stop all threads, and is significantly slower when there
943
+ // are 1000s of threads.
944
+ char maps_path[80];
945
+ snprintf(maps_path, sizeof(maps_path), "/proc/self/task/%d/maps", getpid());
946
+
947
+ int maps_fd;
948
+ NO_INTR(maps_fd = open(maps_path, O_RDONLY));
949
+ FileDescriptor wrapped_maps_fd(maps_fd);
950
+ if (wrapped_maps_fd.get() < 0) {
951
+ ABSL_RAW_LOG(WARNING, "%s: errno=%d", maps_path, errno);
952
+ return false;
953
+ }
954
+
955
+ // Iterate over maps and look for the map containing the pc. Then
956
+ // look into the symbol tables inside.
957
+ LineReader reader(wrapped_maps_fd.get(), static_cast<char *>(tmp_buf),
958
+ tmp_buf_size);
959
+ while (true) {
960
+ const char *cursor;
961
+ const char *eol;
962
+ if (!reader.ReadLine(&cursor, &eol)) { // EOF or malformed line.
963
+ break;
964
+ }
965
+
966
+ const char *line = cursor;
967
+ const void *start_address;
968
+ // Start parsing line in /proc/self/maps. Here is an example:
969
+ //
970
+ // 08048000-0804c000 r-xp 00000000 08:01 2142121 /bin/cat
971
+ //
972
+ // We want start address (08048000), end address (0804c000), flags
973
+ // (r-xp) and file name (/bin/cat).
974
+
975
+ // Read start address.
976
+ cursor = GetHex(cursor, eol, &start_address);
977
+ if (cursor == eol || *cursor != '-') {
978
+ ABSL_RAW_LOG(WARNING, "Corrupt /proc/self/maps line: %s", line);
979
+ return false;
980
+ }
981
+ ++cursor; // Skip '-'.
982
+
983
+ // Read end address.
984
+ const void *end_address;
985
+ cursor = GetHex(cursor, eol, &end_address);
986
+ if (cursor == eol || *cursor != ' ') {
987
+ ABSL_RAW_LOG(WARNING, "Corrupt /proc/self/maps line: %s", line);
988
+ return false;
989
+ }
990
+ ++cursor; // Skip ' '.
991
+
992
+ // Read flags. Skip flags until we encounter a space or eol.
993
+ const char *const flags_start = cursor;
994
+ while (cursor < eol && *cursor != ' ') {
995
+ ++cursor;
996
+ }
997
+ // We expect at least four letters for flags (ex. "r-xp").
998
+ if (cursor == eol || cursor < flags_start + 4) {
999
+ ABSL_RAW_LOG(WARNING, "Corrupt /proc/self/maps: %s", line);
1000
+ return false;
1001
+ }
1002
+
1003
+ // Check flags.
1004
+ if (!ShouldUseMapping(flags_start)) {
1005
+ continue; // We skip this map.
1006
+ }
1007
+ ++cursor; // Skip ' '.
1008
+
1009
+ // Read file offset.
1010
+ uint64_t offset;
1011
+ cursor = GetHex(cursor, eol, &offset);
1012
+ ++cursor; // Skip ' '.
1013
+
1014
+ // Skip to file name. "cursor" now points to dev. We need to skip at least
1015
+ // two spaces for dev and inode.
1016
+ int num_spaces = 0;
1017
+ while (cursor < eol) {
1018
+ if (*cursor == ' ') {
1019
+ ++num_spaces;
1020
+ } else if (num_spaces >= 2) {
1021
+ // The first non-space character after skipping two spaces
1022
+ // is the beginning of the file name.
1023
+ break;
1024
+ }
1025
+ ++cursor;
1026
+ }
1027
+
1028
+ // Check whether this entry corresponds to our hint table for the true
1029
+ // filename.
1030
+ bool hinted =
1031
+ GetFileMappingHint(&start_address, &end_address, &offset, &cursor);
1032
+ if (!hinted && (cursor == eol || cursor[0] == '[')) {
1033
+ // not an object file, typically [vdso] or [vsyscall]
1034
+ continue;
1035
+ }
1036
+ if (!callback(cursor, start_address, end_address, offset, arg)) break;
1037
+ }
1038
+ return true;
1039
+ }
1040
+
1041
+ // Find the objfile mapped in address region containing [addr, addr + len).
1042
+ ObjFile *Symbolizer::FindObjFile(const void *const addr, size_t len) {
1043
+ for (int i = 0; i < 2; ++i) {
1044
+ if (!ok_) return nullptr;
1045
+
1046
+ // Read /proc/self/maps if necessary
1047
+ if (!addr_map_read_) {
1048
+ addr_map_read_ = true;
1049
+ if (!ReadAddrMap(RegisterObjFile, this, tmp_buf_, TMP_BUF_SIZE)) {
1050
+ ok_ = false;
1051
+ return nullptr;
1052
+ }
1053
+ }
1054
+
1055
+ int lo = 0;
1056
+ int hi = addr_map_.Size();
1057
+ while (lo < hi) {
1058
+ int mid = (lo + hi) / 2;
1059
+ if (addr < addr_map_.At(mid)->end_addr) {
1060
+ hi = mid;
1061
+ } else {
1062
+ lo = mid + 1;
1063
+ }
1064
+ }
1065
+ if (lo != addr_map_.Size()) {
1066
+ ObjFile *obj = addr_map_.At(lo);
1067
+ SAFE_ASSERT(obj->end_addr > addr);
1068
+ if (addr >= obj->start_addr &&
1069
+ reinterpret_cast<const char *>(addr) + len <= obj->end_addr)
1070
+ return obj;
1071
+ }
1072
+
1073
+ // The address mapping may have changed since it was last read. Retry.
1074
+ ClearAddrMap();
1075
+ }
1076
+ return nullptr;
1077
+ }
1078
+
1079
+ void Symbolizer::ClearAddrMap() {
1080
+ for (int i = 0; i != addr_map_.Size(); i++) {
1081
+ ObjFile *o = addr_map_.At(i);
1082
+ base_internal::LowLevelAlloc::Free(o->filename);
1083
+ if (o->fd >= 0) {
1084
+ NO_INTR(close(o->fd));
1085
+ }
1086
+ }
1087
+ addr_map_.Clear();
1088
+ addr_map_read_ = false;
1089
+ }
1090
+
1091
+ // Callback for ReadAddrMap to register objfiles in an in-memory table.
1092
+ bool Symbolizer::RegisterObjFile(const char *filename,
1093
+ const void *const start_addr,
1094
+ const void *const end_addr, uint64_t offset,
1095
+ void *arg) {
1096
+ Symbolizer *impl = static_cast<Symbolizer *>(arg);
1097
+
1098
+ // Files are supposed to be added in the increasing address order. Make
1099
+ // sure that's the case.
1100
+ int addr_map_size = impl->addr_map_.Size();
1101
+ if (addr_map_size != 0) {
1102
+ ObjFile *old = impl->addr_map_.At(addr_map_size - 1);
1103
+ if (old->end_addr > end_addr) {
1104
+ ABSL_RAW_LOG(ERROR,
1105
+ "Unsorted addr map entry: 0x%" PRIxPTR ": %s <-> 0x%" PRIxPTR
1106
+ ": %s",
1107
+ reinterpret_cast<uintptr_t>(end_addr), filename,
1108
+ reinterpret_cast<uintptr_t>(old->end_addr), old->filename);
1109
+ return true;
1110
+ } else if (old->end_addr == end_addr) {
1111
+ // The same entry appears twice. This sometimes happens for [vdso].
1112
+ if (old->start_addr != start_addr ||
1113
+ strcmp(old->filename, filename) != 0) {
1114
+ ABSL_RAW_LOG(ERROR,
1115
+ "Duplicate addr 0x%" PRIxPTR ": %s <-> 0x%" PRIxPTR ": %s",
1116
+ reinterpret_cast<uintptr_t>(end_addr), filename,
1117
+ reinterpret_cast<uintptr_t>(old->end_addr), old->filename);
1118
+ }
1119
+ return true;
1120
+ }
1121
+ }
1122
+ ObjFile *obj = impl->addr_map_.Add();
1123
+ obj->filename = impl->CopyString(filename);
1124
+ obj->start_addr = start_addr;
1125
+ obj->end_addr = end_addr;
1126
+ obj->offset = offset;
1127
+ obj->elf_type = -1; // filled on demand
1128
+ obj->fd = -1; // opened on demand
1129
+ return true;
1130
+ }
1131
+
1132
+ // This function wraps the Demangle function to provide an interface
1133
+ // where the input symbol is demangled in-place.
1134
+ // To keep stack consumption low, we would like this function to not
1135
+ // get inlined.
1136
+ static ABSL_ATTRIBUTE_NOINLINE void DemangleInplace(char *out, int out_size,
1137
+ char *tmp_buf,
1138
+ int tmp_buf_size) {
1139
+ if (Demangle(out, tmp_buf, tmp_buf_size)) {
1140
+ // Demangling succeeded. Copy to out if the space allows.
1141
+ int len = strlen(tmp_buf);
1142
+ if (len + 1 <= out_size) { // +1 for '\0'.
1143
+ SAFE_ASSERT(len < tmp_buf_size);
1144
+ memmove(out, tmp_buf, len + 1);
1145
+ }
1146
+ }
1147
+ }
1148
+
1149
+ SymbolCacheLine *Symbolizer::GetCacheLine(const void *const pc) {
1150
+ uintptr_t pc0 = reinterpret_cast<uintptr_t>(pc);
1151
+ pc0 >>= 3; // drop the low 3 bits
1152
+
1153
+ // Shuffle bits.
1154
+ pc0 ^= (pc0 >> 6) ^ (pc0 >> 12) ^ (pc0 >> 18);
1155
+ return &symbol_cache_[pc0 % SYMBOL_CACHE_LINES];
1156
+ }
1157
+
1158
+ void Symbolizer::AgeSymbols(SymbolCacheLine *line) {
1159
+ for (uint32_t &age : line->age) {
1160
+ ++age;
1161
+ }
1162
+ }
1163
+
1164
+ const char *Symbolizer::FindSymbolInCache(const void *const pc) {
1165
+ if (pc == nullptr) return nullptr;
1166
+
1167
+ SymbolCacheLine *line = GetCacheLine(pc);
1168
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(line->pc); ++i) {
1169
+ if (line->pc[i] == pc) {
1170
+ AgeSymbols(line);
1171
+ line->age[i] = 0;
1172
+ return line->name[i];
1173
+ }
1174
+ }
1175
+ return nullptr;
1176
+ }
1177
+
1178
+ const char *Symbolizer::InsertSymbolInCache(const void *const pc,
1179
+ const char *name) {
1180
+ SAFE_ASSERT(pc != nullptr);
1181
+
1182
+ SymbolCacheLine *line = GetCacheLine(pc);
1183
+ uint32_t max_age = 0;
1184
+ int oldest_index = -1;
1185
+ for (size_t i = 0; i < ABSL_ARRAYSIZE(line->pc); ++i) {
1186
+ if (line->pc[i] == nullptr) {
1187
+ AgeSymbols(line);
1188
+ line->pc[i] = pc;
1189
+ line->name[i] = CopyString(name);
1190
+ line->age[i] = 0;
1191
+ return line->name[i];
1192
+ }
1193
+ if (line->age[i] >= max_age) {
1194
+ max_age = line->age[i];
1195
+ oldest_index = i;
1196
+ }
1197
+ }
1198
+
1199
+ AgeSymbols(line);
1200
+ ABSL_RAW_CHECK(oldest_index >= 0, "Corrupt cache");
1201
+ base_internal::LowLevelAlloc::Free(line->name[oldest_index]);
1202
+ line->pc[oldest_index] = pc;
1203
+ line->name[oldest_index] = CopyString(name);
1204
+ line->age[oldest_index] = 0;
1205
+ return line->name[oldest_index];
1206
+ }
1207
+
1208
+ static void MaybeOpenFdFromSelfExe(ObjFile *obj) {
1209
+ if (memcmp(obj->start_addr, ELFMAG, SELFMAG) != 0) {
1210
+ return;
1211
+ }
1212
+ int fd = open("/proc/self/exe", O_RDONLY);
1213
+ if (fd == -1) {
1214
+ return;
1215
+ }
1216
+ // Verify that contents of /proc/self/exe matches in-memory image of
1217
+ // the binary. This can fail if the "deleted" binary is in fact not
1218
+ // the main executable, or for binaries that have the first PT_LOAD
1219
+ // segment smaller than 4K. We do it in four steps so that the
1220
+ // buffer is smaller and we don't consume too much stack space.
1221
+ const char *mem = reinterpret_cast<const char *>(obj->start_addr);
1222
+ for (int i = 0; i < 4; ++i) {
1223
+ char buf[1024];
1224
+ ssize_t n = read(fd, buf, sizeof(buf));
1225
+ if (n != sizeof(buf) || memcmp(buf, mem, sizeof(buf)) != 0) {
1226
+ close(fd);
1227
+ return;
1228
+ }
1229
+ mem += sizeof(buf);
1230
+ }
1231
+ obj->fd = fd;
1232
+ }
1233
+
1234
+ static bool MaybeInitializeObjFile(ObjFile *obj) {
1235
+ if (obj->fd < 0) {
1236
+ obj->fd = open(obj->filename, O_RDONLY);
1237
+
1238
+ if (obj->fd < 0) {
1239
+ // Getting /proc/self/exe here means that we were hinted.
1240
+ if (strcmp(obj->filename, "/proc/self/exe") == 0) {
1241
+ // /proc/self/exe may be inaccessible (due to setuid, etc.), so try
1242
+ // accessing the binary via argv0.
1243
+ if (argv0_value != nullptr) {
1244
+ obj->fd = open(argv0_value, O_RDONLY);
1245
+ }
1246
+ } else {
1247
+ MaybeOpenFdFromSelfExe(obj);
1248
+ }
1249
+ }
1250
+
1251
+ if (obj->fd < 0) {
1252
+ ABSL_RAW_LOG(WARNING, "%s: open failed: errno=%d", obj->filename, errno);
1253
+ return false;
1254
+ }
1255
+ obj->elf_type = FileGetElfType(obj->fd);
1256
+ if (obj->elf_type < 0) {
1257
+ ABSL_RAW_LOG(WARNING, "%s: wrong elf type: %d", obj->filename,
1258
+ obj->elf_type);
1259
+ return false;
1260
+ }
1261
+
1262
+ if (!ReadFromOffsetExact(obj->fd, &obj->elf_header, sizeof(obj->elf_header),
1263
+ 0)) {
1264
+ ABSL_RAW_LOG(WARNING, "%s: failed to read elf header", obj->filename);
1265
+ return false;
1266
+ }
1267
+ }
1268
+ return true;
1269
+ }
1270
+
1271
+ // The implementation of our symbolization routine. If it
1272
+ // successfully finds the symbol containing "pc" and obtains the
1273
+ // symbol name, returns pointer to that symbol. Otherwise, returns nullptr.
1274
+ // If any symbol decorators have been installed via InstallSymbolDecorator(),
1275
+ // they are called here as well.
1276
+ // To keep stack consumption low, we would like this function to not
1277
+ // get inlined.
1278
+ const char *Symbolizer::GetSymbol(const void *const pc) {
1279
+ const char *entry = FindSymbolInCache(pc);
1280
+ if (entry != nullptr) {
1281
+ return entry;
1282
+ }
1283
+ symbol_buf_[0] = '\0';
1284
+
1285
+ ObjFile *const obj = FindObjFile(pc, 1);
1286
+ ptrdiff_t relocation = 0;
1287
+ int fd = -1;
1288
+ if (obj != nullptr) {
1289
+ if (MaybeInitializeObjFile(obj)) {
1290
+ if (obj->elf_type == ET_DYN &&
1291
+ reinterpret_cast<uint64_t>(obj->start_addr) >= obj->offset) {
1292
+ // This object was relocated.
1293
+ //
1294
+ // For obj->offset > 0, adjust the relocation since a mapping at offset
1295
+ // X in the file will have a start address of [true relocation]+X.
1296
+ relocation = reinterpret_cast<ptrdiff_t>(obj->start_addr) - obj->offset;
1297
+ }
1298
+
1299
+ fd = obj->fd;
1300
+ }
1301
+ if (GetSymbolFromObjectFile(*obj, pc, relocation, symbol_buf_,
1302
+ sizeof(symbol_buf_), tmp_buf_,
1303
+ sizeof(tmp_buf_)) == SYMBOL_FOUND) {
1304
+ // Only try to demangle the symbol name if it fit into symbol_buf_.
1305
+ DemangleInplace(symbol_buf_, sizeof(symbol_buf_), tmp_buf_,
1306
+ sizeof(tmp_buf_));
1307
+ }
1308
+ } else {
1309
+ #if ABSL_HAVE_VDSO_SUPPORT
1310
+ VDSOSupport vdso;
1311
+ if (vdso.IsPresent()) {
1312
+ VDSOSupport::SymbolInfo symbol_info;
1313
+ if (vdso.LookupSymbolByAddress(pc, &symbol_info)) {
1314
+ // All VDSO symbols are known to be short.
1315
+ size_t len = strlen(symbol_info.name);
1316
+ ABSL_RAW_CHECK(len + 1 < sizeof(symbol_buf_),
1317
+ "VDSO symbol unexpectedly long");
1318
+ memcpy(symbol_buf_, symbol_info.name, len + 1);
1319
+ }
1320
+ }
1321
+ #endif
1322
+ }
1323
+
1324
+ if (g_decorators_mu.TryLock()) {
1325
+ if (g_num_decorators > 0) {
1326
+ SymbolDecoratorArgs decorator_args = {
1327
+ pc, relocation, fd, symbol_buf_, sizeof(symbol_buf_),
1328
+ tmp_buf_, sizeof(tmp_buf_), nullptr};
1329
+ for (int i = 0; i < g_num_decorators; ++i) {
1330
+ decorator_args.arg = g_decorators[i].arg;
1331
+ g_decorators[i].fn(&decorator_args);
1332
+ }
1333
+ }
1334
+ g_decorators_mu.Unlock();
1335
+ }
1336
+ if (symbol_buf_[0] == '\0') {
1337
+ return nullptr;
1338
+ }
1339
+ symbol_buf_[sizeof(symbol_buf_) - 1] = '\0'; // Paranoia.
1340
+ return InsertSymbolInCache(pc, symbol_buf_);
1341
+ }
1342
+
1343
+ bool RemoveAllSymbolDecorators(void) {
1344
+ if (!g_decorators_mu.TryLock()) {
1345
+ // Someone else is using decorators. Get out.
1346
+ return false;
1347
+ }
1348
+ g_num_decorators = 0;
1349
+ g_decorators_mu.Unlock();
1350
+ return true;
1351
+ }
1352
+
1353
+ bool RemoveSymbolDecorator(int ticket) {
1354
+ if (!g_decorators_mu.TryLock()) {
1355
+ // Someone else is using decorators. Get out.
1356
+ return false;
1357
+ }
1358
+ for (int i = 0; i < g_num_decorators; ++i) {
1359
+ if (g_decorators[i].ticket == ticket) {
1360
+ while (i < g_num_decorators - 1) {
1361
+ g_decorators[i] = g_decorators[i + 1];
1362
+ ++i;
1363
+ }
1364
+ g_num_decorators = i;
1365
+ break;
1366
+ }
1367
+ }
1368
+ g_decorators_mu.Unlock();
1369
+ return true; // Decorator is known to be removed.
1370
+ }
1371
+
1372
+ int InstallSymbolDecorator(SymbolDecorator decorator, void *arg) {
1373
+ static int ticket = 0;
1374
+
1375
+ if (!g_decorators_mu.TryLock()) {
1376
+ // Someone else is using decorators. Get out.
1377
+ return false;
1378
+ }
1379
+ int ret = ticket;
1380
+ if (g_num_decorators >= kMaxDecorators) {
1381
+ ret = -1;
1382
+ } else {
1383
+ g_decorators[g_num_decorators] = {decorator, arg, ticket++};
1384
+ ++g_num_decorators;
1385
+ }
1386
+ g_decorators_mu.Unlock();
1387
+ return ret;
1388
+ }
1389
+
1390
+ bool RegisterFileMappingHint(const void *start, const void *end, uint64_t offset,
1391
+ const char *filename) {
1392
+ SAFE_ASSERT(start <= end);
1393
+ SAFE_ASSERT(filename != nullptr);
1394
+
1395
+ InitSigSafeArena();
1396
+
1397
+ if (!g_file_mapping_mu.TryLock()) {
1398
+ return false;
1399
+ }
1400
+
1401
+ bool ret = true;
1402
+ if (g_num_file_mapping_hints >= kMaxFileMappingHints) {
1403
+ ret = false;
1404
+ } else {
1405
+ // TODO(ckennelly): Move this into a std::string copy routine.
1406
+ int len = strlen(filename);
1407
+ char *dst = static_cast<char *>(
1408
+ base_internal::LowLevelAlloc::AllocWithArena(len + 1, SigSafeArena()));
1409
+ ABSL_RAW_CHECK(dst != nullptr, "out of memory");
1410
+ memcpy(dst, filename, len + 1);
1411
+
1412
+ auto &hint = g_file_mapping_hints[g_num_file_mapping_hints++];
1413
+ hint.start = start;
1414
+ hint.end = end;
1415
+ hint.offset = offset;
1416
+ hint.filename = dst;
1417
+ }
1418
+
1419
+ g_file_mapping_mu.Unlock();
1420
+ return ret;
1421
+ }
1422
+
1423
+ bool GetFileMappingHint(const void **start, const void **end, uint64_t *offset,
1424
+ const char **filename) {
1425
+ if (!g_file_mapping_mu.TryLock()) {
1426
+ return false;
1427
+ }
1428
+ bool found = false;
1429
+ for (int i = 0; i < g_num_file_mapping_hints; i++) {
1430
+ if (g_file_mapping_hints[i].start <= *start &&
1431
+ *end <= g_file_mapping_hints[i].end) {
1432
+ // We assume that the start_address for the mapping is the base
1433
+ // address of the ELF section, but when [start_address,end_address) is
1434
+ // not strictly equal to [hint.start, hint.end), that assumption is
1435
+ // invalid.
1436
+ //
1437
+ // This uses the hint's start address (even though hint.start is not
1438
+ // necessarily equal to start_address) to ensure the correct
1439
+ // relocation is computed later.
1440
+ *start = g_file_mapping_hints[i].start;
1441
+ *end = g_file_mapping_hints[i].end;
1442
+ *offset = g_file_mapping_hints[i].offset;
1443
+ *filename = g_file_mapping_hints[i].filename;
1444
+ found = true;
1445
+ break;
1446
+ }
1447
+ }
1448
+ g_file_mapping_mu.Unlock();
1449
+ return found;
1450
+ }
1451
+
1452
+ } // namespace debugging_internal
1453
+
1454
+ bool Symbolize(const void *pc, char *out, int out_size) {
1455
+ // Symbolization is very slow under tsan.
1456
+ ANNOTATE_IGNORE_READS_AND_WRITES_BEGIN();
1457
+ SAFE_ASSERT(out_size >= 0);
1458
+ debugging_internal::Symbolizer *s = debugging_internal::AllocateSymbolizer();
1459
+ const char *name = s->GetSymbol(pc);
1460
+ bool ok = false;
1461
+ if (name != nullptr && out_size > 0) {
1462
+ strncpy(out, name, out_size);
1463
+ ok = true;
1464
+ if (out[out_size - 1] != '\0') {
1465
+ // strncpy() does not '\0' terminate when it truncates. Do so, with
1466
+ // trailing ellipsis.
1467
+ static constexpr char kEllipsis[] = "...";
1468
+ int ellipsis_size =
1469
+ std::min(implicit_cast<int>(strlen(kEllipsis)), out_size - 1);
1470
+ memcpy(out + out_size - ellipsis_size - 1, kEllipsis, ellipsis_size);
1471
+ out[out_size - 1] = '\0';
1472
+ }
1473
+ }
1474
+ debugging_internal::FreeSymbolizer(s);
1475
+ ANNOTATE_IGNORE_READS_AND_WRITES_END();
1476
+ return ok;
1477
+ }
1478
+
1479
+ ABSL_NAMESPACE_END
1480
+ } // namespace absl