[PATCH] Fix for uClibc linuxthreads stack checking

Robin Getz rgetz at blackfin.uclinux.org
Thu Sep 15 11:36:57 UTC 2005


Bernd Schmidt found/fixed this problem in uClibc:

http://blackfin.uclinux.org/tracker/index.php?func=detail&aid=882&group_id=17&atid=141

Basically, the uClinux dist includes a few thread demos - thdm and bcdm - 
running them simultaneously sometimes causes bus errors.

Bernd wrote:
>They occur in pthread_handle_sigrestart; thread_self returns a bogus value.
>I managed to capture a debugging log, it's attached as bad-log.  If you 
>look at it you'll notice that the initial stack bounds are bogus: bottom 
>of stack is higher than top of stack.  This appears to be because of a bug 
>in NOMMU_INITIAL_THREAD_BOUNDS(tos,bos): if a new thread has a BOS equal 
>to the initial thread's current TOS, it'll munge the initial thread's 
>stack bounds.  Fixed with the attached patch, which I've committed.
>This should fix the crashes people have seen, but since the bug was always 
>hard to reproduce, I can't be 100% certain they are gone.  Please retest, 
>everyone...

This patch was made against our cvs, which has an older version of uClibc 
in it - this code was recently moved from internals.h to descr.h in the 
uclibc svn, but it still has the same problem:

http://www.uclibc.org/cgi-bin/viewcvs.cgi/trunk/uClibc/libpthread/linuxthreads/descr.h?rev=11408&view=auto

Comments welcome.
-robin 
-------------- next part --------------
00057 : pthread_initialize: initial thread stack bounds: bos=0x1, tos=0x7920000
00057 : __pthread_initialize_manager: manager stack: size=8160, bos=0x7920000, tos=0x7921fe0
00057 : __pthread_initialize_manager: send REQ_DEBUG to manager thread
00057 : pthread_create: write REQ_CREATE to manager thread
00057 : pthread_create: before suspend(self)
00058 : __pthread_manager: before poll
00058 : __pthread_manager: after poll
00058 : __pthread_manager: before __libc_read
00058 : __pthread_manager: after __libc_read, n=148
00058 : __pthread_manager: got REQ_CREATE
00058 : pthread_allocate_stack: malloced chunk: base=0x7924000, size=0x4000
00058 : pthread_allocate_stack: thread stack: bos=0x7924000, tos=0x7927e20
00058 : pthread_allocate_stack: initial stack: bos=0x7921fe1, tos=0x7920000
00058 : pthread_handle_create: cloning new_thread = 0x7927e20
00058 : pthread_handle_create: new thread pid = 59
00058 : __pthread_manager: restarting 126957896
00057 : pthread_handle_sigrestart: 57
00058 : __pthread_manager: before poll
00059 : pthread_start_thread: pid 59
-------------- next part --------------
Index: internals.h
===================================================================
RCS file: /cvsroot/uclinux533/uClinux-dist/uClibc/libpthread/linuxthreads/internals.h,v
retrieving revision 1.2
diff -d -u -r1.2 internals.h
--- internals.h	18 Jul 2005 08:06:15 -0000	1.2
+++ internals.h	15 Sep 2005 10:53:12 -0000
@@ -259,7 +259,10 @@
 extern char *__pthread_initial_thread_bos;
 #ifndef __ARCH_HAS_MMU__
 extern char *__pthread_initial_thread_tos;
-#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) if ((tos)>=__pthread_initial_thread_bos && (bos)<=__pthread_initial_thread_tos) __pthread_initial_thread_bos = (tos)+1
+#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) \
+    if ((tos)>=__pthread_initial_thread_bos \
+	&& (bos)<__pthread_initial_thread_tos) \
+	__pthread_initial_thread_bos = (tos)+1
 #else
 #define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) /* empty */
 #endif /* __ARCH_HAS_MMU__ */


More information about the uClibc mailing list