Merge github.com:grpc/grpc into write_buffering

pull/9252/head
Craig Tiller 8 years ago
commit 32e05e4a9e
  1. 2
      BUILD
  2. 6
      CMakeLists.txt
  3. 8
      Makefile
  4. 2
      build.yaml
  5. 3
      gRPC-Core.podspec
  6. 2
      grpc.gemspec
  7. 2
      include/grpc++/support/channel_arguments.h
  8. 41
      include/grpc/impl/codegen/exec_ctx_fwd.h
  9. 6
      include/grpc/impl/codegen/grpc_types.h
  10. 4
      include/grpc/impl/codegen/slice.h
  11. 2
      package.xml
  12. 3
      src/core/ext/census/grpc_plugin.c
  13. 28
      src/core/ext/client_channel/client_channel.c
  14. 6
      src/core/ext/client_channel/client_channel_factory.c
  15. 11
      src/core/ext/client_channel/client_channel_plugin.c
  16. 19
      src/core/ext/client_channel/http_connect_handshaker.c
  17. 10
      src/core/ext/client_channel/lb_policy_factory.c
  18. 5
      src/core/ext/client_channel/lb_policy_factory.h
  19. 11
      src/core/ext/client_channel/subchannel.c
  20. 2
      src/core/ext/client_channel/subchannel_index.c
  21. 44
      src/core/ext/client_channel/uri_parser.c
  22. 35
      src/core/ext/lb_policy/grpclb/grpclb.c
  23. 2
      src/core/ext/lb_policy/round_robin/round_robin.c
  24. 3
      src/core/ext/load_reporting/load_reporting.c
  25. 12
      src/core/ext/load_reporting/load_reporting_filter.c
  26. 8
      src/core/ext/resolver/dns/native/dns_resolver.c
  27. 16
      src/core/ext/resolver/sockaddr/sockaddr_resolver.c
  28. 5
      src/core/ext/transport/chttp2/client/chttp2_connector.c
  29. 4
      src/core/ext/transport/chttp2/client/insecure/channel_create.c
  30. 2
      src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c
  31. 14
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
  32. 11
      src/core/ext/transport/chttp2/server/chttp2_server.c
  33. 2
      src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c
  34. 6
      src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c
  35. 15
      src/core/ext/transport/chttp2/transport/bin_decoder.c
  36. 5
      src/core/ext/transport/chttp2/transport/bin_decoder.h
  37. 2
      src/core/ext/transport/chttp2/transport/bin_encoder.h
  38. 42
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  39. 57
      src/core/ext/transport/chttp2/transport/hpack_encoder.c
  40. 6
      src/core/ext/transport/chttp2/transport/hpack_encoder.h
  41. 64
      src/core/ext/transport/chttp2/transport/hpack_parser.c
  42. 6
      src/core/ext/transport/chttp2/transport/hpack_parser.h
  43. 35
      src/core/ext/transport/chttp2/transport/hpack_table.c
  44. 13
      src/core/ext/transport/chttp2/transport/hpack_table.h
  45. 4
      src/core/ext/transport/chttp2/transport/incoming_metadata.c
  46. 2
      src/core/ext/transport/chttp2/transport/incoming_metadata.h
  47. 10
      src/core/ext/transport/chttp2/transport/parsing.c
  48. 11
      src/core/ext/transport/chttp2/transport/writing.c
  49. 9
      src/core/ext/transport/cronet/transport/cronet_transport.c
  50. 10
      src/core/lib/channel/channel_args.c
  51. 5
      src/core/lib/channel/channel_args.h
  52. 4
      src/core/lib/channel/channel_stack.c
  53. 12
      src/core/lib/channel/channel_stack_builder.c
  54. 6
      src/core/lib/channel/channel_stack_builder.h
  55. 22
      src/core/lib/channel/compress_filter.c
  56. 3
      src/core/lib/channel/connected_channel.c
  57. 3
      src/core/lib/channel/connected_channel.h
  58. 3
      src/core/lib/channel/deadline_filter.c
  59. 49
      src/core/lib/channel/http_client_filter.c
  60. 39
      src/core/lib/channel/http_server_filter.c
  61. 14
      src/core/lib/channel/message_size_filter.c
  62. 46
      src/core/lib/compression/message_compress.c
  63. 6
      src/core/lib/compression/message_compress.h
  64. 13
      src/core/lib/http/httpcli.c
  65. 19
      src/core/lib/http/httpcli_security_connector.c
  66. 6
      src/core/lib/iomgr/closure.h
  67. 1
      src/core/lib/iomgr/ev_epoll_linux.c
  68. 7
      src/core/lib/iomgr/executor.c
  69. 2
      src/core/lib/iomgr/executor.h
  70. 12
      src/core/lib/iomgr/iomgr.c
  71. 6
      src/core/lib/iomgr/iomgr.h
  72. 45
      src/core/lib/iomgr/resource_quota.c
  73. 4
      src/core/lib/iomgr/resource_quota.h
  74. 2
      src/core/lib/iomgr/socket_mutator.c
  75. 10
      src/core/lib/iomgr/tcp_client_posix.c
  76. 6
      src/core/lib/iomgr/tcp_client_uv.c
  77. 8
      src/core/lib/iomgr/tcp_client_windows.c
  78. 24
      src/core/lib/iomgr/tcp_posix.c
  79. 10
      src/core/lib/iomgr/tcp_server_posix.c
  80. 8
      src/core/lib/iomgr/tcp_server_uv.c
  81. 8
      src/core/lib/iomgr/tcp_server_windows.c
  82. 2
      src/core/lib/iomgr/tcp_uv.c
  83. 7
      src/core/lib/iomgr/tcp_windows.c
  84. 10
      src/core/lib/security/context/security_context.c
  85. 31
      src/core/lib/security/credentials/composite/composite_credentials.c
  86. 55
      src/core/lib/security/credentials/credentials.c
  87. 39
      src/core/lib/security/credentials/credentials.h
  88. 13
      src/core/lib/security/credentials/credentials_metadata.c
  89. 17
      src/core/lib/security/credentials/fake/fake_credentials.c
  90. 40
      src/core/lib/security/credentials/google_default/google_default_credentials.c
  91. 5
      src/core/lib/security/credentials/iam/iam_credentials.c
  92. 28
      src/core/lib/security/credentials/jwt/jwt_credentials.c
  93. 3
      src/core/lib/security/credentials/jwt/jwt_credentials.h
  94. 106
      src/core/lib/security/credentials/jwt/jwt_verifier.c
  95. 8
      src/core/lib/security/credentials/jwt/jwt_verifier.h
  96. 34
      src/core/lib/security/credentials/oauth2/oauth2_credentials.c
  97. 2
      src/core/lib/security/credentials/oauth2/oauth2_credentials.h
  98. 12
      src/core/lib/security/credentials/plugin/plugin_credentials.c
  99. 20
      src/core/lib/security/credentials/ssl/ssl_credentials.c
  100. 21
      src/core/lib/security/transport/client_auth_filter.c
  101. Some files were not shown because too many files have changed in this diff Show More

@ -602,6 +602,7 @@ grpc_cc_library(
"src/core/lib/json/json_reader.h", "src/core/lib/json/json_reader.h",
"src/core/lib/json/json_writer.h", "src/core/lib/json/json_writer.h",
"src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/percent_encoding.h",
"src/core/lib/slice/slice_internal.h",
"src/core/lib/slice/slice_string_helpers.h", "src/core/lib/slice/slice_string_helpers.h",
"src/core/lib/surface/api_trace.h", "src/core/lib/surface/api_trace.h",
"src/core/lib/surface/call.h", "src/core/lib/surface/call.h",
@ -699,6 +700,7 @@ grpc_cc_library(
"include/grpc/impl/codegen/byte_buffer_reader.h", "include/grpc/impl/codegen/byte_buffer_reader.h",
"include/grpc/impl/codegen/compression_types.h", "include/grpc/impl/codegen/compression_types.h",
"include/grpc/impl/codegen/connectivity_state.h", "include/grpc/impl/codegen/connectivity_state.h",
"include/grpc/impl/codegen/exec_ctx_fwd.h",
"include/grpc/impl/codegen/grpc_types.h", "include/grpc/impl/codegen/grpc_types.h",
"include/grpc/impl/codegen/propagation_bits.h", "include/grpc/impl/codegen/propagation_bits.h",
"include/grpc/impl/codegen/status.h", "include/grpc/impl/codegen/status.h",

@ -530,6 +530,7 @@ foreach(_hdr
include/grpc/impl/codegen/byte_buffer_reader.h include/grpc/impl/codegen/byte_buffer_reader.h
include/grpc/impl/codegen/compression_types.h include/grpc/impl/codegen/compression_types.h
include/grpc/impl/codegen/connectivity_state.h include/grpc/impl/codegen/connectivity_state.h
include/grpc/impl/codegen/exec_ctx_fwd.h
include/grpc/impl/codegen/grpc_types.h include/grpc/impl/codegen/grpc_types.h
include/grpc/impl/codegen/propagation_bits.h include/grpc/impl/codegen/propagation_bits.h
include/grpc/impl/codegen/status.h include/grpc/impl/codegen/status.h
@ -781,6 +782,7 @@ foreach(_hdr
include/grpc/impl/codegen/byte_buffer_reader.h include/grpc/impl/codegen/byte_buffer_reader.h
include/grpc/impl/codegen/compression_types.h include/grpc/impl/codegen/compression_types.h
include/grpc/impl/codegen/connectivity_state.h include/grpc/impl/codegen/connectivity_state.h
include/grpc/impl/codegen/exec_ctx_fwd.h
include/grpc/impl/codegen/grpc_types.h include/grpc/impl/codegen/grpc_types.h
include/grpc/impl/codegen/propagation_bits.h include/grpc/impl/codegen/propagation_bits.h
include/grpc/impl/codegen/status.h include/grpc/impl/codegen/status.h
@ -1032,6 +1034,7 @@ foreach(_hdr
include/grpc/impl/codegen/byte_buffer_reader.h include/grpc/impl/codegen/byte_buffer_reader.h
include/grpc/impl/codegen/compression_types.h include/grpc/impl/codegen/compression_types.h
include/grpc/impl/codegen/connectivity_state.h include/grpc/impl/codegen/connectivity_state.h
include/grpc/impl/codegen/exec_ctx_fwd.h
include/grpc/impl/codegen/grpc_types.h include/grpc/impl/codegen/grpc_types.h
include/grpc/impl/codegen/propagation_bits.h include/grpc/impl/codegen/propagation_bits.h
include/grpc/impl/codegen/status.h include/grpc/impl/codegen/status.h
@ -1195,6 +1198,7 @@ foreach(_hdr
include/grpc/impl/codegen/byte_buffer_reader.h include/grpc/impl/codegen/byte_buffer_reader.h
include/grpc/impl/codegen/compression_types.h include/grpc/impl/codegen/compression_types.h
include/grpc/impl/codegen/connectivity_state.h include/grpc/impl/codegen/connectivity_state.h
include/grpc/impl/codegen/exec_ctx_fwd.h
include/grpc/impl/codegen/grpc_types.h include/grpc/impl/codegen/grpc_types.h
include/grpc/impl/codegen/propagation_bits.h include/grpc/impl/codegen/propagation_bits.h
include/grpc/impl/codegen/status.h include/grpc/impl/codegen/status.h
@ -1528,6 +1532,7 @@ foreach(_hdr
include/grpc/impl/codegen/byte_buffer_reader.h include/grpc/impl/codegen/byte_buffer_reader.h
include/grpc/impl/codegen/compression_types.h include/grpc/impl/codegen/compression_types.h
include/grpc/impl/codegen/connectivity_state.h include/grpc/impl/codegen/connectivity_state.h
include/grpc/impl/codegen/exec_ctx_fwd.h
include/grpc/impl/codegen/grpc_types.h include/grpc/impl/codegen/grpc_types.h
include/grpc/impl/codegen/propagation_bits.h include/grpc/impl/codegen/propagation_bits.h
include/grpc/impl/codegen/status.h include/grpc/impl/codegen/status.h
@ -1734,6 +1739,7 @@ foreach(_hdr
include/grpc/impl/codegen/byte_buffer_reader.h include/grpc/impl/codegen/byte_buffer_reader.h
include/grpc/impl/codegen/compression_types.h include/grpc/impl/codegen/compression_types.h
include/grpc/impl/codegen/connectivity_state.h include/grpc/impl/codegen/connectivity_state.h
include/grpc/impl/codegen/exec_ctx_fwd.h
include/grpc/impl/codegen/grpc_types.h include/grpc/impl/codegen/grpc_types.h
include/grpc/impl/codegen/propagation_bits.h include/grpc/impl/codegen/propagation_bits.h
include/grpc/impl/codegen/status.h include/grpc/impl/codegen/status.h

@ -2852,6 +2852,7 @@ PUBLIC_HEADERS_C += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -3122,6 +3123,7 @@ PUBLIC_HEADERS_C += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -3338,6 +3340,7 @@ PUBLIC_HEADERS_C += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -3628,6 +3631,7 @@ PUBLIC_HEADERS_C += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -3872,6 +3876,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -4234,6 +4239,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -4589,6 +4595,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \
@ -4767,6 +4774,7 @@ PUBLIC_HEADERS_CXX += \
include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/byte_buffer_reader.h \
include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/compression_types.h \
include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/connectivity_state.h \
include/grpc/impl/codegen/exec_ctx_fwd.h \
include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/grpc_types.h \
include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/propagation_bits.h \
include/grpc/impl/codegen/status.h \ include/grpc/impl/codegen/status.h \

@ -237,6 +237,7 @@ filegroups:
- src/core/lib/json/json_reader.h - src/core/lib/json/json_reader.h
- src/core/lib/json/json_writer.h - src/core/lib/json/json_writer.h
- src/core/lib/slice/percent_encoding.h - src/core/lib/slice/percent_encoding.h
- src/core/lib/slice/slice_internal.h
- src/core/lib/slice/slice_string_helpers.h - src/core/lib/slice/slice_string_helpers.h
- src/core/lib/surface/api_trace.h - src/core/lib/surface/api_trace.h
- src/core/lib/surface/call.h - src/core/lib/surface/call.h
@ -421,6 +422,7 @@ filegroups:
- include/grpc/impl/codegen/byte_buffer_reader.h - include/grpc/impl/codegen/byte_buffer_reader.h
- include/grpc/impl/codegen/compression_types.h - include/grpc/impl/codegen/compression_types.h
- include/grpc/impl/codegen/connectivity_state.h - include/grpc/impl/codegen/connectivity_state.h
- include/grpc/impl/codegen/exec_ctx_fwd.h
- include/grpc/impl/codegen/grpc_types.h - include/grpc/impl/codegen/grpc_types.h
- include/grpc/impl/codegen/propagation_bits.h - include/grpc/impl/codegen/propagation_bits.h
- include/grpc/impl/codegen/status.h - include/grpc/impl/codegen/status.h

@ -167,6 +167,7 @@ Pod::Spec.new do |s|
'include/grpc/impl/codegen/byte_buffer_reader.h', 'include/grpc/impl/codegen/byte_buffer_reader.h',
'include/grpc/impl/codegen/compression_types.h', 'include/grpc/impl/codegen/compression_types.h',
'include/grpc/impl/codegen/connectivity_state.h', 'include/grpc/impl/codegen/connectivity_state.h',
'include/grpc/impl/codegen/exec_ctx_fwd.h',
'include/grpc/impl/codegen/grpc_types.h', 'include/grpc/impl/codegen/grpc_types.h',
'include/grpc/impl/codegen/propagation_bits.h', 'include/grpc/impl/codegen/propagation_bits.h',
'include/grpc/impl/codegen/status.h', 'include/grpc/impl/codegen/status.h',
@ -321,6 +322,7 @@ Pod::Spec.new do |s|
'src/core/lib/json/json_reader.h', 'src/core/lib/json/json_reader.h',
'src/core/lib/json/json_writer.h', 'src/core/lib/json/json_writer.h',
'src/core/lib/slice/percent_encoding.h', 'src/core/lib/slice/percent_encoding.h',
'src/core/lib/slice/slice_internal.h',
'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/slice/slice_string_helpers.h',
'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/call.h', 'src/core/lib/surface/call.h',
@ -728,6 +730,7 @@ Pod::Spec.new do |s|
'src/core/lib/json/json_reader.h', 'src/core/lib/json/json_reader.h',
'src/core/lib/json/json_writer.h', 'src/core/lib/json/json_writer.h',
'src/core/lib/slice/percent_encoding.h', 'src/core/lib/slice/percent_encoding.h',
'src/core/lib/slice/slice_internal.h',
'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/slice/slice_string_helpers.h',
'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/api_trace.h',
'src/core/lib/surface/call.h', 'src/core/lib/surface/call.h',

@ -148,6 +148,7 @@ Gem::Specification.new do |s|
s.files += %w( include/grpc/impl/codegen/byte_buffer_reader.h ) s.files += %w( include/grpc/impl/codegen/byte_buffer_reader.h )
s.files += %w( include/grpc/impl/codegen/compression_types.h ) s.files += %w( include/grpc/impl/codegen/compression_types.h )
s.files += %w( include/grpc/impl/codegen/connectivity_state.h ) s.files += %w( include/grpc/impl/codegen/connectivity_state.h )
s.files += %w( include/grpc/impl/codegen/exec_ctx_fwd.h )
s.files += %w( include/grpc/impl/codegen/grpc_types.h ) s.files += %w( include/grpc/impl/codegen/grpc_types.h )
s.files += %w( include/grpc/impl/codegen/propagation_bits.h ) s.files += %w( include/grpc/impl/codegen/propagation_bits.h )
s.files += %w( include/grpc/impl/codegen/status.h ) s.files += %w( include/grpc/impl/codegen/status.h )
@ -238,6 +239,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/json/json_reader.h ) s.files += %w( src/core/lib/json/json_reader.h )
s.files += %w( src/core/lib/json/json_writer.h ) s.files += %w( src/core/lib/json/json_writer.h )
s.files += %w( src/core/lib/slice/percent_encoding.h ) s.files += %w( src/core/lib/slice/percent_encoding.h )
s.files += %w( src/core/lib/slice/slice_internal.h )
s.files += %w( src/core/lib/slice/slice_string_helpers.h ) s.files += %w( src/core/lib/slice/slice_string_helpers.h )
s.files += %w( src/core/lib/surface/api_trace.h ) s.files += %w( src/core/lib/surface/api_trace.h )
s.files += %w( src/core/lib/surface/call.h ) s.files += %w( src/core/lib/surface/call.h )

@ -127,7 +127,7 @@ class ChannelArguments {
/// Default pointer argument operations. /// Default pointer argument operations.
struct PointerVtableMembers { struct PointerVtableMembers {
static void* Copy(void* in) { return in; } static void* Copy(void* in) { return in; }
static void Destroy(void* in) {} static void Destroy(grpc_exec_ctx* exec_ctx, void* in) {}
static int Compare(void* a, void* b) { static int Compare(void* a, void* b) {
if (a < b) return -1; if (a < b) return -1;
if (a > b) return 1; if (a > b) return 1;

@ -0,0 +1,41 @@
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H
#define GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H
/* forward declaration for exec_ctx.h */
struct grpc_exec_ctx;
typedef struct grpc_exec_ctx grpc_exec_ctx;
#endif /* GRPC_IMPL_CODEGEN_EXEC_CTX_FWD_H */

@ -34,10 +34,10 @@
#ifndef GRPC_IMPL_CODEGEN_GRPC_TYPES_H #ifndef GRPC_IMPL_CODEGEN_GRPC_TYPES_H
#define GRPC_IMPL_CODEGEN_GRPC_TYPES_H #define GRPC_IMPL_CODEGEN_GRPC_TYPES_H
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/exec_ctx_fwd.h>
#include <grpc/impl/codegen/gpr_types.h> #include <grpc/impl/codegen/gpr_types.h>
#include <grpc/impl/codegen/slice.h> #include <grpc/impl/codegen/slice.h>
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/status.h> #include <grpc/impl/codegen/status.h>
#include <stddef.h> #include <stddef.h>
@ -96,7 +96,7 @@ typedef enum {
typedef struct grpc_arg_pointer_vtable { typedef struct grpc_arg_pointer_vtable {
void *(*copy)(void *p); void *(*copy)(void *p);
void (*destroy)(void *p); void (*destroy)(grpc_exec_ctx *exec_ctx, void *p);
int (*cmp)(void *p, void *q); int (*cmp)(void *p, void *q);
} grpc_arg_pointer_vtable; } grpc_arg_pointer_vtable;

@ -37,6 +37,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <grpc/impl/codegen/exec_ctx_fwd.h>
/* Slice API /* Slice API
A slice represents a contiguous reference counted array of bytes. A slice represents a contiguous reference counted array of bytes.
@ -57,7 +59,7 @@
grpc_slice_new, or grpc_slice_new_with_len instead. */ grpc_slice_new, or grpc_slice_new_with_len instead. */
typedef struct grpc_slice_refcount { typedef struct grpc_slice_refcount {
void (*ref)(void *); void (*ref)(void *);
void (*unref)(void *); void (*unref)(grpc_exec_ctx *exec_ctx, void *);
} grpc_slice_refcount; } grpc_slice_refcount;
#define GRPC_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1) #define GRPC_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1)

@ -156,6 +156,7 @@
<file baseinstalldir="/" name="include/grpc/impl/codegen/byte_buffer_reader.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/byte_buffer_reader.h" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/compression_types.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/compression_types.h" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/connectivity_state.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/connectivity_state.h" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/exec_ctx_fwd.h" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/grpc_types.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/grpc_types.h" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/propagation_bits.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/propagation_bits.h" role="src" />
<file baseinstalldir="/" name="include/grpc/impl/codegen/status.h" role="src" /> <file baseinstalldir="/" name="include/grpc/impl/codegen/status.h" role="src" />
@ -246,6 +247,7 @@
<file baseinstalldir="/" name="src/core/lib/json/json_reader.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/json/json_reader.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/json/json_writer.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/json/json_writer.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/slice/percent_encoding.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/slice/percent_encoding.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/slice/slice_internal.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/slice/slice_string_helpers.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/slice/slice_string_helpers.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/api_trace.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/api_trace.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/call.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/surface/call.h" role="src" />

@ -51,7 +51,8 @@ static bool is_census_enabled(const grpc_channel_args *a) {
return census_enabled(); return census_enabled();
} }
static bool maybe_add_census_filter(grpc_channel_stack_builder *builder, static bool maybe_add_census_filter(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder,
void *arg) { void *arg) {
const grpc_channel_args *args = const grpc_channel_args *args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);

@ -83,8 +83,12 @@ static void *method_parameters_copy(void *value) {
return new_value; return new_value;
} }
static void method_parameters_free(grpc_exec_ctx *exec_ctx, void *p) {
gpr_free(p);
}
static const grpc_mdstr_hash_table_vtable method_parameters_vtable = { static const grpc_mdstr_hash_table_vtable method_parameters_vtable = {
gpr_free, method_parameters_copy}; method_parameters_free, method_parameters_copy};
static void *method_parameters_create_from_json(const grpc_json *json) { static void *method_parameters_create_from_json(const grpc_json *json) {
wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET; wait_for_ready_value wait_for_ready = WAIT_FOR_READY_UNSET;
@ -328,7 +332,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg,
grpc_service_config_create(service_config_json); grpc_service_config_create(service_config_json);
if (service_config != NULL) { if (service_config != NULL) {
method_params_table = grpc_service_config_create_method_config_table( method_params_table = grpc_service_config_create_method_config_table(
service_config, method_parameters_create_from_json, exec_ctx, service_config, method_parameters_create_from_json,
&method_parameters_vtable); &method_parameters_vtable);
grpc_service_config_destroy(service_config); grpc_service_config_destroy(service_config);
} }
@ -337,7 +341,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg,
// be pointing to data inside chand->resolver_result. // be pointing to data inside chand->resolver_result.
// The copy will be saved in chand->lb_policy_name below. // The copy will be saved in chand->lb_policy_name below.
lb_policy_name = gpr_strdup(lb_policy_name); lb_policy_name = gpr_strdup(lb_policy_name);
grpc_channel_args_destroy(chand->resolver_result); grpc_channel_args_destroy(exec_ctx, chand->resolver_result);
chand->resolver_result = NULL; chand->resolver_result = NULL;
} }
@ -358,7 +362,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg,
chand->service_config_json = service_config_json; chand->service_config_json = service_config_json;
} }
if (chand->method_params_table != NULL) { if (chand->method_params_table != NULL) {
grpc_mdstr_hash_table_unref(chand->method_params_table); grpc_mdstr_hash_table_unref(exec_ctx, chand->method_params_table);
} }
chand->method_params_table = method_params_table; chand->method_params_table = method_params_table;
if (lb_policy != NULL) { if (lb_policy != NULL) {
@ -554,7 +558,7 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx,
gpr_free(chand->lb_policy_name); gpr_free(chand->lb_policy_name);
gpr_free(chand->service_config_json); gpr_free(chand->service_config_json);
if (chand->method_params_table != NULL) { if (chand->method_params_table != NULL) {
grpc_mdstr_hash_table_unref(chand->method_params_table); grpc_mdstr_hash_table_unref(exec_ctx, chand->method_params_table);
} }
grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker);
grpc_pollset_set_destroy(chand->interested_parties); grpc_pollset_set_destroy(chand->interested_parties);
@ -1001,8 +1005,8 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg,
gpr_mu_unlock(&chand->mu); gpr_mu_unlock(&chand->mu);
// If the method config table was present, use it. // If the method config table was present, use it.
if (method_params_table != NULL) { if (method_params_table != NULL) {
const method_parameters *method_params = const method_parameters *method_params = grpc_method_config_table_get(
grpc_method_config_table_get(method_params_table, calld->path); exec_ctx, method_params_table, calld->path);
if (method_params != NULL) { if (method_params != NULL) {
const bool have_method_timeout = const bool have_method_timeout =
gpr_time_cmp(method_params->timeout, gpr_time_0(GPR_TIMESPAN)) != 0; gpr_time_cmp(method_params->timeout, gpr_time_0(GPR_TIMESPAN)) != 0;
@ -1025,7 +1029,7 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg,
gpr_mu_unlock(&calld->mu); gpr_mu_unlock(&calld->mu);
} }
} }
grpc_mdstr_hash_table_unref(method_params_table); grpc_mdstr_hash_table_unref(exec_ctx, method_params_table);
} }
} }
GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "read_service_config"); GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "read_service_config");
@ -1066,8 +1070,8 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx,
grpc_mdstr_hash_table *method_params_table = grpc_mdstr_hash_table *method_params_table =
grpc_mdstr_hash_table_ref(chand->method_params_table); grpc_mdstr_hash_table_ref(chand->method_params_table);
gpr_mu_unlock(&chand->mu); gpr_mu_unlock(&chand->mu);
method_parameters *method_params = method_parameters *method_params = grpc_method_config_table_get(
grpc_method_config_table_get(method_params_table, args->path); exec_ctx, method_params_table, args->path);
if (method_params != NULL) { if (method_params != NULL) {
if (gpr_time_cmp(method_params->timeout, if (gpr_time_cmp(method_params->timeout,
gpr_time_0(GPR_CLOCK_MONOTONIC)) != 0) { gpr_time_0(GPR_CLOCK_MONOTONIC)) != 0) {
@ -1080,7 +1084,7 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx,
method_params->wait_for_ready; method_params->wait_for_ready;
} }
} }
grpc_mdstr_hash_table_unref(method_params_table); grpc_mdstr_hash_table_unref(exec_ctx, method_params_table);
} else { } else {
gpr_mu_unlock(&chand->mu); gpr_mu_unlock(&chand->mu);
} }
@ -1109,7 +1113,7 @@ static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx,
void *and_free_memory) { void *and_free_memory) {
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_deadline_state_destroy(exec_ctx, elem); grpc_deadline_state_destroy(exec_ctx, elem);
GRPC_MDSTR_UNREF(calld->path); GRPC_MDSTR_UNREF(exec_ctx, calld->path);
GRPC_ERROR_UNREF(calld->cancel_error); GRPC_ERROR_UNREF(calld->cancel_error);
grpc_subchannel_call *call = GET_CALL(calld); grpc_subchannel_call *call = GET_CALL(calld);
if (call != NULL && call != CANCELLED_CALL) { if (call != NULL && call != CANCELLED_CALL) {

@ -61,12 +61,10 @@ static void* factory_arg_copy(void* factory) {
return factory; return factory;
} }
static void factory_arg_destroy(void* factory) { static void factory_arg_destroy(grpc_exec_ctx* exec_ctx, void* factory) {
// TODO(roth): Remove local exec_ctx when // TODO(roth): Remove local exec_ctx when
// https://github.com/grpc/grpc/pull/8705 is merged. // https://github.com/grpc/grpc/pull/8705 is merged.
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_client_channel_factory_unref(exec_ctx, factory);
grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx);
} }
static int factory_arg_cmp(void* factory1, void* factory2) { static int factory_arg_cmp(void* factory1, void* factory2) {

@ -43,12 +43,14 @@
#include "src/core/ext/client_channel/subchannel_index.h" #include "src/core/ext/client_channel/subchannel_index.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
static bool append_filter(grpc_channel_stack_builder *builder, void *arg) { static bool append_filter(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder, void *arg) {
return grpc_channel_stack_builder_append_filter( return grpc_channel_stack_builder_append_filter(
builder, (const grpc_channel_filter *)arg, NULL, NULL); builder, (const grpc_channel_filter *)arg, NULL, NULL);
} }
static bool set_default_host_if_unset(grpc_channel_stack_builder *builder, static bool set_default_host_if_unset(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder,
void *unused) { void *unused) {
const grpc_channel_args *args = const grpc_channel_args *args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);
@ -66,9 +68,10 @@ static bool set_default_host_if_unset(grpc_channel_stack_builder *builder,
arg.key = GRPC_ARG_DEFAULT_AUTHORITY; arg.key = GRPC_ARG_DEFAULT_AUTHORITY;
arg.value.string = default_authority; arg.value.string = default_authority;
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel_stack_builder_set_channel_arguments(builder, new_args); grpc_channel_stack_builder_set_channel_arguments(exec_ctx, builder,
new_args);
gpr_free(default_authority); gpr_free(default_authority);
grpc_channel_args_destroy(new_args); grpc_channel_args_destroy(exec_ctx, new_args);
} }
return true; return true;
} }

@ -46,6 +46,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/http/format_request.h" #include "src/core/lib/http/format_request.h"
#include "src/core/lib/http/parser.h" #include "src/core/lib/http/parser.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/env.h" #include "src/core/lib/support/env.h"
typedef struct http_connect_handshaker { typedef struct http_connect_handshaker {
@ -83,11 +84,12 @@ static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx,
grpc_endpoint_destroy(exec_ctx, handshaker->endpoint_to_destroy); grpc_endpoint_destroy(exec_ctx, handshaker->endpoint_to_destroy);
} }
if (handshaker->read_buffer_to_destroy != NULL) { if (handshaker->read_buffer_to_destroy != NULL) {
grpc_slice_buffer_destroy(handshaker->read_buffer_to_destroy); grpc_slice_buffer_destroy_internal(exec_ctx,
handshaker->read_buffer_to_destroy);
gpr_free(handshaker->read_buffer_to_destroy); gpr_free(handshaker->read_buffer_to_destroy);
} }
gpr_free(handshaker->proxy_server); gpr_free(handshaker->proxy_server);
grpc_slice_buffer_destroy(&handshaker->write_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, &handshaker->write_buffer);
grpc_http_parser_destroy(&handshaker->http_parser); grpc_http_parser_destroy(&handshaker->http_parser);
grpc_http_response_destroy(&handshaker->http_response); grpc_http_response_destroy(&handshaker->http_response);
gpr_free(handshaker); gpr_free(handshaker);
@ -97,12 +99,12 @@ static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx,
// Set args fields to NULL, saving the endpoint and read buffer for // Set args fields to NULL, saving the endpoint and read buffer for
// later destruction. // later destruction.
static void cleanup_args_for_failure_locked( static void cleanup_args_for_failure_locked(
http_connect_handshaker* handshaker) { grpc_exec_ctx* exec_ctx, http_connect_handshaker* handshaker) {
handshaker->endpoint_to_destroy = handshaker->args->endpoint; handshaker->endpoint_to_destroy = handshaker->args->endpoint;
handshaker->args->endpoint = NULL; handshaker->args->endpoint = NULL;
handshaker->read_buffer_to_destroy = handshaker->args->read_buffer; handshaker->read_buffer_to_destroy = handshaker->args->read_buffer;
handshaker->args->read_buffer = NULL; handshaker->args->read_buffer = NULL;
grpc_channel_args_destroy(handshaker->args->args); grpc_channel_args_destroy(exec_ctx, handshaker->args->args);
handshaker->args->args = NULL; handshaker->args->args = NULL;
} }
@ -125,7 +127,7 @@ static void handshake_failed_locked(grpc_exec_ctx* exec_ctx,
grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint); grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint);
// Not shutting down, so the handshake failed. Clean up before // Not shutting down, so the handshake failed. Clean up before
// invoking the callback. // invoking the callback.
cleanup_args_for_failure_locked(handshaker); cleanup_args_for_failure_locked(exec_ctx, handshaker);
// Set shutdown to true so that subsequent calls to // Set shutdown to true so that subsequent calls to
// http_connect_handshaker_shutdown() do nothing. // http_connect_handshaker_shutdown() do nothing.
handshaker->shutdown = true; handshaker->shutdown = true;
@ -193,7 +195,7 @@ static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg,
&handshaker->args->read_buffer->slices[i + 1], &handshaker->args->read_buffer->slices[i + 1],
handshaker->args->read_buffer->count - i - 1); handshaker->args->read_buffer->count - i - 1);
grpc_slice_buffer_swap(handshaker->args->read_buffer, &tmp_buffer); grpc_slice_buffer_swap(handshaker->args->read_buffer, &tmp_buffer);
grpc_slice_buffer_destroy(&tmp_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, &tmp_buffer);
break; break;
} }
} }
@ -210,7 +212,8 @@ static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg,
// complete (e.g., handling chunked transfer encoding or looking // complete (e.g., handling chunked transfer encoding or looking
// at the Content-Length: header). // at the Content-Length: header).
if (handshaker->http_parser.state != GRPC_HTTP_BODY) { if (handshaker->http_parser.state != GRPC_HTTP_BODY) {
grpc_slice_buffer_reset_and_unref(handshaker->args->read_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx,
handshaker->args->read_buffer);
grpc_endpoint_read(exec_ctx, handshaker->args->endpoint, grpc_endpoint_read(exec_ctx, handshaker->args->endpoint,
handshaker->args->read_buffer, handshaker->args->read_buffer,
&handshaker->response_read_closure); &handshaker->response_read_closure);
@ -255,7 +258,7 @@ static void http_connect_handshaker_shutdown(grpc_exec_ctx* exec_ctx,
if (!handshaker->shutdown) { if (!handshaker->shutdown) {
handshaker->shutdown = true; handshaker->shutdown = true;
grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint); grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint);
cleanup_args_for_failure_locked(handshaker); cleanup_args_for_failure_locked(exec_ctx, handshaker);
} }
gpr_mu_unlock(&handshaker->mu); gpr_mu_unlock(&handshaker->mu);
} }

@ -112,11 +112,13 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1,
return 0; return 0;
} }
void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) { void grpc_lb_addresses_destroy(grpc_exec_ctx* exec_ctx,
grpc_lb_addresses* addresses) {
for (size_t i = 0; i < addresses->num_addresses; ++i) { for (size_t i = 0; i < addresses->num_addresses; ++i) {
gpr_free(addresses->addresses[i].balancer_name); gpr_free(addresses->addresses[i].balancer_name);
if (addresses->addresses[i].user_data != NULL) { if (addresses->addresses[i].user_data != NULL) {
addresses->user_data_vtable->destroy(addresses->addresses[i].user_data); addresses->user_data_vtable->destroy(exec_ctx,
addresses->addresses[i].user_data);
} }
} }
gpr_free(addresses->addresses); gpr_free(addresses->addresses);
@ -126,8 +128,8 @@ void grpc_lb_addresses_destroy(grpc_lb_addresses* addresses) {
static void* lb_addresses_copy(void* addresses) { static void* lb_addresses_copy(void* addresses) {
return grpc_lb_addresses_copy(addresses); return grpc_lb_addresses_copy(addresses);
} }
static void lb_addresses_destroy(void* addresses) { static void lb_addresses_destroy(grpc_exec_ctx* exec_ctx, void* addresses) {
grpc_lb_addresses_destroy(addresses); grpc_lb_addresses_destroy(exec_ctx, addresses);
} }
static int lb_addresses_cmp(void* addresses1, void* addresses2) { static int lb_addresses_cmp(void* addresses1, void* addresses2) {
return grpc_lb_addresses_cmp(addresses1, addresses2); return grpc_lb_addresses_cmp(addresses1, addresses2);

@ -64,7 +64,7 @@ typedef struct grpc_lb_address {
typedef struct grpc_lb_user_data_vtable { typedef struct grpc_lb_user_data_vtable {
void *(*copy)(void *); void *(*copy)(void *);
void (*destroy)(void *); void (*destroy)(grpc_exec_ctx *exec_ctx, void *);
int (*cmp)(void *, void *); int (*cmp)(void *, void *);
} grpc_lb_user_data_vtable; } grpc_lb_user_data_vtable;
@ -96,7 +96,8 @@ int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1,
const grpc_lb_addresses *addresses2); const grpc_lb_addresses *addresses2);
/** Destroys \a addresses. */ /** Destroys \a addresses. */
void grpc_lb_addresses_destroy(grpc_lb_addresses *addresses); void grpc_lb_addresses_destroy(grpc_exec_ctx *exec_ctx,
grpc_lb_addresses *addresses);
/** Returns a channel arg containing \a addresses. */ /** Returns a channel arg containing \a addresses. */
grpc_arg grpc_lb_addresses_create_channel_arg( grpc_arg grpc_lb_addresses_create_channel_arg(

@ -46,6 +46,7 @@
#include "src/core/lib/channel/connected_channel.h" #include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/backoff.h" #include "src/core/lib/support/backoff.h"
#include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
@ -206,9 +207,9 @@ static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) { grpc_error *error) {
grpc_subchannel *c = arg; grpc_subchannel *c = arg;
gpr_free((void *)c->filters); gpr_free((void *)c->filters);
grpc_channel_args_destroy(c->args); grpc_channel_args_destroy(exec_ctx, c->args);
gpr_free(c->addr); gpr_free(c->addr);
grpc_slice_unref(c->initial_connect_string); grpc_slice_unref_internal(exec_ctx, c->initial_connect_string);
grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker);
grpc_connector_unref(exec_ctx, c->connector); grpc_connector_unref(exec_ctx, c->connector);
grpc_pollset_set_destroy(c->pollset_set); grpc_pollset_set_destroy(c->pollset_set);
@ -603,13 +604,13 @@ static void publish_transport_locked(grpc_exec_ctx *exec_ctx,
/* construct channel stack */ /* construct channel stack */
grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create(); grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create();
grpc_channel_stack_builder_set_channel_arguments( grpc_channel_stack_builder_set_channel_arguments(
builder, c->connecting_result.channel_args); exec_ctx, builder, c->connecting_result.channel_args);
grpc_channel_stack_builder_set_transport(builder, grpc_channel_stack_builder_set_transport(builder,
c->connecting_result.transport); c->connecting_result.transport);
if (!grpc_channel_init_create_stack(exec_ctx, builder, if (!grpc_channel_init_create_stack(exec_ctx, builder,
GRPC_CLIENT_SUBCHANNEL)) { GRPC_CLIENT_SUBCHANNEL)) {
grpc_channel_stack_builder_destroy(builder); grpc_channel_stack_builder_destroy(exec_ctx, builder);
abort(); /* TODO(ctiller): what to do here (previously we just crashed) */ abort(); /* TODO(ctiller): what to do here (previously we just crashed) */
} }
grpc_error *error = grpc_channel_stack_builder_finish( grpc_error *error = grpc_channel_stack_builder_finish(
@ -689,7 +690,7 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg,
} }
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connected"); GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connected");
grpc_channel_args_destroy(delete_channel_args); grpc_channel_args_destroy(exec_ctx, delete_channel_args);
} }
/* /*

@ -128,7 +128,7 @@ void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx,
grpc_subchannel_key *k) { grpc_subchannel_key *k) {
grpc_connector_unref(exec_ctx, k->connector); grpc_connector_unref(exec_ctx, k->connector);
gpr_free((grpc_channel_args *)k->args.filters); gpr_free((grpc_channel_args *)k->args.filters);
grpc_channel_args_destroy((grpc_channel_args *)k->args.args); grpc_channel_args_destroy(exec_ctx, (grpc_channel_args *)k->args.args);
gpr_free(k->args.addr); gpr_free(k->args.addr);
gpr_free(k); gpr_free(k);
} }

@ -42,7 +42,6 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
/** a size_t default value... maps to all 1's */ /** a size_t default value... maps to all 1's */
@ -138,7 +137,6 @@ static int parse_fragment_or_query(const char *uri_text, size_t *i) {
return 1; return 1;
} }
static void do_nothing(void *ignored) {}
static void parse_query_parts(grpc_uri *uri) { static void parse_query_parts(grpc_uri *uri) {
static const char *QUERY_PARTS_SEPARATOR = "&"; static const char *QUERY_PARTS_SEPARATOR = "&";
static const char *QUERY_PARTS_VALUE_SEPARATOR = "="; static const char *QUERY_PARTS_VALUE_SEPARATOR = "=";
@ -149,38 +147,32 @@ static void parse_query_parts(grpc_uri *uri) {
uri->num_query_parts = 0; uri->num_query_parts = 0;
return; return;
} }
grpc_slice query_slice =
grpc_slice_new(uri->query, strlen(uri->query), do_nothing);
grpc_slice_buffer query_parts; /* the &-separated elements of the query */
grpc_slice_buffer query_param_parts; /* the =-separated subelements */
grpc_slice_buffer_init(&query_parts); gpr_string_split(uri->query, QUERY_PARTS_SEPARATOR, &uri->query_parts,
grpc_slice_buffer_init(&query_param_parts); &uri->num_query_parts);
uri->query_parts_values = gpr_malloc(uri->num_query_parts * sizeof(char **));
grpc_slice_split(query_slice, QUERY_PARTS_SEPARATOR, &query_parts); for (size_t i = 0; i < uri->num_query_parts; i++) {
uri->query_parts = gpr_malloc(query_parts.count * sizeof(char *)); char **query_param_parts;
uri->query_parts_values = gpr_malloc(query_parts.count * sizeof(char *)); size_t num_query_param_parts;
uri->num_query_parts = query_parts.count; char *full = uri->query_parts[i];
for (size_t i = 0; i < query_parts.count; i++) { gpr_string_split(full, QUERY_PARTS_VALUE_SEPARATOR, &query_param_parts,
grpc_slice_split(query_parts.slices[i], QUERY_PARTS_VALUE_SEPARATOR, &num_query_param_parts);
&query_param_parts); GPR_ASSERT(num_query_param_parts > 0);
GPR_ASSERT(query_param_parts.count > 0); uri->query_parts[i] = query_param_parts[0];
uri->query_parts[i] = if (num_query_param_parts > 1) {
grpc_dump_slice(query_param_parts.slices[0], GPR_DUMP_ASCII);
if (query_param_parts.count > 1) {
/* TODO(dgq): only the first value after the separator is considered. /* TODO(dgq): only the first value after the separator is considered.
* Perhaps all chars after the first separator for the query part should * Perhaps all chars after the first separator for the query part should
* be included, even if they include the separator. */ * be included, even if they include the separator. */
uri->query_parts_values[i] = uri->query_parts_values[i] = query_param_parts[1];
grpc_dump_slice(query_param_parts.slices[1], GPR_DUMP_ASCII);
} else { } else {
uri->query_parts_values[i] = NULL; uri->query_parts_values[i] = NULL;
} }
grpc_slice_buffer_reset_and_unref(&query_param_parts); for (size_t j = 2; j < num_query_param_parts; j++) {
gpr_free(query_param_parts[j]);
}
gpr_free(query_param_parts);
gpr_free(full);
} }
grpc_slice_buffer_destroy(&query_parts);
grpc_slice_buffer_destroy(&query_param_parts);
grpc_slice_unref(query_slice);
} }
grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) { grpc_uri *grpc_uri_parse(const char *uri_text, int suppress_errors) {

@ -117,6 +117,7 @@
#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/backoff.h" #include "src/core/lib/support/backoff.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
@ -386,8 +387,8 @@ static bool is_server_valid(const grpc_grpclb_server *server, size_t idx,
static void *lb_token_copy(void *token) { static void *lb_token_copy(void *token) {
return token == NULL ? NULL : GRPC_MDELEM_REF(token); return token == NULL ? NULL : GRPC_MDELEM_REF(token);
} }
static void lb_token_destroy(void *token) { static void lb_token_destroy(grpc_exec_ctx *exec_ctx, void *token) {
if (token != NULL) GRPC_MDELEM_UNREF(token); if (token != NULL) GRPC_MDELEM_UNREF(exec_ctx, token);
} }
static int lb_token_cmp(void *token1, void *token2) { static int lb_token_cmp(void *token1, void *token2) {
if (token1 > token2) return 1; if (token1 > token2) return 1;
@ -421,7 +422,7 @@ static void parse_server(const grpc_grpclb_server *server,
/* Returns addresses extracted from \a serverlist. */ /* Returns addresses extracted from \a serverlist. */
static grpc_lb_addresses *process_serverlist_locked( static grpc_lb_addresses *process_serverlist_locked(
const grpc_grpclb_serverlist *serverlist) { grpc_exec_ctx *exec_ctx, const grpc_grpclb_serverlist *serverlist) {
size_t num_valid = 0; size_t num_valid = 0;
/* first pass: count how many are valid in order to allocate the necessary /* first pass: count how many are valid in order to allocate the necessary
* memory in a single block */ * memory in a single block */
@ -457,8 +458,8 @@ static grpc_lb_addresses *process_serverlist_locked(
strnlen(server->load_balance_token, lb_token_max_length); strnlen(server->load_balance_token, lb_token_max_length);
grpc_mdstr *lb_token_mdstr = grpc_mdstr_from_buffer( grpc_mdstr *lb_token_mdstr = grpc_mdstr_from_buffer(
(uint8_t *)server->load_balance_token, lb_token_length); (uint8_t *)server->load_balance_token, lb_token_length);
user_data = grpc_mdelem_from_metadata_strings(GRPC_MDSTR_LB_TOKEN, user_data = grpc_mdelem_from_metadata_strings(
lb_token_mdstr); exec_ctx, GRPC_MDSTR_LB_TOKEN, lb_token_mdstr);
} else { } else {
char *uri = grpc_sockaddr_to_uri(&addr); char *uri = grpc_sockaddr_to_uri(&addr);
gpr_log(GPR_INFO, gpr_log(GPR_INFO,
@ -581,7 +582,8 @@ static grpc_lb_policy *create_rr_locked(
grpc_lb_policy_args args; grpc_lb_policy_args args;
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.client_channel_factory = glb_policy->cc_factory; args.client_channel_factory = glb_policy->cc_factory;
grpc_lb_addresses *addresses = process_serverlist_locked(serverlist); grpc_lb_addresses *addresses =
process_serverlist_locked(exec_ctx, serverlist);
// Replace the LB addresses in the channel args that we pass down to // Replace the LB addresses in the channel args that we pass down to
// the subchannel. // the subchannel.
@ -593,8 +595,8 @@ static grpc_lb_policy *create_rr_locked(
grpc_lb_policy *rr = grpc_lb_policy_create(exec_ctx, "round_robin", &args); grpc_lb_policy *rr = grpc_lb_policy_create(exec_ctx, "round_robin", &args);
GPR_ASSERT(rr != NULL); GPR_ASSERT(rr != NULL);
grpc_lb_addresses_destroy(addresses); grpc_lb_addresses_destroy(exec_ctx, addresses);
grpc_channel_args_destroy(args.args); grpc_channel_args_destroy(exec_ctx, args.args);
return rr; return rr;
} }
@ -840,7 +842,7 @@ static grpc_lb_policy *glb_create(grpc_exec_ctx *exec_ctx,
glb_policy->lb_channel = grpc_client_channel_factory_create_channel( glb_policy->lb_channel = grpc_client_channel_factory_create_channel(
exec_ctx, glb_policy->cc_factory, target_uri_str, exec_ctx, glb_policy->cc_factory, target_uri_str,
GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args); GRPC_CLIENT_CHANNEL_TYPE_LOAD_BALANCING, new_args);
grpc_channel_args_destroy(new_args); grpc_channel_args_destroy(exec_ctx, new_args);
gpr_free(target_uri_str); gpr_free(target_uri_str);
for (size_t i = 0; i < num_grpclb_addrs; i++) { for (size_t i = 0; i < num_grpclb_addrs; i++) {
@ -866,7 +868,7 @@ static void glb_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
GPR_ASSERT(glb_policy->pending_picks == NULL); GPR_ASSERT(glb_policy->pending_picks == NULL);
GPR_ASSERT(glb_policy->pending_pings == NULL); GPR_ASSERT(glb_policy->pending_pings == NULL);
gpr_free((void *)glb_policy->server_name); gpr_free((void *)glb_policy->server_name);
grpc_channel_args_destroy(glb_policy->args); grpc_channel_args_destroy(exec_ctx, glb_policy->args);
grpc_channel_destroy(glb_policy->lb_channel); grpc_channel_destroy(glb_policy->lb_channel);
glb_policy->lb_channel = NULL; glb_policy->lb_channel = NULL;
grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker); grpc_connectivity_state_destroy(exec_ctx, &glb_policy->state_tracker);
@ -1089,7 +1091,8 @@ static void lb_on_server_status_received(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error); grpc_error *error);
static void lb_on_response_received(grpc_exec_ctx *exec_ctx, void *arg, static void lb_on_response_received(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error); grpc_error *error);
static void lb_call_init_locked(glb_lb_policy *glb_policy) { static void lb_call_init_locked(grpc_exec_ctx *exec_ctx,
glb_lb_policy *glb_policy) {
GPR_ASSERT(glb_policy->server_name != NULL); GPR_ASSERT(glb_policy->server_name != NULL);
GPR_ASSERT(glb_policy->server_name[0] != '\0'); GPR_ASSERT(glb_policy->server_name[0] != '\0');
GPR_ASSERT(!glb_policy->shutting_down); GPR_ASSERT(!glb_policy->shutting_down);
@ -1098,7 +1101,7 @@ static void lb_call_init_locked(glb_lb_policy *glb_policy) {
* glb_policy->base.interested_parties, which is comprised of the polling * glb_policy->base.interested_parties, which is comprised of the polling
* entities from \a client_channel. */ * entities from \a client_channel. */
glb_policy->lb_call = grpc_channel_create_pollset_set_call( glb_policy->lb_call = grpc_channel_create_pollset_set_call(
glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, exec_ctx, glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS,
glb_policy->base.interested_parties, glb_policy->base.interested_parties,
"/grpc.lb.v1.LoadBalancer/BalanceLoad", glb_policy->server_name, "/grpc.lb.v1.LoadBalancer/BalanceLoad", glb_policy->server_name,
glb_policy->deadline, NULL); glb_policy->deadline, NULL);
@ -1111,7 +1114,7 @@ static void lb_call_init_locked(glb_lb_policy *glb_policy) {
grpc_slice request_payload_slice = grpc_grpclb_request_encode(request); grpc_slice request_payload_slice = grpc_grpclb_request_encode(request);
glb_policy->lb_request_payload = glb_policy->lb_request_payload =
grpc_raw_byte_buffer_create(&request_payload_slice, 1); grpc_raw_byte_buffer_create(&request_payload_slice, 1);
grpc_slice_unref(request_payload_slice); grpc_slice_unref_internal(exec_ctx, request_payload_slice);
grpc_grpclb_request_destroy(request); grpc_grpclb_request_destroy(request);
glb_policy->lb_call_status_details = NULL; glb_policy->lb_call_status_details = NULL;
@ -1152,7 +1155,7 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(glb_policy->lb_channel != NULL); GPR_ASSERT(glb_policy->lb_channel != NULL);
if (glb_policy->shutting_down) return; if (glb_policy->shutting_down) return;
lb_call_init_locked(glb_policy); lb_call_init_locked(exec_ctx, glb_policy);
if (grpc_lb_glb_trace) { if (grpc_lb_glb_trace) {
gpr_log(GPR_INFO, "Query for backends (grpclb: %p, lb_call: %p)", gpr_log(GPR_INFO, "Query for backends (grpclb: %p, lb_call: %p)",
@ -1237,7 +1240,7 @@ static void lb_on_response_received(grpc_exec_ctx *exec_ctx, void *arg,
grpc_grpclb_response_parse_serverlist(response_slice); grpc_grpclb_response_parse_serverlist(response_slice);
if (serverlist != NULL) { if (serverlist != NULL) {
GPR_ASSERT(glb_policy->lb_call != NULL); GPR_ASSERT(glb_policy->lb_call != NULL);
grpc_slice_unref(response_slice); grpc_slice_unref_internal(exec_ctx, response_slice);
if (grpc_lb_glb_trace) { if (grpc_lb_glb_trace) {
gpr_log(GPR_INFO, "Serverlist with %lu servers received", gpr_log(GPR_INFO, "Serverlist with %lu servers received",
(unsigned long)serverlist->num_servers); (unsigned long)serverlist->num_servers);
@ -1281,7 +1284,7 @@ static void lb_on_response_received(grpc_exec_ctx *exec_ctx, void *arg,
} else { /* serverlist == NULL */ } else { /* serverlist == NULL */
gpr_log(GPR_ERROR, "Invalid LB response received: '%s'. Ignoring.", gpr_log(GPR_ERROR, "Invalid LB response received: '%s'. Ignoring.",
grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX)); grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX));
grpc_slice_unref(response_slice); grpc_slice_unref_internal(exec_ctx, response_slice);
} }
if (!glb_policy->shutting_down) { if (!glb_policy->shutting_down) {

@ -284,7 +284,7 @@ static void rr_destroy(grpc_exec_ctx *exec_ctx, grpc_lb_policy *pol) {
GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, "rr_destroy"); GRPC_SUBCHANNEL_UNREF(exec_ctx, sd->subchannel, "rr_destroy");
if (sd->user_data != NULL) { if (sd->user_data != NULL) {
GPR_ASSERT(sd->user_data_vtable != NULL); GPR_ASSERT(sd->user_data_vtable != NULL);
sd->user_data_vtable->destroy(sd->user_data); sd->user_data_vtable->destroy(exec_ctx, sd->user_data);
} }
gpr_free(sd); gpr_free(sd);
} }

@ -53,7 +53,8 @@ static bool is_load_reporting_enabled(const grpc_channel_args *a) {
return false; return false;
} }
static bool maybe_add_load_reporting_filter(grpc_channel_stack_builder *builder, static bool maybe_add_load_reporting_filter(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder,
void *arg) { void *arg) {
const grpc_channel_args *args = const grpc_channel_args *args =
grpc_channel_stack_builder_get_channel_arguments(builder); grpc_channel_stack_builder_get_channel_arguments(builder);

@ -68,7 +68,8 @@ typedef struct {
grpc_exec_ctx *exec_ctx; grpc_exec_ctx *exec_ctx;
} recv_md_filter_args; } recv_md_filter_args;
static grpc_mdelem *recv_md_filter(void *user_data, grpc_mdelem *md) { static grpc_mdelem *recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data,
grpc_mdelem *md) {
recv_md_filter_args *a = user_data; recv_md_filter_args *a = user_data;
grpc_call_element *elem = a->elem; grpc_call_element *elem = a->elem;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
@ -92,8 +93,8 @@ static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data,
recv_md_filter_args a; recv_md_filter_args a;
a.elem = elem; a.elem = elem;
a.exec_ctx = exec_ctx; a.exec_ctx = exec_ctx;
grpc_metadata_batch_filter(calld->recv_initial_metadata, recv_md_filter, grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata,
&a); recv_md_filter, &a);
if (calld->service_method == NULL) { if (calld->service_method == NULL) {
err = err =
grpc_error_add_child(err, GRPC_ERROR_CREATE("Missing :path header")); grpc_error_add_child(err, GRPC_ERROR_CREATE("Missing :path header"));
@ -192,7 +193,8 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
*/ */
} }
static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) { static grpc_mdelem *lr_trailing_md_filter(grpc_exec_ctx *exec_ctx,
void *user_data, grpc_mdelem *md) {
grpc_call_element *elem = user_data; grpc_call_element *elem = user_data;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
@ -216,7 +218,7 @@ static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx,
calld->ops_recv_initial_metadata_ready = op->recv_initial_metadata_ready; calld->ops_recv_initial_metadata_ready = op->recv_initial_metadata_ready;
op->recv_initial_metadata_ready = &calld->on_initial_md_ready; op->recv_initial_metadata_ready = &calld->on_initial_md_ready;
} else if (op->send_trailing_metadata) { } else if (op->send_trailing_metadata) {
grpc_metadata_batch_filter(op->send_trailing_metadata, grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata,
lr_trailing_md_filter, elem); lr_trailing_md_filter, elem);
} }
grpc_call_next_op(exec_ctx, elem, op); grpc_call_next_op(exec_ctx, elem, op);

@ -182,7 +182,7 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses); grpc_arg new_arg = grpc_lb_addresses_create_channel_arg(addresses);
result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1); result = grpc_channel_args_copy_and_add(r->channel_args, &new_arg, 1);
grpc_resolved_addresses_destroy(r->addresses); grpc_resolved_addresses_destroy(r->addresses);
grpc_lb_addresses_destroy(addresses); grpc_lb_addresses_destroy(exec_ctx, addresses);
} else { } else {
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now);
@ -203,7 +203,7 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg,
now); now);
} }
if (r->resolved_result != NULL) { if (r->resolved_result != NULL) {
grpc_channel_args_destroy(r->resolved_result); grpc_channel_args_destroy(exec_ctx, r->resolved_result);
} }
r->resolved_result = result; r->resolved_result = result;
r->resolved_version++; r->resolved_version++;
@ -242,12 +242,12 @@ static void dns_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
dns_resolver *r = (dns_resolver *)gr; dns_resolver *r = (dns_resolver *)gr;
gpr_mu_destroy(&r->mu); gpr_mu_destroy(&r->mu);
if (r->resolved_result != NULL) { if (r->resolved_result != NULL) {
grpc_channel_args_destroy(r->resolved_result); grpc_channel_args_destroy(exec_ctx, r->resolved_result);
} }
grpc_pollset_set_destroy(r->interested_parties); grpc_pollset_set_destroy(r->interested_parties);
gpr_free(r->name_to_resolve); gpr_free(r->name_to_resolve);
gpr_free(r->default_port); gpr_free(r->default_port);
grpc_channel_args_destroy(r->channel_args); grpc_channel_args_destroy(exec_ctx, r->channel_args);
gpr_free(r); gpr_free(r);
} }

@ -47,6 +47,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/iomgr/unix_sockets_posix.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
@ -131,8 +132,8 @@ static void sockaddr_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) { static void sockaddr_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
sockaddr_resolver *r = (sockaddr_resolver *)gr; sockaddr_resolver *r = (sockaddr_resolver *)gr;
gpr_mu_destroy(&r->mu); gpr_mu_destroy(&r->mu);
grpc_lb_addresses_destroy(r->addresses); grpc_lb_addresses_destroy(exec_ctx, r->addresses);
grpc_channel_args_destroy(r->channel_args); grpc_channel_args_destroy(exec_ctx, r->channel_args);
gpr_free(r); gpr_free(r);
} }
@ -161,7 +162,8 @@ char *unix_get_default_authority(grpc_resolver_factory *factory,
static void do_nothing(void *ignored) {} static void do_nothing(void *ignored) {}
static grpc_resolver *sockaddr_create(grpc_resolver_args *args, static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx,
grpc_resolver_args *args,
int parse(grpc_uri *uri, int parse(grpc_uri *uri,
grpc_resolved_address *dst)) { grpc_resolved_address *dst)) {
if (0 != strcmp(args->uri->authority, "")) { if (0 != strcmp(args->uri->authority, "")) {
@ -188,10 +190,10 @@ static grpc_resolver *sockaddr_create(grpc_resolver_args *args,
gpr_free(part_str); gpr_free(part_str);
if (errors_found) break; if (errors_found) break;
} }
grpc_slice_buffer_destroy(&path_parts); grpc_slice_buffer_destroy_internal(exec_ctx, &path_parts);
grpc_slice_unref(path_slice); grpc_slice_unref_internal(exec_ctx, path_slice);
if (errors_found) { if (errors_found) {
grpc_lb_addresses_destroy(addresses); grpc_lb_addresses_destroy(exec_ctx, addresses);
return NULL; return NULL;
} }
/* Instantiate resolver. */ /* Instantiate resolver. */
@ -216,7 +218,7 @@ static void sockaddr_factory_unref(grpc_resolver_factory *factory) {}
static grpc_resolver *name##_factory_create_resolver( \ static grpc_resolver *name##_factory_create_resolver( \
grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, \ grpc_exec_ctx *exec_ctx, grpc_resolver_factory *factory, \
grpc_resolver_args *args) { \ grpc_resolver_args *args) { \
return sockaddr_create(args, parse_##name); \ return sockaddr_create(exec_ctx, args, parse_##name); \
} \ } \
static const grpc_resolver_factory_vtable name##_factory_vtable = { \ static const grpc_resolver_factory_vtable name##_factory_vtable = { \
sockaddr_factory_ref, sockaddr_factory_unref, \ sockaddr_factory_ref, sockaddr_factory_unref, \

@ -47,6 +47,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h" #include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/slice/slice_internal.h"
typedef struct { typedef struct {
grpc_connector base; grpc_connector base;
@ -123,8 +124,8 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
// point this can be removed. // point this can be removed.
grpc_endpoint_shutdown(exec_ctx, args->endpoint); grpc_endpoint_shutdown(exec_ctx, args->endpoint);
grpc_endpoint_destroy(exec_ctx, args->endpoint); grpc_endpoint_destroy(exec_ctx, args->endpoint);
grpc_channel_args_destroy(args->args); grpc_channel_args_destroy(exec_ctx, args->args);
grpc_slice_buffer_destroy(args->read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer);
gpr_free(args->read_buffer); gpr_free(args->read_buffer);
} else { } else {
error = GRPC_ERROR_REF(error); error = GRPC_ERROR_REF(error);

@ -72,7 +72,7 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args, grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
GRPC_CLIENT_CHANNEL, NULL); GRPC_CLIENT_CHANNEL, NULL);
grpc_channel_args_destroy(new_args); grpc_channel_args_destroy(exec_ctx, new_args);
return channel; return channel;
} }
@ -105,7 +105,7 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
grpc_channel *channel = client_channel_factory_create_channel( grpc_channel *channel = client_channel_factory_create_channel(
&exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args); &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
// Clean up. // Clean up.
grpc_channel_args_destroy(new_args); grpc_channel_args_destroy(&exec_ctx, new_args);
grpc_client_channel_factory_unref(&exec_ctx, factory); grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
return channel != NULL ? channel : grpc_lame_client_channel_create( return channel != NULL ? channel : grpc_lame_client_channel_create(

@ -74,7 +74,7 @@ grpc_channel *grpc_insecure_channel_create_from_fd(
GPR_ASSERT(transport); GPR_ASSERT(transport);
grpc_channel *channel = grpc_channel_create( grpc_channel *channel = grpc_channel_create(
&exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport); &exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
grpc_channel_args_destroy(final_args); grpc_channel_args_destroy(&exec_ctx, final_args);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);

@ -62,7 +62,7 @@ static void client_channel_factory_unref(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) { grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {
client_channel_factory *f = (client_channel_factory *)cc_factory; client_channel_factory *f = (client_channel_factory *)cc_factory;
if (gpr_unref(&f->refs)) { if (gpr_unref(&f->refs)) {
GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &f->security_connector->base,
"client_channel_factory"); "client_channel_factory");
gpr_free(f); gpr_free(f);
} }
@ -97,7 +97,7 @@ static grpc_channel *client_channel_factory_create_channel(
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1); grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args, grpc_channel *channel = grpc_channel_create(exec_ctx, target, new_args,
GRPC_CLIENT_CHANNEL, NULL); GRPC_CLIENT_CHANNEL, NULL);
grpc_channel_args_destroy(new_args); grpc_channel_args_destroy(exec_ctx, new_args);
return channel; return channel;
} }
@ -132,8 +132,8 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
grpc_channel_security_connector *security_connector; grpc_channel_security_connector *security_connector;
grpc_channel_args *new_args_from_connector; grpc_channel_args *new_args_from_connector;
if (grpc_channel_credentials_create_security_connector( if (grpc_channel_credentials_create_security_connector(
creds, target, args, &security_connector, &new_args_from_connector) != &exec_ctx, creds, target, args, &security_connector,
GRPC_SECURITY_OK) { &new_args_from_connector) != GRPC_SECURITY_OK) {
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
return grpc_lame_client_channel_create( return grpc_lame_client_channel_create(
target, GRPC_STATUS_INTERNAL, "Failed to create security connector."); target, GRPC_STATUS_INTERNAL, "Failed to create security connector.");
@ -155,15 +155,15 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
new_args_from_connector != NULL ? new_args_from_connector : args, new_args_from_connector != NULL ? new_args_from_connector : args,
new_args, GPR_ARRAY_SIZE(new_args)); new_args, GPR_ARRAY_SIZE(new_args));
if (new_args_from_connector != NULL) { if (new_args_from_connector != NULL) {
grpc_channel_args_destroy(new_args_from_connector); grpc_channel_args_destroy(&exec_ctx, new_args_from_connector);
} }
// Create channel. // Create channel.
grpc_channel *channel = client_channel_factory_create_channel( grpc_channel *channel = client_channel_factory_create_channel(
&exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args_copy); &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args_copy);
// Clean up. // Clean up.
GRPC_SECURITY_CONNECTOR_UNREF(&f->security_connector->base, GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &f->security_connector->base,
"secure_client_channel_factory_create_channel"); "secure_client_channel_factory_create_channel");
grpc_channel_args_destroy(args_copy); grpc_channel_args_destroy(&exec_ctx, args_copy);
grpc_client_channel_factory_unref(&exec_ctx, &f->base); grpc_client_channel_factory_unref(&exec_ctx, &f->base);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
return channel; /* may be NULL */ return channel; /* may be NULL */

@ -50,6 +50,7 @@
#include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/tcp_server.h" #include "src/core/lib/iomgr/tcp_server.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/server.h" #include "src/core/lib/surface/server.h"
@ -148,8 +149,8 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
// point this can be removed. // point this can be removed.
grpc_endpoint_shutdown(exec_ctx, args->endpoint); grpc_endpoint_shutdown(exec_ctx, args->endpoint);
grpc_endpoint_destroy(exec_ctx, args->endpoint); grpc_endpoint_destroy(exec_ctx, args->endpoint);
grpc_channel_args_destroy(args->args); grpc_channel_args_destroy(exec_ctx, args->args);
grpc_slice_buffer_destroy(args->read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer);
gpr_free(args->read_buffer); gpr_free(args->read_buffer);
} }
} else { } else {
@ -164,7 +165,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
connection_state->accepting_pollset, args->args); connection_state->accepting_pollset, args->args);
grpc_chttp2_transport_start_reading(exec_ctx, transport, grpc_chttp2_transport_start_reading(exec_ctx, transport,
args->read_buffer); args->read_buffer);
grpc_channel_args_destroy(args->args); grpc_channel_args_destroy(exec_ctx, args->args);
} }
} }
pending_handshake_manager_remove_locked(connection_state->server_state, pending_handshake_manager_remove_locked(connection_state->server_state,
@ -238,7 +239,7 @@ static void tcp_server_shutdown_complete(grpc_exec_ctx *exec_ctx, void *arg,
destroy_done->cb(exec_ctx, destroy_done->cb_arg, GRPC_ERROR_REF(error)); destroy_done->cb(exec_ctx, destroy_done->cb_arg, GRPC_ERROR_REF(error));
grpc_exec_ctx_flush(exec_ctx); grpc_exec_ctx_flush(exec_ctx);
} }
grpc_channel_args_destroy(state->args); grpc_channel_args_destroy(exec_ctx, state->args);
gpr_mu_destroy(&state->mu); gpr_mu_destroy(&state->mu);
gpr_free(state); gpr_free(state);
} }
@ -346,7 +347,7 @@ error:
if (tcp_server) { if (tcp_server) {
grpc_tcp_server_unref(exec_ctx, tcp_server); grpc_tcp_server_unref(exec_ctx, tcp_server);
} else { } else {
grpc_channel_args_destroy(args); grpc_channel_args_destroy(exec_ctx, args);
grpc_chttp2_server_handshaker_factory_destroy(exec_ctx, handshaker_factory); grpc_chttp2_server_handshaker_factory_destroy(exec_ctx, handshaker_factory);
gpr_free(state); gpr_free(state);
} }

@ -62,7 +62,7 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server *server,
grpc_endpoint *server_endpoint = grpc_endpoint *server_endpoint =
grpc_tcp_create(grpc_fd_create(fd, name), resource_quota, grpc_tcp_create(grpc_fd_create(fd, name), resource_quota,
GRPC_TCP_DEFAULT_READ_SLICE_SIZE, name); GRPC_TCP_DEFAULT_READ_SLICE_SIZE, name);
grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); grpc_resource_quota_unref_internal(&exec_ctx, resource_quota);
gpr_free(name); gpr_free(name);

@ -67,8 +67,8 @@ static void server_security_handshaker_factory_destroy(
grpc_exec_ctx *exec_ctx, grpc_chttp2_server_handshaker_factory *hf) { grpc_exec_ctx *exec_ctx, grpc_chttp2_server_handshaker_factory *hf) {
server_security_handshaker_factory *handshaker_factory = server_security_handshaker_factory *handshaker_factory =
(server_security_handshaker_factory *)hf; (server_security_handshaker_factory *)hf;
GRPC_SECURITY_CONNECTOR_UNREF(&handshaker_factory->security_connector->base, GRPC_SECURITY_CONNECTOR_UNREF(
"server"); exec_ctx, &handshaker_factory->security_connector->base, "server");
gpr_free(hf); gpr_free(hf);
} }
@ -94,7 +94,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
goto done; goto done;
} }
grpc_security_status status = grpc_security_status status =
grpc_server_credentials_create_security_connector(creds, &sc); grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc);
if (status != GRPC_SECURITY_OK) { if (status != GRPC_SECURITY_OK) {
char *msg; char *msg;
gpr_asprintf(&msg, gpr_asprintf(&msg,

@ -34,6 +34,7 @@
#include "src/core/ext/transport/chttp2/transport/bin_decoder.h" #include "src/core/ext/transport/chttp2/transport/bin_decoder.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
@ -143,7 +144,8 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx) {
return true; return true;
} }
grpc_slice grpc_chttp2_base64_decode(grpc_slice input) { grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx,
grpc_slice input) {
size_t input_length = GRPC_SLICE_LENGTH(input); size_t input_length = GRPC_SLICE_LENGTH(input);
size_t output_length = input_length / 4 * 3; size_t output_length = input_length / 4 * 3;
struct grpc_base64_decode_context ctx; struct grpc_base64_decode_context ctx;
@ -179,7 +181,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) {
char *s = grpc_dump_slice(input, GPR_DUMP_ASCII); char *s = grpc_dump_slice(input, GPR_DUMP_ASCII);
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s);
gpr_free(s); gpr_free(s);
grpc_slice_unref(output); grpc_slice_unref_internal(exec_ctx, output);
return gpr_empty_slice(); return gpr_empty_slice();
} }
GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output));
@ -187,7 +189,8 @@ grpc_slice grpc_chttp2_base64_decode(grpc_slice input) {
return output; return output;
} }
grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx,
grpc_slice input,
size_t output_length) { size_t output_length) {
size_t input_length = GRPC_SLICE_LENGTH(input); size_t input_length = GRPC_SLICE_LENGTH(input);
grpc_slice output = grpc_slice_malloc(output_length); grpc_slice output = grpc_slice_malloc(output_length);
@ -200,7 +203,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input,
"grpc_chttp2_base64_decode_with_length has a length of %d, which " "grpc_chttp2_base64_decode_with_length has a length of %d, which "
"has a tail of 1 byte.\n", "has a tail of 1 byte.\n",
(int)input_length); (int)input_length);
grpc_slice_unref(output); grpc_slice_unref_internal(exec_ctx, output);
return gpr_empty_slice(); return gpr_empty_slice();
} }
@ -210,7 +213,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input,
"than the max possible output length %d.\n", "than the max possible output length %d.\n",
(int)output_length, (int)output_length,
(int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); (int)(input_length / 4 * 3 + tail_xtra[input_length % 4]));
grpc_slice_unref(output); grpc_slice_unref_internal(exec_ctx, output);
return gpr_empty_slice(); return gpr_empty_slice();
} }
@ -224,7 +227,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input,
char *s = grpc_dump_slice(input, GPR_DUMP_ASCII); char *s = grpc_dump_slice(input, GPR_DUMP_ASCII);
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s);
gpr_free(s); gpr_free(s);
grpc_slice_unref(output); grpc_slice_unref_internal(exec_ctx, output);
return gpr_empty_slice(); return gpr_empty_slice();
} }
GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output));

@ -55,12 +55,13 @@ bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx);
/* base64 decode a slice with pad chars. Returns a new slice, does not take /* base64 decode a slice with pad chars. Returns a new slice, does not take
ownership of the input. Returns an empty slice if decoding is failed. */ ownership of the input. Returns an empty slice if decoding is failed. */
grpc_slice grpc_chttp2_base64_decode(grpc_slice input); grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, grpc_slice input);
/* base64 decode a slice without pad chars, data length is needed. Returns a new /* base64 decode a slice without pad chars, data length is needed. Returns a new
slice, does not take ownership of the input. Returns an empty slice if slice, does not take ownership of the input. Returns an empty slice if
decoding is failed. */ decoding is failed. */
grpc_slice grpc_chttp2_base64_decode_with_length(grpc_slice input, grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx,
grpc_slice input,
size_t output_length); size_t output_length);
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */ #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */

@ -47,7 +47,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input);
/* equivalent to: /* equivalent to:
grpc_slice x = grpc_chttp2_base64_encode(input); grpc_slice x = grpc_chttp2_base64_encode(input);
grpc_slice y = grpc_chttp2_huffman_compress(x); grpc_slice y = grpc_chttp2_huffman_compress(x);
grpc_slice_unref(x); grpc_slice_unref_internal(exec_ctx, x);
return y; */ return y; */
grpc_slice grpc_chttp2_base64_encode_and_huffman_compress_impl( grpc_slice grpc_chttp2_base64_encode_and_huffman_compress_impl(
grpc_slice input); grpc_slice input);

@ -51,6 +51,7 @@
#include "src/core/lib/http/parser.h" #include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/workqueue.h" #include "src/core/lib/iomgr/workqueue.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
@ -131,13 +132,13 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx,
grpc_endpoint_destroy(exec_ctx, t->ep); grpc_endpoint_destroy(exec_ctx, t->ep);
grpc_slice_buffer_destroy(&t->qbuf); grpc_slice_buffer_destroy_internal(exec_ctx, &t->qbuf);
grpc_slice_buffer_destroy(&t->outbuf); grpc_slice_buffer_destroy_internal(exec_ctx, &t->outbuf);
grpc_chttp2_hpack_compressor_destroy(&t->hpack_compressor); grpc_chttp2_hpack_compressor_destroy(exec_ctx, &t->hpack_compressor);
grpc_slice_buffer_destroy(&t->read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, &t->read_buffer);
grpc_chttp2_hpack_parser_destroy(&t->hpack_parser); grpc_chttp2_hpack_parser_destroy(exec_ctx, &t->hpack_parser);
grpc_chttp2_goaway_parser_destroy(&t->goaway_parser); grpc_chttp2_goaway_parser_destroy(&t->goaway_parser);
for (i = 0; i < STREAM_LIST_COUNT; i++) { for (i = 0; i < STREAM_LIST_COUNT; i++) {
@ -247,7 +248,7 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
grpc_combiner_scheduler(t->combiner, false)); grpc_combiner_scheduler(t->combiner, false));
grpc_chttp2_goaway_parser_init(&t->goaway_parser); grpc_chttp2_goaway_parser_init(&t->goaway_parser);
grpc_chttp2_hpack_parser_init(&t->hpack_parser); grpc_chttp2_hpack_parser_init(exec_ctx, &t->hpack_parser);
grpc_slice_buffer_init(&t->read_buffer); grpc_slice_buffer_init(&t->read_buffer);
@ -521,9 +522,11 @@ static void destroy_stream_locked(grpc_exec_ctx *exec_ctx, void *sp,
GPR_ASSERT(s->recv_message_ready == NULL); GPR_ASSERT(s->recv_message_ready == NULL);
GPR_ASSERT(s->recv_trailing_metadata_finished == NULL); GPR_ASSERT(s->recv_trailing_metadata_finished == NULL);
grpc_chttp2_data_parser_destroy(exec_ctx, &s->data_parser); grpc_chttp2_data_parser_destroy(exec_ctx, &s->data_parser);
grpc_chttp2_incoming_metadata_buffer_destroy(&s->metadata_buffer[0]); grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx,
grpc_chttp2_incoming_metadata_buffer_destroy(&s->metadata_buffer[1]); &s->metadata_buffer[0]);
grpc_slice_buffer_destroy(&s->flow_controlled_buffer); grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx,
&s->metadata_buffer[1]);
grpc_slice_buffer_destroy_internal(exec_ctx, &s->flow_controlled_buffer);
GRPC_ERROR_UNREF(s->read_closed_error); GRPC_ERROR_UNREF(s->read_closed_error);
GRPC_ERROR_UNREF(s->write_closed_error); GRPC_ERROR_UNREF(s->write_closed_error);
@ -758,7 +761,7 @@ void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx *exec_ctx,
char *msg = grpc_dump_slice(goaway_text, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *msg = grpc_dump_slice(goaway_text, GPR_DUMP_HEX | GPR_DUMP_ASCII);
GRPC_CHTTP2_IF_TRACING( GRPC_CHTTP2_IF_TRACING(
gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg)); gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg));
grpc_slice_unref(goaway_text); grpc_slice_unref_internal(exec_ctx, goaway_text);
t->seen_goaway = 1; t->seen_goaway = 1;
/* lie: use transient failure from the transport to indicate goaway has been /* lie: use transient failure from the transport to indicate goaway has been
* received */ * received */
@ -1284,7 +1287,7 @@ static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx,
if (op->send_goaway) { if (op->send_goaway) {
send_goaway(exec_ctx, t, send_goaway(exec_ctx, t,
grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), grpc_chttp2_grpc_status_to_http2_error(op->goaway_status),
grpc_slice_ref(*op->goaway_message)); grpc_slice_ref_internal(*op->goaway_message));
} }
if (op->set_accept_stream) { if (op->set_accept_stream) {
@ -1515,21 +1518,22 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
char status_string[GPR_LTOA_MIN_BUFSIZE]; char status_string[GPR_LTOA_MIN_BUFSIZE];
gpr_ltoa(status, status_string); gpr_ltoa(status, status_string);
grpc_chttp2_incoming_metadata_buffer_add( grpc_chttp2_incoming_metadata_buffer_add(
&s->metadata_buffer[1], &s->metadata_buffer[1], grpc_mdelem_from_metadata_strings(
grpc_mdelem_from_metadata_strings( exec_ctx, GRPC_MDSTR_GRPC_STATUS,
GRPC_MDSTR_GRPC_STATUS, grpc_mdstr_from_string(status_string))); grpc_mdstr_from_string(status_string)));
if (slice) { if (slice) {
grpc_chttp2_incoming_metadata_buffer_add( grpc_chttp2_incoming_metadata_buffer_add(
&s->metadata_buffer[1], &s->metadata_buffer[1],
grpc_mdelem_from_metadata_strings( grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_GRPC_MESSAGE, exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
grpc_mdstr_from_slice(grpc_slice_ref(*slice)))); grpc_mdstr_from_slice(exec_ctx,
grpc_slice_ref_internal(*slice))));
} }
s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE; s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE;
grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
} }
if (slice) { if (slice) {
grpc_slice_unref(*slice); grpc_slice_unref_internal(exec_ctx, *slice);
} }
} }
@ -1897,7 +1901,7 @@ static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp,
keep_reading = true; keep_reading = true;
GRPC_CHTTP2_REF_TRANSPORT(t, "keep_reading"); GRPC_CHTTP2_REF_TRANSPORT(t, "keep_reading");
} }
grpc_slice_buffer_reset_and_unref(&t->read_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->read_buffer);
if (keep_reading) { if (keep_reading) {
grpc_endpoint_read(exec_ctx, t->ep, &t->read_buffer, grpc_endpoint_read(exec_ctx, t->ep, &t->read_buffer,
@ -1952,7 +1956,7 @@ static void incoming_byte_stream_unref(grpc_exec_ctx *exec_ctx,
grpc_chttp2_incoming_byte_stream *bs) { grpc_chttp2_incoming_byte_stream *bs) {
if (gpr_unref(&bs->refs)) { if (gpr_unref(&bs->refs)) {
GRPC_ERROR_UNREF(bs->error); GRPC_ERROR_UNREF(bs->error);
grpc_slice_buffer_destroy(&bs->slices); grpc_slice_buffer_destroy_internal(exec_ctx, &bs->slices);
gpr_mu_destroy(&bs->slice_mu); gpr_mu_destroy(&bs->slice_mu);
gpr_free(bs); gpr_free(bs);
} }

@ -48,6 +48,7 @@
#include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/ext/transport/chttp2/transport/bin_encoder.h"
#include "src/core/ext/transport/chttp2/transport/hpack_table.h" #include "src/core/ext/transport/chttp2/transport/hpack_table.h"
#include "src/core/ext/transport/chttp2/transport/varint.h" #include "src/core/ext/transport/chttp2/transport/varint.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/metadata.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/timeout_encoding.h" #include "src/core/lib/transport/timeout_encoding.h"
@ -183,7 +184,8 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) {
} }
/* add an element to the decoder table */ /* add an element to the decoder table */
static void add_elem(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem) { static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c,
grpc_mdelem *elem) {
uint32_t key_hash = elem->key->hash; uint32_t key_hash = elem->key->hash;
uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash);
uint32_t new_index = c->tail_remote_index + c->table_elems + 1; uint32_t new_index = c->tail_remote_index + c->table_elems + 1;
@ -227,12 +229,12 @@ static void add_elem(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem) {
} else if (c->indices_elems[HASH_FRAGMENT_2(elem_hash)] < } else if (c->indices_elems[HASH_FRAGMENT_2(elem_hash)] <
c->indices_elems[HASH_FRAGMENT_3(elem_hash)]) { c->indices_elems[HASH_FRAGMENT_3(elem_hash)]) {
/* not there: replace oldest */ /* not there: replace oldest */
GRPC_MDELEM_UNREF(c->entries_elems[HASH_FRAGMENT_2(elem_hash)]); GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[HASH_FRAGMENT_2(elem_hash)]);
c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = GRPC_MDELEM_REF(elem); c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = GRPC_MDELEM_REF(elem);
c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index;
} else { } else {
/* not there: replace oldest */ /* not there: replace oldest */
GRPC_MDELEM_UNREF(c->entries_elems[HASH_FRAGMENT_3(elem_hash)]); GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[HASH_FRAGMENT_3(elem_hash)]);
c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = GRPC_MDELEM_REF(elem); c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = GRPC_MDELEM_REF(elem);
c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index;
} }
@ -251,11 +253,11 @@ static void add_elem(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem) {
c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index;
} else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] < } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] <
c->indices_keys[HASH_FRAGMENT_3(key_hash)]) { c->indices_keys[HASH_FRAGMENT_3(key_hash)]) {
GRPC_MDSTR_UNREF(c->entries_keys[HASH_FRAGMENT_2(key_hash)]); GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[HASH_FRAGMENT_2(key_hash)]);
c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key);
c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index;
} else { } else {
GRPC_MDSTR_UNREF(c->entries_keys[HASH_FRAGMENT_3(key_hash)]); GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[HASH_FRAGMENT_3(key_hash)]);
c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key);
c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index;
} }
@ -294,7 +296,7 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c,
add_tiny_header_data(st, len_pfx), len_pfx); add_tiny_header_data(st, len_pfx), len_pfx);
GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix, GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix,
add_tiny_header_data(st, len_val_len), len_val_len); add_tiny_header_data(st, len_val_len), len_val_len);
add_header_data(st, grpc_slice_ref(value_slice)); add_header_data(st, grpc_slice_ref_internal(value_slice));
} }
static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c,
@ -311,7 +313,7 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c,
add_tiny_header_data(st, len_pfx), len_pfx); add_tiny_header_data(st, len_pfx), len_pfx);
GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix, GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix,
add_tiny_header_data(st, len_val_len), len_val_len); add_tiny_header_data(st, len_val_len), len_val_len);
add_header_data(st, grpc_slice_ref(value_slice)); add_header_data(st, grpc_slice_ref_internal(value_slice));
} }
static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
@ -327,10 +329,10 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
*add_tiny_header_data(st, 1) = 0x40; *add_tiny_header_data(st, 1) = 0x40;
GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
add_tiny_header_data(st, len_key_len), len_key_len); add_tiny_header_data(st, len_key_len), len_key_len);
add_header_data(st, grpc_slice_ref(elem->key->slice)); add_header_data(st, grpc_slice_ref_internal(elem->key->slice));
GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix,
add_tiny_header_data(st, len_val_len), len_val_len); add_tiny_header_data(st, len_val_len), len_val_len);
add_header_data(st, grpc_slice_ref(value_slice)); add_header_data(st, grpc_slice_ref_internal(value_slice));
} }
static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
@ -346,10 +348,10 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
*add_tiny_header_data(st, 1) = 0x00; *add_tiny_header_data(st, 1) = 0x00;
GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
add_tiny_header_data(st, len_key_len), len_key_len); add_tiny_header_data(st, len_key_len), len_key_len);
add_header_data(st, grpc_slice_ref(elem->key->slice)); add_header_data(st, grpc_slice_ref_internal(elem->key->slice));
GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix,
add_tiny_header_data(st, len_val_len), len_val_len); add_tiny_header_data(st, len_val_len), len_val_len);
add_header_data(st, grpc_slice_ref(value_slice)); add_header_data(st, grpc_slice_ref_internal(value_slice));
} }
static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c, static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c,
@ -366,8 +368,8 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor *c, uint32_t elem_index) {
} }
/* encode an mdelem */ /* encode an mdelem */
static void hpack_enc(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c,
framer_state *st) { grpc_mdelem *elem, framer_state *st) {
uint32_t key_hash = elem->key->hash; uint32_t key_hash = elem->key->hash;
uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash);
size_t decoder_space_usage; size_t decoder_space_usage;
@ -417,7 +419,7 @@ static void hpack_enc(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem,
/* HIT: key (first cuckoo hash) */ /* HIT: key (first cuckoo hash) */
if (should_add_elem) { if (should_add_elem) {
emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st); emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st);
add_elem(c, elem); add_elem(exec_ctx, c, elem);
return; return;
} else { } else {
emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st); emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
@ -432,7 +434,7 @@ static void hpack_enc(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem,
/* HIT: key (first cuckoo hash) */ /* HIT: key (first cuckoo hash) */
if (should_add_elem) { if (should_add_elem) {
emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st); emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st);
add_elem(c, elem); add_elem(exec_ctx, c, elem);
return; return;
} else { } else {
emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st); emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
@ -445,7 +447,7 @@ static void hpack_enc(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem,
if (should_add_elem) { if (should_add_elem) {
emit_lithdr_incidx_v(c, elem, st); emit_lithdr_incidx_v(c, elem, st);
add_elem(c, elem); add_elem(exec_ctx, c, elem);
return; return;
} else { } else {
emit_lithdr_noidx_v(c, elem, st); emit_lithdr_noidx_v(c, elem, st);
@ -457,16 +459,17 @@ static void hpack_enc(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem,
#define STRLEN_LIT(x) (sizeof(x) - 1) #define STRLEN_LIT(x) (sizeof(x) - 1)
#define TIMEOUT_KEY "grpc-timeout" #define TIMEOUT_KEY "grpc-timeout"
static void deadline_enc(grpc_chttp2_hpack_compressor *c, gpr_timespec deadline, static void deadline_enc(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_compressor *c, gpr_timespec deadline,
framer_state *st) { framer_state *st) {
char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE];
grpc_mdelem *mdelem; grpc_mdelem *mdelem;
grpc_http2_encode_timeout( grpc_http2_encode_timeout(
gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str); gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str);
mdelem = grpc_mdelem_from_metadata_strings( mdelem = grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_GRPC_TIMEOUT, grpc_mdstr_from_string(timeout_str)); exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, grpc_mdstr_from_string(timeout_str));
hpack_enc(c, mdelem, st); hpack_enc(exec_ctx, c, mdelem, st);
GRPC_MDELEM_UNREF(mdelem); GRPC_MDELEM_UNREF(exec_ctx, mdelem);
} }
static uint32_t elems_for_bytes(uint32_t bytes) { return (bytes + 31) / 32; } static uint32_t elems_for_bytes(uint32_t bytes) { return (bytes + 31) / 32; }
@ -483,11 +486,12 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c) {
sizeof(*c->table_elem_size) * c->cap_table_elems); sizeof(*c->table_elem_size) * c->cap_table_elems);
} }
void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) { void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_compressor *c) {
int i; int i;
for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) {
if (c->entries_keys[i]) GRPC_MDSTR_UNREF(c->entries_keys[i]); if (c->entries_keys[i]) GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[i]);
if (c->entries_elems[i]) GRPC_MDELEM_UNREF(c->entries_elems[i]); if (c->entries_elems[i]) GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]);
} }
gpr_free(c->table_elem_size); gpr_free(c->table_elem_size);
} }
@ -542,7 +546,8 @@ void grpc_chttp2_hpack_compressor_set_max_table_size(
} }
} }
void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_compressor *c,
uint32_t stream_id, uint32_t stream_id,
grpc_metadata_batch *metadata, int is_eof, grpc_metadata_batch *metadata, int is_eof,
size_t max_frame_size, size_t max_frame_size,
@ -571,11 +576,11 @@ void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c,
} }
grpc_metadata_batch_assert_ok(metadata); grpc_metadata_batch_assert_ok(metadata);
for (l = metadata->list.head; l; l = l->next) { for (l = metadata->list.head; l; l = l->next) {
hpack_enc(c, l->md, &st); hpack_enc(exec_ctx, c, l->md, &st);
} }
deadline = metadata->deadline; deadline = metadata->deadline;
if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) != 0) { if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) != 0) {
deadline_enc(c, deadline, &st); deadline_enc(exec_ctx, c, deadline, &st);
} }
finish_frame(&st, 1, is_eof); finish_frame(&st, 1, is_eof);

@ -83,13 +83,15 @@ typedef struct {
} grpc_chttp2_hpack_compressor; } grpc_chttp2_hpack_compressor;
void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c); void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c);
void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c); void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_compressor *c);
void grpc_chttp2_hpack_compressor_set_max_table_size( void grpc_chttp2_hpack_compressor_set_max_table_size(
grpc_chttp2_hpack_compressor *c, uint32_t max_table_size); grpc_chttp2_hpack_compressor *c, uint32_t max_table_size);
void grpc_chttp2_hpack_compressor_set_max_usable_size( void grpc_chttp2_hpack_compressor_set_max_usable_size(
grpc_chttp2_hpack_compressor *c, uint32_t max_table_size); grpc_chttp2_hpack_compressor *c, uint32_t max_table_size);
void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, uint32_t id, void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_compressor *c, uint32_t id,
grpc_metadata_batch *metadata, int is_eof, grpc_metadata_batch *metadata, int is_eof,
size_t max_frame_size, size_t max_frame_size,
grpc_transport_one_way_stats *stats, grpc_transport_one_way_stats *stats,

@ -670,11 +670,11 @@ static const uint8_t inverse_base64[256] = {
static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p,
grpc_mdelem *md, int add_to_table) { grpc_mdelem *md, int add_to_table) {
if (add_to_table) { if (add_to_table) {
grpc_error *err = grpc_chttp2_hptbl_add(&p->table, md); grpc_error *err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md);
if (err != GRPC_ERROR_NONE) return err; if (err != GRPC_ERROR_NONE) return err;
} }
if (p->on_header == NULL) { if (p->on_header == NULL) {
GRPC_MDELEM_UNREF(md); GRPC_MDELEM_UNREF(exec_ctx, md);
return GRPC_ERROR_CREATE("on_header callback not set"); return GRPC_ERROR_CREATE("on_header callback not set");
} }
p->on_header(exec_ctx, p->on_header_user_data, md); p->on_header(exec_ctx, p->on_header_user_data, md);
@ -815,10 +815,10 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx,
const uint8_t *end) { const uint8_t *end) {
grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
GPR_ASSERT(md != NULL); /* handled in string parsing */ GPR_ASSERT(md != NULL); /* handled in string parsing */
grpc_error *err = on_hdr( grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings(
exec_ctx, p, grpc_mdelem_from_metadata_strings(GRPC_MDSTR_REF(md->key), exec_ctx, GRPC_MDSTR_REF(md->key),
take_string(p, &p->value)), take_string(p, &p->value)),
1); 1);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -828,10 +828,10 @@ static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_parser *p, grpc_chttp2_hpack_parser *p,
const uint8_t *cur, const uint8_t *cur,
const uint8_t *end) { const uint8_t *end) {
grpc_error *err = on_hdr( grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings(
exec_ctx, p, grpc_mdelem_from_metadata_strings(take_string(p, &p->key), exec_ctx, take_string(p, &p->key),
take_string(p, &p->value)), take_string(p, &p->value)),
1); 1);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -883,10 +883,10 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx,
const uint8_t *end) { const uint8_t *end) {
grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
GPR_ASSERT(md != NULL); /* handled in string parsing */ GPR_ASSERT(md != NULL); /* handled in string parsing */
grpc_error *err = on_hdr( grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings(
exec_ctx, p, grpc_mdelem_from_metadata_strings(GRPC_MDSTR_REF(md->key), exec_ctx, GRPC_MDSTR_REF(md->key),
take_string(p, &p->value)), take_string(p, &p->value)),
0); 0);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -896,10 +896,10 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_parser *p, grpc_chttp2_hpack_parser *p,
const uint8_t *cur, const uint8_t *cur,
const uint8_t *end) { const uint8_t *end) {
grpc_error *err = on_hdr( grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings(
exec_ctx, p, grpc_mdelem_from_metadata_strings(take_string(p, &p->key), exec_ctx, take_string(p, &p->key),
take_string(p, &p->value)), take_string(p, &p->value)),
0); 0);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -951,10 +951,10 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx,
const uint8_t *end) { const uint8_t *end) {
grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
GPR_ASSERT(md != NULL); /* handled in string parsing */ GPR_ASSERT(md != NULL); /* handled in string parsing */
grpc_error *err = on_hdr( grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings(
exec_ctx, p, grpc_mdelem_from_metadata_strings(GRPC_MDSTR_REF(md->key), exec_ctx, GRPC_MDSTR_REF(md->key),
take_string(p, &p->value)), take_string(p, &p->value)),
0); 0);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -964,10 +964,10 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_parser *p, grpc_chttp2_hpack_parser *p,
const uint8_t *cur, const uint8_t *cur,
const uint8_t *end) { const uint8_t *end) {
grpc_error *err = on_hdr( grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings(
exec_ctx, p, grpc_mdelem_from_metadata_strings(take_string(p, &p->key), exec_ctx, take_string(p, &p->key),
take_string(p, &p->value)), take_string(p, &p->value)),
0); 0);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -1020,7 +1020,7 @@ static grpc_error *finish_max_tbl_size(grpc_exec_ctx *exec_ctx,
gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index);
} }
grpc_error *err = grpc_error *err =
grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index); grpc_chttp2_hptbl_set_current_table_size(exec_ctx, &p->table, p->index);
if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err);
return parse_begin(exec_ctx, p, cur, end); return parse_begin(exec_ctx, p, cur, end);
} }
@ -1534,7 +1534,8 @@ static grpc_error *parse_value_string_with_literal_key(
/* PUBLIC INTERFACE */ /* PUBLIC INTERFACE */
void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p) { void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_parser *p) {
p->on_header = NULL; p->on_header = NULL;
p->on_header_user_data = NULL; p->on_header_user_data = NULL;
p->state = parse_begin; p->state = parse_begin;
@ -1546,7 +1547,7 @@ void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p) {
p->value.length = 0; p->value.length = 0;
p->dynamic_table_update_allowed = 2; p->dynamic_table_update_allowed = 2;
p->last_error = GRPC_ERROR_NONE; p->last_error = GRPC_ERROR_NONE;
grpc_chttp2_hptbl_init(&p->table); grpc_chttp2_hptbl_init(exec_ctx, &p->table);
} }
void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) { void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) {
@ -1554,8 +1555,9 @@ void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) {
p->state = parse_stream_dep0; p->state = parse_stream_dep0;
} }
void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p) { void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl_destroy(&p->table); grpc_chttp2_hpack_parser *p) {
grpc_chttp2_hptbl_destroy(exec_ctx, &p->table);
GRPC_ERROR_UNREF(p->last_error); GRPC_ERROR_UNREF(p->last_error);
gpr_free(p->key.str); gpr_free(p->key.str);
gpr_free(p->value.str); gpr_free(p->value.str);

@ -99,8 +99,10 @@ struct grpc_chttp2_hpack_parser {
grpc_chttp2_hptbl table; grpc_chttp2_hptbl table;
}; };
void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p); void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx,
void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p); grpc_chttp2_hpack_parser *p);
void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hpack_parser *p);
void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p);

@ -179,7 +179,7 @@ static uint32_t entries_for_bytes(uint32_t bytes) {
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
} }
void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl) { void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) {
size_t i; size_t i;
memset(tbl, 0, sizeof(*tbl)); memset(tbl, 0, sizeof(*tbl));
@ -190,18 +190,20 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl) {
tbl->ents = gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries); tbl->ents = gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries);
memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries);
for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
tbl->static_ents[i - 1] = tbl->static_ents[i - 1] = grpc_mdelem_from_strings(
grpc_mdelem_from_strings(static_table[i].key, static_table[i].value); exec_ctx, static_table[i].key, static_table[i].value);
} }
} }
void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl) { void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl) {
size_t i; size_t i;
for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
GRPC_MDELEM_UNREF(tbl->static_ents[i]); GRPC_MDELEM_UNREF(exec_ctx, tbl->static_ents[i]);
} }
for (i = 0; i < tbl->num_ents; i++) { for (i = 0; i < tbl->num_ents; i++) {
GRPC_MDELEM_UNREF(tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]); GRPC_MDELEM_UNREF(exec_ctx,
tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]);
} }
gpr_free(tbl->ents); gpr_free(tbl->ents);
} }
@ -224,7 +226,7 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
} }
/* Evict one element from the table */ /* Evict one element from the table */
static void evict1(grpc_chttp2_hptbl *tbl) { static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) {
grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; grpc_mdelem *first_ent = tbl->ents[tbl->first_ent];
size_t elem_bytes = GRPC_SLICE_LENGTH(first_ent->key->slice) + size_t elem_bytes = GRPC_SLICE_LENGTH(first_ent->key->slice) +
GRPC_SLICE_LENGTH(first_ent->value->slice) + GRPC_SLICE_LENGTH(first_ent->value->slice) +
@ -233,7 +235,7 @@ static void evict1(grpc_chttp2_hptbl *tbl) {
tbl->mem_used -= (uint32_t)elem_bytes; tbl->mem_used -= (uint32_t)elem_bytes;
tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries); tbl->first_ent = ((tbl->first_ent + 1) % tbl->cap_entries);
tbl->num_ents--; tbl->num_ents--;
GRPC_MDELEM_UNREF(first_ent); GRPC_MDELEM_UNREF(exec_ctx, first_ent);
} }
static void rebuild_ents(grpc_chttp2_hptbl *tbl, uint32_t new_cap) { static void rebuild_ents(grpc_chttp2_hptbl *tbl, uint32_t new_cap) {
@ -249,7 +251,8 @@ static void rebuild_ents(grpc_chttp2_hptbl *tbl, uint32_t new_cap) {
tbl->first_ent = 0; tbl->first_ent = 0;
} }
void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl, void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl,
uint32_t max_bytes) { uint32_t max_bytes) {
if (tbl->max_bytes == max_bytes) { if (tbl->max_bytes == max_bytes) {
return; return;
@ -258,12 +261,13 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl,
gpr_log(GPR_DEBUG, "Update hpack parser max size to %d", max_bytes); gpr_log(GPR_DEBUG, "Update hpack parser max size to %d", max_bytes);
} }
while (tbl->mem_used > max_bytes) { while (tbl->mem_used > max_bytes) {
evict1(tbl); evict1(exec_ctx, tbl);
} }
tbl->max_bytes = max_bytes; tbl->max_bytes = max_bytes;
} }
grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl, grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl,
uint32_t bytes) { uint32_t bytes) {
if (tbl->current_table_bytes == bytes) { if (tbl->current_table_bytes == bytes) {
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
@ -281,7 +285,7 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes); gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes);
} }
while (tbl->mem_used > bytes) { while (tbl->mem_used > bytes) {
evict1(tbl); evict1(exec_ctx, tbl);
} }
tbl->current_table_bytes = bytes; tbl->current_table_bytes = bytes;
tbl->max_entries = entries_for_bytes(bytes); tbl->max_entries = entries_for_bytes(bytes);
@ -296,7 +300,8 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
grpc_error *grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
/* determine how many bytes of buffer this entry represents */ /* determine how many bytes of buffer this entry represents */
size_t elem_bytes = GRPC_SLICE_LENGTH(md->key->slice) + size_t elem_bytes = GRPC_SLICE_LENGTH(md->key->slice) +
GRPC_SLICE_LENGTH(md->value->slice) + GRPC_SLICE_LENGTH(md->value->slice) +
@ -326,14 +331,14 @@ grpc_error *grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
* empty table. * empty table.
*/ */
while (tbl->num_ents) { while (tbl->num_ents) {
evict1(tbl); evict1(exec_ctx, tbl);
} }
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
/* evict entries to ensure no overflow */ /* evict entries to ensure no overflow */
while (elem_bytes > (size_t)tbl->current_table_bytes - tbl->mem_used) { while (elem_bytes > (size_t)tbl->current_table_bytes - tbl->mem_used) {
evict1(tbl); evict1(exec_ctx, tbl);
} }
/* copy the finalized entry in */ /* copy the finalized entry in */

@ -84,18 +84,21 @@ typedef struct {
} grpc_chttp2_hptbl; } grpc_chttp2_hptbl;
/* initialize a hpack table */ /* initialize a hpack table */
void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl); void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl);
void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl); void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl);
void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl, void grpc_chttp2_hptbl_set_max_bytes(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl,
uint32_t max_bytes); uint32_t max_bytes);
grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl, grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl,
uint32_t bytes); uint32_t bytes);
/* lookup a table entry based on its hpack index */ /* lookup a table entry based on its hpack index */
grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
uint32_t index); uint32_t index);
/* add a table entry to the index */ /* add a table entry to the index */
grpc_error *grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx,
grpc_chttp2_hptbl *tbl,
grpc_mdelem *md) GRPC_MUST_USE_RESULT; grpc_mdelem *md) GRPC_MUST_USE_RESULT;
/* Find a key/value pair in the table... returns the index in the table of the /* Find a key/value pair in the table... returns the index in the table of the
most similar entry, or 0 if the value was not found */ most similar entry, or 0 if the value was not found */

@ -46,11 +46,11 @@ void grpc_chttp2_incoming_metadata_buffer_init(
} }
void grpc_chttp2_incoming_metadata_buffer_destroy( void grpc_chttp2_incoming_metadata_buffer_destroy(
grpc_chttp2_incoming_metadata_buffer *buffer) { grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer) {
size_t i; size_t i;
if (!buffer->published) { if (!buffer->published) {
for (i = 0; i < buffer->count; i++) { for (i = 0; i < buffer->count; i++) {
GRPC_MDELEM_UNREF(buffer->elems[i].md); GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md);
} }
} }
gpr_free(buffer->elems); gpr_free(buffer->elems);

@ -49,7 +49,7 @@ typedef struct {
void grpc_chttp2_incoming_metadata_buffer_init( void grpc_chttp2_incoming_metadata_buffer_init(
grpc_chttp2_incoming_metadata_buffer *buffer); grpc_chttp2_incoming_metadata_buffer *buffer);
void grpc_chttp2_incoming_metadata_buffer_destroy( void grpc_chttp2_incoming_metadata_buffer_destroy(
grpc_chttp2_incoming_metadata_buffer *buffer); grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer);
void grpc_chttp2_incoming_metadata_buffer_publish( void grpc_chttp2_incoming_metadata_buffer_publish(
grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch); grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch);

@ -336,7 +336,7 @@ static grpc_error *skip_parser(grpc_exec_ctx *exec_ctx, void *parser,
} }
static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem *md) { static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem *md) {
GRPC_MDELEM_UNREF(md); GRPC_MDELEM_UNREF(exec_ctx, md);
} }
static grpc_error *init_skip_frame_parser(grpc_exec_ctx *exec_ctx, static grpc_error *init_skip_frame_parser(grpc_exec_ctx *exec_ctx,
@ -477,7 +477,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp,
grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer_set_deadline(
&s->metadata_buffer[0], &s->metadata_buffer[0],
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout)); gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout));
GRPC_MDELEM_UNREF(md); GRPC_MDELEM_UNREF(exec_ctx, md);
} else { } else {
const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md); const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md);
const size_t metadata_size_limit = const size_t metadata_size_limit =
@ -495,7 +495,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp,
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED));
grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); grpc_chttp2_parsing_become_skip_parser(exec_ctx, t);
s->seen_error = true; s->seen_error = true;
GRPC_MDELEM_UNREF(md); GRPC_MDELEM_UNREF(exec_ctx, md);
} else { } else {
grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[0], md); grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[0], md);
} }
@ -538,7 +538,7 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp,
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED)); GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED));
grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); grpc_chttp2_parsing_become_skip_parser(exec_ctx, t);
s->seen_error = true; s->seen_error = true;
GRPC_MDELEM_UNREF(md); GRPC_MDELEM_UNREF(exec_ctx, md);
} else { } else {
grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[1], md); grpc_chttp2_incoming_metadata_buffer_add(&s->metadata_buffer[1], md);
} }
@ -712,7 +712,7 @@ static grpc_error *init_settings_frame_parser(grpc_exec_ctx *exec_ctx,
memcpy(t->settings[GRPC_ACKED_SETTINGS], t->settings[GRPC_SENT_SETTINGS], memcpy(t->settings[GRPC_ACKED_SETTINGS], t->settings[GRPC_SENT_SETTINGS],
GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t)); GRPC_CHTTP2_NUM_SETTINGS * sizeof(uint32_t));
grpc_chttp2_hptbl_set_max_bytes( grpc_chttp2_hptbl_set_max_bytes(
&t->hpack_parser.table, exec_ctx, &t->hpack_parser.table,
t->settings[GRPC_ACKED_SETTINGS] t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]); [GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE]);
t->sent_local_settings = 0; t->sent_local_settings = 0;

@ -39,6 +39,7 @@
#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/ext/transport/chttp2/transport/http2_errors.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
static void add_to_write_list(grpc_chttp2_write_cb **list, static void add_to_write_list(grpc_chttp2_write_cb **list,
grpc_chttp2_write_cb *cb) { grpc_chttp2_write_cb *cb) {
@ -119,7 +120,7 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx,
/* send initial metadata if it's available */ /* send initial metadata if it's available */
if (!sent_initial_metadata && s->send_initial_metadata) { if (!sent_initial_metadata && s->send_initial_metadata) {
grpc_chttp2_encode_header( grpc_chttp2_encode_header(
&t->hpack_compressor, s->id, s->send_initial_metadata, 0, exec_ctx, &t->hpack_compressor, s->id, s->send_initial_metadata, 0,
t->settings[GRPC_ACKED_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], t->settings[GRPC_ACKED_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE],
&s->stats.outgoing, &t->outbuf); &s->stats.outgoing, &t->outbuf);
s->send_initial_metadata = NULL; s->send_initial_metadata = NULL;
@ -186,9 +187,9 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx,
&s->stats.outgoing, &t->outbuf); &s->stats.outgoing, &t->outbuf);
} else { } else {
grpc_chttp2_encode_header( grpc_chttp2_encode_header(
&t->hpack_compressor, s->id, s->send_trailing_metadata, true, exec_ctx, &t->hpack_compressor, s->id, s->send_trailing_metadata,
t->settings[GRPC_ACKED_SETTINGS] true, t->settings[GRPC_ACKED_SETTINGS]
[GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE], [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE],
&s->stats.outgoing, &t->outbuf); &s->stats.outgoing, &t->outbuf);
} }
s->send_trailing_metadata = NULL; s->send_trailing_metadata = NULL;
@ -254,7 +255,7 @@ void grpc_chttp2_end_write(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
} }
GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:end"); GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:end");
} }
grpc_slice_buffer_reset_and_unref(&t->outbuf); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->outbuf);
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
GPR_TIMER_END("grpc_chttp2_end_write", 0); GPR_TIMER_END("grpc_chttp2_end_write", 0);
} }

@ -427,6 +427,7 @@ static void on_response_headers_received(
cronet_bidirectional_stream *stream, cronet_bidirectional_stream *stream,
const cronet_bidirectional_stream_header_array *headers, const cronet_bidirectional_stream_header_array *headers,
const char *negotiated_protocol) { const char *negotiated_protocol) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream,
headers, negotiated_protocol); headers, negotiated_protocol);
stream_obj *s = (stream_obj *)stream->annotation; stream_obj *s = (stream_obj *)stream->annotation;
@ -438,7 +439,7 @@ static void on_response_headers_received(
grpc_chttp2_incoming_metadata_buffer_add( grpc_chttp2_incoming_metadata_buffer_add(
&s->state.rs.initial_metadata, &s->state.rs.initial_metadata,
grpc_mdelem_from_metadata_strings( grpc_mdelem_from_metadata_strings(
grpc_mdstr_from_string(headers->headers[i].key), &exec_ctx, grpc_mdstr_from_string(headers->headers[i].key),
grpc_mdstr_from_string(headers->headers[i].value))); grpc_mdstr_from_string(headers->headers[i].value)));
} }
s->state.state_callback_received[OP_RECV_INITIAL_METADATA] = true; s->state.state_callback_received[OP_RECV_INITIAL_METADATA] = true;
@ -455,6 +456,7 @@ static void on_response_headers_received(
s->state.rs.remaining_bytes); s->state.rs.remaining_bytes);
} }
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
grpc_exec_ctx_finish(&exec_ctx);
execute_from_storage(s); execute_from_storage(s);
} }
@ -520,6 +522,7 @@ static void on_read_completed(cronet_bidirectional_stream *stream, char *data,
static void on_response_trailers_received( static void on_response_trailers_received(
cronet_bidirectional_stream *stream, cronet_bidirectional_stream *stream,
const cronet_bidirectional_stream_header_array *trailers) { const cronet_bidirectional_stream_header_array *trailers) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream,
trailers); trailers);
stream_obj *s = (stream_obj *)stream->annotation; stream_obj *s = (stream_obj *)stream->annotation;
@ -534,7 +537,7 @@ static void on_response_trailers_received(
grpc_chttp2_incoming_metadata_buffer_add( grpc_chttp2_incoming_metadata_buffer_add(
&s->state.rs.trailing_metadata, &s->state.rs.trailing_metadata,
grpc_mdelem_from_metadata_strings( grpc_mdelem_from_metadata_strings(
grpc_mdstr_from_string(trailers->headers[i].key), &exec_ctx, grpc_mdstr_from_string(trailers->headers[i].key),
grpc_mdstr_from_string(trailers->headers[i].value))); grpc_mdstr_from_string(trailers->headers[i].value)));
s->state.rs.trailing_metadata_valid = true; s->state.rs.trailing_metadata_valid = true;
if (0 == strcmp(trailers->headers[i].key, "grpc-status") && if (0 == strcmp(trailers->headers[i].key, "grpc-status") &&
@ -554,8 +557,10 @@ static void on_response_trailers_received(
s->state.state_op_done[OP_SEND_TRAILING_METADATA] = true; s->state.state_op_done[OP_SEND_TRAILING_METADATA] = true;
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
grpc_exec_ctx_finish(&exec_ctx);
} else { } else {
gpr_mu_unlock(&s->mu); gpr_mu_unlock(&s->mu);
grpc_exec_ctx_finish(&exec_ctx);
execute_from_storage(s); execute_from_storage(s);
} }
} }

@ -184,7 +184,7 @@ grpc_channel_args *grpc_channel_args_normalize(const grpc_channel_args *a) {
return b; return b;
} }
void grpc_channel_args_destroy(grpc_channel_args *a) { void grpc_channel_args_destroy(grpc_exec_ctx *exec_ctx, grpc_channel_args *a) {
size_t i; size_t i;
if (!a) return; if (!a) return;
for (i = 0; i < a->num_args; i++) { for (i = 0; i < a->num_args; i++) {
@ -195,7 +195,8 @@ void grpc_channel_args_destroy(grpc_channel_args *a) {
case GRPC_ARG_INTEGER: case GRPC_ARG_INTEGER:
break; break;
case GRPC_ARG_POINTER: case GRPC_ARG_POINTER:
a->args[i].value.pointer.vtable->destroy(a->args[i].value.pointer.p); a->args[i].value.pointer.vtable->destroy(exec_ctx,
a->args[i].value.pointer.p);
break; break;
} }
gpr_free(a->args[i].key); gpr_free(a->args[i].key);
@ -249,7 +250,8 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args *a,
} }
grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
grpc_channel_args **a, grpc_compression_algorithm algorithm, int state) { grpc_exec_ctx *exec_ctx, grpc_channel_args **a,
grpc_compression_algorithm algorithm, int state) {
int *states_arg = NULL; int *states_arg = NULL;
grpc_channel_args *result = *a; grpc_channel_args *result = *a;
const int states_arg_found = const int states_arg_found =
@ -282,7 +284,7 @@ grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm); GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm);
} }
result = grpc_channel_args_copy_and_add(*a, &tmp, 1); result = grpc_channel_args_copy_and_add(*a, &tmp, 1);
grpc_channel_args_destroy(*a); grpc_channel_args_destroy(exec_ctx, *a);
*a = result; *a = result;
} }
return result; return result;

@ -68,7 +68,7 @@ grpc_channel_args *grpc_channel_args_merge(const grpc_channel_args *a,
const grpc_channel_args *b); const grpc_channel_args *b);
/** Destroy arguments created by \a grpc_channel_args_copy */ /** Destroy arguments created by \a grpc_channel_args_copy */
void grpc_channel_args_destroy(grpc_channel_args *a); void grpc_channel_args_destroy(grpc_exec_ctx *exec_ctx, grpc_channel_args *a);
/** Returns the compression algorithm set in \a a. */ /** Returns the compression algorithm set in \a a. */
grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( grpc_compression_algorithm grpc_channel_args_get_compression_algorithm(
@ -88,7 +88,8 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm(
* modified to point to the returned instance (which may be different from the * modified to point to the returned instance (which may be different from the
* input value of \a a). */ * input value of \a a). */
grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( grpc_channel_args *grpc_channel_args_compression_algorithm_set_state(
grpc_channel_args **a, grpc_compression_algorithm algorithm, int enabled); grpc_exec_ctx *exec_ctx, grpc_channel_args **a,
grpc_compression_algorithm algorithm, int enabled);
/** Returns the bitset representing the support state (true for enabled, false /** Returns the bitset representing the support state (true for enabled, false
* for disabled) for compression algorithms. * for disabled) for compression algorithms.

@ -310,7 +310,7 @@ void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx,
memset(op, 0, sizeof(*op)); memset(op, 0, sizeof(*op));
op->on_complete = op->on_complete =
grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx);
grpc_transport_stream_op_add_cancellation_with_message(op, status, grpc_transport_stream_op_add_cancellation_with_message(exec_ctx, op, status,
optional_message); optional_message);
elem->filter->start_transport_stream_op(exec_ctx, elem, op); elem->filter->start_transport_stream_op(exec_ctx, elem, op);
} }
@ -323,6 +323,6 @@ void grpc_call_element_send_close_with_message(grpc_exec_ctx *exec_ctx,
memset(op, 0, sizeof(*op)); memset(op, 0, sizeof(*op));
op->on_complete = op->on_complete =
grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx);
grpc_transport_stream_op_add_close(op, status, optional_message); grpc_transport_stream_op_add_close(exec_ctx, op, status, optional_message);
elem->filter->start_transport_stream_op(exec_ctx, elem, op); elem->filter->start_transport_stream_op(exec_ctx, elem, op);
} }

@ -138,9 +138,10 @@ void grpc_channel_stack_builder_set_name(grpc_channel_stack_builder *builder,
} }
void grpc_channel_stack_builder_set_channel_arguments( void grpc_channel_stack_builder_set_channel_arguments(
grpc_channel_stack_builder *builder, const grpc_channel_args *args) { grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder,
const grpc_channel_args *args) {
if (builder->args != NULL) { if (builder->args != NULL) {
grpc_channel_args_destroy(builder->args); grpc_channel_args_destroy(exec_ctx, builder->args);
} }
builder->args = grpc_channel_args_copy(args); builder->args = grpc_channel_args_copy(args);
} }
@ -213,7 +214,8 @@ bool grpc_channel_stack_builder_add_filter_after(
return true; return true;
} }
void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder *builder) { void grpc_channel_stack_builder_destroy(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder) {
filter_node *p = builder->begin.next; filter_node *p = builder->begin.next;
while (p != &builder->end) { while (p != &builder->end) {
filter_node *next = p->next; filter_node *next = p->next;
@ -221,7 +223,7 @@ void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder *builder) {
p = next; p = next;
} }
if (builder->args != NULL) { if (builder->args != NULL) {
grpc_channel_args_destroy(builder->args); grpc_channel_args_destroy(exec_ctx, builder->args);
} }
gpr_free(builder->target); gpr_free(builder->target);
gpr_free(builder); gpr_free(builder);
@ -276,7 +278,7 @@ grpc_error *grpc_channel_stack_builder_finish(
} }
} }
grpc_channel_stack_builder_destroy(builder); grpc_channel_stack_builder_destroy(exec_ctx, builder);
gpr_free((grpc_channel_filter **)filters); gpr_free((grpc_channel_filter **)filters);
return error; return error;

@ -73,7 +73,8 @@ grpc_transport *grpc_channel_stack_builder_get_transport(
/// Set channel arguments: copies args /// Set channel arguments: copies args
void grpc_channel_stack_builder_set_channel_arguments( void grpc_channel_stack_builder_set_channel_arguments(
grpc_channel_stack_builder *builder, const grpc_channel_args *args); grpc_exec_ctx *exec_ctx, grpc_channel_stack_builder *builder,
const grpc_channel_args *args);
/// Return a borrowed pointer to the channel arguments /// Return a borrowed pointer to the channel arguments
const grpc_channel_args *grpc_channel_stack_builder_get_channel_arguments( const grpc_channel_args *grpc_channel_stack_builder_get_channel_arguments(
@ -157,7 +158,8 @@ grpc_error *grpc_channel_stack_builder_finish(
void *destroy_arg, void **result); void *destroy_arg, void **result);
/// Destroy the builder without creating a channel stack /// Destroy the builder without creating a channel stack
void grpc_channel_stack_builder_destroy(grpc_channel_stack_builder *builder); void grpc_channel_stack_builder_destroy(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder);
extern int grpc_trace_channel_stack_builder; extern int grpc_trace_channel_stack_builder;

@ -44,6 +44,7 @@
#include "src/core/lib/compression/algorithm_metadata.h" #include "src/core/lib/compression/algorithm_metadata.h"
#include "src/core/lib/compression/message_compress.h" #include "src/core/lib/compression/message_compress.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
@ -82,7 +83,8 @@ typedef struct channel_data {
/** For each \a md element from the incoming metadata, filter out the entry for /** For each \a md element from the incoming metadata, filter out the entry for
* "grpc-encoding", using its value to populate the call data's * "grpc-encoding", using its value to populate the call data's
* compression_algorithm field. */ * compression_algorithm field. */
static grpc_mdelem *compression_md_filter(void *user_data, grpc_mdelem *md) { static grpc_mdelem *compression_md_filter(grpc_exec_ctx *exec_ctx,
void *user_data, grpc_mdelem *md) {
grpc_call_element *elem = user_data; grpc_call_element *elem = user_data;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
channel_data *channeld = elem->channel_data; channel_data *channeld = elem->channel_data;
@ -130,12 +132,14 @@ static int skip_compression(grpc_call_element *elem, uint32_t flags) {
/** Filter initial metadata */ /** Filter initial metadata */
static void process_send_initial_metadata( static void process_send_initial_metadata(
grpc_call_element *elem, grpc_metadata_batch *initial_metadata) { grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
grpc_metadata_batch *initial_metadata) {
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
channel_data *channeld = elem->channel_data; channel_data *channeld = elem->channel_data;
/* Parse incoming request for compression. If any, it'll be available /* Parse incoming request for compression. If any, it'll be available
* at calld->compression_algorithm */ * at calld->compression_algorithm */
grpc_metadata_batch_filter(initial_metadata, compression_md_filter, elem); grpc_metadata_batch_filter(exec_ctx, initial_metadata, compression_md_filter,
elem);
if (!calld->has_compression_algorithm) { if (!calld->has_compression_algorithm) {
/* If no algorithm was found in the metadata and we aren't /* If no algorithm was found in the metadata and we aren't
* exceptionally skipping compression, fall back to the channel * exceptionally skipping compression, fall back to the channel
@ -161,7 +165,7 @@ static void continue_send_message(grpc_exec_ctx *exec_ctx,
static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) {
grpc_call_element *elem = elemp; grpc_call_element *elem = elemp;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_slice_buffer_reset_and_unref(&calld->slices); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &calld->slices);
calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error); calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error);
} }
@ -171,8 +175,8 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
int did_compress; int did_compress;
grpc_slice_buffer tmp; grpc_slice_buffer tmp;
grpc_slice_buffer_init(&tmp); grpc_slice_buffer_init(&tmp);
did_compress = did_compress = grpc_msg_compress(exec_ctx, calld->compression_algorithm,
grpc_msg_compress(calld->compression_algorithm, &calld->slices, &tmp); &calld->slices, &tmp);
if (did_compress) { if (did_compress) {
if (grpc_compression_trace) { if (grpc_compression_trace) {
char *algo_name; char *algo_name;
@ -199,7 +203,7 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
} }
} }
grpc_slice_buffer_destroy(&tmp); grpc_slice_buffer_destroy_internal(exec_ctx, &tmp);
grpc_slice_buffer_stream_init(&calld->replacement_stream, &calld->slices, grpc_slice_buffer_stream_init(&calld->replacement_stream, &calld->slices,
calld->send_flags); calld->send_flags);
@ -243,7 +247,7 @@ static void compress_start_transport_stream_op(grpc_exec_ctx *exec_ctx,
GPR_TIMER_BEGIN("compress_start_transport_stream_op", 0); GPR_TIMER_BEGIN("compress_start_transport_stream_op", 0);
if (op->send_initial_metadata) { if (op->send_initial_metadata) {
process_send_initial_metadata(elem, op->send_initial_metadata); process_send_initial_metadata(exec_ctx, elem, op->send_initial_metadata);
} }
if (op->send_message != NULL && if (op->send_message != NULL &&
!skip_compression(elem, op->send_message->flags)) { !skip_compression(elem, op->send_message->flags)) {
@ -283,7 +287,7 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
void *ignored) { void *ignored) {
/* grab pointers to our data from the call element */ /* grab pointers to our data from the call element */
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_slice_buffer_destroy(&calld->slices); grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices);
} }
/* Constructor for channel_data */ /* Constructor for channel_data */

@ -171,7 +171,8 @@ static void bind_transport(grpc_channel_stack *channel_stack,
channel_stack->call_stack_size += grpc_transport_stream_size(t); channel_stack->call_stack_size += grpc_transport_stream_size(t);
} }
bool grpc_add_connected_filter(grpc_channel_stack_builder *builder, bool grpc_add_connected_filter(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder,
void *arg_must_be_null) { void *arg_must_be_null) {
GPR_ASSERT(arg_must_be_null == NULL); GPR_ASSERT(arg_must_be_null == NULL);
grpc_transport *t = grpc_channel_stack_builder_get_transport(builder); grpc_transport *t = grpc_channel_stack_builder_get_transport(builder);

@ -36,7 +36,8 @@
#include "src/core/lib/channel/channel_stack_builder.h" #include "src/core/lib/channel/channel_stack_builder.h"
bool grpc_add_connected_filter(grpc_channel_stack_builder *builder, bool grpc_add_connected_filter(grpc_exec_ctx *exec_ctx,
grpc_channel_stack_builder *builder,
void *arg_must_be_null); void *arg_must_be_null);
#endif /* GRPC_CORE_LIB_CHANNEL_CONNECTED_CHANNEL_H */ #endif /* GRPC_CORE_LIB_CHANNEL_CONNECTED_CHANNEL_H */

@ -41,6 +41,7 @@
#include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/slice/slice_internal.h"
// //
// grpc_deadline_state // grpc_deadline_state
@ -58,7 +59,7 @@ static void timer_callback(grpc_exec_ctx* exec_ctx, void* arg,
grpc_slice msg = grpc_slice_from_static_string("Deadline Exceeded"); grpc_slice msg = grpc_slice_from_static_string("Deadline Exceeded");
grpc_call_element_send_cancel_with_message( grpc_call_element_send_cancel_with_message(
exec_ctx, elem, GRPC_STATUS_DEADLINE_EXCEEDED, &msg); exec_ctx, elem, GRPC_STATUS_DEADLINE_EXCEEDED, &msg);
grpc_slice_unref(msg); grpc_slice_unref_internal(exec_ctx, msg);
} }
GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer"); GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer");
} }

@ -37,6 +37,7 @@
#include <string.h> #include <string.h>
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/percent_encoding.h" #include "src/core/lib/slice/percent_encoding.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/transport_impl.h" #include "src/core/lib/transport/transport_impl.h"
@ -92,13 +93,9 @@ typedef struct channel_data {
size_t max_payload_size_for_get; size_t max_payload_size_for_get;
} channel_data; } channel_data;
typedef struct { static grpc_mdelem *client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data,
grpc_call_element *elem; grpc_mdelem *md) {
grpc_exec_ctx *exec_ctx; grpc_call_element *elem = user_data;
} client_recv_filter_args;
static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) {
client_recv_filter_args *a = user_data;
if (md == GRPC_MDELEM_STATUS_200) { if (md == GRPC_MDELEM_STATUS_200) {
return NULL; return NULL;
} else if (md->key == GRPC_MDSTR_STATUS) { } else if (md->key == GRPC_MDSTR_STATUS) {
@ -107,18 +104,19 @@ static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) {
grpc_mdstr_as_c_string(md->value)); grpc_mdstr_as_c_string(md->value));
grpc_slice message = grpc_slice_from_copied_string(message_string); grpc_slice message = grpc_slice_from_copied_string(message_string);
gpr_free(message_string); gpr_free(message_string);
grpc_call_element_send_close_with_message(a->exec_ctx, a->elem, grpc_call_element_send_close_with_message(exec_ctx, elem,
GRPC_STATUS_CANCELLED, &message); GRPC_STATUS_CANCELLED, &message);
return NULL; return NULL;
} else if (md->key == GRPC_MDSTR_GRPC_MESSAGE) { } else if (md->key == GRPC_MDSTR_GRPC_MESSAGE) {
grpc_slice pct_decoded_msg = grpc_slice pct_decoded_msg =
grpc_permissive_percent_decode_slice(md->value->slice); grpc_permissive_percent_decode_slice(md->value->slice);
if (grpc_slice_is_equivalent(pct_decoded_msg, md->value->slice)) { if (grpc_slice_is_equivalent(pct_decoded_msg, md->value->slice)) {
grpc_slice_unref(pct_decoded_msg); grpc_slice_unref_internal(exec_ctx, pct_decoded_msg);
return md; return md;
} else { } else {
return grpc_mdelem_from_metadata_strings( return grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_GRPC_MESSAGE, grpc_mdstr_from_slice(pct_decoded_msg)); exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
grpc_mdstr_from_slice(exec_ctx, pct_decoded_msg));
} }
} else if (md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) { } else if (md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) {
return NULL; return NULL;
@ -147,11 +145,8 @@ static void hc_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx,
void *user_data, grpc_error *error) { void *user_data, grpc_error *error) {
grpc_call_element *elem = user_data; grpc_call_element *elem = user_data;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
client_recv_filter_args a; grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata,
a.elem = elem; client_recv_filter, elem);
a.exec_ctx = exec_ctx;
grpc_metadata_batch_filter(calld->recv_initial_metadata, client_recv_filter,
&a);
grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
} }
@ -160,11 +155,8 @@ static void hc_on_recv_trailing_metadata(grpc_exec_ctx *exec_ctx,
void *user_data, grpc_error *error) { void *user_data, grpc_error *error) {
grpc_call_element *elem = user_data; grpc_call_element *elem = user_data;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
client_recv_filter_args a; grpc_metadata_batch_filter(exec_ctx, calld->recv_trailing_metadata,
a.elem = elem; client_recv_filter, elem);
a.exec_ctx = exec_ctx;
grpc_metadata_batch_filter(calld->recv_trailing_metadata, client_recv_filter,
&a);
grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata, grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata,
GRPC_ERROR_REF(error)); GRPC_ERROR_REF(error));
} }
@ -183,11 +175,12 @@ static void hc_on_complete(grpc_exec_ctx *exec_ctx, void *user_data,
static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) {
grpc_call_element *elem = elemp; grpc_call_element *elem = elemp;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_slice_buffer_reset_and_unref(&calld->slices); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &calld->slices);
calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error); calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error);
} }
static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) { static grpc_mdelem *client_strip_filter(grpc_exec_ctx *exec_ctx,
void *user_data, grpc_mdelem *md) {
/* eat the things we'd like to set ourselves */ /* eat the things we'd like to set ourselves */
if (md->key == GRPC_MDSTR_METHOD) return NULL; if (md->key == GRPC_MDSTR_METHOD) return NULL;
if (md->key == GRPC_MDSTR_SCHEME) return NULL; if (md->key == GRPC_MDSTR_SCHEME) return NULL;
@ -275,7 +268,7 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
/* when all the send_message data is available, then create a MDELEM and /* when all the send_message data is available, then create a MDELEM and
append to headers */ append to headers */
grpc_mdelem *payload_bin = grpc_mdelem_from_metadata_strings( grpc_mdelem *payload_bin = grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_GRPC_PAYLOAD_BIN, exec_ctx, GRPC_MDSTR_GRPC_PAYLOAD_BIN,
grpc_mdstr_from_buffer(calld->payload_bytes, grpc_mdstr_from_buffer(calld->payload_bytes,
op->send_message->length)); op->send_message->length));
grpc_metadata_batch_add_tail(op->send_initial_metadata, grpc_metadata_batch_add_tail(op->send_initial_metadata,
@ -292,8 +285,8 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
} }
} }
grpc_metadata_batch_filter(op->send_initial_metadata, client_strip_filter, grpc_metadata_batch_filter(exec_ctx, op->send_initial_metadata,
elem); client_strip_filter, elem);
/* Send : prefixed headers, which have to be before any application /* Send : prefixed headers, which have to be before any application
layer headers. */ layer headers. */
grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->method, grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->method,
@ -371,7 +364,7 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
const grpc_call_final_info *final_info, const grpc_call_final_info *final_info,
void *ignored) { void *ignored) {
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_slice_buffer_destroy(&calld->slices); grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices);
} }
static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) {
@ -472,7 +465,7 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx,
chand->max_payload_size_for_get = chand->max_payload_size_for_get =
max_payload_size_from_args(args->channel_args); max_payload_size_from_args(args->channel_args);
chand->user_agent = grpc_mdelem_from_metadata_strings( chand->user_agent = grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_USER_AGENT, exec_ctx, GRPC_MDSTR_USER_AGENT,
user_agent_from_args(args->channel_args, user_agent_from_args(args->channel_args,
args->optional_transport->vtable->name)); args->optional_transport->vtable->name));
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
@ -482,7 +475,7 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx,
static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
grpc_channel_element *elem) { grpc_channel_element *elem) {
channel_data *chand = elem->channel_data; channel_data *chand = elem->channel_data;
GRPC_MDELEM_UNREF(chand->user_agent); GRPC_MDELEM_UNREF(exec_ctx, chand->user_agent);
} }
const grpc_channel_filter grpc_http_client_filter = { const grpc_channel_filter grpc_http_client_filter = {

@ -38,6 +38,7 @@
#include <string.h> #include <string.h>
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/percent_encoding.h" #include "src/core/lib/slice/percent_encoding.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
#define EXPECTED_CONTENT_TYPE "application/grpc" #define EXPECTED_CONTENT_TYPE "application/grpc"
@ -82,31 +83,28 @@ typedef struct call_data {
typedef struct channel_data { uint8_t unused; } channel_data; typedef struct channel_data { uint8_t unused; } channel_data;
typedef struct { static grpc_mdelem *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem; void *user_data,
grpc_exec_ctx *exec_ctx;
} server_filter_args;
static grpc_mdelem *server_filter_outgoing_metadata(void *user_data,
grpc_mdelem *md) { grpc_mdelem *md) {
if (md->key == GRPC_MDSTR_GRPC_MESSAGE) { if (md->key == GRPC_MDSTR_GRPC_MESSAGE) {
grpc_slice pct_encoded_msg = grpc_percent_encode_slice( grpc_slice pct_encoded_msg = grpc_percent_encode_slice(
md->value->slice, grpc_compatible_percent_encoding_unreserved_bytes); md->value->slice, grpc_compatible_percent_encoding_unreserved_bytes);
if (grpc_slice_is_equivalent(pct_encoded_msg, md->value->slice)) { if (grpc_slice_is_equivalent(pct_encoded_msg, md->value->slice)) {
grpc_slice_unref(pct_encoded_msg); grpc_slice_unref_internal(exec_ctx, pct_encoded_msg);
return md; return md;
} else { } else {
return grpc_mdelem_from_metadata_strings( return grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_GRPC_MESSAGE, grpc_mdstr_from_slice(pct_encoded_msg)); exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
grpc_mdstr_from_slice(exec_ctx, pct_encoded_msg));
} }
} else { } else {
return md; return md;
} }
} }
static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data,
server_filter_args *a = user_data; grpc_mdelem *md) {
grpc_call_element *elem = a->elem; grpc_call_element *elem = user_data;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
/* Check if it is one of the headers we care about. */ /* Check if it is one of the headers we care about. */
@ -157,7 +155,7 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) {
/* swallow it and error everything out. */ /* swallow it and error everything out. */
/* TODO(klempner): We ought to generate more descriptive error messages /* TODO(klempner): We ought to generate more descriptive error messages
on the wire here. */ on the wire here. */
grpc_call_element_send_cancel(a->exec_ctx, elem); grpc_call_element_send_cancel(exec_ctx, elem);
return NULL; return NULL;
} else if (md->key == GRPC_MDSTR_PATH) { } else if (md->key == GRPC_MDSTR_PATH) {
if (calld->seen_path) { if (calld->seen_path) {
@ -173,7 +171,7 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) {
/* translate host to :authority since :authority may be /* translate host to :authority since :authority may be
omitted */ omitted */
grpc_mdelem *authority = grpc_mdelem_from_metadata_strings( grpc_mdelem *authority = grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_AUTHORITY, GRPC_MDSTR_REF(md->value)); exec_ctx, GRPC_MDSTR_AUTHORITY, GRPC_MDSTR_REF(md->value));
calld->seen_authority = 1; calld->seen_authority = 1;
return authority; return authority;
} else if (md->key == GRPC_MDSTR_GRPC_PAYLOAD_BIN) { } else if (md->key == GRPC_MDSTR_GRPC_PAYLOAD_BIN) {
@ -181,7 +179,7 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) {
header field */ header field */
calld->seen_payload_bin = 1; calld->seen_payload_bin = 1;
grpc_slice_buffer_add(&calld->read_slice_buffer, grpc_slice_buffer_add(&calld->read_slice_buffer,
grpc_slice_ref(md->value->slice)); grpc_slice_ref_internal(md->value->slice));
grpc_slice_buffer_stream_init(&calld->read_stream, grpc_slice_buffer_stream_init(&calld->read_stream,
&calld->read_slice_buffer, 0); &calld->read_slice_buffer, 0);
return NULL; return NULL;
@ -195,10 +193,8 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data,
grpc_call_element *elem = user_data; grpc_call_element *elem = user_data;
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
if (err == GRPC_ERROR_NONE) { if (err == GRPC_ERROR_NONE) {
server_filter_args a; grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata,
a.elem = elem; server_filter, elem);
a.exec_ctx = exec_ctx;
grpc_metadata_batch_filter(calld->recv_initial_metadata, server_filter, &a);
/* Have we seen the required http2 transport headers? /* Have we seen the required http2 transport headers?
(:method, :scheme, content-type, with :path and :authority covered (:method, :scheme, content-type, with :path and :authority covered
at the channel level right now) */ at the channel level right now) */
@ -310,9 +306,8 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
} }
if (op->send_trailing_metadata) { if (op->send_trailing_metadata) {
server_filter_args a = {elem, exec_ctx}; grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata,
grpc_metadata_batch_filter(op->send_trailing_metadata, server_filter_outgoing_metadata, elem);
server_filter_outgoing_metadata, &a);
} }
} }
@ -349,7 +344,7 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
const grpc_call_final_info *final_info, const grpc_call_final_info *final_info,
void *ignored) { void *ignored) {
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_slice_buffer_destroy(&calld->read_slice_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, &calld->read_slice_buffer);
} }
/* Constructor for channel_data */ /* Constructor for channel_data */

@ -54,8 +54,12 @@ static void* message_size_limits_copy(void* value) {
return new_value; return new_value;
} }
static void message_size_limits_free(grpc_exec_ctx* exec_ctx, void* value) {
gpr_free(value);
}
static const grpc_mdstr_hash_table_vtable message_size_limits_vtable = { static const grpc_mdstr_hash_table_vtable message_size_limits_vtable = {
gpr_free, message_size_limits_copy}; message_size_limits_free, message_size_limits_copy};
static void* message_size_limits_create_from_json(const grpc_json* json) { static void* message_size_limits_create_from_json(const grpc_json* json) {
int max_request_message_bytes = -1; int max_request_message_bytes = -1;
@ -169,8 +173,8 @@ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx,
calld->max_send_size = chand->max_send_size; calld->max_send_size = chand->max_send_size;
calld->max_recv_size = chand->max_recv_size; calld->max_recv_size = chand->max_recv_size;
if (chand->method_limit_table != NULL) { if (chand->method_limit_table != NULL) {
message_size_limits* limits = message_size_limits* limits = grpc_method_config_table_get(
grpc_method_config_table_get(chand->method_limit_table, args->path); exec_ctx, chand->method_limit_table, args->path);
if (limits != NULL) { if (limits != NULL) {
if (limits->max_send_size >= 0 && if (limits->max_send_size >= 0 &&
(limits->max_send_size < calld->max_send_size || (limits->max_send_size < calld->max_send_size ||
@ -227,7 +231,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx,
if (service_config != NULL) { if (service_config != NULL) {
chand->method_limit_table = chand->method_limit_table =
grpc_service_config_create_method_config_table( grpc_service_config_create_method_config_table(
service_config, message_size_limits_create_from_json, exec_ctx, service_config, message_size_limits_create_from_json,
&message_size_limits_vtable); &message_size_limits_vtable);
grpc_service_config_destroy(service_config); grpc_service_config_destroy(service_config);
} }
@ -239,7 +243,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx,
static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, static void destroy_channel_elem(grpc_exec_ctx* exec_ctx,
grpc_channel_element* elem) { grpc_channel_element* elem) {
channel_data* chand = elem->channel_data; channel_data* chand = elem->channel_data;
grpc_mdstr_hash_table_unref(chand->method_limit_table); grpc_mdstr_hash_table_unref(exec_ctx, chand->method_limit_table);
} }
const grpc_channel_filter grpc_message_size_filter = { const grpc_channel_filter grpc_message_size_filter = {

@ -40,10 +40,12 @@
#include <zlib.h> #include <zlib.h>
#include "src/core/lib/slice/slice_internal.h"
#define OUTPUT_BLOCK_SIZE 1024 #define OUTPUT_BLOCK_SIZE 1024
static int zlib_body(z_stream* zs, grpc_slice_buffer* input, static int zlib_body(grpc_exec_ctx* exec_ctx, z_stream* zs,
grpc_slice_buffer* output, grpc_slice_buffer* input, grpc_slice_buffer* output,
int (*flate)(z_stream* zs, int flush)) { int (*flate)(z_stream* zs, int flush)) {
int r; int r;
int flush; int flush;
@ -87,7 +89,7 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
return 1; return 1;
error: error:
grpc_slice_unref(outbuf); grpc_slice_unref_internal(exec_ctx, outbuf);
return 0; return 0;
} }
@ -97,8 +99,8 @@ static void* zalloc_gpr(void* opaque, unsigned int items, unsigned int size) {
static void zfree_gpr(void* opaque, void* address) { gpr_free(address); } static void zfree_gpr(void* opaque, void* address) { gpr_free(address); }
static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output, static int zlib_compress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input,
int gzip) { grpc_slice_buffer* output, int gzip) {
z_stream zs; z_stream zs;
int r; int r;
size_t i; size_t i;
@ -110,10 +112,11 @@ static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output,
r = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | (gzip ? 16 : 0), r = deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | (gzip ? 16 : 0),
8, Z_DEFAULT_STRATEGY); 8, Z_DEFAULT_STRATEGY);
GPR_ASSERT(r == Z_OK); GPR_ASSERT(r == Z_OK);
r = zlib_body(&zs, input, output, deflate) && output->length < input->length; r = zlib_body(exec_ctx, &zs, input, output, deflate) &&
output->length < input->length;
if (!r) { if (!r) {
for (i = count_before; i < output->count; i++) { for (i = count_before; i < output->count; i++) {
grpc_slice_unref(output->slices[i]); grpc_slice_unref_internal(exec_ctx, output->slices[i]);
} }
output->count = count_before; output->count = count_before;
output->length = length_before; output->length = length_before;
@ -122,8 +125,8 @@ static int zlib_compress(grpc_slice_buffer* input, grpc_slice_buffer* output,
return r; return r;
} }
static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output, static int zlib_decompress(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* input,
int gzip) { grpc_slice_buffer* output, int gzip) {
z_stream zs; z_stream zs;
int r; int r;
size_t i; size_t i;
@ -134,10 +137,10 @@ static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output,
zs.zfree = zfree_gpr; zs.zfree = zfree_gpr;
r = inflateInit2(&zs, 15 | (gzip ? 16 : 0)); r = inflateInit2(&zs, 15 | (gzip ? 16 : 0));
GPR_ASSERT(r == Z_OK); GPR_ASSERT(r == Z_OK);
r = zlib_body(&zs, input, output, inflate); r = zlib_body(exec_ctx, &zs, input, output, inflate);
if (!r) { if (!r) {
for (i = count_before; i < output->count; i++) { for (i = count_before; i < output->count; i++) {
grpc_slice_unref(output->slices[i]); grpc_slice_unref_internal(exec_ctx, output->slices[i]);
} }
output->count = count_before; output->count = count_before;
output->length = length_before; output->length = length_before;
@ -149,12 +152,13 @@ static int zlib_decompress(grpc_slice_buffer* input, grpc_slice_buffer* output,
static int copy(grpc_slice_buffer* input, grpc_slice_buffer* output) { static int copy(grpc_slice_buffer* input, grpc_slice_buffer* output) {
size_t i; size_t i;
for (i = 0; i < input->count; i++) { for (i = 0; i < input->count; i++) {
grpc_slice_buffer_add(output, grpc_slice_ref(input->slices[i])); grpc_slice_buffer_add(output, grpc_slice_ref_internal(input->slices[i]));
} }
return 1; return 1;
} }
static int compress_inner(grpc_compression_algorithm algorithm, static int compress_inner(grpc_exec_ctx* exec_ctx,
grpc_compression_algorithm algorithm,
grpc_slice_buffer* input, grpc_slice_buffer* output) { grpc_slice_buffer* input, grpc_slice_buffer* output) {
switch (algorithm) { switch (algorithm) {
case GRPC_COMPRESS_NONE: case GRPC_COMPRESS_NONE:
@ -162,9 +166,9 @@ static int compress_inner(grpc_compression_algorithm algorithm,
rely on that here */ rely on that here */
return 0; return 0;
case GRPC_COMPRESS_DEFLATE: case GRPC_COMPRESS_DEFLATE:
return zlib_compress(input, output, 0); return zlib_compress(exec_ctx, input, output, 0);
case GRPC_COMPRESS_GZIP: case GRPC_COMPRESS_GZIP:
return zlib_compress(input, output, 1); return zlib_compress(exec_ctx, input, output, 1);
case GRPC_COMPRESS_ALGORITHMS_COUNT: case GRPC_COMPRESS_ALGORITHMS_COUNT:
break; break;
} }
@ -172,24 +176,26 @@ static int compress_inner(grpc_compression_algorithm algorithm,
return 0; return 0;
} }
int grpc_msg_compress(grpc_compression_algorithm algorithm, int grpc_msg_compress(grpc_exec_ctx* exec_ctx,
grpc_compression_algorithm algorithm,
grpc_slice_buffer* input, grpc_slice_buffer* output) { grpc_slice_buffer* input, grpc_slice_buffer* output) {
if (!compress_inner(algorithm, input, output)) { if (!compress_inner(exec_ctx, algorithm, input, output)) {
copy(input, output); copy(input, output);
return 0; return 0;
} }
return 1; return 1;
} }
int grpc_msg_decompress(grpc_compression_algorithm algorithm, int grpc_msg_decompress(grpc_exec_ctx* exec_ctx,
grpc_compression_algorithm algorithm,
grpc_slice_buffer* input, grpc_slice_buffer* output) { grpc_slice_buffer* input, grpc_slice_buffer* output) {
switch (algorithm) { switch (algorithm) {
case GRPC_COMPRESS_NONE: case GRPC_COMPRESS_NONE:
return copy(input, output); return copy(input, output);
case GRPC_COMPRESS_DEFLATE: case GRPC_COMPRESS_DEFLATE:
return zlib_decompress(input, output, 0); return zlib_decompress(exec_ctx, input, output, 0);
case GRPC_COMPRESS_GZIP: case GRPC_COMPRESS_GZIP:
return zlib_decompress(input, output, 1); return zlib_decompress(exec_ctx, input, output, 1);
case GRPC_COMPRESS_ALGORITHMS_COUNT: case GRPC_COMPRESS_ALGORITHMS_COUNT:
break; break;
} }

@ -40,13 +40,15 @@
/* compress 'input' to 'output' using 'algorithm'. /* compress 'input' to 'output' using 'algorithm'.
On success, appends compressed slices to output and returns 1. On success, appends compressed slices to output and returns 1.
On failure, appends uncompressed slices to output and returns 0. */ On failure, appends uncompressed slices to output and returns 0. */
int grpc_msg_compress(grpc_compression_algorithm algorithm, int grpc_msg_compress(grpc_exec_ctx* exec_ctx,
grpc_compression_algorithm algorithm,
grpc_slice_buffer* input, grpc_slice_buffer* output); grpc_slice_buffer* input, grpc_slice_buffer* output);
/* decompress 'input' to 'output' using 'algorithm'. /* decompress 'input' to 'output' using 'algorithm'.
On success, appends slices to output and returns 1. On success, appends slices to output and returns 1.
On failure, output is unchanged, and returns 0. */ On failure, output is unchanged, and returns 0. */
int grpc_msg_decompress(grpc_compression_algorithm algorithm, int grpc_msg_decompress(grpc_exec_ctx* exec_ctx,
grpc_compression_algorithm algorithm,
grpc_slice_buffer* input, grpc_slice_buffer* output); grpc_slice_buffer* input, grpc_slice_buffer* output);
#endif /* GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H */ #endif /* GRPC_CORE_LIB_COMPRESSION_MESSAGE_COMPRESS_H */

@ -47,6 +47,7 @@
#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr_utils.h"
#include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
typedef struct { typedef struct {
@ -111,14 +112,14 @@ static void finish(grpc_exec_ctx *exec_ctx, internal_request *req,
if (req->ep != NULL) { if (req->ep != NULL) {
grpc_endpoint_destroy(exec_ctx, req->ep); grpc_endpoint_destroy(exec_ctx, req->ep);
} }
grpc_slice_unref(req->request_text); grpc_slice_unref_internal(exec_ctx, req->request_text);
gpr_free(req->host); gpr_free(req->host);
gpr_free(req->ssl_host_override); gpr_free(req->ssl_host_override);
grpc_iomgr_unregister_object(&req->iomgr_obj); grpc_iomgr_unregister_object(&req->iomgr_obj);
grpc_slice_buffer_destroy(&req->incoming); grpc_slice_buffer_destroy_internal(exec_ctx, &req->incoming);
grpc_slice_buffer_destroy(&req->outgoing); grpc_slice_buffer_destroy_internal(exec_ctx, &req->outgoing);
GRPC_ERROR_UNREF(req->overall_error); GRPC_ERROR_UNREF(req->overall_error);
grpc_resource_quota_internal_unref(exec_ctx, req->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, req->resource_quota);
gpr_free(req); gpr_free(req);
} }
@ -178,7 +179,7 @@ static void done_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
} }
static void start_write(grpc_exec_ctx *exec_ctx, internal_request *req) { static void start_write(grpc_exec_ctx *exec_ctx, internal_request *req) {
grpc_slice_ref(req->request_text); grpc_slice_ref_internal(req->request_text);
grpc_slice_buffer_add(&req->outgoing, req->request_text); grpc_slice_buffer_add(&req->outgoing, req->request_text);
grpc_endpoint_write(exec_ctx, req->ep, &req->outgoing, &req->done_write); grpc_endpoint_write(exec_ctx, req->ep, &req->outgoing, &req->done_write);
} }
@ -266,7 +267,7 @@ static void internal_request_begin(grpc_exec_ctx *exec_ctx,
req->context = context; req->context = context;
req->pollent = pollent; req->pollent = pollent;
req->overall_error = GRPC_ERROR_NONE; req->overall_error = GRPC_ERROR_NONE;
req->resource_quota = grpc_resource_quota_internal_ref(resource_quota); req->resource_quota = grpc_resource_quota_ref_internal(resource_quota);
grpc_closure_init(&req->on_read, on_read, req, grpc_schedule_on_exec_ctx); grpc_closure_init(&req->on_read, on_read, req, grpc_schedule_on_exec_ctx);
grpc_closure_init(&req->done_write, done_write, req, grpc_closure_init(&req->done_write, done_write, req,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);

@ -41,6 +41,7 @@
#include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/security/transport/security_handshaker.h" #include "src/core/lib/security/transport/security_handshaker.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
#include "src/core/lib/tsi/ssl_transport_security.h" #include "src/core/lib/tsi/ssl_transport_security.h"
@ -50,7 +51,8 @@ typedef struct {
char *secure_peer_name; char *secure_peer_name;
} grpc_httpcli_ssl_channel_security_connector; } grpc_httpcli_ssl_channel_security_connector;
static void httpcli_ssl_destroy(grpc_security_connector *sc) { static void httpcli_ssl_destroy(grpc_exec_ctx *exec_ctx,
grpc_security_connector *sc) {
grpc_httpcli_ssl_channel_security_connector *c = grpc_httpcli_ssl_channel_security_connector *c =
(grpc_httpcli_ssl_channel_security_connector *)sc; (grpc_httpcli_ssl_channel_security_connector *)sc;
if (c->handshaker_factory != NULL) { if (c->handshaker_factory != NULL) {
@ -104,8 +106,9 @@ static grpc_security_connector_vtable httpcli_ssl_vtable = {
httpcli_ssl_destroy, httpcli_ssl_check_peer}; httpcli_ssl_destroy, httpcli_ssl_check_peer};
static grpc_security_status httpcli_ssl_channel_security_connector_create( static grpc_security_status httpcli_ssl_channel_security_connector_create(
const unsigned char *pem_root_certs, size_t pem_root_certs_size, grpc_exec_ctx *exec_ctx, const unsigned char *pem_root_certs,
const char *secure_peer_name, grpc_channel_security_connector **sc) { size_t pem_root_certs_size, const char *secure_peer_name,
grpc_channel_security_connector **sc) {
tsi_result result = TSI_OK; tsi_result result = TSI_OK;
grpc_httpcli_ssl_channel_security_connector *c; grpc_httpcli_ssl_channel_security_connector *c;
@ -129,7 +132,7 @@ static grpc_security_status httpcli_ssl_channel_security_connector_create(
if (result != TSI_OK) { if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.", gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
tsi_result_to_string(result)); tsi_result_to_string(result));
httpcli_ssl_destroy(&c->base.base); httpcli_ssl_destroy(exec_ctx, &c->base.base);
*sc = NULL; *sc = NULL;
return GRPC_SECURITY_ERROR; return GRPC_SECURITY_ERROR;
} }
@ -156,8 +159,8 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error_free_string(msg); grpc_error_free_string(msg);
c->func(exec_ctx, c->arg, NULL); c->func(exec_ctx, c->arg, NULL);
} else { } else {
grpc_channel_args_destroy(args->args); grpc_channel_args_destroy(exec_ctx, args->args);
grpc_slice_buffer_destroy(args->read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, args->read_buffer);
gpr_free(args->read_buffer); gpr_free(args->read_buffer);
c->func(exec_ctx, c->arg, args->endpoint); c->func(exec_ctx, c->arg, args->endpoint);
} }
@ -184,14 +187,14 @@ static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
c->arg = arg; c->arg = arg;
c->handshake_mgr = grpc_handshake_manager_create(); c->handshake_mgr = grpc_handshake_manager_create();
GPR_ASSERT(httpcli_ssl_channel_security_connector_create( GPR_ASSERT(httpcli_ssl_channel_security_connector_create(
pem_root_certs, pem_root_certs_size, host, &sc) == exec_ctx, pem_root_certs, pem_root_certs_size, host, &sc) ==
GRPC_SECURITY_OK); GRPC_SECURITY_OK);
grpc_channel_security_connector_add_handshakers(exec_ctx, sc, grpc_channel_security_connector_add_handshakers(exec_ctx, sc,
c->handshake_mgr); c->handshake_mgr);
grpc_handshake_manager_do_handshake( grpc_handshake_manager_do_handshake(
exec_ctx, c->handshake_mgr, tcp, NULL /* channel_args */, deadline, exec_ctx, c->handshake_mgr, tcp, NULL /* channel_args */, deadline,
NULL /* acceptor */, on_handshake_done, c /* user_data */); NULL /* acceptor */, on_handshake_done, c /* user_data */);
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli"); GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "httpcli");
} }
const grpc_httpcli_handshaker grpc_httpcli_ssl = {"https", ssl_handshake}; const grpc_httpcli_handshaker grpc_httpcli_ssl = {"https", ssl_handshake};

@ -35,6 +35,8 @@
#define GRPC_CORE_LIB_IOMGR_CLOSURE_H #define GRPC_CORE_LIB_IOMGR_CLOSURE_H
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <grpc/impl/codegen/exec_ctx_fwd.h>
#include <stdbool.h> #include <stdbool.h>
#include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/error.h"
#include "src/core/lib/support/mpscq.h" #include "src/core/lib/support/mpscq.h"
@ -42,10 +44,6 @@
struct grpc_closure; struct grpc_closure;
typedef struct grpc_closure grpc_closure; typedef struct grpc_closure grpc_closure;
/* forward declaration for exec_ctx.h */
struct grpc_exec_ctx;
typedef struct grpc_exec_ctx grpc_exec_ctx;
typedef struct grpc_closure_list { typedef struct grpc_closure_list {
grpc_closure *head; grpc_closure *head;
grpc_closure *tail; grpc_closure *tail;

@ -31,7 +31,6 @@
* *
*/ */
#include <grpc/grpc_posix.h>
#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/port.h"
/* This polling engine is only relevant on linux kernels supporting epoll() */ /* This polling engine is only relevant on linux kernels supporting epoll() */

@ -130,9 +130,8 @@ static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
gpr_mu_unlock(&g_executor.mu); gpr_mu_unlock(&g_executor.mu);
} }
void grpc_executor_shutdown() { void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx) {
int pending_join; int pending_join;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_mu_lock(&g_executor.mu); gpr_mu_lock(&g_executor.mu);
pending_join = g_executor.pending_join; pending_join = g_executor.pending_join;
@ -147,11 +146,11 @@ void grpc_executor_shutdown() {
while (c != NULL) { while (c != NULL) {
grpc_closure *next = c->next_data.next; grpc_closure *next = c->next_data.next;
grpc_error *error = c->error_data.error; grpc_error *error = c->error_data.error;
c->cb(&exec_ctx, c->cb_arg, error); c->cb(exec_ctx, c->cb_arg, error);
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
c = next; c = next;
} }
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_flush(exec_ctx);
GPR_ASSERT(grpc_closure_list_empty(g_executor.closures)); GPR_ASSERT(grpc_closure_list_empty(g_executor.closures));
if (pending_join) { if (pending_join) {
gpr_thd_join(g_executor.tid); gpr_thd_join(g_executor.tid);

@ -46,6 +46,6 @@ void grpc_executor_init();
extern grpc_closure_scheduler *grpc_executor_scheduler; extern grpc_closure_scheduler *grpc_executor_scheduler;
/** Shutdown the executor, running all pending work as part of the call */ /** Shutdown the executor, running all pending work as part of the call */
void grpc_executor_shutdown(); void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx);
#endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */ #endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */

@ -83,11 +83,10 @@ static void dump_objects(const char *kind) {
} }
} }
void grpc_iomgr_shutdown(void) { void grpc_iomgr_shutdown(grpc_exec_ctx *exec_ctx) {
gpr_timespec shutdown_deadline = gpr_time_add( gpr_timespec shutdown_deadline = gpr_time_add(
gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN)); gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(10, GPR_TIMESPAN));
gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec last_warning_time = gpr_now(GPR_CLOCK_REALTIME);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_iomgr_platform_flush(); grpc_iomgr_platform_flush();
@ -104,10 +103,9 @@ void grpc_iomgr_shutdown(void) {
} }
last_warning_time = gpr_now(GPR_CLOCK_REALTIME); last_warning_time = gpr_now(GPR_CLOCK_REALTIME);
} }
if (grpc_timer_check(&exec_ctx, gpr_inf_future(GPR_CLOCK_MONOTONIC), if (grpc_timer_check(exec_ctx, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL)) {
NULL)) {
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_flush(exec_ctx);
grpc_iomgr_platform_flush(); grpc_iomgr_platform_flush();
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);
continue; continue;
@ -139,8 +137,8 @@ void grpc_iomgr_shutdown(void) {
} }
gpr_mu_unlock(&g_mu); gpr_mu_unlock(&g_mu);
grpc_timer_list_shutdown(&exec_ctx); grpc_timer_list_shutdown(exec_ctx);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_flush(exec_ctx);
/* ensure all threads have left g_mu */ /* ensure all threads have left g_mu */
gpr_mu_lock(&g_mu); gpr_mu_lock(&g_mu);

@ -34,12 +34,14 @@
#ifndef GRPC_CORE_LIB_IOMGR_IOMGR_H #ifndef GRPC_CORE_LIB_IOMGR_IOMGR_H
#define GRPC_CORE_LIB_IOMGR_IOMGR_H #define GRPC_CORE_LIB_IOMGR_IOMGR_H
#include <grpc/impl/codegen/exec_ctx_fwd.h>
#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/port.h"
/** Initializes the iomgr. */ /** Initializes the iomgr. */
void grpc_iomgr_init(void); void grpc_iomgr_init(void);
/** Signals the intention to shutdown the iomgr. */ /** Signals the intention to shutdown the iomgr. Expects to be able to flush
void grpc_iomgr_shutdown(void); * exec_ctx. */
void grpc_iomgr_shutdown(grpc_exec_ctx *exec_ctx);
#endif /* GRPC_CORE_LIB_IOMGR_IOMGR_H */ #endif /* GRPC_CORE_LIB_IOMGR_IOMGR_H */

@ -257,14 +257,14 @@ static void rq_step(grpc_exec_ctx *exec_ctx, void *rq, grpc_error *error) {
} }
done: done:
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
} }
static void rq_step_sched(grpc_exec_ctx *exec_ctx, static void rq_step_sched(grpc_exec_ctx *exec_ctx,
grpc_resource_quota *resource_quota) { grpc_resource_quota *resource_quota) {
if (resource_quota->step_scheduled) return; if (resource_quota->step_scheduled) return;
resource_quota->step_scheduled = true; resource_quota->step_scheduled = true;
grpc_resource_quota_internal_ref(resource_quota); grpc_resource_quota_ref_internal(resource_quota);
grpc_closure_sched(exec_ctx, &resource_quota->rq_step_closure, grpc_closure_sched(exec_ctx, &resource_quota->rq_step_closure,
GRPC_ERROR_NONE); GRPC_ERROR_NONE);
} }
@ -344,7 +344,7 @@ static bool rq_reclaim(grpc_exec_ctx *exec_ctx,
destructive ? "destructive" : "benign"); destructive ? "destructive" : "benign");
} }
resource_quota->reclaiming = true; resource_quota->reclaiming = true;
grpc_resource_quota_internal_ref(resource_quota); grpc_resource_quota_ref_internal(resource_quota);
grpc_closure *c = resource_user->reclaimers[destructive]; grpc_closure *c = resource_user->reclaimers[destructive];
GPR_ASSERT(c); GPR_ASSERT(c);
resource_quota->debug_only_last_reclaimer_resource_user = resource_user; resource_quota->debug_only_last_reclaimer_resource_user = resource_user;
@ -370,21 +370,10 @@ static void ru_slice_ref(void *p) {
gpr_ref(&rc->refs); gpr_ref(&rc->refs);
} }
static void ru_slice_unref(void *p) { static void ru_slice_unref(grpc_exec_ctx *exec_ctx, void *p) {
ru_slice_refcount *rc = p; ru_slice_refcount *rc = p;
if (gpr_unref(&rc->refs)) { if (gpr_unref(&rc->refs)) {
/* TODO(ctiller): this is dangerous, but I think safe for now: grpc_resource_user_free(exec_ctx, rc->resource_user, rc->size);
we have no guarantee here that we're at a safe point for creating an
execution context, but we have no way of writing this code otherwise.
In the future: consider lifting grpc_slice to grpc, and offering an
internal_{ref,unref} pair that is execution context aware.
Alternatively,
make exec_ctx be thread local and 'do the right thing' (whatever that
is)
if NULL */
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_user_free(&exec_ctx, rc->resource_user, rc->size);
grpc_exec_ctx_finish(&exec_ctx);
gpr_free(rc); gpr_free(rc);
} }
} }
@ -503,7 +492,7 @@ static void ru_destroy(grpc_exec_ctx *exec_ctx, void *ru, grpc_error *error) {
resource_user->resource_quota->free_pool += resource_user->free_pool; resource_user->resource_quota->free_pool += resource_user->free_pool;
rq_step_sched(exec_ctx, resource_user->resource_quota); rq_step_sched(exec_ctx, resource_user->resource_quota);
} }
grpc_resource_quota_internal_unref(exec_ctx, resource_user->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_user->resource_quota);
gpr_mu_destroy(&resource_user->mu); gpr_mu_destroy(&resource_user->mu);
gpr_free(resource_user->name); gpr_free(resource_user->name);
gpr_free(resource_user); gpr_free(resource_user);
@ -539,7 +528,7 @@ static void rq_resize(grpc_exec_ctx *exec_ctx, void *args, grpc_error *error) {
a->resource_quota->size += delta; a->resource_quota->size += delta;
a->resource_quota->free_pool += delta; a->resource_quota->free_pool += delta;
rq_step_sched(exec_ctx, a->resource_quota); rq_step_sched(exec_ctx, a->resource_quota);
grpc_resource_quota_internal_unref(exec_ctx, a->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, a->resource_quota);
gpr_free(a); gpr_free(a);
} }
@ -548,7 +537,7 @@ static void rq_reclamation_done(grpc_exec_ctx *exec_ctx, void *rq,
grpc_resource_quota *resource_quota = rq; grpc_resource_quota *resource_quota = rq;
resource_quota->reclaiming = false; resource_quota->reclaiming = false;
rq_step_sched(exec_ctx, resource_quota); rq_step_sched(exec_ctx, resource_quota);
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
} }
/******************************************************************************* /*******************************************************************************
@ -582,7 +571,7 @@ grpc_resource_quota *grpc_resource_quota_create(const char *name) {
return resource_quota; return resource_quota;
} }
void grpc_resource_quota_internal_unref(grpc_exec_ctx *exec_ctx, void grpc_resource_quota_unref_internal(grpc_exec_ctx *exec_ctx,
grpc_resource_quota *resource_quota) { grpc_resource_quota *resource_quota) {
if (gpr_unref(&resource_quota->refs)) { if (gpr_unref(&resource_quota->refs)) {
grpc_combiner_destroy(exec_ctx, resource_quota->combiner); grpc_combiner_destroy(exec_ctx, resource_quota->combiner);
@ -594,11 +583,11 @@ void grpc_resource_quota_internal_unref(grpc_exec_ctx *exec_ctx,
/* Public API */ /* Public API */
void grpc_resource_quota_unref(grpc_resource_quota *resource_quota) { void grpc_resource_quota_unref(grpc_resource_quota *resource_quota) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); grpc_resource_quota_unref_internal(&exec_ctx, resource_quota);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
grpc_resource_quota *grpc_resource_quota_internal_ref( grpc_resource_quota *grpc_resource_quota_ref_internal(
grpc_resource_quota *resource_quota) { grpc_resource_quota *resource_quota) {
gpr_ref(&resource_quota->refs); gpr_ref(&resource_quota->refs);
return resource_quota; return resource_quota;
@ -606,7 +595,7 @@ grpc_resource_quota *grpc_resource_quota_internal_ref(
/* Public API */ /* Public API */
void grpc_resource_quota_ref(grpc_resource_quota *resource_quota) { void grpc_resource_quota_ref(grpc_resource_quota *resource_quota) {
grpc_resource_quota_internal_ref(resource_quota); grpc_resource_quota_ref_internal(resource_quota);
} }
/* Public API */ /* Public API */
@ -614,7 +603,7 @@ void grpc_resource_quota_resize(grpc_resource_quota *resource_quota,
size_t size) { size_t size) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
rq_resize_args *a = gpr_malloc(sizeof(*a)); rq_resize_args *a = gpr_malloc(sizeof(*a));
a->resource_quota = grpc_resource_quota_internal_ref(resource_quota); a->resource_quota = grpc_resource_quota_ref_internal(resource_quota);
a->size = (int64_t)size; a->size = (int64_t)size;
grpc_closure_init(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx); grpc_closure_init(&a->closure, rq_resize, a, grpc_schedule_on_exec_ctx);
grpc_closure_sched(&exec_ctx, &a->closure, GRPC_ERROR_NONE); grpc_closure_sched(&exec_ctx, &a->closure, GRPC_ERROR_NONE);
@ -630,7 +619,7 @@ grpc_resource_quota *grpc_resource_quota_from_channel_args(
for (size_t i = 0; i < channel_args->num_args; i++) { for (size_t i = 0; i < channel_args->num_args; i++) {
if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
if (channel_args->args[i].type == GRPC_ARG_POINTER) { if (channel_args->args[i].type == GRPC_ARG_POINTER) {
return grpc_resource_quota_internal_ref( return grpc_resource_quota_ref_internal(
channel_args->args[i].value.pointer.p); channel_args->args[i].value.pointer.p);
} else { } else {
gpr_log(GPR_DEBUG, GRPC_ARG_RESOURCE_QUOTA " should be a pointer"); gpr_log(GPR_DEBUG, GRPC_ARG_RESOURCE_QUOTA " should be a pointer");
@ -645,7 +634,9 @@ static void *rq_copy(void *rq) {
return rq; return rq;
} }
static void rq_destroy(void *rq) { grpc_resource_quota_unref(rq); } static void rq_destroy(grpc_exec_ctx *exec_ctx, void *rq) {
grpc_resource_quota_unref_internal(exec_ctx, rq);
}
static int rq_cmp(void *a, void *b) { return GPR_ICMP(a, b); } static int rq_cmp(void *a, void *b) { return GPR_ICMP(a, b); }
@ -662,7 +653,7 @@ grpc_resource_user *grpc_resource_user_create(
grpc_resource_quota *resource_quota, const char *name) { grpc_resource_quota *resource_quota, const char *name) {
grpc_resource_user *resource_user = gpr_malloc(sizeof(*resource_user)); grpc_resource_user *resource_user = gpr_malloc(sizeof(*resource_user));
resource_user->resource_quota = resource_user->resource_quota =
grpc_resource_quota_internal_ref(resource_quota); grpc_resource_quota_ref_internal(resource_quota);
grpc_closure_init(&resource_user->allocate_closure, &ru_allocate, grpc_closure_init(&resource_user->allocate_closure, &ru_allocate,
resource_user, resource_user,
grpc_combiner_scheduler(resource_quota->combiner, false)); grpc_combiner_scheduler(resource_quota->combiner, false));

@ -77,9 +77,9 @@
extern int grpc_resource_quota_trace; extern int grpc_resource_quota_trace;
grpc_resource_quota *grpc_resource_quota_internal_ref( grpc_resource_quota *grpc_resource_quota_ref_internal(
grpc_resource_quota *resource_quota); grpc_resource_quota *resource_quota);
void grpc_resource_quota_internal_unref(grpc_exec_ctx *exec_ctx, void grpc_resource_quota_unref_internal(grpc_exec_ctx *exec_ctx,
grpc_resource_quota *resource_quota); grpc_resource_quota *resource_quota);
grpc_resource_quota *grpc_resource_quota_from_channel_args( grpc_resource_quota *grpc_resource_quota_from_channel_args(
const grpc_channel_args *channel_args); const grpc_channel_args *channel_args);

@ -76,7 +76,7 @@ static void *socket_mutator_arg_copy(void *p) {
return grpc_socket_mutator_ref(p); return grpc_socket_mutator_ref(p);
} }
static void socket_mutator_arg_destroy(void *p) { static void socket_mutator_arg_destroy(grpc_exec_ctx *exec_ctx, void *p) {
grpc_socket_mutator_unref(p); grpc_socket_mutator_unref(p);
} }

@ -128,7 +128,7 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) {
if (done) { if (done) {
gpr_mu_destroy(&ac->mu); gpr_mu_destroy(&ac->mu);
gpr_free(ac->addr_str); gpr_free(ac->addr_str);
grpc_channel_args_destroy(ac->channel_args); grpc_channel_args_destroy(exec_ctx, ac->channel_args);
gpr_free(ac); gpr_free(ac);
} }
} }
@ -148,8 +148,8 @@ grpc_endpoint *grpc_tcp_client_create_from_fd(
&channel_args->args[i], options); &channel_args->args[i], options);
} else if (0 == } else if (0 ==
strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
resource_quota = grpc_resource_quota_internal_ref( resource_quota = grpc_resource_quota_ref_internal(
channel_args->args[i].value.pointer.p); channel_args->args[i].value.pointer.p);
} }
} }
@ -157,7 +157,7 @@ grpc_endpoint *grpc_tcp_client_create_from_fd(
grpc_endpoint *ep = grpc_endpoint *ep =
grpc_tcp_create(fd, resource_quota, tcp_read_chunk_size, addr_str); grpc_tcp_create(fd, resource_quota, tcp_read_chunk_size, addr_str);
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
return ep; return ep;
} }
@ -262,7 +262,7 @@ finish:
if (done) { if (done) {
gpr_mu_destroy(&ac->mu); gpr_mu_destroy(&ac->mu);
gpr_free(ac->addr_str); gpr_free(ac->addr_str);
grpc_channel_args_destroy(ac->channel_args); grpc_channel_args_destroy(exec_ctx, ac->channel_args);
gpr_free(ac); gpr_free(ac);
} }
grpc_closure_sched(exec_ctx, closure, error); grpc_closure_sched(exec_ctx, closure, error);

@ -59,7 +59,7 @@ typedef struct grpc_uv_tcp_connect {
static void uv_tcp_connect_cleanup(grpc_exec_ctx *exec_ctx, static void uv_tcp_connect_cleanup(grpc_exec_ctx *exec_ctx,
grpc_uv_tcp_connect *connect) { grpc_uv_tcp_connect *connect) {
grpc_resource_quota_internal_unref(exec_ctx, connect->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, connect->resource_quota);
gpr_free(connect); gpr_free(connect);
} }
@ -128,8 +128,8 @@ static void tcp_client_connect_impl(grpc_exec_ctx *exec_ctx,
if (channel_args != NULL) { if (channel_args != NULL) {
for (size_t i = 0; i < channel_args->num_args; i++) { for (size_t i = 0; i < channel_args->num_args; i++) {
if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
resource_quota = grpc_resource_quota_internal_ref( resource_quota = grpc_resource_quota_ref_internal(
channel_args->args[i].value.pointer.p); channel_args->args[i].value.pointer.p);
} }
} }

@ -71,7 +71,7 @@ static void async_connect_unlock_and_cleanup(grpc_exec_ctx *exec_ctx,
int done = (--ac->refs == 0); int done = (--ac->refs == 0);
gpr_mu_unlock(&ac->mu); gpr_mu_unlock(&ac->mu);
if (done) { if (done) {
grpc_resource_quota_internal_unref(exec_ctx, ac->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, ac->resource_quota);
gpr_mu_destroy(&ac->mu); gpr_mu_destroy(&ac->mu);
gpr_free(ac->addr_name); gpr_free(ac->addr_name);
gpr_free(ac); gpr_free(ac);
@ -157,8 +157,8 @@ void grpc_tcp_client_connect(grpc_exec_ctx *exec_ctx, grpc_closure *on_done,
if (channel_args != NULL) { if (channel_args != NULL) {
for (size_t i = 0; i < channel_args->num_args; i++) { for (size_t i = 0; i < channel_args->num_args; i++) {
if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) {
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
resource_quota = grpc_resource_quota_internal_ref( resource_quota = grpc_resource_quota_ref_internal(
channel_args->args[i].value.pointer.p); channel_args->args[i].value.pointer.p);
} }
} }
@ -246,7 +246,7 @@ failure:
} else if (sock != INVALID_SOCKET) { } else if (sock != INVALID_SOCKET) {
closesocket(sock); closesocket(sock);
} }
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
grpc_closure_sched(exec_ctx, on_done, final_error); grpc_closure_sched(exec_ctx, on_done, final_error);
} }

@ -56,6 +56,7 @@
#include "src/core/lib/debug/trace.h" #include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
@ -127,7 +128,7 @@ static void tcp_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
grpc_fd_orphan(exec_ctx, tcp->em_fd, tcp->release_fd_cb, tcp->release_fd, grpc_fd_orphan(exec_ctx, tcp->em_fd, tcp->release_fd_cb, tcp->release_fd,
"tcp_unref_orphan"); "tcp_unref_orphan");
grpc_slice_buffer_destroy(&tcp->last_read_buffer); grpc_slice_buffer_destroy_internal(exec_ctx, &tcp->last_read_buffer);
grpc_resource_user_unref(exec_ctx, tcp->resource_user); grpc_resource_user_unref(exec_ctx, tcp->resource_user);
gpr_free(tcp->peer_string); gpr_free(tcp->peer_string);
gpr_free(tcp); gpr_free(tcp);
@ -168,7 +169,7 @@ static void tcp_ref(grpc_tcp *tcp) { gpr_ref(&tcp->refcount); }
static void tcp_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { static void tcp_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
grpc_network_status_unregister_endpoint(ep); grpc_network_status_unregister_endpoint(ep);
grpc_tcp *tcp = (grpc_tcp *)ep; grpc_tcp *tcp = (grpc_tcp *)ep;
grpc_slice_buffer_reset_and_unref(&tcp->last_read_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &tcp->last_read_buffer);
TCP_UNREF(exec_ctx, tcp, "destroy"); TCP_UNREF(exec_ctx, tcp, "destroy");
} }
@ -235,14 +236,15 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
/* We've consumed the edge, request a new one */ /* We've consumed the edge, request a new one */
grpc_fd_notify_on_read(exec_ctx, tcp->em_fd, &tcp->read_closure); grpc_fd_notify_on_read(exec_ctx, tcp->em_fd, &tcp->read_closure);
} else { } else {
grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx,
tcp->incoming_buffer);
call_read_cb(exec_ctx, tcp, call_read_cb(exec_ctx, tcp,
tcp_annotate_error(GRPC_OS_ERROR(errno, "recvmsg"), tcp)); tcp_annotate_error(GRPC_OS_ERROR(errno, "recvmsg"), tcp));
TCP_UNREF(exec_ctx, tcp, "read"); TCP_UNREF(exec_ctx, tcp, "read");
} }
} else if (read_bytes == 0) { } else if (read_bytes == 0) {
/* 0 read size ==> end of stream */ /* 0 read size ==> end of stream */
grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer);
call_read_cb(exec_ctx, tcp, call_read_cb(exec_ctx, tcp,
tcp_annotate_error(GRPC_ERROR_CREATE("Socket closed"), tcp)); tcp_annotate_error(GRPC_ERROR_CREATE("Socket closed"), tcp));
TCP_UNREF(exec_ctx, tcp, "read"); TCP_UNREF(exec_ctx, tcp, "read");
@ -268,8 +270,9 @@ static void tcp_read_allocation_done(grpc_exec_ctx *exec_ctx, void *tcpp,
grpc_error *error) { grpc_error *error) {
grpc_tcp *tcp = tcpp; grpc_tcp *tcp = tcpp;
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer);
grpc_slice_buffer_reset_and_unref(&tcp->last_read_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx,
&tcp->last_read_buffer);
call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error));
TCP_UNREF(exec_ctx, tcp, "read"); TCP_UNREF(exec_ctx, tcp, "read");
} else { } else {
@ -294,8 +297,9 @@ static void tcp_handle_read(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */,
GPR_ASSERT(!tcp->finished_edge); GPR_ASSERT(!tcp->finished_edge);
if (error != GRPC_ERROR_NONE) { if (error != GRPC_ERROR_NONE) {
grpc_slice_buffer_reset_and_unref(tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer);
grpc_slice_buffer_reset_and_unref(&tcp->last_read_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx,
&tcp->last_read_buffer);
call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error)); call_read_cb(exec_ctx, tcp, GRPC_ERROR_REF(error));
TCP_UNREF(exec_ctx, tcp, "read"); TCP_UNREF(exec_ctx, tcp, "read");
} else { } else {
@ -309,7 +313,7 @@ static void tcp_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
GPR_ASSERT(tcp->read_cb == NULL); GPR_ASSERT(tcp->read_cb == NULL);
tcp->read_cb = cb; tcp->read_cb = cb;
tcp->incoming_buffer = incoming_buffer; tcp->incoming_buffer = incoming_buffer;
grpc_slice_buffer_reset_and_unref(incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, incoming_buffer);
grpc_slice_buffer_swap(incoming_buffer, &tcp->last_read_buffer); grpc_slice_buffer_swap(incoming_buffer, &tcp->last_read_buffer);
TCP_REF(tcp, "read"); TCP_REF(tcp, "read");
if (tcp->finished_edge) { if (tcp->finished_edge) {
@ -578,7 +582,7 @@ void grpc_tcp_destroy_and_release_fd(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
GPR_ASSERT(ep->vtable == &vtable); GPR_ASSERT(ep->vtable == &vtable);
tcp->release_fd = fd; tcp->release_fd = fd;
tcp->release_fd_cb = done; tcp->release_fd_cb = done;
grpc_slice_buffer_reset_and_unref(&tcp->last_read_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &tcp->last_read_buffer);
TCP_UNREF(exec_ctx, tcp, "destroy"); TCP_UNREF(exec_ctx, tcp, "destroy");
} }

@ -167,18 +167,18 @@ grpc_error *grpc_tcp_server_create(grpc_exec_ctx *exec_ctx,
s->so_reuseport = s->so_reuseport =
has_so_reuseport && (args->args[i].value.integer != 0); has_so_reuseport && (args->args[i].value.integer != 0);
} else { } else {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
return GRPC_ERROR_CREATE(GRPC_ARG_ALLOW_REUSEPORT return GRPC_ERROR_CREATE(GRPC_ARG_ALLOW_REUSEPORT
" must be an integer"); " must be an integer");
} }
} else if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { } else if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) {
if (args->args[i].type == GRPC_ARG_POINTER) { if (args->args[i].type == GRPC_ARG_POINTER) {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
s->resource_quota = s->resource_quota =
grpc_resource_quota_internal_ref(args->args[i].value.pointer.p); grpc_resource_quota_ref_internal(args->args[i].value.pointer.p);
} else { } else {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
return GRPC_ERROR_CREATE(GRPC_ARG_RESOURCE_QUOTA return GRPC_ERROR_CREATE(GRPC_ARG_RESOURCE_QUOTA
" must be a pointer to a buffer pool"); " must be a pointer to a buffer pool");
@ -219,7 +219,7 @@ static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
gpr_free(sp); gpr_free(sp);
} }
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
} }

@ -89,11 +89,11 @@ grpc_error *grpc_tcp_server_create(grpc_exec_ctx *exec_ctx,
for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) {
if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) {
if (args->args[i].type == GRPC_ARG_POINTER) { if (args->args[i].type == GRPC_ARG_POINTER) {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
s->resource_quota = s->resource_quota =
grpc_resource_quota_internal_ref(args->args[i].value.pointer.p); grpc_resource_quota_ref_internal(args->args[i].value.pointer.p);
} else { } else {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
return GRPC_ERROR_CREATE(GRPC_ARG_RESOURCE_QUOTA return GRPC_ERROR_CREATE(GRPC_ARG_RESOURCE_QUOTA
" must be a pointer to a buffer pool"); " must be a pointer to a buffer pool");
@ -136,7 +136,7 @@ static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
gpr_free(sp->handle); gpr_free(sp->handle);
gpr_free(sp); gpr_free(sp);
} }
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
} }

@ -116,11 +116,11 @@ grpc_error *grpc_tcp_server_create(grpc_exec_ctx *exec_ctx,
for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) {
if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) {
if (args->args[i].type == GRPC_ARG_POINTER) { if (args->args[i].type == GRPC_ARG_POINTER) {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
s->resource_quota = s->resource_quota =
grpc_resource_quota_internal_ref(args->args[i].value.pointer.p); grpc_resource_quota_ref_internal(args->args[i].value.pointer.p);
} else { } else {
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
return GRPC_ERROR_CREATE(GRPC_ARG_RESOURCE_QUOTA return GRPC_ERROR_CREATE(GRPC_ARG_RESOURCE_QUOTA
" must be a pointer to a buffer pool"); " must be a pointer to a buffer pool");
@ -155,7 +155,7 @@ static void destroy_server(grpc_exec_ctx *exec_ctx, void *arg,
grpc_winsocket_destroy(sp->socket); grpc_winsocket_destroy(sp->socket);
gpr_free(sp); gpr_free(sp);
} }
grpc_resource_quota_internal_unref(exec_ctx, s->resource_quota); grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
gpr_free(s); gpr_free(s);
} }

@ -181,7 +181,7 @@ static void uv_endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
GPR_ASSERT(tcp->read_cb == NULL); GPR_ASSERT(tcp->read_cb == NULL);
tcp->read_cb = cb; tcp->read_cb = cb;
tcp->read_slices = read_slices; tcp->read_slices = read_slices;
grpc_slice_buffer_reset_and_unref(read_slices); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices);
TCP_REF(tcp, "read"); TCP_REF(tcp, "read");
// TODO(murgatroid99): figure out what the return value here means // TODO(murgatroid99): figure out what the return value here means
status = status =

@ -53,6 +53,7 @@
#include "src/core/lib/iomgr/socket_windows.h" #include "src/core/lib/iomgr/socket_windows.h"
#include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/timer.h"
#include "src/core/lib/slice/slice_internal.h"
#if defined(__MSYS__) && defined(GPR_ARCH_64) #if defined(__MSYS__) && defined(GPR_ARCH_64)
/* Nasty workaround for nasty bug when using the 64 bits msys compiler /* Nasty workaround for nasty bug when using the 64 bits msys compiler
@ -174,13 +175,13 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *tcpp, grpc_error *error) {
char *utf8_message = gpr_format_message(info->wsa_error); char *utf8_message = gpr_format_message(info->wsa_error);
error = GRPC_ERROR_CREATE(utf8_message); error = GRPC_ERROR_CREATE(utf8_message);
gpr_free(utf8_message); gpr_free(utf8_message);
grpc_slice_unref(tcp->read_slice); grpc_slice_unref_internal(exec_ctx, tcp->read_slice);
} else { } else {
if (info->bytes_transfered != 0 && !tcp->shutting_down) { if (info->bytes_transfered != 0 && !tcp->shutting_down) {
sub = grpc_slice_sub_no_ref(tcp->read_slice, 0, info->bytes_transfered); sub = grpc_slice_sub_no_ref(tcp->read_slice, 0, info->bytes_transfered);
grpc_slice_buffer_add(tcp->read_slices, sub); grpc_slice_buffer_add(tcp->read_slices, sub);
} else { } else {
grpc_slice_unref(tcp->read_slice); grpc_slice_unref_internal(exec_ctx, tcp->read_slice);
error = GRPC_ERROR_CREATE("End of TCP stream"); error = GRPC_ERROR_CREATE("End of TCP stream");
} }
} }
@ -209,7 +210,7 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
tcp->read_cb = cb; tcp->read_cb = cb;
tcp->read_slices = read_slices; tcp->read_slices = read_slices;
grpc_slice_buffer_reset_and_unref(read_slices); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices);
tcp->read_slice = grpc_slice_malloc(8192); tcp->read_slice = grpc_slice_malloc(8192);

@ -47,6 +47,7 @@
grpc_call_error grpc_call_set_credentials(grpc_call *call, grpc_call_error grpc_call_set_credentials(grpc_call *call,
grpc_call_credentials *creds) { grpc_call_credentials *creds) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_client_security_context *ctx = NULL; grpc_client_security_context *ctx = NULL;
GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2, GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2,
(call, creds)); (call, creds));
@ -62,9 +63,10 @@ grpc_call_error grpc_call_set_credentials(grpc_call *call,
grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx, grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx,
grpc_client_security_context_destroy); grpc_client_security_context_destroy);
} else { } else {
grpc_call_credentials_unref(ctx->creds); grpc_call_credentials_unref(&exec_ctx, ctx->creds);
ctx->creds = grpc_call_credentials_ref(creds); ctx->creds = grpc_call_credentials_ref(creds);
} }
grpc_exec_ctx_finish(&exec_ctx);
return GRPC_CALL_OK; return GRPC_CALL_OK;
} }
@ -96,13 +98,15 @@ grpc_client_security_context *grpc_client_security_context_create(void) {
} }
void grpc_client_security_context_destroy(void *ctx) { void grpc_client_security_context_destroy(void *ctx) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_client_security_context *c = (grpc_client_security_context *)ctx; grpc_client_security_context *c = (grpc_client_security_context *)ctx;
grpc_call_credentials_unref(c->creds); grpc_call_credentials_unref(&exec_ctx, c->creds);
GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context"); GRPC_AUTH_CONTEXT_UNREF(c->auth_context, "client_security_context");
if (c->extension.instance != NULL && c->extension.destroy != NULL) { if (c->extension.instance != NULL && c->extension.destroy != NULL) {
c->extension.destroy(c->extension.instance); c->extension.destroy(c->extension.instance);
} }
gpr_free(ctx); gpr_free(ctx);
grpc_exec_ctx_finish(&exec_ctx);
} }
/* --- grpc_server_security_context --- */ /* --- grpc_server_security_context --- */
@ -307,7 +311,7 @@ void grpc_auth_property_reset(grpc_auth_property *property) {
memset(property, 0, sizeof(grpc_auth_property)); memset(property, 0, sizeof(grpc_auth_property));
} }
static void auth_context_pointer_arg_destroy(void *p) { static void auth_context_pointer_arg_destroy(grpc_exec_ctx *exec_ctx, void *p) {
GRPC_AUTH_CONTEXT_UNREF(p, "auth_context_pointer_arg"); GRPC_AUTH_CONTEXT_UNREF(p, "auth_context_pointer_arg");
} }

@ -54,18 +54,20 @@ typedef struct {
grpc_credentials_metadata_cb cb; grpc_credentials_metadata_cb cb;
} grpc_composite_call_credentials_metadata_context; } grpc_composite_call_credentials_metadata_context;
static void composite_call_destruct(grpc_call_credentials *creds) { static void composite_call_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_composite_call_credentials *c = (grpc_composite_call_credentials *)creds; grpc_composite_call_credentials *c = (grpc_composite_call_credentials *)creds;
size_t i; size_t i;
for (i = 0; i < c->inner.num_creds; i++) { for (i = 0; i < c->inner.num_creds; i++) {
grpc_call_credentials_unref(c->inner.creds_array[i]); grpc_call_credentials_unref(exec_ctx, c->inner.creds_array[i]);
} }
gpr_free(c->inner.creds_array); gpr_free(c->inner.creds_array);
} }
static void composite_call_md_context_destroy( static void composite_call_md_context_destroy(
grpc_exec_ctx *exec_ctx,
grpc_composite_call_credentials_metadata_context *ctx) { grpc_composite_call_credentials_metadata_context *ctx) {
grpc_credentials_md_store_unref(ctx->md_elems); grpc_credentials_md_store_unref(exec_ctx, ctx->md_elems);
gpr_free(ctx); gpr_free(ctx);
} }
@ -103,7 +105,7 @@ static void composite_call_metadata_cb(grpc_exec_ctx *exec_ctx, void *user_data,
/* We're done!. */ /* We're done!. */
ctx->cb(exec_ctx, ctx->user_data, ctx->md_elems->entries, ctx->cb(exec_ctx, ctx->user_data, ctx->md_elems->entries,
ctx->md_elems->num_entries, GRPC_CREDENTIALS_OK, NULL); ctx->md_elems->num_entries, GRPC_CREDENTIALS_OK, NULL);
composite_call_md_context_destroy(ctx); composite_call_md_context_destroy(exec_ctx, ctx);
} }
static void composite_call_get_request_metadata( static void composite_call_get_request_metadata(
@ -209,17 +211,19 @@ grpc_call_credentials *grpc_credentials_contains_type(
/* -- Composite channel credentials. -- */ /* -- Composite channel credentials. -- */
static void composite_channel_destruct(grpc_channel_credentials *creds) { static void composite_channel_destruct(grpc_exec_ctx *exec_ctx,
grpc_channel_credentials *creds) {
grpc_composite_channel_credentials *c = grpc_composite_channel_credentials *c =
(grpc_composite_channel_credentials *)creds; (grpc_composite_channel_credentials *)creds;
grpc_channel_credentials_unref(c->inner_creds); grpc_channel_credentials_unref(exec_ctx, c->inner_creds);
grpc_call_credentials_unref(c->call_creds); grpc_call_credentials_unref(exec_ctx, c->call_creds);
} }
static grpc_security_status composite_channel_create_security_connector( static grpc_security_status composite_channel_create_security_connector(
grpc_channel_credentials *creds, grpc_call_credentials *call_creds, grpc_exec_ctx *exec_ctx, grpc_channel_credentials *creds,
const char *target, const grpc_channel_args *args, grpc_call_credentials *call_creds, const char *target,
grpc_channel_security_connector **sc, grpc_channel_args **new_args) { const grpc_channel_args *args, grpc_channel_security_connector **sc,
grpc_channel_args **new_args) {
grpc_composite_channel_credentials *c = grpc_composite_channel_credentials *c =
(grpc_composite_channel_credentials *)creds; (grpc_composite_channel_credentials *)creds;
grpc_security_status status = GRPC_SECURITY_ERROR; grpc_security_status status = GRPC_SECURITY_ERROR;
@ -233,11 +237,12 @@ static grpc_security_status composite_channel_create_security_connector(
grpc_call_credentials *composite_call_creds = grpc_call_credentials *composite_call_creds =
grpc_composite_call_credentials_create(c->call_creds, call_creds, NULL); grpc_composite_call_credentials_create(c->call_creds, call_creds, NULL);
status = c->inner_creds->vtable->create_security_connector( status = c->inner_creds->vtable->create_security_connector(
c->inner_creds, composite_call_creds, target, args, sc, new_args); exec_ctx, c->inner_creds, composite_call_creds, target, args, sc,
grpc_call_credentials_unref(composite_call_creds); new_args);
grpc_call_credentials_unref(exec_ctx, composite_call_creds);
} else { } else {
status = c->inner_creds->vtable->create_security_connector( status = c->inner_creds->vtable->create_security_connector(
c->inner_creds, c->call_creds, target, args, sc, new_args); exec_ctx, c->inner_creds, c->call_creds, target, args, sc, new_args);
} }
return status; return status;
} }

@ -66,8 +66,8 @@ grpc_credentials_metadata_request *grpc_credentials_metadata_request_create(
} }
void grpc_credentials_metadata_request_destroy( void grpc_credentials_metadata_request_destroy(
grpc_credentials_metadata_request *r) { grpc_exec_ctx *exec_ctx, grpc_credentials_metadata_request *r) {
grpc_call_credentials_unref(r->creds); grpc_call_credentials_unref(exec_ctx, r->creds);
grpc_http_response_destroy(&r->response); grpc_http_response_destroy(&r->response);
gpr_free(r); gpr_free(r);
} }
@ -79,17 +79,22 @@ grpc_channel_credentials *grpc_channel_credentials_ref(
return creds; return creds;
} }
void grpc_channel_credentials_unref(grpc_channel_credentials *creds) { void grpc_channel_credentials_unref(grpc_exec_ctx *exec_ctx,
grpc_channel_credentials *creds) {
if (creds == NULL) return; if (creds == NULL) return;
if (gpr_unref(&creds->refcount)) { if (gpr_unref(&creds->refcount)) {
if (creds->vtable->destruct != NULL) creds->vtable->destruct(creds); if (creds->vtable->destruct != NULL) {
creds->vtable->destruct(exec_ctx, creds);
}
gpr_free(creds); gpr_free(creds);
} }
} }
void grpc_channel_credentials_release(grpc_channel_credentials *creds) { void grpc_channel_credentials_release(grpc_channel_credentials *creds) {
GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds)); GRPC_API_TRACE("grpc_channel_credentials_release(creds=%p)", 1, (creds));
grpc_channel_credentials_unref(creds); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_channel_credentials_unref(&exec_ctx, creds);
grpc_exec_ctx_finish(&exec_ctx);
} }
grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds) { grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds) {
@ -98,17 +103,22 @@ grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds) {
return creds; return creds;
} }
void grpc_call_credentials_unref(grpc_call_credentials *creds) { void grpc_call_credentials_unref(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
if (creds == NULL) return; if (creds == NULL) return;
if (gpr_unref(&creds->refcount)) { if (gpr_unref(&creds->refcount)) {
if (creds->vtable->destruct != NULL) creds->vtable->destruct(creds); if (creds->vtable->destruct != NULL) {
creds->vtable->destruct(exec_ctx, creds);
}
gpr_free(creds); gpr_free(creds);
} }
} }
void grpc_call_credentials_release(grpc_call_credentials *creds) { void grpc_call_credentials_release(grpc_call_credentials *creds) {
GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds)); GRPC_API_TRACE("grpc_call_credentials_release(creds=%p)", 1, (creds));
grpc_call_credentials_unref(creds); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_call_credentials_unref(&exec_ctx, creds);
grpc_exec_ctx_finish(&exec_ctx);
} }
void grpc_call_credentials_get_request_metadata( void grpc_call_credentials_get_request_metadata(
@ -126,16 +136,16 @@ void grpc_call_credentials_get_request_metadata(
} }
grpc_security_status grpc_channel_credentials_create_security_connector( grpc_security_status grpc_channel_credentials_create_security_connector(
grpc_channel_credentials *channel_creds, const char *target, grpc_exec_ctx *exec_ctx, grpc_channel_credentials *channel_creds,
const grpc_channel_args *args, grpc_channel_security_connector **sc, const char *target, const grpc_channel_args *args,
grpc_channel_args **new_args) { grpc_channel_security_connector **sc, grpc_channel_args **new_args) {
*new_args = NULL; *new_args = NULL;
if (channel_creds == NULL) { if (channel_creds == NULL) {
return GRPC_SECURITY_ERROR; return GRPC_SECURITY_ERROR;
} }
GPR_ASSERT(channel_creds->vtable->create_security_connector != NULL); GPR_ASSERT(channel_creds->vtable->create_security_connector != NULL);
return channel_creds->vtable->create_security_connector( return channel_creds->vtable->create_security_connector(
channel_creds, NULL, target, args, sc, new_args); exec_ctx, channel_creds, NULL, target, args, sc, new_args);
} }
grpc_channel_credentials * grpc_channel_credentials *
@ -157,10 +167,13 @@ grpc_server_credentials *grpc_server_credentials_ref(
return creds; return creds;
} }
void grpc_server_credentials_unref(grpc_server_credentials *creds) { void grpc_server_credentials_unref(grpc_exec_ctx *exec_ctx,
grpc_server_credentials *creds) {
if (creds == NULL) return; if (creds == NULL) return;
if (gpr_unref(&creds->refcount)) { if (gpr_unref(&creds->refcount)) {
if (creds->vtable->destruct != NULL) creds->vtable->destruct(creds); if (creds->vtable->destruct != NULL) {
creds->vtable->destruct(exec_ctx, creds);
}
if (creds->processor.destroy != NULL && creds->processor.state != NULL) { if (creds->processor.destroy != NULL && creds->processor.state != NULL) {
creds->processor.destroy(creds->processor.state); creds->processor.destroy(creds->processor.state);
} }
@ -170,16 +183,19 @@ void grpc_server_credentials_unref(grpc_server_credentials *creds) {
void grpc_server_credentials_release(grpc_server_credentials *creds) { void grpc_server_credentials_release(grpc_server_credentials *creds) {
GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds)); GRPC_API_TRACE("grpc_server_credentials_release(creds=%p)", 1, (creds));
grpc_server_credentials_unref(creds); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_server_credentials_unref(&exec_ctx, creds);
grpc_exec_ctx_finish(&exec_ctx);
} }
grpc_security_status grpc_server_credentials_create_security_connector( grpc_security_status grpc_server_credentials_create_security_connector(
grpc_server_credentials *creds, grpc_server_security_connector **sc) { grpc_exec_ctx *exec_ctx, grpc_server_credentials *creds,
grpc_server_security_connector **sc) {
if (creds == NULL || creds->vtable->create_security_connector == NULL) { if (creds == NULL || creds->vtable->create_security_connector == NULL) {
gpr_log(GPR_ERROR, "Server credentials cannot create security context."); gpr_log(GPR_ERROR, "Server credentials cannot create security context.");
return GRPC_SECURITY_ERROR; return GRPC_SECURITY_ERROR;
} }
return creds->vtable->create_security_connector(creds, sc); return creds->vtable->create_security_connector(exec_ctx, creds, sc);
} }
void grpc_server_credentials_set_auth_metadata_processor( void grpc_server_credentials_set_auth_metadata_processor(
@ -196,8 +212,9 @@ void grpc_server_credentials_set_auth_metadata_processor(
creds->processor = processor; creds->processor = processor;
} }
static void server_credentials_pointer_arg_destroy(void *p) { static void server_credentials_pointer_arg_destroy(grpc_exec_ctx *exec_ctx,
grpc_server_credentials_unref(p); void *p) {
grpc_server_credentials_unref(exec_ctx, p);
} }
static void *server_credentials_pointer_arg_copy(void *p) { static void *server_credentials_pointer_arg_copy(void *p) {

@ -101,12 +101,13 @@ void grpc_override_well_known_credentials_path_getter(
/* --- grpc_channel_credentials. --- */ /* --- grpc_channel_credentials. --- */
typedef struct { typedef struct {
void (*destruct)(grpc_channel_credentials *c); void (*destruct)(grpc_exec_ctx *exec_ctx, grpc_channel_credentials *c);
grpc_security_status (*create_security_connector)( grpc_security_status (*create_security_connector)(
grpc_channel_credentials *c, grpc_call_credentials *call_creds, grpc_exec_ctx *exec_ctx, grpc_channel_credentials *c,
const char *target, const grpc_channel_args *args, grpc_call_credentials *call_creds, const char *target,
grpc_channel_security_connector **sc, grpc_channel_args **new_args); const grpc_channel_args *args, grpc_channel_security_connector **sc,
grpc_channel_args **new_args);
grpc_channel_credentials *(*duplicate_without_call_credentials)( grpc_channel_credentials *(*duplicate_without_call_credentials)(
grpc_channel_credentials *c); grpc_channel_credentials *c);
@ -120,16 +121,17 @@ struct grpc_channel_credentials {
grpc_channel_credentials *grpc_channel_credentials_ref( grpc_channel_credentials *grpc_channel_credentials_ref(
grpc_channel_credentials *creds); grpc_channel_credentials *creds);
void grpc_channel_credentials_unref(grpc_channel_credentials *creds); void grpc_channel_credentials_unref(grpc_exec_ctx *exec_ctx,
grpc_channel_credentials *creds);
/* Creates a security connector for the channel. May also create new channel /* Creates a security connector for the channel. May also create new channel
args for the channel to be used in place of the passed in const args if args for the channel to be used in place of the passed in const args if
returned non NULL. In that case the caller is responsible for destroying returned non NULL. In that case the caller is responsible for destroying
new_args after channel creation. */ new_args after channel creation. */
grpc_security_status grpc_channel_credentials_create_security_connector( grpc_security_status grpc_channel_credentials_create_security_connector(
grpc_channel_credentials *creds, const char *target, grpc_exec_ctx *exec_ctx, grpc_channel_credentials *creds,
const grpc_channel_args *args, grpc_channel_security_connector **sc, const char *target, const grpc_channel_args *args,
grpc_channel_args **new_args); grpc_channel_security_connector **sc, grpc_channel_args **new_args);
/* Creates a version of the channel credentials without any attached call /* Creates a version of the channel credentials without any attached call
credentials. This can be used in order to open a channel to a non-trusted credentials. This can be used in order to open a channel to a non-trusted
@ -162,7 +164,8 @@ void grpc_credentials_md_store_add_cstrings(grpc_credentials_md_store *store,
const char *key, const char *value); const char *key, const char *value);
grpc_credentials_md_store *grpc_credentials_md_store_ref( grpc_credentials_md_store *grpc_credentials_md_store_ref(
grpc_credentials_md_store *store); grpc_credentials_md_store *store);
void grpc_credentials_md_store_unref(grpc_credentials_md_store *store); void grpc_credentials_md_store_unref(grpc_exec_ctx *exec_ctx,
grpc_credentials_md_store *store);
/* --- grpc_call_credentials. --- */ /* --- grpc_call_credentials. --- */
@ -172,7 +175,7 @@ typedef void (*grpc_credentials_metadata_cb)(
size_t num_md, grpc_credentials_status status, const char *error_details); size_t num_md, grpc_credentials_status status, const char *error_details);
typedef struct { typedef struct {
void (*destruct)(grpc_call_credentials *c); void (*destruct)(grpc_exec_ctx *exec_ctx, grpc_call_credentials *c);
void (*get_request_metadata)(grpc_exec_ctx *exec_ctx, void (*get_request_metadata)(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *c, grpc_call_credentials *c,
grpc_polling_entity *pollent, grpc_polling_entity *pollent,
@ -188,7 +191,8 @@ struct grpc_call_credentials {
}; };
grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds); grpc_call_credentials *grpc_call_credentials_ref(grpc_call_credentials *creds);
void grpc_call_credentials_unref(grpc_call_credentials *creds); void grpc_call_credentials_unref(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds);
void grpc_call_credentials_get_request_metadata( void grpc_call_credentials_get_request_metadata(
grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds, grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds,
grpc_polling_entity *pollent, grpc_auth_metadata_context context, grpc_polling_entity *pollent, grpc_auth_metadata_context context,
@ -202,9 +206,10 @@ grpc_call_credentials *grpc_md_only_test_credentials_create(
/* --- grpc_server_credentials. --- */ /* --- grpc_server_credentials. --- */
typedef struct { typedef struct {
void (*destruct)(grpc_server_credentials *c); void (*destruct)(grpc_exec_ctx *exec_ctx, grpc_server_credentials *c);
grpc_security_status (*create_security_connector)( grpc_security_status (*create_security_connector)(
grpc_server_credentials *c, grpc_server_security_connector **sc); grpc_exec_ctx *exec_ctx, grpc_server_credentials *c,
grpc_server_security_connector **sc);
} grpc_server_credentials_vtable; } grpc_server_credentials_vtable;
struct grpc_server_credentials { struct grpc_server_credentials {
@ -215,12 +220,14 @@ struct grpc_server_credentials {
}; };
grpc_security_status grpc_server_credentials_create_security_connector( grpc_security_status grpc_server_credentials_create_security_connector(
grpc_server_credentials *creds, grpc_server_security_connector **sc); grpc_exec_ctx *exec_ctx, grpc_server_credentials *creds,
grpc_server_security_connector **sc);
grpc_server_credentials *grpc_server_credentials_ref( grpc_server_credentials *grpc_server_credentials_ref(
grpc_server_credentials *creds); grpc_server_credentials *creds);
void grpc_server_credentials_unref(grpc_server_credentials *creds); void grpc_server_credentials_unref(grpc_exec_ctx *exec_ctx,
grpc_server_credentials *creds);
#define GRPC_SERVER_CREDENTIALS_ARG "grpc.server_credentials" #define GRPC_SERVER_CREDENTIALS_ARG "grpc.server_credentials"
@ -243,6 +250,6 @@ grpc_credentials_metadata_request *grpc_credentials_metadata_request_create(
void *user_data); void *user_data);
void grpc_credentials_metadata_request_destroy( void grpc_credentials_metadata_request_destroy(
grpc_credentials_metadata_request *r); grpc_exec_ctx *exec_ctx, grpc_credentials_metadata_request *r);
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H */ #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_CREDENTIALS_H */

@ -37,6 +37,8 @@
#include <string.h> #include <string.h>
#include "src/core/lib/slice/slice_internal.h"
static void store_ensure_capacity(grpc_credentials_md_store *store) { static void store_ensure_capacity(grpc_credentials_md_store *store) {
if (store->num_entries == store->allocated) { if (store->num_entries == store->allocated) {
store->allocated = (store->allocated == 0) ? 1 : store->allocated * 2; store->allocated = (store->allocated == 0) ? 1 : store->allocated * 2;
@ -62,8 +64,8 @@ void grpc_credentials_md_store_add(grpc_credentials_md_store *store,
grpc_slice key, grpc_slice value) { grpc_slice key, grpc_slice value) {
if (store == NULL) return; if (store == NULL) return;
store_ensure_capacity(store); store_ensure_capacity(store);
store->entries[store->num_entries].key = grpc_slice_ref(key); store->entries[store->num_entries].key = grpc_slice_ref_internal(key);
store->entries[store->num_entries].value = grpc_slice_ref(value); store->entries[store->num_entries].value = grpc_slice_ref_internal(value);
store->num_entries++; store->num_entries++;
} }
@ -85,14 +87,15 @@ grpc_credentials_md_store *grpc_credentials_md_store_ref(
return store; return store;
} }
void grpc_credentials_md_store_unref(grpc_credentials_md_store *store) { void grpc_credentials_md_store_unref(grpc_exec_ctx *exec_ctx,
grpc_credentials_md_store *store) {
if (store == NULL) return; if (store == NULL) return;
if (gpr_unref(&store->refcount)) { if (gpr_unref(&store->refcount)) {
if (store->entries != NULL) { if (store->entries != NULL) {
size_t i; size_t i;
for (i = 0; i < store->num_entries; i++) { for (i = 0; i < store->num_entries; i++) {
grpc_slice_unref(store->entries[i].key); grpc_slice_unref_internal(exec_ctx, store->entries[i].key);
grpc_slice_unref(store->entries[i].value); grpc_slice_unref_internal(exec_ctx, store->entries[i].value);
} }
gpr_free(store->entries); gpr_free(store->entries);
} }

@ -45,16 +45,18 @@
/* -- Fake transport security credentials. -- */ /* -- Fake transport security credentials. -- */
static grpc_security_status fake_transport_security_create_security_connector( static grpc_security_status fake_transport_security_create_security_connector(
grpc_channel_credentials *c, grpc_call_credentials *call_creds, grpc_exec_ctx *exec_ctx, grpc_channel_credentials *c,
const char *target, const grpc_channel_args *args, grpc_call_credentials *call_creds, const char *target,
grpc_channel_security_connector **sc, grpc_channel_args **new_args) { const grpc_channel_args *args, grpc_channel_security_connector **sc,
grpc_channel_args **new_args) {
*sc = grpc_fake_channel_security_connector_create(call_creds); *sc = grpc_fake_channel_security_connector_create(call_creds);
return GRPC_SECURITY_OK; return GRPC_SECURITY_OK;
} }
static grpc_security_status static grpc_security_status
fake_transport_security_server_create_security_connector( fake_transport_security_server_create_security_connector(
grpc_server_credentials *c, grpc_server_security_connector **sc) { grpc_exec_ctx *exec_ctx, grpc_server_credentials *c,
grpc_server_security_connector **sc) {
*sc = grpc_fake_server_security_connector_create(); *sc = grpc_fake_server_security_connector_create();
return GRPC_SECURITY_OK; return GRPC_SECURITY_OK;
} }
@ -89,9 +91,10 @@ grpc_server_credentials *grpc_fake_transport_security_server_credentials_create(
/* -- Metadata-only test credentials. -- */ /* -- Metadata-only test credentials. -- */
static void md_only_test_destruct(grpc_call_credentials *creds) { static void md_only_test_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)creds; grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)creds;
grpc_credentials_md_store_unref(c->md_store); grpc_credentials_md_store_unref(exec_ctx, c->md_store);
} }
static void on_simulated_token_fetch_done(grpc_exec_ctx *exec_ctx, static void on_simulated_token_fetch_done(grpc_exec_ctx *exec_ctx,
@ -101,7 +104,7 @@ static void on_simulated_token_fetch_done(grpc_exec_ctx *exec_ctx,
grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)r->creds; grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)r->creds;
r->cb(exec_ctx, r->user_data, c->md_store->entries, c->md_store->num_entries, r->cb(exec_ctx, r->user_data, c->md_store->entries, c->md_store->num_entries,
GRPC_CREDENTIALS_OK, NULL); GRPC_CREDENTIALS_OK, NULL);
grpc_credentials_metadata_request_destroy(r); grpc_credentials_metadata_request_destroy(exec_ctx, r);
} }
static void md_only_test_get_request_metadata( static void md_only_test_get_request_metadata(

@ -45,6 +45,7 @@
#include "src/core/lib/iomgr/polling_entity.h" #include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/security/credentials/jwt/jwt_credentials.h" #include "src/core/lib/security/credentials/jwt/jwt_credentials.h"
#include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h" #include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/slice/slice_string_helpers.h"
#include "src/core/lib/support/env.h" #include "src/core/lib/support/env.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
@ -101,11 +102,10 @@ static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, grpc_error *e) {
grpc_pollset_destroy(p); grpc_pollset_destroy(p);
} }
static int is_stack_running_on_compute_engine(void) { static int is_stack_running_on_compute_engine(grpc_exec_ctx *exec_ctx) {
compute_engine_detector detector; compute_engine_detector detector;
grpc_httpcli_request request; grpc_httpcli_request request;
grpc_httpcli_context context; grpc_httpcli_context context;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_closure destroy_closure; grpc_closure destroy_closure;
/* The http call is local. If it takes more than one sec, it is for sure not /* The http call is local. If it takes more than one sec, it is for sure not
@ -128,14 +128,14 @@ static int is_stack_running_on_compute_engine(void) {
grpc_resource_quota *resource_quota = grpc_resource_quota *resource_quota =
grpc_resource_quota_create("google_default_credentials"); grpc_resource_quota_create("google_default_credentials");
grpc_httpcli_get( grpc_httpcli_get(
&exec_ctx, &context, &detector.pollent, resource_quota, &request, exec_ctx, &context, &detector.pollent, resource_quota, &request,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay), gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay),
grpc_closure_create(on_compute_engine_detection_http_response, &detector, grpc_closure_create(on_compute_engine_detection_http_response, &detector,
grpc_schedule_on_exec_ctx), grpc_schedule_on_exec_ctx),
&detector.response); &detector.response);
grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
grpc_exec_ctx_flush(&exec_ctx); grpc_exec_ctx_flush(exec_ctx);
/* Block until we get the response. This is not ideal but this should only be /* Block until we get the response. This is not ideal but this should only be
called once for the lifetime of the process by the default credentials. */ called once for the lifetime of the process by the default credentials. */
@ -144,7 +144,7 @@ static int is_stack_running_on_compute_engine(void) {
grpc_pollset_worker *worker = NULL; grpc_pollset_worker *worker = NULL;
if (!GRPC_LOG_IF_ERROR( if (!GRPC_LOG_IF_ERROR(
"pollset_work", "pollset_work",
grpc_pollset_work(&exec_ctx, grpc_pollset_work(exec_ctx,
grpc_polling_entity_pollset(&detector.pollent), grpc_polling_entity_pollset(&detector.pollent),
&worker, gpr_now(GPR_CLOCK_MONOTONIC), &worker, gpr_now(GPR_CLOCK_MONOTONIC),
gpr_inf_future(GPR_CLOCK_MONOTONIC)))) { gpr_inf_future(GPR_CLOCK_MONOTONIC)))) {
@ -158,11 +158,11 @@ static int is_stack_running_on_compute_engine(void) {
grpc_closure_init(&destroy_closure, destroy_pollset, grpc_closure_init(&destroy_closure, destroy_pollset,
grpc_polling_entity_pollset(&detector.pollent), grpc_polling_entity_pollset(&detector.pollent),
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
grpc_pollset_shutdown(&exec_ctx, grpc_pollset_shutdown(exec_ctx,
grpc_polling_entity_pollset(&detector.pollent), grpc_polling_entity_pollset(&detector.pollent),
&destroy_closure); &destroy_closure);
grpc_exec_ctx_finish(&exec_ctx);
g_polling_mu = NULL; g_polling_mu = NULL;
grpc_exec_ctx_flush(exec_ctx);
gpr_free(grpc_polling_entity_pollset(&detector.pollent)); gpr_free(grpc_polling_entity_pollset(&detector.pollent));
grpc_http_response_destroy(&detector.response); grpc_http_response_destroy(&detector.response);
@ -172,7 +172,7 @@ static int is_stack_running_on_compute_engine(void) {
/* Takes ownership of creds_path if not NULL. */ /* Takes ownership of creds_path if not NULL. */
static grpc_error *create_default_creds_from_path( static grpc_error *create_default_creds_from_path(
char *creds_path, grpc_call_credentials **creds) { grpc_exec_ctx *exec_ctx, char *creds_path, grpc_call_credentials **creds) {
grpc_json *json = NULL; grpc_json *json = NULL;
grpc_auth_json_key key; grpc_auth_json_key key;
grpc_auth_refresh_token token; grpc_auth_refresh_token token;
@ -202,7 +202,7 @@ static grpc_error *create_default_creds_from_path(
if (grpc_auth_json_key_is_valid(&key)) { if (grpc_auth_json_key_is_valid(&key)) {
result = result =
grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
key, grpc_max_auth_token_lifetime()); exec_ctx, key, grpc_max_auth_token_lifetime());
if (result == NULL) { if (result == NULL) {
error = GRPC_ERROR_CREATE( error = GRPC_ERROR_CREATE(
"grpc_service_account_jwt_access_credentials_create_from_auth_json_" "grpc_service_account_jwt_access_credentials_create_from_auth_json_"
@ -227,7 +227,7 @@ static grpc_error *create_default_creds_from_path(
end: end:
GPR_ASSERT((result == NULL) + (error == GRPC_ERROR_NONE) == 1); GPR_ASSERT((result == NULL) + (error == GRPC_ERROR_NONE) == 1);
if (creds_path != NULL) gpr_free(creds_path); if (creds_path != NULL) gpr_free(creds_path);
grpc_slice_unref(creds_data); grpc_slice_unref_internal(exec_ctx, creds_data);
if (json != NULL) grpc_json_destroy(json); if (json != NULL) grpc_json_destroy(json);
*creds = result; *creds = result;
return error; return error;
@ -238,6 +238,7 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) {
grpc_call_credentials *call_creds = NULL; grpc_call_credentials *call_creds = NULL;
grpc_error *error = GRPC_ERROR_CREATE("Failed to create Google credentials"); grpc_error *error = GRPC_ERROR_CREATE("Failed to create Google credentials");
grpc_error *err; grpc_error *err;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ()); GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ());
@ -252,20 +253,22 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) {
/* First, try the environment variable. */ /* First, try the environment variable. */
err = create_default_creds_from_path( err = create_default_creds_from_path(
gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds); &exec_ctx, gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds);
if (err == GRPC_ERROR_NONE) goto end; if (err == GRPC_ERROR_NONE) goto end;
error = grpc_error_add_child(error, err); error = grpc_error_add_child(error, err);
/* Then the well-known file. */ /* Then the well-known file. */
err = create_default_creds_from_path( err = create_default_creds_from_path(
grpc_get_well_known_google_credentials_file_path(), &call_creds); &exec_ctx, grpc_get_well_known_google_credentials_file_path(),
&call_creds);
if (err == GRPC_ERROR_NONE) goto end; if (err == GRPC_ERROR_NONE) goto end;
error = grpc_error_add_child(error, err); error = grpc_error_add_child(error, err);
/* At last try to see if we're on compute engine (do the detection only once /* At last try to see if we're on compute engine (do the detection only once
since it requires a network test). */ since it requires a network test). */
if (!compute_engine_detection_done) { if (!compute_engine_detection_done) {
int need_compute_engine_creds = is_stack_running_on_compute_engine(); int need_compute_engine_creds =
is_stack_running_on_compute_engine(&exec_ctx);
compute_engine_detection_done = 1; compute_engine_detection_done = 1;
if (need_compute_engine_creds) { if (need_compute_engine_creds) {
call_creds = grpc_google_compute_engine_credentials_create(NULL); call_creds = grpc_google_compute_engine_credentials_create(NULL);
@ -288,8 +291,8 @@ end:
grpc_composite_channel_credentials_create(ssl_creds, call_creds, grpc_composite_channel_credentials_create(ssl_creds, call_creds,
NULL)); NULL));
GPR_ASSERT(default_credentials != NULL); GPR_ASSERT(default_credentials != NULL);
grpc_channel_credentials_unref(ssl_creds); grpc_channel_credentials_unref(&exec_ctx, ssl_creds);
grpc_call_credentials_unref(call_creds); grpc_call_credentials_unref(&exec_ctx, call_creds);
result = default_credentials; result = default_credentials;
} else { } else {
gpr_log(GPR_ERROR, "Could not create google default credentials."); gpr_log(GPR_ERROR, "Could not create google default credentials.");
@ -301,18 +304,21 @@ end:
} else { } else {
GRPC_ERROR_UNREF(error); GRPC_ERROR_UNREF(error);
} }
grpc_exec_ctx_finish(&exec_ctx);
return result; return result;
} }
void grpc_flush_cached_google_default_credentials(void) { void grpc_flush_cached_google_default_credentials(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_once_init(&g_once, init_default_credentials); gpr_once_init(&g_once, init_default_credentials);
gpr_mu_lock(&g_state_mu); gpr_mu_lock(&g_state_mu);
if (default_credentials != NULL) { if (default_credentials != NULL) {
grpc_channel_credentials_unref(default_credentials); grpc_channel_credentials_unref(&exec_ctx, default_credentials);
default_credentials = NULL; default_credentials = NULL;
} }
compute_engine_detection_done = 0; compute_engine_detection_done = 0;
gpr_mu_unlock(&g_state_mu); gpr_mu_unlock(&g_state_mu);
grpc_exec_ctx_finish(&exec_ctx);
} }
/* -- Well known credentials path. -- */ /* -- Well known credentials path. -- */

@ -42,9 +42,10 @@
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/sync.h> #include <grpc/support/sync.h>
static void iam_destruct(grpc_call_credentials *creds) { static void iam_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_google_iam_credentials *c = (grpc_google_iam_credentials *)creds; grpc_google_iam_credentials *c = (grpc_google_iam_credentials *)creds;
grpc_credentials_md_store_unref(c->iam_md); grpc_credentials_md_store_unref(exec_ctx, c->iam_md);
} }
static void iam_get_request_metadata(grpc_exec_ctx *exec_ctx, static void iam_get_request_metadata(grpc_exec_ctx *exec_ctx,

@ -42,9 +42,10 @@
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/sync.h> #include <grpc/support/sync.h>
static void jwt_reset_cache(grpc_service_account_jwt_access_credentials *c) { static void jwt_reset_cache(grpc_exec_ctx *exec_ctx,
grpc_service_account_jwt_access_credentials *c) {
if (c->cached.jwt_md != NULL) { if (c->cached.jwt_md != NULL) {
grpc_credentials_md_store_unref(c->cached.jwt_md); grpc_credentials_md_store_unref(exec_ctx, c->cached.jwt_md);
c->cached.jwt_md = NULL; c->cached.jwt_md = NULL;
} }
if (c->cached.service_url != NULL) { if (c->cached.service_url != NULL) {
@ -54,11 +55,12 @@ static void jwt_reset_cache(grpc_service_account_jwt_access_credentials *c) {
c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME); c->cached.jwt_expiration = gpr_inf_past(GPR_CLOCK_REALTIME);
} }
static void jwt_destruct(grpc_call_credentials *creds) { static void jwt_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_service_account_jwt_access_credentials *c = grpc_service_account_jwt_access_credentials *c =
(grpc_service_account_jwt_access_credentials *)creds; (grpc_service_account_jwt_access_credentials *)creds;
grpc_auth_json_key_destruct(&c->key); grpc_auth_json_key_destruct(&c->key);
jwt_reset_cache(c); jwt_reset_cache(exec_ctx, c);
gpr_mu_destroy(&c->cache_mu); gpr_mu_destroy(&c->cache_mu);
} }
@ -92,7 +94,7 @@ static void jwt_get_request_metadata(grpc_exec_ctx *exec_ctx,
char *jwt = NULL; char *jwt = NULL;
/* Generate a new jwt. */ /* Generate a new jwt. */
gpr_mu_lock(&c->cache_mu); gpr_mu_lock(&c->cache_mu);
jwt_reset_cache(c); jwt_reset_cache(exec_ctx, c);
jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url, jwt = grpc_jwt_encode_and_sign(&c->key, context.service_url,
c->jwt_lifetime, NULL); c->jwt_lifetime, NULL);
if (jwt != NULL) { if (jwt != NULL) {
@ -114,7 +116,7 @@ static void jwt_get_request_metadata(grpc_exec_ctx *exec_ctx,
if (jwt_md != NULL) { if (jwt_md != NULL) {
cb(exec_ctx, user_data, jwt_md->entries, jwt_md->num_entries, cb(exec_ctx, user_data, jwt_md->entries, jwt_md->num_entries,
GRPC_CREDENTIALS_OK, NULL); GRPC_CREDENTIALS_OK, NULL);
grpc_credentials_md_store_unref(jwt_md); grpc_credentials_md_store_unref(exec_ctx, jwt_md);
} else { } else {
cb(exec_ctx, user_data, NULL, 0, GRPC_CREDENTIALS_ERROR, cb(exec_ctx, user_data, NULL, 0, GRPC_CREDENTIALS_ERROR,
"Could not generate JWT."); "Could not generate JWT.");
@ -126,7 +128,8 @@ static grpc_call_credentials_vtable jwt_vtable = {jwt_destruct,
grpc_call_credentials * grpc_call_credentials *
grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
grpc_auth_json_key key, gpr_timespec token_lifetime) { grpc_exec_ctx *exec_ctx, grpc_auth_json_key key,
gpr_timespec token_lifetime) {
grpc_service_account_jwt_access_credentials *c; grpc_service_account_jwt_access_credentials *c;
if (!grpc_auth_json_key_is_valid(&key)) { if (!grpc_auth_json_key_is_valid(&key)) {
gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation"); gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
@ -140,7 +143,7 @@ grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
c->key = key; c->key = key;
c->jwt_lifetime = token_lifetime; c->jwt_lifetime = token_lifetime;
gpr_mu_init(&c->cache_mu); gpr_mu_init(&c->cache_mu);
jwt_reset_cache(c); jwt_reset_cache(exec_ctx, c);
return &c->base; return &c->base;
} }
@ -183,6 +186,11 @@ grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
gpr_free(clean_json); gpr_free(clean_json);
} }
GPR_ASSERT(reserved == NULL); GPR_ASSERT(reserved == NULL);
return grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_auth_json_key_create_from_string(json_key), token_lifetime); grpc_call_credentials *creds =
grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
&exec_ctx, grpc_auth_json_key_create_from_string(json_key),
token_lifetime);
grpc_exec_ctx_finish(&exec_ctx);
return creds;
} }

@ -57,6 +57,7 @@ typedef struct {
// Takes ownership of the key. // Takes ownership of the key.
grpc_call_credentials * grpc_call_credentials *
grpc_service_account_jwt_access_credentials_create_from_auth_json_key( grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
grpc_auth_json_key key, gpr_timespec token_lifetime); grpc_exec_ctx *exec_ctx, grpc_auth_json_key key,
gpr_timespec token_lifetime);
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H */ #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_JWT_JWT_CREDENTIALS_H */

@ -36,12 +36,6 @@
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
#include "src/core/lib/http/httpcli.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/security/util/b64.h"
#include "src/core/lib/support/string.h"
#include "src/core/lib/tsi/ssl_types.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
@ -49,6 +43,13 @@
#include <grpc/support/useful.h> #include <grpc/support/useful.h>
#include <openssl/pem.h> #include <openssl/pem.h>
#include "src/core/lib/http/httpcli.h"
#include "src/core/lib/iomgr/polling_entity.h"
#include "src/core/lib/security/util/b64.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h"
#include "src/core/lib/tsi/ssl_types.h"
/* --- Utils. --- */ /* --- Utils. --- */
const char *grpc_jwt_verifier_status_to_string( const char *grpc_jwt_verifier_status_to_string(
@ -85,11 +86,12 @@ static const EVP_MD *evp_md_from_alg(const char *alg) {
} }
} }
static grpc_json *parse_json_part_from_jwt(const char *str, size_t len, static grpc_json *parse_json_part_from_jwt(grpc_exec_ctx *exec_ctx,
const char *str, size_t len,
grpc_slice *buffer) { grpc_slice *buffer) {
grpc_json *json; grpc_json *json;
*buffer = grpc_base64_decode_with_len(str, len, 1); *buffer = grpc_base64_decode_with_len(exec_ctx, str, len, 1);
if (GRPC_SLICE_IS_EMPTY(*buffer)) { if (GRPC_SLICE_IS_EMPTY(*buffer)) {
gpr_log(GPR_ERROR, "Invalid base64."); gpr_log(GPR_ERROR, "Invalid base64.");
return NULL; return NULL;
@ -97,7 +99,7 @@ static grpc_json *parse_json_part_from_jwt(const char *str, size_t len,
json = grpc_json_parse_string_with_len((char *)GRPC_SLICE_START_PTR(*buffer), json = grpc_json_parse_string_with_len((char *)GRPC_SLICE_START_PTR(*buffer),
GRPC_SLICE_LENGTH(*buffer)); GRPC_SLICE_LENGTH(*buffer));
if (json == NULL) { if (json == NULL) {
grpc_slice_unref(*buffer); grpc_slice_unref_internal(exec_ctx, *buffer);
gpr_log(GPR_ERROR, "JSON parsing error."); gpr_log(GPR_ERROR, "JSON parsing error.");
} }
return json; return json;
@ -133,13 +135,14 @@ typedef struct {
grpc_slice buffer; grpc_slice buffer;
} jose_header; } jose_header;
static void jose_header_destroy(jose_header *h) { static void jose_header_destroy(grpc_exec_ctx *exec_ctx, jose_header *h) {
grpc_slice_unref(h->buffer); grpc_slice_unref_internal(exec_ctx, h->buffer);
gpr_free(h); gpr_free(h);
} }
/* Takes ownership of json and buffer. */ /* Takes ownership of json and buffer. */
static jose_header *jose_header_from_json(grpc_json *json, grpc_slice buffer) { static jose_header *jose_header_from_json(grpc_exec_ctx *exec_ctx,
grpc_json *json, grpc_slice buffer) {
grpc_json *cur; grpc_json *cur;
jose_header *h = gpr_malloc(sizeof(jose_header)); jose_header *h = gpr_malloc(sizeof(jose_header));
memset(h, 0, sizeof(jose_header)); memset(h, 0, sizeof(jose_header));
@ -174,7 +177,7 @@ static jose_header *jose_header_from_json(grpc_json *json, grpc_slice buffer) {
error: error:
grpc_json_destroy(json); grpc_json_destroy(json);
jose_header_destroy(h); jose_header_destroy(exec_ctx, h);
return NULL; return NULL;
} }
@ -194,9 +197,9 @@ struct grpc_jwt_claims {
grpc_slice buffer; grpc_slice buffer;
}; };
void grpc_jwt_claims_destroy(grpc_jwt_claims *claims) { void grpc_jwt_claims_destroy(grpc_exec_ctx *exec_ctx, grpc_jwt_claims *claims) {
grpc_json_destroy(claims->json); grpc_json_destroy(claims->json);
grpc_slice_unref(claims->buffer); grpc_slice_unref_internal(exec_ctx, claims->buffer);
gpr_free(claims); gpr_free(claims);
} }
@ -241,7 +244,8 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims *claims) {
} }
/* Takes ownership of json and buffer even in case of failure. */ /* Takes ownership of json and buffer even in case of failure. */
grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_json *json, grpc_slice buffer) { grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_exec_ctx *exec_ctx,
grpc_json *json, grpc_slice buffer) {
grpc_json *cur; grpc_json *cur;
grpc_jwt_claims *claims = gpr_malloc(sizeof(grpc_jwt_claims)); grpc_jwt_claims *claims = gpr_malloc(sizeof(grpc_jwt_claims));
memset(claims, 0, sizeof(grpc_jwt_claims)); memset(claims, 0, sizeof(grpc_jwt_claims));
@ -282,7 +286,7 @@ grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_json *json, grpc_slice buffer) {
return claims; return claims;
error: error:
grpc_jwt_claims_destroy(claims); grpc_jwt_claims_destroy(exec_ctx, claims);
return NULL; return NULL;
} }
@ -374,12 +378,12 @@ static verifier_cb_ctx *verifier_cb_ctx_create(
return ctx; return ctx;
} }
void verifier_cb_ctx_destroy(verifier_cb_ctx *ctx) { void verifier_cb_ctx_destroy(grpc_exec_ctx *exec_ctx, verifier_cb_ctx *ctx) {
if (ctx->audience != NULL) gpr_free(ctx->audience); if (ctx->audience != NULL) gpr_free(ctx->audience);
if (ctx->claims != NULL) grpc_jwt_claims_destroy(ctx->claims); if (ctx->claims != NULL) grpc_jwt_claims_destroy(exec_ctx, ctx->claims);
grpc_slice_unref(ctx->signature); grpc_slice_unref_internal(exec_ctx, ctx->signature);
grpc_slice_unref(ctx->signed_data); grpc_slice_unref_internal(exec_ctx, ctx->signed_data);
jose_header_destroy(ctx->header); jose_header_destroy(exec_ctx, ctx->header);
for (size_t i = 0; i < HTTP_RESPONSE_COUNT; i++) { for (size_t i = 0; i < HTTP_RESPONSE_COUNT; i++) {
grpc_http_response_destroy(&ctx->responses[i]); grpc_http_response_destroy(&ctx->responses[i]);
} }
@ -459,23 +463,24 @@ end:
return result; return result;
} }
static BIGNUM *bignum_from_base64(const char *b64) { static BIGNUM *bignum_from_base64(grpc_exec_ctx *exec_ctx, const char *b64) {
BIGNUM *result = NULL; BIGNUM *result = NULL;
grpc_slice bin; grpc_slice bin;
if (b64 == NULL) return NULL; if (b64 == NULL) return NULL;
bin = grpc_base64_decode(b64, 1); bin = grpc_base64_decode(exec_ctx, b64, 1);
if (GRPC_SLICE_IS_EMPTY(bin)) { if (GRPC_SLICE_IS_EMPTY(bin)) {
gpr_log(GPR_ERROR, "Invalid base64 for big num."); gpr_log(GPR_ERROR, "Invalid base64 for big num.");
return NULL; return NULL;
} }
result = BN_bin2bn(GRPC_SLICE_START_PTR(bin), result = BN_bin2bn(GRPC_SLICE_START_PTR(bin),
TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), NULL); TSI_SIZE_AS_SIZE(GRPC_SLICE_LENGTH(bin)), NULL);
grpc_slice_unref(bin); grpc_slice_unref_internal(exec_ctx, bin);
return result; return result;
} }
static EVP_PKEY *pkey_from_jwk(const grpc_json *json, const char *kty) { static EVP_PKEY *pkey_from_jwk(grpc_exec_ctx *exec_ctx, const grpc_json *json,
const char *kty) {
const grpc_json *key_prop; const grpc_json *key_prop;
RSA *rsa = NULL; RSA *rsa = NULL;
EVP_PKEY *result = NULL; EVP_PKEY *result = NULL;
@ -492,10 +497,12 @@ static EVP_PKEY *pkey_from_jwk(const grpc_json *json, const char *kty) {
} }
for (key_prop = json->child; key_prop != NULL; key_prop = key_prop->next) { for (key_prop = json->child; key_prop != NULL; key_prop = key_prop->next) {
if (strcmp(key_prop->key, "n") == 0) { if (strcmp(key_prop->key, "n") == 0) {
rsa->n = bignum_from_base64(validate_string_field(key_prop, "n")); rsa->n =
bignum_from_base64(exec_ctx, validate_string_field(key_prop, "n"));
if (rsa->n == NULL) goto end; if (rsa->n == NULL) goto end;
} else if (strcmp(key_prop->key, "e") == 0) { } else if (strcmp(key_prop->key, "e") == 0) {
rsa->e = bignum_from_base64(validate_string_field(key_prop, "e")); rsa->e =
bignum_from_base64(exec_ctx, validate_string_field(key_prop, "e"));
if (rsa->e == NULL) goto end; if (rsa->e == NULL) goto end;
} }
} }
@ -511,7 +518,8 @@ end:
return result; return result;
} }
static EVP_PKEY *find_verification_key(const grpc_json *json, static EVP_PKEY *find_verification_key(grpc_exec_ctx *exec_ctx,
const grpc_json *json,
const char *header_alg, const char *header_alg,
const char *header_kid) { const char *header_kid) {
const grpc_json *jkey; const grpc_json *jkey;
@ -555,7 +563,7 @@ static EVP_PKEY *find_verification_key(const grpc_json *json,
} }
if (alg != NULL && kid != NULL && kty != NULL && if (alg != NULL && kid != NULL && kty != NULL &&
strcmp(kid, header_kid) == 0 && strcmp(alg, header_alg) == 0) { strcmp(kid, header_kid) == 0 && strcmp(alg, header_alg) == 0) {
return pkey_from_jwk(jkey, kty); return pkey_from_jwk(exec_ctx, jkey, kty);
} }
} }
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
@ -609,7 +617,7 @@ static void on_keys_retrieved(grpc_exec_ctx *exec_ctx, void *user_data,
goto end; goto end;
} }
verification_key = verification_key =
find_verification_key(json, ctx->header->alg, ctx->header->kid); find_verification_key(exec_ctx, json, ctx->header->alg, ctx->header->kid);
if (verification_key == NULL) { if (verification_key == NULL) {
gpr_log(GPR_ERROR, "Could not find verification key with kid %s.", gpr_log(GPR_ERROR, "Could not find verification key with kid %s.",
ctx->header->kid); ctx->header->kid);
@ -633,8 +641,8 @@ static void on_keys_retrieved(grpc_exec_ctx *exec_ctx, void *user_data,
end: end:
if (json != NULL) grpc_json_destroy(json); if (json != NULL) grpc_json_destroy(json);
if (verification_key != NULL) EVP_PKEY_free(verification_key); if (verification_key != NULL) EVP_PKEY_free(verification_key);
ctx->user_cb(ctx->user_data, status, claims); ctx->user_cb(exec_ctx, ctx->user_data, status, claims);
verifier_cb_ctx_destroy(ctx); verifier_cb_ctx_destroy(exec_ctx, ctx);
} }
static void on_openid_config_retrieved(grpc_exec_ctx *exec_ctx, void *user_data, static void on_openid_config_retrieved(grpc_exec_ctx *exec_ctx, void *user_data,
@ -679,15 +687,16 @@ static void on_openid_config_retrieved(grpc_exec_ctx *exec_ctx, void *user_data,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_max_delay), gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_max_delay),
grpc_closure_create(on_keys_retrieved, ctx, grpc_schedule_on_exec_ctx), grpc_closure_create(on_keys_retrieved, ctx, grpc_schedule_on_exec_ctx),
&ctx->responses[HTTP_RESPONSE_KEYS]); &ctx->responses[HTTP_RESPONSE_KEYS]);
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
grpc_json_destroy(json); grpc_json_destroy(json);
gpr_free(req.host); gpr_free(req.host);
return; return;
error: error:
if (json != NULL) grpc_json_destroy(json); if (json != NULL) grpc_json_destroy(json);
ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, NULL); ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR,
verifier_cb_ctx_destroy(ctx); NULL);
verifier_cb_ctx_destroy(exec_ctx, ctx);
} }
static email_key_mapping *verifier_get_mapping(grpc_jwt_verifier *v, static email_key_mapping *verifier_get_mapping(grpc_jwt_verifier *v,
@ -805,14 +814,15 @@ static void retrieve_key_and_verify(grpc_exec_ctx *exec_ctx,
exec_ctx, &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req, exec_ctx, &ctx->verifier->http_ctx, &ctx->pollent, resource_quota, &req,
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_max_delay), gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), grpc_jwt_verifier_max_delay),
http_cb, &ctx->responses[rsp_idx]); http_cb, &ctx->responses[rsp_idx]);
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
gpr_free(req.host); gpr_free(req.host);
gpr_free(req.http.path); gpr_free(req.http.path);
return; return;
error: error:
ctx->user_cb(ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR, NULL); ctx->user_cb(exec_ctx, ctx->user_data, GRPC_JWT_VERIFIER_KEY_RETRIEVAL_ERROR,
verifier_cb_ctx_destroy(ctx); NULL);
verifier_cb_ctx_destroy(exec_ctx, ctx);
} }
void grpc_jwt_verifier_verify(grpc_exec_ctx *exec_ctx, void grpc_jwt_verifier_verify(grpc_exec_ctx *exec_ctx,
@ -834,22 +844,24 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(verifier != NULL && jwt != NULL && audience != NULL && cb != NULL); GPR_ASSERT(verifier != NULL && jwt != NULL && audience != NULL && cb != NULL);
dot = strchr(cur, '.'); dot = strchr(cur, '.');
if (dot == NULL) goto error; if (dot == NULL) goto error;
json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &header_buffer); json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur),
&header_buffer);
if (json == NULL) goto error; if (json == NULL) goto error;
header = jose_header_from_json(json, header_buffer); header = jose_header_from_json(exec_ctx, json, header_buffer);
if (header == NULL) goto error; if (header == NULL) goto error;
cur = dot + 1; cur = dot + 1;
dot = strchr(cur, '.'); dot = strchr(cur, '.');
if (dot == NULL) goto error; if (dot == NULL) goto error;
json = parse_json_part_from_jwt(cur, (size_t)(dot - cur), &claims_buffer); json = parse_json_part_from_jwt(exec_ctx, cur, (size_t)(dot - cur),
&claims_buffer);
if (json == NULL) goto error; if (json == NULL) goto error;
claims = grpc_jwt_claims_from_json(json, claims_buffer); claims = grpc_jwt_claims_from_json(exec_ctx, json, claims_buffer);
if (claims == NULL) goto error; if (claims == NULL) goto error;
signed_jwt_len = (size_t)(dot - jwt); signed_jwt_len = (size_t)(dot - jwt);
cur = dot + 1; cur = dot + 1;
signature = grpc_base64_decode(cur, 1); signature = grpc_base64_decode(exec_ctx, cur, 1);
if (GRPC_SLICE_IS_EMPTY(signature)) goto error; if (GRPC_SLICE_IS_EMPTY(signature)) goto error;
retrieve_key_and_verify( retrieve_key_and_verify(
exec_ctx, exec_ctx,
@ -858,9 +870,9 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx *exec_ctx,
return; return;
error: error:
if (header != NULL) jose_header_destroy(header); if (header != NULL) jose_header_destroy(exec_ctx, header);
if (claims != NULL) grpc_jwt_claims_destroy(claims); if (claims != NULL) grpc_jwt_claims_destroy(exec_ctx, claims);
cb(user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, NULL); cb(exec_ctx, user_data, GRPC_JWT_VERIFIER_BAD_FORMAT, NULL);
} }
grpc_jwt_verifier *grpc_jwt_verifier_create( grpc_jwt_verifier *grpc_jwt_verifier_create(

@ -66,7 +66,7 @@ const char *grpc_jwt_verifier_status_to_string(grpc_jwt_verifier_status status);
typedef struct grpc_jwt_claims grpc_jwt_claims; typedef struct grpc_jwt_claims grpc_jwt_claims;
void grpc_jwt_claims_destroy(grpc_jwt_claims *claims); void grpc_jwt_claims_destroy(grpc_exec_ctx *exec_ctx, grpc_jwt_claims *claims);
/* Returns the whole JSON tree of the claims. */ /* Returns the whole JSON tree of the claims. */
const grpc_json *grpc_jwt_claims_json(const grpc_jwt_claims *claims); const grpc_json *grpc_jwt_claims_json(const grpc_jwt_claims *claims);
@ -115,7 +115,8 @@ void grpc_jwt_verifier_destroy(grpc_jwt_verifier *verifier);
is done (maybe in another thread). is done (maybe in another thread).
It is the responsibility of the callee to call grpc_jwt_claims_destroy on It is the responsibility of the callee to call grpc_jwt_claims_destroy on
the claims. */ the claims. */
typedef void (*grpc_jwt_verification_done_cb)(void *user_data, typedef void (*grpc_jwt_verification_done_cb)(grpc_exec_ctx *exec_ctx,
void *user_data,
grpc_jwt_verifier_status status, grpc_jwt_verifier_status status,
grpc_jwt_claims *claims); grpc_jwt_claims *claims);
@ -129,7 +130,8 @@ void grpc_jwt_verifier_verify(grpc_exec_ctx *exec_ctx,
/* --- TESTING ONLY exposed functions. --- */ /* --- TESTING ONLY exposed functions. --- */
grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_json *json, grpc_slice buffer); grpc_jwt_claims *grpc_jwt_claims_from_json(grpc_exec_ctx *exec_ctx,
grpc_json *json, grpc_slice buffer);
grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims *claims, grpc_jwt_verifier_status grpc_jwt_claims_check(const grpc_jwt_claims *claims,
const char *audience); const char *audience);
const char *grpc_jwt_issuer_email_domain(const char *issuer); const char *grpc_jwt_issuer_email_domain(const char *issuer);

@ -118,18 +118,19 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token *refresh_token) {
// Oauth2 Token Fetcher credentials. // Oauth2 Token Fetcher credentials.
// //
static void oauth2_token_fetcher_destruct(grpc_call_credentials *creds) { static void oauth2_token_fetcher_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_oauth2_token_fetcher_credentials *c = grpc_oauth2_token_fetcher_credentials *c =
(grpc_oauth2_token_fetcher_credentials *)creds; (grpc_oauth2_token_fetcher_credentials *)creds;
grpc_credentials_md_store_unref(c->access_token_md); grpc_credentials_md_store_unref(exec_ctx, c->access_token_md);
gpr_mu_destroy(&c->mu); gpr_mu_destroy(&c->mu);
grpc_httpcli_context_destroy(&c->httpcli_context); grpc_httpcli_context_destroy(&c->httpcli_context);
} }
grpc_credentials_status grpc_credentials_status
grpc_oauth2_token_fetcher_credentials_parse_server_response( grpc_oauth2_token_fetcher_credentials_parse_server_response(
const grpc_http_response *response, grpc_credentials_md_store **token_md, grpc_exec_ctx *exec_ctx, const grpc_http_response *response,
gpr_timespec *token_lifetime) { grpc_credentials_md_store **token_md, gpr_timespec *token_lifetime) {
char *null_terminated_body = NULL; char *null_terminated_body = NULL;
char *new_access_token = NULL; char *new_access_token = NULL;
grpc_credentials_status status = GRPC_CREDENTIALS_OK; grpc_credentials_status status = GRPC_CREDENTIALS_OK;
@ -198,7 +199,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
token_lifetime->tv_sec = strtol(expires_in->value, NULL, 10); token_lifetime->tv_sec = strtol(expires_in->value, NULL, 10);
token_lifetime->tv_nsec = 0; token_lifetime->tv_nsec = 0;
token_lifetime->clock_type = GPR_TIMESPAN; token_lifetime->clock_type = GPR_TIMESPAN;
if (*token_md != NULL) grpc_credentials_md_store_unref(*token_md); if (*token_md != NULL) grpc_credentials_md_store_unref(exec_ctx, *token_md);
*token_md = grpc_credentials_md_store_create(1); *token_md = grpc_credentials_md_store_create(1);
grpc_credentials_md_store_add_cstrings( grpc_credentials_md_store_add_cstrings(
*token_md, GRPC_AUTHORIZATION_METADATA_KEY, new_access_token); *token_md, GRPC_AUTHORIZATION_METADATA_KEY, new_access_token);
@ -207,7 +208,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
end: end:
if (status != GRPC_CREDENTIALS_OK && (*token_md != NULL)) { if (status != GRPC_CREDENTIALS_OK && (*token_md != NULL)) {
grpc_credentials_md_store_unref(*token_md); grpc_credentials_md_store_unref(exec_ctx, *token_md);
*token_md = NULL; *token_md = NULL;
} }
if (null_terminated_body != NULL) gpr_free(null_terminated_body); if (null_terminated_body != NULL) gpr_free(null_terminated_body);
@ -230,7 +231,7 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx *exec_ctx,
gpr_mu_lock(&c->mu); gpr_mu_lock(&c->mu);
status = grpc_oauth2_token_fetcher_credentials_parse_server_response( status = grpc_oauth2_token_fetcher_credentials_parse_server_response(
&r->response, &c->access_token_md, &token_lifetime); exec_ctx, &r->response, &c->access_token_md, &token_lifetime);
if (status == GRPC_CREDENTIALS_OK) { if (status == GRPC_CREDENTIALS_OK) {
c->token_expiration = c->token_expiration =
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), token_lifetime); gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), token_lifetime);
@ -242,7 +243,7 @@ static void on_oauth2_token_fetcher_http_response(grpc_exec_ctx *exec_ctx,
"Error occured when fetching oauth2 token."); "Error occured when fetching oauth2 token.");
} }
gpr_mu_unlock(&c->mu); gpr_mu_unlock(&c->mu);
grpc_credentials_metadata_request_destroy(r); grpc_credentials_metadata_request_destroy(exec_ctx, r);
} }
static void oauth2_token_fetcher_get_request_metadata( static void oauth2_token_fetcher_get_request_metadata(
@ -268,7 +269,7 @@ static void oauth2_token_fetcher_get_request_metadata(
if (cached_access_token_md != NULL) { if (cached_access_token_md != NULL) {
cb(exec_ctx, user_data, cached_access_token_md->entries, cb(exec_ctx, user_data, cached_access_token_md->entries,
cached_access_token_md->num_entries, GRPC_CREDENTIALS_OK, NULL); cached_access_token_md->num_entries, GRPC_CREDENTIALS_OK, NULL);
grpc_credentials_md_store_unref(cached_access_token_md); grpc_credentials_md_store_unref(exec_ctx, cached_access_token_md);
} else { } else {
c->fetch_func( c->fetch_func(
exec_ctx, exec_ctx,
@ -315,8 +316,9 @@ static void compute_engine_fetch_oauth2(
grpc_httpcli_get( grpc_httpcli_get(
exec_ctx, httpcli_context, pollent, resource_quota, &request, deadline, exec_ctx, httpcli_context, pollent, resource_quota, &request, deadline,
grpc_closure_create(response_cb, metadata_req, grpc_schedule_on_exec_ctx), grpc_closure_create(response_cb, metadata_req, grpc_schedule_on_exec_ctx),
&metadata_req->response); &metadata_req->response);
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
} }
grpc_call_credentials *grpc_google_compute_engine_credentials_create( grpc_call_credentials *grpc_google_compute_engine_credentials_create(
@ -335,11 +337,12 @@ grpc_call_credentials *grpc_google_compute_engine_credentials_create(
// Google Refresh Token credentials. // Google Refresh Token credentials.
// //
static void refresh_token_destruct(grpc_call_credentials *creds) { static void refresh_token_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_google_refresh_token_credentials *c = grpc_google_refresh_token_credentials *c =
(grpc_google_refresh_token_credentials *)creds; (grpc_google_refresh_token_credentials *)creds;
grpc_auth_refresh_token_destruct(&c->refresh_token); grpc_auth_refresh_token_destruct(&c->refresh_token);
oauth2_token_fetcher_destruct(&c->base.base); oauth2_token_fetcher_destruct(exec_ctx, &c->base.base);
} }
static grpc_call_credentials_vtable refresh_token_vtable = { static grpc_call_credentials_vtable refresh_token_vtable = {
@ -374,7 +377,7 @@ static void refresh_token_fetch_oauth2(
strlen(body), deadline, strlen(body), deadline,
grpc_closure_create(response_cb, metadata_req, grpc_schedule_on_exec_ctx), grpc_closure_create(response_cb, metadata_req, grpc_schedule_on_exec_ctx),
&metadata_req->response); &metadata_req->response);
grpc_resource_quota_internal_unref(exec_ctx, resource_quota); grpc_resource_quota_unref_internal(exec_ctx, resource_quota);
gpr_free(body); gpr_free(body);
} }
@ -426,9 +429,10 @@ grpc_call_credentials *grpc_google_refresh_token_credentials_create(
// Oauth2 Access Token credentials. // Oauth2 Access Token credentials.
// //
static void access_token_destruct(grpc_call_credentials *creds) { static void access_token_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_access_token_credentials *c = (grpc_access_token_credentials *)creds; grpc_access_token_credentials *c = (grpc_access_token_credentials *)creds;
grpc_credentials_md_store_unref(c->access_token_md); grpc_credentials_md_store_unref(exec_ctx, c->access_token_md);
} }
static void access_token_get_request_metadata( static void access_token_get_request_metadata(

@ -103,7 +103,7 @@ grpc_refresh_token_credentials_create_from_auth_refresh_token(
// Exposed for testing only. // Exposed for testing only.
grpc_credentials_status grpc_credentials_status
grpc_oauth2_token_fetcher_credentials_parse_server_response( grpc_oauth2_token_fetcher_credentials_parse_server_response(
const struct grpc_http_response *response, grpc_exec_ctx *exec_ctx, const struct grpc_http_response *response,
grpc_credentials_md_store **token_md, gpr_timespec *token_lifetime); grpc_credentials_md_store **token_md, gpr_timespec *token_lifetime);
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_OAUTH2_OAUTH2_CREDENTIALS_H */ #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_OAUTH2_OAUTH2_CREDENTIALS_H */

@ -35,20 +35,22 @@
#include <string.h> #include <string.h>
#include "src/core/lib/surface/api_trace.h"
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include <grpc/support/sync.h> #include <grpc/support/sync.h>
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/api_trace.h"
typedef struct { typedef struct {
void *user_data; void *user_data;
grpc_credentials_metadata_cb cb; grpc_credentials_metadata_cb cb;
} grpc_metadata_plugin_request; } grpc_metadata_plugin_request;
static void plugin_destruct(grpc_call_credentials *creds) { static void plugin_destruct(grpc_exec_ctx *exec_ctx,
grpc_call_credentials *creds) {
grpc_plugin_credentials *c = (grpc_plugin_credentials *)creds; grpc_plugin_credentials *c = (grpc_plugin_credentials *)creds;
if (c->plugin.state != NULL && c->plugin.destroy != NULL) { if (c->plugin.state != NULL && c->plugin.destroy != NULL) {
c->plugin.destroy(c->plugin.state); c->plugin.destroy(c->plugin.state);
@ -100,8 +102,8 @@ static void plugin_md_request_metadata_ready(void *request,
r->cb(&exec_ctx, r->user_data, md_array, num_md, GRPC_CREDENTIALS_OK, r->cb(&exec_ctx, r->user_data, md_array, num_md, GRPC_CREDENTIALS_OK,
NULL); NULL);
for (i = 0; i < num_md; i++) { for (i = 0; i < num_md; i++) {
grpc_slice_unref(md_array[i].key); grpc_slice_unref_internal(&exec_ctx, md_array[i].key);
grpc_slice_unref(md_array[i].value); grpc_slice_unref_internal(&exec_ctx, md_array[i].value);
} }
gpr_free(md_array); gpr_free(md_array);
} else if (num_md == 0) { } else if (num_md == 0) {

@ -57,7 +57,8 @@ static void ssl_copy_key_material(const char *input, unsigned char **output,
// SSL Channel Credentials. // SSL Channel Credentials.
// //
static void ssl_destruct(grpc_channel_credentials *creds) { static void ssl_destruct(grpc_exec_ctx *exec_ctx,
grpc_channel_credentials *creds) {
grpc_ssl_credentials *c = (grpc_ssl_credentials *)creds; grpc_ssl_credentials *c = (grpc_ssl_credentials *)creds;
if (c->config.pem_root_certs != NULL) gpr_free(c->config.pem_root_certs); if (c->config.pem_root_certs != NULL) gpr_free(c->config.pem_root_certs);
if (c->config.pem_private_key != NULL) gpr_free(c->config.pem_private_key); if (c->config.pem_private_key != NULL) gpr_free(c->config.pem_private_key);
@ -65,9 +66,10 @@ static void ssl_destruct(grpc_channel_credentials *creds) {
} }
static grpc_security_status ssl_create_security_connector( static grpc_security_status ssl_create_security_connector(
grpc_channel_credentials *creds, grpc_call_credentials *call_creds, grpc_exec_ctx *exec_ctx, grpc_channel_credentials *creds,
const char *target, const grpc_channel_args *args, grpc_call_credentials *call_creds, const char *target,
grpc_channel_security_connector **sc, grpc_channel_args **new_args) { const grpc_channel_args *args, grpc_channel_security_connector **sc,
grpc_channel_args **new_args) {
grpc_ssl_credentials *c = (grpc_ssl_credentials *)creds; grpc_ssl_credentials *c = (grpc_ssl_credentials *)creds;
grpc_security_status status = GRPC_SECURITY_OK; grpc_security_status status = GRPC_SECURITY_OK;
size_t i = 0; size_t i = 0;
@ -83,7 +85,7 @@ static grpc_security_status ssl_create_security_connector(
} }
} }
status = grpc_ssl_channel_security_connector_create( status = grpc_ssl_channel_security_connector_create(
call_creds, &c->config, target, overridden_target_name, sc); exec_ctx, call_creds, &c->config, target, overridden_target_name, sc);
if (status != GRPC_SECURITY_OK) { if (status != GRPC_SECURITY_OK) {
return status; return status;
} }
@ -138,7 +140,8 @@ grpc_channel_credentials *grpc_ssl_credentials_create(
// SSL Server Credentials. // SSL Server Credentials.
// //
static void ssl_server_destruct(grpc_server_credentials *creds) { static void ssl_server_destruct(grpc_exec_ctx *exec_ctx,
grpc_server_credentials *creds) {
grpc_ssl_server_credentials *c = (grpc_ssl_server_credentials *)creds; grpc_ssl_server_credentials *c = (grpc_ssl_server_credentials *)creds;
size_t i; size_t i;
for (i = 0; i < c->config.num_key_cert_pairs; i++) { for (i = 0; i < c->config.num_key_cert_pairs; i++) {
@ -161,9 +164,10 @@ static void ssl_server_destruct(grpc_server_credentials *creds) {
} }
static grpc_security_status ssl_server_create_security_connector( static grpc_security_status ssl_server_create_security_connector(
grpc_server_credentials *creds, grpc_server_security_connector **sc) { grpc_exec_ctx *exec_ctx, grpc_server_credentials *creds,
grpc_server_security_connector **sc) {
grpc_ssl_server_credentials *c = (grpc_ssl_server_credentials *)creds; grpc_ssl_server_credentials *c = (grpc_ssl_server_credentials *)creds;
return grpc_ssl_server_security_connector_create(&c->config, sc); return grpc_ssl_server_security_connector_create(exec_ctx, &c->config, sc);
} }
static grpc_server_credentials_vtable ssl_server_vtable = { static grpc_server_credentials_vtable ssl_server_vtable = {

@ -44,6 +44,7 @@
#include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/security/transport/security_connector.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
#include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
@ -93,7 +94,8 @@ static void bubble_up_error(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
gpr_log(GPR_ERROR, "Client side authentication failure: %s", error_msg); gpr_log(GPR_ERROR, "Client side authentication failure: %s", error_msg);
grpc_slice error_slice = grpc_slice_from_copied_string(error_msg); grpc_slice error_slice = grpc_slice_from_copied_string(error_msg);
grpc_transport_stream_op_add_close(&calld->op, status, &error_slice); grpc_transport_stream_op_add_close(exec_ctx, &calld->op, status,
&error_slice);
grpc_call_next_op(exec_ctx, elem, &calld->op); grpc_call_next_op(exec_ctx, elem, &calld->op);
} }
@ -121,8 +123,9 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data,
for (i = 0; i < num_md; i++) { for (i = 0; i < num_md; i++) {
grpc_metadata_batch_add_tail( grpc_metadata_batch_add_tail(
mdb, &calld->md_links[i], mdb, &calld->md_links[i],
grpc_mdelem_from_slices(grpc_slice_ref(md_elems[i].key), grpc_mdelem_from_slices(exec_ctx,
grpc_slice_ref(md_elems[i].value))); grpc_slice_ref_internal(md_elems[i].key),
grpc_slice_ref_internal(md_elems[i].value)));
} }
grpc_call_next_op(exec_ctx, elem, op); grpc_call_next_op(exec_ctx, elem, op);
} }
@ -248,10 +251,10 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx,
/* Pointer comparison is OK for md_elems created from the same context. /* Pointer comparison is OK for md_elems created from the same context.
*/ */
if (md->key == GRPC_MDSTR_AUTHORITY) { if (md->key == GRPC_MDSTR_AUTHORITY) {
if (calld->host != NULL) GRPC_MDSTR_UNREF(calld->host); if (calld->host != NULL) GRPC_MDSTR_UNREF(exec_ctx, calld->host);
calld->host = GRPC_MDSTR_REF(md->value); calld->host = GRPC_MDSTR_REF(md->value);
} else if (md->key == GRPC_MDSTR_PATH) { } else if (md->key == GRPC_MDSTR_PATH) {
if (calld->method != NULL) GRPC_MDSTR_UNREF(calld->method); if (calld->method != NULL) GRPC_MDSTR_UNREF(exec_ctx, calld->method);
calld->method = GRPC_MDSTR_REF(md->value); calld->method = GRPC_MDSTR_REF(md->value);
} }
} }
@ -292,12 +295,12 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
const grpc_call_final_info *final_info, const grpc_call_final_info *final_info,
void *ignored) { void *ignored) {
call_data *calld = elem->call_data; call_data *calld = elem->call_data;
grpc_call_credentials_unref(calld->creds); grpc_call_credentials_unref(exec_ctx, calld->creds);
if (calld->host != NULL) { if (calld->host != NULL) {
GRPC_MDSTR_UNREF(calld->host); GRPC_MDSTR_UNREF(exec_ctx, calld->host);
} }
if (calld->method != NULL) { if (calld->method != NULL) {
GRPC_MDSTR_UNREF(calld->method); GRPC_MDSTR_UNREF(exec_ctx, calld->method);
} }
reset_auth_metadata_context(&calld->auth_md_context); reset_auth_metadata_context(&calld->auth_md_context);
} }
@ -337,7 +340,7 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
channel_data *chand = elem->channel_data; channel_data *chand = elem->channel_data;
grpc_channel_security_connector *sc = chand->security_connector; grpc_channel_security_connector *sc = chand->security_connector;
if (sc != NULL) { if (sc != NULL) {
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "client_auth_filter"); GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &sc->base, "client_auth_filter");
} }
GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "client_auth_filter"); GRPC_AUTH_CONTEXT_UNREF(chand->auth_context, "client_auth_filter");
} }

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save