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>
This commit is contained in:
David Allsopp 2021-07-20 16:07:00 +01:00 committed by Corinna Vinschen
parent 44a3966577
commit 51a297bcbf
2 changed files with 8 additions and 2 deletions

View File

@ -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);
}

View File

@ -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.