aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2024-08-25 03:35:29 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2024-08-25 03:35:29 +0200
commitf071795d80255755c4f3d2bdc6c55e67753b52b9 (patch)
tree67a303b570cfd6336d5e7c8e9ce00e876ca6662a
parent82b5340ebdb8f00589d548e6e2dc8c998f07d0c5 (diff)
downloadglibc-f071795d80255755c4f3d2bdc6c55e67753b52b9.zip
glibc-f071795d80255755c4f3d2bdc6c55e67753b52b9.tar.gz
glibc-f071795d80255755c4f3d2bdc6c55e67753b52b9.tar.bz2
mach: Fix bogus negative return
One can be very unlucky to call time_now first just before a second switch, and mach_msg sleep just a bit more enough for the second time_now call to count one second too many (or even more if scheduling is really unlucky). So we have to protect against returning a bogus negative value in such case.
-rw-r--r--sysdeps/mach/sleep.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c
index 572be15..aa750c1 100644
--- a/sysdeps/mach/sleep.c
+++ b/sysdeps/mach/sleep.c
@@ -43,6 +43,9 @@ __sleep (unsigned int seconds)
after = time_now ();
__mach_port_destroy (__mach_task_self (), recv);
+ if (after - before > seconds)
+ return 0;
+
return seconds - (after - before);
}
weak_alias (__sleep, sleep)