From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13797 invoked by alias); 17 Jun 2003 22:03:04 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 13750 invoked from network); 17 Jun 2003 22:03:03 -0000 Received: from unknown (HELO localhost.localdomain) (195.113.19.66) by sources.redhat.com with SMTP; 17 Jun 2003 22:03:03 -0000 Received: from sunsite.ms.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by localhost.localdomain (8.12.8/8.12.8) with ESMTP id h5HM30qO018465; Wed, 18 Jun 2003 00:03:00 +0200 Received: (from jakub@localhost) by sunsite.ms.mff.cuni.cz (8.12.8/8.12.8/Submit) id h5HM30ZK018457; Wed, 18 Jun 2003 00:03:00 +0200 Date: Tue, 17 Jun 2003 22:03:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] cancellation support in librt for linuxthreads Message-ID: <20030617220300.GM20507@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2003-06/txt/msg00034.txt.bz2 Hi! Seems to work on all the arches I've tried (all those changed with exception of sparc*, but that one should be obvious ;) ). 2003-06-18 Jakub Jelinek * internals.h (__librt_multiple_threads, __librt_enable_asynccancel, __librt_disable_asynccancel): Declare. (LIBC_CANCEL_ASYNC, LIBC_CANCEL_RESET, LIBC_CANCEL_HANDLED): Define for IS_IN_librt. * sysdeps/unix/sysv/linux/i386/sysdep-cancel.h: Support cancellation in librt. * sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h: Likewise. * sysdeps/x86_64/tcb-offsets.sym: New file. * sysdeps/x86_64/Makefile: New file. * sysdeps/x86_64/tls.h (tcbhead_t): Add multiple_threads. * Versions (libc): Export __librt_enable_asynccancel, __librt_disable_asynccancel and __librt_multiple_threads as GLIBC_PRIVATE. * libc-cancellation.c (__librt_multiple_threads, __librt_enable_asynccancel, __librt_disable_asynccancel): New aliases. --- libc/linuxthreads/internals.h.jj 2003-04-23 14:11:51.000000000 -0400 +++ libc/linuxthreads/internals.h 2003-06-17 09:45:07.000000000 -0400 @@ -257,6 +257,7 @@ static inline int nonexisting_handle(pth /* Defined and used in libc.so. */ extern int __libc_multiple_threads attribute_hidden; +extern int __librt_multiple_threads; /* Debugging */ @@ -468,6 +469,10 @@ extern int __libc_enable_asynccancel (vo extern void __libc_disable_asynccancel (int oldtype) internal_function attribute_hidden; +/* The two functions are in libc.so and are exported. */ +extern int __librt_enable_asynccancel (void); +extern void __librt_disable_asynccancel (int oldtype) internal_function; + extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe) attribute_hidden; extern pid_t __pthread_fork (struct fork_block *b) attribute_hidden; @@ -480,7 +485,7 @@ extern pid_t __pthread_fork (struct fork # define LIBC_CANCEL_HANDLED() \ __asm (".globl " __SYMBOL_PREFIX "__libc_enable_asynccancel"); \ __asm (".globl " __SYMBOL_PREFIX "__libc_disable_asynccancel") -#elif defined NOT_IN_libc && defined IS_IN_libpthread +#elif defined IS_IN_libpthread # define LIBC_CANCEL_ASYNC() \ __pthread_enable_asynccancel () # define LIBC_CANCEL_RESET(oldtype) \ @@ -488,6 +493,14 @@ extern pid_t __pthread_fork (struct fork # define LIBC_CANCEL_HANDLED() \ __asm (".globl " __SYMBOL_PREFIX "__pthread_enable_asynccancel"); \ __asm (".globl " __SYMBOL_PREFIX "__pthread_disable_asynccancel") +#elif defined IS_IN_librt +# define LIBC_CANCEL_ASYNC() \ + __librt_enable_asynccancel () +# define LIBC_CANCEL_RESET(oldtype) \ + __librt_disable_asynccancel (oldtype) +# 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. */ --- libc/linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h.jj 2003-04-14 07:11:23.000000000 -0400 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/i386/sysdep-cancel.h 2003-06-17 09:57:30.000000000 -0400 @@ -24,7 +24,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -108,8 +108,10 @@ #if !defined NOT_IN_libc # define __local_multiple_threads __libc_multiple_threads -#else +#elif defined IS_IN_libpthread # define __local_multiple_threads __pthread_multiple_threads +#else +# define __local_multiple_threads __librt_multiple_threads #endif # ifndef __ASSEMBLER__ @@ -118,7 +120,12 @@ __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ p_header.data.multiple_threads) == 0, 1) # else -extern int __local_multiple_threads attribute_hidden; +extern int __local_multiple_threads +# if !defined NOT_IN_libc || defined IS_IN_libpthread + attribute_hidden; +# else + ; +# endif # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # endif # else @@ -127,16 +134,23 @@ extern int __local_multiple_threads attr # elif defined FLOATING_STACKS && USE___THREAD # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET # else -# if !defined HAVE_HIDDEN || !USE___THREAD +# if !defined NOT_IN_libc || defined IS_IN_libpthread +# define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx) +# else +# define __SINGLE_THREAD_CMP \ + movl __local_multiple_threads@GOT(%ecx), %ecx;\ + cmpl $0, (%ecx) +# endif +# if !defined HAVE_HIDDEN || !USE___THREAD # define SINGLE_THREAD_P \ SETUP_PIC_REG (cx); \ addl $_GLOBAL_OFFSET_TABLE_, %ecx; \ - cmpl $0, __local_multiple_threads@GOTOFF(%ecx) + __SINGLE_THREAD_CMP # else # define SINGLE_THREAD_P \ call __i686.get_pc_thunk.cx; \ addl $_GLOBAL_OFFSET_TABLE_, %ecx; \ - cmpl $0, __local_multiple_threads@GOTOFF(%ecx) + __SINGLE_THREAD_CMP # endif # endif # endif --- libc/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h.jj 2003-04-29 07:19:32.000000000 -0400 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/ia64/sysdep-cancel.h 2003-06-17 10:17:02.000000000 -0400 @@ -23,7 +23,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -85,9 +85,12 @@ __syscall_error_##args: \ # ifdef IS_IN_libpthread # define CENABLE br.call.sptk.many b0 = __pthread_enable_asynccancel # define CDISABLE br.call.sptk.many b0 = __pthread_disable_asynccancel -# else +# elif !defined NOT_IN_libc # define CENABLE br.call.sptk.many b0 = __libc_enable_asynccancel # define CDISABLE br.call.sptk.many b0 = __libc_disable_asynccancel +# else +# define CENABLE br.call.sptk.many b0 = __librt_enable_asynccancel +# define CDISABLE br.call.sptk.many b0 = __librt_disable_asynccancel # endif #define COPY_ARGS_0 /* Nothing */ --- libc/linuxthreads/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h.jj 2003-01-14 10:01:31.000000000 -0500 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h 2003-06-17 10:29:45.000000000 -0400 @@ -23,7 +23,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -62,9 +62,12 @@ L(pseudo_end): # ifdef IS_IN_libpthread # define CENABLE __pthread_enable_asynccancel # define CDISABLE __pthread_disable_asynccancel -# else +# elif !defined NOT_IN_libc # define CENABLE __libc_enable_asynccancel # define CDISABLE __libc_disable_asynccancel +# else +# define CENABLE __librt_enable_asynccancel +# define CDISABLE __librt_disable_asynccancel # endif #define STM_0 /* Nothing */ --- libc/linuxthreads/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h.jj 2003-01-30 05:01:47.000000000 -0500 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/s390/s390-64/sysdep-cancel.h 2003-06-17 10:39:36.000000000 -0400 @@ -23,7 +23,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -58,10 +58,13 @@ L(pseudo_end): # define CENABLE __pthread_enable_asynccancel # define CDISABLE __pthread_disable_asynccancel # define __local_multiple_threads __pthread_multiple_threads -# else +# elif !defined NOT_IN_libc # define CENABLE __libc_enable_asynccancel # define CDISABLE __libc_disable_asynccancel # define __local_multiple_threads __libc_multiple_threads +# else +# define CENABLE __librt_enable_asynccancel +# define CDISABLE __librt_disable_asynccancel # endif #define STM_0 /* Nothing */ @@ -78,14 +81,31 @@ L(pseudo_end): #define LM_4 lmg %r2,%r5,16+160(%r15); #define LM_5 lmg %r2,%r5,16+160(%r15); -# ifndef __ASSEMBLER__ +# if !defined NOT_IN_libc || defined IS_IN_libpthread +# ifndef __ASSEMBLER__ extern int __local_multiple_threads attribute_hidden; -# define SINGLE_THREAD_P \ +# define SINGLE_THREAD_P \ __builtin_expect (__local_multiple_threads == 0, 1) -# else -# define SINGLE_THREAD_P \ +# else +# define SINGLE_THREAD_P \ larl %r1,__local_multiple_threads; \ icm %r0,15,0(%r1); +# endif + +# else + +# ifndef __ASSEMBLER__ +# define SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + p_header.data.multiple_threads) == 0, 1) +# else +# define SINGLE_THREAD_P \ + ear %r1,%a0; \ + sllg %r1,%r1,32; \ + ear %r1,%a1; \ + icm %r1,15,MULTIPLE_THREADS_OFFSET(%r1); +# endif + # endif #elif !defined __ASSEMBLER__ --- libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h.jj 2003-01-30 05:01:47.000000000 -0500 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc32/sysdep-cancel.h 2003-06-17 10:44:54.000000000 -0400 @@ -23,7 +23,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -68,9 +68,12 @@ SYSCALL_ERROR_HANDLER_ENTRY(__syscall_er # ifdef IS_IN_libpthread # define CENABLE call __pthread_enable_asynccancel # define CDISABLE call __pthread_disable_asynccancel -# else +# elif defined !NOT_IN_libc # define CENABLE call __libc_enable_asynccancel # define CDISABLE call __libc_disable_asynccancel +# else +# define CENABLE call __librt_enable_asynccancel +# define CDISABLE call __librt_disable_asynccancel # endif #define COPY_ARGS_0 /* Nothing */ --- libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h.jj 2003-02-22 17:53:59.000000000 -0500 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/sparc/sparc64/sysdep-cancel.h 2003-06-17 10:44:37.000000000 -0400 @@ -23,7 +23,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -67,9 +67,12 @@ SYSCALL_ERROR_HANDLER_ENTRY(__syscall_er # ifdef IS_IN_libpthread # define CENABLE call __pthread_enable_asynccancel # define CDISABLE call __pthread_disable_asynccancel -# else +# elif !defined NOT_IN_libc # define CENABLE call __libc_enable_asynccancel # define CDISABLE call __libc_disable_asynccancel +# else +# define CENABLE call __librt_enable_asynccancel +# define CDISABLE call __librt_disable_asynccancel # endif #define COPY_ARGS_0 /* Nothing */ --- libc/linuxthreads/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h.jj 2003-06-04 14:23:06.000000000 -0400 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/x86_64/sysdep-cancel.h 2003-06-17 11:04:01.000000000 -0400 @@ -24,7 +24,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -94,18 +94,34 @@ # define CENABLE call __pthread_enable_asynccancel; # define CDISABLE call __pthread_disable_asynccancel; # define __local_multiple_threads __pthread_multiple_threads -# else +# elif !defined NOT_IN_libc # define CENABLE call __libc_enable_asynccancel; # define CDISABLE call __libc_disable_asynccancel; # define __local_multiple_threads __libc_multiple_threads +# else +# define CENABLE call __librt_enable_asynccancel@plt; +# define CDISABLE call __librt_disable_asynccancel@plt; # endif -# ifndef __ASSEMBLER__ +# if defined IS_IN_libpthread || !defined NOT_IN_libc +# ifndef __ASSEMBLER__ extern int __local_multiple_threads attribute_hidden; # define SINGLE_THREAD_P \ __builtin_expect (__local_multiple_threads == 0, 1) +# else +# define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip) +# endif + # else -# define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip) + +# ifndef __ASSEMBLER__ +# define SINGLE_THREAD_P \ + __builtin_expect (THREAD_GETMEM (THREAD_SELF, \ + p_header.data.multiple_threads) == 0, 1) +# else +# define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET +# endif + # endif #elif !defined __ASSEMBLER__ --- libc/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h.jj 2003-04-29 07:19:32.000000000 -0400 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep-cancel.h 2003-06-17 10:24:14.000000000 -0400 @@ -23,7 +23,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -78,9 +78,12 @@ # ifdef IS_IN_libpthread # define CENABLE bl JUMPTARGET(__pthread_enable_asynccancel) # define CDISABLE bl JUMPTARGET(__pthread_disable_asynccancel) -# else +# elif !defined NOT_IN_libc # define CENABLE bl JUMPTARGET(__libc_enable_asynccancel) # define CDISABLE bl JUMPTARGET(__libc_disable_asynccancel) +# else +# define CENABLE bl JUMPTARGET(__librt_enable_asynccancel) +# define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel) # endif # ifndef __ASSEMBLER__ --- libc/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h.jj 2003-06-16 14:26:10.000000000 -0400 +++ libc/linuxthreads/sysdeps/unix/sysv/linux/powerpc/powerpc64/sysdep-cancel.h 2003-06-17 10:27:52.000000000 -0400 @@ -22,7 +22,7 @@ # include #endif -#if !defined NOT_IN_libc || defined IS_IN_libpthread +#if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt # undef PSEUDO # define PSEUDO(name, syscall_name, args) \ @@ -78,14 +78,23 @@ # define CENABLE bl JUMPTARGET(__pthread_enable_asynccancel) # define CDISABLE bl JUMPTARGET(__pthread_disable_asynccancel) # define __local_multiple_threads __pthread_multiple_threads -# else +# elif !defined NOT_IN_libc # define CENABLE bl JUMPTARGET(__libc_enable_asynccancel) # define CDISABLE bl JUMPTARGET(__libc_disable_asynccancel) # define __local_multiple_threads __libc_multiple_threads +# else +# define CENABLE bl JUMPTARGET(__librt_enable_asynccancel); nop +# define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel); nop +# define __local_multiple_threads __librt_multiple_threads # endif # ifndef __ASSEMBLER__ -extern int __local_multiple_threads attribute_hidden; +extern int __local_multiple_threads +# if !defined NOT_IN_libc || defined IS_IN_libpthread + attribute_hidden; +# else + ; +# endif # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1) # else # define SINGLE_THREAD_P \ --- libc/linuxthreads/sysdeps/x86_64/tcb-offsets.sym.jj 2003-06-17 10:46:05.000000000 -0400 +++ libc/linuxthreads/sysdeps/x86_64/tcb-offsets.sym 2003-06-17 10:46:33.000000000 -0400 @@ -0,0 +1,4 @@ +#include +#include + +MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) --- libc/linuxthreads/sysdeps/x86_64/Makefile.jj 2003-06-17 10:46:15.000000000 -0400 +++ libc/linuxthreads/sysdeps/x86_64/Makefile 2003-06-17 10:46:23.000000000 -0400 @@ -0,0 +1,3 @@ +ifeq ($(subdir),csu) +gen-as-const-headers += tcb-offsets.sym +endif --- libc/linuxthreads/sysdeps/x86_64/tls.h.jj 2002-12-28 06:29:35.000000000 -0500 +++ libc/linuxthreads/sysdeps/x86_64/tls.h 2003-06-17 10:47:00.000000000 -0400 @@ -39,6 +39,7 @@ typedef struct thread descriptor used by libpthread. */ dtv_t *dtv; void *self; /* Pointer to the thread descriptor. */ + int multiple_threads; } tcbhead_t; #endif --- libc/linuxthreads/Versions.jj 2003-03-20 05:58:49.000000000 -0500 +++ libc/linuxthreads/Versions 2003-06-17 09:46:38.000000000 -0400 @@ -31,7 +31,8 @@ libc { __libc_creat; __libc_poll; __libc_pselect; __libc_select; __libc_sigpause; __libc_sigsuspend; __libc_sigwait; __libc_sigwaitinfo; - __libc_waitid; __libc___xpg_sigpause; + __libc_waitid; __libc___xpg_sigpause; __librt_enable_asynccancel; + __librt_disable_asynccancel; __librt_multiple_threads; } } --- libc/linuxthreads/libc-cancellation.c.jj 2003-01-03 08:06:37.000000000 -0500 +++ libc/linuxthreads/libc-cancellation.c 2003-06-17 09:46:22.000000000 -0400 @@ -31,7 +31,8 @@ weak_extern (__pthread_do_exit) # endif -int __libc_multiple_threads attribute_hidden; +int __libc_multiple_threads attribute_hidden __attribute__((nocommon)); +strong_alias (__libc_multiple_threads, __librt_multiple_threads); /* The next two functions are similar to pthread_setcanceltype() but more specialized for the use in the cancelable functions like write(). @@ -49,6 +50,7 @@ __libc_enable_asynccancel (void) (PTHREAD_CANCELED, CURRENT_STACK_FRAME), 0); return oldtype; } +strong_alias (__libc_enable_asynccancel, __librt_enable_asynccancel) void internal_function attribute_hidden @@ -57,5 +59,6 @@ __libc_disable_asynccancel (int oldtype) pthread_descr self = thread_self(); LIBC_THREAD_SETMEM(self, p_canceltype, oldtype); } +strong_alias (__libc_disable_asynccancel, __librt_disable_asynccancel) #endif Jakub