This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

portability problem in pthread_create()



pthread_create() puts a pthread_info struct on the stack. 
If (sizeof(pthread_info) % sizeof(CYG_WORD)) != 0 this will
make the stack unaligned which in turn will cause the assert 
in Cyg_HardwareThread::attach_stack() to fail.

Suggested fix:

Index: packages/compat/posix/current/src/pthread.cxx
===================================================================
RCS file: /n/cvsroot/os/ecos/packages/compat/posix/current/src/pthread.cxx,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- packages/compat/posix/current/src/pthread.cxx	12 Dec 2001 11:55:44 -0000	1.1.1.1
+++ packages/compat/posix/current/src/pthread.cxx	4 Mar 2002 17:36:59 -0000	1.2
@@ -536,8 +536,9 @@
 
     nthread = (pthread_info *)stackbase;
 
-    stackbase += sizeof(pthread_info);
-    stacksize -= sizeof(pthread_info);
+    // Round size of pthread_info upward to sizeof(CYG_WORD) to keep stack aligned
+    stackbase += (sizeof(pthread_info)+sizeof(CYG_WORD)-1) & ~(sizeof(CYG_WORD)-1);
+    stacksize -= (sizeof(pthread_info)+sizeof(CYG_WORD)-1) & ~(sizeof(CYG_WORD)-1);
     
     thread_table[thread_next] = nthread;

Alternatively, fix the stack alignment assert, e.g. by introducing 
a separate platform defined macro for stack alignment instead of 
assuming that CYG_WORD alignment is required.

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]