patches/uClibc/0.9.29/700-linuxthreads.patch
changeset 747 d3e603e7c17c
parent 746 b150d6f590fc
child 748 61cd4eb6034d
     1.1 --- a/patches/uClibc/0.9.29/700-linuxthreads.patch	Mon Jul 28 21:08:01 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,145 +0,0 @@
     1.4 ---- a/libpthread/linuxthreads.old/attr.c	2006-01-24 12:41:01.000000000 -0500
     1.5 -+++ b/libpthread/linuxthreads.old/attr.c	2008-02-10 11:35:32.000000000 -0500
     1.6 -@@ -25,6 +25,14 @@
     1.7 - #include "pthread.h"
     1.8 - #include "internals.h"
     1.9 - 
    1.10 -+#include <sys/resource.h>
    1.11 -+#include <inttypes.h>
    1.12 -+#include <stdio.h>
    1.13 -+#include <stdio_ext.h>
    1.14 -+#include <stdlib.h>
    1.15 -+#include <sys/resource.h>
    1.16 -+
    1.17 -+
    1.18 - /* NOTE: With uClibc I don't think we need this versioning stuff.
    1.19 -  * Therefore, define the function pthread_attr_init() here using
    1.20 -  * a strong symbol. */
    1.21 -@@ -209,4 +217,94 @@ int __pthread_attr_getstacksize(const pt
    1.22 -   *stacksize = attr->__stacksize;
    1.23 -   return 0;
    1.24 - }
    1.25 -+
    1.26 -+
    1.27 -+extern int *__libc_stack_end;
    1.28 -+
    1.29 - weak_alias (__pthread_attr_getstacksize, pthread_attr_getstacksize)
    1.30 -+void* pthread_getattr_np(pthread_t thread, pthread_attr_t *attr)
    1.31 -+{
    1.32 -+    static void *stackBase = 0;
    1.33 -+    static size_t stackSize = 0;
    1.34 -+    int ret = 0;
    1.35 -+    /* Stack size limit.  */
    1.36 -+    struct rlimit rl;
    1.37 -+
    1.38 -+    /* The safest way to get the top of the stack is to read
    1.39 -+    /proc/self/maps and locate the line into which
    1.40 -+    __libc_stack_end falls.  */
    1.41 -+    FILE *fp = fopen("/proc/self/maps", "rc");
    1.42 -+    if (fp == NULL)
    1.43 -+        ret = errno;
    1.44 -+    /* We need the limit of the stack in any case.  */
    1.45 -+    else if (getrlimit (RLIMIT_STACK, &rl) != 0)
    1.46 -+        ret = errno;
    1.47 -+    else {
    1.48 -+        /* We need no locking.  */
    1.49 -+        __fsetlocking (fp, FSETLOCKING_BYCALLER);
    1.50 -+
    1.51 -+        /* Until we found an entry (which should always be the case)
    1.52 -+        mark the result as a failure.  */
    1.53 -+        ret = ENOENT;
    1.54 -+
    1.55 -+        char *line = NULL;
    1.56 -+        size_t linelen = 0;
    1.57 -+        uintptr_t last_to = 0;
    1.58 -+
    1.59 -+        while (! feof_unlocked (fp)) {
    1.60 -+            if (getdelim (&line, &linelen, '\n', fp) <= 0)
    1.61 -+                break;
    1.62 -+
    1.63 -+            uintptr_t from;
    1.64 -+            uintptr_t to;
    1.65 -+            if (sscanf (line, "%x-%x", &from, &to) != 2)
    1.66 -+                continue;
    1.67 -+            if (from <= (uintptr_t) __libc_stack_end
    1.68 -+            && (uintptr_t) __libc_stack_end < to) {
    1.69 -+                /* Found the entry.  Now we have the info we need.  */
    1.70 -+                attr->__stacksize = rl.rlim_cur;
    1.71 -+#ifdef _STACK_GROWS_UP
    1.72 -+                /* Don't check to enforce a limit on the __stacksize */
    1.73 -+                attr->__stackaddr = (void *) from;
    1.74 -+#else
    1.75 -+                attr->__stackaddr = (void *) to;
    1.76 -+
    1.77 -+                /* The limit might be too high.  */
    1.78 -+                if ((size_t) attr->__stacksize > (size_t) attr->__stackaddr - last_to)
    1.79 -+                    attr->__stacksize = (size_t) attr->__stackaddr - last_to;
    1.80 -+#endif
    1.81 -+
    1.82 -+                /* We succeed and no need to look further.  */
    1.83 -+                ret = 0;
    1.84 -+                break;
    1.85 -+            }
    1.86 -+            last_to = to;
    1.87 -+        }
    1.88 -+
    1.89 -+        fclose (fp);
    1.90 -+        free (line);
    1.91 -+    }
    1.92 -+#ifndef _STACK_GROWS_UP
    1.93 -+    stackBase = (char *) attr->__stackaddr - attr->__stacksize;
    1.94 -+#else
    1.95 -+    stackBase = attr->__stackaddr;
    1.96 -+#endif
    1.97 -+    stackSize = attr->__stacksize;
    1.98 -+    return (void*)(stackBase + stackSize);
    1.99 -+}
   1.100 -+
   1.101 -+int __pthread_attr_getstack (const pthread_attr_t *attr, void **stackaddr,
   1.102 -+			     size_t *stacksize)
   1.103 -+{
   1.104 -+  /* XXX This function has a stupid definition.  The standard specifies
   1.105 -+     no error value but what is if no stack address was set?  We simply
   1.106 -+     return the value we have in the member.  */
   1.107 -+#ifndef _STACK_GROWS_UP
   1.108 -+  *stackaddr = (char *) attr->__stackaddr - attr->__stacksize;
   1.109 -+#else
   1.110 -+  *stackaddr = attr->__stackaddr;
   1.111 -+#endif
   1.112 -+  *stacksize = attr->__stacksize;
   1.113 -+  return 0;
   1.114 -+}
   1.115 -+weak_alias (__pthread_attr_getstack, pthread_attr_getstack)
   1.116 -
   1.117 ---- a/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h	2006-12-07 22:19:36.000000000 -0500
   1.118 -+++ b/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h	2008-02-10 11:42:35.000000000 -0500
   1.119 -@@ -288,15 +288,11 @@ extern int pthread_attr_getstacksize (__
   1.120 - 				      __attr, size_t *__restrict __stacksize)
   1.121 -      __THROW;
   1.122 - 
   1.123 --#if 0
   1.124 --/* Not yet implemented in uClibc! */
   1.125 --
   1.126 - #ifdef __USE_GNU
   1.127 - /* Initialize thread attribute *ATTR with attributes corresponding to the
   1.128 -    already running thread TH.  It shall be called on unitialized ATTR
   1.129 -    and destroyed with pthread_attr_destroy when no longer needed.  */
   1.130 --extern int pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) __THROW;
   1.131 --#endif
   1.132 -+extern void* pthread_getattr_np(pthread_t thread, pthread_attr_t *attr);
   1.133 - #endif
   1.134 - 
   1.135 - /* Functions for scheduling control.  */
   1.136 -@@ -599,6 +595,11 @@ extern int pthread_cancel (pthread_t __c
   1.137 -    cancelled.  */
   1.138 - extern void pthread_testcancel (void);
   1.139 - 
   1.140 -+/* Return the previously set address for the stack.  */
   1.141 -+extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr,
   1.142 -+				  void **__restrict __stackaddr,
   1.143 -+				  size_t *__restrict __stacksize) __THROW;
   1.144 -+
   1.145 - 
   1.146 - /* Install a cleanup handler: ROUTINE will be called with arguments ARG
   1.147 -    when the thread is cancelled or calls pthread_exit.  ROUTINE will also
   1.148 -