summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qsystemdetection.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp5
-rw-r--r--src/corelib/kernel/qfunctions_nacl.cpp13
-rw-r--r--src/corelib/kernel/qfunctions_nacl.h4
-rw-r--r--src/corelib/plugin/qlibrary.cpp2
-rw-r--r--src/corelib/plugin/qplugin.h16
-rw-r--r--src/corelib/thread/qmutex.cpp6
-rw-r--r--src/corelib/thread/qmutex_unix.cpp4
-rw-r--r--src/corelib/thread/qwaitcondition_unix.cpp17
-rw-r--r--src/corelib/tools/qsimd.cpp4
10 files changed, 59 insertions, 14 deletions
diff --git a/src/corelib/global/qsystemdetection.h b/src/corelib/global/qsystemdetection.h
index 250f186926..74c734e245 100644
--- a/src/corelib/global/qsystemdetection.h
+++ b/src/corelib/global/qsystemdetection.h
@@ -330,7 +330,9 @@
# define Q_OS_PNACL
#endif
#ifdef __EMSCRIPTEN__
+# ifndef Q_OS_NACL_EMSCRIPTEN
# define Q_OS_NACL_EMSCRIPTEN
+# endif
#endif
#endif
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index 58164dba47..60b46a35f5 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -190,12 +190,15 @@ int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags,
int wakeUpFd = initThreadWakeUp();
highest = qMax(highest, wakeUpFd);
#endif
-
+#ifdef Q_OS_NACL_EMSCRIPTEN
+ nsel = 0;
+#else
nsel = q->select(highest + 1,
&sn_vec[0].select_fds,
&sn_vec[1].select_fds,
&sn_vec[2].select_fds,
timeout);
+#endif
} while (nsel == -1 && (errno == EINTR || errno == EAGAIN));
if (nsel == -1) {
diff --git a/src/corelib/kernel/qfunctions_nacl.cpp b/src/corelib/kernel/qfunctions_nacl.cpp
index 5234452581..1c66ea5b23 100644
--- a/src/corelib/kernel/qfunctions_nacl.cpp
+++ b/src/corelib/kernel/qfunctions_nacl.cpp
@@ -82,7 +82,6 @@ void pthread_testcancel(void)
}
-
int pthread_cancel(pthread_t)
{
return 0;
@@ -140,10 +139,12 @@ int sigaction(int, const struct sigaction *, struct sigaction *)
return 0;
}
+#ifndef Q_OS_NACL_EMSCRIPTEN
int open(const char *, int, ...)
{
return 0;
}
+#endif
int open64(const char *, int, ...)
{
@@ -155,12 +156,12 @@ long pathconf(const char *, int)
return 0;
}
+#ifndef Q_OS_NACL_EMSCRIPTEN
int access(const char *, int)
{
return 0;
}
-#ifndef Q_OS_NACL_EMSCRIPTEN
typedef long off64_t;
off64_t ftello64(void *)
{
@@ -197,8 +198,6 @@ int unsetenv(const char *name)
}
#endif
-} // Extern C
-
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
{
return 0;
@@ -209,10 +208,9 @@ int pselect(int nfds, fd_set * readfds, fd_set * writefds, fd_set * errorfds, co
return 0;
}
-#ifdef Q_OS_NACL_EMSCRIPTEN
-
-// pthread stubs (no thrading support in emscripten)
+} // Extern C
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(__EMSCRIPTEN_PTHREADS__)
int pthread_setcancelstate(int state, int *oldstate)
{
return 0;
@@ -332,7 +330,6 @@ int sched_get_priority_min(int policy)
{
return 0;
}
-
#endif
// Several Qt components (such at the QtCore event dispatcher and networking)
diff --git a/src/corelib/kernel/qfunctions_nacl.h b/src/corelib/kernel/qfunctions_nacl.h
index 34e0efda1d..915f9c4220 100644
--- a/src/corelib/kernel/qfunctions_nacl.h
+++ b/src/corelib/kernel/qfunctions_nacl.h
@@ -128,11 +128,11 @@ int setenv(const char *name, const char *value, int overwrite) __attribute__((we
int unsetenv(const char *name) __attribute__((weak));
#endif
-}
-
int select(int nfds, fd_set * readfds, fd_set * writefds, fd_set * errorfds, struct timeval * timeout) __attribute__((weak));
int pselect(int nfds, fd_set * readfds, fd_set * writefds, fd_set * errorfds, const struct timespec * timeout, const sigset_t * sigmask) __attribute__((weak));
+}
+
QT_END_NAMESPACE
#endif //Q_OS_NACL
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 2df48cff34..0d0a97f82e 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -712,7 +712,7 @@ void QLibraryPrivate::updatePluginState()
}
#endif
-#if !defined (Q_OS_NACL)
+#if !defined (Q_OS_NACL) || defined (Q_OS_NACL_EMSCRIPTEN)
if (!pHnd) {
// scan for the plugin metadata without loading
success = findPatternUnloaded(fileName, this);
diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h
index 9b3725a718..9af1629a13 100644
--- a/src/corelib/plugin/qplugin.h
+++ b/src/corelib/plugin/qplugin.h
@@ -40,7 +40,6 @@
QT_BEGIN_NAMESPACE
-
#ifndef Q_EXTERN_C
# ifdef __cplusplus
# define Q_EXTERN_C extern "C"
@@ -71,7 +70,20 @@ Q_DECLARE_TYPEINFO(QStaticPlugin, Q_PRIMITIVE_TYPE);
void Q_CORE_EXPORT qRegisterStaticPluginFunction(QStaticPlugin staticPlugin);
-#ifdef Q_OS_PNACL
+#if defined(Q_OS_NACL_EMSCRIPTEN)
+// It is important that the metadata is aligned in Emscripten because we are
+// not allowed to read unaligned data in JS/Emscripten.
+// Without this, importing static plugins will randomly fail because reading
+// the offset 'size' value in QLibraryPrivate::fromRawMetaData is undefined behavior.
+// For this purpose, aligning to 32 bits would suffice.
+// Using 64 bits is probably overkill, but should ensure that this problem doesn't
+// surface in other parts of the code.
+
+// TODO Do we need "section" and "used" attributes on Emscripten?
+// TODO Should we reduce alignment to 32 bits?
+# define QT_PLUGIN_METADATA_SECTION \
+ __attribute__ ((section (".qtmetadata"))) __attribute__((used)) __attribute__((aligned(64)))
+#elif defined(Q_OS_PNACL)
// PNaCl does not support "section":
// "Variable _ZL17qt_pluginMetaData has disallowed "section" attribute"
// PNaCl is Q_CC_CLANG. TODO: should it not set Q_OF_ELF?
diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp
index 14dc72a1f5..6e93e3b0d7 100644
--- a/src/corelib/thread/qmutex.cpp
+++ b/src/corelib/thread/qmutex.cpp
@@ -271,6 +271,12 @@ bool QMutex::tryLock(int timeout) QT_MUTEX_LOCK_NOEXCEPT
*/
void QMutex::unlock() Q_DECL_NOTHROW
{
+ // TODO replace this with using pthread stubs instead
+ // Note: Defining QT_NO_THREAD won't work because too many
+ // Qt internals (QFuture, QThreadPool, etc.) depend on threads
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(Q_OS_NACL_EMSCRIPTEN_PTHREADS)
+ return;
+#endif
QMutexData *current;
if (fastTryUnlock(current))
return;
diff --git a/src/corelib/thread/qmutex_unix.cpp b/src/corelib/thread/qmutex_unix.cpp
index 74e0d68f94..abb02d77ae 100644
--- a/src/corelib/thread/qmutex_unix.cpp
+++ b/src/corelib/thread/qmutex_unix.cpp
@@ -70,6 +70,10 @@ QMutexPrivate::~QMutexPrivate()
bool QMutexPrivate::wait(int timeout)
{
+ // TODO Emscripten specialization could perhaps be replaced with pthread stubs
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(Q_OS_NACL_EMSCRIPTEN_PTHREADS)
+ return false;
+#endif
report_error(pthread_mutex_lock(&mutex), "QMutex::lock", "mutex lock");
int errorCode = 0;
while (!wakeup) {
diff --git a/src/corelib/thread/qwaitcondition_unix.cpp b/src/corelib/thread/qwaitcondition_unix.cpp
index b531707dd2..19c816475e 100644
--- a/src/corelib/thread/qwaitcondition_unix.cpp
+++ b/src/corelib/thread/qwaitcondition_unix.cpp
@@ -114,6 +114,10 @@ public:
int wait_relative(unsigned long time)
{
+ // TODO Emscripten specialization could perhaps be replaced with pthread stubs
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(Q_OS_NACL_EMSCRIPTEN_PTHREADS)
+ return 0;
+#endif
timespec ti;
#ifdef Q_OS_ANDROID
if (local_cond_timedwait_relative) {
@@ -128,6 +132,10 @@ public:
bool wait(unsigned long time)
{
+ // TODO Emscripten specialization could perhaps be replaced with pthread stubs
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(Q_OS_NACL_EMSCRIPTEN_PTHREADS)
+ return true;
+#endif
int code;
forever {
if (time != ULONG_MAX) {
@@ -194,6 +202,11 @@ void QWaitCondition::wakeAll()
bool QWaitCondition::wait(QMutex *mutex, unsigned long time)
{
+ // TODO Emscripten specialization could perhaps be replaced with pthread stubs
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(Q_OS_NACL_EMSCRIPTEN_PTHREADS)
+ return true;
+#endif
+
if (! mutex)
return false;
if (mutex->isRecursive()) {
@@ -214,6 +227,10 @@ bool QWaitCondition::wait(QMutex *mutex, unsigned long time)
bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time)
{
+ // TODO Emscripten specialization could perhaps be replaced with pthread stubs
+#if defined(Q_OS_NACL_EMSCRIPTEN) && !defined(Q_OS_NACL_EMSCRIPTEN_PTHREADS)
+ return true;
+#endif
if (!readWriteLock || readWriteLock->d->accessCount == 0)
return false;
if (readWriteLock->d->accessCount < -1) {
diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
index 971d0c0cec..137988ce39 100644
--- a/src/corelib/tools/qsimd.cpp
+++ b/src/corelib/tools/qsimd.cpp
@@ -640,6 +640,10 @@ int ffsll(quint64 i)
# define ffsll __builtin_ffsll
#endif
+#if defined(Q_OS_NACL_NEWLIB) || defined(Q_OS_NACL_EMSCRIPTEN)
+# define ffsll __builtin_ffsll
+#endif
+
#ifdef Q_ATOMIC_INT64_IS_SUPPORTED
Q_CORE_EXPORT QBasicAtomicInteger<quint64> qt_cpu_features[1] = { Q_BASIC_ATOMIC_INITIALIZER(0) };
#else