public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited] htl: Fix sem_wait race between read and gsync_wait
@ 2022-12-29 23:42 Samuel Thibault
  0 siblings, 0 replies; only message in thread
From: Samuel Thibault @ 2022-12-29 23:42 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault, commit-hurd

If the value changes between sem_wait's read and the gsync_wait call,
the kernel will return KERN_INVALID_ARGUMENT, which we have to interpret
as the value having already changed.

This fixes applications (e.g. libgo) seeing sem_wait erroneously return
KERN_INVALID_ARGUMENT.
---
 sysdeps/htl/sem-timedwait.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/htl/sem-timedwait.c b/sysdeps/htl/sem-timedwait.c
index 1b1eec9f59..c610804b08 100644
--- a/sysdeps/htl/sem-timedwait.c
+++ b/sysdeps/htl/sem-timedwait.c
@@ -79,7 +79,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
 		      ((unsigned int *) &sem->data) + SEM_VALUE_OFFSET,
 		      0, flags);
 
-	  if (err != 0)
+	  if (err != 0 && err != KERN_INVALID_ARGUMENT)
 	    {
 	      /* Error, interruption or timeout, abort.  */
 	      if (err == KERN_TIMEDOUT)
@@ -138,7 +138,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
 		err = __lll_wait_intr (&isem->value,
 			  SEM_NWAITERS_MASK, flags);
 
-	      if (err != 0)
+	      if (err != 0 && err != KERN_INVALID_ARGUMENT)
 		{
 		  /* Error, interruption or timeout, abort.  */
 		  if (err == KERN_TIMEDOUT)
-- 
2.35.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-29 23:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-29 23:42 [hurd,commited] htl: Fix sem_wait race between read and gsync_wait Samuel Thibault

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