public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Ensure nanosleep(2) never returns negative rem
Date: Thu, 22 Jul 2021 07:58:58 +0000 (GMT)	[thread overview]
Message-ID: <20210722075858.C881A3858002@sourceware.org> (raw)

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

commit 51a297bcbf05f332462a577563234062660e6384
Author: David Allsopp <david.allsopp@metastack.com>
Date:   Tue Jul 20 16:07:00 2021 +0100

    Ensure nanosleep(2) never returns negative rem
    
    It appears to be the case that NtQueryTimer can return a negative time
    remaining for an unsignalled timer. The value appears to be less than
    the timer resolution.
    
    Signed-off-by: David Allsopp <david.allsopp@metastack.com>

Diff:
---
 winsup/cygwin/cygwait.cc    | 6 ++++--
 winsup/cygwin/release/3.2.1 | 4 ++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/cygwait.cc b/winsup/cygwin/cygwait.cc
index 1d6c7c9cc..dbbe1db6e 100644
--- a/winsup/cygwin/cygwait.cc
+++ b/winsup/cygwin/cygwait.cc
@@ -104,8 +104,10 @@ cygwait (HANDLE object, PLARGE_INTEGER timeout, unsigned mask)
 		    sizeof tbi, NULL);
       /* if timer expired, TimeRemaining is negative and represents the
 	  system uptime when signalled */
-      if (timeout->QuadPart < 0LL)
-	timeout->QuadPart = tbi.SignalState ? 0LL : tbi.TimeRemaining.QuadPart;
+      if (timeout->QuadPart < 0LL) {
+	timeout->QuadPart = tbi.SignalState || tbi.TimeRemaining.QuadPart < 0LL
+                            ? 0LL : tbi.TimeRemaining.QuadPart;
+      }
       NtCancelTimer (_my_tls.locals.cw_timer, NULL);
     }
 
diff --git a/winsup/cygwin/release/3.2.1 b/winsup/cygwin/release/3.2.1
index 4f4db622a..2a339718c 100644
--- a/winsup/cygwin/release/3.2.1
+++ b/winsup/cygwin/release/3.2.1
@@ -44,3 +44,7 @@ Bug Fixes
   AF_UNSPEC.  As specified by POSIX and Linux, this is allowed on
   datagram sockets, and its effect is to reset the socket's peer
   address.
+
+- Fix nanosleep(2) returning negative rem. NtQueryTimer appears to be able to
+  return a negative remaining time (less than the timer resolution) for
+  unsignalled timers.


                 reply	other threads:[~2021-07-22  7:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210722075858.C881A3858002@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).