This is the mail archive of the ecos-patches@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]

Add pthread paranoia checks


Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/compat/posix/current/ChangeLog,v
retrieving revision 1.44
diff -u -5 -p -r1.44 ChangeLog
--- ChangeLog	20 Mar 2003 16:06:47 -0000	1.44
+++ ChangeLog	18 Jun 2003 04:59:15 -0000
@@ -1,5 +1,12 @@
+2003-06-18  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* src/pthread.cxx (pthread_self_info): Just add some comments so
+	no-one's tempted to uncomment assert.
+	(pthread_create): Verify that self is a valid POSIX thread when
+	needed.
+
 2003-03-20  Mark Salter  <msalter@redhat.com>
 
 	* include/pthread.h: Avoid conflict with recently introduced gcc
 	__thread keyword.
 
Index: src/pthread.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/compat/posix/current/src/pthread.cxx,v
retrieving revision 1.12
diff -u -5 -p -r1.12 pthread.cxx
--- src/pthread.cxx	23 May 2002 22:59:59 -0000	1.12
+++ src/pthread.cxx	18 Jun 2003 04:59:15 -0000
@@ -158,10 +158,14 @@ pthread_info *pthread_self_info(void)
 
     CYG_CHECK_DATA_PTR(thread, "Illegal current thread");
     
     pthread_info *info = (pthread_info *)thread->get_data(CYGNUM_KERNEL_THREADS_DATA_POSIX);
 
+    // This assertion mustn't be enabled because sometimes we can legitimately
+    // carefully call this as long as we realise the value can be NULL.
+    // e.g. consider the use of this when inheriting sigmasks when in the
+    // context of creating the main() thread.
 //    CYG_CHECK_DATA_PTR(info, "Not a POSIX thread!!!");
 
     return info;
 }
 
@@ -474,10 +478,21 @@ externC int pthread_create ( pthread_t *
 
     // Adjust the attributes to cope with the setting of inheritsched.
 
     if( use_attr.inheritsched == PTHREAD_INHERIT_SCHED )
     {
+        CYG_ASSERT( NULL != self,
+                    "Attempt to inherit sched policy from non-POSIX thread" );
+#ifdef CYGDBG_USE_ASSERTS
+        // paranoia check
+        int i;
+        for (i=(sizeof(thread_table)/sizeof(*thread_table))-1; i>=0; i--) {
+            if (thread_table[i] == self)
+                break;
+        }
+        CYG_ASSERT( i>=0, "Current pthread not found in table" );
+#endif
         use_attr.schedpolicy = self->attr.schedpolicy;
         use_attr.schedparam  = self->attr.schedparam;
     }
 
     CYG_ADDRWORD stackbase, stacksize;
@@ -597,10 +612,23 @@ externC int pthread_create ( pthread_t *
 
     nthread->joiner = new(nthread->joiner_obj) Cyg_Condition_Variable( pthread_mutex );
 
 #ifdef CYGPKG_POSIX_SIGNALS
     // Initialize signal specific fields.
+    if (NULL != self) {
+        CYG_CHECK_DATA_PTR( self,
+                            "Attempt to inherit signal mask from bogus pthread" );
+#ifdef CYGDBG_USE_ASSERTS
+        // paranoia check
+        int i;
+        for (i=(sizeof(thread_table)/sizeof(*thread_table))-1; i>=0; i--) {
+            if (thread_table[i] == self)
+                break;
+        }
+        CYG_ASSERT( i>=0, "Current pthread not found in table" );
+#endif
+    }
     cyg_posix_thread_siginit( nthread, self );
 #endif
 
     // create the underlying eCos thread
 


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