Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsymbolsresolveutils.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:execute-external-code
4
6
7#include <qdebug.h>
8#include <qloggingcategory.h>
9
11
12Q_STATIC_LOGGING_CATEGORY(qLcSymbolsResolver, "qt.multimedia.symbolsresolver");
13
14bool SymbolsResolver::isLazyLoadEnabled()
15{
16 static const bool lazyLoad =
17 !static_cast<bool>(qEnvironmentVariableIntValue("QT_INSTANT_LOAD_FFMPEG_STUBS"));
18 return lazyLoad;
19}
20
21SymbolsResolver::SymbolsResolver(const char *libLoggingName, LibraryLoader loader)
22 : m_libLoggingName(libLoggingName)
23{
24 Q_ASSERT(libLoggingName);
25 Q_ASSERT(loader);
26
27 auto library = loader();
28 if (library && library->isLoaded())
29 m_library = std::move(library);
30 else
31 qCWarning(qLcSymbolsResolver) << "Couldn't load" << m_libLoggingName << "library";
32}
33
34SymbolsResolver::SymbolsResolver(const char *libName, const char *version,
35 const char *libLoggingName)
36 : m_libLoggingName(libLoggingName ? libLoggingName : libName)
37{
38 Q_ASSERT(libName);
39 Q_ASSERT(version);
40
41 auto library = std::make_unique<QLibrary>(QString::fromLocal8Bit(libName),
42 QString::fromLocal8Bit(version));
43 if (library->load())
44 m_library = std::move(library);
45 else
46 qCWarning(qLcSymbolsResolver) << "Couldn't load" << m_libLoggingName << "library";
47}
48
49SymbolsResolver::~SymbolsResolver()
50{
51 if (m_library)
52 m_library->unload();
53}
54
55QFunctionPointer SymbolsResolver::initOptionalFunction(const char *funcName)
56{
57 return m_library ? m_library->resolve(funcName) : nullptr;
58}
59
60QFunctionPointer SymbolsResolver::initFunction(const char *funcName)
61{
62 QFunctionPointer func = initOptionalFunction(funcName);
63
64 if (!func && m_library)
65 {
66 qCWarning(qLcSymbolsResolver) << "Couldn't resolve" << m_libLoggingName << "symbol" << funcName;
67 m_library->unload();
68 m_library.reset();
69 }
70
71 return func;
72}
73
74void SymbolsResolver::checkLibrariesLoaded(SymbolsMarker *begin, SymbolsMarker *end)
75{
76 if (m_library) {
77 qCDebug(qLcSymbolsResolver) << m_libLoggingName << "symbols resolved";
78 } else {
79 const auto size = reinterpret_cast<char *>(end) - reinterpret_cast<char *>(begin);
80 memset(begin, 0, size);
81 qCWarning(qLcSymbolsResolver) << "Couldn't resolve" << m_libLoggingName << "symbols";
82 }
83}
84
85QT_END_NAMESPACE
Combined button and popup list for selecting options.
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)