From 74f418b29d1e9463028f2ae4cc2a9c74d39aeaab Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 29 Oct 2020 15:34:31 -0300 Subject: nptl: Return EINVAL for pthread_mutex_clocklock/PI with CLOCK_MONOTONIC [BZ #26801] Linux futex FUTEX_LOCK_PI operation only supports CLOCK_REALTIME, so pthread_mutex_clocklock operation with priority aware mutexes may fail depending of the input timeout. Also, it is not possible to convert a CLOCK_MONOTONIC to a CLOCK_REALTIME due the possible wall clock time change which might invalid the requested timeout. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski --- nptl/pthread_mutex_timedlock.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'nptl/pthread_mutex_timedlock.c') diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index b42862193a..aaaafa21ce 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -313,6 +313,13 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, case PTHREAD_MUTEX_PI_ROBUST_NORMAL_NP: case PTHREAD_MUTEX_PI_ROBUST_ADAPTIVE_NP: { + /* Currently futex FUTEX_LOCK_PI operation only provides support for + CLOCK_REALTIME and trying to emulate by converting a + CLOCK_MONOTONIC to CLOCK_REALTIME will take in account possible + changes to the wall clock. */ + if (__glibc_unlikely (clockid != CLOCK_REALTIME)) + return EINVAL; + int kind, robust; { /* See concurrency notes regarding __kind in struct __pthread_mutex_s -- cgit 1.4.1