This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Kernel thread data tweak to avoid overflow
- From: Jonathan Larmour <jlarmour at jifvik dot org>
- To: ecos-patches at sources dot redhat dot com
- Date: Thu, 30 Jan 2003 07:01:40 GMT
- Subject: Kernel thread data tweak to avoid overflow
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/ChangeLog,v
retrieving revision 1.90
diff -u -5 -p -r1.90 ChangeLog
--- ChangeLog 28 Jan 2003 05:07:01 -0000 1.90
+++ ChangeLog 30 Jan 2003 07:01:39 -0000
@@ -1,5 +1,10 @@
+2003-01-30 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * src/common/thread.cxx: Fix potential warning and overflow with
+ CYGNUM_KERNEL_THREADS_DATA_MAX == 32.
+
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: cdl/thread.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/cdl/thread.cdl,v
retrieving revision 1.9
diff -u -5 -p -r1.9 thread.cdl
--- cdl/thread.cdl 28 Jan 2003 04:21:37 -0000 1.9
+++ cdl/thread.cdl 30 Jan 2003 07:01:39 -0000
@@ -163,22 +163,22 @@ cdl_component CYGVAR_KERNEL_THREADS_DATA
the ISO C library."
cdl_option CYGNUM_KERNEL_THREADS_DATA_MAX {
display "Number of words of per-thread data"
flavor data
- legal_values 4 to 31
+ legal_values 4 to 32
default_value 6
description "
It is possible for the kernel to support per-thread data, in
other words an area of memory specific to each thread which
can be used to store data for that thread. This per-thread
data can be used by applications or by other packages such as
the ISO C library. This configuration option controls the
number of words of per-thread data that the kernel will
allow. In the current implementation a bitmask is used to identify
used per-thread data slots and so the maximum legal value must
- remain 31."
+ remain 32."
}
cdl_component CYGNUM_KERNEL_THREADS_DATA_ALL {
display "Bitmap of preallocated slots of thread data"
flavor data
Index: src/common/thread.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/common/thread.cxx,v
retrieving revision 1.19
diff -u -5 -p -r1.19 thread.cxx
--- src/common/thread.cxx 12 Dec 2002 18:31:47 -0000 1.19
+++ src/common/thread.cxx 30 Jan 2003 07:01:39 -0000
@@ -1053,11 +1053,13 @@ Cyg_Thread::deliver_exception(
#ifdef CYGVAR_KERNEL_THREADS_DATA
// Set the data map bits for each free slot in the data array.
cyg_ucount32 Cyg_Thread::thread_data_map = (~CYGNUM_KERNEL_THREADS_DATA_ALL) &
- ((1<<CYGNUM_KERNEL_THREADS_DATA_MAX)-1);
+ (1+(((cyg_ucount32)(1<<(CYGNUM_KERNEL_THREADS_DATA_MAX-1))-1)<<1));
+// the second expression is equivalent to ((1<<CYGNUM_KERNEL_THREADS_DATA_MAX)-1);
+// but avoids overflow. The compiler will compile to a constant just fine.
Cyg_Thread::cyg_data_index
Cyg_Thread::new_data_index()
{
Cyg_Scheduler::lock();