[BZ,19944] nptl/pthread_mutex*lock: don't ignore unknown error codes
Commit Message
pthread_mutex_lock(), pthread_mutex_trylock() and pthread_mutex_unlock()
ignore the return code from the futex syscall unless it is something
the function expects.
This patch forwards the error code to the user instead of simply
ignoring it.
2016-04-13 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
[BZ #19944]
* nptl/pthread_mutex_lock.c: return unhandled sys_futex error.
* nptl/pthread_mutex_trylock.c: return unhandled sys_futex
error.
* nptl/pthread_mutex_unlock.c: return unhandled sys_futex error.
---
nptl/pthread_mutex_lock.c | 3 ++-
nptl/pthread_mutex_trylock.c | 2 ++
nptl/pthread_mutex_unlock.c | 5 ++++-
3 files changed, 8 insertions(+), 2 deletions(-)
Comments
I won't bother with the several style problems in your patch. Please see
previous discussions about the futex error cases. Torvald was leading the
charge on converting things to use the new internal layers that handle
futex error checking. The only changes we want are in that direction.
Thanks,
Roland
On 2016-04-13 13:15:14 [-0700], Roland McGrath wrote:
> I won't bother with the several style problems in your patch. Please see
> previous discussions about the futex error cases. Torvald was leading the
> charge on converting things to use the new internal layers that handle
> futex error checking. The only changes we want are in that direction.
Are we talking about this thread:
https://sourceware.org/ml/libc-alpha/2014-09/msg00381.html
Subject: Futex error handling
Date: Tue, 16 Sep 2014 17:36:25 +0200
> Thanks,
> Roland
Sebastian
On Wed, 2016-04-13 at 22:52 +0200, Sebastian Andrzej Siewior wrote:
> On 2016-04-13 13:15:14 [-0700], Roland McGrath wrote:
> > I won't bother with the several style problems in your patch. Please see
> > previous discussions about the futex error cases. Torvald was leading the
> > charge on converting things to use the new internal layers that handle
> > futex error checking. The only changes we want are in that direction.
>
> Are we talking about this thread:
> https://sourceware.org/ml/libc-alpha/2014-09/msg00381.html
>
> Subject: Futex error handling
> Date: Tue, 16 Sep 2014 17:36:25 +0200
That is the start of it. The result is that we have a new
glibc-internal futex interface that does error checking, see
sysdeps/unix/sysv/linux/futex-internal.h and
sysdeps/nptl/futex-internal.h for details.
The way we handle futex errors should be consistent with what we do in
there; if you spot missing errors we do not test for explicitly (ie,
which are listed in the updated futex manpage but not part of the glibc
code), please fix this in the wrappers.
Regarding the mutex changes, what we should do there eventually is use
the new futex interface. We cannot just forward errors to the callers
of POSIX functions because POSIX might not specify the same error codes
as futexes do.
@@ -354,7 +354,8 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
/* Delay the thread indefinitely. */
while (1)
pause_not_cancel ();
- }
+ } else if (INTERNAL_SYSCALL_ERROR_P (e, __err))
+ return INTERNAL_SYSCALL_ERRNO (e, __err);
oldval = mutex->__data.__lock;
@@ -265,6 +265,8 @@ __pthread_mutex_trylock (pthread_mutex_t *mutex)
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);
return EBUSY;
+ } else if (INTERNAL_SYSCALL_ERROR_P (e, __err)) {
+ return INTERNAL_SYSCALL_ERRNO (e, __err);
}
oldval = mutex->__data.__lock;
@@ -243,8 +243,11 @@ __pthread_mutex_unlock_full (pthread_mutex_t *mutex, int decr)
tid)))
{
INTERNAL_SYSCALL_DECL (__err);
- INTERNAL_SYSCALL (futex, __err, 2, &mutex->__data.__lock,
+ int e = INTERNAL_SYSCALL (futex, __err, 2, &mutex->__data.__lock,
__lll_private_flag (FUTEX_UNLOCK_PI, private));
+
+ if (INTERNAL_SYSCALL_ERROR_P (e, __err))
+ return INTERNAL_SYSCALL_ERRNO (e, __err);
}
THREAD_SETMEM (THREAD_SELF, robust_head.list_op_pending, NULL);