grpc 1.26.0 → 1.27.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +1654 -1519
- data/etc/roots.pem +44 -0
- data/include/grpc/grpc_security.h +37 -15
- data/include/grpc/grpc_security_constants.h +27 -0
- data/include/grpc/impl/codegen/grpc_types.h +14 -0
- data/include/grpc/impl/codegen/port_platform.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
- data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
- data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +3 -10
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
- data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
- data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
- data/src/core/lib/channel/channelz.h +11 -1
- data/src/core/lib/gpr/time_precise.cc +1 -1
- data/src/core/lib/gprpp/optional.h +26 -0
- data/src/core/lib/gprpp/string_view.h +14 -10
- data/src/core/lib/iomgr/executor.cc +1 -1
- data/src/core/lib/iomgr/fork_posix.cc +4 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
- data/src/core/lib/iomgr/tcp_custom.h +3 -0
- data/src/core/lib/iomgr/tcp_posix.cc +607 -56
- data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
- data/src/core/lib/json/json.h +11 -1
- data/src/core/lib/json/json_reader.cc +206 -28
- data/src/core/lib/json/json_writer.cc +111 -24
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
- data/src/core/lib/security/credentials/credentials.h +10 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
- data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
- data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
- data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
- data/src/core/lib/surface/completion_queue.cc +22 -1
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
- data/src/core/tsi/fake_transport_security.cc +7 -3
- data/src/core/tsi/fake_transport_security.h +2 -0
- data/src/core/tsi/ssl_transport_security.cc +144 -8
- data/src/core/tsi/ssl_transport_security.h +15 -1
- data/src/core/tsi/transport_security.cc +13 -0
- data/src/core/tsi/transport_security_grpc.cc +2 -2
- data/src/core/tsi/transport_security_grpc.h +2 -2
- data/src/core/tsi/transport_security_interface.h +12 -0
- data/src/ruby/bin/math_pb.rb +5 -5
- data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
- data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
- data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
- data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
- data/third_party/abseil-cpp/absl/base/casts.h +184 -0
- data/third_party/abseil-cpp/absl/base/config.h +622 -0
- data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
- data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
- data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
- data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
- data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
- data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
- data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
- data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
- data/third_party/abseil-cpp/absl/base/macros.h +220 -0
- data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
- data/third_party/abseil-cpp/absl/base/options.h +214 -0
- data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
- data/third_party/abseil-cpp/absl/base/port.h +26 -0
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
- data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
- data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
- data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
- data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
- data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
- data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
- data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
- data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
- data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
- data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
- data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
- data/third_party/abseil-cpp/absl/strings/match.h +90 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
- data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
- data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
- data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
- data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
- data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
- data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
- data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
- data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
- data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
- data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
- data/third_party/abseil-cpp/absl/types/optional.h +776 -0
- data/third_party/abseil-cpp/absl/types/span.h +713 -0
- data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
- data/third_party/upb/upb/decode.c +4 -0
- data/third_party/upb/upb/port.c +0 -1
- data/third_party/upb/upb/port_def.inc +1 -3
- data/third_party/upb/upb/table.c +2 -1
- metadata +147 -43
- data/src/core/lib/json/json_common.h +0 -34
- data/src/core/lib/json/json_reader.h +0 -146
- data/src/core/lib/json/json_string.cc +0 -367
- data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,237 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#include "absl/base/internal/raw_logging.h"
|
16
|
+
|
17
|
+
#include <stddef.h>
|
18
|
+
#include <cstdarg>
|
19
|
+
#include <cstdio>
|
20
|
+
#include <cstdlib>
|
21
|
+
#include <cstring>
|
22
|
+
|
23
|
+
#include "absl/base/attributes.h"
|
24
|
+
#include "absl/base/config.h"
|
25
|
+
#include "absl/base/internal/atomic_hook.h"
|
26
|
+
#include "absl/base/log_severity.h"
|
27
|
+
|
28
|
+
// We know how to perform low-level writes to stderr in POSIX and Windows. For
|
29
|
+
// these platforms, we define the token ABSL_LOW_LEVEL_WRITE_SUPPORTED.
|
30
|
+
// Much of raw_logging.cc becomes a no-op when we can't output messages,
|
31
|
+
// although a FATAL ABSL_RAW_LOG message will still abort the process.
|
32
|
+
|
33
|
+
// ABSL_HAVE_POSIX_WRITE is defined when the platform provides posix write()
|
34
|
+
// (as from unistd.h)
|
35
|
+
//
|
36
|
+
// This preprocessor token is also defined in raw_io.cc. If you need to copy
|
37
|
+
// this, consider moving both to config.h instead.
|
38
|
+
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
|
39
|
+
defined(__Fuchsia__) || defined(__native_client__) || \
|
40
|
+
defined(__EMSCRIPTEN__) || defined(__ASYLO__)
|
41
|
+
|
42
|
+
#include <unistd.h>
|
43
|
+
|
44
|
+
#define ABSL_HAVE_POSIX_WRITE 1
|
45
|
+
#define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1
|
46
|
+
#else
|
47
|
+
#undef ABSL_HAVE_POSIX_WRITE
|
48
|
+
#endif
|
49
|
+
|
50
|
+
// ABSL_HAVE_SYSCALL_WRITE is defined when the platform provides the syscall
|
51
|
+
// syscall(SYS_write, /*int*/ fd, /*char* */ buf, /*size_t*/ len);
|
52
|
+
// for low level operations that want to avoid libc.
|
53
|
+
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__ANDROID__)
|
54
|
+
#include <sys/syscall.h>
|
55
|
+
#define ABSL_HAVE_SYSCALL_WRITE 1
|
56
|
+
#define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1
|
57
|
+
#else
|
58
|
+
#undef ABSL_HAVE_SYSCALL_WRITE
|
59
|
+
#endif
|
60
|
+
|
61
|
+
#ifdef _WIN32
|
62
|
+
#include <io.h>
|
63
|
+
|
64
|
+
#define ABSL_HAVE_RAW_IO 1
|
65
|
+
#define ABSL_LOW_LEVEL_WRITE_SUPPORTED 1
|
66
|
+
#else
|
67
|
+
#undef ABSL_HAVE_RAW_IO
|
68
|
+
#endif
|
69
|
+
|
70
|
+
// TODO(gfalcon): We want raw-logging to work on as many platforms as possible.
|
71
|
+
// Explicitly #error out when not ABSL_LOW_LEVEL_WRITE_SUPPORTED, except for a
|
72
|
+
// whitelisted set of platforms for which we expect not to be able to raw log.
|
73
|
+
|
74
|
+
ABSL_CONST_INIT static absl::base_internal::AtomicHook<
|
75
|
+
absl::raw_logging_internal::LogPrefixHook> log_prefix_hook;
|
76
|
+
ABSL_CONST_INIT static absl::base_internal::AtomicHook<
|
77
|
+
absl::raw_logging_internal::AbortHook> abort_hook;
|
78
|
+
|
79
|
+
#ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
80
|
+
static const char kTruncated[] = " ... (message truncated)\n";
|
81
|
+
|
82
|
+
// sprintf the format to the buffer, adjusting *buf and *size to reflect the
|
83
|
+
// consumed bytes, and return whether the message fit without truncation. If
|
84
|
+
// truncation occurred, if possible leave room in the buffer for the message
|
85
|
+
// kTruncated[].
|
86
|
+
inline static bool VADoRawLog(char** buf, int* size, const char* format,
|
87
|
+
va_list ap) ABSL_PRINTF_ATTRIBUTE(3, 0);
|
88
|
+
inline static bool VADoRawLog(char** buf, int* size,
|
89
|
+
const char* format, va_list ap) {
|
90
|
+
int n = vsnprintf(*buf, *size, format, ap);
|
91
|
+
bool result = true;
|
92
|
+
if (n < 0 || n > *size) {
|
93
|
+
result = false;
|
94
|
+
if (static_cast<size_t>(*size) > sizeof(kTruncated)) {
|
95
|
+
n = *size - sizeof(kTruncated); // room for truncation message
|
96
|
+
} else {
|
97
|
+
n = 0; // no room for truncation message
|
98
|
+
}
|
99
|
+
}
|
100
|
+
*size -= n;
|
101
|
+
*buf += n;
|
102
|
+
return result;
|
103
|
+
}
|
104
|
+
#endif // ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
105
|
+
|
106
|
+
static constexpr int kLogBufSize = 3000;
|
107
|
+
|
108
|
+
namespace {
|
109
|
+
|
110
|
+
// CAVEAT: vsnprintf called from *DoRawLog below has some (exotic) code paths
|
111
|
+
// that invoke malloc() and getenv() that might acquire some locks.
|
112
|
+
|
113
|
+
// Helper for RawLog below.
|
114
|
+
// *DoRawLog writes to *buf of *size and move them past the written portion.
|
115
|
+
// It returns true iff there was no overflow or error.
|
116
|
+
bool DoRawLog(char** buf, int* size, const char* format, ...)
|
117
|
+
ABSL_PRINTF_ATTRIBUTE(3, 4);
|
118
|
+
bool DoRawLog(char** buf, int* size, const char* format, ...) {
|
119
|
+
va_list ap;
|
120
|
+
va_start(ap, format);
|
121
|
+
int n = vsnprintf(*buf, *size, format, ap);
|
122
|
+
va_end(ap);
|
123
|
+
if (n < 0 || n > *size) return false;
|
124
|
+
*size -= n;
|
125
|
+
*buf += n;
|
126
|
+
return true;
|
127
|
+
}
|
128
|
+
|
129
|
+
void RawLogVA(absl::LogSeverity severity, const char* file, int line,
|
130
|
+
const char* format, va_list ap) ABSL_PRINTF_ATTRIBUTE(4, 0);
|
131
|
+
void RawLogVA(absl::LogSeverity severity, const char* file, int line,
|
132
|
+
const char* format, va_list ap) {
|
133
|
+
char buffer[kLogBufSize];
|
134
|
+
char* buf = buffer;
|
135
|
+
int size = sizeof(buffer);
|
136
|
+
#ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
137
|
+
bool enabled = true;
|
138
|
+
#else
|
139
|
+
bool enabled = false;
|
140
|
+
#endif
|
141
|
+
|
142
|
+
#ifdef ABSL_MIN_LOG_LEVEL
|
143
|
+
if (severity < static_cast<absl::LogSeverity>(ABSL_MIN_LOG_LEVEL) &&
|
144
|
+
severity < absl::LogSeverity::kFatal) {
|
145
|
+
enabled = false;
|
146
|
+
}
|
147
|
+
#endif
|
148
|
+
|
149
|
+
auto log_prefix_hook_ptr = log_prefix_hook.Load();
|
150
|
+
if (log_prefix_hook_ptr) {
|
151
|
+
enabled = log_prefix_hook_ptr(severity, file, line, &buf, &size);
|
152
|
+
} else {
|
153
|
+
if (enabled) {
|
154
|
+
DoRawLog(&buf, &size, "[%s : %d] RAW: ", file, line);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
const char* const prefix_end = buf;
|
158
|
+
|
159
|
+
#ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
160
|
+
if (enabled) {
|
161
|
+
bool no_chop = VADoRawLog(&buf, &size, format, ap);
|
162
|
+
if (no_chop) {
|
163
|
+
DoRawLog(&buf, &size, "\n");
|
164
|
+
} else {
|
165
|
+
DoRawLog(&buf, &size, "%s", kTruncated);
|
166
|
+
}
|
167
|
+
absl::raw_logging_internal::SafeWriteToStderr(buffer, strlen(buffer));
|
168
|
+
}
|
169
|
+
#else
|
170
|
+
static_cast<void>(format);
|
171
|
+
static_cast<void>(ap);
|
172
|
+
#endif
|
173
|
+
|
174
|
+
// Abort the process after logging a FATAL message, even if the output itself
|
175
|
+
// was suppressed.
|
176
|
+
if (severity == absl::LogSeverity::kFatal) {
|
177
|
+
abort_hook(file, line, buffer, prefix_end, buffer + kLogBufSize);
|
178
|
+
abort();
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
} // namespace
|
183
|
+
|
184
|
+
namespace absl {
|
185
|
+
ABSL_NAMESPACE_BEGIN
|
186
|
+
namespace raw_logging_internal {
|
187
|
+
void SafeWriteToStderr(const char *s, size_t len) {
|
188
|
+
#if defined(ABSL_HAVE_SYSCALL_WRITE)
|
189
|
+
syscall(SYS_write, STDERR_FILENO, s, len);
|
190
|
+
#elif defined(ABSL_HAVE_POSIX_WRITE)
|
191
|
+
write(STDERR_FILENO, s, len);
|
192
|
+
#elif defined(ABSL_HAVE_RAW_IO)
|
193
|
+
_write(/* stderr */ 2, s, len);
|
194
|
+
#else
|
195
|
+
// stderr logging unsupported on this platform
|
196
|
+
(void) s;
|
197
|
+
(void) len;
|
198
|
+
#endif
|
199
|
+
}
|
200
|
+
|
201
|
+
void RawLog(absl::LogSeverity severity, const char* file, int line,
|
202
|
+
const char* format, ...) ABSL_PRINTF_ATTRIBUTE(4, 5);
|
203
|
+
void RawLog(absl::LogSeverity severity, const char* file, int line,
|
204
|
+
const char* format, ...) {
|
205
|
+
va_list ap;
|
206
|
+
va_start(ap, format);
|
207
|
+
RawLogVA(severity, file, line, format, ap);
|
208
|
+
va_end(ap);
|
209
|
+
}
|
210
|
+
|
211
|
+
// Non-formatting version of RawLog().
|
212
|
+
//
|
213
|
+
// TODO(gfalcon): When string_view no longer depends on base, change this
|
214
|
+
// interface to take its message as a string_view instead.
|
215
|
+
static void DefaultInternalLog(absl::LogSeverity severity, const char* file,
|
216
|
+
int line, const std::string& message) {
|
217
|
+
RawLog(severity, file, line, "%s", message.c_str());
|
218
|
+
}
|
219
|
+
|
220
|
+
bool RawLoggingFullySupported() {
|
221
|
+
#ifdef ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
222
|
+
return true;
|
223
|
+
#else // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
224
|
+
return false;
|
225
|
+
#endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
|
226
|
+
}
|
227
|
+
|
228
|
+
ABSL_CONST_INIT absl::base_internal::AtomicHook<InternalLogFunction>
|
229
|
+
internal_log_function(DefaultInternalLog);
|
230
|
+
|
231
|
+
void RegisterInternalLogFunction(InternalLogFunction func) {
|
232
|
+
internal_log_function.Store(func);
|
233
|
+
}
|
234
|
+
|
235
|
+
} // namespace raw_logging_internal
|
236
|
+
ABSL_NAMESPACE_END
|
237
|
+
} // namespace absl
|
@@ -0,0 +1,179 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
//
|
15
|
+
// Thread-safe logging routines that do not allocate any memory or
|
16
|
+
// acquire any locks, and can therefore be used by low-level memory
|
17
|
+
// allocation, synchronization, and signal-handling code.
|
18
|
+
|
19
|
+
#ifndef ABSL_BASE_INTERNAL_RAW_LOGGING_H_
|
20
|
+
#define ABSL_BASE_INTERNAL_RAW_LOGGING_H_
|
21
|
+
|
22
|
+
#include <string>
|
23
|
+
|
24
|
+
#include "absl/base/attributes.h"
|
25
|
+
#include "absl/base/internal/atomic_hook.h"
|
26
|
+
#include "absl/base/log_severity.h"
|
27
|
+
#include "absl/base/macros.h"
|
28
|
+
#include "absl/base/port.h"
|
29
|
+
|
30
|
+
// This is similar to LOG(severity) << format..., but
|
31
|
+
// * it is to be used ONLY by low-level modules that can't use normal LOG()
|
32
|
+
// * it is designed to be a low-level logger that does not allocate any
|
33
|
+
// memory and does not need any locks, hence:
|
34
|
+
// * it logs straight and ONLY to STDERR w/o buffering
|
35
|
+
// * it uses an explicit printf-format and arguments list
|
36
|
+
// * it will silently chop off really long message strings
|
37
|
+
// Usage example:
|
38
|
+
// ABSL_RAW_LOG(ERROR, "Failed foo with %i: %s", status, error);
|
39
|
+
// This will print an almost standard log line like this to stderr only:
|
40
|
+
// E0821 211317 file.cc:123] RAW: Failed foo with 22: bad_file
|
41
|
+
|
42
|
+
#define ABSL_RAW_LOG(severity, ...) \
|
43
|
+
do { \
|
44
|
+
constexpr const char* absl_raw_logging_internal_basename = \
|
45
|
+
::absl::raw_logging_internal::Basename(__FILE__, \
|
46
|
+
sizeof(__FILE__) - 1); \
|
47
|
+
::absl::raw_logging_internal::RawLog(ABSL_RAW_LOGGING_INTERNAL_##severity, \
|
48
|
+
absl_raw_logging_internal_basename, \
|
49
|
+
__LINE__, __VA_ARGS__); \
|
50
|
+
} while (0)
|
51
|
+
|
52
|
+
// Similar to CHECK(condition) << message, but for low-level modules:
|
53
|
+
// we use only ABSL_RAW_LOG that does not allocate memory.
|
54
|
+
// We do not want to provide args list here to encourage this usage:
|
55
|
+
// if (!cond) ABSL_RAW_LOG(FATAL, "foo ...", hard_to_compute_args);
|
56
|
+
// so that the args are not computed when not needed.
|
57
|
+
#define ABSL_RAW_CHECK(condition, message) \
|
58
|
+
do { \
|
59
|
+
if (ABSL_PREDICT_FALSE(!(condition))) { \
|
60
|
+
ABSL_RAW_LOG(FATAL, "Check %s failed: %s", #condition, message); \
|
61
|
+
} \
|
62
|
+
} while (0)
|
63
|
+
|
64
|
+
// ABSL_INTERNAL_LOG and ABSL_INTERNAL_CHECK work like the RAW variants above,
|
65
|
+
// except that if the richer log library is linked into the binary, we dispatch
|
66
|
+
// to that instead. This is potentially useful for internal logging and
|
67
|
+
// assertions, where we are using RAW_LOG neither for its async-signal-safety
|
68
|
+
// nor for its non-allocating nature, but rather because raw logging has very
|
69
|
+
// few other dependencies.
|
70
|
+
//
|
71
|
+
// The API is a subset of the above: each macro only takes two arguments. Use
|
72
|
+
// StrCat if you need to build a richer message.
|
73
|
+
#define ABSL_INTERNAL_LOG(severity, message) \
|
74
|
+
do { \
|
75
|
+
::absl::raw_logging_internal::internal_log_function( \
|
76
|
+
ABSL_RAW_LOGGING_INTERNAL_##severity, __FILE__, __LINE__, message); \
|
77
|
+
} while (0)
|
78
|
+
|
79
|
+
#define ABSL_INTERNAL_CHECK(condition, message) \
|
80
|
+
do { \
|
81
|
+
if (ABSL_PREDICT_FALSE(!(condition))) { \
|
82
|
+
std::string death_message = "Check " #condition " failed: "; \
|
83
|
+
death_message += std::string(message); \
|
84
|
+
ABSL_INTERNAL_LOG(FATAL, death_message); \
|
85
|
+
} \
|
86
|
+
} while (0)
|
87
|
+
|
88
|
+
#define ABSL_RAW_LOGGING_INTERNAL_INFO ::absl::LogSeverity::kInfo
|
89
|
+
#define ABSL_RAW_LOGGING_INTERNAL_WARNING ::absl::LogSeverity::kWarning
|
90
|
+
#define ABSL_RAW_LOGGING_INTERNAL_ERROR ::absl::LogSeverity::kError
|
91
|
+
#define ABSL_RAW_LOGGING_INTERNAL_FATAL ::absl::LogSeverity::kFatal
|
92
|
+
#define ABSL_RAW_LOGGING_INTERNAL_LEVEL(severity) \
|
93
|
+
::absl::NormalizeLogSeverity(severity)
|
94
|
+
|
95
|
+
namespace absl {
|
96
|
+
ABSL_NAMESPACE_BEGIN
|
97
|
+
namespace raw_logging_internal {
|
98
|
+
|
99
|
+
// Helper function to implement ABSL_RAW_LOG
|
100
|
+
// Logs format... at "severity" level, reporting it
|
101
|
+
// as called from file:line.
|
102
|
+
// This does not allocate memory or acquire locks.
|
103
|
+
void RawLog(absl::LogSeverity severity, const char* file, int line,
|
104
|
+
const char* format, ...) ABSL_PRINTF_ATTRIBUTE(4, 5);
|
105
|
+
|
106
|
+
// Writes the provided buffer directly to stderr, in a safe, low-level manner.
|
107
|
+
//
|
108
|
+
// In POSIX this means calling write(), which is async-signal safe and does
|
109
|
+
// not malloc. If the platform supports the SYS_write syscall, we invoke that
|
110
|
+
// directly to side-step any libc interception.
|
111
|
+
void SafeWriteToStderr(const char *s, size_t len);
|
112
|
+
|
113
|
+
// compile-time function to get the "base" filename, that is, the part of
|
114
|
+
// a filename after the last "/" or "\" path separator. The search starts at
|
115
|
+
// the end of the string; the second parameter is the length of the string.
|
116
|
+
constexpr const char* Basename(const char* fname, int offset) {
|
117
|
+
return offset == 0 || fname[offset - 1] == '/' || fname[offset - 1] == '\\'
|
118
|
+
? fname + offset
|
119
|
+
: Basename(fname, offset - 1);
|
120
|
+
}
|
121
|
+
|
122
|
+
// For testing only.
|
123
|
+
// Returns true if raw logging is fully supported. When it is not
|
124
|
+
// fully supported, no messages will be emitted, but a log at FATAL
|
125
|
+
// severity will cause an abort.
|
126
|
+
//
|
127
|
+
// TODO(gfalcon): Come up with a better name for this method.
|
128
|
+
bool RawLoggingFullySupported();
|
129
|
+
|
130
|
+
// Function type for a raw_logging customization hook for suppressing messages
|
131
|
+
// by severity, and for writing custom prefixes on non-suppressed messages.
|
132
|
+
//
|
133
|
+
// The installed hook is called for every raw log invocation. The message will
|
134
|
+
// be logged to stderr only if the hook returns true. FATAL errors will cause
|
135
|
+
// the process to abort, even if writing to stderr is suppressed. The hook is
|
136
|
+
// also provided with an output buffer, where it can write a custom log message
|
137
|
+
// prefix.
|
138
|
+
//
|
139
|
+
// The raw_logging system does not allocate memory or grab locks. User-provided
|
140
|
+
// hooks must avoid these operations, and must not throw exceptions.
|
141
|
+
//
|
142
|
+
// 'severity' is the severity level of the message being written.
|
143
|
+
// 'file' and 'line' are the file and line number where the ABSL_RAW_LOG macro
|
144
|
+
// was located.
|
145
|
+
// 'buffer' and 'buf_size' are pointers to the buffer and buffer size. If the
|
146
|
+
// hook writes a prefix, it must increment *buffer and decrement *buf_size
|
147
|
+
// accordingly.
|
148
|
+
using LogPrefixHook = bool (*)(absl::LogSeverity severity, const char* file,
|
149
|
+
int line, char** buffer, int* buf_size);
|
150
|
+
|
151
|
+
// Function type for a raw_logging customization hook called to abort a process
|
152
|
+
// when a FATAL message is logged. If the provided AbortHook() returns, the
|
153
|
+
// logging system will call abort().
|
154
|
+
//
|
155
|
+
// 'file' and 'line' are the file and line number where the ABSL_RAW_LOG macro
|
156
|
+
// was located.
|
157
|
+
// The NUL-terminated logged message lives in the buffer between 'buf_start'
|
158
|
+
// and 'buf_end'. 'prefix_end' points to the first non-prefix character of the
|
159
|
+
// buffer (as written by the LogPrefixHook.)
|
160
|
+
using AbortHook = void (*)(const char* file, int line, const char* buf_start,
|
161
|
+
const char* prefix_end, const char* buf_end);
|
162
|
+
|
163
|
+
// Internal logging function for ABSL_INTERNAL_LOG to dispatch to.
|
164
|
+
//
|
165
|
+
// TODO(gfalcon): When string_view no longer depends on base, change this
|
166
|
+
// interface to take its message as a string_view instead.
|
167
|
+
using InternalLogFunction = void (*)(absl::LogSeverity severity,
|
168
|
+
const char* file, int line,
|
169
|
+
const std::string& message);
|
170
|
+
|
171
|
+
extern base_internal::AtomicHook<InternalLogFunction> internal_log_function;
|
172
|
+
|
173
|
+
void RegisterInternalLogFunction(InternalLogFunction func);
|
174
|
+
|
175
|
+
} // namespace raw_logging_internal
|
176
|
+
ABSL_NAMESPACE_END
|
177
|
+
} // namespace absl
|
178
|
+
|
179
|
+
#endif // ABSL_BASE_INTERNAL_RAW_LOGGING_H_
|
@@ -0,0 +1,58 @@
|
|
1
|
+
// Copyright 2017 The Abseil Authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
//
|
15
|
+
// Core interfaces and definitions used by by low-level interfaces such as
|
16
|
+
// SpinLock.
|
17
|
+
|
18
|
+
#ifndef ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
|
19
|
+
#define ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
|
20
|
+
|
21
|
+
#include "absl/base/config.h"
|
22
|
+
|
23
|
+
namespace absl {
|
24
|
+
ABSL_NAMESPACE_BEGIN
|
25
|
+
namespace base_internal {
|
26
|
+
|
27
|
+
// Used to describe how a thread may be scheduled. Typically associated with
|
28
|
+
// the declaration of a resource supporting synchronized access.
|
29
|
+
//
|
30
|
+
// SCHEDULE_COOPERATIVE_AND_KERNEL:
|
31
|
+
// Specifies that when waiting, a cooperative thread (e.g. a Fiber) may
|
32
|
+
// reschedule (using base::scheduling semantics); allowing other cooperative
|
33
|
+
// threads to proceed.
|
34
|
+
//
|
35
|
+
// SCHEDULE_KERNEL_ONLY: (Also described as "non-cooperative")
|
36
|
+
// Specifies that no cooperative scheduling semantics may be used, even if the
|
37
|
+
// current thread is itself cooperatively scheduled. This means that
|
38
|
+
// cooperative threads will NOT allow other cooperative threads to execute in
|
39
|
+
// their place while waiting for a resource of this type. Host operating system
|
40
|
+
// semantics (e.g. a futex) may still be used.
|
41
|
+
//
|
42
|
+
// When optional, clients should strongly prefer SCHEDULE_COOPERATIVE_AND_KERNEL
|
43
|
+
// by default. SCHEDULE_KERNEL_ONLY should only be used for resources on which
|
44
|
+
// base::scheduling (e.g. the implementation of a Scheduler) may depend.
|
45
|
+
//
|
46
|
+
// NOTE: Cooperative resources may not be nested below non-cooperative ones.
|
47
|
+
// This means that it is invalid to to acquire a SCHEDULE_COOPERATIVE_AND_KERNEL
|
48
|
+
// resource if a SCHEDULE_KERNEL_ONLY resource is already held.
|
49
|
+
enum SchedulingMode {
|
50
|
+
SCHEDULE_KERNEL_ONLY = 0, // Allow scheduling only the host OS.
|
51
|
+
SCHEDULE_COOPERATIVE_AND_KERNEL, // Also allow cooperative scheduling.
|
52
|
+
};
|
53
|
+
|
54
|
+
} // namespace base_internal
|
55
|
+
ABSL_NAMESPACE_END
|
56
|
+
} // namespace absl
|
57
|
+
|
58
|
+
#endif // ABSL_BASE_INTERNAL_SCHEDULING_MODE_H_
|