Skip to content

Commit 1065514

Browse files
Abseil Teamrogeeff
Abseil Team
authored andcommitted
Export of internal Abseil changes
-- 07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <[email protected]>: Correct the comment from "AlphaNum" to "Arg". PiperOrigin-RevId: 416139192 -- adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <[email protected]>: Fix NewExternalRep() to require data being non-empty, and remove nullptr return. PiperOrigin-RevId: 416135865 -- c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <[email protected]>: Fix doc comment for absl::ascii_isprint(). The comment was incorrectly saying that it includes all whitespace. It doesn't; the only whitespace char it includes is ' '. PiperOrigin-RevId: 416112524 -- d83327800159c07002b6865e21232a12463e02dd by Abseil Team <[email protected]>: Internal change PiperOrigin-RevId: 416099978 -- baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <[email protected]>: Prevent compiler from optimizing Group_Match* benchmarks away. Currently we benchmark single store of precomputed value. Not all affected benchmarks show performance changes: BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10) BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10) BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10) BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8) BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9) But inspecting the generated code shows the difference, e. g. BM_Group_MatchFirstEmptyOrDeleted Before: add $0xffffffffffffffff,%rbx jne 30 After: pcmpeqd %xmm0,%xmm0 pcmpgtb -0x30(%rbp),%xmm0 pmovmskb %xmm0,%eax add: 0x23$0xffffffffffffffff,%rbx jne 40 PiperOrigin-RevId: 416083515 -- 122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <[email protected]>: Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error. PiperOrigin-RevId: 416036072 -- 020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <[email protected]>: Make Cord::InlineRep::set_data unconditionally zero out memory. Currently there is a single case where we don't zero out memory as an optimization. Unconditional zeroing doesn't show any changes in benchmarks, except for the unrelated improvement: BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19) BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17) BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17) BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20) BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17) BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18) BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18) BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16) BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18) BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16) BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19) BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16) This is clearly an alignmnet effect since number of the executed instructions is the same: M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal) BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39) BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40) BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39) BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40) BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39) BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40) BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39) BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40) BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40) BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40) BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40) This makes code simpler and doesn't regress performance. PiperOrigin-RevId: 415560574 -- 37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <[email protected]>: Internal change PiperOrigin-RevId: 415558737 -- 86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <[email protected]>: Internal change PiperOrigin-RevId: 415515201 -- 6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <[email protected]>: Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp PiperOrigin-RevId: 415360871 -- 9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <[email protected]>: absl::flat_hash_set compiles with -Wconversion -Wsign-compare PiperOrigin-RevId: 415357498 -- 9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <[email protected]>: Fix AddressIsReadable for the corner case of (aligned) addr == NULL. PiperOrigin-RevId: 415307792 -- 1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <[email protected]>: Internal change PiperOrigin-RevId: 415162872 -- 64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <[email protected]>: Fix a typo in the comments PiperOrigin-RevId: 415088461 -- 41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <[email protected]>: Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic for system call sandboxes. PiperOrigin-RevId: 415073965 -- 870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <[email protected]>: Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER PiperOrigin-RevId: 414871189 -- f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <[email protected]>: Remove reference to __SANITIZE_MEMORY__, which does not exist It appears to have been copied by pattern matching from the ASAN/TSAN code blocks. https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126 PiperOrigin-RevId: 414806587 -- b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <[email protected]>: Rollback previous commit: SYS_open is not defined in certain environments. PiperOrigin-RevId: 414521820 -- 5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <[email protected]>: Use syscall(SYS_open, ...) instead of open() to avoid possible symbol interposition. Also add some warning notes. PiperOrigin-RevId: 414508186 -- 1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <[email protected]>: Correct aarch64 macro check The macro is __aarch64__, not __arch64__. PiperOrigin-RevId: 414446225 -- a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <[email protected]>: Fix backwards comment in the last commit. PiperOrigin-RevId: 414281214 -- 11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <[email protected]>: AddressIsReadable() didn't work correctly on ARM when the given pointer was misaligned at the end of the page. Fix that by aligning the pointer on an 8-byte boundary before checking it. PiperOrigin-RevId: 414203863 GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348 Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
1 parent fb7dd24 commit 1065514

File tree

14 files changed

+189
-133
lines changed

14 files changed

+189
-133
lines changed

absl/base/config.h

+22-2
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,6 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
751751
// a compiler instrumentation module and a run-time library.
752752
#ifdef ABSL_HAVE_MEMORY_SANITIZER
753753
#error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
754-
#elif defined(__SANITIZE_MEMORY__)
755-
#define ABSL_HAVE_MEMORY_SANITIZER 1
756754
#elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer)
757755
#define ABSL_HAVE_MEMORY_SANITIZER 1
758756
#endif
@@ -779,6 +777,28 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
779777
#define ABSL_HAVE_ADDRESS_SANITIZER 1
780778
#endif
781779

780+
// ABSL_HAVE_HWADDRESS_SANITIZER
781+
//
782+
// Hardware-Assisted AddressSanitizer (or HWASAN) is even faster than asan
783+
// memory error detector which can use CPU features like ARM TBI, Intel LAM or
784+
// AMD UAI.
785+
#ifdef ABSL_HAVE_HWADDRESS_SANITIZER
786+
#error "ABSL_HAVE_HWADDRESS_SANITIZER cannot be directly set."
787+
#elif defined(__SANITIZE_HWADDRESS__)
788+
#define ABSL_HAVE_HWADDRESS_SANITIZER 1
789+
#elif ABSL_HAVE_FEATURE(hwaddress_sanitizer)
790+
#define ABSL_HAVE_HWADDRESS_SANITIZER 1
791+
#endif
792+
793+
// ABSL_HAVE_LEAK_SANITIZER
794+
//
795+
// LeakSanitizer (or lsan) is a detector of memory leaks.
796+
#ifdef ABSL_HAVE_LEAK_SANITIZER
797+
#error "ABSL_HAVE_LEAK_SANITIZER cannot be directly set."
798+
#elif ABSL_HAVE_FEATURE(leak_sanitizer)
799+
#define ABSL_HAVE_LEAK_SANITIZER 1
800+
#endif
801+
782802
// ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
783803
//
784804
// Class template argument deduction is a language feature added in C++17.

absl/base/internal/direct_mmap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd,
8080
(defined(__PPC__) && !defined(__PPC64__)) || \
8181
(defined(__riscv) && __riscv_xlen == 32) || \
8282
(defined(__s390__) && !defined(__s390x__)) || \
83-
(defined(__sparc__) && !defined(__arch64__))
83+
(defined(__sparc__) && !defined(__aarch64__))
8484
// On these architectures, implement mmap with mmap2.
8585
static int pagesize = 0;
8686
if (pagesize == 0) {

absl/container/internal/raw_hash_set.h

+14-13
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ constexpr bool IsNoThrowSwappable(std::false_type /* is_swappable */) {
201201
template <typename T>
202202
uint32_t TrailingZeros(T x) {
203203
ABSL_INTERNAL_ASSUME(x != 0);
204-
return countr_zero(x);
204+
return static_cast<uint32_t>(countr_zero(x));
205205
}
206206

207207
// An abstraction over a bitmask. It provides an easy way to iterate through the
@@ -230,7 +230,7 @@ class BitMask {
230230
return *this;
231231
}
232232
explicit operator bool() const { return mask_ != 0; }
233-
int operator*() const { return LowestBitSet(); }
233+
uint32_t operator*() const { return LowestBitSet(); }
234234
uint32_t LowestBitSet() const {
235235
return container_internal::TrailingZeros(mask_) >> Shift;
236236
}
@@ -248,7 +248,7 @@ class BitMask {
248248
uint32_t LeadingZeros() const {
249249
constexpr int total_significant_bits = SignificantBits << Shift;
250250
constexpr int extra_bits = sizeof(T) * 8 - total_significant_bits;
251-
return countl_zero(mask_ << extra_bits) >> Shift;
251+
return static_cast<uint32_t>(countl_zero(mask_ << extra_bits)) >> Shift;
252252
}
253253

254254
private:
@@ -360,30 +360,31 @@ struct GroupSse2Impl {
360360
BitMask<uint32_t, kWidth> Match(h2_t hash) const {
361361
auto match = _mm_set1_epi8(hash);
362362
return BitMask<uint32_t, kWidth>(
363-
_mm_movemask_epi8(_mm_cmpeq_epi8(match, ctrl)));
363+
static_cast<uint32_t>(_mm_movemask_epi8(_mm_cmpeq_epi8(match, ctrl))));
364364
}
365365

366366
// Returns a bitmask representing the positions of empty slots.
367367
BitMask<uint32_t, kWidth> MatchEmpty() const {
368368
#if ABSL_INTERNAL_RAW_HASH_SET_HAVE_SSSE3
369369
// This only works because ctrl_t::kEmpty is -128.
370370
return BitMask<uint32_t, kWidth>(
371-
_mm_movemask_epi8(_mm_sign_epi8(ctrl, ctrl)));
371+
static_cast<uint32_t>(_mm_movemask_epi8(_mm_sign_epi8(ctrl, ctrl))));
372372
#else
373373
return Match(static_cast<h2_t>(ctrl_t::kEmpty));
374374
#endif
375375
}
376376

377377
// Returns a bitmask representing the positions of empty or deleted slots.
378378
BitMask<uint32_t, kWidth> MatchEmptyOrDeleted() const {
379-
auto special = _mm_set1_epi8(static_cast<int8_t>(ctrl_t::kSentinel));
379+
auto special = _mm_set1_epi8(static_cast<uint8_t>(ctrl_t::kSentinel));
380380
return BitMask<uint32_t, kWidth>(
381-
_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)));
381+
static_cast<uint32_t>(
382+
_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl))));
382383
}
383384

384385
// Returns the number of trailing empty or deleted elements in the group.
385386
uint32_t CountLeadingEmptyOrDeleted() const {
386-
auto special = _mm_set1_epi8(static_cast<int8_t>(ctrl_t::kSentinel));
387+
auto special = _mm_set1_epi8(static_cast<uint8_t>(ctrl_t::kSentinel));
387388
return TrailingZeros(static_cast<uint32_t>(
388389
_mm_movemask_epi8(_mm_cmpgt_epi8_fixed(special, ctrl)) + 1));
389390
}
@@ -1465,7 +1466,7 @@ class raw_hash_set {
14651466
auto seq = probe(ctrl_, hash, capacity_);
14661467
while (true) {
14671468
Group g{ctrl_ + seq.offset()};
1468-
for (int i : g.Match(H2(hash))) {
1469+
for (uint32_t i : g.Match(H2(hash))) {
14691470
if (ABSL_PREDICT_TRUE(PolicyTraits::apply(
14701471
EqualElement<K>{key, eq_ref()},
14711472
PolicyTraits::element(slots_ + seq.offset(i)))))
@@ -1610,7 +1611,7 @@ class raw_hash_set {
16101611
void erase_meta_only(const_iterator it) {
16111612
assert(IsFull(*it.inner_.ctrl_) && "erasing a dangling iterator");
16121613
--size_;
1613-
const size_t index = it.inner_.ctrl_ - ctrl_;
1614+
const size_t index = static_cast<size_t>(it.inner_.ctrl_ - ctrl_);
16141615
const size_t index_before = (index - Group::kWidth) & capacity_;
16151616
const auto empty_after = Group(it.inner_.ctrl_).MatchEmpty();
16161617
const auto empty_before = Group(ctrl_ + index_before).MatchEmpty();
@@ -1832,7 +1833,7 @@ class raw_hash_set {
18321833
auto seq = probe(ctrl_, hash, capacity_);
18331834
while (true) {
18341835
Group g{ctrl_ + seq.offset()};
1835-
for (int i : g.Match(H2(hash))) {
1836+
for (uint32_t i : g.Match(H2(hash))) {
18361837
if (ABSL_PREDICT_TRUE(PolicyTraits::element(slots_ + seq.offset(i)) ==
18371838
elem))
18381839
return true;
@@ -1864,7 +1865,7 @@ class raw_hash_set {
18641865
auto seq = probe(ctrl_, hash, capacity_);
18651866
while (true) {
18661867
Group g{ctrl_ + seq.offset()};
1867-
for (int i : g.Match(H2(hash))) {
1868+
for (uint32_t i : g.Match(H2(hash))) {
18681869
if (ABSL_PREDICT_TRUE(PolicyTraits::apply(
18691870
EqualElement<K>{key, eq_ref()},
18701871
PolicyTraits::element(slots_ + seq.offset(i)))))
@@ -1984,7 +1985,7 @@ struct HashtableDebugAccess<Set, absl::void_t<typename Set::raw_hash_set>> {
19841985
auto seq = probe(set.ctrl_, hash, set.capacity_);
19851986
while (true) {
19861987
container_internal::Group g{set.ctrl_ + seq.offset()};
1987-
for (int i : g.Match(container_internal::H2(hash))) {
1988+
for (uint32_t i : g.Match(container_internal::H2(hash))) {
19881989
if (Traits::apply(
19891990
typename Set::template EqualElement<typename Set::key_type>{
19901991
key, set.eq_ref()},

absl/container/internal/raw_hash_set_benchmark.cc

+16-4
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ void BM_Group_Match(benchmark::State& state) {
330330
h2_t h = 1;
331331
for (auto _ : state) {
332332
::benchmark::DoNotOptimize(h);
333+
::benchmark::DoNotOptimize(g);
333334
::benchmark::DoNotOptimize(g.Match(h));
334335
}
335336
}
@@ -339,32 +340,43 @@ void BM_Group_MatchEmpty(benchmark::State& state) {
339340
std::array<ctrl_t, Group::kWidth> group;
340341
Iota(group.begin(), group.end(), -4);
341342
Group g{group.data()};
342-
for (auto _ : state) ::benchmark::DoNotOptimize(g.MatchEmpty());
343+
for (auto _ : state) {
344+
::benchmark::DoNotOptimize(g);
345+
::benchmark::DoNotOptimize(g.MatchEmpty());
346+
}
343347
}
344348
BENCHMARK(BM_Group_MatchEmpty);
345349

346350
void BM_Group_MatchEmptyOrDeleted(benchmark::State& state) {
347351
std::array<ctrl_t, Group::kWidth> group;
348352
Iota(group.begin(), group.end(), -4);
349353
Group g{group.data()};
350-
for (auto _ : state) ::benchmark::DoNotOptimize(g.MatchEmptyOrDeleted());
354+
for (auto _ : state) {
355+
::benchmark::DoNotOptimize(g);
356+
::benchmark::DoNotOptimize(g.MatchEmptyOrDeleted());
357+
}
351358
}
352359
BENCHMARK(BM_Group_MatchEmptyOrDeleted);
353360

354361
void BM_Group_CountLeadingEmptyOrDeleted(benchmark::State& state) {
355362
std::array<ctrl_t, Group::kWidth> group;
356363
Iota(group.begin(), group.end(), -2);
357364
Group g{group.data()};
358-
for (auto _ : state)
365+
for (auto _ : state) {
366+
::benchmark::DoNotOptimize(g);
359367
::benchmark::DoNotOptimize(g.CountLeadingEmptyOrDeleted());
368+
}
360369
}
361370
BENCHMARK(BM_Group_CountLeadingEmptyOrDeleted);
362371

363372
void BM_Group_MatchFirstEmptyOrDeleted(benchmark::State& state) {
364373
std::array<ctrl_t, Group::kWidth> group;
365374
Iota(group.begin(), group.end(), -2);
366375
Group g{group.data()};
367-
for (auto _ : state) ::benchmark::DoNotOptimize(*g.MatchEmptyOrDeleted());
376+
for (auto _ : state) {
377+
::benchmark::DoNotOptimize(g);
378+
::benchmark::DoNotOptimize(*g.MatchEmptyOrDeleted());
379+
}
368380
}
369381
BENCHMARK(BM_Group_MatchFirstEmptyOrDeleted);
370382

absl/debugging/internal/address_is_readable.cc

+46-56
Original file line numberDiff line numberDiff line change
@@ -30,77 +30,67 @@ bool AddressIsReadable(const void* /* addr */) { return true; }
3030
ABSL_NAMESPACE_END
3131
} // namespace absl
3232

33-
#else
33+
#else // __linux__ && !__ANDROID__
3434

35-
#include <fcntl.h>
36-
#include <sys/stat.h>
37-
#include <sys/syscall.h>
38-
#include <sys/types.h>
35+
#include <stdint.h>
36+
#include <syscall.h>
3937
#include <unistd.h>
4038

41-
#include <cerrno>
42-
4339
#include "absl/base/internal/errno_saver.h"
4440
#include "absl/base/internal/raw_logging.h"
4541

4642
namespace absl {
4743
ABSL_NAMESPACE_BEGIN
4844
namespace debugging_internal {
4945

46+
// NOTE: be extra careful about adding any interposable function calls here
47+
// (such as open(), read(), etc.). These symbols may be interposed and will get
48+
// invoked in contexts they don't expect.
49+
//
50+
// NOTE: any new system calls here may also require sandbox reconfiguration.
51+
//
5052
bool AddressIsReadable(const void *addr) {
51-
int fd = 0;
53+
// Align address on 8-byte boundary. On aarch64, checking last
54+
// byte before inaccessible page returned unexpected EFAULT.
55+
const uintptr_t u_addr = reinterpret_cast<uintptr_t>(addr) & ~7;
56+
addr = reinterpret_cast<const void *>(u_addr);
57+
58+
// rt_sigprocmask below will succeed for this input.
59+
if (addr == nullptr) return false;
60+
5261
absl::base_internal::ErrnoSaver errno_saver;
53-
for (int j = 0; j < 2; j++) {
54-
// Here we probe with some syscall which
55-
// - accepts a one-byte region of user memory as input
56-
// - tests for EFAULT before other validation
57-
// - has no problematic side-effects
58-
//
59-
// connect(2) works for this. It copies the address into kernel
60-
// memory before any validation beyond requiring an open fd.
61-
// But a one byte address is never valid (sa_family is two bytes),
62-
// so the call cannot succeed and change any state.
63-
//
64-
// This strategy depends on Linux implementation details,
65-
// so we rely on the test to alert us if it stops working.
66-
//
67-
// Some discarded past approaches:
68-
// - msync() doesn't reject PROT_NONE regions
69-
// - write() on /dev/null doesn't return EFAULT
70-
// - write() on a pipe requires creating it and draining the writes
71-
//
72-
// Use syscall(SYS_connect, ...) instead of connect() to prevent ASAN
73-
// and other checkers from complaining about accesses to arbitrary memory.
74-
do {
75-
ABSL_RAW_CHECK(syscall(SYS_connect, fd, addr, 1) == -1,
76-
"should never succeed");
77-
} while (errno == EINTR);
78-
if (errno == EFAULT) return false;
79-
if (errno == EBADF) {
80-
if (j != 0) {
81-
// Unclear what happened.
82-
ABSL_RAW_LOG(ERROR, "unexpected EBADF on fd %d", fd);
83-
return false;
84-
}
85-
// fd 0 must have been closed. Try opening it again.
86-
// Note: we shouldn't leak too many file descriptors here, since we expect
87-
// to get fd==0 reopened.
88-
fd = open("/dev/null", O_RDONLY);
89-
if (fd == -1) {
90-
ABSL_RAW_LOG(ERROR, "can't open /dev/null");
91-
return false;
92-
}
93-
} else {
94-
// probably EINVAL or ENOTSOCK; we got past EFAULT validation.
95-
return true;
96-
}
97-
}
98-
ABSL_RAW_CHECK(false, "unreachable");
99-
return false;
62+
63+
// Here we probe with some syscall which
64+
// - accepts an 8-byte region of user memory as input
65+
// - tests for EFAULT before other validation
66+
// - has no problematic side-effects
67+
//
68+
// rt_sigprocmask(2) works for this. It copies sizeof(kernel_sigset_t)==8
69+
// bytes from the address into the kernel memory before any validation.
70+
//
71+
// The call can never succeed, since the `how` parameter is not one of
72+
// SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK.
73+
//
74+
// This strategy depends on Linux implementation details,
75+
// so we rely on the test to alert us if it stops working.
76+
//
77+
// Some discarded past approaches:
78+
// - msync() doesn't reject PROT_NONE regions
79+
// - write() on /dev/null doesn't return EFAULT
80+
// - write() on a pipe requires creating it and draining the writes
81+
// - connect() works but is problematic for sandboxes and needs a valid
82+
// file descriptor
83+
//
84+
// This can never succeed (invalid first argument to sigprocmask).
85+
ABSL_RAW_CHECK(syscall(SYS_rt_sigprocmask, ~0, addr, nullptr,
86+
/*sizeof(kernel_sigset_t)*/ 8) == -1,
87+
"unexpected success");
88+
ABSL_RAW_CHECK(errno == EFAULT || errno == EINVAL, "unexpected errno");
89+
return errno != EFAULT;
10090
}
10191

10292
} // namespace debugging_internal
10393
ABSL_NAMESPACE_END
10494
} // namespace absl
10595

106-
#endif
96+
#endif // __linux__ && !__ANDROID__

absl/flags/declare.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ABSL_NAMESPACE_END
6060
// The ABSL_DECLARE_FLAG(type, name) macro expands to:
6161
//
6262
// extern absl::Flag<type> FLAGS_name;
63-
#define ABSL_DECLARE_FLAG(type, name) extern ::absl::Flag<type> FLAGS_##name
63+
#define ABSL_DECLARE_FLAG(type, name) \
64+
extern absl::Flag<type> FLAGS_##name; \
65+
namespace absl /* block flags in namespaces */ {} \
66+
/* second redeclaration is to allow applying attributes */ \
67+
extern absl::Flag<type> FLAGS_##name
6468

6569
#endif // ABSL_FLAGS_DECLARE_H_

absl/random/internal/randen_detect.cc

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#if defined(ABSL_INTERNAL_USE_X86_CPUID)
4141
#if defined(_WIN32) || defined(_WIN64)
4242
#include <intrin.h> // NOLINT(build/include_order)
43-
#pragma intrinsic(__cpuid)
4443
#else
4544
// MSVC-equivalent __cpuid intrinsic function.
4645
static void __cpuid(int cpu_info[4], int info_type) {

absl/strings/ascii.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ inline bool ascii_isdigit(unsigned char c) { return c >= '0' && c <= '9'; }
133133

134134
// ascii_isprint()
135135
//
136-
// Determines whether the given character is printable, including whitespace.
136+
// Determines whether the given character is printable, including spaces.
137137
inline bool ascii_isprint(unsigned char c) { return c >= 32 && c < 127; }
138138

139139
// ascii_isgraph()

0 commit comments

Comments
 (0)