uClibc-0.9.29-linuxthreads.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. --- a/libpthread/linuxthreads.old/attr.c 2006-01-24 12:41:01.000000000 -0500
  2. +++ b/libpthread/linuxthreads.old/attr.c 2008-02-10 11:35:32.000000000 -0500
  3. @@ -25,6 +25,14 @@
  4. #include "pthread.h"
  5. #include "internals.h"
  6. +#include <sys/resource.h>
  7. +#include <inttypes.h>
  8. +#include <stdio.h>
  9. +#include <stdio_ext.h>
  10. +#include <stdlib.h>
  11. +#include <sys/resource.h>
  12. +
  13. +
  14. /* NOTE: With uClibc I don't think we need this versioning stuff.
  15. * Therefore, define the function pthread_attr_init() here using
  16. * a strong symbol. */
  17. @@ -209,4 +217,94 @@ int __pthread_attr_getstacksize(const pt
  18. *stacksize = attr->__stacksize;
  19. return 0;
  20. }
  21. +
  22. +
  23. +extern int *__libc_stack_end;
  24. +
  25. weak_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)
  26. +void* pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
  27. +{
  28. + static void *stackBase = 0;
  29. + static size_t stackSize = 0;
  30. + int ret = 0;
  31. + /* Stack size limit. */
  32. + struct rlimit rl;
  33. +
  34. + /* The safest way to get the top of the stack is to read
  35. + /proc/self/maps and locate the line into which
  36. + __libc_stack_end falls. */
  37. + FILE *fp = fopen("/proc/self/maps", "rc");
  38. + if (fp == NULL)
  39. + ret = errno;
  40. + /* We need the limit of the stack in any case. */
  41. + else if (getrlimit (RLIMIT_STACK, &rl) != 0)
  42. + ret = errno;
  43. + else {
  44. + /* We need no locking. */
  45. + __fsetlocking (fp, FSETLOCKING_BYCALLER);
  46. +
  47. + /* Until we found an entry (which should always be the case)
  48. + mark the result as a failure. */
  49. + ret = ENOENT;
  50. +
  51. + char *line = NULL;
  52. + size_t linelen = 0;
  53. + uintptr_t last_to = 0;
  54. +
  55. + while (! feof_unlocked (fp)) {
  56. + if (getdelim (&line, &linelen, '\n', fp) <= 0)
  57. + break;
  58. +
  59. + uintptr_t from;
  60. + uintptr_t to;
  61. + if (sscanf (line, "%x-%x", &from, &to) != 2)
  62. + continue;
  63. + if (from <= (uintptr_t) __libc_stack_end
  64. + && (uintptr_t) __libc_stack_end < to) {
  65. + /* Found the entry. Now we have the info we need. */
  66. + attr->__stacksize = rl.rlim_cur;
  67. +#ifdef _STACK_GROWS_UP
  68. + /* Don't check to enforce a limit on the __stacksize */
  69. + attr->__stackaddr = (void *) from;
  70. +#else
  71. + attr->__stackaddr = (void *) to;
  72. +
  73. + /* The limit might be too high. */
  74. + if ((size_t) attr->__stacksize > (size_t) attr->__stackaddr - last_to)
  75. + attr->__stacksize = (size_t) attr->__stackaddr - last_to;
  76. +#endif
  77. +
  78. + /* We succeed and no need to look further. */
  79. + ret = 0;
  80. + break;
  81. + }
  82. + last_to = to;
  83. + }
  84. +
  85. + fclose (fp);
  86. + free (line);
  87. + }
  88. +#ifndef _STACK_GROWS_UP
  89. + stackBase = (char *) attr->__stackaddr - attr->__stacksize;
  90. +#else
  91. + stackBase = attr->__stackaddr;
  92. +#endif
  93. + stackSize = attr->__stacksize;
  94. + return (void*)(stackBase + stackSize);
  95. +}
  96. +
  97. +int __pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr,
  98. + size_t *stacksize)
  99. +{
  100. + /* XXX This function has a stupid definition. The standard specifies
  101. + no error value but what is if no stack address was set? We simply
  102. + return the value we have in the member. */
  103. +#ifndef _STACK_GROWS_UP
  104. + *stackaddr = (char *) attr->__stackaddr - attr->__stacksize;
  105. +#else
  106. + *stackaddr = attr->__stackaddr;
  107. +#endif
  108. + *stacksize = attr->__stacksize;
  109. + return 0;
  110. +}
  111. +weak_alias (__pthread_attr_getstack, pthread_attr_getstack)
  112. --- a/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h 2006-12-07 22:19:36.000000000 -0500
  113. +++ b/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h 2008-02-10 11:42:35.000000000 -0500
  114. @@ -288,15 +288,11 @@ extern int pthread_attr_getstacksize (__
  115. __attr, size_t *__restrict __stacksize)
  116. __THROW;
  117. -#if 0
  118. -/* Not yet implemented in uClibc! */
  119. -
  120. #ifdef __USE_GNU
  121. /* Initialize thread attribute *ATTR with attributes corresponding to the
  122. already running thread TH. It shall be called on unitialized ATTR
  123. and destroyed with pthread_attr_destroy when no longer needed. */
  124. -extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW;
  125. -#endif
  126. +extern void* pthread_getattr_np(pthread_t thread, pthread_attr_t *attr);
  127. #endif
  128. /* Functions for scheduling control. */
  129. @@ -599,6 +595,11 @@ extern int pthread_cancel (pthread_t __c
  130. cancelled. */
  131. extern void pthread_testcancel (void);
  132. +/* Return the previously set address for the stack. */
  133. +extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
  134. + void **__restrict __stackaddr,
  135. + size_t *__restrict __stacksize) __THROW;
  136. +
  137. /* Install a cleanup handler: ROUTINE will be called with arguments ARG
  138. when the thread is cancelled or calls pthread_exit. ROUTINE will also