Browse Source

Patch from Stefan Allius and Edie C. Dost:
In linuxthreads/errno.h the functions __errno_location and
__h_errno_location wasn't safe against calling before the
library is initialized.

Eric Andersen 22 years ago
parent
commit
ac3f49cb80
2 changed files with 21 additions and 5 deletions
  1. 18 4
      libpthread/linuxthreads/errno.c
  2. 3 1
      libpthread/linuxthreads/pthread.c

+ 18 - 4
libpthread/linuxthreads/errno.c

@@ -20,15 +20,29 @@
 #include <netdb.h>
 #include "pthread.h"
 #include "internals.h"
+#include <stdio.h>
+extern int _errno;
+extern int _h_errno;
 
 int * __errno_location()
 {
-  pthread_descr self = thread_self();
-  return THREAD_GETMEM (self, p_errnop);
+  /* check, if the library is initilize */
+  if (__pthread_initial_thread_bos != NULL)
+  {
+    pthread_descr self = thread_self();
+    return THREAD_GETMEM (self, p_errnop);
+  }
+  return &_errno;
 }
 
 int * __h_errno_location()
 {
-  pthread_descr self = thread_self();
-  return THREAD_GETMEM (self, p_h_errnop);
+  /* check, if the library is initilize */
+  if (__pthread_initial_thread_bos != NULL)
+  {
+    pthread_descr self = thread_self();
+
+    return THREAD_GETMEM (self, p_h_errnop);
+  }
+  return &_h_errno;        
 }

+ 3 - 1
libpthread/linuxthreads/pthread.c

@@ -349,8 +349,10 @@ int __pthread_initialize_manager(void)
   NOMMU_INITIAL_THREAD_BOUNDS(__pthread_manager_thread_tos,__pthread_manager_thread_bos);
   PDEBUG("manager stack: size=%d, bos=%p, tos=%p\n", THREAD_MANAGER_STACK_SIZE,
 	 __pthread_manager_thread_bos, __pthread_manager_thread_tos);
+#if 0
   PDEBUG("initial stack: estimate bos=%p, tos=%p\n",
-	 __pthread_initial_thread_bos, __pthread_initial_thread_tos);
+  	 __pthread_initial_thread_bos, __pthread_initial_thread_tos);
+#endif
 
   /* Setup pipe to communicate with thread manager */
   if (pipe(manager_pipe) == -1) {