[hurd,commited,1/3] hurd: fix usleep(ULONG_MAX)

Message ID 20200629003218.794639-2-samuel.thibault@ens-lyon.org
State New
Headers show
Series
  • hurd: More cancelation point work
Related show

Commit Message

Samuel Thibault June 29, 2020, 12:32 a.m.
* sysdeps/mach/usleep.c (usleep): Clamp timeout when rouding up.
---
 sysdeps/mach/usleep.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
2.27.0

Comments

Andreas Schwab June 29, 2020, 7:58 a.m. | #1
On Jun 29 2020, Samuel Thibault wrote:

>    (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,

> -		     0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL);

> +		     0, 0, recv, useconds_up / 1000, MACH_PORT_NULL);


Perhaps it should be written as useconds / 1000 + (useconds % 1000 !=
0).

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Samuel Thibault June 29, 2020, 8:12 a.m. | #2
Andreas Schwab, le lun. 29 juin 2020 09:58:12 +0200, a ecrit:
> On Jun 29 2020, Samuel Thibault wrote:

> 

> >    (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,

> > -		     0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL);

> > +		     0, 0, recv, useconds_up / 1000, MACH_PORT_NULL);

> 

> Perhaps it should be written as useconds / 1000 + (useconds % 1000 !=

> 0).


Right, that's less hardcoding indeed :)

Samuel

Patch

diff --git a/sysdeps/mach/usleep.c b/sysdeps/mach/usleep.c
index 530336ba0b..d53eb04a51 100644
--- a/sysdeps/mach/usleep.c
+++ b/sysdeps/mach/usleep.c
@@ -25,11 +25,15 @@  int
 usleep (useconds_t useconds)
 {
   mach_port_t recv;
+  useconds_t useconds_up = useconds + 999;
+
+  if (useconds_up < useconds)
+    useconds_up = UINT32_MAX;
 
   recv = __mach_reply_port ();
 
   (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT,
-		     0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL);
+		     0, 0, recv, useconds_up / 1000, MACH_PORT_NULL);
   __mach_port_destroy (mach_task_self (), recv);
 
   return 0;