This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
passing private flag to SYS_futex in sem_post on x86_64
- From: "Petar Jovanovic" <petar dot jovanovic at rt-rk dot com>
- To: <libc-alpha at sourceware dot org>
- Date: Thu, 13 Sep 2012 14:49:10 +0200
- Subject: passing private flag to SYS_futex in sem_post on x86_64
Implementation of sem_post for i386/x86_64 (sem_post.S) is slightly
different
than c-implementation on other architectures. In some tests that
(deliberately)
abuse futex and check for program behaviour, results are different on x86 on
one
side and MIPS and ARM (to name a few) on the other side.
When sem_t gets overwritten, data in it is incorrect. It seems that
sem_post.S
does not think this can happen, and thus relies on isem->private to have a
correct value.
Is this correct behaviour? If not, we could add a small change like this:
diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
index 65e715d..9cb7efa 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
@@ -49,8 +49,9 @@ sem_post:
je 2f
movl $SYS_futex, %eax
- movl $FUTEX_WAKE, %esi
- orl PRIVATE(%rdi), %esi
+ movl PRIVATE(%rdi), %esi
+ andl $FUTEX_PRIVATE_FLAG, %esi
+ orl $FUTEX_WAKE, %esi
movl $1, %edx
syscall
This way, similar to other architectures, we isolate private flag from the
variable private, and then use it to 'or' with FUTEX_WAKE.
This will also get us rid of strange logs in strace such as:
futex(0x7fff07dddf20, 0x55555555 /* FUTEX_??? */, 1) = -1 ENOSYS (Function
not implemented)
What do you say?
Regards,
Petar