Skip to content

Update folly/docs/Synchronized.md - #15

Closed
ajtulloch wants to merge 1 commit into
meta:masterfrom
ajtulloch:patch-1
Closed

ajtulloch wants to merge 1 commit into
meta:masterfrom
ajtulloch:patch-1

Conversation

@ajtulloch

Copy link
Copy Markdown

Fixed escaping bug where the > in operator-> was interpreted as starting a code block. 

Fixed escaping bug where the `>` in `operator->` was interpreted as starting a code block. 
@jdelong

jdelong commented Sep 24, 2012

Copy link
Copy Markdown
Contributor

Thanks; I merged it upstream (so it'll be pushed back out in the next push).

@jdelong jdelong closed this Sep 24, 2012
jdelong pushed a commit that referenced this pull request Oct 12, 2012
Summary:
Fixed escaping bug where the `>` in `operator->` was
interpreted as starting a code block.  Folly github pull #15.

Test Plan: no

Reviewed By: [email protected]

FB internal diff: D582873
@tian-yuan tian-yuan mentioned this pull request Jul 23, 2016
@tdauth tdauth mentioned this pull request Mar 3, 2017
facebook-github-bot pushed a commit that referenced this pull request Mar 31, 2017
Summary:
ubsan flags this problem:

```
buck-out/opt-ubsan/gen/folly/__default_headers__#header-mode-symlink-tree-with-header-map,headers/folly/experimental/StringKeyedCommon.h:31:18: runtime error: null pointer passed as argument 2, which is declared to never be null
third-party-buck/gcc-4.9-glibc-2.20-fb/build/glibc/include/string.h:47:28: note: nonnull attribute specified here
    #0 0x5cb88f in std::pair<std::__detail::_Node_iterator<std::pair<folly::Range<char const*> const, facebook::eden::GitIgnore>, false, true>, bool> folly::StringKeyedUnorderedMap<facebook::eden::GitIgnore, folly::Hash, std::equal_to<folly::Range<char const*> >, std::allocator<std::pair<folly::Range<char const*> const, facebook::eden::GitIgnore> > >::emplace<facebook::eden::GitIgnore>(folly::Range<char const*>, facebook::eden::GitIgnore&&) buck-out/opt-ubsan/gen/folly/__default_headers__#header-mode-symlink-tree-with-header-map,headers/folly/experimental/StringKeyedCommon.h:31
    #1 0x5c6652 in facebook::eden::(anonymous namespace)::IgnoreChecker::isIgnored(facebook::eden::detail::RelativePathBase<folly::Range<char const*> >) eden/fs/inodes/Dirstate.cpp:226
    #2 0x5c6037 in facebook::eden::(anonymous namespace)::IgnoreChecker::isIgnored(facebook::eden::detail::RelativePathBase<folly::Range<char const*> >) eden/fs/inodes/Dirstate.cpp:180
    #3 0x5c5173 in facebook::eden::Dirstate::getStatusForExistingDirectory(facebook::eden::detail::RelativePathBase<folly::Range<char const*> >) const eden/fs/inodes/Dirstate.cpp:372
    #4 0x5c4509 in facebook::eden::Dirstate::getStatus() const eden/fs/inodes/Dirstate.cpp:272
    #5 0x50a448 in verifyExpectedDirstate(facebook::eden::Dirstate const*, std::unordered_map<std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> >, facebook::eden::StatusCode, std::hash<std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> > >, std::equal_to<std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> > >, std::allocator<std::pair<std::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, std::fbstring_core<char> > const, facebook::eden::StatusCode> > >&&) eden/fs/inodes/test/DirstateTest.cpp:48
    #6 0x50c70c in Dirstate_addDirectoriesWithMixOfFiles_Test::TestBody() eden/fs/inodes/test/DirstateTest.cpp:220
    #7 0xb45857 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/./src/gtest.cc:2364
    #8 0xb36784 in testing::Test::Run() /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/./src/gtest.cc:2437
    #9 0xb36957 in testing::TestInfo::Run() [clone .part.558] /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/./src/gtest.cc:2612
    #10 0xb36b74 in testing::TestCase::Run() [clone .part.559] /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/./src/gtest.cc:2587
    #11 0xb3806e in testing::internal::UnitTestImpl::RunAllTests() [clone .part.561] /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/./src/gtest.cc:4571
    #12 0xb382d9 in testing::UnitTest::Run() /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/./src/gtest.cc:4519
    #13 0x861ca7 in main third-party-buck/gcc-4.9-glibc-2.20-fb/build/gtest/include/gtest/gtest.h:2326
    #14 0x7f20be0740f5 in __libc_start_main /home/engshare/third-party2/glibc/2.20/src/glibc-2.20/csu/libc-start.c:289
    #15 0x4a552c in _start /home/engshare/third-party2/glibc/2.20/src/glibc-2.20/csu/../sysdeps/x86_64/start.S:122

UndefinedBehaviorSanitizer: undefined-behavior buck-out/opt-ubsan/gen/folly/__default_headers__#header-mode-symlink-tree-with-header-map,headers/folly/experimental/StringKeyedCommon.h:31:18
```

The issue is that `StringPiece` default constructs to `{nullptr, nullptr}` as a valid representation of an empty string.
This is tripping up UBSAN in this case.

The fix is a trivial nullptr check

Reviewed By: igorsugak

Differential Revision: D4791015

fbshipit-source-id: dec7484b29ecb29c17b8dd6a9b0e8093f07d63cb
facebook-github-bot pushed a commit that referenced this pull request Dec 18, 2019
Summary:
Exposed by UBSAN's unsigned-integer-overflow:
```
> folly/experimental/observer/detail/Core.cpp:179:9: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long')
>     #0 0x7f605837dfea in folly::observer_detail::Core::removeStaleDependents()::$_4::operator()(std::vector<std::weak_ptr<folly::observer_detail::Core>, std::allocator<std::weak_ptr<folly::observer_detail::Core> > >&) const folly/experimental/observer/detail/Core.cpp:179
>     #1 0x7f6058344b0c in auto folly::SynchronizedBase<folly::Synchronized<std::vector<std::weak_ptr<folly::observer_detail::Core>, std::allocator<std::weak_ptr<folly::observer_detail::Core> > >, folly::SharedMutexImpl<false, void, std::atomic, false, false> >, (folly::detail::MutexLevel)1>::withWLock<folly::observer_detail::Core::removeStaleDependents()::$_4>(folly::observer_detail::Core::removeStaleDependents()::$_4&&) folly/Synchronized.h:210
>     #2 0x7f6058344917 in folly::observer_detail::Core::removeStaleDependents() folly/experimental/observer/detail/Core.cpp:174
>     #3 0x7f60583785cb in folly::observer_detail::Core::~Core()::$_2::operator()(std::unordered_set<std::shared_ptr<folly::observer_detail::Core>, std::hash<std::shared_ptr<folly::observer_detail::Core> >, std::equal_to<std::shared_ptr<folly::observer_detail::Core> >, std::allocator<std::shared_ptr<folly::observer_detail::Core> > > const&) const folly/experimental/observer/detail/Core.cpp:156
>     #4 0x7f6058343cdc in auto folly::SynchronizedBase<folly::Synchronized<std::unordered_set<std::shared_ptr<folly::observer_detail::Core>, std::hash<std::shared_ptr<folly::observer_detail::Core> >, std::equal_to<std::shared_ptr<folly::observer_detail::Core> >, std::allocator<std::shared_ptr<folly::observer_detail::Core> > >, folly::SharedMutexImpl<false, void, std::atomic, false, false> >, (folly::detail::MutexLevel)1>::withWLock<folly::observer_detail::Core::~Core()::$_2>(folly::ob
server_detail::Core::~Core()::$_2&&) folly/Synchronized.h:210
>     #5 0x7f6058343a17 in folly::observer_detail::Core::~Core() folly/experimental/observer/detail/Core.cpp:154
>     #6 0x7f605838b8ca in std::_Sp_counted_ptr<folly::observer_detail::Core*, (__gnu_cxx::_Lock_policy)2>::_M_dispose() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/shared_ptr_base.h:378
>     #7 0x7f605834d411 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/shared_ptr_base.h:156
>     #8 0x7f605834d332 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/shared_ptr_base.h:686
>     #9 0x7f605834d23a in std::__shared_ptr<folly::observer_detail::Core, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/shared_ptr_base.h:1125
>     #10 0x7f605833c416 in std::shared_ptr<folly::observer_detail::Core>::~shared_ptr() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/shared_ptr.h:93
>     #11 0x7f6058376413 in folly::observer_detail::ObserverManager::scheduleRefresh(std::shared_ptr<folly::observer_detail::Core>, unsigned long)::'lambda'()::~() folly/experimental/observer/detail/ObserverManager.h:91
>     #12 0x7f6058377014 in unsigned long folly::detail::function::execSmall<folly::observer_detail::ObserverManager::scheduleRefresh(std::shared_ptr<folly::observer_detail::Core>, unsigned long)::'lambda'()>(folly::detail::function::Op, folly::detail::function::Data*, folly::detail::function::Data*) folly/Function.h:592
>     #13 0x7f6058377788 in folly::Function<void ()>::exec(folly::detail::function::Op, folly::detail::function::Data*, folly::detail::function::Data*) const folly/Function.h:649
>     #14 0x7f6058376380 in folly::Function<void ()>::~Function() folly/Function.h:781
>     #15 0x7f6058477b99 in folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()::operator()() const folly/experimental/observer/detail/ObserverManager.cpp:73
>     #16 0x7f6058473de8 in void std::__invoke_impl<void, folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()>(std::__invoke_other, folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()&&) buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/invoke.h:60
>     #17 0x7f6058473c08 in std::__invoke_result<folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()>::type std::__invoke<folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()>(folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()&&) buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/bits/invok
e.h:95
>     #18 0x7f6058473b66 in decltype(std::__invoke(_S_declval<0ul>())) std::thread::_Invoker<std::tuple<folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()> >::_M_invoke<0ul>(std::_Index_tuple<0ul>) buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/thread:234
>     #19 0x7f6058473a43 in std::thread::_Invoker<std::tuple<folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()> >::operator()() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/thread:243
>     #20 0x7f6058473549 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<folly::observer_detail::ObserverManager::UpdatesManager::CurrentQueue::CurrentQueue()::'lambda'()> > >::_M_run() buck-out/cells/fbsource/gen/third-party/gcc/7.x/stdc++-headers#header-mode-symlink-tree-with-header-map,headers/thread:186
>     #21 0x7f60576bac5f in std::execute_native_thread_routine(void*) third-party/gcc/7.x/libstdc++-v3/src/c++11/thread.cc:83
>     #22 0x7f605639e6b5 in start_thread /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/nptl/pthread_create.c:465:7
>     #23 0x7f6055ecdebe in __GI___clone /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/sysdeps/unix/sysv/linux/x86_64/clone.S:95
>
> SUMMARY: UndefinedBehaviorSanitizer: unsigned-integer-overflow folly/experimental/observer/detail/Core.cpp:179:9
```

Fix the error by rearranging increment and decrement operations.

Reviewed By: leikahing

Differential Revision: D19164999

fbshipit-source-id: d3c9b638492d0bf44c2acaac1e95fafe8b785182
facebook-github-bot pushed a commit that referenced this pull request Dec 19, 2019
Summary:
Exposed by UBSAN's misaligned-pointer-use:
```lang=bash
> folly/test/stl_tests/StlVectorTest.cpp:544:12: runtime error: upcast of misaligned address 0x0000feebdaed for type 'DataTracker<false>', which requires 8 byte alignment
> 0x0000feebdaed: note: pointer points here
> <memory cannot be printed>
>     #0 0x6c9b93 in DataTracker<false>::~DataTracker() folly/test/stl_tests/StlVectorTest.cpp:544
>     #1 0x6c94fe in Data<0u, 0ul>::~Data() folly/test/stl_tests/StlVectorTest.cpp:605
>     #2 0xcc5f93 in void test_iteratorInsertionN2<folly::fbvector<Data<0u, 0ul>, std::allocator<Data<0u, 0ul> > > >(std::integral_constant<bool, true>) folly/test/stl_tests/StlVectorTest.cpp:2422
>     #3 0x5c9bac in void test_iteratorInsertionN3<folly::fbvector<Data<0u, 0ul>, std::allocator<Data<0u, 0ul> > > >() folly/test/stl_tests/StlVectorTest.cpp:2422
>     #4 0x5c67bd in FBVector_iteratorInsertionN_Test::TestBody() folly/test/stl_tests/StlVectorTest.cpp:2422
>     #5 0x7f9c4e5316c9 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:2464
>     #6 0x7f9c4e530dcc in testing::Test::Run() xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:2480
>     #7 0x7f9c4e5350a0 in testing::TestInfo::Run() xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:2662
>     #8 0x7f9c4e539408 in testing::TestCase::Run() xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:2780
>     #9 0x7f9c4e55a672 in testing::internal::UnitTestImpl::RunAllTests() xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:4655
>     #10 0x7f9c4e5595de in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:2464
>     #11 0x7f9c4e558b72 in testing::UnitTest::Run() xplat/third-party/gmock/googletest-1.8.0/googletest/src/gtest.cc:4263
>     #12 0x6591f3 in RUN_ALL_TESTS() buck-out/cells/fbsource/gen/xplat/third-party/gmock/gtest_headers#header-mode-symlink-tree-with-header-map,headers/gtest/gtest.h:2247
>     #13 0x659139 in main folly/test/stl_tests/StlVectorTest.cpp:3074
>     #14 0x7f9c4c75b1a5 in __libc_start_main /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/csu/libc-start.c:308:16
>     #15 0x4de029 in _start /home/engshare/third-party2/glibc/2.26/src/glibc-2.26/sysdeps/x86_64/start.S:120
>
> SUMMARY: UndefinedBehaviorSanitizer: misaligned-pointer-use folly/test/stl_tests/StlVectorTest.cpp:544:12
```

Make the crafted pointer address aligned.

Reviewed By: Gownta

Differential Revision: D19166262

fbshipit-source-id: f766656d031079350838598b135275bdbc047642
facebook-github-bot pushed a commit that referenced this pull request Oct 19, 2020
Summary:
Pull Request resolved: facebookexperimental/rust-shed#15

With the update from rustc 1.44 to 1.47 the doctests started to break when building a crate that depends on a different crate of the same name, see this: rust-lang/cargo#6819

This diff also removes the TravisCI build as it was broken and unused for some time.

Reviewed By: krallin

Differential Revision: D24390815

fbshipit-source-id: fa9c78ef394640afbf8c419f8276bbf339960406
dotconnor pushed a commit to 5448C8/folly that referenced this pull request Mar 19, 2021
…eta#15)

Summary:
Pull Request resolved: facebookexperimental/rust-shed#15

With the update from rustc 1.44 to 1.47 the doctests started to break when building a crate that depends on a different crate of the same name, see this: rust-lang/cargo#6819

This diff also removes the TravisCI build as it was broken and unused for some time.

Reviewed By: krallin

Differential Revision: D24390815

fbshipit-source-id: fa9c78ef394640afbf8c419f8276bbf339960406
@zhngs zhngs mentioned this pull request Nov 21, 2022
facebook-github-bot pushed a commit that referenced this pull request Mar 8, 2023
Summary:
AsyncUDPSocket test cases are crashing when running under llvm15. During
debugging it seems that the issue is the fact that the code tries to allocated 0
size array. Changing the code to prevent such allocation.

This is not very clean why to fix, but I am not sure if there is better one.
Please let me know if you have any suggestions.

Sample crash:
```
$ buck test //folly/io/async/test:async_udp_socket_test
...
stdout:
Note: Google Test filter = AsyncUDPSocketTest.TestDetachAttach
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from AsyncUDPSocketTest
[ RUN      ] AsyncUDPSocketTest.TestDetachAttach

stderr:
fbcode/folly/io/async/AsyncUDPSocket.cpp:699:10: runtime error: variable length array bound evaluates to non-positive value 0
    #0 0x7f4d8ed93704 in folly::AsyncUDPSocket::writev(folly::SocketAddress const&, iovec const*, unsigned long, int) fbcode/folly/io/async/AsyncUDPSocket.cpp:698
    #1 0x7f4d8ed9081f in folly::AsyncUDPSocket::writeGSO(folly::SocketAddress const&, std::unique_ptr<folly::IOBuf, std::default_delete<folly::IOBuf>> const&, int) fbcode/folly/io/async/AsyncUDPSocket.cpp:528
    #2 0x7f4d8ed900b2 in folly::AsyncUDPSocket::write(folly::SocketAddress const&, std::unique_ptr<folly::IOBuf, std::default_delete<folly::IOBuf>> const&) fbcode/folly/io/async/AsyncUDPSocket.cpp:660
    #3 0x350a05 in AsyncUDPSocketTest_TestDetachAttach_Test::TestBody() fbcode/folly/io/async/test/AsyncUDPSocketTest.cpp:914
    #4 0x7f4d90dd1ad5 in testing::Test::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:2682:50
    #5 0x7f4d90dd1ad5 in testing::Test::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:2672:6
    #6 0x7f4d90dd1c64 in testing::TestInfo::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:2861:14
    #7 0x7f4d90dd1c64 in testing::TestInfo::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:2833:6
    #8 0x7f4d90dd2321 in testing::TestSuite::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:3015:31
    #9 0x7f4d90dd2321 in testing::TestSuite::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:2993:6
    #10 0x7f4d90dd2b1e in testing::internal::UnitTestImpl::RunAllTests() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:5855:47
    #11 0x7f4d90dd1d87 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:2665:29
    #12 0x7f4d90dd1d87 in testing::UnitTest::Run() /home/engshare/third-party2/googletest/1.11.0/src/googletest/googletest/src/gtest.cc:5438:55
    #13 0x7f4d90d5c990 in RUN_ALL_TESTS() fbcode/third-party-buck/platform010/build/googletest/include/gtest/gtest.h:2490
    #14 0x7f4d90d5c618 in main fbcode/common/gtest/LightMain.cpp:20
    #15 0x7f4d8ea2c656 in __libc_start_call_main /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #16 0x7f4d8ea2c717 in __libc_start_main@GLIBC_2.2.5 /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../csu/libc-start.c:409:3
    #17 0x33ea60 in _start /home/engshare/third-party2/glibc/2.34/src/glibc-2.34/csu/../sysdeps/x86_64/start.S:116
...
```

Reviewed By: russoue, dmm-fb

Differential Revision: D43858875

fbshipit-source-id: 93749bab17027b6dfc0dbc01b6c183e501a5494c
facebook-github-bot pushed a commit that referenced this pull request Aug 12, 2024
Summary:
Ucache with io_uring is crashing with this stack trace:

```
(lldb) bt
* thread #1, name = 'ucache', stop reason = signal SIGSEGV: address not mapped to object
  * frame #0: 0x0000000000000000
    frame #1: 0x00007f517ba44560 libc.so.6`__restore_rt at libc_sigaction.c:13
    frame #2: 0x000000000a16e249 ucache`folly::AsyncIoUringSocket::ReadSqe::callback(this=0x00007f498c5955e0, cqe=<unavailable>) at AsyncIoUringSocket.cpp:639
    frame #3: 0x000000000964196a ucache`folly::IoUringBackend::getActiveEvents(folly::IoUringBackend::WaitForEventsMode) [inlined] folly::IoSqeBase::internalCallback(this=<unavailable>, cqe=<unavailable>) at IoUringBackend.cpp:0
    frame #4: 0x000000000964195c ucache`folly::IoUringBackend::getActiveEvents(folly::IoUringBackend::WaitForEventsMode) [inlined] folly::IoUringBackend::internalProcessCqe(this=0x00007f4a8f989c00, maxGet=4294967295, mode=NORMAL) at IoUringBackend.cpp:1556
    frame #5: 0x000000000964190f ucache`folly::IoUringBackend::getActiveEvents(this=0x00007f4a8f989c00, waitForEvents=<unavailable>) at IoUringBackend.cpp:1527
    frame #6: 0x0000000009640ac9 ucache`folly::IoUringBackend::eb_event_base_loop(this=0x00007f4a8f989c00, flags=1) at IoUringBackend.cpp:1178
    frame #7: 0x000000001b61547c ucache`folly::EventBase::loopMain(this=0x00007f4a8f97af00, flags=0, options=<unavailable>) at EventBase.cpp:0
    frame #8: 0x000000001bab9a2d ucache`folly::EventBase::loopBody(this=0x00007f4a8f97af00, flags=0, options=(ignoreKeepAlive = false, allowSuspension = false)) at EventBase.cpp:513
    frame #9: 0x000000000a3a6c90 ucache`folly::EventBase::loop(this=<unavailable>) at EventBase.cpp:474
    frame #10: 0x000000000a3a75f7 ucache`folly::EventBase::loopForever(this=<unavailable>) at EventBase.cpp:781
    frame #11: 0x000000000a436907 ucache`folly::IOThreadPoolExecutor::threadRun(this=0x00007f4da3fce1c0, thread=<unavailable>) at IOThreadPoolExecutor.cpp:240
    frame #12: 0x0000000009ed68b8 ucache`void std::__invoke_impl<void, void (folly::ThreadPoolExecutor::*&)(std::shared_ptr<folly::ThreadPoolExecutor::Thread>), folly::ThreadPoolExecutor*&, std::shared_ptr<folly::ThreadPoolExecutor::Thread>&>((null)=<unavailable>, __f=<unavailable>, __t=<unavailable>, __args=<unavailable>) at invoke.h:74
    frame #13: 0x00007f517b6df4e5 libstdc++.so.6`std::execute_native_thread_routine(__p=0x00007f4da01bdbe0) at thread.cc:82:18
    frame #14: 0x00007f517ba9abc9 libc.so.6`start_thread(arg=<unavailable>) at pthread_create.c:434:8
    frame #15: 0x00007f517bb2cf5c libc.so.6`__clone3 at clone3.S:81
```

In frame 2 the offending function is `ReadSqe::callback()`: https://fburl.com/code/4fb46hdq

The problem is that `readCallback_` is null:

```
(lldb) fr v readCallback_
(folly::AsyncReader::ReadCallback *) readCallback_ = nullptr
```

However, `readCallback_` is checked earlier in the the function `ReadSqe::callback()`: https://fburl.com/code/dhnndk29

`AsyncIoUringSocket::readError()` now fails all pending writes and calls `writeErr()`, whose implementation can then close out a socket and call `AsyncIoUringSocket::setReadCB(nullptr)` to change the callback.

Move the call to `AsyncIoUringSocket::readError()` after the call to `readCallback_`.

Reviewed By: dmm-fb

Differential Revision: D60880377

fbshipit-source-id: 42d2f430cd3dc3f4787d0e4c29da7c8ef31ba9a8
facebook-github-bot pushed a commit that referenced this pull request Apr 25, 2025
…hRttiImpl

Summary:
### Overview

I observed failures like:
```
==33555==ERROR: AddressSanitizer: unknown-crash on address 0x800000010516ecee at pc 0x0001062597f4 bp 0x00016b80d470 sp 0x00016b80cc08
READ of size 155 at 0x800000010516ecee thread T0
    #0 0x0001062597f0  (libclang_rt.asan_osx_dynamic.dylib:arm64+0x157f0)
    #1 0x000104f58508 in std::type_info::before[abi:ne180100](std::type_info const&) const+0x8c (core_tests_binary:arm64+0x10096c508)
    #2 0x000104f58418 in std::__1::type_index::operator<[abi:ne180100](std::__1::type_index const&) const+0xa4 (core_tests_binary:arm64+0x10096c418)
    #3 0x000104f57c00 in void* folly::detail::(anonymous namespace)::StaticSingletonManagerWithRttiImpl::create<folly::detail::StaticSingletonManagerWithRtti::Arg>(folly::detail::StaticSingletonManagerWithRtti::Arg&)+0x148 (core_tests_binary:arm64+0x10096bc00)
    #4 0x000104f58110 in void* folly::detail::StaticSingletonManagerWithRtti::create_<true>(folly::detail::StaticSingletonManagerWithRtti::Arg&)+0xc (core_tests_binary:arm64+0x10096c110)
    #5 0x000104fc0b64 in folly::detail::UniqueInstance::enforce(folly::detail::UniqueInstance::Arg&)+0x30c (core_tests_binary:arm64+0x1009d4b64)
    #6 0x000104793064 in __cxx_global_var_init.286+0x34 (core_tests_binary:arm64+0x1001a7064)
    #7 0x00018fc4ac14  (<unknown module>)
    #8 0x00018fc87014  (<unknown module>)
    #9 0x00018fca6ccc  (<unknown module>)
    #10 0x00018fca3abc  (<unknown module>)
    #11 0x00018fca51fc  (<unknown module>)
    #12 0x00018fc86ae4  (<unknown module>)
    #13 0x00018fc4a9cc  (<unknown module>)
    #14 0x00018fc52358  (<unknown module>)
    #15 0x00018fc4b168  (<unknown module>)
    #16 0x00018fc4f8d8  (<unknown module>)
    #17 0x00018fc4b474  (<unknown module>)
    #18 0x00018fc6c284  (<unknown module>)
    #19 0x00018fc2fda8  (<unknown module>)
    #20 0x00018fc2f180  (<unknown module>)
    #21 0x00018fc2eafc  (<unknown module>)

Address 0x800000010516ecee is a wild pointer inside of access range of size 0x00000000009b.
AddressSanitizer: unknown-crash (core_tests_binary:arm64+0x10096c508) in std::type_info::before[abi:ne180100](std::type_info const&) const+0x8c
==33555==ABORTING
```

Looks like the address sanitizer found a memory issue in the implementation of `std::type_info::before`, when I force it to use the more robust type_info comparison algorithm. I couldn't find any references to known problems around this, internally or externally, and unfortunately that's code we can't easily fix.

Instead of relying on the seemingly problematic implementation of `std::type_info::before`, I'm changing the `std::map` to an `std::unordered_map` which instead relies on equality comparison, which is in turn directly controlled by `_LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION`. See discussion in the comments for additional context on this decision.

Reviewed By: yfeldblum

Differential Revision: D73379250

fbshipit-source-id: 257bb77a8b6bb69b364bf4c6edcbdb160c84ca74
meta-codesync Bot pushed a commit that referenced this pull request Aug 27, 2026
Summary:
On by default wherever `svmatch` is available.

`F14Chunk::tagMatchIter` computes the match as an SVE predicate via `svmatch_u8`
and then throws it away, rebuilding the same 4-bit-spaced mask the plain-NEON
path uses so it can hand back a `SparseMaskIter`. On Neoverse V2 the generated
hot path is:

```
match  p1.b, p0/z, z1.b, z0.b     // sets NZCV itself
b.eq   <no-match>                 // svptest_any is free, folds into MATCH flags
mov    z1.b, p1/z, #17            -.
shrn   v1.8b, v1.8h, #4            | five instructions purely to rebuild
fmov   x3, d1                      | the index the predicate already held
rbit   x3, x3                      |
clz    x6, x3                     -'
```

`BRKB` sets the active lanes preceding the first match, so `CNTP` of that is the
index directly. That replaces the five-instruction chain with two, and keeps the
free `b.eq` early-out off MATCH's own flags.

After the optimization, hot path becomes:
```
match   p1.b, p0/z, z1.b, z0.b
b.eq   <no-match>
brkb    p2.b, p0/z, p1.b // -> lanes before first match
cntp    x3,   p0,  p2.b // -> first-match index i
```

`svbool_t` is a sizeless type, so it cannot be a class member or travel back
inside a `std::pair` — a predicate-native `SparseMaskIter` is not expressible.
Instead this adds `F14Chunk::forEachTagMatch`, which inverts the loop so the
predicate stays in a register. Everything except the SVE2 build gets a
`FOLLY_ALWAYS_INLINE` wrapper over the existing `tagMatchIter`, so the other
backends are unchanged. `tagMatchIter` had exactly two callers, `findImpl` and
`findMatching`, and both are rewritten to take a callback.

`FOLLY_F14_SVE_PREDICATE_NATIVE_ACTIVE` is `FOLLY_NEON &&
FOLLY_ARM_FEATURE_NEON_SVE_BRIDGE && FOLLY_ARM_FEATURE_SVE2` — exactly the
condition the `svmatch` `tagMatchIter` this replaces already compiles under — so
it turns on automatically wherever that path exists and is inert everywhere
else. `svmatch` is the only SVE2-only intrinsic in the sequence — `BRKB`,
`BRKA`, `CNTP` and predicate `BIC` are all SVE1 — so SVE2 is the correct gate.
There is no build knob: the two configurations where `FOLLY_ARM_FEATURE_SVE2` is
set but the body still cannot compile — an SVE2 target whose toolchain has no
`arm_neon_sve_bridge.h`, and `__CUDACC__`, where `Portability.h` forces
`FOLLY_NEON` to 0 — keep the generic wrapper because the macro tests those two
terms as well.

== Generated code ==

Full annotated probe loop for `F14ValueMap<K, std::array<uint8_t, 1>>` `Find`,
with `findImpl` inlined, `fbcode//mode/opt`, Grace (Neoverse V2). The two
excerpts above are taken from these. The source being compiled is one iteration
of:

```
ChunkPtr chunk = chunks_ + (index & chunkMask);
if (prefetch == Prefetch::ENABLED && Chunk::kChunkStride > 64)
  prefetchAddr(chunk->itemAddr(8));
ItemIter found{};
if (chunk->forEachTagMatch(needleV, [&](unsigned i) {
      if (FOLLY_LIKELY(this->keyMatchesItem(key, chunk->item(i)))) {
        found = ItemIter{chunk, i}; return true;
      }
      return false;
    })) { return found; }
if (FOLLY_LIKELY(chunk->outboundOverflowCount() == 0)) break;
index += step;
```

=== `uint64_t` key ===

Chunk stride 256 B, item 16 B. `keyMatchesItem` is a `cmp`, so there is no call
in the loop and nothing is ever spilled.

Before, `322d80 .. 322ddc`, 24 instructions:

```
  322d4c:  whilelo p0.b, wzr, w9         ; governing predicate, hoisted
  322d54:  mov x12, #0x7fffffffffffffff  ; mask constant, hoisted
loop:
  322d80:  and x2, x0, x1                ; index & chunkMask
  322d84:  lsl x3, x2, #8                ;   * sizeof(Chunk) = 256
  322d88:  add x2, x18, x3               ; chunk
  322d8c:  prfm pldl1keep, [x2, #144]    ; prefetchAddr(chunk->itemAddr(8))
  322d90:  ld1b {z1.b}, p0/z, [x18, x3]  ; tags_[0..15]
  322d94:  match p1.b, p0/z, z1.b, z0.b  ; svmatch_u8 -- also sets NZCV
  322d98:  b.eq 322dcc                   ; svptest_any() == false (free)
  322d9c:  mov z1.b, p1/z, #17           ; -. 0x11 per matching lane
  322da0:  shrn v1.8b, v1.8h, #4         ;  | narrow to 4 bits/lane
  322da4:  fmov x3, d1                   ;  | predicate -> GPR, the long way
  322da8:  rbit x3, x3                   ;  |
  322dac:  clz x4, x3                    ; -' x4 = first match index * 4
  322db0:  add x5, x2, x4, lsl #2        ; item = chunk + i*16
  322db4:  ldr x6, [x5, #16]             ; keyMatchesItem
  322db8:  cmp x15, x6
  322dbc:  b.eq 322de4                   ; hit -> ItemIter{chunk, i}
  322dc0:  lsr x4, x12, x4               ; SparseMaskIter advance; needs the
  322dc4:  ands x3, x4, x3               ;   hoisted 0x7fff.. constant
  322dc8:  b.ne 322dac                   ; next tag match
  322dcc:  ldrb w2, [x2, #15]            ; outboundOverflowCount()
  322dd0:  cbz w2, 322e44                ; == 0 -> break
  322dd4:  subs x17, x17, #0x1
  322dd8:  add x0, x16, x0               ; index += step
  322ddc:  b.ne 322d80
```

After, `3229c8 .. 322a1c`, 22 instructions:

```
  322998:  whilelo p0.b, wzr, w9         ; governing predicate, hoisted
loop:
  3229c8:  and x1, x18, x0               ; index & chunkMask
  3229cc:  lsl x2, x1, #8                ;   * sizeof(Chunk) = 256
  3229d0:  add x1, x17, x2               ; chunk
  3229d4:  prfm pldl1keep, [x1, #144]    ; prefetchAddr(chunk->itemAddr(8))
  3229d8:  ld1b {z1.b}, p0/z, [x17, x2]  ; tags_[0..15]
  3229dc:  match p1.b, p0/z, z1.b, z0.b  ; svmatch_u8 -- also sets NZCV
  3229e0:  b.eq 322a0c                   ; svptest_any() == false (free)
  3229e4:  brkb p2.b, p0/z, p1.b         ; lanes strictly before first match
  3229e8:  cntp x2, p0, p2.b             ; count them = the index
  3229ec:  ubfiz x2, x2, #4, #32         ;   * 16
  3229f0:  add x2, x1, x2                ; item = chunk + i*16
  3229f4:  ldr x3, [x2, #16]             ; keyMatchesItem
  3229f8:  cmp x14, x3
  3229fc:  b.eq 322a24                   ; hit -> ItemIter{chunk, i}
  322a00:  brka p2.b, p0/z, p1.b         ; lanes up to AND INCLUDING it
  322a04:  bics p1.b, p0/z, p1.b, p2.b   ; clear it; BICS sets the flags
  322a08:  b.ne 3229e4                   ; next tag match
  322a0c:  ldrb w1, [x1, #15]            ; outboundOverflowCount()
  322a10:  cbz w1, 322a84                ; == 0 -> break
  322a14:  subs x16, x16, #0x1
  322a18:  add x18, x15, x18             ; index += step
  322a1c:  b.ne 3229c8
```

`match` to item-address goes 6 -> 4 instructions, and the loop-invariant
`0x7fffffffffffffff` that `SparseMaskIter` needs disappears, freeing a register
across the whole loop.

=== `std::string` key ===

Chunk stride 576 B, item 40 B. Here `keyMatchesItem` is a size compare plus an
out-of-line `bcmp`, and that call is what makes the two arms diverge: under the
base AAPCS64 a normal callee clobbers all of `p0`-`p15`, so any live predicate
has to go to the stack. That is what `addvl sp, sp, #-2` reserves, and what
`str p` / `ldr p` move.

LLVM clones the probe loop here — `cbnz x21, <main loop>` at the foot of the
hash block dispatches on key length, so there is a second, call-free copy for
the empty-key case (30 -> 27 instructions, never executed by this benchmark).
The 48-instruction string-hash block that precedes the loop is byte-identical
between the two arms. Only the main loop is shown.

Before, `3235e0 .. 3236c0`, 57 instructions:

```
  323508:  addvl sp, sp, #-2             ; VL-scaled SVE spill area
  3235ac:  str p1, [x29, #-1, mul vl]    ; governing predicate spilled ONCE
loop:
  3235e0:  and x8, x28, x19
  3235e4:  mul x8, x8, x6                ; * 576
  3235e8:  add x25, x26, x8
  3235ec:  prfm pldl1keep, [x25, #336]   ; prefetchAddr(chunk->itemAddr(8))
  3235f0:  ld1b {z0.b}, p1/z, [x26, x8]  ; tags_[0..15]
  3235f4:  match p0.b, p1/z, z0.b, z1.b  ; svmatch_u8
  3235f8:  b.eq 3236b0                   ; no match
  3235fc:  mov z0.b, p0/z, #17           ; -. rebuild the nibble mask
  323600:  str w23, [sp, #44]
  323604:  str z1, [x29, #-2, mul vl]    ; needle vector spilled
  323608:  stp x12, x10, [sp, #24]
  32360c:  shrn v0.8b, v0.8h, #4         ;  |
  323610:  fmov x8, d0                   ;  |
  323614:  rbit x8, x8                   ;  |
  323618:  str x8, [sp, #56]             ; GPR spill: the reversed mask
  32361c:  clz x8, x8                    ;  -' index * 4
  323620:  mov w9, #0x28
  323624:  str x8, [sp, #48]             ; GPR spill: the index * 4
  323628:  lsr x8, x8, #2
  32362c:  umaddl x24, w8, w9, x25       ; item = chunk + i*40
  323630:  ldr x8, [x24, #24]            ; keyMatchesItem: size first
  323634:  cmp x21, x8
  323638:  b.ne 323690                   ; size mismatch -> next tag match
  32363c:  ldr x1, [x24, #16]
  323640:  mov x0, x22
  323644:  mov x2, x21
  323648:  mov x23, x22                  ; shuffle to keep x30/x22 alive
  32364c:  mov x22, x30                  ;   across the call
  323650:  bl bcmp                       ; CALL
  323654:  mov x3, #0xbfd6
  323658:  mov x1, #0xacc9
  32365c:  ldr p1, [x29, #-1, mul vl]    ; predicate refill
  323660:  movk x3, #0x7d8f, lsl #16
  323664:  movk x1, #0x962e, lsl #16
  323668:  mov x30, x22                  ; undo the shuffle
  32366c:  movk x3, #0x6556, lsl #32
  323670:  movk x1, #0x4b93, lsl #32
  323674:  mov x22, x23
  323678:  mov w6, #0x240
  32367c:  mov x5, #0xffffffffffffffff
  323680:  mov w4, #0x1
  323684:  movk x3, #0x4227, lsl #48
  323688:  movk x1, #0x8bb8, lsl #48
  32368c:  cbz w0, 323898                ; bcmp == 0 -> hit
  323690:  ldp x10, x9, [sp, #48]        ; refill index*4 and mask
  323694:  mov x8, #0x7fffffffffffffff
  323698:  ldr z1, [x29, #-2, mul vl]    ; refill needle
  32369c:  ldr w23, [sp, #44]
  3236a0:  lsr x8, x8, x10
  3236a4:  ldp x12, x10, [sp, #24]
  3236a8:  and x8, x8, x9
  3236ac:  cbnz x8, 323618               ; next tag match
  3236b0:  ldrb w8, [x25, #15]           ; outboundOverflowCount()
  3236b4:  cbz w8, 3238b8                ; == 0 -> break
  3236b8:  subs x12, x12, #0x1
  3236bc:  add x28, x28, x10             ; index += step
  3236c0:  b.ne 3235e0
```

After, `323220 .. 3232d8`, 47 instructions:

```
  323148:  addvl sp, sp, #-2             ; VL-scaled SVE spill area
  3231ec:  str p2, [x29, #-1, mul vl]    ; governing predicate spilled ONCE
loop:
  323220:  and x8, x28, x19
  323224:  mul x8, x8, x6                ; * 576
  323228:  add x27, x26, x8
  32322c:  prfm pldl1keep, [x27, #336]   ; prefetchAddr(chunk->itemAddr(8))
  323230:  ld1b {z0.b}, p2/z, [x26, x8]  ; tags_[0..15]
  323234:  match p1.b, p2/z, z0.b, z1.b  ; svmatch_u8
  323238:  b.eq 3232c8                   ; no match
  32323c:  str w23, [sp, #44]
  323240:  str z1, [x29, #-2, mul vl]    ; needle vector spilled
  323244:  stp x12, x10, [sp, #24]
  323248:  brkb p0.b, p2/z, p1.b         ; lanes before the first match
  32324c:  mov w9, #0x28
  323250:  str p1, [x29, #-2, mul vl]    ; THE NEW SPILL: match predicate
  323254:  cntp x8, p2, p0.b             ; count them = the index
  323258:  umaddl x23, w8, w9, x27       ; item = chunk + i*40
  32325c:  ldr x8, [x23, #24]            ; keyMatchesItem: size first
  323260:  cmp x21, x8
  323264:  b.ne 3232ac                   ; size mismatch -> next tag match
  323268:  ldr x1, [x23, #16]
  32326c:  mov x0, x22
  323270:  mov x2, x21                   ; no x30/x22 shuffle needed
  323274:  bl bcmp                       ; CALL
  323278:  mov x3, #0xbfd6
  32327c:  mov x1, #0xacc9
  323280:  ldr p2, [x29, #-1, mul vl]    ; governing predicate refill
  323284:  movk x3, #0x7d8f, lsl #16
  323288:  movk x1, #0x962e, lsl #16
  32328c:  mov w6, #0x240
  323290:  movk x3, #0x6556, lsl #32
  323294:  movk x1, #0x4b93, lsl #32
  323298:  mov x5, #0xffffffffffffffff
  32329c:  mov w4, #0x1
  3232a0:  movk x3, #0x4227, lsl #48
  3232a4:  movk x1, #0x8bb8, lsl #48
  3232a8:  cbz w0, 32349c                ; bcmp == 0 -> hit
  3232ac:  ldr p1, [x29, #-2, mul vl]    ; match predicate refill
  3232b0:  ldr z1, [x29, #-2, mul vl]    ; needle refill
  3232b4:  ldr w23, [sp, #44]
  3232b8:  ldp x12, x10, [sp, #24]
  3232bc:  brka p0.b, p2/z, p1.b         ; lanes up to AND INCLUDING it
  3232c0:  bics p1.b, p2/z, p1.b, p0.b   ; clear it; BICS sets the flags
  3232c4:  b.ne 323248                   ; next tag match
  3232c8:  ldrb w8, [x27, #15]           ; outboundOverflowCount()
  3232cc:  cbz w8, 3234bc                ; == 0 -> break
  3232d0:  subs x12, x12, #0x1
  3232d4:  add x28, x28, x10             ; index += step
  3232d8:  b.ne 323220
```

The trade is in one place. Before spills two GPRs (`[sp, #56]` the reversed
mask, `[sp, #48]` the index) and refills them with an `ldp`; after spills one
predicate and refills it with one `ldr`. Because the predicate carries the
iteration state directly, the five-instruction mask rebuild, the
`0x7fffffffffffffff` constant, and the four `mov`s shuffling `x22`/`x23`/`x30`
around the call all go away.

`str z1, [x29, #-2, mul vl]` and `str p1, [x29, #-2, mul vl]` read like the
second stomps the first; they do not. `mul vl` scales by VL for Z registers and
by VL/8 for P registers, so at VL=128 the two slots are `x29-32 .. x29-16` and
`x29-4 .. x29-2`.

=== Counts ===

| region | before | after | delta |
| --- | --- | --- | --- |
| `uint64_t` probe loop | 24 | 22 | -2 |
| -- match -> item address | 6 | 4 | -2 |
| -- next-match advance | 3 | 3 | 0 |
| `std::string` probe loop | 57 | 47 | **-10** |
| -- match -> `bl bcmp` | 24 | 17 | -7 |
| -- `bcmp` return -> loop-back | 28 | 25 | -3 |
| `std::string` empty-key clone | 30 | 27 | -3 |

`addvl sp, sp, #-2` is unchanged in both `std::string` arms (same SVE spill
area), while the fixed frame shrinks `0x40` -> `0x30` — exactly the 16 bytes of
GPR mask spills that go away.

For a *second* tag match in the same chunk the new path is 10 instructions
(`brkb` .. `b.ne`) against the old 8 (`clz` .. `b.ne`), because `brkb`+`cntp`
are re-executed where the old code re-entered at `clz`. False tag matches are
~1/255 per key, well below the first-match saving.

Depends on D117044647, which gates the pre-existing `svmatch` sites on SVE2 —
without it an SVE1 target cannot compile this file at all.

Result on Grace (Neoverse V2), `hash_maps_bench` find, ~5-6% faster.

Reviewed By: yfeldblum

Differential Revision: D117005509

fbshipit-source-id: 30f4dda50935e9bde72dab323408560a2c43b064
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants