webkit-pthread_getattr_np.patch 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Patch WebKit because pthread_getattr_np is not implemented in uClibc
  2. Define UCLIBC_USE_PROC_SELF_MAPS etc. as a workaround for uClibc. This
  3. code was in the qtoipa webkit but appears to have been removed from
  4. more recent versions of webkit.
  5. See: http://bugreports.qt.nokia.com/browse/QTBUG-6551
  6. Credit for fix: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=545066#545066
  7. Signed-off-by: Paul Jones <paul@pauljones.id.au>
  8. Index: webkit-1.2.3/JavaScriptCore/runtime/Collector.cpp
  9. ===================================================================
  10. --- webkit-1.2.3.orig/JavaScriptCore/runtime/Collector.cpp 2010-07-22 17:16:19.000000000 +0200
  11. +++ webkit-1.2.3/JavaScriptCore/runtime/Collector.cpp 2010-07-22 17:25:02.000000000 +0200
  12. @@ -75,6 +75,19 @@
  13. #endif
  14. #include <unistd.h>
  15. +#if defined(__UCLIBC__)
  16. +// versions of uClibc 0.9.32 and below with linuxthreads.old do not have
  17. +// pthread_getattr_np or pthread_attr_getstack.
  18. +#if __UCLIBC_MAJOR__ == 0 && \
  19. + (__UCLIBC_MINOR__ < 9 || \
  20. + (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) && \
  21. + defined(__LINUXTHREADS_OLD__)
  22. +#define UCLIBC_USE_PROC_SELF_MAPS 1
  23. +#include <stdio_ext.h>
  24. +extern int *__libc_stack_end;
  25. +#endif
  26. +#endif
  27. +
  28. #if OS(SOLARIS)
  29. #include <thread.h>
  30. #else
  31. @@ -610,6 +622,36 @@
  32. get_thread_info(find_thread(NULL), &threadInfo);
  33. return threadInfo.stack_end;
  34. #elif OS(UNIX)
  35. +#ifdef UCLIBC_USE_PROC_SELF_MAPS
  36. + // Read /proc/self/maps and locate the line whose address
  37. + // range contains __libc_stack_end.
  38. + FILE *file = fopen("/proc/self/maps", "r");
  39. + if (!file)
  40. + return 0;
  41. + __fsetlocking(file, FSETLOCKING_BYCALLER);
  42. + char *line = NULL;
  43. + size_t lineLen = 0;
  44. + while (!feof_unlocked(file)) {
  45. + if (getdelim(&line, &lineLen, '\n', file) <= 0)
  46. + break;
  47. + long from;
  48. + long to;
  49. + if (sscanf (line, "%lx-%lx", &from, &to) != 2)
  50. + continue;
  51. + if (from <= (long)__libc_stack_end && (long)__libc_stack_end < to) {
  52. + fclose(file);
  53. + free(line);
  54. +#ifdef _STACK_GROWS_UP
  55. + return (void *)from;
  56. +#else
  57. + return (void *)to;
  58. +#endif
  59. + }
  60. + }
  61. + fclose(file);
  62. + free(line);
  63. + return 0;
  64. +#else
  65. static void* stackBase = 0;
  66. static size_t stackSize = 0;
  67. static pthread_t stackThread;
  68. @@ -631,6 +673,7 @@
  69. stackThread = thread;
  70. }
  71. return static_cast<char*>(stackBase) + stackSize;
  72. +#endif
  73. #elif OS(WINCE)
  74. if (g_stackBase)
  75. return g_stackBase;