cobalt/posix/mutex: Harmonize pthread_mutex_timedlock() and sem_timedwait()
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
@@ -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
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 timeoutpthread_mutex_timedlock()was failing with-EFAULTin case the mutex could be taken immediately.Signed-off-by Florian Bezdeka <[email protected]>---
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,
Floriantestsuite/smokey/posix-mutex/posix-mutex.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)testsuite/smokey/posix-mutex/posix-mutex.c +0
-0@@ -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;/*
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 timeoutpthread_mutex_timedlock()was failing with-EFAULTin case the mutex could be taken immediately.
Quoted 8 lines
Signed-off-by Florian Bezdeka <[email protected]>---
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,
Floriantestsuite/smokey/posix-mutex/posix-mutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)testsuite/smokey/posix-mutex/posix-mutex.c +2
-2@@ -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.