Skip to contentSkip to conversation

cobalt/posix/mutex: Harmonize pthread_mutex_timedlock() and sem_timedwait()

PATCH In review Florian Bezdeka 2 participants 3 messages Jul 29, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 cobalt/posix/mutex: Harmonize pthread_mutex_timedlock() and sem_timedwait()

According to the POSIX spec the value of the timeout parameter needs not to be validated if the mutex/semaphore could be taken immediately.

While the implementation of the semaphore timedwait (sem_timedwait()) allowed an invalid timeout pthread_mutex_timedlock() was failing with -EFAULT in case the mutex could be taken immediately.

---

This was detected while preparing y2038 stuff. Not sure if that should go into 3.2. Comments welcome...

CCed Philippe because he was already involved some (long) time ago.

Regards,
Florian

 testsuite/smokey/posix-mutex/posix-mutex.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testsuite/smokey/posix-mutex/posix-mutex.c +2 -2
index 0f4dbe739..4aad24964 100644
@@ -1007,7 +1007,7 @@ static void *mutex_timed_locker_inv_timeout(void *arg)
 	struct locker_context *p = arg;
 	int ret;
 
-	if (__F(ret, pthread_mutex_timedlock(p->mutex, (void*) 0xdeadbeef)) &&
+	if (__F(ret, pthread_mutex_timedlock(p->mutex, (void *) 0xdeadbeef)) &&
 	    __Tassert(ret == -EFAULT))
 		return (void *)1;
 
@@ -1032,7 +1032,7 @@ static int check_timedlock_abstime_validation(void)
 	 * The second parameter of phtread_mutex_timedlock() is flagged as
 	 * __nonnull so we take an invalid address instead of NULL.
 	 */
-	if (!__T(ret, pthread_mutex_timedlock(&mutex, (void*) 0xdeadbeef)))
+	if (!__T(ret, pthread_mutex_timedlock(&mutex, (void *) 0xdeadbeef)))
 		return ret;
 
 	/*
Signature · 1 line
2.30.2
#1 lore raw

Please ignore this one... Local tooling bug.

Quoted 46 lines · Florian Bezdeka

According to the POSIX spec the value of the timeout parameter needs not to be validated if the mutex/semaphore could be taken immediately.

While the implementation of the semaphore timedwait (sem_timedwait()) allowed an invalid timeout pthread_mutex_timedlock() was failing with -EFAULT in case the mutex could be taken immediately.

---

This was detected while preparing y2038 stuff. Not sure if that should go into 3.2. Comments welcome...

CCed Philippe because he was already involved some (long) time ago.

Regards,
Florian

 testsuite/smokey/posix-mutex/posix-mutex.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
testsuite/smokey/posix-mutex/posix-mutex.c +0 -0
index 0f4dbe739..4aad24964 100644
@@ -1007,7 +1007,7 @@ static void *mutex_timed_locker_inv_timeout(void *arg)
  	struct locker_context *p = arg;
  	int ret;

testsuite/smokey/posix-mutex/posix-mutex.c +1 -1
-	if (__F(ret, pthread_mutex_timedlock(p->mutex, (void*) 0xdeadbeef)) &&
+	if (__F(ret, pthread_mutex_timedlock(p->mutex, (void *) 0xdeadbeef)) &&

  __Tassert(ret == -EFAULT))
  return (void *)1;

testsuite/smokey/posix-mutex/posix-mutex.c +1 -1
@@ -1032,7 +1032,7 @@ static int check_timedlock_abstime_validation(void)
  	 * The second parameter of phtread_mutex_timedlock() is flagged as
  	 * __nonnull so we take an invalid address instead of NULL.
  	 */
-	if (!__T(ret, pthread_mutex_timedlock(&mutex, (void*) 0xdeadbeef)))
+	if (!__T(ret, pthread_mutex_timedlock(&mutex, (void *) 0xdeadbeef)))
  		return ret;

  /*

#2 lore raw
In reply to Florian Bezdeka
Quoted 7 lines · Florian Bezdeka

According to the POSIX spec the value of the timeout parameter needs not to be validated if the mutex/semaphore could be taken immediately.

While the implementation of the semaphore timedwait (sem_timedwait()) allowed an invalid timeout pthread_mutex_timedlock() was failing with -EFAULT in case the mutex could be taken immediately.

Quoted 8 lines

---

This was detected while preparing y2038 stuff. Not sure if that should go into 3.2. Comments welcome...

CCed Philippe because he was already involved some (long) time ago.

I do agree wholeheartedly with the fundamental whitespace cleanup!

Quoted 28 lines

Regards,
Florian

 testsuite/smokey/posix-mutex/posix-mutex.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
testsuite/smokey/posix-mutex/posix-mutex.c +2 -2
index 0f4dbe739..4aad24964 100644
@@ -1007,7 +1007,7 @@ static void *mutex_timed_locker_inv_timeout(void *arg)
 	struct locker_context *p = arg;
 	int ret;
 
-	if (__F(ret, pthread_mutex_timedlock(p->mutex, (void*) 0xdeadbeef)) &&
+	if (__F(ret, pthread_mutex_timedlock(p->mutex, (void *) 0xdeadbeef)) &&
 	    __Tassert(ret == -EFAULT))
 		return (void *)1;
 
@@ -1032,7 +1032,7 @@ static int check_timedlock_abstime_validation(void)
 	 * The second parameter of phtread_mutex_timedlock() is flagged as
 	 * __nonnull so we take an invalid address instead of NULL.
 	 */
-	if (!__T(ret, pthread_mutex_timedlock(&mutex, (void*) 0xdeadbeef)))
+	if (!__T(ret, pthread_mutex_timedlock(&mutex, (void *) 0xdeadbeef)))
 		return ret;
 
 	/*
Signature · 1 line
Philippe.