genode/repos/libports/src/lib/qt5/patches/qt5_qtbase_genode.patch

381 lines
15 KiB
Diff

qt5_qtbase_genode.patch
From: Christian Prochaska <christian.prochaska@genode-labs.com>
Genode-specific adaptations
---
qtbase/src/corelib/codecs/qtextcodec.cpp | 4 +
qtbase/src/corelib/global/qcompilerdetection.h | 4 +
qtbase/src/corelib/global/qsystemdetection.h | 5 +-
qtbase/src/corelib/global/qversiontagging.cpp | 2 -
qtbase/src/corelib/io/qresource.cpp | 2 -
qtbase/src/corelib/kernel/qcoreapplication.cpp | 2 -
.../src/corelib/kernel/qeventdispatcher_unix.cpp | 7 +++
qtbase/src/corelib/kernel/qtranslator.cpp | 2 -
qtbase/src/corelib/thread/qthread.cpp | 4 +
qtbase/src/corelib/thread/qthread_p.h | 55 ++++++++++++++++++++
qtbase/src/corelib/tools/qdatetime.cpp | 3 +
qtbase/src/gui/image/qxpmhandler.cpp | 8 +++
.../network/access/qnetworkaccessfilebackend.cpp | 5 ++
qtbase/src/network/kernel/qhostinfo.cpp | 5 ++
qtbase/src/network/kernel/qhostinfo_unix.cpp | 7 ++-
qtbase/src/widgets/dialogs/qfiledialog.cpp | 2 -
qtbase/src/widgets/styles/qstylefactory.cpp | 7 +++
17 files changed, 116 insertions(+), 8 deletions(-)
diff --git a/qtbase/src/corelib/codecs/qtextcodec.cpp b/qtbase/src/corelib/codecs/qtextcodec.cpp
index edb03af..1008447 100644
--- a/qtbase/src/corelib/codecs/qtextcodec.cpp
+++ b/qtbase/src/corelib/codecs/qtextcodec.cpp
@@ -204,7 +204,11 @@ static QTextCodec *setupLocaleMapper()
// First part is getting that locale name. First try setlocale() which
// definitely knows it, but since we cannot fully trust it, get ready
// to fall back to environment variables.
+#ifdef Q_OS_GENODE
+ const QByteArray ctype;
+#else
const QByteArray ctype = setlocale(LC_CTYPE, 0);
+#endif /* Q_OS_GENODE */
// Get the first nonempty value from $LC_ALL, $LC_CTYPE, and $LANG
// environment variables.
diff --git a/qtbase/src/corelib/global/qcompilerdetection.h b/qtbase/src/corelib/global/qcompilerdetection.h
index d0eb2af..66364fd 100644
--- a/qtbase/src/corelib/global/qcompilerdetection.h
+++ b/qtbase/src/corelib/global/qcompilerdetection.h
@@ -889,7 +889,9 @@
# define Q_COMPILER_ALIGNAS
# define Q_COMPILER_ALIGNOF
# define Q_COMPILER_INHERITING_CONSTRUCTORS
-# define Q_COMPILER_THREAD_LOCAL
+# ifndef __GENODE__
+# define Q_COMPILER_THREAD_LOCAL
+# endif
# if Q_CC_GNU > 408 || __GNUC_PATCHLEVEL__ >= 1
# define Q_COMPILER_REF_QUALIFIERS
# endif
diff --git a/qtbase/src/corelib/global/qsystemdetection.h b/qtbase/src/corelib/global/qsystemdetection.h
index 1e852ae..99394de 100644
--- a/qtbase/src/corelib/global/qsystemdetection.h
+++ b/qtbase/src/corelib/global/qsystemdetection.h
@@ -47,6 +47,7 @@
/*
The operating system, must be one of: (Q_OS_x)
+ GENODE - Genode
DARWIN - Any Darwin system (OS X, iOS, watchOS, tvOS)
MACOS - macOS
IOS - iOS
@@ -92,7 +93,9 @@
- Q_OS_FREEBSD_KERNEL is always defined on FreeBSD, even if the userland is from GNU
*/
-#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
+#if defined(__GENODE__)
+# define Q_OS_GENODE
+#elif defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
# include <TargetConditionals.h>
# if defined(TARGET_OS_MAC) && TARGET_OS_MAC
# define Q_OS_DARWIN
diff --git a/qtbase/src/corelib/global/qversiontagging.cpp b/qtbase/src/corelib/global/qversiontagging.cpp
index e3d4037..7e57df5 100644
--- a/qtbase/src/corelib/global/qversiontagging.cpp
+++ b/qtbase/src/corelib/global/qversiontagging.cpp
@@ -42,7 +42,7 @@
#define SYM QT_MANGLE_NAMESPACE(qt_version_tag)
//#define SSYM QT_STRINGIFY(SYM)
-#if defined(Q_CC_GNU) && defined(Q_OF_ELF) && !defined(Q_OS_ANDROID)
+#if defined(Q_CC_GNU) && defined(Q_OF_ELF) && !defined(Q_OS_ANDROID) && !defined(Q_OS_GENODE)
# define make_versioned_symbol2(sym, m, n, separator) \
Q_CORE_EXPORT extern const char sym ## _ ## m ## _ ## n = 0; \
asm(".symver " QT_STRINGIFY(sym) "_" QT_STRINGIFY(m) "_" QT_STRINGIFY(n) ", " \
diff --git a/qtbase/src/corelib/io/qresource.cpp b/qtbase/src/corelib/io/qresource.cpp
index 96957ac..ff82f21 100644
--- a/qtbase/src/corelib/io/qresource.cpp
+++ b/qtbase/src/corelib/io/qresource.cpp
@@ -928,7 +928,7 @@ public:
}
};
-#if defined(Q_OS_UNIX) && !defined (Q_OS_NACL) && !defined(Q_OS_INTEGRITY)
+#if defined(Q_OS_UNIX) && !defined (Q_OS_NACL) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_GENODE)
#define QT_USE_MMAP
#endif
diff --git a/qtbase/src/corelib/kernel/qcoreapplication.cpp b/qtbase/src/corelib/kernel/qcoreapplication.cpp
index 2179a0d..71617cc 100644
--- a/qtbase/src/corelib/kernel/qcoreapplication.cpp
+++ b/qtbase/src/corelib/kernel/qcoreapplication.cpp
@@ -575,7 +575,7 @@ void QCoreApplicationPrivate::initLocale()
if (qt_locale_initialized)
return;
qt_locale_initialized = true;
-#if defined(Q_OS_UNIX) && !defined(QT_BOOTSTRAPPED)
+#if defined(Q_OS_UNIX) && !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_GENODE)
setlocale(LC_ALL, "");
#endif
}
diff --git a/qtbase/src/corelib/kernel/qeventdispatcher_unix.cpp b/qtbase/src/corelib/kernel/qeventdispatcher_unix.cpp
index 802962d..be1803c 100644
--- a/qtbase/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/qtbase/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -73,6 +73,11 @@
# include <sys/times.h>
#endif
+#ifdef Q_OS_GENODE
+#include <timer_session/connection.h>
+#define perror Genode::error
+#endif /* Q_OS_GENODE */
+
QT_BEGIN_NAMESPACE
static const char *socketType(QSocketNotifier::Type type)
@@ -200,6 +205,8 @@ int QThreadPipe::check(const pollfd &pfd)
#if defined(Q_OS_VXWORKS)
::read(fds[0], c, sizeof(c));
::ioctl(fds[0], FIOFLUSH, 0);
+#elif defined(Q_OS_GENODE)
+ ::read(fds[0], c, sizeof(c)); // FIXME: the while loop only works in non-blocking mode
#else
# ifndef QT_NO_EVENTFD
if (fds[1] == -1) {
diff --git a/qtbase/src/corelib/kernel/qtranslator.cpp b/qtbase/src/corelib/kernel/qtranslator.cpp
index 2c813b5..3fb323e 100644
--- a/qtbase/src/corelib/kernel/qtranslator.cpp
+++ b/qtbase/src/corelib/kernel/qtranslator.cpp
@@ -57,7 +57,7 @@
#include "qendian.h"
#include "qresource.h"
-#if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_GENODE)
#define QT_USE_MMAP
#include "private/qcore_unix_p.h"
#endif
diff --git a/qtbase/src/corelib/thread/qthread.cpp b/qtbase/src/corelib/thread/qthread.cpp
index 4aac24f..76ba470 100644
--- a/qtbase/src/corelib/thread/qthread.cpp
+++ b/qtbase/src/corelib/thread/qthread.cpp
@@ -149,6 +149,10 @@ QThreadPrivate::QThreadPrivate(QThreadData *d)
exited(false), returnCode(-1),
stackSize(0), priority(QThread::InheritPriority), data(d)
{
+#ifdef Q_OS_GENODE
+ genode_thread = 0;
+#endif /* Q_OS_GENODE */
+
#if defined (Q_OS_WIN)
handle = 0;
# ifndef Q_OS_WINRT
diff --git a/qtbase/src/corelib/thread/qthread_p.h b/qtbase/src/corelib/thread/qthread_p.h
index 37eca9c..a55b27d 100644
--- a/qtbase/src/corelib/thread/qthread_p.h
+++ b/qtbase/src/corelib/thread/qthread_p.h
@@ -53,6 +53,10 @@
//
//
+#ifdef Q_OS_GENODE
+#include <thread_qt.h>
+#endif
+
#include "qplatformdefs.h"
#include "QtCore/qthread.h"
#include "QtCore/qmutex.h"
@@ -176,11 +180,62 @@ public:
static QThread *threadForId(int id);
#ifdef Q_OS_UNIX
+#ifdef Q_OS_GENODE
+
+ class Genode_thread : public Genode::Thread_qt
+ {
+ private:
+
+ /*
+ * The '_finished_lock' is necessary because 'QThreadPrivate::mutex'
+ * uses a 'Genode::Timed_semaphore' internally and it isn't safe
+ * to delete a Genode thread that just called 'Semaphore::up()',
+ * because the 'Semaphore::_meta_lock' could still be locked.
+ */
+ Genode::Lock _finished_lock;
+ QThread *_qthread;
+
+ public:
+
+ Genode_thread(QThread *qthread)
+ : _finished_lock(Genode::Lock::LOCKED),
+ _qthread(qthread) { }
+
+ virtual void entry()
+ {
+ QThreadPrivate::start(_qthread);
+ QThreadPrivate::finish(_qthread);
+ _finished_lock.unlock();
+ }
+
+ void join()
+ {
+ _finished_lock.lock();
+ }
+ };
+
+ Genode_thread *genode_thread;
+
+ struct tls_struct {
+ QThreadData *data;
+ bool termination_enabled;
+ };
+
+ static QHash<Qt::HANDLE, struct tls_struct> tls;
+
+ Qt::HANDLE thread_id;
+ QWaitCondition thread_done;
+
+ static void *start(void *arg);
+ static void finish(void *arg);
+
+#else // Q_OS_UNIX && !Q_OS_GENODE
QWaitCondition thread_done;
static void *start(void *arg);
static void finish(void *);
+#endif // Q_OS_GENODE
#endif // Q_OS_UNIX
#ifdef Q_OS_WIN
diff --git a/qtbase/src/corelib/tools/qdatetime.cpp b/qtbase/src/corelib/tools/qdatetime.cpp
index bfc7e1c..eac18c9 100644
--- a/qtbase/src/corelib/tools/qdatetime.cpp
+++ b/qtbase/src/corelib/tools/qdatetime.cpp
@@ -2170,6 +2170,9 @@ static int qt_timezone()
long offset;
_get_timezone(&offset);
return offset;
+#elif defined(Q_OS_GENODE)
+ /* no timezone support on Genode */
+ return 0;
#elif defined(Q_OS_BSD4) && !defined(Q_OS_DARWIN)
time_t clock = time(NULL);
struct tm t;
diff --git a/qtbase/src/gui/image/qxpmhandler.cpp b/qtbase/src/gui/image/qxpmhandler.cpp
index c8c8f99..714016a 100644
--- a/qtbase/src/gui/image/qxpmhandler.cpp
+++ b/qtbase/src/gui/image/qxpmhandler.cpp
@@ -848,8 +848,16 @@ static bool read_xpm_header(
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
if (sscanf_s(buf, "%d %d %d %d", w, h, ncols, cpp) < 4)
#else
+#ifdef Q_OS_GENODE
+ *w = QString(buf).section(" ", 0, 0, QString::SectionSkipEmpty).toInt();
+ *h = QString(buf).section(" ", 1, 1, QString::SectionSkipEmpty).toInt();
+ *ncols = QString(buf).section(" ", 2, 2, QString::SectionSkipEmpty).toInt();
+ *cpp = QString(buf).section(" ", 3, 3, QString::SectionSkipEmpty).toInt();
+ if (*w <= 0 || *h <= 0 || *ncols <= 0 || *cpp <= 0)
+#else
if (sscanf(buf, "%d %d %d %d", w, h, ncols, cpp) < 4)
#endif
+#endif
return false; // < 4 numbers parsed
return true;
diff --git a/qtbase/src/network/access/qnetworkaccessfilebackend.cpp b/qtbase/src/network/access/qnetworkaccessfilebackend.cpp
index 6043943..291df77 100644
--- a/qtbase/src/network/access/qnetworkaccessfilebackend.cpp
+++ b/qtbase/src/network/access/qnetworkaccessfilebackend.cpp
@@ -124,6 +124,7 @@ void QNetworkAccessFileBackend::open()
url.setPath(QLatin1String("/"));
setUrl(url);
+#ifndef Q_OS_GENODE
QString fileName = url.toLocalFile();
if (fileName.isEmpty()) {
if (url.scheme() == QLatin1String("qrc")) {
@@ -137,6 +138,10 @@ void QNetworkAccessFileBackend::open()
fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
}
}
+#else
+ QString fileName = QLatin1String(":") + url.path();
+#endif
+
file.setFileName(fileName);
if (operation() == QNetworkAccessManager::GetOperation) {
diff --git a/qtbase/src/network/kernel/qhostinfo.cpp b/qtbase/src/network/kernel/qhostinfo.cpp
index 88df65d..cbaca0b 100644
--- a/qtbase/src/network/kernel/qhostinfo.cpp
+++ b/qtbase/src/network/kernel/qhostinfo.cpp
@@ -556,7 +556,12 @@ QHostInfoLookupManager::QHostInfoLookupManager() : mutex(QMutex::Recursive), was
{
moveToThread(QCoreApplicationPrivate::mainThread());
connect(QCoreApplication::instance(), SIGNAL(destroyed()), SLOT(waitForThreadPoolDone()), Qt::DirectConnection);
+#ifdef Q_OS_GENODE
+ /* 'getaddrinfo()' is currently not thread-safe on Genode */
+ threadPool.setMaxThreadCount(1);
+#else
threadPool.setMaxThreadCount(20); // do up to 20 DNS lookups in parallel
+#endif
}
QHostInfoLookupManager::~QHostInfoLookupManager()
diff --git a/qtbase/src/network/kernel/qhostinfo_unix.cpp b/qtbase/src/network/kernel/qhostinfo_unix.cpp
index 7af8db7..1f40ad1 100644
--- a/qtbase/src/network/kernel/qhostinfo_unix.cpp
+++ b/qtbase/src/network/kernel/qhostinfo_unix.cpp
@@ -148,6 +148,11 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
QHostAddress address;
if (address.setAddress(hostName)) {
// Reverse lookup
+#ifdef Q_OS_GENODE
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(tr("Reverse lookup is not implemented because of missing support in lwip."));
+ return results;
+#else
// Reverse lookups using getnameinfo are broken on darwin, use gethostbyaddr instead.
#if !defined (QT_NO_GETADDRINFO) && !defined (Q_OS_DARWIN)
sockaddr_in sa4;
@@ -178,7 +183,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
if (ent)
results.setHostName(QString::fromLatin1(ent->h_name));
#endif
-
+#endif
if (results.hostName().isEmpty())
results.setHostName(address.toString());
results.setAddresses(QList<QHostAddress>() << address);
diff --git a/qtbase/src/widgets/dialogs/qfiledialog.cpp b/qtbase/src/widgets/dialogs/qfiledialog.cpp
index fc360d8..6b0fd42 100644
--- a/qtbase/src/widgets/dialogs/qfiledialog.cpp
+++ b/qtbase/src/widgets/dialogs/qfiledialog.cpp
@@ -1111,7 +1111,7 @@ Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path)
const QString homePath = QDir::homePath();
#else
const QByteArray userName = path.midRef(1, separatorPosition - 1).toLocal8Bit();
-# if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD)
+# if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) && !defined(Q_OS_GENODE)
passwd pw;
passwd *tmpPw;
char buf[200];
diff --git a/qtbase/src/widgets/styles/qstylefactory.cpp b/qtbase/src/widgets/styles/qstylefactory.cpp
index bebd322..d0e2ebb 100644
--- a/qtbase/src/widgets/styles/qstylefactory.cpp
+++ b/qtbase/src/widgets/styles/qstylefactory.cpp
@@ -176,6 +176,13 @@ QStringList QStyleFactory::keys()
const PluginKeyMap::const_iterator cend = keyMap.constEnd();
for (PluginKeyMap::const_iterator it = keyMap.constBegin(); it != cend; ++it)
list.append(it.value());
+#ifdef Q_OS_GENODE
+/* on Genode, the first style in the list gets selected by default and we want the "Fusion" style */
+#ifndef QT_NO_STYLE_FUSION
+ if (!list.contains(QLatin1String("Fusion")))
+ list << QLatin1String("Fusion");
+#endif
+#endif
#ifndef QT_NO_STYLE_WINDOWS
if (!list.contains(QLatin1String("Windows")))
list << QLatin1String("Windows");