office-gobmx/stoc
Stephan Bergmann 04a8f3a42c Destruction of Registry and RegitsryKey isn't MT-safe
...as the underlying ORegistry and ORegKey modify their ref counts outside any
locked mutexes.  For example, <https://ci.libreoffice.org/job/lo_ubsan/2572/>
had failed during CustomTarget_odk/build-examples_java with

> ==402==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d00035d920 at pc 0x7f379ce963d9 bp 0x7ffe74b1ac60 sp 0x7ffe74b1ac58
> READ of size 4 at 0x60d00035d920 thread T0
>     #0 0x7f379ce963d8 in ORegistry::acquire() /registry/source/regimpl.hxx:49:18
>     #1 0x7f379ce947a3 in acquire(void*) /registry/source/registry.cxx:38:15
>     #2 0x7f375ee9287e in Registry::operator=(Registry const&) /include/registry/registry.hxx:961:9
>     #3 0x7f375ee92654 in RegistryKey::setRegistry(Registry const&) /include/registry/registry.hxx:647:20
>     #4 0x7f375ee91d66 in Registry::openRootKey(RegistryKey&) /include/registry/registry.hxx:979:18
>     #5 0x7f375ee725da in (anonymous namespace)::SimpleRegistry::getRootKey() /stoc/source/simpleregistry/simpleregistry.cxx:889:30
>     #6 0x7f375ee73a56 in non-virtual thunk to (anonymous namespace)::SimpleRegistry::getRootKey() /stoc/source/simpleregistry/simpleregistry.cxx
>     #7 0x7f37828e142c in gcc3::callVirtualMethod(void*, unsigned int, void*, _typelib_TypeDescriptionReference*, bool, unsigned long*, unsigned int, unsigned long*, double*) /bridges/source/cpp_uno/gcc3_linux_x86-64/callvirtualmethod.cxx:77:5
>     #8 0x7f37828db812 in cpp_call(bridges::cpp_uno::shared::UnoInterfaceProxy*, bridges::cpp_uno::shared::VtableSlot, _typelib_TypeDescriptionReference*, int, _typelib_MethodParameter*, void*, void**, _uno_Any**) /bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx:233:13
>     #9 0x7f37828d8668 in unoInterfaceProxyDispatch /bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx:413:13
>     #10 0x7f375cfebc05 in binaryurp::IncomingRequest::execute_throw(binaryurp::BinaryAny*, std::__debug::vector<binaryurp::BinaryAny, std::allocator<binaryurp::BinaryAny> >*) const /binaryurp/source/incomingrequest.cxx:236:13
>     #11 0x7f375cfe5a46 in binaryurp::IncomingRequest::execute() const /binaryurp/source/incomingrequest.cxx:79:26
>     #12 0x7f375d0ae662 in request /binaryurp/source/reader.cxx:86:9
>     #13 0x7f37b5cf5a2b in cppu_threadpool::JobQueue::enter(void const*, bool) /cppu/source/threadpool/jobqueue.cxx💯17
>     #14 0x7f37b5d44637 in cppu_threadpool::ThreadPool::enter(rtl::ByteSequence const&, void const*) /cppu/source/threadpool/threadpool.cxx:304:33
>     #15 0x7f37b5d468d4 in uno_threadpool_enter /cppu/source/threadpool/threadpool.cxx:408:33
>     #16 0x7f375cf144fa in binaryurp::Bridge::makeCall(rtl::OUString const&, com::sun::uno::TypeDescription const&, bool, std::__debug::vector<binaryurp::BinaryAny, std::allocator<binaryurp::BinaryAny> >&&, binaryurp::BinaryAny*, std::__debug::vector<binaryurp::BinaryAny, std::allocator<binaryurp::BinaryAny> >*) /binaryurp/source/bridge.cxx:606:9
>     #17 0x7f375d0aa130 in binaryurp::Proxy::do_dispatch_throw(_typelib_TypeDescription const*, void*, void**, _uno_Any**) const /binaryurp/source/proxy.cxx:169:18
>     #18 0x7f375d0a82f4 in binaryurp::Proxy::do_dispatch(_typelib_TypeDescription const*, void*, void**, _uno_Any**) const /binaryurp/source/proxy.cxx:102:13
>     #19 0x7f375d0a80cf in proxy_dispatchInterface /binaryurp/source/proxy.cxx:61:36
>     #20 0x7f3782881fff in cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy*, _typelib_TypeDescription const*, _typelib_TypeDescriptionReference*, int, _typelib_MethodParameter*, void**, void**, void**, unsigned long*) /bridges/source/cpp_uno/gcc3_linux_x86-64/cpp2uno.cxx:191:5
>     #21 0x7f378287ef40 in cpp_vtable_call /bridges/source/cpp_uno/gcc3_linux_x86-64/cpp2uno.cxx:389:28
>     #22 0x7f378292d60d in privateSnippetExecutor (/instdir/program/libgcc3_uno.so+0x13960d)
>     #23 0x7f3774fd11c7 in dp_registry::backend::component::(anonymous namespace)::BackendImpl::ComponentPackageImpl::processPackage_(osl::ResettableGuard<osl::Mutex>&, bool, bool, rtl::Reference<dp_misc::AbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/registry/component/dp_component.cxx:1376:17
>     #24 0x7f37750f1c11 in dp_registry::backend::Package::processPackage_impl(bool, bool, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/registry/dp_backend.cxx:631:17
>     #25 0x7f37750f3f4b in dp_registry::backend::Package::registerPackage(unsigned char, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/registry/dp_backend.cxx:688:5
>     #26 0x7f3775206b47 in dp_registry::backend::bundle::(anonymous namespace)::BackendImpl::PackageImpl::processPackage_(osl::ResettableGuard<osl::Mutex>&, bool, bool, rtl::Reference<dp_misc::AbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/registry/package/dp_package.cxx:805:27
>     #27 0x7f37750f1c11 in dp_registry::backend::Package::processPackage_impl(bool, bool, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/registry/dp_backend.cxx:631:17
>     #28 0x7f37750f3f4b in dp_registry::backend::Package::registerPackage(unsigned char, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/registry/dp_backend.cxx:688:5
>     #29 0x7f3774e55b17 in dp_manager::ExtensionManager::activateExtension(com::sun::uno::Sequence<com::sun::uno::Reference<com::sun::deployment::XPackage> > const&, bool, bool, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/manager/dp_extensionmanager.cxx:473:23
>     #30 0x7f3774e54ab4 in dp_manager::ExtensionManager::activateExtension(rtl::OUString const&, rtl::OUString const&, bool, bool, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/manager/dp_extensionmanager.cxx:423:5
>     #31 0x7f3774e5fa40 in dp_manager::ExtensionManager::addExtension(rtl::OUString const&, com::sun::uno::Sequence<com::sun:🫘:NamedValue> const&, rtl::OUString const&, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/manager/dp_extensionmanager.cxx:723:21
>     #32 0x7f3774e62b64 in non-virtual thunk to dp_manager::ExtensionManager::addExtension(rtl::OUString const&, com::sun::uno::Sequence<com::sun:🫘:NamedValue> const&, rtl::OUString const&, com::sun::uno::Reference<com::sun::task::XAbortChannel> const&, com::sun::uno::Reference<com::sun::ucb::XCommandEnvironment> const&) /desktop/source/deployment/manager/dp_extensionmanager.cxx
>     #33 0x7f37ba706dcf in unopkg_main /desktop/source/pkgchk/unopkg/unopkg_app.cxx:429:40
>     #34 0x501298 in sal_main /desktop/source/pkgchk/unopkg/unopkg_main.c:24:31
>     #35 0x501276 in main /desktop/source/pkgchk/unopkg/unopkg_main.c:24:1
>
> 0x60d00035d920 is located 0 bytes inside of 136-byte region [0x60d00035d920,0x60d00035d9a8)
> freed by thread T6 (cppu_threadpool) here:
>     #0 0x4fe928 in operator delete(void*, unsigned long) /home/tdf/lode/packages/llvm-llvmorg-12.0.1.src/compiler-rt/lib/asan/asan_new_delete.cpp:172
>     #1 0x7f379ce94875 in release(void*) /registry/source/registry.cxx:47:9
>     #2 0x7f375ee8e6b5 in Registry::~Registry() /include/registry/registry.hxx:955:13
>     #3 0x7f375ee92582 in RegistryKey::~RegistryKey() /include/registry/registry.hxx:655:5
>     #4 0x7f375ee744e6 in (anonymous namespace)::Key::~Key() /stoc/source/simpleregistry/simpleregistry.cxx:101:7
>     #5 0x7f375ee74558 in (anonymous namespace)::Key::~Key() /stoc/source/simpleregistry/simpleregistry.cxx:101:7
>     #6 0x7f37b53a682a in cppu::OWeakObject::release() /cppuhelper/source/weak.cxx:230:9
>     #7 0x7f375ec5c009 in cppu::WeakImplHelper<com::sun::registry::XRegistryKey>::release() /include/cppuhelper/implbase.hxx:115:66
>     #8 0x7f37828f0054 in freeUnoInterfaceProxy /bridges/source/cpp_uno/shared/unointerfaceproxy.cxx:42:19
>     #9 0x7f37b5ee924d in (anonymous namespace)::s_stub_defenv_revokeInterface(__va_list_tag (*) [1]) /cppu/source/uno/lbenv.cxx:372:17
>     #10 0x7f37b5e8fcbc in s_environment_invoke_v(_uno_Environment*, _uno_Environment*, void (*)(__va_list_tag (*) [1]), __va_list_tag (*) [1]) /cppu/source/uno/EnvStack.cxx:293:9
>     #11 0x7f37b5e8fa04 in uno_Environment_invoke_v /cppu/source/uno/EnvStack.cxx:312:5
>     #12 0x7f37b5e9016a in uno_Environment_invoke /cppu/source/uno/EnvStack.cxx:321:5
>     #13 0x7f37b5ec2dc5 in (anonymous namespace)::defenv_revokeInterface(_uno_ExtEnvironment*, void*) /cppu/source/uno/lbenv.cxx:426:5
>     #14 0x7f37828f0f08 in releaseProxy /bridges/source/cpp_uno/shared/unointerfaceproxy.cxx:78:9
>     #15 0x7f375cf305c5 in com::sun::uno::UnoInterfaceReference::~UnoInterfaceReference() /include/uno/dispatcher.hxx:107:9
>     #16 0x7f375cf0f387 in binaryurp::Bridge::releaseStub(rtl::OUString const&, com::sun::uno::TypeDescription const&) /binaryurp/source/bridge.cxx:514:1
>     #17 0x7f375cfe8b9b in binaryurp::IncomingRequest::execute_throw(binaryurp::BinaryAny*, std::__debug::vector<binaryurp::BinaryAny, std::allocator<binaryurp::BinaryAny> >*) const /binaryurp/source/incomingrequest.cxx:138:18
>     #18 0x7f375cfe5a46 in binaryurp::IncomingRequest::execute() const /binaryurp/source/incomingrequest.cxx:79:26
>     #19 0x7f375d0ae662 in request /binaryurp/source/reader.cxx:86:9
>     #20 0x7f37b5cf5a2b in cppu_threadpool::JobQueue::enter(void const*, bool) /cppu/source/threadpool/jobqueue.cxx💯17
>     #21 0x7f37b5d161c4 in cppu_threadpool::ORequestThread::run() /cppu/source/threadpool/thread.cxx:165:31
>     #22 0x7f37b5d20fc4 in threadFunc /include/osl/thread.hxx:189:15
>     #23 0x7f37bb9d9f0f in osl_thread_start_Impl(void*) /sal/osl/unx/thread.cxx:265:9
>     #24 0x7f37b9e35ea4 in start_thread /usr/src/debug/glibc-2.17-c758a686/nptl/pthread_create.c:307

The SimpleRegistry UNO implementation appears to be the only one of the few
remaining uses of the legacy registry functionality that suffers from this
issue, so address things there and keep the registry functionality itself non-
MT-safe.

Change-Id: I5a87f1c66d838603672f6dfd19e6d1b617fbe691
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142713
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-11-14 18:19:24 +01:00
..
source Destruction of Registry and RegitsryKey isn't MT-safe 2022-11-14 18:19:24 +01:00
test tdf#145759 Use symbolic constants instead of magic numerical constants 2022-10-25 08:12:26 +02:00
util
CppunitTest_stoc_uriproc.mk
IwyuFilter_stoc.yaml tdf#42949 Fix new IWYU warnings in directories s* 2020-12-01 14:56:43 +01:00
Library_bootstrap.mk URE Library_boostrap should not depend on Library_comphelper 2022-05-09 17:58:29 +02:00
Library_introspection.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Library_invocadapt.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Library_invocation.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Library_javaloader.mk Don't use Library_tl in URE libraries 2022-02-25 08:20:55 +01:00
Library_javavm.mk Don't use Library_tl in URE libraries 2022-02-25 08:20:55 +01:00
Library_namingservice.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Library_proxyfac.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Library_reflection.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Library_stocservices.mk Generally determine Rdb content from gb_*_set_componentfile calls 2021-12-10 08:14:24 +01:00
Makefile
Module_stoc.mk
README.md
unosdk.mk

Registries, Reflection, Introspection Implementation for UNO

The UNO types and services bootstrapping code is very old, and concepts are tightly knit together. Whenever you want to change something you risk backwards incompatibility. The code causes mental pain, and whenever you need to touch it you want to run away screaming. One typically ends up doing minimally invasive changes. That way, you have a chance of surviving the process. But you also pile up guilt.

At the heart of the matter there is the old binary "store" file structure and the XRegistry interface on top of it. At runtime, both all the UNO type information (scattered across a number of binary .rdb files) and all the UNO service information (scattered across a number of .rdb files that used to be binary but have been mostly changed to XML now) are represented by a single XRegistry instance each.

The way the respective information is represented in the XRegistry interface simply corresponds to the way the information is stored in the binary .rdb files. Those files are designed for storage of hierarchically nested small blobs of information. Hence, for example information about a UNO interface type com.sun.star.foo.XBar is stored in a nested "folder" with path com - sun - star - foo - XBar, containing little blobs of information about the type's ancestors, its methods, etc. Similarly for information about instantiable services like com.sun.star.baz.Boz.

As there are typically multiple .rdb files containing types resp. services (URE specific, LO specific, from extensions, ...), but they need to be represented by a single XRegistry instance, so "nested registries" were invented. They effectively form a linear list of chaining XRegistry instances together. Whenever a path needs to be looked up in the top-level registry, it effectively searches through the linear list of nested registries. All with the cumbersome UNO XRegistry interface between the individual parts. Horror.

When the XML service .rdbs were introduced, we chickened out (see above for rationale) and put them behind an XRegistry facade, so that they would seamlessly integrate with the existing mess. We postponed systematic clean-up to the pie-in-the-sky days of LibreOffice 4 (or, "once we'll become incompatible with OpenOffice.org," as the phrase used to be back then)