Commit 31b27c0b64 for qemu.org
commit 31b27c0b645e8c596e69027d714ce075f1374792
Author: Barnabás Pőcze <pobrn@protonmail.com>
Date: Thu Nov 19 19:12:53 2026 +0000
linux-user: do not emulate PI futexes given endianness mismatch
For PI futexes, the futex word is expected to contain the thread id in native
byte order. And failing to emulate that leads to issues as e.g. glibc does
not expect `ESRCH` to be returned from a `FUTEX_LOCK_PI` operation.
If the mutex is set to be "robust", then this is detected as unrecoverable
failure and glibc aborts (since a robust mutex should've been unlocked by
the kernel when the owner dies):
Fatal glibc error: pthread_mutex_lock.c:450 (__pthread_mutex_lock_full): assertion failed: e != ESRCH || !robust
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted (core dumped)
Since `FUTEX_LOCK_PI{,2}` cannot be easily emulated when the host and target
endianness differs, do not handle them, and return `ENOSYS`. This allows
e.g. glibc to detect that they do not work and handle things accordingly.
Link: https://gitlab.com/qemu-project/qemu/-/work_items/4911
Cc: qemu-stable@nongnu.org
Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Helge Deller <deller@gmx.de>
Tested-by: Helge Deller <deller@gmx.de> # on 32-bit parisc big endian guest
Signed-off-by: Helge Deller <deller@gmx.de>
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 350e69e2d0..d2a6cfb454 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8243,6 +8243,7 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
case FUTEX_WAIT_BITSET:
val = tswap32(val);
break;
+#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
case FUTEX_WAIT_REQUEUE_PI:
val = tswap32(val);
haddr2 = g2h(cpu, uaddr2);
@@ -8250,10 +8251,11 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
case FUTEX_LOCK_PI:
case FUTEX_LOCK_PI2:
break;
- case FUTEX_WAKE:
- case FUTEX_WAKE_BITSET:
case FUTEX_TRYLOCK_PI:
case FUTEX_UNLOCK_PI:
+#endif
+ case FUTEX_WAKE:
+ case FUTEX_WAKE_BITSET:
timeout = 0;
break;
case FUTEX_FD:
@@ -8261,7 +8263,9 @@ static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
timeout = 0;
break;
case FUTEX_CMP_REQUEUE:
+#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN
case FUTEX_CMP_REQUEUE_PI:
+#endif
val3 = tswap32(val3);
/* fall through */
case FUTEX_REQUEUE: