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]

Re: Kernel KAPI and instrumentation mods


As promised/threatened, I've added a bit more checking to the cyg_thread_get_next() etc. recent additions, to help detect inconsistencies.

Jifl

2003-01-28 Jonathan Larmour <jifl@eCosCentric.com>

* src/common/kapi.cxx (cyg_thread_get_next): Be quite zealous about
checking the validity of passed in threads in debug mode.
(cyg_thread_get_info): Ditto.

Index: src/common/kapi.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/common/kapi.cxx,v
retrieving revision 1.20
diff -u -5 -p -r1.20 kapi.cxx
--- src/common/kapi.cxx 12 Dec 2002 18:31:47 -0000 1.20
+++ src/common/kapi.cxx 28 Jan 2003 05:03:16 -0000
@@ -315,24 +315,35 @@ externC cyg_uint32 cyg_thread_measure_st
#ifdef CYGVAR_KERNEL_THREADS_LIST

cyg_bool_t cyg_thread_get_next( cyg_handle_t *current, cyg_uint16 *id )
{
cyg_bool_t result = true;
-
+
+ // There is a minute but finite chance that the thread could have
+ // exitted since the previous cyg_thread_get_next() call, and we can't
+ // detect the ID mismatch further down. So be quite zealous with checking.
+
+ CYG_CHECK_DATA_PTRC( current );
+ CYG_CHECK_DATA_PTRC( id );
+ if ( *current != 0 )
+ CYG_CHECK_DATA_PTRC( *current );
+
Cyg_Scheduler::lock();

Cyg_Thread *thread = (Cyg_Thread *)*current;
-
+ CYG_ASSERT_CLASSC( thread );
if( *current == 0 )
{
thread = Cyg_Thread::get_list_head();
*current = (cyg_handle_t)thread;
*id = thread->get_unique_id();
}
else if( (thread->get_unique_id() == *id) &&
(thread = thread->get_list_next()) != NULL )
{
+ CYG_CHECK_DATA_PTRC( thread );
+ CYG_ASSERT_CLASSC( thread );
*current = (cyg_handle_t)thread;
*id = thread->get_unique_id();
}
else
{
@@ -371,15 +382,19 @@ cyg_bool_t cyg_thread_get_info( cyg_hand
cyg_uint16 id,
cyg_thread_info *info )
{
cyg_bool_t result = true;
Cyg_Thread *thread = (Cyg_Thread *)threadh;
+ CYG_CHECK_DATA_PTRC( thread );
+ if ( NULL != info )
+ CYG_CHECK_DATA_PTRC( info );

Cyg_Scheduler::lock();

if( thread->get_unique_id() == id && info != NULL )
{
+ CYG_ASSERT_CLASSC( thread );
info->handle = threadh;
info->id = id;
info->state = thread->get_state();
#ifdef CYGVAR_KERNEL_THREADS_NAME
info->name = thread->get_name();


Jifl
--
eCosCentric http://www.eCosCentric.com/ <info@eCosCentric.com>
--[ "You can complain because roses have thorns, or you ]--
--[ can rejoice because thorns have roses." -Lincoln ]-- Opinions==mine


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