1 Add pthred_getattr_np / phread_attr_getstrack alternatives for uClibc
3 Based on https://dev.openwrt.org/log/packages/Xorg/lib/qt4/patches/100-fix-webkit-for-uclibc.patch?rev=20371
5 Signed-off-by: Johan Sagaert <sagaert.johan@skynet.be>
7 src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp | 61 ++++++++++
8 1 file changed, 61 insertions(+)
10 Index: qt-everywhere-opensource-src-4.8.1/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp
11 ===================================================================
12 --- qt-everywhere-opensource-src-4.8.1.orig/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp
13 +++ qt-everywhere-opensource-src-4.8.1/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp
18 +#if defined(QT_LINUXBASE)
22 +#if defined(__UCLIBC__)
23 +// versions of uClibc 0.9.32 and below with linuxthreads.old do not have
24 +// pthread_getattr_np or pthread_attr_getstack.
25 +#if __UCLIBC_MAJOR__ == 0 && \
26 + (__UCLIBC_MINOR__ < 9 || \
27 + (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) && \
28 + defined(__LINUXTHREADS_OLD__)
29 +#define UCLIBC_USE_PROC_SELF_MAPS 1
30 +#include <stdio_ext.h>
31 +extern int *__libc_stack_end;
39 get_thread_info(find_thread(NULL), &threadInfo);
40 return threadInfo.stack_end;
42 +#ifdef UCLIBC_USE_PROC_SELF_MAPS
43 + // Read /proc/self/maps and locate the line whose address
44 + // range contains __libc_stack_end.
45 + FILE *file = fopen("/proc/self/maps", "r");
48 + __fsetlocking(file, FSETLOCKING_BYCALLER);
51 + while (!feof_unlocked(file)) {
52 + if (getdelim(&line, &lineLen, '\n', file) <= 0)
57 + if (sscanf (line, "%lx-%lx", &from, &to) != 2)
59 + if (from <= (long)__libc_stack_end && (long)__libc_stack_end < to) {
62 +#ifdef _STACK_GROWS_UP
63 + return (void *)from;
73 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
74 MutexLocker locker(mutex);
75 static void* stackBase = 0;
77 static pthread_t stackThread;
78 pthread_t thread = pthread_self();
79 if (stackBase == 0 || thread != stackThread) {
81 +#if defined(QT_LINUXBASE)
82 + // LinuxBase is missing pthread_getattr_np - resolve it once at runtime instead
83 + // see http://bugs.linuxbase.org/show_bug.cgi?id=2364
84 + typedef int (*GetAttrPtr)(pthread_t, pthread_attr_t *);
85 + static int (*pthread_getattr_np_ptr)(pthread_t, pthread_attr_t *) = 0;
86 + if (!pthread_getattr_np_ptr)
87 + *(void **)&pthread_getattr_np_ptr = dlsym(RTLD_DEFAULT, "pthread_getattr_np");
90 pthread_attr_init(&sattr);
91 #if HAVE(PTHREAD_NP_H) || OS(NETBSD)
92 // e.g. on FreeBSD 5.4, neundorf@kde.org
93 pthread_attr_get_np(thread, &sattr);
94 +#elif defined(QT_LINUXBASE)
95 + if (pthread_getattr_np_ptr)
96 + pthread_getattr_np_ptr(thread, &sattr);
98 // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
99 pthread_getattr_np(thread, &sattr);
101 stackThread = thread;
103 return static_cast<char*>(stackBase) + stackSize;
106 #error Need a way to get the stack base on this platform