Index: c/src/exec/score/ChangeLog
===================================================================
--- c/src/exec/score/ChangeLog	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ c/src/exec/score/ChangeLog	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -1,2 +1,10 @@
+
+2001-08-09	Joel Sherrill <joel@OARcorp.com>
+
+	* include/rtems/score/coremsg.h, inline/rtems/score/coremsg.inl,
+	src/coremsgsubmit.c: Unblocking message queue operations should
+	NOT use _Thread_Executing for return status since it is permissible
+	to invoke message send operations from an ISR.  This was reported
+	by Suvrat Gupta <suvrat@utstar.com>.
 
 2000-05-25	Sergei Organov <osv@javad.ru>
Index: c/src/exec/score/include/rtems/score/coremsg.h
===================================================================
--- c/src/exec/score/include/rtems/score/coremsg.h	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ c/src/exec/score/include/rtems/score/coremsg.h	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -240,5 +240,5 @@
  */
  
-void _CORE_message_queue_Submit(
+CORE_message_queue_Status _CORE_message_queue_Submit(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
Index: c/src/exec/score/inline/rtems/score/coremsg.inl
===================================================================
--- c/src/exec/score/inline/rtems/score/coremsg.inl	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ c/src/exec/score/inline/rtems/score/coremsg.inl	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -28,5 +28,5 @@
  */
  
-RTEMS_INLINE_ROUTINE void _CORE_message_queue_Send(
+RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Send(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
@@ -38,5 +38,5 @@
 )
 {
-  _CORE_message_queue_Submit(
+  return _CORE_message_queue_Submit(
     the_message_queue,
     buffer,
@@ -63,5 +63,5 @@
  */
  
-RTEMS_INLINE_ROUTINE void _CORE_message_queue_Urgent(
+RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Urgent(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
@@ -73,5 +73,5 @@
 )
 {
-  _CORE_message_queue_Submit(
+  return _CORE_message_queue_Submit(
     the_message_queue,
     buffer,
Index: c/src/exec/score/src/coremsgsubmit.c
===================================================================
--- c/src/exec/score/src/coremsgsubmit.c	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ c/src/exec/score/src/coremsgsubmit.c	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -54,5 +54,5 @@
  */
 
-void _CORE_message_queue_Submit(
+CORE_message_queue_Status _CORE_message_queue_Submit(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
@@ -68,12 +68,7 @@
   CORE_message_queue_Buffer_control   *the_message;
   Thread_Control                      *the_thread;
-  Thread_Control                      *executing;
-
-  _Thread_Executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
 
   if ( size > the_message_queue->maximum_message_size ) {
-    _Thread_Executing->Wait.return_code =
-       CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
-    return;
+    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
   }
 
@@ -97,5 +92,5 @@
         (*api_message_queue_mp_support) ( the_thread, id );
 #endif
-      return;
+      return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
     }
   }
@@ -115,8 +110,7 @@
      *  NOTE: If the system is consistent, this error should never occur.
      */
+
     if ( !the_message ) {
-      _Thread_Executing->Wait.return_code =
-          CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
-      return;
+      return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
     }
 
@@ -134,5 +128,5 @@
        submit_type
     );
-    return;
+    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
   }
 
@@ -144,19 +138,38 @@
 
   if ( !wait ) {
-    _Thread_Executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
-    return;
+    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
   }
 
-  executing = _Thread_Executing;
+  /*
+   *  Do NOT block on a send if the caller is in an ISR.  It is
+   *  deadly to block in an ISR.
+   */
 
-  _ISR_Disable( level );
-  _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
-  executing->Wait.queue              = &the_message_queue->Wait_queue;
-  executing->Wait.id                 = id;
-  executing->Wait.return_argument    = (void *)buffer;
-  executing->Wait.return_argument_1  = (void *)size;
-  executing->Wait.count              = submit_type;
-  _ISR_Enable( level );
+  if ( _ISR_Is_in_progress() ) {
+    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
+  }
 
-  _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+  /*
+   *  WARNING!! executing should NOT be used prior to this point.
+   *  Thus the unusual choice to open a new scope and declare 
+   *  it as a variable.  Doing this emphasizes how dangerous it
+   *  would be to use this variable prior to here.
+   */
+
+  { 
+    Thread_Control  *executing = _Thread_Executing;
+
+    _ISR_Disable( level );
+    _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
+    executing->Wait.queue              = &the_message_queue->Wait_queue;
+    executing->Wait.id                 = id;
+    executing->Wait.return_argument    = (void *)buffer;
+    executing->Wait.return_argument_1  = (void *)size;
+    executing->Wait.count              = submit_type;
+    _ISR_Enable( level );
+
+    _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+  }
+
+  return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
 }
Index: cpukit/score/ChangeLog
===================================================================
--- cpukit/score/ChangeLog	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ cpukit/score/ChangeLog	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -1,2 +1,10 @@
+
+2001-08-09	Joel Sherrill <joel@OARcorp.com>
+
+	* include/rtems/score/coremsg.h, inline/rtems/score/coremsg.inl,
+	src/coremsgsubmit.c: Unblocking message queue operations should
+	NOT use _Thread_Executing for return status since it is permissible
+	to invoke message send operations from an ISR.  This was reported
+	by Suvrat Gupta <suvrat@utstar.com>.
 
 2000-05-25	Sergei Organov <osv@javad.ru>
Index: cpukit/score/include/rtems/score/coremsg.h
===================================================================
--- cpukit/score/include/rtems/score/coremsg.h	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ cpukit/score/include/rtems/score/coremsg.h	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -240,5 +240,5 @@
  */
  
-void _CORE_message_queue_Submit(
+CORE_message_queue_Status _CORE_message_queue_Submit(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
Index: cpukit/score/inline/rtems/score/coremsg.inl
===================================================================
--- cpukit/score/inline/rtems/score/coremsg.inl	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ cpukit/score/inline/rtems/score/coremsg.inl	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -28,5 +28,5 @@
  */
  
-RTEMS_INLINE_ROUTINE void _CORE_message_queue_Send(
+RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Send(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
@@ -38,5 +38,5 @@
 )
 {
-  _CORE_message_queue_Submit(
+  return _CORE_message_queue_Submit(
     the_message_queue,
     buffer,
@@ -63,5 +63,5 @@
  */
  
-RTEMS_INLINE_ROUTINE void _CORE_message_queue_Urgent(
+RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Urgent(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
@@ -73,5 +73,5 @@
 )
 {
-  _CORE_message_queue_Submit(
+  return _CORE_message_queue_Submit(
     the_message_queue,
     buffer,
Index: cpukit/score/src/coremsgsubmit.c
===================================================================
--- cpukit/score/src/coremsgsubmit.c	(revision 2082fe2919cef92399f22c887248fda3727069e7)
+++ cpukit/score/src/coremsgsubmit.c	(revision 00815403be55800c8e6c9ecf8464def7179bbc21)
@@ -54,5 +54,5 @@
  */
 
-void _CORE_message_queue_Submit(
+CORE_message_queue_Status _CORE_message_queue_Submit(
   CORE_message_queue_Control                *the_message_queue,
   void                                      *buffer,
@@ -68,12 +68,7 @@
   CORE_message_queue_Buffer_control   *the_message;
   Thread_Control                      *the_thread;
-  Thread_Control                      *executing;
-
-  _Thread_Executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
 
   if ( size > the_message_queue->maximum_message_size ) {
-    _Thread_Executing->Wait.return_code =
-       CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
-    return;
+    return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE;
   }
 
@@ -97,5 +92,5 @@
         (*api_message_queue_mp_support) ( the_thread, id );
 #endif
-      return;
+      return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
     }
   }
@@ -115,8 +110,7 @@
      *  NOTE: If the system is consistent, this error should never occur.
      */
+
     if ( !the_message ) {
-      _Thread_Executing->Wait.return_code =
-          CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
-      return;
+      return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
     }
 
@@ -134,5 +128,5 @@
        submit_type
     );
-    return;
+    return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
   }
 
@@ -144,19 +138,38 @@
 
   if ( !wait ) {
-    _Thread_Executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
-    return;
+    return CORE_MESSAGE_QUEUE_STATUS_TOO_MANY;
   }
 
-  executing = _Thread_Executing;
+  /*
+   *  Do NOT block on a send if the caller is in an ISR.  It is
+   *  deadly to block in an ISR.
+   */
 
-  _ISR_Disable( level );
-  _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
-  executing->Wait.queue              = &the_message_queue->Wait_queue;
-  executing->Wait.id                 = id;
-  executing->Wait.return_argument    = (void *)buffer;
-  executing->Wait.return_argument_1  = (void *)size;
-  executing->Wait.count              = submit_type;
-  _ISR_Enable( level );
+  if ( _ISR_Is_in_progress() ) {
+    return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED;
+  }
 
-  _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+  /*
+   *  WARNING!! executing should NOT be used prior to this point.
+   *  Thus the unusual choice to open a new scope and declare 
+   *  it as a variable.  Doing this emphasizes how dangerous it
+   *  would be to use this variable prior to here.
+   */
+
+  { 
+    Thread_Control  *executing = _Thread_Executing;
+
+    _ISR_Disable( level );
+    _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
+    executing->Wait.queue              = &the_message_queue->Wait_queue;
+    executing->Wait.id                 = id;
+    executing->Wait.return_argument    = (void *)buffer;
+    executing->Wait.return_argument_1  = (void *)size;
+    executing->Wait.count              = submit_type;
+    _ISR_Enable( level );
+
+    _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+  }
+
+  return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
 }
