diff options
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 10 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S | 93 | ||||
-rw-r--r-- | nptl/tst-once3.c | 37 | ||||
-rw-r--r-- | nptl/tst-once4.c | 44 | ||||
-rw-r--r-- | nptl/tst-oncex3.c | 1 | ||||
-rw-r--r-- | nptl/tst-oncex4.c | 1 |
6 files changed, 126 insertions, 60 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 0223847..11071d6 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,13 @@ +2003-06-30 Ulrich Drepper <drepper@redhat.com> + + * sysdeps/unix/sysv/linux/i386/pthread_once.S (__pthread_once): + Use correct cleanup handler registration. Add unwind info. + * tst-once3.c: Add cleanup handler and check it is called. + * tst-once4.c: Likewise. + * tst-oncex3.c: New file. + * tst-oncex4.c: New file. + * Makefile: Add rules to build and run tst-oncex3 and tst-oncex4. + 2003-06-29 Ulrich Drepper <drepper@redhat.com> * sysdeps/pthread/configure.in: Check for C cleanup handling in gcc. diff --git a/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S index 8d3deb8..3bab92f 100644 --- a/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S +++ b/nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S @@ -17,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <unwindbuf.h> #include <sysdep.h> #ifndef UP @@ -36,6 +37,7 @@ .globl __pthread_once .type __pthread_once,@function .align 16 + cfi_startproc __pthread_once: movl 4(%esp), %ecx testl $2, (%ecx) @@ -44,7 +46,11 @@ __pthread_once: ret 1: pushl %ebx + cfi_adjust_cfa_offset (4) + cfi_rel_offset (3, 0) pushl %esi + cfi_adjust_cfa_offset (4) + cfi_rel_offset (6, 0) movl %ecx, %ebx xorl %esi, %esi @@ -90,33 +96,35 @@ __pthread_once: jmp 6b 3: /* Call the initializer function after setting up the - cancellation handler. */ - subl $16, %esp - - /* Push the cleanup handler. */ -#ifdef PIC - leal clear_once_control@GOTOFF(%ecx), %eax -#else - leal clear_once_control, %eax -#endif - movl %esp, %edx - pushl %ebx - pushl %eax - pushl %edx - call __pthread_cleanup_push /* Note: no @PLT. */ - - call *44(%esp) - - /* Pop the cleanup handler. This code depends on the once - handler and _pthread_cleanup_push not touch the content - of the stack. Otherwise the first parameter would have - to be reloaded. */ + cancellation handler. Note that it is not possible here + to use the unwind-based cleanup handling. This would require + that the user-provided function and all the code it calls + is compiled with exceptions. Unfortunately this cannot be + guaranteed. */ + subl $UNWINDBUFSIZE+8, %esp + cfi_adjust_cfa_offset (UNWINDBUFSIZE+8) + movl %ecx, %ebx /* PIC register value. */ + + leal 8+UWJMPBUF(%esp), %eax movl $0, 4(%esp) - call __pthread_cleanup_pop /* Note: no @PLT. */ + movl %eax, (%esp) + call __sigsetjmp@PLT + jne 7f - addl $28, %esp + leal 8(%esp), %eax + call __pthread_register_cancel + + /* Call the user-provided initialization function. */ + call *24+UNWINDBUFSIZE(%esp) + + /* Pop the cleanup handler. */ + leal 8(%esp), %eax + call __pthread_unregister_cancel + addl $UNWINDBUFSIZE+8, %esp + cfi_adjust_cfa_offset (-UNWINDBUFSIZE-8) /* Sucessful run of the initializer. Signal that we are done. */ + movl 12(%esp), %ebx LOCK addl $1, (%ebx) @@ -127,25 +135,19 @@ __pthread_once: ENTER_KERNEL 4: popl %esi + cfi_adjust_cfa_offset (-4) + cfi_restore (6) popl %ebx + cfi_adjust_cfa_offset (-4) + cfi_restore (3) xorl %eax, %eax ret - .size __pthread_once,.-__pthread_once - - .globl __pthread_once_internal -__pthread_once_internal = __pthread_once - - .globl pthread_once -pthread_once = __pthread_once - - - .type clear_once_control,@function - .align 16 -clear_once_control: - pushl %ebx - - movl 8(%esp), %ebx +7: /* __sigsetjmp returned for the second time. */ + movl 20+UNWINDBUFSIZE(%esp), %ebx + cfi_adjust_cfa_offset (UNWINDBUFSIZE+16) + cfi_offset (3, -8) + cfi_offset (6, -12) movl $0, (%ebx) movl $0x7fffffff, %edx @@ -153,9 +155,18 @@ clear_once_control: movl $SYS_futex, %eax ENTER_KERNEL - popl %ebx - ret - .size clear_once_control,.-clear_once_control + leal 8(%esp), %eax + call __pthread_unwind_next /* Note: no @PLT. */ + /* NOTREACHED */ + hlt + cfi_endproc + .size __pthread_once,.-__pthread_once + + .globl __pthread_once_internal +__pthread_once_internal = __pthread_once + + .globl pthread_once +pthread_once = __pthread_once #ifdef PIC diff --git a/nptl/tst-once3.c b/nptl/tst-once3.c index 802864c..43b354a 100644 --- a/nptl/tst-once3.c +++ b/nptl/tst-once3.c @@ -33,6 +33,7 @@ static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; static pthread_barrier_t bar; static int global; +static int cl_called; static void once_handler1 (void) @@ -42,6 +43,7 @@ once_handler1 (void) puts ("once_handler1: mutex_lock failed"); exit (1); } + puts ("once_handler1: locked"); int r = pthread_barrier_wait (&bar); if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD) @@ -53,6 +55,7 @@ once_handler1 (void) pthread_cond_wait (&cond, &mut); /* We should never get here. */ + exit (42); } static void @@ -62,11 +65,22 @@ once_handler2 (void) } +static void +cl (void *arg) +{ + cl_called = 1; +} + + static void * tf (void *arg) { + pthread_cleanup_push (cl, NULL) + pthread_once (&once, once_handler1); + pthread_cleanup_pop (0); + /* We should never get here. */ puts ("pthread_once in tf returned"); exit (1); @@ -81,40 +95,41 @@ do_test (void) if (pthread_barrier_init (&bar, NULL, 2) != 0) { puts ("barrier_init failed"); - exit (1); + return 1; } if (pthread_create (&th, NULL, tf, NULL) != 0) { puts ("first create failed"); - exit (1); + return 1; } int r = pthread_barrier_wait (&bar); if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD) { puts ("barrier_wait failed"); - exit (1); + return 1; } if (pthread_mutex_lock (&mut) != 0) { puts ("mutex_lock failed"); - exit (1); + return 1; } /* We unlock the mutex so that we catch the case where the pthread_cond_wait call incorrectly resumes and tries to get the mutex. */ if (pthread_mutex_unlock (&mut) != 0) { puts ("mutex_unlock failed"); - exit (1); + return 1; } /* Cancel the thread. */ + puts ("going to cancel"); if (pthread_cancel (th) != 0) { puts ("cancel failed"); - exit (1); + return 1; } void *result; @@ -122,7 +137,13 @@ do_test (void) if (result != PTHREAD_CANCELED) { puts ("join didn't return PTHREAD_CANCELED"); - exit (1); + return 1; + } + + if (cl_called != 1) + { + puts ("cleanup handler not called"); + return 1; } pthread_once (&once, once_handler2); @@ -130,7 +151,7 @@ do_test (void) if (global != 1) { puts ("global still 0"); - exit (1); + return 1; } return 0; diff --git a/nptl/tst-once4.c b/nptl/tst-once4.c index be83b54..bf0638b 100644 --- a/nptl/tst-once4.c +++ b/nptl/tst-once4.c @@ -34,6 +34,7 @@ static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; static pthread_barrier_t bar; static int global; +static int cl_called; static void once_handler1 (void) @@ -64,11 +65,22 @@ once_handler2 (void) } +static void +cl (void *arg) +{ + ++cl_called; +} + + static void * tf1 (void *arg) { + pthread_cleanup_push (cl, NULL); + pthread_once (&once, once_handler1); + pthread_cleanup_pop (0); + /* We should never get here. */ puts ("pthread_once in tf returned"); exit (1); @@ -78,6 +90,8 @@ tf1 (void *arg) static void * tf2 (void *arg) { + pthread_cleanup_push (cl, NULL); + int r = pthread_barrier_wait (&bar); if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD) { @@ -85,6 +99,8 @@ tf2 (void *arg) exit (1); } + pthread_cleanup_pop (0); + pthread_once (&once, once_handler2); return NULL; @@ -99,46 +115,46 @@ do_test (void) if (pthread_barrier_init (&bar, NULL, 2) != 0) { puts ("barrier_init failed"); - exit (1); + return 1; } if (pthread_create (&th[0], NULL, tf1, NULL) != 0) { puts ("first create failed"); - exit (1); + return 1; } int r = pthread_barrier_wait (&bar); if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD) { puts ("first barrier_wait failed"); - exit (1); + return 1; } if (pthread_mutex_lock (&mut) != 0) { puts ("mutex_lock failed"); - exit (1); + return 1; } /* We unlock the mutex so that we catch the case where the pthread_cond_wait call incorrectly resumes and tries to get the mutex. */ if (pthread_mutex_unlock (&mut) != 0) { puts ("mutex_unlock failed"); - exit (1); + return 1; } if (pthread_create (&th[1], NULL, tf2, NULL) != 0) { puts ("second create failed"); - exit (1); + return 1; } r = pthread_barrier_wait (&bar); if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD) { puts ("second barrier_wait failed"); - exit (1); + return 1; } /* Give the second thread a chance to reach the pthread_once call. */ @@ -148,7 +164,7 @@ do_test (void) if (pthread_cancel (th[0]) != 0) { puts ("cancel failed"); - exit (1); + return 1; } void *result; @@ -156,7 +172,7 @@ do_test (void) if (result != PTHREAD_CANCELED) { puts ("first join didn't return PTHREAD_CANCELED"); - exit (1); + return 1; } puts ("joined first thread"); @@ -165,13 +181,19 @@ do_test (void) if (result != NULL) { puts ("second join didn't return PTHREAD_CANCELED"); - exit (1); + return 1; } if (global != 1) { puts ("global still 0"); - exit (1); + return 1; + } + + if (cl_called != 1) + { + printf ("cl_called = %d\n", cl_called); + return 1; } return 0; diff --git a/nptl/tst-oncex3.c b/nptl/tst-oncex3.c new file mode 100644 index 0000000..08225b8 --- /dev/null +++ b/nptl/tst-oncex3.c @@ -0,0 +1 @@ +#include "tst-once3.c" diff --git a/nptl/tst-oncex4.c b/nptl/tst-oncex4.c new file mode 100644 index 0000000..9b4d98f --- /dev/null +++ b/nptl/tst-oncex4.c @@ -0,0 +1 @@ +#include "tst-once4.c" |