https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2644508ff8144e534dfcd2c7d1aef38c4eacadf8

commit 2644508ff8144e534dfcd2c7d1aef38c4eacadf8
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Mon Jan 27 20:56:01 2025 +0100
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Mon Jan 27 22:17:33 2025 +0100

    Cygwin: message queues: avoid deadlocks in multi-threaded processes
    
    Deadlocks have been observed if the message queue functions are called
    from different threads in the same process.
    
    Remove incorrectly locking the descriptor table while accessing the
    message queue fhandler, potentially calling blocking functions.
    
    Fixes: 46f3b0ce85a9 ("Cygwin: POSIX msg queues: move all mq_* functionality 
into fhandler_mqueue")
    Reported-by: Christian Franke <[email protected]>
    Signed-off-by: Corinna Vinschen <[email protected]>
    (cherry picked from commit fe6ddc15a35636ca7027c32e4c60ebb136fc9d7f)

Diff:
---
 winsup/cygwin/posix_ipc.cc  | 10 +++++-----
 winsup/cygwin/release/3.5.7 |  4 ++++
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/posix_ipc.cc b/winsup/cygwin/posix_ipc.cc
index 2650c35aca8a..c188b0ce21e1 100644
--- a/winsup/cygwin/posix_ipc.cc
+++ b/winsup/cygwin/posix_ipc.cc
@@ -224,7 +224,7 @@ mq_getattr (mqd_t mqd, struct mq_attr *mqstat)
 {
   int ret = -1;
 
-  cygheap_fdget fd ((int) mqd, true);
+  cygheap_fdget fd ((int) mqd);
   if (fd >= 0)
     {
       fhandler_mqueue *fh = fd->is_mqueue ();
@@ -241,7 +241,7 @@ mq_setattr (mqd_t mqd, const struct mq_attr *mqstat, struct 
mq_attr *omqstat)
 {
   int ret = -1;
 
-  cygheap_fdget fd ((int) mqd, true);
+  cygheap_fdget fd ((int) mqd);
   if (fd >= 0)
     {
       fhandler_mqueue *fh = fd->is_mqueue ();
@@ -258,7 +258,7 @@ mq_notify (mqd_t mqd, const struct sigevent *notification)
 {
   int ret = -1;
 
-  cygheap_fdget fd ((int) mqd, true);
+  cygheap_fdget fd ((int) mqd);
   if (fd >= 0)
     {
       fhandler_mqueue *fh = fd->is_mqueue ();
@@ -276,7 +276,7 @@ mq_timedsend (mqd_t mqd, const char *ptr, size_t len, 
unsigned int prio,
 {
   int ret = -1;
 
-  cygheap_fdget fd ((int) mqd, true);
+  cygheap_fdget fd ((int) mqd);
   if (fd >= 0)
     {
       fhandler_mqueue *fh = fd->is_mqueue ();
@@ -300,7 +300,7 @@ mq_timedreceive (mqd_t mqd, char *ptr, size_t maxlen, 
unsigned int *priop,
 {
   int ret = -1;
 
-  cygheap_fdget fd ((int) mqd, true);
+  cygheap_fdget fd ((int) mqd);
   if (fd >= 0)
     {
       fhandler_mqueue *fh = fd->is_mqueue ();
diff --git a/winsup/cygwin/release/3.5.7 b/winsup/cygwin/release/3.5.7
index 12180efd9a82..87baa3ada56f 100644
--- a/winsup/cygwin/release/3.5.7
+++ b/winsup/cygwin/release/3.5.7
@@ -3,3 +3,7 @@ Fixes:
 
 - Fix stat() on message queues.
   Addresses: https://cygwin.com/pipermail/cygwin/2025-January/257186.html
+
+- Avoid deadlocks when calling message queue functions from different threads
+  in the same process.
+  Addresses: https://cygwin.com/pipermail/cygwin/2025-January/257120.html

Reply via email to