qt-4.7.3-pthread_getattr_np.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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,22 @@
  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.31 and below 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__ <= 31))
  19. +#define UCLIBC_USE_PROC_SELF_MAPS 1
  20. +#include <stdio_ext.h>
  21. +extern int *__libc_stack_end;
  22. +#endif
  23. +#endif
  24. +
  25. #if OS(SOLARIS)
  26. #include <thread.h>
  27. #else
  28. @@ -667,18 +683,61 @@ static inline void* currentThreadStackBa
  29. get_thread_info(find_thread(NULL), &threadInfo);
  30. return threadInfo.stack_end;
  31. #elif OS(UNIX)
  32. +#ifdef UCLIBC_USE_PROC_SELF_MAPS
  33. + // Read /proc/self/maps and locate the line whose address
  34. + // range contains __libc_stack_end.
  35. + FILE *file = fopen("/proc/self/maps", "r");
  36. + if (!file)
  37. + return 0;
  38. + __fsetlocking(file, FSETLOCKING_BYCALLER);
  39. + char *line = NULL;
  40. + size_t lineLen = 0;
  41. + while (!feof_unlocked(file)) {
  42. + if (getdelim(&line, &lineLen, '\n', file) <= 0)
  43. + break;
  44. +
  45. + long from;
  46. + long to;
  47. + if (sscanf (line, "%lx-%lx", &from, &to) != 2)
  48. + continue;
  49. + if (from <= (long)__libc_stack_end && (long)__libc_stack_end < to) {
  50. + fclose(file);
  51. + free(line);
  52. +#ifdef _STACK_GROWS_UP
  53. + return (void *)from;
  54. +#else
  55. + return (void *)to;
  56. +#endif
  57. + }
  58. + }
  59. + fclose(file);
  60. + free(line);
  61. + return 0;
  62. +#else
  63. AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
  64. MutexLocker locker(mutex);
  65. static void* stackBase = 0;
  66. static size_t stackSize = 0;
  67. static pthread_t stackThread;
  68. pthread_t thread = pthread_self();
  69. if (stackBase == 0 || thread != stackThread) {
  70. +
  71. +#if defined(QT_LINUXBASE)
  72. + // LinuxBase is missing pthread_getattr_np - resolve it once at runtime instead
  73. + // see http://bugs.linuxbase.org/show_bug.cgi?id=2364
  74. + typedef int (*GetAttrPtr)(pthread_t, pthread_attr_t *);
  75. + static int (*pthread_getattr_np_ptr)(pthread_t, pthread_attr_t *) = 0;
  76. + if (!pthread_getattr_np_ptr)
  77. + *(void **)&pthread_getattr_np_ptr = dlsym(RTLD_DEFAULT, "pthread_getattr_np");
  78. +#endif
  79. pthread_attr_t sattr;
  80. pthread_attr_init(&sattr);
  81. #if HAVE(PTHREAD_NP_H) || OS(NETBSD)
  82. // e.g. on FreeBSD 5.4, neundorf@kde.org
  83. pthread_attr_get_np(thread, &sattr);
  84. +#elif defined(QT_LINUXBASE)
  85. + if (pthread_getattr_np_ptr)
  86. + pthread_getattr_np_ptr(thread, &sattr);
  87. #else
  88. // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
  89. pthread_getattr_np(thread, &sattr);
  90. @@ -690,6 +749,7 @@ static inline void* currentThreadStackBa
  91. stackThread = thread;
  92. }
  93. return static_cast<char*>(stackBase) + stackSize;
  94. +#endif
  95. #elif OS(WINCE)
  96. AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
  97. MutexLocker locker(mutex);