Index: cpukit/ChangeLog
===================================================================
--- cpukit/ChangeLog	(revision 68cc3adb75d2b2084f75291f4801eb16362d7c8c)
+++ cpukit/ChangeLog	(revision 652524d9538f50e229349314043cedb5a15f18be)
@@ -1,2 +1,11 @@
+2004-02-26	Joel Sherrill <joel@OARcorp.com>
+
+	PR 582/core
+	* posix/src/mqueue.c, posix/src/mqueuecreatesupp.c,
+	posix/src/mqueuedeletesupp.c, posix/src/mqueueunlink.c: Use memory
+	from workspace to avoid use of mutex during dispatch disable critical
+	section. Besides memory for object names should come from the
+	Workspace anyway.
+
 2004-02-12	Ralf Corsepius <corsepiu@faw.uni-ulm.de>
 
Index: cpukit/posix/src/mqueue.c
===================================================================
--- cpukit/posix/src/mqueue.c	(revision 68cc3adb75d2b2084f75291f4801eb16362d7c8c)
+++ cpukit/posix/src/mqueue.c	(revision 652524d9538f50e229349314043cedb5a15f18be)
@@ -26,4 +26,5 @@
 #include <fcntl.h>
 #include <mqueue.h>
+#include <limits.h>
 
 #include <rtems/system.h>
@@ -71,6 +72,6 @@
     sizeof( POSIX_Message_queue_Control_fd ),
                                 /* size of this object's control block */
-    FALSE,                      /* TRUE if names for this object are strings */
-    0                           /* maximum length of each object's name */
+    TRUE,                       /* TRUE if names for this object are strings */
+    NAME_MAX                    /* maximum length of each object's name */
 #if defined(RTEMS_MULTIPROCESSING)
     ,
Index: cpukit/posix/src/mqueuecreatesupp.c
===================================================================
--- cpukit/posix/src/mqueuecreatesupp.c	(revision 68cc3adb75d2b2084f75291f4801eb16362d7c8c)
+++ cpukit/posix/src/mqueuecreatesupp.c	(revision 652524d9538f50e229349314043cedb5a15f18be)
@@ -19,4 +19,5 @@
 #endif
 
+#include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -30,7 +31,11 @@
 #include <rtems/system.h>
 #include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
 #include <rtems/seterr.h>
 #include <rtems/posix/mqueue.h>
 #include <rtems/posix/time.h>
+
+/* pure ANSI mode does not have this prototype */
+size_t strnlen(const char *, size_t);
 
 /*PAGE
@@ -43,5 +48,5 @@
  
 int _POSIX_Message_queue_Create_support(
-  const char                    *_name,
+  const char                    *name_arg,
   int                            pshared,
   struct mq_attr                *attr_ptr,
@@ -52,5 +57,10 @@
   CORE_message_queue_Attributes *the_mq_attr;
   struct mq_attr                 attr;
-  char *name;
+  char                          *name;
+  size_t                         n;
+
+  n = strnlen( name_arg, NAME_MAX );
+  if ( n > NAME_MAX ) 
+    return ENAMETOOLONG;
 
   _Thread_Disable_dispatch();
@@ -101,4 +111,16 @@
   the_mq->linked = TRUE;
 
+  /*
+   * Make a copy of the user's string for name just in case it was
+   * dynamically constructed.
+   */
+
+  name = _Workspace_Allocate(n);
+  if (!name) {
+    _POSIX_Message_queue_Free( the_mq );
+    _Thread_Enable_dispatch();
+    rtems_set_errno_and_return_minus_one( ENOMEM );
+  }
+  strcpy( name, name_arg );
  
   /* XXX
@@ -124,10 +146,9 @@
  
     _POSIX_Message_queue_Free( the_mq );
+    _Workspace_Free(name);
     _Thread_Enable_dispatch();
     rtems_set_errno_and_return_minus_one( ENOSPC );
   }
 
-  name = malloc(256);
-  strcpy( name, _name );
   _Objects_Open(
     &_POSIX_Message_queue_Information,
Index: cpukit/posix/src/mqueuedeletesupp.c
===================================================================
--- cpukit/posix/src/mqueuedeletesupp.c	(revision 68cc3adb75d2b2084f75291f4801eb16362d7c8c)
+++ cpukit/posix/src/mqueuedeletesupp.c	(revision 652524d9538f50e229349314043cedb5a15f18be)
@@ -29,4 +29,5 @@
 #include <rtems/system.h>
 #include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
 #include <rtems/seterr.h>
 #include <rtems/posix/mqueue.h>
@@ -43,4 +44,8 @@
 {
   if ( !the_mq->linked && !the_mq->open_count ) {
+      /* the name memory may have been freed by unlink. */
+      if ( the_mq->Object.name )
+        _Workspace_Free( the_mq->Object.name );
+
       _Objects_Close( &_POSIX_Message_queue_Information, &the_mq->Object );
  
Index: cpukit/posix/src/mqueueunlink.c
===================================================================
--- cpukit/posix/src/mqueueunlink.c	(revision 68cc3adb75d2b2084f75291f4801eb16362d7c8c)
+++ cpukit/posix/src/mqueueunlink.c	(revision 652524d9538f50e229349314043cedb5a15f18be)
@@ -29,4 +29,5 @@
 #include <rtems/system.h>
 #include <rtems/score/watchdog.h>
+#include <rtems/score/wkspace.h>
 #include <rtems/seterr.h>
 #include <rtems/posix/mqueue.h>
@@ -76,4 +77,5 @@
  
   the_mq->linked = FALSE;
+  _Workspace_Free( the_mq->Object.name );
   _POSIX_Message_queue_Namespace_remove( the_mq );
   _POSIX_Message_queue_Delete( the_mq );
