Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 08:27:29

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QSHAREDMEMORY_H
0006 #define QSHAREDMEMORY_H
0007 
0008 #include <QtCore/qtipccommon.h>
0009 #ifndef QT_NO_QOBJECT
0010 # include <QtCore/qobject.h>
0011 #else
0012 # include <QtCore/qobjectdefs.h>
0013 # include <QtCore/qscopedpointer.h>
0014 # include <QtCore/qstring.h>
0015 #endif
0016 
0017 QT_BEGIN_NAMESPACE
0018 
0019 #if QT_CONFIG(sharedmemory)
0020 
0021 class QSharedMemoryPrivate;
0022 
0023 class Q_CORE_EXPORT QSharedMemory : public QObject
0024 {
0025     Q_OBJECT
0026     Q_DECLARE_PRIVATE(QSharedMemory)
0027 
0028 public:
0029     enum AccessMode
0030     {
0031         ReadOnly,
0032         ReadWrite
0033     };
0034     Q_ENUM(AccessMode)
0035 
0036     enum SharedMemoryError
0037     {
0038         NoError,
0039         PermissionDenied,
0040         InvalidSize,
0041         KeyError,
0042         AlreadyExists,
0043         NotFound,
0044         LockError,
0045         OutOfResources,
0046         UnknownError
0047     };
0048     Q_ENUM(SharedMemoryError)
0049 
0050     QSharedMemory(QObject *parent = nullptr);
0051     QSharedMemory(const QNativeIpcKey &key, QObject *parent = nullptr);
0052     ~QSharedMemory();
0053 
0054     QSharedMemory(const QString &key, QObject *parent = nullptr);
0055     void setKey(const QString &key);
0056     QString key() const;
0057 
0058     void setNativeKey(const QNativeIpcKey &key);
0059     void setNativeKey(const QString &key, QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs())
0060     { setNativeKey({ key, type }); }
0061     QString nativeKey() const;
0062     QNativeIpcKey nativeIpcKey() const;
0063 #if QT_CORE_REMOVED_SINCE(6, 5)
0064     void setNativeKey(const QString &key);
0065 #endif
0066 
0067     bool create(qsizetype size, AccessMode mode = ReadWrite);
0068     qsizetype size() const;
0069 
0070     bool attach(AccessMode mode = ReadWrite);
0071     bool isAttached() const;
0072     bool detach();
0073 
0074     void *data();
0075     const void* constData() const;
0076     const void *data() const;
0077 
0078 #if QT_CONFIG(systemsemaphore)
0079     bool lock();
0080     bool unlock();
0081 #endif
0082 
0083     SharedMemoryError error() const;
0084     QString errorString() const;
0085 
0086     static bool isKeyTypeSupported(QNativeIpcKey::Type type) Q_DECL_CONST_FUNCTION;
0087     static QNativeIpcKey platformSafeKey(const QString &key,
0088             QNativeIpcKey::Type type = QNativeIpcKey::DefaultTypeForOs);
0089     static QNativeIpcKey legacyNativeKey(const QString &key,
0090             QNativeIpcKey::Type type = QNativeIpcKey::legacyDefaultTypeForOs());
0091 
0092 private:
0093     Q_DISABLE_COPY(QSharedMemory)
0094 };
0095 
0096 #endif // QT_CONFIG(sharedmemory)
0097 
0098 QT_END_NAMESPACE
0099 
0100 #endif // QSHAREDMEMORY_H