diff options
| author | Ulrich Drepper <drepper@redhat.com> | 2003-06-08 05:28:14 +0000 |
|---|---|---|
| committer | Ulrich Drepper <drepper@redhat.com> | 2003-06-08 05:28:14 +0000 |
| commit | 7726edc27354afe163f492c0e6a8d4354fddb494 (patch) | |
| tree | 22a712872298767abf2b081d9f766a33cad8fa20 | |
| parent | ede0f73aeabe62589f6ca19a6987f48aa0d06184 (diff) | |
| download | glibc-7726edc27354afe163f492c0e6a8d4354fddb494.tar.xz glibc-7726edc27354afe163f492c0e6a8d4354fddb494.zip | |
Update.
2003-06-07 Ulrich Drepper <drepper@redhat.com>
* cleanup_routine.c: New file.
* Versions (libpthread) [GLIBC_2.3.3]: Add __pthread_cleanup_routine.
* sysdeps/pthread/pthread.h: Add support for fully exception-based
cleanup handling.
* Makefile (libpthread-routines): Add cleanup_routine.
Add more CFLAGS variables to compile with exceptions. Add comments
why which file needs unwind tables.
(tests) [have-forced-unwind==yes]: Add tst-cancelx* and tst-cleanupx*
tests.
* tst-cancelx1.c: New file.
* tst-cancelx2.c: New file.
* tst-cancelx3.c: New file.
* tst-cancelx4.c: New file.
* tst-cancelx5.c: New file.
* tst-cancelx6.c: New file.
* tst-cancelx7.c: New file.
* tst-cancelx8.c: New file.
* tst-cancelx9.c: New file.
* tst-cancelx10.c: New file.
* tst-cancelx11.c: New file.
* tst-cancelx12.c: New file.
* tst-cancelx13.c: New file.
* tst-cancelx14.c: New file.
* tst-cancelx15.c: New file.
* tst-cleanupx0.c: New file.
* tst-cleanupx0.expect: New file.
* tst-cleanupx1.c: New file.
* tst-cleanupx2.c: New file.
* tst-cleanupx3.c: New file.
* tst-cleanup0.c: Make standard compliant.
* tst-cleanup1.c: Likewise.
* sysdeps/unix/sysv/linux/sem_timedwait.c: Add cancellation support.
* sysdeps/unix/sysv/linux/sem_wait.c: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Likewise.
* sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Likewise.
* sysdeps/i386/tcb-offsets.sym: Add RESULT, CANCELHANDLING, and
CLEANUP_JMP_BUF.
* sysdeps/x86_64/tcb-offsets.sym: Likewise.
* tst-cancel12.c: New file.
* tst-cancel13.c: New file.
* tst-cancel14.c: New file.
* tst-cancel15.c: New file.
* Makefile (tests): Add tst-cancel12, tst-cancel13, tst-cancel14,
and tst-cancel15.
* tst-cancel1.c: Add some comments.
* sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Compute relative
timeout correctly.
40 files changed, 1099 insertions, 71 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 0d0c5682a6..aa18be29a2 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,59 @@ +2003-06-07 Ulrich Drepper <drepper@redhat.com> + + * cleanup_routine.c: New file. + * Versions (libpthread) [GLIBC_2.3.3]: Add __pthread_cleanup_routine. + * sysdeps/pthread/pthread.h: Add support for fully exception-based + cleanup handling. + * Makefile (libpthread-routines): Add cleanup_routine. + Add more CFLAGS variables to compile with exceptions. Add comments + why which file needs unwind tables. + (tests) [have-forced-unwind==yes]: Add tst-cancelx* and tst-cleanupx* + tests. + * tst-cancelx1.c: New file. + * tst-cancelx2.c: New file. + * tst-cancelx3.c: New file. + * tst-cancelx4.c: New file. + * tst-cancelx5.c: New file. + * tst-cancelx6.c: New file. + * tst-cancelx7.c: New file. + * tst-cancelx8.c: New file. + * tst-cancelx9.c: New file. + * tst-cancelx10.c: New file. + * tst-cancelx11.c: New file. + * tst-cancelx12.c: New file. + * tst-cancelx13.c: New file. + * tst-cancelx14.c: New file. + * tst-cancelx15.c: New file. + * tst-cleanupx0.c: New file. + * tst-cleanupx0.expect: New file. + * tst-cleanupx1.c: New file. + * tst-cleanupx2.c: New file. + * tst-cleanupx3.c: New file. + + * tst-cleanup0.c: Make standard compliant. + * tst-cleanup1.c: Likewise. + + * sysdeps/unix/sysv/linux/sem_timedwait.c: Add cancellation support. + * sysdeps/unix/sysv/linux/sem_wait.c: Likewise. + * sysdeps/unix/sysv/linux/i386/i486/sem_timedwait.S: Likewise. + * sysdeps/unix/sysv/linux/i386/i486/sem_wait.S: Likewise. + * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise. + * sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Likewise. + * sysdeps/i386/tcb-offsets.sym: Add RESULT, CANCELHANDLING, and + CLEANUP_JMP_BUF. + * sysdeps/x86_64/tcb-offsets.sym: Likewise. + * tst-cancel12.c: New file. + * tst-cancel13.c: New file. + * tst-cancel14.c: New file. + * tst-cancel15.c: New file. + * Makefile (tests): Add tst-cancel12, tst-cancel13, tst-cancel14, + and tst-cancel15. + + * tst-cancel1.c: Add some comments. + + * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Compute relative + timeout correctly. + 2003-06-06 Ulrich Drepper <drepper@redhat.com> * Makefile (CFLAGS-pthread_cancel.c): Define. diff --git a/nptl/Makefile b/nptl/Makefile index 78d05f45e3..74ede7775b 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -116,7 +116,8 @@ libpthread-routines = init events version \ sigaction \ herrno res pt-allocrtsig \ pthread_kill_other_threads \ - pthread_getaffinity pthread_setaffinity + pthread_getaffinity pthread_setaffinity \ + cleanup_routine libpthread-shared-only-routines = version pt-allocrtsig libpthread-static-only-routines = pthread_atfork @@ -124,16 +125,41 @@ libpthread-static-only-routines = pthread_atfork libpthread-nonshared = pthread_atfork CFLAGS-pthread_atfork.c = -DNOT_IN_libc + +# Since cancellation handling is in large parts handled using exceptions +# we have to compile some files with exception handling enabled, some +# even with asynchronous unwind tables. + +# init.c contains sigcancel_handler(). CFLAGS-init.c = -fexceptions -fasynchronous-unwind-tables +# The unwind code itself, CFLAGS-unwind.c = -fexceptions + +# The following three functions must be async-cancel safe. +CFLAGS-pthread_cancel.c = -fexceptions -fasynchronous-unwind-tables +CFLAGS-pthread_setcancelstate.c = -fexceptions -fasynchronous-unwind-tables +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 +# be executed. Therefore exceptions have to be thrown through this +# function. +CFLAGS-pthread_exit.c = -fexceptions + +# The following are cancellation points. Some of the functions can +# block and therefore temporarily enable asynchronous cancellation. +# Those must be compiled asynchronous unwind tables. CFLAGS-pthread_testcancel.c = -fexceptions CFLAGS-pthread_join.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-pthread_timedjoin.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-pthread_cond_wait.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-pthread_cond_timedwait.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-pthread_cancel.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-cancellation.c = -fasynchronous-unwind-tables -CFLAGS-libc-cancellation.c = -fasynchronous-unwind-tables +CFLAGS-sem_wait.c = -fexceptions -fasynchronous-unwind-tables +CFLAGS-sem_timedwait.c = -fexceptions -fasynchronous-unwind-tables # Don't generate deps for calls with no sources. See sysdeps/unix/Makefile. omit-deps = $(unix-syscalls:%=ptw-%) @@ -165,7 +191,7 @@ tests = tst-attr1 tst-attr2 \ tst-atfork1 \ tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \ tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \ - tst-cancel11 \ + tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \ tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 \ tst-flock1 tst-flock2 \ tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \ @@ -192,6 +218,12 @@ LDFLAGS-pthread.so = -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst include ../Makeconfig +ifeq ($(have-forced-unwind),yes) +tests += tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx5 \ + tst-cancelx6 tst-cancelx7 tst-cancelx8 tst-cancelx9 tst-cancelx10 \ + tst-cancelx11 tst-cancelx12 tst-cancelx13 tst-cancelx14 tst-cancelx15\ + tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3 +endif ifeq ($(build-shared),yes) tests += tst-atfork2 tst-tls3 endif @@ -292,6 +324,23 @@ CFLAGS-pthread_self.os += -fomit-frame-pointer CFLAGS-tst-unload.c += -DPREFIX=\"$(objpfx)\" +# Run the cancellation and cleanup tests also for the modern, exception-based +# implementation. For this we have to pass the -fexceptions parameter. +CFLAGS-tst-cancelx2.c += -fexceptions +CFLAGS-tst-cancelx3.c += -fexceptions +CFLAGS-tst-cancelx4.c += -fexceptions +CFLAGS-tst-cancelx5.c += -fexceptions +CFLAGS-tst-cancelx6.c += -fexceptions +CFLAGS-tst-cancelx7.c += -fexceptions +CFLAGS-tst-cancelx8.c += -fexceptions +CFLAGS-tst-cancelx9.c += -fexceptions +CFLAGS-tst-cancelx10.c += -fexceptions +CFLAGS-tst-cancelx11.c += -fexceptions +CFLAGS-tst-cleanupx0.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-tst-cleanupx1.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-tst-cleanupx2.c += -fexceptions +CFLAGS-tst-cleanupx3.c += -fexceptions + tst-cancel7-ARGS = --command "$(built-program-cmd)" tst-umask1-ARGS = $(objpfx)tst-umask1.temp diff --git a/nptl/Versions b/nptl/Versions index c602d5e048..a8fa3c85e8 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -216,6 +216,7 @@ libpthread { __pthread_register_cancel; __pthread_unregister_cancel; __pthread_register_cancel_defer; __pthread_unregister_cancel_restore; __pthread_unwind_next; + __pthread_cleanup_routine; # New affinity interfaces. pthread_getaffinity_np; pthread_setaffinity_np; diff --git a/nptl/cleanup_routine.c b/nptl/cleanup_routine.c new file mode 100644 index 0000000000..cbf2318343 --- /dev/null +++ b/nptl/cleanup_routine.c @@ -0,0 +1,28 @@ +/* Copyright (C) 2003 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, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <pthread.h> + + +void +__pthread_cleanup_routine (struct __pthread_cleanup_frame *f) +{ + if (f->__do_it) + f->__cancel_routine (f->__cancel_arg); +} diff --git a/nptl/sysdeps/i386/tcb-offsets.sym b/nptl/sysdeps/i386/tcb-offsets.sym index 12cb6f00f9..a83c3c9a9b 100644 --- a/nptl/sysdeps/i386/tcb-offsets.sym +++ b/nptl/sysdeps/i386/tcb-offsets.sym @@ -1,7 +1,10 @@ #include <sysdep.h> #include <tls.h> +RESULT offsetof (struct pthread, result) TID offsetof (struct pthread, tid) +CANCELHANDLING offsetof (struct pthread, cancelhandling) +CLEANUP_JMP_BUF offsetof (struct pthread, cleanup_jmp_buf) MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) SYSINFO_OFFSET offsetof (tcbhead_t, sysinfo) CLEANUP offsetof (struct pthread, cleanup) diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h index c0375ae223..1f0a34baa2 100644 --- a/nptl/sysdeps/pthread/pthread.h +++ b/nptl/sysdeps/pthread/pthread.h @@ -419,14 +419,132 @@ typedef struct #endif +/* Structure to hold the cleanup handler information. */ +struct __pthread_cleanup_frame +{ + void (*__cancel_routine) (void *); + void *__cancel_arg; + int __do_it; + int __cancel_type; +}; + +#if defined __GNUC__ && defined __EXCEPTIONS +# ifdef __cplusplus +/* Class to handle cancellation handler invocation. */ +class __pthread_cleanup_class +{ + void (*__cancel_routine) (void *); + void *__cancel_arg; + int __do_it; + int __cancel_type; + + public: + __pthread_cleanup_class (void (*__fct) (void *), void *__arg) + : __cancel_routine (__fct), __cancel_arg (__arg), __do_it (1) { } + ~__pthread_cleanup_class () { if (__do_it) __cancel_routine (__cancel_arg); } + __setdoit (int __newval) { __do_it = __newval; } + __defer () { pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, + &__cancel_type); + __restore () const { pthread_setcanceltype (__cancel_type, 0); +}; + +/* Install a cleanup handler: ROUTINE will be called with arguments ARG + when the thread is canceled or calls pthread_exit. ROUTINE will also + be called with arguments ARG when the matching pthread_cleanup_pop + is executed with non-zero EXECUTE argument. + + pthread_cleanup_push and pthread_cleanup_pop are macros and must always + be used in matching pairs at the same nesting level of braces. */ +# define pthread_cleanup_push(routine, arg) \ + do { \ + __pthread_cleanup_class __clframe (routine, arg) + +/* Remove a cleanup handler installed by the matching pthread_cleanup_push. + If EXECUTE is non-zero, the handler function is called. */ +# define pthread_cleanup_pop(execute) \ + __clframe.__setdoit (execute); \ + } while (0) + +# ifdef __USE_GNU +/* Install a cleanup handler as pthread_cleanup_push does, but also + saves the current cancellation type and sets it to deferred + cancellation. */ +# define pthread_cleanup_push_defer_np(routine, arg) \ + do { \ + __pthread_cleanup_class __clframe (routine, arg); \ + __clframe.__defer () + +/* Remove a cleanup handler as pthread_cleanup_pop does, but also + restores the cancellation type that was in effect when the matching + pthread_cleanup_push_defer was called. */ +# define pthread_cleanup_pop_restore_np(execute) \ + __clframe.__restore (); \ + __clframe.__setdoit (execute); \ + } while (0) +# endif +# else +/* Function called to call the cleanup handler. As an extern inline + function the compiler is free to decide inlining the change when + needed or fall back on the copy which must exist somewhere + else. */ +extern inline void +__pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) +{ + if (__frame->__do_it) + __frame->__cancel_routine (__frame->__cancel_arg); +} + /* Install a cleanup handler: ROUTINE will be called with arguments ARG - when the thread is cancelled or calls pthread_exit. ROUTINE will also + when the thread is canceled or calls pthread_exit. ROUTINE will also be called with arguments ARG when the matching pthread_cleanup_pop is executed with non-zero EXECUTE argument. pthread_cleanup_push and pthread_cleanup_pop are macros and must always be used in matching pairs at the same nesting l |
