summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/i386
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2015-03-25 15:17:54 +0000
committerJoseph Myers <joseph@codesourcery.com>2015-03-25 15:17:54 +0000
commita9fe4c5aa8e53ee30f7d0a1c878391d5d6324e6e (patch)
treeb57c4c83b9a6758d50264de82f0e4a09c9bde4b1 /sysdeps/unix/sysv/linux/i386
parentafcd9480feca651eef436d8438b783dde5c3bbb2 (diff)
downloadglibc-a9fe4c5aa8e53ee30f7d0a1c878391d5d6324e6e.tar.gz
glibc-a9fe4c5aa8e53ee30f7d0a1c878391d5d6324e6e.tar.xz
glibc-a9fe4c5aa8e53ee30f7d0a1c878391d5d6324e6e.zip
Support six-argument syscalls from C for 32-bit x86, use generic lowlevellock-futex.h (bug 18138).
This patch follows the approach outlined in
<https://sourceware.org/ml/libc-alpha/2015-03/msg00656.html> to
support six-argument syscalls from INTERNAL_SYSCALL for 32-bit x86,
making them call a function __libc_do_syscall that takes the syscall
number and three syscall arguments in the registers in which the
kernel expects them, along with a pointer to a structure containing
the other three arguments.

In turn, this allows the generic lowlevellock-futex.h to be used on
32-bit x86, so supporting lll_futex_timed_wait_bitset (and so allowing
FUTEX_CLOCK_REALTIME to be used in various cases, so fixing bug 18138
for 32-bit x86 and leaving hppa as the only architecture missing
lll_futex_timed_wait_bitset).  The change to lowlevellock.h's
definition of SYS_futex is because the generic lowlevelloc-futex.h
ends up bringing in bits/syscall.h which defines SYS_futex to
__NR_futex, so resulting in redefinition errors.  The revised
definition in lowlevellock.h is in line with what the x86_64 version
does.

__libc_do_syscall is only needed in libpthread at present (meaning
nothing special needs to be done to make it shared-only in most
libraries containing it, static in libc only, as on ARM).

Tested for 32-bit x86, with the glibc testsuite and with the test in
bug 18138.  The failures seen

FAIL: nptl/tst-cleanupx4
FAIL: rt/tst-cpuclock2

are pre-existing.

	[BZ #18138]
	* sysdeps/unix/sysv/linux/i386/sysdep.h (struct
	libc_do_syscall_args): New structure.
	(INTERNAL_SYSCALL_MAIN_0): New macro.
	(INTERNAL_SYSCALL_MAIN_1): Likewise.
	(INTERNAL_SYSCALL_MAIN_2): Likewise.
	(INTERNAL_SYSCALL_MAIN_3): Likewise.
	(INTERNAL_SYSCALL_MAIN_4): Likewise.
	(INTERNAL_SYSCALL_MAIN_5): Likewise.
	(INTERNAL_SYSCALL_MAIN_6): Likewise.  Call __libc_do_syscall.
	(INTERNAL_SYSCALL): Define to use INTERNAL_SYSCALL_MAIN_##nr.
	Replace conditional definitions by conditional definitions of ....
	(INTERNAL_SYSCALL_MAIN_INLINE): ... this.  New macro.
	* sysdeps/unix/sysv/linux/i386/libc-do-syscall.S: New file.
	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = nptl]
	(libpthread-sysdep_routines): Add libc-do-syscall.
	* sysdeps/unix/sysv/linux/i386/lowlevellock-futex.h: Remove file.
	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (SYS_futex): Define
	to __NR_futex not 240.
Diffstat (limited to 'sysdeps/unix/sysv/linux/i386')
-rw-r--r--sysdeps/unix/sysv/linux/i386/Makefile5
-rw-r--r--sysdeps/unix/sysv/linux/i386/libc-do-syscall.S50
-rw-r--r--sysdeps/unix/sysv/linux/i386/lowlevellock-futex.h137
-rw-r--r--sysdeps/unix/sysv/linux/i386/lowlevellock.h2
-rw-r--r--sysdeps/unix/sysv/linux/i386/sysdep.h65
5 files changed, 106 insertions, 153 deletions
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index acc30219e8..d7a59d345d 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -14,6 +14,11 @@ ifeq ($(subdir),io)
 sysdep_routines += call_sync_file_range
 endif
 
+# libpthread uses six-argument inline syscalls.
+ifeq ($(subdir),nptl)
+libpthread-sysdep_routines += libc-do-syscall
+endif
+
 ifeq ($(subdir),resource)
 sysdep_routines += oldgetrlimit64
 endif
diff --git a/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S b/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S
new file mode 100644
index 0000000000..af5c6f05a6
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/libc-do-syscall.S
@@ -0,0 +1,50 @@
+/* Out-of-line syscall stub for six-argument syscalls from C.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* %eax, %ecx, %edx and %esi contain the values expected by the kernel.
+   %edi points to a structure with the values of %ebx, %edi and %ebp.  */
+
+	.hidden __libc_do_syscall
+
+ENTRY (__libc_do_syscall)
+	pushl	%ebx
+	cfi_adjust_cfa_offset (4)
+	cfi_rel_offset (ebx, 0)
+	pushl	%edi
+	cfi_adjust_cfa_offset (4)
+	cfi_rel_offset (edi, 0)
+	pushl	%ebp
+	cfi_adjust_cfa_offset (4)
+	cfi_rel_offset (ebp, 0)
+	movl	0(%edi), %ebx
+	movl	8(%edi), %ebp
+	movl	4(%edi), %edi
+	ENTER_KERNEL
+	popl	%ebp
+	cfi_adjust_cfa_offset (-4)
+	cfi_restore (ebp)
+	popl	%edi
+	cfi_adjust_cfa_offset (-4)
+	cfi_restore (edi)
+	popl	%ebx
+	cfi_adjust_cfa_offset (-4)
+	cfi_restore (ebx)
+	ret
+END (__libc_do_syscall)
diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/i386/lowlevellock-futex.h
deleted file mode 100644
index f08b5b8497..0000000000
--- a/sysdeps/unix/sysv/linux/i386/lowlevellock-futex.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/* Low-level locking access to futex facilities.  Linux/i386 version.
-   Copyright (C) 2014-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifndef _LOWLEVELLOCK_FUTEX_H
-#define _LOWLEVELLOCK_FUTEX_H	1
-
-#define FUTEX_WAIT		0
-#define FUTEX_WAKE		1
-#define FUTEX_CMP_REQUEUE	4
-#define FUTEX_WAKE_OP		5
-#define FUTEX_LOCK_PI		6
-#define FUTEX_UNLOCK_PI		7
-#define FUTEX_TRYLOCK_PI	8
-#define FUTEX_WAIT_BITSET	9
-#define FUTEX_WAKE_BITSET	10
-#define FUTEX_WAIT_REQUEUE_PI	11
-#define FUTEX_CMP_REQUEUE_PI	12
-#define FUTEX_PRIVATE_FLAG	128
-#define FUTEX_CLOCK_REALTIME	256
-
-#define FUTEX_BITSET_MATCH_ANY	0xffffffff
-
-#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE	((4 << 24) | 1)
-
-/* Values for 'private' parameter of locking macros.  Yes, the
-   definition seems to be backwards.  But it is not.  The bit will be
-   reversed before passing to the system call.  */
-#define LLL_PRIVATE	0
-#define LLL_SHARED	FUTEX_PRIVATE_FLAG
-
-
-#if IS_IN (libc) || IS_IN (rtld)
-/* In libc.so or ld.so all futexes are private.  */
-# ifdef __ASSUME_PRIVATE_FUTEX
-#  define __lll_private_flag(fl, private) \
-  ((fl) | FUTEX_PRIVATE_FLAG)
-# else
-#  define __lll_private_flag(fl, private) \
-  ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))
-# endif
-#else
-# ifdef __ASSUME_PRIVATE_FUTEX
-#  define __lll_private_flag(fl, private) \
-  (((fl) | FUTEX_PRIVATE_FLAG) ^ (private))
-# else
-#  define __lll_private_flag(fl, private) \
-  (__builtin_constant_p (private)					      \
-   ? ((private) == 0							      \
-      ? ((fl) | THREAD_GETMEM (THREAD_SELF, header.private_futex))	      \
-      : (fl))								      \
-   : ({ unsigned int __fl = ((private) ^ FUTEX_PRIVATE_FLAG);		      \
-	asm ("andl %%gs:%P1, %0" : "+r" (__fl)				      \
-	     : "i" (offsetof (struct pthread, header.private_futex)));	      \
-	__fl | (fl); }))
-# endif
-#endif
-
-
-#ifndef __ASSEMBLER__
-
-/* To avoid naming conflicts with lowlevellock.h, use a different prefix
-   here.  */
-#ifdef PIC
-# define LLLF_EBX_LOAD	"xchgl %2, %%ebx\n"
-# define LLLF_EBX_REG	"D"
-#else
-# define LLLF_EBX_LOAD
-# define LLLF_EBX_REG	"b"
-#endif
-
-#ifdef I386_USE_SYSENTER
-# ifdef SHARED
-#  define LLLF_ENTER_KERNEL	"call *%%gs:%P6\n\t"
-# else
-#  define LLLF_ENTER_KERNEL	"call *_dl_sysinfo\n\t"
-# endif
-#else
-# define LLLF_ENTER_KERNEL	"int $0x80\n\t"
-#endif
-
-
-#define lll_futex_wait(futex, val, private) \
-  lll_futex_timed_wait (futex, val, NULL, private)
-
-
-#define lll_futex_timed_wait(futex, val, timeout, private) \
-  ({									      \
-    int __status;							      \
-    register __typeof (val) _val asm ("edx") = (val);			      \
-    __asm __volatile (LLLF_EBX_LOAD					      \
-		      LLLF_ENTER_KERNEL					      \
-		      LLLF_EBX_LOAD					      \
-		      : "=a" (__status)					      \
-		      : "0" (SYS_futex), LLLF_EBX_REG (futex), "S" (timeout),  \
-			"c" (__lll_private_flag (FUTEX_WAIT, private)),	      \
-			"d" (_val), "i" (offsetof (tcbhead_t, sysinfo))	      \
-		      : "memory");					      \
-    __status;								      \
-  })
-
-
-#define lll_futex_wake(futex, nr, private) \
-  ({									      \
-    int __status;							      \
-    register __typeof (nr) _nr asm ("edx") = (nr);			      \
-    LIBC_PROBE (lll_futex_wake, 3, futex, nr, private);                       \
-    __asm __volatile (LLLF_EBX_LOAD					      \
-		      LLLF_ENTER_KERNEL					      \
-		      LLLF_EBX_LOAD					      \
-		      : "=a" (__status)					      \
-		      : "0" (SYS_futex), LLLF_EBX_REG (futex),		      \
-			"c" (__lll_private_flag (FUTEX_WAKE, private)),	      \
-			"d" (_nr),					      \
-			"i" (0) /* phony, to align next arg's number */,      \
-			"i" (offsetof (tcbhead_t, sysinfo)));		      \
-    __status;								      \
-  })
-
-
-#endif  /* !__ASSEMBLER__ */
-
-#endif	/* lowlevellock-futex.h */
diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
index 1132124308..2bf251fbc6 100644
--- a/sysdeps/unix/sysv/linux/i386/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
@@ -48,7 +48,7 @@
 #include <lowlevellock-futex.h>
 
 /* XXX Remove when no assembler code uses futexes anymore.  */
-#define SYS_futex		240
+#define SYS_futex		__NR_futex
 
 #ifndef __ASSEMBLER__
 
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 180f334240..7f6fcf3288 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -304,6 +304,17 @@ asm (".L__X'%ebx = 1\n\t"
      ".endif\n\t"
      ".endm\n\t");
 
+/* Six-argument syscalls use an out-of-line helper, because an inline
+   asm using all registers apart from %esp cannot work reliably and
+   the assembler does not support describing an asm that saves and
+   restores %ebp itself as a separate stack frame.  This structure
+   stores the arguments not passed in registers; %edi is passed with a
+   pointer to this structure.  */
+struct libc_do_syscall_args
+{
+  int ebx, edi, ebp;
+};
+
 /* Define a macro which expands inline into the wrapper code for a system
    call.  */
 #undef INLINE_SYSCALL
@@ -325,11 +336,42 @@ asm (".L__X'%ebx = 1\n\t"
    The _NCS variant allows non-constant syscall numbers but it is not
    possible to use more than four parameters.  */
 #undef INTERNAL_SYSCALL
-#ifdef I386_USE_SYSENTER
-# ifdef SHARED
-#  define INTERNAL_SYSCALL(name, err, nr, args...) \
+#define INTERNAL_SYSCALL_MAIN_0(name, err, args...) \
+    INTERNAL_SYSCALL_MAIN_INLINE(name, err, 0, args)
+#define INTERNAL_SYSCALL_MAIN_1(name, err, args...) \
+    INTERNAL_SYSCALL_MAIN_INLINE(name, err, 1, args)
+#define INTERNAL_SYSCALL_MAIN_2(name, err, args...) \
+    INTERNAL_SYSCALL_MAIN_INLINE(name, err, 2, args)
+#define INTERNAL_SYSCALL_MAIN_3(name, err, args...) \
+    INTERNAL_SYSCALL_MAIN_INLINE(name, err, 3, args)
+#define INTERNAL_SYSCALL_MAIN_4(name, err, args...) \
+    INTERNAL_SYSCALL_MAIN_INLINE(name, err, 4, args)
+#define INTERNAL_SYSCALL_MAIN_5(name, err, args...) \
+    INTERNAL_SYSCALL_MAIN_INLINE(name, err, 5, args)
+/* Each object using 6-argument inline syscalls must include a
+   definition of __libc_do_syscall.  */
+#define INTERNAL_SYSCALL_MAIN_6(name, err, arg1, arg2, arg3,		\
+				arg4, arg5, arg6)			\
+  struct libc_do_syscall_args _xv =					\
+    {									\
+      (int) (arg1),							\
+      (int) (arg5),							\
+      (int) (arg6)							\
+    };									\
+    asm volatile (							\
+    "movl %1, %%eax\n\t"						\
+    "call __libc_do_syscall"						\
+    : "=a" (resultvar)							\
+    : "i" (__NR_##name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv) \
+    : "memory", "cc")
+#define INTERNAL_SYSCALL(name, err, nr, args...) \
   ({									      \
     register unsigned int resultvar;					      \
+    INTERNAL_SYSCALL_MAIN_##nr (name, err, args);			      \
+    (int) resultvar; })
+#ifdef I386_USE_SYSENTER
+# ifdef SHARED
+#  define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
     asm volatile (							      \
     LOADARGS_##nr							      \
@@ -338,8 +380,7 @@ asm (".L__X'%ebx = 1\n\t"
     RESTOREARGS_##nr							      \
     : "=a" (resultvar)							      \
     : "i" (__NR_##name), "i" (offsetof (tcbhead_t, sysinfo))		      \
-      ASMFMT_##nr(args) : "memory", "cc");				      \
-    (int) resultvar; })
+      ASMFMT_##nr(args) : "memory", "cc")
 #  define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({									      \
     register unsigned int resultvar;					      \
@@ -353,9 +394,7 @@ asm (".L__X'%ebx = 1\n\t"
       ASMFMT_##nr(args) : "memory", "cc");				      \
     (int) resultvar; })
 # else
-#  define INTERNAL_SYSCALL(name, err, nr, args...) \
-  ({									      \
-    register unsigned int resultvar;					      \
+#  define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
     asm volatile (							      \
     LOADARGS_##nr							      \
@@ -363,8 +402,7 @@ asm (".L__X'%ebx = 1\n\t"
     "call *_dl_sysinfo\n\t"						      \
     RESTOREARGS_##nr							      \
     : "=a" (resultvar)							      \
-    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");		      \
-    (int) resultvar; })
+    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc")
 #  define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({									      \
     register unsigned int resultvar;					      \
@@ -378,9 +416,7 @@ asm (".L__X'%ebx = 1\n\t"
     (int) resultvar; })
 # endif
 #else
-# define INTERNAL_SYSCALL(name, err, nr, args...) \
-  ({									      \
-    register unsigned int resultvar;					      \
+# define INTERNAL_SYSCALL_MAIN_INLINE(name, err, nr, args...) \
     EXTRAVAR_##nr							      \
     asm volatile (							      \
     LOADARGS_##nr							      \
@@ -388,8 +424,7 @@ asm (".L__X'%ebx = 1\n\t"
     "int $0x80\n\t"							      \
     RESTOREARGS_##nr							      \
     : "=a" (resultvar)							      \
-    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");		      \
-    (int) resultvar; })
+    : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc")
 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
   ({									      \
     register unsigned int resultvar;					      \