This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix pthread_getattr_np call in boehm-gc
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Cc: Hans Boehm <Hans dot Boehm at hp dot com>
- Date: Fri, 22 Jun 2007 06:19:32 -0400
- Subject: [PATCH] Fix pthread_getattr_np call in boehm-gc
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
pthread_getattr_np can fail for various reasons and if it does,
pthread_attr_t is uninitialized and therefore neither pthread_attr_getstack
nor pthread_attr_destroy should be called on it.
E.g. if pthread_getattr_np is called from the initial thread on Linux
and /proc is not mapped, pthread_getattr_np will fail as /proc/self/maps
couldn't be read, pthread_attr_getstack will then return random values
and pthread_attr_destroy likely crash as it tries to free cpuset that wasn't
malloced.
Ok for 4.3/4.2/4.1?
2007-06-22 Jakub Jelinek <jakub@redhat.com>
* pthread_support.c (GC_get_thread_stack_base): Handle
pthread_getattr_np failures.
--- boehm-gc/pthread_support.c.jj 2006-10-05 00:29:37.000000000 +0200
+++ boehm-gc/pthread_support.c 2007-06-22 12:08:46.000000000 +0200
@@ -1135,7 +1135,13 @@ GC_PTR GC_get_thread_stack_base()
size_t stack_size;
my_pthread = pthread_self();
- pthread_getattr_np (my_pthread, &attr);
+ if (pthread_getattr_np (my_pthread, &attr) != 0)
+ {
+# ifdef DEBUG_THREADS
+ GC_printf1("Can not determine stack base for attached thread");
+# endif
+ return 0;
+ }
pthread_attr_getstack (&attr, (void **) &stack_addr, &stack_size);
pthread_attr_destroy (&attr);
Jakub