0005-pthread_getattr_np.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. ---
  5. src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp | 61 ++++++++++
  6. 1 file changed, 61 insertions(+)
  7. Index: qt-everywhere-opensource-src-4.8.1/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp
  8. ===================================================================
  9. --- qt-everywhere-opensource-src-4.8.1.orig/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp
  10. +++ qt-everywhere-opensource-src-4.8.1/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp
  11. @@ -70,6 +70,23 @@
  12. #endif
  13. #include <unistd.h>
  14. +#if defined(QT_LINUXBASE)
  15. +#include <dlfcn.h>
  16. +#endif
  17. +
  18. +#if defined(__UCLIBC__)
  19. +// versions of uClibc 0.9.32 and below with linuxthreads.old do not have
  20. +// pthread_getattr_np or pthread_attr_getstack.
  21. +#if __UCLIBC_MAJOR__ == 0 && \
  22. + (__UCLIBC_MINOR__ < 9 || \
  23. + (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) && \
  24. + defined(__LINUXTHREADS_OLD__)
  25. +#define UCLIBC_USE_PROC_SELF_MAPS 1
  26. +#include <stdio_ext.h>
  27. +extern int *__libc_stack_end;
  28. +#endif
  29. +#endif
  30. +
  31. #if OS(SOLARIS)
  32. #include <thread.h>
  33. #else
  34. @@ -648,6 +665,37 @@
  35. get_thread_info(find_thread(NULL), &threadInfo);
  36. return threadInfo.stack_end;
  37. #elif OS(UNIX)
  38. +#ifdef UCLIBC_USE_PROC_SELF_MAPS
  39. + // Read /proc/self/maps and locate the line whose address
  40. + // range contains __libc_stack_end.
  41. + FILE *file = fopen("/proc/self/maps", "r");
  42. + if (!file)
  43. + return 0;
  44. + __fsetlocking(file, FSETLOCKING_BYCALLER);
  45. + char *line = NULL;
  46. + size_t lineLen = 0;
  47. + while (!feof_unlocked(file)) {
  48. + if (getdelim(&line, &lineLen, '\n', file) <= 0)
  49. + break;
  50. +
  51. + long from;
  52. + long to;
  53. + if (sscanf (line, "%lx-%lx", &from, &to) != 2)
  54. + continue;
  55. + if (from <= (long)__libc_stack_end && (long)__libc_stack_end < to) {
  56. + fclose(file);
  57. + free(line);
  58. +#ifdef _STACK_GROWS_UP
  59. + return (void *)from;
  60. +#else
  61. + return (void *)to;
  62. +#endif
  63. + }
  64. + }
  65. + fclose(file);
  66. + free(line);
  67. + return 0;
  68. +#else
  69. AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
  70. MutexLocker locker(mutex);
  71. static void* stackBase = 0;
  72. @@ -655,11 +703,23 @@
  73. static pthread_t stackThread;
  74. pthread_t thread = pthread_self();
  75. if (stackBase == 0 || thread != stackThread) {
  76. +
  77. +#if defined(QT_LINUXBASE)
  78. + // LinuxBase is missing pthread_getattr_np - resolve it once at runtime instead
  79. + // see http://bugs.linuxbase.org/show_bug.cgi?id=2364
  80. + typedef int (*GetAttrPtr)(pthread_t, pthread_attr_t *);
  81. + static int (*pthread_getattr_np_ptr)(pthread_t, pthread_attr_t *) = 0;
  82. + if (!pthread_getattr_np_ptr)
  83. + *(void **)&pthread_getattr_np_ptr = dlsym(RTLD_DEFAULT, "pthread_getattr_np");
  84. +#endif
  85. pthread_attr_t sattr;
  86. pthread_attr_init(&sattr);
  87. #if HAVE(PTHREAD_NP_H) || OS(NETBSD)
  88. // e.g. on FreeBSD 5.4, neundorf@kde.org
  89. pthread_attr_get_np(thread, &sattr);
  90. +#elif defined(QT_LINUXBASE)
  91. + if (pthread_getattr_np_ptr)
  92. + pthread_getattr_np_ptr(thread, &sattr);
  93. #else
  94. // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
  95. pthread_getattr_np(thread, &sattr);
  96. @@ -671,6 +731,7 @@
  97. stackThread = thread;
  98. }
  99. return static_cast<char*>(stackBase) + stackSize;
  100. +#endif
  101. #else
  102. #error Need a way to get the stack base on this platform
  103. #endif