Index: cpukit/rtems/src/msg.c
===================================================================
--- cpukit/rtems/src/msg.c	(revision ea9d7db3b0c547aedd6cde436dcf8064e9364117)
+++ cpukit/rtems/src/msg.c	(revision 3b438fa4b0284d340b60d865f4afcb76f363bc90)
@@ -36,5 +36,4 @@
  *  Input parameters:
  *    maximum_message_queues - number of message queues to initialize
- *    maximum_message        - number of messages per queue
  *
  *  Output parameters:  NONE
@@ -42,9 +41,7 @@
 
 void _Message_queue_Manager_initialization(
-  unsigned32 maximum_message_queues,
-  unsigned32 maximum_messages
-)
-{
-
+  unsigned32 maximum_message_queues
+)
+{
   _Objects_Initialize_information(
     &_Message_queue_Information,
@@ -53,22 +50,55 @@
     sizeof( Message_queue_Control )
   );
-
-  if ( maximum_messages == 0 ) {
-
-    _Chain_Initialize_empty( &_Message_queue_Inactive_messages );
-
-  } else {
-
-
-    _Chain_Initialize(
-      &_Message_queue_Inactive_messages,
-      _Workspace_Allocate_or_fatal_error(
-        maximum_messages * sizeof( Message_queue_Buffer_control )
-      ),
-      maximum_messages,
-      sizeof( Message_queue_Buffer_control )
-    );
-
-  }
+}
+
+/*PAGE
+ *
+ *  _Message_queue_Allocate
+ *
+ *  Allocate a message queue and the space for its messages
+ */
+
+Message_queue_Control *_Message_queue_Allocate (
+  unsigned32          count,
+  unsigned32          max_message_size
+)
+{
+    Message_queue_Control *mq = 0;
+    unsigned32 message_buffering_required;
+    unsigned32 allocated_message_size;
+
+    mq = (Message_queue_Control *)_Objects_Allocate(&_Message_queue_Information);
+    if (mq == 0)
+        goto failed;
+
+    mq->maximum_message_size = max_message_size;
+
+    /*
+     * round size up to multiple of a ptr for chain init
+     */
+    
+    allocated_message_size = max_message_size;
+    if (allocated_message_size & (sizeof(unsigned32) - 1))
+    {
+        allocated_message_size += sizeof(unsigned32);
+        allocated_message_size &= ~(sizeof(unsigned32) - 1);
+    }
+    
+    message_buffering_required = count * (allocated_message_size + sizeof(Message_queue_Buffer_control));
+  
+    mq->message_buffers = (Message_queue_Buffer *) _Workspace_Allocate(message_buffering_required);
+    if (mq->message_buffers == 0)
+        goto failed;
+  
+    _Chain_Initialize(&mq->Inactive_messages,
+                      mq->message_buffers,
+                      count,
+                      allocated_message_size + sizeof(Message_queue_Buffer_control));
+    return mq;
+
+failed:
+    if (mq)
+        _Message_queue_Free(mq);
+    return (Message_queue_Control *) 0;
 }
 
@@ -83,4 +113,5 @@
  *    name          - user defined queue name
  *    count         - maximum message and reserved buffer count
+ *    max_message_size - maximum size of each message
  *    attribute_set - process method
  *    id            - pointer to queue
@@ -95,5 +126,6 @@
   Objects_Name        name,
   unsigned32          count,
-  rtems_attribute  attribute_set,
+  unsigned32          max_message_size,
+  rtems_attribute     attribute_set,
   Objects_Id         *id
 )
@@ -108,7 +140,28 @@
     return( RTEMS_MP_NOT_CONFIGURED );
 
+  if (count == 0)
+      return RTEMS_INVALID_NUMBER;
+
+  if (max_message_size == 0)
+      return RTEMS_INVALID_SIZE;
+
+#if 1
+  /*
+   * I am not 100% sure this should be an error.
+   * It seems reasonable to create a que with a large max size,
+   * and then just send smaller msgs from remote (or all) nodes.
+   */
+  
+  if ( _Attributes_Is_global( attribute_set ) &&
+       _Configuration_MPCI_table &&
+       (_Configuration_MPCI_table->maximum_packet_size < max_message_size))
+  {
+      return RTEMS_INVALID_SIZE;
+  }
+#endif
+       
   _Thread_Disable_dispatch();              /* protects object pointer */
 
-  the_message_queue = _Message_queue_Allocate();
+  the_message_queue = _Message_queue_Allocate(count, max_message_size);
 
   if ( !the_message_queue ) {
@@ -122,13 +175,10 @@
     _Message_queue_Free( the_message_queue );
     _Thread_Enable_dispatch();
-    return( RTEMS_TOO_MANY );
-  }
-
-  if ( _Attributes_Is_limit( attribute_set ) )
-    the_message_queue->maximum_pending_messages = count;
-  else
-    the_message_queue->maximum_pending_messages = 0xffffffff;
-
-  the_message_queue->attribute_set              = attribute_set;
+    return RTEMS_TOO_MANY;
+  }
+
+  the_message_queue->maximum_pending_messages = count;
+
+  the_message_queue->attribute_set = attribute_set;
   the_message_queue->number_of_pending_messages = 0;
 
@@ -265,13 +315,9 @@
 rtems_status_code rtems_message_queue_send(
   Objects_Id            id,
-  void                 *buffer
-)
-{
-  return( _Message_queue_Submit(
-      id,
-      (Message_queue_Buffer *) buffer,
-      MESSAGE_QUEUE_SEND_REQUEST
-    )
-  );
+  void                 *buffer,
+  unsigned32            size
+)
+{
+  return _Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_SEND_REQUEST);
 }
 
@@ -294,13 +340,9 @@
 rtems_status_code rtems_message_queue_urgent(
   Objects_Id            id,
-  void                 *buffer
-)
-{
-  return( _Message_queue_Submit(
-      id,
-      (Message_queue_Buffer *) buffer,
-      MESSAGE_QUEUE_URGENT_REQUEST
-    )
-  );
+  void                 *buffer,
+  unsigned32            size
+)
+{
+  return _Message_queue_Submit(id, buffer, size, MESSAGE_QUEUE_URGENT_REQUEST);
 }
 
@@ -326,4 +368,5 @@
   Objects_Id            id,
   void                 *buffer,
+  unsigned32            size,
   unsigned32           *count
 )
@@ -345,19 +388,31 @@
           MESSAGE_QUEUE_MP_BROADCAST_REQUEST,
           id,
-          (Message_queue_Buffer *) buffer,
-          0,                               /* Not used */
+          buffer,
+          &size,
+          0,                               /* option_set not used */
           MPCI_DEFAULT_TIMEOUT
         );
 
     case OBJECTS_LOCAL:
+    {
+      Thread_Wait_information *waitp;
+      unsigned32 constrained_size;
+
       number_broadcasted = 0;
       while ( (the_thread =
                  _Thread_queue_Dequeue(&the_message_queue->Wait_queue)) ) {
+        waitp = &the_thread->Wait;
         number_broadcasted += 1;
-        _Message_queue_Copy_buffer(
-          (Message_queue_Buffer *) buffer,
-          the_thread->Wait.return_argument
-        );
-
+
+        constrained_size = size;
+        if (size > the_message_queue->maximum_message_size)
+            constrained_size = the_message_queue->maximum_message_size;
+
+        _Message_queue_Copy_buffer(buffer,
+                                   waitp->return_argument,
+                                   constrained_size);
+
+        *waitp->Extra.message_size_p = constrained_size;
+        
         if ( !_Objects_Is_local_id( the_thread->Object.id ) ) {
           the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
@@ -373,7 +428,9 @@
       *count = number_broadcasted;
       return( RTEMS_SUCCESSFUL );
-  }
-
-  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
+    }
+
+    default:
+      return RTEMS_INTERNAL_ERROR;
+  }
 }
 
@@ -399,22 +456,26 @@
   Objects_Id            id,
   void                 *buffer,
+  unsigned32           *size_p,
   unsigned32            option_set,
-  rtems_interval     timeout
+  rtems_interval        timeout
 )
 {
   register Message_queue_Control *the_message_queue;
-  Objects_Locations                      location;
+  Objects_Locations               location;
 
   the_message_queue = _Message_queue_Get( id, &location );
   switch ( location ) {
+
     case OBJECTS_ERROR:
       return( RTEMS_INVALID_ID );
+
     case OBJECTS_REMOTE:
       _Thread_Executing->Wait.return_argument = buffer;
-      return
-        _Message_queue_MP_Send_request_packet(
+      
+      return _Message_queue_MP_Send_request_packet(
           MESSAGE_QUEUE_MP_RECEIVE_REQUEST,
           id,
           buffer,
+          size_p,
           option_set,
           timeout
@@ -422,8 +483,13 @@
 
     case OBJECTS_LOCAL:
-      if ( !_Message_queue_Seize( the_message_queue, option_set, buffer ) )
+      if ( ! _Message_queue_Seize(the_message_queue,
+                                  option_set,
+                                  buffer,
+                                  size_p))
+      {
         _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
+      }
       _Thread_Enable_dispatch();
-      return( _Thread_Executing->Wait.return_code );
+      return _Thread_Executing->Wait.return_code;
   }
 
@@ -468,6 +534,7 @@
           MESSAGE_QUEUE_MP_FLUSH_REQUEST,
           id,
-          0,                               /* Not used */
-          0,                               /* Not used */
+          0,                               /* buffer not used */
+          0,                               /* size_p */
+          0,                               /* option_set not used */
           MPCI_DEFAULT_TIMEOUT
         );
@@ -512,5 +579,6 @@
   Message_queue_Control  *the_message_queue,
   rtems_option            option_set,
-  Message_queue_Buffer   *buffer
+  void                   *buffer,
+  unsigned32             *size_p
 )
 {
@@ -527,6 +595,7 @@
     the_message = _Message_queue_Get_pending_message( the_message_queue );
     _ISR_Enable( level );
-    _Message_queue_Copy_buffer( &the_message->Contents, buffer );
-    _Message_queue_Free_message_buffer( the_message );
+    *size_p = the_message->Contents.size;
+    _Message_queue_Copy_buffer( the_message->Contents.buffer, buffer, *size_p );
+    _Message_queue_Free_message_buffer(the_message_queue, the_message );
     return( TRUE );
   }
@@ -543,6 +612,7 @@
   executing->Wait.option_set         = option_set;
   executing->Wait.return_argument    = (unsigned32 *)buffer;
+  executing->Wait.Extra.message_size_p = size_p;
   _ISR_Enable( level );
-  return( FALSE );
+  return FALSE;
 }
 
@@ -568,20 +638,20 @@
 )
 {
-  ISR_Level          level;
+  ISR_Level   level;
   Chain_Node *inactive_first;
   Chain_Node *message_queue_first;
   Chain_Node *message_queue_last;
-  unsigned32         count;
+  unsigned32  count;
 
   _ISR_Disable( level );
-    inactive_first      = _Message_queue_Inactive_messages.first;
+    inactive_first      = the_message_queue->Inactive_messages.first;
     message_queue_first = the_message_queue->Pending_messages.first;
     message_queue_last  = the_message_queue->Pending_messages.last;
 
-    _Message_queue_Inactive_messages.first = message_queue_first;
-    message_queue_last->next               = inactive_first;
-    inactive_first->previous               = message_queue_last;
+    the_message_queue->Inactive_messages.first = message_queue_first;
+    message_queue_last->next = inactive_first;
+    inactive_first->previous = message_queue_last;
     message_queue_first->previous          =
-               _Chain_Head( &_Message_queue_Inactive_messages );
+               _Chain_Head( &the_message_queue->Inactive_messages );
 
     _Chain_Initialize_empty( &the_message_queue->Pending_messages );
@@ -590,5 +660,5 @@
     the_message_queue->number_of_pending_messages = 0;
   _ISR_Enable( level );
-  return( count );
+  return count;
 }
 
@@ -606,15 +676,17 @@
  *  Input parameters:
  *    id          - pointer to message queue
- *    the_buffer  - pointer to message buffer
+ *    buffer      - pointer to message buffer
+ *    size        - size in bytes of message to send
  *    submit_type - send or urgent message
  *
  *  Output parameters:
  *    RTEMS_SUCCESSFUL - if successful
- *    error code        - if unsuccessful
+ *    error code       - if unsuccessful
  */
 
 rtems_status_code _Message_queue_Submit(
   Objects_Id                  id,
-  Message_queue_Buffer       *buffer,
+  void                       *buffer,
+  unsigned32                  size,
   Message_queue_Submit_types  submit_type
 )
@@ -626,7 +698,9 @@
 
   the_message_queue = _Message_queue_Get( id, &location );
-  switch ( location ) {
+  switch ( location )
+  {
     case OBJECTS_ERROR:
       return( RTEMS_INVALID_ID );
+
     case OBJECTS_REMOTE:
       switch ( submit_type ) {
@@ -637,5 +711,6 @@
               id,
               buffer,
-              0,                               /* Not used */
+              &size,
+              0,                               /* option_set */
               MPCI_DEFAULT_TIMEOUT
             );
@@ -647,18 +722,31 @@
               id,
               buffer,
-              0,                               /* Not used */
+              &size,
+              0,                               /* option_set */
               MPCI_DEFAULT_TIMEOUT
             );
       }
+
     case OBJECTS_LOCAL:
+      if (size > the_message_queue->maximum_message_size)
+      {
+          _Thread_Enable_dispatch();
+          return RTEMS_INVALID_SIZE;
+      }
+
+      /*
+       * Is there a thread currently waiting on this message queue?
+       */
+      
       the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue );
-
-      if ( the_thread ) {
-
+      if ( the_thread )
+      {
         _Message_queue_Copy_buffer(
           buffer,
-          the_thread->Wait.return_argument
+          the_thread->Wait.return_argument,
+          size
         );
-
+        *the_thread->Wait.Extra.message_size_p = size;
+        
         if ( !_Objects_Is_local_id( the_thread->Object.id ) ) {
           the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
@@ -675,4 +763,9 @@
       }
 
+      /*
+       * No one waiting on this one currently.
+       * Allocate a message buffer and store it away
+       */
+
       if ( the_message_queue->number_of_pending_messages ==
            the_message_queue->maximum_pending_messages ) {
@@ -681,13 +774,13 @@
       }
 
-      the_message = _Message_queue_Allocate_message_buffer();
-
-      if ( !the_message ) {
+      the_message = _Message_queue_Allocate_message_buffer(the_message_queue);
+      if ( the_message == 0) {
         _Thread_Enable_dispatch();
         return( RTEMS_UNSATISFIED );
       }
 
-      _Message_queue_Copy_buffer( buffer, &the_message->Contents );
-
+      _Message_queue_Copy_buffer( buffer, the_message->Contents.buffer, size );
+      the_message->Contents.size = size;
+      
       the_message_queue->number_of_pending_messages += 1;
 
@@ -703,6 +796,7 @@
       _Thread_Enable_dispatch();
       return( RTEMS_SUCCESSFUL );
-  }
-
-  return( RTEMS_INTERNAL_ERROR );   /* unreached - only to remove warnings */
-}
+          
+    default:
+      return RTEMS_INTERNAL_ERROR;       /* And they were such nice boys, too! */
+  }
+}
Index: cpukit/rtems/src/msgmp.c
===================================================================
--- cpukit/rtems/src/msgmp.c	(revision ea9d7db3b0c547aedd6cde436dcf8064e9364117)
+++ cpukit/rtems/src/msgmp.c	(revision 3b438fa4b0284d340b60d865f4afcb76f363bc90)
@@ -22,4 +22,5 @@
 #include <rtems/thread.h>
 #include <rtems/watchdog.h>
+#include <rtems/config.h>
 
 /*PAGE
@@ -86,7 +87,8 @@
   Message_queue_MP_Remote_operations  operation,
   Objects_Id                          message_queue_id,
-  Message_queue_Buffer               *buffer,
-  rtems_option                     option_set,
-  rtems_interval                   timeout
+  void                               *buffer,
+  unsigned32                         *size_p,
+  rtems_option                        option_set,
+  rtems_interval                      timeout
 )
 {
@@ -95,5 +97,4 @@
   switch ( operation ) {
 
-    case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
     case MESSAGE_QUEUE_MP_SEND_REQUEST:
     case MESSAGE_QUEUE_MP_URGENT_REQUEST:
@@ -103,23 +104,67 @@
       the_packet                    = _Message_queue_MP_Get_packet();
       the_packet->Prefix.the_class  = RTEMS_MP_PACKET_MESSAGE_QUEUE;
-      the_packet->Prefix.length     = sizeof ( Message_queue_MP_Packet );
-      the_packet->Prefix.to_convert = sizeof ( Message_queue_MP_Packet ) -
-                         sizeof ( Message_queue_Buffer );
+      the_packet->Prefix.length     = sizeof(Message_queue_MP_Packet);
+      if ( size_p )
+      the_packet->Prefix.length     += *size_p;
+      the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet);
+
+      /*
+       * make sure message is not too big for our MPCI driver
+       * We have to check it here instead of waiting for MPCI because
+       * we are about to slam in the payload
+       */
+
+      if (the_packet->Prefix.length >
+          _Configuration_MPCI_table->maximum_packet_size)
+      {
+          _Thread_Enable_dispatch();
+          return RTEMS_INVALID_SIZE;
+      }
+
       if ( ! _Options_Is_no_wait(option_set))
           the_packet->Prefix.timeout = timeout;
 
-      the_packet->operation         = operation;
-      the_packet->Prefix.id         = message_queue_id;
-      the_packet->option_set        = option_set;
-
-      if ( buffer )
-        _Message_queue_Copy_buffer( buffer, &the_packet->Buffer );
-
-      return
-        _MPCI_Send_request_packet(
-          rtems_get_node( message_queue_id ),
-          &the_packet->Prefix,
-          STATES_WAITING_FOR_MESSAGE
-        );
+      the_packet->operation  = operation;
+      the_packet->Prefix.id  = message_queue_id;
+      the_packet->option_set = option_set;
+
+      /*
+       * Copy the data into place if needed
+       */
+      
+      if (buffer)
+      {
+          the_packet->Buffer.size = *size_p;
+          _Message_queue_Copy_buffer(buffer,
+                                     the_packet->Buffer.buffer,
+                                     *size_p);
+      }
+
+      return _MPCI_Send_request_packet(rtems_get_node(message_queue_id),
+                                       &the_packet->Prefix,
+                                       STATES_WAITING_FOR_MESSAGE);
+      break;
+
+    case MESSAGE_QUEUE_MP_RECEIVE_REQUEST:
+
+      the_packet                    = _Message_queue_MP_Get_packet();
+      the_packet->Prefix.the_class  = RTEMS_MP_PACKET_MESSAGE_QUEUE;
+      the_packet->Prefix.length     = sizeof(Message_queue_MP_Packet);
+      the_packet->Prefix.to_convert = sizeof(Message_queue_MP_Packet);
+
+      if ( ! _Options_Is_no_wait(option_set))
+          the_packet->Prefix.timeout = timeout;
+
+      the_packet->operation  = MESSAGE_QUEUE_MP_RECEIVE_REQUEST;
+      the_packet->Prefix.id  = message_queue_id;
+      the_packet->option_set = option_set;
+      the_packet->size       = 0;        /* just in case of an error */
+
+      _Thread_Executing->Wait.return_argument      = (unsigned32 *)buffer;
+      _Thread_Executing->Wait.Extra.message_size_p = size_p;
+      
+      return _MPCI_Send_request_packet(rtems_get_node(message_queue_id),
+                                       &the_packet->Prefix,
+                                       STATES_WAITING_FOR_MESSAGE);
       break;
 
@@ -133,10 +178,6 @@
     case MESSAGE_QUEUE_MP_FLUSH_RESPONSE:
       break;
-
   }
-  /*
-   *  The following line is included to satisfy compilers which
-   *  produce warnings when a function does not end with a return.
-   */
+
   return RTEMS_SUCCESSFUL;
 }
@@ -169,8 +210,14 @@
  *  The packet being returned already contains the class, length, and
  *  to_convert fields, therefore they are not set in this routine.
+ *
+ *  Exception: MESSAGE_QUEUE_MP_RECEIVE_RESPONSE needs payload length
+ *             added to 'length'
  */
       the_packet->operation = operation;
       the_packet->Prefix.id = the_packet->Prefix.source_tid;
 
+      if (operation == MESSAGE_QUEUE_MP_RECEIVE_RESPONSE)
+          the_packet->Prefix.length += the_packet->size;
+      
       _MPCI_Send_response_packet(
         rtems_get_node( the_packet->Prefix.source_tid ),
@@ -244,5 +291,6 @@
       the_packet->Prefix.return_code = rtems_message_queue_receive(
         the_packet->Prefix.id,
-        &the_packet->Buffer,
+        the_packet->Buffer.buffer,
+        &the_packet->size,
         the_packet->option_set,
         the_packet->Prefix.timeout
@@ -261,8 +309,13 @@
       the_thread = _MPCI_Process_response( the_packet_prefix );
 
-      _Message_queue_Copy_buffer(
-        &the_packet->Buffer,
-        (Message_queue_Buffer *) the_thread->Wait.return_argument
-      );
+      if (the_packet->Prefix.return_code == RTEMS_SUCCESSFUL) {
+        *the_thread->Wait.Extra.message_size_p = the_packet->size;
+
+        _Message_queue_Copy_buffer(
+          the_packet->Buffer.buffer,
+          the_thread->Wait.return_argument,
+          the_packet->size
+        );
+      }
 
       _MPCI_Return_packet( the_packet_prefix );
@@ -273,5 +326,6 @@
       the_packet->Prefix.return_code = rtems_message_queue_send(
         the_packet->Prefix.id,
-        &the_packet->Buffer
+        the_packet->Buffer.buffer,
+        the_packet->Buffer.size
       );
 
@@ -295,5 +349,6 @@
       the_packet->Prefix.return_code = rtems_message_queue_urgent(
         the_packet->Prefix.id,
-        &the_packet->Buffer
+        the_packet->Buffer.buffer,
+        the_packet->Buffer.size
       );
 
@@ -309,5 +364,6 @@
       the_packet->Prefix.return_code = rtems_message_queue_broadcast(
         the_packet->Prefix.id,
-        &the_packet->Buffer,
+        the_packet->Buffer.buffer,
+        the_packet->Buffer.size,
         &the_packet->count
       );
