qt-4.7.4-pthread_getattr_np.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. Add pthred_getattr_np / phread_attr_getstrack alternatives for uClibc
  2. Based on https://dev.openwrt.org/log/packages/Xorg/lib/qt4/patches/100-fix-webkit-for-uclibc.patch?rev=20371
  3. Signed-off-by: Johan Sagaert <sagaert.johan@skynet.be>
  4. --- qt-everywhere-opensource-src-4.6.2/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp 2010-02-11 16:55:20.000000000 +0100
  5. +++ qt-everywhere-opensource-src-4.6.2JS/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp 2010-05-23 10:49:29.000000000 +0200
  6. @@ -75,6 +75,23 @@
  7. #endif
  8. #include <unistd.h>
  9. +#if defined(QT_LINUXBASE)
  10. +#include <dlfcn.h>
  11. +#endif
  12. +
  13. +#if defined(__UCLIBC__)
  14. +// versions of uClibc 0.9.32 and below with linuxthreads.old do not have
  15. +// pthread_getattr_np or pthread_attr_getstack.
  16. +#if __UCLIBC_MAJOR__ == 0 && \
  17. + (__UCLIBC_MINOR__ < 9 || \
  18. + (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) && \
  19. + defined(__LINUXTHREADS_OLD__)
  20. +#define UCLIBC_USE_PROC_SELF_MAPS 1
  21. +#include <stdio_ext.h>
  22. +extern int *__libc_stack_end;
  23. +#endif
  24. +#endif
  25. +
  26. #if OS(SOLARIS)
  27. #include <thread.h>
  28. #else
  29. @@ -667,18 +683,61 @@ static inline void* currentThreadStackBa
  30. get_thread_info(find_thread(NULL), &threadInfo);
  31. return threadInfo.stack_end;
  32. #elif OS(UNIX)
  33. +#ifdef UCLIBC_USE_PROC_SELF_MAPS
  34. + // Read /proc/self/maps and locate the line whose address
  35. + // range contains __libc_stack_end.
  36. + FILE *file = fopen("/proc/self/maps", "r");
  37. + if (!file)
  38. + return 0;
  39. + __fsetlocking(file, FSETLOCKING_BYCALLER);
  40. + char *line = NULL;
  41. + size_t lineLen = 0;
  42. + while (!feof_unlocked(file)) {
  43. + if (getdelim(&line, &lineLen, '\n', file) <= 0)
  44. + break;
  45. +
  46. + long from;
  47. + long to;
  48. + if (sscanf (line, "%lx-%lx", &from, &to) != 2)
  49. + continue;
  50. + if (from <= (long)__libc_stack_end && (long)__libc_stack_end < to) {
  51. + fclose(file);
  52. + free(line);
  53. +#ifdef _STACK_GROWS_UP
  54. + return (void *)from;
  55. +#else
  56. + return (void *)to;
  57. +#endif
  58. + }
  59. + }
  60. + fclose(file);
  61. + free(line);
  62. + return 0;
  63. +#else
  64. AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
  65. MutexLocker locker(mutex);
  66. static void* stackBase = 0;
  67. static size_t stackSize = 0;
  68. static pthread_t stackThread;
  69. pthread_t thread = pthread_self();
  70. if (stackBase == 0 || thread != stackThread) {
  71. +
  72. +#if defined(QT_LINUXBASE)
  73. + // LinuxBase is missing pthread_getattr_np - resolve it once at runtime instead
  74. + // see http://bugs.linuxbase.org/show_bug.cgi?id=2364
  75. + typedef int (*GetAttrPtr)(pthread_t, pthread_attr_t *);
  76. + static int (*pthread_getattr_np_ptr)(pthread_t, pthread_attr_t *) = 0;
  77. + if (!pthread_getattr_np_ptr)
  78. + *(void **)&pthread_getattr_np_ptr = dlsym(RTLD_DEFAULT, "pthread_getattr_np");
  79. +#endif
  80. pthread_attr_t sattr;
  81. pthread_attr_init(&sattr);
  82. #if HAVE(PTHREAD_NP_H) || OS(NETBSD)
  83. // e.g. on FreeBSD 5.4, neundorf@kde.org
  84. pthread_attr_get_np(thread, &sattr);
  85. +#elif defined(QT_LINUXBASE)
  86. + if (pthread_getattr_np_ptr)
  87. + pthread_getattr_np_ptr(thread, &sattr);
  88. #else
  89. // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
  90. pthread_getattr_np(thread, &sattr);
  91. @@ -690,6 +749,7 @@ static inline void* currentThreadStackBa
  92. stackThread = thread;
  93. }
  94. return static_cast<char*>(stackBase) + stackSize;
  95. +#endif
  96. #elif OS(WINCE)
  97. AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
  98. MutexLocker locker(mutex);