This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch azanella/bz12683 created. glibc-2.21-339-g30c1d83


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, azanella/bz12683 has been created
        at  30c1d83e03b58b1b956a664786108f8f50dc77ff (commit)

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=30c1d83e03b58b1b956a664786108f8f50dc77ff

commit 30c1d83e03b58b1b956a664786108f8f50dc77ff
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri May 8 17:12:31 2015 -0300

    nptl: arm: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the ARM modifications required for the BZ#12683 fix.
    It basically removes the enable_asynccancel/disable_asynccancel function
    usage on code, provide a arch-specific symbol that contains global
    markers to be used in SIGCANCEL handler.

diff --git a/ChangeLog b/ChangeLog
index 4649ab8..14531e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/arm/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/arm/sysdep-cancel.h (PSEUDO): Redefine
+	to call __syscall_cancel function for cancellable syscalls.
+	* sysdeps/unix/sysv/linux/arm/sysdep.h (SYSCALL_CANCEL_ERROR): Add
+	definition.
+	(SYSCALL_CANCEL_ERRNO): Likewise.
+
 	* sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S: New file.
 	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Redefine
 	to call __syscall_cancel function for cancellable syscalls.
diff --git a/sysdeps/unix/sysv/linux/arm/syscall_cancel.S b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
new file mode 100644
index 0000000..29d78c5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/arm/syscall_cancel.S
@@ -0,0 +1,56 @@
+/* Cancellable syscall wrapper - aarch64 version.
+   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>
+
+	.thumb
+	.syntax unified
+
+ENTRY (__syscall_cancel_arch)
+	.fnstart
+        mov	ip,sp
+        stmfd	sp!,{r4,r5,r6,r7,lr}
+	.save	{r4,r5,r6,r7,lr}
+
+	cfi_adjust_cfa_offset (20)
+	cfi_rel_offset (lr, 16)
+
+	.globl __syscall_cancel_arch_start
+__syscall_cancel_arch_start:
+
+        ldr	r0,[r0]
+	tst	r0, #4
+        bne	1f
+
+        mov	r7,r1
+        mov	r0,r2
+        mov	r1,r3
+        ldmfd	ip,{r2,r3,r4,r5,r6}
+        svc	0x0
+
+	.globl __syscall_cancel_arch_end
+__syscall_cancel_arch_end:
+	ldmfd	sp!,{r4,r5,r6,r7,lr}
+	cfi_adjust_cfa_offset (-16);
+        bx	lr
+
+1:
+	bl	__syscall_do_cancel
+	.fnend
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h b/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
index bdefa80..9f03bb5 100644
--- a/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h
@@ -19,10 +19,17 @@
 #include <tls.h>
 #ifndef __ASSEMBLER__
 # include <nptl/pthreadP.h>
+# include <sys/ucontext.h>
 #endif
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
+# if IS_IN (libc)
+#  define JMP_SYSCALL_CANCEL  HIDDEN_JUMPTARGET(__syscall_cancel)
+# else
+#  define JMP_SYSCALL_CANCEL  __syscall_cancel(PLT)
+# endif
+
 /* NOTE: We do mark syscalls with unwind annotations, for the benefit of
    cancellation; but they're really only accurate at the point of the
    syscall.  The ARM unwind directives are not rich enough without adding
@@ -31,16 +38,10 @@
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)				\
 	.text;								\
-  ENTRY (__##syscall_name##_nocancel);					\
-	CFI_SECTIONS;							\
-	DO_CALL (syscall_name, args);					\
-	cmn	r0, $4096;						\
-	PSEUDO_RET;							\
-  END (__##syscall_name##_nocancel);					\
   ENTRY (name);								\
 	SINGLE_THREAD_P;						\
-	DOARGS_##args;							\
 	bne .Lpseudo_cancel;						\
+	DOARGS_##args;							\
 	cfi_remember_state;						\
 	ldr	r7, =SYS_ify (syscall_name);				\
 	swi	0x0;							\
@@ -50,20 +51,31 @@
 	cfi_restore_state;						\
   .Lpseudo_cancel:							\
 	.fnstart;	/* matched by the .fnend in UNDOARGS below.  */	\
-	DOCARGS_##args;	/* save syscall args etc. around CENABLE.  */	\
-	CENABLE;							\
-	mov ip, r0;		/* put mask in safe place.  */		\
-	UNDOCARGS_##args;	/* restore syscall args.  */		\
-	ldr	r7, =SYS_ify (syscall_name);				\
-	swi	0x0;		/* do the call.  */			\
-	mov	r7, r0;		/* save syscall return value.  */	\
-	mov	r0, ip;		/* get mask back.  */			\
-	CDISABLE;							\
-	mov	r0, r7;		/* retrieve return value.  */		\
-	RESTORE_LR_##args;						\
-	UNDOARGS_##args;						\
+	push	{r4, r5, lr};						\
+	.save   {r4, r5, lr};						\
+	PSEUDO_CANCEL_BEFORE;						\
+	movw	r0, SYS_ify (syscall_name);				\
+	PSEUDO_CANCEL_AFTER;						\
+	pop	{r4, r5, pc};						\
+	.fnend;								\
 	cmn	r0, $4096
 
+# define PSEUDO_CANCEL_BEFORE						\
+	.pad	#20;							\
+	sub	sp, sp, #20;						\
+	ldr	r5, [sp, #32];						\
+	ldr	r4, [sp, #36];						\
+	str	r3, [sp];						\
+	mov	r3, r2;							\
+	str	r5, [sp, #4];						\
+	mov	r2, r1;							\
+	str	r4, [sp, #8];						\
+	mov	r1, r0
+
+# define PSEUDO_CANCEL_AFTER						\
+	bl	JMP_SYSCALL_CANCEL;					\
+	add	sp, sp, #20
+
 /* DOARGS pushes eight bytes on the stack for five arguments, twelve bytes for
    six arguments, and four bytes for fewer.  In order to preserve doubleword
    alignment, sometimes we must save an extra register.  */
@@ -182,18 +194,9 @@
 	RESTORE_LR_0
 
 # if IS_IN (libpthread)
-#  define CENABLE	bl PLTJMP(__pthread_enable_asynccancel)
-#  define CDISABLE	bl PLTJMP(__pthread_disable_asynccancel)
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	bl PLTJMP(__libc_enable_asynccancel)
-#  define CDISABLE	bl PLTJMP(__libc_disable_asynccancel)
 #  define __local_multiple_threads __libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE	bl PLTJMP(__librt_enable_asynccancel)
-#  define CDISABLE	bl PLTJMP(__librt_disable_asynccancel)
-# else
-#  error Unsupported library
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
@@ -238,4 +241,10 @@ extern int __local_multiple_threads attribute_hidden;
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+long int __pthread_get_ip (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.arm_pc;
+}
 #endif
diff --git a/sysdeps/unix/sysv/linux/arm/sysdep.h b/sysdeps/unix/sysv/linux/arm/sysdep.h
index 37eac19..43ae45b 100644
--- a/sysdeps/unix/sysv/linux/arm/sysdep.h
+++ b/sysdeps/unix/sysv/linux/arm/sysdep.h
@@ -387,6 +387,14 @@ __local_syscall_error:						\
 #undef INTERNAL_SYSCALL_ERRNO
 #define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))
 
+#undef SYSCALL_CANCEL_ERROR
+#define SYSCALL_CANCEL_ERROR(__val) \
+  ((unsigned int) (__val) >= 0xfffff001u)
+
+#undef SYSCALL_CANCEL_ERRNO
+#define SYSCALL_CANCEL_ERRNO(__val) \
+  (-(__val))
+
 #define LOAD_ARGS_0()
 #define ASM_ARGS_0
 #define LOAD_ARGS_1(a1)				\

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=91537db53ac12c8433d86676d93434f4a2ad91b6

commit 91537db53ac12c8433d86676d93434f4a2ad91b6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Wed May 6 17:51:29 2015 -0300

    nptl: aarch64: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the aarch64 modifications required for the BZ#12683 fix.
    It basically removes the enable_asynccancel/disable_asynccancel function
    usage on code, provide a arch-specific symbol that contains global
    markers to be used in SIGCANCEL handler.

diff --git a/ChangeLog b/ChangeLog
index 1dee7a8..4649ab8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h (PSEUDO): Redefine
+	to call __syscall_cancel function for cancellable syscalls.
+	(__pthread_get_ip): Add implementation.
+	* sysdeps/unix/sysv/linux/aarch64/sysdep.h (SYSCALL_CANCEL_ERROR): Add
+	definition.
+	(SYSCALL_CANCEL_ERRNO): Likewise.
+
 	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove macro.
 	* sysdeps/unix/sysv/linux/i386/Makefile
 	[$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object.
diff --git a/sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S b/sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S
new file mode 100644
index 0000000..ea20303
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/syscall_cancel.S
@@ -0,0 +1,65 @@
+/* Cancellable syscall wrapper - aarch64 version.
+   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>
+
+/* __syscall_cancel_arch(&self->cancelhandling, nr, a1, a2, a3, a4, a5, a6)
+                                 x0             x1  x2  x3  x4  x5  x6  x7 */
+
+ENTRY (__syscall_cancel_arch)
+
+        stp     x29, x30, [sp, -16]!
+        cfi_def_cfa_offset (16)
+        cfi_offset (29, -16)
+        cfi_offset (30, -8)
+        add     x29, sp, 0
+        cfi_def_cfa_register (29)
+
+	.globl __syscall_cancel_arch_start
+	.type  __syscall_cancel_arch_start,@function
+__syscall_cancel_arch_start:
+
+	ldr	w0, [x0]
+	tbnz    w0, 2, 1f
+
+	mov	x8, x1
+	mov	x0, x2
+	mov	x1, x3
+	mov	x2, x4
+	mov	x3, x5
+	mov	x4, x6
+	mov	x5, x7
+	svc	0x0
+
+	.globl __syscall_cancel_arch_end
+	.type  __syscall_cancel_arch_end,@function
+__syscall_cancel_arch_end:
+
+        ldp     x29, x30, [sp], 16
+        cfi_remember_state
+        cfi_restore (30)
+        cfi_restore (29)
+        cfi_def_cfa (31, 0)
+	ret
+
+1:
+	cfi_restore_state
+	b	__syscall_do_cancel
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
index 36e8e39..ba91268 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h
@@ -20,42 +20,50 @@
 #include <tls.h>
 #ifndef __ASSEMBLER__
 # include <nptl/pthreadP.h>
+# include <sys/ucontext.h>
 #endif
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
+# if IS_IN (libc)
+#  define JMP_SYSCALL_CANCEL HIDDEN_JUMPTARGET(__syscall_cancel)
+# else
+#  define JMP_SYSCALL_CANCEL __syscall_cancel
+# endif
+
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)				\
-	.section ".text";						\
-ENTRY (__##syscall_name##_nocancel);					\
-.Lpseudo_nocancel:							\
-	DO_CALL (syscall_name, args);					\
-.Lpseudo_finish:							\
-	cmn	x0, 4095;						\
-	b.cs	.Lsyscall_error;					\
-	.subsection 2;							\
-	.size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
+        .section ".text";                                               \
+ENTRY (__##syscall_name##_nocancel);                                    \
+L(pseudo_nocancel):							\
+        DO_CALL (syscall_name, args);                                   \
+L(pseudo_finish):							\
+        cmn     x0, 4095;                                               \
+        b.cs    L(syscall_error);					\
+        .subsection 2;							\
+        .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
 ENTRY (name);								\
 	SINGLE_THREAD_P(16);						\
-	cbz	w16, .Lpseudo_nocancel;					\
-	/* Setup common stack frame no matter the number of args.	\
-	   Also save the first arg, since it's basically free.  */	\
-	stp	x30, x0, [sp, -64]!;					\
-	cfi_adjust_cfa_offset (64);					\
-	cfi_rel_offset (x30, 0);					\
-	DOCARGS_##args;		/* save syscall args around CENABLE.  */ \
-	CENABLE;							\
-	mov	x16, x0;	/* save mask around syscall.  */	\
-	UNDOCARGS_##args;	/* restore syscall args.  */		\
-	DO_CALL (syscall_name, args);					\
-	str	x0, [sp, 8];	/* save result around CDISABLE.  */	\
-	mov	x0, x16;	/* restore mask for CDISABLE.  */	\
-	CDISABLE;							\
-	/* Break down the stack frame, restoring result at once.  */	\
-	ldp	x30, x0, [sp], 64;					\
-	cfi_adjust_cfa_offset (-64);					\
-	cfi_restore (x30);						\
-	b	.Lpseudo_finish;					\
+	cbz	w16, L(pseudo_nocancel);				\
+        stp     x29, x30, [sp, -16]!;					\
+        cfi_def_cfa_offset (16);					\
+        cfi_offset (29, -16);						\
+        cfi_offset (30, -8);						\
+	add	x29, sp, 0;						\
+	cfi_def_cfa_register (29);					\
+	mov	x6, x5;							\
+	mov	x5, x4;							\
+	mov	x4, x3;							\
+	mov	x3, x2;							\
+	mov	x2, x1;							\
+	mov	x1, x0;							\
+	mov	x0, SYS_ify (syscall_name);				\
+	bl	JMP_SYSCALL_CANCEL;					\
+        ldp     x29, x30, [sp], 16;					\
+        cfi_restore (30);                                              \
+        cfi_restore (29);						\
+        cfi_def_cfa (31, 0);						\
+	b       L(pseudo_finish);					\
 	cfi_endproc;							\
 	.size	name, .-name;						\
 	.previous
@@ -65,35 +73,10 @@ ENTRY (name);								\
 	SYSCALL_ERROR_HANDLER;						\
 	cfi_endproc
 
-# define DOCARGS_0
-# define DOCARGS_1
-# define DOCARGS_2	str x1, [sp, 16]
-# define DOCARGS_3	stp x1, x2, [sp, 16]
-# define DOCARGS_4	DOCARGS_3; str x3, [sp, 32]
-# define DOCARGS_5	DOCARGS_3; stp x3, x4, [sp, 32]
-# define DOCARGS_6	DOCARGS_5; str x5, [sp, 48]
-
-# define UNDOCARGS_0
-# define UNDOCARGS_1	ldr x0, [sp, 8]
-# define UNDOCARGS_2	ldp x0, x1, [sp, 8]
-# define UNDOCARGS_3	UNDOCARGS_1; ldp x1, x2, [sp, 16]
-# define UNDOCARGS_4	UNDOCARGS_2; ldp x2, x3, [sp, 24]
-# define UNDOCARGS_5	UNDOCARGS_3; ldp x3, x4, [sp, 32]
-# define UNDOCARGS_6	UNDOCARGS_4; ldp x4, x5, [sp, 40]
-
 # if IS_IN (libpthread)
-#  define CENABLE	bl __pthread_enable_asynccancel
-#  define CDISABLE	bl __pthread_disable_asynccancel
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	bl __libc_enable_asynccancel
-#  define CDISABLE	bl __libc_disable_asynccancel
 #  define __local_multiple_threads __libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE	bl __librt_enable_asynccancel
-#  define CDISABLE	bl __librt_disable_asynccancel
-# else
-#  error Unsupported library
 # endif
 
 # if IS_IN (libpthread) || IS_IN (libc)
@@ -131,4 +114,10 @@ extern int __local_multiple_threads attribute_hidden;
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+long int __pthread_get_ip (const struct ucontext *uc)
+{
+  return uc->uc_mcontext.pc;
+}
 #endif
diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
index 91e03fc..c545065 100644
--- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h
@@ -262,6 +262,14 @@
 # undef INTERNAL_SYSCALL_ERRNO
 # define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))
 
+#undef SYSCALL_CANCEL_ERROR
+#define SYSCALL_CANCEL_ERROR(__val) \
+  ((unsigned long) (__val) >= (unsigned long) -4095)
+
+#undef SYSCALL_CANCEL_ERRNO
+#define SYSCALL_CANCEL_ERRNO(__val) \
+  (-(__val))
+
 # define LOAD_ARGS_0()				\
   register long _x0 asm ("x0");
 # define LOAD_ARGS_1(x0)			\

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=106db3996d419f397102364431bdd707267b7d1b

commit 106db3996d419f397102364431bdd707267b7d1b
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon May 4 16:30:13 2015 -0300

    nptl: i386: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patch adds the i386 modifications required for the BZ#12683 fix.
    It basically removes the enable_asynccancel/disable_asynccancel function
    usage on code used on x86_64, provide a arch-specific symbol that
    contains global markers to be used in SIGCANCEL handler.

diff --git a/ChangeLog b/ChangeLog
index ff5dbb9..1dee7a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/i386/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove macro.
+	* sysdeps/unix/sysv/linux/i386/Makefile
+	[$(subdir) = elf] (sysdep-rtld_routines): Add libc-do-syscall object.
+	* sysdeps/unix/sysv/linux/i386/libc-cancellation.c: New file.
+	* sysdeps/unix/sysv/linux/i386/lowlevellock.h (lll_wait_tid): Use
+	cancellable futex syscall macro.
+	* sysdeps/unix/sysv/linux/i386/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (PSEUDO): Redefine to
+	call __syscall_cancel function for cancellable syscalls.
+	* sysdeps/unix/sysv/linux/i386/sysdep.h (SYSCALL_CANCEL_ERROR): New
+	define.
+	(SYSCALL_CANCEL_ERRNO): Likewise.
+
 	* sysdeps/unix/sysv/linux/i386/fcntl.c (NO_CANCELLATION): Replace
 	by IS_IN (rtld).
 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h (PSEUDO):
diff --git a/sysdeps/i386/nptl/tls.h b/sysdeps/i386/nptl/tls.h
index 829cd3a..ffac3a8 100644
--- a/sysdeps/i386/nptl/tls.h
+++ b/sysdeps/i386/nptl/tls.h
@@ -395,17 +395,6 @@ tls_fill_user_desc (union user_desc_init *desc,
 	      abort (); })
 
 
-/* Atomic set bit.  */
-#define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
-  (void) ({ if (sizeof ((descr)->member) == 4)				      \
-	      asm volatile (LOCK_PREFIX "orl %1, %%gs:%P0"		      \
-			    :: "i" (offsetof (struct pthread, member)),	      \
-			       "ir" (1 << (bit)));			      \
-	    else							      \
-	      /* Not necessary for other sizes in the moment.  */	      \
-	      abort (); })
-
-
 /* Call the user-provided thread function.  */
 #define CALL_THREAD_FCT(descr) \
   ({ void *__res;							      \
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index 80da593..4f83d08 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -6,6 +6,7 @@ sysdep_routines += ioperm iopl vm86
 endif
 
 ifeq ($(subdir),elf)
+sysdep-rtld_routines += libc-do-syscall
 sysdep-others += lddlibc4
 install-bin += lddlibc4
 endif
diff --git a/sysdeps/unix/sysv/linux/i386/libc-cancellation.c b/sysdeps/unix/sysv/linux/i386/libc-cancellation.c
new file mode 100644
index 0000000..ff07ea4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/libc-cancellation.c
@@ -0,0 +1,46 @@
+/* i386 cancellation definitions.
+   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>
+
+#define INTERNAL_SYSCALL_MAIN_6_NCS(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)							\
+    : "0" (name), "c" (arg2), "d" (arg3), "S" (arg4), "D" (&_xv)	\
+    : "memory", "cc")
+
+#undef INTERNAL_SYSCALL_NCS
+#define INTERNAL_SYSCALL_NCS(name, err, nr, arg1, arg2, arg3, arg4,	\
+			     arg5, arg6)				\
+  ({									\
+    unsigned int resultvar;						\
+    INTERNAL_SYSCALL_MAIN_6_NCS (name, err, arg1, arg2, arg3, arg4,	\
+				 arg5, arg6);				\
+    (int) resultvar;							\
+  })
+
+#include <nptl/libc-cancellation.c>
diff --git a/sysdeps/unix/sysv/linux/i386/lowlevellock.h b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
index f57afc6..69fcaa4 100644
--- a/sysdeps/unix/sysv/linux/i386/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/i386/lowlevellock.h
@@ -287,7 +287,7 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
   do {					\
     __typeof (tid) __tid;		\
     while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+      lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);\
   } while (0)
 
 extern int __lll_timedwait_tid (int *tid, const struct timespec *abstime)
diff --git a/sysdeps/unix/sysv/linux/i386/syscall_cancel.S b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
new file mode 100644
index 0000000..37f75f3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/syscall_cancel.S
@@ -0,0 +1,92 @@
+/* Cancellable syscall wrapper - x86_64 version.
+   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>
+
+ENTRY (__syscall_cancel_arch)
+	pushl %ebp
+	cfi_def_cfa_offset (8)
+	cfi_offset (ebp, -8)
+	pushl %edi
+	cfi_def_cfa_offset (12)
+	cfi_offset (edi, -12)
+	pushl %esi
+	cfi_def_cfa_offset (16)
+	cfi_offset (esi, -16)
+	pushl %ebx
+	cfi_def_cfa_offset (20)
+	cfi_offset (ebx, -20)
+
+	.globl __syscall_cancel_arch_start
+	.type  __syscall_cancel_arch_start,@function
+__syscall_cancel_arch_start:
+
+	testb	$4, (%eax)
+	jne     1f //L(syscall_cancel_arch_do_cancel)
+
+	movl    24(%esp), %eax
+	movl    28(%esp), %ebx
+	movl    32(%esp), %ecx
+	movl    36(%esp), %edx
+	movl    40(%esp), %esi
+	movl    44(%esp), %edi
+	movl    48(%esp), %ebp
+
+        /* It can not use the vDSO __kernel_vsyscall because the cancelable
+	   checks in libc-cancelation.c requires to know if the cancellation
+	   IP value that was trigger between the two
+	   __syscall_cancel_arch_{start,end} marks.  */
+	int	$128
+
+	.globl __syscall_cancel_arch_end
+	.type  __syscall_cancel_arch_end,@function
+__syscall_cancel_arch_end:
+
+	popl %ebx
+	cfi_restore (ebx)
+	cfi_def_cfa_offset (16)
+	popl %esi
+	cfi_restore (esi)
+	cfi_def_cfa_offset (12)
+	popl %edi
+	cfi_restore (edi)
+	cfi_def_cfa_offset (8)
+	popl %ebp
+	cfi_restore (ebp)
+	cfi_def_cfa_offset (4)
+        ret
+
+1:
+	/* Although the __syscall_do_cancel do not return, we need to stack
+	   being set correctly so exceptions work correctly.  */
+	popl %ebx
+	cfi_restore (ebx)
+	cfi_def_cfa_offset (16)
+	popl %esi
+	cfi_restore (esi)
+	cfi_def_cfa_offset (12)
+	popl %edi
+	cfi_restore (edi)
+	cfi_def_cfa_offset (8)
+	popl %ebp
+	cfi_restore (ebp)
+	cfi_def_cfa_offset (4)
+	jmp __syscall_do_cancel
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h b/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
index 1f86dae..d8cdd27 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h
@@ -24,112 +24,66 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
+# if IS_IN (libc)
+#  define JMP_STARTFUNC							      \
+    subl $16, %esp
+#  define JMP_SYSCALL_CANCEL						      \
+    HIDDEN_JUMPTARGET(__syscall_cancel)
+#  define JMP_ENDFUNC							      \
+    addl $44, %esp;							      \
+    cfi_def_cfa_offset (4)
+# else
+#  define JMP_STARTFUNC							      \
+    pushl %ebx;								      \
+    cfi_def_cfa_offset (8);						      \
+    cfi_offset (ebx, -8);						      \
+    SETUP_PIC_REG (bx);							      \
+    addl $_GLOBAL_OFFSET_TABLE_, %ebx;					      \
+    subl $12, %esp
+#  define JMP_SYSCALL_CANCEL \
+    __syscall_cancel@plt
+#  define JMP_ENDFUNC							      \
+    addl $40, %esp;							      \
+    cfi_def_cfa_offset (8);						      \
+    popl %ebx;								      \
+    cfi_restore (ebx);							      \
+    cfi_def_cfa_offset (4)
+# endif
+
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)				      \
   .text;								      \
   ENTRY (name)								      \
     cmpl $0, %gs:MULTIPLE_THREADS_OFFSET;				      \
     jne L(pseudo_cancel);						      \
-  .type __##syscall_name##_nocancel,@function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
     DO_CALL (syscall_name, args);					      \
     cmpl $-4095, %eax;							      \
     jae SYSCALL_ERROR_LABEL;						      \
     ret;								      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
   L(pseudo_cancel):							      \
-    CENABLE								      \
-    SAVE_OLDTYPE_##args							      \
-    PUSHCARGS_##args							      \
-    DOCARGS_##args							      \
-    movl $SYS_ify (syscall_name), %eax;					      \
-    ENTER_KERNEL;							      \
-    POPCARGS_##args;							      \
-    POPSTATE_##args							      \
+    JMP_STARTFUNC;							      \
+    cfi_def_cfa_offset (20);						      \
+    pushl 40(%esp);							      \
+    cfi_def_cfa_offset (24);						      \
+    pushl 40(%esp);							      \
+    cfi_def_cfa_offset (28);						      \
+    pushl 40(%esp);							      \
+    cfi_def_cfa_offset (32);						      \
+    pushl 40(%esp);							      \
+    cfi_def_cfa_offset (36);						      \
+    pushl 40(%esp);							      \
+    cfi_def_cfa_offset (40);						      \
+    pushl 40(%esp);							      \
+    cfi_def_cfa_offset (44);						      \
+    pushl $SYS_ify (syscall_name);					      \
+    cfi_def_cfa_offset (48);						      \
+    call JMP_SYSCALL_CANCEL;						      \
+    JMP_ENDFUNC;							      \
     cmpl $-4095, %eax;							      \
     jae SYSCALL_ERROR_LABEL
 
-# define SAVE_OLDTYPE_0	movl %eax, %ecx;
-# define SAVE_OLDTYPE_1	SAVE_OLDTYPE_0
-# define SAVE_OLDTYPE_2	pushl %eax; cfi_adjust_cfa_offset (4);
-# define SAVE_OLDTYPE_3	SAVE_OLDTYPE_2
-# define SAVE_OLDTYPE_4	SAVE_OLDTYPE_2
-# define SAVE_OLDTYPE_5	SAVE_OLDTYPE_2
-# define SAVE_OLDTYPE_6	SAVE_OLDTYPE_2
-
-# define PUSHCARGS_0	/* No arguments to push.  */
-# define DOCARGS_0	/* No arguments to frob.  */
-# define POPCARGS_0	/* No arguments to pop.  */
-# define _PUSHCARGS_0	/* No arguments to push.  */
-# define _POPCARGS_0	/* No arguments to pop.  */
-
-# define PUSHCARGS_1	movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
-# define DOCARGS_1	_DOARGS_1 (4)
-# define POPCARGS_1	POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
-# define _PUSHCARGS_1	pushl %ebx; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (ebx, 0); _PUSHCARGS_0
-# define _POPCARGS_1	_POPCARGS_0; popl %ebx; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
-
-# define PUSHCARGS_2	PUSHCARGS_1
-# define DOCARGS_2	_DOARGS_2 (12)
-# define POPCARGS_2	POPCARGS_1
-# define _PUSHCARGS_2	_PUSHCARGS_1
-# define _POPCARGS_2	_POPCARGS_1
-
-# define PUSHCARGS_3	_PUSHCARGS_2
-# define DOCARGS_3	_DOARGS_3 (20)
-# define POPCARGS_3	_POPCARGS_3
-# define _PUSHCARGS_3	_PUSHCARGS_2
-# define _POPCARGS_3	_POPCARGS_2
-
-# define PUSHCARGS_4	_PUSHCARGS_4
-# define DOCARGS_4	_DOARGS_4 (28)
-# define POPCARGS_4	_POPCARGS_4
-# define _PUSHCARGS_4	pushl %esi; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (esi, 0); _PUSHCARGS_3
-# define _POPCARGS_4	_POPCARGS_3; popl %esi; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (esi);
-
-# define PUSHCARGS_5	_PUSHCARGS_5
-# define DOCARGS_5	_DOARGS_5 (36)
-# define POPCARGS_5	_POPCARGS_5
-# define _PUSHCARGS_5	pushl %edi; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (edi, 0); _PUSHCARGS_4
-# define _POPCARGS_5	_POPCARGS_4; popl %edi; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (edi);
-
-# define PUSHCARGS_6	_PUSHCARGS_6
-# define DOCARGS_6	_DOARGS_6 (44)
-# define POPCARGS_6	_POPCARGS_6
-# define _PUSHCARGS_6	pushl %ebp; cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (ebp, 0); _PUSHCARGS_5
-# define _POPCARGS_6	_POPCARGS_5; popl %ebp; \
-			cfi_adjust_cfa_offset (-4); cfi_restore (ebp);
-
-# if IS_IN (libpthread)
-#  define CENABLE	call __pthread_enable_asynccancel;
-#  define CDISABLE	call __pthread_disable_asynccancel
-# elif IS_IN (libc)
-#  define CENABLE	call __libc_enable_asynccancel;
-#  define CDISABLE	call __libc_disable_asynccancel
-# elif IS_IN (librt)
-#  define CENABLE	call __librt_enable_asynccancel;
-#  define CDISABLE	call __librt_disable_asynccancel
-# else
-#  error Unsupported library
-# endif
-# define POPSTATE_0 \
- pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
- CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
-# define POPSTATE_1	POPSTATE_0
-# define POPSTATE_2	xchgl (%esp), %eax; CDISABLE; popl %eax; \
-			cfi_adjust_cfa_offset (-4);
-# define POPSTATE_3	POPSTATE_2
-# define POPSTATE_4	POPSTATE_3
-# define POPSTATE_5	POPSTATE_4
-# define POPSTATE_6	POPSTATE_5
+# undef PSEUDO_RET
+# define PSEUDO_RET
 
 # ifndef __ASSEMBLER__
 #  define SINGLE_THREAD_P \
@@ -150,4 +104,10 @@
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+long int __pthread_get_ip (const ucontext_t *uc)
+{
+  return (long int)uc->uc_mcontext.gregs[REG_EIP];
+}
 #endif
diff --git a/sysdeps/unix/sysv/linux/i386/sysdep.h b/sysdeps/unix/sysv/linux/i386/sysdep.h
index 7f6fcf3..818fcb3 100644
--- a/sysdeps/unix/sysv/linux/i386/sysdep.h
+++ b/sysdeps/unix/sysv/linux/i386/sysdep.h
@@ -448,6 +448,14 @@ struct libc_do_syscall_args
 #undef INTERNAL_SYSCALL_ERRNO
 #define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))
 
+#undef SYSCALL_CANCEL_ERROR
+#define SYSCALL_CANCEL_ERROR(__val) \
+  ((unsigned int) (__val) >= 0xfffff001u)
+
+#undef SYSCALL_CANCEL_ERRNO
+#define SYSCALL_CANCEL_ERRNO(__val) \
+  (-(__val))
+
 #define LOADARGS_0
 #ifdef __PIC__
 # if defined I386_USE_SYSENTER && defined SHARED

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=1a4dab520a2b0b52f3266c1269ca2a04d29aae32

commit 1a4dab520a2b0b52f3266c1269ca2a04d29aae32
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Mon Sep 29 09:20:10 2014 -0400

    nptl: ppc32: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches adds the ppc32 modification required for the BZ#12683
    fix.  It basically removes the enable_asynccancel/disable_asynccancel
    function usage on code used on ppc32.

diff --git a/ChangeLog b/ChangeLog
index fb30a5d..ff5dbb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/i386/fcntl.c (NO_CANCELLATION): Replace
+	by IS_IN (rtld).
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h (PSEUDO):
+	Redefine to call __syscall_cancel function for cancellable syscalls.
+	(__pthread_get_ip): Add implementation.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
+	[SYSCALL_CANCEL_ERROR]: New macro.
+	[SYSCALL_CANCEL_ERRNO]: New macro.
+
 	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t):
 	Define type for x32.
 	(__SSC): Add platform specific macro.
diff --git a/sysdeps/unix/sysv/linux/i386/fcntl.c b/sysdeps/unix/sysv/linux/i386/fcntl.c
index 56f4bd1..ac5eed4 100644
--- a/sysdeps/unix/sysv/linux/i386/fcntl.c
+++ b/sysdeps/unix/sysv/linux/i386/fcntl.c
@@ -23,7 +23,7 @@
 
 #include <sys/syscall.h>
 
-#ifndef NO_CANCELLATION
+#if !IS_IN (rtld)
 int
 __fcntl_nocancel (int fd, int cmd, ...)
 {
@@ -36,7 +36,7 @@ __fcntl_nocancel (int fd, int cmd, ...)
 
   return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
 }
-#endif /* NO_CANCELLATION */
+#endif
 
 
 int
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
index dd9ff1c..d625495 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h
@@ -25,94 +25,83 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
+# if !IS_IN (libc)
+#  define SETUP_PIC							\
+    bcl     20,31,got_label;						\
+got_label:
+
+#  define CANCEL_JUMPTARGET						\
+    stw   r30,8(r1);							\
+    mflr  r30;								\
+    addis r30,r30,_GLOBAL_OFFSET_TABLE_-got_label@ha;			\
+    addi  r30,r30,_GLOBAL_OFFSET_TABLE_-got_label@l;			\
+    bl    __syscall_cancel@plt;						\
+    lwz   r30,8(r1)
+# else
+#  define SETUP_PIC
+#  if defined SHARED && defined PIC
+#   define CANCEL_JUMPTARGET						\
+    bl    __GI___syscall_cancel@locaL
+#  else
+#   define CANCEL_JUMPTARGET						\
+    bl    __syscall_cancel
+#  endif
+# endif
+
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)				\
   .section ".text";							\
   ENTRY (name)								\
     SINGLE_THREAD_P;							\
-    bne- .Lpseudo_cancel;						\
-  .type __##syscall_name##_nocancel,@function;				\
-  .globl __##syscall_name##_nocancel;					\
-  __##syscall_name##_nocancel:						\
+    bne- L(pseudo_cancel);						\
     DO_CALL (SYS_ify (syscall_name));					\
-    PSEUDO_RET;								\
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	\
-  .Lpseudo_cancel:							\
-    stwu 1,-48(1);							\
-    cfi_adjust_cfa_offset (48);						\
-    mflr 9;								\
-    stw 9,52(1);							\
+    bnslr+;								\
+    b __syscall_error@local;						\
+  L(pseudo_cancel):							\
+    stwu r1,-16(r1);							\
+    cfi_adjust_cfa_offset (16);						\
+    mflr r0;								\
+    SETUP_PIC;								\
+    stw  r0,20(r1);							\
     cfi_offset (lr, 4);							\
-    DOCARGS_##args;	/* save syscall args around CENABLE.  */	\
-    CENABLE;								\
-    stw 3,16(1);	/* store CENABLE return value (MASK).  */	\
-    UNDOCARGS_##args;	/* restore syscall args.  */			\
-    DO_CALL (SYS_ify (syscall_name));					\
-    mfcr 0;		/* save CR/R3 around CDISABLE.  */		\
-    stw 3,8(1);								\
-    stw 0,12(1);							\
-    lwz 3,16(1);	/* pass MASK to CDISABLE.  */			\
-    CDISABLE;								\
-    lwz 4,52(1);							\
-    lwz 0,12(1);	/* restore CR/R3. */				\
-    lwz 3,8(1);								\
-    mtlr 4;								\
-    mtcr 0;								\
-    addi 1,1,48;
-
-# define DOCARGS_0
-# define UNDOCARGS_0
-
-# define DOCARGS_1	stw 3,20(1); DOCARGS_0
-# define UNDOCARGS_1	lwz 3,20(1); UNDOCARGS_0
-
-# define DOCARGS_2	stw 4,24(1); DOCARGS_1
-# define UNDOCARGS_2	lwz 4,24(1); UNDOCARGS_1
-
-# define DOCARGS_3	stw 5,28(1); DOCARGS_2
-# define UNDOCARGS_3	lwz 5,28(1); UNDOCARGS_2
-
-# define DOCARGS_4	stw 6,32(1); DOCARGS_3
-# define UNDOCARGS_4	lwz 6,32(1); UNDOCARGS_3
-
-# define DOCARGS_5	stw 7,36(1); DOCARGS_4
-# define UNDOCARGS_5	lwz 7,36(1); UNDOCARGS_4
-
-# define DOCARGS_6	stw 8,40(1); DOCARGS_5
-# define UNDOCARGS_6	lwz 8,40(1); UNDOCARGS_5
-
-# if IS_IN (libpthread)
-#  define CENABLE	bl __pthread_enable_asynccancel@local
-#  define CDISABLE	bl __pthread_disable_asynccancel@local
-# elif IS_IN (libc)
-#  define CENABLE	bl __libc_enable_asynccancel@local
-#  define CDISABLE	bl __libc_disable_asynccancel@local
-# elif IS_IN (librt)
-#  define CENABLE	bl __librt_enable_asynccancel@local
-#  define CDISABLE	bl __librt_disable_asynccancel@local
-# else
-#  error Unsupported library
-# endif
+    mr   r9,r8;								\
+    mr   r8,r7;								\
+    mr   r7,r6;								\
+    mr   r6,r5;								\
+    mr   r5,r4;								\
+    mr   r4,r3;								\
+    li   r3,SYS_ify (syscall_name);					\
+    CANCEL_JUMPTARGET;							\
+    lwz  r0,20(r1);							\
+    addi r1,r1,16;							\
+    cfi_adjust_cfa_offset (-16);					\
+    mtlr r0;								\
+    cfi_restore (lr);							\
+    b    __syscall_cancel_error@local;
+
+# undef PSEUDO_RET
+# define PSEUDO_RET
 
 # ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				   header.multiple_threads) == 0, 1)
+#  define SINGLE_THREAD_P                                               \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF,                         \
+                                   header.multiple_threads) == 0, 1)
 # else
-#  define SINGLE_THREAD_P						\
-  lwz 10,MULTIPLE_THREADS_OFFSET(2);					\
+#  define SINGLE_THREAD_P                                               \
+  lwz 10,MULTIPLE_THREADS_OFFSET(2);                                    \
   cmpwi 10,0
 # endif
 
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
 #endif
 
 #ifndef __ASSEMBLER__
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+const char * __pthread_get_ip (const ucontext_t *uc)
+{
+  return (char *)uc->uc_mcontext.uc_regs->gregs[PT_NIP];
+}
 #endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
index 0b41e8c..d6c0031 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
@@ -168,6 +168,14 @@
     sc_ret;								\
   })
 
+#undef SYSCALL_CANCEL_ERROR
+#define SYSCALL_CANCEL_ERROR(err)					\
+  (err > 0xfffffffffffff000UL)
+
+#undef SYSCALL_CANCEL_ERRNO
+#define SYSCALL_CANCEL_ERRNO(err)					\
+  (-err)
+
 /* Define a macro which expands inline into the wrapper code for a system
    call. This use is for internal calls that do not need to handle errors
    normally. It will never touch errno.

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=d8f73d814e1f6e28a02b0034456deb04228d39d5

commit d8f73d814e1f6e28a02b0034456deb04228d39d5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Sat May 9 14:20:26 2015 -0300

    nptl: x32: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches adds the x32 modification required for the BZ#12683 fix.
    It basically adjust the syscall size used to pass the arguments to
    the syscall cancel wrappers.

diff --git a/ChangeLog b/ChangeLog
index 3c22b6e..fb30a5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h (__syscall_arg_t):
+	Define type for x32.
+	(__SSC): Add platform specific macro.
+
 	* sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file.
 	* sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file.
 	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
index 2324168..f2dc8f0 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h
@@ -18,6 +18,27 @@
 #ifndef _LINUX_X32_SYSDEP_H
 #define _LINUX_X32_SYSDEP_H 1
 
+#ifndef __ASSEMBLER__
+#include <libc-internal.h>
+
+typedef long long int __syscall_arg_t;
+
+/* Syscall arguments for x32 follows x86_64 size, however pointers are 32
+   bits in size.  This suppress the GCC warning "cast from pointer to 
+   integer of different size" when calling __syscall_cancel with
+   pointer as arguments.  */
+# define __SSC(__x)						\
+  ({								\
+    __syscall_arg_t __ret;					\
+    DIAG_PUSH_NEEDS_COMMENT;					\
+    DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wpointer-to-int-cast");	\
+    __ret = (sizeof(1 ? (__x) : 0ULL) < 8 ?			\
+      (unsigned long int) (__x) : (long long int) (__x));	\
+    DIAG_POP_NEEDS_COMMENT;					\
+    __ret;							\
+  })
+#endif
+
 /* There is some commonality.  */
 #include <sysdeps/unix/sysv/linux/x86_64/sysdep.h>
 #include <sysdeps/x86_64/x32/sysdep.h>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8f3b2363c6600a0e5dfd7495a88c907d7480f4a4

commit 8f3b2363c6600a0e5dfd7495a88c907d7480f4a4
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Mon Sep 29 09:48:34 2014 -0300

    nptl: x86_64: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches adds the x86_64 modification required for the BZ#12683 fix.
    It basically removes the enable_asynccancel/disable_asynccancel function
    usage on code used on x86_64, provide a arch-specific symbol that
    contains global markers to be used in SIGCANCEL handler, and remove
    x86_64 assembly pthread conditional and semaphore code to use default
    one (that already contains the cancel call fixes).

diff --git a/ChangeLog b/ChangeLog
index b4f80ce..3c22b6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/x86_64/cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.h (lll_wait_tid):
+	Use cancellable futex wait call.
+	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (PSEUDO): Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S: New file.
+	* sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h (PSEUDO): Redefine to
+	call __syscall_cancel function for cancellable syscalls.
+	(CENABLE): Remove definition.
+	(CDISABLE): Likewise.
+	(__pthread_get_ip): Add implementation.
+	* sysdeps/unix/sysv/linux/x86_64/sysdep.h (SYSCALL_CANCEL_ERROR): New
+	define.
+	(SYSCALL_CANCEL_ERRNO): Likewise.
+	* sysdeps/x86_64/nptl/tcb-offsets.sym [TCB_CANCELING_BITMASK]:
+	Remove.
+	* sysdeps/x86_64/nptl/tls.h (THREAD_ATOMIC_BIT_SET): Remove
+	macro.
+
 	* nptl/Makefile [routines]: Add syscall_cancel object.
 	[libpthread-routines]: Remove cancellation object.
 	(CFLAGS-cancellation.c): Remove -fasynchronous-unwind-tables.
diff --git a/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/sysdeps/unix/sysv/linux/x86_64/cancellation.S
deleted file mode 100644
index 4c34beb..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/cancellation.S
+++ /dev/null
@@ -1,117 +0,0 @@
-/* Copyright (C) 2009-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   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>
-#include <tcb-offsets.h>
-#include <kernel-features.h>
-#include "lowlevellock.h"
-
-#if IS_IN (libpthread)
-# if defined SHARED && !defined NO_HIDDEN
-#  define __pthread_unwind __GI___pthread_unwind
-# endif
-#else
-# ifndef SHARED
-	.weak __pthread_unwind
-# endif
-#endif
-
-
-#ifdef __ASSUME_PRIVATE_FUTEX
-# define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	$(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
-#else
-# if FUTEX_WAIT == 0
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg
-# else
-#  define LOAD_PRIVATE_FUTEX_WAIT(reg) \
-	movl	%fs:PRIVATE_FUTEX, reg ; \
-	orl	$FUTEX_WAIT, reg
-# endif
-#endif
-
-/* It is crucial that the functions in this file don't modify registers
-   other than %rax and %r11.  The syscall wrapper code depends on this
-   because it doesn't explicitly save the other registers which hold
-   relevant values.  */
-	.text
-
-	.hidden __pthread_enable_asynccancel
-ENTRY(__pthread_enable_asynccancel)
-	movl	%fs:CANCELHANDLING, %eax
-2:	movl	%eax, %r11d
-	orl	$TCB_CANCELTYPE_BITMASK, %r11d
-	cmpl	%eax, %r11d
-	je	1f
-
-	lock
-	cmpxchgl %r11d, %fs:CANCELHANDLING
-	jnz	2b
-
-	andl	$(TCB_CANCELSTATE_BITMASK|TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK|TCB_EXITING_BITMASK|TCB_CANCEL_RESTMASK|TCB_TERMINATED_BITMASK), %r11d
-	cmpl	$(TCB_CANCELTYPE_BITMASK|TCB_CANCELED_BITMASK), %r11d
-	je	3f
-
-1:	ret
-
-3:	subq	$8, %rsp
-	cfi_adjust_cfa_offset(8)
-	LP_OP(mov) $TCB_PTHREAD_CANCELED, %fs:RESULT
-	lock
-	orl	$TCB_EXITING_BITMASK, %fs:CANCELHANDLING
-	mov	%fs:CLEANUP_JMP_BUF, %RDI_LP
-#ifdef SHARED
-	call	__pthread_unwind@PLT
-#else
-	call	__pthread_unwind
-#endif
-	hlt
-END(__pthread_enable_asynccancel)
-
-
-	.hidden __pthread_disable_asynccancel
-ENTRY(__pthread_disable_asynccancel)
-	testl	$TCB_CANCELTYPE_BITMASK, %edi
-	jnz	1f
-
-	movl	%fs:CANCELHANDLING, %eax
-2:	movl	%eax, %r11d
-	andl	$~TCB_CANCELTYPE_BITMASK, %r11d
-	lock
-	cmpxchgl %r11d, %fs:CANCELHANDLING
-	jnz	2b
-
-	movl	%r11d, %eax
-3:	andl	$(TCB_CANCELING_BITMASK|TCB_CANCELED_BITMASK), %eax
-	cmpl	$TCB_CANCELING_BITMASK, %eax
-	je	4f
-1:	ret
-
-	/* Performance doesn't matter in this loop.  We will
-	   delay until the thread is canceled.  And we will unlikely
-	   enter the loop twice.  */
-4:	mov	%fs:0, %RDI_LP
-	movl	$__NR_futex, %eax
-	xorq	%r10, %r10
-	addq	$CANCELHANDLING, %rdi
-	LOAD_PRIVATE_FUTEX_WAIT (%esi)
-	syscall
-	movl	%fs:CANCELHANDLING, %eax
-	jmp	3b
-END(__pthread_disable_asynccancel)
diff --git a/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S b/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
deleted file mode 100644
index dbb39f3..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/libc-cancellation.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (C) 2009-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   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/>.  */
-
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include "cancellation.S"
diff --git a/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S b/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
deleted file mode 100644
index 40b2986..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (C) 2009-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
-
-   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/>.  */
-
-#define __pthread_enable_asynccancel __librt_enable_asynccancel
-#define __pthread_disable_asynccancel __librt_disable_asynccancel
-#include "cancellation.S"
diff --git a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
index 573b48c..4ef8d58 100644
--- a/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
+++ b/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
@@ -309,10 +309,10 @@ extern int __lll_timedlock_elision (int *futex, short *adapt_count,
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
    operations for futex wake-up when the clone terminates.  */
 #define lll_wait_tid(tid) \
-  do {					\
-    __typeof (tid) __tid;		\
-    while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+  do {									      \
+    __typeof (tid) __tid;						      \
+    while ((__tid = (tid)) != 0)					      \
+      lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);		      \
   } while (0)
 
 extern int __lll_timedwait_tid (int *, const struct timespec *)
diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S b/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S
new file mode 100644
index 0000000..1a7bd93
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/syscall_cancel.S
@@ -0,0 +1,49 @@
+/* Cancellable syscall wrapper - x86_64 version.
+   Copyright (C) 2014 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>
+
+ENTRY (__syscall_cancel_arch)
+
+	.globl __syscall_cancel_arch_start
+	.type  __syscall_cancel_arch_start,@function
+__syscall_cancel_arch_start:
+
+        mov    (%rdi),%eax
+	testb  $4, (%rdi)
+        jne    __syscall_do_cancel
+
+        mov    %rdi,%r11
+        mov    %rsi,%rax
+        mov    %rdx,%rdi
+        mov    %rcx,%rsi
+        mov    %r8,%rdx
+        mov    %r9,%r10
+        mov    8(%rsp),%r8
+        mov    16(%rsp),%r9
+        mov    %r11,8(%rsp)
+        syscall
+
+	.globl __syscall_cancel_arch_end
+	.type  __syscall_cancel_arch_end,@function
+__syscall_cancel_arch_end:
+
+	ret
+
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
index 6436ff0..a216364 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h
@@ -24,53 +24,43 @@
 
 #if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
 
-/* The code to disable cancellation depends on the fact that the called
-   functions are special.  They don't modify registers other than %rax
-   and %r11 if they return.  Therefore we don't have to preserve other
-   registers around these calls.  */
+# if IS_IN (libc)
+#  define JMP_SYSCALL_CANCEL HIDDEN_JUMPTARGET(__syscall_cancel)
+# else
+#  define JMP_SYSCALL_CANCEL __syscall_cancel@plt
+# endif
+
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)				      \
   .text;								      \
   ENTRY (name)								      \
     SINGLE_THREAD_P;							      \
     jne L(pseudo_cancel);						      \
-  .type __##syscall_name##_nocancel,@function;				      \
-  .globl __##syscall_name##_nocancel;					      \
-  __##syscall_name##_nocancel:						      \
     DO_CALL (syscall_name, args);					      \
     cmpq $-4095, %rax;							      \
     jae SYSCALL_ERROR_LABEL;						      \
     ret;								      \
-  .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel;	      \
   L(pseudo_cancel):							      \
-    /* We always have to align the stack before calling a function.  */	      \
-    subq $8, %rsp; cfi_adjust_cfa_offset (8);				      \
-    CENABLE								      \
-    /* The return value from CENABLE is argument for CDISABLE.  */	      \
-    movq %rax, (%rsp);							      \
-    DO_CALL (syscall_name, args);					      \
-    movq (%rsp), %rdi;							      \
-    /* Save %rax since it's the error code from the syscall.  */	      \
-    movq %rax, %rdx;							      \
-    CDISABLE								      \
-    movq %rdx, %rax;							      \
-    addq $8,%rsp; cfi_adjust_cfa_offset (-8);				      \
-    cmpq $-4095, %rax;							      \
-    jae SYSCALL_ERROR_LABEL
-
+    subq  $24, %rsp;							      \
+    cfi_def_cfa_offset (32);						      \
+    movq  %r9, (%rsp);							      \
+    movq  %r8, %r9;							      \
+    movq  %rcx, %r8;							      \
+    movq  %rdx, %rcx;							      \
+    movq  %rsi, %rdx;							      \
+    movq  %rdi, %rsi;							      \
+    lea   SYS_ify (syscall_name), %edi;					      \
+    call  JMP_SYSCALL_CANCEL;						      \
+    cfi_def_cfa_offset (8);						      \
+    addq  $24, %rsp;							      \
+    cmpq  $-4095, %rax;							      \
+    jae SYSCALL_ERROR_LABEL;
 
 # if IS_IN (libpthread)
-#  define CENABLE	call __pthread_enable_asynccancel;
-#  define CDISABLE	call __pthread_disable_asynccancel;
 #  define __local_multiple_threads __pthread_multiple_threads
 # elif IS_IN (libc)
-#  define CENABLE	call __libc_enable_asynccancel;
-#  define CDISABLE	call __libc_disable_asynccancel;
 #  define __local_multiple_threads __libc_multiple_threads
-# elif IS_IN (librt)
-#  define CENABLE	call __librt_enable_asynccancel;
-#  define CDISABLE	call __librt_disable_asynccancel;
-# else
+# elif !IS_IN (librt)
 #  error Unsupported library
 # endif
 
@@ -78,7 +68,7 @@
 #  ifndef __ASSEMBLER__
 extern int __local_multiple_threads attribute_hidden;
 #   define SINGLE_THREAD_P \
-  __builtin_expect (__local_multiple_threads == 0, 1)
+	  __builtin_expect (__local_multiple_threads == 0, 1)
 #  else
 #   define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
 #  endif
@@ -87,18 +77,13 @@ extern int __local_multiple_threads attribute_hidden;
 
 #  ifndef __ASSEMBLER__
 #   define SINGLE_THREAD_P \
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
-				   header.multiple_threads) == 0, 1)
+	  __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
+					   header.multiple_threads) == 0, 1)
 #  else
 #   define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
-#  endif
+#  endif /* __ASSEMBLER  */
 
-# endif
-
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
+# endif /* IS_IN (libpthread) || IS_IN (libc)  */
 
 #endif
 
@@ -106,4 +91,10 @@ extern int __local_multiple_threads attribute_hidden;
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+long int __pthread_get_ip (const ucontext_t *uc)
+{
+  return (long int)uc->uc_mcontext.gregs[REG_RIP];
+}
 #endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index 3dbd7d2..85f0e01 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -307,6 +307,15 @@
   INTERNAL_SYSCALL (name, err, nr, ##args)
 # endif
 
+# undef SYSCALL_CANCEL_ERROR
+# define SYSCALL_CANCEL_ERROR(__val)					      \
+  ((unsigned long int) (long int) (__val) >= -4095L)
+
+# undef SYSCALL_CANCEL_ERRNO
+# define SYSCALL_CANCEL_ERRNO(__val)					      \
+  (-(__val))
+
+
 # define LOAD_ARGS_0()
 # define LOAD_REGS_0
 # define ASM_ARGS_0
diff --git a/sysdeps/x86_64/nptl/tcb-offsets.sym b/sysdeps/x86_64/nptl/tcb-offsets.sym
index 729d1da..026c9de 100644
--- a/sysdeps/x86_64/nptl/tcb-offsets.sym
+++ b/sysdeps/x86_64/nptl/tcb-offsets.sym
@@ -21,7 +21,6 @@ RTLD_SAVESPACE_SSE	offsetof (tcbhead_t, rtld_savespace_sse)
 -- Not strictly offsets, but these values are also used in the TCB.
 TCB_CANCELSTATE_BITMASK	 CANCELSTATE_BITMASK
 TCB_CANCELTYPE_BITMASK	 CANCELTYPE_BITMASK
-TCB_CANCELING_BITMASK	 CANCELING_BITMASK
 TCB_CANCELED_BITMASK	 CANCELED_BITMASK
 TCB_EXITING_BITMASK	 EXITING_BITMASK
 TCB_CANCEL_RESTMASK	 CANCEL_RESTMASK
diff --git a/sysdeps/x86_64/nptl/tls.h b/sysdeps/x86_64/nptl/tls.h
index d7543c6..0e277ec 100644
--- a/sysdeps/x86_64/nptl/tls.h
+++ b/sysdeps/x86_64/nptl/tls.h
@@ -325,17 +325,6 @@ typedef struct
 	      abort (); })
 
 
-/* Atomic set bit.  */
-# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \
-  (void) ({ if (sizeof ((descr)->member) == 4)				      \
-	      asm volatile (LOCK_PREFIX "orl %1, %%fs:%P0"		      \
-			    :: "i" (offsetof (struct pthread, member)),	      \
-			       "ir" (1 << (bit)));			      \
-	    else							      \
-	      /* Not necessary for other sizes in the moment.  */	      \
-	      abort (); })
-
-
 # define CALL_THREAD_FCT(descr) \
   ({ void *__res;							      \
      asm volatile ("movq %%fs:%P2, %%rdi\n\t"				      \

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=8acc7f59665239c1e23ec2e397c4c1bb8c8b5a9c

commit 8acc7f59665239c1e23ec2e397c4c1bb8c8b5a9c
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Sun Sep 28 23:42:13 2014 -0400

    nptl: powerpc64: Fix Race conditions in pthread cancellation (BZ#12683)
    
    This patches fixes some race conditions in NPTL cancellation code by
    redefining how cancellable syscalls are defined and handled.  Current
    approach is to enable asynchronous cancellation prior to making the syscall
    and restore the previous cancellation type once the syscall returns.
    
    As decribed in BZ#12683, this approach shows 2 important problems:
    
    1. Cancellation can act after the syscall has returned from kernel, but
       before userspace saves the return value.  It might result in a resource
       leak if the syscall allocated a resource or a side effect (partial
       read/write), and there is no way to program handle it with cancellation
       handlers.
    
    2. If a signal is handled while the thread is blocked at a cancellable
       syscall, the entire signal handler runs with asynchronous cancellation
       enabled.  This can lead to issues if the signal handler call functions
       which are async-signal-safe but not async-cancel-safe.
    
    For cancellation to work correctly, there are 5 points at which the
    cancellation signal could arrive:
    
    1. Before the final testcancel before the syscall is made.
    2. Between the testcancel and the syscall.
    3. While the syscall is blocked and no side effects have yet taken place.
    4. While the syscall is blocked but with some side effects already having
       taken place (e.g. a partial read or write).
    5. After the syscall has returned.
    
    And GLIBC wants to act on cancellation in cases 1, 2, and 3 but not in case
    4 or 5.  The proposed solution follows:
    
    * Handling case 1 is trivial: do a conditional branch based on whether the
      thread has received a cancellation request;
    * Case 2 can be caught by the signal handler determining that the saved
      program counter (from the ucontext_t) is in some address range beginning
      just before the "testcancel" and ending with the syscall instruction.
    * In this case, except for certain syscalls that ALWAYS fail with EINTR
      even for non-interrupting signals, the kernel will reset the program
      counter to point at the syscall instruction during signal handling, so
      that the syscall is restarted when the signal handler returns. So, from
      the signal handler's standpoint, this looks the same as case 2, and thus
      it's taken care of.
    * In this case, the kernel cannot restart the syscall; when it's
      interrupted by a signal, the kernel must cause the syscall to return
      with whatever partial result it obtained (e.g. partial read or write).
    * In this case, the saved program counter points just after the syscall
      instruction, so the signal handler won't act on cancellation.
      This one is equal to 4. since the program counter is past the syscall
      instruction already.
    
    Another case that needs handling is syscalls that fail with EINTR even
    when the signal handler is non-interrupting. In this case, the syscall
    wrapper code can just check the cancellation flag when the errno result
    is EINTR, and act on cancellation if it's set.
    
    The proposed GLIBC adjustments are:
    
    1. Remove the enable_asynccancel/disable_asynccancel function usage in
       syscall definition and instead make them call a common symbol that will
       check if cancellation is enabled, call the arch-specific cancellable
       entry-point and cancel the thread when required.
    2. Provide a arch-specific symbol that contains global markers. These
       markers will be used in SIGCANCEL handler to check if the interruption
       has been called in a valid syscall and if the syscalls has been
       completed or not.
    3. Rewrite SIGCANCEL asynchronous handler to check for both cancelling type
       and if current IP from signal handler falls between the global markes
       and act accordingly.
    4. Adjust nptl/pthread_cancel.c to send an signal instead of acting
       directly. This avoid synchronization issues about updating the
       cancellation status and also focus the logic on signal handler and
       cancellation syscall code.
    5. Adjust pthread code to replace CANCEL_ASYNC/CANCEL_RESET calls to
       appropriated cancelable futex syscalls.
    6. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to
       appropriated cancelable syscalls.
    7. Adjust 'lowlevellock.h' arch-specific implementations to provide
       cancelable futex calls (used in libpthread code).
    
    This patch adds the proposed changes to NPTL and the changes required
    for powerpc64.

diff --git a/ChangeLog b/ChangeLog
index fea36d8..b4f80ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,120 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/Makefile [routines]: Add syscall_cancel object.
+	[libpthread-routines]: Remove cancellation object.
+	(CFLAGS-cancellation.c): Remove -fasynchronous-unwind-tables.
+	* nptl/Versions [GLIBC_PRIVATE] (libc): Add __syscall_cancel,
+	__syscall_cancel_arch_start, and __syscall_cancel_arch_end.
+	* nptl/cancellation.c: Remove file.
+	* nptl/descr.h (CANCELING_BIT): Remove define.
+	(CANCELING_BITMASK): Likewise.
+	(CANCEL_RESTMASK): Adjust value with CANCELED_BIT remove.
+	* nptl/libc-cancellation.c (__syscall_cancel): Add non-cancellable
+	implementation for loader and cancellable one for libc.
+	(__syscall_do_cancel): New function: cancel call for syscall wrappers.
+	* nptl/lowlevellock.c (__lll_timedwait_tid): Using cancellable futex
+	call.
+	* nptl/nptl-init.c (sigcancel_handler): Rewrite function to avoid race
+	conditions.
+	(__pthread_initialize_minimal_internal): Add SA_RESTART to SIGCANCEL
+	handler.
+	* nptl/pt-system.c [LIBC_CANCEL_HANDLED]: Remove definition.
+	* io/creat.c (LIBC_CANCEL_HANDLED): Likewise.
+	* io/ppoll.c [ppoll] (LIBC_CANCEL_HANDLED): Likewise.
+	* misc/pselect [__pselect] (LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/posix/pause.c (LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/unix/sysv/linux/generic/creat.c (LIBC_CANCEL_HANDLED):
+	Likewise.
+	* nptl/pthreadP.h (__do_cancel): Rewrite to both disable asynchronous
+	cancellation and setting the thread as cancelled.
+	(CANCEL_ASYNC): Remove definition.
+	(CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_ASYNC): Likewise.
+	(LIBC_CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_HANDLED): Likewise.
+	(__syscall_cancel_arch): Add prototype.
+	(__pthread_enable_asynccancel): Remove prototype.
+	(__pthread_disable_asynccancel): Likewise.
+	(__libc_enable_asynccancel): Likewise.
+	(__libc_disable_asynccancel): Likewise.
+	(__librt_enable_asynccancel): Likewise.
+	(__librt_disable_asynccancel): Likewise.
+	(__syscall_cancel): Add prototype.
+	* nptl/pthread_cancel.c (pthread_cancel): Rewrite to just set
+	CANCELLED_BIT and call __pthread_kill.
+	* nptl/pthread_cond_timedwait.c (__pthread_cond_timedwait): Remove
+	calls to enable/disable asynchronous cancellation and use call to
+	cancellable syscall entrypoint when required.
+	* nptl/pthread_cond_wait.c (__pthread_cond_wait): Likewise.
+	* nptl/pthread_create.c (start_thread): Likewise.
+	* nptl/pthread_timedjoin.c (pthread_timedjoin_np): Likewise.
+	* nptl/sem_timedwait.c (sem_timedwait):  Likewise.
+	* nptl/sem_wait.c (__new_sem_wait): Likewise.
+	* nptl/sem_waitcommon.c (futex_abstimed_wait): Likewise.
+	* sysdeps/nptl/aio_misc.h (AIO_MISC_WAIT): Likewise.
+	* sysdeps/nptl/gai_misc.h (GAI_MISC_WAIT): Likewise.
+	* sysdeps/posix/sigpause.c (do_sigpause): Likewise.
+	* sysdeps/posix/sigwait.c (__sigwait): Likewise.
+	* sysdeps/posix/waitid.c (__waitid): Likewise.
+	* sysdeps/nptl/lowlevellock.h (lll_wait_tid): Likewise.
+	* sysdeps/posix/open64.c (__libc_open64): Likewise.
+	* sysdeps/unix/sysv/linux/sigwait.c (__sigwait): Likewise.
+	* nptl/pthread_exit.c (pthread_exit): Rewrite to set EXITING_BIT
+	before call __pthread_unwind.
+	* nptl/pthread_join.c (pthread_join): Remove CANCEL_ASYNC/CANCEL_RESET
+	usage.
+	* rt/Makefile [CFLAGS-librt-cancellation.c]: Remove rule.
+	* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
+	(LIBC_CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/unix/sysv/linux/clock_nanosleep.c (__clock_nanosleep):
+	Likewise.
+	* sysdeps/unix/sysv/linux/fcntl.c (__libc_fcntl): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c (__libc_fcntl):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c (__libc_fnctl):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S (__socket):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h (PSEUDO):
+	Likewise.
+	(PSEUDO_RET): Likewise.
+	(__pthread_get_ip): Add implementation.
+	* sysdeps/nptl/Makefile [$(subdir) = rt] (librt-sysdep_routines):
+	Remove librt-cancellation object.
+	[$(subdir) = rt] (librt-cancellation.c): Remove rule.
+	* sysdeps/nptl/librt-cancellation.c: Remove file.
+	* sysdeps/unix/sysv/linux/lowlevellock-futex.h (lll_futex_wait_cancel):
+	New define: cancellable futex wait.
+	(lll_futex_timed_wait_cancel): New define: cancellable timed wait.
+	(lll_futex_timed_wait_bitset_cancel): New define: cancellable timed
+	wait bitset.
+	(lll_futex_wait_requeue_pi_cancel): New define: cancellable wait
+	requeue PI futex.
+	(lll_futex_timed_wait_requeue_pi_cancel): New define: cancellable time
+	wait requeue PI futex.
+	(lll_wait_tid): Use cancellable futex wait call.
+	* 
+	* sysdeps/powerpc/nptl/pthreaddef.h (__pthread_get_ip): New function:
+	return ucontext_t instruction point address.
+	* sysdeps/unix/sysdep.h (SYSCALL_CANCEL): New macro: cancelable
+	syscall calls.
+	(__syscall_cancel): New prototype.
+	* sysdeps/unix/sysv/linux/socketcall.h (SOCKETCALL): Use __SSC macros.
+	(SOCKETCALL_CANCEL): Use SYSCALL_CANCEL macros.
+	* sysdeps/generic/sysdep-cancel.h (LIBC_CANCEL_ASYNC): Remove define.
+	(LIBC_CANCEL_RESET): Likewise.
+	(LIBC_CANCEL_HANDLED): Likewise.
+	* sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Allow
+	SIGCANCEL to be sent.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
+	(SYSCALL_CANCEL_ERROR): New define.
+	(SYSCALL_CANCEL_ERRNO): New define.
+	* sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S: New file:
+	cancellable syscall.
+	* sysdeps/unix/sysv/linux/powerpc/sysdep.c (__syscall_cancel_error):
+	New symbol: cancellable syscall error handler.
+
 	* nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove
 	tst-cancel-wrappers.sh.
 	* nptl/tst-cancel-wrappers.sh: Remove file.
diff --git a/io/creat.c b/io/creat.c
index c03810d..f602401 100644
--- a/io/creat.c
+++ b/io/creat.c
@@ -29,6 +29,3 @@ creat (file, mode)
 {
   return __open (file, O_WRONLY|O_CREAT|O_TRUNC, mode);
 }
-
-/* __open handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
diff --git a/io/ppoll.c b/io/ppoll.c
index f64c737..3f08f1d 100644
--- a/io/ppoll.c
+++ b/io/ppoll.c
@@ -70,7 +70,5 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
 }
 
 #ifndef ppoll
-/* __poll handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
 libc_hidden_def (ppoll);
 #endif
diff --git a/misc/pselect.c b/misc/pselect.c
index 2f8d0a3..e8d6dfd 100644
--- a/misc/pselect.c
+++ b/misc/pselect.c
@@ -73,6 +73,4 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
 }
 #ifndef __pselect
 weak_alias (__pselect, pselect)
-/* __select handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
 #endif
diff --git a/nptl/Makefile b/nptl/Makefile
index 13113c1..6659460 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -30,7 +30,7 @@ install-lib-ldscripts := libpthread.so
 
 routines = alloca_cutoff forward libc-lowlevellock libc-cancellation \
 	   libc-cleanup libc_pthread_init libc_multiple_threads \
-	   register-atfork unregister-atfork
+	   register-atfork unregister-atfork syscall_cancel
 shared-only-routines = forward
 
 libpthread-routines = nptl-init vars events version \
@@ -104,7 +104,6 @@ libpthread-routines = nptl-init vars events version \
 		      cleanup cleanup_defer cleanup_compat \
 		      cleanup_defer_compat unwind \
 		      pt-longjmp pt-cleanup\
-		      cancellation \
 		      lowlevellock lowlevelrobustlock \
 		      pt-fork pt-vfork \
 		      ptw-write ptw-read ptw-close ptw-fcntl ptw-accept \
@@ -157,7 +156,6 @@ CFLAGS-pthread_setcanceltype.c = -fexceptions -fasynchronous-unwind-tables
 
 # These are internal functions which similar functionality as setcancelstate
 # and setcanceltype.
-CFLAGS-cancellation.c = -fasynchronous-unwind-tables
 CFLAGS-libc-cancellation.c = -fasynchronous-unwind-tables
 
 # Calling pthread_exit() must cause the registered cancel handlers to
diff --git a/nptl/Versions b/nptl/Versions
index bc8a15b..10a724d 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -36,6 +36,9 @@ libc {
     __libc_pthread_init;
     __libc_current_sigrtmin_private; __libc_current_sigrtmax_private;
     __libc_allocate_rtsig_private;
+    __syscall_cancel;
+    __syscall_cancel_arch_start;
+    __syscall_cancel_arch_end;
   }
 }
 
diff --git a/nptl/cancellation.c b/nptl/cancellation.c
deleted file mode 100644
index deac1eb..0000000
--- a/nptl/cancellation.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   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 <setjmp.h>
-#include <stdlib.h>
-#include "pthreadP.h"
-
-
-/* The next two functions are similar to pthread_setcanceltype() but
-   more specialized for the use in the cancelable functions like write().
-   They do not need to check parameters etc.  */
-int
-attribute_hidden
-__pthread_enable_asynccancel (void)
-{
-  struct pthread *self = THREAD_SELF;
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-
-  while (1)
-    {
-      int newval = oldval | CANCELTYPE_BITMASK;
-
-      if (newval == oldval)
-	break;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (__glibc_likely (curval == oldval))
-	{
-	  if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	    {
-	      THREAD_SETMEM (self, result, PTHREAD_CANCELED);
-	      __do_cancel ();
-	    }
-
-	  break;
-	}
-
-      /* Prepare the next round.  */
-      oldval = curval;
-    }
-
-  return oldval;
-}
-
-
-void
-internal_function attribute_hidden
-__pthread_disable_asynccancel (int oldtype)
-{
-  /* If asynchronous cancellation was enabled before we do not have
-     anything to do.  */
-  if (oldtype & CANCELTYPE_BITMASK)
-    return;
-
-  struct pthread *self = THREAD_SELF;
-  int newval;
-
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-
-  while (1)
-    {
-      newval = oldval & ~CANCELTYPE_BITMASK;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (__glibc_likely (curval == oldval))
-	break;
-
-      /* Prepare the next round.  */
-      oldval = curval;
-    }
-
-  /* We cannot return when we are being canceled.  Upon return the
-     thread might be things which would have to be undone.  The
-     following loop should loop until the cancellation signal is
-     delivered.  */
-  while (__builtin_expect ((newval & (CANCELING_BITMASK | CANCELED_BITMASK))
-			   == CANCELING_BITMASK, 0))
-    {
-      lll_futex_wait (&self->cancelhandling, newval, LLL_PRIVATE);
-      newval = THREAD_GETMEM (self, cancelhandling);
-    }
-}
diff --git a/nptl/descr.h b/nptl/descr.h
index 5bd1282..9566809 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -263,23 +263,20 @@ struct pthread
   /* Bit set if asynchronous cancellation mode is selected.  */
 #define CANCELTYPE_BIT		1
 #define CANCELTYPE_BITMASK	(0x01 << CANCELTYPE_BIT)
-  /* Bit set if canceling has been initiated.  */
-#define CANCELING_BIT		2
-#define CANCELING_BITMASK	(0x01 << CANCELING_BIT)
-  /* Bit set if canceled.  */
-#define CANCELED_BIT		3
+  /* Bit set if threads is canceled.  */
+#define CANCELED_BIT		2
 #define CANCELED_BITMASK	(0x01 << CANCELED_BIT)
   /* Bit set if thread is exiting.  */
-#define EXITING_BIT		4
+#define EXITING_BIT		3
 #define EXITING_BITMASK		(0x01 << EXITING_BIT)
   /* Bit set if thread terminated and TCB is freed.  */
-#define TERMINATED_BIT		5
+#define TERMINATED_BIT		4
 #define TERMINATED_BITMASK	(0x01 << TERMINATED_BIT)
   /* Bit set if thread is supposed to change XID.  */
-#define SETXID_BIT		6
+#define SETXID_BIT		5
 #define SETXID_BITMASK		(0x01 << SETXID_BIT)
   /* Mask for the rest.  Helps the compiler to optimize.  */
-#define CANCEL_RESTMASK		0xffffff80
+#define CANCEL_RESTMASK		0xffffffc0
 
 #define CANCEL_ENABLED_AND_CANCELED(value) \
   (((value) & (CANCELSTATE_BITMASK | CANCELED_BITMASK | EXITING_BITMASK	      \
diff --git a/nptl/libc-cancellation.c b/nptl/libc-cancellation.c
index cc9dc06..5c7d357 100644
--- a/nptl/libc-cancellation.c
+++ b/nptl/libc-cancellation.c
@@ -16,9 +16,63 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <setjmp.h>
+#include <stdlib.h>
 #include "pthreadP.h"
 
+#if IS_IN (rtld)
 
-#define __pthread_enable_asynccancel __libc_enable_asynccancel
-#define __pthread_disable_asynccancel __libc_disable_asynccancel
-#include <nptl/cancellation.c>
+long int
+__syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1,
+		  __syscall_arg_t arg2, __syscall_arg_t arg3,
+		  __syscall_arg_t arg4, __syscall_arg_t arg5,
+		  __syscall_arg_t arg6)
+{
+  INTERNAL_SYSCALL_DECL (err);
+  return INTERNAL_SYSCALL_NCS (nr, err, 6, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+#else
+
+/* Cancellation function called by all cancellable syscalls.  */
+long int
+__syscall_cancel (__syscall_arg_t nr, __syscall_arg_t a1,
+		  __syscall_arg_t a2, __syscall_arg_t a3,
+		  __syscall_arg_t a4, __syscall_arg_t a5,
+		  __syscall_arg_t a6)
+{
+  pthread_t self = (pthread_t) THREAD_SELF;
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  long int result;
+
+  /* If cancellation is not enabled, call the syscall directly.  */
+  if (pd->cancelhandling & CANCELSTATE_BITMASK)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      result = INTERNAL_SYSCALL_NCS (nr, err, 6, a1, a2, a3, a4, a5, a6);
+      return INTERNAL_SYSCALL_ERROR_P (result, err) ? -result : result;
+    }
+
+  /* Call the arch-specific entry points that contains the globals markers
+     to be checked by SIGCANCEL handler.  */
+  result = __syscall_cancel_arch (&pd->cancelhandling, nr, a1, a2, a3, a4, a5,
+			          a6);
+
+  if ((result == -EINTR)
+      && (pd->cancelhandling & CANCELED_BITMASK)
+      && !(pd->cancelhandling & CANCELSTATE_BITMASK))
+    __do_cancel ();
+
+  return result;
+}
+libc_hidden_def (__syscall_cancel)
+
+/* Since __do_cancel is a always inline function, this creates a symbol the
+   arch-specific symbol can call to cancel the thread.  */
+void
+__syscall_do_cancel (void)
+{
+  __do_cancel ();
+}
+
+#endif
diff --git a/nptl/lowlevellock.c b/nptl/lowlevellock.c
index 98c859f..4b2effe 100644
--- a/nptl/lowlevellock.c
+++ b/nptl/lowlevellock.c
@@ -122,7 +122,7 @@ __lll_timedwait_tid (int *tidp, const struct timespec *abstime)
          The kernel up to version 3.16.3 does not use the private futex
          operations for futex wake-up when the clone terminates.
       */
-      if (lll_futex_timed_wait (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT)
+      if (lll_futex_timed_wait_cancel (tidp, tid, &rt, LLL_SHARED) == -ETIMEDOUT)
 	return ETIMEDOUT;
     }
 
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 1ad41c5..ae5b809 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -36,6 +36,7 @@
 #include <lowlevellock.h>
 #include <kernel-features.h>
 #include <libc-internal.h>
+#include <sysdep-cancel.h>
 
 #ifndef TLS_MULTIPLE_THREADS_IN_TCB
 /* Pointer to the corresponding variable in libc.  */
@@ -198,36 +199,41 @@ sigcancel_handler (int sig, siginfo_t *si, void *ctx)
     return;
 
   struct pthread *self = THREAD_SELF;
+  volatile struct pthread *pd = (volatile struct pthread *) self;
+  ucontext_t *uc = ctx;
+  const char *tip = (const char *)__pthread_get_ip (ctx);
 
-  int oldval = THREAD_GETMEM (self, cancelhandling);
-  while (1)
+  extern const char __syscall_cancel_arch_start[1];
+  extern const char __syscall_cancel_arch_end[1];
+
+  if (((pd->cancelhandling & (CANCELSTATE_BITMASK)) != 0)
+      || ((pd->cancelhandling & CANCELED_BITMASK) == 0))
+    return;
+
+  __sigaddset (&uc->uc_sigmask, SIGCANCEL);
+
+  /* Check if asynchronous cancellation mode is set and if interrupted
+     instruction pointer falls within the cancellable syscall code.  For
+     interruptable syscalls that might generate external side-effects (partial
+     reads or writes, for instance), the kernel will set the IP to after
+     '__syscall_cancel_arch_end', thus disabling the cancellation and allowing
+     the process to handle such conditions.  */
+  if (pd->cancelhandling & CANCELTYPE_BITMASK ||
+      (tip >= __syscall_cancel_arch_start && tip < __syscall_cancel_arch_end))
     {
-      /* We are canceled now.  When canceled by another thread this flag
-	 is already set but if the signal is directly send (internally or
-	 from another process) is has to be done here.  */
-      int newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK;
-
-      if (oldval == newval || (oldval & EXITING_BITMASK) != 0)
-	/* Already canceled or exiting.  */
-	break;
-
-      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
-					      oldval);
-      if (curval == oldval)
-	{
-	  /* Set the return value.  */
-	  THREAD_SETMEM (self, result, PTHREAD_CANCELED);
-
-	  /* Make sure asynchronous cancellation is still enabled.  */
-	  if ((newval & CANCELTYPE_BITMASK) != 0)
-	    /* Run the registered destructors and terminate the thread.  */
-	    __do_cancel ();
-
-	  break;
-	}
-
-      oldval = curval;
+      THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+      THREAD_SETMEM (self, result, PTHREAD_CANCELED);
+
+      /* __pthread_sigmask removes SIGCANCEL from the set.  */
+      INTERNAL_SYSCALL_DECL (err);
+      INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIGCANCEL, &uc->uc_sigmask, 0,
+                        _NSIG / 8);
+
+      __do_cancel ();
     }
+
+  INLINE_SYSCALL (tgkill, 3, THREAD_GETMEM (THREAD_SELF, pid), pd->tid,
+		  SIGCANCEL);
 }
 #endif
 
@@ -396,7 +402,10 @@ __pthread_initialize_minimal_internal (void)
      cannot install the handler we do not abort.  Maybe we should, but
      it is only asynchronous cancellation which is affected.  */
   sa.sa_sigaction = sigcancel_handler;
-  sa.sa_flags = SA_SIGINFO;
+  /* The signal handle should be non-interruptible to avoid the risk of
+     spurious EINTR caused by SIGCANCEL sent to process or if pthread_cancel
+     is called while cancellation is disabled in the target thread.  */
+  sa.sa_flags = SA_SIGINFO | SA_RESTART;
   (void) __libc_sigaction (SIGCANCEL, &sa, NULL);
 # endif
 
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 84a7105..f29f23e 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -278,49 +278,32 @@ __do_cancel (void)
   struct pthread *self = THREAD_SELF;
 
   /* Make sure we get no more cancellations.  */
-  THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+  int oldval = THREAD_GETMEM (self, cancelhandling);
+  while (1)
+    {
+      int newval = (oldval | CANCELSTATE_BITMASK);
+      newval &= ~(CANCELTYPE_BITMASK);
+      if (oldval == newval)
+	break;
+
+      int curval = THREAD_ATOMIC_CMPXCHG_VAL (self, cancelhandling, newval,
+					  oldval);
+      if (__glibc_likely (curval == oldval))
+	break;
+      oldval = curval;
+    }
+
+  THREAD_SETMEM (self, result, PTHREAD_CANCELED);
 
   __pthread_unwind ((__pthread_unwind_buf_t *)
 		    THREAD_GETMEM (self, cleanup_jmp_buf));
 }
 
 
-/* Set cancellation mode to asynchronous.  */
-#define CANCEL_ASYNC() \
-  __pthread_enable_asynccancel ()
-/* Reset to previous cancellation mode.  */
-#define CANCEL_RESET(oldtype) \
-  __pthread_disable_asynccancel (oldtype)
-
-#if IS_IN (libc)
-/* Same as CANCEL_ASYNC, but for use in libc.so.  */
-# define LIBC_CANCEL_ASYNC() \
-  __libc_enable_asynccancel ()
-/* Same as CANCEL_RESET, but for use in libc.so.  */
-# define LIBC_CANCEL_RESET(oldtype) \
-  __libc_disable_asynccancel (oldtype)
-# define LIBC_CANCEL_HANDLED() \
-  __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \
-  __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel")
-#elif IS_IN (libpthread)
-# define LIBC_CANCEL_ASYNC() CANCEL_ASYNC ()
-# define LIBC_CANCEL_RESET(val) CANCEL_RESET (val)
-# define LIBC_CANCEL_HANDLED() \
-  __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \
-  __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel")
-#elif IS_IN (librt)
-# define LIBC_CANCEL_ASYNC() \
-  __librt_enable_asynccancel ()
-# define LIBC_CANCEL_RESET(val) \
-  __librt_disable_asynccancel (val)
-# define LIBC_CANCEL_HANDLED() \
-  __asm (".globl " __SYMBOL_PREFIX "__librt_enable_asynccancel"); \
-  __asm (".globl " __SYMBOL_PREFIX "__librt_disable_asynccancel")
-#else
-# define LIBC_CANCEL_ASYNC()	0 /* Just a dummy value.  */
-# define LIBC_CANCEL_RESET(val)	((void)(val)) /* Nothing, but evaluate it.  */
-# define LIBC_CANCEL_HANDLED()	/* Nothing.  */
-#endif
+extern long int __syscall_cancel_arch (volatile void *, __syscall_arg_t nr,
+     __syscall_arg_t arg1, __syscall_arg_t arg2, __syscall_arg_t arg3,
+     __syscall_arg_t arg4, __syscall_arg_t arg5, __syscall_arg_t arg6);
+libc_hidden_proto (__syscall_cancel_arch);
 
 
 /* Internal prototypes.  */
@@ -488,9 +471,6 @@ extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
 extern int __pthread_kill (pthread_t threadid, int signo);
 extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
 extern int __pthread_setcanceltype (int type, int *oldtype);
-extern int __pthread_enable_asynccancel (void) attribute_hidden;
-extern void __pthread_disable_asynccancel (int oldtype)
-     internal_function attribute_hidden;
 
 #if IS_IN (libpthread)
 hidden_proto (__pthread_mutex_init)
@@ -520,16 +500,6 @@ extern int __pthread_cond_wait_2_0 (pthread_cond_2_0_t *cond,
 extern int __pthread_getaffinity_np (pthread_t th, size_t cpusetsize,
 				     cpu_set_t *cpuset);
 
-/* The two functions are in libc.so and not exported.  */
-extern int __libc_enable_asynccancel (void) attribute_hidden;
-extern void __libc_disable_asynccancel (int oldtype)
-     internal_function attribute_hidden;
-
-
-/* The two functions are in librt.so and not exported.  */
-extern int __librt_enable_asynccancel (void) attribute_hidden;
-extern void __librt_disable_asynccancel (int oldtype)
-     internal_function attribute_hidden;
 
 #if IS_IN (libpthread)
 /* Special versions which use non-exported functions.  */
diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
index 981e4bc..c0776c6 100644
--- a/nptl/pthread_cancel.c
+++ b/nptl/pthread_cancel.c
@@ -23,7 +23,6 @@
 #include <atomic.h>
 #include <sysdep.h>
 
-
 int
 pthread_cancel (pthread_t th)
 {
@@ -37,75 +36,17 @@ pthread_cancel (pthread_t th)
 #ifdef SHARED
   pthread_cancel_init ();
 #endif
-  int result = 0;
-  int oldval;
-  int newval;
-  do
-    {
-    again:
-      oldval = pd->cancelhandling;
-      newval = oldval | CANCELING_BITMASK | CANCELED_BITMASK;
-
-      /* Avoid doing unnecessary work.  The atomic operation can
-	 potentially be expensive if the bug has to be locked and
-	 remote cache lines have to be invalidated.  */
-      if (oldval == newval)
-	break;
-
-      /* If the cancellation is handled asynchronously just send a
-	 signal.  We avoid this if possible since it's more
-	 expensive.  */
-      if (CANCEL_ENABLED_AND_CANCELED_AND_ASYNCHRONOUS (newval))
-	{
-	  /* Mark the cancellation as "in progress".  */
-	  if (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling,
-						    oldval | CANCELING_BITMASK,
-						    oldval))
-	    goto again;
-
-#ifdef SIGCANCEL
-	  /* The cancellation handler will take care of marking the
-	     thread as canceled.  */
-	  INTERNAL_SYSCALL_DECL (err);
-
-	  /* One comment: The PID field in the TCB can temporarily be
-	     changed (in fork).  But this must not affect this code
-	     here.  Since this function would have to be called while
-	     the thread is executing fork, it would have to happen in
-	     a signal handler.  But this is no allowed, pthread_cancel
-	     is not guaranteed to be async-safe.  */
-	  int val;
-	  val = INTERNAL_SYSCALL (tgkill, err, 3,
-				  THREAD_GETMEM (THREAD_SELF, pid), pd->tid,
-				  SIGCANCEL);
-
-	  if (INTERNAL_SYSCALL_ERROR_P (val, err))
-	    result = INTERNAL_SYSCALL_ERRNO (val, err);
-#else
-          /* It should be impossible to get here at all, since
-             pthread_setcanceltype should never have allowed
-             PTHREAD_CANCEL_ASYNCHRONOUS to be set.  */
-          abort ();
-#endif
-
-	  break;
-	}
 
-	/* A single-threaded process should be able to kill itself, since
-	   there is nothing in the POSIX specification that says that it
-	   cannot.  So we set multiple_threads to true so that cancellation
-	   points get executed.  */
-	THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
+  THREAD_ATOMIC_BIT_SET (pd, cancelhandling, CANCELED_BIT);
+  /* A single-threaded process should be able to kill itself, since there is
+     nothing in the POSIX specification that says that it cannot.  So we set
+     multiple_threads to true so that cancellation points get executed.  */
+  THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
 #ifndef TLS_MULTIPLE_THREADS_IN_TCB
-	__pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
+  __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;
 #endif
-    }
-  /* Mark the thread as canceled.  This has to be done
-     atomically since other bits could be modified as well.  */
-  while (atomic_compare_and_exchange_bool_acq (&pd->cancelhandling, newval,
-					       oldval));
 
-  return result;
+  return __pthread_kill (th, SIGCANCEL);
 }
 
 PTHREAD_STATIC_FN_REQUIRE (pthread_create)
diff --git a/nptl/pthread_cond_timedwait.c b/nptl/pthread_cond_timedwait.c
index 10b0a61..8c944c6 100644
--- a/nptl/pthread_cond_timedwait.c
+++ b/nptl/pthread_cond_timedwait.c
@@ -42,7 +42,6 @@ extern void __condvar_cleanup (void *arg)
 
 struct _condvar_cleanup_buffer
 {
-  int oldtype;
   pthread_cond_t *cond;
   pthread_mutex_t *mutex;
   unsigned int bc_seq;
@@ -63,7 +62,7 @@ __pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
   int pshared = (cond->__data.__mutex == (void *) ~0l)
 		? LLL_SHARED : LLL_PRIVATE;
 
-#if (defined lll_futex_timed_wait_requeue_pi \
+#if (defined lll_futex_timed_wait_requeue_pi_cancel \
      && defined __ASSUME_REQUEUE_PI)
   int pi_flag = 0;
 #endif
@@ -156,12 +155,9 @@ __pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
       /* Prepare to wait.  Release the condvar futex.  */
       lll_unlock (cond->__data.__lock, pshared);
 
-      /* Enable asynchronous cancellation.  Required by the standard.  */
-      cbuffer.oldtype = __pthread_enable_asynccancel ();
-
 /* REQUEUE_PI was implemented after FUTEX_CLOCK_REALTIME, so it is sufficient
    to check just the former.  */
-#if (defined lll_futex_timed_wait_requeue_pi \
+#if (defined lll_futex_timed_wait_requeue_pi_cancel \
      && defined __ASSUME_REQUEUE_PI)
       /* If pi_flag remained 1 then it means that we had the lock and the mutex
 	 but a spurious waker raced ahead of us.  Give back the mutex before
@@ -177,10 +173,11 @@ __pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
 	{
 	  unsigned int clockbit = (cond->__data.__nwaiters & 1
 				   ? 0 : FUTEX_CLOCK_REALTIME);
-	  err = lll_futex_timed_wait_requeue_pi (&cond->__data.__futex,
-						 futex_val, abstime, clockbit,
-						 &mutex->__data.__lock,
-						 pshared);
+	  err = lll_futex_timed_wait_requeue_pi_cancel (&cond->__data.__futex,
+							futex_val, abstime,
+							clockbit,
+							&mutex->__data.__lock,
+							pshared);
 	  pi_flag = (err == 0);
 	}
       else
@@ -188,21 +185,19 @@ __pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
 
 	{
 #if (!defined __ASSUME_FUTEX_CLOCK_REALTIME \
-     || !defined lll_futex_timed_wait_bitset)
+     || !defined lll_futex_timed_wait_bitset_cancel)
 	  /* Wait until woken by signal or broadcast.  */
-	  err = lll_futex_timed_wait (&cond->__data.__futex,
-				      futex_val, &rt, pshared);
+	  err = lll_futex_timed_wait_cancel (&cond->__data.__futex,
+					     futex_val, &rt, pshared);
 #else
 	  unsigned int clockbit = (cond->__data.__nwaiters & 1
 				   ? 0 : FUTEX_CLOCK_REALTIME);
-	  err = lll_futex_timed_wait_bitset (&cond->__data.__futex, futex_val,
-					     abstime, clockbit, pshared);
+	  err = lll_futex_timed_wait_bitset_cancel (&cond->__data.__futex,
+						    futex_val,abstime,
+						    clockbit, pshared);
 #endif
 	}
 
-      /* Disable asynchronous cancellation.  */
-      __pthread_disable_asynccancel (cbuffer.oldtype);
-
       /* We are going to look at shared data again, so get the lock.  */
       lll_lock (cond->__data.__lock, pshared);
 
diff --git a/nptl/pthread_cond_wait.c b/nptl/pthread_cond_wait.c
index 0d6558b..8e7bebb 100644
--- a/nptl/pthread_cond_wait.c
+++ b/nptl/pthread_cond_wait.c
@@ -29,7 +29,6 @@
 
 struct _condvar_cleanup_buffer
 {
-  int oldtype;
   pthread_cond_t *cond;
   pthread_mutex_t *mutex;
   unsigned int bc_seq;
@@ -106,7 +105,7 @@ __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
   int pshared = (cond->__data.__mutex == (void *) ~0l)
 		? LLL_SHARED : LLL_PRIVATE;
 
-#if (defined lll_futex_wait_requeue_pi \
+#if (defined lll_futex_wait_requeue_pi_cancel \
      && defined __ASSUME_REQUEUE_PI)
   int pi_flag = 0;
 #endif
@@ -157,10 +156,7 @@ __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
       /* Prepare to wait.  Release the condvar futex.  */
       lll_unlock (cond->__data.__lock, pshared);
 
-      /* Enable asynchronous cancellation.  Required by the standard.  */
-      cbuffer.oldtype = __pthread_enable_asynccancel ();
-
-#if (defined lll_futex_wait_requeue_pi \
+#if (defined lll_futex_wait_requeue_pi_cancel \
      && defined __ASSUME_REQUEUE_PI)
       /* If pi_flag remained 1 then it means that we had the lock and the mutex
 	 but a spurious waker raced ahead of us.  Give back the mutex before
@@ -174,19 +170,17 @@ __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
 
       if (pi_flag)
 	{
-	  err = lll_futex_wait_requeue_pi (&cond->__data.__futex,
-					   futex_val, &mutex->__data.__lock,
-					   pshared);
+	  err = lll_futex_wait_requeue_pi_cancel (&cond->__data.__futex,
+						  futex_val,
+						  &mutex->__data.__lock,
+						  pshared);
 
 	  pi_flag = (err == 0);
 	}
       else
 #endif
 	  /* Wait until woken by signal or broadcast.  */
-	lll_futex_wait (&cond->__data.__futex, futex_val, pshared);
-
-      /* Disable asynchronous cancellation.  */
-      __pthread_disable_asynccancel (cbuffer.oldtype);
+	lll_futex_wait_cancel (&cond->__data.__futex, futex_val, pshared);
 
       /* We are going to look at shared data again, so get the lock.  */
       lll_lock (cond->__data.__lock, pshared);
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 71a5619..bdd6c0c 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -288,7 +288,7 @@ START_THREAD_DEFN
   /* If the parent was running cancellation handlers while creating
      the thread the new thread inherited the signal mask.  Reset the
      cancellation signal mask.  */
-  if (__glibc_unlikely (pd->parent_cancelhandling & CANCELING_BITMASK))
+  if (__glibc_unlikely (pd->parent_cancelhandling & CANCELED_BITMASK))
     {
       INTERNAL_SYSCALL_DECL (err);
       sigset_t mask;
@@ -316,14 +316,10 @@ START_THREAD_DEFN
 
       if (__glibc_unlikely (pd->stopped_start))
 	{
-	  int oldtype = CANCEL_ASYNC ();
-
 	  /* Get the lock the parent locked to force synchronization.  */
 	  lll_lock (pd->lock, LLL_PRIVATE);
 	  /* And give it up right away.  */
 	  lll_unlock (pd->lock, LLL_PRIVATE);
-
-	  CANCEL_RESET (oldtype);
 	}
 
       LIBC_PROBE (pthread_start, 3, (pthread_t) pd, pd->start_routine, pd->arg);
diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c
index a60adbd..6976980 100644
--- a/nptl/pthread_exit.c
+++ b/nptl/pthread_exit.c
@@ -23,9 +23,14 @@
 void
 __pthread_exit (void *value)
 {
-  THREAD_SETMEM (THREAD_SELF, result, value);
+  struct pthread *self = THREAD_SELF;
 
-  __do_cancel ();
+  THREAD_SETMEM (self, result, value);
+
+  THREAD_ATOMIC_BIT_SET (self, cancelhandling, EXITING_BIT);
+
+  __pthread_unwind ((__pthread_unwind_buf_t *)
+		    THREAD_GETMEM (self, cleanup_jmp_buf));
 }
 strong_alias (__pthread_exit, pthread_exit)
 
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index c841ff9..2c8ce0c 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -61,13 +61,10 @@ pthread_join (pthread_t threadid, void **thread_return)
      un-wait-ed for again.  */
   pthread_cleanup_push (cleanup, &pd->joinid);
 
-  /* Switch to asynchronous cancellation.  */
-  int oldtype = CANCEL_ASYNC ();
-
   if ((pd == self
        || (self->joinid == pd
 	   && (pd->cancelhandling
-	       & (CANCELING_BITMASK | CANCELED_BITMASK | EXITING_BITMASK
+	       & (CANCELED_BITMASK | EXITING_BITMASK
 		  | TERMINATED_BITMASK)) == 0))
       && !CANCEL_ENABLED_AND_CANCELED (self->cancelhandling))
     /* This is a deadlock situation.  The threads are waiting for each
@@ -89,10 +86,6 @@ pthread_join (pthread_t threadid, void **thread_return)
     /* Wait for the child.  */
     lll_wait_tid (pd->tid);
 
-
-  /* Restore cancellation mode.  */
-  CANCEL_RESET (oldtype);
-
   /* Remove the handler.  */
   pthread_cleanup_pop (0);
 
diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c
index 10567e6..2131e95 100644
--- a/nptl/pthread_timedjoin.c
+++ b/nptl/pthread_timedjoin.c
@@ -71,17 +71,9 @@ pthread_timedjoin_np (pthread_t threadid, void **thread_return,
      un-wait-ed for again.  */
   pthread_cleanup_push (cleanup, &pd->joinid);
 
-  /* Switch to asynchronous cancellation.  */
-  int oldtype = CANCEL_ASYNC ();
-
-
   /* Wait for the child.  */
   result = lll_timedwait_tid (pd->tid, abstime);
 
-
-  /* Restore cancellation mode.  */
-  CANCEL_RESET (oldtype);
-
   /* Remove the handler.  */
   pthread_cleanup_pop (0);
 
diff --git a/nptl/sem_wait.c b/nptl/sem_wait.c
index c1fd10c..66a4820 100644
--- a/nptl/sem_wait.c
+++ b/nptl/sem_wait.c
@@ -42,14 +42,8 @@ __old_sem_wait (sem_t *sem)
       if (atomic_decrement_if_positive (futex) > 0)
 	return 0;
 
-      /* Enable asynchronous cancellation.  Required by the standard.  */
-      int oldtype = __pthread_enable_asynccancel ();
-
       /* Always assume the semaphore is shared.  */
-      err = lll_futex_wait (futex, 0, LLL_SHARED);
-
-      /* Disable asynchronous cancellation.  */
-      __pthread_disable_asynccancel (oldtype);
+      err = lll_futex_wait_cancel (futex, 0, LLL_SHARED);
     }
   while (err == 0 || err == -EWOULDBLOCK);
 
diff --git a/nptl/sem_waitcommon.c b/nptl/sem_waitcommon.c
index 772425d..7ffa01d 100644
--- a/nptl/sem_waitcommon.c
+++ b/nptl/sem_waitcommon.c
@@ -35,14 +35,13 @@ static __always_inline int
 futex_abstimed_wait (unsigned int* futex, unsigned int expected,
 		     const struct timespec* abstime, int private, bool cancel)
 {
-  int err, oldtype;
+  int err;
   if (abstime == NULL)
     {
       if (cancel)
-	oldtype = __pthread_enable_asynccancel ();
-      err = lll_futex_wait (futex, expected, private);
-      if (cancel)
-	__pthread_disable_asynccancel (oldtype);
+	err = lll_futex_wait_cancel (futex, expected, private);
+      else
+	err = lll_futex_wait (futex, expected, private);
     }
   else
     {
@@ -78,16 +77,15 @@ futex_abstimed_wait (unsigned int* futex, unsigned int expected,
       rt.tv_nsec = nsec;
 #endif
       if (cancel)
-	oldtype = __pthread_enable_asynccancel ();
+
 #if (defined __ASSUME_FUTEX_CLOCK_REALTIME	\
      && defined lll_futex_timed_wait_bitset)
-      err = lll_futex_timed_wait_bitset (futex, expected, abstime,
-					 FUTEX_CLOCK_REALTIME, private);
+      err = lll_futex_timed_wait_bitset_cancel (futex, expected, abstime,
+						FUTEX_CLOCK_REALTIME,
+						private);
 #else
-      err = lll_futex_timed_wait (futex, expected, &rt, private);
+      err = lll_futex_timed_wait_cancel (futex, expected, &rt, private);
 #endif
-      if (cancel)
-	__pthread_disable_asynccancel (oldtype);
     }
   switch (err)
     {
diff --git a/rt/Makefile b/rt/Makefile
index e62e059..11a2dd5 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -62,7 +62,6 @@ include ../Rules
 
 CFLAGS-aio_suspend.c = -fexceptions
 CFLAGS-clock_nanosleep.c = -fexceptions -fasynchronous-unwind-tables
-CFLAGS-librt-cancellation.c = -fasynchronous-unwind-tables
 
 LDFLAGS-rt.so = -Wl,--enable-new-dtags,-z,nodelete
 
diff --git a/sysdeps/generic/sysdep-cancel.h b/sysdeps/generic/sysdep-cancel.h
index ba6a1e0..5c84b44 100644
--- a/sysdeps/generic/sysdep-cancel.h
+++ b/sysdeps/generic/sysdep-cancel.h
@@ -3,6 +3,3 @@
 /* No multi-thread handling enabled.  */
 #define SINGLE_THREAD_P (1)
 #define RTLD_SINGLE_THREAD_P (1)
-#define LIBC_CANCEL_ASYNC()	0 /* Just a dummy value.  */
-#define LIBC_CANCEL_RESET(val)	((void)(val)) /* Nothing, but evaluate it.  */
-#define LIBC_CANCEL_HANDLED()	/* Nothing.  */
diff --git a/sysdeps/nptl/Makefile b/sysdeps/nptl/Makefile
index e9339a3..0d44a08 100644
--- a/sysdeps/nptl/Makefile
+++ b/sysdeps/nptl/Makefile
@@ -21,8 +21,7 @@ libpthread-sysdep_routines += errno-loc
 endif
 
 ifeq ($(subdir),rt)
-librt-sysdep_routines += timer_routines librt-cancellation
-CFLAGS-librt-cancellation.c += -fexceptions -fasynchronous-unwind-tables
+librt-sysdep_routines += timer_routines
 
 ifeq ($(have-forced-unwind),yes)
 tests += tst-mqueue8x
diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
index fb69b0f..5101591 100644
--- a/sysdeps/nptl/aio_misc.h
+++ b/sysdeps/nptl/aio_misc.h
@@ -41,15 +41,15 @@
       {									      \
 	pthread_mutex_unlock (&__aio_requests_mutex);			      \
 									      \
-	int oldtype;							      \
-	if (cancel)							      \
-	  oldtype = LIBC_CANCEL_ASYNC ();				      \
-									      \
 	int status;							      \
 	do								      \
 	  {								      \
-	    status = lll_futex_timed_wait (futexaddr, oldval, timeout,	      \
-					   LLL_PRIVATE);		      \
+	    if (cancel)							      \
+	      status = lll_futex_timed_wait_cancel (futexaddr, oldval,	      \
+						    timeout, LLL_PRIVATE);    \
+	    else							      \
+	      status = lll_futex_timed_wait (futexaddr, oldval, timeout,      \
+					     LLL_PRIVATE);		      \
 	    if (status != -EWOULDBLOCK)					      \
 	      break;							      \
 									      \
@@ -57,9 +57,6 @@
 	  }								      \
 	while (oldval != 0);						      \
 									      \
-	if (cancel)							      \
-	  LIBC_CANCEL_RESET (oldtype);					      \
-									      \
 	if (status == -EINTR)						      \
 	  result = EINTR;						      \
 	else if (status == -ETIMEDOUT)					      \
diff --git a/sysdeps/nptl/gai_misc.h b/sysdeps/nptl/gai_misc.h
index bb83dca..0efef23 100644
--- a/sysdeps/nptl/gai_misc.h
+++ b/sysdeps/nptl/gai_misc.h
@@ -42,15 +42,15 @@
       {									      \
 	pthread_mutex_unlock (&__gai_requests_mutex);			      \
 									      \
-	int oldtype;							      \
-	if (cancel)							      \
-	  oldtype = LIBC_CANCEL_ASYNC ();				      \
-									      \
 	int status;							      \
 	do								      \
 	  {								      \
-	    status = lll_futex_timed_wait (futexaddr, oldval, timeout,	      \
-					   LLL_PRIVATE);		      \
+	    if (cancel)							      \
+	      status = lll_futex_timed_wait_cancel (futexaddr, oldval,	      \
+						    timeout, LLL_PRIVATE);    \
+	    else							      \
+	      status = lll_futex_timed_wait (futexaddr, oldval, timeout,      \
+					     LLL_PRIVATE);		      \
 	    if (status != -EWOULDBLOCK)					      \
 	      break;							      \
 									      \
@@ -58,9 +58,6 @@
 	  }								      \
 	while (oldval != 0);						      \
 									      \
-	if (cancel)							      \
-	  LIBC_CANCEL_RESET (oldtype);					      \
-									      \
 	if (status == -EINTR)						      \
 	  result = EINTR;						      \
 	else if (status == -ETIMEDOUT)					      \
diff --git a/sysdeps/nptl/librt-cancellation.c b/sysdeps/nptl/librt-cancellation.c
deleted file mode 100644
index facfbdb..0000000
--- a/sysdeps/nptl/librt-cancellation.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   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 <nptl/pthreadP.h>
-
-
-#define __pthread_enable_asynccancel __librt_enable_asynccancel
-#define __pthread_disable_asynccancel __librt_disable_asynccancel
-#include <nptl/cancellation.c>
diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h
index 27f4142..4f1b7ff 100644
--- a/sysdeps/nptl/lowlevellock.h
+++ b/sysdeps/nptl/lowlevellock.h
@@ -243,7 +243,7 @@ extern int __lll_robust_timedlock_wait (int *futex, const struct timespec *,
   do {					\
     __typeof (tid) __tid;		\
     while ((__tid = (tid)) != 0)	\
-      lll_futex_wait (&(tid), __tid, LLL_SHARED);\
+      lll_futex_wait_cancel (&(tid), __tid, LLL_SHARED);\
   } while (0)
 
 extern int __lll_timedwait_tid (int *, const struct timespec *)
diff --git a/sysdeps/posix/open64.c b/sysdeps/posix/open64.c
index 74f669f..0c91963 100644
--- a/sysdeps/posix/open64.c
+++ b/sysdeps/posix/open64.c
@@ -34,16 +34,8 @@ __libc_open64 (const char *file, int oflag, ...)
       va_end (arg);
     }
 
-  if (SINGLE_THREAD_P)
-    return __libc_open (file, oflag | O_LARGEFILE, mode);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = __libc_open (file, oflag | O_LARGEFILE, mode);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  /* __libc_open should be a cancellation point.  */
+  return __libc_open (file, oflag | O_LARGEFILE, mode);
 }
 weak_alias (__libc_open64, __open64)
 libc_hidden_weak (__open64)
diff --git a/sysdeps/posix/pause.c b/sysdeps/posix/pause.c
index 6ba4d42..bdaf1cb 100644
--- a/sysdeps/posix/pause.c
+++ b/sysdeps/posix/pause.c
@@ -38,8 +38,6 @@ __libc_pause (void)
 }
 weak_alias (__libc_pause, pause)
 
-LIBC_CANCEL_HANDLED ();		/* sigsuspend handles our cancellation.  */
-
 #ifndef NO_CANCELLATION
 # include <not-cancel.h>
 
diff --git a/sysdeps/posix/sigpause.c b/sysdeps/posix/sigpause.c
index 662640d..863b541 100644
--- a/sysdeps/posix/sigpause.c
+++ b/sysdeps/posix/sigpause.c
@@ -50,16 +50,7 @@ do_sigpause (int sig_or_mask, int is_sig)
 int
 __sigpause (int sig_or_mask, int is_sig)
 {
-  if (SINGLE_THREAD_P)
-    return do_sigpause (sig_or_mask, is_sig);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigpause (sig_or_mask, is_sig);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return do_sigpause (sig_or_mask, is_sig);
 }
 libc_hidden_def (__sigpause)
 
diff --git a/sysdeps/posix/sigwait.c b/sysdeps/posix/sigwait.c
index 8dc550b..f4b5d2f 100644
--- a/sysdeps/posix/sigwait.c
+++ b/sysdeps/posix/sigwait.c
@@ -88,13 +88,8 @@ __sigwait (const sigset_t *set, int *sig)
   if (SINGLE_THREAD_P)
     return do_sigwait (set, sig);
 
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigwait (set, sig);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  /* do_sigwait should be a cancellation point.  */
+  return do_sigwait (set, sig);
 }
 libc_hidden_def (__sigwait)
 weak_alias (__sigwait, sigwait)
diff --git a/sysdeps/posix/waitid.c b/sysdeps/posix/waitid.c
index de41227..00a7db5 100644
--- a/sysdeps/posix/waitid.c
+++ b/sysdeps/posix/waitid.c
@@ -151,16 +151,7 @@ OUR_WAITID (idtype_t idtype, id_t id, siginfo_t *infop, int options)
 int
 __waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
 {
-  if (SINGLE_THREAD_P)
-    return do_waitid (idtype, id, infop, options);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_waitid (idtype, id, infop, options);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return do_waitid (idtype, id, infop, options);
 }
 weak_alias (__waitid, waitid)
 strong_alias (__waitid, __libc_waitid)
diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 52dad58..8de99f1 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -20,31 +20,69 @@
 #include <sys/syscall.h>
 #define	HAVE_SYSCALLS
 
+#ifndef __ASSEMBLER__
+# include <errno.h>
+
 /* Note that using a `PASTE' macro loses.  */
 #define	SYSCALL__(name, args)	PSEUDO (__##name, name, args)
 #define	SYSCALL(name, args)	PSEUDO (name, name, args)
 
 /* Cancellation macros.  */
-#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,n,...) n
+#ifndef __SSC
+typedef long int __syscall_arg_t;
+# define __SSC(__x) ((__syscall_arg_t) (__x))
+#endif
+
+#define __SYSCALL_CANCEL0(__n) \
+  (__syscall_cancel)(__n, 0, 0, 0, 0, 0, 0)
+#define __SYSCALL_CANCEL1(__n, __a) \
+  (__syscall_cancel)(__n, __SSC(__a), 0, 0, 0, 0, 0)
+#define __SYSCALL_CANCEL2(__n, __a, __b) \
+  (__syscall_cancel)(__n, __SSC(__a), __SSC(__b), 0, 0, 0, 0)
+#define __SYSCALL_CANCEL3(__n, __a, __b, __c) \
+  (__syscall_cancel)(__n, __SSC(__a), __SSC(__b), __SSC(__c), 0, 0, 0)
+#define __SYSCALL_CANCEL4(__n, __a, __b, __c, __d) \
+  (__syscall_cancel)(__n, __SSC(__a), __SSC(__b), __SSC(__c), __SSC(__d), \
+		     0, 0)
+#define __SYSCALL_CANCEL5(__n, __a, __b, __c, __d, __e) \
+  (__syscall_cancel)(__n, __SSC(__a), __SSC(__b), __SSC(__c), __SSC(__d), \
+		     __SSC(__e), 0)
+#define __SYSCALL_CANCEL6(__n, __a, __b, __c, __d, __e, __f) \
+  (__syscall_cancel)(__n, __SSC(__a), __SSC(__b), __SSC(__c), __SSC(__d), \
+		     __SSC(__e), __SSC(__f))
+
+#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
 #define __SYSCALL_NARGS(...) \
   __SYSCALL_NARGS_X (__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0,)
+#define __SYSCALL_CONCAT_X(__a,__b)	__a##__b
+#define __SYSCALL_CONCAT(__a,__b)	__SYSCALL_CONCAT_X (__a, __b)
+#define __SYSCALL_DISP(__b,...) \
+  __SYSCALL_CONCAT (__b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
+
+#define __SYSCALL_CANCEL(...) __SYSCALL_DISP (__SYSCALL_CANCEL, __VA_ARGS__)
 
-#define SYSCALL_CANCEL(name, ...) \
-  ({									     \
-    long int sc_ret;							     \
-    if (SINGLE_THREAD_P) 						     \
-      sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS(__VA_ARGS__),	     \
-			       __VA_ARGS__);				     \
-    else								     \
-      {									     \
-	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
-	sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS (__VA_ARGS__),	     \
-				 __VA_ARGS__);				     \
-        LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
-      }									     \
-    sc_ret;								     \
+#define SYSCALL_CANCEL_NCS(name, nr, args...)				\
+  __SYSCALL_CANCEL (__NR_##name, nr, args)
+
+#define SYSCALL_CANCEL(name, args...)					\
+  ({									\
+    long int sc_ret = SYSCALL_CANCEL_NCS (name, args);			\
+    if (SYSCALL_CANCEL_ERROR (sc_ret))					\
+      {									\
+        __set_errno (SYSCALL_CANCEL_ERRNO (sc_ret));			\
+        sc_ret = -1L;							\
+      }									\
+    sc_ret;								\
   })
 
+long int __syscall_cancel (__syscall_arg_t nr, __syscall_arg_t arg1,
+			   __syscall_arg_t arg2, __syscall_arg_t arg3,
+			   __syscall_arg_t arg4, __syscall_arg_t arg5,
+			   __syscall_arg_t arg6);
+libc_hidden_proto (__syscall_cancel);
+
+#endif
+
 /* Machine-dependent sysdep.h files are expected to define the macro
    PSEUDO (function_name, syscall_name) to emit assembly code to define the
    C-callable function FUNCTION_NAME to do system call SYSCALL_NAME.
diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c
index 69c47ca..fd96783 100644
--- a/sysdeps/unix/sysv/linux/clock_nanosleep.c
+++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c
@@ -28,7 +28,6 @@ int
 __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
 		   struct timespec *rem)
 {
-  INTERNAL_SYSCALL_DECL (err);
   int r;
 
   if (clock_id == CLOCK_THREAD_CPUTIME_ID)
@@ -36,19 +35,9 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req,
   if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
     clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
 
-  if (SINGLE_THREAD_P)
-    r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem);
-  else
-    {
-      int oldstate = LIBC_CANCEL_ASYNC ();
+  r = SYSCALL_CANCEL_NCS (clock_nanosleep, clock_id, flags, req, rem);
 
-      r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req,
-			    rem);
-
-      LIBC_CANCEL_RESET (oldstate);
-    }
-
-  return (INTERNAL_SYSCALL_ERROR_P (r, err)
-	  ? INTERNAL_SYSCALL_ERRNO (r, err) : 0);
+  return (SYSCALL_CANCEL_ERROR (r)
+	  ? SYSCALL_CANCEL_ERRNO (r) : 0);
 }
 weak_alias (__clock_nanosleep, clock_nanosleep)
diff --git a/sysdeps/unix/sysv/linux/fcntl.c b/sysdeps/unix/sysv/linux/fcntl.c
index fa184db..192e50d 100644
--- a/sysdeps/unix/sysv/linux/fcntl.c
+++ b/sysdeps/unix/sysv/linux/fcntl.c
@@ -25,7 +25,7 @@
 
 
 static int
-do_fcntl (int fd, int cmd, void *arg)
+__fcntl_common_nocancel (int fd, int cmd, void *arg)
 {
   if (cmd != F_GETOWN)
     return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
@@ -40,8 +40,22 @@ do_fcntl (int fd, int cmd, void *arg)
   return -1;
 }
 
+static int
+__fcntl_common_cancel (int fd, int cmd, void *arg)
+{
+  if (cmd != F_GETOWN)
+    return SYSCALL_CANCEL (fcntl, fd, cmd, arg);
 
-#ifndef NO_CANCELLATION
+  struct f_owner_ex fex;
+  int res = SYSCALL_CANCEL_NCS (fcntl, fd, F_GETOWN_EX, &fex);
+  if (!SYSCALL_CANCEL_ERROR (res))
+    return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
+
+  __set_errno (SYSCALL_CANCEL_ERRNO (res));
+  return -1;
+}
+
+#if !IS_IN (rtld)
 int
 __fcntl_nocancel (int fd, int cmd, ...)
 {
@@ -52,11 +66,10 @@ __fcntl_nocancel (int fd, int cmd, ...)
   arg = va_arg (ap, void *);
   va_end (ap);
 
-  return do_fcntl (fd, cmd, arg);
+  return __fcntl_common_nocancel (fd, cmd, arg);
 }
 #endif
 
-
 int
 __libc_fcntl (int fd, int cmd, ...)
 {
@@ -67,16 +80,10 @@ __libc_fcntl (int fd, int cmd, ...)
   arg = va_arg (ap, void *);
   va_end (ap);
 
-  if (SINGLE_THREAD_P || cmd != F_SETLKW)
-    return do_fcntl (fd, cmd, arg);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_fcntl (fd, cmd, arg);
-
-  LIBC_CANCEL_RESET (oldtype);
+  if (cmd != F_SETLKW)
+    return __fcntl_common_nocancel (fd, cmd, arg);
 
-  return result;
+  return __fcntl_common_cancel (fd,cmd, arg);
 }
 libc_hidden_def (__libc_fcntl)
 
diff --git a/sysdeps/unix/sysv/linux/generic/creat.c b/sysdeps/unix/sysv/linux/generic/creat.c
index dc298fb..36eb4e5 100644
--- a/sysdeps/unix/sysv/linux/generic/creat.c
+++ b/sysdeps/unix/sysv/linux/generic/creat.c
@@ -29,9 +29,6 @@ creat (const char *file, mode_t mode)
   return __open (file, O_WRONLY | O_CREAT | O_TRUNC, mode);
 }
 
-/* __open handles cancellation.  */
-LIBC_CANCEL_HANDLED ();
-
 #if __WORDSIZE == 64
 weak_alias (creat, creat64)
 #endif
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
index a11bf83..80b0603 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c
@@ -26,7 +26,7 @@
 
 
 static int
-do_fcntl (int fd, int cmd, void *arg)
+__fcntl_common_nocancel (int fd, int cmd, void *arg)
 {
   if (cmd != F_GETOWN)
     return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
@@ -41,8 +41,22 @@ do_fcntl (int fd, int cmd, void *arg)
   return -1;
 }
 
+static int
+__fcntl_common_cancel (int fd, int cmd, void *arg)
+{
+  if (cmd != F_GETOWN)
+    return SYSCALL_CANCEL (fcntl64, fd, cmd, arg);
+
+  struct f_owner_ex fex;
+  int res = SYSCALL_CANCEL_NCS (fcntl64, fd, F_GETOWN_EX, &fex);
+  if (!SYSCALL_CANCEL_ERROR (res))
+    return fex.type == F_OWNER_GID ? -fex.pid : fex.pid;
 
-#ifndef NO_CANCELLATION
+  __set_errno (SYSCALL_CANCEL_ERRNO (res));
+  return -1;
+}
+
+#if !IS_IN (rtld)
 int
 __fcntl_nocancel (int fd, int cmd, ...)
 {
@@ -53,7 +67,7 @@ __fcntl_nocancel (int fd, int cmd, ...)
   arg = va_arg (ap, void *);
   va_end (ap);
 
-  return do_fcntl (fd, cmd, arg);
+  return __fcntl_common_nocancel (fd, cmd, arg);
 }
 #endif
 
@@ -69,15 +83,9 @@ __libc_fcntl (int fd, int cmd, ...)
   va_end (ap);
 
   if (SINGLE_THREAD_P || cmd != F_SETLKW)
-    return do_fcntl (fd, cmd, arg);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_fcntl (fd, cmd, arg);
-
-  LIBC_CANCEL_RESET (oldtype);
+    return __fcntl_common_nocancel (fd, cmd, arg);
 
-  return result;
+  return __fcntl_common_cancel (fd,cmd, arg);
 }
 libc_hidden_def (__libc_fcntl)
 
diff --git a/sysdeps/unix/sysv/linux/lowlevellock-futex.h b/sysdeps/unix/sysv/linux/lowlevellock-futex.h
index 59f6627..1edb66f 100644
--- a/sysdeps/unix/sysv/linux/lowlevellock-futex.h
+++ b/sysdeps/unix/sysv/linux/lowlevellock-futex.h
@@ -135,6 +135,50 @@
 					 private),                      \
 		     nr_wake, nr_move, mutex, val)
 
-#endif  /* !__ASSEMBLER__  */
+/* Cancellable futex macros.  */
+#define lll_futex_wait_cancel(futexp, val, private) \
+  lll_futex_timed_wait_cancel (futexp, val, NULL, private)
+
+#define lll_futex_timed_wait_cancel(futexp, val, timespec, private)	      \
+  ({									      \
+    long int __ret;							      \
+    int __op = FUTEX_WAIT;						      \
+                                                                              \
+    __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
+			      __SSC (__lll_private_flag (__op, private)),     \
+			      __SSC (val), __SSC (timespec), 0, 0);           \
+    __ret;								      \
+  })
+
+#define lll_futex_timed_wait_bitset_cancel(futexp, val, timespec, clockbit,   \
+					   private)			      \
+  ({                                                                          \
+    long int __ret;                                                           \
+    int __op = FUTEX_WAIT_BITSET | clockbit;                                  \
+                                                                              \
+    __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
+			      __SSC (__lll_private_flag (__op, private)),     \
+			      __SSC (val), __SSC (timespec), 0,	              \
+                              FUTEX_BITSET_MATCH_ANY);                        \
+    __ret;								      \
+  })
+
+#define lll_futex_wait_requeue_pi_cancel(futexp, val, mutex, private) \
+  lll_futex_timed_wait_requeue_pi_cancel (futexp, val, NULL, 0, mutex, private)
+
+#define lll_futex_timed_wait_requeue_pi_cancel(futexp, val, timespec, 	      \
+					       clockbit, mutex, private)      \
+  ({									      \
+    long int __ret;							      \
+    int __op = FUTEX_WAIT_REQUEUE_PI | clockbit;			      \
+									      \
+    __ret = __syscall_cancel (__NR_futex, __SSC (futexp),		      \
+			      __SSC (__lll_private_flag (__op, private)),     \
+			      __SSC (val), __SSC (timespec),		      \
+			      __SSC (mutex), 0); 		      	      \
+    __ret;								      \
+  })
+
+# endif  /* !__ASSEMBLER__  */
 
 #endif  /* lowlevellock-futex.h */
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c b/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
index 69031ba..3a10d16 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
@@ -23,8 +23,7 @@
 
 #include <sys/syscall.h>
 
-
-#ifndef NO_CANCELLATION
+#if !IS_IN (rtld)
 int
 __fcntl_nocancel (int fd, int cmd, ...)
 {
@@ -39,7 +38,6 @@ __fcntl_nocancel (int fd, int cmd, ...)
 }
 #endif
 
-
 int
 __libc_fcntl (int fd, int cmd, ...)
 {
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
index 5cd7ddb..9381bfc 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h
@@ -27,121 +27,70 @@
 
 # define DASHDASHPFX(str) __##str
 
-#if _CALL_ELF == 2
-#define CANCEL_FRAMESIZE (FRAME_MIN_SIZE+16+48)
-#define CANCEL_PARM_SAVE (FRAME_MIN_SIZE+16)
-#else
-#define CANCEL_FRAMESIZE (FRAME_MIN_SIZE+16)
-#define CANCEL_PARM_SAVE (CANCEL_FRAMESIZE+FRAME_PARM_SAVE)
-#endif
+# if !IS_IN (libc)
+#  undef HIDDEN_JUMPTARGET
+#  define HIDDEN_JUMPTARGET(__symbol) __symbol
+# endif
+
+#define CANCEL_FRAMESIZE (FRAME_MIN_SIZE)
 
 # undef PSEUDO
 # define PSEUDO(name, syscall_name, args)				\
   .section ".text";							\
   ENTRY (name)								\
     SINGLE_THREAD_P;							\
-    bne- .Lpseudo_cancel;						\
-  .type DASHDASHPFX(syscall_name##_nocancel),@function;			\
-  .globl DASHDASHPFX(syscall_name##_nocancel);				\
-  DASHDASHPFX(syscall_name##_nocancel):					\
+    bne- L(pseudo_cancel);						\
     DO_CALL (SYS_ify (syscall_name));					\
-    PSEUDO_RET;								\
-  .size DASHDASHPFX(syscall_name##_nocancel),.-DASHDASHPFX(syscall_name##_nocancel);	\
-  .Lpseudo_cancel:							\
-    stdu 1,-CANCEL_FRAMESIZE(1);					\
-    cfi_adjust_cfa_offset (CANCEL_FRAMESIZE);				\
-    mflr 9;								\
-    std  9,CANCEL_FRAMESIZE+FRAME_LR_SAVE(1);				\
+    bnslr+;								\
+    TAIL_CALL_SYSCALL_ERROR;						\
+  L(pseudo_cancel):							\
+    mflr r0;								\
+    std  r0,FRAME_LR_SAVE(r1);						\
     cfi_offset (lr, FRAME_LR_SAVE);					\
-    DOCARGS_##args;	/* save syscall args around CENABLE.  */	\
-    CENABLE;								\
-    std  3,FRAME_MIN_SIZE(1); /* store CENABLE return value (MASK).  */	\
-    UNDOCARGS_##args;	/* restore syscall args.  */			\
-    DO_CALL (SYS_ify (syscall_name));					\
-    mfcr 0;		/* save CR/R3 around CDISABLE.  */		\
-    std  3,FRAME_MIN_SIZE+8(1);						\
-    std  0,CANCEL_FRAMESIZE+FRAME_CR_SAVE(1);				\
-    cfi_offset (cr, FRAME_CR_SAVE);					\
-    ld   3,FRAME_MIN_SIZE(1); /* pass MASK to CDISABLE.  */		\
-    CDISABLE;								\
-    ld   9,CANCEL_FRAMESIZE+FRAME_LR_SAVE(1);				\
-    ld   0,CANCEL_FRAMESIZE+FRAME_CR_SAVE(1); /* restore CR/R3. */	\
-    ld   3,FRAME_MIN_SIZE+8(1);						\
-    mtlr 9;								\
-    mtcr 0;								\
-    addi 1,1,CANCEL_FRAMESIZE;						\
+    stdu r1,-CANCEL_FRAMESIZE(r1);					\
+    cfi_adjust_cfa_offset (CANCEL_FRAMESIZE);				\
+    mr   r9,r8;								\
+    mr   r8,r7;								\
+    mr   r7,r6;								\
+    mr   r6,r5;								\
+    mr   r5,r4;								\
+    mr   r4,r3;								\
+    li   r3,SYS_ify (syscall_name);					\
+    bl   HIDDEN_JUMPTARGET(__syscall_cancel);				\
+    nop;								\
+    bl   JUMPTARGET(__syscall_cancel_error);				\
+    nop;								\
+    addi r1,r1,CANCEL_FRAMESIZE;					\
     cfi_adjust_cfa_offset (-CANCEL_FRAMESIZE);				\
+    ld   r0,FRAME_LR_SAVE(r1);						\
+    mtlr r0;								\
     cfi_restore (lr);							\
-    cfi_restore (cr)
-
-# define DOCARGS_0
-# define UNDOCARGS_0
-
-# define DOCARGS_1	std 3,CANCEL_PARM_SAVE(1); DOCARGS_0
-# define UNDOCARGS_1	ld 3,CANCEL_PARM_SAVE(1); UNDOCARGS_0
-
-# define DOCARGS_2	std 4,CANCEL_PARM_SAVE+8(1); DOCARGS_1
-# define UNDOCARGS_2	ld 4,CANCEL_PARM_SAVE+8(1); UNDOCARGS_1
-
-# define DOCARGS_3	std 5,CANCEL_PARM_SAVE+16(1); DOCARGS_2
-# define UNDOCARGS_3	ld 5,CANCEL_PARM_SAVE+16(1); UNDOCARGS_2
+    blr
 
-# define DOCARGS_4	std 6,CANCEL_PARM_SAVE+24(1); DOCARGS_3
-# define UNDOCARGS_4	ld 6,CANCEL_PARM_SAVE+24(1); UNDOCARGS_3
-
-# define DOCARGS_5	std 7,CANCEL_PARM_SAVE+32(1); DOCARGS_4
-# define UNDOCARGS_5	ld 7,CANCEL_PARM_SAVE+32(1); UNDOCARGS_4
-
-# define DOCARGS_6	std 8,CANCEL_PARM_SAVE+40(1); DOCARGS_5
-# define UNDOCARGS_6	ld 8,CANCEL_PARM_SAVE+40(1); UNDOCARGS_5
-
-# if IS_IN (libpthread)
-#  ifdef SHARED
-#   define CENABLE	bl JUMPTARGET(__pthread_enable_asynccancel)
-#   define CDISABLE	bl JUMPTARGET(__pthread_disable_asynccancel)
-#  else
-#   define CENABLE	bl JUMPTARGET(__pthread_enable_asynccancel); nop
-#   define CDISABLE	bl JUMPTARGET(__pthread_disable_asynccancel); nop
-#  endif
-# elif IS_IN (libc)
-#  ifdef SHARED
-#   define CENABLE	bl JUMPTARGET(__libc_enable_asynccancel)
-#   define CDISABLE	bl JUMPTARGET(__libc_disable_asynccancel)
-#  else
-#   define CENABLE	bl JUMPTARGET(__libc_enable_asynccancel); nop
-#   define CDISABLE	bl JUMPTARGET(__libc_disable_asynccancel); nop
-#  endif
-# elif IS_IN (librt)
-#  ifdef SHARED
-#   define CENABLE	bl JUMPTARGET(__librt_enable_asynccancel)
-#   define CDISABLE	bl JUMPTARGET(__librt_disable_asynccancel)
-#  else
-#   define CENABLE	bl JUMPTARGET(__librt_enable_asynccancel); nop
-#   define CDISABLE	bl JUMPTARGET(__librt_disable_asynccancel); nop
-#  endif
-# else
-#  error Unsupported library
-# endif
+# undef PSEUDO_RET
+# define PSEUDO_RET
 
 # ifndef __ASSEMBLER__
-#  define SINGLE_THREAD_P						\
-  __builtin_expect (THREAD_GETMEM (THREAD_SELF,				\
-				   header.multiple_threads) == 0, 1)
+#  define SINGLE_THREAD_P                                               \
+  __builtin_expect (THREAD_GETMEM (THREAD_SELF,                         \
+                                   header.multiple_threads) == 0, 1)
 # else
-#   define SINGLE_THREAD_P						\
-  lwz   10,MULTIPLE_THREADS_OFFSET(13);				\
+#   define SINGLE_THREAD_P                                              \
+  lwz   10,MULTIPLE_THREADS_OFFSET(13);                         	\
   cmpwi 10,0
 # endif
 
-#elif !defined __ASSEMBLER__
-
-# define SINGLE_THREAD_P (1)
-# define NO_CANCELLATION 1
-
 #endif
 
 #ifndef __ASSEMBLER__
 # define RTLD_SINGLE_THREAD_P \
   __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
 				   header.multiple_threads) == 0, 1)
+
+static inline
+const char * __pthread_get_ip (const ucontext_t *uc)
+{
+  return (char *)uc->uc_mcontext.gp_regs[PT_NIP];
+}
+
 #endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
index 324e19b..0ec2759 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep.h
@@ -184,6 +184,15 @@
     sc_ret;								\
   })
 
+#undef SYSCALL_CANCEL_ERROR
+#define SYSCALL_CANCEL_ERROR(err)					\
+  (err > 0xfffffffffffff000UL)
+
+#undef SYSCALL_CANCEL_ERRNO
+#define SYSCALL_CANCEL_ERRNO(err)					\
+  (-err)
+
+
 /* Define a macro which expands inline into the wrapper code for a system
    call. This use is for internal calls that do not need to handle errors
    normally. It will never touch errno. This returns just what the kernel
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.c b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
similarity index 50%
copy from sysdeps/unix/sysv/linux/powerpc/sysdep.c
copy to sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
index 6dc6737..4d9e5b5 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.c
+++ b/sysdeps/unix/sysv/linux/powerpc/syscall_cancel.S
@@ -1,4 +1,5 @@
-/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
+/* Cancellable syscall wrapper - powerpc version.
+   Copyright (C) 2014 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
@@ -16,13 +17,40 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include <sysdep.h>
-#include <errno.h>
-
-/* This routine is jumped to by all the syscall handlers, to stash
-   an error number into errno.  */
-int
-__syscall_error (int err_no)
-{
-  __set_errno (err_no);
-  return -1;
-}
+
+ENTRY (__syscall_cancel_arch)
+
+	.globl __syscall_cancel_arch_start
+	.type  __syscall_cancel_arch_start,@function
+__syscall_cancel_arch_start:
+
+	/*mflr	r10
+	std	r10,FRAME_LR_SAVE(r1)*/
+
+	lwz     r0,0(r3)
+	rldicl. r0,r0,62,63
+	beq     1f
+	b       __syscall_do_cancel
+	nop
+1:
+	mr      r0,r4
+	mr      r3,r5
+	mr      r4,r6
+	mr      r5,r7
+	mr      r6,r8
+	mr      r7,r9
+	mr      r8,r10
+	sc
+
+	.globl __syscall_cancel_arch_end
+	.type  __syscall_cancel_arch_end,@function
+__syscall_cancel_arch_end:
+
+	/*ld	r10,FRAME_LR_SAVE(r1)
+	mtlr	r10*/
+
+	bnslr+
+	neg	r3,r3
+	blr
+END (__syscall_cancel_arch)
+libc_hidden_def (__syscall_cancel_arch)
diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.c b/sysdeps/unix/sysv/linux/powerpc/sysdep.c
index 6dc6737..8d58fd0 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.c
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.c
@@ -26,3 +26,14 @@ __syscall_error (int err_no)
   __set_errno (err_no);
   return -1;
 }
+
+long int
+__syscall_cancel_error (unsigned long err)
+{
+  if (__glibc_unlikely ((err) & (1 << 28)))
+    {
+      __set_errno (-err);
+      return -1;
+    }
+  return err;
+}
diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c
index 8e8996a..f6d619c 100644
--- a/sysdeps/unix/sysv/linux/pthread_kill.c
+++ b/sysdeps/unix/sysv/linux/pthread_kill.c
@@ -41,9 +41,8 @@ __pthread_kill (pthread_t threadid, int signo)
     /* Not a valid thread handle.  */
     return ESRCH;
 
-  /* Disallow sending the signal we use for cancellation, timers,
-     for the setxid implementation.  */
-  if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID)
+  /* Disallow sending the signal we use for setxid implementation.  */
+  if (signo == SIGSETXID)
     return EINVAL;
 
   /* We have a special syscall to do the work.  */
diff --git a/sysdeps/unix/sysv/linux/sigwait.c b/sysdeps/unix/sysv/linux/sigwait.c
index 26c3241..1003e5f 100644
--- a/sysdeps/unix/sysv/linux/sigwait.c
+++ b/sysdeps/unix/sysv/linux/sigwait.c
@@ -55,32 +55,17 @@ do_sigwait (const sigset_t *set, int *sig)
 
   /* XXX The size argument hopefully will have to be changed to the
      real size of the user-level sigset_t.  */
-#ifdef INTERNAL_SYSCALL
-  INTERNAL_SYSCALL_DECL (err);
   do
-    ret = INTERNAL_SYSCALL (rt_sigtimedwait, err, 4, set,
-			    NULL, NULL, _NSIG / 8);
-  while (INTERNAL_SYSCALL_ERROR_P (ret, err)
-	 && INTERNAL_SYSCALL_ERRNO (ret, err) == EINTR);
-  if (! INTERNAL_SYSCALL_ERROR_P (ret, err))
+    ret = SYSCALL_CANCEL_NCS (rt_sigtimedwait, set, NULL, NULL, _NSIG / 8);
+  while (SYSCALL_CANCEL_ERROR (ret)
+	 && SYSCALL_CANCEL_ERRNO (ret) == EINTR);
+  if (!SYSCALL_CANCEL_ERROR (ret))
     {
       *sig = ret;
       ret = 0;
     }
   else
-    ret = INTERNAL_SYSCALL_ERRNO (ret, err);
-#else
-  do
-    ret = INLINE_SYSCALL (rt_sigtimedwait, 4, set, NULL, NULL, _NSIG / 8);
-  while (ret == -1 && errno == EINTR);
-  if (ret != -1)
-    {
-      *sig = ret;
-      ret = 0;
-    }
-  else
-    ret = errno;
-#endif
+    ret = SYSCALL_CANCEL_ERRNO (ret);
 
   return ret;
 }
@@ -88,16 +73,7 @@ do_sigwait (const sigset_t *set, int *sig)
 int
 __sigwait (const sigset_t *set, int *sig)
 {
-  if (SINGLE_THREAD_P)
-    return do_sigwait (set, sig);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigwait (set, sig);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return do_sigwait (set, sig);
 }
 libc_hidden_def (__sigwait)
 weak_alias (__sigwait, sigwait)
diff --git a/sysdeps/unix/sysv/linux/socketcall.h b/sysdeps/unix/sysv/linux/socketcall.h
index 6ddb09d..0a3a4f7 100644
--- a/sysdeps/unix/sysv/linux/socketcall.h
+++ b/sysdeps/unix/sysv/linux/socketcall.h
@@ -49,34 +49,26 @@
 
 #define SOCKETCALL(name, __a1, __a2, __a3, __a4, __a5, __a6)		\
   ({									\
-    long int __args[6] = { (long int) __a1,				\
-                           (long int) __a2,				\
-                           (long int) __a3,				\
-                           (long int) __a4,				\
-                           (long int) __a5,				\
-                           (long int) __a6 };				\
+    __syscall_arg_t __args[6] = { __SSC (__a1), __SSC (__a2),		\
+				  __SSC (__a3), __SSC (__a4), 		\
+				  __SSC (__a5), __SSC (__a6) };		\
     long int sc_ret = INLINE_SYSCALL (socketcall, 2, SOCKOP_##name,	\
-                                     __args);				\
+				      __args);				\
     sc_ret;								\
   })
 
-#if IS_IN (libc)
-# define __pthread_enable_asynccancel  __libc_enable_asynccancel
-# define __pthread_disable_asynccancel __libc_disable_asynccancel
-#endif
-
 #define SOCKETCALL_CANCEL(name, __a1, __a2, __a3, __a4, __a5, __a6)	\
   ({									\
-    long int __args[6] = { (long int) __a1,				\
-                           (long int) __a2,				\
-                           (long int) __a3,				\
-                           (long int) __a4,				\
-                           (long int) __a5,				\
-                           (long int) __a6 };				\
-    int oldtype = LIBC_CANCEL_ASYNC ();					\
-    long int sc_ret = INLINE_SYSCALL (socketcall, 2, SOCKOP_##name,	\
-                                     __args);				\
-    LIBC_CANCEL_RESET (oldtype);					\
+    __syscall_arg_t __args[6] = { __SSC (__a1), __SSC (__a2),		\
+				  __SSC (__a3), __SSC (__a4), 		\
+				  __SSC (__a5), __SSC (__a6) };		\
+    long int sc_ret = SYSCALL_CANCEL_NCS (socketcall, SOCKOP_##name,	\
+					  __args);			\
+    if (SYSCALL_CANCEL_ERROR (sc_ret))					\
+      {									\
+        __set_errno (SYSCALL_CANCEL_ERRNO (sc_ret));			\
+        sc_ret = -1L;							\
+      }									\
     sc_ret;								\
   })
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=1871d32b63787103e59339ef11133f227da04c4c

commit 1871d32b63787103e59339ef11133f227da04c4c
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Wed Sep 24 20:22:05 2014 -0300

    nptl: Fix testcases for new pthread cancellation mechanism
    
    With upcoming fix for BZ#12683, pthread cancellation does not act for:
    
    1. If syscall is blocked but with some side effects already having taken
       place (e.g. a partial read or write)
    2. After the syscall has returned.
    
    It is because program need to act on such cases (for instance, to avoid
    leak of allocated resources our handling partial read/write).
    
    This patches fixes the NPTL testcase that assumes the old behavior and
    also remove the tst-cancel-wrappers.sh test (which checks for symbols
    that does not exist anymore).

diff --git a/ChangeLog b/ChangeLog
index f3bffdc..fea36d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* nptl/Makefile [$(run-built-tests) = yes] (tests-special): Remove
+	tst-cancel-wrappers.sh.
+	* nptl/tst-cancel-wrappers.sh: Remove file.
+	* nptl/tst-cancel2.c (tf): Add pthread_testcancel after cancellable
+	syscall.
+	* nptl/tst-cancel20.c (sh_body): Likewise.
+	* nptl/tst-cancel21.c (sh_body): Likewise.
+	(tf_body): Likewise.
+	* nptl/tst-cancel4.c (tf_Write): Likewise.
+	(tf_send): Likewise.
+	(tf_open64): New test: check for open64 cancellable syscall.
+	(tf_pread64): New test: check for pread64 cancellable syscall.
+	(tf_pwrite64): New test: check for pwrite64 cancellable syscall.
+
 	* sysdeps/unix/sysdep.h [SYSCALL_CANCEL]: New macro: define
 	cancellable syscalls.
 	(SYS_ify): Add guard to no redefine it.
diff --git a/nptl/Makefile b/nptl/Makefile
index d784c8d..13113c1 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -378,8 +378,7 @@ tests-reverse += tst-cancel5 tst-cancel23 tst-vfork1x tst-vfork2x
 ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-stack3-mem.out $(objpfx)tst-oddstacklimit.out
 ifeq ($(build-shared),yes)
-tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out \
-		 $(objpfx)tst-cancel-wrappers.out
+tests-special += $(objpfx)tst-tls6.out $(objpfx)tst-cleanup0-cmp.out
 endif
 endif
 
@@ -586,7 +585,7 @@ $(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)/
 endif
 
 generated += libpthread_nonshared.a \
-	     multidir.mk tst-atfork2.mtrace tst-cancel-wrappers.out \
+	     multidir.mk tst-atfork2.mtrace \
 	     tst-tls6.out
 
 generated += $(objpfx)tst-atfork2.mtrace \
@@ -601,18 +600,6 @@ generated += banner.h
 LDFLAGS-pthread.so += -e __nptl_main
 endif
 
-ifeq ($(run-built-tests),yes)
-ifeq (yes,$(build-shared))
-$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
-	$(SHELL) $< '$(NM)' \
-		    $(common-objpfx)libc_pic.a \
-		    $(common-objpfx)libc.a \
-		    $(objpfx)libpthread_pic.a \
-		    $(objpfx)libpthread.a > $@; \
-	$(evaluate-test)
-endif
-endif
-
 tst-exec4-ARGS = $(host-test-program-cmd)
 
 $(objpfx)tst-execstack: $(libdl)
diff --git a/nptl/tst-cancel-wrappers.sh b/nptl/tst-cancel-wrappers.sh
deleted file mode 100644
index b2d8302..0000000
--- a/nptl/tst-cancel-wrappers.sh
+++ /dev/null
@@ -1,92 +0,0 @@
-#! /bin/sh
-# Test whether all cancelable functions are cancelable.
-# Copyright (C) 2002-2015 Free Software Foundation, Inc.
-# This file is part of the GNU C Library.
-# Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
-
-# 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/>.
-
-NM="$1"; shift
-while [ $# -gt 0 ]; do
-  ( $NM -P $1; echo 'end[end]:' ) | gawk ' BEGIN {
-C["accept"]=1
-C["close"]=1
-C["connect"]=1
-C["creat"]=1
-C["fcntl"]=1
-C["fdatasync"]=1
-C["fsync"]=1
-C["msgrcv"]=1
-C["msgsnd"]=1
-C["msync"]=1
-C["nanosleep"]=1
-C["open"]=1
-C["open64"]=1
-C["pause"]=1
-C["poll"]=1
-C["pread"]=1
-C["pread64"]=1
-C["pselect"]=1
-C["pwrite"]=1
-C["pwrite64"]=1
-C["read"]=1
-C["readv"]=1
-C["recv"]=1
-C["recvfrom"]=1
-C["recvmsg"]=1
-C["select"]=1
-C["send"]=1
-C["sendmsg"]=1
-C["sendto"]=1
-C["sigpause"]=1
-C["sigsuspend"]=1
-C["sigwait"]=1
-C["sigwaitinfo"]=1
-C["tcdrain"]=1
-C["wait"]=1
-C["waitid"]=1
-C["waitpid"]=1
-C["write"]=1
-C["writev"]=1
-C["__xpg_sigpause"]=1
-}
-/:$/ {
-  if (seen)
-    {
-      if (!seen_enable || !seen_disable)
-	{
-	  printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen
-	  ret = 1
-	}
-    }
-  seen=""
-  seen_enable=""
-  seen_disable=""
-  object=gensub(/^.*\[(.*)\]:$/,"\\1","",$0)
-  next
-}
-{
-  if (C[$1] && $2 ~ /^[TW]$/)
-    seen=$1
-  else if ($1 ~ /^([.]|)__(libc|pthread)_enable_asynccancel$/ && $2 == "U")
-    seen_enable=1
-  else if ($1 ~ /^([.]|)__(libc|pthread)_disable_asynccancel$/ && $2 == "U")
-    seen_disable=1
-}
-END {
-  exit ret
-}' || exit
-  shift
-done
diff --git a/nptl/tst-cancel2.c b/nptl/tst-cancel2.c
index 1a74992..3d34169 100644
--- a/nptl/tst-cancel2.c
+++ b/nptl/tst-cancel2.c
@@ -33,6 +33,9 @@ tf (void *arg)
   char buf[100000];
 
   while (write (fd[1], buf, sizeof (buf)) > 0);
+  /* The write can return a value higher than 0 (meaning partial write)
+     due the SIGCANCEL, but the thread may still pending cancellation.  */
+  pthread_testcancel ();
 
   return (void *) 42l;
 }
diff --git a/nptl/tst-cancel20.c b/nptl/tst-cancel20.c
index 51b558e..614708a 100644
--- a/nptl/tst-cancel20.c
+++ b/nptl/tst-cancel20.c
@@ -49,6 +49,9 @@ sh_body (void)
       puts ("read succeeded");
       exit (1);
     }
+  /* The read can return a value higher than 0 (meaning partial reads)
+     due the SIGCANCEL, but the thread may still pending cancellation.  */
+  pthread_testcancel ();
 
   pthread_cleanup_pop (0);
 }
@@ -84,7 +87,8 @@ tf_body (void)
       puts ("read succeeded");
       exit (1);
     }
-
+  /* Check for partial read.  */
+  pthread_testcancel ();
   read (fd[0], &c, 1);
 
   pthread_cleanup_pop (0);
diff --git a/nptl/tst-cancel21.c b/nptl/tst-cancel21.c
index b54f236..b1370e1 100644
--- a/nptl/tst-cancel21.c
+++ b/nptl/tst-cancel21.c
@@ -50,6 +50,9 @@ sh_body (void)
       puts ("read succeeded");
       exit (1);
     }
+  /* The write can return a value higher than 0 (meaning partial write)
+     due the SIGCANCEL, but the thread may still pending cancellation.  */
+  pthread_testcancel ();
 
   pthread_cleanup_pop (0);
 }
@@ -85,6 +88,8 @@ tf_body (void)
       puts ("read succeeded");
       exit (1);
     }
+  /* Check partial read.  */
+  pthread_testcancel ();
 
   read (fd[0], &c, 1);
 
diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c
index e50afd7..0a41d95 100644
--- a/nptl/tst-cancel4.c
+++ b/nptl/tst-cancel4.c
@@ -38,8 +38,10 @@
 #include <sys/un.h>
 #include <sys/wait.h>
 
-#include "pthreadP.h"
-
+/* The signal used for asynchronous cancelation.  */
+#ifndef SIGCANCEL
+# define SIGCANCEL       __SIGRTMIN
+#endif
 
 /* Since STREAMS are not supported in the standard Linux kernel and
    there we don't advertise STREAMS as supported is no need to test
@@ -247,6 +249,9 @@ tf_write  (void *arg)
   char buf[WRITE_BUFFER_SIZE];
   memset (buf, '\0', sizeof (buf));
   s = write (fd, buf, sizeof (buf));
+  /* The write can return a value higher than 0 (meaning partial write)
+     due the SIGCANCEL, but the thread may still pending cancellation.  */
+  pthread_testcancel ();
 
   pthread_cleanup_pop (0);
 
@@ -1143,6 +1148,8 @@ tf_send (void *arg)
   char mem[700000];
 
   send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
+  /* Check for partial send.  */
+  pthread_testcancel ();
 
   pthread_cleanup_pop (0);
 
@@ -1425,6 +1432,38 @@ tf_open (void *arg)
   exit (1);
 }
 
+static void *
+tf_open64 (void *arg)
+{
+  if (arg == NULL)
+    // XXX If somebody can provide a portable test case in which open()
+    // blocks we can enable this test to run in both rounds.
+    abort ();
+
+  int r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      printf ("%s: barrier_wait failed\n", __FUNCTION__);
+      exit (1);
+    }
+
+  r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+      exit (1);
+    }
+
+  pthread_cleanup_push (cl, NULL);
+
+  open64 ("Makefile", O_RDONLY);
+
+  pthread_cleanup_pop (0);
+
+  printf ("%s: open returned\n", __FUNCTION__);
+
+  exit (1);
+}
 
 static void *
 tf_close (void *arg)
@@ -1510,6 +1549,46 @@ tf_pread (void *arg)
   exit (1);
 }
 
+static void *
+tf_pread64 (void *arg)
+{
+  if (arg == NULL)
+    // XXX If somebody can provide a portable test case in which pread()
+    // blocks we can enable this test to run in both rounds.
+    abort ();
+
+  tempfd = open64 ("Makefile", O_RDONLY);
+  if (tempfd == -1)
+    {
+      printf ("%s: cannot open64 Makefile\n", __FUNCTION__);
+      exit (1);
+    }
+
+  int r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      printf ("%s: barrier_wait failed\n", __FUNCTION__);
+      exit (1);
+    }
+
+  r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+      exit (1);
+    }
+
+  pthread_cleanup_push (cl, NULL);
+
+  char mem[10];
+  pread64 (tempfd, mem, sizeof (mem), 0);
+
+  pthread_cleanup_pop (0);
+
+  printf ("%s: pread64 returned\n", __FUNCTION__);
+
+  exit (1);
+}
 
 static void *
 tf_pwrite (void *arg)
@@ -1554,6 +1633,48 @@ tf_pwrite (void *arg)
   exit (1);
 }
 
+static void *
+tf_pwrite64 (void *arg)
+{
+  if (arg == NULL)
+    // XXX If somebody can provide a portable test case in which pwrite()
+    // blocks we can enable this test to run in both rounds.
+    abort ();
+
+  char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
+  tempfd = mkstemp (fname);
+  if (tempfd == -1)
+    {
+      printf ("%s: mkstemp failed\n", __FUNCTION__);
+      exit (1);
+    }
+  unlink (fname);
+
+  int r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      printf ("%s: barrier_wait failed\n", __FUNCTION__);
+      exit (1);
+    }
+
+  r = pthread_barrier_wait (&b2);
+  if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
+    {
+      printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
+      exit (1);
+    }
+
+  pthread_cleanup_push (cl, NULL);
+
+  char mem[10];
+  pwrite64 (tempfd, mem, sizeof (mem), 0);
+
+  pthread_cleanup_pop (0);
+
+  printf ("%s: pwrite64 returned\n", __FUNCTION__);
+
+  exit (1);
+}
 
 static void *
 tf_fsync (void *arg)
@@ -2141,9 +2262,12 @@ static struct
   ADD_TEST (recvfrom, 2, 0),
   ADD_TEST (recvmsg, 2, 0),
   ADD_TEST (open, 2, 1),
+  ADD_TEST (open64, 2, 1),
   ADD_TEST (close, 2, 1),
   ADD_TEST (pread, 2, 1),
+  ADD_TEST (pread64, 2, 1),
   ADD_TEST (pwrite, 2, 1),
+  ADD_TEST (pwrite64, 2, 1),
   ADD_TEST (fsync, 2, 1),
   ADD_TEST (fdatasync, 2, 1),
   ADD_TEST (msync, 2, 1),

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=b6fed57e117e6c57c7a4eeead63691fcacfbaf12

commit b6fed57e117e6c57c7a4eeead63691fcacfbaf12
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Sun Sep 28 08:46:23 2014 -0300

    nptl: Rewrite cancellation macros
    
    This patch changes the way cancellation entrypoints are defined to
    instead call the macro SYSCALL_CANCEL.  An usual cnacellation definition
    is defined as:
    
      if (SINGLE_THREAD_P)
        return INLINE_SYSCALL (syscall, NARGS, args...)
    
      int oldtype = LIBC_CANCEL_ASYNC ();
    
      return INLINE_SYSCALL (syscall, NARGS, args...)
    
      LIBC_CANCEL_RESET (oldtype);
    
    And it is rewrited as just:
    
      SYSCALL_CANCEL (syscall, args...)
    
    The idea is to remove LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET explicit
    usage.

diff --git a/ChangeLog b/ChangeLog
index eb800a9..f3bffdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,114 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysdep.h [SYSCALL_CANCEL]: New macro: define
+	cancellable syscalls.
+	(SYS_ify): Add guard to no redefine it.
+	(INLINE_SYSCALL): Likewise.
+	* sysdeps/unix/sysv/linux/accept4.c (accept4): Remove
+	LIBC_CANCEL_ASYNC/INLINE_SYSCALL/LIBC_CANCEL_RESET and use
+	SYSCALL_CANCEL instead.
+	* sysdeps/unix/sysv/linux/alpha/fdatasync.c (__fdatasync): Likewise.
+	* sysdeps/unix/sysv/linux/arm/pread.c (__libc_pread): Likewise.
+	* sysdeps/unix/sysv/linux/arm/pread64.c (__libc_pread64): Likewise.
+	* sysdeps/unix/sysv/linux/arm/pwrite.c (__libc_pwrite): Likewise.
+	* sysdeps/unix/sysv/linux/arm/pwrite64.c (__libc_pwrite64): Likewise.
+	* sysdeps/unix/sysv/linux/epoll_pwait.c (epoll_pwait): Likewise.
+	* sysdeps/unix/sysv/linux/fallocate.c (fallocate): Likewise.
+	* sysdeps/unix/sysv/linux/fallocate64.c (fallocate64): Likewise.
+	* sysdeps/unix/sysv/linux/generic/open.c (__libc_open): Likewise.
+	* sysdeps/unix/sysv/linux/generic/open64.c (__libc_open64): Likewise.
+	* sysdeps/unix/sysv/linux/generic/pause.c (__libc_pause): Likewise.
+	* sysdeps/unix/sysv/linux/generic/poll.c (__poll): Likewise.
+	* sysdeps/unix/sysv/linux/generic/recv.c (__libc_recv): Likewise.
+	* sysdeps/unix/sysv/linux/generic/select.c (__select): Likewise.
+	* sysdeps/unix/sysv/linux/generic/send.c (__libc_send): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c (__libc_pread):
+	Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c
+	(__libc_pread64): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c
+	(__libc_preadv): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c
+	(__libc_readv64): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c
+	(__libc_pwrite): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c
+	(__libc_pwrite64): Likewise.
+	* sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c
+	(__libc_pwritev): Likewise.
+	* sysdeps/sysv/linux/generic/wordsize-32/pwritev64.c
+	(__libc_pwritev64): Likewise.
+	* sysdeps/unix/sysv/linux/i386/fcntl.c (__libc_fcntl): Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips32/sync_file_range.c
+	(sync_file_range): Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c (fallocate):
+	Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate64.c (fallocate64):
+	Likewise.
+	* sysdeps/unix/sysv/linux/mips/pread.c (__libc_pread): Likewise.
+	* sysdeps/unix/sysv/linux/mips/pread64.c (__libc_pread64): Likewise.
+	* sysdeps/unix/sysv/linux/mips/pwrite.c (__libc_pwrite): Likewise.
+	* sysdeps/unix/sysv/linux/mips/pwrite64.c (__libc_pwrite64): Likewise.
+	* sysdeps/unix/sysv/linux/msgrcv.c (__libc_msgrcv): Likewise.
+	* sysdeps/unix/sysv/linux/msgsnd.c (__libc_msgsnd): Likewise.
+	* sysdeps/unix/sysv/linux/open64.c (__libc_open64): Likewise.
+	* sysdeps/unix/sysv/linux/openat.c (__libc_openat): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c (__libc_pread):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c
+	(__libc_read64): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c (__libc_write):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c (__libc_write64):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c (__libc_fcntl):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/pread.c (__libc_pread):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/pread64.c
+	(__libc_pread64): Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite.c (__libc_pwrite):
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/pwrite64.c
+	(__libc_pwrite64): Likewise.
+	* sysdeps/sysv/linux/powerpc/powerpc64/sync_file_range.c
+	(sync_file_range): Likewise.
+	* sysdeps/unix/sysv/linux/ppoll.c (ppoll): Likewise.
+	* sysdeps/unix/sysv/linux/pread.c (__libc_pread): Likewise.
+	* sysdeps/unix/sysv/linux/pread64.c (__libc_pread64): Likewise.
+	* sysdeps/unix/sysv/linux/preadv.c (__libc_preadv): Likewise.
+	* sysdeps/unix/sysv/linux/pselect.c (__pselect): Likewise.
+	* sysdeps/unix/sysv/linux/pwrite.c (__libc_pwrite): Likewise.
+	* sysdeps/unix/sysv/linux/pwrite64.c (__libc_pwrite64): Likewise.
+	* sysdeps/unix/sysv/linux/pwritev.c (PWRITEV): Likewise.
+	* sysdeps/unix/sysv/linux/readv.c (__libc_readv): Likewise.
+	* sysdeps/unix/sysv/linux/recvmmsg.c (recvmmsg): Likewise.
+	* sysdeps/unix/sysv/linux/sendmmsg.c (sendmmsg): Likewise.
+	* sysdeps/unix/sysv/linux/sh/pread.c (__libc_pread): Likewise.
+	* sysdeps/unix/sysv/linux/sh/pread64.c (__libc_pread64): Likewise.
+	* sysdeps/unix/sysv/linux/sh/pwrite.c (__libc_pwrite): Likewise.
+	* sysdeps/unix/sysv/linux/sh/pwrite64.c (__libc_pwrite64): Likewise.
+	* sysdeps/unix/sysv/linux/sigsuspend.c (__sigsuspend): Likewise.
+	* sysdeps/unix/sysv/linux/sigtimedwait.c (__sigtimedwait): Likewise.
+	* sysdeps/unix/sysv/linux/sigwaitinfo.c (__sigwaitinfo): Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/msgrcv.c (__libc_msgrcv):
+	Likewise.
+	* sysdeps/unix/sysv/linux/sync_file_range.c (sync_file_range):
+	Likewise.
+	* sysdeps/unix/sysv/linux/tcdrain.c (__libc_tcdrain): Likewise.
+	* sysdeps/unix/sysv/linux/timer_routines.c (timer_helper_thread):
+	Likewise.
+	* sysdeps/unix/sysv/linux/wait.c (__libc_wait): Likewise.
+	* sysdeps/unix/sysv/linux/waitid.c (__waitid): Likewise.
+	* sysdeps/unix/sysv/linux/waitpid.c (__libc_waitpid): Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/fallocate.c (fallocate):
+	Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/preadv.c (preadv): Likewise.
+	* sysdeps/unix/sysv/linux/wordsize-64/pwritev.c (pwritev): Likewise.
+	* sysdeps/unix/sysv/linux/writev.c (__libc_writev): Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/recv.c (__libc_recv): Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/send.c (__libc_send): Likewise.
+
 	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
 	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Remove
 
diff --git a/sysdeps/unix/sysdep.h b/sysdeps/unix/sysdep.h
index 5fa6580..52dad58 100644
--- a/sysdeps/unix/sysdep.h
+++ b/sysdeps/unix/sysdep.h
@@ -24,6 +24,27 @@
 #define	SYSCALL__(name, args)	PSEUDO (__##name, name, args)
 #define	SYSCALL(name, args)	PSEUDO (name, name, args)
 
+/* Cancellation macros.  */
+#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,n,...) n
+#define __SYSCALL_NARGS(...) \
+  __SYSCALL_NARGS_X (__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0,)
+
+#define SYSCALL_CANCEL(name, ...) \
+  ({									     \
+    long int sc_ret;							     \
+    if (SINGLE_THREAD_P) 						     \
+      sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS(__VA_ARGS__),	     \
+			       __VA_ARGS__);				     \
+    else								     \
+      {									     \
+	int sc_cancel_oldtype = LIBC_CANCEL_ASYNC ();			     \
+	sc_ret = INLINE_SYSCALL (name, __SYSCALL_NARGS (__VA_ARGS__),	     \
+				 __VA_ARGS__);				     \
+        LIBC_CANCEL_RESET (sc_cancel_oldtype);				     \
+      }									     \
+    sc_ret;								     \
+  })
+
 /* Machine-dependent sysdep.h files are expected to define the macro
    PSEUDO (function_name, syscall_name) to emit assembly code to define the
    C-callable function FUNCTION_NAME to do system call SYSCALL_NAME.
@@ -31,7 +52,9 @@
    an instruction such that "MOVE(r1, r0)" works.  ret should be defined
    as the return instruction.  */
 
+#ifndef SYS_ify
 #define SYS_ify(syscall_name) SYS_##syscall_name
+#endif
 
 /* Terminate a system call named SYM.  This is used on some platforms
    to generate correct debugging information.  */
@@ -47,4 +70,6 @@
 
 /* Wrappers around system calls should normally inline the system call code.
    But sometimes it is not possible or implemented and we use this code.  */
+#ifndef INLINE_SYSCALL
 #define INLINE_SYSCALL(name, nr, args...) __syscall_##name (args)
+#endif
diff --git a/sysdeps/unix/sysv/linux/accept4.c b/sysdeps/unix/sysv/linux/accept4.c
index 8e70b81..59293f9 100644
--- a/sysdeps/unix/sysv/linux/accept4.c
+++ b/sysdeps/unix/sysv/linux/accept4.c
@@ -37,17 +37,7 @@
 int
 accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (accept4, 4, fd, addr.__sockaddr__, addr_len, flags);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (accept4, 4, fd, addr.__sockaddr__, addr_len,
-			       flags);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len, flags);
 }
 #elif defined __NR_socketcall
 # include <socketcall.h>
diff --git a/sysdeps/unix/sysv/linux/alpha/fdatasync.c b/sysdeps/unix/sysv/linux/alpha/fdatasync.c
index c9424e2..c8b711e 100644
--- a/sysdeps/unix/sysv/linux/alpha/fdatasync.c
+++ b/sysdeps/unix/sysv/linux/alpha/fdatasync.c
@@ -26,39 +26,23 @@
 
 #include <kernel-features.h>
 
-static int
-do_fdatasync (int fd)
+int
+__fdatasync (int fd)
 {
 #ifdef __ASSUME_FDATASYNC
-  return INLINE_SYSCALL (fdatasync, 1, fd);
+  return SYSCALL_CANCEL (fdatasync, fd);
 #elif defined __NR_fdatasync
   static int __have_no_fdatasync;
 
   if (!__builtin_expect (__have_no_fdatasync, 0))
     {
-      int result = INLINE_SYSCALL (fdatasync, 1, fd);
+      int result = SYSCALL_CANCEL (fdatasync, fd);
       if (__builtin_expect (result, 0) != -1 || errno != ENOSYS)
 	return result;
 
       __have_no_fdatasync = 1;
     }
 #endif
-  return INLINE_SYSCALL (fsync, 1, fd);
-}
-
-int
-__fdatasync (int fd)
-{
-  if (SINGLE_THREAD_P)
-    return do_fdatasync (fd);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_fdatasync (fd);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fsync, fd);
 }
-
 weak_alias (__fdatasync, fdatasync)
diff --git a/sysdeps/unix/sysv/linux/arm/pread.c b/sysdeps/unix/sysv/linux/arm/pread.c
index 64bc0a1..91b3c66 100644
--- a/sysdeps/unix/sysv/linux/arm/pread.c
+++ b/sysdeps/unix/sysv/linux/arm/pread.c
@@ -26,28 +26,10 @@
 ssize_t
 __libc_pread (int fd, void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* In the ARM EABI, 64-bit values are aligned to even/odd register
-	 pairs for syscalls.  */
-      result = INLINE_SYSCALL (pread64, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR (offset >> 31, offset));
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* In the ARM EABI, 64-bit values are aligned to even/odd register
      pairs for syscalls.  */
-  result = INLINE_SYSCALL (pread64, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR (offset >> 31, offset));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread64, fd, buf, count, 0,
+			 __LONG_LONG_PAIR (offset >> 31, offset));
 }
 
 strong_alias (__libc_pread, __pread)
diff --git a/sysdeps/unix/sysv/linux/arm/pread64.c b/sysdeps/unix/sysv/linux/arm/pread64.c
index 7860699..ca71feb 100644
--- a/sysdeps/unix/sysv/linux/arm/pread64.c
+++ b/sysdeps/unix/sysv/linux/arm/pread64.c
@@ -26,30 +26,11 @@
 ssize_t
 __libc_pread64 (int fd, void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* In the ARM EABI, 64-bit values are aligned to even/odd register
-	 pairs for syscalls.  */
-      result = INLINE_SYSCALL (pread64, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR ((off_t) (offset >> 32),
-						 (off_t) (offset & 0xffffffff)));
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* In the ARM EABI, 64-bit values are aligned to even/odd register
      pairs for syscalls.  */
-  result = INLINE_SYSCALL (pread64, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread64, fd, buf, count, 0,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 }
 
 weak_alias (__libc_pread64, __pread64)
diff --git a/sysdeps/unix/sysv/linux/arm/pwrite.c b/sysdeps/unix/sysv/linux/arm/pwrite.c
index 11a963c..e22e112 100644
--- a/sysdeps/unix/sysv/linux/arm/pwrite.c
+++ b/sysdeps/unix/sysv/linux/arm/pwrite.c
@@ -26,28 +26,10 @@
 ssize_t
 __libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* In the ARM EABI, 64-bit values are aligned to even/odd register
-	 pairs for syscalls.  */
-      result = INLINE_SYSCALL (pwrite64, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR (offset >> 31, offset));
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* In the ARM EABI, 64-bit values are aligned to even/odd register
      pairs for syscalls.  */
-  result = INLINE_SYSCALL (pwrite64, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR (offset >> 31, offset));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite64, fd, buf, count, 0,
+			 __LONG_LONG_PAIR (offset >> 31, offset));
 }
 
 strong_alias (__libc_pwrite, __pwrite)
diff --git a/sysdeps/unix/sysv/linux/arm/pwrite64.c b/sysdeps/unix/sysv/linux/arm/pwrite64.c
index 9cb67ff..b63fbc8 100644
--- a/sysdeps/unix/sysv/linux/arm/pwrite64.c
+++ b/sysdeps/unix/sysv/linux/arm/pwrite64.c
@@ -26,30 +26,11 @@
 ssize_t
 __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* In the ARM EABI, 64-bit values are aligned to even/odd register
-	 pairs for syscalls.  */
-      result = INLINE_SYSCALL (pwrite64, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR ((off_t) (offset >> 32),
-						 (off_t) (offset & 0xffffffff)));
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* In the ARM EABI, 64-bit values are aligned to even/odd register
      pairs for syscalls.  */
-  result = INLINE_SYSCALL (pwrite64, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite64, fd, buf, count, 0,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 }
 
 weak_alias (__libc_pwrite64, __pwrite64)
diff --git a/sysdeps/unix/sysv/linux/epoll_pwait.c b/sysdeps/unix/sysv/linux/epoll_pwait.c
index 65fefec..0e39013 100644
--- a/sysdeps/unix/sysv/linux/epoll_pwait.c
+++ b/sysdeps/unix/sysv/linux/epoll_pwait.c
@@ -39,18 +39,8 @@ int epoll_pwait (int epfd, struct epoll_event *events,
 		 int maxevents, int timeout,
 		 const sigset_t *set)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (epoll_pwait, 6, epfd, events, maxevents, timeout,
-			   set, _NSIG / 8);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (epoll_pwait, 6, epfd, events, maxevents,
-			       timeout, set, _NSIG / 8);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (epoll_pwait, epfd, events, maxevents,
+			 timeout, set, _NSIG / 8);
 }
 
 #else
diff --git a/sysdeps/unix/sysv/linux/fallocate.c b/sysdeps/unix/sysv/linux/fallocate.c
index e9668bf..f3de90c 100644
--- a/sysdeps/unix/sysv/linux/fallocate.c
+++ b/sysdeps/unix/sysv/linux/fallocate.c
@@ -25,21 +25,9 @@ int
 fallocate (int fd, int mode, __off_t offset, __off_t len)
 {
 #ifdef __NR_fallocate
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (fallocate, 6, fd, mode,
-			   __LONG_LONG_PAIR (offset >> 31, offset),
-			   __LONG_LONG_PAIR (len >> 31, len));
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (fallocate, 6, fd, mode,
-			   __LONG_LONG_PAIR (offset >> 31, offset),
-			   __LONG_LONG_PAIR (len >> 31, len));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fallocate, fd, mode,
+			 __LONG_LONG_PAIR (offset >> 31, offset),
+			 __LONG_LONG_PAIR (len >> 31, len));
 #else
   __set_errno (ENOSYS);
   return -1;
diff --git a/sysdeps/unix/sysv/linux/fallocate64.c b/sysdeps/unix/sysv/linux/fallocate64.c
index 96acb28..191fa57 100644
--- a/sysdeps/unix/sysv/linux/fallocate64.c
+++ b/sysdeps/unix/sysv/linux/fallocate64.c
@@ -25,25 +25,11 @@ int
 fallocate64 (int fd, int mode, __off64_t offset, __off64_t len)
 {
 #ifdef __NR_fallocate
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (fallocate, 6, fd, mode,
-			   __LONG_LONG_PAIR ((long int) (offset >> 32),
-					     (long int) offset),
-			   __LONG_LONG_PAIR ((long int) (len >> 32),
-					     (long int) len));
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (fallocate, 6, fd, mode,
-			   __LONG_LONG_PAIR ((long int) (offset >> 32),
-					     (long int) offset),
-			   __LONG_LONG_PAIR ((long int) (len >> 32),
-					     (long int) len));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fallocate, fd, mode,
+			 __LONG_LONG_PAIR ((long int) (offset >> 32),
+					   (long int) offset),
+			 __LONG_LONG_PAIR ((long int) (len >> 32),
+					   (long int) len));
 #else
   __set_errno (ENOSYS);
   return -1;
diff --git a/sysdeps/unix/sysv/linux/generic/open.c b/sysdeps/unix/sysv/linux/generic/open.c
index 289f57a..66cc2ed 100644
--- a/sysdeps/unix/sysv/linux/generic/open.c
+++ b/sysdeps/unix/sysv/linux/generic/open.c
@@ -37,16 +37,7 @@ __libc_open (const char *file, int oflag, ...)
       va_end (arg);
     }
 
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file, oflag, mode);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (openat, AT_FDCWD, file, oflag, mode);
 }
 libc_hidden_def (__libc_open)
 
diff --git a/sysdeps/unix/sysv/linux/generic/open64.c b/sysdeps/unix/sysv/linux/generic/open64.c
index 374e41c..402bc7c 100644
--- a/sysdeps/unix/sysv/linux/generic/open64.c
+++ b/sysdeps/unix/sysv/linux/generic/open64.c
@@ -37,18 +37,7 @@ __libc_open64 (const char *file, int oflag, ...)
       va_end (arg);
     }
 
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (openat, 4, AT_FDCWD, file,
-                           oflag | O_LARGEFILE, mode);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (openat, 4, AT_FDCWD, file,
-                               oflag | O_LARGEFILE, mode);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (openat, AT_FDCWD, file, oflag | O_LARGEFILE, mode);
 }
 weak_alias (__libc_open64, __open64)
 libc_hidden_weak (__open64)
diff --git a/sysdeps/unix/sysv/linux/generic/pause.c b/sysdeps/unix/sysv/linux/generic/pause.c
index 7966df2..45d3a0e 100644
--- a/sysdeps/unix/sysv/linux/generic/pause.c
+++ b/sysdeps/unix/sysv/linux/generic/pause.c
@@ -23,41 +23,17 @@
 /* Suspend the process until a signal arrives.
    This always returns -1 and sets errno to EINTR.  */
 
-static int
-__syscall_pause (void)
+int
+__libc_pause (void)
 {
   sigset_t set;
 
   int rc =
-    INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set, _NSIG / 8);
+    SYSCALL_CANCEL (rt_sigprocmask, SIG_BLOCK, NULL, &set, _NSIG / 8);
   if (rc == 0)
-    rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8);
+    rc = SYSCALL_CANCEL (rt_sigsuspend, &set, _NSIG / 8);
 
   return rc;
 }
 
-int
-__libc_pause (void)
-{
-  if (SINGLE_THREAD_P)
-    return __syscall_pause ();
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = __syscall_pause ();
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
 weak_alias (__libc_pause, pause)
-
-#ifndef NO_CANCELLATION
-# include <not-cancel.h>
-
-int
-__pause_nocancel (void)
-{
-  return __syscall_pause ();
-}
-#endif
diff --git a/sysdeps/unix/sysv/linux/generic/poll.c b/sysdeps/unix/sysv/linux/generic/poll.c
index 7ef42f3..2a95796 100644
--- a/sysdeps/unix/sysv/linux/generic/poll.c
+++ b/sysdeps/unix/sysv/linux/generic/poll.c
@@ -35,16 +35,7 @@ __poll (struct pollfd *fds, nfds_t nfds, int timeout)
       timeout_ts_p = &timeout_ts;
     }
 
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout_ts_p, NULL, 0);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout_ts_p, NULL, 0);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (ppoll, fds, nfds, timeout_ts_p, NULL, 0);
 }
 libc_hidden_def (__poll)
 weak_alias (__poll, poll)
diff --git a/sysdeps/unix/sysv/linux/generic/recv.c b/sysdeps/unix/sysv/linux/generic/recv.c
index d827b3e..3786172 100644
--- a/sysdeps/unix/sysv/linux/generic/recv.c
+++ b/sysdeps/unix/sysv/linux/generic/recv.c
@@ -24,22 +24,8 @@
 ssize_t
 __libc_recv (int sockfd, void *buffer, size_t len, int flags)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (recvfrom, 6, sockfd, buffer, len, flags,
-                             NULL, NULL);
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (recvfrom, 6, sockfd, buffer, len, flags,
-                               NULL, NULL);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
-
-  return result;
+  return SYSCALL_CANCEL (recvfrom, sockfd, buffer, len, flags,
+			 NULL, NULL);
 }
 strong_alias (__libc_recv, __recv)
 weak_alias (__libc_recv, recv)
diff --git a/sysdeps/unix/sysv/linux/generic/select.c b/sysdeps/unix/sysv/linux/generic/select.c
index 455c308..f7f1e18 100644
--- a/sysdeps/unix/sysv/linux/generic/select.c
+++ b/sysdeps/unix/sysv/linux/generic/select.c
@@ -42,20 +42,8 @@ __select(int nfds, fd_set *readfds,
       tsp = &ts;
     }
 
-  if (SINGLE_THREAD_P)
-    {
-      result = INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds,
-                               tsp, NULL);
-    }
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds,
-                               tsp, NULL);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds, tsp,
+			   NULL);
 
   if (timeout)
     {
diff --git a/sysdeps/unix/sysv/linux/generic/send.c b/sysdeps/unix/sysv/linux/generic/send.c
index dfbdc09..fed6961 100644
--- a/sysdeps/unix/sysv/linux/generic/send.c
+++ b/sysdeps/unix/sysv/linux/generic/send.c
@@ -24,20 +24,7 @@
 ssize_t
 __libc_send (int sockfd, const void *buffer, size_t len, int flags)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (sendto, 6, sockfd, buffer, len, flags, NULL, 0);
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (sendto, 6, sockfd, buffer, len, flags, NULL, 0);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
-
-  return result;
+  return SYSCALL_CANCEL (sendto, sockfd, buffer, len, flags, NULL, 0);
 }
 strong_alias (__libc_send, __send)
 weak_alias (__libc_send, send)
diff --git a/sysdeps/unix/sysv/linux/generic/sysdep.h b/sysdeps/unix/sysv/linux/generic/sysdep.h
index 160804c..11da9d2 100644
--- a/sysdeps/unix/sysv/linux/generic/sysdep.h
+++ b/sysdeps/unix/sysv/linux/generic/sysdep.h
@@ -18,6 +18,7 @@
 
 #include <bits/wordsize.h>
 #include <kernel-features.h>
+#include <sysdeps/unix/sysdep.h>
 
 /* Provide the common name to allow more code reuse.  */
 #define __NR__llseek __NR_llseek
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c
index ad97e97..6f9703c 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread.c
@@ -25,28 +25,13 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_pread (int fd, void *buf, size_t count, off_t offset)
+ssize_t
+__libc_pread (int fd, void *buf, size_t count, off_t offset)
 {
   assert (sizeof (offset) == 4);
-  return INLINE_SYSCALL (pread64, __ALIGNMENT_COUNT (5, 6), fd,
+  return SYSCALL_CANCEL (pread64, fd,
                          buf, count, __ALIGNMENT_ARG
                          __LONG_LONG_PAIR (offset >> 31, offset));
 }
-
-ssize_t
-__libc_pread (int fd, void *buf, size_t count, off_t offset)
-{
-  if (SINGLE_THREAD_P)
-    return do_pread (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pread (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
 strong_alias (__libc_pread, __pread)
 weak_alias (__libc_pread, pread)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c
index 7250893..a3f8ec1 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pread64.c
@@ -24,29 +24,11 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_pread64 (int fd, void *buf, size_t count, off64_t offset)
-{
-  return INLINE_SYSCALL (pread64, __ALIGNMENT_COUNT (5, 6), fd,
-                         buf, count, __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR ((off_t) (offset >> 32),
-                                           (off_t) (offset & 0xffffffff)));
-}
-
-
 ssize_t
 __libc_pread64 (int fd, void *buf, size_t count, off64_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pread64 (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pread64 (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread64, fd, buf, count, __ALIGNMENT_ARG
+                         __LONG_LONG_PAIR ((off_t) (offset >> 32),
+                                           (off_t) (offset & 0xffffffff)));
 }
-
 weak_alias (__libc_pread64, __pread64) weak_alias (__libc_pread64, pread64)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c
index 9a1832a..d127fee 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv.c
@@ -26,28 +26,13 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_preadv (int fd, const struct iovec *vector, int count, off_t offset)
+ssize_t
+__libc_preadv (int fd, const struct iovec *vector, int count, off_t offset)
 {
   assert (sizeof (offset) == 4);
-  return INLINE_SYSCALL (preadv, __ALIGNMENT_COUNT (5, 6), fd,
+  return SYSCALL_CANCEL (preadv, fd,
                          vector, count, __ALIGNMENT_ARG
                          __LONG_LONG_PAIR (offset >> 31, offset));
 }
-
-ssize_t
-__libc_preadv (int fd, const struct iovec *vector, int count, off_t offset)
-{
-  if (SINGLE_THREAD_P)
-    return do_preadv (fd, vector, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_preadv (fd, vector, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
 strong_alias (__libc_preadv, __preadv)
 weak_alias (__libc_preadv, preadv)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c
index df1c010..7e7ebf7 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/preadv64.c
@@ -25,30 +25,14 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset)
+ssize_t
+__libc_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset)
 {
-  return INLINE_SYSCALL (preadv, __ALIGNMENT_COUNT (5, 6), fd,
+  return SYSCALL_CANCEL (preadv, fd,
                          vector, count, __ALIGNMENT_ARG
                          __LONG_LONG_PAIR ((off_t) (offset >> 32),
                                            (off_t) (offset & 0xffffffff)));
 }
 
-
-ssize_t
-__libc_preadv64 (int fd, const struct iovec *vector, int count, off64_t offset)
-{
-  if (SINGLE_THREAD_P)
-    return do_preadv64 (fd, vector, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_preadv64 (fd, vector, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
-
 strong_alias (__libc_preadv64, __preadv64)
 weak_alias (__libc_preadv64, preadv64)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c
index e897c7d..2f0f7a1 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite.c
@@ -25,29 +25,12 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_pwrite (int fd, const void *buf, size_t count, off_t offset)
-{
-  assert (sizeof (offset) == 4);
-  return INLINE_SYSCALL (pwrite64, __ALIGNMENT_COUNT (5, 6), fd,
-                         buf, count, __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR (offset >> 31, offset));
-}
-
-
 ssize_t
 __libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pwrite (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pwrite (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  assert (sizeof (offset) == 4);
+  return SYSCALL_CANCEL (pwrite64, fd, buf, count, __ALIGNMENT_ARG
+                         __LONG_LONG_PAIR (offset >> 31, offset));
 }
 strong_alias (__libc_pwrite, __pwrite)
 weak_alias (__libc_pwrite, pwrite)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c
index 3ac1339..f222016 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwrite64.c
@@ -24,30 +24,12 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
-{
-  return INLINE_SYSCALL (pwrite64, __ALIGNMENT_COUNT (5, 6), fd,
-                         buf, count, __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR ((off_t) (offset >> 32),
-                                           (off_t) (offset & 0xffffffff)));
-}
-
-
 ssize_t
 __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pwrite64 (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pwrite64 (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite64, fd, buf, count, __ALIGNMENT_ARG
+                         __LONG_LONG_PAIR ((off_t) (offset >> 32),
+                                           (off_t) (offset & 0xffffffff)));
 }
-
 weak_alias (__libc_pwrite64, __pwrite64)
 libc_hidden_weak (__pwrite64) weak_alias (__libc_pwrite64, pwrite64)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c
index db1e4cb..273b0ff 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev.c
@@ -26,29 +26,12 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_pwritev (int fd, const struct iovec *vector, int count, off_t offset)
-{
-  assert (sizeof (offset) == 4);
-  return INLINE_SYSCALL (pwritev, __ALIGNMENT_COUNT (5, 6), fd,
-                         vector, count, __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR (offset >> 31, offset));
-}
-
-
 ssize_t
 __libc_pwritev (int fd, const struct iovec *vector, int count, off_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pwritev (fd, vector, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pwritev (fd, vector, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  assert (sizeof (offset) == 4);
+  return SYSCALL_CANCEL (pwritev, fd, vector, count, __ALIGNMENT_ARG
+                         __LONG_LONG_PAIR (offset >> 31, offset));
 }
 strong_alias (__libc_pwritev, __pwritev)
 weak_alias (__libc_pwritev, pwritev)
diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c
index eb85e07..9d3fa75 100644
--- a/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c
+++ b/sysdeps/unix/sysv/linux/generic/wordsize-32/pwritev64.c
@@ -25,31 +25,14 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-static ssize_t
-do_pwritev64 (int fd, const struct iovec *vector, int count, off64_t offset)
-{
-  return INLINE_SYSCALL (pwritev, __ALIGNMENT_COUNT (5, 6), fd,
-                         vector, count, __ALIGNMENT_ARG
-                         __LONG_LONG_PAIR ((off_t) (offset >> 32),
-                                           (off_t) (offset & 0xffffffff)));
-}
-
-
 ssize_t
 __libc_pwritev64 (int fd, const struct iovec *vector, int count,
                   off64_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pwritev64 (fd, vector, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pwritev64 (fd, vector, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwritev, fd,
+                         vector, count, __ALIGNMENT_ARG
+                         __LONG_LONG_PAIR ((off_t) (offset >> 32),
+                                           (off_t) (offset & 0xffffffff)));
 }
-
 strong_alias (__libc_pwritev64, pwritev64)
 weak_alias (__libc_pwritev64, __pwritev64)
diff --git a/sysdeps/unix/sysv/linux/i386/fcntl.c b/sysdeps/unix/sysv/linux/i386/fcntl.c
index 9132c5a..56f4bd1 100644
--- a/sysdeps/unix/sysv/linux/i386/fcntl.c
+++ b/sysdeps/unix/sysv/linux/i386/fcntl.c
@@ -49,16 +49,10 @@ __libc_fcntl (int fd, int cmd, ...)
   arg = va_arg (ap, void *);
   va_end (ap);
 
-  if (SINGLE_THREAD_P || (cmd != F_SETLKW && cmd != F_SETLKW64))
+  if ((cmd != F_SETLKW) && (cmd != F_SETLKW64))
     return INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
 
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (fcntl64, 3, fd, cmd, arg);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fcntl64, fd, cmd, arg);
 }
 libc_hidden_def (__libc_fcntl)
 
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/sync_file_range.c b/sysdeps/unix/sysv/linux/mips/mips32/sync_file_range.c
index 3c91d15..b79e44d 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/sync_file_range.c
+++ b/sysdeps/unix/sysv/linux/mips/mips32/sync_file_range.c
@@ -28,23 +28,10 @@
 int
 sync_file_range (int fd, __off64_t from, __off64_t to, unsigned int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (sync_file_range, 7, fd, 0,
-			   __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
-			   __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
-			   flags);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (sync_file_range, 7, fd, 0,
-			   __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
-			   __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
-			   flags);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (sync_file_range, fd, 0,
+			 __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
+			 __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
+			 flags);
 }
 #else
 int
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c b/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c
index 2331cec..ce29a0e 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c
@@ -25,17 +25,7 @@ int
 fallocate (int fd, int mode, __off_t offset, __off_t len)
 {
 #ifdef __NR_fallocate
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (fallocate, 4, fd, mode, offset, len);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (fallocate, 4, fd, mode, offset, len);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fallocate, fd, mode, offset, len);
 #else
   __set_errno (ENOSYS);
   return -1;
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate64.c b/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate64.c
index d3ed5d1..077127e 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate64.c
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate64.c
@@ -25,17 +25,7 @@ int
 fallocate64 (int fd, int mode, __off64_t offset, __off64_t len)
 {
 #ifdef __NR_fallocate
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (fallocate, 4, fd, mode, offset, len);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (fallocate, 4, fd, mode, offset, len);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fallocate, fd, mode, offset, len);
 #else
   __set_errno (ENOSYS);
   return -1;
diff --git a/sysdeps/unix/sysv/linux/mips/pread.c b/sysdeps/unix/sysv/linux/mips/pread.c
index a7b1618..0bd712d 100644
--- a/sysdeps/unix/sysv/linux/mips/pread.c
+++ b/sysdeps/unix/sysv/linux/mips/pread.c
@@ -38,35 +38,16 @@
 ssize_t
 __libc_pread (int fd, void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
 #if _MIPS_SIM != _ABI64
   assert (sizeof (offset) == 4);
 #endif
 
-  if (SINGLE_THREAD_P)
-    {
-#if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-      result = INLINE_SYSCALL (pread, 4, fd, buf, count, offset);
-#else
-      result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR (offset >> 31, offset));
-#endif
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-  result = INLINE_SYSCALL (pread, 4, fd, buf, count, offset);
+  return SYSCALL_CANCEL (pread, fd, buf, count, offset);
 #else
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR (offset >> 31, offset));
+  return SYSCALL_CANCEL (pread, fd, buf, count, 0,
+			 __LONG_LONG_PAIR (offset >> 31, offset));
 #endif
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
 }
 
 strong_alias (__libc_pread, __pread)
diff --git a/sysdeps/unix/sysv/linux/mips/pread64.c b/sysdeps/unix/sysv/linux/mips/pread64.c
index ad948aa..3ed100b 100644
--- a/sysdeps/unix/sysv/linux/mips/pread64.c
+++ b/sysdeps/unix/sysv/linux/mips/pread64.c
@@ -37,34 +37,13 @@
 ssize_t
 __libc_pread64 (int fd, void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-
-  if (SINGLE_THREAD_P)
-    {
 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-      result = INLINE_SYSCALL (pread, 4, fd, buf, count, offset);
+  return SYSCALL_CANCEL (pread, fd, buf, count, offset);
 #else
-     result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			      __LONG_LONG_PAIR ((off_t) (offset >> 32),
-			      (off_t) (offset & 0xffffffff)));
+  return SYSCALL_CANCEL (pread, fd, buf, count, 0,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 #endif
-     return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-#if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-  result = INLINE_SYSCALL (pread, 4, fd, buf, count, offset);
-#else
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-#endif
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
 }
 
 weak_alias (__libc_pread64, __pread64)
diff --git a/sysdeps/unix/sysv/linux/mips/pwrite.c b/sysdeps/unix/sysv/linux/mips/pwrite.c
index 2c38e04..f4d71d4 100644
--- a/sysdeps/unix/sysv/linux/mips/pwrite.c
+++ b/sysdeps/unix/sysv/linux/mips/pwrite.c
@@ -38,35 +38,16 @@
 ssize_t
 __libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
 #if _MIPS_SIM != _ABI64
   assert (sizeof (offset) == 4);
 #endif
 
-  if (SINGLE_THREAD_P)
-    {
-#if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-      result = INLINE_SYSCALL (pwrite, 4, fd, buf, count, offset);
-#else
-      result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR (offset >> 31, offset));
-#endif
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-  result = INLINE_SYSCALL (pwrite, 4, fd, buf, count, offset);
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, offset);
 #else
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR (offset >> 31, offset));
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, 0,
+			 __LONG_LONG_PAIR (offset >> 31, offset));
 #endif
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
 }
 
 strong_alias (__libc_pwrite, __pwrite)
diff --git a/sysdeps/unix/sysv/linux/mips/pwrite64.c b/sysdeps/unix/sysv/linux/mips/pwrite64.c
index 504c88a..ac0dc40 100644
--- a/sysdeps/unix/sysv/linux/mips/pwrite64.c
+++ b/sysdeps/unix/sysv/linux/mips/pwrite64.c
@@ -37,34 +37,13 @@
 ssize_t
 __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-      result = INLINE_SYSCALL (pwrite, 4, fd, buf, count, offset);
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, offset);
 #else
-     result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			      __LONG_LONG_PAIR ((off_t) (offset >> 32),
-			     (off_t) (offset & 0xffffffff)));
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, 0,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 #endif
-
-     return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-#if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
-  result = INLINE_SYSCALL (pwrite, 4, fd, buf, count, offset);
-#else
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-#endif
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
 }
 
 weak_alias (__libc_pwrite64, __pwrite64)
diff --git a/sysdeps/unix/sysv/linux/msgrcv.c b/sysdeps/unix/sysv/linux/msgrcv.c
index 1c3698c..660ff29 100644
--- a/sysdeps/unix/sysv/linux/msgrcv.c
+++ b/sysdeps/unix/sysv/linux/msgrcv.c
@@ -43,16 +43,6 @@ __libc_msgrcv (int msqid, void *msgp, size_t msgsz, long int msgtyp,
   tmp.msgp = msgp;
   tmp.msgtyp = msgtyp;
 
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (ipc, 5, IPCOP_msgrcv, msqid, msgsz, msgflg, &tmp);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = INLINE_SYSCALL (ipc, 5, IPCOP_msgrcv, msqid, msgsz, msgflg,
-				   &tmp);
-
-   LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (ipc, IPCOP_msgrcv, msqid, msgsz, msgflg, &tmp);
 }
 weak_alias (__libc_msgrcv, msgrcv)
diff --git a/sysdeps/unix/sysv/linux/msgsnd.c b/sysdeps/unix/sysv/linux/msgsnd.c
index d548aab..dfed539 100644
--- a/sysdeps/unix/sysv/linux/msgsnd.c
+++ b/sysdeps/unix/sysv/linux/msgsnd.c
@@ -26,17 +26,7 @@
 int
 __libc_msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (ipc, 5, IPCOP_msgsnd, msqid, msgsz,
-			   msgflg, (void *) msgp);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (ipc, 5, IPCOP_msgsnd, msqid, msgsz,
-			       msgflg, (void *) msgp);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (ipc, IPCOP_msgsnd, msqid, msgsz, msgflg,
+			 (void *) msgp);
 }
 weak_alias (__libc_msgsnd, msgsnd)
diff --git a/sysdeps/unix/sysv/linux/open64.c b/sysdeps/unix/sysv/linux/open64.c
index d3ab813..b90294a 100644
--- a/sysdeps/unix/sysv/linux/open64.c
+++ b/sysdeps/unix/sysv/linux/open64.c
@@ -36,16 +36,7 @@ __libc_open64 (const char *file, int oflag, ...)
       va_end (arg);
     }
 
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (open, 3, file, oflag | O_LARGEFILE, mode);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (open, 3, file, oflag | O_LARGEFILE, mode);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (open, file, oflag | O_LARGEFILE, mode);
 }
 weak_alias (__libc_open64, __open64)
 libc_hidden_weak (__open64)
diff --git a/sysdeps/unix/sysv/linux/openat.c b/sysdeps/unix/sysv/linux/openat.c
index 30d8e6e..6777123 100644
--- a/sysdeps/unix/sysv/linux/openat.c
+++ b/sysdeps/unix/sysv/linux/openat.c
@@ -68,16 +68,7 @@ __OPENAT (int fd, const char *file, int oflag, ...)
       va_end (arg);
     }
 
-  if (SINGLE_THREAD_P)
-    return OPENAT_NOT_CANCEL (fd, file, oflag, mode);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int res = OPENAT_NOT_CANCEL (fd, file, oflag, mode);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return res;
+  return SYSCALL_CANCEL (openat, fd, file, oflag, mode);
 }
 libc_hidden_def (__OPENAT)
 weak_alias (__OPENAT, OPENAT)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c
index 10763f5..f6b7f43 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread.c
@@ -26,26 +26,8 @@
 ssize_t
 __libc_pread (int fd, void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-      result = INLINE_SYSCALL (pread, 6, fd, buf, count,
-			       0, offset >> 31, offset);
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count,
-			       0, offset >> 31, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread, fd, buf, count, 0, offset >> 31, offset);
 }
 
 strong_alias (__libc_pread, __pread)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c
index f3dc7e5..75ee34b 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pread64.c
@@ -26,28 +26,9 @@
 ssize_t
 __libc_pread64 (int fd, void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-      result = INLINE_SYSCALL (pread, 6, fd, buf, count,
-			       0, (long) (offset >> 32),
-			       (long) offset);
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count,
-			   0, (long) (offset >> 32),
-			   (long) offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread, fd, buf, count, 0, (long) (offset >> 32),
+			 (long) offset);
 }
 
 weak_alias (__libc_pread64, __pread64)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c
index 65109ed..fc822d7 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite.c
@@ -27,26 +27,8 @@
 ssize_t
 __libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-      result = INLINE_SYSCALL (pwrite, 6, fd, buf, count,
-			       0, offset >> 31, offset);
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count,
-			   0, offset >> 31, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, 0, offset >> 31, offset);
 }
 
 strong_alias (__libc_pwrite, __pwrite)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c
index 77749c9..dbeaed8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/pwrite64.c
@@ -26,28 +26,9 @@
 ssize_t
 __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
   /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-      result = INLINE_SYSCALL (pwrite, 6, fd, buf, count,
-			       0, (long) (offset >> 32),
-			       (long) offset);
-
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  /* On PPC32 64bit values are aligned in odd/even register pairs.  */
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count,
-			   0, (long) (offset >> 32),
-			   (long) offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, 0, (long) (offset >> 32),
+			 (long) offset);
 }
 
 weak_alias (__libc_pwrite64, __pwrite64)
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c b/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
index a4f90b6..69031ba 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c
@@ -53,16 +53,10 @@ __libc_fcntl (int fd, int cmd, ...)
   if (cmd >= F_GETLK64 && cmd <= F_SETLKW64)
     cmd -= F_GETLK64 - F_GETLK;
 
-  if (SINGLE_THREAD_P || cmd != F_SETLKW)
+  if (cmd != F_SETLKW)
     return INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
 
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (fcntl, 3, fd, cmd, arg);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fcntl, fd, cmd, arg);
 }
 libc_hidden_def (__libc_fcntl)
 
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sync_file_range.c b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sync_file_range.c
index 18bb0dd..9f46458 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/sync_file_range.c
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/sync_file_range.c
@@ -28,17 +28,7 @@
 int
 sync_file_range (int fd, __off64_t from, __off64_t to, unsigned int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (sync_file_range2, 4, fd, flags, from, to);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (sync_file_range2, 4, fd, flags, from, to);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (sync_file_range2, fd, flags, from, to);
 }
 #else
 int
diff --git a/sysdeps/unix/sysv/linux/ppoll.c b/sysdeps/unix/sysv/linux/ppoll.c
index 6e83424..77a2e7e 100644
--- a/sysdeps/unix/sysv/linux/ppoll.c
+++ b/sysdeps/unix/sysv/linux/ppoll.c
@@ -47,17 +47,7 @@ ppoll (struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
 
   int result;
 
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout, sigmask, _NSIG / 8);
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (ppoll, 5, fds, nfds, timeout, sigmask,
-			       _NSIG / 8);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = SYSCALL_CANCEL (ppoll, fds, nfds, timeout, sigmask, _NSIG / 8);
 
 # ifndef __ASSUME_PPOLL
   if (result == -1 && errno == ENOSYS)
diff --git a/sysdeps/unix/sysv/linux/pread.c b/sysdeps/unix/sysv/linux/pread.c
index 5c1b174..09389e4 100644
--- a/sysdeps/unix/sysv/linux/pread.c
+++ b/sysdeps/unix/sysv/linux/pread.c
@@ -32,36 +32,17 @@
 #endif
 
 
-static ssize_t
-#ifdef NO_CANCELLATION
-inline __attribute ((always_inline))
-#endif
-do_pread (int fd, void *buf, size_t count, off_t offset)
+ssize_t
+__libc_pread (int fd, void *buf, size_t count, off_t offset)
 {
   ssize_t result;
 
   assert (sizeof (offset) == 4);
-  result = INLINE_SYSCALL (pread, 5, fd, buf, count,
+  result = SYSCALL_CANCEL (pread, fd, buf, count,
 			   __LONG_LONG_PAIR (offset >> 31, offset));
 
   return result;
 }
 
-
-ssize_t
-__libc_pread (int fd, void *buf, size_t count, off_t offset)
-{
-  if (SINGLE_THREAD_P)
-    return do_pread (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pread (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
-
 strong_alias (__libc_pread, __pread)
 weak_alias (__libc_pread, pread)
diff --git a/sysdeps/unix/sysv/linux/pread64.c b/sysdeps/unix/sysv/linux/pread64.c
index a8cfb5d..baf2355 100644
--- a/sysdeps/unix/sysv/linux/pread64.c
+++ b/sysdeps/unix/sysv/linux/pread64.c
@@ -31,32 +31,12 @@
 #endif
 
 
-static ssize_t
-do_pread64 (int fd, void *buf, size_t count, off64_t offset)
-{
-  ssize_t result;
-
-  result = INLINE_SYSCALL (pread, 5, fd, buf, count,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-
-  return result;
-}
-
-
 ssize_t
 __libc_pread64 (int fd, void *buf, size_t count, off64_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pread64 (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pread64 (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread, fd, buf, count,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 }
 
 weak_alias (__libc_pread64, __pread64)
diff --git a/sysdeps/unix/sysv/linux/preadv.c b/sysdeps/unix/sysv/linux/preadv.c
index 091f9a7..2d08be4 100644
--- a/sysdeps/unix/sysv/linux/preadv.c
+++ b/sysdeps/unix/sysv/linux/preadv.c
@@ -53,18 +53,8 @@ PREADV (int fd, const struct iovec *vector, int count, OFF_T offset)
 #ifdef __NR_preadv
   ssize_t result;
 
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (preadv, 5, fd, vector, count,
-			     LO_HI_LONG (offset));
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (preadv, 5, fd, vector, count,
-			       LO_HI_LONG (offset));
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = SYSCALL_CANCEL (preadv, fd, vector, count, LO_HI_LONG (offset));
+
 # ifdef __ASSUME_PREADV
   return result;
 # endif
diff --git a/sysdeps/unix/sysv/linux/pselect.c b/sysdeps/unix/sysv/linux/pselect.c
index f342a13..30d51d7 100644
--- a/sysdeps/unix/sysv/linux/pselect.c
+++ b/sysdeps/unix/sysv/linux/pselect.c
@@ -63,22 +63,11 @@ __pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
 
 #ifndef CALL_PSELECT6
 # define CALL_PSELECT6(nfds, readfds, writefds, exceptfds, timeout, data) \
-  INLINE_SYSCALL (pselect6, 6, nfds, readfds, writefds, exceptfds,	      \
-		  timeout, data)
+  SYSCALL_CANCEL (pselect6, nfds, readfds, writefds, exceptfds,	timeout, data)
 #endif
 
-  if (SINGLE_THREAD_P)
-    result = CALL_PSELECT6 (nfds, readfds, writefds, exceptfds, timeout,
-			    &data);
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = CALL_PSELECT6 (nfds, readfds, writefds, exceptfds, timeout,
-			      &data);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = CALL_PSELECT6 (nfds, readfds, writefds, exceptfds, timeout,
+			  &data);
 
 # ifndef __ASSUME_PSELECT
   if (result == -1 && errno == ENOSYS)
diff --git a/sysdeps/unix/sysv/linux/pwrite.c b/sysdeps/unix/sysv/linux/pwrite.c
index 80c2e22..b77985d 100644
--- a/sysdeps/unix/sysv/linux/pwrite.c
+++ b/sysdeps/unix/sysv/linux/pwrite.c
@@ -32,36 +32,17 @@
 #endif
 
 
-static ssize_t
-#ifdef NO_CANCELLATION
-inline __attribute ((always_inline))
-#endif
-do_pwrite (int fd, const void *buf, size_t count, off_t offset)
+ssize_t
+__libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
 {
   ssize_t result;
 
   assert (sizeof (offset) == 4);
-  result = INLINE_SYSCALL (pwrite, 5, fd, buf, count,
+  result = SYSCALL_CANCEL (pwrite, fd, buf, count,
 			   __LONG_LONG_PAIR (offset >> 31, offset));
 
   return result;
 }
 
-
-ssize_t
-__libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
-{
-  if (SINGLE_THREAD_P)
-    return do_pwrite (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pwrite (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
-
 strong_alias (__libc_pwrite, __pwrite)
 weak_alias (__libc_pwrite, pwrite)
diff --git a/sysdeps/unix/sysv/linux/pwrite64.c b/sysdeps/unix/sysv/linux/pwrite64.c
index 7fce75a..a5d0fb7 100644
--- a/sysdeps/unix/sysv/linux/pwrite64.c
+++ b/sysdeps/unix/sysv/linux/pwrite64.c
@@ -31,34 +31,13 @@
 #endif
 
 
-static ssize_t
-do_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
-{
-  ssize_t result;
-
-  result = INLINE_SYSCALL (pwrite, 5, fd, buf, count,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-
-  return result;
-}
-
-
 ssize_t
 __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
 {
-  if (SINGLE_THREAD_P)
-    return do_pwrite64 (fd, buf, count, offset);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = do_pwrite64 (fd, buf, count, offset);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite, fd, buf, count,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 }
-
 weak_alias (__libc_pwrite64, __pwrite64)
 libc_hidden_weak (__pwrite64)
 weak_alias (__libc_pwrite64, pwrite64)
diff --git a/sysdeps/unix/sysv/linux/pwritev.c b/sysdeps/unix/sysv/linux/pwritev.c
index 91e58b5..7aa9238 100644
--- a/sysdeps/unix/sysv/linux/pwritev.c
+++ b/sysdeps/unix/sysv/linux/pwritev.c
@@ -53,18 +53,8 @@ PWRITEV (int fd, const struct iovec *vector, int count, OFF_T offset)
 #ifdef __NR_pwritev
   ssize_t result;
 
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (pwritev, 5, fd, vector, count,
-			     LO_HI_LONG (offset));
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (pwritev, 5, fd, vector, count,
-			     LO_HI_LONG (offset));
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = SYSCALL_CANCEL (pwritev, fd, vector, count, LO_HI_LONG (offset));
+
 # ifdef __ASSUME_PWRITEV
   return result;
 # endif
diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
index 73b3ee0..4063368 100644
--- a/sysdeps/unix/sysv/linux/recvmmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmmsg.c
@@ -37,16 +37,7 @@ int
 recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
 	  struct timespec *tmo)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (recvmmsg, 5, fd, vmessages, vlen, flags, tmo);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (recvmmsg, 5, fd, vmessages, vlen, flags, tmo);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, tmo);
 }
 #elif defined __NR_socketcall
 # include <socketcall.h>
diff --git a/sysdeps/unix/sysv/linux/sendmmsg.c b/sysdeps/unix/sysv/linux/sendmmsg.c
index 7bad328..dc0aa75 100644
--- a/sysdeps/unix/sysv/linux/sendmmsg.c
+++ b/sysdeps/unix/sysv/linux/sendmmsg.c
@@ -36,16 +36,7 @@
 int
 __sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (sendmmsg, 4, fd, vmessages, vlen, flags);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = INLINE_SYSCALL (sendmmsg, 4, fd, vmessages, vlen, flags);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (sendmmsg, fd, vmessages, vlen, flags);
 }
 libc_hidden_def (__sendmmsg)
 weak_alias (__sendmmsg, sendmmsg)
diff --git a/sysdeps/unix/sysv/linux/sh/pread.c b/sysdeps/unix/sysv/linux/sh/pread.c
index 9d4b5de..2f926b3 100644
--- a/sysdeps/unix/sysv/linux/sh/pread.c
+++ b/sysdeps/unix/sysv/linux/sh/pread.c
@@ -35,23 +35,8 @@
 ssize_t
 __libc_pread (int fd, void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR (offset >> 31, offset));
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR (offset >> 31, offset));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread, fd, buf, count, 0,
+			 __LONG_LONG_PAIR (offset >> 31, offset));
 }
 
 strong_alias (__libc_pread, __pread)
diff --git a/sysdeps/unix/sysv/linux/sh/pread64.c b/sysdeps/unix/sysv/linux/sh/pread64.c
index 195eacc..697718d 100644
--- a/sysdeps/unix/sysv/linux/sh/pread64.c
+++ b/sysdeps/unix/sysv/linux/sh/pread64.c
@@ -34,25 +34,9 @@
 ssize_t
 __libc_pread64 (int fd, void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-     result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			      __LONG_LONG_PAIR ((off_t) (offset >> 32),
-			      (off_t) (offset & 0xffffffff)));
-     return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (pread, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pread, fd, buf, count, 0,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 }
 
 weak_alias (__libc_pread64, __pread64)
diff --git a/sysdeps/unix/sysv/linux/sh/pwrite.c b/sysdeps/unix/sysv/linux/sh/pwrite.c
index c187d0a..fcbb7fc 100644
--- a/sysdeps/unix/sysv/linux/sh/pwrite.c
+++ b/sysdeps/unix/sysv/linux/sh/pwrite.c
@@ -35,23 +35,8 @@
 ssize_t
 __libc_pwrite (int fd, const void *buf, size_t count, off_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-      result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			       __LONG_LONG_PAIR (offset >> 31, offset));
-      return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR (offset >> 31, offset));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, 0,
+			 __LONG_LONG_PAIR (offset >> 31, offset));
 }
 
 strong_alias (__libc_pwrite, __pwrite)
diff --git a/sysdeps/unix/sysv/linux/sh/pwrite64.c b/sysdeps/unix/sysv/linux/sh/pwrite64.c
index 0d15ca2..0c189fe 100644
--- a/sysdeps/unix/sysv/linux/sh/pwrite64.c
+++ b/sysdeps/unix/sysv/linux/sh/pwrite64.c
@@ -34,26 +34,9 @@
 ssize_t
 __libc_pwrite64 (int fd, const void *buf, size_t count, off64_t offset)
 {
-  ssize_t result;
-
-  if (SINGLE_THREAD_P)
-    {
-     result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			      __LONG_LONG_PAIR ((off_t) (offset >> 32),
-			     (off_t) (offset & 0xffffffff)));
-
-     return result;
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (pwrite, 6, fd, buf, count, 0,
-			   __LONG_LONG_PAIR ((off_t) (offset >> 32),
-					     (off_t) (offset & 0xffffffff)));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (pwrite, fd, buf, count, 0,
+			 __LONG_LONG_PAIR ((off_t) (offset >> 32),
+					   (off_t) (offset & 0xffffffff)));
 }
 
 weak_alias (__libc_pwrite64, __pwrite64)
diff --git a/sysdeps/unix/sysv/linux/sigsuspend.c b/sysdeps/unix/sysv/linux/sigsuspend.c
index 89c5d65..9047623 100644
--- a/sysdeps/unix/sysv/linux/sigsuspend.c
+++ b/sysdeps/unix/sysv/linux/sigsuspend.c
@@ -22,38 +22,13 @@
 #include <sysdep-cancel.h>
 #include <sys/syscall.h>
 
-
-static inline int __attribute__ ((always_inline))
-do_sigsuspend (const sigset_t *set)
-{
-  return INLINE_SYSCALL (rt_sigsuspend, 2, set, _NSIG / 8);
-}
-
 /* Change the set of blocked signals to SET,
    wait until a signal arrives, and restore the set of blocked signals.  */
 int
 __sigsuspend (const sigset_t *set)
 {
-  if (SINGLE_THREAD_P)
-    return do_sigsuspend (set);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  int result = do_sigsuspend (set);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (rt_sigsuspend, set, _NSIG / 8);
 }
 libc_hidden_def (__sigsuspend)
 weak_alias (__sigsuspend, sigsuspend)
 strong_alias (__sigsuspend, __libc_sigsuspend)
-
-#ifndef NO_CANCELLATION
-int
-__sigsuspend_nocancel (set)
-     const sigset_t *set;
-{
-  return do_sigsuspend (set);
-}
-#endif
diff --git a/sysdeps/unix/sysv/linux/sigtimedwait.c b/sysdeps/unix/sysv/linux/sigtimedwait.c
index 209198e..a2e5b41 100644
--- a/sysdeps/unix/sysv/linux/sigtimedwait.c
+++ b/sysdeps/unix/sysv/linux/sigtimedwait.c
@@ -25,9 +25,9 @@
 
 #ifdef __NR_rt_sigtimedwait
 
-static int
-do_sigtimedwait (const sigset_t *set, siginfo_t *info,
-		 const struct timespec *timeout)
+int
+__sigtimedwait (const sigset_t *set, siginfo_t *info,
+		const struct timespec *timeout)
 {
 #ifdef SIGCANCEL
   sigset_t tmpset;
@@ -51,8 +51,7 @@ do_sigtimedwait (const sigset_t *set, siginfo_t *info,
 
     /* XXX The size argument hopefully will have to be changed to the
        real size of the user-level sigset_t.  */
-  int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
-			       info, timeout, _NSIG / 8);
+  int result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, timeout, _NSIG / 8);
 
   /* The kernel generates a SI_TKILL code in si_code in case tkill is
      used.  tkill is transparently used in raise().  Since having
@@ -63,26 +62,6 @@ do_sigtimedwait (const sigset_t *set, siginfo_t *info,
 
   return result;
 }
-
-
-/* Return any pending signal or wait for one for the given time.  */
-int
-__sigtimedwait (const sigset_t *set, siginfo_t *info,
-		const struct timespec *timeout)
-{
-  if (SINGLE_THREAD_P)
-    return do_sigtimedwait (set, info, timeout);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  /* XXX The size argument hopefully will have to be changed to the
-     real size of the user-level sigset_t.  */
-  int result = do_sigtimedwait (set, info, timeout);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
 libc_hidden_def (__sigtimedwait)
 weak_alias (__sigtimedwait, sigtimedwait)
 #else
diff --git a/sysdeps/unix/sysv/linux/sigwaitinfo.c b/sysdeps/unix/sysv/linux/sigwaitinfo.c
index fe23c9f..47e6dd6 100644
--- a/sysdeps/unix/sysv/linux/sigwaitinfo.c
+++ b/sysdeps/unix/sysv/linux/sigwaitinfo.c
@@ -27,8 +27,9 @@
 
 #ifdef __NR_rt_sigtimedwait
 
-static int
-do_sigwaitinfo (const sigset_t *set, siginfo_t *info)
+/* Return any pending signal or wait for one for the given time.  */
+int
+__sigwaitinfo (const sigset_t *set, siginfo_t *info)
 {
 #ifdef SIGCANCEL
   sigset_t tmpset;
@@ -52,8 +53,7 @@ do_sigwaitinfo (const sigset_t *set, siginfo_t *info)
 
   /* XXX The size argument hopefully will have to be changed to the
      real size of the user-level sigset_t.  */
-  int result = INLINE_SYSCALL (rt_sigtimedwait, 4, set,
-			       info, NULL, _NSIG / 8);
+  int result = SYSCALL_CANCEL (rt_sigtimedwait, set, info, NULL, _NSIG / 8);
 
   /* The kernel generates a SI_TKILL code in si_code in case tkill is
      used.  tkill is transparently used in raise().  Since having
@@ -65,24 +65,6 @@ do_sigwaitinfo (const sigset_t *set, siginfo_t *info)
   return result;
 }
 
-
-/* Return any pending signal or wait for one for the given time.  */
-int
-__sigwaitinfo (const sigset_t *set, siginfo_t *info)
-{
-  if (SINGLE_THREAD_P)
-    return do_sigwaitinfo (set, info);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  /* XXX The size argument hopefully will have to be changed to the
-     real size of the user-level sigset_t.  */
-  int result = do_sigwaitinfo (set, info);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}
 libc_hidden_def (__sigwaitinfo)
 weak_alias (__sigwaitinfo, sigwaitinfo)
 #else
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/msgrcv.c b/sysdeps/unix/sysv/linux/sparc/sparc64/msgrcv.c
index 8928060..169ac53 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/msgrcv.c
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/msgrcv.c
@@ -26,17 +26,7 @@ ssize_t
 __libc_msgrcv (int msqid, void *msgp, size_t msgsz, long int msgtyp,
 	       int msgflg)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (ipc, 6, IPCOP_msgrcv, msqid, msgsz, msgflg,
-			   msgp, msgtyp);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = INLINE_SYSCALL (ipc, 6, IPCOP_msgrcv, msqid, msgsz, msgflg,
-				   msgp, msgtyp);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (ipc, IPCOP_msgrcv, msqid, msgsz, msgflg,
+			 msgp, msgtyp);
 }
 weak_alias (__libc_msgrcv, msgrcv)
diff --git a/sysdeps/unix/sysv/linux/sync_file_range.c b/sysdeps/unix/sysv/linux/sync_file_range.c
index c07ece0..2ea6dcf 100644
--- a/sysdeps/unix/sysv/linux/sync_file_range.c
+++ b/sysdeps/unix/sysv/linux/sync_file_range.c
@@ -28,43 +28,18 @@
 int
 sync_file_range (int fd, __off64_t from, __off64_t to, unsigned int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (sync_file_range, 6, fd,
-			   __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
-			   __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
-			   flags);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (sync_file_range, 6, fd,
-			   __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
-			   __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
-			   flags);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (sync_file_range, fd,
+			 __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
+			 __LONG_LONG_PAIR ((long) (to >> 32), (long) to),
+			 flags);
 }
 #elif defined __NR_sync_file_range2
 int
 sync_file_range (int fd, __off64_t from, __off64_t to, unsigned int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (sync_file_range2, 6, fd, flags,
-			   __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
-			   __LONG_LONG_PAIR ((long) (to >> 32), (long) to));
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (sync_file_range2, 6, fd, flags,
-			   __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
-			   __LONG_LONG_PAIR ((long) (to >> 32), (long) to));
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (sync_file_range2, fd, flags,
+			 __LONG_LONG_PAIR ((long) (from >> 32), (long) from),
+			 __LONG_LONG_PAIR ((long) (to >> 32), (long) to));
 }
 #else
 int
diff --git a/sysdeps/unix/sysv/linux/tcdrain.c b/sysdeps/unix/sysv/linux/tcdrain.c
index c0f2e1d..f60dd4d 100644
--- a/sysdeps/unix/sysv/linux/tcdrain.c
+++ b/sysdeps/unix/sysv/linux/tcdrain.c
@@ -24,17 +24,7 @@
 int
 __libc_tcdrain (int fd)
 {
-  if (SINGLE_THREAD_P)
-    /* With an argument of 1, TCSBRK for output to be drain.  */
-    return INLINE_SYSCALL (ioctl, 3, fd, TCSBRK, 1);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
   /* With an argument of 1, TCSBRK for output to be drain.  */
-  int result = INLINE_SYSCALL (ioctl, 3, fd, TCSBRK, 1);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (ioctl, fd, TCSBRK, 1);
 }
 weak_alias (__libc_tcdrain, tcdrain)
diff --git a/sysdeps/unix/sysv/linux/timer_routines.c b/sysdeps/unix/sysv/linux/timer_routines.c
index 4401a8b..4cf6eca 100644
--- a/sysdeps/unix/sysv/linux/timer_routines.c
+++ b/sysdeps/unix/sysv/linux/timer_routines.c
@@ -20,7 +20,7 @@
 #include <setjmp.h>
 #include <signal.h>
 #include <stdbool.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
 #include <nptl/pthreadP.h>
 #include "kernel-posix-timers.h"
 
@@ -84,14 +84,9 @@ timer_helper_thread (void *arg)
       /* sigwaitinfo cannot be used here, since it deletes
 	 SIGCANCEL == SIGTIMER from the set.  */
 
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
       /* XXX The size argument hopefully will have to be changed to the
 	 real size of the user-level sigset_t.  */
-      int result = INLINE_SYSCALL (rt_sigtimedwait, 4, &ss, &si, NULL,
-				   _NSIG / 8);
-
-      LIBC_CANCEL_RESET (oldtype);
+      int result = SYSCALL_CANCEL (rt_sigtimedwait, &ss, &si, NULL, _NSIG / 8);
 
       if (result > 0)
 	{
diff --git a/sysdeps/unix/sysv/linux/wait.c b/sysdeps/unix/sysv/linux/wait.c
index 029d975..5b76c7c 100644
--- a/sysdeps/unix/sysv/linux/wait.c
+++ b/sysdeps/unix/sysv/linux/wait.c
@@ -26,17 +26,8 @@
 pid_t
 __libc_wait (__WAIT_STATUS_DEFN stat_loc)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
-			   (struct rusage *) NULL);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  pid_t result = INLINE_SYSCALL (wait4, 4, WAIT_ANY, stat_loc, 0,
+  pid_t result = SYSCALL_CANCEL (wait4, WAIT_ANY, stat_loc, 0,
 				 (struct rusage *) NULL);
-
-  LIBC_CANCEL_RESET (oldtype);
-
   return result;
 }
 
diff --git a/sysdeps/unix/sysv/linux/waitid.c b/sysdeps/unix/sysv/linux/waitid.c
index 12d5702..71d3a5a 100644
--- a/sysdeps/unix/sysv/linux/waitid.c
+++ b/sysdeps/unix/sysv/linux/waitid.c
@@ -19,15 +19,14 @@
 #include <stddef.h>
 #include <errno.h>
 #include <sys/wait.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
 
-static inline int
-do_waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
+int
+__waitid (idtype_t idtype, id_t id, siginfo_t *infop, int options)
 {
   /* The unused fifth argument is a `struct rusage *' that we could
      pass if we were using waitid to simulate wait3/wait4.  */
-  return INLINE_SYSCALL (waitid, 5, idtype, id, infop, options, NULL);
+  return SYSCALL_CANCEL (waitid, idtype, id, infop, options, NULL);
 }
-#define NO_DO_WAITID
-
-#include "sysdeps/posix/waitid.c"
+weak_alias (__waitid, waitid)
+strong_alias (__waitid, __libc_waitid)
diff --git a/sysdeps/unix/sysv/linux/waitpid.c b/sysdeps/unix/sysv/linux/waitpid.c
index 0d780da..59d0c9e 100644
--- a/sysdeps/unix/sysv/linux/waitpid.c
+++ b/sysdeps/unix/sysv/linux/waitpid.c
@@ -23,26 +23,11 @@
 __pid_t
 __waitpid (__pid_t pid, int *stat_loc, int options)
 {
-  if (SINGLE_THREAD_P)
-    {
 #ifdef __NR_waitpid
-      return INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options);
+  return SYSCALL_CANCEL (waitpid, pid, stat_loc, options);
 #else
-      return INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL);
+  return SYSCALL_CANCEL (wait4, pid, stat_loc, options, NULL);
 #endif
-    }
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-#ifdef __NR_waitpid
-  int result = INLINE_SYSCALL (waitpid, 3, pid, stat_loc, options);
-#else
-  int result = INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL);
-#endif
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
 }
 libc_hidden_def (__waitpid)
 weak_alias (__waitpid, waitpid)
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/fallocate.c b/sysdeps/unix/sysv/linux/wordsize-64/fallocate.c
index c723fef..627ac2a 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/fallocate.c
+++ b/sysdeps/unix/sysv/linux/wordsize-64/fallocate.c
@@ -25,17 +25,7 @@ int
 fallocate (int fd, int mode, __off_t offset, __off_t len)
 {
 #ifdef __NR_fallocate
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (fallocate, 4, fd, mode, offset, len);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = INLINE_SYSCALL (fallocate, 4, fd, mode, offset, len);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (fallocate, fd, mode, offset, len);
 #else
   __set_errno (ENOSYS);
   return -1;
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/preadv.c b/sysdeps/unix/sysv/linux/wordsize-64/preadv.c
index 9b3ae70..5e22c4b 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/preadv.c
+++ b/sysdeps/unix/sysv/linux/wordsize-64/preadv.c
@@ -38,16 +38,7 @@ preadv (int fd, const struct iovec *vector, int count, off_t offset)
 #ifdef __NR_preadv
   ssize_t result;
 
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (preadv, 4, fd, vector, count, offset);
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (preadv, 4, fd, vector, count, offset);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = SYSCALL_CANCEL (preadv, fd, vector, count, offset);
 # ifdef __ASSUME_PREADV
   return result;
 # endif
diff --git a/sysdeps/unix/sysv/linux/wordsize-64/pwritev.c b/sysdeps/unix/sysv/linux/wordsize-64/pwritev.c
index 960c8c0..ccf96dd 100644
--- a/sysdeps/unix/sysv/linux/wordsize-64/pwritev.c
+++ b/sysdeps/unix/sysv/linux/wordsize-64/pwritev.c
@@ -38,16 +38,7 @@ pwritev (int fd, const struct iovec *vector, int count, off_t offset)
 #ifdef __NR_pwritev
   ssize_t result;
 
-  if (SINGLE_THREAD_P)
-    result = INLINE_SYSCALL (pwritev, 4, fd, vector, count, offset);
-  else
-    {
-      int oldtype = LIBC_CANCEL_ASYNC ();
-
-      result = INLINE_SYSCALL (pwritev, 4, fd, vector, count, offset);
-
-      LIBC_CANCEL_RESET (oldtype);
-    }
+  result = SYSCALL_CANCEL (pwritev, fd, vector, count, offset);
 # ifdef __ASSUME_PWRITEV
   return result;
 # endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/recv.c b/sysdeps/unix/sysv/linux/x86_64/recv.c
index 7b956a5..995d11d 100644
--- a/sysdeps/unix/sysv/linux/x86_64/recv.c
+++ b/sysdeps/unix/sysv/linux/x86_64/recv.c
@@ -25,16 +25,7 @@
 ssize_t
 __libc_recv (int fd, void *buf, size_t n, int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (recvfrom, fd, buf, n, flags, NULL, NULL);
 }
 
 weak_alias (__libc_recv, __recv)
diff --git a/sysdeps/unix/sysv/linux/x86_64/send.c b/sysdeps/unix/sysv/linux/x86_64/send.c
index c8dadfa..864a8d5 100644
--- a/sysdeps/unix/sysv/linux/x86_64/send.c
+++ b/sysdeps/unix/sysv/linux/x86_64/send.c
@@ -23,17 +23,7 @@
 ssize_t
 __libc_send (int fd, const void *buf, size_t n, int flags)
 {
-  if (SINGLE_THREAD_P)
-    return INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL, (size_t) 0);
-
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  ssize_t result = INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL,
-				   (size_t) 0);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
+  return SYSCALL_CANCEL (sendto, fd, buf, n, flags, NULL, (size_t) 0);
 }
 
 weak_alias (__libc_send, __send)

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=5e6e69846f710fe97962340d24f0544c5107716f

commit 5e6e69846f710fe97962340d24f0544c5107716f
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Wed Sep 24 21:52:07 2014 -0300

    nptl: x86_64: Remove assembly pthread_cond_{timed}wait.S implementation
    
    This patch removes the x86_64 assembly implementation for
    pthread_cond_timedwait and pthread_cond_wait for upcoming BZ#12683 fix.
    The patch requires that cancellable futex calls to be called through
    __syscall_cancel. Although it not strictly require, the remove of the
    x86_64 specific implementation follows the rationale:
    
    1. The adjustments required to this fix is extensive (parameters
       save, functions calls, etc.) and there is little gain in keep an
       alternate implementation for x86_64 in term of maintanability.
    2. There is no pthread_cond benchmark that shows these implementations
       are more 'optimized' that what current compilers can produce using
       generic C code.
    3. The changes required also can change the exact gains this optimized is
       intended to provide.

diff --git a/ChangeLog b/ChangeLog
index 31e30aa..eb800a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/x86_64/librt-cancellation.S: Remove file.
+	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S: Remove
+
 	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = misc)]: Remove
 	call_pselect6 object.
 	[$(subdir) = io]: Remove call_sync_file_range object.
diff --git a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
deleted file mode 100644
index 15b872d..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
+++ /dev/null
@@ -1,623 +0,0 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   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>
-#include <shlib-compat.h>
-#include <lowlevellock.h>
-#include <lowlevelcond.h>
-#include <pthread-pi-defines.h>
-#include <pthread-errnos.h>
-#include <stap-probe.h>
-
-#include <kernel-features.h>
-
-
-	.text
-
-
-/* int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
-			       const struct timespec *abstime)  */
-	.globl	__pthread_cond_timedwait
-	.type	__pthread_cond_timedwait, @function
-	.align	16
-__pthread_cond_timedwait:
-.LSTARTCODE:
-	cfi_startproc
-#ifdef SHARED
-	cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
-			DW.ref.__gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
-#else
-	cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
-#endif
-
-	pushq	%r12
-	cfi_adjust_cfa_offset(8)
-	cfi_rel_offset(%r12, 0)
-	pushq	%r13
-	cfi_adjust_cfa_offset(8)
-	cfi_rel_offset(%r13, 0)
-	pushq	%r14
-	cfi_adjust_cfa_offset(8)
-	cfi_rel_offset(%r14, 0)
-	pushq	%r15
-	cfi_adjust_cfa_offset(8)
-	cfi_rel_offset(%r15, 0)
-#define FRAME_SIZE (32+8)
-	subq	$FRAME_SIZE, %rsp
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-	cfi_remember_state
-
-	LIBC_PROBE (cond_timedwait, 3, %rdi, %rsi, %rdx)
-
-	cmpq	$1000000000, 8(%rdx)
-	movl	$EINVAL, %eax
-	jae	48f
-
-	/* Stack frame:
-
-	   rsp + 48
-		    +--------------------------+
-	   rsp + 32 | timeout value            |
-		    +--------------------------+
-	   rsp + 24 | old wake_seq value       |
-		    +--------------------------+
-	   rsp + 16 | mutex pointer            |
-		    +--------------------------+
-	   rsp +  8 | condvar pointer          |
-		    +--------------------------+
-	   rsp +  4 | old broadcast_seq value  |
-		    +--------------------------+
-	   rsp +  0 | old cancellation mode    |
-		    +--------------------------+
-	*/
-
-	LP_OP(cmp) $-1, dep_mutex(%rdi)
-
-	/* Prepare structure passed to cancellation handler.  */
-	movq	%rdi, 8(%rsp)
-	movq	%rsi, 16(%rsp)
-	movq	%rdx, %r13
-
-	je	22f
-	mov	%RSI_LP, dep_mutex(%rdi)
-
-22:
-	xorb	%r15b, %r15b
-
-	/* Get internal lock.  */
-	movl	$1, %esi
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %esi, (%rdi)
-#else
-	cmpxchgl %esi, cond_lock(%rdi)
-#endif
-	jnz	31f
-
-	/* Unlock the mutex.  */
-32:	movq	16(%rsp), %rdi
-	xorl	%esi, %esi
-	callq	__pthread_mutex_unlock_usercnt
-
-	testl	%eax, %eax
-	jne	46f
-
-	movq	8(%rsp), %rdi
-	incq	total_seq(%rdi)
-	incl	cond_futex(%rdi)
-	addl	$(1 << nwaiters_shift), cond_nwaiters(%rdi)
-
-	/* Get and store current wakeup_seq value.  */
-	movq	8(%rsp), %rdi
-	movq	wakeup_seq(%rdi), %r9
-	movl	broadcast_seq(%rdi), %edx
-	movq	%r9, 24(%rsp)
-	movl	%edx, 4(%rsp)
-
-	cmpq	$0, (%r13)
-	movq	$-ETIMEDOUT, %r14
-	js	36f
-
-38:	movl	cond_futex(%rdi), %r12d
-
-	/* Unlock.  */
-	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	jne	33f
-
-.LcleanupSTART1:
-34:	callq	__pthread_enable_asynccancel
-	movl	%eax, (%rsp)
-
-	movq	%r13, %r10
-	movl	$FUTEX_WAIT_BITSET, %esi
-	LP_OP(cmp) $-1, dep_mutex(%rdi)
-	je	60f
-
-	mov	dep_mutex(%rdi), %R8_LP
-	/* Requeue to a non-robust PI mutex if the PI bit is set and
-	the robust bit is not set.  */
-	movl	MUTEX_KIND(%r8), %eax
-	andl	$(ROBUST_BIT|PI_BIT), %eax
-	cmpl	$PI_BIT, %eax
-	jne	61f
-
-	movl	$(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
-	xorl	%eax, %eax
-	/* The following only works like this because we only support
-	   two clocks, represented using a single bit.  */
-	testl	$1, cond_nwaiters(%rdi)
-	movl	$FUTEX_CLOCK_REALTIME, %edx
-	cmove	%edx, %eax
-	orl	%eax, %esi
-	movq	%r12, %rdx
-	addq	$cond_futex, %rdi
-	movl	$SYS_futex, %eax
-	syscall
-
-	cmpl	$0, %eax
-	sete	%r15b
-
-#ifdef __ASSUME_REQUEUE_PI
-	jmp	62f
-#else
-	je	62f
-
-	/* When a futex syscall with FUTEX_WAIT_REQUEUE_PI returns
-	   successfully, it has already locked the mutex for us and the
-	   pi_flag (%r15b) is set to denote that fact.  However, if another
-	   thread changed the futex value before we entered the wait, the
-	   syscall may return an EAGAIN and the mutex is not locked.  We go
-	   ahead with a success anyway since later we look at the pi_flag to
-	   decide if we got the mutex or not.  The sequence numbers then make
-	   sure that only one of the threads actually wake up.  We retry using
-	   normal FUTEX_WAIT only if the kernel returned ENOSYS, since normal
-	   and PI futexes don't mix.
-
-	   Note that we don't check for EAGAIN specifically; we assume that the
-	   only other error the futex function could return is EAGAIN (barring
-	   the ETIMEOUT of course, for the timeout case in futex) since
-	   anything else would mean an error in our function.  It is too
-	   expensive to do that check for every call (which is  quite common in
-	   case of a large number of threads), so it has been skipped.  */
-	cmpl    $-ENOSYS, %eax
-	jne     62f
-
-	subq	$cond_futex, %rdi
-#endif
-
-61:	movl	$(FUTEX_WAIT_BITSET|FUTEX_PRIVATE_FLAG), %esi
-60:	xorb	%r15b, %r15b
-	xorl	%eax, %eax
-	/* The following only works like this because we only support
-	   two clocks, represented using a single bit.  */
-	testl	$1, cond_nwaiters(%rdi)
-	movl	$FUTEX_CLOCK_REALTIME, %edx
-	movl	$0xffffffff, %r9d
-	cmove	%edx, %eax
-	orl	%eax, %esi
-	movq	%r12, %rdx
-	addq	$cond_futex, %rdi
-	movl	$SYS_futex, %eax
-	syscall
-62:	movq	%rax, %r14
-
-	movl	(%rsp), %edi
-	callq	__pthread_disable_asynccancel
-.LcleanupEND1:
-
-	/* Lock.  */
-	movq	8(%rsp), %rdi
-	movl	$1, %esi
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %esi, (%rdi)
-#else
-	cmpxchgl %esi, cond_lock(%rdi)
-#endif
-	jne	35f
-
-36:	movl	broadcast_seq(%rdi), %edx
-
-	movq	woken_seq(%rdi), %rax
-
-	movq	wakeup_seq(%rdi), %r9
-
-	cmpl	4(%rsp), %edx
-	jne	53f
-
-	cmpq	24(%rsp), %r9
-	jbe	45f
-
-	cmpq	%rax, %r9
-	ja	39f
-
-45:	cmpq	$-ETIMEDOUT, %r14
-	je	99f
-
-	/* We need to go back to futex_wait.  If we're using requeue_pi, then
-	   release the mutex we had acquired and go back.  */
-	test	%r15b, %r15b
-	jz	38b
-
-	/* Adjust the mutex values first and then unlock it.  The unlock
-	   should always succeed or else the kernel did not lock the
-	   mutex correctly.  */
-	movq	%r8, %rdi
-	callq	__pthread_mutex_cond_lock_adjust
-	xorl	%esi, %esi
-	callq	__pthread_mutex_unlock_usercnt
-	/* Reload cond_var.  */
-	movq	8(%rsp), %rdi
-	jmp	38b
-
-99:	incq	wakeup_seq(%rdi)
-	incl	cond_futex(%rdi)
-	movl	$ETIMEDOUT, %r14d
-	jmp	44f
-
-53:	xorq	%r14, %r14
-	jmp	54f
-
-39:	xorq	%r14, %r14
-44:	incq	woken_seq(%rdi)
-
-54:	subl	$(1 << nwaiters_shift), cond_nwaiters(%rdi)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	cmpq	$0xffffffffffffffff, total_seq(%rdi)
-	jne	55f
-	movl	cond_nwaiters(%rdi), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	55f
-
-	addq	$cond_nwaiters, %rdi
-	LP_OP(cmp) $-1, dep_mutex-cond_nwaiters(%rdi)
-	movl	$1, %edx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAKE, %eax
-	movl	$(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
-	cmove	%eax, %esi
-#else
-	movl	$0, %eax
-	movl	%fs:PRIVATE_FUTEX, %esi
-	cmove	%eax, %esi
-	orl	$FUTEX_WAKE, %esi
-#endif
-	movl	$SYS_futex, %eax
-	syscall
-	subq	$cond_nwaiters, %rdi
-
-55:	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	jne	40f
-
-	/* If requeue_pi is used the kernel performs the locking of the
-	   mutex. */
-41:	movq	16(%rsp), %rdi
-	testb	%r15b, %r15b
-	jnz	64f
-
-	callq	__pthread_mutex_cond_lock
-
-63:	testq	%rax, %rax
-	cmoveq	%r14, %rax
-
-48:	addq	$FRAME_SIZE, %rsp
-	cfi_adjust_cfa_offset(-FRAME_SIZE)
-	popq	%r15
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r15)
-	popq	%r14
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r14)
-	popq	%r13
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r13)
-	popq	%r12
-	cfi_adjust_cfa_offset(-8)
-	cfi_restore(%r12)
-
-	retq
-
-	cfi_restore_state
-
-64:	callq	__pthread_mutex_cond_lock_adjust
-	movq	%r14, %rax
-	jmp	48b
-
-	/* Initial locking failed.  */
-31:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_lock_wait
-	jmp	32b
-
-	/* Unlock in loop requires wakeup.  */
-33:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_unlock_wake
-	jmp	34b
-
-	/* Locking in loop failed.  */
-35:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_lock_wait
-#if cond_lock != 0
-	subq	$cond_lock, %rdi
-#endif
-	jmp	36b
-
-	/* Unlock after loop requires wakeup.  */
-40:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_unlock_wake
-	jmp	41b
-
-	/* The initial unlocking of the mutex failed.  */
-46:	movq	8(%rsp), %rdi
-	movq	%rax, (%rsp)
-	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	jne	47f
-
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_unlock_wake
-
-47:	movq	(%rsp), %rax
-	jmp	48b
-
-	.size	__pthread_cond_timedwait, .-__pthread_cond_timedwait
-versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
-		  GLIBC_2_3_2)
-
-
-	.align	16
-	.type	__condvar_cleanup2, @function
-__condvar_cleanup2:
-	/* Stack frame:
-
-	   rsp + 72
-		    +--------------------------+
-	   rsp + 64 | %r12                     |
-		    +--------------------------+
-	   rsp + 56 | %r13                     |
-		    +--------------------------+
-	   rsp + 48 | %r14                     |
-		    +--------------------------+
-	   rsp + 24 | unused                   |
-		    +--------------------------+
-	   rsp + 16 | mutex pointer            |
-		    +--------------------------+
-	   rsp +  8 | condvar pointer          |
-		    +--------------------------+
-	   rsp +  4 | old broadcast_seq value  |
-		    +--------------------------+
-	   rsp +  0 | old cancellation mode    |
-		    +--------------------------+
-	*/
-
-	movq	%rax, 24(%rsp)
-
-	/* Get internal lock.  */
-	movq	8(%rsp), %rdi
-	movl	$1, %esi
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %esi, (%rdi)
-#else
-	cmpxchgl %esi, cond_lock(%rdi)
-#endif
-	jz	1f
-
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_lock_wait
-#if cond_lock != 0
-	subq	$cond_lock, %rdi
-#endif
-
-1:	movl	broadcast_seq(%rdi), %edx
-	cmpl	4(%rsp), %edx
-	jne	3f
-
-	/* We increment the wakeup_seq counter only if it is lower than
-	   total_seq.  If this is not the case the thread was woken and
-	   then canceled.  In this case we ignore the signal.  */
-	movq	total_seq(%rdi), %rax
-	cmpq	wakeup_seq(%rdi), %rax
-	jbe	6f
-	incq	wakeup_seq(%rdi)
-	incl	cond_futex(%rdi)
-6:	incq	woken_seq(%rdi)
-
-3:	subl	$(1 << nwaiters_shift), cond_nwaiters(%rdi)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	xorq	%r12, %r12
-	cmpq	$0xffffffffffffffff, total_seq(%rdi)
-	jne	4f
-	movl	cond_nwaiters(%rdi), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	4f
-
-	LP_OP(cmp) $-1, dep_mutex(%rdi)
-	leaq	cond_nwaiters(%rdi), %rdi
-	movl	$1, %edx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAKE, %eax
-	movl	$(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
-	cmove	%eax, %esi
-#else
-	movl	$0, %eax
-	movl	%fs:PRIVATE_FUTEX, %esi
-	cmove	%eax, %esi
-	orl	$FUTEX_WAKE, %esi
-#endif
-	movl	$SYS_futex, %eax
-	syscall
-	subq	$cond_nwaiters, %rdi
-	movl	$1, %r12d
-
-4:	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	je	2f
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_unlock_wake
-
-	/* Wake up all waiters to make sure no signal gets lost.  */
-2:	testq	%r12, %r12
-	jnz	5f
-	addq	$cond_futex, %rdi
-	LP_OP(cmp) $-1, dep_mutex-cond_futex(%rdi)
-	movl	$0x7fffffff, %edx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAKE, %eax
-	movl	$(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
-	cmove	%eax, %esi
-#else
-	movl	$0, %eax
-	movl	%fs:PRIVATE_FUTEX, %esi
-	cmove	%eax, %esi
-	orl	$FUTEX_WAKE, %esi
-#endif
-	movl	$SYS_futex, %eax
-	syscall
-
-	/* Lock the mutex only if we don't own it already.  This only happens
-	   in case of PI mutexes, if we got cancelled after a successful
-	   return of the futex syscall and before disabling async
-	   cancellation.  */
-5:	movq	16(%rsp), %rdi
-	movl	MUTEX_KIND(%rdi), %eax
-	andl	$(ROBUST_BIT|PI_BIT), %eax
-	cmpl	$PI_BIT, %eax
-	jne	7f
-
-	movl	(%rdi), %eax
-	andl	$TID_MASK, %eax
-	cmpl	%eax, %fs:TID
-	jne	7f
-	/* We managed to get the lock.  Fix it up before returning.  */
-	callq	__pthread_mutex_cond_lock_adjust
-	jmp	8f
-
-7:	callq	__pthread_mutex_cond_lock
-
-8:	movq	24(%rsp), %rdi
-	movq	FRAME_SIZE(%rsp), %r15
-	movq	FRAME_SIZE+8(%rsp), %r14
-	movq	FRAME_SIZE+16(%rsp), %r13
-	movq	FRAME_SIZE+24(%rsp), %r12
-.LcallUR:
-	call	_Unwind_Resume@PLT
-	hlt
-.LENDCODE:
-	cfi_endproc
-	.size	__condvar_cleanup2, .-__condvar_cleanup2
-
-
-	.section .gcc_except_table,"a",@progbits
-.LexceptSTART:
-	.byte	DW_EH_PE_omit			# @LPStart format
-	.byte	DW_EH_PE_omit			# @TType format
-	.byte	DW_EH_PE_uleb128		# call-site format
-	.uleb128 .Lcstend-.Lcstbegin
-.Lcstbegin:
-	.uleb128 .LcleanupSTART1-.LSTARTCODE
-	.uleb128 .LcleanupEND1-.LcleanupSTART1
-	.uleb128 __condvar_cleanup2-.LSTARTCODE
-	.uleb128  0
-	.uleb128 .LcallUR-.LSTARTCODE
-	.uleb128 .LENDCODE-.LcallUR
-	.uleb128 0
-	.uleb128  0
-.Lcstend:
-
-
-#ifdef SHARED
-	.hidden	DW.ref.__gcc_personality_v0
-	.weak	DW.ref.__gcc_personality_v0
-	.section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
-	.align	LP_SIZE
-	.type	DW.ref.__gcc_personality_v0, @object
-	.size	DW.ref.__gcc_personality_v0, LP_SIZE
-DW.ref.__gcc_personality_v0:
-	ASM_ADDR __gcc_personality_v0
-#endif
diff --git a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
deleted file mode 100644
index 2e564a7..0000000
--- a/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
+++ /dev/null
@@ -1,555 +0,0 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   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>
-#include <shlib-compat.h>
-#include <lowlevellock.h>
-#include <lowlevelcond.h>
-#include <tcb-offsets.h>
-#include <pthread-pi-defines.h>
-#include <pthread-errnos.h>
-#include <stap-probe.h>
-
-#include <kernel-features.h>
-
-
-	.text
-
-/* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)  */
-	.globl	__pthread_cond_wait
-	.type	__pthread_cond_wait, @function
-	.align	16
-__pthread_cond_wait:
-.LSTARTCODE:
-	cfi_startproc
-#ifdef SHARED
-	cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
-			DW.ref.__gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
-#else
-	cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
-#endif
-
-#define FRAME_SIZE (32+8)
-	leaq	-FRAME_SIZE(%rsp), %rsp
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-
-	/* Stack frame:
-
-	   rsp + 32
-		    +--------------------------+
-	   rsp + 24 | old wake_seq value       |
-		    +--------------------------+
-	   rsp + 16 | mutex pointer            |
-		    +--------------------------+
-	   rsp +  8 | condvar pointer          |
-		    +--------------------------+
-	   rsp +  4 | old broadcast_seq value  |
-		    +--------------------------+
-	   rsp +  0 | old cancellation mode    |
-		    +--------------------------+
-	*/
-
-	LIBC_PROBE (cond_wait, 2, %rdi, %rsi)
-
-	LP_OP(cmp) $-1, dep_mutex(%rdi)
-
-	/* Prepare structure passed to cancellation handler.  */
-	movq	%rdi, 8(%rsp)
-	movq	%rsi, 16(%rsp)
-
-	je	15f
-	mov	%RSI_LP, dep_mutex(%rdi)
-
-	/* Get internal lock.  */
-15:	movl	$1, %esi
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %esi, (%rdi)
-#else
-	cmpxchgl %esi, cond_lock(%rdi)
-#endif
-	jne	1f
-
-	/* Unlock the mutex.  */
-2:	movq	16(%rsp), %rdi
-	xorl	%esi, %esi
-	callq	__pthread_mutex_unlock_usercnt
-
-	testl	%eax, %eax
-	jne	12f
-
-	movq	8(%rsp), %rdi
-	incq	total_seq(%rdi)
-	incl	cond_futex(%rdi)
-	addl	$(1 << nwaiters_shift), cond_nwaiters(%rdi)
-
-	/* Get and store current wakeup_seq value.  */
-	movq	8(%rsp), %rdi
-	movq	wakeup_seq(%rdi), %r9
-	movl	broadcast_seq(%rdi), %edx
-	movq	%r9, 24(%rsp)
-	movl	%edx, 4(%rsp)
-
-	/* Unlock.  */
-8:	movl	cond_futex(%rdi), %edx
-	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	jne	3f
-
-.LcleanupSTART:
-4:	callq	__pthread_enable_asynccancel
-	movl	%eax, (%rsp)
-
-	xorq	%r10, %r10
-	LP_OP(cmp) $-1, dep_mutex(%rdi)
-	leaq	cond_futex(%rdi), %rdi
-	movl	$FUTEX_WAIT, %esi
-	je	60f
-
-	mov	dep_mutex-cond_futex(%rdi), %R8_LP
-	/* Requeue to a non-robust PI mutex if the PI bit is set and
-	the robust bit is not set.  */
-	movl	MUTEX_KIND(%r8), %eax
-	andl	$(ROBUST_BIT|PI_BIT), %eax
-	cmpl	$PI_BIT, %eax
-	jne	61f
-
-	movl	$(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
-	movl	$SYS_futex, %eax
-	syscall
-
-	cmpl	$0, %eax
-	sete	%r8b
-
-#ifdef __ASSUME_REQUEUE_PI
-	jmp	62f
-#else
-	je	62f
-
-	/* When a futex syscall with FUTEX_WAIT_REQUEUE_PI returns
-	   successfully, it has already locked the mutex for us and the
-	   pi_flag (%r8b) is set to denote that fact.  However, if another
-	   thread changed the futex value before we entered the wait, the
-	   syscall may return an EAGAIN and the mutex is not locked.  We go
-	   ahead with a success anyway since later we look at the pi_flag to
-	   decide if we got the mutex or not.  The sequence numbers then make
-	   sure that only one of the threads actually wake up.  We retry using
-	   normal FUTEX_WAIT only if the kernel returned ENOSYS, since normal
-	   and PI futexes don't mix.
-
-	   Note that we don't check for EAGAIN specifically; we assume that the
-	   only other error the futex function could return is EAGAIN since
-	   anything else would mean an error in our function.  It is too
-	   expensive to do that check for every call (which is 	quite common in
-	   case of a large number of threads), so it has been skipped.  */
-	cmpl	$-ENOSYS, %eax
-	jne	62f
-
-# ifndef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAIT, %esi
-# endif
-#endif
-
-61:
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$(FUTEX_WAIT|FUTEX_PRIVATE_FLAG), %esi
-#else
-	orl	%fs:PRIVATE_FUTEX, %esi
-#endif
-60:	xorb	%r8b, %r8b
-	movl	$SYS_futex, %eax
-	syscall
-
-62:	movl	(%rsp), %edi
-	callq	__pthread_disable_asynccancel
-.LcleanupEND:
-
-	/* Lock.  */
-	movq	8(%rsp), %rdi
-	movl	$1, %esi
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %esi, (%rdi)
-#else
-	cmpxchgl %esi, cond_lock(%rdi)
-#endif
-	jnz	5f
-
-6:	movl	broadcast_seq(%rdi), %edx
-
-	movq	woken_seq(%rdi), %rax
-
-	movq	wakeup_seq(%rdi), %r9
-
-	cmpl	4(%rsp), %edx
-	jne	16f
-
-	cmpq	24(%rsp), %r9
-	jbe	19f
-
-	cmpq	%rax, %r9
-	jna	19f
-
-	incq	woken_seq(%rdi)
-
-	/* Unlock */
-16:	subl	$(1 << nwaiters_shift), cond_nwaiters(%rdi)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	cmpq	$0xffffffffffffffff, total_seq(%rdi)
-	jne	17f
-	movl	cond_nwaiters(%rdi), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	17f
-
-	addq	$cond_nwaiters, %rdi
-	LP_OP(cmp) $-1, dep_mutex-cond_nwaiters(%rdi)
-	movl	$1, %edx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAKE, %eax
-	movl	$(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
-	cmove	%eax, %esi
-#else
-	movl	$0, %eax
-	movl	%fs:PRIVATE_FUTEX, %esi
-	cmove	%eax, %esi
-	orl	$FUTEX_WAKE, %esi
-#endif
-	movl	$SYS_futex, %eax
-	syscall
-	subq	$cond_nwaiters, %rdi
-
-17:	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	jne	10f
-
-	/* If requeue_pi is used the kernel performs the locking of the
-	   mutex. */
-11:	movq	16(%rsp), %rdi
-	testb	%r8b, %r8b
-	jnz	18f
-
-	callq	__pthread_mutex_cond_lock
-
-14:	leaq	FRAME_SIZE(%rsp), %rsp
-	cfi_adjust_cfa_offset(-FRAME_SIZE)
-
-	/* We return the result of the mutex_lock operation.  */
-	retq
-
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-
-18:	callq	__pthread_mutex_cond_lock_adjust
-	xorl	%eax, %eax
-	jmp	14b
-
-	/* We need to go back to futex_wait.  If we're using requeue_pi, then
-	   release the mutex we had acquired and go back.  */
-19:	testb	%r8b, %r8b
-	jz	8b
-
-	/* Adjust the mutex values first and then unlock it.  The unlock
-	   should always succeed or else the kernel did not lock the mutex
-	   correctly.  */
-	movq	16(%rsp), %rdi
-	callq	__pthread_mutex_cond_lock_adjust
-	movq	%rdi, %r8
-	xorl	%esi, %esi
-	callq	__pthread_mutex_unlock_usercnt
-	/* Reload cond_var.  */
-	movq	8(%rsp), %rdi
-	jmp	8b
-
-	/* Initial locking failed.  */
-1:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_lock_wait
-	jmp	2b
-
-	/* Unlock in loop requires wakeup.  */
-3:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	/* The call preserves %rdx.  */
-	callq	__lll_unlock_wake
-#if cond_lock != 0
-	subq	$cond_lock, %rdi
-#endif
-	jmp	4b
-
-	/* Locking in loop failed.  */
-5:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_lock_wait
-#if cond_lock != 0
-	subq	$cond_lock, %rdi
-#endif
-	jmp	6b
-
-	/* Unlock after loop requires wakeup.  */
-10:
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_unlock_wake
-	jmp	11b
-
-	/* The initial unlocking of the mutex failed.  */
-12:	movq	%rax, %r10
-	movq	8(%rsp), %rdi
-	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	je	13f
-
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_unlock_wake
-
-13:	movq	%r10, %rax
-	jmp	14b
-
-	.size	__pthread_cond_wait, .-__pthread_cond_wait
-versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
-		  GLIBC_2_3_2)
-
-
-	.align	16
-	.type	__condvar_cleanup1, @function
-	.globl	__condvar_cleanup1
-	.hidden	__condvar_cleanup1
-__condvar_cleanup1:
-	/* Stack frame:
-
-	   rsp + 32
-		    +--------------------------+
-	   rsp + 24 | unused                   |
-		    +--------------------------+
-	   rsp + 16 | mutex pointer            |
-		    +--------------------------+
-	   rsp +  8 | condvar pointer          |
-		    +--------------------------+
-	   rsp +  4 | old broadcast_seq value  |
-		    +--------------------------+
-	   rsp +  0 | old cancellation mode    |
-		    +--------------------------+
-	*/
-
-	movq	%rax, 24(%rsp)
-
-	/* Get internal lock.  */
-	movq	8(%rsp), %rdi
-	movl	$1, %esi
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %esi, (%rdi)
-#else
-	cmpxchgl %esi, cond_lock(%rdi)
-#endif
-	jz	1f
-
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	callq	__lll_lock_wait
-#if cond_lock != 0
-	subq	$cond_lock, %rdi
-#endif
-
-1:	movl	broadcast_seq(%rdi), %edx
-	cmpl	4(%rsp), %edx
-	jne	3f
-
-	/* We increment the wakeup_seq counter only if it is lower than
-	   total_seq.  If this is not the case the thread was woken and
-	   then canceled.  In this case we ignore the signal.  */
-	movq	total_seq(%rdi), %rax
-	cmpq	wakeup_seq(%rdi), %rax
-	jbe	6f
-	incq	wakeup_seq(%rdi)
-	incl	cond_futex(%rdi)
-6:	incq	woken_seq(%rdi)
-
-3:	subl	$(1 << nwaiters_shift), cond_nwaiters(%rdi)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	xorl	%ecx, %ecx
-	cmpq	$0xffffffffffffffff, total_seq(%rdi)
-	jne	4f
-	movl	cond_nwaiters(%rdi), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	4f
-
-	LP_OP(cmp) $-1, dep_mutex(%rdi)
-	leaq	cond_nwaiters(%rdi), %rdi
-	movl	$1, %edx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAKE, %eax
-	movl	$(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
-	cmove	%eax, %esi
-#else
-	movl	$0, %eax
-	movl	%fs:PRIVATE_FUTEX, %esi
-	cmove	%eax, %esi
-	orl	$FUTEX_WAKE, %esi
-#endif
-	movl	$SYS_futex, %eax
-	syscall
-	subq	$cond_nwaiters, %rdi
-	movl	$1, %ecx
-
-4:	LOCK
-#if cond_lock == 0
-	decl	(%rdi)
-#else
-	decl	cond_lock(%rdi)
-#endif
-	je	2f
-#if cond_lock != 0
-	addq	$cond_lock, %rdi
-#endif
-	LP_OP(cmp) $-1, dep_mutex-cond_lock(%rdi)
-	movl	$LLL_PRIVATE, %eax
-	movl	$LLL_SHARED, %esi
-	cmovne	%eax, %esi
-	/* The call preserves %rcx.  */
-	callq	__lll_unlock_wake
-
-	/* Wake up all waiters to make sure no signal gets lost.  */
-2:	testl	%ecx, %ecx
-	jnz	5f
-	addq	$cond_futex, %rdi
-	LP_OP(cmp) $-1, dep_mutex-cond_futex(%rdi)
-	movl	$0x7fffffff, %edx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	movl	$FUTEX_WAKE, %eax
-	movl	$(FUTEX_WAKE|FUTEX_PRIVATE_FLAG), %esi
-	cmove	%eax, %esi
-#else
-	movl	$0, %eax
-	movl	%fs:PRIVATE_FUTEX, %esi
-	cmove	%eax, %esi
-	orl	$FUTEX_WAKE, %esi
-#endif
-	movl	$SYS_futex, %eax
-	syscall
-
-	/* Lock the mutex only if we don't own it already.  This only happens
-	   in case of PI mutexes, if we got cancelled after a successful
-	   return of the futex syscall and before disabling async
-	   cancellation.  */
-5:	movq	16(%rsp), %rdi
-	movl	MUTEX_KIND(%rdi), %eax
-	andl	$(ROBUST_BIT|PI_BIT), %eax
-	cmpl	$PI_BIT, %eax
-	jne	7f
-
-	movl	(%rdi), %eax
-	andl	$TID_MASK, %eax
-	cmpl	%eax, %fs:TID
-	jne	7f
-	/* We managed to get the lock.  Fix it up before returning.  */
-	callq	__pthread_mutex_cond_lock_adjust
-	jmp	8f
-
-
-7:	callq	__pthread_mutex_cond_lock
-
-8:	movq	24(%rsp), %rdi
-.LcallUR:
-	call	_Unwind_Resume@PLT
-	hlt
-.LENDCODE:
-	cfi_endproc
-	.size	__condvar_cleanup1, .-__condvar_cleanup1
-
-
-	.section .gcc_except_table,"a",@progbits
-.LexceptSTART:
-	.byte	DW_EH_PE_omit			# @LPStart format
-	.byte	DW_EH_PE_omit			# @TType format
-	.byte	DW_EH_PE_uleb128		# call-site format
-	.uleb128 .Lcstend-.Lcstbegin
-.Lcstbegin:
-	.uleb128 .LcleanupSTART-.LSTARTCODE
-	.uleb128 .LcleanupEND-.LcleanupSTART
-	.uleb128 __condvar_cleanup1-.LSTARTCODE
-	.uleb128 0
-	.uleb128 .LcallUR-.LSTARTCODE
-	.uleb128 .LENDCODE-.LcallUR
-	.uleb128 0
-	.uleb128 0
-.Lcstend:
-
-
-#ifdef SHARED
-	.hidden	DW.ref.__gcc_personality_v0
-	.weak	DW.ref.__gcc_personality_v0
-	.section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
-	.align	LP_SIZE
-	.type	DW.ref.__gcc_personality_v0, @object
-	.size	DW.ref.__gcc_personality_v0, LP_SIZE
-DW.ref.__gcc_personality_v0:
-	ASM_ADDR __gcc_personality_v0
-#endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=689cfad50b70308d0605d297862e9b611ccbcb80

commit 689cfad50b70308d0605d297862e9b611ccbcb80
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon May 4 12:29:15 2015 -0300

    i386: Remove six-argument specialized implementations
    
    This patch removes the specialized i386 assembly implementations for
    fallocate{64}, pselect, and sync_file_range now that i386 have
    support for 6 argument syscalls.

diff --git a/ChangeLog b/ChangeLog
index 3a98f33..31e30aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = misc)]: Remove
+	call_pselect6 object.
+	[$(subdir) = io]: Remove call_sync_file_range object.
+	* sysdeps/unix/sysv/linux/i386/call_pselect6.S: Remove file.
+	* sysdeps/unix/sysv/linux/i386/call_sync_file_range.S: Remove file.
+	* sysdeps/unix/sysv/linux/i386/pselect.c: Remove file.
+	* sysdeps/unix/sysv/linux/i386/sync_file_range.c: Remove file.
+
 	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Remove
 	file.
 	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile
index e0fb1ed..80da593 100644
--- a/sysdeps/unix/sysv/linux/i386/Makefile
+++ b/sysdeps/unix/sysv/linux/i386/Makefile
@@ -2,7 +2,7 @@
 default-abi := 32
 
 ifeq ($(subdir),misc)
-sysdep_routines += ioperm iopl vm86 call_pselect6
+sysdep_routines += ioperm iopl vm86
 endif
 
 ifeq ($(subdir),elf)
@@ -12,7 +12,7 @@ endif
 
 # fallocate, posix_fallocate use six-argument inline syscalls.
 ifeq ($(subdir),io)
-sysdep_routines += call_sync_file_range libc-do-syscall
+sysdep_routines += libc-do-syscall
 endif
 
 # libpthread uses six-argument inline syscalls.
diff --git a/sysdeps/unix/sysv/linux/i386/call_pselect6.S b/sysdeps/unix/sysv/linux/i386/call_pselect6.S
deleted file mode 100644
index 610c263..0000000
--- a/sysdeps/unix/sysv/linux/i386/call_pselect6.S
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Copyright (C) 2006-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2006.
-
-   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>
-
-#ifdef __NR_pselect6
-	.text
-ENTRY(__call_pselect6)
-	.hidden __call_pselect6
-	pushl	%ebx
-	cfi_adjust_cfa_offset (4)
-	pushl	%esi
-	cfi_adjust_cfa_offset (4)
-	pushl	%edi
-	cfi_adjust_cfa_offset (4)
-	pushl	%ebp
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (ebp, 0)
-	cfi_rel_offset (edi, 4)
-	cfi_rel_offset (esi, 8)
-	cfi_rel_offset (ebx, 12)
-
-	movl	$__NR_pselect6, %eax
-	movl	20(%esp), %ebx
-	movl	24(%esp), %ecx
-	movl	28(%esp), %edx
-	movl	32(%esp), %esi
-	movl	36(%esp), %edi
-	movl	40(%esp), %ebp
-
-	/* The syscall handling cannot handle 6 parameters.  Yet.  */
-	int	$0x80
-
-	popl	%ebp
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebp)
-	popl	%edi
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (edi)
-	popl	%esi
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (esi)
-	popl	%ebx
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebx)
-
-	ret
-END(__call_pselect6)
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/call_sync_file_range.S b/sysdeps/unix/sysv/linux/i386/call_sync_file_range.S
deleted file mode 100644
index 02c2048..0000000
--- a/sysdeps/unix/sysv/linux/i386/call_sync_file_range.S
+++ /dev/null
@@ -1,70 +0,0 @@
-/* Selective file content synch'ing.
-   Copyright (C) 2006-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>
-#define _ERRNO_H        1
-#include <bits/errno.h>
-
-
-	.text
-ENTRY (__call_sync_file_range)
-#ifdef __NR_sync_file_range
-	pushl	%ebx
-	cfi_adjust_cfa_offset (4)
-	pushl	%esi
-	cfi_adjust_cfa_offset (4)
-	pushl	%edi
-	cfi_adjust_cfa_offset (4)
-	pushl	%ebp
-	cfi_adjust_cfa_offset (4)
-
-	movl	20(%esp), %ebx
-	cfi_rel_offset (ebx, 12)
-	movl	24(%esp), %ecx
-	movl	28(%esp), %edx
-	movl	32(%esp), %esi
-	cfi_rel_offset (esi, 8)
-	movl	36(%esp), %edi
-	cfi_rel_offset (edi, 4)
-	movl	40(%esp), %ebp
-	cfi_rel_offset (ebp, 0)
-
-	movl	$SYS_ify(sync_file_range), %eax
-	ENTER_KERNEL
-
-	popl	%ebp
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebp)
-	popl	%edi
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (edi)
-	popl	%esi
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (esi)
-	popl	%ebx
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebx)
-
-	cmpl	$-4095, %eax
-	jae	SYSCALL_ERROR_LABEL
-#else
-	movl	$-ENOSYS, %eax
-	jmp	SYSCALL_ERROR_LABEL
-#endif
-	ret
-PSEUDO_END (__call_sync_file_range)
diff --git a/sysdeps/unix/sysv/linux/i386/pselect.c b/sysdeps/unix/sysv/linux/i386/pselect.c
deleted file mode 100644
index 2646608..0000000
--- a/sysdeps/unix/sysv/linux/i386/pselect.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <sys/select.h>
-
-extern int __call_pselect6 (int nfds, fd_set *readfds, fd_set *writefds,
-			    fd_set *exceptfds, const struct timespec *timeout,
-			    void *data) attribute_hidden;
-
-
-#define CALL_PSELECT6(nfds, readfds, writefds, exceptfds, timeout, data) \
-  ({ int r = __call_pselect6 (nfds, readfds, writefds, exceptfds, timeout,    \
-			      data);					      \
-     if (r < 0 && r > -4096)						      \
-       {								      \
-	 __set_errno (-r);						      \
-	 r = -1;							      \
-       }								      \
-     r; })
-
-#include "../pselect.c"
diff --git a/sysdeps/unix/sysv/linux/i386/sync_file_range.c b/sysdeps/unix/sysv/linux/i386/sync_file_range.c
deleted file mode 100644
index 8ce0287..0000000
--- a/sysdeps/unix/sysv/linux/i386/sync_file_range.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Selective file content synch'ing.
-   Copyright (C) 2006-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 <errno.h>
-#include <fcntl.h>
-#include <sysdep-cancel.h>
-
-
-extern int __call_sync_file_range (int fd, off64_t offset, off64_t nbytes,
-				   unsigned int flags)
-     attribute_hidden;
-
-
-int
-sync_file_range (int fd, __off64_t from, __off64_t to, unsigned int flags)
-{
-  if (SINGLE_THREAD_P)
-    return __call_sync_file_range (fd, from, to, flags);
-
-  int result;
-  int oldtype = LIBC_CANCEL_ASYNC ();
-
-  result = __call_sync_file_range (fd, from, to, flags);
-
-  LIBC_CANCEL_RESET (oldtype);
-
-  return result;
-}

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=c803026d83aca0de517a8fc79190cb1442bb1989

commit c803026d83aca0de517a8fc79190cb1442bb1989
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon May 4 11:37:02 2015 -0300

    i386: Remove assembly pthread_cond_{timed}wait.S implementation
    
    With i386 support to call six-argument syscall through C code, it can use
    the default C NPTL pthread_cond_{timed}wait implementation. This patch
    removes the i386 assembly implementation for pthread_cond_timedwait and
    pthread_cond_wait for upcoming BZ#12683 fix.
    
    The patch requires that cancellable futex calls to be called through
    __syscall_cancel instead. Although it not strictly require, the remove
    of the i386 specific implementation follows the rationale:
    
    1. The adjustments required to this fix is extensive (parameters
       save, functions calls, etc.) and there is little gain in keep an
       alternate implementation for i386 in term of maintanability.
    2. There is no pthread_cond benchmark that shows these implementations
       are more 'optimized' that what current compilers can produce using
       generic C code.
    3. The changes required also can change the exact gains this optimized is
       intended to provide.

diff --git a/ChangeLog b/ChangeLog
index 4719e8f..3a98f33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S: Remove
+	file.
+	* sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S: Likewise.
+
 	* sysdeps/unix/sysv/linux/socketcall.h (SOCKOP_invalid): Define.
 	(SOCKETCALL): New macro: non-cancellable socketcall.
 	(SOCKETCALL_CANCEL): New macro: cancellable socketcall.
diff --git a/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S b/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
deleted file mode 100644
index 130c090..0000000
--- a/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S
+++ /dev/null
@@ -1,973 +0,0 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   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>
-#include <shlib-compat.h>
-#include <lowlevellock.h>
-#include <lowlevelcond.h>
-#include <pthread-errnos.h>
-#include <pthread-pi-defines.h>
-#include <kernel-features.h>
-#include <stap-probe.h>
-
-	.text
-
-/* int pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex,
-			       const struct timespec *abstime)  */
-	.globl	__pthread_cond_timedwait
-	.type	__pthread_cond_timedwait, @function
-	.align	16
-__pthread_cond_timedwait:
-.LSTARTCODE:
-	cfi_startproc
-#ifdef SHARED
-	cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
-			DW.ref.__gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
-#else
-	cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
-#endif
-
-	pushl	%ebp
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%ebp, 0)
-	pushl	%edi
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%edi, 0)
-	pushl	%esi
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%esi, 0)
-	pushl	%ebx
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%ebx, 0)
-
-	movl	20(%esp), %ebx
-	movl	28(%esp), %ebp
-
-	LIBC_PROBE (cond_timedwait, 3, %ebx, 24(%esp), %ebp)
-
-	cmpl	$1000000000, 4(%ebp)
-	movl	$EINVAL, %eax
-	jae	18f
-
-	/* Stack frame:
-
-	   esp + 32
-		    +--------------------------+
-	   esp + 24 | timeout value            |
-		    +--------------------------+
-	   esp + 20 | futex pointer            |
-		    +--------------------------+
-	   esp + 16 | pi-requeued flag         |
-		    +--------------------------+
-	   esp + 12 | old broadcast_seq value  |
-		    +--------------------------+
-	   esp +  4 | old wake_seq value       |
-		    +--------------------------+
-	   esp +  0 | old cancellation mode    |
-		    +--------------------------+
-	*/
-
-#ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-# ifdef PIC
-	LOAD_PIC_REG (cx)
-	cmpl	$0, __have_futex_clock_realtime@GOTOFF(%ecx)
-# else
-	cmpl	$0, __have_futex_clock_realtime
-# endif
-	je	.Lreltmo
-#endif
-
-	/* Get internal lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-#else
-	cmpxchgl %edx, cond_lock(%ebx)
-#endif
-	jnz	1f
-
-	/* Store the reference to the mutex.  If there is already a
-	   different value in there this is a bad user bug.  */
-2:	cmpl	$-1, dep_mutex(%ebx)
-	movl	24(%esp), %eax
-	je	17f
-	movl	%eax, dep_mutex(%ebx)
-
-	/* Unlock the mutex.  */
-17:	xorl	%edx, %edx
-	call	__pthread_mutex_unlock_usercnt
-
-	testl	%eax, %eax
-	jne	16f
-
-	addl	$1, total_seq(%ebx)
-	adcl	$0, total_seq+4(%ebx)
-	addl	$1, cond_futex(%ebx)
-	addl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-#ifdef __ASSUME_FUTEX_CLOCK_REALTIME
-# define FRAME_SIZE 24
-#else
-# define FRAME_SIZE 32
-#endif
-	subl	$FRAME_SIZE, %esp
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-	cfi_remember_state
-
-	/* Get and store current wakeup_seq value.  */
-	movl	wakeup_seq(%ebx), %edi
-	movl	wakeup_seq+4(%ebx), %edx
-	movl	broadcast_seq(%ebx), %eax
-	movl	%edi, 4(%esp)
-	movl	%edx, 8(%esp)
-	movl	%eax, 12(%esp)
-
-	/* Reset the pi-requeued flag.  */
-	movl	$0, 16(%esp)
-
-	cmpl	$0, (%ebp)
-	movl	$-ETIMEDOUT, %esi
-	js	6f
-
-8:	movl	cond_futex(%ebx), %edi
-	movl	%edi, 20(%esp)
-
-	/* Unlock.  */
-	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	jne	3f
-
-.LcleanupSTART:
-4:	call	__pthread_enable_asynccancel
-	movl	%eax, (%esp)
-
-	leal	(%ebp), %esi
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	sete	%cl
-	je	40f
-
-	movl	dep_mutex(%ebx), %edi
-	/* Requeue to a non-robust PI mutex if the PI bit is set and
-	   the robust bit is not set.  */
-	movl	MUTEX_KIND(%edi), %eax
-	andl	$(ROBUST_BIT|PI_BIT), %eax
-	cmpl	$PI_BIT, %eax
-	jne	40f
-
-	movl	$(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
-	/* The following only works like this because we only support
-	   two clocks, represented using a single bit.  */
-	testl	$1, cond_nwaiters(%ebx)
-	/* XXX Need to implement using sete instead of a jump.  */
-	jne	42f
-	orl	$FUTEX_CLOCK_REALTIME, %ecx
-
-42:	movl	20(%esp), %edx
-	addl	$cond_futex, %ebx
-.Ladd_cond_futex_pi:
-	movl	$SYS_futex, %eax
-	ENTER_KERNEL
-	subl	$cond_futex, %ebx
-.Lsub_cond_futex_pi:
-	movl	%eax, %esi
-	/* Set the pi-requeued flag only if the kernel has returned 0. The
-	   kernel does not hold the mutex on ETIMEDOUT or any other error.  */
-	cmpl	$0, %eax
-	sete	16(%esp)
-	je	41f
-
-	/* When a futex syscall with FUTEX_WAIT_REQUEUE_PI returns
-	   successfully, it has already locked the mutex for us and the
-	   pi_flag (16(%esp)) is set to denote that fact.  However, if another
-	   thread changed the futex value before we entered the wait, the
-	   syscall may return an EAGAIN and the mutex is not locked.  We go
-	   ahead with a success anyway since later we look at the pi_flag to
-	   decide if we got the mutex or not.  The sequence numbers then make
-	   sure that only one of the threads actually wake up.  We retry using
-	   normal FUTEX_WAIT only if the kernel returned ENOSYS, since normal
-	   and PI futexes don't mix.
-
-	   Note that we don't check for EAGAIN specifically; we assume that the
-	   only other error the futex function could return is EAGAIN (barring
-	   the ETIMEOUT of course, for the timeout case in futex) since
-	   anything else would mean an error in our function.  It is too
-	   expensive to do that check for every call (which is  quite common in
-	   case of a large number of threads), so it has been skipped.  */
-	cmpl	$-ENOSYS, %eax
-	jne	41f
-	xorl	%ecx, %ecx
-
-40:	subl	$1, %ecx
-	movl	$0, 16(%esp)
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAIT_BITSET, %ecx
-	/* The following only works like this because we only support
-	   two clocks, represented using a single bit.  */
-	testl	$1, cond_nwaiters(%ebx)
-	jne	30f
-	orl	$FUTEX_CLOCK_REALTIME, %ecx
-30:
-	movl	20(%esp), %edx
-	movl	$0xffffffff, %ebp
-	addl	$cond_futex, %ebx
-.Ladd_cond_futex:
-	movl	$SYS_futex, %eax
-	ENTER_KERNEL
-	subl	$cond_futex, %ebx
-.Lsub_cond_futex:
-	movl	28+FRAME_SIZE(%esp), %ebp
-	movl	%eax, %esi
-
-41:	movl	(%esp), %eax
-	call	__pthread_disable_asynccancel
-.LcleanupEND:
-
-	/* Lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-#else
-	cmpxchgl %edx, cond_lock(%ebx)
-#endif
-	jnz	5f
-
-6:	movl	broadcast_seq(%ebx), %eax
-	cmpl	12(%esp), %eax
-	jne	23f
-
-	movl	woken_seq(%ebx), %eax
-	movl	woken_seq+4(%ebx), %ecx
-
-	movl	wakeup_seq(%ebx), %edi
-	movl	wakeup_seq+4(%ebx), %edx
-
-	cmpl	8(%esp), %edx
-	jne	7f
-	cmpl	4(%esp), %edi
-	je	15f
-
-7:	cmpl	%ecx, %edx
-	jne	9f
-	cmp	%eax, %edi
-	jne	9f
-
-15:	cmpl	$-ETIMEDOUT, %esi
-	je	28f
-
-	/* We need to go back to futex_wait.  If we're using requeue_pi, then
-	   release the mutex we had acquired and go back.  */
-	movl	16(%esp), %edx
-	test	%edx, %edx
-	jz	8b
-
-	/* Adjust the mutex values first and then unlock it.  The unlock
-	   should always succeed or else the kernel did not lock the mutex
-	   correctly.  */
-	movl	dep_mutex(%ebx), %eax
-	call	__pthread_mutex_cond_lock_adjust
-	xorl	%edx, %edx
-	call	__pthread_mutex_unlock_usercnt
-	jmp	8b
-
-28:	addl	$1, wakeup_seq(%ebx)
-	adcl	$0, wakeup_seq+4(%ebx)
-	addl	$1, cond_futex(%ebx)
-	movl	$ETIMEDOUT, %esi
-	jmp	14f
-
-23:	xorl	%esi, %esi
-	jmp	24f
-
-9:	xorl	%esi, %esi
-14:	addl	$1, woken_seq(%ebx)
-	adcl	$0, woken_seq+4(%ebx)
-
-24:	subl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	movl	total_seq(%ebx), %eax
-	andl	total_seq+4(%ebx), %eax
-	cmpl	$0xffffffff, %eax
-	jne	25f
-	movl	cond_nwaiters(%ebx), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	25f
-
-	addl	$cond_nwaiters, %ebx
-	movl	$SYS_futex, %eax
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex-cond_nwaiters(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAKE, %ecx
-	movl	$1, %edx
-	ENTER_KERNEL
-	subl	$cond_nwaiters, %ebx
-
-25:	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	jne	10f
-
-11:	movl	24+FRAME_SIZE(%esp), %eax
-	/* With requeue_pi, the mutex lock is held in the kernel.  */
-	movl	16(%esp), %ecx
-	testl	%ecx, %ecx
-	jnz	27f
-
-	call	__pthread_mutex_cond_lock
-26:	addl	$FRAME_SIZE, %esp
-	cfi_adjust_cfa_offset(-FRAME_SIZE)
-
-	/* We return the result of the mutex_lock operation if it failed.  */
-	testl	%eax, %eax
-#ifdef HAVE_CMOV
-	cmovel	%esi, %eax
-#else
-	jne	22f
-	movl	%esi, %eax
-22:
-#endif
-
-18:	popl	%ebx
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%ebx)
-	popl	%esi
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%esi)
-	popl	%edi
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%edi)
-	popl	%ebp
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%ebp)
-
-	ret
-
-	cfi_restore_state
-
-27:	call	__pthread_mutex_cond_lock_adjust
-	xorl	%eax, %eax
-	jmp	26b
-
-	cfi_adjust_cfa_offset(-FRAME_SIZE);
-	/* Initial locking failed.  */
-1:
-#if cond_lock == 0
-	movl	%ebx, %edx
-#else
-	leal	cond_lock(%ebx), %edx
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_lock_wait
-	jmp	2b
-
-	/* The initial unlocking of the mutex failed.  */
-16:
-	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	jne	18b
-
-	movl	%eax, %esi
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-
-	movl	%esi, %eax
-	jmp	18b
-
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-
-	/* Unlock in loop requires wakeup.  */
-3:
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-	jmp	4b
-
-	/* Locking in loop failed.  */
-5:
-#if cond_lock == 0
-	movl	%ebx, %edx
-#else
-	leal	cond_lock(%ebx), %edx
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_lock_wait
-	jmp	6b
-
-	/* Unlock after loop requires wakeup.  */
-10:
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-	jmp	11b
-
-#ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-	cfi_adjust_cfa_offset(-FRAME_SIZE)
-.Lreltmo:
-	/* Get internal lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-# if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-# else
-	cmpxchgl %edx, cond_lock(%ebx)
-# endif
-	jnz	101f
-
-	/* Store the reference to the mutex.  If there is already a
-	   different value in there this is a bad user bug.  */
-102:	cmpl	$-1, dep_mutex(%ebx)
-	movl	24(%esp), %eax
-	je	117f
-	movl	%eax, dep_mutex(%ebx)
-
-	/* Unlock the mutex.  */
-117:	xorl	%edx, %edx
-	call	__pthread_mutex_unlock_usercnt
-
-	testl	%eax, %eax
-	jne	16b
-
-	addl	$1, total_seq(%ebx)
-	adcl	$0, total_seq+4(%ebx)
-	addl	$1, cond_futex(%ebx)
-	addl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-	subl	$FRAME_SIZE, %esp
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-
-	/* Get and store current wakeup_seq value.  */
-	movl	wakeup_seq(%ebx), %edi
-	movl	wakeup_seq+4(%ebx), %edx
-	movl	broadcast_seq(%ebx), %eax
-	movl	%edi, 4(%esp)
-	movl	%edx, 8(%esp)
-	movl	%eax, 12(%esp)
-
-	/* Reset the pi-requeued flag.  */
-	movl	$0, 16(%esp)
-
-	/* Get the current time.  */
-108:	movl	%ebx, %edx
-# ifdef __NR_clock_gettime
-	/* Get the clock number.  */
-	movl	cond_nwaiters(%ebx), %ebx
-	andl	$((1 << nwaiters_shift) - 1), %ebx
-	/* Only clocks 0 and 1 are allowed so far.  Both are handled in the
-	   kernel.  */
-	leal	24(%esp), %ecx
-	movl	$__NR_clock_gettime, %eax
-	ENTER_KERNEL
-	movl	%edx, %ebx
-
-	/* Compute relative timeout.  */
-	movl	(%ebp), %ecx
-	movl	4(%ebp), %edx
-	subl	24(%esp), %ecx
-	subl	28(%esp), %edx
-# else
-	/* Get the current time.  */
-	leal	24(%esp), %ebx
-	xorl	%ecx, %ecx
-	movl	$__NR_gettimeofday, %eax
-	ENTER_KERNEL
-	movl	%edx, %ebx
-
-	/* Compute relative timeout.  */
-	movl	28(%esp), %eax
-	movl	$1000, %edx
-	mul	%edx		/* Milli seconds to nano seconds.  */
-	movl	(%ebp), %ecx
-	movl	4(%ebp), %edx
-	subl	24(%esp), %ecx
-	subl	%eax, %edx
-# endif
-	jns	112f
-	addl	$1000000000, %edx
-	subl	$1, %ecx
-112:	testl	%ecx, %ecx
-	movl	$-ETIMEDOUT, %esi
-	js	106f
-
-	/* Store relative timeout.  */
-121:	movl	%ecx, 24(%esp)
-	movl	%edx, 28(%esp)
-
-	movl	cond_futex(%ebx), %edi
-	movl	%edi, 20(%esp)
-
-	/* Unlock.  */
-	LOCK
-# if cond_lock == 0
-	subl	$1, (%ebx)
-# else
-	subl	$1, cond_lock(%ebx)
-# endif
-	jne	103f
-
-.LcleanupSTART2:
-104:	call	__pthread_enable_asynccancel
-	movl	%eax, (%esp)
-
-	leal	24(%esp), %esi
-# if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-# endif
-	cmpl	$-1, dep_mutex(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-# ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-# else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-# endif
-# if FUTEX_WAIT != 0
-	addl	$FUTEX_WAIT, %ecx
-# endif
-	movl	20(%esp), %edx
-	addl	$cond_futex, %ebx
-.Ladd_cond_futex2:
-	movl	$SYS_futex, %eax
-	ENTER_KERNEL
-	subl	$cond_futex, %ebx
-.Lsub_cond_futex2:
-	movl	%eax, %esi
-
-141:	movl	(%esp), %eax
-	call	__pthread_disable_asynccancel
-.LcleanupEND2:
-
-
-	/* Lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-# if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-# else
-	cmpxchgl %edx, cond_lock(%ebx)
-# endif
-	jnz	105f
-
-106:	movl	broadcast_seq(%ebx), %eax
-	cmpl	12(%esp), %eax
-	jne	23b
-
-	movl	woken_seq(%ebx), %eax
-	movl	woken_seq+4(%ebx), %ecx
-
-	movl	wakeup_seq(%ebx), %edi
-	movl	wakeup_seq+4(%ebx), %edx
-
-	cmpl	8(%esp), %edx
-	jne	107f
-	cmpl	4(%esp), %edi
-	je	115f
-
-107:	cmpl	%ecx, %edx
-	jne	9b
-	cmp	%eax, %edi
-	jne	9b
-
-115:	cmpl	$-ETIMEDOUT, %esi
-	je	28b
-
-	jmp	8b
-
-	cfi_adjust_cfa_offset(-FRAME_SIZE)
-	/* Initial locking failed.  */
-101:
-# if cond_lock == 0
-	movl	%ebx, %edx
-# else
-	leal	cond_lock(%ebx), %edx
-# endif
-# if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-# endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-# if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-# endif
-	call	__lll_lock_wait
-	jmp	102b
-
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-
-	/* Unlock in loop requires wakeup.  */
-103:
-# if cond_lock == 0
-	movl	%ebx, %eax
-# else
-	leal	cond_lock(%ebx), %eax
-# endif
-# if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-# endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-# if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-# endif
-	call	__lll_unlock_wake
-	jmp	104b
-
-	/* Locking in loop failed.  */
-105:
-# if cond_lock == 0
-	movl	%ebx, %edx
-# else
-	leal	cond_lock(%ebx), %edx
-# endif
-# if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-# endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-# if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-# endif
-	call	__lll_lock_wait
-	jmp	106b
-#endif
-
-	.size	__pthread_cond_timedwait, .-__pthread_cond_timedwait
-versioned_symbol (libpthread, __pthread_cond_timedwait, pthread_cond_timedwait,
-		  GLIBC_2_3_2)
-
-
-	.type	__condvar_tw_cleanup2, @function
-__condvar_tw_cleanup2:
-	subl	$cond_futex, %ebx
-	.size	__condvar_tw_cleanup2, .-__condvar_tw_cleanup2
-	.type	__condvar_tw_cleanup, @function
-__condvar_tw_cleanup:
-	movl	%eax, %esi
-
-	/* Get internal lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-#else
-	cmpxchgl %edx, cond_lock(%ebx)
-#endif
-	jz	1f
-
-#if cond_lock == 0
-	movl	%ebx, %edx
-#else
-	leal	cond_lock(%ebx), %edx
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_lock_wait
-
-1:	movl	broadcast_seq(%ebx), %eax
-	cmpl	12(%esp), %eax
-	jne	3f
-
-	/* We increment the wakeup_seq counter only if it is lower than
-	   total_seq.  If this is not the case the thread was woken and
-	   then canceled.  In this case we ignore the signal.  */
-	movl	total_seq(%ebx), %eax
-	movl	total_seq+4(%ebx), %edi
-	cmpl	wakeup_seq+4(%ebx), %edi
-	jb	6f
-	ja	7f
-	cmpl	wakeup_seq(%ebx), %eax
-	jbe	7f
-
-6:	addl	$1, wakeup_seq(%ebx)
-	adcl	$0, wakeup_seq+4(%ebx)
-	addl	$1, cond_futex(%ebx)
-
-7:	addl	$1, woken_seq(%ebx)
-	adcl	$0, woken_seq+4(%ebx)
-
-3:	subl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	xorl	%edi, %edi
-	movl	total_seq(%ebx), %eax
-	andl	total_seq+4(%ebx), %eax
-	cmpl	$0xffffffff, %eax
-	jne	4f
-	movl	cond_nwaiters(%ebx), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	4f
-
-	addl	$cond_nwaiters, %ebx
-	movl	$SYS_futex, %eax
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex-cond_nwaiters(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAKE, %ecx
-	movl	$1, %edx
-	ENTER_KERNEL
-	subl	$cond_nwaiters, %ebx
-	movl	$1, %edi
-
-4:	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	je	2f
-
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-
-	/* Wake up all waiters to make sure no signal gets lost.  */
-2:	testl	%edi, %edi
-	jnz	5f
-	addl	$cond_futex, %ebx
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex-cond_futex(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAKE, %ecx
-	movl	$SYS_futex, %eax
-	movl	$0x7fffffff, %edx
-	ENTER_KERNEL
-
-	/* Lock the mutex only if we don't own it already.  This only happens
-	   in case of PI mutexes, if we got cancelled after a successful
-	   return of the futex syscall and before disabling async
-	   cancellation.  */
-5:	movl	24+FRAME_SIZE(%esp), %eax
-	movl	MUTEX_KIND(%eax), %ebx
-	andl	$(ROBUST_BIT|PI_BIT), %ebx
-	cmpl	$PI_BIT, %ebx
-	jne	8f
-
-	movl	(%eax), %ebx
-	andl	$TID_MASK, %ebx
-	cmpl	%ebx, %gs:TID
-	jne	8f
-	/* We managed to get the lock.  Fix it up before returning.  */
-	call	__pthread_mutex_cond_lock_adjust
-	jmp	9f
-
-8:	call	__pthread_mutex_cond_lock
-
-9:	movl	%esi, (%esp)
-.LcallUR:
-	call	_Unwind_Resume
-	hlt
-.LENDCODE:
-	cfi_endproc
-	.size	__condvar_tw_cleanup, .-__condvar_tw_cleanup
-
-
-	.section .gcc_except_table,"a",@progbits
-.LexceptSTART:
-	.byte	DW_EH_PE_omit			# @LPStart format (omit)
-	.byte	DW_EH_PE_omit			# @TType format (omit)
-	.byte	DW_EH_PE_sdata4			# call-site format
-						# DW_EH_PE_sdata4
-	.uleb128 .Lcstend-.Lcstbegin
-.Lcstbegin:
-	.long	.LcleanupSTART-.LSTARTCODE
-	.long	.Ladd_cond_futex_pi-.LcleanupSTART
-	.long	__condvar_tw_cleanup-.LSTARTCODE
-	.uleb128  0
-	.long	.Ladd_cond_futex_pi-.LSTARTCODE
-	.long	.Lsub_cond_futex_pi-.Ladd_cond_futex_pi
-	.long	__condvar_tw_cleanup2-.LSTARTCODE
-	.uleb128  0
-	.long	.Lsub_cond_futex_pi-.LSTARTCODE
-	.long	.Ladd_cond_futex-.Lsub_cond_futex_pi
-	.long	__condvar_tw_cleanup-.LSTARTCODE
-	.uleb128  0
-	.long	.Ladd_cond_futex-.LSTARTCODE
-	.long	.Lsub_cond_futex-.Ladd_cond_futex
-	.long	__condvar_tw_cleanup2-.LSTARTCODE
-	.uleb128  0
-	.long	.Lsub_cond_futex-.LSTARTCODE
-	.long	.LcleanupEND-.Lsub_cond_futex
-	.long	__condvar_tw_cleanup-.LSTARTCODE
-	.uleb128  0
-#ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-	.long	.LcleanupSTART2-.LSTARTCODE
-	.long	.Ladd_cond_futex2-.LcleanupSTART2
-	.long	__condvar_tw_cleanup-.LSTARTCODE
-	.uleb128  0
-	.long	.Ladd_cond_futex2-.LSTARTCODE
-	.long	.Lsub_cond_futex2-.Ladd_cond_futex2
-	.long	__condvar_tw_cleanup2-.LSTARTCODE
-	.uleb128  0
-	.long	.Lsub_cond_futex2-.LSTARTCODE
-	.long	.LcleanupEND2-.Lsub_cond_futex2
-	.long	__condvar_tw_cleanup-.LSTARTCODE
-	.uleb128  0
-#endif
-	.long	.LcallUR-.LSTARTCODE
-	.long	.LENDCODE-.LcallUR
-	.long	0
-	.uleb128  0
-.Lcstend:
-
-
-#ifdef SHARED
-	.hidden DW.ref.__gcc_personality_v0
-	.weak	DW.ref.__gcc_personality_v0
-	.section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
-	.align	4
-	.type	DW.ref.__gcc_personality_v0, @object
-	.size	DW.ref.__gcc_personality_v0, 4
-DW.ref.__gcc_personality_v0:
-	.long   __gcc_personality_v0
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S b/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
deleted file mode 100644
index ec3538f..0000000
--- a/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S
+++ /dev/null
@@ -1,641 +0,0 @@
-/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   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>
-#include <shlib-compat.h>
-#include <lowlevellock.h>
-#include <lowlevelcond.h>
-#include <tcb-offsets.h>
-#include <pthread-errnos.h>
-#include <pthread-pi-defines.h>
-#include <kernel-features.h>
-#include <stap-probe.h>
-
-
-	.text
-
-/* int pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)  */
-	.globl	__pthread_cond_wait
-	.type	__pthread_cond_wait, @function
-	.align	16
-__pthread_cond_wait:
-.LSTARTCODE:
-	cfi_startproc
-#ifdef SHARED
-	cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
-			DW.ref.__gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
-#else
-	cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
-	cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
-#endif
-
-	pushl	%ebp
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%ebp, 0)
-	pushl	%edi
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%edi, 0)
-	pushl	%esi
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%esi, 0)
-	pushl	%ebx
-	cfi_adjust_cfa_offset(4)
-	cfi_rel_offset(%ebx, 0)
-
-	xorl	%esi, %esi
-	movl	20(%esp), %ebx
-
-	LIBC_PROBE (cond_wait, 2, 24(%esp), %ebx)
-
-	/* Get internal lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-#else
-	cmpxchgl %edx, cond_lock(%ebx)
-#endif
-	jnz	1f
-
-	/* Store the reference to the mutex.  If there is already a
-	   different value in there this is a bad user bug.  */
-2:	cmpl	$-1, dep_mutex(%ebx)
-	movl	24(%esp), %eax
-	je	15f
-	movl	%eax, dep_mutex(%ebx)
-
-	/* Unlock the mutex.  */
-15:	xorl	%edx, %edx
-	call	__pthread_mutex_unlock_usercnt
-
-	testl	%eax, %eax
-	jne	12f
-
-	addl	$1, total_seq(%ebx)
-	adcl	$0, total_seq+4(%ebx)
-	addl	$1, cond_futex(%ebx)
-	addl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-#define FRAME_SIZE 20
-	subl	$FRAME_SIZE, %esp
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-	cfi_remember_state
-
-	/* Get and store current wakeup_seq value.  */
-	movl	wakeup_seq(%ebx), %edi
-	movl	wakeup_seq+4(%ebx), %edx
-	movl	broadcast_seq(%ebx), %eax
-	movl	%edi, 4(%esp)
-	movl	%edx, 8(%esp)
-	movl	%eax, 12(%esp)
-
-	/* Reset the pi-requeued flag.  */
-8:	movl	$0, 16(%esp)
-	movl	cond_futex(%ebx), %ebp
-
-	/* Unlock.  */
-	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	jne	3f
-
-.LcleanupSTART:
-4:	call	__pthread_enable_asynccancel
-	movl	%eax, (%esp)
-
-	xorl	%ecx, %ecx
-	cmpl	$-1, dep_mutex(%ebx)
-	sete	%cl
-	je	18f
-
-	movl	dep_mutex(%ebx), %edi
-	/* Requeue to a non-robust PI mutex if the PI bit is set and
-	   the robust bit is not set.  */
-	movl	MUTEX_KIND(%edi), %eax
-	andl	$(ROBUST_BIT|PI_BIT), %eax
-	cmpl	$PI_BIT, %eax
-	jne	18f
-
-	movl	$(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %ecx
-	movl	%ebp, %edx
-	xorl	%esi, %esi
-	addl	$cond_futex, %ebx
-.Ladd_cond_futex_pi:
-	movl	$SYS_futex, %eax
-	ENTER_KERNEL
-	subl	$cond_futex, %ebx
-.Lsub_cond_futex_pi:
-	/* Set the pi-requeued flag only if the kernel has returned 0. The
-	   kernel does not hold the mutex on error.  */
-	cmpl	$0, %eax
-	sete	16(%esp)
-	je	19f
-
-	/* When a futex syscall with FUTEX_WAIT_REQUEUE_PI returns
-	   successfully, it has already locked the mutex for us and the
-	   pi_flag (16(%esp)) is set to denote that fact.  However, if another
-	   thread changed the futex value before we entered the wait, the
-	   syscall may return an EAGAIN and the mutex is not locked.  We go
-	   ahead with a success anyway since later we look at the pi_flag to
-	   decide if we got the mutex or not.  The sequence numbers then make
-	   sure that only one of the threads actually wake up.  We retry using
-	   normal FUTEX_WAIT only if the kernel returned ENOSYS, since normal
-	   and PI futexes don't mix.
-
-	   Note that we don't check for EAGAIN specifically; we assume that the
-	   only other error the futex function could return is EAGAIN since
-	   anything else would mean an error in our function.  It is too
-	   expensive to do that check for every call (which is 	quite common in
-	   case of a large number of threads), so it has been skipped.  */
-	cmpl	$-ENOSYS, %eax
-	jne	19f
-	xorl	%ecx, %ecx
-
-18:	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-#if FUTEX_WAIT != 0
-	addl	$FUTEX_WAIT, %ecx
-#endif
-	movl	%ebp, %edx
-	addl	$cond_futex, %ebx
-.Ladd_cond_futex:
-	movl	$SYS_futex, %eax
-	ENTER_KERNEL
-	subl	$cond_futex, %ebx
-.Lsub_cond_futex:
-
-19:	movl	(%esp), %eax
-	call	__pthread_disable_asynccancel
-.LcleanupEND:
-
-	/* Lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-#else
-	cmpxchgl %edx, cond_lock(%ebx)
-#endif
-	jnz	5f
-
-6:	movl	broadcast_seq(%ebx), %eax
-	cmpl	12(%esp), %eax
-	jne	16f
-
-	movl	woken_seq(%ebx), %eax
-	movl	woken_seq+4(%ebx), %ecx
-
-	movl	wakeup_seq(%ebx), %edi
-	movl	wakeup_seq+4(%ebx), %edx
-
-	cmpl	8(%esp), %edx
-	jne	7f
-	cmpl	4(%esp), %edi
-	je	22f
-
-7:	cmpl	%ecx, %edx
-	jne	9f
-	cmp	%eax, %edi
-	je	22f
-
-9:	addl	$1, woken_seq(%ebx)
-	adcl	$0, woken_seq+4(%ebx)
-
-	/* Unlock */
-16:	subl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	movl	total_seq(%ebx), %eax
-	andl	total_seq+4(%ebx), %eax
-	cmpl	$0xffffffff, %eax
-	jne	17f
-	movl	cond_nwaiters(%ebx), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	17f
-
-	addl	$cond_nwaiters, %ebx
-	movl	$SYS_futex, %eax
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex-cond_nwaiters(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAKE, %ecx
-	movl	$1, %edx
-	ENTER_KERNEL
-	subl	$cond_nwaiters, %ebx
-
-17:	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	jne	10f
-
-	/* With requeue_pi, the mutex lock is held in the kernel.  */
-11:	movl	24+FRAME_SIZE(%esp), %eax
-	movl	16(%esp), %ecx
-	testl	%ecx, %ecx
-	jnz	21f
-
-	call	__pthread_mutex_cond_lock
-20:	addl	$FRAME_SIZE, %esp
-	cfi_adjust_cfa_offset(-FRAME_SIZE);
-
-14:	popl	%ebx
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%ebx)
-	popl	%esi
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%esi)
-	popl	%edi
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%edi)
-	popl	%ebp
-	cfi_adjust_cfa_offset(-4)
-	cfi_restore(%ebp)
-
-	/* We return the result of the mutex_lock operation.  */
-	ret
-
-	cfi_restore_state
-
-21:	call	__pthread_mutex_cond_lock_adjust
-	xorl	%eax, %eax
-	jmp	20b
-
-	cfi_adjust_cfa_offset(-FRAME_SIZE);
-
-	/* We need to go back to futex_wait.  If we're using requeue_pi, then
-	   release the mutex we had acquired and go back.  */
-22:	movl	16(%esp), %edx
-	test	%edx, %edx
-	jz	8b
-
-	/* Adjust the mutex values first and then unlock it.  The unlock
-	   should always succeed or else the kernel did not lock the mutex
-	   correctly.  */
-	movl	dep_mutex(%ebx), %eax
-	call    __pthread_mutex_cond_lock_adjust
-	xorl	%edx, %edx
-	call	__pthread_mutex_unlock_usercnt
-	jmp	8b
-
-	/* Initial locking failed.  */
-1:
-#if cond_lock == 0
-	movl	%ebx, %edx
-#else
-	leal	cond_lock(%ebx), %edx
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_lock_wait
-	jmp	2b
-
-	/* The initial unlocking of the mutex failed.  */
-12:
-	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	jne	14b
-
-	movl	%eax, %esi
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-
-	movl	%esi, %eax
-	jmp	14b
-
-	cfi_adjust_cfa_offset(FRAME_SIZE)
-
-	/* Unlock in loop requires wakeup.  */
-3:
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-	jmp	4b
-
-	/* Locking in loop failed.  */
-5:
-#if cond_lock == 0
-	movl	%ebx, %edx
-#else
-	leal	cond_lock(%ebx), %edx
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_lock_wait
-	jmp	6b
-
-	/* Unlock after loop requires wakeup.  */
-10:
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-	jmp	11b
-
-	.size	__pthread_cond_wait, .-__pthread_cond_wait
-versioned_symbol (libpthread, __pthread_cond_wait, pthread_cond_wait,
-		  GLIBC_2_3_2)
-
-
-	.type	__condvar_w_cleanup2, @function
-__condvar_w_cleanup2:
-	subl	$cond_futex, %ebx
-	.size	__condvar_w_cleanup2, .-__condvar_w_cleanup2
-.LSbl4:
-	.type	__condvar_w_cleanup, @function
-__condvar_w_cleanup:
-	movl	%eax, %esi
-
-	/* Get internal lock.  */
-	movl	$1, %edx
-	xorl	%eax, %eax
-	LOCK
-#if cond_lock == 0
-	cmpxchgl %edx, (%ebx)
-#else
-	cmpxchgl %edx, cond_lock(%ebx)
-#endif
-	jz	1f
-
-#if cond_lock == 0
-	movl	%ebx, %edx
-#else
-	leal	cond_lock(%ebx), %edx
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_lock_wait
-
-1:	movl	broadcast_seq(%ebx), %eax
-	cmpl	12(%esp), %eax
-	jne	3f
-
-	/* We increment the wakeup_seq counter only if it is lower than
-	   total_seq.  If this is not the case the thread was woken and
-	   then canceled.  In this case we ignore the signal.  */
-	movl	total_seq(%ebx), %eax
-	movl	total_seq+4(%ebx), %edi
-	cmpl	wakeup_seq+4(%ebx), %edi
-	jb	6f
-	ja	7f
-	cmpl	wakeup_seq(%ebx), %eax
-	jbe	7f
-
-6:	addl	$1, wakeup_seq(%ebx)
-	adcl	$0, wakeup_seq+4(%ebx)
-	addl	$1, cond_futex(%ebx)
-
-7:	addl	$1, woken_seq(%ebx)
-	adcl	$0, woken_seq+4(%ebx)
-
-3:	subl	$(1 << nwaiters_shift), cond_nwaiters(%ebx)
-
-	/* Wake up a thread which wants to destroy the condvar object.  */
-	xorl	%edi, %edi
-	movl	total_seq(%ebx), %eax
-	andl	total_seq+4(%ebx), %eax
-	cmpl	$0xffffffff, %eax
-	jne	4f
-	movl	cond_nwaiters(%ebx), %eax
-	andl	$~((1 << nwaiters_shift) - 1), %eax
-	jne	4f
-
-	addl	$cond_nwaiters, %ebx
-	movl	$SYS_futex, %eax
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex-cond_nwaiters(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAKE, %ecx
-	movl	$1, %edx
-	ENTER_KERNEL
-	subl	$cond_nwaiters, %ebx
-	movl	$1, %edi
-
-4:	LOCK
-#if cond_lock == 0
-	subl	$1, (%ebx)
-#else
-	subl	$1, cond_lock(%ebx)
-#endif
-	je	2f
-
-#if cond_lock == 0
-	movl	%ebx, %eax
-#else
-	leal	cond_lock(%ebx), %eax
-#endif
-#if (LLL_SHARED-LLL_PRIVATE) > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex(%ebx)
-	setne	%cl
-	subl	$1, %ecx
-	andl	$(LLL_SHARED-LLL_PRIVATE), %ecx
-#if LLL_PRIVATE != 0
-	addl	$LLL_PRIVATE, %ecx
-#endif
-	call	__lll_unlock_wake
-
-	/* Wake up all waiters to make sure no signal gets lost.  */
-2:	testl	%edi, %edi
-	jnz	5f
-	addl	$cond_futex, %ebx
-#if FUTEX_PRIVATE_FLAG > 255
-	xorl	%ecx, %ecx
-#endif
-	cmpl	$-1, dep_mutex-cond_futex(%ebx)
-	sete	%cl
-	subl	$1, %ecx
-#ifdef __ASSUME_PRIVATE_FUTEX
-	andl	$FUTEX_PRIVATE_FLAG, %ecx
-#else
-	andl	%gs:PRIVATE_FUTEX, %ecx
-#endif
-	addl	$FUTEX_WAKE, %ecx
-	movl	$SYS_futex, %eax
-	movl	$0x7fffffff, %edx
-	ENTER_KERNEL
-
-	/* Lock the mutex only if we don't own it already.  This only happens
-	   in case of PI mutexes, if we got cancelled after a successful
-	   return of the futex syscall and before disabling async
-	   cancellation.  */
-5:	movl	24+FRAME_SIZE(%esp), %eax
-	movl	MUTEX_KIND(%eax), %ebx
-	andl	$(ROBUST_BIT|PI_BIT), %ebx
-	cmpl	$PI_BIT, %ebx
-	jne	8f
-
-	movl	(%eax), %ebx
-	andl	$TID_MASK, %ebx
-	cmpl	%ebx, %gs:TID
-	jne	8f
-	/* We managed to get the lock.  Fix it up before returning.  */
-	call	__pthread_mutex_cond_lock_adjust
-	jmp	9f
-
-8:	call	__pthread_mutex_cond_lock
-
-9:	movl	%esi, (%esp)
-.LcallUR:
-	call	_Unwind_Resume
-	hlt
-.LENDCODE:
-	cfi_endproc
-	.size	__condvar_w_cleanup, .-__condvar_w_cleanup
-
-
-	.section .gcc_except_table,"a",@progbits
-.LexceptSTART:
-	.byte	DW_EH_PE_omit			# @LPStart format (omit)
-	.byte	DW_EH_PE_omit			# @TType format (omit)
-	.byte	DW_EH_PE_sdata4			# call-site format
-						# DW_EH_PE_sdata4
-	.uleb128 .Lcstend-.Lcstbegin
-.Lcstbegin:
-	.long	.LcleanupSTART-.LSTARTCODE
-	.long	.Ladd_cond_futex_pi-.LcleanupSTART
-	.long	__condvar_w_cleanup-.LSTARTCODE
-	.uleb128  0
-	.long	.Ladd_cond_futex_pi-.LSTARTCODE
-	.long	.Lsub_cond_futex_pi-.Ladd_cond_futex_pi
-	.long	__condvar_w_cleanup2-.LSTARTCODE
-	.uleb128  0
-	.long	.Lsub_cond_futex_pi-.LSTARTCODE
-	.long	.Ladd_cond_futex-.Lsub_cond_futex_pi
-	.long	__condvar_w_cleanup-.LSTARTCODE
-	.uleb128  0
-	.long	.Ladd_cond_futex-.LSTARTCODE
-	.long	.Lsub_cond_futex-.Ladd_cond_futex
-	.long	__condvar_w_cleanup2-.LSTARTCODE
-	.uleb128  0
-	.long	.Lsub_cond_futex-.LSTARTCODE
-	.long	.LcleanupEND-.Lsub_cond_futex
-	.long	__condvar_w_cleanup-.LSTARTCODE
-	.uleb128  0
-	.long	.LcallUR-.LSTARTCODE
-	.long	.LENDCODE-.LcallUR
-	.long	0
-	.uleb128  0
-.Lcstend:
-
-#ifdef SHARED
-	.hidden DW.ref.__gcc_personality_v0
-	.weak   DW.ref.__gcc_personality_v0
-	.section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
-	.align 4
-	.type   DW.ref.__gcc_personality_v0, @object
-	.size   DW.ref.__gcc_personality_v0, 4
-DW.ref.__gcc_personality_v0:
-	.long   __gcc_personality_v0
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S b/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S
deleted file mode 100644
index d96af08..0000000
--- a/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_timedwait.S
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (C) 2003-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
-
-   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 "../i486/pthread_cond_timedwait.S"
diff --git a/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S b/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S
deleted file mode 100644
index 9696972..0000000
--- a/sysdeps/unix/sysv/linux/i386/i586/pthread_cond_wait.S
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (C) 2003-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
-
-   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 "../i486/pthread_cond_wait.S"
diff --git a/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S b/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S
deleted file mode 100644
index 0e8d7ff..0000000
--- a/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_timedwait.S
+++ /dev/null
@@ -1,20 +0,0 @@
-/* Copyright (C) 2003-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
-
-   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/>.  */
-
-#define HAVE_CMOV 1
-#include "../i486/pthread_cond_timedwait.S"
diff --git a/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S b/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S
deleted file mode 100644
index 9696972..0000000
--- a/sysdeps/unix/sysv/linux/i386/i686/pthread_cond_wait.S
+++ /dev/null
@@ -1,19 +0,0 @@
-/* Copyright (C) 2003-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
-
-   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 "../i486/pthread_cond_wait.S"

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=0bda2dfd7c8bc23f73bbc5b6bd33ae2f053432c0

commit 0bda2dfd7c8bc23f73bbc5b6bd33ae2f053432c0
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Thu Apr 30 17:09:28 2015 -0300

    Remove socket.S implementation
    
    This patch removes the socket.S implementation for all ports and replace
    it by a C implementation using socketcall.  For ports that implement
    the syscall directly, there is no change.
    
    The patch idea is to simplify the socket function implementation that
    uses the socketcall to be based on C implemetation instead of a pseudo
    assembly implementation with arch specific parts.  All the affect
    architectures (i386, microblaze, mips, powerpc, and sparc) have support
    for 6 argument syscalls.
    
    I have cross-build GLIBC for afore-mentioned ports and tested on both
    i386 and ppc32 without regressions.

diff --git a/ChangeLog b/ChangeLog
index 528e575..4719e8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,80 @@
 2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/unix/sysv/linux/socketcall.h (SOCKOP_invalid): Define.
+	(SOCKETCALL): New macro: non-cancellable socketcall.
+	(SOCKETCALL_CANCEL): New macro: cancellable socketcall.
+	* sysdeps/unix/sysv/linux/Makefile [$(subdir) = socket]: Remove
+	internal_accept4, internal_recvmmsg, and internal_sendmmsg rules.
+	* sysdeps/unix/sysv/linux/accept.c: New file.
+	* sysdeps/unix/sysv/linux/bind.c: Likewise.
+	* sysdeps/unix/sysv/linux/connect.c: Likewise.
+	* sysdeps/unix/sysv/linux/getpeername.c: Likewise.
+	* sysdeps/unix/sysv/linux/getsockname.c: Likewise.
+	* sysdeps/unix/sysv/linux/getsockopt.c: Likewise.
+	* sysdeps/unix/sysv/linux/listen.c: Likewise.
+	* sysdeps/unix/sysv/linux/recv.c: Likewise.
+	* sysdeps/unix/sysv/linux/recvfrom.c: Likewise.
+	* sysdeps/unix/sysv/linux/recvmsg.c: Likewise.
+	* sysdeps/unix/sysv/linux/send.c: Likewise.
+	* sysdeps/unix/sysv/linux/sendmsg.c: Likewise.
+	* sysdeps/unix/sysv/linux/sendto.c: Likewise.
+	* sysdeps/unix/sysv/linux/setsockopt.c: Likewise.
+	* sysdeps/unix/sysv/linux/shutdown.c: Likewise.
+	* sysdeps/unix/sysv/linux/socket.c: Likewise.
+	* sysdeps/unix/sysv/linux/socketpair.c: Likewise.
+	* sysdeps/unix/sysv/linux/recvmmsg.c (__internal_recvmmsg): Remove
+	prototype.
+	(recvmmsg) [__ASSUME_RECVMMSG_SOCKETCALL]: Add C based implementation.
+	(recvmmsg) [!__ASSUME_RECVMMSG_SOCKETCALL]: Use SOCKETCALL_CANCEL macro
+	instead of __internal_xxx function.
+	* sysdeps/unix/sysv/linux/accept4.c (__internal_accept4): Remove
+	prototype.
+	(accept4) [__ASSUME_ACCEPT4_SOCKETCALL]: Add C based implementation.
+	(accept4) [!__ASSUME_ACCEPT4_SOCKETCALL]: Use SOCKETCALL_CANCEL macro
+	instead of __internal_xxx function.
+	* sysdeps/unix/sysv/linux/sendmmsg.c (__internal_sendmmsg): Remove
+	prototype.
+	(sendmmsg) [__ASSUME_SENDMMSG_SOCKETCALL]: Add C based implementation.
+	(sendmmsg) [!__ASSUME_SENDMMSG_SOCKETCALL]: Use SOCKETCALL_CANCEL macro
+	instead of __internal_xxx function.
+	* sysdeps/unix/sysv/linux/accept.S: Remove file.
+	* sysdeps/unix/sysv/linux/bind.S: Likewise.
+	* sysdeps/unix/sysv/linux/connect.S: Likewise.
+	* sysdeps/unix/sysv/linux/getpeername.S: Likewise.
+	* sysdeps/unix/sysv/linux/getsockname.S: Likewise.
+	* sysdeps/unix/sysv/linux/getsockopt.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/accept4.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/internal_accept4.S: Likewise.
+	* sysdeps/unix/sysv/linux/i386/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/internal_accept4.S: Likewise.
+	* sysdeps/unix/sysv/linux/internal_recvmmsg.S: Likewise.
+	* sysdeps/unix/sysv/linux/internal_sendmmsg.S: Likewise.
+	* sysdeps/unix/sysv/linux/listen.S: Likewise.
+	* sysdeps/unix/sysv/linux/microblaze/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips32/internal_accept4.S: Likewise.
+	* sysdeps/sysv/linux/mips/mips32/internal_recvmmsg.S: Likewise.
+	* sysdeps/sysv/linux/mips/mips32/internal_sendmmsg.S: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/recv.S: Likewise.
+	* sysdeps/unix/sysv/linux/recvfrom.S: Likewise.
+	* sysdeps/unix/sysv/linux/recvmsg.S: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-64/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/send.S: Likewise.
+	* sysdeps/unix/sysv/linux/sendmsg.S: Likewise.
+	* sysdeps/unix/sysv/linux/sendto.S: Likewise.
+	* sysdeps/unix/sysv/linux/setsockopt.S: Likewise.
+	* sysdeps/unix/sysv/linux/sh/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/shutdown.S: Likewise.
+	* sysdeps/unix/sysv/linux/socketpair.S: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/socket.S: Likewise.
+	* sysdeps/unix/sysv/linux/kernel-features.h: Adjust comment on how
+	socketcall is implemented in GLIBC.
+	* sysdeps/unix/sysv/linux/malloc-sysdep.h (check_may_shrink_heap):
+	Initialize val variable.
+
 	* sysdeps/unix/sysv/linux/not-cancel.h (open_not_cancel): Rewrite to
 	be an inline implementation regardless of library is built within.
 	(open_not_cancel_2): Likewise.
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index c26a12f..bfbabd4 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -11,10 +11,6 @@ ifeq ($(subdir),malloc)
 CFLAGS-malloc.c += -DMORECORE_CLEARS=2
 endif
 
-ifeq ($(subdir),socket)
-sysdep_routines += internal_accept4 internal_recvmmsg internal_sendmmsg
-endif
-
 ifeq ($(subdir),misc)
 include $(firstword $(wildcard $(sysdirs:=/sysctl.mk)))
 
diff --git a/sysdeps/unix/sysv/linux/accept.S b/sysdeps/unix/sysv/linux/accept.S
deleted file mode 100644
index 491ebe2..0000000
--- a/sysdeps/unix/sysv/linux/accept.S
+++ /dev/null
@@ -1,6 +0,0 @@
-#define	socket	accept
-#define	__socket __libc_accept
-#define	NARGS	3
-#define NEED_CANCELLATION
-#include <socket.S>
-libc_hidden_def (accept)
diff --git a/sysdeps/unix/sysv/linux/accept.c b/sysdeps/unix/sysv/linux/accept.c
new file mode 100644
index 0000000..ddf2065
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/accept.c
@@ -0,0 +1,31 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+int
+__libc_accept (int fd, __SOCKADDR_ARG addr, socklen_t *len)
+{
+  return SOCKETCALL_CANCEL (accept, fd, addr.__sockaddr__, len, 0, 0, 0);
+}
+weak_alias (__libc_accept, accept)
+libc_hidden_def (accept)
diff --git a/sysdeps/unix/sysv/linux/accept4.c b/sysdeps/unix/sysv/linux/accept4.c
index 5dbcef3..8e70b81 100644
--- a/sysdeps/unix/sysv/linux/accept4.c
+++ b/sysdeps/unix/sysv/linux/accept4.c
@@ -50,11 +50,15 @@ accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
   return result;
 }
 #elif defined __NR_socketcall
-# ifndef __ASSUME_ACCEPT4_SOCKETCALL
-extern int __internal_accept4 (int fd, __SOCKADDR_ARG addr,
-			       socklen_t *addr_len, int flags)
-     attribute_hidden;
-
+# include <socketcall.h>
+# ifdef __ASSUME_ACCEPT4_SOCKETCALL
+int
+accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
+{
+  return SOCKETCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len, flags,
+			    0, 0);
+}
+# else
 static int have_accept4;
 
 int
@@ -62,7 +66,8 @@ accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
 {
   if (__glibc_likely (have_accept4 >= 0))
     {
-      int ret = __internal_accept4 (fd, addr, addr_len, flags);
+      int ret = SOCKETCALL_CANCEL (accept4, fd, addr.__sockaddr__, addr_len,
+				   flags, 0, 0);
       /* The kernel returns -EINVAL for unknown socket operations.
 	 We need to convert that error to an ENOSYS error.  */
       if (__builtin_expect (ret < 0, 0)
@@ -72,7 +77,8 @@ accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
 	  /* Try another call, this time with the FLAGS parameter
 	     cleared and an invalid file descriptor.  This call will not
 	     cause any harm and it will return immediately.  */
-	  ret = __internal_accept4 (-1, addr, addr_len, 0);
+	  ret = SOCKETCALL_CANCEL (invalid, addr.__sockaddr__, addr_len, 0,
+				   0, 0, 0);
 	  if (errno == EINVAL)
 	    {
 	      have_accept4 = -1;
@@ -90,11 +96,8 @@ accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
   __set_errno (ENOSYS);
   return -1;
 }
-# else
-/* When __ASSUME_ACCEPT4_SOCKETCALL accept4 is defined in
-   internal_accept4.S.  */
-# endif
-#else
+# endif /* __ASSUME_ACCEPT4_SOCKETCALL  */
+#else /* __NR_socketcall   */
 int
 accept4 (int fd, __SOCKADDR_ARG addr, socklen_t *addr_len, int flags)
 {
diff --git a/sysdeps/unix/sysv/linux/bind.S b/sysdeps/unix/sysv/linux/bind.S
deleted file mode 100644
index 61fb5eb..0000000
--- a/sysdeps/unix/sysv/linux/bind.S
+++ /dev/null
@@ -1,3 +0,0 @@
-#define	socket	bind
-#define	NARGS	3
-#include <socket.S>
diff --git a/sysdeps/unix/sysv/linux/bind.c b/sysdeps/unix/sysv/linux/bind.c
new file mode 100644
index 0000000..db72df6
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/bind.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
+{
+  return SOCKETCALL (bind, fd, addr.__sockaddr__, len, 0, 0, 0);
+}
+weak_alias (__bind, bind)
diff --git a/sysdeps/unix/sysv/linux/connect.S b/sysdeps/unix/sysv/linux/connect.S
deleted file mode 100644
index 21fc4a6..0000000
--- a/sysdeps/unix/sysv/linux/connect.S
+++ /dev/null
@@ -1,7 +0,0 @@
-#define	socket	connect
-#define __socket __libc_connect
-#define	NARGS	3
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_connect, __connect)
-libc_hidden_weak (__connect)
diff --git a/sysdeps/unix/sysv/linux/connect.c b/sysdeps/unix/sysv/linux/connect.c
new file mode 100644
index 0000000..8ed0963
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/connect.c
@@ -0,0 +1,32 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+int
+__libc_connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
+{
+  return SOCKETCALL_CANCEL (connect, fd, addr.__sockaddr__, len,  0, 0, 0);
+}
+weak_alias (__libc_connect, connect)
+weak_alias (__libc_connect, __connect)
+libc_hidden_weak (__connect)
diff --git a/sysdeps/unix/sysv/linux/getpeername.S b/sysdeps/unix/sysv/linux/getpeername.S
deleted file mode 100644
index a6d8e86..0000000
--- a/sysdeps/unix/sysv/linux/getpeername.S
+++ /dev/null
@@ -1,3 +0,0 @@
-#define	socket	getpeername
-#define	NARGS	3
-#include <socket.S>
diff --git a/sysdeps/unix/sysv/linux/getpeername.c b/sysdeps/unix/sysv/linux/getpeername.c
new file mode 100644
index 0000000..adee2ba
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getpeername.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__getpeername (int fd, __SOCKADDR_ARG addr, socklen_t *len)
+{
+  return SOCKETCALL (getpeername, fd, addr.__sockaddr__, len, 0, 0, 0);
+}
+weak_alias (__getpeername, getpeername)
diff --git a/sysdeps/unix/sysv/linux/getsockname.S b/sysdeps/unix/sysv/linux/getsockname.S
deleted file mode 100644
index c138be9..0000000
--- a/sysdeps/unix/sysv/linux/getsockname.S
+++ /dev/null
@@ -1,3 +0,0 @@
-#define	socket	getsockname
-#define	NARGS	3
-#include <socket.S>
diff --git a/sysdeps/unix/sysv/linux/getsockname.c b/sysdeps/unix/sysv/linux/getsockname.c
new file mode 100644
index 0000000..564afac
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getsockname.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__getsockname (int fd, __SOCKADDR_ARG addr, socklen_t *len)
+{
+  return SOCKETCALL (getsockname, fd, addr.__sockaddr__, len, 0, 0, 0);
+}
+weak_alias (__getsockname, getsockname)
diff --git a/sysdeps/unix/sysv/linux/getsockopt.S b/sysdeps/unix/sysv/linux/getsockopt.S
deleted file mode 100644
index 6f98208..0000000
--- a/sysdeps/unix/sysv/linux/getsockopt.S
+++ /dev/null
@@ -1,3 +0,0 @@
-#define	socket	getsockopt
-#define	NARGS	5
-#include <socket.S>
diff --git a/sysdeps/unix/sysv/linux/getsockopt.c b/sysdeps/unix/sysv/linux/getsockopt.c
new file mode 100644
index 0000000..10d14c8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/getsockopt.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__getsockopt (int fd, int level, int optname, void *optval, socklen_t *len)
+{
+  return SOCKETCALL (getsockopt, fd, level, optname, optval, len, 0);
+}
+weak_alias (__getsockopt, getsockopt)
diff --git a/sysdeps/unix/sysv/linux/i386/accept4.S b/sysdeps/unix/sysv/linux/i386/accept4.S
deleted file mode 100644
index 6ed8395..0000000
--- a/sysdeps/unix/sysv/linux/i386/accept4.S
+++ /dev/null
@@ -1,177 +0,0 @@
-/* Copyright (C) 1995-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-cancel.h>
-#include <socketcall.h>
-#include <tls.h>
-#include <kernel-features.h>
-
-#define EINVAL	22
-#define ENOSYS	38
-
-#ifdef __ASSUME_ACCEPT4_SOCKETCALL
-# define errlabel SYSCALL_ERROR_LABEL
-#else
-# define errlabel .Lerr
-	.data
-have_accept4:
-	.long	0
-#endif
-
-	.text
-/* The socket-oriented system calls are handled unusally in Linux/i386.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.  */
-
-.globl __libc_accept4
-ENTRY (__libc_accept4)
-#ifdef CENABLE
-	SINGLE_THREAD_P
-	jne 1f
-#endif
-
-	/* Save registers.  */
-	movl %ebx, %edx
-	cfi_register (3, 2)
-
-	movl $SYS_ify(socketcall), %eax	/* System call number in %eax.  */
-
-	movl $SOCKOP_accept4, %ebx	/* Subcode is first arg to syscall.  */
-	lea 4(%esp), %ecx		/* Address of args is 2nd arg.  */
-
-        /* Do the system call trap.  */
-	ENTER_KERNEL
-
-	/* Restore registers.  */
-	movl %edx, %ebx
-	cfi_restore (3)
-
-	/* %eax is < 0 if there was an error.  */
-	cmpl $-125, %eax
-	jae errlabel
-
-	/* Successful; return the syscall's value.  */
-	ret
-
-
-#ifdef CENABLE
-	/* We need one more register.  */
-1:	pushl %esi
-	cfi_adjust_cfa_offset(4)
-
-	/* Enable asynchronous cancellation.  */
-	CENABLE
-	movl %eax, %esi
-	cfi_offset(6, -8)		/* %esi */
-
-	/* Save registers.  */
-	movl %ebx, %edx
-	cfi_register (3, 2)
-
-	movl $SYS_ify(socketcall), %eax	/* System call number in %eax.  */
-
-	movl $SOCKOP_accept4, %ebx	/* Subcode is first arg to syscall.  */
-	lea 8(%esp), %ecx		/* Address of args is 2nd arg.  */
-
-        /* Do the system call trap.  */
-	ENTER_KERNEL
-
-	/* Restore registers.  */
-	movl %edx, %ebx
-	cfi_restore (3)
-
-	/* Restore the cancellation.  */
-	xchgl %esi, %eax
-	CDISABLE
-
-	/* Restore registers.  */
-	movl %esi, %eax
-	popl %esi
-	cfi_restore (6)
-	cfi_adjust_cfa_offset(-4)
-
-	/* %eax is < 0 if there was an error.  */
-	cmpl $-125, %eax
-	jae errlabel
-
-	/* Successful; return the syscall's value.  */
-	ret
-#endif
-
-#ifndef __ASSUME_ACCEPT4_SOCKETCALL
-	/* The kernel returns -EINVAL for unknown socket operations.
-	   We need to convert that error to an ENOSYS error.  */
-.Lerr:	cmpl $-EINVAL, %eax
-	jne SYSCALL_ERROR_LABEL
-
-	/* Save registers.  */
-	pushl %ebx
-	cfi_adjust_cfa_offset(4)
-	cfi_offset(ebx, -8)
-
-# ifdef PIC
-	SETUP_PIC_REG (dx)
-	addl $_GLOBAL_OFFSET_TABLE_, %edx
-	movl have_accept4@GOTOFF(%edx), %eax
-# else
-	movl have_accept4, %eax
-# endif
-	testl %eax, %eax
-	jne 1f
-
-	/* Try another call, this time with the FLAGS parameter
-	   cleared and an invalid file descriptor.  This call will not
-	   cause any harm and it will return immediately.  */
-	movl $-1, 8(%esp)
-	movl $0, 20(%esp)
-
-	movl $SYS_ify(socketcall), %eax	/* System call number in %eax.  */
-
-	movl $SOCKOP_accept4, %ebx	/* Subcode is first arg to syscall.  */
-	lea 8(%esp), %ecx		/* Address of args is 2nd arg.  */
-
-        /* Do the system call trap.  */
-	ENTER_KERNEL
-
-	cmpl $-EINVAL, %eax
-	movl $-1, %eax
-	je 3f
-	movl $1, %eax
-3:
-# ifdef PIC
-	movl %eax, have_accept4@GOTOFF(%edx)
-# else
-	movl %eax, have_accept4
-# endif
-
-	testl %eax, %eax
-
-1:	movl $-EINVAL, %eax
-	jns 2f
-	movl $-ENOSYS, %eax
-
-	/* Restore registers.  */
-2:	popl %ebx
-	cfi_restore (ebx)
-
-	jmp SYSCALL_ERROR_LABEL
-#endif
-PSEUDO_END (__libc_accept4)
-
-weak_alias (__libc_accept4, accept4)
diff --git a/sysdeps/unix/sysv/linux/i386/internal_accept4.S b/sysdeps/unix/sysv/linux/i386/internal_accept4.S
deleted file mode 100644
index c3f1630..0000000
--- a/sysdeps/unix/sysv/linux/i386/internal_accept4.S
+++ /dev/null
@@ -1 +0,0 @@
-/* Not needed, accept4.S has everything.  */
diff --git a/sysdeps/unix/sysv/linux/i386/socket.S b/sysdeps/unix/sysv/linux/i386/socket.S
deleted file mode 100644
index d87390c..0000000
--- a/sysdeps/unix/sysv/linux/i386/socket.S
+++ /dev/null
@@ -1,122 +0,0 @@
-/* Copyright (C) 1995-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-cancel.h>
-#include <socketcall.h>
-#include <tls.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-	.text
-/* The socket-oriented system calls are handled unusally in Linux/i386.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.  */
-
-#ifndef __socket
-# ifndef NO_WEAK_ALIAS
-#  define __socket P(__,socket)
-# else
-#  define __socket socket
-# endif
-#endif
-
-.globl __socket
-ENTRY (__socket)
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	jne 1f
-#endif
-
-	/* Save registers.  */
-	movl %ebx, %edx
-	cfi_register (3, 2)
-
-	movl $SYS_ify(socketcall), %eax	/* System call number in %eax.  */
-
-	/* Use ## so `socket' is a separate token that might be #define'd.  */
-	movl $P(SOCKOP_,socket), %ebx	/* Subcode is first arg to syscall.  */
-	lea 4(%esp), %ecx		/* Address of args is 2nd arg.  */
-
-        /* Do the system call trap.  */
-	ENTER_KERNEL
-
-	/* Restore registers.  */
-	movl %edx, %ebx
-	cfi_restore (3)
-
-	/* %eax is < 0 if there was an error.  */
-	cmpl $-125, %eax
-	jae SYSCALL_ERROR_LABEL
-
-	/* Successful; return the syscall's value.  */
-	ret
-
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	/* We need one more register.  */
-1:	pushl %esi
-	cfi_adjust_cfa_offset(4)
-
-	/* Enable asynchronous cancellation.  */
-	CENABLE
-	movl %eax, %esi
-	cfi_offset(6, -8)		/* %esi */
-
-	/* Save registers.  */
-	movl %ebx, %edx
-	cfi_register (3, 2)
-
-	movl $SYS_ify(socketcall), %eax	/* System call number in %eax.  */
-
-	/* Use ## so `socket' is a separate token that might be #define'd.  */
-	movl $P(SOCKOP_,socket), %ebx	/* Subcode is first arg to syscall.  */
-	lea 8(%esp), %ecx		/* Address of args is 2nd arg.  */
-
-        /* Do the system call trap.  */
-	ENTER_KERNEL
-
-	/* Restore registers.  */
-	movl %edx, %ebx
-	cfi_restore (3)
-
-	/* Restore the cancellation.  */
-	xchgl %esi, %eax
-	CDISABLE
-
-	/* Restore registers.  */
-	movl %esi, %eax
-	popl %esi
-	cfi_restore (6)
-	cfi_adjust_cfa_offset(-4)
-
-	/* %eax is < 0 if there was an error.  */
-	cmpl $-125, %eax
-	jae SYSCALL_ERROR_LABEL
-
-	/* Successful; return the syscall's value.  */
-	ret
-#endif
-PSEUDO_END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/internal_accept4.S b/sysdeps/unix/sysv/linux/internal_accept4.S
deleted file mode 100644
index f0c61b5..0000000
--- a/sysdeps/unix/sysv/linux/internal_accept4.S
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <kernel-features.h>
-#include <sys/syscall.h>
-
-/* Do not use the accept4 syscall on socketcall architectures unless
-   it was added at the same time as the socketcall support or can be
-   assumed to be present.  */
-#if defined __ASSUME_SOCKETCALL \
-    && !defined __ASSUME_ACCEPT4_SYSCALL_WITH_SOCKETCALL \
-    && !defined __ASSUME_ACCEPT4_SYSCALL
-# undef __NR_accept4
-#endif
-
-#if !defined __NR_accept4 && defined __NR_socketcall
-# define socket	accept4
-# ifdef __ASSUME_ACCEPT4_SOCKETCALL
-#  define __socket accept4
-# else
-#  define __socket __internal_accept4
-# endif
-# define NARGS 4
-# define NEED_CANCELLATION
-# define NO_WEAK_ALIAS
-# include <socket.S>
-#endif
diff --git a/sysdeps/unix/sysv/linux/internal_recvmmsg.S b/sysdeps/unix/sysv/linux/internal_recvmmsg.S
deleted file mode 100644
index 6b776b9..0000000
--- a/sysdeps/unix/sysv/linux/internal_recvmmsg.S
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <kernel-features.h>
-#include <sys/syscall.h>
-
-/* Do not use the recvmmsg syscall on socketcall architectures unless
-   it was added at the same time as the socketcall support or can be
-   assumed to be present.  */
-#if defined __ASSUME_SOCKETCALL \
-    && !defined __ASSUME_RECVMMSG_SYSCALL_WITH_SOCKETCALL \
-    && !defined __ASSUME_RECVMMSG_SYSCALL
-# undef __NR_recvmmsg
-#endif
-
-#if !defined __NR_recvmmsg && defined __NR_socketcall
-# define socket	recvmmsg
-# ifdef __ASSUME_RECVMMSG_SOCKETCALL
-#  define __socket recvmmsg
-# else
-#  define __socket __internal_recvmmsg
-# endif
-# define NARGS 5
-# define NEED_CANCELLATION
-# define NO_WEAK_ALIAS
-# include <socket.S>
-#endif
diff --git a/sysdeps/unix/sysv/linux/internal_sendmmsg.S b/sysdeps/unix/sysv/linux/internal_sendmmsg.S
deleted file mode 100644
index 4d903ea..0000000
--- a/sysdeps/unix/sysv/linux/internal_sendmmsg.S
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <kernel-features.h>
-#include <sys/syscall.h>
-
-/* Do not use the sendmmsg syscall on socketcall architectures unless
-   it was added at the same time as the socketcall support or can be
-   assumed to be present.  */
-#if defined __ASSUME_SOCKETCALL \
-    && !defined __ASSUME_SENDMMSG_SYSCALL_WITH_SOCKETCALL \
-    && !defined __ASSUME_SENDMMSG_SYSCALL
-# undef __NR_sendmmsg
-#endif
-
-#if !defined __NR_sendmmsg && defined __NR_socketcall
-# define socket	sendmmsg
-# ifndef __ASSUME_SENDMMSG_SOCKETCALL
-#  define __socket __internal_sendmmsg
-#  define NO_WEAK_ALIAS
-# endif
-# define NARGS 4
-# define NEED_CANCELLATION
-# include <socket.S>
-# ifdef __ASSUME_SENDMMSG_SOCKETCALL
-libc_hidden_def (__sendmmsg)
-# endif
-#endif
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 2ca6f10..48c0b00 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -41,9 +41,8 @@
 #define __ASSUME_SENDFILE		1
 
 /* Some architectures use the socketcall multiplexer for some or all
-   socket-related operations, via a socket.S file in glibc, instead of
-   separate syscalls.  __ASSUME_SOCKETCALL is defined for such
-   architectures.  */
+   socket-related operations instead of separate syscalls.  
+   __ASSUME_SOCKETCALL is defined for such architectures.  */
 
 /* Linux 2.3.39 introduced IPC64.  Except for powerpc.  Linux 2.4.0 on
    PPC introduced a correct IPC64.  But PowerPC64 does not support a
diff --git a/sysdeps/unix/sysv/linux/listen.S b/sysdeps/unix/sysv/linux/listen.S
deleted file mode 100644
index bed6a05..0000000
--- a/sysdeps/unix/sysv/linux/listen.S
+++ /dev/null
@@ -1,5 +0,0 @@
-#define	socket	listen
-#define	NARGS	2
-#define NO_WEAK_ALIAS	1
-#include <socket.S>
-weak_alias (listen, __listen)
diff --git a/sysdeps/unix/sysv/linux/listen.c b/sysdeps/unix/sysv/linux/listen.c
new file mode 100644
index 0000000..48d94a2
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/listen.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+listen (int fd, int backlog)
+{
+  return SOCKETCALL (listen, fd, backlog, 0, 0, 0, 0);
+}
+weak_alias (listen, __listen);
diff --git a/sysdeps/unix/sysv/linux/malloc-sysdep.h b/sysdeps/unix/sysv/linux/malloc-sysdep.h
index cd6255f..6af1107 100644
--- a/sysdeps/unix/sysv/linux/malloc-sysdep.h
+++ b/sysdeps/unix/sysv/linux/malloc-sysdep.h
@@ -46,7 +46,7 @@ check_may_shrink_heap (void)
 				  O_RDONLY | O_CLOEXEC);
       if (fd >= 0)
 	{
-	  char val;
+	  char val = 0;
 	  ssize_t n = read_not_cancel (fd, &val, 1);
 	  may_shrink_heap = n > 0 && val == '2';
 	  close_not_cancel_no_status (fd);
diff --git a/sysdeps/unix/sysv/linux/microblaze/socket.S b/sysdeps/unix/sysv/linux/microblaze/socket.S
deleted file mode 100644
index a3b4048..0000000
--- a/sysdeps/unix/sysv/linux/microblaze/socket.S
+++ /dev/null
@@ -1,126 +0,0 @@
-/* Copyright (C) 2009-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-cancel.h>
-#include <socketcall.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-/* The socket-oriented system calls are handled unusally in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.
-   They also #define a 'number-of-arguments' word in NARGS, which
-   defaults to 3.  */
-
-#ifndef NARGS
-# ifdef socket
-#  error NARGS not defined
-# endif
-# define NARGS 3
-#endif
-
-/* Stack usage:
-   0 - r15 (return address)
-   4 - 12 args to syscall
-   16 - scratch for cancellation state
-   20 - scratch for return value
-*/
-#define stackadjust 24
-
-#ifndef __socket
-# ifndef NO_WEAK_ALIAS
-#  define __socket P(__,socket)
-# else
-#  define __socket socket
-# endif
-#endif
-
-	.text
-ENTRY(__socket)
-	addik r1,r1,-stackadjust
-	swi r15,r1,0
-#if NARGS >= 1
-	swi  r5,r1,stackadjust+4
-#endif
-#if NARGS >= 2
-	swi  r6,r1,stackadjust+8
-#endif
-#if NARGS >= 3
-	swi  r7,r1,stackadjust+12
-#endif
-#if NARGS >= 4
-	swi  r8,r1,stackadjust+16
-#endif
-#if NARGS >= 5
-	swi  r9,r1,stackadjust+20
-#endif
-#if NARGS >= 6
-	swi  r10,r1,stackadjust+24
-#endif
-/* The rest of the args (if any) are on the caller's stack already.  */
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P(r12)
-	bnei	r12,L(socket_cancel)
-#endif
-
-	addik	r12,r0,SYS_ify(socketcall)
-	addik	r5,r0,P(SOCKOP_,socket)
-	addik	r6,r1,stackadjust+4
-	brki	r14,8
-	addk	r0,r0,r0
-	lwi	r15,r1,0
-	addik	r1,r1,stackadjust
-	addik   r4,r0,-4095
-	cmpu	r4,r4,r3
-	bgei	r4,SYSCALL_ERROR_LABEL
-	rtsd	r15,8
-	addk	r0,r0,r0
-
-#if defined NEED_CANCELLATION && defined CENABLE
-L(socket_cancel):
-	CENABLE
-	swi	r3,r1,16
-	addik	r12,r0,SYS_ify(socketcall)
-	addik	r5,r0,P(SOCKOP_,socket)
-	addik	r6,r1,stackadjust+4
-	brki	r14,8
-	addk	r0,r0,r0
-	swi	r3,r1,20
-	lwi	r5,r1,16
-	CDISABLE
-	lwi	r3,r1,20
-	lwi	r15,r1,0
-	addik	r1,r1,stackadjust
-	addik   r4,r0,-4095
-	cmpu	r4,r4,r3
-	bgei	r4,SYSCALL_ERROR_LABEL
-	rtsd	r15,8
-	addk	r0,r0,r0
-#endif
-
-PSEUDO_END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/internal_accept4.S b/sysdeps/unix/sysv/linux/mips/mips32/internal_accept4.S
deleted file mode 100644
index 30434d7..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips32/internal_accept4.S
+++ /dev/null
@@ -1,2 +0,0 @@
-/* MIPS does not have socket.S and the socketcall syscall should
-   generally be avoided, though it exists.  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/internal_recvmmsg.S b/sysdeps/unix/sysv/linux/mips/mips32/internal_recvmmsg.S
deleted file mode 100644
index 30434d7..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips32/internal_recvmmsg.S
+++ /dev/null
@@ -1,2 +0,0 @@
-/* MIPS does not have socket.S and the socketcall syscall should
-   generally be avoided, though it exists.  */
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/internal_sendmmsg.S b/sysdeps/unix/sysv/linux/mips/mips32/internal_sendmmsg.S
deleted file mode 100644
index 30434d7..0000000
--- a/sysdeps/unix/sysv/linux/mips/mips32/internal_sendmmsg.S
+++ /dev/null
@@ -1,2 +0,0 @@
-/* MIPS does not have socket.S and the socketcall syscall should
-   generally be avoided, though it exists.  */
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S b/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S
deleted file mode 100644
index 7dc59b4..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/socket.S
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Copyright (C) 1995-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-cancel.h>
-#include <socketcall.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-/* The socket-oriented system calls are handled unusally in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.
-   They also #define a 'number-of-arguments' word in NARGS, which
-   defaults to 3.  */
-
-#ifndef NARGS
-#ifdef socket
-#error NARGS not defined
-#endif
-#define NARGS 3
-#endif
-
-/* 0(r1) and 4(r1) are reserved by the ABI, 8(r1), 12(r1), 16(r1) are used
-   for temp saves.  44(r1) is used to save r30.  */
-#define stackblock 20
-
-#ifndef __socket
-# ifndef NO_WEAK_ALIAS
-#  define __socket P(__,socket)
-# else
-#  define __socket socket
-# endif
-#endif
-
-	.text
-ENTRY(__socket)
-	stwu r1,-48(r1)
-	cfi_adjust_cfa_offset(48)
-#if NARGS >= 1
-	stw  r3,stackblock(r1)
-#endif
-#if NARGS >= 2
-	stw  r4,4+stackblock(r1)
-#endif
-#if NARGS >= 3
-	stw  r5,8+stackblock(r1)
-#endif
-#if NARGS >= 4
-	stw  r6,12+stackblock(r1)
-#endif
-#if NARGS >= 5
-	stw  r7,16+stackblock(r1)
-#endif
-#if NARGS >= 6
-	stw  r8,20+stackblock(r1)
-#endif
-#if NARGS >= 7
-#error too many arguments!
-#endif
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	bne-	.Lsocket_cancel
-#endif
-
-	li	r3,P(SOCKOP_,socket)
-	addi	r4,r1,stackblock
-	DO_CALL(SYS_ify(socketcall))
-	addi	r1,r1,48
-	PSEUDO_RET
-
-#if defined NEED_CANCELLATION && defined CENABLE
-.Lsocket_cancel:
-	mflr	r9
-	stw	r9,52(r1)
-	cfi_offset (lr, 4)
-	CENABLE
-	stw	r3,16(r1)
-	li	r3,P(SOCKOP_,socket)
-	addi	r4,r1,stackblock
-	DO_CALL(SYS_ify(socketcall))
-	mfcr	r0
-	stw	r3,8(r1)
-	stw	r0,12(r1)
-	lwz	r3,16(r1)
-	CDISABLE
-	lwz	r4,52(r1)
-	lwz	r0,12(r1)
-	lwz	r3,8(r1)
-	mtlr	r4
-	mtcr	r0
-	addi	r1,r1,48
-	PSEUDO_RET
-#endif
-
-PSEUDO_END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S b/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S
deleted file mode 100644
index 1028444..0000000
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/socket.S
+++ /dev/null
@@ -1,134 +0,0 @@
-/* Copyright (C) 1995-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 Library General Public License as
-   published by the Free Software Foundation; either version 2 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
-   Library General Public License for more details.
-
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   see <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep-cancel.h>
-#include <socketcall.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-/* The socket-oriented system calls are handled unusally in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.
-   They also #define a 'number-of-arguments' word in NARGS, which
-   defaults to 3.  */
-
-#ifndef NARGS
-#ifdef socket
-#error NARGS not defined
-#endif
-#define NARGS 3
-#endif
-
-#ifndef __socket
-# ifndef NO_WEAK_ALIAS
-#  define __socket P(__,socket)
-# else
-#  define __socket socket
-# endif
-#endif
-
-#if _CALL_ELF == 2
-#define FRAMESIZE (FRAME_MIN_SIZE+16+64)
-#define stackblock (FRAME_MIN_SIZE+16)
-#else
-#define FRAMESIZE (FRAME_MIN_SIZE+16)
-#define stackblock (FRAMESIZE+FRAME_PARM_SAVE) /* offset to parm save area.  */
-#endif
-
-	.text
-ENTRY(__socket)
-	CALL_MCOUNT NARGS
-	stdu r1,-FRAMESIZE(r1)
-	cfi_adjust_cfa_offset(FRAMESIZE)
-#if NARGS >= 1
-	std  r3,stackblock(r1)
-#endif
-#if NARGS >= 2
-	std  r4,8+stackblock(r1)
-#endif
-#if NARGS >= 3
-	std  r5,16+stackblock(r1)
-#endif
-#if NARGS >= 4
-	std  r6,24+stackblock(r1)
-#endif
-#if NARGS >= 5
-	std  r7,32+stackblock(r1)
-#endif
-#if NARGS >= 6
-	std  r8,40+stackblock(r1)
-#endif
-#if NARGS >= 7
-	std  r9,48+stackblock(r1)
-#endif
-#if NARGS >= 8
-	std  r10,56+stackblock(r1)
-#endif
-#if NARGS >= 9
-#error too many arguments!
-#endif
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	bne-	.Lsocket_cancel
-#endif
-
-	li	r3,P(SOCKOP_,socket)
-	addi	r4,r1,stackblock
-	DO_CALL(SYS_ify(socketcall))
-	addi	r1,r1,FRAMESIZE
-	cfi_adjust_cfa_offset(-FRAMESIZE)
-	PSEUDO_RET
-
-#if defined NEED_CANCELLATION && defined CENABLE
-.Lsocket_cancel:
-	cfi_adjust_cfa_offset(FRAMESIZE)
-	mflr	r9
-	std	r9,FRAMESIZE+FRAME_LR_SAVE(r1)
-	cfi_offset (lr, FRAME_LR_SAVE)
-	CENABLE
-	std	r3,FRAME_MIN_SIZE+8(r1)
-	li	r3,P(SOCKOP_,socket)
-	addi	r4,r1,stackblock
-	DO_CALL(SYS_ify(socketcall))
-	mfcr	r0
-	std	r3,FRAME_MIN_SIZE(r1)
-	std	r0,FRAMESIZE+FRAME_CR_SAVE(r1)
-	cfi_offset (cr, FRAME_CR_SAVE)
-	ld  	r3,FRAME_MIN_SIZE+8(r1)
-	CDISABLE
-	ld	r4,FRAMESIZE+FRAME_LR_SAVE(r1)
-	ld	r0,FRAMESIZE+FRAME_CR_SAVE(r1)
-	ld	r3,FRAME_MIN_SIZE(r1)
-	mtlr	r4
-	mtcr	r0
-	addi	r1,r1,FRAMESIZE
-	cfi_adjust_cfa_offset(-FRAMESIZE)
-	cfi_restore(lr)
-	cfi_restore(cr)
-	PSEUDO_RET
-#endif
-PSEUDO_END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/recv.S b/sysdeps/unix/sysv/linux/recv.S
deleted file mode 100644
index 331844a..0000000
--- a/sysdeps/unix/sysv/linux/recv.S
+++ /dev/null
@@ -1,6 +0,0 @@
-#define	socket	recv
-#define	__socket __libc_recv
-#define	NARGS	4
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_recv, __recv)
diff --git a/sysdeps/unix/sysv/linux/recv.c b/sysdeps/unix/sysv/linux/recv.c
new file mode 100644
index 0000000..1ecc0eb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/recv.c
@@ -0,0 +1,31 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+ssize_t
+__libc_recv (int fd, void *buf, size_t len, int flags)
+{
+  return SOCKETCALL_CANCEL (recv, fd, buf, len, flags, 0, 0);
+}
+weak_alias (__libc_recv, recv)
+weak_alias (__libc_recv, __recv)
diff --git a/sysdeps/unix/sysv/linux/recvfrom.S b/sysdeps/unix/sysv/linux/recvfrom.S
deleted file mode 100644
index ccbb0a7..0000000
--- a/sysdeps/unix/sysv/linux/recvfrom.S
+++ /dev/null
@@ -1,6 +0,0 @@
-#define	socket	recvfrom
-#define	__socket __libc_recvfrom
-#define	NARGS	6
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_recvfrom, __recvfrom)
diff --git a/sysdeps/unix/sysv/linux/recvfrom.c b/sysdeps/unix/sysv/linux/recvfrom.c
new file mode 100644
index 0000000..90eb40d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/recvfrom.c
@@ -0,0 +1,33 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+ssize_t
+__libc_recvfrom (int fd, void *buf, size_t len, int flags,
+		 __SOCKADDR_ARG addr, socklen_t *addrlen)
+{
+  return SOCKETCALL_CANCEL (recvfrom, fd, buf, len, flags, addr.__sockaddr__,
+			    addrlen);
+}
+weak_alias (__libc_recvfrom, recvfrom)
+weak_alias (__libc_recvfrom, __recvfrom)
diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c
index c3a4874..73b3ee0 100644
--- a/sysdeps/unix/sysv/linux/recvmmsg.c
+++ b/sysdeps/unix/sysv/linux/recvmmsg.c
@@ -49,12 +49,15 @@ recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
   return result;
 }
 #elif defined __NR_socketcall
-# ifndef __ASSUME_RECVMMSG_SOCKETCALL
-extern int __internal_recvmmsg (int fd, struct mmsghdr *vmessages,
-				unsigned int vlen, int flags,
-				struct timespec *tmo)
-     attribute_hidden;
-
+# include <socketcall.h>
+# ifdef __ASSUME_RECVMMSG_SOCKETCALL
+int
+recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
+	  struct timespec *tmo)
+{
+  return SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, tmo, 0, 0);
+}
+# else
 static int have_recvmmsg;
 
 int
@@ -63,7 +66,8 @@ recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
 {
   if (__glibc_likely (have_recvmmsg >= 0))
     {
-      int ret = __internal_recvmmsg (fd, vmessages, vlen, flags, tmo);
+      int ret = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags,
+				   tmo, 0);
       /* The kernel returns -EINVAL for unknown socket operations.
 	 We need to convert that error to an ENOSYS error.  */
       if (__builtin_expect (ret < 0, 0)
@@ -74,7 +78,7 @@ recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
 	     descriptor and all other parameters cleared.  This call
 	     will not cause any harm and it will return
 	     immediately.  */
-	  ret = __internal_recvmmsg (-1, 0, 0, 0, 0);
+	  ret = SOCKETCALL_CANCEL (invalid, 0, 0, 0, 0, 0, 0);
 	  if (errno == EINVAL)
 	    {
 	      have_recvmmsg = -1;
@@ -92,10 +96,7 @@ recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags,
   __set_errno (ENOSYS);
   return -1;
 }
-# else
-/* When __ASSUME_RECVMMSG_SOCKETCALL recvmmsg is defined in
-   internal_recvmmsg.S.  */
-# endif
+# endif /* __ASSUME_RECVMMSG_SOCKETCALL  */
 #else
 # include <socket/recvmmsg.c>
 #endif
diff --git a/sysdeps/unix/sysv/linux/recvmsg.S b/sysdeps/unix/sysv/linux/recvmsg.S
deleted file mode 100644
index d44bc39..0000000
--- a/sysdeps/unix/sysv/linux/recvmsg.S
+++ /dev/null
@@ -1,6 +0,0 @@
-#define	socket	recvmsg
-#define	__socket __libc_recvmsg
-#define	NARGS	3
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_recvmsg, __recvmsg)
diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c
new file mode 100644
index 0000000..1d68a71
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/recvmsg.c
@@ -0,0 +1,31 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+ssize_t
+__libc_recvmsg (int fd, struct msghdr *msg, int flags)
+{
+  return SOCKETCALL_CANCEL (recvmsg, fd, msg, flags,  0, 0, 0);
+}
+weak_alias (__libc_recvmsg, recvmsg)
+weak_alias (__libc_recvmsg, __recvmsg)
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/socket.S b/sysdeps/unix/sysv/linux/s390/s390-32/socket.S
deleted file mode 100644
index 4611e52..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-32/socket.S
+++ /dev/null
@@ -1,142 +0,0 @@
-/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
-   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-cancel.h>
-#include <socketcall.h>
-
-/* &%/$&!! preprocessor */
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-	.text
-/* The socket-oriented system calls are handled unusally in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.  */
-
-#ifndef __socket
-#ifndef NO_WEAK_ALIAS
-#define __socket P(__,socket)
-#else
-#define __socket socket
-#endif
-#endif
-
-#ifndef NARGS      /* the socket.o object is compiled directly ... */
-#define NARGS 3
-#endif
-
-.globl __socket
-ENTRY(__socket)
-	/* Save registers and setup stack.  */
-	stm     %r6,%r15,24(%r15)       /* save registers */
-	cfi_offset (%r15, -36)
-	cfi_offset (%r14, -40)
-	cfi_offset (%r13, -44)
-	cfi_offset (%r12, -48)
-	cfi_offset (%r11, -52)
-	cfi_offset (%r10, -56)
-	cfi_offset (%r9, -60)
-	cfi_offset (%r8, -64)
-	cfi_offset (%r7, -68)
-	cfi_offset (%r6, -72)
-	lr      %r1,%r15
-	l       %r0,4(0,%r15)           /* load eos */
-	ahi     %r15,-120               /* buy stack space */
-	cfi_adjust_cfa_offset (120)
-	st      %r1,0(0,%r15)           /* store back chain */
-	st      %r0,4(0,%r15)           /* store eos */
-
-	/* Reorder arguments */
-#if (NARGS >= 6)
-	mvc     0x74(4,%r15),216(%r15)  /* move between parameter lists */
-#endif
-#if (NARGS >= 5)
-	st      %r6,0x70(0,%r15)        /* store into parameter list */
-#endif
-#if (NARGS >= 4)
-	st      %r5,0x6C(0,%r15)        /* store into parameter list */
-#endif
-#if (NARGS >= 3)
-	st      %r4,0x68(0,%r15)        /* store into parameter list */
-#endif
-#if (NARGS >= 2)
-	st      %r3,0x64(0,%r15)        /* store into parameter list */
-	st      %r2,0x60(0,%r15)
-#endif
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P (%r4)
-	jne	L(socket_cancel)
-#endif
-
-	/* load subcode for socket syscall */
-	lhi     %r2,P(SOCKOP_,socket)
-	la      %r3,0x60(0,%r15)        /* load address of parameter list */
-
-	/* Do the system call trap.  */
-	svc     SYS_ify(socketcall)
-
-4:
-	l       %r15,0(0,%r15)          /* load back chain */
-	lm      %r6,15,24(%r15)         /* load registers */
-
-	/* gpr2 is < 0 if there was an error.  */
-	lhi     %r0,-125
-	clr     %r2,%r0
-	jnl     SYSCALL_ERROR_LABEL
-
-	/* Successful; return the syscall's value.  */
-	br      %r14
-
-#if defined NEED_CANCELLATION && defined CENABLE
-L(socket_cancel):
-	basr	%r13,0
-1:	l	%r1,2f-1b(%r13)
-	/* call CENABLE.  */
-	bas	%r14,0(%r13,%r1)
-	lr	%r0,%r2
-
-	/* load subcode for socket syscall */
-	lhi     %r2,P(SOCKOP_,socket)
-	la      %r3,0x60(0,%r15)        /* load address of parameter list */
-
-	/* Do the system call trap.  */
-	svc     SYS_ify(socketcall)
-
-	l	%r3,3f-1b(%r13)
-	lr	%r12,%r2
-	lr	%r2,%r0
-	/* call CDISABLE.  */
-	bas     %r14,0(%r13,%r3)
-	lr	%r2,%r12
-	j	4b
-
-2:	.long	CENABLE-1b
-3:	.long	CDISABLE-1b
-#endif
-
-	SYSCALL_ERROR_HANDLER
-END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/socket.S b/sysdeps/unix/sysv/linux/s390/s390-64/socket.S
deleted file mode 100644
index 26b39f9..0000000
--- a/sysdeps/unix/sysv/linux/s390/s390-64/socket.S
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Copyright (C) 2001-2015 Free Software Foundation, Inc.
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
-   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-cancel.h>
-#include <socketcall.h>
-
-/* &%/$&!! preprocessor */
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-        .text
-/* The socket-oriented system calls are handled unusally in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.  */
-
-#ifndef __socket
-#ifndef NO_WEAK_ALIAS
-#define __socket P(__,socket)
-#else
-#define __socket socket
-#endif
-#endif
-
-#ifndef NARGS      /* The socket.o object is compiled directly ... */
-#define NARGS 3
-#endif
-
-.globl __socket
-ENTRY(__socket)
-	/* Save registers and setup stack.  */
-        stmg    %r6,%r15,48(%r15)       /* Save registers.  */
-	cfi_offset (%r15,-40)
-	cfi_offset (%r14,-48)
-	cfi_offset (%r13,-56)
-	cfi_offset (%r12,-64)
-	cfi_offset (%r11,-72)
-	cfi_offset (%r10,-80)
-	cfi_offset (%r9,-88)
-	cfi_offset (%r8,-96)
-	cfi_offset (%r7,-104)
-	cfi_offset (%r6,-112)
-        lgr     %r1,%r15
-        lg      %r0,8(%r15)             /* Load eos.  */
-        aghi     %r15,-208              /* Buy stack space.  */
-	cfi_adjust_cfa_offset (208)
-        stg     %r1,0(%r15)             /* Store back chain.  */
-        stg     %r0,8(%r15)             /* Store eos.  */
-
-        /* Reorder arguments.  */
-#if (NARGS >= 6)
-        mvc     200(8,%r15),368(%r15)   /* Move between parameter lists.  */
-#endif
-#if (NARGS >= 5)
-        stg     %r6,192(%r15)           /* Store into parameter list.  */
-#endif
-#if (NARGS >= 4)
-	stg     %r5,184(%r15)            /* Store into parameter list.  */
-#endif
-#if (NARGS >= 3)
-	stg     %r4,176(%r15)            /* Store into parameter list.  */
-#endif
-#if (NARGS >= 2)
-        stg     %r3,168(%r15)           /* Store into parameter list.  */
-	stg     %r2,160(%r15)
-#endif
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	jne	L(socket_cancel)
-#endif
-
-        /* Load subcode for socket syscall.  */
-        lghi    %r2,P(SOCKOP_,socket)
-	la      %r3,160(%r15)           /* Load address of parameter list.  */
-
-        /* Do the system call trap.  */
-        svc     SYS_ify(socketcall)
-
-4:
-        lg      %r15,0(%r15)            /* Load back chain.  */
-        lmg     %r6,15,48(%r15)         /* Load registers.  */
-
-	/* gpr2 is < 0 if there was an error.  */
-        lghi    %r0,-125
-        clgr    %r2,%r0
-        jgnl    SYSCALL_ERROR_LABEL
-
-	/* Successful; return the syscall's value.  */
-	br      %r14
-
-#if defined NEED_CANCELLATION && defined CENABLE
-L(socket_cancel):
-	brasl	%r14,CENABLE
-	lr	%r0,%r2
-
-	/* Load subcode for socket syscall.  */
-	lghi	%r2,P(SOCKOP_,socket)
-	la	%r3,160(%r15)		/* Load address of parameter list.  */
-
-	/* Do the system call trap.  */
-	svc	SYS_ify(socketcall)
-
-	lgr	%r12,%r2
-	lr	%r2,%r0
-	brasl	%r14,CDISABLE
-
-	lgr	%r2,%r12
-	j	4b
-#endif
-
-	SYSCALL_ERROR_HANDLER
-END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
-
diff --git a/sysdeps/unix/sysv/linux/send.S b/sysdeps/unix/sysv/linux/send.S
deleted file mode 100644
index 259748f..0000000
--- a/sysdeps/unix/sysv/linux/send.S
+++ /dev/null
@@ -1,7 +0,0 @@
-#define	socket	send
-#define	__socket __libc_send
-#define	NARGS	4
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_send, __send)
-libc_hidden_def (__send)
diff --git a/sysdeps/unix/sysv/linux/send.c b/sysdeps/unix/sysv/linux/send.c
new file mode 100644
index 0000000..25333d0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/send.c
@@ -0,0 +1,32 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+ssize_t
+__libc_send (int fd, const void *buf, size_t len, int flags)
+{
+  return SOCKETCALL_CANCEL (send, fd, buf, len, flags, 0, 0);
+}
+weak_alias (__libc_send, send)
+weak_alias (__libc_send, __send)
+libc_hidden_def (__send)
diff --git a/sysdeps/unix/sysv/linux/sendmmsg.c b/sysdeps/unix/sysv/linux/sendmmsg.c
index a95aff1..7bad328 100644
--- a/sysdeps/unix/sysv/linux/sendmmsg.c
+++ b/sysdeps/unix/sysv/linux/sendmmsg.c
@@ -50,11 +50,14 @@ __sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
 libc_hidden_def (__sendmmsg)
 weak_alias (__sendmmsg, sendmmsg)
 #elif defined __NR_socketcall
-# ifndef __ASSUME_SENDMMSG_SOCKETCALL
-extern int __internal_sendmmsg (int fd, struct mmsghdr *vmessages,
-				unsigned int vlen, int flags)
-     attribute_hidden;
-
+# include <socketcall.h>
+# ifdef __ASSUME_SENDMMSG_SOCKETCALL
+int
+__sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
+{
+  return SOCKETCALL_CANCEL (sendmmsg, fd, vmessages, vlen, flags, 0, 0);
+}
+# else
 static int have_sendmmsg;
 
 int
@@ -62,7 +65,7 @@ __sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
 {
   if (__glibc_likely (have_sendmmsg >= 0))
     {
-      int ret = __internal_sendmmsg (fd, vmessages, vlen, flags);
+      int ret = SOCKETCALL_CANCEL (sendmmsg, fd, vmessages, vlen, flags, 0, 0);
       /* The kernel returns -EINVAL for unknown socket operations.
 	 We need to convert that error to an ENOSYS error.  */
       if (__builtin_expect (ret < 0, 0)
@@ -73,7 +76,7 @@ __sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
 	     descriptor and all other parameters cleared.  This call
 	     will not cause any harm and it will return
 	     immediately.  */
-	  ret = __internal_sendmmsg (-1, 0, 0, 0);
+	  ret = SOCKETCALL_CANCEL (invalid, 0, 0, 0, 0, 0, 0);
 	  if (errno == EINVAL)
 	    {
 	      have_sendmmsg = -1;
@@ -91,12 +94,9 @@ __sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
   __set_errno (ENOSYS);
   return -1;
 }
+# endif /* __ASSUME_SENDMMSG_SOCKETCALL  */
 libc_hidden_def (__sendmmsg)
 weak_alias (__sendmmsg, sendmmsg)
-# else
-/* When __ASSUME_SENDMMSG_SOCKETCALL sendmmsg is defined in
-   internal_sendmmsg.S.  */
-# endif
 #else
 # include <socket/sendmmsg.c>
 #endif
diff --git a/sysdeps/unix/sysv/linux/sendmsg.S b/sysdeps/unix/sysv/linux/sendmsg.S
deleted file mode 100644
index a220894..0000000
--- a/sysdeps/unix/sysv/linux/sendmsg.S
+++ /dev/null
@@ -1,6 +0,0 @@
-#define	socket	sendmsg
-#define	__socket __libc_sendmsg
-#define	NARGS	3
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_sendmsg, __sendmsg)
diff --git a/sysdeps/unix/sysv/linux/sendmsg.c b/sysdeps/unix/sysv/linux/sendmsg.c
new file mode 100644
index 0000000..67f4317
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sendmsg.c
@@ -0,0 +1,31 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+ssize_t
+__libc_sendmsg (int fd, const struct msghdr *msg, int flags)
+{
+  return SOCKETCALL_CANCEL (sendmsg, fd, msg, flags, 0, 0, 0);
+}
+weak_alias (__libc_sendmsg, sendmsg)
+weak_alias (__libc_sendmsg, __sendmsg)
diff --git a/sysdeps/unix/sysv/linux/sendto.S b/sysdeps/unix/sysv/linux/sendto.S
deleted file mode 100644
index a65e44f..0000000
--- a/sysdeps/unix/sysv/linux/sendto.S
+++ /dev/null
@@ -1,6 +0,0 @@
-#define	socket	sendto
-#define	__socket __libc_sendto
-#define	NARGS	6
-#define NEED_CANCELLATION
-#include <socket.S>
-weak_alias (__libc_sendto, __sendto)
diff --git a/sysdeps/unix/sysv/linux/sendto.c b/sysdeps/unix/sysv/linux/sendto.c
new file mode 100644
index 0000000..d2896a6
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sendto.c
@@ -0,0 +1,33 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <sysdep-cancel.h>
+#include <socketcall.h>
+
+ssize_t
+__libc_sendto (int fd, const void *buf, size_t len, int flags,
+	       __CONST_SOCKADDR_ARG addr, socklen_t addrlen)
+{
+  return SOCKETCALL_CANCEL (sendto, fd, buf, len, flags, addr.__sockaddr__,
+			    addrlen);
+}
+weak_alias (__libc_sendto, sendto)
+weak_alias (__libc_sendto, __sendto)
diff --git a/sysdeps/unix/sysv/linux/setsockopt.S b/sysdeps/unix/sysv/linux/setsockopt.S
deleted file mode 100644
index 4e40ccb..0000000
--- a/sysdeps/unix/sysv/linux/setsockopt.S
+++ /dev/null
@@ -1,5 +0,0 @@
-#define	socket	setsockopt
-#define	NARGS	5
-#define NO_WEAK_ALIAS	1
-#include <socket.S>
-weak_alias (setsockopt, __setsockopt)
diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c
new file mode 100644
index 0000000..5f66f73
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/setsockopt.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+setsockopt (int fd, int level, int optname, const void *optval, socklen_t len)
+{
+  return SOCKETCALL (setsockopt, fd, level, optname, optval, len, 0);
+}
+weak_alias (setsockopt, __setsockopt)
diff --git a/sysdeps/unix/sysv/linux/sh/socket.S b/sysdeps/unix/sysv/linux/sh/socket.S
deleted file mode 100644
index ee99e84..0000000
--- a/sysdeps/unix/sysv/linux/sh/socket.S
+++ /dev/null
@@ -1,179 +0,0 @@
-/* Copyright (C) 1999-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-cancel.h>
-#include <socketcall.h>
-#include <tls.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-	.text
-/* The socket-oriented system calls are handled unusally in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.  */
-
-#ifndef __socket
-#ifndef NO_WEAK_ALIAS
-#define __socket P(__,socket)
-#else
-#define __socket socket
-#endif
-#endif
-
-#define PUSHARGS_1	mov.l r4,@-r15;	\
-			cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (r4, 0)
-#define PUSHARGS_2	mov.l r5,@-r15; \
-			cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (r5, 0); \
-			PUSHARGS_1
-#define PUSHARGS_3	mov.l r6,@-r15; \
-			cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (r6, 0); \
-			PUSHARGS_2
-#define PUSHARGS_4	mov.l r7,@-r15; \
-			cfi_adjust_cfa_offset (4); \
-			cfi_rel_offset (r7, 0); \
-			PUSHARGS_3
-#define PUSHARGS_5	PUSHARGS_4	/* Caller has already pushed arg 5 */
-#define PUSHARGS_6	PUSHARGS_4	/* Caller has already pushed arg 5,6 */
-
-#define POPARGS_1	add #4,r15; cfi_adjust_cfa_offset (-4)
-#define POPARGS_2	add #8,r15; cfi_adjust_cfa_offset (-8)
-#define POPARGS_3	add #12,r15; cfi_adjust_cfa_offset (-12)
-#define POPARGS_4	add #16,r15; cfi_adjust_cfa_offset (-16)
-#define POPARGS_5	POPARGS_4
-#define POPARGS_6	POPARGS_4
-
-#define ADJUSTCFI_1	cfi_adjust_cfa_offset (4); \
-			cfi_offset (r4, -4)
-#define ADJUSTCFI_2	cfi_adjust_cfa_offset (8); \
-			cfi_offset (r4, -4); \
-			cfi_offset (r5, -8)
-#define ADJUSTCFI_3	cfi_adjust_cfa_offset (12); \
-			cfi_offset (r4, -4); \
-			cfi_offset (r5, -8); \
-			cfi_offset (r6, -12)
-#define ADJUSTCFI_4	cfi_adjust_cfa_offset (16); \
-			cfi_offset (r4, -4); \
-			cfi_offset (r5, -8); \
-			cfi_offset (r6, -12); \
-			cfi_offset (r7, -16)
-#define ADJUSTCFI_5	ADJUSTCFI_4
-#define ADJUSTCFI_6	ADJUSTCFI_4
-
-#ifndef NARGS
-/* If we were called with no wrapper, this is really socket().  */
-#define NARGS 3
-#endif
-
-.globl __socket
-ENTRY (__socket)
-	/* This will not work in the case of a socket call being interrupted
-	   by a signal.  If the signal handler uses any stack the arguments
-	   to socket will be trashed.  The results of a restart of any
-	   socket call are then unpredictable.  */
-
-	/* Push args onto the stack.  */
-	P(PUSHARGS_,NARGS)
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	bf .Lsocket_cancel
-#endif
-
-	/* Do the system call trap.  */
-	mov #+P(SOCKOP_,socket), r4
-	mov r15, r5
-	mov.l .L1,r3
-	trapa #0x12
-
-	/* Pop args off the stack */
-	P(POPARGS_,NARGS)
-
-	mov     r0, r1
-	mov	#-12, r2
-	shad	r2, r1
-	not	r1, r1			// r1=0 means r0 = -1 to -4095
-	tst	r1, r1			// i.e. error in linux
-	bf	.Lpseudo_end
-.Lsyscall_error:
-	SYSCALL_ERROR_HANDLER
-.Lpseudo_end:
-	/* Successful; return the syscall's value.  */
-	rts
-	 nop
-
-#if defined NEED_CANCELLATION && defined CENABLE
-.Lsocket_cancel:
-	/* Enable asynchronous cancellation.  */
-	P(ADJUSTCFI_,NARGS)
-	sts.l pr,@-r15
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (pr, 0)
-	CENABLE
-	lds.l @r15+,pr
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (pr)
-
-	/* Do the system call trap.  */
-	mov #+P(SOCKOP_,socket), r4
-	mov r15, r5
-	mov.l .L1,r3
-	trapa #0x12
-
-	sts.l pr,@-r15
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (pr, 0)
-	mov.l r0,@-r15
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (r0, 0)
-	CDISABLE
-	mov.l @r15+,r0
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (r0)
-	lds.l @r15+,pr
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (pr)
-
-	/* Pop args off the stack */
-	P(POPARGS_,NARGS)
-
-	mov     r0, r1
-	mov	#-12, r2
-	shad	r2, r1
-	not	r1, r1			// r1=0 means r0 = -1 to -4095
-	tst	r1, r1			// i.e. error in linux
-	bf	.Lpseudo_end
-	bra	.Lsyscall_error
-	 nop
-#endif
-
-	.align 2
-.L1:
-	.long	SYS_ify(socketcall)
-
-PSEUDO_END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/shutdown.S b/sysdeps/unix/sysv/linux/shutdown.S
deleted file mode 100644
index e2462d0..0000000
--- a/sysdeps/unix/sysv/linux/shutdown.S
+++ /dev/null
@@ -1,3 +0,0 @@
-#define	socket	shutdown
-#define	NARGS	2
-#include <socket.S>
diff --git a/sysdeps/unix/sysv/linux/shutdown.c b/sysdeps/unix/sysv/linux/shutdown.c
new file mode 100644
index 0000000..a4c9eb6
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/shutdown.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__shutdown (int fd, int how)
+{
+  return SOCKETCALL (shutdown, fd, how, 0, 0, 0, 0);
+}
+weak_alias (__shutdown, shutdown)
diff --git a/sysdeps/unix/sysv/linux/socket.c b/sysdeps/unix/sysv/linux/socket.c
new file mode 100644
index 0000000..8e9d868
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/socket.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__socket (int fd, int type, int domain)
+{
+  return SOCKETCALL (socket, fd, type, domain, 0, 0, 0);
+}
+weak_alias (__socket, socket)
diff --git a/sysdeps/unix/sysv/linux/socketcall.h b/sysdeps/unix/sysv/linux/socketcall.h
index e59067d..6ddb09d 100644
--- a/sysdeps/unix/sysv/linux/socketcall.h
+++ b/sysdeps/unix/sysv/linux/socketcall.h
@@ -25,6 +25,7 @@
    We cannot use an enum here because the values are used in assembler
    code.  */
 
+#define SOCKOP_invalid		-1
 #define SOCKOP_socket		1
 #define SOCKOP_bind		2
 #define SOCKOP_connect		3
@@ -46,4 +47,38 @@
 #define SOCKOP_recvmmsg		19
 #define SOCKOP_sendmmsg		20
 
+#define SOCKETCALL(name, __a1, __a2, __a3, __a4, __a5, __a6)		\
+  ({									\
+    long int __args[6] = { (long int) __a1,				\
+                           (long int) __a2,				\
+                           (long int) __a3,				\
+                           (long int) __a4,				\
+                           (long int) __a5,				\
+                           (long int) __a6 };				\
+    long int sc_ret = INLINE_SYSCALL (socketcall, 2, SOCKOP_##name,	\
+                                     __args);				\
+    sc_ret;								\
+  })
+
+#if IS_IN (libc)
+# define __pthread_enable_asynccancel  __libc_enable_asynccancel
+# define __pthread_disable_asynccancel __libc_disable_asynccancel
+#endif
+
+#define SOCKETCALL_CANCEL(name, __a1, __a2, __a3, __a4, __a5, __a6)	\
+  ({									\
+    long int __args[6] = { (long int) __a1,				\
+                           (long int) __a2,				\
+                           (long int) __a3,				\
+                           (long int) __a4,				\
+                           (long int) __a5,				\
+                           (long int) __a6 };				\
+    int oldtype = LIBC_CANCEL_ASYNC ();					\
+    long int sc_ret = INLINE_SYSCALL (socketcall, 2, SOCKOP_##name,	\
+                                     __args);				\
+    LIBC_CANCEL_RESET (oldtype);					\
+    sc_ret;								\
+  })
+
+
 #endif /* sys/socketcall.h */
diff --git a/sysdeps/unix/sysv/linux/socketpair.S b/sysdeps/unix/sysv/linux/socketpair.S
deleted file mode 100644
index c954ad1..0000000
--- a/sysdeps/unix/sysv/linux/socketpair.S
+++ /dev/null
@@ -1,3 +0,0 @@
-#define	socket	socketpair
-#define	NARGS	4
-#include <socket.S>
diff --git a/sysdeps/unix/sysv/linux/socketpair.c b/sysdeps/unix/sysv/linux/socketpair.c
new file mode 100644
index 0000000..10ca7c0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/socketpair.c
@@ -0,0 +1,29 @@
+/* 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 <errno.h>
+#include <signal.h>
+#include <sys/socket.h>
+
+#include <socketcall.h>
+
+int
+__socketpair (int domain, int type, int protocol, int sv[2])
+{
+  return SOCKETCALL (socketpair, domain, type, protocol, sv, 0, 0);
+}
+weak_alias (__socketpair, socketpair)
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S b/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S
deleted file mode 100644
index 59c8164..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/socket.S
+++ /dev/null
@@ -1,116 +0,0 @@
-/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
-
-   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-cancel.h>
-#include <socketcall.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-#ifndef NARGS
-#ifdef socket
-#error NARGS not defined
-#endif
-#define NARGS 3
-#endif
-
-	.text
-/* The socket-oriented system calls are handled unusually in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.  */
-
-#ifndef __socket
-# ifndef NO_WEAK_ALIAS
-#  define __socket P(__,socket)
-# else
-#  define __socket socket
-# endif
-#endif
-
-	.globl		__syscall_error
-ENTRY (__socket)
-
-	/* Drop up to 6 arguments (recvfrom) into the memory allocated by
-	   the caller for varargs, since that's really what we have.  */
-	st %o0, [%sp + 68 + 0]
-	st %o1, [%sp + 68 + 4]
-#if NARGS > 2
-	st %o2, [%sp + 68 + 8]
-#if NARGS > 3
-	st %o3, [%sp + 68 + 12]
-#if NARGS > 4
-	st %o4, [%sp + 68 + 16]
-#if NARGS > 5
-	st %o5, [%sp + 68 + 20]
-#endif
-#endif
-#endif
-#endif
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	cmp %g1, 0
-	bne .Lsocket_cancel
-#endif
-	 mov P(SOCKOP_,socket), %o0	/* arg 1: socket subfunction */
-	add %sp, 68, %o1		/* arg 2: parameter block */
-	LOADSYSCALL(socketcall)
-	t 0x10
-	bcc 1f
-	 mov %o7, %g1
-	call __syscall_error
-	 mov %g1, %o7
-1:	jmpl %o7 + 8, %g0
-	 nop
-
-#if defined NEED_CANCELLATION && defined CENABLE
-.Lsocket_cancel:
-	save %sp, -96, %sp
-	cfi_def_cfa_register(%fp)
-	cfi_window_save
-	cfi_register(%o7, %i7)
-	CENABLE
-	 nop
-	mov %o0, %l0
-	add %sp, 68 + 96, %o1
-	mov P(SOCKOP_,socket), %o0
-	LOADSYSCALL(socketcall)
-	t 0x10
-	bcc 1f
-	 mov %o0, %l1
-	CDISABLE;
-	 mov %l0, %o0;
-	call __syscall_error;
-	 mov %l1, %o0;
-	b 1f
-	 mov -1, %l1;
-1:	CDISABLE
-	 mov %l0, %o0
-2:	jmpl %i7 + 8, %g0
-	 restore %g0, %l1, %o0
-#endif
-
-END (__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S b/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S
deleted file mode 100644
index b680165..0000000
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
-
-   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-cancel.h>
-#include <socketcall.h>
-
-#define P(a, b) P2(a, b)
-#define P2(a, b) a##b
-
-#ifndef NARGS
-#ifdef socket
-#error NARGS not defined
-#endif
-#define NARGS 3
-#endif
-
-	.text
-/* The socket-oriented system calls are handled unusually in Linux.
-   They are all gated through the single `socketcall' system call number.
-   `socketcall' takes two arguments: the first is the subcode, specifying
-   which socket function is being called; and the second is a pointer to
-   the arguments to the specific function.
-
-   The .S files for the other calls just #define socket and #include this.  */
-
-#ifndef __socket
-# ifndef NO_WEAK_ALIAS
-#  define __socket P(__,socket)
-# else
-#  define __socket socket
-# endif
-#endif
-
-	.globl	__syscall_error
-ENTRY(__socket)
-
-	/* Drop up to 6 arguments (recvfrom) into the memory allocated by
-	   the caller for varargs, since that's really what we have.  */
-	stx	%o0, [%sp + STACK_BIAS + 128 + 0]
-	stx	%o1, [%sp + STACK_BIAS + 128 + 8]
-#if NARGS > 2
-	stx	%o2, [%sp + STACK_BIAS + 128 + 16]
-#if NARGS > 3
-	stx	%o3, [%sp + STACK_BIAS + 128 + 24]
-#if NARGS > 4
-	stx	%o4, [%sp + STACK_BIAS + 128 + 32]
-#if NARGS > 5
-	stx	%o5, [%sp + STACK_BIAS + 128 + 40]
-#endif
-#endif
-#endif
-#endif
-
-#if defined NEED_CANCELLATION && defined CENABLE
-	SINGLE_THREAD_P
-	cmp	%g1, 0
-	bne	.Lsocket_cancel
-#endif
-	 mov	P(SOCKOP_,socket), %o0		/* arg 1: socket subfunction */
-	add	%sp, STACK_BIAS + 128, %o1	/* arg 2: parameter block */
-	LOADSYSCALL(socketcall)
-	ta	0x6d
-
-	bcc,pt	%xcc, 1f
-	 mov	%o7, %g1
-	call	__syscall_error
-	 mov	%g1, %o7
-1:	retl
-	 nop
-
-#if defined NEED_CANCELLATION && defined CENABLE
-.Lsocket_cancel:
-	save	%sp, -160, %sp
-	cfi_def_cfa_register (%fp)
-	cfi_window_save
-	cfi_register (%o7, %i7)
-	CENABLE
-	 nop
-	mov	%o0, %l0
-	add	%sp, 160 + STACK_BIAS + 128, %o1
-	mov	P(SOCKOP_,socket), %o0
-	LOADSYSCALL(socketcall)
-	ta	0x6d
-
-	bcc,pt	%xcc, 1f
-	 mov	%o0, %l1
-	CDISABLE;
-	 mov	%l0, %o0;
-	call	__syscall_error;
-	 mov	%l1, %o0;
-	ba,pt	%xcc, 2f
-	 mov	-1, %l1;
-1:	CDISABLE
-	 mov	%l0, %o0
-2:	jmpl	%i7 + 8, %g0
-	 restore %g0, %l1, %o0
-#endif
-
-END(__socket)
-
-#ifndef NO_WEAK_ALIAS
-weak_alias (__socket, socket)
-#endif

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=54144232eba9d0a5f8c3f8e59581e0b9513fd831

commit 54144232eba9d0a5f8c3f8e59581e0b9513fd831
Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
Date:   Wed Sep 24 13:38:59 2014 -0300

    Use inline syscalls for non-cancellable versions
    
    This patch uses inline calls (through INLINE_SYSCALL macro) to define
    the non-cancellable functions macros to avoid use of the
    syscall_nocancel entrypoint.

diff --git a/ChangeLog b/ChangeLog
index 05c23e7..528e575 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2015-05-11  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* sysdeps/unix/sysv/linux/not-cancel.h (open_not_cancel): Rewrite to
+	be an inline implementation regardless of library is built within.
+	(open_not_cancel_2): Likewise.
+	(__read_nocancel): Likewise.
+	(__write_nocancel): Likewise.
+	(openat_not_cancel): Likewise.
+	(openat_not_cancel_3): Likewise.
+	(openat64_not_cancel): Likewise.
+	(openat64_not_cancel_3): Likewise.
+	(__close_nocancel): Likewise.
+	(pause_not_cancel): Likewise.
+	(nanosleep_not_cancel): Likewise.
+	(sigsuspend_not_cancel): Likewise.
+
 2015-05-11  Andreas Schwab  <schwab@suse.de>
 
 	[BZ #18007]
diff --git a/sysdeps/unix/sysv/linux/not-cancel.h b/sysdeps/unix/sysv/linux/not-cancel.h
index 62d487f..8a358fd 100644
--- a/sysdeps/unix/sysv/linux/not-cancel.h
+++ b/sysdeps/unix/sysv/linux/not-cancel.h
@@ -17,48 +17,48 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#ifndef NOT_CANCEL_H
+# define NOT_CANCEL_H
+
 #include <sysdep.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/syscall.h>
 
-#if IS_IN (libc) || IS_IN (libpthread) || IS_IN (librt)
-extern int __open_nocancel (const char *, int, ...) attribute_hidden;
-extern int __close_nocancel (int) attribute_hidden;
-extern int __read_nocancel (int, void *, size_t) attribute_hidden;
-extern int __write_nocancel (int, const void *, size_t) attribute_hidden;
-extern pid_t __waitpid_nocancel (pid_t, int *, int) attribute_hidden;
-extern int __openat_nocancel (int fd, const char *fname, int oflag,
-				mode_t mode) attribute_hidden;
-extern int __openat64_nocancel (int fd, const char *fname, int oflag,
-				  mode_t mode) attribute_hidden;
+/* Uncancelable open.  */
+#ifdef __NR_open
+# define open_not_cancel(name, flags, mode) \
+   INLINE_SYSCALL (open, 3, name, flags, mode)
+# define open_not_cancel_2(name, flags) \
+   INLINE_SYSCALL (open, 2, name, flags)
 #else
-# define __open_nocancel(name, ...) __open (name, __VA_ARGS__)
-# define __close_nocancel(fd) __close (fd)
-# define __read_nocancel(fd, buf, len) __read (fd, buf, len)
-# define __write_nocancel(fd, buf, len) __write (fd, buf, len)
-# define __waitpid_nocancel(pid, stat_loc, options) \
-  __waitpid (pid, stat_loc, options)
-# define __openat_nocancel(fd, fname, oflag, mode) \
-  openat (fd, fname, oflag, mode)
-# define __openat64_nocancel(fd, fname, oflag, mode) \
-  openat64 (fd, fname, oflag, mode)
+# define open_not_cancel(name, flags, mode) \
+   INLINE_SYSCALL (openat, 4, AT_FDCWD, name, flags, mode)
+# define open_not_cancel_2(name, flags) \
+   INLINE_SYSCALL (openat, 3, AT_FDCWD, name, flags)
 #endif
 
-/* Uncancelable open.  */
-#define open_not_cancel(name, flags, mode) \
-   __open_nocancel (name, flags, mode)
-#define open_not_cancel_2(name, flags) \
-   __open_nocancel (name, flags)
+/* Uncancelable read.  */
+#define __read_nocancel(fd, buf, len) \
+  INLINE_SYSCALL (read, 3, fd, buf, len)
+
+/* Uncancelable write.  */
+#define __write_nocancel(fd, buf, len) \
+  INLINE_SYSCALL (write, 3, fd, buf, len)
 
 /* Uncancelable openat.  */
 #define openat_not_cancel(fd, fname, oflag, mode) \
-  __openat_nocancel (fd, fname, oflag, mode)
+  INLINE_SYSCALL (openat, 4, fd, fname, oflag, mode)
 #define openat_not_cancel_3(fd, fname, oflag) \
-  __openat_nocancel (fd, fname, oflag, 0)
+  INLINE_SYSCALL (openat, 3, fd, fname, oflag)
 #define openat64_not_cancel(fd, fname, oflag, mode) \
-  __openat64_nocancel (fd, fname, oflag, mode)
+  INLINE_SYSCALL (openat, 4, fd, fname, oflag | O_LARGEFILE, mode)
 #define openat64_not_cancel_3(fd, fname, oflag) \
-  __openat64_nocancel (fd, fname, oflag, 0)
+  INLINE_SYSCALL (openat, 3, fd, fname, oflag | O_LARGEFILE)
 
 /* Uncancelable close.  */
+#define __close_nocancel(fd) \
+  INLINE_SYSCALL (close, 1, fd)
 #define close_not_cancel(fd) \
   __close_nocancel (fd)
 #define close_not_cancel_no_status(fd) \
@@ -83,17 +83,27 @@ extern int __openat64_nocancel (int fd, const char *fname, int oflag,
   __fcntl_nocancel (fd, cmd, val)
 
 /* Uncancelable waitpid.  */
-#define waitpid_not_cancel(pid, stat_loc, options) \
+#define __waitpid_nocancel(pid, stat_loc, options) \
   INLINE_SYSCALL (wait4, 4, pid, stat_loc, options, NULL)
+#define waitpid_not_cancel(pid, stat_loc, options) \
+  __waitpid_nocancel(pid, stat_loc, options)
 
 /* Uncancelable pause.  */
 #define pause_not_cancel() \
-  __pause_nocancel ()
+  ({ sigset_t set; 							     \
+     int __rc = INLINE_SYSCALL (rt_sigprocmask, 4, SIG_BLOCK, NULL, &set,    \
+				_NSIG / 8);				     \
+     if (__rc == 0)							     \
+       __rc = INLINE_SYSCALL (rt_sigsuspend, 2, &set, _NSIG / 8);	     \
+     __rc;								     \
+  })
 
 /* Uncancelable nanosleep.  */
 #define nanosleep_not_cancel(requested_time, remaining) \
-  __nanosleep_nocancel (requested_time, remaining)
+  INLINE_SYSCALL (nanosleep, 2, requested_time, remaining)
 
 /* Uncancelable sigsuspend.  */
 #define sigsuspend_not_cancel(set) \
-  __sigsuspend_nocancel (set)
+  INLINE_SYSCALL (rt_sigsuspend, 2, set, _NSIG / 8)
+
+#endif /* NOT_CANCEL_H  */
diff --git a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
index 5b6bb51..3578ea8 100644
--- a/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
+++ b/sysdeps/unix/sysv/linux/powerpc/get_clockfreq.c
@@ -41,7 +41,7 @@ __get_clockfreq (void)
      contains at least one line like:
      timebase        : 33333333
      We search for this line and convert the number into an integer.  */
-  int fd = __open_nocancel ("/proc/cpuinfo", O_RDONLY);
+  int fd = open_not_cancel_2 ("/proc/cpuinfo", O_RDONLY);
   if (__glibc_likely (fd != -1))
     return result;
 

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]