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
qlibrary_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2021 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QLIBRARY_P_H
7#define QLIBRARY_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists for the convenience
14// of the QLibrary class. This header file may change from
15// version to version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include "QtCore/qlibrary.h"
21
22#include "QtCore/private/qplugin_p.h"
23#include "QtCore/qloggingcategory.h"
24#include "QtCore/qmutex.h"
25#include "QtCore/qplugin.h"
26#include "QtCore/qpointer.h"
27#include "QtCore/qstringlist.h"
28#ifdef Q_OS_WIN
29# include "QtCore/qt_windows.h"
30#endif
31
32#include <memory>
33
35
37
39
41{
44#if defined(Q_OF_MACH_O)
45 bool isEncrypted = false;
46#endif
47};
48
49class QLibraryStore;
51{
52public:
53#ifdef Q_OS_WIN
54 using Handle = HINSTANCE;
55#else
56 using Handle = void *;
57#endif
59
60 struct Deleter {
61 // QLibraryPrivate::release() is not, yet, and cannot easily be made, noexcept:
62 void operator()(QLibraryPrivate *p) const { p->release(); }
63 };
64 using UniquePtr = std::unique_ptr<QLibraryPrivate, Deleter>;
65
68
69 bool load();
70 QtPluginInstanceFunction loadPlugin(); // loads and resolves instance
72 void release();
73 QFunctionPointer resolve(const char *);
74
76 { return QLibrary::LoadHints(loadHintsInt.loadRelaxed()); }
77 void setLoadHints(QLibrary::LoadHints lh);
79
80 static QLibraryPrivate *findOrCreate(const QString &fileName, const QString &version = QString(),
81 QLibrary::LoadHints loadHints = { });
82 static QStringList suffixes_sys(const QString &fullVersion);
83 static constexpr QStringView prefix_sys()
84 {
85#ifdef Q_OS_WIN
86 return {};
87#elif defined(Q_OS_CYGWIN)
88 return u"cyg";
89#else
90 return u"lib";
91#endif
92 }
93
96
97 // the mutex protects the fields below
99 QPointer<QObject> inst; // used by QFactoryLoader
103
104 void updatePluginState();
105 bool isPlugin();
106
107 static QLibraryPrivate* get(QLibrary* lib)
108 {
109 return lib->d.data();
110 }
111
112private:
113 explicit QLibraryPrivate(const QString &canonicalFileName, const QString &version, QLibrary::LoadHints loadHints);
114 ~QLibraryPrivate();
115 void mergeLoadHints(QLibrary::LoadHints loadHints);
116
117 bool load_sys();
118 bool unload_sys();
119 QFunctionPointer resolve_sys(const char *);
120
121 QAtomicInt loadHintsInt;
122
123 /// counts how many QLibrary or QPluginLoader are attached to us, plus 1 if it's loaded
124 QAtomicInt libraryRefCount;
125 /// counts how many times load() or loadPlugin() were called
126 QAtomicInt libraryUnloadCount;
127
128 enum { IsAPlugin, IsNotAPlugin, MightBeAPlugin } pluginState;
129 friend class QLibraryStore;
130};
131
132QT_END_NAMESPACE
133
134#endif // QLIBRARY_P_H
QString errorString
Definition qlibrary_p.h:101
Q_AUTOTEST_EXPORT bool unload(UnloadFlag flag=UnloadSys)
Definition qlibrary.cpp:556
QString qualifiedFileName
Definition qlibrary_p.h:102
QtPluginInstanceFunction loadPlugin()
Definition qlibrary.cpp:583
QAtomicPointer< std::remove_pointer< Handle >::type > pHnd
Definition qlibrary_p.h:95
static constexpr QStringView prefix_sys()
Definition qlibrary_p.h:83
static QStringList suffixes_sys(const QString &fullVersion)
void setLoadHints(QLibrary::LoadHints lh)
Definition qlibrary.cpp:487
const QString fileName
Definition qlibrary_p.h:66
const QString fullVersion
Definition qlibrary_p.h:67
void updatePluginState()
Definition qlibrary.cpp:724
QAtomicPointer< std::remove_pointer< QtPluginInstanceFunction >::type > instanceFactory
Definition qlibrary_p.h:94
QPluginParsedMetaData metaData
Definition qlibrary_p.h:100
QFunctionPointer resolve(const char *)
Definition qlibrary.cpp:480
QPointer< QObject > inst
Definition qlibrary_p.h:99
std::unique_ptr< QLibraryPrivate, Deleter > UniquePtr
Definition qlibrary_p.h:64
QObject * pluginInstance()
Definition qlibrary.cpp:501
static QLibraryPrivate * findOrCreate(const QString &fileName, const QString &version=QString(), QLibrary::LoadHints loadHints={ })
Definition qlibrary.cpp:461
static QLibraryPrivate * get(QLibrary *lib)
Definition qlibrary_p.h:107
QLibrary::LoadHints loadHints() const
Definition qlibrary_p.h:75
static QT_WARNING_PUSH const WORD ExpectedMachine
static QLatin1StringView findSectionName(const IMAGE_SECTION_HEADER *section, QByteArrayView stringTable)
static constexpr auto metadataSectionName() noexcept
#define peDebug
static constexpr bool IncludeValidityChecks
static std::optional< QByteArrayView > findStringTable(QByteArrayView data, const IMAGE_NT_HEADERS *ntHeader, const ErrorMaker &error)
static constexpr QLatin1StringView truncatedSectionName
static const WORD ExpectedOptionalHeaderSignature
static const IMAGE_SECTION_HEADER * findSectionTable(QByteArrayView data, const IMAGE_NT_HEADERS *ntHeader, const ErrorMaker &error)
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcQIORing)
QT_REQUIRE_CONFIG(library)
void operator()(QLibraryPrivate *p) const
Definition qlibrary_p.h:62