Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ulrich Drepper committed Jun 8, 2003
1 parent ede0f73 commit 7726edc
Show file tree
Hide file tree
Showing 40 changed files with 1,099 additions and 71 deletions.
56 changes: 56 additions & 0 deletions 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.
Expand Down
59 changes: 54 additions & 5 deletions nptl/Makefile
Expand Up @@ -116,24 +116,50 @@ 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

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-%)
Expand Down Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions nptl/Versions
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions 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);
}
3 changes: 3 additions & 0 deletions 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)
Expand Down
137 changes: 128 additions & 9 deletions nptl/sysdeps/pthread/pthread.h
Expand Up @@ -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 level of braces. */
#define pthread_cleanup_push(routine, arg) \
# define pthread_cleanup_push(routine, arg) \
do { \
struct __pthread_cleanup_frame __clframe \
__attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
= { .__cancel_routine = (routine), .__cancel_arg = (arg), \
.__do_it = 1 };

/* 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.__do_it = (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 { \
struct __pthread_cleanup_frame __clframe \
__attribute__ ((__cleanup__ (__pthread_cleanup_routine))) \
= { .__cancel_routine = (routine), .__cancel_arg = (arg), \
.__do_it = 1 }; \
(void) pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED, \
&__clframe.__cancel_type)

/* 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) \
(void) pthread_setcanceltype (__clframe.__cancel_type, NULL); \
__clframe.__do_it = (execute); \
} while (0)
# endif
# endif
#else
/* 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_unwind_buf_t __cancel_buf; \
void (*__cancel_routine) (void *) = (routine); \
Expand All @@ -447,7 +565,7 @@ extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)

/* 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) \
# define pthread_cleanup_pop(execute) \
} while (0); \
__pthread_unregister_cancel (&__cancel_buf); \
if (execute) \
Expand All @@ -456,11 +574,11 @@ extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf)
extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
__cleanup_fct_attribute;

#ifdef __USE_GNU
# 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(routine, arg) \
# define pthread_cleanup_push_defer_np(routine, arg) \
do { \
__pthread_unwind_buf_t __cancel_buf; \
void (*__cancel_routine) (void *) = (routine); \
Expand All @@ -482,23 +600,24 @@ extern void __pthread_register_cancel_defer (__pthread_unwind_buf_t *__buf)
/* 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_cleanup(execute) \
# define pthread_cleanup_pop_restore_np(execute) \
} while (0); \
__pthread_unregister_cancel_restore (&__cancel_buf); \
if (execute) \
__cancel_routine (__cancel_arg); \
} while (0)
extern void __pthread_unregister_cancel_restore (__pthread_unwind_buf_t *__buf)
__cleanup_fct_attribute;
#endif
# endif

/* Internal interface to initiate cleanup. */
extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf)
__cleanup_fct_attribute __attribute ((__noreturn__))
#ifndef SHARED
# ifndef SHARED
__attribute ((__weak__))
#endif
# endif
;
#endif

/* Function used in the macros. */
struct __jmp_buf_tag;
Expand Down

0 comments on commit 7726edc

Please sign in to comment.