mirror of git://sourceware.org/git/glibc.git
Update.
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.
This commit is contained in:
parent
5a8e918dc6
commit
3a4d1e1e49
|
@ -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>
|
2003-06-29 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
* sysdeps/pthread/configure.in: Check for C cleanup handling in gcc.
|
* sysdeps/pthread/configure.in: Check for C cleanup handling in gcc.
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
02111-1307 USA. */
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <unwindbuf.h>
|
||||||
#include <sysdep.h>
|
#include <sysdep.h>
|
||||||
|
|
||||||
#ifndef UP
|
#ifndef UP
|
||||||
|
@ -36,6 +37,7 @@
|
||||||
.globl __pthread_once
|
.globl __pthread_once
|
||||||
.type __pthread_once,@function
|
.type __pthread_once,@function
|
||||||
.align 16
|
.align 16
|
||||||
|
cfi_startproc
|
||||||
__pthread_once:
|
__pthread_once:
|
||||||
movl 4(%esp), %ecx
|
movl 4(%esp), %ecx
|
||||||
testl $2, (%ecx)
|
testl $2, (%ecx)
|
||||||
|
@ -44,7 +46,11 @@ __pthread_once:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
1: pushl %ebx
|
1: pushl %ebx
|
||||||
|
cfi_adjust_cfa_offset (4)
|
||||||
|
cfi_rel_offset (3, 0)
|
||||||
pushl %esi
|
pushl %esi
|
||||||
|
cfi_adjust_cfa_offset (4)
|
||||||
|
cfi_rel_offset (6, 0)
|
||||||
movl %ecx, %ebx
|
movl %ecx, %ebx
|
||||||
xorl %esi, %esi
|
xorl %esi, %esi
|
||||||
|
|
||||||
|
@ -90,33 +96,35 @@ __pthread_once:
|
||||||
jmp 6b
|
jmp 6b
|
||||||
|
|
||||||
3: /* Call the initializer function after setting up the
|
3: /* Call the initializer function after setting up the
|
||||||
cancellation handler. */
|
cancellation handler. Note that it is not possible here
|
||||||
subl $16, %esp
|
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. */
|
||||||
|
|
||||||
/* Push the cleanup handler. */
|
leal 8+UWJMPBUF(%esp), %eax
|
||||||
#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. */
|
|
||||||
movl $0, 4(%esp)
|
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. */
|
/* Sucessful run of the initializer. Signal that we are done. */
|
||||||
|
movl 12(%esp), %ebx
|
||||||
LOCK
|
LOCK
|
||||||
addl $1, (%ebx)
|
addl $1, (%ebx)
|
||||||
|
|
||||||
|
@ -127,25 +135,19 @@ __pthread_once:
|
||||||
ENTER_KERNEL
|
ENTER_KERNEL
|
||||||
|
|
||||||
4: popl %esi
|
4: popl %esi
|
||||||
|
cfi_adjust_cfa_offset (-4)
|
||||||
|
cfi_restore (6)
|
||||||
popl %ebx
|
popl %ebx
|
||||||
|
cfi_adjust_cfa_offset (-4)
|
||||||
|
cfi_restore (3)
|
||||||
xorl %eax, %eax
|
xorl %eax, %eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.size __pthread_once,.-__pthread_once
|
7: /* __sigsetjmp returned for the second time. */
|
||||||
|
movl 20+UNWINDBUFSIZE(%esp), %ebx
|
||||||
.globl __pthread_once_internal
|
cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
|
||||||
__pthread_once_internal = __pthread_once
|
cfi_offset (3, -8)
|
||||||
|
cfi_offset (6, -12)
|
||||||
.globl pthread_once
|
|
||||||
pthread_once = __pthread_once
|
|
||||||
|
|
||||||
|
|
||||||
.type clear_once_control,@function
|
|
||||||
.align 16
|
|
||||||
clear_once_control:
|
|
||||||
pushl %ebx
|
|
||||||
|
|
||||||
movl 8(%esp), %ebx
|
|
||||||
movl $0, (%ebx)
|
movl $0, (%ebx)
|
||||||
|
|
||||||
movl $0x7fffffff, %edx
|
movl $0x7fffffff, %edx
|
||||||
|
@ -153,9 +155,18 @@ clear_once_control:
|
||||||
movl $SYS_futex, %eax
|
movl $SYS_futex, %eax
|
||||||
ENTER_KERNEL
|
ENTER_KERNEL
|
||||||
|
|
||||||
popl %ebx
|
leal 8(%esp), %eax
|
||||||
ret
|
call __pthread_unwind_next /* Note: no @PLT. */
|
||||||
.size clear_once_control,.-clear_once_control
|
/* 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
|
#ifdef PIC
|
||||||
|
|
|
@ -33,6 +33,7 @@ static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_barrier_t bar;
|
static pthread_barrier_t bar;
|
||||||
|
|
||||||
static int global;
|
static int global;
|
||||||
|
static int cl_called;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
once_handler1 (void)
|
once_handler1 (void)
|
||||||
|
@ -42,6 +43,7 @@ once_handler1 (void)
|
||||||
puts ("once_handler1: mutex_lock failed");
|
puts ("once_handler1: mutex_lock failed");
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
puts ("once_handler1: locked");
|
||||||
|
|
||||||
int r = pthread_barrier_wait (&bar);
|
int r = pthread_barrier_wait (&bar);
|
||||||
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
|
@ -53,6 +55,7 @@ once_handler1 (void)
|
||||||
pthread_cond_wait (&cond, &mut);
|
pthread_cond_wait (&cond, &mut);
|
||||||
|
|
||||||
/* We should never get here. */
|
/* We should never get here. */
|
||||||
|
exit (42);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -62,11 +65,22 @@ once_handler2 (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
cl (void *arg)
|
||||||
|
{
|
||||||
|
cl_called = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
tf (void *arg)
|
tf (void *arg)
|
||||||
{
|
{
|
||||||
|
pthread_cleanup_push (cl, NULL)
|
||||||
|
|
||||||
pthread_once (&once, once_handler1);
|
pthread_once (&once, once_handler1);
|
||||||
|
|
||||||
|
pthread_cleanup_pop (0);
|
||||||
|
|
||||||
/* We should never get here. */
|
/* We should never get here. */
|
||||||
puts ("pthread_once in tf returned");
|
puts ("pthread_once in tf returned");
|
||||||
exit (1);
|
exit (1);
|
||||||
|
@ -81,40 +95,41 @@ do_test (void)
|
||||||
if (pthread_barrier_init (&bar, NULL, 2) != 0)
|
if (pthread_barrier_init (&bar, NULL, 2) != 0)
|
||||||
{
|
{
|
||||||
puts ("barrier_init failed");
|
puts ("barrier_init failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_create (&th, NULL, tf, NULL) != 0)
|
if (pthread_create (&th, NULL, tf, NULL) != 0)
|
||||||
{
|
{
|
||||||
puts ("first create failed");
|
puts ("first create failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = pthread_barrier_wait (&bar);
|
int r = pthread_barrier_wait (&bar);
|
||||||
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
{
|
{
|
||||||
puts ("barrier_wait failed");
|
puts ("barrier_wait failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_mutex_lock (&mut) != 0)
|
if (pthread_mutex_lock (&mut) != 0)
|
||||||
{
|
{
|
||||||
puts ("mutex_lock failed");
|
puts ("mutex_lock failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
/* We unlock the mutex so that we catch the case where the pthread_cond_wait
|
/* We unlock the mutex so that we catch the case where the pthread_cond_wait
|
||||||
call incorrectly resumes and tries to get the mutex. */
|
call incorrectly resumes and tries to get the mutex. */
|
||||||
if (pthread_mutex_unlock (&mut) != 0)
|
if (pthread_mutex_unlock (&mut) != 0)
|
||||||
{
|
{
|
||||||
puts ("mutex_unlock failed");
|
puts ("mutex_unlock failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cancel the thread. */
|
/* Cancel the thread. */
|
||||||
|
puts ("going to cancel");
|
||||||
if (pthread_cancel (th) != 0)
|
if (pthread_cancel (th) != 0)
|
||||||
{
|
{
|
||||||
puts ("cancel failed");
|
puts ("cancel failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *result;
|
void *result;
|
||||||
|
@ -122,7 +137,13 @@ do_test (void)
|
||||||
if (result != PTHREAD_CANCELED)
|
if (result != PTHREAD_CANCELED)
|
||||||
{
|
{
|
||||||
puts ("join didn't return 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);
|
pthread_once (&once, once_handler2);
|
||||||
|
@ -130,7 +151,7 @@ do_test (void)
|
||||||
if (global != 1)
|
if (global != 1)
|
||||||
{
|
{
|
||||||
puts ("global still 0");
|
puts ("global still 0");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -34,6 +34,7 @@ static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_barrier_t bar;
|
static pthread_barrier_t bar;
|
||||||
|
|
||||||
static int global;
|
static int global;
|
||||||
|
static int cl_called;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
once_handler1 (void)
|
once_handler1 (void)
|
||||||
|
@ -64,11 +65,22 @@ once_handler2 (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
cl (void *arg)
|
||||||
|
{
|
||||||
|
++cl_called;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
tf1 (void *arg)
|
tf1 (void *arg)
|
||||||
{
|
{
|
||||||
|
pthread_cleanup_push (cl, NULL);
|
||||||
|
|
||||||
pthread_once (&once, once_handler1);
|
pthread_once (&once, once_handler1);
|
||||||
|
|
||||||
|
pthread_cleanup_pop (0);
|
||||||
|
|
||||||
/* We should never get here. */
|
/* We should never get here. */
|
||||||
puts ("pthread_once in tf returned");
|
puts ("pthread_once in tf returned");
|
||||||
exit (1);
|
exit (1);
|
||||||
|
@ -78,6 +90,8 @@ tf1 (void *arg)
|
||||||
static void *
|
static void *
|
||||||
tf2 (void *arg)
|
tf2 (void *arg)
|
||||||
{
|
{
|
||||||
|
pthread_cleanup_push (cl, NULL);
|
||||||
|
|
||||||
int r = pthread_barrier_wait (&bar);
|
int r = pthread_barrier_wait (&bar);
|
||||||
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
{
|
{
|
||||||
|
@ -85,6 +99,8 @@ tf2 (void *arg)
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_cleanup_pop (0);
|
||||||
|
|
||||||
pthread_once (&once, once_handler2);
|
pthread_once (&once, once_handler2);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -99,46 +115,46 @@ do_test (void)
|
||||||
if (pthread_barrier_init (&bar, NULL, 2) != 0)
|
if (pthread_barrier_init (&bar, NULL, 2) != 0)
|
||||||
{
|
{
|
||||||
puts ("barrier_init failed");
|
puts ("barrier_init failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_create (&th[0], NULL, tf1, NULL) != 0)
|
if (pthread_create (&th[0], NULL, tf1, NULL) != 0)
|
||||||
{
|
{
|
||||||
puts ("first create failed");
|
puts ("first create failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = pthread_barrier_wait (&bar);
|
int r = pthread_barrier_wait (&bar);
|
||||||
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
{
|
{
|
||||||
puts ("first barrier_wait failed");
|
puts ("first barrier_wait failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_mutex_lock (&mut) != 0)
|
if (pthread_mutex_lock (&mut) != 0)
|
||||||
{
|
{
|
||||||
puts ("mutex_lock failed");
|
puts ("mutex_lock failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
/* We unlock the mutex so that we catch the case where the pthread_cond_wait
|
/* We unlock the mutex so that we catch the case where the pthread_cond_wait
|
||||||
call incorrectly resumes and tries to get the mutex. */
|
call incorrectly resumes and tries to get the mutex. */
|
||||||
if (pthread_mutex_unlock (&mut) != 0)
|
if (pthread_mutex_unlock (&mut) != 0)
|
||||||
{
|
{
|
||||||
puts ("mutex_unlock failed");
|
puts ("mutex_unlock failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_create (&th[1], NULL, tf2, NULL) != 0)
|
if (pthread_create (&th[1], NULL, tf2, NULL) != 0)
|
||||||
{
|
{
|
||||||
puts ("second create failed");
|
puts ("second create failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = pthread_barrier_wait (&bar);
|
r = pthread_barrier_wait (&bar);
|
||||||
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
if (r != 0 && r!= PTHREAD_BARRIER_SERIAL_THREAD)
|
||||||
{
|
{
|
||||||
puts ("second barrier_wait failed");
|
puts ("second barrier_wait failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Give the second thread a chance to reach the pthread_once call. */
|
/* 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)
|
if (pthread_cancel (th[0]) != 0)
|
||||||
{
|
{
|
||||||
puts ("cancel failed");
|
puts ("cancel failed");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *result;
|
void *result;
|
||||||
|
@ -156,7 +172,7 @@ do_test (void)
|
||||||
if (result != PTHREAD_CANCELED)
|
if (result != PTHREAD_CANCELED)
|
||||||
{
|
{
|
||||||
puts ("first join didn't return PTHREAD_CANCELED");
|
puts ("first join didn't return PTHREAD_CANCELED");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
puts ("joined first thread");
|
puts ("joined first thread");
|
||||||
|
@ -165,13 +181,19 @@ do_test (void)
|
||||||
if (result != NULL)
|
if (result != NULL)
|
||||||
{
|
{
|
||||||
puts ("second join didn't return PTHREAD_CANCELED");
|
puts ("second join didn't return PTHREAD_CANCELED");
|
||||||
exit (1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global != 1)
|
if (global != 1)
|
||||||
{
|
{
|
||||||
puts ("global still 0");
|
puts ("global still 0");
|
||||||
exit (1);
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cl_called != 1)
|
||||||
|
{
|
||||||
|
printf ("cl_called = %d\n", cl_called);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
#include "tst-once3.c"
|
|
@ -0,0 +1 @@
|
||||||
|
#include "tst-once4.c"
|
Loading…
Reference in New Issue